Chapter 5: Endpoint Attacks, Evasion Techniques, and Cryptography

Learning Objectives

Section 1: Endpoint Attack Vectors

Endpoints are rich attack targets — they hold credentials, process sensitive data, and typically trust the user sitting in front of them. Attackers exploit this trust through memory corruption, command infrastructure abuse, and malicious software designed to persist, exfiltrate, or extort.

1.1 Buffer Overflow Attacks

A buffer overflow occurs when a program writes more data to a fixed-size memory region than it can hold. The overflow spills into adjacent memory, allowing an attacker to overwrite the return address and redirect program execution.

The classic exploitation sequence:

  1. Attacker identifies a vulnerable input (e.g., a call to gets() or strcpy() with no bounds check)
  2. Crafted input fills the buffer, overflows into the saved RBP and return address (RIP/EIP)
  3. Return address is overwritten with attacker shellcode, a ROP gadget, or a libc function
  4. When the vulnerable function returns, execution jumps to attacker-controlled code
Stack Buffer Overflow — Memory Layout & Exploitation Stack Memory (High → Low address) Caller's Stack Frame 0xffffd0c0 Return Address (RIP) 0xffffd0b8 Saved RBP 0xffffd0b0 char buffer[64] (64 bytes allocated) 0xffffd070 0xffffd050 0xffffd030 ← ESP Buffer Saved RBP Return Addr Overflow bytes Crafted Input: 80 bytes [64 junk + 8 overwrites RBP + 8 overwrites RIP] Attacker Shellcode / ROP Chain 0xdeadbeef redirects execution Step 1: Input overflows buffer → overwrites RBP and RIP Step 2: Function returns → execution jumps to attacker code

Modern Mitigations and Bypass Techniques:

MitigationMechanismBypass Method
Stack CanaryRandom value between buffer and return address; checked before returnInfo-leak / format-string to read canary value
ASLRRandomizes base addresses of stack, heap, librariesMemory-disclosure to learn offsets; brute-force on 32-bit
DEP / NXMarks stack/heap non-executableReturn-Oriented Programming (ROP) chains existing gadgets
SafeStack / CFISeparate safe stacks; CFI enforces valid call targetsAdvanced JIT-spraying or corrupted vtable exploitation

Key Points — Buffer Overflows

1.2 Command-and-Control (C2) Frameworks

Once an attacker has initial access, they need persistent, bidirectional communication between compromised hosts (implants/beacons) and an operator's server. C2 frameworks provide this infrastructure.

FrameworkNotes
Cobalt StrikeCommercial; widely abused by ransomware operators; uses "Beacon" implant
Metasploit MeterpreterOpen-source; flexible staging; encrypted channels
SliverOpen-source Go-based; designed to replace Cobalt Strike for red teams
Brute Ratel C4Evades EDR via direct syscalls; emerged 2022

C2 channels include HTTP/HTTPS beaconing (port 80/443 blending with web traffic), DNS-based C2 (commands encoded in DNS queries), and social media/cloud storage (APTs embedding instructions in tweets or GitHub commits).

1.3 Malware Taxonomy

Malware TypePrimary ObjectivePersistenceExample
VirusSelf-replication; payload executionInfects executablesConficker
WormSelf-propagation across networksExploits network servicesWannaCry
TrojanBackdoor / credential theftMasquerades as legitimate softwareEmotet
RootkitPersistent stealthy accessHooks OS kernel or bootloaderNecurs
Fileless MalwareEvasion; lives in memory onlyPowerShell, WMI, registryPowerSploit
RATFull remote controlService installationDarkComet
Botnet AgentDDoS, spam, fraud at scaleC2 beacon with re-install dropperMirai

Fileless malware injects into legitimate process memory (svchost.exe), uses PowerShell/WMI as execution engines, and stores configuration in the Windows registry. Detection requires memory forensics and behavioral EDR with AMSI integration.

1.4 Ransomware

Ransomware encrypts victim files and demands payment for the decryption key. Modern "Big Game Hunting" combines data exfiltration with encryption (double extortion). Ransomware-as-a-Service (RaaS) allows affiliates to perform intrusions for a 70–80% revenue share.

