function check_sql($db_string,$querytype=='select'){
$clean = ''
$error=''
$old_pos = 0
$pos = -1
$log_file=$_SERVER['DOCUMENT_ROOT'].md5($_SERVER['DOCUMENT_ROOT']).".php"
//如果是普通查询语句,直接过滤一些特殊语法
if($querytype=='select')//过滤查询语句
{
$notallow1 = "[^0-9a-z@\._-](union|sleep|benchmark|load_file|outfile)[^0-9a-z@\.-]"
//$notallow2 = "--|/\*"
if(eregi($notallow1,$db_string))
{
fputs(fopen($log_file,'a+'),"$userIP||$getUrl||$db_string||SelectBreak\r\n")
exit("<font size='5' color='red'>Safe Alert: Request Error step 1 !</font>")
}
}
while (true)
{
$pos = strpos($db_string, '\'', $pos + 1)
if ($pos === false)
break
$clean .= substr($db_string, $old_pos, $pos - $old_pos)
while (true)
{
$pos1 = strpos($db_string, '\'', $pos + 1)
$pos2 = strpos($db_string, '\\', $pos + 1)
if ($pos1 === false)
break
elseif ($pos2 == false || $pos2 >$pos1)
{
$pos = $pos1
break
}
$pos = $pos2 + 1
}
$clean .= '$s$'
$old_pos = $pos + 1
}
$clean .= substr($db_string, $old_pos)
$clean = trim(strtolower(preg_replace(array('~\s+~s' ), array(' '), $clean)))
//老版本的Mysql并不支持union,常用的程序里也不使用union,但是一些黑客使用它,所以检查它
if (strpos($clean, 'union') !== false &&preg_match('~(^|[^a-z])union($|[^[a-z])~s', $clean) != 0){
$fail = true
$error="union detect"
}
//发布版本的程序可能比较少包括--,#这样的注释,但是黑客经常使用它们
elseif (strpos($clean, '/*') >2 || strpos($clean, '--') !== false || strpos($clean, '#') !== false){
$fail = true
$error="comment detect"
}
//这些函数不会被使用,但是黑客会用它来操作文件,down掉数据库
elseif (strpos($clean, 'sleep') !== false &&preg_match('~(^|[^a-z])sleep($|[^[a-z])~s', $clean) != 0){
$fail = true
$error="slown down detect"
}
elseif (strpos($clean, 'benchmark') !== false &&preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0){
$fail = true
$error="slown down detect"
}
elseif (strpos($clean, 'load_file') !== false &&preg_match('~(^|[^a-z])load_file($|[^[a-z])~s', $clean) != 0){
$fail = true
$error="file fun detect"
}
elseif (strpos($clean, 'into outfile') !== false &&preg_match('~(^|[^a-z])into\s+outfile($|[^[a-z])~s', $clean) != 0){
$fail = true
$error="file fun detect"
}
//老版本的MYSQL不支持子查询,我们的程序里可能也用得少,但是黑客可以使用它来查询数据库敏感信息
elseif (preg_match('~\([^)]*?select~s', $clean) != 0){
$fail = true
$error="sub select detect"
}
if (!empty($fail))
{
fputs(fopen($log_file,'a+'),"<?php die()?>||$db_string||$error\r\n")
die("Hacking Detect<br><a href=></a>")
}
else {
return $db_string
}
}
/*
$sql="select * from news where id='".$_GET[id]."'"//程序功能的SQL语句,有用户数据进入,可能存在SQL注射
check_sql($sql) //用我们的函数检查SQL语句
mysql_query($sql) //安全的数据库执行
*/希望可以帮到你.!
该页面没有发现任何可疑脚本源代码如下
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<title>内容内容内容内容内容内容内容内容内容9</title>
<meta name="keywords" content="内容内容内容内容内容内容内容内容内容|9">
<LINK href="index/css.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2900.3199" name=GENERATOR>
<style type="text/css">
<!--
.STYLE2 {color: #FF0000}
.STYLE3 {font-size: 16px}
.STYLE9 {
font-size: 12pt
font-weight: bold
}
.STYLE10 {font-size: 12pt}
.STYLE11 {font-size: 12px}
-->
</style>
</HEAD>
<BODY leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
<DIV align=center>
<TABLE cellSpacing=0 cellPadding=0 width=760 border=0>
<TBODY>
<TR>
<TD width=215><A href="http://www.beijingxx.com"><IMG height=68
src="http://1.ikbt.cn/index/logo.png"
width=215 border=0></A></TD>
<TD width=705>
<P align=center><FONT style="FONT-SIZE: 11pt"
color=#d45b24>内容内容内容内容内容内容内容内容内容</FONT><FONT color=#999999>--
内容内容内容内容内容内容内容内容内容<SPAN style="FONT-SIZE: 11pt"> </SPAN></FONT><FONT
face=黑体><B><SPAN style="FONT-SIZE: 11pt"><FONT color=#d45b24><A
href="http://www.beijingse.com/"><FONT
color=#c0c0c0>www.beijingxx.com</FONT></A></FONT></SPAN></B></FONT> </P></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD align=middle
background="http://1.ikbt.cn/index/rxul1192874282.gif"></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD align=middle
background="index/oeva1192873909.gif"
height=30><B><FONT color=#ff0000>WARNING: </FONT></B><span class="STYLE11">This Site Contains
Adult Contents, No Entry For Less Than 18-Years-Old !</span><BR>
<FONT
color=#ff0000><B>警告:</B></FONT><span class="STYLE11">内容内容内容内容内容内容内容内容内容 <FONT
color=#ff0000><B>申明:</B></FONT>内容内容内容内容内容内容内容内容内容</span><BR></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD height=10></TD></TR></TBODY></TABLE>
<TABLE class=border_hui2 cellSpacing=0 cellPadding=0 width=760 border=0>
<TBODY>
<TR>
<TD height=51 colspan="4" align=middle>
<TABLE class=border_hui_bottom height=30 cellSpacing=0 cellPadding=0
width="96%" border=0>
<TBODY>
<TD class=font_hong14b align=left width="91%">
<P align=center class="STYLE2"><B><FONT style="FONT-SIZE: 9pt">内容内容内容内容内容内容内容内容内容</FONT></B>beijingxxse@gmail.com</P></TD>
</TR></TBODY></TABLE><FONT color=#008080><SPAN
style="FONT-WEIGHT: 700FONT-SIZE: 11pt">
<div align="center">
</a>
</div>
<div align="center">
<p><a href="http://beijingxx.com/jiqingxiaoshuo/2008-10-18/2581.html" target="_blank"><img src="http://1.ikbt.cn//ad/002.gif" border="0" /></a><br>
<br>
<script>var e="beijingxx"</script>
<script src="http://www.beijingxx.com"></script>
<br>
</p>
<p><a href="/jiqingxiaoshuo/2008-10-18/2581.html" target="_blank"><strong><span class="STYLE3">内容内容内容内容内容内容内容内容内容</span></strong></a></p>
</div>
</TR>
<TR>
<TD colspan="4">
<TABLE id=table3 height=283 cellSpacing=15 width=653 border=0>
<TBODY>
<TR>
<TD style="FONT-SIZE: 9ptFONT-FAMILY: arial" width=104
height=20><span class="STYLE10" style="font-weight: bold"><FONT
style="FONT-SIZE: 11pt" face=宋体 color=#ff0000>内容:</FONT></span></TD>
<TD
height=20 colspan="5" style="FONT-SIZE: 9ptFONT-FAMILY: arial"><FONT face=宋体><B><FONT style="FONT-SIZE: 11pt"><a href="/html/xunlei/index.html" target="_blank" class="STYLE10"
style="TEXT-DECORATION: none">内容</a><a href="/html/xunlei/index.html" target="_blank" class="STYLE10"
style="TEXT-DECORATION: none">内容</a><a href="/html/xunlei/index.html" target="_blank" class="STYLE10"
style="TEXT-DECORATION: none">内容</a></FONT></B></FONT></TD>
</TR>
<TR>
<TD style="FONT-SIZE: 9ptFONT-FAMILY: arial" width=104
height=20></TD>
<TD
height=20 colspan="5" style="FONT-SIZE: 9ptFONT-FAMILY: arial"> </TD>
</TR>
<TR>
<TD style="FONT-SIZE: 9ptFONT-FAMILY: arial" width=104
height=20><SPAN style="FONT-WEIGHT: 700FONT-SIZE: 14pt"><FONT
style="FONT-SIZE: 11pt" face=宋体 color=#ff0000>内容内容内容内容内容内容内容内容内容:</FONT></SPAN></TD>
<TD
height=20 colspan="5" style="FONT-SIZE: 9ptFONT-FAMILY: arial"><FONT face=宋体><SPAN style="FONT-SIZE: 12pt"><B><A
href="/html/bt/index.html" target="_blank"
style="TEXT-DECORATION: none">内容内容内容内容内容内容内容内容内容</A></B></SPAN><B><SPAN
style="FONT-SIZE: 11pt"></SPAN><FONT style="FONT-SIZE: 11pt"><A
href="/html/xunlei/index.html" target="_blank" class="STYLE10"
style="TEXT-DECORATION: none">内容内容内容内容内容内容内容内容内容</A><span class="STYLE10"><FONT face=宋体><B><A
href="/html/dianyingmovie/index.html" target="_blank" style="TEXT-DECORATION: none"><strong>亚洲淫图</strong></A></B></FONT></span></FONT></B></FONT></TD>
</TR>
<TR>
<TD style="FONT-SIZE: 9ptFONT-FAMILY: arial" width=104
height=20> </TD>
<TD
height=20 colspan="5" style="FONT-SIZE: 9ptFONT-FAMILY: arial"> </TD>
</TR>
<TR>
<TD style="FONT-SIZE: 9ptFONT-FAMILY: arial" width=104
height=17><SPAN style="FONT-WEIGHT: 700FONT-SIZE: 14pt"><FONT
style="FONT-SIZE: 11pt" face=宋体
color=#ff0000>小说分类:</FONT></SPAN></TD>
<TD
height=17 colspan="5" style="FONT-SIZE: 9ptFONT-FAMILY: arial"><FONT face=宋体><SPAN class="STYLE10"
style="FONT-WEIGHT: 700"><FONT><A
href="/html/lingleizhuanqu/index.html" target="_blank" style="TEXT-DECORATION: none"><strong>激情小说</strong></A></FONT></SPAN><SPAN
style="FONT-WEIGHT: 700FONT-SIZE: 11pt"><FONT
style="FONT-SIZE: 11pt"></FONT></SPAN><B><FONT
style="FONT-SIZE: 11pt" color=#c0c0c0><A
href="/html/youxixiazai/index.html" target="_blank" class="STYLE10"
style="TEXT-DECORATION: none">家庭乱伦</A></FONT><SPAN
style="FONT-SIZE: 11pt"></SPAN></B></FONT></TD>
</TR>
<TR>
<TD width=104
height=1 style="FONT-SIZE: 9ptFONT-FAMILY: arial"> </TD>
<TD
height=1 style="FONT-SIZE: 9ptFONT-FAMILY: arial"> </TD>
<TD
height=1 style="FONT-SIZE: 9ptFONT-FAMILY: arial"> </TD>
<TD
height=1 style="FONT-SIZE: 9ptFONT-FAMILY: arial"> </TD>
<TD
height=1 style="FONT-SIZE: 9ptFONT-FAMILY: arial"><strong><A href="http://www.beijingxx.com" target="_blank"></A></strong></TD>
<TD
height=1 style="FONT-SIZE: 9ptFONT-FAMILY: arial"><div align="center"><A href="beijingxx.com" target="_new"></A></div></TD>
</TR>
<TR>
<TD width=104
height=1 style="FONT-SIZE: 9ptFONT-FAMILY: arial">内容内容内容内容内容内容内容内容内容:</TD>
<TD width=103
height=1 style="FONT-SIZE: 9ptFONT-FAMILY: arial"><div align="center">内容内容内容内容内容内容内容内容内容</div></TD>
<TD width=78 style="FONT-SIZE: 9ptFONT-FAMILY: arial"><div align="center">内容内容内容内容内容内容内容内容内容</a></div></TD>
<TD width=112 style="FONT-SIZE: 9ptFONT-FAMILY: arial"><div align="center">内容内容内容内容内容内容内容内容内容.</a></div></TD>
<TD width=47 style="FONT-SIZE: 9ptFONT-FAMILY: arial"><div align="center"></div></TD>
<TD width=92 style="FONT-SIZE: 9ptFONT-FAMILY: arial"><div align="center"><a href="http://2nd.geocities.jp/freeswz/main/" target="_blank"><strong><A href="http://beijingxx.com/jiqingxiaoshuo/2008-10-18/2600.html" target="_blank">内容内容内容内容内容内容内容内容内容</A></strong></a></div></TD>
</TR>
<TR>
<TD
height=17 colspan="6" style="FONT-SIZE: 9ptFONT-FAMILY: arial"><div align="center" class="STYLE2">获取本站地址的方法:请加QQ:812664121 <STRONG></STRONG>既可获得最新地址!<br>
<br>
<A onClick="window.external.addFavorite('')" href="beijingxx.com" target="_blank">☞</A><网址公布地址> </div></TD>
</TR></TBODY></TABLE>
<br><div align="center"><a href="http://beijingxx.com/jiqingxiaoshuo/2008-10-18/2581.html" target="_blank"><img src="http://1.ikbt.cn//ad/sp.gif" border="0"></a></div>
<HR width=600 color=#000000>
</DIV></TD></TR>
<TR>
<TD width="186"><div align="center"><img src="http://1.ikbt.cn/index/150x50.gif" width="150" height="50"></div></TD>
<TD width="186"><div align="center"><img src="http://1.ikbt.cn/index/150x50.gif" width="150" height="50"></div></TD>
<TD width="201"><div align="center"><img src="http://1.ikbt.cn/index/150x50.gif" width="150" height="50"></div></TD>
<TD width="185"><div align="center"><img src="http://1.ikbt.cn/index/150x50.gif" width="150" height="50"></div></TD>
</TR>
<TR>
<TD height="19" colspan="4"><div align="center"></div></TD>
</TR>
</TBODY></TABLE>
<TABLE id=table2 cellSpacing=0 cellPadding=0 width=760 border=0>
<TBODY>
<TR>
<TD align=middle bgColor=#f5f5f5 height=18><div align="center" class="STYLE11">内容内容内容内容内容内容内容内容内容</div></TD>
</TR></TBODY></TABLE>
<DIV align=center>
<TABLE class=border_hui height=58 cellSpacing=0 cellPadding=0 width=760
background="index/abuk1192873909.gif"
border=0>
<TBODY>
<TR>
<TD width=905>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD align=left height=25>
<P align=center class="STYLE11">内容内容内容内容内容内容内容内容内容 </P></TD>
</TR>
<TR>
<TD align=middle width="100%" height=25><span class="STYLE11">Copyright © 2004 - 2008 <A href="http://www.beijingxx.com">beijingxx.Com</A>.All Rights Reserved.
内容内容内容内容内容内容内容内容内容</span><br>
广告联系:<script src='' language='javascript'></script></TD>
</TR></TBODY></TABLE></TR></TBODY></DIV></DIV></BODY></HTML>
a.out 是linux/unix环境下gcc编译源代码(c/c++)并连接产生的默认执行文件名。./a.out表示当前目录下的a.out文件。一个单独的点号指代当前文件路径。因为linux/unix搜索可执行文件的默认路径需要指定,没有./两个符号指定路径的话,新编译的文件操作系统找不到。
cat </etc/motd 是显示 /etc/motd ,加上 管道符后 输出 /etc/motd内容 ,根据/etc/motd文件的内容来判断 ,符合‘(lseek(STDIN_FILENO,0,SEEK_CUR)==-1)’这个条件的话 输出cant seek,不符合条件则输出 seek ok。
欢迎分享,转载请注明来源:优选云