SQL Smuggling The Attack That Wasn’t There

OWASP Israel 2007 December 3rd

Avi Douglen Senior AppSec Consultant Comsec Global [email protected] Based on http://www.ComsecGlobal.com/Research/SQL_Smuggling.pdf

Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License.

The OWASP Foundation http://www.owasp.org

OWASP

2

Agenda SQL Injection Revisited Classic Smuggling Introducing SQL Smuggling Common SQL Smuggling Unicode Unicode Smuggling Applicability Recommendations and Conclusions

OWASP

3

OWASP SQL Injection Revisited Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License.

The OWASP Foundation http://www.owasp.org

SQL Injection Basics Well known attack against DB Main cause: Lack of data validation Causes input to “break out” of query Most often based on special characters E.g. E.g. Quote (‘) to terminate strings

Rest of string seen as SQL commands

OWASP

5

Prevention Mechanisms Data validation Stored Procedures Parameterized queries Command / Parameter objects Strongly Strongly typed API

Least Privilege

OWASP

6

Data Validation Best to limit input to specific format E.g. 9 digits for Id Email address Etc.

Can use Regular Expressions But not always possible Sometimes need to accept free text E.g. comments, forums, etc

OWASP

7

Parent Injection – Exploits of a Mom

OWASP

8

Data Validation Ensure parameter types E.g. numeric fields must be numeric

Size Range E.g. 0 < age < 120

Escape special characters E.g. Quotes

Block SQL keywords E.g. UNION SELECT, INSERT etc. OWASP

9

Data Validation Best Practice: Whitelist allowed patterns Don’t Blacklist blocked patterns/characters Never complete Hard to maintain May affect performance…

Blacklist not best – but can block attacks Assuming specific attack was defined

BUT…. Does it work??

OWASP

10

OWASP Classic Smuggling Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License.

The OWASP Foundation http://www.owasp.org

The Beerbelly…

OWASP

12

General Smuggling Attacks Based on sneaking data where prohibited Smuggling avoids detection or prevention Even against mechanisms that look for it

Bad data looks good Malicious data does not yet exist At least not in context of validation

Cannot be detected with standard checks By definition

OWASP

13

HTTP Request Smuggling Discovered by Amit Klein et al. in 2005 Based on discrepancies in parsing HTTP Differences in handling malformed requests Attacker can bypass protection mechanisms Causes Causes devices to “see” different requests Usually not detected by IDS/IPS, WAF …

OWASP

14

OWASP Introducing SQL Smuggling http://www.ComsecGlobal.com/Research/SQL_Smuggling.pdf Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License.

The OWASP Foundation http://www.owasp.org

Definition SQL Injection that evades detection Even when searched for

Exploits differences of interpretation Attack does not exist in validation context Accepted by DB server as valid

OWASP

16

Characteristics Malicious strings not present Cannot be found by validation WAF and IDS/IPS mostly do not help Application checks do not work Evades Evades Blacklists May be mitigated by architecture / design

OWASP

17

OWASP

18

OWASP Common SQL Smuggling Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License.

The OWASP Foundation http://www.owasp.org

Platform-Specific Syntax Non-standard extensions to ANSI SQL Might not be recognized by validations E.g. MySQL backslash (“\”) escaping Simply doubling quotes doesn’t work: “\’” translates to “\’’” MySQL sees: “\’’”

E.g. Who blocks [MS-SQL] OPENROWSET?

OWASP

20

Signature Evasion Many validations search for known strings E.g. INSERT, DELETE, UNION SELECT, etc.

Numerous ways to evade patterns Innovative use of whitespace Inline comments (using /*…*/) Different encodings Dynamic concatenation/execution of strings  E.g. CHAR() or "EXEC ('INS' + 'ERT INTO…')"

OWASP

21

OWASP Unicode Smuggling Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License.

The OWASP Foundation http://www.owasp.org

Homoglyphs Many Unicode characters “look like” others E.g. Ā (U+0100) is similar to A (U+0041) Stronger homoglyphs look identical

Visually misleading Can be dependant on font

Usually mentioned as user-misdirection Referred to in context of IDNs

OWASP

23

OWASP

24

Character Set Support Servers can support translation from Unicode to Localized character sets Local charsets do not contain all Unicode E.g. Ā not in Windows-1255 E.g. ‫( א‬U+05D0) not in latin1

So what happens?

OWASP

25

Homoglyphic Transformation If a character is “forced” to local charset: Error Character is dropped Automatic translation

Translation occurs if similar character exists Based on “best fit” heuristic E.g. Ā is forced to A

OWASP

26

But Ā is not A!

OWASP

27

Exploit Scenario Attacker sends U+02BC Application/WAF search for quote U+0027 Does not exist! Database “forces” input to local charset U+02BC U+02BC  quote… on the database! Now there’s quote, get some SQL Injection!

OWASP

28

Analysis Characters created by DB Quote does NOT exist before Can bypass filters and get a quote to DB Same with many other characters Can’t Can’t find a quote if it’s not there Validation CANNOT work!

OWASP

29

OWASP Applicability Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License.

The OWASP Foundation http://www.owasp.org

So, How Common IS This? Well, not very… BUT it does exist Originally discovered at client

OWASP

31

Unicode-based Smuggling Depends on: Dynamic SQL concatenation (can be in SP) Validation based on Blacklists Unicode forced into local charset DB support of homoglyphic transformation…  So far:  MS-SQL  MySQL Connect/J (old version)

OWASP

32

On The Other Hand… SQL Smuggling is more common Aspects exist in most systems It is likely there are other issues to be discovered Most blacklists can be penetrated

OWASP

33

OWASP Recommendations & Conclusion Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License.

The OWASP Foundation http://www.owasp.org

