軟體弱點掃描

55
軟軟軟軟軟軟軟軟 軟軟 軟軟軟軟 -體 報報報報報報 2015/08/07 Docs https ://doc.co/fDKqw8

Upload: rainmaker-ho

Post on 16-Apr-2017

57 views

Category:

Software


0 download

TRANSCRIPT

Page 1: 軟體弱點掃描

軟體開發測試實務研習-軟體弱點掃描報告人:亂馬客日 期: 2015/08/07Docs : https://doc.co/fDKqw8

Page 2: 軟體弱點掃描

2

Agenda Why Tools 常見問題

SQL Injection Cross Site Scripting(XSS) Misconfiguration Hash Insecure direct object reference

Page 3: 軟體弱點掃描

3

WHY?

Page 4: 軟體弱點掃描

4

SonyPicture.com

Over 1,000,000 users’s personal information, Including passwords, email, home address, …..

Page 6: 軟體弱點掃描

6

Page 8: 軟體弱點掃描

8

Tools

Page 9: 軟體弱點掃描

9

人肉搜索 - Wireshark

Page 10: 軟體弱點掃描

10

人肉搜索 - Fiddler

Page 11: 軟體弱點掃描

11

開發工具 -VS.NET

Page 12: 軟體弱點掃描

12

開發工具 -VS.NET

Page 13: 軟體弱點掃描

13

白箱工具 - Checkmarx

Page 14: 軟體弱點掃描

14

黑箱工具 - AppScan

Page 15: 軟體弱點掃描

15

白名單 ? 請帖

Page 16: 軟體弱點掃描

16

黑名單 ? 通緝令

Page 17: 軟體弱點掃描

17

常見問題 SQL Injection Cross Site Scripting(XSS) Misconfiguration Hash Insecure direct object reference

Page 18: 軟體弱點掃描

18

SQLInjectio

n

Page 19: 軟體弱點掃描

19

SQL Injection 體驗 http://goo.gl/53RTpt

點選任一個分類 將值改成 3 ( 有 22 筆資料 )

?ProductSubCategoryId=3 再將值改成 3 or 0 = 0 ( 有 504 筆資料 )

?ProductSubCategoryId=3 or 0=0

Page 20: 軟體弱點掃描

20

SQL Injection 體驗 -2 將值改成 r

?ProductSubCategoryId=r

Page 21: 軟體弱點掃描

21

SQL Injection 體驗 -3 Blind 攻擊 找出 Table Name

?ProductSubCategoryId=(SELECT name FROM sysobjects WHERE id = (SELECT TOP 1 id FROM (SELECT TOP 1 id FROM sysobjects WHERE xtype=CHAR(85) ORDER BY id) sq ORDER BY id desc))

改成 2, 3 ….

Page 22: 軟體弱點掃描

22

SQL Injection 體驗 -4 Blind 攻擊 找出 Column Name

?ProductSubCategoryId=(SELECT COL_NAME((SELECT TOP 1 id FROM (SELECT TOP 3 id FROM sysobjects WHERE xtype=CHAR(85) ORDER BY id) sq ORDER BY id desc), 3) )

Page 23: 軟體弱點掃描

23

SQL Injection 體驗 -5 取得 信用卡號 (Table:CreditCard, Column:

CardNumber) ?ProductSubCategoryId=(SELECT TOP 1

CardNumber FROM dbo.CreditCard )

Page 24: 軟體弱點掃描

24

SQL Injection 體驗 -7 字串的也可以哦 !

點選「 Search 」 輸入 a ,可以查出 a 開頭的產品 輸入 a’or 1=1 -- ,就可以查出所有的產品

常使用在 Login 的畫面

Page 25: 軟體弱點掃描

25

SQL injection

http://tdd-2012-1/injection/Product.aspx?ProductSubCategoryId = 1

SELECT * FROM Product WHERE ProductSubCategoryID = 1

Trusted

Untrusted

Page 26: 軟體弱點掃描

26

Source of untrusted data From the user

URL via a query string or route Posted via a form

From the browser Cookies Request headers

From other locations External services database

Page 27: 軟體弱點掃描

27

Approaches to whitelisting Type conversion

Int, date, GUID … Regular expression

Email, phone Know good values

Countries, Products …

Page 28: 軟體弱點掃描

28

解法 Type conversion & 參數化

Page 29: 軟體弱點掃描

29

XSS

Page 30: 軟體弱點掃描

30

XSS 體驗 Reflected XSS http://goo.gl/XqBbly

輸入 lager

再輸入 <i>lager</i> 可以發現 斜體字了。

