微軟掃描器安裝以及使用

ApplicationInspector是一款功能強大的軟件源代碼分析與審計工具,它可以幫助研究人員識別和發現目標應用程序中的公衆周知的功能以及源代碼中有意思的特性,並清楚目標應用的本質特徵以及實現的功能。

ApplicationInspector跟傳統靜態分析工具不同的是,它不會嘗試去識別目標應用模式的好與壞,它只會報告它所檢測到的應用程序模式,而且它會使用超過400種規則來完成檢測,其中包含可能會影響應用程序安全性的一些模式,例如所使用的加密算法等等。ApplicationInspector會直接檢查目標應用程序的源代碼,而不是選擇信任已有文檔或安全建議,這對於分析開源項目或其他組件來說,能夠提升準確率。

ApplicationInspector支持掃描各種編程語言,其中包括C、C++、C、Java、JavaScript、HTML、Python、Objective-C、GO、Ruby以及PowerShell等等,並且還支持掃描混合語言的文件。除此之外,ApplicationInspector還支持HTML、JSON和text等輸出格式,默認輸出報告格式爲HTML。

值得一提的是,ApplicationInspector提供了一個可過濾的指示器,以此來提供最小化的誤報率,並幫助研究人員自定義默認規則以及條件匹配邏輯。

 

工具下載

廣大研究人員可以使用下列命令將項目源 碼克隆至本地:

git clone https://github.com/microsoft/ApplicationInspector.git

項目構建

項目的源碼構建需要安裝.NET Core 3.0,並使用標準的dotnet構建命令直接在項目根目錄運行。

框架依賴:

dotnet build -c Release

目標平臺構建:


 

dotnet publish -c Release -r win-x86

dotnet publish -c Release -r linux-x64

dotnet publish -c Release -r osx-x64

 

工具使用

如需使用ApplicationInspector,可以直接下載對應的ApplicationInspector版本。如果你是用的是.NET Core版本,你還需要安裝.NET Core v3.0或更高版本。

ApplicationInspector是一款基於命令行的工具,因此我們可以直接在Windows、Linux或macOS平臺上通過命令行終端來運行該工具:

> dotnet AppInspector.dll or on *Windows* simply AppInspector.exe <command> <options>

Microsoft Application Inspector 1.0.25
ApplicationInspector 1.0.25

(c) Microsoft Corporation. All rights reserved

ERROR(S):
  No verb selected.

  analyze        Inspect source directory/file/compressed file (.tgz|zip) against defined characteristics
  tagdiff        Compares unique tag values between two source paths
  tagtest        Test presence of smaller set or custom tags in source (compare or verify modes)
  exporttags     Export default unique rule tags to view what features may be detected
  verifyrules    Verify rules syntax is valid
  help           Display more information on a specific command
  version        Display version information

 

使用樣例

命令行幫助信息:

  Usage: dotnet AppInspector.dll [arguments] [options]

  dotnet AppInspector.dll -description of available commands
  dotnet AppInspector.dll <command> -options description for a given command

 

分析命令:

 Usage: dotnet AppInspector.dll analyze [arguments] [options]

  Arguments:
  -s, --source-path             Required. Path to source code to inspect (required)
  -o, --output-file-path        Path to output file.  Ignored with -f html option which auto creates output.html
  -f, --output-file-format      Output format [html|json|text]. Default = html
  -e, --text-format             Match text format specifiers 
  -r, --custom-rules-path       Custom rules path
  -t, --tag-output-only         Output only contains identified tags. Default = false
  -i, --ignore-default-rules    Ignore default rules bundled with application. Default = false
  -d, --allow-dup-tags          Output only non-unique tag matches. Default = false
  -c, --confidence-filters      Output only matches with confidence [high|medium|low].  Default = high,medium
  -k, --file-path-exclusions    Exclude source files [none|<list>]. Default = sample,example,test,docs,.vs,.git
  -x, --console-verbosity       Console verbosity [high|medium|low|none].  Default = medium
  -l, --log-file-path           Log file path.  Default is <application path>/log.txt
  -v, --log-file-level          Log file level [Debug|Info|Warn|Error|Fatal|Off].  Default = Error

 

掃描一個項目目錄,不需要輸出“output.html”文件(默認):

dotnet AppInspector.dll analyze -s /home/user/myproject 

