push
pop
mov
call
ret
jmp
cmp
test
xor
lea
add
sub
academy$ cd /lessons/assembly-basics && cat lesson.info
-rw-r--r-- 1 hacker hacker 15KB Dec 25 10:30 lesson.info
[LESSON_02][BEGINNER]

[πŸ› οΈ ASSEMBLY FUNDAMENTALS]

// Master the building blocks of reverse engineering by understanding assembly language, CPU architecture, and how high-level code translates to machine instructions.

academy$ cat objectives.md

[🎯 LEARNING_OBJECTIVES]

> learning_outcomes.list

  • [βœ“]Understand CPU architecture basics and instruction execution
  • [βœ“]Know the purpose and usage of CPU registers
  • [βœ“]Read and interpret basic assembly instructions
  • [βœ“]Understand memory layout and addressing modes

> prerequisites.cfg

  • - Basic programming concepts
  • - Understanding of variables and functions
  • - Completed Lesson 1: Foundations
# Estimated completion time: 3 hours
academy$ ls -la /tools/assembly_analysis/

[πŸ› οΈ ESSENTIAL_TOOLS]

[! WARNING] Tool Setup Required

# This lesson contains real analysis outputs and screenshots.
# Install the tools below to follow along with hands-on practice.

$Free Tools (Start Here!)

