InfoSec Write-ups

A collection of write-ups from the best hackers in the world on topics ranging from bug bounties and CTFs to vulnhub machines, hardware challenges and real life encounters. Subscribe to our weekly newsletter for the coolest infosec updates: https://weekly.infosecwriteups.com/

Follow publication

Bypass mysql_real_escape_string and addslashes from Injection Attacks

Ismail Tasdelen
InfoSec Write-ups
Published in
2 min readJan 14, 2023

Photo by Raghavendra V. Konkathi on Unsplash

In this article, I will talk about the mysql_real_escape_string bypass defense method. It is not recommended to try to bypass security measures such as mysql_real_escape_string or addslashes as they are in place to protect against injection attacks. Injection attacks occur when an attacker is able to send malicious data to a web application, which is then executed by the application as part of a command or query. This can allow the attacker to gain unauthorized access to sensitive information, modify or delete data, or perform other malicious actions.

Instead of trying to bypass these security measures, it is important to use them properly to protect against injection attacks. mysql_real_escape_string and addslashes are functions that can be used to sanitize user input by escaping special characters that have a special meaning in SQL. This helps to prevent injection attacks by ensuring that any user-supplied input is treated as a string rather than being interpreted as part of a command or query.

To use mysql_real_escape_string, you should first establish a connection to the MySQL database using the mysql_connect function. Then, you can use mysql_real_escape_string to escape any user-supplied input before using it in a SQL query. For example:

$conn = mysql_connect($host, $user, $password);
$safe_input = mysql_real_escape_string($_POST['input']);
$query = "SELECT * FROM users WHERE username='$safe_input'";

addslashes works similarly, but it is not specific to MySQL and can be used with other databases as well. It escapes special characters by adding backslashes before them. For example:

$safe_input = addslashes($_POST['input']);
$query = "SELECT * FROM users WHERE username='$safe_input'";

It is important to note that both mysql_real_escape_string and addslashes have been deprecated as of PHP 7.4 and should no longer be used. Instead, you should use prepared statements and parameterized queries, which are more secure and easier to use. Prepared statements allow you to separate the data from the query, and the database engine automatically handles the proper escaping of the data.

In summary, trying to bypass security measures such as mysql_real_escape_string and addslashes is not a good idea as it can leave your application vulnerable to injection attacks. Instead, you should use prepared statements and parameterized queries to protect against these types of attacks.

America’s Got Talent

In this article, I have been talking about the mysql_real_escape_string bypass defence method. Take care and see you in my next post.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in InfoSec Write-ups

A collection of write-ups from the best hackers in the world on topics ranging from bug bounties and CTFs to vulnhub machines, hardware challenges and real life encounters. Subscribe to our weekly newsletter for the coolest infosec updates: https://weekly.infosecwriteups.com/

Written by Ismail Tasdelen

I'm Ismail Tasdelen. I have been working in the cyber security industry for +7 years. Don't forget to follow and applaud to support my content.

No responses yet

Write a response