论坛: 黑客进阶 标题: perl程序,能帮我分析一下原因码?? 复制本贴地址    
作者: skywee [skywee]    论坛用户   登录
下面这个端口扫描程序在本机上运行正确,但上传到服务器作为CGI程序运行时输出错误,能帮我分析一下原因码??
#!/usr/bin/perl 
print "Content-type: text/html\n\n"; 
print"<html>\n";

use Socket;

$proto=getprotobyname('tcp');
$host = 'countersafety.51.net';
$iaddr = inet_aton($host);

$portstart=1;
$portend=200;
$portnum=($portend-$portstart)+1;
if($portnum%10==0)
{
$forknum=$portnum/10;
}
else
{
$forknum=($portnum-$portnum%10)/10+1;
}

for($i=0;$i<$forknum;$i++)
{

$pid=fork();

if($pid==0)
{
for($port=$portstart+$i*10;$port<$portstart+$i*10+10 and $port<=$portend;$port++){

socket(SOCKET,PF_INET,SOCKET_STREAM,$proto) or die "Can't create socket: $!";

$serv_addr = sockaddr_in($port,$iaddr);

if(connect(SOCKET,$serv_addr))
{
print"$port port is open!\n";
}
close(SOCKET);
}
exit(0);

}
}

waitpid($pid,0);
print"</html>\n";


地主 发表时间: 11/29 13:31

回复: aoming [aoming]   版主   登录
请问是什么样的错误提示?刚才试了一下,是不是这样的:
----------------------------
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@51.net and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log

-------------------

也许是服务器端限制了。
我的空间是51的A型用户,一些小的cgi程序可以正常运行,但是上次搞BBS300
0和雷敖的论坛时也是这样的提示。

希望精通perl-cgi的朋友能跟跟帖,大家一起研究cgi:)



[此贴被 咖啡╃泡面(aoming) 在 11月30日16时9分 编辑过]

B1层 发表时间: 11/30 16:12

回复: skywee [skywee]   论坛用户   登录
不是,是输出很多的Content-type: text/html。奇怪!!!

B2层 发表时间: 11/30 16:13

回复: NetDemon [netdemon]   ADMIN   登录
try
del 
print "Content-type: text/html\n\n"; 
print"<html>\n";
.....

pull to 

$serv_addr = sockaddr_in($port,$iaddr);

if(connect(SOCKET,$serv_addr))
{
print "Content-type: text/html\n\n"; 
print"<html>\n";

print"$port port is open!\n";
}
close(SOCKET);
}
exit(0);


或把use sockect 
放在前面



[此贴被 NetDemon(netdemon) 在 12月1日2时17分 编辑过]

B3层 发表时间: 12/1 2:24

回复: NetDemon [netdemon]   ADMIN   登录
试了试,你的代阿问题十足,不可能在本机上运行正确
因为
socket(SOCKET,PF_INET,SOCKET_STREAM,$proto) or die "Can't create socket: $!";
这里错了
SOCKET_STREAM要改为SOCK_STREAM

这样还是会打出很多Content-type: text/html 
因为你fork一次,整个代码由头到脚再次运行,包括了print "Content-type: text/html\n\n";
这个头在CGI调用了只需要输出一次就行了 

B4层 发表时间: 12/01 02:56

回复: NetDemon [netdemon]   ADMIN   登录
CGI程序基本等于不支持fork()

B5层 发表时间: 12/01 03:09

回复: skywee [skywee]   论坛用户   登录
在windows下命令行和Apache肯定都能运行正常,我把这个代码变成多线程的也能正常运行。但是到了linux下,连命令行都不行了。
原因应该正是你说的:
因为
socket(SOCKET,PF_INET,SOCKET_STREAM,$proto) or die "Can't create socket: $!";
这里错了
SOCKET_STREAM要改为SOCK_STREAM!
谢谢!

B6层 发表时间: 12/02 09:43

回复: skywee [skywee]   论坛用户   登录
顺便说一下,多进程在cgi上的扫描结果有问题,而多线程的扫描结果是正确的,不知道什么原因?

B7层 发表时间: 12/02 09:45

论坛: 黑客进阶

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号