Jump to content

Website being hacked! Some one is deleting all posts!


runnerjp

Recommended Posts

Hey guys,

 

I logged on to edit my website today to find that most of my forum posts have been deleted!

 

I have no idea how they have done this....

 

I have made sure all $_gets and $_posts have mysql real escaped and i just cant find out how they are doing it.

 

Can any one offer me guidence to find the errors ....

 

i can provide access to the site to find the error itself.

 

Anything to prevent my hard work being destroyed.

Link to comment
Share on other sites

they could have but i dont see how they edited it... iv just chnage permissions on the edit button to delete posts ect so i can try clean it up alittle quikly- usually it has if{$userid = '1'}  so only Admin can edit it.

 

 

for time being i think i might log all logins with date time ip ect....

all errors (how would i create error log so i can record username ip and error made @ time??)

and all deletiong ect made by users.

 

Try track down how and who is doing it

Link to comment
Share on other sites

they could have but i dont see how they edited it... iv just chnage permissions on the edit button to delete posts ect so i can try clean it up alittle quikly- usually it has if{$userid = '1'}  so only Admin can edit it.

 

 

for time being i think i might log all logins with date time ip ect....

all errors (how would i create error log so i can record username ip and error made @ time??)

and all deletiong ect made by users.

 

Try track down how and who is doing it

if u can provide us ur code then i can surely help u out on hw u can log the details of the guys who are doing in out..

What do you mean by logs??

 

i mean this one onlyy.. whether u are storing any thing when some one is doing something on ur site...

this would slow down ur process but it will surely help u out when something like this happens... :)

 

Link to comment
Share on other sites

if u can provide us ur code then i can surely help u out on hw u can log the details of the guys who are doing in out..

Ok well usernames are stored as $username; 

the page they are on is stored as $url;

time is $time;

 

any other part of code u want?

 

mean this one onlyy.. whether u are storing any thing when some one is doing something on ur site...

this would slow down ur process but it will surely help u out when something like this happens... 

 

and no i dont sadly, but i think i best lol

 

Link to comment
Share on other sites

so u are using the admin login only to delete the posts right, so what u can do is check  the http referrer from which they are using to access the pages of deletion. if any script is doing it out then obviously  u can restrict that..

 

check with these server variables and add the ones  which ever u need most

 

http://php.net/manual/en/reserved.variables.server.php

Link to comment
Share on other sites

I have had alook at the page and it does not make sence to me :(

 

Also do you know how to log errors??

 

so far i have-

 

 

/* we will do our own error handling. */
error_reporting(0); // Turns off all error reporting.

/* user defined error handling function. */
function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
{
    // timestamp for the error entry.
    $dt = date('Y-m-d H:i:s (T)');

    // define an assoc array of error string
    // in reality the only entries we should
    // consider are E_WARNING, E_NOTICE, E_USER_ERROR,
    // E_USER_WARNING and E_USER_NOTICE.
    $errortype = array (
                E_ERROR => 'Error',
                E_WARNING => 'Warning',
                E_PARSE => 'Parsing Error',
                E_NOTICE => 'Notice',
                E_CORE_ERROR => 'Core Error',
                E_CORE_WARNING => 'Core Warning',
                E_COMPILE_ERROR => 'Compile Error',
                E_COMPILE_WARNING => 'Compile Warning',
                E_USER_ERROR => 'User Error',
                E_USER_WARNING => 'User Warning',
                E_USER_NOTICE => 'User Notice',
                E_STRICT => 'Runtime Notice'
                );
    // set of errors for which a var trace will be saved.
    $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);

    $err = "<errorentry>\n";
    $err .= "\t<datetime>" .$dt. "</datetime>\n";
    $err .= "\t<errornum>" .$errno. "</errornum>\n";
    $err .= "\t<errortype>" .$errortype[$errno]. "</errortype>\n";
    $err .= "\t<errormsg>" .$errmsg. "</errormsg>\n";
    $err .= "\t<scriptname>" .$filename. "</scriptname>\n";
    $err .= "\t<scriptlinenum>" .$linenum. "</scriptlinenum>\n";

    if (in_array($errno, $user_errors)) {
        $err .= "\t<vartrace>" .wddx_serialize_value($vars, 'Variables'). "</vartrace>\n";
    }
    $err .= "</errorentry>\n\n";

    // save to the error log file, and e-mail me if there is a critical user error.
    error_log($err, 3, '../error_log.log');
    if ($errno == E_USER_ERROR) {
        mail('bgates@gmail.com', 'Critical User Error', $err);
    }
}
$old_error_handler = set_error_handler('userErrorHandler');

 

