SQL Inections Issa
SQL Inections Issa
12/08/21
ISSA
DC 405
Agenda
• Disclaimer
• What are SLQ Injection
• Into to SQL
• Attack Vectors
• Bypassing filters
• Demos
• Countermeasures
• Questions
2
Disclaimer
3
SQL Injections
• SQL injection
– code injection technique that exploits a security
vulnerability in application
– occurs at the database layer of an application.
4
SQL Injections
• Authentication Bypass
• Information Disclosure
• Compromised Data Integrity
• Compromised Availability of Data
• Remote Command Execution
5
Basic SQL
Select
Insert
Update
Delete
Union
6
SQL - Select
7
SQL - Insert
8
SQL - Update
9
SQL - Delete
1. Delete records
10
SQL - Union
11
Terminators
• ; Semi colon ends current SQL query and starts a new one
– SELECT * FROM users ; DROP TABLE users
• Stacked Query
• -- Double dash ignores remaining query string
– Select * FROM users -- limit 10
• Can be used in conjunction
– SELECT * FROM users WHERE id=''; DROP TABLE users; -- '
AND password=''
12
Where Clause Pruning
13
SQL Injection Cause
14
Techniques
15
SQL Injection Types
• Passive
– Exposing database information
• Information retrieval
• Active
– Altering database information
• Insertion
• Deletion
16
Testing for Vulnerability
• Manual
– Time consuming
• Automated
– SQL injection scanners only scan for known
vulnerabilities
• Google
– Incorrect syntax near
17
Toolbox
• SQLIer
• SQLbftools
• SQLibf
• SQLBrute
• BobCat
• SQLMap
• Absinthe
• SQL Injection Pen-testing Tool
• SQID
• SQLNinja
• FJ-Injector Framwork
• Automagic SQL Injector
• NGSS SQL Injector
18
Identifying Vulnerable Site
• ' or 1=1--
" or 1=1--
or 1=1--
' or 'a'='a
" or "a"="a
') or ('a'='a
20
Bypassing Filters
• Escaping entities
– %26%23039 == ' == ‘ (single quote)
• %26 == &
• %23 == #
• 039 Entity number
– Select * FROM users WHERE username=‘secret%26%23039 OR %26%23039X
%26%23039=%26%23039X
– Evaluated as > Select * FROM users WHERE username=‘secret ‘ OR ‘X’ = ‘X’
• This evaluates to always true
• Char function
– Char(83,101,108,101,99,116,32,42,32,102,114,111,109,32,117,115,101,114,115)
– Select * from users
21
Bypassing Filters
22
Bypassing Filters
• 1=(SELECT LOAD_FILE('var/log/messages') )
– MySQL Error: 1064 (You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '\'var/log/messages\') ) limit 5 -- = 1 order by average
desc limit 10' at line 1)
• Char
• Hex
– 1=(SELECT
LOAD_FILE(0x2F7661722F6C6F672F6D65737361676573)
23
Bypassing Blacklists
24
Escape Characters
• %26%23039 OR %26%23039X%26%23039=
%26%23039X
– ‘ OR ‘X’ = ‘X’
25
Demos
• Prerecorded demos
26
Countermeasures
• System Administrators
– White List / Blacklist Input Validation
– Least Privileges
– Application firewalls
• Developer
– Stored Procedures
– Parameterized queries
– Exception handling
27
Whitelist Input validation
• UrlScan v3.0
– restricts the types of HTTP requests that IIS will process
[SQL Injection Headers]
AppliesTo=.asp,.aspx
• SNORT
– Create rule to check for SQL attack
alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS
(msg:"SQL Injection "; flow:to_server,established;
uricontent:".php | .aspx | .asp";
pcre:"/(\%27)|(\')|(\-\-)|(%23)|(#)/i";
classtype:Web-application-attack; sid :9099; rev:5;)
28
Least Privileges
29
Application Firewalls
• Software
– Easy to install and maintain
• Hardware
– Expensive
– Plug and Play
• Examples:
– dotDefender
– webApp.SECURE
– SonicWALL
– WatchGuard
30
References
• http://www.owasp.org/index.php/OWASP_Testing_Guide_App
endix_C:_Fuzz_Vectors#Passive_SQL_Injection_.28SQP.29
• http://upload.wikimedia.org/wikipedia/en/a/aa/SQL_ANATOM
Y_wiki.svg
• http://www.cisco.com/web/about/security/intelligence/sql_injec
tion.html
31