Guest User

Untitled

a guest
Dec 31st, 2012
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <!-- ^ Always define a DOCTYPE - Read more about DOCTYPEs on w3c -->
  3. <html>
  4. <head>
  5.     <title>Vulnerability Scanner</title>
  6.     <style type="text/css">
  7.         body {
  8.             color: #ffffff;
  9.             text-shadow: 2px 2px #000000;
  10.             background-color: #282828;
  11.             font-family: Arial, Helvetica, sans-serif;
  12.         }
  13.  
  14.         pre {
  15.             background-color: #353535;
  16.             border: solid 1px #505050;
  17.         }
  18.  
  19.         input {
  20.             font-family: Arial, Helvetica, sans-serif;
  21.         }
  22.  
  23.         .Button {
  24.             padding: 5px 10px;
  25.             background: #303030;
  26.             border: solid #101010 1px;
  27.             color: #fff;
  28.             cursor: pointer;
  29.             font-weight: bold;
  30.             border-radius: 5px;
  31.             -moz-border-radius: 5px;
  32.             -webkit-border-radius: 5px;
  33.             text-shadow: 1px 1px #000;
  34.         }
  35.  
  36.         .Input {
  37.             border: solid #101010 1px;
  38.             color: white;
  39.             font-weight: bold;
  40.             padding: 3px;
  41.             background-color: #252525;
  42.         }
  43.     </style>
  44. </head>
  45.  
  46. <body>
  47.     <div align="center">
  48.         <pre>
  49.              _____   _                  _      _          _                          _         _  
  50.             |_   _| | |__     ___      / \    | |   ___  | |__     ___   _ __ ___   (_)  ___  | |_
  51.               | |   | |_ \   / _ \    / _ \   | |  / __| | |_ \   / _ \ | |_ ` _ \  | | / __| | __|
  52.               | |   | | | | |  __/   / ___ \  | | | (__  | | | | |  __/ | | | | | | | | \__ \ | |_
  53.               |_|   |_| |_|  \___|  /_/   \_\ |_|  \___| |_| |_|  \___| |_| |_| |_| |_| |___/  \__|
  54.               Vulnerability Scanner                                              www.hackforums.net
  55.         </pre>
  56.  
  57.         <form method="POST" action="">
  58.             Enter URL : <input type="text" name="url" value="<?php if(isset($_POST['url'])){echo(htmlentities($_POST['url']));}
  59.             else{echo('http://example.com/index.php?id=1');} ?>" size="75" class="Input" />
  60.             <input type="submit" name="submit" value="Scan" class="Button" />
  61.         </form>
  62.  
  63.         <br />
  64. <?php
  65.  
  66. //Coded by The Alchemist
  67. //Styled and modified by ande
  68. //Thanks again ande
  69.  
  70. class VulnScanner {
  71.    // ^   ^    CamelCase.
  72.  
  73.     // This is a good example, you should NEVER store data in the class that the user is going to want to change. Make a config file, use an XML file etc are all great alternatives.
  74.     protected $types = array(
  75.         'sql' => array('errors' => array("mysql_", "You have an error in your SQL syntax", "SQL Error", "Database Error", "supplied argument is not a valid MySQL result resource"),'vulnerability' => array("'",'"')),
  76.         'rfi' => array('errors' => array("Welcome to Facebook - Log In, Sign Up or Learn More", "failed to open stream: No such file or directory"), 'vulnerability' => array("http://www.facebook.com")),
  77.         'lfi' => array('errors' => array("root:x:0:0:root:", "failed to open stream: No such file or directory"), 'vulnerability' => array("../etc/passwd",
  78.                        "../../etc/passwd",
  79.                        "../../../etc/passwd",
  80.                        "../../../../etc/passwd",
  81.                        "../../../../../etc/passwd",
  82.                        "../../../../../../etc/passwd")),
  83.         'xss' => array('errors' => array("<img src=\"http://owned.com\"/>"), 'vulnerability' => array("'\"/><img src=\"http://owned.com\"/>"))
  84.     );
  85.  
  86.     public function __construct() {
  87.         // This is good too. We want the user to know that he can't use it before it spits out 2349234982 errors.
  88.         if(extension_loaded('curl')) {
  89.             throw new Exception('cURL must be enabled');
  90.         }
  91.     }
  92.     public function isValid($link) {
  93.                     // ^ You should try loosely following PSR standards (I say loosely because PSR standards are far too strict, even for me.) -- This example is known as "camelCase"
  94.         // Personally, I don't think you even need a function for this. But, this is much cleaner. Research "PHP Ternary" (I say PHP ternary because PHP ternary is different than literally every other langauage)
  95.         return filter_var($link, FILTER_VALIDATE_URL) ? (strstr($link, "=") ? true : false) : false;
  96.     }
  97.  
  98.  
  99.     private function getContents($link, $userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0') {
  100.                      // Again, camelCase
  101.         $ch = curl_init();
  102.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  103.         curl_setopt($ch, CURLOPT_VERBOSE, true);
  104.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  105.         curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
  106.                                             // Beats storing an unchangeable variable. If it's something that that user may want to change without much hassle, put it in the argument list@
  107.         curl_setopt($ch, CURLOPT_URL,$link);
  108.         $result = curl_exec($ch);
  109.         return $result;
  110.     }
  111.  
  112.     private function errorCheck($url, $addtourl, $errorar) {
  113.                                 // Even if you are documenting your functions, all variable names should be clear. This doesn't mean really long names, but give it short and simple meanings.
  114.         foreach($addtourl as $val) {
  115.             $link = $url.$val;
  116.             $contents = $this->getcontents($link);
  117.             foreach($errorar as $err) {
  118.                 if(strstr($contents, $err)) {
  119.                     return true;
  120.                 }
  121.             }
  122.         }
  123.         return false;
  124.     }
  125.  
  126.     // See? Much cleaner! Still lots more do to though...
  127.     public function isVulnerable($url, $type = 'sql') {
  128.         if(!isset($this->types[$type])) {
  129.             throw new Exception('Invalid type: ' . $type);
  130.         } else {
  131.             if($this->errorCheck($link, $this->$type['vulnerability'], $this->$type['errors']) ) {
  132.                 echo htmlentities($link) . " <span style=\"color: red;\">might</span> be vulnerable to SQL Injection.<br />";
  133.             } else {
  134.                 echo htmlentities($link) . " is probably <span style=\"color: red;\">NOT</span> vulnerable to SQL Injection.<br />";
  135.             }
  136.         }
  137.     }
  138.  
  139.     public function isSQLVulnerable($link) {
  140.         $orig = $link; // Why'd you do that? VulnScanner::errorcheck did not reference the variable, so making an "original value" variable is redundant.
  141.         if($this->errorcheck($orig,$this->sql,$this->sqlerrors))
  142.             echo htmlentities($orig) ." <span style=\"color: red;\">might</span> be vulnerable to SQL Injection.<br />";
  143.         else
  144.             echo htmlentities($orig) ." is probably <span style=\"color: red;\">NOT</span> vulnerable to SQL Injection.<br />";
  145.     }
  146. }
  147.  
  148.  
  149.  
  150. if(isset($_POST['url']) && isset($_POST['submit'])) {
  151.     $obj = new VulnScanner();
  152.     $link = $_POST['url'];
  153.     if($obj->isValid($link)) {
  154.         $obj->isVulnerable($link, 'sql'); // ta-da!
  155.     } else {
  156.         echo "<span style=\"color: red;\">". htmlentities($link) ." is not a valid link.</span>";
  157.     }
  158. }
  159. ?>
  160. </body>
  161. </html>
Advertisement
Add Comment
Please, Sign In to add comment