C99 is a PHP webshell. Attackers uploads it on web server in order to get information and above all execute commands with web user privileges (ex: www-data).
This webshell is protected by a customizable password, so interface access is limited to people who know the password.
But the password verification mechanism is vulnerable ... in fact the flaw was deliberately inserted into the code to permit the webshell author to bypass it.
Username and password are hardcoded to be easily editable.
Next, login and password are checked by the following code:
if (($_SERVER["PHP_AUTH_USER"] != $login) or (md5($_SERVER["PHP_AUTH_PW"]) != $md5_pass))
If login and password are not correct, an error page indicate that access is forbidden.
But checking is processed only if login is not empty:
$login is normally initialized staticly at the begining but after that the variable can be modified by
extract() function :
PHP documentation say :
(PHP 4, PHP 5, PHP 7)
extract — Import variables into the current symbol table from an array Description Import variables from an array into the current symbol table.
Checks each key to see whether it has a valid variable name. It also checks for collisions with existing variables in the symbol table.
int extract ( array &$array [, int $flags = EXTR_OVERWRITE [, string $prefix = NULL ]] )
extract() is mostly used to initialize variables from an array.
blue, medium, sphere
So for each line of the array, the key becomes the variable name and the value is given to the variable.
This function is dangerous because of it default behaviour : if a key of the extracted array match with an existant variable, the variable value will be replaced by the value of the array given in paramteter to extract().
To develop a secure software, never use extract() with unknown data or user's data (ex: prompt).
There are flags (ex: EXTR_SKIP) to protect already existing variable.
Bypass authentification is very simple : overwrite
It's possible because of:
Why a backdoor?
Pirates infect websites with webshells, but because this webshell is backdoored other pirates (authors of the webshell) will be able to control the server too.
extract() function and
c999shcook array are useless for the webshell but allow to overwrite any variables in the PHP script.
There is another flaw
There is a lot of c99.php variant: c99, c999, c99shell, c99unlimited, ... so some differences may occure.
There is multiple version of each variant and each variant can be declined in multiple forms: php, txt, jpg, ...
The simplest versions of c99 include a clear script:
Others like c99-bd try to poorly obfuscate it:
But a simple HTML decoder will decode
Others like c100, r57, c999 or updated c99 version have more sophisticated method like packing the script:
and unpack code can be a lot more complex than only base64_decode it or hex_to_ascii it.
The goal is always the same : each time the page is displayed, the website hosting the webshell will do a request to the malicious address and send the URL where it comes from, permiting to the malicious author to know all the website hosting the backdoored webshell.
The malicious script from
http://www.r57.gen.tr/yazciz/ciz.js looks like this:
Script kiddies, lamers, and inattentive pirates will use webshells without looking carefully at the code. The combo flaw + inventory of infected website is an easy way, for webshells' authors, to control a network of server (ex: creating a botnet) by letting to others the system corruption task.
More sophisticated piracy tools have some vulnerabilities too. Malwares like Smoke Loader (SQL injection), CrimePack (SQL injection) or Zeus (remote access via upload) have been corrupted.
When using tools, be carefull, backdoors may be hidden. Pay attention to images, scripts, css, external request, mail functions, encoded code, ...
Source: C99.php : Quand même les backdoors sont backdoorées by Hugo Ballesteros