SlideShare a Scribd company logo
1 of 70
Download to read offline
CNIT 129S: Securing
Web Applications
Ch 9: Attacking Data Stores
 

Part 2 of 2
Bypassing Filters
Avoiding Blocked
Characters
• App removes or encodes some character
s

• Single quotation mark is not needed for
injection into a numerical
fi
el
d

• You can also use string functions to
dynamically construct a string containing
fi
ltered characters
CHR or CHAR Function
• These queries work on Oracle and MS-SQL,
respectively
Comment Symbol Blocked
• Code i
s

SELECT * from users WHERE name='uname
'

• Try injecting this value for name
:

' or 1=1 -
-

• To creat
e

SELECT * from users WHERE name='' or 1=1 --
'

• But the "--' is blocked
Correct Syntax Without
Comment
• Injecting this value for name
:

' or 'a'='
a

• To creat
e

SELECT * from users WHERE name=''
or 'a'='a'
Circumventing Simple
Validation
• If "SELECT" is blocked, try these bypasses:
Using SQL Comments
• If spaces are blocked, use comments instea
d

• MySQL allows comments within keywords
Second-Order SQL Injection
• Many applications handle data safely when it is
fi
rst entered into the databas
e

• But it may later be processed in unsafe ways
App Adds a Second Quote
• Register an account with this name
:

foo
'

• The correct way to insert that value is by adding a
second quote (link Ch 2a
)

INSERT INTO users (username,
password, ID, privs) VALUES
('foo''', 'secret', 2248, 1)
Password Change
• Requires user to input old password, and
compares it to the password retrieved with
:

SELECT password FROM users WHERE
username = 'foo'
'

• This is a syntax error.
Exploit
• Register a new user with this name
:

' or 1 in (SELECT password FROM users
WHERE username = 'admin')-
-

• Perform a password change, and MS-SQL will
return this error, exposing the administrator
password
Advanced Exploitation
• The previous attacks had a ready means of
exposing dat
a

• Adding UNION to a query that returns the
result
s

• Returning data in an error message
Denial of Service
• Turn off an MS-SQL databas
e

' shutdown-
-

• Drop tabl
e

' drop table users--
Retrieving Data as Numbers
• No strings
fi
elds may be vulnerable, because
single quotes are
fi
ltere
d

• Numeric
fi
elds are vulnerable, but only allow
you to retrieve numerical value
s

• Use functions to convert characters to numbers
Using an Out-of-Band
Channel
• You can inject a query but you can't see the
result
s

• Some databases allow you to make a network
connection inside the query language
MS-SQL 2000 and Earlier
Oracle
• UTL_HTTP makes an HTTP reques
t

• Attacker can use a netcat listener
Oracle
• DNS request is even less likely to be blocked
MySQL
• To retrieve the
fi
le, set up an SMB share on your
serve
r

• Alowing anonymous write access
Leveraging the Operating
System
• Sometimes you can get the ability to execute shell
command
s

• Such as by using a PHP shel
l

• Then you can use built-in commands like
 

• tftp, mail, telne
t

• Or copy data into a
fi
le in the Web root so you can
retrieve it with a browser
9b-1
Conditional Responses:


"Blind SQL Injection"
• Suppose your query doesn't return any data you
can see, an
d

• You can't use an out-of-band channel to
ex
fi
ltrate dat
a

• You can still get data, if there's any detectable
behavior by the database that depends on your
query
Example
• Put in this text for username, and anything for
passwor
d

admin' -
-

• You'll be logged in as admin
True or False?
• This username will log in as admin
:

admin' AND 1=1-
-

• This one will not log i
n

admin' AND 1=2--
Finding One Letter
• This username will log in as admin
:

• This one will not log i
n
Inducing Conditional Errors
• On an Oracle database, this query will produce
an error if the account "DBSNMP" exist
s

• If it doesn't, the "1/0" will never be evaluated
and it won't cause an error
Does User "AAAAA" Exist?
Using Time Delays
• MS-SQL has a built-in WAITFOR comman
d

• This query waits for 5 seconds if the current
database user is 'sa'
Conditional Delays
• You can ask a yes/no question and get the
answer from the delay
Testing Single Bits
• Using bitwise AND operator
&

• And the POWER command
MySQL Delays
• Current versions have a sleep functio
n

• For older versions (prior to 5.0.12), use
benchmark to repeat a calculation many times
Oracle
• No function to cause a delay, but you can use
URL_HTTP to connect to a non-existent serve
r

