Perl 로 된 간단한 tcp port scanner 보안 도구 사용

서버 내부에서 포트 스캐닝 도구 사용이 여의치 않을 때 사용할 수 있는 간단한 포트 스캐너

#!/usr/bin/perl

use IO::Socket;

$port = 1;
$output ="./result.txt";

open (LIST, ">>$output");
while ($port <= 1024) {
  $sock = new IO::Socket::INET (PeerAddr => '192.168.1.1',
                                              PeerPort => $port,
                                              Proto => 'tcp');
  if ($sock) {
    close $sock;
    print "$port -open\n";
    print LIST "$port -open\n";
    $port = $port + 1;
  } else {
    print "$port -closed\n";
    $port = $port + 1;
  }
}
close(LIST);

위의 예제에서는 타겟 주소와 start port, end port 가 static 하게 박혀 있으므로 상황에 따라 적절하게 수정해줄 필요가 있음.

파일 다운로드 : scan.pl


트랙백

이 글과 관련된 글 쓰기 (트랙백 보내기)
TrackbackURL : http://swbae.egloos.com/tb/1701032 [도움말]

덧글

  • aero 2008/01/21 11:46 # 삭제 답글

    약간 수정해 봤습니다.
    #!/usr/bin/perl
    use strict;
    use warnings;
    use IO::Socket;

    my $output ="./result.txt";
    open my $fh,">>$output";
    foreach my $port ($ARGV[1]..$ARGV[2]) {
    my $sock = new IO::Socket::INET (PeerAddr => $ARGV[0], PeerPort => $port, Proto => 'tcp');
    if ($sock) {
    print "$port -open\n";
    print $fh "$port -open\n";
    close $sock;
    } else {
    print "$port -closed\n";
    }
    }
    close($fh);

    사용법> perl scan.pl 서버ip 시작포트 끝포트
    perl scan.pl 192.168.1.1 1 1024


  • suban 2008/01/23 20:29 # 삭제 답글

    퍼갈게욥!! 윗분도 감사합니다~
덧글 입력 영역