Chapt5 OWASP SQL XSS EH
Chapt5 OWASP SQL XSS EH
and XSS
Open Web Application Security Project
(OWASP)
• The Open Web Application Security Project (OWASP) is an
open community dedicated to enabling organizations to
develop, purchase, and maintain applications that can be
trusted.
• Types of Preventions:
1. Use a safe API which avoids the use of the interpreter
entirely or provides a parameterized interface.
2. Carefully escape special characters using the specific
escape syntax for that interpreter.
3. Positive or “white list” input validation, but this is not a
complete defense as many applications require special
characters in their input.
How it works and why
• “The vulnerability happens when user input is either incorrectly
filtered for string literal escape characters embedded in SQL
statements or user input is weakly typed and unexpectedly executed.”
• Look for the “php?id=5” note: can be any number after the = sign.
• Now type an invalid string literal escape character after the last
character in the URL, in this case after the “5”. An apostrophe ‘ or
pound sign # are recommended.
In both cases, the attacker modifies the ‘id’ parameter value in their browser to
send: ' UNION SLEEP(10);--. For example:
http://example.com/app/accountView?id=' UNION SELECT
SLEEP(10);--
This changes the meaning of both queries to return all the records from the
accounts table. More dangerous attacks could modify or delete data or even invoke
stored procedures.
Step Two: Choose method of injection
• There are many ways to launch an SQL injection. Here are two common
ones.
• SQL Tag Injection: Type a pound sign (#) into the websites URL followed
by malicious code. SQL tags use a format like this:
• #TABLE1_SELECT_ROW2ksd9204255nazx
• If you know SQL than you can give the table commands remotely,
including pasting in source code for viruses.
• This method is more flexible and allows a wider range of options, yet for
simplicity sake we will use a second option.
• You now have full reign over an SQL database. What you do with the
database is up to you. You can access and edit the database like any
other user, except that you have to hack in again (unless you inject a
script that opens a backdoor to the database you can use).
• For more information on what you can do once inside, refer to the
following:
• http://www.unixwiz.net/techtips/sql-injection.html
How to Defend?
How to avoid SQL Injection
• Reflected: The injected code will be send to the server via HTTP
request. The server embed the input with the html file and return
the file (HTTP Response) to browser. When the browser executes
the HTML file, it also execute the embedded script.
•
Step Two
• Testing the Exploit:
• First find a data entry point, like a search box or a
username/password field.
• Type a String into the field and click view source. Look for
something like “<p>Hello myString </p>” this is the format we
want to see.
• Types of Preventions:
1. Encoding – Escaping any character a user enters before
displaying it
2. Whitelisting – Only allow certain characters (e.g. A-Z and
0-9) to be entered
3. Blacklisting – Not allowing a user to enter sequences such
as <script> or <and>
References
• https://www.owasp.org/index.php/Top_10
• https://www.owasp.org/index.php/SQL_Injection
• https://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet
• http://www.unixwiz.net/techtips/sql-injection.html
• https://www.owasp.org/index.php/Testing_for_Cross_site_scripting
• https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet
• http://msdn.microsoft.com/en-us/library/a2a4yykt(v=vs.85).aspx