• Causes a delay until the request times out
Oracle
• This query causes a timeout if the default Oracle
account "DBSNMP" exists
Beyond SQL Injection:


Escalating the Database
Attack
Further Attacks
• SQL injection lets you get the data in the
database, but you can go furthe
r

• If database is shared by other applications,
you may be able to access other application's
dat
a

• Compromise the OS of the database serve
r

• Pivot: use the DB server to attack other
servers from inside the network
Further Attacks
• Make network connections back out to your
own computer, to ex
fi
ltrate data and evade
IDS system
s

• Extend database functionality by creating
user-de
fi
ned function
s

• You can reintroduce functionality that has
been removed or disable
d

• Possible if you get database administrator
privileges
MS-SQL
• xp_cmdshell stored procedur
e

• Included by defaul
t

• Allows DBA (Database Administrator) to execute
shell commands
MS-SQL
• Other stored procedures also allow powerful
attack
s

• These read and write to the Registr
y

• xp_regread & xp_regwrite
Dealing with Default
Lockdowns
• MS-SQL 2005 and later disable xp_cmdshell by
default, but you can just enable it if you are DBA
MySQL
• load_
fi
le allows attacker to read a
fi
l
e

• "into out
fi
le" allows attacker to write to a
fi
l
e

• This example makes all hosts trusted on Linux
SQL Exploitation Tools
Algorithm
SQLMAP
9b-2
Preventing SQL Injection
Blocking Apostrophes
• Won't stop injection into numerical
fi
eld
s

• If you allow apostrophes into data
fi
elds by
doubling them, you can have second-order SQL
injection vulnerabilities
Stored Procedures
• Makes code re-use easie
r

• But doesn't prevent SQL injection if user input is
included in a parameter
Stored Procedures
• Developer de
fi
nes a procedur
e

• Attacker can still inject with this passwor
d

• Resulting query
Parameterized Queries
Vulnerable Code
• User input inserted into a command, which is
parsed later to match quotes
Parameterized Version
• User input replaces placeholder "?
"

• No parsing required, not vulnerable to SQLi
Provisos
• Use parameterized queries for EVERY quer
y

• Not just the ones that are obviously user-
controllabl
e

• Every item of data should be parameterize
d

• Be careful if user data changes table or column name
s

• Allow only values from a whitelist of known safe
value
s

• You cannot use parameter placeholders for other parts
of the query, such as SORT BY ASC or SORT BY DES
C

• If they must be adjusted, use whitelisting
Defense in Depth
• Application should use low privileges when
accessing the database, not DB
A

• Remove or disable unnecessary functions of D
B

• Apply vendor patche
s

• Subscribe to vulnerability noti
fi
cation
services to work around new, unpatchable
vulnerabilities
Injecting into NoSQL
NoSQL
• Doesn't require structured data like SQ
L

• in SQL,
fi
elds must be de
fi
ned in a Schema,
as Text, Number, etc
.

• In NoSQL, keys and values can be arbitrarily
de
fi
ne
d

• A new and less mature technology than SQL
Injecting into MongoDB
Example Login Code
Injection
• Log in with this username, and any passwor
d

Marcus'/
/

• Javascript function becomes this:
Another Injection
• Log in with this username, and any passwor
d

• This is always true (link Ch 9b)
Injecting into XPATH
• XML Data 

Store
Injection
• This query retrieves a stored credit card number
from a username and passwor
d

• This injection:
Finding XPATH Injection
Flaws
• These strings usually break the synta
x

• These strings change behavior without breaking
syntax
Preventing XPATH Injection
• Filter inputs with a whitelis
t

• Remove these characters
LDAP
• Lightweight Directory Access Protocol (LDAP
)

• Used to store names, phone numbers, email
addresses, etc
.

• Used in Microsoft Active Director
y

• Also in OpenLDAP
LDAP Queries
• Match a usernam
e

• Match any one of these condition
s

• Match all of these conditions
LDAP Injection Limitations
• Possible, but less exploitable becaus
e

• Logical operators come before user-supplied
data, so attacker can't form "or 1=1
"

• Directory attributes to be returned are hard-
coded and can't usually be manipulate
d

• Applications rarely return informative error
messages, so exploitation is "blind"
3

More Related Content

What's hot

Ch 3: Web Application Technologies
Ch 3: Web Application TechnologiesCh 3: Web Application Technologies
Ch 3: Web Application TechnologiesSam Bowne
 
