Raptor(猛禽)是一款基於WEB界面的github源代碼掃描器。你只需要給它一個Github repository的URL地址,它就能進行自動掃描。
簡單介紹
你也可以在Raptor設置WEB監控機制,在每次進行提交或者合併分支時,它會收到消息然後進行自動化掃描。這些掃描工作是異步進行的,而且只有啓動掃描的用戶自己才能看到掃描結果。
Raptor的一些特性:
插件體系結構(新加入的插件能直接使用+生成統一報告)
WEB服務可以定時自動化運行(不需要去UI界面操作)
爲新的漏洞或者編程語言,進行創建/編輯/刪除簽名的操作
筆者聲明一下,這個項目是爲了幫助社區和初創企業進行代碼安全檢測,可能不會有商業產品的那樣的質量保證。此外,這個工具只是爲了給代碼審計和研發人員提供發現漏洞的切入點,所以請不要盲目信任工具輸出的內容。當然,如果你將它加入CI/CD(持續集成和持續交付)的話,那應該會不錯的。
在這裏Raptor集成了一些插件。大家注意,爲了兼容本框架,下面不少的工具/模塊/庫都是被改過的:
MozillaScanJS – 掃描JavaScript (主要是客戶端的Node.JS等等, 未來會支持Chrome和Firefox插件)
Brakeman- 掃描Ruby Rails
RIPS - 掃描PHP
Manitree – 掃描 AndroidManifest.xml等等
規則包:
ActionScript – 掃描Flash/Flex(ActionScript 2.0 & 3.0)源
FindSecurityBugs (只含規則) – 掃描Java (J2EE, JSP, Android, Scala, Groovy等等)
gitrob – 掃描敏感數據的泄露(包含證書/配置/備份/私密設置的信息)
安裝步驟
筆者安裝時,在Ubuntu 14.04 x64 LAMP環境下測試通過,安裝視頻在這裏。
$ wget https://github.com/dpnishant/raptor/archive/master.zip -O raptor.zip$ unzip raptor.zip$ cd raptor-master$ sudo sh install.sh
使用方法
使用視頻在這裏。
cd raptor-mastersudo sh start.sh #starts the backendweb-service
然後你就可以訪問本地的WEB服務了:
http://localhost/raptor/
登陸
你可以用你在github服務器上註冊的用戶名來登陸,密碼任意輸入即可(但在查看掃描結果的時候,需要用到相應的用戶名)。
比如,如果你在github.com上註冊了賬戶foobar,你就需要用foobar這個賬戶名去掃描github.com上面的repos。
但是,如果你在私人的github服務器上註冊了foobar_corp賬戶,比如:
https://github.corp.company.com/
在這時,你就需要使用賬戶foobar_corp,去掃描github.corp.company.com服務器上的repos。
提醒一下大家,現在沒有在demo版本中搞數據庫,所以現在密碼驗證的地方可以隨意輸入。
規則編輯器
你可以使用系統自帶的輕量級GUI規則編輯器,用它來加入新的規則。當然啦,你也可以使用其他文本編輯器,因爲規則包文件只是普通的JSON文件。操作時只需要打開backend/rules下面的規則包,然後將修改/新增後的規則,保存在backend/rules目錄下面即可。簡單來說,你需要做的只有少量的編輯工作。注意,將新的規則包的文件名加入到這裏,這裏不要帶上.rulepack的後綴,重啓服務器後就大功告成啦。
你可以通過這裏的URL地址直接訪問規則編輯器:
http://localhost/raptor/editrules.php
添加規則
ignore_list.rulepack:
你可以添加一些針對目錄名/文件名的正則匹配,避免raptor去掃一些無用的文件如jquery.min.js,或者去深入掃描/test/這樣的目錄。在“插件”選項裏,規則插件都放在rules目錄下。Issue區域是規則包文件裏提到的issue的ID: Example#1, Example#2。match_type區域的值可以是regex/start/end三個選項,value區域的值是爲了配合match_type區域而填寫的字符串,這裏需要進行Base64編碼以防出現JSON syntax語法錯誤。解釋一下,match_type中的regex是基於正則的匹配,start會匹配字符串片段開頭,end會匹配字符串片段結尾。
這是在掃描器掃描完issue後進行的,它會依次遍歷發現的issue,然後去除其中(ignore_list.rulepack)裏面匹配到的內容。
規則實例:
{ "files": [ "/.", "bootstrap", "jquery", "uglify", "knockout", "angular", "backbone", "ember", "yui", "mocha", "express", "yql", "dataTables" ], "directories":[ "/node_modules/", "/test/" ], "plugins": [ { "name":"common", <----- Name of the Plugin "issue":"HARD_CRED1", <----- ID of the issue "patterns": [ { "match_type": "start", <----- Match type can be either"regex", "start" or "end" "value": "foreach" <----- The actual string tomatch. Base64 Encode this pattern if match_type is "regex" }, { "match_type": "start", "value": "for" }, { "match_type": "start", "value": "elseif" } ] } ]}
your_rule_name.rulepack:
你自己可能也會創建一個新的規則包(rulepack)/掃描插件,然後將其加入掃描器框架。那麼,下面筆者就簡單介紹一下該規則包的JSON格式。
{ "plugin_type":"plugin_name", <-- Give ita name (any string) "file_types":[ ".java", <-- Add as many file extensions, you would want the scanner to pickwhile scanning ".js" ], "rules": [ { "id":"HARD_CRED1", <-- Aunique IssueID, be creative. "severity": "High", <-- This can be High, Medium or Low.This would accordingly show up in the graphs in UI. "title":"Title of the Issue", <--The title of the issue. "description": "This text here shall be reflected in theUI as description of the issue.", <-- The description of the issue, this is optional. "remediation": "The text here shall be reflected in theUI as the steps to remediate the issue", <-- The remediation of the issue, this is optional. "link":"Any URL that has more resources about the issue.", <-- URL of the issue. This is optional "example_insecure": "Put the insecure version of the codesnippet for learning purpose.", <-- This is optional "example_secure": "Put the secure version of the codesnippet for learning purpose.", <-- This is optional "platform_version": "all", <-- Leave it like that "enabled":"true", <-- Thisvalue enables or disables the rule during the scan. It can be either"true" or "false". "logic":"Explain the logic behind this rule for future updation orcustomization", <-- This isoptional "signature": "base64encode(regexp)" <-- Write the Regular Expression of yourpattern and then base64encode it to put it here. } ]}
如果你想要更好地利用這個掃描器,並不僅僅將其作爲一個正則匹配器,你可以寫一個像這樣的簡單掃描插件,在這裏整合腳本,並腳本加入規則插件列表中。我想,這對那些有着python基礎的人是非常簡單的。