📚 Table of Contents
- 1. Introduction - What You'll Learn
- 2. Setup - Getting Started with IDA
- 3. Static Analysis Basics
- 4. IDA Pro Basics for Beginners
- 5. Question 1a: How Key Files Are Used
- 6. Question 1b: Key Selection Criterion
- 7. Question 2a: Encryption Method
- 8. Question 2b: Decryption Process
- 9. Question 3: Decrypt the Message
- 10. Question 4: Memory Forensics
- 11. Quick Reference Cheat Sheet
1. Introduction - What You'll Learn 🎯
Welcome! This tutorial teaches you how to analyze malware like a professional. You'll learn:
- ✅ How to use IDA Pro (the industry-standard tool)
- ✅ How to read assembly code and opcodes
- ✅ How to identify encryption algorithms
- ✅ How to decrypt encrypted files
- ✅ How to answer exam questions with proper citations
📁 Binary: mock_1.exe
🎯 Goal: Understand encryption and decrypt Settings.ini
What is mock_1.exe?
It's a Windows program that:
- Reads a file called
input.txt - Picks one of 7 key files (key0 to key6) based on the day of the week
- Encrypts the input using a simple cipher
- Writes the result to
output.txt
2. Setup - Getting Started with IDA 🛠️
Files You Need:
| File | Description | Size |
|---|---|---|
| mock_1.exe | The malware binary we're analyzing | 9.5 KB |
| Settings.ini | Encrypted message (our target!) | 20 bytes |
| key0 - key7 | Key files (8 files total) | Various |
| mock_1.c | Source code (for reference) | 2.4 KB |
Step 1: Verify the Binary
Step 2: Open in IDA Free
mock_1.exe
3. Static Analysis Basics 🔍
Before opening IDA, let's gather basic information:
File Type Analysis
What this means: It's a 32-bit Windows executable
String Analysis
Encrypted File Analysis
This is our encrypted message - 20 bytes of gibberish!
Which Key Was Used?
February 5, 2016 was a Friday
Friday = Day 5 = key5 was used!
4. IDA Pro Basics for Beginners 🎓
Essential IDA Hotkeys
| Key | Function | What It Shows |
|---|---|---|
| Shift+F12 | Strings Window | All text strings in the program |
| Shift+F3 | Functions Window | List of all functions |
| X | Cross-References | Where is this item used? |
| Space | Graph/Text View | Toggle between views |
| F5 | Decompile | Convert to C-like code |
| G | Jump to Address | Go to specific location |
Understanding Assembly Code
- Address: Where the instruction is located in memory
- Opcode: The actual machine code (in hex)
- Instruction: Human-readable assembly command
- Comment: IDA's notes (or your own)
Common Instructions You'll See
| Instruction | Meaning | Example |
|---|---|---|
mov |
Move/Copy data | mov eax, 5 → EAX = 5 |
add |
Addition | add eax, ebx → EAX = EAX + EBX |
sub |
Subtraction | sub eax, 10 → EAX = EAX - 10 |
cmp |
Compare | cmp eax, 6 → Compare EAX with 6 |
call |
Call function | call _time → Call time() |
jmp |
Jump | jmp loc_401234 → Go to address |
5. Question 1a: How Key Files Are Used 📂
State how mock_1.exe uses the key files (key0 … key7). Cite relevant opcodes to support your claims.
Finding the Answer in IDA - Step by Step
Press Shift+F12 to see all strings
Look for "key0", "key1", etc. in the list
Double-click on "key0" → Press X for cross-references
You'll find code that calls
_stat to get file size
call _stat at address 0x004014CB
Keep scrolling to find time-related functions
Understanding the SWITCH Statement
✅ ANSWER TO QUESTION 1a:
mock_1.exe uses key files as follows:
- File Size Checking:
- All key files (key0-key6) are accessed via
stat() - Opcode:
call _statat0x004014CB - Purpose: Get file size for each key file
- All key files (key0-key6) are accessed via
- Key Selection:
- Only key0-key6 are referenced (7 files)
- key7 is never used (no string reference)
- String addresses: 0x004040D0 through 0x004040EE
- SWITCH-CASE Structure:
- Uses jump table for efficient selection
- Opcode:
cmp eax, 6at0x0040160B - Handles cases 0-6 only
6. Question 1b: Key Selection Criterion ⏰
What is the key selection criterion of mock_1.exe? Cite relevant opcodes to support your claim.
Analyzing the Time Functions
Understanding struct tm
The localtime() function returns a pointer to a struct tm:
| Field | Offset | Description |
|---|---|---|
| tm_sec | +0x00 | Seconds (0-59) |
| tm_min | +0x04 | Minutes (0-59) |
| tm_hour | +0x08 | Hours (0-23) |
| tm_mday | +0x0C | Day of month (1-31) |
| tm_mon | +0x10 | Month (0-11) |
| tm_year | +0x14 | Years since 1900 |
| tm_wday | +0x18 | Day of week (0-6) |
mov eax, [eax+18h]Offset 0x18 (24 in decimal) = tm_wday field!
This is the DAY OF THE WEEK!
Day of Week Values
| tm_wday Value | Day Name | Key Used |
|---|---|---|
| 0 | Sunday | key0 |
| 1 | Monday | key1 |
| 2 | Tuesday | key2 |
| 3 | Wednesday | key3 |
| 4 | Thursday | key4 |
| 5 | Friday | key5 ← Settings.ini! |
| 6 | Saturday | key6 |
✅ ANSWER TO QUESTION 1b:
The key selection criterion is day of the week (tm_wday).
Mechanism:
- Get System Time:
- Opcode:
call _timeat0x004015F1
- Opcode:
- Convert to Local Time:
- Opcode:
call _localtimeat0x004015FD - Returns pointer to struct tm
- Opcode:
- Extract Day of Week:
- Opcode:
mov eax, [eax+18h]at0x00401602 - Accesses tm_wday field at offset 0x18
- Value range: 0-6 (0=Sunday, 6=Saturday)
- Opcode:
- Validate Range:
- Opcode:
cmp eax, 6at0x0040160B
- Opcode:
7. Question 2a: Encryption Method 🔐
Explain how the file input.txt is encrypted. Cite relevant opcodes to support your claims.
Finding the Encrypt Function
Press Shift+F12 and search for "Encrypting"
Double-click → Press X → Jump to the function
The Encryption Loop
add edx, eax at 0x0040145FThis is an ADD cipher, NOT XOR!
Formula:
encrypted = (input + key) mod 256
Circular Key Mechanism
If the input file is longer than the key file, the key repeats from the beginning. This is called a "circular" or "repeating" key.
✅ ANSWER TO QUESTION 2a:
The file input.txt is encrypted using a simple ADD cipher with a circular key.
Process:
- Byte-by-Byte Reading:
- Read input byte:
call ds:fgetcat0x00401476 - Read key byte:
call ds:fgetcat0x00401430
- Read input byte:
- Circular Key:
- If key reaches EOF:
call ds:rewindat0x00401444 - Key repeats from beginning
- If key reaches EOF:
- ADD Encryption:
- Opcode:
add edx, eaxat0x0040145F - Formula: encrypted = (input + key) mod 256
- Byte arithmetic wraps at 256
- Opcode:
- Write Output:
call fputcat0x0040146B
8. Question 2b: Decryption Process 🔓
Given that settings.ini is in ASCII text and encoded by mock_1.exe, explain how you could decrypt the settings.ini. Describe the decryption process using the first byte.
Understanding the Inverse Operation
If encryption is ADDITION, then decryption is SUBTRACTION:
Step 1: Identify the Correct Key
Step 2: Get First Byte Values
Step 3: Perform Decryption
Why Modulo 256?
During encryption, the ADD operation "wraps around" at 256:
✅ ANSWER TO QUESTION 2b:
Decryption Formula: plaintext = (encrypted - key) mod 256
First Byte Decryption:
- Identify Key File:
- Settings.ini date: Feb 5, 2016 (Friday)
- Use key5
- Get Values:
- Encrypted[0] = 0x19 (25)
- Key5[0] = 0xC5 (197)
- Calculate:
- 25 - 197 = -172
- -172 mod 256 = -172 + 256 = 84
- 84 = 'T' in ASCII
- Verification:
- Encrypt: 84 + 197 = 281
- 281 mod 256 = 25 ✓
9. Question 3: Decrypt the Message 💬
Given that settings.ini is in ASCII text and encoded by mock_1.exe, write down the decrypted message from settings.ini.
Python Decryption Script
Byte-by-Byte Decryption Table
| Byte # | Encrypted | Key5 | Decrypted | ASCII |
|---|---|---|---|---|
| 1 | 0x19 (25) | 0xC5 (197) | 84 | T |
| 2 | 0x6A (106) | 0x22 (34) | 72 | H |
| 3 | 0x38 (56) | 0xCF (207) | 105 | i |
| 4 | 0xFD (253) | 0x8A (138) | 115 | s |
| ... | ... | ... | ... | ... |
✅ ANSWER TO QUESTION 3:
(Note: Message includes a newline character at the end)
10. Question 4: Memory Forensics 🧠
Describe 3 artifacts that can be found using Memory Forensics.
✅ ANSWER TO QUESTION 4:
1. Process and Network Data Structures
Data structures that track running processes, network connections, and resources:
- Process list (PID, parent PID, command line)
- Active network connections (IP, ports)
- Open file handles
- Loaded DLL modules
Forensic Value: Identify malicious processes, hidden processes, and network activity
2. Passwords and Encryption Keys
Credentials and cryptographic keys in clear text:
- User passwords (encrypted on disk, plain in RAM)
- Encryption keys for real-time operations
- Session tokens and authentication data
- NTLM hashes, Kerberos tickets
Why in Memory: Software needs plaintext credentials for authentication and real-time encryption
3. Unpacked/Decrypted Executables
Malware that's packed or encrypted on disk must be decrypted in memory:
- Packed malware (UPX, Themida, custom packers)
- Encrypted code sections
- Injected code in other processes
- Shellcode and position-independent code
Why in Memory: CPU can only execute decoded instructions; packers are anti-analysis, not operational
11. Quick Reference Cheat Sheet 📋
IDA Hotkeys
| Key | Function |
|---|---|
| Shift+F12 | Strings window |
| Shift+F3 | Functions window |
| X | Cross-references |
| Space | Toggle graph/text view |
| F5 | Decompile to C |
| G | Jump to address |
| N | Rename variable |
| ; | Add comment |
Key Findings Summary
| Item | Value |
|---|---|
| Binary | mock_1.exe |
| MD5 | b184c31f067377516da9f4d2228ee8c9 |
| Keys Used | key0-key6 only (key7 NOT used) |
| Selection Method | Day of week (tm_wday) |
| Settings.ini Key | key5 (Friday, Feb 5, 2016) |
| Encryption | ADD cipher: (input + key) mod 256 |
| Decryption | SUB cipher: (encrypted - key) mod 256 |
| Decrypted Message | THis is a mock test |
Critical Opcodes to Remember
| Address | Opcode | Purpose |
|---|---|---|
| 0x004014CB | call _stat | Get file size |
| 0x004015F1 | call _time | Get system time |
| 0x004015FD | call _localtime | Convert time |
| 0x00401602 | mov eax, [eax+18h] | Get tm_wday |
| 0x0040160B | cmp eax, 6 | Validate day 0-6 |
| 0x00401476 | call ds:fgetc | Read input byte |
| 0x00401430 | call ds:fgetc | Read key byte |
| 0x00401444 | call ds:rewind | Circular key |
| 0x0040145F | add edx, eax | ADD encryption |
| 0x0040146B | call fputc | Write output |
struct tm Offsets
Exam Tips
- ✅ Always cite opcodes with addresses
- ✅ Show your calculations step-by-step
- ✅ Verify answers make sense (printable ASCII)
- ✅ Check file dates to identify key
- ✅ Remember: ADD cipher, NOT XOR
- ✅ Handle negative numbers with modulo 256