没有合适的资源?快使用搜索试试~ 我知道了~
sql注入原理及php防注入代码.doc
1 下载量 180 浏览量
2022-12-02
22:23:49
上传
评论
收藏 279KB DOC 举报
温馨提示
试读
10页
sql注入原理及php防注入代码.doc
资源推荐
资源详情
资源评论
1、基本概念
○
1
php.ini 文件中的一个设置:magic_quotes_gpc。
此设置默认是关闭的,即 magic_quotes_gpc=off,一般将其设置为 on。为 on 时,
php 应用程序服务器将自动把用户提交的对 SQL 的查询进行转换,比如吧“’”转
化为“\’”,它的作用是在敏感字符前加一个反斜杠“\”,这对防止 SQL 注入有重大
作用。
○
2
函数 addslashes()
作用是在所有 外部数据敏感字符’(单引号)、\(反斜杠)、NUL 的前面加上反斜杠。
○
3
函数 intval()
作用是将数据类型转化为整型。
注意:在新版本 PHP 中,即使 magic_quotes_gpc 设成了 on,在使用 addslashes()
函数来处理时不会出现冲突的,可以大胆使用。
2、sql 漏洞注入原理
○
1
基础过滤和二次过滤
一般情况下,在获得用户提交的参数时,首先要进行一些基础性的过滤,然后再
根据程序的响应的功能以及用户输入进行二次过滤。在所有用户输入处对敏感字
符进行过滤,敏感字符如下:
"\", "&", " ", "'", "/", "*", ",", "<", ">", "", " ", "", "#", "$", "(", ")", "%", "@", "+",
"?", ";", "^","--","and","or","select","update"
在 javascript 中使用代码过滤敏感字符串:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>标题页</title>
<script LANGUAGE="JavaScript">
function check(inputStr) {
if (typeof(inputStr) != "string") { return inputStr; } //判断是否是字符串类型
var tmpValue = inputStr;
//以下搜索字符串中的特殊字符,如果存在,则替换成""
while (tmpValue.indexOf(';') > -1) {tmpValue = tmpValue.replace(';',''); }
while (tmpValue.indexOf('<') > -1) {tmpValue = tmpValue.replace('<',''); }
while (tmpValue.indexOf('>') > -1) {tmpValue = tmpValue.replace('>',''); }
while (tmpValue.indexOf('--') > -1) {tmpValue = tmpValue.replace('--',''); }
while (tmpValue.indexOf(",") > -1) {tmpValue = tmpValue.replace(",",""); }
while (tmpValue.indexOf("'") > -1) {tmpValue = tmpValue.replace("'",""); }
while (tmpValue.indexOf("?") > -1) {tmpValue = tmpValue.replace("?",""); }
document.getElementById("txt1").value = tmpValue; //重新显示更改后的变量
}
</script>
</head>
<body>
<input type=text id="txt1" value="select * from userinfo where username=zhang' and
passwrod=2" style="width: 392px">
<input type=button value="提交" onClick="check(txt1.value)">
</body>
资源评论
Mmnnnbb123
- 粉丝: 680
- 资源: 8万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功