Introduction
Government ministries, banks, telecom operators, and utility companies across Pakistan rely on large-scale relational databases to store everything from citizen identity records to financial transaction histories. These data stores β housed in systems like Oracle, PostgreSQL, MySQL, and Microsoft SQL Server β are high-value targets for both external attackers and malicious insiders. A SOC analyst who can detect database compromise early, before data is exfiltrated or manipulated, adds enormous defensive value.
This lesson walks through database attack taxonomies mapped to MITRE ATT&CK, practical monitoring techniques using native database logging and SIEM integrations, and scenario-based detection workflows applicable to Pakistani organizations.
Common Database Attack Vectors in the Pakistani Context
Pakistan's regulatory environment β governed by the Prevention of Electronic Crimes Act (PECA) 2016 and SBP banking guidelines β places strict obligations on data custodians. Attackers targeting Pakistani entities frequently pursue:
- SQL Injection (T1055): Web-facing applications connected to backend databases remain a primary vector. Pakistani government portals and e-government services have historically been scanned and exploited.
- Privilege Escalation (T1068): Weak database role configurations allow low-privilege users to gain DBA-level access.
- Credential Dumping (T1003): In-memory credential harvesting from database processes.
- Data Exfiltration (T1041): Bulk SELECT queries or database dumps transferred to attacker-controlled endpoints.
- Tampering (T1525): Direct UPDATE/DELETE operations to alter transaction records, especially relevant in financial databases.
The NCCIA cybercrime helpline 1799 has reported increasing cases of compromised database credentials being traded on underground forums, often tied to phishing campaigns impersonating NADRA or FBR.
Setting Up Database Audit Logging
Every SOC analyst should ensure the following logging is enabled on monitored database instances:
- Statement logs: All SQL queries executed, including the user, timestamp, source IP, and affected rows.
- Connection logs: Failed and successful authentication attempts, session duration, and source client details.
- DDL event logs: CREATE, ALTER, DROP operations on schemas and tables.
- Error logs: Database-level errors, deadlocks, and timeout conditions.
For MySQL, enable the general query log and slow query log in my.cnf:
[mysqld]
general_log = 1
general_log_file = /var/log/mysql/general.log
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
For PostgreSQL, modify postgresql.conf to enable logging:
log_statement = 'all'
log_duration = on
log_line_prefix = '%t %p %u@%d '
logging_collector = on
For Microsoft SQL Server, enable via SQL Server Management Studio (SSMS) β Server Properties β Security, and configure trace flags 7806 for centralized table capture.
Detecting SQL Injection and Suspicious Queries
Forward database logs to your SIEM (e.g., Wazuh, ELK, or Splunk) using Filebeat or a database-specific connector. Build detection logic using Sigma rules. Example:
title: Suspicious SQL Injection Attempt via UNION SELECT
id: 3001
status: experimental
description: Detects UNION-based SQL injection patterns in database logs
logsource:
product: mysql
service: general
detection:
keywords:
- 'UNION SELECT'
- 'UNION ALL SELECT'
- '0x7e'
- 'concat('
condition: keywords
level: high
Additional Sigma rules should flag:
- Queries containing multiple semicolons attempting stacked queries.
- Hex-encoded strings in WHERE clauses.
- Unusually high row counts returned to a single query from an application account.
- SELECT * FROM multiple system tables (information_schema, mysql.user) by non-admin users.
Insider Threat Detection: Monitoring Privileged Access
In Pakistani organizations, insider threats are a significant concern β particularly for databases holding NADRA records, tax identification data, and banking records. Monitor for:
- Off-hours access: Database connections from IPs outside normal business hours.
- Bulk exports: Large result sets being selected and transferred β particularly from HR or citizen records tables.
- Privilege changes: ALTER USER or GRANT statements modifying role permissions.
- Direct admin connections: DBA accounts logging in from non-standard workstations.
Correlate database logs with Active Directory authentication events to detect "impossible logins" β a user authenticating to the database from two geographically distant IPs within minutes.
Responding to a Database Breach
If a database compromise is confirmed:
- Isolate the database server from the network β prevent further data egress.
- Preserve evidence: Take a forensic snapshot of transaction logs before any rollback.
- Identify scope: Determine which schemas and record counts were accessed or modified.
- Notify stakeholders: Under PECA 2016, data breaches affecting personal information must be reported to NCCIA 1799 and potentially the PTA.
- Reset credentials: Force-password all database accounts, especially service accounts embedded in application configs.
- Review application logs: Identify the attacker's initial entry point β likely a vulnerable web application.
Takeaway
This week, identify the top three database servers in your organization's environment and confirm that audit logging is enabled and forwarding to your SIEM. Write at least two Sigma rules covering SQL injection patterns and bulk export anomalies. In a real incident, the minutes saved by having these logs already configured can mean the difference between containing a breach and losing citizen data.
For free cybersecurity support or to report a data breach, contact NCCIA at 1799 or visit pisa.maahir.io.
