473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Tracking down a hacker (my site has been compromised)

Tarantulus
114 100+
Hi guys,

I've been hacked. my homepage has had [HTML]<script>[/HTML] tage inserted into it pointing to a russian site with a trojan...

only problem is I don't know how, and don't know where to start looking.

the page in question is static HTML, no PHP at all, but I'm assuming the attack vector is somewhere in the PHP or SQL, am I barking up the wrong tree?

any pointers will be muchly appreciated as I'm completely lost.

Thanks in advance
Aug 21 '08 #1
4 1711
FLEB
30
- Is the server space managed by someone else? Is it a shared host? If it's a shared host or a server managed by someone else, the attacker may have come in by exploiting some software or services on the server that you have no control over. If it's a shared host, they might have gotten in through someone else's insecure script, and been able to get at your files through inadequate user separation.

- Is that HTML directory set to be world-writable? If so, you may want to look at any scripts that have the ability to write to the server.

As for tracking down the attacker, you might have a look at your access and error logs. IIRC, there are tools you can use to scan and analyze your logs, although I don't know them offhand. Also, if you're running on managed space, talk to the people who run the servers-- they might have more access and insight into what happened.
Aug 21 '08 #2
pbmods
5,821 Expert 4TB
Heya, Tarantulus.

If a file has been overwritten, you might have suffered from a file path injection attack.

Quick example:
Expand|Select|Wrap|Line Numbers
  1. move_uploaded_file($_FILES['upload']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/uploads/' . $_FILES['upload']['name']);
  2.  
If the value of $_FILES['upload']['name'] is "../index.html" for example, your file might get overwritten.

To protect against file path injection, use realpath() (http://php.net/realpath) and do a strpos() against a known good directory.

Also, any script that include()'s or eval()'s User input can be compromised.

For example (and a very crude one, but bear with me):
Expand|Select|Wrap|Line Numbers
  1. include $_GET['script_name'] . '.php';
  2.  
If the value of $_GET['script_name'] is 'http://some-evil-domain.com/evil/script', then you'd be lucky if all that happened was your static index got rewritten!

To protect yourself against PHP code injection, you should get in the following habits:
  • Never ever ever trust input, no matter where it comes from. If it's supposed to be an int, cast it (http://php.net/manual/en/language.ty...e-juggling.php). If it's supposed to be a string, run it through a switch or in_array() to ensure that only "safe" values make it through.
  • Don't trust data from your database, either. If an attacker manages to inject any malicious code into your database, you have to be able to detect it. If you can, trigger some kind of alert when you encounter an attack that originates from database data, as you will have a much easier time tracing an attack if you know what script probably put it there.
  • Always escape output. If it's going to the database, run it through mysql_real_escape_string() (http://php.net/mysql_real_escape_string). If it's going to be sent to the browser, use htmlentities() (http://php.net/htmlentities).
  • Never send ID numbers to the browser. The User's ID might be e.g., 428, but you should never send the browser to profile.php?user=428. Use his (unique) username instead and send the browser to profile.php?user=mickeyc. Best Buy got in trouble for this.

I bring up that last point because a crafty hacker might not be able to crack your login page, but if you rely on a User ID coming from the browser somewhere, then he might be able to use that to execute a script as, say, an Admin User.
Aug 22 '08 #3
JackRbt
22
Hi. The attack on your machine probably came from somebody else's hacked zombie machine.
Aug 22 '08 #4
Tarantulus
114 100+
Thanks for the detailed responses.
I'm not doing any file manipulation in my scripts, and for all of my SQL input I'm
Expand|Select|Wrap|Line Numbers
  1. using mysql_real_escape_string()
so I'm assuming from what you've all said that the attack vector is out of my control (it's a shared host).

thanks a lot
Aug 22 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Paul C | last post by:
I have a font size being applied to an element, however I have been unable to track where it is coming from. Is there an app that will tell you the complete style sheet property of an element...
4
by: Ben Amada | last post by:
Hello! There are a couple of visitors (out of dozens) to this web page who are causing the following error to occur: "Object reference not set to an instance of an object." I'm actually...
16
by: Ben | last post by:
I'm doing a bunch of data mining against a postgres database and have run into an interesting problem with deadlocks. The problem is, postgres is detecting them and then wacking the offending...
7
by: Alan Pretre | last post by:
I have an application installed at a customer site that has been getting a general network error for a couple of years. I was hoping that .NET 2.0 would clear it up, but unfortunately it didn't. ...
6
by: depkefamily | last post by:
I have a large C++ program using multiple vendors DLLs which is giving me a major headache. Under release mode I get exceptions thrown from what looks like a dereferenced corrupt pointer. The...
6
by: DFS | last post by:
One of my systems grew exponentially - from 13mb to 43mb - after adding some 10 temp tables (with no data), a new form, and about a thousand lines of code. The .mdb has mostly table links, lots of...
0
by: preport | last post by:
All of the sudden I'm getting an error for a webservice on my dev machine. I'm getting a 404: The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its...
16
by: tagg3rx | last post by:
Hi All, I recently implemented a global error catcher in my application that sends me an e-mail every time an error happens. One error I'm seeing regularly that I can't track down appears to have...
11
by: Jeigh | last post by:
Quite a while back now I had a file uploaded to my site overwriting the index, which boasted of this hackers amazing skills in defacing my site. Never did figure out how they did it, however I found...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.