14 Web Security
14 Web Security
Major vulnerabilities:
• Injection
• Cross Site Request Forgery (CSRF)
• Cross Site Scripting (XSS)
Injection attack
Injection: Untrusted data is sent to an interpreter as a part of
the command or query
• Code Injection
• SQL Injection
Code Injection
• An attacker could provide malicious code as an input to
the web server.
• If the web server is not careful about checking user
inputs, it may affect by Code Injection.
• For example, if a user types 2+3 into the website, the
server will run eval(‘2+3’) and return the result to the
user.
Code Injection
Course_rating
id course rating
1 CS101 4.5
2 CS201 4.4
3 CS301 4.6
http://www.Course.edu/Course_rating?course=CS101
Next, we need to add some SQL syntax so that this query returns more than 0 rows.
One trick for forcing a SQL query to always return something is to add some logic
that always evaluates to true, such as OR 1=1:
SELECT username FROM users WHERE username = 'User1' OR 1=1' AND password = '_____'
SQL Injection
Next, we have to add some SQL so that the rest of the query doesn’t throw a syntax
error.
One way of doing this is to add a semicolon (ending the previous query) and write a
dummy query that matches the remaining SQL:
• Escape inputs
• Use parameterized/prepared SQL
• Use ORM framework