1.LLVM安裝:Download LLVM releases(用于編譯混淆後替換bin)
設定下環境變量:
version見lib\clang下的檔案夾名
set LLVMInstallDir=C:\Program Files\LLVM
set LLVMToolsVersion=12.0.0
rem LLVMToolsVersion = name of the last subfolder in the path C:\Program Files\LLVM\lib\clang\12.0.0
2.vs安裝llvm插件
2019:llvm2019 - Visual Studio Marketplace
2017:LLVM Compiler Toolchain - Visual Studio Marketplace
3.修改WDK配置檔案
找到PlatformToolsets目錄
複制WindowsKernelModeDriver10.0并重命名WindowsKernelModeDriver10.0_LLVM
修改Toolset.props
<PropertyGroup>
<V141PropsFile>$(VCTargetsPath)\Platforms\$(Platform)\PlatformToolsets\v141\Toolset.props</V141PropsFile>
<V142PropsFile>$(VCTargetsPath)\Platforms\$(Platform)\PlatformToolsets\v142\Toolset.props</V142PropsFile>
<ClangPropsFile>$(VCTargetsPath)\Platforms\$(Platform)\PlatformToolsets\llvm\Toolset.props</ClangPropsFile>
</PropertyGroup>
<Import Condition="Exists('$(ClangPropsFile)')" Project="$(ClangPropsFile)" />
<Import Condition="!Exists('$(V142PropsFile)')" Project="$(V142PropsFile)" />
<Import Condition="!Exists('$(V142PropsFile)')" Project="$(V141PropsFile)" />
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiI2EzX4xSZz91ZsAzNfRHLGZkRGZkRfJ3bs92YskTMfVmepNHL90zdihGbHpFaoJzYwZVbZBnVIFWMo1WZBJUaUVkTxE1X0hXZ0xCMx81dvRWYoNHLrdEZwZ1Rh5WNXp1bwNjW1ZUba9VZwlHdssmch1mclRXY39CXldWYtlWPzNXZj9mcw1ycz9WL49zZuBnLyUTOwATN0IjM1IDOwEjMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
Toolset.targets
<PropertyGroup>
<V141TargetsFile>$(VCTargetsPath)\Platforms\$(Platform)\PlatformToolsets\v141\Toolset.targets</V141TargetsFile>
<V142TargetsFile>$(VCTargetsPath)\Platforms\$(Platform)\PlatformToolsets\v142\Toolset.targets</V142TargetsFile>
<ClangTargetsFile>$(VCTargetsPath)\Platforms\$(Platform)\PlatformToolsets\llvm\Toolset.targets</ClangTargetsFile>
</PropertyGroup>
<Import Project="$(WDKContentRoot)\build\WindowsDriver.common.targets" Condition="Exists('$(WDKContentRoot)\build\WindowsDriver.common.targets')"/>
<Import Condition="Exists('$(ClangTargetsFile)')" Project="$(ClangTargetsFile)" />
<Import Condition="!Exists('$(V142TargetsFile)')" Project="$(V142TargetsFile)" />
<Import Condition="!Exists('$(V142TargetsFile)')" Project="$(V141TargetsFile)" />
4.平台工具集選擇10.0_LLVM
選擇完确認後重新打開屬性頁會出現LLVM,将Use lld-link設為否
接着禁用spectre
c/c++指令行 其他選項 從父級繼承勾去掉
混淆指令見最後
現在工程環境已經ok了,
去編譯帶混淆的llvm替換官方的llvm工具
本文章使用
heroims/obfuscator at llvm-9.0 (github.com)
amimo/goron: Yet another llvm based obfuscator (github.com)
選擇其一即可,推薦goron
編譯obfuscator使用mingw
1.Download | CMake (安裝時直接選擇添加PATH)
2.Downloads [mingw-w64](手動添加bin到PATH)
3.
git clone -b llvm-9.0.1 https://github.com/heroims/obfuscator
cd obfuscator
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -G "MinGW Makefiles" ../
mingw32-make.exe -j7
4.編譯大概20分鐘左右,編譯完成後把bin目錄的檔案全部複制到官方下載下傳的bin目錄替換(編譯成功bin目錄必有clang.exe)
5.打開配置好的驅動工程檔案 c/c++ 指令行 添加
-mllvm -bcf -mllvm -bcf_prob=73 -mllvm -bcf_loop=1 -mllvm -sub -mllvm -sub_loop=5 -mllvm -fla -mllvm -split_num=5 -mllvm -aesSeed=ABCDBEEFDEADDVBEDEADBEEFDEADERTG
具體意思見Features · obfuscator-llvm/obfuscator Wiki (github.com)
編譯goron
使用vs2019或2017編譯
git clone https://github.com/amimo/goron.git -b llvm-7.1.0
cd goron
mkdir build
cd build
cmake -DLLVM_ENABLE_PROJECTS=clang -G "Visual Studio XXXX" -A x64 -Thost=x64 ..\llvm
xxxx根據你的vs版本,不知道名字先随便輸一個錯誤的比如就xxx,會列出全部的名字,選擇一個你有的vs版本名即可
vs開llvm.sln 有兩個坑
1.找到LLVMMIPO和LLVMObfuscator工程
分别在其預定義中添加ENDIAN_LITTLE定義
2.clangDaemon\CodeComplete.h 用記事本打開編碼儲存為為UNICODE L1200
接着找到ALL_BUILD工程 編譯release x64即可.過程大概30分鐘左右
編譯成功bin目錄必有clang.exe,将bin目錄的所有檔案複制到官網的llvm bin目錄替換
打開配置好的驅動工程.
c/c++指令行 其它選項添加
-mllvm -irobf-cse -mllvm -irobf-indbr -mllvm -irobf-icall -mllvm -irobf-indgv -mllvm -irobf-cff
具有意思見goron github說明
對于一些内聯彙編指令不能使用,可以用.asm
參考:
[原創]如何使用LLVM編譯Windows驅動(混淆&Asm)-程式設計技術-看雪論壇-安全社群|安全招聘|bbs.pediy.com