Binca Sql-Injection
Binca Sql-Injection
Perhaps the most well known web app flaw '," String delimiter
Easier to address from an app security perspective, but remains a ; Terminates a SQL statements
common flaw. -- , # , /* Comment delimiters
Apps employ relational databases for a multitude of reasons %,* Wildcard characters
App interfaces to add, update and render data || , + , " " String concatenation characters
Flaw originates from app allowing user-supplied input to be dynami‐ +,<,>,= Mathematical operators
cally used in a SQL query
= Test for equivalence
Numerous different Relational Database Management Systems in
() Calling functions, sub-queries, and INSERTs
use including Oracle, MySQL, MSSQL
%00 Null byte
Note: Names for data types may vary across RDBMSs The 1=1 changes query logic because it is always true.
;-- Ends the payload completing the statement and comments out the
remaining code to prevent syntax errors
Involves finding correct prefixes, payloads and suffixes to evoke Database Not only hint at the presence of SQLi but may guide us
desired behavior. Error in crafting input for exploitation. If you see database
Significant aspect of discovering SQLi flaws is determining reusable Messages error messages it is NOT blind SQLI
pieces of our injection. Custom Can require a different approach because the error will
Most obvious balancing act is quotes. Error not indicate if the input is being interpreted.
Messages
The most common data type our input will land within are strings so
proper prefixes and suffixes to accommodate strings are necessary.
Equivalent String Injections
Example with comments: John';--
Prefix Suffix Note
SELECT...WHERE lname='John';--';
John' ;# Commenting
Example without comments: John' OR '1'='1 John' ;-- Commenting
SELECT...WHERE lname='John' OR '1'='1'; Jo'/* */'hn Inline Commenting
Jo' 'hn Concatenation (with or without spaces)
Balancing Column Numbers and Data Types
Jo'| |'hn Concatenation
INSERT and UNION statement require us to know the number of
Comment delimiters (--, /**/, #) can allow injections to succeed that
columns required or used, otherwise a DB Syntax Error will occur
would otherwise fail.
INSERT and UNION statements also require the data type
The -- and # are useful SQL suffixes.
associated with the columns to be compatible.
Injecting into the middle of a SQL statement/query will not allow us to
ORDER BY [#] is another option where the number is incrementally alter the rest of the SQL statement but it will show us if our input is
increased until an error is thrown. being interpreted on the backend when we experience custome error
Note: Numbers and strings are typically compatible. messages (Blind SQLi).
Input locations that leverage/interact with backend DB such as login John' AND 1;# True
functionality. John' AND 1=1;# True
HTTP Request portions that are common input locations: John' AND 0;# False
GET URL query parameters
John' AND 1=0;# False
POST payload
If it evaluates to True (AND 1=1) or False (AND 1=0)
HTTP COOKIE
Prefix: Dent' AND
HTTP User-agent
Evaluates: substr((select table_name from information_sch‐
HTTP COOKIE and User-agent are more likely to be blind.
ema.tables limit 1,),1,1) > "a"
Suffix: ;#
Classes of SQLi
Out-of-Band SQLi
No errors messages
No visible responses
No boolean/inference opportunities without or without timing
Requires an alternative communication channel to discover or exploit
these flaws
Out-of-Band Channels may provide for faster ex-filtration of some
flaws susceptible to inference techniques. Typically leverages HTTP
or DNS to tunnel communications back to attacker controlled server
Query Disclosure