SQL Injection is an injection flaw where a web application allows a user to send un-sanitized input into a SQL query.
The textbook example is that a web application has a username field that inserts the user’s input into the following SQL query:
statement = "SELECT * FROM users WHERE name = '" + userName + "';"
The user then types
a' or '1'='1 into the username field. This creates the following SQL statement:
SELECT * FROM users WHERE name = 'a' or '1'='1'
If the statement variable is used for the authentication procedure then the evaluation of the SQL statement will always be true.
An attacker can cause damage if they appended something like,
'; DROP TABLE users;--
This would produce the following SQL statement:
statement = "SELECT * FROM users WHERE name = ''; DROP TABLE users;--';
Which would result in the users table being deleted from the Database.
When developing a security strategy for web applications many companies have no idea where to begin. The Open Web Application Security Project (OWASP) understood this problem and developed the OWASP Top 10.
The OWASP top 10 are the top 10 vulnerabilities that are found in web applications. This will begin a 10-part series dedicated to each of these vulnerabilities.
If you are a developer, you should understand these vulnerabilities. Understanding them is critical into introducing less vulnerabilities into your code.
The OWASP Top 10:
A1 – Cross Site Scripting (XSS)
A2 – Injection Flaws
A3 – Malicious File Execution
A4 – Insecure Direct Object Reference
A5 – Cross Site Request Forgery (CSRF)
A6 – Information Leakage and Improper Error Handling
A7 – Broken Authentication and Session Management
A8 – Insecure Cryptographic Storage
A9 – Insecure Communications
A10 – Failure to Restrict URL Access
Posted in Buzzwords, Compliance, OWASP, Primer, Vulnerabilities, Web Application Security
Tagged Broken Authentication, Business Needs, Compliance, CSRF, Failure to Restrict URL Access, General Security, Improper Error Handling, Information Leakage, Injection Flaws, Insecure Communications, Insecure Cryptographic Storage, Insecure Direct Object Reference, internet security, Malicious File Execution, OWASP, security, security software, Threats, Vulnerabilities, Web Application Security, XSS
Photo: B.G. Lewandowski
Why did you just click that link? Most likely you have came to this site by clicking a link from another site. Why did you do that? Did you trust the person who sent you the link? Did you click a link from Twitter, Facebook, or an email someone sent you?
When you click a link, you are telling your browser, “I trust this person.” However, this is not the way we use the Internet. We click on links all the time. We click on links from “untrusted” sources. We click links from people we don’t know and we even click on URL’s that have been modified. On Twitter, a person is much more inclined to click the shortened link http://bit.ly/5hXRW then they are to click http://somewherebank.com/transfer.jsp?amount=1000&to_account=56777564. Even though the shortened link could redirect to the somwherebank.com site.
But, why would someone trick you into clicking a cleverly disguised link? The site that you are redirected to may seem harmless. It could also be extremely malicious.
What happens if this page, (the one you are currently viewing), was filled with Cross-Site Request Forgery (CSRF) links? This web page could be setup with all types of malicious intent. However, you didn’t know that when clicking the link. Now, it is too late.
If this site did have Cross-Site Requests, I could do things such as:
- Change the password on your Facebook account
- Transfer the money from your on-line bank account to another account
- Enact trades from a financial institution such as E*Trade
The sites that I exploit would have to be vulnerable to CSRF. But researchers, such as Mike Bailey and Russ McRee, are constantly finding CSRF vulnerabilities in web applications.
An example of how clicking links from untrusted sources is never good was demonstrated in Billy Rios and Nitesh Dhanjani, Bad Sushi talk. In their presentation they described sending phishers a word document stating their account numbers were inside. They sent this email to 25 known phishers. 10 of the phishers opened the word document and were presented with this. In addition, there was another link that said, “Actually, my account information is here.” 3 of the 10 clicked on that link. Even the phishers click links they shouldn’t.
What should be done? Who knows. It is human nature to trust people and we can’t get things done if every time someone sends us a link we open up a VMware image to view a link. So continue using the Internet the way you have been and remember, “These aren’t the droids your looking for.”
Today, I thought I would post great resources for information. If you want to be good at security, it means you need to be well read.
Here are the top five web application security blogs in no particular order.
- Jeremiah Grossman – Probably the most read web application security blogger. Jeremiah reads all of the material so you don’t have too.
- Rsnake / Robert Hansen – The other most read web application security blogger. Interesting Note: Graduated my alma mater.
- Holistic InfoSec – Russ McRee’s blog. Russ puts people on the stove. He posts are controversial and exciting. According to ISS, Russ was one of the Top Vulnerability Discoverers in 2008. Keep an eye on him, it is interesting to see what he will do next.
- Billy Rios – Also known as the XS-Sniper! Billy is behind some of the most innovative research as of late. He is the man behind Gifars and URI overflows. He is also known to smuggle olives on occasion.
- Nitesh Dhanjani – Although he covers a wide range of topics outside of web application security, Nitesh continually blogs about topics that are thought-provoking.
If it hasn’t already, Cross-Site Scripting (XSS) will soon be replacing SQL injection as the new buzzword in the security sector. XSS will continually be a topic on this blog as well as others ,,,. Due to this fact, I think a primer would be a good idea for those who don’t know or understand this problem.
Many articles have been written about Cross-Site Scripting and if you want to have a better understanding of the problem, I suggest you read those documents (Links at the bottom of the post).
Basically, There are 3 types of Cross-Site Scripting:
- Stored/Non-Reflective/Persistent Cross Site Scripting (User visits the XSS’ed page)
- Non-Stored/Reflective/Reflected Cross Sited Scripting (User clicks a link that embeds the script into the loaded page)
- DOM Based Cross Site Scripting (please read this article)
All of these names make it confusing for a first timer to understand XSS. There really should be a better web application security standards organization. Here is a breakdown of Persistent XSS and Reflective XSS. These are the big two that most people talk about when they are referring to Cross Site Scripting. If you understand these well, you will be able to participate in 90% of XSS conversations.
Persistent Cross-Site Scripting
Persistent XSS is arguably more dangerous than reflective XSS. This attack embeds the malicious script permanently into the web application. The script will then wait until people access the page it is located on.
Here is an attack using Persistent Cross-Site Scripting:
- The victim visits a website they trust, amazon.com.
- A script has been inserted by an attacker on a page they happen to visit while on amazon.com.
- The script executes in the context of amazon.com.
- The victim is then compromised.
Note: Obviously, someone can increase the chances of the victim visiting this page (step 2) through social engineering, phishing, etc.
Reflective Cross-Site Scripting
These are the ones the media usually reports on. ,,. In this attack, some type of social engineering is involved for the attack to be successful.
Here is an attack, using Reflective Cross-Site Scripting:
- The victim gets an email/Instant Message that contains a link.
- The victim clicks the link. (Requires User Intervention)
- A script has been inserted by an attacker on the page they then visit.
- The script executes in the context of that site.
- The victim is then compromised.
Note: I want to reiterate that this attack requires some type of user intervention (step 2).
Why is Cross-Site Scripting Bad?
Cross-Site Scripting can lead to all sorts of different exploits, including system compromise. For an attacker to do this, they need to break out of the browser’s context. We have seen examples that breaking out of the browser is not that hard to do.
In addition, an attacker can also establish a bi-directional channel using iframes. This creates a man-in-the-middle attack. The attacker can then intercept key strokes, use the victim as an intranet portscanner, and even stealing creditials. The attacker is only limited by their knowledge of scripting.
Example of a bi-directional channel
Hopefully, this gives you a better understanding of Cross-Site Scripting. Feel free to leave comments if you don’t understand something and I will address it in the article.
Cross-Site Scripting (XSS) FAQ
OWASP Guide to XSS
XSS Video Tutorial (via youtube)
XSS Attack API
Posted in Buzzwords, OWASP, Primer, Vulnerabilities, Web Application Security
Tagged Buzzword, Compliance, Cross-Site Scripting, Non-Persistent, Persistent, Reflect, Reflective, Reflexive, Stored XSS, Technology, Threats, Vulnerabilities, Web Application Security, XSS