CNIT 152 12 Investigating Windows Systems (Part 1 of 3)
CNIT 152 12 Investigating Windows Systems (Part 1 of 3)CNIT 152 12 Investigating Windows Systems (Part 1 of 3)
CNIT 152 12 Investigating Windows Systems (Part 1 of 3)Sam Bowne
 
CNIT 126: Ch 2 & 3
CNIT 126: Ch 2 & 3CNIT 126: Ch 2 & 3
CNIT 126: Ch 2 & 3Sam Bowne
 
Practical Malware Analysis: Ch 8: Debugging
Practical Malware Analysis: Ch 8: Debugging Practical Malware Analysis: Ch 8: Debugging
Practical Malware Analysis: Ch 8: Debugging Sam Bowne
 
CNIT 126 12: Covert Malware Launching
CNIT 126 12: Covert Malware LaunchingCNIT 126 12: Covert Malware Launching
CNIT 126 12: Covert Malware LaunchingSam Bowne
 
CNIT 124 Ch10-12: Local Exploits through Bypassing AV
CNIT 124 Ch10-12: Local Exploits through Bypassing AVCNIT 124 Ch10-12: Local Exploits through Bypassing AV
CNIT 124 Ch10-12: Local Exploits through Bypassing AVSam Bowne
 
CNIT 127 Ch 16: Fault Injection and 17: The Art of Fuzzing
CNIT 127 Ch 16: Fault Injection and 17: The Art of FuzzingCNIT 127 Ch 16: Fault Injection and 17: The Art of Fuzzing
CNIT 127 Ch 16: Fault Injection and 17: The Art of FuzzingSam Bowne
 
CNIT 126 Ch 9: OllyDbg
CNIT 126 Ch 9: OllyDbgCNIT 126 Ch 9: OllyDbg
CNIT 126 Ch 9: OllyDbgSam Bowne
 
CNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgCNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgSam Bowne
 
Practical Malware Analysis: Ch 15: Anti-Disassembly
Practical Malware Analysis: Ch 15: Anti-DisassemblyPractical Malware Analysis: Ch 15: Anti-Disassembly
Practical Malware Analysis: Ch 15: Anti-DisassemblySam Bowne
 
CNIT 126 8: Debugging
CNIT 126 8: DebuggingCNIT 126 8: Debugging
CNIT 126 8: DebuggingSam Bowne
 
CNIT 126 7: Analyzing Malicious Windows Programs
CNIT 126 7: Analyzing Malicious Windows ProgramsCNIT 126 7: Analyzing Malicious Windows Programs
CNIT 126 7: Analyzing Malicious Windows ProgramsSam Bowne
 
CNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static Techniques
CNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static TechniquesCNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static Techniques
CNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static TechniquesSam Bowne
 
CNIT 152 10 Enterprise Service
CNIT 152 10 Enterprise ServiceCNIT 152 10 Enterprise Service
CNIT 152 10 Enterprise ServiceSam Bowne
 
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site ScriptingCNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site ScriptingSam Bowne
 
CNIT 123 Ch 10: Hacking Web Servers
CNIT 123 Ch 10: Hacking Web ServersCNIT 123 Ch 10: Hacking Web Servers
CNIT 123 Ch 10: Hacking Web ServersSam Bowne
 
Practical Malware Analysis: Ch 7: Analyzing Malicious Windows Programs
Practical Malware Analysis: Ch 7: Analyzing Malicious Windows Programs Practical Malware Analysis: Ch 7: Analyzing Malicious Windows Programs
Practical Malware Analysis: Ch 7: Analyzing Malicious Windows Programs Sam Bowne
 
CNIT 126 9: OllyDbg
CNIT 126 9: OllyDbgCNIT 126 9: OllyDbg
CNIT 126 9: OllyDbgSam Bowne
 
Practical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbgPractical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbgSam Bowne
 
CISSP Prep: Ch 9. Software Development Security
CISSP Prep: Ch 9. Software Development SecurityCISSP Prep: Ch 9. Software Development Security
CISSP Prep: Ch 9. Software Development SecuritySam Bowne
 

What's hot (20)

Ch 3: Web Application Technologies
Ch 3: Web Application TechnologiesCh 3: Web Application Technologies
Ch 3: Web Application Technologies
 
CNIT 152 12 Investigating Windows Systems (Part 1 of 3)
CNIT 152 12 Investigating Windows Systems (Part 1 of 3)CNIT 152 12 Investigating Windows Systems (Part 1 of 3)
CNIT 152 12 Investigating Windows Systems (Part 1 of 3)
 