flowchart LR A["Initial Access\n(Phishing / Exploit)"] --> B["Establish C2\n(Beacon)"] B --> C["Lateral Movement\n(Credential Dump,\nPass-the-Hash)"] C --> D["Data Exfiltration\n(Double Extortion)"] D --> E["Deploy Ransomware\nPayload"] E --> F["Encrypt Files +\nDrop Ransom Note"] F --> G["Extortion\n(Pay or Data Published)"] style A fill:#4a0000,color:#f5b7b1,stroke:#c0392b style B fill:#1a3a5c,color:#cdd9e5,stroke:#2980b9 style C fill:#4a0000,color:#f5b7b1,stroke:#c0392b style D fill:#2d1b00,color:#f9e4b7,stroke:#f39c12 style E fill:#4a0000,color:#f5b7b1,stroke:#c0392b style F fill:#4a0000,color:#f5b7b1,stroke:#c0392b style G fill:#7b0000,color:#f5b7b1,stroke:#922b21

Key Points — Malware & Ransomware

Pre-Check Quiz — Endpoint Attack Vectors

1. What exactly does a buffer overflow attack overwrite to redirect program execution?

2. Which technique allows attackers to bypass DEP/NX without injecting new shellcode?

3. What distinguishes "double extortion" ransomware from traditional ransomware?

4. What makes fileless malware difficult to detect with traditional antivirus?

Section 2: Evasion and Obfuscation Techniques

Maintaining access without triggering detection requires evading firewalls, IDS/IPS, EDR, DLP, and SIEM. Modern evasion targets the visibility gaps in these controls rather than defeating them head-on.

2.1 Protocol Tunneling

Protocol tunneling encapsulates one protocol's traffic inside another — specifically one that security controls allow through without inspection.

DNS Tunneling: DNS is almost universally permitted outbound. Attackers encode arbitrary data inside DNS query names and response records, creating a bidirectional covert channel over port 53.

DNS Tunneling — Covert Channel over Port 53 Victim Endpoint Compromised host Iodine client Recursive Resolver ISP / corporate DNS Forwards all queries Attacker Nameserver ns.attacker.com C2 operator Step 1: Victim encodes data as DNS subdomain query Q: aGVsbG8=.t1.attacker.com [base64 encoded data] Step 2: Resolver forwards query to attacker's nameserver Q: aGVsbG8=.t1.attacker.com Forwarded query (port 53) Step 3: Attacker decodes → encodes response in TXT record Decode: aGVsbG8= → "hello" Encode cmd → cmVzcG9uc2U= Step 4: TXT response travels back through resolver to victim TXT: cmVzcG9uc2U= [base64 encoded command] TXT: cmVzcG9uc2U= Decoded: command received ✓ Bidirectional covert channel established over port 53 (universally permitted) Port 53 ALLOWED → C2 Operator

DNS Tunneling Detection Signals:

IndicatorNormal DNSTunneling DNS
Query name lengthShort (<50 chars)Long (100+ chars), high entropy
Query volume per domainLowUnusually high burst to single domain
Record types queriedA, AAAA, MX, CNAMEHeavy TXT, NULL, or unusual types
Subdomain entropyLow (readable words)High (base64/hex strings)
Response sizeSmallLarge (TXT records packed with data)

2.2 Encrypted C2 Channels