πŸ” Ghidra (NSA's Free Disassembler)

Professional-grade reverse engineering tool, completely free!

Install: Download from ghidra-sre.org
Platforms: Windows, macOS, Linux
Best for: Complete binary analysis, decompilation

πŸ’» Command Line Tools

Built into most systems or easily installable:

objdump - Disassemble binaries
strings - Extract text from binaries
hexdump - View binary data
file - Identify file types

🐍 Radare2/rizin

Powerful command-line reverse engineering framework

Install: brew install radare2 (macOS)
Best for: Advanced users, scripting, automation

πŸ’ŽProfessional Tools

πŸ”₯ IDA Pro (Industry Standard)

The gold standard for professional reverse engineering

Cost: $1,800+ (Free version available with limitations)
Best for: Professional malware analysis, research

⚑ x64dbg (Windows Debugger)

Excellent free debugger for Windows programs

Install: Download from GitHub (x64dbg/x64dbg)
Best for: Dynamic analysis, debugging

πŸ”¬ Binary Ninja

Modern interface with powerful analysis capabilities

Cost: $399+ (Student discounts available)
Best for: Modern UI, plugin development

πŸš€ Quick Start: Your First Analysis (Using Ghidra)

1. Installation

# Download Ghidra from ghidra-sre.org
# Extract the zip file
# Run ghidraRun (Linux/Mac) or ghidraRun.bat (Windows)

2. Create Your First Project

β€’ File β†’ New Project
β€’ Choose "Non-Shared Project"
β€’ Give it a name like "Assembly_Practice"

3. Import a Binary

β€’ Drag & drop any executable file
β€’ Or File β†’ Import File
β€’ Try with /bin/ls (Linux/Mac) or C:\Windows\System32\calc.exe

4. Start Analysis

β€’ Double-click your imported file
β€’ Click "Yes" when asked to analyze
β€’ Wait for analysis to complete

πŸ’‘ Pro Tip: Start with simple programs like calculator or text editors. They're easier to understand and less overwhelming than complex software.

academy$ cat /proc/cpuinfo | head -20

[🏒️ CPU_ARCHITECTURE]

The Central Processing Unit (CPU)

The CPU is the brain of your computer, executing instructions one by one in a continuous cycle. Understanding this cycle is crucial for reverse engineering because we're essentially reading the CPU's "thoughts" when we analyze assembly code.

🎯 Why This Matters for Reverse Engineering:

  • β€’ Malware Analysis: Understanding how instructions execute helps you trace malicious behavior step by step
  • β€’ Vulnerability Research: CPU execution patterns reveal where programs might crash or behave unexpectedly
  • β€’ Code Protection Bypass: Knowing instruction flow helps you skip license checks or authentication
  • β€’ Performance Analysis: Identify bottlenecks and optimization opportunities in software

πŸ“‹ The Instruction Execution Cycle

πŸ”
Fetch

Get next instruction from memory

πŸ”
Decode

Interpret what the instruction means

⚑
Execute

Perform the operation

πŸ’Ύ
Store

Save results if needed

πŸ“ Real Example: Password Check Bypass

Imagine you're reversing a program with a password check:

; High-level: if (password == "secret123") unlock();
cmp rax, rbx ; Compare entered password with correct one
je unlock_function ; Jump to unlock if equal
jmp access_denied ; Otherwise deny access

Reverse Engineering Insight: You could change the je (jump if equal) to jmp (always jump) to bypass the password check entirely!

x86-64 Architecture Overview

Most modern computers use x86-64 architecture (also called AMD64). This is what we'll focus on as it's the most common in reverse engineering scenarios.

πŸ” Key Characteristics of x86-64:

  • β€’ 64-bit architecture - Can handle 64-bit data and addresses
  • β€’ Variable instruction length - Instructions can be 1-15 bytes long
  • β€’ Complex Instruction Set - Many powerful instructions available
  • β€’ Multiple addressing modes - Flexible ways to access memory

πŸ’» Reverse Engineering Impact:

Variable Length = Analysis Challenge

Disassemblers can misinterpret where instructions start/end, making malware analysis harder.

Complex Instructions = Hidden Logic

Single instructions can perform multiple operations, hiding complex behavior in simple-looking code.

academy$ gdb -batch -ex "info registers"

[πŸ“¦ CPU_REGISTERS]

Registers are like the CPU's personal workspace - small, super-fast storage locations directly inside the processor. Think of them as the CPU's "hands" for holding and manipulating data.

πŸ•΅οΈβ€β™‚οΈ Why Registers are a Reverse Engineer's Best Friend:

Function Arguments

Registers hold function parameters, revealing what data is being passed around

Return Values

Function results appear in specific registers, showing program outcomes

Hidden Data

Malware often stores decryption keys or important values in registers

Program State

Register contents reveal the current state and behavior of the program

πŸ› οΈ General Purpose Registers

RAX64-bit

Accumulator - Often holds return values

Common use: Function results, arithmetic

πŸ” RE Example: Check if function returned 0 (success) or 1 (failure)

RBX64-bit

Base - General storage

Common use: Data storage, base addresses

πŸ” RE Example: Often holds pointers to important data structures or strings

RCX64-bit

Counter - Loop operations

Common use: Loop counters, string operations

πŸ” RE Example: Find loop boundaries to understand encryption algorithms

RDX64-bit

Data - I/O operations

Common use: I/O port access, large arithmetic

πŸ” RE Example: Contains file handles or network socket descriptors

RSI64-bit

Source Index - Source for operations

Common use: String/memory copy source

πŸ” RE Example: Points to source data in memory copying/decryption routines

RDI64-bit

Destination Index

Common use: String/memory copy destination

πŸ” RE Example: Points to where malware writes decoded payload

R8-R1564-bit

Additional general registers

Common use: Extra storage in 64-bit mode

πŸ” RE Example: Modern malware uses these for complex obfuscation schemes

βš™οΈ Special Purpose Registers

RIPSpecial

Instruction Pointer

Points to next instruction to execute

RE Importance: Critical for control flow analysis

RSPSpecial

Stack Pointer

Points to top of the stack

RE Importance: Essential for function calls

RBPSpecial

Base Pointer

Points to base of current stack frame

RE Importance: Helps navigate local variables

RFLAGSSpecial

Status Flags

Stores condition codes and CPU state

RE Importance: Controls conditional jumps

πŸ’‘ Pro Tip: Register Naming

Registers have different names based on their size:

  • β€’ RAX = 64-bit (full register)
  • β€’ EAX = 32-bit (lower half)
  • β€’ AX = 16-bit (lower quarter)
  • β€’ AL = 8-bit (lowest byte)

πŸ” Practical Example: License Check Analysis

Let's see how registers reveal program logic:

; License validation function
mov rdi, license_key ; Load license key address into RDI
call validate_license ; Call validation function
test rax, rax ; Check return value in RAX
jz show_trial_popup ; Jump if RAX = 0 (invalid license)
mov rbx, 1 ; Set RBX = 1 (full version flag)
What we learned:
  • β€’ RDI holds the license key - we found where it's stored!
  • β€’ RAX contains validation result - 0 = invalid, non-zero = valid
  • β€’ RBX tracks software mode - we could patch this to always = 1
academy$ objdump -d ./binary | head -30

[πŸ“ ASSEMBLY_INSTRUCTIONS]

Assembly instructions are like a very simple language the CPU understands. Each instruction tells the CPU to perform one basic operation. Let's learn the most common ones you'll encounter in reverse engineering.

⚑ Why Each Instruction Type Matters in Reverse Engineering:

πŸ“¦ Data Movement

Reveals how malware loads encrypted payloads, API addresses, or configuration data

πŸ”’ Arithmetic

Shows encryption/decryption algorithms, checksum calculations, and obfuscation math

πŸ”„ Control Flow

Exposes program logic - loops, conditions, function calls, and decision points

πŸ“¦Data Movement Instructions

MOV

Copy data from source to destination

mov rax, 42 ; Put value 42 into RAX
mov rbx, rax ; Copy RAX value to RBX
mov rax, [rbp-8] ; Load value from memory
πŸ” RE Insight: mov rax, [0x401000]might load a decryption key from a fixed memory location!

LEA

Load Effective Address - calculate address

lea rax, [rbx+8] ; RAX = address of RBX+8
lea rcx, [rsi*2] ; RCX = address of RSI*2

πŸ”’Arithmetic Instructions

ADD / SUB

Addition and subtraction

add rax, 5 ; RAX = RAX + 5
sub rbx, rcx ; RBX = RBX - RCX
add rax, [rsp] ; RAX = RAX + value at RSP
πŸ” RE Example: Simple XOR decryption often usesadd rax, 1 to increment through encrypted data!

MUL / IMUL

Unsigned and signed multiplication

imul rax, 3 ; RAX = RAX * 3
imul rbx, rcx ; RBX = RBX * RCX

πŸ”„Control Flow Instructions

JMP

Unconditional jump

jmp label ; Jump to label
jmp rax ; Jump to address in RAX

CMP

Compare two values

cmp rax, 0 ; Compare RAX to 0
cmp rbx, rcx ; Compare RBX to RCX

Conditional Jumps

Jump based on flags

je label ; Jump if equal
jne label ; Jump if not equal
jg label ; Jump if greater

🧠 Understanding Control Flow

The combination of CMP followed by conditional jumps is how if-statements, loops, and other control structures are implemented at the assembly level. This pattern is everywhere in reverse engineering!

; Trial software time check
mov rax, [trial_days] ; Load days used
cmp rax, 30 ; Compare with 30 days
jg show_expired_message ; Jump if > 30 days
jmp continue_normal ; Otherwise continue
πŸ”§ Bypass Strategy: Change jg to jmp continue_normalto make the trial never expire!
academy$ cat /proc/self/maps

[πŸ—ΊοΈ MEMORY_LAYOUT]

Understanding how programs organize memory is crucial for reverse engineering. Let's explore the typical memory layout of a running program.

πŸ›‘οΈ Why Memory Layout is Critical for Security Analysis:

Buffer Overflow Detection

Stack layout helps identify when programs write beyond buffer boundaries

Exploit Development

Memory layout knowledge is essential for ROP chains and shellcode injection

Malware Analysis

Understanding where malware stores data helps locate encryption keys and config

Anti-Analysis Evasion

Memory protections and ASLR can be bypassed with proper layout understanding

πŸ“š Memory Sections

StackHigh addresses

Function calls, local variables

Grows downward

HeapMiddle addresses

Dynamic memory allocation

Grows upward

DataLow addresses

Global variables, initialized data

Fixed size

TextLowest addresses

Program instructions (code)

Fixed size

🎯 Addressing Modes

Different ways to specify where data is located:

Immediatemov rax, 42

Value is specified directly in instruction

Registermov rax, rbx

Value is in a register

Direct Memorymov rax, [0x400000]

Value is at specific memory address

Indirectmov rax, [rbx]

Address is stored in register

Displacementmov rax, [rbp-8]

Base register plus/minus offset

Indexedmov rax, [rbx+rcx*4]

Complex calculation for address

πŸ” Reverse Engineering Tip:

Pay attention to addressing patterns![rbp-8], [rbp-16]usually indicate local variables, while[rip+offset] often points to global data.

πŸ’₯ Buffer Overflow Example:

Here's how addressing reveals vulnerability:

; Vulnerable function
mov rdi, [rbp-32] ; Load buffer address
mov rsi, user_input ; Load user input
call strcpy ; Copy without bounds check!
; If input > 32 bytes, overwrites return address at [rbp+8]

Vulnerability: Buffer at [rbp-32] can overflow into return address at [rbp+8], allowing code execution!

academy$ ./analyze_binary --step-by-step --beginner-mode

[πŸ”¬ BINARY_ANALYSIS_TUTORIAL]

🎯 Learning Goal

By following this guide, you'll learn exactly how to analyze any binary file from start to finish. We'll use both command-line tools and Ghidra to give you multiple approaches.

CLICommand Line Analysis

Step 1: Basic File Info

# Check file type
file /path/to/binary
# Check file size
ls -la /path/to/binary

Always start here! Know what you're dealing with.

Step 2: String Analysis

# Extract all strings
strings /path/to/binary
# Look for URLs/IPs
strings /path/to/binary | grep -E "http|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"
# Find function names
strings /path/to/binary | grep -E "^[a-zA-Z_][a-zA-Z0-9_]*$"

Strings reveal a lot! Look for passwords, URLs, error messages.

Step 3: Disassembly

# Disassemble main function
objdump -d /path/to/binary | grep -A 20 "<main>"
# Show all functions
objdump -t /path/to/binary

Start with main(), then explore interesting functions.

Step 4: Advanced Analysis

# Check for security features
checksec --file=/path/to/binary
# Library dependencies
ldd /path/to/binary # Linux
otool -L /path/to/binary # macOS

Understand the binary's security posture and dependencies.

GUIGhidra Analysis

Step 1: Import & Analyze

  • β€’ File β†’ Import File (or drag & drop)
  • β€’ Double-click imported file
  • β€’ Click "Yes" to analyze when prompted
  • β€’ Wait for auto-analysis to complete (green bar)
πŸ’‘ Tip: Auto-analysis finds functions, strings, and references automatically!

Step 2: Navigate the Interface

  • β€’ Symbol Tree: Functions, variables, imports
  • β€’ Listing: Assembly code view
  • β€’ Decompiler: C-like pseudo code
  • β€’ Program Tree: File structure
πŸ” Pro Tip: Click on main() in Symbol Tree to jump to the entry point!

Step 3: Analysis Features

  • β€’ String Search: Search β†’ For Strings
  • β€’ Cross References: Right-click β†’ Show References
  • β€’ Function Graph: Window β†’ Function Graph
  • β€’ Hex View: Window β†’ Bytes
⚑ Quick Tip: Press 'G' to jump to any address directly!

Step 4: Make Notes

  • β€’ Right-click β†’ Set Comment (add notes)
  • β€’ Right-click β†’ Set Label (rename functions)
  • β€’ Bookmarks β†’ Add Bookmark (save locations)
  • β€’ File β†’ Export β†’ Various formats
πŸ“ Remember: Good analysis notes are crucial for complex binaries!

🎯 Common Patterns to Look For

🚨 Suspicious Indicators

β€’
Anti-debugging: ptrace, IsDebuggerPresent
β€’
Network activity: IP addresses, URLs, ports
β€’
File operations: fopen, temp directories, persistence paths
β€’
Encryption/Obfuscation: XOR operations, base64, random-looking strings

βœ… Normal Program Elements

β€’
Standard functions: main, printf, malloc
β€’
Error messages: "Usage:", "Error:", help text
β€’
Version info: Version numbers, copyright, author
β€’
Libraries: Standard system libraries, common frameworks
academy$ cd /exercises && ls -la

[πŸ”¬ HANDS_ON_EXERCISES]

Now that you know the process, let's practice! We'll analyze two binaries: a simple "hello" program and an educational malware simulation. Use the techniques from above to follow along.

1Exercise 1: Hello Binary Analysis

Let's start with our simple hello program to understand the basics.

Step 1: File Information

First, let's identify what type of file we're dealing with:

$ file exercises/hello
exercises/hello: Mach-O 64-bit executable arm64
# Alternative: Get more details
$ file -b exercises/hello
Mach-O 64-bit executable arm64
# Check file size and permissions
$ ls -la exercises/hello
-rwxr-xr-x 1 user staff 16384 Dec 25 10:30 exercises/hello
βœ… What this tells us:
  • β€’ 64-bit ARM executable (Apple Silicon)
  • β€’ 16KB file size (typical for simple programs)
  • β€’ Executable permissions set
πŸ”§ Troubleshooting:
  • β€’ No file? Check you're in the right directory
  • β€’ Permission denied? Use chmod +x
  • β€’ Different architecture? That's expected!

Step 2: String Analysis

Extract readable strings to understand the program's purpose:

$ strings exercises/hello
Hello, Reverse Engineering World!
This is a simple program for analysis.
/System/Library/Frameworks/...
dylib
# Filter for interesting strings only
$ strings exercises/hello | grep -v "^/" | grep -v "dylib"
Hello, Reverse Engineering World!
This is a simple program for analysis.
# Look for function names and APIs
$ strings exercises/hello | grep -E "(printf|main|puts)"
printf
πŸ” Analysis Insights:
  • β€’ Two clear text messages (program purpose)
  • β€’ Uses printf function for output
  • β€’ No suspicious URLs or IPs found
  • β€’ Standard system library paths
⚑ Pro Tips:
  • β€’ Use strings -n 8 for longer strings
  • β€’ Try strings -e l for UTF-16
  • β€’ Pipe to sort | uniq to remove duplicates
  • β€’ Look for base64, hex, or encrypted data

Step 3: Disassembly Analysis

Now let's look at the actual assembly code:

$ objdump -d exercises/hello
0000000100000460 <_main>:
100000460: d10083ff sub sp, sp, #0x20
100000464: a9017bfd stp x29, x30, [sp, #0x10]
100000468: 910043fd add x29, sp, #0x10
10000046c: 52800008 mov w8, #0x0
100000470: b9000be8 str w8, [sp, #0x8]
100000478: 90000000 adrp x0, 0x100000000
10000047c: 9112b000 add x0, x0, #0x4ac
100000480: 94000008 bl 0x1000004a0
100000490: b9400be0 ldr w0, [sp, #0x8]
100000498: d65f03c0 ret
πŸ” Analysis Notes:
  • β€’ sub sp, sp, #0x20 - Allocate stack space
  • β€’ stp x29, x30 - Save frame pointer and return address
  • β€’ adrp/add - Load string addresses
  • β€’ bl - Call printf function
  • β€’ ret - Return from function

2Exercise 2: Educational Malware Analysis

⚠️ Important Safety Note

This is a completely safe educational simulation that only prints messages. It demonstrates common malware techniques without performing any harmful actions.

Step 1: Initial Execution

Run the malware simulation to see what it does:

$ ./exercises/malware_sim
=== EDUCATIONAL MALWARE SIMULATION ===
Decrypted message: }`ttsLidvkh`y`zess
Target file: L@ABUDI^E
[INFO] Scanning system...
[SCAN] Found directory: /tmp
[NETWORK] Attempting to connect to C&C server...
[FILE] Simulating malicious file operations:
[PERSISTENCE] Installing persistence mechanisms:

Step 2: String Analysis - Spotting Obfuscation

Look for suspicious strings and patterns:

$ strings exercises/malware_sim | grep -E "(Debugger|C&C|payload|advanced)"
Debugger detected! Exiting...
[NETWORK] Connection to 192.168.1.100:8080 established (FAKE)
[FILE] Would create: /tmp/malware_payload.exe (SIMULATED)
--advanced
[ADVANCED] Hidden functionality activated!

🚨 Red Flags: Anti-debugging, C&C communication, hidden functionality!

Step 3: Discovering Hidden Features

We found "--advanced" in the strings. Let's try it:

$ ./exercises/malware_sim --advanced
[ADVANCED] Hidden functionality activated!
[ADVANCED] Simulating advanced evasion techniques...
[ADVANCED] Process hollowing simulation (FAKE)
[ADVANCED] Registry manipulation simulation (FAKE)
[ADVANCED] Keylogger simulation (FAKE)

πŸ’‘ Discovery: Hidden advanced malware features unlocked by command-line argument!

Step 4: Finding Encrypted Strings

Look for the obfuscated data at the end of strings output:

$ strings exercises/malware_sim | tail -2
ORFFA~0[VDYZR0KRHWAA
~rspgv1{lw

These are XOR-encrypted strings! Real malware often hides important data this way.

🎯 What We Learned:

  • β€’ Anti-Analysis: Debugger detection to avoid reverse engineering
  • β€’ String Obfuscation: XOR encryption to hide malicious intent
  • β€’ Hidden Functionality: Command-line activated advanced features
  • β€’ Persistence: Attempts to maintain presence on system
  • β€’ C&C Communication: Network communication with control server

πŸ†Challenge: Decrypt the Hidden Messages

Using your assembly knowledge, can you figure out how to decrypt those XOR-encrypted strings? Look at the malware_sim.c source code and find the XOR key!

Hints:

  • β€’ Look for the decrypt_string function
  • β€’ Find the XOR key value (it's 0x32)
  • β€’ Try manually XORing the encrypted bytes
  • β€’ The decrypted results demonstrate the XOR process (they may appear garbled - that's normal!)

πŸ”„Use the XOR Playground Tool!

The XOR playground script makes this challenge much easier to understand. Here's how to use it:

Step 1: Run the Script
python3 xor_playground.py
Step 2: Choose Option 4
Choice (1-5): 4
Step 3: See the Magic!

Option 4 shows the exact encrypted data from malware_sim and demonstrates step-by-step XOR decryption!

Step 4: Experiment

Try option 2 with hex bytes 5d 40 74 and key 50

πŸ’‘ Learning Tip:The playground shows data in multiple formats (hex, decimal, ASCII) - this helps you understand how the same bytes look different depending on interpretation!

πŸ“ŽDownload Practice Files

πŸ“ Exercise Source Files

hello.c
Download

Simple Hello World program with detailed comments and analysis tips

Perfect for beginners β€’ ~2KB β€’ Well-commented
malware_sim.c
Download

Educational malware simulation (completely safe!) with encryption, anti-debugging, and hidden features

Advanced exercise β€’ ~5KB β€’ Multiple techniques

πŸ”§ Analysis Tools

analyze.sh
Download

Comprehensive automated binary analysis script with risk assessment

Professional tool β€’ ~10KB β€’ Full analysis suite
README.md
Download

Complete instructions, learning objectives, and troubleshooting guide

Essential guide β€’ ~8KB β€’ Step-by-step instructions
πŸŽ“STUDENT_GUIDE.md
Download

Complete step-by-step walkthrough - Follow this for guaranteed success!

⭐ Recommended for beginners β€’ ~15KB β€’ 6 phases with examples
QUICK_CHECKLIST.md
Download

Quick reference checklist to track your progress through the challenge

Quick reference β€’ ~2KB β€’ Checkboxes and time estimates
πŸ”„xor_playground.py
Download

Interactive XOR Encryption/Decryption Tool - Perfect for understanding the malware_sim XOR challenge!

⭐ Essential for XOR analysis β€’ ~4KB β€’ 5 interactive modes
Features:
  • β€’ Text encryption/decryption
  • β€’ Hex byte analysis
  • β€’ XOR number calculator
  • β€’ Malware challenge simulation
Usage:
python3 xor_playground.py
Perfect for solving the XOR decryption challenge!

πŸš€ Quick Start Commands

# Download all files at once
curl -O http://localhost:3001/exercises/hello.c
curl -O http://localhost:3001/exercises/malware_sim.c
curl -O http://localhost:3001/exercises/analyze.sh
curl -O http://localhost:3001/exercises/xor_playground.py
curl -O http://localhost:3001/exercises/README.md

# Set up and compile
chmod +x analyze.sh
gcc -o hello hello.c
gcc -o malware_sim malware_sim.c

# Start analyzing!
./analyze.sh hello
./malware_sim --advanced

# Use XOR playground to understand encryption
python3 xor_playground.py
# Try option 4 for malware challenge simulation!

πŸ’‘ Pro tip: Create a new folder for these exercises to keep your workspace organized!

🎁Exercise 3: Your Turn - Analyze Any Binary

πŸ’» Try These Common Binaries

/bin/ls

Directory listing command - great for beginners

Try: strings /bin/ls | grep "Usage"
/usr/bin/whoami

Shows current username - simple and clean

Try: objdump -d /usr/bin/whoami | head -50
/bin/cat

File display utility - moderate complexity

Try: strings /bin/cat | grep -E "(error|usage)" -i

🎯 Analysis Checklist

πŸŽ† Challenge Yourself

Pick a binary you use daily (text editor, browser, game) and spend 30 minutes analyzing it. You'll be amazed at what you discover!

πŸ“„ Essential Analysis Commands

# Basic file information
file /path/to/binary
ls -la /path/to/binary

# Extract and filter strings
strings /path/to/binary
strings /path/to/binary | grep -i error
strings /path/to/binary | grep http

# Disassembly
objdump -d /path/to/binary
objdump -t /path/to/binary

πŸ’‘ Pro tip: Create a simple script with these commands, or use them one by one. Replace /path/to/binary with your actual file path.

🧩 Putting It All Together: From Code to Assembly to Exploitation

Let's see how a simple C function becomes assembly code and reveals security vulnerabilities:

πŸ“ Original C Code:

int
check_password
(
char
* input) {
char
buffer[16];
strcpy
(buffer, input);
if
(
strcmp
(buffer, "secret") == 0)
return
1;
return
0;
}

πŸ”§ Assembly Translation:

sub rsp, 32 ; Allocate 32 bytes
mov rdi, rsp ; buffer = stack pointer
mov rsi, [rbp+16] ; input parameter
call strcpy ; Copy input to buffer
mov rdi, rsp ; Load buffer address
mov rsi, secret_str ; Load "secret"
call strcmp ; Compare strings
test rax, rax ; Check result
je return_success ; Jump if equal
mov rax, 0 ; Return 0 (fail)
jmp exit ; Exit function

🚨 What a Reverse Engineer Sees:

  • β€’ Buffer Overflow: Only 32 bytes allocated but no length check on input
  • β€’ Stack Layout: Buffer starts at RSP, return address 32 bytes higher
  • β€’ Control Flow: Success/fail logic in the conditional jump
  • β€’ Secret Location: Password string address loaded into RSI

πŸ”§ Possible Exploits/Bypasses:

  • β€’ Buffer Overflow: Send 40+ characters to overwrite return address
  • β€’ Logic Bypass: Patch the je return_success to jmp return_success
  • β€’ String Discovery: Find the secret string at the address in RSI
  • β€’ Return Value: Always return 1 by patching the return logic

πŸŽ† The Power of Assembly Knowledge:

By understanding assembly, you can see vulnerabilities invisible in source code, find hidden functionality, bypass security checks, and understand exactly how malware operates. Every high-level programming construct has an assembly representation - and that's where the real secrets hide!

πŸ“š Lesson Summary

βœ… What We Covered:

  • β€’ CPU architecture and instruction execution cycle
  • β€’ General purpose and special registers
  • β€’ Basic assembly instructions (MOV, ADD, JMP, etc.)
  • β€’ Memory layout and addressing modes
  • β€’ Practical analysis techniques

🎯 Next Steps:

  • β€’ Complete the hands-on exercise
  • β€’ Practice reading assembly code daily
  • β€’ Experiment with different binaries
  • β€’ Move to Lesson 3: Executable File Formats