Advertisement
thenadz

Lab Scan - Security Hole

Apr 28th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. <?php
  2. header( 'Content-Type: text/xml' );
  3.  
  4. // DEFINE SHIT
  5. define( 'TEMPLATE',
  6. "<?xml version=\"1.0\"?>
  7. <danscan>
  8.   <finished time=\"%d\" timestr=\"%s\" />
  9. %s</danscan>
  10. " );
  11.  
  12. // INIT SCAN RANGE
  13. $start  = @$_GET['start']  ? (int)$_GET['start'] : 1;
  14. $end    = @$_GET['end']    ? (int)$_GET['end']   : 62;
  15. $prefix = @$_GET['prefix'] ? $_GET['prefix']     : 'dog';
  16.  
  17. // ERROR TRAP
  18. if( $start > $end )
  19.    die( sprintf( TEMPLATE,
  20.         time(NULL),
  21.         date('jS \of F Y h:i:s A'),
  22.         '<error>$start > $end</error>' ) );
  23. elseif( $start < 0 )
  24.    die( sprintf( TEMPLATE,
  25.         time(NULL),
  26.         date('jS \of F Y h:i:s A'),
  27.         '<error>$start < min</error>' ) );
  28.  
  29. // BEGIN GENERATING SCAN RESULTS
  30. $write = '';
  31. for( $i = $start; $i <= $end; $i++ ){
  32.    $mac = sprintf( "$prefix%02d", $i );
  33.    $write .= "   <host name=\"$mac\" status=\"".scan( $mac )."\" />\n";
  34. }
  35.  
  36. // OUTPUT RESULTS
  37. printf( TEMPLATE, time(NULL), date('jS \of F Y h:i:s A'), $write );
  38.  
  39. // HELPERS
  40. function scan( $mac ) {
  41.    $test = shell_exec( "/bin/nc -zv -w 1 $mac 22 2>&1| /bin/cat -" );
  42.    print $test;
  43.  
  44.    if( strpos( $test, 'open' ) !== false )
  45.       return 'linux';
  46.    if( strpos( $test, 'Connection refused' ) !== false )
  47.       return 'windows';
  48.    return 'offline';
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement