Upload files to "src/Utils/deps/spoofcall"
This commit is contained in:
42
src/Utils/deps/spoofcall/RetSpoof.asm
Normal file
42
src/Utils/deps/spoofcall/RetSpoof.asm
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
PUBLIC _spoofer_stub
|
||||||
|
|
||||||
|
.code
|
||||||
|
|
||||||
|
_spoofer_stub PROC
|
||||||
|
pop r11
|
||||||
|
pop r10
|
||||||
|
mov rax, [rsp + 24]
|
||||||
|
|
||||||
|
mov r10, [rax]
|
||||||
|
mov [rsp], r10
|
||||||
|
|
||||||
|
mov r10, [rax + 8]
|
||||||
|
mov [rax + 8], r11
|
||||||
|
|
||||||
|
mov [rax + 16], rbx
|
||||||
|
lea rbx, fixup
|
||||||
|
mov [rax], rbx
|
||||||
|
mov rbx, rax
|
||||||
|
|
||||||
|
jmp r10
|
||||||
|
|
||||||
|
fixup:
|
||||||
|
sub rsp, 16
|
||||||
|
mov rcx, rbx
|
||||||
|
mov rbx, [rcx + 16]
|
||||||
|
jmp QWORD PTR [rcx + 8]
|
||||||
|
_spoofer_stub ENDP
|
||||||
|
|
||||||
|
NtProtectVirtualMemory PROC
|
||||||
|
mov r10, rcx ; Move first parameter from rcx to r10 (syscall convention)
|
||||||
|
mov eax, 50h ; Set syscall number for NtProtectVirtualMemory (Windows 10 x64)
|
||||||
|
test byte ptr [7FFE0308h], 1 ; Check KUSER_SHARED_DATA flag
|
||||||
|
jnz use_int2e ; If flag is set, use int 2Eh
|
||||||
|
syscall ; Execute 64-bit system call
|
||||||
|
ret ; Return with NTSTATUS in eax
|
||||||
|
use_int2e:
|
||||||
|
int 2Eh ; Execute 32-bit system call (compatibility)
|
||||||
|
ret ; Return with NTSTATUS in eax
|
||||||
|
NtProtectVirtualMemory ENDP
|
||||||
|
|
||||||
|
END
|
||||||
146
src/Utils/deps/spoofcall/RetSpoof.hpp
Normal file
146
src/Utils/deps/spoofcall/RetSpoof.hpp
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ULONG32 NTAPI MyZwProtectVirtualMemory(
|
||||||
|
HANDLE ProcessHandle,
|
||||||
|
PVOID* BaseAddress,
|
||||||
|
PULONG RegionSize,
|
||||||
|
ULONG NewProtect,
|
||||||
|
PULONG OldProtect
|
||||||
|
);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
extern "C" void* _spoofer_stub();
|
||||||
|
|
||||||
|
template <typename Ret, typename... Args>
|
||||||
|
static inline auto shellcode_stub_helper(
|
||||||
|
const void* shell,
|
||||||
|
Args... args
|
||||||
|
) -> Ret
|
||||||
|
{
|
||||||
|
auto fn = (Ret(*)(Args...))(shell);
|
||||||
|
return fn(args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <std::size_t Argc, typename Enable = void>
|
||||||
|
struct argument_remapper
|
||||||
|
{
|
||||||
|
template<
|
||||||
|
typename Ret,
|
||||||
|
typename First,
|
||||||
|
typename Second,
|
||||||
|
typename Third,
|
||||||
|
typename Fourth,
|
||||||
|
typename... Pack
|
||||||
|
>
|
||||||
|
static auto do_call(
|
||||||
|
const void* shell,
|
||||||
|
void* shell_param,
|
||||||
|
First first,
|
||||||
|
Second second,
|
||||||
|
Third third,
|
||||||
|
Fourth fourth,
|
||||||
|
Pack... pack
|
||||||
|
) -> Ret
|
||||||
|
{
|
||||||
|
return shellcode_stub_helper<
|
||||||
|
Ret,
|
||||||
|
First,
|
||||||
|
Second,
|
||||||
|
Third,
|
||||||
|
Fourth,
|
||||||
|
void*,
|
||||||
|
void*,
|
||||||
|
Pack...
|
||||||
|
>(
|
||||||
|
shell,
|
||||||
|
first,
|
||||||
|
second,
|
||||||
|
third,
|
||||||
|
fourth,
|
||||||
|
shell_param,
|
||||||
|
nullptr,
|
||||||
|
pack...
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <std::size_t Argc>
|
||||||
|
struct argument_remapper<Argc, std::enable_if_t<(Argc <= 4), void>>
|
||||||
|
{
|
||||||
|
template<
|
||||||
|
typename Ret,
|
||||||
|
typename First = void*,
|
||||||
|
typename Second = void*,
|
||||||
|
typename Third = void*,
|
||||||
|
typename Fourth = void*
|
||||||
|
>
|
||||||
|
static auto do_call(
|
||||||
|
const void* shell,
|
||||||
|
void* shell_param,
|
||||||
|
First first = First{},
|
||||||
|
Second second = Second{},
|
||||||
|
Third third = Third{},
|
||||||
|
Fourth fourth = Fourth{}
|
||||||
|
) -> Ret
|
||||||
|
{
|
||||||
|
return shellcode_stub_helper<
|
||||||
|
Ret,
|
||||||
|
First,
|
||||||
|
Second,
|
||||||
|
Third,
|
||||||
|
Fourth,
|
||||||
|
void*,
|
||||||
|
void*
|
||||||
|
>(
|
||||||
|
shell,
|
||||||
|
first,
|
||||||
|
second,
|
||||||
|
third,
|
||||||
|
fourth,
|
||||||
|
shell_param,
|
||||||
|
nullptr
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Ret, typename... Args>
|
||||||
|
static inline auto spoof_call(
|
||||||
|
const void* trampoline,
|
||||||
|
Ret(*fn)(Args...),
|
||||||
|
Args... args
|
||||||
|
) -> Ret
|
||||||
|
{
|
||||||
|
struct shell_params
|
||||||
|
{
|
||||||
|
const void* trampoline;
|
||||||
|
void* function;
|
||||||
|
void* rbx;
|
||||||
|
};
|
||||||
|
|
||||||
|
shell_params p{ trampoline, reinterpret_cast<void*>(fn) };
|
||||||
|
using mapper = detail::argument_remapper<sizeof...(Args)>;
|
||||||
|
return mapper::template do_call<Ret, Args...>((const void*)&detail::_spoofer_stub, &p, args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" LONG NtProtectVirtualMemory(
|
||||||
|
HANDLE ProcessHandle,
|
||||||
|
PVOID* BaseAddress,
|
||||||
|
PULONG NumberOfBytesToProtect,
|
||||||
|
ULONG NewAccessProtection,
|
||||||
|
PULONG OldAccessProtection
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user