Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Web Development
You last visited: Today at 09:52

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Ask]PHP SQL INJECTION (Hex)

Discussion on [Ask]PHP SQL INJECTION (Hex) within the Web Development forum part of the Coders Den category.

Reply
 
Old   #1
 
banktakung's Avatar
 
elite*gold: 0
Join Date: Dec 2008
Posts: 306
Received Thanks: 59
[Ask]PHP SQL INJECTION (Hex)

PHP Code:
    $username bin2hex($_POST['username']);
    
$pass1 bin2hex($_POST['pass1']);
    
$pass2 bin2hex($_POST['pass2']);
    
$dpass1 bin2hex($_POST['dpass1']);
    
$dpass2 bin2hex($_POST['dpass2']);
    
$email bin2hex($_POST['email']);
    
$gander bin2hex($_POST['gander']);
    
$pincode bin2hex($_POST['pincode']);
    
// TEST HEX QUERY
    
$hex_sql mssql_query("SELECT * FROM ACCOUNT_TBL WHERE account = '".hex($username)."'");
    
$hex mssql_fetch_array($hex_sql);
    echo 
$hex['account'];

function 
hex($h)
  {
  if (!
is_string($h)) return null;
  
$r='';
  for (
$a=0$a<strlen($h); $a+=2) { $r.=chr(hexdec($h{$a}.$h{($a+1)})); }
  return 
$r;
  } 


is it safe??? or i should use pdo
banktakung is offline  
Old 07/06/2015, 03:47   #2

 
Synatex's Avatar
 
elite*gold: 25
Join Date: Apr 2010
Posts: 1,019
Received Thanks: 331
Always use an abstraction layer. It does not matter if it's PDO or any other, just try to remove those old mssql_* and mysql_* functions, they'll be deprecated soon.
Synatex is offline  
Old 07/06/2015, 04:28   #3
 
banktakung's Avatar
 
elite*gold: 0
Join Date: Dec 2008
Posts: 306
Received Thanks: 59
Quote:
Originally Posted by Synatex View Post
Always use an abstraction layer. It does not matter if it's PDO or any other, just try to remove those old mssql_* and mysql_* functions, they'll be deprecated soon.
what should i use for protect sql injection ?
banktakung is offline  
Old 07/06/2015, 11:11   #4


 
tschulian's Avatar
 
elite*gold: 294
Join Date: Sep 2013
Posts: 1,410
Received Thanks: 635
Smth like that:

- preg_replace

tschulian is offline  
Old 07/06/2015, 18:14   #5

 
Synatex's Avatar
 
