SQL Attack

962 Words2 Pages

1. Introduction

Numerous web applications are vulnerable to attack because of unsecure code. Common attacks are SQL injection and XSS. The aim of this project is to identify vulnerabilities in source code, then attack the vulnerabilities, and finally, fix the errors to make the code secure. The input fields in the register and login pages of a basic web application will be used to demonstrate the attacks used. The attacks used in the report are SQL injection and XSS. SQL injection will be fixed using PHP Data Objects (PDO) prepared statements and the XSS vulnerabilities will be fixed using htlmentities.
The report also contains screenshots that will aid the readers overall understanding.

2. Code Vulnerable to SQL Injection

The index page contains one line of code that's vulnerable to SQL injection. The vulnerable code is :
$checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'");
The script builds an SQL query by concatenating hard-coded strings together with a string entered by the user. The interpreter will execute the command based on the inputs received for the username and password fields. The code is not filtered for escape characters and the query is then passed into a SQL statement. The single and double quotes and the concatenation allow SQL injection. The code is vulnerable to SQL injection because the user is free to input anything they want in the form fields. A well crafted query string can manipulate the back-end database and log the user in even if they've not registered. Amending the query string can potentially delete or modify records in the database.

A static code analyzer specifically for PHP code is RIPS. RIPS is one of the best tools to scan for vu...

... middle of paper ...

... execute malicious code on the end users systems. Web pages that pass data to a back-end database are vulnerable to this type of attack. Common examples are login forms with usernames and passwords.

A scan for XSS vulnerbilities in RIPS reveals a total of 15 vulnerabilities. (See Figure 3-1 below).

Figure 3-1 XSS vulnerabilities RIPS.

RIPS returns a number of false positives and should only be used as a guide to aid in finding XSS vulnerabilities. The code on the register page that vulnerable to XSS are the variables username and email. The password variable is not vulnerable becuase it's hashed with MD5. The vulnerable code is :
$username = $_POST['username'] & $email = $_POST['email'].
POST is a little safer than GET because the parameters are not stored in browser history or in web server logs. The variable email on the index page is also vulnerable.

Open Document