如何使用 Microsoft Source Code Analyzer for SQL Injection 自動掃瞄處理整個目錄

Microsoft Source Code Analyzer for SQL Injection這工具只能針對單一檔案作處理。在實際處理上,實在很不方便…科技來自惰性,想了想,決定用powshell 來協助掃瞄目錄這段的處理。

由於要處理的目錄很多,索性把Microsoft Source Code Analyzer for SQL Injection所需的相關參數當作變數,每次掃瞄不同目錄時,在去異動變數即可!以下,就是完整的powershell 程式~


#參數設定
$para_GlobalAsaPath ="D:\www\test"
$para_tocheckdir ="D:\www\test\test_sub"
$para_Output ="D:\www\result.xml" #如果不設定,將會以cmd的初始路徑為依據
$para_IncludePaths ="D:\www\test\include"
$para_tocheckext ="*.asp " #要檢測的附檔名
$para_sqlcheckprog ="D:\sp_sql_check\msscasi_asp.exe" #檢測工具存放路徑和程式名稱

$exe_cmd=""
#組合指令
$g_exe_cmd="$para_sqlcheckprog /GlobalAsaPath=""$para_GlobalAsaPath"" /IncludePaths=""$para_IncludePaths"" /Output=""$para_Output"" /Append "

#取得測試目錄下所有目錄
$array_files=Get-ChildItem -Name -Path $para_tocheckdir $para_tocheckext -Recurse

clear
#是否有檔案?
if ($array_files -is [array]){
 foreach ($filename in $array_files){
  $exe_cmd=$g_exe_cmd + " /input=""$para_tocheckdir\$filename"" "
  echo "$para_tocheckdir\$filename"

   $WshShell = New-Object -ComObject WScript.Shell
   $theprocess= $WshShell.Exec("cmd /c $exe_cmd")
   $watching= get-process -id $theprocess.ProcessID
   $watching.waitforexit()
  }
}
else{
  echo "nothing to do ..."
}

很好笑…就在寫完小程式,也掃了程式後,發現 MSDN SQL Server Security中,早有人提供了 利用VBS掃目錄 的作法了~

呵,不過…相形之下powershell 真的好用多了!

留言