home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / netbus.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  6.1 KB  |  214 lines

  1. Netbus detector 
  2.  
  3. Examines the user's computer for open Netbus (the trojan horse) port and reports the conclusion to the user. 
  4.  
  5.  
  6.  
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
  8. <html>
  9. <!-- Version 1.1, November 29 1998. -->
  10. <!-- Latest version is at http://www.mdb.ku.dk/tarvin/netbus-detector/ -->
  11. <head><title>Netbus detector</title>
  12. <meta name="description" content="Online Netbus detection utility - see if Netbus is installed on your computer"> 
  13. <meta name="keywords" content="detection, netbus">
  14.  
  15. <style type="text/css">
  16. <!--
  17. body {
  18.                 background-color: white;
  19.                 color: black;
  20. }
  21. strong.bad {
  22.                 color: red;
  23.                 font-weight: bold;
  24. }
  25. strong.good {
  26.                 color: green;
  27.                 font-weight: bold;
  28. }
  29. input.submit {
  30.                 background-color: teal;
  31.                 color: white;
  32. }
  33. h1 {
  34.                 color: teal;
  35. }
  36. h2 {
  37.                 color: teal;
  38. }
  39. .permit {
  40.                 background-color: yellow;
  41. }
  42. pre {
  43.                 background-color: yellow;
  44. }
  45. p.note {
  46.                 font-size: smaller;
  47. }
  48. -->
  49. </style>
  50. </head>
  51.  
  52. <body>
  53.  
  54. <h1>Netbus detector</h1>
  55.  
  56. <?php
  57.  
  58. function connectToPort ($host, $port) {
  59.  
  60.     // This function is the interesting part of the script.
  61.     // It may be called from the 'MAIN'
  62.     // part of the script further down.
  63.  
  64.     // Not declared ill unless we find something
  65.     $status = 0;
  66.  
  67.     print "<p><code>Trying port $port at $host...";
  68.  
  69.     // Open a socket to the user's computer (or proxy; in 
  70.     // this case, the result can't be trusted)
  71.     $socket = fsockopen($host, $port, &$errno, &$errstr);
  72.  
  73.     if ($socket) {
  74.         // A connection could be made. Poor user; this is probably 
  75.         // Netbus answering...
  76.         print "<br>Port $port connection established - BAD!</code></p>";
  77.         $status = 1;
  78.  
  79.         // Let's see if it's speaking
  80.  
  81.         // To make sure that we will not be listening for ever
  82.         // in case of a silent (but open) port
  83.         set_socket_blocking($socket, 0);
  84.  
  85.         $count = 0;
  86.         $portOutput = "";
  87.  
  88.         // We will not keep trying for ever; let's stop after
  89.         // 10000 glances
  90.         while ($count < 10000) {
  91.             if ($readString = fread($socket, 1)) {
  92.  
  93.                 // Convert <, >, " and & to HTML entities
  94.                 $readString = htmlspecialchars($readString);
  95.  
  96.                 // Add the output to the sum of output
  97.                 $portOutput .= $readString;
  98.             }
  99.             $count++;
  100.         }
  101.  
  102.         // Enough of this. Close the connection.
  103.         fclose($socket);
  104.  
  105.         if ($portOutput != "") {
  106.             print "<p><code>Output:</code></p><pre>$portOutput</pre>";
  107.         }
  108.  
  109.     } else {
  110.         // In case we have good news:
  111.         print "<br>Port $port connection refused - good</code></p>";
  112.     }
  113.  
  114.     // Return status for the port we just examined
  115.     return $status;
  116. }
  117.  
  118. function printForm ($host, $uri) {
  119.  
  120.     // Make sure the user knows what's going on.
  121.     // This should not be dangerous in any way, but let's ask anyway
  122.     print "
  123.         <form method=post action=\"$uri\">
  124.         <p>Permission to <span class=permit>connect to ports 12345 
  125.         and 12346 at host 
  126.         <code>$host</code></span> granted:  <input 
  127.         type=checkbox name=permission value=\"ok\"></p>
  128.         <p><input class=submit type=submit></p>
  129.         </form>
  130.     ";
  131. }
  132.  
  133. // **********
  134. //    MAIN
  135. // **********
  136.  
  137. // Some definitions - the standard Netbus ports
  138. $netBusPortA = 12345;
  139. $netBusPortB = 12346;
  140.  
  141. // This may seem stupid; but if PHP is running in 'safe mode', 
  142. // the SCRIPT_URI environment variable doesn't seem to 
  143. // be readily available
  144. $uri = "http://" . $SERVER_NAME . $REQUEST_URI;
  145.  
  146. // Standard CGI environment variable; we are not using CGI, but
  147. // fortunately, the variable is still avaliable
  148. $host = gethostbyaddr($REMOTE_ADDR);
  149.  
  150. // Requesting host innocent until otherwise proven
  151. $netBusStatus = 0;
  152.  
  153. // Trying to make sure that the user actually wants me
  154. // to scan his/her ports. - And trying to make sure that nobody is 
  155. // directly linking to the script.
  156. if (!(($permission == "ok") && 
  157.     ($REQUEST_METHOD == "POST") && ($HTTP_REFERER == $uri))) {
  158.     // Write the permission-asking form - i.e. call the
  159.     // previously defined 'printForm' function
  160.     printForm($host, $uri);
  161. } else {
  162.     // Paranoia checks OK. Let's do it
  163.     print "
  164.         <h2>Processing host $host...</h2>
  165.         <table border=1 cellpadding=5>
  166.     ";
  167.  
  168.     print "<tr><td>";
  169.  
  170.     // Call script and add the status to the sum of status
  171.     // codes. The function 'connectToPort' is defined above
  172.     $netBusStatus += connectToPort($host, $netBusPortA);
  173.     print "</td></tr>";
  174.  
  175.     print "<tr><td>";
  176.     // Call the connect-function again for the other port
  177.     $netBusStatus += connectToPort($host, $netBusPortB);
  178.     print "</td></tr>";
  179.  
  180.     print "</table>";
  181.  
  182.     // Summarize results
  183.     print "<h2>Conclusion</h2>";
  184.  
  185.     if ($netBusStatus > 0) {
  186.         // Damn. The sum of status codes should be zero.
  187.         // User probably has Netbus installed.
  188.         print "
  189.             <p>Connection to at least one Netbus port 
  190.             succeeded. That's a <strong class=bad>bad</strong> sign!</p>
  191.             <p>This means that you probably have Netbus installed 
  192.             on your computer. See 
  193.             <a href=\"http://www.iss.net/xforce/alerts/advise8.html\">ISS' 
  194.             alert summary</a> for removal instructions.</p>
  195.         ";
  196.     } else {
  197.         // It's nice to bring good news
  198.         print "
  199.             <p>No Netbus ports responded at host $host. 
  200.             Congratulations - that's a <strong class=good>good</strong> sign!</p>
  201.             <p>This may not be a definitive test, though:
  202.             <br> - If Netbus is installed at non-standard ports or
  203.             <br> - if you are sitting behind a firewall,
  204.             <br>this utility will fail to detect Netbus.</p>
  205.             <p>You may <a href=\"$uri\">try again</a>.</p>
  206.         ";
  207.     }
  208. }
  209.  
  210. ?>
  211.  
  212. </body>
  213. </html>
  214.