WebSec Flashcards
Cross-Site Request Forgery
- user logs into bank and gets a session cookie
- user visits another malicious website that does CSRF:
e.g:
form name=”transfer”
action=”http://bank.com/Transfer.php”
input name=”recipient” value=”badguy” /input name=”amount” value=”100000”> /form
script document.transfer.submit(); /script - browser send cookie and payment fulfilled
Anti-CSRF Token
- includes with every form a random token
- server process only with valid right token
Referrer Validation
- check if it’s right URL
- > still head might be suppressed
Double Submit Cookies
- gives user 2 cookies
- session and anti-CSRF cookie
- sends anti-CSRF cookie in hidden form field
- > cookie tossing is possible; if attack controls subdomain he might set token value
Custom Request Header
- makes a costume XMLHttpRequest headers
- > applications would have to be changed significantly
Cross-site Scripting (XSS)
Server Client
Reflected user must visit malicious link
no change to server
XSS Mitigation
- use safe library’s
- sanitise input
- detect client side XSS by paterns
HttpOnly Cookies
- sends over HTTP(S) cookie which then can’t be accessed by document.cookie
Content Security Policy (CSP)
- CSP controls what/from where content can be added
- CSP by default disables inline script and style attributes
e.g.
script-src ‘self’: Only allow JavaScript per files from same origin
img-src ‘self’ img.com: Only allow images from same origin and img.com
Command Injection in PHP
e. g.
http: //victim.com/calc.php?number=5 -> 5 user input
http: //victim.com/calc.php?number=5; system(‘rm .’);
SQL Injection
e.g.
normal:
SELECT pizza, toppings, quantity, order_day
FROM orders
WHERE userid=4123 AND order_month=10
malicious:
SELECT pizza, toppings, quantity, order_day
FROM orders
WHERE userid=4123 AND order_month=0 OR 1=1
Blind SQL Injection
- if feedback from DB table is invisible to attacker
- has to use side channel to learn result
Preventing SQL Injection
- use prepared statements
- most times problem is that user code is interpreted as programming code
- use placeholders to guaranteed to be data