Database
Table of Contents
An organised collection of structured data, managed by a Database Management System (DBMS). Databases underpin virtually every application — from web backends to security tooling. The two dominant paradigms are relational (SQL) and non-relational (NoSQL), each suited to different data models and access patterns.
Related: NoSQL Databases SQL Databases Structured Query Language SQL Injection NoSQL Injection
Relational (SQL)
Data is stored in tables with rows and columns. Relationships between tables are defined by foreign keys. The schema is fixed at design time. Query language is SQL.
-- Core operations SELECT name, email FROM users WHERE role = 'admin'; INSERT INTO users (name, email) VALUES ('Alice', 'a@a.com'); UPDATE users SET role = 'admin' WHERE id = 5; DELETE FROM users WHERE id = 5;
| Property | Description |
|---|---|
| ACID compliance | Atomicity, Consistency, Isolation, Durability — guarantees transaction integrity |
| Schema | Fixed, enforced at write time |
| Joins | Native — relationships between tables are a first-class feature |
| Scaling | Vertical (bigger server) by default; horizontal sharding is complex |
Common engines: PostgreSQL, MySQL, MariaDB, SQLite, MSSQL
See SQL for query syntax reference.
Non-Relational (NoSQL)
Schema-flexible storage — data models include documents, key-value pairs, wide-column, and graph. Optimised for horizontal scaling, high write throughput, and flexible or evolving data structures.
| Type | Data model | Example engines |
|---|---|---|
| Document | JSON/BSON documents | MongoDB, CouchDB |
| Key-value | Simple key → value pairs | Redis, DynamoDB |
| Wide-column | Column families | Cassandra, HBase |
| Graph | Nodes and edges | Neo4j, Amazon Neptune |
See NoSQL Databases for detail.
When to Use Which
| Factor | Prefer SQL | Prefer NoSQL |
|---|---|---|
| Data structure | Well-defined, relational | Flexible, variable, nested |
| Query complexity | Complex joins, aggregations | Simple lookups, high volume |
| Consistency | Strong ACID guarantees needed | Eventual consistency acceptable |
| Scaling | Moderate, vertical | Massive horizontal scale |
| Transactions | Multi-table transactions | Single-document operations |
In practice many applications use both — a relational DB for core business data and a NoSQL store for sessions, caching, or high-volume event data.
Security Relevance
Both database types are common attack surfaces:
- SQL Injection — user input interpolated into SQL queries; see SQL Injection
- NoSQL Injection — operator injection in MongoDB-style queries; see NoSQL Injection
- Credentials in config files — connection strings frequently contain plaintext passwords and are a high-value target during post-exploitation
- Exposed ports — MySQL (3306), PostgreSQL (5432), MongoDB (27017), Redis (6379) exposed externally without authentication are common critical findings
Tips
- SQLite is a file-based relational database — common in mobile apps, Electron apps, and local tool storage; worth checking for during post-exploitation
- Redis with no authentication is a frequent high-severity finding on misconfigured cloud infrastructure — it supports writing arbitrary files including SSH authorisedkeys
- Neo4j is what BloodHound uses for its AD graph data