CNIT 126: Ch 2 & 3
CNIT 126: Ch 2 & 3CNIT 126: Ch 2 & 3
CNIT 126: Ch 2 & 3
 
Practical Malware Analysis: Ch 8: Debugging
Practical Malware Analysis: Ch 8: Debugging Practical Malware Analysis: Ch 8: Debugging
Practical Malware Analysis: Ch 8: Debugging
 
CNIT 126 12: Covert Malware Launching
CNIT 126 12: Covert Malware LaunchingCNIT 126 12: Covert Malware Launching
CNIT 126 12: Covert Malware Launching
 
CNIT 124 Ch10-12: Local Exploits through Bypassing AV
CNIT 124 Ch10-12: Local Exploits through Bypassing AVCNIT 124 Ch10-12: Local Exploits through Bypassing AV
CNIT 124 Ch10-12: Local Exploits through Bypassing AV
 
CNIT 127 Ch 16: Fault Injection and 17: The Art of Fuzzing
CNIT 127 Ch 16: Fault Injection and 17: The Art of FuzzingCNIT 127 Ch 16: Fault Injection and 17: The Art of Fuzzing
CNIT 127 Ch 16: Fault Injection and 17: The Art of Fuzzing
 
CNIT 126 Ch 9: OllyDbg
CNIT 126 Ch 9: OllyDbgCNIT 126 Ch 9: OllyDbg
CNIT 126 Ch 9: OllyDbg
 
CNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgCNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbg
 
Practical Malware Analysis: Ch 15: Anti-Disassembly
Practical Malware Analysis: Ch 15: Anti-DisassemblyPractical Malware Analysis: Ch 15: Anti-Disassembly
Practical Malware Analysis: Ch 15: Anti-Disassembly
 
CNIT 126 8: Debugging
CNIT 126 8: DebuggingCNIT 126 8: Debugging
CNIT 126 8: Debugging
 
CNIT 126 7: Analyzing Malicious Windows Programs
CNIT 126 7: Analyzing Malicious Windows ProgramsCNIT 126 7: Analyzing Malicious Windows Programs
CNIT 126 7: Analyzing Malicious Windows Programs
 
CNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static Techniques
CNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static TechniquesCNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static Techniques
CNIT 126 Ch 0: Malware Analysis Primer & 1: Basic Static Techniques
 
CNIT 152 10 Enterprise Service
CNIT 152 10 Enterprise ServiceCNIT 152 10 Enterprise Service
CNIT 152 10 Enterprise Service
 
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site ScriptingCNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
 
CNIT 123 Ch 10: Hacking Web Servers
CNIT 123 Ch 10: Hacking Web ServersCNIT 123 Ch 10: Hacking Web Servers
CNIT 123 Ch 10: Hacking Web Servers
 
Practical Malware Analysis: Ch 7: Analyzing Malicious Windows Programs
Practical Malware Analysis: Ch 7: Analyzing Malicious Windows Programs Practical Malware Analysis: Ch 7: Analyzing Malicious Windows Programs
Practical Malware Analysis: Ch 7: Analyzing Malicious Windows Programs
 
CNIT 126 9: OllyDbg
CNIT 126 9: OllyDbgCNIT 126 9: OllyDbg
CNIT 126 9: OllyDbg
 
Practical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbgPractical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbg
 
CISSP Prep: Ch 9. Software Development Security
CISSP Prep: Ch 9. Software Development SecurityCISSP Prep: Ch 9. Software Development Security
CISSP Prep: Ch 9. Software Development Security
 

Similar to CNIT 129S Ch 9: Attacking Data Stores (Part 2 of 2)

CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)
CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)
CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)Sam Bowne
 
SQLi for Security Champions
SQLi for Security ChampionsSQLi for Security Champions
SQLi for Security ChampionsPetraVukmirovic
 
The Spy Who Loathed Me - An Intro to SQL Server Security
The Spy Who Loathed Me - An Intro to SQL Server SecurityThe Spy Who Loathed Me - An Intro to SQL Server Security
The Spy Who Loathed Me - An Intro to SQL Server SecurityChris Bell
 
10 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 2015
10 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 201510 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 2015
10 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 2015Scott Sutherland
 
Practical Approach towards SQLi ppt
Practical Approach towards SQLi pptPractical Approach towards SQLi ppt
Practical Approach towards SQLi pptAhamed Saleem
 
