<?php /* cifrex; 1.1 release http://cxsecurity.com/cifrex/ Copyright (c) 2012, Maksymilian Arciemowicz All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the CXSecurity nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MAKSYMILIAN ARCIEMOWICZ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ // Default directory $default_directory="/"; // Restrict directory // // Example: // $default_directory = /www/phpbb/ // $default_openbasedir = /www/ // // default_openbasediry is equal to default_directory // $default_directory = /www/phpbb/ // $default_openbasedir = // $default_openbasedir=""; // Display Error: [True/False] $default_error=True; // Initial errors if($default_error){ @error_reporting(E_ALL); @set_time_limit(0); } // Initial GPC if( (version_compare(PHP_VERSION, '5.4.0') == -1) AND (ini_get('magic_quotes_gpc')=="1") ){ foreach($_GET as $key => $val) $_GET[$key]=stripslashes($val); foreach($_POST as $key => $val) $_POST[$key]=stripslashes($val); } if(empty($default_openbasedir)) $default_openbasedir=$default_directory; // Initial values // [V1,V2,V3] Value if(!empty($_GET['value1'])) $value1=$_GET['value1']; else if(!empty($_POST['value1'])) $value1=$_POST['value1']; else $value1=""; if(!empty($_GET['value2'])) $value2=$_GET['value2']; else if(!empty($_POST['value2'])) $value2=$_POST['value2']; else $value2=""; if(!empty($_GET['value3'])) $value3=$_GET['value3']; else if(!empty($_POST['value3'])) $value3=$_POST['value3']; else $value3=""; // [T1,T2,T3] True if(!empty($_GET['true1'])) $true1=$_GET['true1']; else if(!empty($_POST['true1'])) $true1=$_POST['true1']; else $true1=""; if(!empty($_GET['true2'])) $true2=$_GET['true2']; else if(!empty($_POST['true2'])) $true2=$_POST['true2']; else $true2=""; if(!empty($_GET['true3'])) $true3=$_GET['true3']; else if(!empty($_POST['true3'])) $true3=$_POST['true3']; else $true3=""; // [F1,F2,F3] False if(!empty($_GET['false1'])) $false1=$_GET['false1']; else if(!empty($_POST['false1'])) $false1=$_POST['false1']; else $false1=""; if(!empty($_GET['false2'])) $false2=$_GET['false2']; else if(!empty($_POST['false2'])) $false2=$_POST['false2']; else $false2=""; if(!empty($_GET['false3'])) $false3=$_GET['false3']; else if(!empty($_POST['false3'])) $false3=$_POST['false3']; else $false3=""; // Initial Directory $katalog=$default_directory; if(!empty($_GET['katalog']) AND 0==strncmp($default_openbasedir, $_POST['katalog'], strlen($default_openbasedir))) $katalog=$_GET['katalog']; if(!empty($_POST['katalog']) AND 0==strncmp($default_openbasedir, $_POST['katalog'], strlen($default_openbasedir))) $katalog=$_POST['katalog']; $katalog=str_replace("../","/",str_replace("/..","/",$katalog)); if(isset($_GET['pokaz']) and $_GET['pokaz']=="main") $_POST['pokaz']=$_GET['pokaz']; if(isset($_GET['show']) AND !empty($_GET['show'])){ $_GET['show']=str_replace("../","/",str_replace("/..","/",$_GET['show'])); if(is_file($_GET['show']) AND 0==strncmp($default_openbasedir, $_GET['show'], strlen($default_openbasedir))){ $handle = fopen($_GET['show'], "r"); $buffer=""; if ($handle){ while (!feof($handle)) $buffer .= htmlentities(fgets($handle, 4096)); die("<PRE>".$buffer); } else die("CAN'T OPEN FILE"); } } echo '<HTML> <HEAD><TITLE>cIFrex 1.1 Regular Expression Research</TITLE></HEAD> <BODY> <PRE> <CENTER>'; if(isset($_POST['sendtocx']) AND $_POST['sendtocx']=='Send to CXSecurity' AND !empty($value1)){ echo ' <FORM name="form" action="http://cxsecurity.com/cifrex/save/" method="post"> <TABLE> <TR> <TD><A HREF="http://cxsecurity.com/cifrex/" Title="cIFrex manual"><IMG src="http://cxsecurity.com/images/logo/cifrex.png" alt="man cIFrex"></TD> <TD><B>cifrex 1.1</b><br>Try to describe the syntax<BR><A href="http://cxsecurity.com/cifrex/filters/">http://cxsecurity.com/cifrex/filters/</A><BR><INPUT type="submit" name="incoming" value="Submit"> <INPUT type="button" name="cancel" value="Cancel"></TD> </TR> </TABLE> <TABLE cellpadding="0" cellspacing="0" border="0" align="center"> <TR> <TD bgcolor="#C7C7C7" width="400">V:</TD> <TD bgcolor="#C7C7C7" width="400">T:</TD> <TD bgcolor="#C7C7C7" width="400">F:</TD> </TR> <TR> <TD bgcolor="#e9e9e9" width="33%">1 <INPUT type="hidden" name="value1" size="50" value="'.htmlspecialchars($value1).'">'.htmlspecialchars($value1).'</TD> <TD bgcolor="#e9e9e9" width="33%">1 <INPUT type="hidden" name="true1" size="50" value="'.htmlspecialchars($true1).'">'.htmlspecialchars($true1).'</TD> <TD bgcolor="#e9e9e9" width="33%">1 <INPUT type="hidden" name="false1" size="50" value="'.htmlspecialchars($false1).'">'.htmlspecialchars($false1).'</TD> </TR> <TR> <TD bgcolor="#e9e9e9" width="33%">2 <INPUT type="hidden" name="value2" size="50" value="'.htmlspecialchars($value2).'">'.htmlspecialchars($value2).'</TD> <TD bgcolor="#e9e9e9" width="33%">2 <INPUT type="hidden" name="true2" size="50" value="'.htmlspecialchars($true2).'">'.htmlspecialchars($true2).'</TD> <TD bgcolor="#e9e9e9" width="33%">2 <INPUT type="hidden" name="false2" size="50" value="'.htmlspecialchars($false2).'">'.htmlspecialchars($false2).'</TD> </TR> <TR> <TD bgcolor="#e9e9e9" width="33%">3 <INPUT type="hidden" name="value3" size="50" value="'.htmlspecialchars($value3).'">'.htmlspecialchars($value3).'</TD> <TD bgcolor="#e9e9e9" width="33%">3 <INPUT type="hidden" name="true3" size="50" value="'.htmlspecialchars($true3).'">'.htmlspecialchars($true3).'</TD> <TD bgcolor="#e9e9e9" width="33%">3 <INPUT type="hidden" name="false3" size="50" value="'.htmlspecialchars($false3).'">'.htmlspecialchars($false3).'</TD> </TR> </TABLE> <TABLE cellpadding="0" cellspacing="0" border="0" align="center"> <TR> <TD bgcolor="#C7C7C7" width="100">C:</TD> <TD bgcolor="#C7C7C7" width="100"><INPUT type="checkbox" name="lc" value="c"'; if(isset($_POST['cin']) AND $_POST['cin']=="1") echo ' checked="checked"'; echo '></TD> <TD bgcolor="#C7C7C7" width="100">C++:</TD> <TD bgcolor="#C7C7C7" width="100"><INPUT type="checkbox" name="lcpp" value="cpp"'; if(isset($_POST['cin']) AND $_POST['cin']=="1") echo ' checked="checked"'; echo '></TD> <TD bgcolor="#C7C7C7" width="100">C#:</TD> <TD bgcolor="#C7C7C7" width="100"><INPUT type="checkbox" name="lcsharp" value="csharp"></TD> <TD bgcolor="#C7C7C7" width="100">HTML:</TD> <TD bgcolor="#C7C7C7" width="100"><INPUT type="checkbox" name="lhtml" value="html"></TD> </TR> <TR> <TD bgcolor="#C7C7C7" width="100">Java:</TD> <TD bgcolor="#C7C7C7" width="100"><INPUT type="checkbox" name="java" value="java"'; if(isset($_POST['javain']) AND $_POST['javain']=="1") echo ' checked="checked"'; echo '></TD> <TD bgcolor="#C7C7C7" width="100">Java script:</TD> <TD bgcolor="#C7C7C7" width="100"><INPUT type="checkbox" name="ljs" value="js"></TD> <TD bgcolor="#C7C7C7" width="100">Perl:</TD> <TD bgcolor="#C7C7C7" width="100"><INPUT type="checkbox" name="lperl" value="perl"'; if(isset($_POST['perlin']) AND $_POST['perlin']=="1") echo ' checked="checked"'; echo '></TD> <TD bgcolor="#C7C7C7" width="100">PHP:</TD> <TD bgcolor="#C7C7C7" width="100"><INPUT type="checkbox" name="lphp" value="php"'; if(isset($_POST['phpin']) AND $_POST['phpin']=="1") echo ' checked="checked"'; echo '></TD> </TR> <TR> <TD bgcolor="#C7C7C7" width="100">Python:</TD> <TD bgcolor="#C7C7C7" width="100"><INPUT type="checkbox" name="lpython" value="python"></TD> <TD bgcolor="#C7C7C7" width="100">Ruby:</TD> <TD bgcolor="#C7C7C7" width="100"><INPUT type="checkbox" name="lruby" value="ruby"></TD> <TD bgcolor="#C7C7C7" width="100">Visual:</TD> <TD bgcolor="#C7C7C7" width="100"><INPUT type="checkbox" name="lvisual" value="visual"></TD> <TD bgcolor="#C7C7C7" width="100">Other:</TD> <TD bgcolor="#C7C7C7" width="100"><INPUT type="checkbox" name="lother" value="other"></TD> </TR> </TABLE> <INPUT type="hidden" name="dir" size="20" value="'.htmlspecialchars($katalog).'"> Do you know <B>CWE</B> ? <INPUT type="text" name="trycwe" value="" size="20"> <B>Topic:</B> <INPUT type="text" name="nazwa" value="" size="50"> <B>Description:</B> <TEXTAREA name="opis" cols="50" rows="10"></textarea> <B>Credit:</B> <INPUT type="text" name="autor" value="" size="50"> <B>Email:</B> <INPUT type="text" name="email" value="" size="50"> <INPUT type="submit" name="incoming" value="Submit"> <INPUT type="button" name="cancel" value="Cancel"> </FORM>'; } else { echo ' <FORM name="form" action="" method="post"> <TABLE> <TR> <TD><A HREF="http://cxsecurity.com/cifrex/" Title="cIFrex manual"><IMG src="http://cxsecurity.com/images/logo/cifrex.png" ALT="man cIFrex"></A></TD> <TD><B>cifrex 1.1</b><br>Free Regular Expression Research<BR><A href="http://cxsecurity.com/cifrex/">http://cxsecurity.com/cifrex/</A><BR><INPUT type="submit" name="trythispatterns" value="Find"> <INPUT type="submit" name="sendtocx" value="Send to CXSecurity"></TD> </TR> </TABLE> Directory: <INPUT type="text" name="katalog" size="20" value="'.htmlspecialchars($katalog).'"> What: C/C++:<INPUT type="checkbox" name="cin" value="1"'; if(isset($_POST['cin']) AND $_POST['cin']==1) echo ' checked="checked"'; echo '> PHP:<INPUT type="checkbox" name="phpin" value="1"'; if(isset($_POST['phpin']) AND $_POST['phpin']==1) echo ' checked="checked"'; echo '> Perl:<INPUT type="checkbox" name="perlin" value="1"'; if(isset($_POST['perlin']) AND $_POST['perlin']==1) echo ' checked="checked"'; echo '> JAVA:<INPUT type="checkbox" name="jin" value="1"'; if(isset($_POST['jin']) AND $_POST['jin']==1) echo ' checked="checked"'; echo '> *:<INPUT type="checkbox" name="allin" value="1"'; if(isset($_POST['allin']) AND $_POST['allin']==1) echo ' checked="checked"'; echo '> Other: <INPUT type="checkbox" name="writeotherin" value="1"'; if(isset($_POST['writeotherin']) AND $_POST['writeotherin']==1) echo ' checked="checked"'; echo '> <INPUT type="text" name="otherexin" value="'; if(isset($_POST['otherexin']) AND !empty($_POST['otherexin'])) echo htmlspecialchars($_POST['otherexin']); echo '" size="5"> <BR> <TABLE cellpadding="0" cellspacing="0" border="0" align="center"> <TR> <TD bgcolor="#C7C7C7" width="33%">V:</TD> <TD bgcolor="#C7C7C7" width="33%">T:</TD> <TD bgcolor="#C7C7C7" width="33%">F:</TD> </TR> <TR> <TD bgcolor="#e9e9e9" width="33%">1 (Required) <INPUT type="text" name="value1" size="50" value="'.htmlspecialchars($value1).'"></TD> <TD bgcolor="#e9e9e9" width="33%">1 <INPUT type="text" name="true1" size="50" value="'.htmlspecialchars($true1).'"></TD> <TD bgcolor="#e9e9e9" width="33%">1 <INPUT type="text" name="false1" size="50" value="'.htmlspecialchars($false1).'"></TD> </TR> <TR> <TD bgcolor="#e9e9e9" width="33%">2 <INPUT type="text" name="value2" size="50" value="'.htmlspecialchars($value2).'"></TD> <TD bgcolor="#e9e9e9" width="33%">2 <INPUT type="text" name="true2" size="50" value="'.htmlspecialchars($true2).'"></TD> <TD bgcolor="#e9e9e9" width="33%">2 <INPUT type="text" name="false2" size="50" value="'.htmlspecialchars($false2).'"></TD> </TR> <TR> <TD bgcolor="#e9e9e9" width="33%">3 <INPUT type="text" name="value3" size="50" value="'.htmlspecialchars($value3).'"></TD> <TD bgcolor="#e9e9e9" width="33%">3 <INPUT type="text" name="true3" size="50" value="'.htmlspecialchars($true3).'"></TD> <TD bgcolor="#e9e9e9" width="33%">3 <INPUT type="text" name="false3" size="50" value="'.htmlspecialchars($false3).'"></TD> </TR> </TABLE> </FORM> </CENTER> '; } if(empty($value1)) die(" </PRE> </BODY> </HTML>"); $acc=$katalog; $pointer=array(); function printarr($txt){ foreach($txt as $r); } function scanpreg($bufftmp,$buffer,$ematchnot){ if(0<preg_match_all("/".$bufftmp."/m",$buffer,$wyszukane2)) if(!empty($ematchnot)){ if(preg_match_all("/".$ematchnot."/m",$buffer,$wyszukane3)<=0){ echo "<FONT color='red'>Check"; print_r($wyszukane2); echo "</FONT>"; unset($wyszukane2); unset($wyszukane3); } else echo "SKIPED"; } else { echo "<FONT color='red'>Check"; print_r($wyszukane2); echo "</FONT>"; unset($wyszukane2); } } function remarr($arr){ $gen=array(); foreach($arr as $val) if(!is_int(array_search($val,$gen))) $gen[]=$val; return $gen; } function scanfile($name){ global $value1,$value2,$value3; global $true1,$true2,$true3; global $false1,$false2,$false3; $handle = fopen($name, "r"); $values[0]=array(); $values[1]=array(); $values[2]=array(); $buffer=''; if ($handle) { while (!feof($handle)) { $buffer .= fgets($handle, 4096); } echo "+"; flush(); if(!empty($value1)){ $resv1=preg_match_all("/".$value1."/m",$buffer,$wyszukane1); if($resv1==0) return 0; else { if(isset($wyszukane1['v1'])) $values[0]=remarr($wyszukane1['v1']); if(isset($wyszukane1['v2'])) $values[1]=remarr($wyszukane1['v2']); if(isset($wyszukane1['v3'])) $values[2]=remarr($wyszukane1['v3']); }} if(!empty($value2)){ $resv2=preg_match_all("/".$value2."/m",$buffer,$wyszukane2); if($resv2==0) return 0; else { if(isset($wyszukane2['v1'])) $values[0]=remarr($wyszukane2['v1']); if(isset($wyszukane2['v2'])) $values[1]=remarr($wyszukane2['v2']); if(isset($wyszukane2['v3'])) $values[2]=remarr($wyszukane2['v3']); }} if(!empty($value3)){ $resv3=preg_match_all("/".$value3."/m",$buffer,$wyszukane3); if($resv3==0) return 0; else { if(isset($wyszukane3['v1'])) $values[0]=remarr($wyszukane3['v1']); if(isset($wyszukane3['v2'])) $values[1]=remarr($wyszukane3['v2']); if(isset($wyszukane3['v3'])) $values[2]=remarr($wyszukane3['v3']); }} for($ffa=0;$ffa<count($values[0]) or $ffa==0;$ffa++) for($ffb=0;$ffb<count($values[1]) or $ffb==0;$ffb++) for($ffc=0;$ffc<count($values[2]) or $ffc==0;$ffc++){ $empty=array(); if(isset($values[0][$ffa])){ $empty[0][1]=$values[0][$ffa]; // if matched value contain _ $values[0][$ffa]=str_replace("_","\_",$values[0][$ffa]); $values[0][$ffa]=str_replace("'","\'",$values[0][$ffa]); } if(isset($values[1][$ffb])){ $empty[0][2]=$values[1][$ffb]; $values[1][$ffb]=str_replace("_","\_",$values[1][$ffb]); $values[1][$ffb]=str_replace("'","\'",$values[1][$ffb]); } if(isset($values[2][$ffc])){ $empty[0][3]=$values[2][$ffc]; $values[2][$ffc]=str_replace("_","\_",$values[2][$ffc]); $values[2][$ffc]=str_replace("'","\'",$values[2][$ffc]); } if(!empty($true1)){ $bufft1=''; if(isset($values[0][$ffa])) $bufft1=str_replace("<v1>",$values[0][$ffa],$true1); if(isset($values[1]) and isset($values[1][$ffb])) $bufft1=str_replace("<v2>",$values[1][$ffb],$bufft1); if(isset($values[2]) and isset($values[2][$ffc])) $bufft1=str_replace("<v3>",$values[2][$ffc],$bufft1); if(preg_match_all("/".$bufft1."/m",$buffer,$empty[1])<=0) continue; } if(!empty($true2)){ if(isset($values[0][$ffa])) $bufft2=str_replace("<v1>",$values[0][$ffa],$true2); if(isset($values[1]) and isset($values[1][$ffb])) $bufft2=str_replace("<v2>",$values[1][$ffb],$bufft2); if(isset($values[2]) and isset($values[2][$ffc])) $bufft2=str_replace("<v3>",$values[2][$ffc],$bufft2); if(preg_match_all("/".$bufft2."/m",$buffer,$empty[2])<=0) continue; } if(!empty($true3)){ if(isset($values[0][$ffa])) $bufft3=str_replace("<v1>",$values[0][$ffa],$true3); if(isset($values[1]) and isset($values[1][$ffb])) $bufft3=str_replace("<v2>",$values[1][$ffb],$bufft3); if(isset($values[2]) and isset($values[2][$ffc])) $bufft3=str_replace("<v3>",$values[2][$ffc],$bufft3); if(preg_match_all("/".$bufft3."/m",$buffer,$empty[3])<=0) continue; } if(!empty($false1)){ if(isset($values[0][$ffa])) $bufft1=str_replace("<v1>",$values[0][$ffa],$false1); if(isset($values[1]) and isset($values[1][$ffb])) $bufft1=str_replace("<v2>",$values[1][$ffb],$bufft1); if(isset($values[2]) and isset($values[2][$ffc])) $bufft1=str_replace("<v3>",$values[2][$ffc],$bufft1); if(0<preg_match_all("/".$bufft1."/m",$buffer,$empty[4])) continue; } if(!empty($false2)){ if(isset($values[0][$ffa])) $bufft2=str_replace("<v1>",$values[0][$ffa],$false2); if(isset($values[1]) and isset($values[1][$ffb])) $bufft2=str_replace("<v2>",$values[1][$ffb],$bufft2); if(isset($values[2]) and isset($values[2][$ffc])) $bufft2=str_replace("<v3>",$values[2][$ffc],$bufft2); if(0<preg_match_all("/".$bufft2."/m",$buffer,$empty[5])) continue; } if(!empty($false3)){ if(isset($values[0][$ffa])) $bufft3=str_replace("<v1>",$values[0][$ffa],$false3); if(isset($values[1]) and isset($values[1][$ffb])) $bufft3=str_replace("<v2>",$values[1][$ffb],$bufft3); if(isset($values[2]) and isset($values[2][$ffc])) $bufft3=str_replace("<v3>",$values[2][$ffc],$bufft3); if(0<preg_match_all("/".$bufft3."/m",$buffer,$empty[6])) continue; } if(is_string($name)) echo " <FONT color='green'>Name:</FONT> <A href=\"http://".$_SERVER["HTTP_HOST"].htmlspecialchars($_SERVER["SCRIPT_NAME"])."?show=".$name."\">".$name."</A>\n"; else echo " <FONT color='green'>Name:</FONT> ".$name."\n"; echo " <FONT color='red'>"; print_r($empty); echo " </FONT>"; flush(); } } } function opend($dir){ global $searchext; if(!($dir[strlen($dir)-1]=='/')){ $dir=$dir."/"; } $arr=array(); if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false){ if(is_dir($dir.$file) or preg_match("/.*\.(?:".$searchext.")$/m",$file)) $arr[]=$dir.$file; } closedir($dh); } return $arr; } function badaj($name){ global $acc,$searchext; for($count=0; $count<count($name); $count++){ if($name[$count][strlen($name[$count])-1]=='.') continue; if(is_file($name[$count]) and preg_match("/.*\.(?:".$searchext.")$/m",$name[$count],$ppemtp)) { scanfile($name[$count]); continue; } if(is_dir($name[$count])){ echo "\n"; echo "<FONT color='brown'>".$name[$count]."</FONT>\n"; badaj(opend($name[$count])); } } return; } if(!isset($_POST['sendtocx'])){ $searchext=''; if(isset($_POST['javain']) AND $_POST['javain']==1){ if(!empty($searchext)) $searchext.='|'; $searchext.='java'; } if(isset($_POST['phpin']) AND $_POST['phpin']==1){ if(!empty($searchext)) $searchext.='|'; $searchext.='php'; } if(isset($_POST['cin']) AND $_POST['cin']==1){ if(!empty($searchext)) $searchext.='|'; $searchext.='c|cpp|cc'; } if(isset($_POST['perlin']) AND $_POST['perlin']==1){ if(!empty($searchext)) $searchext.='|'; $searchext.='pl'; } if(isset($_POST['writeotherin']) AND $_POST['writeotherin']==1 AND !empty($_POST['otherexin'])){ if(!empty($searchext)) $searchext.='|'; $searchext.=$_POST['otherexin']; } if(isset($_POST['allin']) AND $_POST['allin']==1) $searchext='.*'; badaj(opend($katalog)); } echo " </PRE> </BODY> </HTML> "; ?>