Hardcoded & Default Credentials

CWE-258, CWE-259, CWE-259, CWE-798, CWE-1392, CWE-1393

Why They're Critical

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.py
DB_HOST = 'prod-db.internal.company.com'
DB_USER = 'app_user'
DB_PASSWORD = 'SuperSecret123!@#'  # HARDCODED!
DB_DATABASE = 'production'

# Used everywhere in application
def get_db_connection():
    return psycopg2.connect(
        host=DB_HOST,
        user=DB_USER,
        password=DB_PASSWORD,
        database=DB_DATABASE
    )

The vulnerability:

Password visible in:

  • Source code

  • Compiled binaries

  • Git history

  • Backup files

  • Version control systems

  • CI/CD logs

The attack:

  1. Attacker clones repository: git clone https://repo.git

  2. Finds hardcoded credentials: grep -r "DB_PASSWORD" .

  3. Uses credentials to connect: psql -h prod-db.internal... -U app_user

  4. Complete database access achieved

  5. Can read/modify all data

Or:

Result:

  • Complete database compromise

  • All user data exposed

  • Ability to modify data

  • No audit trail (legitimate credentials used)

Finding it: Search source code for hardcoded passwords. Check git history. Decompile binaries. Review configuration files.

Exploit:


Scenario 2: Default Admin Credentials Never Changed

Router/appliance installed with default credentials:

The vulnerability:

Credentials are:

  • Well-known (publicly documented)

  • Never changed after installation

  • Same across all deployments

  • Impossible to distinguish from legitimate access

The attack:

Attacker finds device on network:

Attacker now has:

  • Complete device control

  • Can modify configuration

  • Can access all data

  • Can create backdoors

Result:

  • Device compromise

  • Network access

  • Potential lateral movement

  • Data theft

Finding it: Research default credentials for found devices/software. Try common default passwords (admin/admin, admin/12345, etc.).


Scenario 3: Empty Password in Configuration File

Configuration file with blank password:

The vulnerability:

Empty passwords mean:

  • No authentication

  • Any user can connect

  • Configuration stored but never validated

  • Applications crash when password required

  • Developers might add placeholder and forget to fill it

The attack:

Attacker:

  1. Finds config file (repository, backup, exposed server)

  2. Sees empty password

  3. Connects without authentication: psql -h db.internal -U app_user

  4. No password prompted

  5. Full database access

Result:

  • Unauthenticated database access

  • Complete data compromise

  • No audit trail

Finding it: Examine configuration files. Look for empty values. Try connecting without credentials.


Scenario 4: API Key Hardcoded in Frontend

API key embedded in JavaScript:

The vulnerability:

API keys in frontend:

  • Visible in source code: View Source in browser

  • Visible in network traffic (unless HTTPS)

  • Visible in compiled bundles

  • Visible in git history

  • Visible in browser cache

The attack:

Attacker views page source:

Result:

  • API key compromise

  • Fraudulent charges

  • Customer data theft

  • Complete payment system access

Finding it: View page source. Check network tab. Search for API keys. Decompile bundles.


Scenario 5: SSH Private Key in Repository

Private SSH key committed to git:

The vulnerability:

SSH key in repository:

  • Cloneable by anyone with repo access

  • In git history forever

  • Allows impersonation of users/services

  • Can be used even after removal (still in history)

The attack:

Or:

Result:

  • Server compromise

  • Code modification

  • Data theft

  • Complete infrastructure access

Finding it: Search repository for private keys. Check git history for deleted files. Look for SSH keys in configs.


Scenario 6: Default Credentials in Backup Account

Test/backup account with default credentials never removed:

The vulnerability:

Test/backup accounts:

  • Created during development

  • Never removed from production

  • Have same permissions as main account

  • Use default/weak passwords

  • Easy to guess and compromise

The attack:

Attacker:

  1. Discovers database server

  2. Tries common test account names: test, backup, admin, demo

  3. Tries default passwords: test, 123456, password, admin

  4. One of them works: mysql -u backup -p123456

  5. Full database access

Result:

  • Database compromise

  • Privilege escalation

  • All data exposed

Finding it: List database users. Try default credentials. Look for test/backup accounts.


How to Identify Hardcoded Credentials During Testing

1. Search source code

2. Check git history

3. Examine configuration files

4. Decompile binaries

5. Try default credentials

Research default credentials for:

  • Operating system

  • Database

  • Web server

  • Application

  • Hardware

6. Check environment variables


Mitigation Strategies

Never hardcode credentials

Use external configuration:

Always change default credentials

On first deployment:

Use environment variables

Use secrets management systems

  • AWS Secrets Manager

  • Azure Key Vault

  • HashiCorp Vault

  • Kubernetes Secrets

Prevent credentials in source control

Use .gitignore strictly

Rotate credentials regularly

Even if hardcoded (legacy), rotate every 30-90 days:

Scan for credentials in CI/CD

Audit and review

  • Regular code reviews

  • Scanning tools

  • Security audits

  • Penetration testing


Last updated