- Prepare The Environment.
- Simple Case of SQL Injection Testing
What we need is:
PHP & MYSQL
- You can install PHP & MYSQL from Xampp (apachefriends.org)
- We need that 2 to be active for this testing
Get Development Folder Ready:
- Create folder "sql-injection" inside your root folder for web hosting (if xampp, then htdocs)
- Go inside the folder and create 2 file ("index.php" and "secure_login.php"), like this structure:
-sql-injection
--index.php
--secure_login.php
-
Open "index.php" and write this code:
-
Open "secure_login.php" and write this code:
-
Next, open PhpMyAdmin to create database, here is the step:
- Create database "testdb"
- Create table "users"
- Create field:
- id INT AUTO_INCREMENT PRIMARY KEY
- username VARCHAR(50) NOT NULL
- password VARCHAR(50) NOT NULL
- Then, input data into table with username: "admin" and password: "admin123"
-
Or, you can write this code in SQL script:
-
Lets play the SQL Injection case:
-
Not safe code:
-
Open your php code on: "localhost/sql-injection", it will shown like this:
- Test for login success:
- Input "admin" into field username
- Input "admin123" into field password
- click submit!
- it will shown login success
- Test for login failed:
- Input any value to field username and password
- click submit!
- it will showrn login failed
-
Test for SQL Injection:
- Input this value into field username:
admin' OR '1'='1
- Let field password empty
- click submit!
- see the result
-
Test the SQL Injection into the secure_login (localhost/sql-injection/secure_login.php)
- Input this value into field username:
admin' OR '1'='1
- Let field password empty
- click submit!
- see the result
-
Compare it, and why it secure.
-
SQL Injection case, Done