Recommendations Context-based validation Relate to DB attributes

White-list known characters Avoid any dynamic SQL Do not translate character sets See http://www.ComsecGlobal.com/Research/ SQL_Smuggling.pdf for more information

OWASP

35

Conclusion Input validation is not always enough SQL Smuggling can get through Blacklists don’t work Besides being inefficient

Best Practices are there for a reason! Time to look at the DB platform a little more closely…

OWASP

36

Thank you! http://www.ComsecGlobal.com/ Research/SQL_Smuggling.pdf

Questions? [email protected]

OWASP

37

Unicode Smuggling or SQL Smuggling - owasp

>E.g. 9 digits for Id. >Email address. >Etc. ▫Can use Regular Expressions .... >Automatic translation. ▫Translation occurs if similar character exists. OWASP. 26.

1MB Sizes 22 Downloads 256 Views

Recommend Documents

Download PDF Global Human Smuggling ...
EBOOK Scienza delle conseguenze - Luca De Biase - Book,Download PDF Contention and Corporate Social Responsibility - Sarah A. Soule - Book,FB2 ...

alledged smuggling of turtle eggs.pdf
alledged smuggling of turtle eggs.pdf. alledged smuggling of turtle eggs.pdf. Open. Extract. Open with. Sign In. Details. Comments. General Info. Type. Dimensions. Size. Duration. Location. Modified. Created. Opened by me. Sharing. Description. Downl

pdf-1270\forbidden-creatures-inside-the-world-of-animal-smuggling ...
Try one of the apps below to open or edit this item. pdf-1270\forbidden-creatures-inside-the-world-of-animal-smuggling-and-exotic-pets-by-peter-laufer.pdf.

NET Reverse Engineering - owasp
Exploiting ANY server / application vulnerability to execute commands. • Example application has a vulnerability that let us to access the file system.

unicode explained pdf
Loading… Whoops! There was a problem loading more pages. Retrying... Whoops! There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. unicode explained pdf. unicod

pdf unicode characters
Page 1. Whoops! There was a problem loading more pages. pdf unicode characters. pdf unicode characters. Open. Extract. Open with. Sign In. Main menu.

Gita-Unicode-Bengali.pdf
Page 1. Whoops! There was a problem loading more pages. Retrying... Gita-Unicode-Bengali.pdf. Gita-Unicode-Bengali.pdf. Open. Extract. Open with. Sign In.

OWASP Testing Guide v4.pdf
A Typical SDLC Testing Workflow. 22 - 24. 3. Web Application Security Testing. Introduction and Objectives. Testing Checklist. Information Gathering. Conduct ...

Hindi Unicode to ANSI Converter
... by Maxi and Billo Maxi accoustic guitar Billo lead Kasady violin M & B Martin ... In good hands, it can be a powerful automation tool, not just for converting ...

owasp zap tutorial pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. owasp zap ...

owasp code review guide pdf
Download now. Click here if your download doesn't start automatically. Page 1 of 1. owasp code review guide pdf. owasp code review guide pdf. Open. Extract.

owasp code review guide pdf
owasp code review guide pdf. owasp code review guide pdf. Open. Extract. Open with. Sign In. Main menu. There was a problem previewing this document.

Simon Bennetts - OWASP AppSec Research (AppSecEU) 2015
ZAP (desktop) properties. 13. Database. Data Structures. Processes. Deployment. Users. Roles. Access. Application Lifetime. Licence. Local HSQLDB. Db and ...

Simon Bennetts - OWASP AppSec Research (AppSecEU) 2015
ZAP (desktop) properties. 13. Database. Data Structures. Processes. Deployment. Users. Roles. Access. Application Lifetime. Licence. Local HSQLDB. Db and ...

Ucto: Unicode Tokeniser Reference Guide - GitHub
Available from http://ilk.uvt.nl/downloads/pub/papers/ilk.1205.pdf”. For information about ... The e-mail address for problems with the installation, bug reports, comments and questions is .... .

The Unicode Standard, Version 7.0 -
Range: 1C50–1C7F. This file contains an excerpt from the character code tables and list of character names for. The Unicode Standard, Version 7.0. This file may be changed at any time without notice to reflect errata or other updates to the Unicode

pdf to text unicode
Loading… Whoops! There was a problem loading more pages. Retrying... Whoops! There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. pdf to text unicode. pdf to t

Why does Java use Unicode?
ClassCastException. Invalid cast. IllegalArgumentException. Illegal argument used to invoke a method. IllegalMonitorStateException. Illegal monitor operation, such as waiting on an unlocked thread. IllegalStateException. Environment or application is

Unicode Arabic - UFB50.pdf
This file contains an excerpt from the character code tables and list of character .... FC46. FC47. FC48. FC49. FC4A. FC4B. FC4C. FC4D. FC4E. FC4F. FC50.

Unicode block preview (XeTeX version 0.99999) - GitHub
1. Basic Latin (U+0-U+7F). 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. A. B. C. D. E. F. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 1A. 1B. 10. 1D. 1E. 1F. U+0. U+20. ; ? N. G. ) U+40 ...... FS Met @ 圈 u B x 23 留 s 8.马圈. 5C H W8 @ 留. 9召spe图. SAN 多图.

Simon Bennetts - OWASP Zed Attack Proxy.pdf
Page 2 of 14. The Introduction. • The statement. • You cannot build secure. web applications unless you. know how to attack them. • The problem. • For many ...

Presentación - OWASP-FLISOL-2014.pdf
Paraguay. (EC-Council es conocido principalmente como un. organismo de certificación profesional en el área. de seguridad de la información. Su certificación. más conocida es el CEH-Certified Ethical Hacker,. entre otras). Page 3 of 18. Presenta