|
|
|
@ -2,10 +2,12 @@
|
|
|
|
|
#include <Windows.h>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
|
|
#include <vmp2.hpp>
|
|
|
|
|
#include <vmctx.h>
|
|
|
|
|
#include <vm.h>
|
|
|
|
|
#include <vmprofiler.hpp>
|
|
|
|
|
#include <cli-parser.hpp>
|
|
|
|
|
#include <xtils.hpp>
|
|
|
|
|
|
|
|
|
|
int __cdecl main(int argc, const char* argv[])
|
|
|
|
|
{
|
|
|
|
@ -22,15 +24,14 @@ int __cdecl main(int argc, const char* argv[])
|
|
|
|
|
.description("rva to push prior to a vm_entry")
|
|
|
|
|
.required(true);
|
|
|
|
|
|
|
|
|
|
parser.add_argument()
|
|
|
|
|
.names({ "--imagebase", "--base" })
|
|
|
|
|
.description("image base from OptionalHeader::ImageBase")
|
|
|
|
|
.required(true);
|
|
|
|
|
|
|
|
|
|
parser.add_argument()
|
|
|
|
|
.names({ "--vmtrace", "--trace" })
|
|
|
|
|
.description("a vmp2 file generated by a vmtracer");
|
|
|
|
|
|
|
|
|
|
parser.add_argument()
|
|
|
|
|
.name("--show-vm-handlers")
|
|
|
|
|
.description("show all vm handlers...");
|
|
|
|
|
|
|
|
|
|
parser.enable_help();
|
|
|
|
|
auto err = parser.parse(argc, argv);
|
|
|
|
|
|
|
|
|
@ -55,8 +56,9 @@ int __cdecl main(int argc, const char* argv[])
|
|
|
|
|
module_base + std::strtoull(
|
|
|
|
|
parser.get<std::string>("vmentry").c_str(), nullptr, 16);
|
|
|
|
|
|
|
|
|
|
const auto image_base = std::strtoull(
|
|
|
|
|
parser.get<std::string>("imagebase").c_str(), nullptr, 16);
|
|
|
|
|
const auto image_base =
|
|
|
|
|
xtils::um_t::get_instance()->image_base(
|
|
|
|
|
parser.get<std::string>("bin").c_str());
|
|
|
|
|
|
|
|
|
|
zydis_routine_t vm_entry;
|
|
|
|
|
std::printf("> vm entry start = 0x%p\n", vm_entry_ptr);
|
|
|
|
@ -70,9 +72,11 @@ int __cdecl main(int argc, const char* argv[])
|
|
|
|
|
vm::util::deobfuscate(vm_entry);
|
|
|
|
|
std::printf("> flattened vm entry...\n");
|
|
|
|
|
std::printf("> deobfuscated vm entry...\n");
|
|
|
|
|
std::printf("==================================================================================\n");
|
|
|
|
|
vm::util::print(vm_entry);
|
|
|
|
|
|
|
|
|
|
const auto vm_handler_table = vm::handler::table::get(vm_entry);
|
|
|
|
|
const auto vm_handler_table =
|
|
|
|
|
vm::handler::table::get(vm_entry);
|
|
|
|
|
|
|
|
|
|
if (!vm_handler_table)
|
|
|
|
|
{
|
|
|
|
@ -80,16 +84,48 @@ int __cdecl main(int argc, const char* argv[])
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::printf("==================================================================================\n");
|
|
|
|
|
std::printf("> located vm handler table... at = 0x%p, rva = 0x%p\n", vm_handler_table,
|
|
|
|
|
(reinterpret_cast<std::uintptr_t>(vm_handler_table) - module_base) + image_base);
|
|
|
|
|
|
|
|
|
|
std::vector<vm::handler_t> vm_handlers;
|
|
|
|
|
zydis_decoded_instr_t vm_handler_transform;
|
|
|
|
|
if (!vm::handler::table::get_transform(vm_entry, &vm_handler_transform))
|
|
|
|
|
{
|
|
|
|
|
std::printf("[!] failed to locate vm handler table entry transformation...\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::printf("> vm handler table entries decrypted with = ");
|
|
|
|
|
vm::util::print(vm_handler_transform);
|
|
|
|
|
|
|
|
|
|
vm_handler_transform.mnemonic = vm::transform::inverse[vm_handler_transform.mnemonic];
|
|
|
|
|
std::printf("> vm handler table entries encrypted with = ");
|
|
|
|
|
vm::util::print(vm_handler_transform);
|
|
|
|
|
|
|
|
|
|
std::printf("==================================================================================\n");
|
|
|
|
|
std::vector<zydis_decoded_instr_t> vinstr_rva_decrypt_instrs;
|
|
|
|
|
if (!vm::instrs::get_rva_decrypt(vm_entry, vinstr_rva_decrypt_instrs))
|
|
|
|
|
{
|
|
|
|
|
std::printf("[!] failed to get virtual instruction rva decrypt transformations...\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::printf("> virtual instruction rva decryption instructions:\n");
|
|
|
|
|
for (auto& transform : vinstr_rva_decrypt_instrs)
|
|
|
|
|
{
|
|
|
|
|
std::printf("\t");
|
|
|
|
|
vm::util::print(transform);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<vm::handler::handler_t> vm_handlers;
|
|
|
|
|
if (!vm::handler::get_all(module_base, image_base, vm_entry, vm_handler_table, vm_handlers))
|
|
|
|
|
{
|
|
|
|
|
std::printf("> failed to get all vm handler meta data...\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parser.exists("show-vm-handlers"))
|
|
|
|
|
{
|
|
|
|
|
for (auto idx = 0u; idx < vm_handlers.size(); ++idx)
|
|
|
|
|
{
|
|
|
|
|
auto vm_handler = vm_handlers[idx];
|
|
|
|
@ -109,6 +145,7 @@ int __cdecl main(int argc, const char* argv[])
|
|
|
|
|
|
|
|
|
|
std::printf("=======================================================\n\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parser.exists("vmtrace"))
|
|
|
|
|
{
|
|
|
|
@ -144,7 +181,5 @@ int __cdecl main(int argc, const char* argv[])
|
|
|
|
|
std::tie(virt_instr, log_entry) = vmctx.step())
|
|
|
|
|
std::printf("> %s\n", virt_instr.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::printf("> finished...\n");
|
|
|
|
|
std::getchar();
|
|
|
|
|
}
|