Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix swapped arguments in x64 builders #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions DotNet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,12 @@ public static byte[] ConvertToShellcode(byte[] dllBytes, uint functionHash, byte
newShellcode.Add(0xec);
newShellcode.Add(6 * 8); // 32 bytes for shadow space + 8 bytes for last arg + 8 bytes for stack alignment

// mov qword ptr [rsp + 0x28], rcx (shellcode base) - Push in arg 5
// mov qword ptr [rsp + 0x20], rcx (shellcode base) - Push in arg 5
newShellcode.Add(0x48);
newShellcode.Add(0x89);
newShellcode.Add(0x4C);
newShellcode.Add(0x24);
newShellcode.Add(5 * 8);
newShellcode.Add(4 * 8);

// Setup the location of the DLL into RCX
// add rcx, <Offset of the DLL>
Expand All @@ -586,11 +586,11 @@ public static byte[] ConvertToShellcode(byte[] dllBytes, uint functionHash, byte
foreach (byte b in BitConverter.GetBytes(dllOffset))
newShellcode.Add(b);

// mov dword ptr [rsp + 0x20], <Flags> - Push arg 6 just above shadow space
// mov dword ptr [rsp + 0x28], <Flags> - Push arg 6 just above shadow space
newShellcode.Add(0xc7);
newShellcode.Add(0x44);
newShellcode.Add(0x24);
newShellcode.Add(4 * 8);
newShellcode.Add(5 * 8);
foreach (byte b in BitConverter.GetBytes((uint)flags))
newShellcode.Add(b);

Expand Down
8 changes: 4 additions & 4 deletions Native/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ BOOL ConvertToShellcode(LPVOID inBytes, DWORD length, DWORD userFunction, LPVOID
bootstrap[i++] = 0xec;
bootstrap[i++] = 6 * 8; // 32 bytes for shadow space + 16 bytes for last args

// mov qword ptr [rsp + 0x28], rcx (shellcode base) - Push in arg 5
// mov qword ptr [rsp + 0x20], rcx (shellcode base) - Push in arg 5
bootstrap[i++] = 0x48;
bootstrap[i++] = 0x89;
bootstrap[i++] = 0x4C;
bootstrap[i++] = 0x24;
bootstrap[i++] = 5 * 8;
bootstrap[i++] = 4 * 8;

// add rcx, <Offset of the DLL>
bootstrap[i++] = 0x48;
Expand All @@ -195,11 +195,11 @@ BOOL ConvertToShellcode(LPVOID inBytes, DWORD length, DWORD userFunction, LPVOID
MoveMemory(bootstrap + i, &dllOffset, sizeof(dllOffset));
i += sizeof(dllOffset);

// mov dword ptr [rsp + 0x20], <Flags> - Push arg 6 just above shadow space
// mov dword ptr [rsp + 0x28], <Flags> - Push arg 6 just above shadow space
bootstrap[i++] = 0xC7;
bootstrap[i++] = 0x44;
bootstrap[i++] = 0x24;
bootstrap[i++] = 4 * 8;
bootstrap[i++] = 5 * 8;
MoveMemory(bootstrap + i, &flags, sizeof(flags));
i += sizeof(flags);

Expand Down
8 changes: 4 additions & 4 deletions PowerShell/ConvertTo-Shellcode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ public class sRDI
newShellcode.Add(0xec);
newShellcode.Add(6 * 8); // 32 bytes for shadow space + 8 bytes for last arg + 8 bytes for stack alignment

// mov qword ptr [rsp + 0x28], rcx (shellcode base) - Push in arg 5
// mov qword ptr [rsp + 0x20], rcx (shellcode base) - Push in arg 5
newShellcode.Add(0x48);
newShellcode.Add(0x89);
newShellcode.Add(0x4C);
newShellcode.Add(0x24);
newShellcode.Add(5 * 8);
newShellcode.Add(4 * 8);

// Setup the location of the DLL into RCX
// add rcx, <Offset of the DLL>
Expand All @@ -140,11 +140,11 @@ public class sRDI
foreach (byte b in BitConverter.GetBytes(dllOffset))
newShellcode.Add(b);

// mov dword ptr [rsp + 0x20], <Flags> - Push arg 6 just above shadow space
// mov dword ptr [rsp + 0x28], <Flags> - Push arg 6 just above shadow space
newShellcode.Add(0xc7);
newShellcode.Add(0x44);
newShellcode.Add(0x24);
newShellcode.Add(4 * 8);
newShellcode.Add(5 * 8);
foreach (byte b in BitConverter.GetBytes((uint)flags))
newShellcode.Add(b);

Expand Down
8 changes: 4 additions & 4 deletions Python/ShellcodeRDI.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ def ConvertToShellcode(dllBytes, functionHash=0x10, userData=b'None', flags=0):
bootstrap += b'\x48\x83\xec'
bootstrap += b'\x30' # 32 bytes for shadow space + 16 bytes for last args

# mov qword ptr [rsp + 0x28], rcx (shellcode base) - Push in arg 5
# mov qword ptr [rsp + 0x20], rcx (shellcode base) - Push in arg 5
bootstrap += b'\x48\x89\x4C\x24'
bootstrap += b'\x28'
bootstrap += b'\x20'

# add rcx, <Offset of the DLL>
bootstrap += b'\x48\x81\xc1'
bootstrap += pack('I', dllOffset)

# mov dword ptr [rsp + 0x20], <Flags> - Push in arg 6 just above shadow space
# mov dword ptr [rsp + 0x28], <Flags> - Push in arg 6 just above shadow space
bootstrap += b'\xC7\x44\x24'
bootstrap += b'\x20'
bootstrap += b'\x28'
bootstrap += pack('I', flags)

# call - Transfer execution to the RDI
Expand Down