0 Users appreciate this thread.
SQL Injection
SPCOxion (2014-04-23 18:22:47)this is about SQL injection, not PDO injection
nor is it about why we should and shouldn't use PDO
CoolApps (2014-05-01 16:54:46)I wouldn't just use real escaping.
How it really works?, well...
When you're entering something with a quote such as 1=1', that closes the username and/or password in the query, 1=1 is always true and will select the first row, making you login into a user in ID 1.
If you want to investigate this vulnerability, refer to Google.
SQL Injectable sites, do ' at the end of the ID in a URL.
Also, in a vulnerable login, do 1=1' in the username and password box.
Do NOT try this on other people's site without permission.
2014-05-02 00:22:25
Newer account: NodePoint
Log in to submit a comment
Back to forum: Web Programming (HTML, JS, CSS, PHP, MySQL)
New registered users today: 7
Newest registered user: ElegantVulpes
This forum will mainly be about how to SQL inject, and how to protect against it.
Say you have a register on your site. You have people type in their username and password. Of course, you're going to insert that data into a database... right?
Unless you're careful, people can hack your site like this.
Assuming you're storing the data in variables (i.e. $username = $_POST['username'] ), and then putting those variables into a string you'll user as a SQL query (i.e. $q = "INSERT INTO table VALUES (" . $username . ", " . $password . "
What happens if they type in bob"
Well, that's what SQL Injection is.
This isn't the only way to SQL Inject, so be careful.
There are a few ways to do this, but the simplest way would be to type something into a login.
You type something like this in:
thisismyusername"
Hit enter/submit, and you're done.
(if it worked)
Well, think about it for a second.
When you're logging in, this is the gist of what's going on in the code:
<?php $a = $_POST['something1']; $b = $_POST['something2']; /*validation code shet here*/ mysqli_query($conn, "INSERT INTO something VALUES (" . $a . ", " . $b . "
Emphasis on the mysqli_query.
Now, since they're putting a variable that you control into an SQL command, you can mess sht up.
Once you type something like tom"
Why?
Because then the SQL command would look like this:
INSERT INTO table VALUES (tom); TRUNCATE something)
Now, obviously, that code has a few bugs in it, but you can sort those out.
Very simple, if you're using MySQLi, like you should be.
Before you insert those variables into a database, do something like this...
$a = $_POST['something']; $a = mysqli_real_escape_string(Connection info here, $a);
That's the simplest way, if not the only way; If you're that concerned about it, do a Google search about advanced protection methods or sumthin.