Charge thousands to each card
Sell card data on dark web
Customer accounts compromised
<!-- Page returned with Cache-Control header -->
<html>
<body>
<h1>API Configuration</h1>
<p>Your API Key: sk_live_4eC39HqLyjWDarht8Zlt5Kda</p>
</body>
</html>
<!-- Server sends with default caching headers -->
HTTP/1.1 200 OK
Content-Type: text/html
(No Cache-Control header - page cached by default!)
# Check browser history and cache
cat ~/.mozilla/firefox/*/cache2/entries/*
# Or use tools to extract
python browser_cache_extractor.py
# Finds cached pages with secrets
// Set cookie that persists for 1 year
document.cookie = "sessionToken=" + token + "; max-age=31536000; path=/";
# Extract cookies from browser
sqlite3 ~/.mozilla/firefox/*/cookies.sqlite "SELECT * FROM moz_cookies;"
# Found:
# sessionToken=abc123def456...
# Use in Burp Suite
# Set Cookie header to stolen token
# Hijack victim's session
GET /search?q=ssn:123-45-6789&credit_card=4111111111111111
GET /checkout?total=99.99&discount_code=SENSITIVE123
GET /profile?user_id=42&email=user@example.com&phone=555-0123
// Load password into memory
char[] password = userInput.ToCharArray();
// Use password for authentication
if (VerifyPassword(password, storedHash)) {
AuthenticateUser();
}
// VULNERABLE - Password still in memory!
// Garbage collector hasn't run yet
// Memory dump reveals password
import bcrypt
# Hash at storage time
salt = bcrypt.gensalt(rounds=12)
hashed = bcrypt.hashpw(password.encode(), salt)
# Verify at authentication
if bcrypt.checkpw(password.encode(), hashed):
authenticate()
from cryptography.fernet import Fernet
cipher = Fernet(key)
encrypted_card = cipher.encrypt(card_number.encode())
# Store encrypted_card
# Decrypt only when needed
# Django
from django.views.decorators.cache import never_cache
@never_cache
def sensitive_page(request):
return render(request, 'sensitive.html')
# Or set headers
response['Cache-Control'] = 'no-cache, no-store, must-revalidate'
response['Pragma'] = 'no-cache'
response['Expires'] = '0'
# Set security flags
response.set_cookie(
'sessionid',
value=token,
secure=True, # HTTPS only
httponly=True, # No JavaScript access
samesite='Strict', # CSRF protection
max_age=3600 # 1 hour expiration
)
# Bad
GET /search?ssn=123-45-6789
# Good
POST /search
data={'ssn': '123-45-6789'}
// After using password
Array.Clear(password, 0, password.Length);
// Or use SecureString
SecureString pwd = new SecureString();
pwd.AppendChar('p');
// ... etc
// SecureString automatically clears when disposed
# Use .gitignore
echo ".env" >> .gitignore
echo "config.ini" >> .gitignore
echo "secrets.*" >> .gitignore
# Or use environment variables
export DB_PASSWORD=secret
# Access in code: os.getenv('DB_PASSWORD')