Page 31: 軟體弱點掃描

31

XSS 體驗 -2 Persistent XSS

輸入 ch

輸入 RM

Page 32: 軟體弱點掃描

32

Persistent XSS 除了取 cookie 外 也有可能導到惡意的網坫

Page 33: 軟體弱點掃描

33

如何寫 MySpace 的 XSS

Page 34: 軟體弱點掃描

34

那些內容需要 Encode 呢 ? CSS HTML HTML attribute HTML form URL JavaScript LDAP distinguished name LDAP filter URL URL path XML XML attribute

Page 35: 軟體弱點掃描

35

針對不同的內容 Encode <i>Lager</i>

Context Encoded stringHTML &lt;I&gt;Lager&lt;/I&gt;JavaScript \x3ci\x3eLager\x3c\x2fi\x3eCSS \00003Ci\00003ELager\0003C\00002Fi\00003E

Page 36: 軟體弱點掃描

36

 Anti-Cross Site Scripting Library Encoding Method Should Be Used If … Example/PatternHtmlEncode Untrusted input is used in HTML output except when

assigning to an HTML attribute.<a href="http://www.contoso.com">Click Here [Untrusted input]</a>

HtmlAttributeEncode Untrusted input is used as an HTML attribute <hr noshade size=[Untrusted input]>

JavaScriptEncode Untrusted input is used within a JavaScript context <script type="text/javascript">…[Untrusted input]…</script>

UrlEncode Untrusted input is used in a URL (such as a value in a querystring)

<a href="http://search.msn.com/results.aspx?q=[Untrusted-input]">Click Here!</a>

VisualBasicScriptEncode Untrusted input is used within a Visual Basic Script context

<script type="text/vbscript" language="vbscript">…[Untrusted input]…</script>

XmlEncode Untrusted input is used in XML output, except when assigning to an XML attribute

<xml_tag>[Untrusted input]</xml_tag>

XmlAttributeEncode Untrusted input is used as an XML attribute <xml_tag attribute=[Untrusted input]>Some Text</xml_tag>

Page 37: 軟體弱點掃描

37

Misconfiguration

Page 38: 軟體弱點掃描

38

Misconfig 體驗 http://goo.gl/PABY47

點 Widgets 修改 url

CategoryId=x

Page 39: 軟體弱點掃描

39

Misconfig 體驗 -2 Int64 ?

將值改成 3000000000 ?CategoryId=3000000000

Page 40: 軟體弱點掃描

40

帳號 / 密碼…全都… ..

Page 41: 軟體弱點掃描

41

Misconfig 體驗 -3 misconfig/trace.axd

點 /Widgets.aspx 那個詳細資料 機敏資料 Cookies 實體路徑 LOCAL_ADDR IIS 版本

Page 42: 軟體弱點掃描

42

Misconfig 體驗 -4Elmah( 錯誤記錄模組 )

在 google 中輸入 inurl:elmah.axd "error log for“ inurl:elmah.axd aspxauth

Page 43: 軟體弱點掃描

43

設定 Config For ASP.NET

For Elmah

<customErrors mode=“RemoteOnly” redirectMode=“ResponseRewrite defaultRedirect=“~/Error.aspx” />

<trace enabled=“true”localOnly=“true”/>

Page 44: 軟體弱點掃描

44

Hash

Page 45: 軟體弱點掃描

45

Page 46: 軟體弱點掃描

46

存放密碼的方式 純文字 加解密 Hash Salted Hash

Page 47: 軟體弱點掃描

47

Hash 體驗 http://goo.gl/L2U20k

Page 48: 軟體弱點掃描

48

加 Salt

Page 49: 軟體弱點掃描

49

Insecure direct object

reference

Page 50: 軟體弱點掃描

50

Insecure direct object reference體驗 在 google 上輸入以下的資料

filetype:rtf | filetype:ppt | filetype:pptx | filetype:csv | filetype:xls | filetype:xlsx | filetype:docx | filetype:doc | filetype:pdf " 機密資料禁止 " site:gov.tw

Page 51: 軟體弱點掃描

51

Insecure direct object reference體驗 - 2 http://goo.gl/T25ibb

rm/111111 (rm 登入,密碼 6 個 1) 按下 F12 錄網路 按下 View

Page 52: 軟體弱點掃描

52

Insecure direct object reference體驗 - 3 點選那個 link

輸入 林志玲

Page 53: 軟體弱點掃描

53

要加以限制

Page 54: 軟體弱點掃描

54

Google 找名單

Page 55: 軟體弱點掃描

55

Q&A