if i was to chnage it so i added it to db with username and page ect would this help?

Link to comment
Share on other sites

it is not regarding the errors that i am asking about..

what i am trying to say here is that

suppose if an user logs into ur site

then these are the following details u can fetch from that

SERVER_ADDR

REQUEST_METHOD

REQUEST_TIME

QUERY_STRING

HTTP_REFERER--used to find whether he is coming from a valid url...

REMOTE_ADDR

SCRIPT_FILENAME

 

and so on......

 

these are quite helpfull for you to trace the things while u are working on..

also have a check whether some one is directly accessing ur database and deleting the things

 

change ur mysql password and also the access levels for the user id...

 

 

Link to comment
Share on other sites

It's highly likely that your form processing code where you actually delete posts (and perhaps on all of your admin functions) is either not checking if the current visitor is logged in as an admin or the code you are using to check that can be bypassed.

 

The code we really need to see would be for the delete function and the login security you are using on that page.

 

Just an FYI: HTTP_REFERER is a header that comes with the HTTP request. It can easily be set to anything and in fact most of the web proxy scripts set it to be the same as the domain being requested so that requests that come through such a proxy look like they are from someone who is actually browsing on your site. HTTP_REFERER cannot really be trusted or used for anything more than informational purposes.

Link to comment
Share on other sites

Just an FYI: HTTP_REFERER is a header that comes with the HTTP request. It can easily be set to anything and in fact most of the web proxy scripts set it to be the same as the domain being requested so that requests that come through such a proxy look like they are from someone who is actually browsing on your site. HTTP_REFERER cannot really be trusted or used for anything more than informational purposes.

 

can u provide me with a sample of how to set that ??

Link to comment
Share on other sites

Ok the login system is http://evolt.org/node/60384  - which im 100% sure its secure.

 

The delete posts is

 

   
if (isset($_POST['edit']) && $username = 'Admin') 
{
if(isset($_POST['forumlock']))
{
	$forumlock=1;
}else
{
	$forumlock=0;
}
	$threadid =  mysql_real_escape_string( $_POST['id']);
if ($_POST['deletepost'] == 'deletepost'){ 
     mysql_query("DELETE FROM forumtutorial_posts WHERE postid='$threadid'")  
		or die(mysql_error()); 
$updatep = "UPDATE `users` SET `post_count`=`post_count`-'1' WHERE `Username`='$username'";
            mysql_query ($updatep) or die("Could not update post");

		 mysql_query("DELETE FROM forumtutorial_posts WHERE parentid='$threadid'")  
		or die(mysql_error()); 					
		header( "refresh: 0; url=http://www.runningprofiles.com/members/index.php?page=forum&forum=$forum");
		}
      if(isset($_POST['important']))
	{
	         $important=1;
      }
	else
	{
	          $important=2;
	}

$title = $_POST['title'];
$query = "UPDATE forumtutorial_posts SET forumlock = '$forumlock', important = '$important', title = '$title' WHERE postid='$threadid' ";
mysql_query($query) or die('Error, query failed');
header( "refresh: 0; url=http://www.runningprofiles.com/members/index.php?page=forum&forum=$forum"); 
}
else
{
//	$threadid =  mysql_real_escape_string( $_POST['id']);
$threadid =  $CONT_ID;

$check = '';

$forumlock=0;// default value if it's not set
$checkimpor = '';

$important=0;// default value if it's not set

?>
<script src="../../css/SpryCollapsiblePanel.js" type="text/javascript"></script>
   
      <div id="CollapsiblePanel<?php echo $threadid; ?>" class="CollapsiblePanel">
  <div class="CollapsiblePanelTab"  > Edit</div>
  <div class="CollapsiblePanelContent">
<form name='input' action='index.php?page=forum&forum=<? echo $forum ?>' method='post'>

<div align="center">
  <p>Title:
    <input class='inputinbox' name='title' type='text' value='<? echo $getthreads3[title];?>' />
      <br/>

 <?php   if($getthreads3['forumlock']==1) {

      echo "<input type='checkbox' name='forumlock' checked='checked' />";
}
else 
{
echo "<input type='checkbox' name='forumlock' />";
} ?>
    Lock a Room<br/>
<?php if($getthreads3['important']==1) {   echo "<input type='checkbox' name='important' checked='checked' />";	}
else
{
echo "<input type='checkbox' name='important' />";
}
?>
    Important       <br/>
	    <input type="checkbox" name="deletepost" value="deletepost" />
    Delete post</p>
  <input type="hidden" name="id" value="<?php echo $getthreads3[postid] ?>" />
    <input type='submit' name='edit' class="submit-btn"  value='' />
     
</div>
</form>	  

<?
}
?></div>
</div>


