Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Anti Sql Injection Protection

Custom Title Activated
Loyal Member
Joined
Feb 27, 2004
Messages
1,378
Reaction score
50
Here is some Easy Ways To protecting Your website .. from Different Type of Security Holes.

A. SQL INJECTIONS

How to Use.
1. download the file , put in the same folder as the php file
2. Below are the how to use.. Put these on the top of the page just after <?
PHP:
require_once "sql_inject.php";
$bDestroy_session = TRUE;
$url_redirect = 'index.php';
$sqlinject = new sql_inject('./log_file_sql.log',$bDestroy_session,$url_redirect);
3. THis is the Sql Injection Checker
PHP:
$sqlinject->test($your_sql_data);
Explaination:
require_once "sql_inject.php"; < calls the file protector file
$bDestroy_session = TRUE; < this stops any session they on
$url_redirect = 'index.php'; < if they do a sql injection they are moved to this page
$sqlinject = new sql_inject('./log_file_sql.log',$bDestroy_session,$url_redirect); < this to start the sql injection protection ( also ./log_file_sql.log is the file wer all the attempt are put in.. for u to ban later on ... hehehehhe)

$sql_inject->test($your_sql_data); < this is the implementation of the anti sql injector. where $your_sql_data is the mssql query string.

Thats my best explaination.. im too lazy now.. if u made it work.. try to explain to the others.

Dont pm me about this please..

Additional Info:
PHP:
<?

require_once "sql_inject.php"; 
$bDestroy_session = TRUE; 
$url_redirect = 'index.php'; 
$sqlinject = new sql_inject('./log_file_sql.log',$bDestroy_session,$url_redirect); 

// some line here
// more lines here.. blah blah blah

//below is a little trick to do a post variable on this page.. as u can see the post variable [B]login[/B]  is already been injected with a drop table on memb_info and clevel = 350
$_POST['login'] = "%%'; drop table memb_info ; update character set clevel = 350ere name = '%%"; 
// this type of sql injection is trying to execute more SQL data

// then like any normal page.. u read the $login variable (we can even try to stripslashes it)
$login = stripslashes($_POST['login']);

//your sql query string 
[COLOR=DarkRed]$query[/COLOR] = "Select Name From Character where name = '$login'";
//normally you would check  $something for sql injection, but in this case, due to the new anti sql injection the entire query string can be analysed..

// to analyse query string we do this
$sqlinject->test([COLOR=DarkRed]$query[/COLOR]); 

//now that we checked it.. we can query it
$result = mssql_query([COLOR=DarkRed]$query[/COLOR]);

// more lines here.. blah blaah

?>

--- above would make a new file in ur folder called. log_file_sql.log make sure u make ur folder writable :)
--- now i test the sample php file above.. it works like a charm. :)
UPDATE FOR SOME TYPOS!

B. STOPING OFF DOMAIN TRANSACTIONS
- one of the bigger holes in any website is forms.. cause when u make them.. it doesnt really mean they that way always.. people can just download the form.. edit the action, and send anything they want to your server. This is widely used by the sql injectors.

How to Stop. The Idea is On the Other side of ur Forms... U will have Referral Check. Referal Means the last page that was used before the current one.

