Government Security
Network Security Resources

Jump to content

Photo

Perl+cgi - Network Discovery?


  • Please log in to reply
4 replies to this topic

#1 boney

boney

    Private

  • Members
  • 4 posts

Posted 22 February 2008 - 07:04 AM

Hey all,

Im in need of a script that can scan our local net and see which hosts are up (ip > host > mac)
and you're supposed to be able to run this script in the webbrowser, hence the cgi. Dont really know where to start so..
If anyone can provide some information on where i can read about how such script could be setup, please do :)
or paste your own scripts!

Any help much appriciated

// bny

#2 jg60533

jg60533

    Private First Class

  • Members
  • 42 posts

Posted 22 February 2008 - 07:31 AM

Hey bny,

Maybe checkout the nmap-cgi project? I'm not too familiar with the scripting for this but you may find some info here:
hxxp://nmap-cgi.tuxfamily.org/

Also here is a list of related nmap projects. Maybe one will meet your needs?

hxxp://ftp.iasi.roedu.net/mirrors/download.insecure.org/nmap/nmap_relatedprojects.html

-J

Edit: Sorry I failed to see, when I originally posted this, that you were wanting it to be in Perl.

#3 rlastinger

rlastinger

    Sergeant

  • Members
  • 220 posts

Posted 22 February 2008 - 01:17 PM

Hey bny,

Maybe checkout the nmap-cgi project? I'm not too familiar with the scripting for this but you may find some info here:
hxxp://nmap-cgi.tuxfamily.org/

Also here is a list of related nmap projects. Maybe one will meet your needs?

hxxp://ftp.iasi.roedu.net/mirrors/download.insecure.org/nmap/nmap_relatedprojects.html

-J

Edit: Sorry I failed to see, when I originally posted this, that you were wanting it to be in Perl.



I'm not sure if I carried it with me or not, but I wrote one a while back. I'll see if I still have it. It was just using perl-nmap, but was menu driven, not web based.

#4 boney

boney

    Private

  • Members
  • 4 posts

Posted 25 February 2008 - 04:38 AM

Thanks for the links, i read some stuff in them and made my own script :)
However, im a complete newbie when it comes to programming/scripting in any language, so i kinda need some help with what ive done!

#!/usr/bin/perl
 
 use CGI;
 use CGI::Carp qw(fatalsToBrowser);
 use Nmap::Parser;
 
 # Variables
 ###########################
 my $q = new CGI; 
 my $path = '/usr/bin/nmap';
 my $args = '-sP';
 my @ips  = qw/192.168.1.*/;
 
 # Scan the network for active IPs and do html stuff :/
 ######################################################
 print "Content-Type: text/html\n\n";
 print "<html><head><title>IPs in use: LAN</title></head>\n";
 print "<body>\n";
 
 my $nmap = new Nmap::Parser;
 $nmap->parsescan($path, $args, @ips);
 
 print "
 <style type=text/css>
 body {
	 font-family: helvetica, verdana, arial, sans-serif;
 }
 
 TABLE {
	 border-collapse: collapse;
	 border-spacing: 1;
	 border-width: 1;
	 border-color: rgb(180, 180, 200);
	 background-color: rgb(245, 245, 245);
	 font-family: helvetica, verdana, arial, sans-serif;
	 font-size: 80%;
	 font-weight: normal;
	 margin-top: 1ex;
	 margin-bottom: 1ex;
 }
 
	 TH {
	   background-color: rgb(25, 42, 165);
	   color: rgb(250, 252, 255);
	   padding: 0.4ex 1ex;
	   text-align: left;
	   vertical-align: top;
	 }
 
	 TD {
		 background-color: inherit;
		 /*color: rgb(245, 249, 255);*/
		 padding: 0.4ex 1ex;
		 vertical-align: top;
	 }
 </style>";
 
 print "<h2>IP addresses that are in use</h2>
 <p> This script scans the lan for active IP addresses.</p>";
 
 print "<table width=500 border=1><tr><th width=150>Hostname</th> <th align=right width=100>IP address</th> <th>MAC address</th></tr></table>";
 for my $host ($nmap->all_hosts(up)) {
	   $hostn = $host->hostname;
	   $ip_addr  = $host->addr;
	   $mac_addr = $host->mac_addr;
 #	$vendor = $host->mac_vendor;
 print "<table width=500 border=1><tr> <td width=150>$hostn</td> <td align=left width=100>$ip_addr</td> <td>$mac_addr</td></tr></table> \n";
 }
 
 print "</body>";
 print "</html>\n";

Does anyone know how i can get a pretty output? (theres a white space between every IP now, dunno why :( )
Oh.. and how come MAC addresses only show when i run my script in the terminal and not when i run it in the webserver (the webserver is on the same box as i host as a gateway/router)?

EDIT::
The MAC addresses only show if root runs the script, anyone know why? or possible fixes to this?

// Thanks, boney

#5 boney

boney

    Private

  • Members
  • 4 posts

Posted 26 February 2008 - 12:49 AM

Fixed it by downloading perl-suid and setuid the script.

// bny




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users