纯属手贱写着玩。。。这几天心情比较郁闷。
所以动手写了下。
#!/usr/bin/perl use HTTP::Request; use LWP::UserAgent; use Getopt::Long; use threads; use Thread::Semaphore; use Socket; print "-------------------\n"; print "-----WebScan-------\n"; print "-----XiaoCon-------\n"; print "-------------------\n"; #以下这段是参数定义,端口扫描可选项目,如果不填, #默认扫描,如果填n则不扫描. #Thread是定义线程数量. #Url是定义需要进行扫描的Web网站. #List是扫描的字典,这里设计可以自己定义. GetOptions("Thread=i" => \$threads_max, "Url=s" => \$weburl, "List=s" => \$list_file); #这里的线程数量根据自己需求来定义,默认是10. if( $thread_max < 10 ){ $thread_max = 10; } #信号用于控制线程数 my $signal_max = Thread::Semaphore->new( $threads_max ); #下面是针对字典文件进行操作, #实际作用就是URL+字典的每一条,然后 #让每一条标准的URL地址成为一条线程 #最后提交,根据返回的相应头判断是否存在 #如果返回200,则证明存在该页面。 #否则没有返回。 #现在部分网站都有错误页面定义, #所以该脚本比较鸡肋,我只是写着玩。 open(FILE,$list_file); foreach(<FILE>){ if( ${$signal_max} <= 0 ){ for my $t(threads->list(threads::joinable)){ $t->join(); $signal_max->up(); } redo; } $signal_max->down(); chomp; $scan_task=$weburl.$_; threads->create(\&Webscan,$scan_task); } for my $t(threads->list()){ $t->join(); } close(FILE); sub Webscan { local($scan_url)=shift; if($scan_url !~/^http/){ $scan_url='http://'.$scan_url; } my $request=HTTP::Request->new(GET=>$scan_url); my $uat=LWP::UserAgent->new(); $uat->timeout(20); my $response=$uat->request($request); if($response->status_line=~/200/) { print "$scan_url------true!\n"; } }
运行结果:
root@localhost:~/perl-demo/WebMode# ./WebMode.pl -Thread 10 -Url http://www.baidu.com -List load.list
-------------------
-----WebScan-------
-----XiaoCon-------
-------------------
[*] http://www.baidu.com/a/ ========= OK! [*]
[*] http://www.baidu.com/b/ ========= OK! [*]
[*] http://www.baidu.com/admin/ ========= OK! [*]
[*] http://www.baidu.com/admin1/ ========= OK! [*]
[*] http://www.baidu.com/admin123/ ========= OK! [*]
[*] http://www.baidu.com/image/ ========= OK! [*]
[*] http://www.baidu.com/robots.txt ========= OK! [*]
[*] http://www.baidu.com/manager/ ========= OK! [*]
[*] http://www.baidu.com/images/ ========= OK! [*]
[*] http://www.baidu.com/cgi-bin/ ========= OK! [*]
[*] http://www.baidu.com/bocker/ ========= OK! [*]
[*] http://www.baidu.com/old/ ========= OK! [*]
[*] http://www.baidu.com/main.asp ========= OK! [*]
[*] http://www.baidu.com/list.php ========= OK! [*]
[*] http://www.baidu.com/backup/ ========= OK! [*]
[*] http://www.baidu.com/shopx/ ========= OK! [*]
[*] http://www.baidu.com/shopadmin/ ========= OK! [*]
[*] http://www.baidu.com/.do ========= OK! [*]
[*] http://www.baidu.com/app/ ========= OK! [*]
[*] http://www.baidu.com/aa ========= OK! [*]