用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tools-only/X-Skills --skill security-scan命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | security-scan |
| description | Comprehensive database security scanner with OWASP compliance checks,... |
| shortcut | secu |
Implement production-grade database security scanning for PostgreSQL and MySQL that detects 50+ security vulnerabilities including weak passwords, excessive permissions, SQL injection vectors, missing encryption, exposed ports, and insecure configurations. Provides OWASP Database Security compliance reports, automated remediation scripts, and continuous security monitoring with SOC2/HIPAA/PCI DSS audit trails.
Use /security-scan when you need to:
DON'T use this when:
This command implements comprehensive multi-layer security scanning because:
Alternative considered: Manual security checklist
Alternative considered: Commercial security tools (Tenable, Qualys)
Before running this command:
Ensure connection has permissions to query user roles, grants, and configurations.
Check authentication, authorization, encryption, auditing, and network security.
Categorize vulnerabilities by severity (critical, high, medium, low).
Create SQL scripts to fix identified issues with rollback procedures.
Apply fixes in staging, validate, then re-scan to confirm remediation.
The command generates:
security_report.md - Human-readable security audit report with severity ratingsvulnerabilities.json - Machine-readable findings for CI/CD integrationremediation.sql - SQL script to fix identified vulnerabilitiescompliance_matrix.xlsx - Mapping to SOC2/HIPAA/PCI DSS controlssecurity_baseline.yml - Configuration baseline for future scans#!/usr/bin/env python3
"""
Production-ready PostgreSQL security scanner implementing OWASP
Database Security Project checks with automated remediation.
"""
import psycopg2
from psycopg2.extras import RealDictCursor
from typing import List, Dict, Optional
from dataclasses import dataclass
from enum import Enum
import json
import logging
from datetime import datetime
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class Severity(Enum):
"""Vulnerability severity levels."""
CRITICAL = "critical"
HIGH = "high"
MEDIUM = "medium"
LOW = "low"
INFO = "info"
@dataclass
class SecurityFinding:
"""Represents a security vulnerability finding."""
check_id: str
title: str
severity: Severity
description: str
affected_objects: List[str]
remediation: str
owasp_category: str
compliance_mappings: Dict[str, str]
class PostgreSQLSecurityScanner:
"""
Comprehensive PostgreSQL security scanner with OWASP compliance.
"""
def ():
.conn_string = conn_string
.findings: [SecurityFinding] = []
() -> [SecurityFinding]:
logger.info()
psycopg2.connect(.conn_string) conn:
._check_weak_passwords(conn)
._check_excessive_permissions(conn)
._check_superuser_roles(conn)
._check_public_schema_permissions(conn)
._check_ssl_encryption(conn)
._check_password_encryption(conn)
._check_data_encryption_at_rest(conn)
._check_audit_logging(conn)
._check_connection_logging(conn)
._check_statement_logging(conn)
._check_listen_addresses(conn)
._check_pg_hba_configuration(conn)
._check_dynamic_sql(conn)
._check_untrusted_extensions(conn)
._check_insecure_settings(conn)
._check_default_configurations(conn)
logger.info()
.findings
() -> :
conn.cursor(cursor_factory=RealDictCursor) cur:
cur.execute()
weak_roles = [row[] row cur.fetchall()]
weak_roles:
.findings.append(SecurityFinding(
check_id=,
title=,
severity=Severity.CRITICAL,
description=,
affected_objects=weak_roles,
remediation=,
owasp_category=,
compliance_mappings={
: ,
: ,
:
}
))
() -> :
conn.cursor(cursor_factory=RealDictCursor) cur:
cur.execute()
excessive_grants = cur.fetchall()
excessive_grants:
affected = [
row excessive_grants
]
.findings.append(SecurityFinding(
check_id=,
title=,
severity=Severity.HIGH,
description=,
affected_objects=affected,
remediation=,
owasp_category=,
compliance_mappings={
: ,
:
}
))
() -> :
conn.cursor(cursor_factory=RealDictCursor) cur:
cur.execute()
superusers = [row[] row cur.fetchall()]
(superusers) > :
.findings.append(SecurityFinding(
check_id=,
title=,
severity=Severity.HIGH,
description=,
affected_objects=superusers,
remediation=,
owasp_category=,
compliance_mappings={
: ,
:
}
))
() -> :
conn.cursor(cursor_factory=RealDictCursor) cur:
cur.execute()
can_create = cur.fetchone()[]
can_create:
.findings.append(SecurityFinding(
check_id=,
title=,
severity=Severity.MEDIUM,
description=,
affected_objects=[],
remediation=,
owasp_category=,
compliance_mappings={
:
}
))
() -> :
conn.cursor(cursor_factory=RealDictCursor) cur:
cur.execute()
ssl_enabled = cur.fetchone()[] ==
ssl_enabled:
.findings.append(SecurityFinding(
check_id=,
title=,
severity=Severity.CRITICAL,
description=,
affected_objects=[],
remediation=,
owasp_category=,
compliance_mappings={
: ,
: ,
:
}
))
() -> :
conn.cursor(cursor_factory=RealDictCursor) cur:
cur.execute()
method = cur.fetchone()[]
method != :
.findings.append(SecurityFinding(
check_id=,
title=,
severity=Severity.HIGH,
description=,
affected_objects=[],
remediation=,
owasp_category=,
compliance_mappings={
: ,
:
}
))
() -> :
conn.cursor(cursor_factory=RealDictCursor) cur:
cur.execute()
log_dest = cur.fetchone()[]
log_dest == :
.findings.append(SecurityFinding(
check_id=,
title=,
severity=Severity.HIGH,
description=,
affected_objects=[],
remediation=,
owasp_category=,
compliance_mappings={
: ,
: ,
:
}
))
() -> :
conn.cursor(cursor_factory=RealDictCursor) cur:
cur.execute()
log_connections = cur.fetchone()[] ==
log_connections:
.findings.append(SecurityFinding(
check_id=,
title=,
severity=Severity.MEDIUM,
description=,
affected_objects=[],
remediation=,
owasp_category=,
compliance_mappings={
: ,
:
}
))
() -> :
conn.cursor(cursor_factory=RealDictCursor) cur:
cur.execute()
listen = cur.fetchone()[]
listen (, ):
.findings.append(SecurityFinding(
check_id=,
title=,
severity=Severity.MEDIUM,
description=,
affected_objects=[],
remediation=,
owasp_category=,
compliance_mappings={
: ,
:
}
))
() -> :
conn.cursor(cursor_factory=RealDictCursor) cur:
cur.execute()
vulnerable_funcs = [row[] row cur.fetchall()]
vulnerable_funcs:
.findings.append(SecurityFinding(
check_id=,
title=,
severity=Severity.CRITICAL,
description=,
affected_objects=vulnerable_funcs,
remediation=,
owasp_category=,
compliance_mappings={
: ,
:
}
))
() -> :
conn.cursor(cursor_factory=RealDictCursor) cur:
cur.execute()
checksums = cur.fetchone()
checksums checksums.get() == :
.findings.append(SecurityFinding(
check_id=,
title=,
severity=Severity.LOW,
description=,
affected_objects=[],
remediation=,
owasp_category=,
compliance_mappings={
:
}
))
() -> :
report_lines = [
,
,
,
,
]
severity_counts = {s: s Severity}
finding .findings:
severity_counts[finding.severity] +=
report_lines.append()
report_lines.append()
report_lines.append()
report_lines.append()
report_lines.append()
report_lines.append()
report_lines.append()
report_lines.append()
report_lines.append()
report_lines.append()
i, finding ((.findings, key= f: f.severity.value), ):
severity_emoji = {
Severity.CRITICAL: ,
Severity.HIGH: ,
Severity.MEDIUM: ,
Severity.LOW: ,
Severity.INFO:
}
report_lines.append()
report_lines.append()
report_lines.append()
report_lines.append()
report_lines.append()
report_lines.append()
report_lines.append()
report_lines.append()
finding.affected_objects:
report_lines.append()
obj finding.affected_objects[:]:
report_lines.append()
(finding.affected_objects) > :
report_lines.append()
report_lines.append()
report_lines.append()
report_lines.append()
finding.compliance_mappings:
report_lines.append()
standard, requirement finding.compliance_mappings.items():
report_lines.append()
report_lines.append()
report_lines.append()
report_lines.append()
.join(report_lines)
() -> :
script_lines = [
,
,
,
,
,
,
,
]
critical_findings = [f f .findings f.severity == Severity.CRITICAL]
high_findings = [f f .findings f.severity == Severity.HIGH]
critical_findings:
script_lines.append()
script_lines.append()
finding critical_findings:
script_lines.append()
script_lines.append()
script_lines.append()
high_findings:
script_lines.append()
script_lines.append()
finding high_findings:
script_lines.append()
script_lines.append()
script_lines.append()
script_lines.append()
script_lines.append()
script_lines.append()
.join(script_lines)
__name__ == :
argparse
parser = argparse.ArgumentParser(description=)
parser.add_argument(, required=, =)
parser.add_argument(, default=, =)
args = parser.parse_args()
scanner = PostgreSQLSecurityScanner(conn_string=args.conn)
findings = scanner.scan_all()
os
os.makedirs(args.output_dir, exist_ok=)
(, ) f:
f.write(scanner.generate_report())
(, ) f:
f.write(scanner.generate_remediation_script())
(, ) f:
findings_json = [
{
: f.check_id,
: f.title,
: f.severity.value,
: f.description,
: f.affected_objects,
: f.remediation,
: f.owasp_category,
: f.compliance_mappings
}
f findings
]
json.dump(findings_json, f, indent=)
()
()
| Error | Cause | Solution |
|---|---|---|
| "Permission denied for pg_authid" | Insufficient scanner privileges | Grant pg_read_all_settings and pg_read_all_stats roles |
| "Could not connect to database" | Connection blocked by firewall | Add scanner IP to pg_hba.conf or connect from allowed host |
| "Function does not exist: pg_reload_conf" | Using older PostgreSQL version | Use SELECT pg_ctl reload instead (requires OS access) |
| "SSL connection required" | Database enforces SSL but scanner doesn't use it | Add ?sslmode=require to connection string |
| "Too many findings to process" | Very insecure database | Prioritize critical/high findings first, fix iteratively |
Scan Scope
Severity Thresholds
Remediation Modes
DO:
DON'T:
/database-audit-logger - Implement audit logging found by scanner/database-health-monitor - Monitor security metrics over time/database-backup-automator - Backup before applying security fixes/database-connection-pooler - Secure connection management