The Unofficial NT Hack FAQ - Appendix 2

A-02. Perl Code for NETSCRIPT.PL


Author is David LeBlanc <dleblanc@iss.net>
------------- start netcheck.pl(Win NT Version) ---------------------------
if(length($ARGV[0]) == 0)
{
  print "Usage is perl netcheck.pl IP";
  exit 0;
}

open(NBT, "nbtstat -a ".$ARGV[0]." | ");
while()
{
  if(!grep(/Registered/, $_))
  {
    if(grep(/<00>  UNIQUE/,$_))
    {
      @machine = split(/\s/, $_);
    }
    if(grep(/<00>  GROUP/, $_))
    {
      @domain = split(/\s/, $_);
    }
  }
}

print "Machine = ".$machine[0]."\tDomain = ".$domain[0]."\n";

print "\nChecking Guest Access\n";
open(GUESTCHK, "net use \\\\".$ARGV[0]."\\ipc\$ /user:guest guest | ");
while()
{
  if(grep(/error/,$_))
  {
    print("Guest access denied\n");
  }
}

print "\nObtaining list of shares\n";

open(NTSH, "net view \\\\".$ARGV[0]." | ");
while()
{
  if(grep(/Disk/,$_))
  {
    @tmp = split(/\s/, $_);
    push(@shares, $tmp[0]);
  }
  print;
}

foreach $share (@shares)
{
  open(NETUSE, "net use \\\\".$ARGV[0]."\\".$share." | ");
  while()
  {
    if(grep(/successfully/,$_))
    {
      print $share." opened\n";
    }
  }
}

-------------  end netcheck.pl(Win NT Version)  ---------------------------

------------- start netcheck.pl(Win 95 Version) ---------------------------

if(length($ARGV[0]) == 0)
{
  print "Usage is perl netcheck.pl IP";
  exit 0;
  }

open(NBT, "nbtstat -A ".$ARGV[0]." | ");

while()
{
print;
if(grep(/Registered/, $_))
  {
   if(grep(/<00>  UNIQUE/,$_))
    {
     @machine = split(/\s/, $_);
    }
     if(grep(/<00>  GROUP/, $_))
      {
       @domain = split(/\s/, $_);
      }
   }
}

print "Machine = ".$machine[0]."\tDomain = ".$domain[0]."\n";

print "\nChecking Guest Access\n";
open(GUESTCHK, "net use \\\\".$ARGV[0]."\\ipc\$ /user:guest guest | ");
while()
{
  if(grep(/error/,$_))
  {
    print("Guest access denied\n");
  }
}

print "\nObtaining list of shares\n";

open(NTSH, "net view \\\\".$machine[0]." | ");
while()
{
 if(grep(/Disk/,$_))
  {
   @tmp = split(/\s/, $_);
   push(@shares, $tmp[0]);
  }
 print;
}

foreach $share (@shares)
{
open(NETUSE, "net use \\\\".$machine[0]."\\".$share." | ");
while()
 {
  if(grep(/successfully/,$_))
   {
   print $share." opened\n";
   }
 }
}
-------------  end netcheck.pl(Win 95 Version)  ---------------------------

 

Share this article

Receive all the latest articles by email!

Get all articles delivered directly to your mailbox as and when they are released on WindowSecurity.com! Choose between receiving instant updates with the Real-Time Article Update, or a monthly summary with the Monthly Article Update.



Receive all the latest articles by email!

Receive Real-Time & Monthly WindowSecurity.com article updates in your mailbox. Enter your email below!
Click for Real-Time sample & Monthly sample

Become a WindowSecurity.com member!

Discuss your security issues with thousands of other network security experts. Click here to join!

Community Area

Log in | Register

Solution Center

Readers' Choice

Which is your preferred network auditing solution?