Skip to content

Commit 8a12ab6

Browse files
committed
[FEATURE] Do the bitness check in shellcode runner
1 parent 0fc38b6 commit 8a12ab6

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

runshc/main.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,32 @@ int main(int argc, char *argv[])
2424
std::cout << "[*] Reading module from: " << in_path << std::endl;
2525
BYTE *my_exe = peconv::load_file(in_path, exe_size);
2626
if (!my_exe) {
27-
std::cout << "[-] Loading file failed" << std::endl;
27+
std::cerr << "[ERROR] Loading file failed" << std::endl;
2828
return -1;
2929
}
30+
// if the shellcode is a converted PE, check its bitness before running...
31+
const WORD arch = peconv::get_nt_hdr_architecture(my_exe);
32+
if (arch) {
33+
#ifdef _WIN64
34+
if (arch != IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
35+
std::cerr << "[ERROR] Bitness mismatch: the given payload is not compatibilie with this loader\n";
36+
return 0;
37+
}
38+
#else
39+
if (arch != IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
40+
std::cerr << "[ERROR] Bitness mismatch: the given payload is not compatibilie with this loader\n";
41+
return 0;
42+
}
43+
#endif
44+
}
45+
3046
BYTE *test_buf = peconv::alloc_aligned(exe_size, PAGE_EXECUTE_READWRITE);
3147
if (!test_buf) {
3248
peconv::free_file(my_exe);
33-
std::cout << "[-] Allocating buffer failed" << std::endl;
49+
std::cerr << "[ERROR] Allocating buffer failed" << std::endl;
3450
return -2;
3551
}
52+
3653
//copy file content into executable buffer:
3754
memcpy(test_buf, my_exe, exe_size);
3855

0 commit comments

Comments
 (0)