Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   Уязвимости (https://forum.antichat.xyz/forumdisplay.php?f=74)
-   -   Сканер скриптов на уязвимости (https://forum.antichat.xyz/showthread.php?t=25526)

gemaglabin 17.10.2006 18:21

Сканер скриптов на уязвимости
 
Вот,накатал.База маленькая,дополнить можно самому )

Естествено будут ложные срабатывания,ну вообще х3 , тестим

PHP код:

<html>
<head>
<title>PHP source vulnerability scaner</title>
<style>
body {
margin            : 0px;
    padding            : 0px;
    background-color    : #101010;
    font-family        : "Verdana";
    font-size        : 10px;
    color            : #CCCCCC;
}
.j {
white-space:-moz-pre-wrap;
white-space:-pre-wrap;
white-space:-o-pre-wrap;
ord-wrap:break-word;
margin-top:4px;
margin-bottom:4px;
border:1px solid silver;
background-color:#f5f5f5;
font-family        : "Verdana";
font-size        : 11px;
padding:0.5em;
width:85%;
color:#222
}
.expl {
font-size:small;
margin-left:2em;
margin-right:2em
}
.h {
margin-top:1em;
margin-bottom:0px
}
input,textarea,select { 
font-family        : "Verdana";
font-size        : 10px;
color            : #CCCCCC; 
border: 1px solid #404040; 
BACKGROUND-COLOR: #222;
Width: 190px;
Heigth:46;
}
td {
font-size: 12px;
font-family: Verdana, "Trebuchet MS";
text-align: left;
}
code{
</style><hr>
</head>

  <div style="align:center;">
  <form name="scan" method="post">
  <center>  
  <table border="0" cellpadding="2" cellspacing="0" style="">
  <tr>
  <td>Directory&nbsp;</td>
  <td colspan="2"><input name="dir" type="text" value=""/></td>
  <td colspan="2"><input type="submit" Value="Run"/></td>
  </tr>
  </table>
  </center>
    <hr>
  </div>
</body>
</html>

<?php

ini_set
("display_errors","0");

function 
_highlight()
{
 global 
$ftext;

 
$phpteg    = array ("'&lt;\?php'si",
                     
"'&lt;\?'si",
                     
"'\?&gt;'si");
                     
 
$fphpteg   = array ("<font color=#95001E>&lt;?php</font>",
                     
"<font color=#95001E>&lt;?</font>",
                     
"<font color=#95001E>&gt;</font>");
                     
 
$strings   = array ("'(\"[^\"]*\")'si",
                     
"'(\'[^\']*\')'si");
                     
 
$fstrings  = array ("<font color=#DD0000>\\1</font>",
                     
"<font color=#DD0000>\\1</font>");
                     
 
$operator  = array ("'\,'si",
                     
"'\-'si",
                     
"'\+'si",
                     
"'\('si",
                     
"'\)'si",
                     
"'\{'si",
                     
"'\}'si");
                     
 
$foperator = array ("<font color=#007700>,</font>",
                     
"<font color=#007700>-</font>",
                     
"<font color=#007700>+</font>",
                     
"<font color=#007700>(</font>",
                     
"<font color=#007700>)</font>",
                     
"<font color=#007700>{</font>",
                     
"<font color=#007700>}</font>");
                     
 
$reserved  = array ("'(echo)'si",
                     
"'(print)'si",
                     
"'(while)'si",
                     
"'(switch)'si",
                     
"'(if)'si",
                     
"'(else)'si",
                     
"'(function)'si",
                     
"'(array)'si",
                     
"'(for)'si");
                     
 
$freserved  array_fill (0,count($reserved),"<font color=#007700>\\1</font>");                    
                     
                     
 
$comment   "'((?:#|//)[^\n]*|/\*.*?\*/)'si";
 
 
$function  "'([\w]+)([\s]*)[\(]'si";
 
 
$variable "'([\$]{1,2}[A-Za-z_]+)'si";

 
$ftext str_replace("<""&lt;"$ftext);
 
$ftext str_replace(">""&gt" $ftext); 
 
$ftemp preg_replace ($phpteg  ,$fphpteg,$ftext);
 
$ftemp preg_replace ($comment ,"<font color=#244ECC>\\1</font>",$ftemp);
 
$ftemp preg_replace ($function,"<font color=#0000cc>\\1</font>\\2(",$ftemp);
 
$ftemp preg_replace ($operator,$foperator,$ftemp);
 
$ftemp preg_replace ($variable,"<font color=#0000BB>\\1</font>",$ftemp);
 
$ftemp preg_replace ($strings ,$fstrings,$ftemp);
 
$ftemp preg_replace ($reserved,$freserved,$ftemp);
 
 return 
"<code>$ftemp</code>";
}

function 
show_error ($title,$num,$text)
{
 global 
$filename;
 print (
'<div class=h>');
 print (
"<font size=2>$title in $filename at $num</font>");
 print (
'<pre class=j>');
 print (
$num);
 print (
':&nbsp;');
 print (
'<font size=3>'._highlight("<?php\n".$text."?>").'</font>');
 print (
'</div></pre>');
}
  
function 
scan_file($file)
{
 global 
$ftext;
 global 
$filename;
 
$fileh file($file'r');
 for (
$i=0;$i<=count($fileh);$i++)
 {
 
# scan for sql errors
  
if (preg_match('[mysql_query\(.*\$_(GET|POST|SESSION|COOKIE|REQUEST).*\)]'$fileh[$i],$res)    ||
      
preg_match('[WHERE .*=\$_(GET|POST|SESSION|COOKIE|REQUEST)]'$fileh[$i],$res)              ||
      
preg_match('[request.form|request.querystring ADODB.Connection]',$fileh[$i],$res)           ||
      
preg_match('[query\(.*\$_(GET|POST|COOKIE|REQUEST).*\)]',$fileh[$i],$res) )
  {
     
$ftext     .= $fileh[$i];
     
$vuln       $vuln 1;
     echo 
show_error('Possible SQL injection',$i,$ftext);
  } 
 
# scan for php injections
 
if (preg_match('[(include|require)(_once)\s*(\(|\s).*\$_(GET|POST|SESSION|COOKIE|REQUEST)]'$fileh[$i],$res) ||
     
preg_match('[(eval)\(\$_(GET|POST|REQUEST|COOKIE)]'$fileh[$i],$res))
  {
     
$ftext     .= $fileh[$i];
     
$vuln       $vuln 1;
     echo 
show_error('Possible PHP injection',$i,$ftext);
  }  
  
# scan for xss bugs
 
if (preg_match('[(echo|print).*\$_(GET|POST|SESSION|COOKIE|REQUEST)]'$fileh[$i],$res) ||
     
preg_match("<(echo|print).*\$_SERVER\['PHP_SELF']>"$fileh[$i],$res))
  {
     
$ftext     .= $fileh[$i];
     
$vuln       $vuln 1;
     echo 
show_error('Possible XSS bug',$i,$ftext);
  }  
   
# dangerous code
 
if (preg_match('[\s+eval\s*\(\s*\$_(GET|POST|SESSION|COOKIE|REQUEST)]'$fileh[$i],$res)             ||
     
preg_match('[(system|popen|shell_exec|exec)\s*\(\$_(GET|POST|COOKIE|REQUEST).*\)]'$fileh[$i],$res)) 
  {
     
$ftext     .= $fileh[$i];
     
$vuln       $vuln 1;
     echo 
show_error('Dangerous code',$i,$ftext);
  } 
  
# HTTP response splitting
 
if (preg_match('[header\s*\("Location:.*\$_(GET|POST|SESSION|COOKIE|REQUEST).*\)]'$fileh[$i],$res) ||
     
preg_match('[header\s*\(.*\$_(GET|POST|SESSION|COOKIE|REQUEST).*\)]'$fileh[$i],$res))
  {
     
$ftext     .= $fileh[$i];
     
$vuln       $vuln 1;
     echo 
show_error('HTTP response splitting',$i,$ftext);
  } 
 }
}

if (isset(
$_POST['dir']))
{
 
$dir opendir($_POST['dir']);
 if (!
$dir) die("<center><h1>Cannot open directory</h1></center>");
 else
 {
  while ((
$ffile readdir($dir)) !== false $filez .= $ffile."\n";
  
$filezexplode("\n",$filez);
  
$vuln       0;
  for (
$b=0;$b<=count($filez);$b++)
  {
   
$filename $filez[$b];
   if (
is_file($filename)) echo scan_file($filename);
  }   
  
closedir ($dir);
 }
}
?>


ground_zero 17.10.2006 18:45

расскажи пожалуста по подробней как им пользоватса

gemaglabin 17.10.2006 19:00

Ничего сложного ; )

Указываешь путь к папке где лежат нужные скрипты и ждешь результата

http://img136.imageshack.us/img136/5039/scanmf3.th.png

Koller 17.10.2006 19:20

Possible SQL injection in Scaner ot geb.php at 162

162: preg_match('[request.form|request.querystring ADODB.Connection]',$fileh[$i],$res) ||

Работает...
gemaglabin как всегда нас порадовал...
Лови +...

ground_zero 17.10.2006 19:29

тоже самое 162: preg_match('[request.form|request.querystring ADODB.Connection]',$fileh[$i],$res) ||
... единственное что удручает нужно знать точный путь к папке на сервере +

gemaglabin 17.10.2006 19:31

Это он у вас нашел уязвимости в моем же скрипте %)

EXSlim 17.10.2006 19:39

Молодец. Просто хороший скрипт для начинающих php кодеров...молодец

ground_zero 17.10.2006 19:40

смотрим дальше у меня там ещё e107 есть чота должен показать ...

gemaglabin 17.10.2006 19:41

Надо конечноже расширять базу скрипта,одними регулярками тут не обойдешься.

ground_zero 17.10.2006 19:57

не показал даже возможности sql ни в e107 ни в php_nuke но всёравно респект сканер работает


Время: 18:23