■はじめに
以下に紹介するさまざまなソースにより、スキャナを垣間見ましょう。
■Perl版
ほとんどのスキャナはCで書かれていて、IPヘッダファイルに依存しているので、Perlだけで書かれているというのはユニークです。
#!/usr/bin/perl use IO::Socket; my ($line, $port, $sock,
@servers); my $VERSION='1.0'; ($server = $ARGV[0]) ||
&usage; $begin = ($ARGV[1] || 0); for
($port=$begin;$port<=65000;$port++) { $sock =
IO::Socket::INET->new(PeerAddr => $server, PeerPort =>
$port, Proto => 'tcp');
if ($sock) { print "Connected on port
$port\n"; } else { # print "$port failed\n";
} } # End for sub usage { print "Usage: portscan hostname [start
at port number]\n"; exit(0); } =head1 NAME portscan - Scans a host on TCP ports to
determine what is listening =head1 DESCRIPTION Determines on which TCP ports a host is
listening for incoming connections. Useful for determining what services are
running on a server. =head1 PREREQUISITE uses IO::Socket =head1 COREQUISITE None =head1 README Determines on which TCP ports a host is
listening for incoming connections. Useful for determining what services are
running on a server. =pod OSNAMES MSWin32, Unix =pod SCRIPT CATEGORIES Networking =cut
■CGI(Perl)版←「scan.cgi」 = 755」
#! /usr/local/bin/perl use Socket; ########## 変数設定 ###########
$thiscgi = ""; ########## メイン ########### &deco; print "Content-type:
text/html\n\n"; $thost=$FORM{'host'}; if ($thost eq ''){ &pr_f } &hyoji; ########### 表示 ########### sub hyoji { print
"<html><head><title>Portscan</title></head>\n";
print "<body bgcolor=\"black\"
text=\"white\"><center>\n"; $ipa = inet_aton($thost) or
&error; $ip=$FORM{'ip'}; print
"<h1>Scanning</h1><br><br>Target_host:$thost<br><br>\n";
print
"Target_port:$ip<br><br>\n"; &sok; print
"</center></body></html>\n"; exit; } ########## デコード ##########
sub deco{ if ($ENV{'REQUEST_METHOD'} eq "POST")
{ read(STDIN, $buffer,
$ENV{'CONTENT_LENGTH'}); } else { $buffer =
$ENV{'QUERY_STRING'}; } @pairs = split(/&/,$buffer);
foreach $pair (@pairs) { ($name, $value) = split(/=/,
$pair); $value =~ tr/+/ /; $value =~
s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value; } } ########## エラー処理 ##########
sub error { print "Content-type:
text/html\n\n"; print
"<html><head><title>ERROR</title></head>\n";
print "<body><font
size=7>Error!!</font></body></html>\n";
exit; } ########## 入力フォーム
########### sub pr_f{ print
"<html><head><title>Portscan</title></head>\n";
print "<body bgcolor=\"black\"
text=\"white\">\n"; print
"<center><h1>Portscan</h1><br>\n";
print "<form method=\"GET\"
action=\"$thiscgi\">\n"; print "Target_hostname<input
type=text name=\"host\"><br>"; print "Target_port<input type=text
name=\"ip\" value=\"69\"><br>"; print "<input type=submit
value=\"scan\">\n"; print "<input type=reset
value=\"reset\">\n"; print
"</form><br>\n"; print
"</center></body></html>\n"; exit; } ########## ソケット処理 ##########
sub sok { socket
(SOCK,PF_INET,SOCK_STREAM,getprotobyname('tcp'));
if (connect
(SOCK,sockaddr_in($ip,$ipa))) { print "$ip :
Connection!!!<br>\n"; }else{ print ""; } close(SOCK,0); }
■参考文献
|
|||
|
|