[BMZCTF]-hitcon_2017_ssrfme

[BMZCTF]-hitcon_2017_ssrfme
在这里插入图片描述
依旧是直接给出题目源代码
这里列一下几个用到的函数吧

file_put_contents — 将一个字符串写入文件
pathinfo — 返回文件路径的信息
escapeshellarg — 把字符串转码为可以在 shell 命令里使用的参数
shell_exec — 通过 shell 环境执行命令,并且将完整的输出以字符串的方式返回。

这题代码简而言之就是会先生成一个文件夹,路径是orange+你的ip地址经过MD5加密后的密文,所以实际位置就是/sandbox/md5(orange+ip)

接下来就是get访问一个url,url可控
然后就是一个可控的filename,将会生成一个文件在/sandbox/md5(orange+ip),也就是说会有/sandbox/md5(orange+ip)/filename,最后会将url访问到的数据写在filename

总的来说,就是url记录你想查看的文件路径,filename确定一个文件名,你访问该文件可以看到url记录的文件路径的内容

那就开始操作吧
在这里插入图片描述
在这里插入图片描述

md5这里是32位小写
在这里插入图片描述
这里说我没有权限访问该路径,这让我一下子就有点懵了,我还以为cookie什么的有问题,或者是我做题思路错了,后来看了大佬们的wp才知道,这里没权限并不影响后续操作

在这里插入图片描述
在这里插入图片描述
这里看到一个/flag,访问看看
在这里插入图片描述

在这里插入图片描述
emem啥也没有,应该是这里没错的啊,后面转念一想,flag应该记录在文本文件才对

在这里插入图片描述
在这里插入图片描述
成功拿下

### HITCON 2017 SSRF Challenge Overview The **HITCON 2017 CTF** featured a variety of challenges, including those related to Server-Side Request Forgery (SSRF). These challenges were designed to test participants' understanding of web application vulnerabilities and their ability to exploit them effectively. One notable challenge was the **SSRFme task**, which involved exploiting an SSRF vulnerability within a PHP-based system. The provided code snippet demonstrates how the `$_SERVER['HTTP_X_FORWARDED_FOR']` variable is manipulated by splitting its value using commas as delimiters[^5]. This manipulation allows attackers to control the `$http_x_headers[0]` value, potentially leading to unauthorized access or command execution scenarios. In another instance, contestants had to leverage file-writing capabilities through GET requests combined with filename parameters[^4]. By carefully crafting filenames that included shell commands such as `/readflag`, they could execute arbitrary commands on the server side. Specifically: - A request like `/?url=/&filename=aaa` would create a new file named after the specified parameter. - Subsequent exploitation steps allowed reading sensitive files from restricted directories via crafted URLs incorporating malicious payloads into both query strings (`?`) and headers. Additionally, there exists documentation regarding similar exercises where users reconstruct past competitions’ problems locally for practice purposes—such efforts often involve setting up Docker containers mimicking original environments accurately so learners may gain hands-on experience without needing direct participation during actual events themselves[^1]. For further exploration beyond just theoretical knowledge about these types of attacks but also practical implementations thereof consider reviewing additional resources discussing advanced techniques surrounding path traversal exploits alongside other common injection vectors present throughout modern-day applications today too! ```python import os from flask import Flask, request app = Flask(__name__) @app.route('/') def index(): url = request.args.get('url', '') filename = request.args.get('filename', 'default.txt') try: response = open(url) # Vulnerable line due to lack of validation content = response.read() with open(f"/tmp/{filename}", "w") as f: f.write(content) return f"Content written successfully to {filename}" except Exception as e: return str(e), 400 if __name__ == '__main__': app.run(debug=True) ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值