TinyPortal

Development => Support => Topic started by: dimdom on March 04, 2008, 01:45:22 PM

Title: Security issue (i think)
Post by: dimdom on March 04, 2008, 01:45:22 PM
From time to time, my error log fills up with errors like the one below:


http://www.testtest.com/RSD/index.php?amp;;tpstart=http://sahel55.com/articles/omaduro/kimumid/
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'http://sahel55.com/articles/omaduro/kimumid/, 8' at line 7
File: /home/testest/public_html/RSD/Sources/TPortal.php


with different "strange" addresses like "http://www.pattibus.it/phplib-7.2b/pages/ilosi/dohigal/" and other exotic ones.

All errors pointing mainly at Sources/TPortal.php, with other few pointing at other TP php files....

After that, a bot is managing to register to my site, even though I have captcha enabled and age verification enabled... They can register but they cant post since they cant activate their accounts through email....

Any ideas?
Title: Re: Security issue (i think)
Post by: IchBin on March 04, 2008, 02:53:51 PM
Its an exploit "attempt". Its not a security hole because their is not breach as SMF cleans URL's as SHOULD your host through the PHP settings. Bots are capable of registering no matter what. What makes you think its a bot and not a real person?
Title: Re: Security issue (i think)
Post by: dimdom on March 04, 2008, 04:49:58 PM
IchBin, thanx for your quick reply.

If I get it right there must be something that I can do to prevent these exploit attempts, telling about the problem to my hosting company for example?

With names like "Viagragirl" and 123berussitnco" what else can it be than bots? And all these, just stack on the age verification, cause they all need aproval through their profiles...
Title: Re: Security issue (i think)
Post by: IchBin on March 04, 2008, 06:28:08 PM
Don't forget that people get paid to spam. There are people out there that are paid to spam the net by going around and registering to sites and spamming their links and pictures etc. Viagragirl could just as easily be a real human and not a bot.

You can't keep people from trying to exploit servers. In a lot of cases, these are automated attempts made by a machine that is infected with a virus or trojan.

When I setup my first linux server I freaked out when I looked at the access logs for SSH. There were literally hundreds of brute force attacks on SSH within just a few days. I would grep the logs and filter out the IP and drop them at the firewall. After a couple of weeks it dawned on me that these weren't real people all the time, as the hack attempts were driven by a script with the attempts being less than seconds apart. Not much you can do, other than being an active admin to police your site. Just make sure your scripts are up to date, and that you don't leave any lose ends around. I know quite a few people that have been hacked by scripts that they forget they even have. :(
Title: Re: Security issue (i think)
Post by: dimdom on March 04, 2008, 06:33:30 PM
QuoteNot much you can do, other than being an active admin to police your site.

I do that all the time. :o

Thank you, once more. :)
Title: Re: Security issue (i think)
Post by: ShadowMaster on March 07, 2008, 02:53:20 PM
Running a site which attracts a fair amount of traffic and running TPortal, my error logs where flooded with entries just like this.

While these attempts pose little danger, i wasn't too happy about TP blindly using the URL input without any form of verification before running the SQL query.

A simple fix which eliminates these errors from showing up is verifying that the input is numeric.

In Sources/TPortal.php i did the following around line 1725

Old:


// Show the latest news, with a template... by board. Modified from SSI.php
function TP_boardNews($board, $limit = null, $start = null, $length = null)
{
        global $scripturl, $db_prefix, $txt;
        global $settings, $modSettings, $context, $user_info;

        loadLanguage('Stats');



new:

// Show the latest news, with a template... by board. Modified from SSI.php
function TP_boardNews($board, $limit = null, $start = null, $length = null)
{
        global $scripturl, $db_prefix, $txt;
        global $settings, $modSettings, $context, $user_info;

        if (!is_numeric($limit) || !is_numeric($start) || !is_numeric($length))
        {
                die('Hacking attempt...');
        }

        loadLanguage('Stats');


Granted you could take it further and do more than just display an error like email notifications, error logging, automatic banning etc.
Title: Re: Security issue (i think)
Post by: dimdom on March 09, 2008, 12:04:44 PM
ShadowMaster, thanks for your tip.

I did that and till now, havent seen any new garbage in my error log. :)
Title: Re: Security issue (i think)
Post by: Elrond on March 09, 2008, 01:07:07 PM
SMF's source file called QueryString.php does do a lot of cleaning of the $_POST, $_REQUEST, $_GET, $_FILE and other submission methods to prevent entry of single quotes and slash methods as well as most other methods with htmlspecialchars to clean out any html (including javascript) and addslashes, preventing anything from template parsing errors to major database issues. mysql_real_escape_string should be used in many cases though, as that cleans out non-standard hex-type entires that replace a single quote with a character entity equivalent to a single or double quote.

If anyone ends up having any problems with that, mysql_real_escape_string will be needed (it's very unusual to find someone hacking to the point that SMF's addslashes_recursive function as well as other recursive functions don't work; in fact I've never really known it to happen since their last security updates).

I get the same bots coming on the three domains I control, all have SMF and TP. Other hostees have used other forum software such as phpBB for their sub-domains and/or purchased ones and so I keep an eye out for those more so than the SMF/SMF+TP sites.

If you do get your database hacked (depending on what level the hack does damage), you can still use the server logs to check where most recent data was submitted and then go through CPanel or phpmyadmin or whatever and edit out bad parts causing the problem. It sucks to have to do but I've done it for another site I administrate (not on my own servers or network has it happened - yet - praise be the Lord for that).

Quote from: ShadowMaster on March 07, 2008, 02:53:20 PM
Running a site which attracts a fair amount of traffic and running TPortal, my error logs where flooded with entries just like this.

While these attempts pose little danger, i wasn't too happy about TP blindly using the URL input without any form of verification before running the SQL query.

A simple fix which eliminates these errors from showing up is verifying that the input is numeric.

In Sources/TPortal.php i did the following around line 1725

Old:


// Show the latest news, with a template... by board. Modified from SSI.php
function TP_boardNews($board, $limit = null, $start = null, $length = null)
{
        global $scripturl, $db_prefix, $txt;
        global $settings, $modSettings, $context, $user_info;

        loadLanguage('Stats');



new:

// Show the latest news, with a template... by board. Modified from SSI.php
function TP_boardNews($board, $limit = null, $start = null, $length = null)
{
        global $scripturl, $db_prefix, $txt;
        global $settings, $modSettings, $context, $user_info;

        if (!is_numeric($limit) || !is_numeric($start) || !is_numeric($length))
        {
                die('Hacking attempt...');
        }

        loadLanguage('Stats');


Granted you could take it further and do more than just display an error like email notifications, error logging, automatic banning etc.

That is definitely a good idea.

That's pretty much what I sort of did on my own site, just in case the data submitted failed to be cleaned to the point where it was safe. In my case I have them redirected to an error site that scares the heck out of the bot if said user is not a bot.

For one thing, I've found that a lot of the urls these bots or spammers try to use end up not actually existing, though they do sometimes. Most of them give 404 errors. Of course it might be the fact that I use script blocker (NoScript) for Firefox as well when I browse. NoScript has an update every day or two so it is annoying sometimes when I want to just get to browsing, but waiting a few extra seconds for it isn't too bad, though this is sort of off-topic.
Title: Re: Security issue (i think)
Post by: ShadowMaster on March 09, 2008, 09:10:55 PM
Quote from: Elrond on March 09, 2008, 01:07:07 PM
SMF's source file called QueryString.php does do a lot of cleaning of the $_POST, $_REQUEST, $_GET, $_FILE and other submission methods to prevent entry of single quotes and slash methods as well as most other methods with htmlspecialchars to clean out any html (including javascript) and addslashes, preventing anything from template parsing errors to major database issues. mysql_real_escape_string should be used in many cases though, as that cleans out non-standard hex-type entires that replace a single quote with a character entity equivalent to a single or double quote.

On a small side note. I realize that my post could indicate that i was under the impression that TP takes no precautions at all. That was not my intention. I am aware that input is sanitized, i was merely referring to the lack of sanity checking before carrying out the query.

Title: Re: Security issue (i think)
Post by: G6Cad on March 23, 2008, 10:48:35 AM
This seems to be good to go so i mark this to solved.