添加自定義掃描規則:

dotnet AppInspector.dll analyze -s /home/user/myproject -r /my/rules/directory -r /my/other/rules

JSON格式輸出:

dotnet AppInspector.dll analyze -s /home/user/myproject -f json

Tagdiff命令

如果你需要使用不同的標籤(功能)來分析、比對和報告兩個不同的項目,比如說兩個不同版本的項目,你可以使用tagdiff命令:

 Usage: dotnet AppInspector.dll tagdiff [arguments] [options]

  Arguments:
  --src1                        Required. Source 1 to compare (required)
  --src2                        Required. Source 2 to compare (required
  -t, --test-type               Type of test to run [equality|inequality].  Default = equality
  -r, --custom-rules-path       Custom rules path
  -i, --ignore-default-rules    Ignore default rules bundled with application.  Default = false
  -o, --output-file-path        Path to output file
  -x, --console-verbosity       Console verbosity [high|medium|low].  Default = medium
  -l, --log-file-path           Log file path
  -v, --log-file-level          Log file level [error|trace|debug|info].  Default = error

 

查看不同項目對比結果的命令如下:

dotnet AppInspector.dll tagdiff --src1 /home/user/project1 --src2 /home/user/project2

基本使用1:

dotnet AppInspector.dll tagdiff --src1 /home/user/project1 --src2 /home/user/project2 -t equality

基本使用2:

dotnet AppInspector.dll tagdiff --src1 /home/user/project1 --src2 /home/user/project2 -t inequality

TagTest命令

該命令用於識別目標項目中是否存在指定的一系列規則,比如說,你想知道目標應用中是否使用了某個加密算法,就可以使用該命令了。

命令參數如下:

 Usage: dotnet AppInspector.dll tagtest [arguments] [options

  Arguments:
  -s, --source-path             Required. Source to test (required)
  -t, --test-type               Test to perform [rulespresent|rulesnotpresent].  Default = rulespresent
  -r, --custom-rules-path       Custom rules path 
  -i, --ignore-default-rules    Ignore default rules bundled with application.  Default = true
  -o, --output-file-path        Path to output file
  -x, --console-verbosity       Console verbosity [high|medium|low].  Default = medium
  -l, --log-file-path           Log file path
  -v, --log-file-level          Log file level

 

使用下列命令即可查看目標項目中是否存在某規則集:

dotnet AppInspector.dll tagtest -s /home/user/project1 -r /home/user/myrules.json

基本使用1:

dotnet AppInspector.dll tagtest -s /home/user/project1 -r /home/user/myrules.json -t rulespresent

基本使用2:

dotnet AppInspector.dll tagtest -s /home/user/project1 -r /home/user/myrules.json -t rulesnotpresent

ExportTags命令

該命令可以輸出指定標籤的規則集模式:

 

  Usage: dotnet AppInspector.dll exporttags [arguments] [options]

  Arguments:
  -r, --custom-rules-path       Custom rules path
  -i, --ignore-default-rules    Ignore default rules bundled with application.  Default = false
  -o, --output-file-path        Path to output file
  -x, --console-verbosity       Console verbosity [high|medium|low].  Default = medium

 

輸出默認規則標籤至終端:

dotnet AppInspector.dll exporttags

使用輸出文件:

dotnet AppInspector.dll exporttags -o /home/user/myproject/exportags.txt

使用自定義規則以及輸出文件:

dotnet AppInspector.dll exporttags -r /home/user/myproject/customrules -o /hom/user/myproject/exportags.txt

Verify命令

該命令可以驗證規則集是否兼容,並保證導入和分析時不會發生錯誤:

  Usage: dotnet AppInspector.dll verifyrules [arguments]

  Arguments:
  -r, --custom-rules-path       Custom rules path
  -i, --ignore-default-rules    Ignore default rules bundled with application.  Default = false
  -o, --output-file-path        Path to output file
  -x, --console-verbosity       Console verbosity [high|medium|low].  Default = medium.

 

驗證默認規則:

dotnet AppInspector.dll verifyrules

使用自定義規則:

dotnet AppInspector.dll verifyrules -r /home/user/myproject/customrules -i

項目地址

ApplicationInspector:【GitHub傳送門

參考資料

1、https://github.com/Microsoft/ApplicationInspector/wiki

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章