Guest User

Untitled

a guest
Dec 31st, 2012
2
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.15 KB | None | 0 0
  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. <body>
  46.     <div align="center">
  47.         <pre>
  48.              _____   _                  _      _          _                          _         _  
  49.             |_   _| | |__     ___      / \    | |   ___  | |__     ___   _ __ ___   (_)  ___  | |_
  50.               | |   | |_ \   / _ \    / _ \   | |  / __| | |_ \   / _ \ | |_ ` _ \  | | / __| | __|
  51.               | |   | | | | |  __/   / ___ \  | | | (__  | | | | |  __/ | | | | | | | | \__ \ | |_
  52.               |_|   |_| |_|  \___|  /_/   \_\ |_|  \___| |_| |_|  \___| |_| |_| |_| |_| |___/  \__|
  53.               Vulnerability Scanner                                              www.hackforums.net
  54.         </pre>
  55.  
  56.         <form method="POST" action="">
  57.             Enter URL : <input type="text" name="url" value="<?php if(isset($_POST['url'])){echo(htmlentities($_POST['url']));}
  58.             else{echo('http://example.com/index.php?id=1');} ?>" size="75" class="Input" />
  59.             <input type="submit" name="submit" value="Scan" class="Button" />
  60.         </form>
  61.  
  62.         <br />
  63. <?php
  64.  
  65. //Coded by The Alchemist
  66. //Styled and modified by ande
  67. //Thanks again ande
  68.  
  69. class VulnScanner {
  70.    // ^   ^    CamelCase.
  71.  
  72.     // 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.
  73.     protected $types = array(
  74.         '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("'",'"')),
  75.         '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")),
  76.         'lfi' => array('errors' => array("root:x:0:0:root:", "failed to open stream: No such file or directory"), 'vulnerability' => array("../etc/passwd",
  77.                        "../../etc/passwd",
  78.                        "../../../etc/passwd",
  79.                        "../../../../etc/passwd",
  80.                        "../../../../../etc/passwd",
  81.                        "../../../../../../etc/passwd")),
  82.         'xss' => array('errors' => array("<img src=\"http://owned.com\"/>"), 'vulnerability' => array("'\"/><img src=\"http://owned.com\"/>"))
  83.     );
  84.  
  85.     public function __construct() {
  86.         // This is good too. We want the user to know that he can't use it before it spits out 2349234982 errors.
  87.         if(extension_loaded('curl')) {
  88.             throw new Exception('cURL must be enabled');
  89.         }
  90.     }
  91.     public function isValid($link) {
  92.                     // ^ 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"
  93.         // 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)
  94.         return filter_var($link, FILTER_VALIDATE_URL) ? (strstr($link, "=") ? true : false) : false;
  95.     }
  96.  
  97.  
  98.     private function getContents($link, $userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0') {
  99.                      // Again, camelCase
  100.         $ch = curl_init();
  101.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  102.         curl_setopt($ch, CURLOPT_VERBOSE, true);
  103.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  104.         curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
  105.                                             // 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@
  106.         curl_setopt($ch, CURLOPT_URL,$link);
  107.         $result = curl_exec($ch);
  108.         return $result;
  109.     }
  110.  
  111.     private function errorCheck($url, $addtourl, $errorar) {
  112.                                 // 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.
  113.         foreach($addtourl as $val) {
  114.             $link = $url.$val;
  115.             $contents = $this->getcontents($link);
  116.             foreach($errorar as $err) {
  117.                 if(strstr($contents, $err)) {
  118.                     return true;
  119.                 }
  120.             }
  121.         }
  122.         return false;
  123.     }
  124.  
  125.     // See? Much cleaner! Still lots more do to though...
  126.     public function isVulnerable($url, $type = 'sql') {
  127.         if(!isset($this->types[$type])) {
  128.             throw new Exception('Invalid type: ' . $type);
  129.         } else {
  130.             if($this->errorCheck($link, $this->$type['vulnerability'], $this->$type['errors']) ) {
  131.                 echo htmlentities($link) . " <span style=\"color: red;\">might</span> be vulnerable to SQL Injection.<br />";
  132.             } else {
  133.                 echo htmlentities($link) . " is probably <span style=\"color: red;\">NOT</span> vulnerable to SQL Injection.<br />";
  134.             }
  135.         }
  136.     }
  137.  
  138.     public function isSQLVulnerable($link) {
  139.         $orig = $link; // Why'd you do that? VulnScanner::errorcheck did not reference the variable, so making an "original value" variable is redundant.
  140.         if($this->errorcheck($orig,$this->sql,$this->sqlerrors))
  141.             echo htmlentities($orig) ." <span style=\"color: red;\">might</span> be vulnerable to SQL Injection.<br />";
  142.         else
  143.             echo htmlentities($orig) ." is probably <span style=\"color: red;\">NOT</span> vulnerable to SQL Injection.<br />";
  144.     }
  145. }
  146.  
  147.  
  148.  
  149. if(isset($_POST['url']) && isset($_POST['submit'])) {
  150.     $obj = new VulnScanner();
  151.     $link = $_POST['url'];
  152.     if($obj->isValid($link)) {
  153.         $obj->isVulnerable($link, 'sql'); // ta-da!
  154.     } else {
  155.         echo "<span style=\"color: red;\">". htmlentities($link) ." is not a valid link.</span>";
  156.     }
  157. }
  158. ?>
  159. </body>
  160. </html>
Advertisement
Add Comment
Please, Sign In to add comment