<script type="text/javascript">
<!--
var CollapsiblePanel1 = new Spry.Widget.CollapsiblePanel("CollapsiblePanel<?php echo $threadid; ?>", {contentIsOpen:false});
//-->
      </script>


Link to comment
Share on other sites

im 100% sure its secure.

 

No, it's not. There are two possible exploits. 1) It does not stop execution of the code on the page when it redirects, so when a login fails, the code on the page is still executed. 2) If you are not stopping the execution of the code on the page after you check if someone is not logged in, your delete code is still being executed.

 

Edit: And I just looked at the 'admin' code that comes with that script. If you copied what it is doing, it is not protecting and preventing the code on your pages from being executed. All a hacker needs to do is ignore the header() redirects (which is the default if someone was using a CURL script to access your pages) and he can get any of your 'protected' code to execute.

Link to comment
Share on other sites

 

 

No, it's not. There are two possible exploits. 1) It does not stop execution of the code on the page when it redirects, so when a login fails, the code on the page is still executed.

 

 

 

2) If you are not stopping the execution of the code on the page after you check if someone is not logged in, your delete code is still being executed.

 

Edit: And I just looked at the 'admin' code that comes with that script. If you copied what it is doing, it is not protecting and preventing the code on your pages from being executed. All a hacker needs to do is ignore the header() redirects (which is the default if someone was using a CURL script to access your pages) and he can get any of your 'protected' code to execute.

 

Wow... ok how would you advise to solve these?

 

Edit: i dont use the admin script im making my own using this function

 

function checkLogin($levels)
{

			global $db;
			$kt = split(' ', $levels);

			if (!$_SESSION['logged_in'])
			{

							$access = false;

							if (isset($_COOKIE['cookie_id']))
							{ //if we have a cookie

											$query = 'SELECT * FROM ' . DBPREFIX . 'users WHERE ID = ' . $db->qstr($_COOKIE['cookie_id']);

											if ($db->RecordCount($query) == 1)
											{ //only one user can match that query
															$row = $db->getRow($query);

															//let's see if we pass the validation, no monkey business
															if ($_COOKIE['authenticate'] == md5(getIP() . $row->Password . $_SERVER['USER_AGENT']))
															{
																			//we set the sessions so we don't repeat this step over and over again
																			$_SESSION['user_id'] = $row->ID;
																			$_SESSION['logged_in'] = true;

																			//now we check the level access, we might not have the permission
																			if (in_array(get_level_access($_SESSION['user_id']), $kt))
																			{
																							//we do?! horray!
																							$access = true;
																			}
															}
											}
							}
			}
			else
			{
							$access = false;

							if (in_array(get_level_access($_SESSION['user_id']), $kt))
							{
											$access = true;
							}
			}

			if ($access == false)
			{
							header('Location: http://www.runningprofiles.com/error.php');
							exit();

			}
}
   

Link to comment
Share on other sites

Every header() redirect needs an exit; statement after it to stop the execution of the code at that point or you need to insure through conditional logic (i.e. an else{} statement) that you only execute the code you want when you want it.

 

This is not secure -

if(some security test here){
    header('Location:.....');
}
// code here is still executed while the browser performs the redirect

 

This is secure -

if(some security test here){
    header('Location:.....');
    exit;
}
// code here is not executed while the browser performs the redirect

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.