[Cacti <= 0.8.6i] Remote Injection Exploit

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

User avatar
hbokh
Posts: 40
Joined: Thu Feb 24, 2005 4:29 pm
Location: Groningen, NL

[Cacti <= 0.8.6i] Remote Injection Exploit

Post by hbokh »

Cacti <= 0.8.6i cmd.php popen() Remote Injection Exploit

HEADS UP!

See http://www.milw0rm.com/exploits/3029 for the actual exploit...
Or am I stepping out of line here?
This is my sick nature...
amaret0
Posts: 1
Joined: Thu Dec 28, 2006 2:02 am

Post by amaret0 »

Sorry for the question, but...
Are there any fixes/patches for this "hot" bug?
Or any temporary solution?

Thanks in advance.

~A
Wunk
Posts: 37
Joined: Fri Mar 05, 2004 8:34 am
Contact:

Post by Wunk »

I second this, any quick fixes / patch ?


edit:

Quick fix: just make cmd.php unreadable by the user that the webserver runs as (nobody/apache/httpd), just make sure it's readable by the user that the poller runs as.
Jeroen Wunnink
Easyhosting.nl Sysadmin
User avatar
sizulku
Cacti User
Posts: 110
Joined: Mon Nov 04, 2002 9:15 am
Location: ACEH
Contact:

Post by sizulku »

Have you try this exploit? I'm using it on my cacti 0.8.6h but won't work so I'm safe :oops:
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Post by rony »

You only have to worry if you have "register_globals" enabled in php.

If you are worried about this issue, and you should be, if your Cacti installation is exposed to the internet, I would suggest that you limit access to Cacti and make sure that "register_globals" is off.
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
User avatar
egarnel
Cacti Pro User
Posts: 708
Joined: Thu Nov 21, 2002 8:55 am
Location: Austin, TX

Post by egarnel »

It appears that register_globals is off by default in CactiEZ v1.0 and the beta.

Locking down access to your monitoring servers is good practice as well.
Cacti1 OS: CentOS 5.6 | 300+ devices
Cacti2 OS: CentOS 5.6 | 300+ devices
King of the Elves
Local Anarchists Union #427
"Anarchism is founded on the observation that since few men are wise enough to rule themselves, even fewer are wise enough to rule others." -Edward Abbey
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Post by rony »

Issue reported into the bug datatbase.

Link for those who would like to track.
http://bugs.cacti.net/view.php?id=883
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
cigamit
Developer
Posts: 3367
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Post by cigamit »

Even with register globals off, I seem to be able to exploit it.

I can stop it from proceeding if I change

Code: Select all

/* do NOT run this script through a web browser */
if (!isset($_SERVER["argv"][0])) {
	die("<br><strong>This script is only meant to run at the command line.</strong>");
}
to this

Code: Select all

/* do NOT run this script through a web browser */
if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD'])  || isset($_SERVER['REMOTE_ADDR'])) {
	die("<br><strong>This script is only meant to run at the command line.</strong>");
}
This works great on Apache, but I am unsure of how it will work on IIS (I don't have an IIS server to test on).
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Post by rony »

You can get past the die, yes, but can you inject the command into the table?
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
rgod
Posts: 2
Joined: Thu Dec 28, 2006 4:04 am

Post by rgod »

the exploit condition is register_argc_argv = on, not register_globals = on, like you wrote in mantis.
Request method check works fine

ah, I see the wrong check in various scripts, so... other attack maybe possible, so if you have that directive on, grep for that.

This .htaccess line should work temporarily, it worked for me:

php_value register_argc_argv off
tsnww
Posts: 17
Joined: Wed Mar 15, 2006 8:59 am

Actual description of issue **not exploit code**

Post by tsnww »

Cacti "cmd.php" Command Execution and SQL Injection Advisory Available in Danish Advisory Available in German

Secunia Advisory: SA23528
Release Date: 2006-12-28

Critical:
Highly critical
Impact: Security Bypass
Manipulation of data
System access
Where: From remote
Solution Status: Unpatched

Software: Cacti 0.x




Description:
rgod has discovered three vulnerabilities in Cacti, which can be exploited by malicious people to bypass certain security restrictions, manipulate data and compromise vulnerable systems.

1) The cmd.php script does not properly restrict access to command line usage and is installed in a web-accessible location.

Successful exploitation requires that "register_argc_argv" is enabled.

2) Input passed in the URL to cmd.php is not properly sanitised before being used in SQL queries. This can be exploited to manipulate SQL queries by injecting arbitrary SQL code.

Successful exploitation requires that "register_argc_argv" is enabled.

3) The results from the SQL queries in 2) in cmd.php are not properly sanitised before being used as shell commands. This can be exploited to inject arbitrary shell commands.

The vulnerabilities are confirmed in version 0.8.6i. Other versions may also be affected.

Solution:
Move the "cmd.php" script to a not web-accessible path, and update other scripts accordingly.

Edit the source code to ensure that input is properly sanitised.

Provided and/or discovered by:
rgod
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Post by rony »

Sorry home sick today. Guess I didn't review the exploit that well.

Bug updated.
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
cigamit
Developer
Posts: 3367
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Post by cigamit »

Just to note, on both my testing systems and my remote production box, disabling register_argc_argv causes Cacti to stop polling.
cigamit
Developer
Posts: 3367
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Post by cigamit »

Well, the effective way to stop the exploit is to properly check the passed arguments before inserting. They should be numbers, so lets just check them and exit if they aren't what we want.

Find this block of code

Code: Select all

}else{
	$print_data_to_stdout = false;
	if ($_SERVER["argc"] == "3") {
		if ($_SERVER["argv"][1] <= $_SERVER["argv"][2]) {
and add this code directly afterwards.

Code: Select all

			$_SERVER["argv"][1] = input_validate_input_number($_SERVER["argv"][1]);
			$_SERVER["argv"][2] = input_validate_input_number($_SERVER["argv"][2]);
tsnww
Posts: 17
Joined: Wed Mar 15, 2006 8:59 am

Post by tsnww »

^ I've added your code into cmd.php on my box... I haven't tried the exploit against it but watching to make sure all is well w/ the server for now ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests