You are a junior security engineer at Acme Systems Inc.
The team is reviewing login_server, a legacy C program that handles
user authentication for internal tools. Your task is to walk through the full
Secure SDLC: identify a buffer overflow vulnerability, understand how it works,
file a security ticket, and verify the fix.
📋 System Requirements
• Accept username + password input
• Validate credentials against a user store
• Log all login attempts
• Support up to 64-char usernames
• Written in C, runs on Linux x86-64
⚠️ Threat Model (STRIDE)
Spoofing — fake credentials
Tampering — corrupt session data
Repudiation — forged logs
Info Disclosure — memory leaks
Denial of Service — crash server
Escalation of Privilege — our target today
💡 KEY CONCEPT — What is a Buffer Overflow?
A buffer overflow occurs when a program writes more data to a fixed-size memory buffer than it can hold.
The excess data spills into adjacent memory regions — potentially overwriting critical values like
return addresses that control where execution jumps next. This is one of the oldest and most
dangerous vulnerability classes in software security.
❓ Quick Check — Before We Begin
Which part of a C program's memory layout holds local variables?
PHASE 2
Vulnerable Code Review
Static analysis — reading the source for bugs
🔍 STATIC ANALYSIS
We're reading the source code before running anything. This is called static analysis —
it's the first line of defense in a Secure SDLC. Look carefully at the highlighted lines.
📄 login_server.c — Source Code
1// login_server.c — Acme Systems Internal Auth 2#include<stdio.h> 3#include<string.h> 4#include<stdlib.h> 5 6voidauthenticate(char *input) { 7char username[64]; // Fixed 64-byte buffer on the stack 8int auth_flag = 0; // 0 = not authenticated 9 10// ⚠️ VULNERABILITY: strcpy does NO bounds checking! 11strcpy(username, input); // Copies ALL of input into 64-byte buffer 12 13if (auth_flag != 0) { 14printf("[AUTH] Access GRANTED for: %s\n", username); 15grant_access(); 16 } else { 17printf("[AUTH] Access DENIED for: %s\n", username); 18 } 19} 20 21intmain() { 22char input[512]; 23printf("Username: "); 24fgets(input, sizeof(input), stdin); 25authenticate(input); 26return0; 27}
🔬 Analysis — What Makes This Dangerous?
The vulnerability is on line 11. Let's break it down:
strcpy(username, input) strcpy copies bytes from input into username until it hits a null byte \0.
It has no idea how large the destination buffer is. If input is longer than 64 bytes,
it will keep writing past the end of username.
auth_flag lives right after username on the stack
The C compiler lays out local variables sequentially on the stack.
auth_flag sits right after username[64]. An input longer than 64 bytes will overwrite it!
The exploit path:
Send 65+ bytes → overflow username → write non-zero value into auth_flag →
the if (auth_flag != 0) check passes → access granted without a valid password!
❓ Code Review Quiz
Why is strcpy() considered an unsafe function in C?
PHASE 3
Exploit the Vulnerability
Dynamic analysis — triggering the bug in a controlled environment
⚠️ CONTROLLED ENVIRONMENT
This is a simulation. In real security work, exploits are only run against systems you own
or have written permission to test. Unauthorized exploitation is illegal.
💻 Simulated Terminal — Try the Exploit
Enter a username and press Run to simulate program execution.
Try different lengths to see what happens.
bash — login_server simulation
$./login_server
Program compiled. Ready for input. Try entering a username...
Username:
💡 Hints: Try admin (normal), then AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA (65 A's)
🚨 VULNERABILITY CONFIRMED
You've demonstrated the buffer overflow! An input of 65+ characters overwrote auth_flag,
bypassing authentication entirely. An attacker doesn't need the real password — just a long string.
📊 What Happened? — Step by Step
Step 1Program calls authenticate(input)Step 2Stack frame created: username[64] then auth_flag=0Step 3strcpy copies your 65-byte input into the 64-byte bufferStep 4Byte 65 overflows into auth_flag, setting it to 0x41 (ASCII 'A')Step 5if (auth_flag != 0) → true! Access granted.
PHASE 4
Root Cause & Memory Analysis
Understanding the stack layout during exploitation
The letter 'A' has ASCII value 65, which in hexadecimal is 0x41. When we overflow
the buffer with 65 'A' characters, the 65th byte writes 0x41 into auth_flag.
Since 0x41 ≠ 0, the if (auth_flag != 0) condition evaluates to true.
'A' → decimal 65 → hex 0x41 → not zero → authenticated!
📚 REAL-WORLD IMPACT — Beyond auth_flag
In more serious exploits, attackers aim further: overwriting the saved return address allows them
to redirect program execution to attacker-controlled code (shellcode). This is the foundation of
classic stack smashing attacks. Modern systems use mitigations like ASLR, stack canaries, and NX bits —
but these are defeated if software is built without them.
❓ Memory Quiz
In a classic stack buffer overflow, what critical value does an attacker try to overwrite to gain arbitrary code execution?
PHASE 5
File a Security Ticket
Documenting the vulnerability in the SDLC issue tracker
🎫 WHY TICKETS MATTER
Every discovered vulnerability must be formally documented so it can be tracked, prioritized,
assigned, and verified after patching. This is a critical step in the Secure SDLC — without it,
bugs get forgotten and ships stay vulnerable.
📝 New Security Vulnerability Report
SEC-0000CRITICAL
Title
Reported by
Component
CVSS Score
CWE Reference
Priority
Impact
Recommended Fix
Filed by: security-lab@acme.com · · Status: OPEN
✅ TICKET SUBMITTED
Your security ticket has been filed. The development team has been notified and must address
this before the next release. Now let's see the fix!