Hack your db before the hackers do
Hack your db before the hackers doHack your db before the hackers do
Hack your db before the hackers dofangjiafu
 
Roman Rehak: 24/7 Database Administration + Database Mail Unleashed
Roman Rehak: 24/7 Database Administration + Database Mail UnleashedRoman Rehak: 24/7 Database Administration + Database Mail Unleashed
Roman Rehak: 24/7 Database Administration + Database Mail UnleashedMSDEVMTL
 
Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacksNitish Kumar
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptxKulbir4
 
Dealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NETDealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NETFernando G. Guerrero
 
Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacksKumar
 
Developing on SQL Azure
Developing on SQL AzureDeveloping on SQL Azure
Developing on SQL AzureIke Ellis
 
Web hacking series part 3
Web hacking series part 3Web hacking series part 3
Web hacking series part 3Aditya Kamat
 
Locking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptxLocking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptxDave Stokes
 
Geek Sync | Field Medic’s Guide to Database Mirroring
Geek Sync | Field Medic’s Guide to Database MirroringGeek Sync | Field Medic’s Guide to Database Mirroring
Geek Sync | Field Medic’s Guide to Database MirroringIDERA Software
 
SQL INJECTION
SQL INJECTIONSQL INJECTION
SQL INJECTIONAnoop T
 

Similar to CNIT 129S Ch 9: Attacking Data Stores (Part 2 of 2) (20)

CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)
CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)
CNIT 129S: 9: Attacking Data Stores (Part 2 of 2)
 
SQLi for Security Champions
SQLi for Security ChampionsSQLi for Security Champions
SQLi for Security Champions
 
The Spy Who Loathed Me - An Intro to SQL Server Security
The Spy Who Loathed Me - An Intro to SQL Server SecurityThe Spy Who Loathed Me - An Intro to SQL Server Security
The Spy Who Loathed Me - An Intro to SQL Server Security
 
10 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 2015
10 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 201510 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 2015
10 Deadly Sins of SQL Server Configuration - APPSEC CALIFORNIA 2015
 
Practical Approach towards SQLi ppt
Practical Approach towards SQLi pptPractical Approach towards SQLi ppt
Practical Approach towards SQLi ppt
 
Hack your db before the hackers do
Hack your db before the hackers doHack your db before the hackers do
Hack your db before the hackers do
 
Roman Rehak: 24/7 Database Administration + Database Mail Unleashed
Roman Rehak: 24/7 Database Administration + Database Mail UnleashedRoman Rehak: 24/7 Database Administration + Database Mail Unleashed
Roman Rehak: 24/7 Database Administration + Database Mail Unleashed
 
Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacks
 
Day 6.pptx
Day 6.pptxDay 6.pptx
Day 6.pptx
 
Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacks
 
SQL Injection in JAVA
SQL Injection in JAVASQL Injection in JAVA
SQL Injection in JAVA
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
 
Dealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NETDealing with SQL Security from ADO.NET
Dealing with SQL Security from ADO.NET
 
Sql injection attacks
Sql injection attacksSql injection attacks
Sql injection attacks
 
Developing on SQL Azure
Developing on SQL AzureDeveloping on SQL Azure
Developing on SQL Azure
 
Web hacking series part 3
Web hacking series part 3Web hacking series part 3
Web hacking series part 3
 
Locking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptxLocking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptx
 
Geek Sync | Field Medic’s Guide to Database Mirroring
Geek Sync | Field Medic’s Guide to Database MirroringGeek Sync | Field Medic’s Guide to Database Mirroring
Geek Sync | Field Medic’s Guide to Database Mirroring
 
Google Dorks and SQL Injection
Google Dorks and SQL InjectionGoogle Dorks and SQL Injection
Google Dorks and SQL Injection
 
SQL INJECTION
SQL INJECTIONSQL INJECTION
SQL INJECTION
 

More from Sam Bowne

3: DNS vulnerabilities
3: DNS vulnerabilities 3: DNS vulnerabilities
3: DNS vulnerabilities Sam Bowne
 
8. Software Development Security
8. Software Development Security8. Software Development Security
8. Software Development SecuritySam Bowne
 
4 Mapping the Application
4 Mapping the Application4 Mapping the Application
4 Mapping the ApplicationSam Bowne
 
3. Attacking iOS Applications (Part 2)
 3. Attacking iOS Applications (Part 2) 3. Attacking iOS Applications (Part 2)