elite*gold: 25
Join Date: Apr 2010
Posts: 1,019
Received Thanks: 331
Quote:
Originally Posted by banktakung View Post
what should i use for protect sql injection ?
In normal cases (if you're talking about SQL injection only) all those new abstraction layers offer variable escaping. As example: In a normal prepared query using PDO all the variables you bind are escaped.

If you're using MySQLi there is a function called real_escape_string().
Synatex is offline  
Old 07/09/2015, 21:18   #6

 
xEncounter's Avatar
 
elite*gold: 22
Join Date: Nov 2009
Posts: 1,552
Received Thanks: 361
Quote:
Originally Posted by Synatex View Post
In normal cases (if you're talking about SQL injection only) all those new abstraction layers offer variable escaping. As example: In a normal prepared query using PDO all the variables you bind are escaped.

If you're using MySQLi there is a function called real_escape_string().
the function real_escape_string() is also available in mysql...



The only real way to prevent sql injection is the use of prepared statements.

In pdo it's somethin like :

PHP Code:
$pdo = new PDO("mysql:host=;dbname=","root","toor");

$query $pdo->prepare("SELECT * FROM user WHERE id  = ?");
$query->bindParam(1,$id,PDO::PARAM_INT);
$query->execute(); 
xEncounter is offline  
Old 07/10/2015, 00:42   #7

 
Synatex's Avatar
 
elite*gold: 25
Join Date: Apr 2010
Posts: 1,019
Received Thanks: 331
Quote:
Originally Posted by xEncounter View Post
the function real_escape_string() is also available in mysql...



The only real way to prevent sql injection is the use of prepared statements.

In pdo it's somethin like :

PHP Code:
$pdo = new PDO("mysql:host=;dbname=","root","toor");

$query $pdo->prepare("SELECT * FROM user WHERE id  = ?");
$query->bindParam(1,$id,PDO::PARAM_INT);
$query->execute(); 
First of all: The case you have linked will not be able to be used in like 99% of real running systems. However, you're right that mysql has the same function but as I stated above: mysql_* is deprecated soon and the usage of it should not be taught to new users.

However, if you're taking this really rare case as an example for not using real_escape_string() then you should note that your statement is not true as well.

In the same stackoverflow post in which it says that real_escape_string() can be bypassed is also stated that prepared statements can be bypassed - saying that PDO is more secure is not really true since you still have to configurate it correctly. And if we get into configuration you could say that any system which is configured correctly can not or just in a really few cases be attacked.

To sum it up: Change the charset and be sure to use UTF-8 and all this hex shit won't even happen.
Synatex is offline  
Old 07/10/2015, 01:53   #8
 
manulaiko3.0's Avatar
 
elite*gold: 0
Join Date: May 2014
Posts: 663
Received Thanks: 1,154
I use htmlentities, appart from avoiding SQL injection also avoids XSS injection, this is my function:

Code:
/**
 * XSS and SQL Injection Fix
 *
 * Will receive a string as parameter and will be parsed to HTML to avoid XSS
 * injection, can be used to avoid SQL injection too}
 *
 * @param string text text to parse
*
* @return string sanitized text
*/
public static function sanitize ($text)
{
    $table = get_html_translation_table ( HTML_ENTITIES , ENT_QUOTES );
    $textArray = str_split ($text);
    $result = array ();

    //Loop text to find HTML entities
    foreach($textArray as $key => $value) {
        if(isset ($table[$value])) {
            //Get HTML value
            $value = $table[$value];
        }
        //Add it to array
        $result[] = $value;
    }

    //parse new lines to HTML and build string
    $str = nl2br ( implode( "" , $result));
    $ret = str_replace ( "\r\n" , "" , $str);

    return $ret;
}
manulaiko3.0 is offline  
Reply


Similar Threads Similar Threads
Help me please (Injection)
09/29/2014 - S4 League - 11 Replies
So here's how it started : I looked at this post http://www.elitepvpers.com/forum/s4-league-hacks-b ots-cheats-exploits/3407140-xavision-id-manager.ht ml and wanted to try out the item manager but i didnt know how to bypass (already downloaded the bypass) but it is just frustrating that i dont know how to use the Faith injector. Add me on skype so i can share my screen with you and you can give me help and get a thanks !! Skype: Sasora.OfTheRedSands
[C/C++] Injection - the other way
02/03/2014 - Coding Snippets - 0 Replies
Hello! Today i will share with you an injection technique which could be really powerfull. The injection technique is called: PE Injection. It allows you to inject code directly in other processes. It works by allocating the executable memory in the target process, relocate the image of the injector process, and then write the relocated image into the target process. Finally the created remote thread will execute your code. Lets summarize: The injector write his own image into...
Smc injection
07/27/2012 - SRO Private Server - 3 Replies
how can i do that ? i saw this : http://www.elitepvpers.com/forum/private-sro-explo its-hacks-bots-guides/1575275-release-release-cert ification-server-global-manager-billing-exploits.h tml , saw some guides about sql injection , would appreciate some help , and how can i know the ip and port of a IIS of a server ?
SQL injection Help
06/08/2010 - Kal Online - 9 Replies
hi every one im just wanna request i need some one give me link or so to how to do SQL injection On Private Server and Examples on any server because i learned alot but on other sites when i start with kalonline sites XD i got fucked up and i can't do any thing so i hope some one help me to do
WTB sql injection
11/27/2008 - Trading - 0 Replies
prove me that your coin hack work and i will buy it



All times are GMT +1. The time now is 09:52.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.