Databases: The Crown Jewels Under Siege
Every Pakistani organization—from telecom operators managing NADRA verification data to e-commerce platforms processing JazzCash transactions—stores critical data in databases that attackers actively target. SQL injection remains the most prevalent web attack vector, and database misconfigurations routinely expose sensitive information. This lesson equips you to monitor database security and detect attacks targeting your most valuable data assets.
Common Database Security Threats in Pakistani Context
Pakistani organizations face elevated risk from:
- Web application SQL injection: Legacy portals for government services, banking, and e-commerce frequently contain unpatched injection vulnerabilities
- Privilege escalation: Overprivileged database accounts exploited via application vulnerabilities
- Data exfiltration: Large SELECT queries indicating bulk data extraction
- Compliance violations: Storing CNIC numbers, financial records, or healthcare data without proper encryption or access controls
MITRE ATT&CK techniques relevant to database attacks include T1190 (Exploit Public-Facing Application), T1005 (Data from Local System), and T1078.003 (Local Accounts).
Implementing Database Activity Monitoring (DAM)
Deploy database activity monitoring solutions (MySQL Enterprise Audit, pgAudit for PostgreSQL, or commercial tools like Imperva DAM) to capture all SQL operations. For resource-constrained Pakistani organizations, native database logging provides adequate coverage:
PostgreSQL audit configuration:
ALTER SYSTEM SET shared_preload_libraries = 'pgaudit';
ALTER SYSTEM SET pgaudit.log = 'READ, WRITE, FUNCTION';
SELECT pg_reload_conf();
MySQL general log enablement (temporary for investigation):
SET GLOBAL general_log = 'ON';
SET GLOBAL log_output = 'FILE';
SET GLOBAL general_log_file = '/var/log/mysql/audit.log';
Forward these logs to your SIEM using Filebeat or direct syslog integration for centralized analysis.
Detecting SQL Injection with Wireshark and Sigma Rules
Capture SQL injection attempts using Wireshark during incident investigation:
tcpdump -i eth0 -w sqli_capture.pcap port 3306 or port 5432
Filter for SQL injection signatures in packet captures:
tcp contains "UNION SELECT"
tcp contains "' OR '1'='1"
tcp contains "waitfor delay"
tcp contains "information_schema"
Create SIEM detection rules using Sigma for SQL injection:
title: SQL Injection Attempt - UNION SELECT
logsource: product: webserver
detection:
selection:
query|contains: 'UNION SELECT'
query|contains: '--'
condition: selection
level: high
mitre_technique: T1190
Sensitive Data Classification and Protection
Pakistan's data protection requirements (evolving under NCCIA implementation) require organizations to identify and protect personal data. Conduct data classification:
Classification tiers for Pakistani organizations:
- Critical: CNIC numbers, biometric data, financial credentials—require encryption at rest, MFA access, and audit logging
- Sensitive: Health records, legal documents, internal communications—encrypted storage, role-based access
- Internal: HR records, operational data—standard access controls
- Public: Marketing materials, public filings—no restrictions
Scan databases for unencrypted sensitive fields using tools like sqlmap (for testing only, with authorization) or OpenDLP for data discovery. Flag columns containing 'cnic', 'password', 'account_number', or 'biometric' for immediate security review.
Database Hardening for Production Deployments
Essential hardening steps:
- Disable or restrict REMOTE_ROOT_LOGIN in MySQL/MariaDB configurations
- Enforce complex passwords for database service accounts using PAM policies
- Implement network segmentation—database servers should not be directly internet-accessible
- Enable SSL/TLS for all database connections, especially for applications connecting from DMZ
- Configure connection pooling with limited application database accounts—avoid shared admin credentials
Do / Don't
Do: Implement query whitelisting for critical applications—allow only approved SQL patterns, block everything else. This prevents both injection exploitation and insider SQL abuse.
Don't: Store plaintext CNIC numbers or financial credentials—use field-level encryption with application-level key management. If breached, encrypted fields significantly reduce compliance impact.
Takeaway: This week, run this query against your MySQL or PostgreSQL databases to identify potential SQL injection points: SELECT table_name, column_name FROM information_schema.columns WHERE column_name LIKE '%pass%' OR column_name LIKE '%token%'; Review who has SELECT access to these columns and implement least-privilege access controls immediately.