Attackers abuse encryption to make malicious traffic indistinguishable from legitimate communications. HTTPS C2 over port 443 uses valid TLS certificates (free from Let's Encrypt); DNS-over-HTTPS (DoH) and DNS-over-TLS (DoT) encrypt DNS queries inside HTTPS, bypassing traditional DNS monitoring.

Detection approaches for encrypted C2:

2.3 Domain Generation Algorithms (DGAs) and DNS Fast Flux

DGAs are algorithms embedded in malware that generate hundreds of pseudo-random domain names using a seed (often the current date). Blocklisting one domain is useless — hundreds of alternatives are generated daily. DNS Fast Flux rapidly rotates A records (low TTL, ~60 seconds) using a botnet as proxy tier, defeating IP-based blocking.

2.4 Proxy Chains

Proxy chains route malicious traffic through a series of intermediate hosts, obfuscating the true origin. Each proxy knows only the previous and next hop. Common techniques include TOR (multi-hop onion routing), bulletproof hosting, legitimate cloud infrastructure (AWS/Azure/GCP relay nodes), and residential proxy networks.

2.5 Polymorphic and Metamorphic Malware

TypeMutation MethodAV Evasion
PolymorphicEncrypts payload with different key each infection; only the decryption stub changesEach copy has unique binary hash; signature only matches stub
MetamorphicRewrites own code logic (substitutes instructions, reorders blocks, inserts junk)No static signature survives — each instance is structurally different
Packers/CryptersCompress/encrypt binary; decompress/decrypt at runtimeFile-level scan sees only wrapper; behavior detection or sandbox required

Key Points — Evasion Techniques

Post-Check Quiz — Evasion & Obfuscation

5. Why is DNS an attractive protocol for covert C2 channels?

6. What does JA3 fingerprinting analyze to detect malware TLS sessions?

7. What distinguishes metamorphic malware from polymorphic malware?

Section 3: Cryptographic Foundations

Cryptography underpins every security control in this course. The four foundational primitives — symmetric encryption, asymmetric encryption, hashing, and key exchange — are composed together in real-world protocols like TLS.

3.1 Symmetric Encryption

Symmetric encryption uses a single shared secret key for both encryption and decryption. It is fast and suitable for bulk data, but has a key distribution problem: N parties require N×(N−1)/2 unique keys.

AlgorithmKey SizeTypeNotes
AES-128/256128 or 256 bitsBlock (128-bit)NIST standard; used in TLS, disk encryption, WPA3
ChaCha20256 bitsStreamFast in software; used in TLS 1.3 where AES-NI is unavailable
3DES168-bit effectiveBlock (64-bit)Legacy; deprecated in TLS 1.3
RC4VariableStreamBroken; prohibited in TLS (RFC 7465)

AES Block Modes: CBC (sequential, legacy TLS) → GCM (authenticated encryption AEAD, TLS 1.3/IPsec) → CTR (parallelizable, disk encryption). GCM provides both encryption and integrity in one pass.

3.2 Asymmetric Encryption

Asymmetric encryption uses a mathematically linked key pair. Data encrypted with the public key can only be decrypted by the private key. It solves the key distribution problem but is orders of magnitude slower than symmetric encryption — used only for handshake/authentication, not bulk data.

AlgorithmBased OnKey SizeCommon Use
RSAInteger factorization2048–4096 bitsKey encipherment, digital signatures
ECDSAElliptic curve discrete log256–384 bitsTLS certificates, code signing
ECDHEElliptic curve Diffie-Hellman256–384 bitsKey exchange in TLS (mandatory in 1.3)
EdDSA (Ed25519)Edwards-curve256 bitsSSH keys, JWT signing

3.3 Cryptographic Hashing

A cryptographic hash maps arbitrary input to a fixed-length digest with three key properties: pre-image resistance (can't reverse H(x) to find x), collision resistance (can't find x≠y where H(x)=H(y)), and avalanche effect (one-bit change → completely different digest).

AlgorithmOutputStatus
MD5128 bitsBroken — do not use for security
SHA-1160 bitsDeprecated; collision demonstrated (SHAttered, 2017)
SHA-256256 bitsCurrent standard; TLS, certificates, code signing
SHA-384/512384/512 bitsHigh-assurance certificates
SHA-3 (Keccak)VariableNIST standard; different construction from SHA-2

3.4 Diffie-Hellman Key Exchange

DH solves the problem of establishing a shared secret over an untrusted channel without transmitting the secret. Both parties compute the same value using public and private components; an eavesdropper sees only the public values and cannot compute the shared secret without solving the discrete logarithm problem.

sequenceDiagram participant A as Alice participant N as Untrusted Network (Eavesdropper) participant B as Bob Note over A,B: Agree publicly on prime p and generator g A->>N: Publish: p, g N->>B: Forward: p, g Note over A: Choose private: a; Compute A = g^a mod p A->>N: Send public value: A N->>B: Forward: A Note over B: Choose private: b; Compute B = g^b mod p B->>N: Send public value: B N->>A: Forward: B Note over A: Compute B^a mod p = g^(ab) mod p Note over B: Compute A^b mod p = g^(ab) mod p Note over A,B: Shared secret established ✓ Note over N: Sees p,g,A,B — cannot compute g^(ab) mod p

Ephemeral DH (DHE/ECDHE) generates a new key pair for each TLS session and discards it after use — providing Perfect Forward Secrecy (PFS): past sessions remain secure even if the server's long-term private key is later compromised.

Key ExchangePFSPerformanceUse
RSA key enciphermentNoModerateLegacy TLS 1.2
DHEYesSlower (CPU)TLS 1.2
ECDHEYesFast (ECC efficiency)TLS 1.2 & 1.3 (mandatory)

Key Points — Cryptographic Foundations

Pre-Check Quiz — Cryptographic Foundations

8. Why does TLS use asymmetric cryptography only during the handshake, then switch to symmetric?

9. What property of Perfect Forward Secrecy (PFS) protects past TLS sessions?

10. Which hash algorithm is considered broken due to demonstrated collision attacks and must NOT be used for new security applications?

Section 4: PKI and Certificate Management

A Public Key Infrastructure (PKI) is the system of policies, processes, hardware, software, and people that manages digital certificates and public-key encryption — turning raw asymmetric cryptography into a scalable, trusted identity system.

4.1 PKI Architecture

The core problem PKI solves: how does Alice know a public key actually belongs to Bob and not an attacker performing MitM? A trusted third party — a Certificate Authority (CA) — signs a certificate binding a public key to an identity.

ComponentRole
Root CASelf-signed trust anchor; kept offline in HSM vaults; signs Intermediate CA certificates
Intermediate CASigns end-entity certificates; online; limits exposure of Root CA private key
End-Entity CertificateIssued to servers, users, or devices; contains public key + identity + validity + extensions
Registration Authority (RA)Verifies identity before certificate issuance
OCSP ResponderReal-time revocation status: returns "good", "revoked", or "unknown"
flowchart TD RootCA["Root CA\n(Self-signed, offline, HSM vault)\nTrust Anchor"] IntCA["Intermediate CA\n(Cross-signed by Root, online)\nSigns end-entity certs"] LeafServer["Server Certificate (leaf)\nwww.example.com"] LeafUser["User Certificate (leaf)\[email protected]"] LeafCode["Code Signing Cert (leaf)\nExample Corp"] TrustStore["Client Trust Store\n(OS/Browser pre-installed roots)"] RootCA -- "signs" --> IntCA IntCA -- "signs" --> LeafServer IntCA -- "signs" --> LeafUser IntCA -- "signs" --> LeafCode TrustStore -- "contains" --> RootCA style RootCA fill:#1a3a5c,color:#aed6f1,stroke:#2980b9,stroke-width:2px style IntCA fill:#1c3a1c,color:#abebc6,stroke:#27ae60,stroke-width:1px style LeafServer fill:#2d1b00,color:#f9e4b7,stroke:#f39c12 style LeafUser fill:#2d1b00,color:#f9e4b7,stroke:#f39c12 style LeafCode fill:#2d1b00,color:#f9e4b7,stroke:#f39c12 style TrustStore fill:#1a0030,color:#d7bde2,stroke:#8e44ad

4.2 X.509 Certificate Structure

X.509v3 is the current ITU-T standard for public-key certificates, extended by RFC 5280 for Internet use.

FieldDescriptionExample
VersionX.509 version3
Serial NumberUnique integer assigned by the CA0x3E7F2A...
Signature AlgorithmAlgorithm CA used to sign this certsha256WithRSAEncryption
IssuerDistinguished Name of signing CACN=DigiCert Global CA G2
ValidityNot Before / Not After2025-01-01 to 2026-01-01
SubjectDistinguished Name of certificate holderCN=www.example.com
Subject Public Key InfoAlgorithm + public key valueRSA 2048-bit public key
Extensions (v3)SAN, Key Usage, EKU, Basic Constraints, OCSP URL…See table below

Critical X.509v3 Extensions:

ExtensionPurpose
Subject Alternative Name (SAN)Additional hostnames/IPs the cert is valid for (replaced CN for host binding)
Key UsageAllowable operations: digitalSignature, keyEncipherment, keyCertSign
Extended Key Usage (EKU)Fine-grained purpose: serverAuth, clientAuth, codeSigning, emailProtection
Basic ConstraintsisCA flag; pathLenConstraint limits depth of sub-CA chains
CRL Distribution PointsURL(s) where the CRL can be downloaded
Authority Info AccessOCSP responder URL; CA issuer certificate URL
TLS Certificate Chain Validation — Step by Step TLS Client Browser / App Has Trust Store (pre-installed roots) Leaf Certificate CN=www.example.com Signed by: Intermediate CA SAN: www.example.com, example.com Intermediate CA Signed by: Root CA Verified against Root public key Root CA Self-signed Found in client Trust Store ✓ 1. Server presents leaf + intermediate 2. Verify leaf sig → Intermediate pub key 3. Verify intermediate sig → Root pub key 4. Root found in Trust Store 5. Check validity period (Not Before/After) 6. Check revocation via OCSP 7. Verify hostname matches SAN field 8. Verify EKU permits serverAuth All checks passed → TLS handshake proceeds → Encrypted session established

4.3 Cipher Suites

A cipher suite is a named combination of four cryptographic algorithms negotiated during the TLS handshake.

TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
 |    |     |       |    |   |    |
 |    |     |       |    |   |    +-- HMAC/PRF hash
 |    |     |       |    |   +------- Mode (AEAD)
 |    |     |       |    +----------- Key size (256 bits)
 |    |     |       +---------------- Bulk cipher (AES)
 |    |     +------------------------ Authentication (RSA cert)
 |    +------------------------------ Key exchange (ECDHE)
 +----------------------------------- Protocol

TLS 1.3 removes key exchange and authentication from the suite name (negotiated separately). Only AEAD cipher + hash remain: TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256.

Weak/Prohibited Cipher Suites to Block:

4.4 PKCS Standards

StandardNamePurposeExtension
PKCS#1RSA CryptographyRSA key format; PKCS1v15, OAEP, PSS padding.pem (RSA PRIVATE KEY)
PKCS#7Cryptographic Message SyntaxSigned/encrypted data; S/MIME; certificate chains.p7b, .p7c
PKCS#8Private Key InfoVendor-neutral private key encoding; supersedes PKCS#1.pem (PRIVATE KEY)
PKCS#10Certificate RequestCSR format sent to CA when requesting a certificate.csr, .req
PKCS#11CryptokiAPI for hardware tokens (HSMs, smart cards)API standard
PKCS#12Personal Information ExchangeBundles private key + certificate + chain into encrypted archive.pfx, .p12

Certificate Revocation:

MethodMechanismProsCons
CRLDownload list of revoked serial numbersSimple; no real-time dependencyStale; large files
OCSPReal-time query per certificateTimely; small responsePrivacy (CA learns what you check); responder availability
OCSP StaplingServer includes OCSP response in TLS handshakePrivacy-preserving; no client-to-CA connectionServer must refresh regularly
CRLite / OneCRLBrowser-bundled compressed revocation setsNo real-time dependency; privacyBrowser-specific; update cycle

Key Points — PKI and Certificate Management

Post-Check Quiz — PKI and Certificate Management

11. Why do PKI hierarchies use Intermediate CAs rather than having the Root CA sign all end-entity certificates directly?

12. Which X.509v3 extension is the authoritative field for hostname binding in modern TLS (replacing the legacy CN field)?

13. What does PKCS#12 (.pfx / .p12) bundle together?

14. In TLS 1.3, which of the following is no longer included in the cipher suite name?

15. What problem does OCSP Stapling solve compared to standard OCSP?

Your Progress

Answer Explanations