#!/usr/local/bin/perl # Script to print on port services and trojans # Called from ports.html # Written by Robert G. Ferrell (rgferrell@direcway.com) # Revised 4/28/2000 RGF: Fix trojan field reporting problem # Revised 8/11/2000 RGF: Fix error message when 0 selected # Revised 5/21/2001 RGF: Change if to unless in trojan field test require qq(INSERT CGI LIBRARY HERE); &ReadParse; $rootdir = qq(INSERT DOCUMENT DIRECTORY HERE); $dbase = qq($rootdir/ports.db); $port_in = $in{'port_no'}; $port_in =~ s/^\s//; $keywd = $in{'keyword'}; $keywd =~ s/^\s//; $p_stat = 0; $k_stat = 0; $k_inc = 0; $count = 0; $port_match = 0; $key_match = 0; print "Content-type: text/html\n\n"; if ($port_in =~ /^\d{1,5}$/) { $p_stat = 1; $search = qq(Port); $term = $port_in; &print_results; } elsif ($keywd ne "") { $k_stat = 1; $search = qq(Keyword); $term = $keywd; &print_results; } else { &no_data; } sub bad_port { print <<"End_of_print1"; Unix Port Services/Trojan Search Results

Unix Port Services/Trojan Search Results


Your port entry was $port_in. Make sure port number is an integer from 0 to 65536.

Please use the BACK button on your browser to return to the search page and try again.


End_of_print1 exit(); } sub no_data { print <<"End_of_print2"; Unix Port Services/Trojan Search Results

Unix Port Services/Trojan Search Results


No Port Number or Keyword Provided!

Please use the BACK button on your browser to return to the search page and try again.


End_of_print2 exit(); } sub print_results { print <<"End_of_print3"; Unix Port Services/Trojan Search Results

Unix Port Services/Trojan Search Results


$search: $term

Search Results End_of_print3 open(DB, $dbase); while(defined($line = )) { ($serv,$port,$prot,$desc,$troj) = split(/\|/, $line); $serv = "N/A" if ($serv !~ /\w/g); $desc = "N/A" if ($desc !~ /\w/g); $troj = "None Known" unless ($troj =~ /\w*/); if ($p_stat == 1) { unless (($port_in =~ /^\d{1,5}$/) && ($port_in < 65537)) { &bad_port; } if ($port == $port_in) { $port_match = 1; $count++; print ""; print ""; print ""; } } elsif (($p_stat == 0) && ($k_stat == 1)) { $key_match = grep (/$keywd/i, $line); if ($key_match != 0) { $count++; print ""; print ""; print ""; $k_inc++; } } } close(DB); if (($k_stat == 1) && ($key_match == 0) && ($k_inc == 0)) { print ""; } elsif (($p_stat == 1) && ($port_match == 0)) { print ""; } print <<"End_of_print6";
PORTPROTOCOL SERVICEDESCRIPTION TROJAN(S)
$port$prot$serv$desc$troj
$port$prot$serv$desc$troj
Keyword Not Found
No Assigned Services

Total Returns = $count


End_of_print6 }