Skip to content

Commit e08d4a2

Browse files
committed
fixed DarthTon#295
1 parent 34c0ca3 commit e08d4a2

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

src/BlackBone/Process/RPC/RemoteContext.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class RemoteContext
134134
return _ctx.R9;
135135

136136
default:
137-
return _memory.Read<DWORD64>( _ctx.Rsp + 0x30 + (index - 4) * _wordSize ).result( 0 );
137+
return _memory.Read<DWORD64>( _ctx.Rsp + 0x28 + (index - 4) * _wordSize ).result( 0 );
138138
}
139139
}
140140
else
@@ -173,7 +173,7 @@ class RemoteContext
173173
break;
174174

175175
default:
176-
return (_memory.Write( _ctx.Rsp + 0x30 + (index - 4) * _wordSize, val ) == STATUS_SUCCESS);
176+
return (_memory.Write( _ctx.Rsp + 0x28 + (index - 4) * _wordSize, val ) == STATUS_SUCCESS);
177177
}
178178

179179
return true;

src/BlackBoneTest/TestRemoteHook.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Testing
44
{
55
struct HookClass
66
{
7-
void HookFn( RemoteContext& context )
7+
void HookNtOpenProcess( RemoteContext& context )
88
{
99
//
1010
// Get process ID
@@ -26,6 +26,18 @@ namespace Testing
2626
}
2727
}
2828

29+
void HookNtAllocateVirtualMemory( RemoteContext& context )
30+
{
31+
AssertEx::AreEqual( reinterpret_cast<HANDLE>(context.getArg( 0 )), GetCurrentProcess() );
32+
AssertEx::AreNotEqual( context.getArg( 1 ), DWORD64( 0 ) );
33+
AssertEx::AreEqual( context.getArg( 2 ), DWORD64( 0 ) );
34+
AssertEx::AreNotEqual( context.getArg( 3 ), DWORD64( 0 ) );
35+
AssertEx::AreEqual( context.getArg( 4 ), DWORD64( MEM_RESERVE | MEM_COMMIT ) );
36+
AssertEx::AreEqual( context.getArg( 5 ), DWORD64( PAGE_EXECUTE_READWRITE ) );
37+
38+
calls++;
39+
}
40+
2941
Process process;
3042
int calls = 0;
3143
};
@@ -54,7 +66,7 @@ namespace Testing
5466
AssertEx::IsTrue( pHookFn.success() );
5567

5668
// Hook and try to terminate from remote process
57-
AssertEx::NtSuccess( hooker.process.hooks().Apply( RemoteHook::hwbp, pHookFn->procAddress, &HookClass::HookFn, hooker ) );
69+
AssertEx::NtSuccess( hooker.process.hooks().Apply( RemoteHook::hwbp, pHookFn->procAddress, &HookClass::HookNtOpenProcess, hooker ) );
5870

5971
auto terminate = MakeRemoteFunction<long( *)(DWORD)>( hooker.process, terminatePtr->procAddress );
6072
auto result = terminate( GetCurrentProcessId() );
@@ -65,5 +77,33 @@ namespace Testing
6577
AssertEx::AreEqual( ERROR_ACCESS_DENIED, result.result() );
6678
AssertEx::AreEqual( 1, hooker.calls );
6779
}
80+
81+
TEST_METHOD( NtAllocateVirtualMemory )
82+
{
83+
HookClass hooker;
84+
85+
auto path = GetTestHelperHost();
86+
AssertEx::IsFalse( path.empty() );
87+
88+
// Give process some time to initialize
89+
AssertEx::NtSuccess( hooker.process.CreateAndAttach( path ) );
90+
Sleep( 100 );
91+
92+
// Get function
93+
auto pHookFn = hooker.process.modules().GetNtdllExport( "NtAllocateVirtualMemory" );
94+
AssertEx::IsTrue( pHookFn.success() );
95+
96+
PVOID base = nullptr;
97+
SIZE_T size = 0xDEAD;
98+
auto NtAllocateVirtualMemory = MakeRemoteFunction<NTSTATUS( __stdcall * )(HANDLE, PVOID*, ULONG_PTR, PSIZE_T, ULONG, ULONG)>( hooker.process, pHookFn->procAddress );
99+
100+
// Hook and try to call
101+
AssertEx::NtSuccess( hooker.process.hooks().Apply( RemoteHook::hwbp, pHookFn->procAddress, &HookClass::HookNtAllocateVirtualMemory, hooker ) );
102+
auto result = NtAllocateVirtualMemory.Call( { GetCurrentProcess(), &base, 0, &size, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE } );
103+
104+
hooker.process.Terminate();
105+
106+
AssertEx::AreEqual( 1, hooker.calls );
107+
}
68108
};
69109
}

0 commit comments

Comments
 (0)