forked from Troyalabs/Pyrebox-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AntiAntiVM.py
166 lines (132 loc) · 4.8 KB
/
AntiAntiVM.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#-------------------------------------------------------------------------------
# Troyalabs Module for PyreBox
# Module Name: AntiAntiVM
# Authors: @j0sm1 (JoseMi Holguin) and @bondey_M (Marc Salinas)
# Version: 0.1 (For now just a PoC)
# Description: An anti VM detection module for Pyrebox inspired by Idastealth and Pafish
#-------------------------------------------------------------------------------
from __future__ import print_function
from api import CallbackManager
import api
import functools
from api import BP
import pefile
#TEMPORAL
from ipython_shell import start_shell
process_is_created = 0
target_pgd = 0
target_name = ""
target_pid = 0
def opcodes(cpu_index,cpu,pc,next_pc):
global pyrebox_print
global target_pgd
if api.is_kernel_running(cpu_index) == False:
pgd = api.get_running_process(cpu_index)
if pgd == target_pgd and pc < 0x500000:
if cpu.EBX == 0x54474354:
api.w_r(0,"EBX",0x72657661)
api.w_r(0,"ECX",0x33333179)
api.w_r(0,"EDX",0x70796837)
pyrebox_print("[*] Hypervisor name check %x" % pc)
#start_shell()
elif cpu.EBX == 0x756e6547:
pyrebox_print("[*] GenuineIntel check %x" % pc)
elif cpu.EBX == 0x72695620:
api.w_r(0,"EAX",0x65746e49)
api.w_r(0,"EBX",0x6f63206c)
api.w_r(0,"ECX",0x49206572)
api.w_r(0,"EDX",0x00003936)
pyrebox_print("[*] CPU Name check %x" % pc)
#start_shell()
elif cpu.ECX == 0x80000001: #Not pretty elegant
api.w_r(0,"ECX",0x00000000)
pyrebox_print("[*] Hypervisor bit check %x" % pc)
else:
pyrebox_print("[*] Unknown Check (TODO) %x" % pc)
#start_shell()
def new_proc(pid, pgd, name):
global process_is_created
global cm
global target_pgd
global target_pid
global target_name
global pyrebox_print
if name == "malo.exe":
target_pgd = pgd
target_name = name
target_pid = pid
process_is_created = 1
pyrebox_print("[*] Proc created")
api.start_monitoring_process(target_pgd)
cm.add_callback(CallbackManager.CONTEXTCHANGE_CB, functools.partial(context_change, pgd, name), name="context_change")
cm.rm_callback("vmi_new_proc")
def context_change(pgd_target, target_mod_name, old_pgd, new_pgd):
'''Callback triggered for every context change
:param target_pgd: This parameter is inserted using functools.partial (see callback registration)
:param target_mod_name: This parameter is inserted using functools.partial (see callback registration)
:param old_pgd: This is the first parameter of the callback
:param new_pgd: This is the second parameter of the callback
'''
global cm
global target_pgd
global target_pid
global target_name
if target_pgd == new_pgd:
ep = find_ep(target_pgd, target_mod_name)
if ep is not None:
pyrebox_print("The entry point for %s is %x\n" % (target_mod_name, ep))
cm.rm_callback("context_change")
cm.add_callback(CallbackManager.OPCODE_RANGE_CB, opcodes, name="opcode2_%x" % (target_pid), start_opcode=0x0fa2, end_opcode=0x0fa2)
############### TODO (hooking VM detection Windows APIs)
#cm.add_callback(CallbackManager.INSN_BEGIN_CB,ep_hit,addr=ep,pgd=target_pgd)
def update_symbols(cpu_index,cpu):
global cm
global target_pgd
pgd = api.get_running_process(cpu_index)
start_shell()
if pgd == target_pgd:
api.get_symbol_list()
cm.rm_callback("update_symbols")
def initialize_callbacks(module_hdl, printer):
global cm
global pyrebox_print
from plugins.guest_agent import guest_agent
pyrebox_print = printer
cm = CallbackManager(module_hdl)
guest_agent.copy_file("/home/marc/sdcard/zoo/gen/sample.exe","C:\\ProgramData\\malo.exe")
cm.add_callback(CallbackManager.CREATEPROC_CB, new_proc, name="vmi_new_proc")
guest_agent.execute_file("C:\\ProgramData\\malo.exe")
def find_ep(pgd, proc_name):
'''Given an address space and a process name, uses pefile module
to get its entry point
'''
global cm
global loaded_processes
import api
for m in api.get_module_list(pgd):
name = m["name"]
base = m["base"]
# size = m["size"]
if name == proc_name:
try:
pe_data = api.r_va(pgd, base, 0x1000)
pe = pefile.PE(data=pe_data)
ep = pe.OPTIONAL_HEADER.AddressOfEntryPoint
return (base + ep)
except Exception:
pyrebox_print("Unable to run pefile on loaded module %s" % name)
############### TODO (hooking VM detection Windows APIs)
def ep_hit(cpu_index,cpu):
global target_pgd
api.start_monitoring_process(target_pgd)
simbols = api.get_symbol_list(target_pgd)
for sim in simbols:
if sim["name"] == "GetDiskFreeSpaceExW" or sim["name"] == "GetDiskFreeSpaceExA":
pyrebox_print("found! %s" % sim["addr"])
cm.add_callback(CallbackManager.INSN_BEGIN_CB,GetFreeSpaceCalled,addr=sim["addr"],pgd=target_pgd)
start_shell()
def GetFreeSpaceCalled(addr,pgd):
start_shell()
cm.add_callback(CallbackManager.INSN_BEGIN_CB,my_function,addr=addr,pgd=pgd)
def my_function(cpu_index,cpu):
start_shell()