HITCON 2017 babyfirst-revenge-v2(命令执行绕过五)

本文详细解析了一道PHP CTF挑战题目,介绍了如何利用特殊命令和文件名排序技巧完成任务。通过构造特定的命令序列,实现了文件内容的精确写入,并最终获取shell权限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目地址:https://github.com/otakekumi/CTF-Challenge/blob/master/PHP/chall_2/index.php

发现和上一题大体相似,但是发现有一个不一样,长度从5变成了4,没办法利用>>二次写入了。

但是我们如果就这样是没法儿按照字典序直接写入ls -t>g到文件的。 因为这一串无论怎么分割写入都无法遵从字典序或是字典序的逆序。

然后就不会了,想了n久还是不会,最后只有去看wp了。

首先介绍几个命令:

dir:虽然基本上和 ls 一样,但有两个好处,一是开头字母是d ,这使得它在 alphabetical 序中靠前,二是按列输出,不换行。

* :相当于$(dir *),所以说如果文件名如果是命令的话就会返回执行的结果,之后的作为参数传入.

rev:可以反转文件每一行的内容。

所以这样如果dir在最前面的话,就可以把当前目录的文件都返回.

>dir
>sl
>g\>
>ht-

之后将*的结果写入文件中,紧接着写入rev文件.

>*>v
>rev


最后执行rev v>u,这个命令需要通过*命令的其它形式实现.

*v>u
这个命令就是$(dir *v)>u,dir *v返回的就是结尾为v的文件.


这个地方其实是一个很巧妙的方式,因为*v恰好是可以匹配到revv的,如果文件名换成其它字母会因为排序错误或者没有作为rev的参数而逆序失败.
之后的步骤就没有什么多大的区别了.

基本上就前面的写文件操作不一样。

exp执行,getshell!

参考链接:https://xz.aliyun.com/t/1579

### 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) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值