3. Attacking iOS Applications (Part 2)Sam Bowne
 
12 Elliptic Curves
12 Elliptic Curves12 Elliptic Curves
12 Elliptic CurvesSam Bowne
 
11. Diffie-Hellman
11. Diffie-Hellman11. Diffie-Hellman
11. Diffie-HellmanSam Bowne
 
2a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 12a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 1Sam Bowne
 
9 Writing Secure Android Applications
9 Writing Secure Android Applications9 Writing Secure Android Applications
9 Writing Secure Android ApplicationsSam Bowne
 
12 Investigating Windows Systems (Part 2 of 3)
12 Investigating Windows Systems (Part 2 of 3)12 Investigating Windows Systems (Part 2 of 3)
12 Investigating Windows Systems (Part 2 of 3)Sam Bowne
 
12 Investigating Windows Systems (Part 1 of 3
12 Investigating Windows Systems (Part 1 of 312 Investigating Windows Systems (Part 1 of 3
12 Investigating Windows Systems (Part 1 of 3Sam Bowne
 
9. Hard Problems
9. Hard Problems9. Hard Problems
9. Hard ProblemsSam Bowne
 
8 Android Implementation Issues (Part 1)
8 Android Implementation Issues (Part 1)8 Android Implementation Issues (Part 1)
8 Android Implementation Issues (Part 1)Sam Bowne
 
11 Analysis Methodology
11 Analysis Methodology11 Analysis Methodology
11 Analysis MethodologySam Bowne
 
8. Authenticated Encryption
8. Authenticated Encryption8. Authenticated Encryption
8. Authenticated EncryptionSam Bowne
 
7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)Sam Bowne
 
7. Attacking Android Applications (Part 1)
7. Attacking Android Applications (Part 1)7. Attacking Android Applications (Part 1)
7. Attacking Android Applications (Part 1)Sam Bowne
 
5. Stream Ciphers
5. Stream Ciphers5. Stream Ciphers
5. Stream CiphersSam Bowne
 
6 Scope & 7 Live Data Collection
6 Scope & 7 Live Data Collection6 Scope & 7 Live Data Collection
6 Scope & 7 Live Data CollectionSam Bowne
 

More from Sam Bowne (20)

Cyberwar
CyberwarCyberwar
Cyberwar
 
3: DNS vulnerabilities
3: DNS vulnerabilities 3: DNS vulnerabilities
3: DNS vulnerabilities
 
8. Software Development Security
8. Software Development Security8. Software Development Security
8. Software Development Security
 
4 Mapping the Application
4 Mapping the Application4 Mapping the Application
4 Mapping the Application
 
3. Attacking iOS Applications (Part 2)
 3. Attacking iOS Applications (Part 2) 3. Attacking iOS Applications (Part 2)
3. Attacking iOS Applications (Part 2)
 
12 Elliptic Curves
12 Elliptic Curves12 Elliptic Curves
12 Elliptic Curves
 
11. Diffie-Hellman
11. Diffie-Hellman11. Diffie-Hellman
11. Diffie-Hellman
 
2a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 12a Analyzing iOS Apps Part 1
2a Analyzing iOS Apps Part 1
 
9 Writing Secure Android Applications
9 Writing Secure Android Applications9 Writing Secure Android Applications
9 Writing Secure Android Applications
 
12 Investigating Windows Systems (Part 2 of 3)
12 Investigating Windows Systems (Part 2 of 3)12 Investigating Windows Systems (Part 2 of 3)
12 Investigating Windows Systems (Part 2 of 3)
 
10 RSA
10 RSA10 RSA
10 RSA
 
12 Investigating Windows Systems (Part 1 of 3
12 Investigating Windows Systems (Part 1 of 312 Investigating Windows Systems (Part 1 of 3
12 Investigating Windows Systems (Part 1 of 3
 
9. Hard Problems
9. Hard Problems9. Hard Problems
9. Hard Problems
 
8 Android Implementation Issues (Part 1)
8 Android Implementation Issues (Part 1)8 Android Implementation Issues (Part 1)
8 Android Implementation Issues (Part 1)
 
11 Analysis Methodology
11 Analysis Methodology11 Analysis Methodology
11 Analysis Methodology
 
8. Authenticated Encryption
8. Authenticated Encryption8. Authenticated Encryption
8. Authenticated Encryption
 
7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)7. Attacking Android Applications (Part 2)
7. Attacking Android Applications (Part 2)
 
7. Attacking Android Applications (Part 1)
7. Attacking Android Applications (Part 1)7. Attacking Android Applications (Part 1)
7. Attacking Android Applications (Part 1)
 
5. Stream Ciphers
5. Stream Ciphers5. Stream Ciphers
5. Stream Ciphers
 
6 Scope & 7 Live Data Collection
6 Scope & 7 Live Data Collection6 Scope & 7 Live Data Collection
6 Scope & 7 Live Data Collection
 

Recently uploaded

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Recently uploaded (20)

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

CNIT 129S Ch 9: Attacking Data Stores (Part 2 of 2)

  • 1. CNIT 129S: Securing Web Applications Ch 9: Attacking Data Stores Part 2 of 2
  • 3. Avoiding Blocked Characters • App removes or encodes some character s • Single quotation mark is not needed for injection into a numerical fi el d • You can also use string functions to dynamically construct a string containing fi ltered characters
  • 4. CHR or CHAR Function • These queries work on Oracle and MS-SQL, respectively
  • 5. Comment Symbol Blocked • Code i s SELECT * from users WHERE name='uname ' • Try injecting this value for name : ' or 1=1 - - • To creat e SELECT * from users WHERE name='' or 1=1 -- ' • But the "--' is blocked
  • 6. Correct Syntax Without Comment • Injecting this value for name : ' or 'a'=' a • To creat e SELECT * from users WHERE name='' or 'a'='a'
  • 7. Circumventing Simple Validation • If "SELECT" is blocked, try these bypasses:
  • 8. Using SQL Comments • If spaces are blocked, use comments instea d • MySQL allows comments within keywords
  • 9. Second-Order SQL Injection • Many applications handle data safely when it is fi rst entered into the databas e • But it may later be processed in unsafe ways
  • 10. App Adds a Second Quote • Register an account with this name : foo ' • The correct way to insert that value is by adding a second quote (link Ch 2a ) INSERT INTO users (username, password, ID, privs) VALUES ('foo''', 'secret', 2248, 1)
  • 11. Password Change • Requires user to input old password, and compares it to the password retrieved with : SELECT password FROM users WHERE username = 'foo' ' • This is a syntax error.
  • 12. Exploit • Register a new user with this name : ' or 1 in (SELECT password FROM users WHERE username = 'admin')- - • Perform a password change, and MS-SQL will return this error, exposing the administrator password
  • 13. Advanced Exploitation • The previous attacks had a ready means of exposing dat a • Adding UNION to a query that returns the result s • Returning data in an error message
  • 14. Denial of Service • Turn off an MS-SQL databas e ' shutdown- - • Drop tabl e ' drop table users--
  • 15. Retrieving Data as Numbers • No strings fi elds may be vulnerable, because single quotes are fi ltere d • Numeric fi elds are vulnerable, but only allow you to retrieve numerical value s • Use functions to convert characters to numbers
  • 16.
  • 17. Using an Out-of-Band Channel • You can inject a query but you can't see the result s • Some databases allow you to make a network connection inside the query language
  • 18. MS-SQL 2000 and Earlier
  • 19. Oracle • UTL_HTTP makes an HTTP reques t • Attacker can use a netcat listener
  • 20. Oracle • DNS request is even less likely to be blocked
  • 21. MySQL • To retrieve the fi le, set up an SMB share on your serve r • Alowing anonymous write access
  • 22. Leveraging the Operating System • Sometimes you can get the ability to execute shell command s • Such as by using a PHP shel l • Then you can use built-in commands like • tftp, mail, telne t • Or copy data into a fi le in the Web root so you can retrieve it with a browser
  • 23. 9b-1
  • 24. Conditional Responses: "Blind SQL Injection" • Suppose your query doesn't return any data you can see, an d • You can't use an out-of-band channel to ex fi ltrate dat a • You can still get data, if there's any detectable behavior by the database that depends on your query
  • 25. Example • Put in this text for username, and anything for passwor d admin' - - • You'll be logged in as admin
  • 26. True or False? • This username will log in as admin : admin' AND 1=1- - • This one will not log i n admin' AND 1=2--
  • 27. Finding One Letter • This username will log in as admin : • This one will not log i n
  • 28. Inducing Conditional Errors • On an Oracle database, this query will produce an error if the account "DBSNMP" exist s • If it doesn't, the "1/0" will never be evaluated and it won't cause an error
  • 30. Using Time Delays • MS-SQL has a built-in WAITFOR comman d • This query waits for 5 seconds if the current database user is 'sa'
  • 31. Conditional Delays • You can ask a yes/no question and get the answer from the delay
  • 32. Testing Single Bits • Using bitwise AND operator & • And the POWER command
  • 33. MySQL Delays • Current versions have a sleep functio n • For older versions (prior to 5.0.12), use benchmark to repeat a calculation many times
  • 34. Oracle • No function to cause a delay, but you can use URL_HTTP to connect to a non-existent serve r • Causes a delay until the request times out
  • 35. Oracle • This query causes a timeout if the default Oracle account "DBSNMP" exists
  • 36. Beyond SQL Injection: Escalating the Database Attack
  • 37. Further Attacks • SQL injection lets you get the data in the database, but you can go furthe r • If database is shared by other applications, you may be able to access other application's dat a • Compromise the OS of the database serve r • Pivot: use the DB server to attack other servers from inside the network
  • 38. Further Attacks • Make network connections back out to your own computer, to ex fi ltrate data and evade IDS system s • Extend database functionality by creating user-de fi ned function s • You can reintroduce functionality that has been removed or disable d • Possible if you get database administrator privileges
  • 39. MS-SQL • xp_cmdshell stored procedur e • Included by defaul t • Allows DBA (Database Administrator) to execute shell commands
  • 40. MS-SQL • Other stored procedures also allow powerful attack s • These read and write to the Registr y • xp_regread & xp_regwrite
  • 41. Dealing with Default Lockdowns • MS-SQL 2005 and later disable xp_cmdshell by default, but you can just enable it if you are DBA
  • 42. MySQL • load_ fi le allows attacker to read a fi l e • "into out fi le" allows attacker to write to a fi l e • This example makes all hosts trusted on Linux
  • 46. 9b-2
  • 48. Blocking Apostrophes • Won't stop injection into numerical fi eld s • If you allow apostrophes into data fi elds by doubling them, you can have second-order SQL injection vulnerabilities
  • 49. Stored Procedures • Makes code re-use easie r • But doesn't prevent SQL injection if user input is included in a parameter
  • 50. Stored Procedures • Developer de fi nes a procedur e • Attacker can still inject with this passwor d • Resulting query
  • 52. Vulnerable Code • User input inserted into a command, which is parsed later to match quotes
  • 53. Parameterized Version • User input replaces placeholder "? " • No parsing required, not vulnerable to SQLi
  • 54. Provisos • Use parameterized queries for EVERY quer y • Not just the ones that are obviously user- controllabl e • Every item of data should be parameterize d • Be careful if user data changes table or column name s • Allow only values from a whitelist of known safe value s • You cannot use parameter placeholders for other parts of the query, such as SORT BY ASC or SORT BY DES C • If they must be adjusted, use whitelisting
  • 55. Defense in Depth • Application should use low privileges when accessing the database, not DB A • Remove or disable unnecessary functions of D B • Apply vendor patche s • Subscribe to vulnerability noti fi cation services to work around new, unpatchable vulnerabilities
  • 57. NoSQL • Doesn't require structured data like SQ L • in SQL, fi elds must be de fi ned in a Schema, as Text, Number, etc . • In NoSQL, keys and values can be arbitrarily de fi ne d • A new and less mature technology than SQL
  • 58.
  • 60. Injection • Log in with this username, and any passwor d Marcus'/ / • Javascript function becomes this:
  • 61. Another Injection • Log in with this username, and any passwor d • This is always true (link Ch 9b)
  • 62. Injecting into XPATH • XML Data 
 Store
  • 63.
  • 64. Injection • This query retrieves a stored credit card number from a username and passwor d • This injection:
  • 65. Finding XPATH Injection Flaws • These strings usually break the synta x • These strings change behavior without breaking syntax
  • 66. Preventing XPATH Injection • Filter inputs with a whitelis t • Remove these characters
  • 67. LDAP • Lightweight Directory Access Protocol (LDAP ) • Used to store names, phone numbers, email addresses, etc . • Used in Microsoft Active Director y • Also in OpenLDAP
  • 68. LDAP Queries • Match a usernam e • Match any one of these condition s • Match all of these conditions
  • 69. LDAP Injection Limitations • Possible, but less exploitable becaus e • Logical operators come before user-supplied data, so attacker can't form "or 1=1 " • Directory attributes to be returned are hard- coded and can't usually be manipulate d • Applications rarely return informative error messages, so exploitation is "blind"
  • 70. 3