Put this on ur a File Ur targeting as an Action on a form.
PHP:
if (stristr($_SERVER['HTTP_REFERER'], 'http://www.supamu.info') === FALSE ) {
    die ( 'Hacking attempt. Your are such a Nooby!.. ' ); 
**

-- above is checking if the last referral was from the domain. if not it stop the entire page from loading any further. wat u can also do is add a logging system to this, which ill do in the next tutorial.

C. Adding a Simple Auto File Logger To your Website

This is to catch those hacking attempts on a FILE! The anti Sql Injector already has it's Own Logging system.. but this is for those other stuff u want to log. like for example. The Referral Check.

here is the main function for the logger (u need to put this somewer on ur php file a global insert file)
PHP:
function filelogs($type, $info, $muser) {
$agent = $_SERVER['HTTP_USER_AGENT']; 
    $uri = $_SERVER['REQUEST_URI']; 
    $ip = $_SERVER['REMOTE_ADDR']; 
    $ref = $_SERVER['HTTP_REFERER']; 
    $dtime = date('r'); 
     
    if($ref == ""){ 
        $ref = "None"; 
    ** 
    if($user == ""){ 
        $user = "None"; 
    ** 
    $location = "/";
    $type = $location . $type . ".txt";
    $entry_line = "$dtime - IP: $ip | Agent: $agent  | URL: $uri | Referrer: $ref | Username: $muser | Query : $info \n"; 
    $fp = fopen("$type", "a"); 
    fputs($fp, $entry_line); 
    fclose($fp); 
**

How to Use is like Simple Like this

PHP:
   filelogs('filename', $additionalinfo, $theusername);

filename = just to separate from one kind of logs to another
$additionalinfo = this is some info u wanna include in the logs like queries or the current referrer's address
$theusername = if u have cookies.. u can put them here.. so ull know who to ban for this acts.

A sample script.. this is combined with the the Referral Filter on B

PHP:
if (stristr($_SERVER['HTTP_REFERER'], 'http://www.supamu.info') === FALSE ) {
   
   filelogs('account-creat', $_SERVER['HTTP_REFERER'], $_POST['Member_ID']);
   die ( 'Hacking attempt. Your are such a Nooby!.. ' ); 
**

Ill do more later.. Just ask here if u wanna me to do any kind of protection.
 

Attachments

You must be registered for see attachments list
Last edited:
Custom Title Activated
Loyal Member
Joined
Feb 27, 2004
Messages
1,378
Reaction score
50
Ow.. if u are asking wat it actually stops..

it stops:
1. More sql query to be runned.
2. always true expression
3. Try to modify it's right injection

It doesnt stop Update DROP or any illegal words but ... it then again it doesnt need to stop those cause u already stoping it from making a second query.
 
Newbie Spellweaver
Joined
Sep 15, 2004
Messages
32
Reaction score
0
Hello!
I have a question about your sql injection
about this:

2. Below are the how to use.. Put these on the top of the page just after <?

PHP Code:

Wat is the page that i have to put this file i mean the php code?
it is in config.php?

plsss reply
 
Newbie Spellweaver
Joined
Sep 13, 2004
Messages
17
Reaction score
0
Is this the basic foundation of MuToolz or something different?
 
Newbie Spellweaver
Joined
Aug 5, 2004
Messages
47
Reaction score
0
nice one.... hope hackers cant get into my php...
 
Custom Title Activated
Loyal Member
Joined
Feb 27, 2004
Messages
1,378
Reaction score
50
this is totaly difference.. the public release of Mutoolz doesnt have this..

here is a sample of a php file ...

<?

require_once "sql_inject.php";
$bDestroy_session = TRUE;
$url_redirect = 'index.php';
$sqlinject = new sql_inject('./log_file_sql.log',$bDestroy_session,$url_redirect);

// some line here
// more lines here.. blah blah blah

//your sql query string
$query = "Select Name From Character where name = '$something'";
//normally you would check $something for sql injection, but in this case, due to the new anti sql injection the entire query string can be analysed..

// to analyse query string we do this
$sqlinject->test($query);

//now that we checked it.. we can query it
$result = mssql_query($query);

// more lines here.. blah blaah

?>
 
Last edited:
Junior Spellweaver
Joined
Sep 12, 2004
Messages
134
Reaction score
14
I have one problem... look this

Fatal error: Call to a member function on a non-object in c:\apache\www\teste.php on line 18
 
Initiate Mage
Joined
May 31, 2004
Messages
1
Reaction score
0
Its only for PHP websites, right? if I run ASP website so I dont need this?
 
Newbie Spellweaver
Joined
Sep 15, 2004
Messages
32
Reaction score
0
Hello guys nice job but i got this problem too??

Fatal error: Call to a member function on a non-object in c:\appserv\www\includes\config.php on line 26

can u help me guys.. plsss..thankss...
 
Newbie Spellweaver
Joined
Jul 4, 2004
Messages
51
Reaction score
0
i just stick the file in the folder?
and in ALL of the pages i place require_once "sql_inject.php";
$bDestroy_session = TRUE;
$url_redirect = 'index.php';
$sqlinject = new sql_inject('./log_file_sql.log',$bDestroy_session,$url_redirect) ;

// some line here
// more lines here.. blah blah blah

//your sql query string
$query = "Select Name From Character where name = '$something'";
//normally you would check $something for sql injection, but in this case, due to the new anti sql injection the entire query string can be analysed..

// to analyse query string we do this
$sql_inject->test($query);

//now that we checked it.. we can query it
$result = mssql_query($query);

// more lines here.. blah blaah
----------------------------------------------------------------------
right after after <?
 
Custom Title Activated
Loyal Member
Joined
Feb 27, 2004
Messages
1,378
Reaction score
50
any php script u have running this can be use to protect it.

koaru* .. upload a sample page u updated. .let me see if it is good to go.
 
Back
Top