<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[gOxiA=苏繁=SuFan Blog]]></title> 
<link>https://sufan.maytide.net/index.php</link> 
<description><![CDATA[gOxiA,苏繁,sufan,Microsoft MVP]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[gOxiA=苏繁=SuFan Blog]]></copyright>
<item>
<link>https://sufan.maytide.net/read.php/776.htm</link>
<title><![CDATA[防范SQL注入式攻击 ]]></title> 
<author>gOxiA &lt;sufan_cn@msn.com&gt;</author>
<category><![CDATA[SQL Server]]></category>
<pubDate>Wed, 08 Sep 2004 08:26:43 +0000</pubDate> 
<guid>https://sufan.maytide.net/read.php/776.htm</guid> 
<description>
<![CDATA[ 
	SQL注入式攻击是利用是指利用设计上的漏洞，在目标服务器上运行Sql命令以及进行其他方式的攻击<br/>动态生成Sql命令时没有对用户输入的数据进行验证是Sql注入攻击得逞的主要原因。<br/>比如：<br/> 如果你的查询语句是select * from admin where username='\&quot;&amp;user&amp;\&quot;' and password='\&quot;&amp;pwd&amp;\&quot;'\&quot;<br/><br/> 那么，如果我的用户名是：1' or '1'='1<br/> 那么，你的查询语句将会变成：<br/> select * from admin where username='1 or '1'='1' and password='\&quot;&amp;pwd&amp;\&quot;'\&quot;<br/> 这样你的查询语句就通过了，从而就可以进入你的管理界面。<br/><br/>所以防范的时候需要对用户的输入进行检查。特别式一些特殊字符，比如单引号，双引号，分号，逗号，冒号，连接号等进行转换或者过滤。<br/><br/>需要过滤的特殊字符及字符串有：<br/>　　<div class="code">net user<br/>　　 xp_cmdshell<br/>　　 /add<br/>　　 exec master.dbo.xp_cmdshell<br/>　　 net localgroup administrators<br/>　　 select<br/>　　 count<br/>　　 Asc<br/>　　 char<br/>　　 mid<br/>　　 '<br/>　　 :<br/>　　 \&quot;<br/>　　 insert<br/>　　 delete from<br/>　　 drop table<br/>　　 update<br/>　　 truncate<br/>　　 from<br/>　　 %</div><br/><br/>下面是我写的两种关于解决注入式攻击的防范代码，供大家学习参考！<br/>js版的防范SQL注入式攻击代码～：<br/><br/><div class="code">&lt;script language=\&quot;j avascript\&quot;&gt;<br/>&lt;!--<br/> var url = location.search;<br/> var re=/^\?(.*)(select%20|insert%20|delete%20from%20|count\(|drop%20table|update%20truncate%20|asc\(|mid\(|char\(|xp_cmdshell|exec%20master|net%20localgroup%20administrators|\&quot;|:|net%20user|\'|%20or%20)(.*)$/gi;<br/> var e = re.test(url);<br/> if(e) &#123;<br/> &nbsp;alert(\&quot;地址中含有非法字符～\&quot;);<br/> &nbsp;location.href=\&quot;error.asp\&quot;;<br/> &#125;<br/>//--&gt;<br/>&lt;script&gt;</div><br/><br/><br/>asp版的防范SQL注入式攻击代码～：<br/><div class="code">&lt;%<br/>On Error Resume Next<br/>Dim strTemp<br/><br/>If LCase(Request.ServerVariables(\&quot;HTTPS\&quot;)) = \&quot;off\&quot; Then<br/> strTemp = \&quot;http://\&quot;<br/>Else<br/> strTemp = \&quot;https://\&quot;<br/>End If<br/><br/>strTemp = strTemp &amp; Request.ServerVariables(\&quot;SERVER_NAME\&quot;)<br/>If Request.ServerVariables(\&quot;SERVER_PORT\&quot;) &lt;&gt; 80 Then strTemp = strTemp &amp; \&quot;:\&quot; &amp; Request.ServerVariables(\&quot;SERVER_PORT\&quot;)<br/><br/>strTemp = strTemp &amp; Request.ServerVariables(\&quot;URL\&quot;)<br/><br/>If Trim(Request.QueryString) &lt;&gt; \&quot;\&quot; Then strTemp = strTemp &amp; \&quot;?\&quot; &amp; Trim(Request.QueryString)<br/><br/>strTemp = LCase(strTemp)<br/><br/>If Instr(strTemp,\&quot;select%20\&quot;) or Instr(strTemp,\&quot;insert%20\&quot;) or Instr(strTemp,\&quot;delete%20from\&quot;) or Instr(strTemp,\&quot;count(\&quot;) or Instr(strTemp,\&quot;drop%20table\&quot;) or Instr(strTemp,\&quot;update%20\&quot;) or Instr(strTemp,\&quot;truncate%20\&quot;) or Instr(strTemp,\&quot;asc(\&quot;) or Instr(strTemp,\&quot;mid(\&quot;) or Instr(strTemp,\&quot;char(\&quot;) or Instr(strTemp,\&quot;xp_cmdshell\&quot;) or Instr(strTemp,\&quot;exec%20master\&quot;) or Instr(strTemp,\&quot;net%20localgroup%20administrators\&quot;) &nbsp;or Instr(strTemp,\&quot;:\&quot;) or Instr(strTemp,\&quot;net%20user\&quot;) or Instr(strTemp,\&quot;'\&quot;) or Instr(strTemp,\&quot;%20or%20\&quot;) then<br/> Response.Write \&quot;&lt;script language='j avascript'&gt;\&quot;<br/> Response.Write \&quot;alert('非法地址！！');\&quot;<br/> Response.Write \&quot;location.href='error.asp';\&quot;<br/> Response.Write \&quot;&lt;script&gt;\&quot;<br/>End If<br/>%&gt;</div>
]]>
</description>
</item>
</channel>
</rss>