关于 security
面向安全与开发团队的信息安全参考指南,汇集网络安全、事件响应和安全架构框架。内容涵盖漏洞管理、身份访问、OWASP 风险及应用和供应链安全实践。
主要功能
- 01安全架构与云安全控制
- 02漏洞评估和补丁管理
- 03身份与特权访问管理
- 04OWASP Top 10 示例
- 05SAST、DAST 与供应链安全
适用场景
- 01制定组织安全架构
- 02建立漏洞修复流程
- 03审查应用代码中的常见风险
- 04规划安全培训和指标
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ travisjneuman/ .claude --skill security安装后在 Claude Code 中输入/security确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/fortune50-information-security.mdincident-response.mdsecurity-frameworks.md详细介绍
信息安全专家
涵盖网络安全、事件响应和安全架构的综合安全框架。
安全架构
零信任架构
ZERO TRUST PRINCIPLES:
- Never trust, always verify
- Assume breach
- Verify explicitly
- Least privilege access
- Micro-segmentation
ZERO TRUST COMPONENTS:
IDENTITY:
- Strong authentication (MFA)
- Identity governance
- Privileged access management
- Continuous validation
DEVICES:
- Device health verification
- Endpoint detection and response
- Mobile device management
- Asset inventory
NETWORK:
- Micro-segmentation
- Software-defined perimeter
- Encrypted communications
- Network access control
APPLICATIONS:
- Application-level authentication
- API security
- Web application firewall
- Secure coding practices
DATA:
- Data classification
- Encryption at rest and in transit
- Data loss prevention
- Access controls
深度防御
SECURITY LAYERS:
PHYSICAL:
- Data center security
- Badge access
- Surveillance
- Environmental controls
PERIMETER:
- Firewalls
- IDS/IPS
- DMZ
- VPN
NETWORK:
- Segmentation
- Encryption
- Network monitoring
- NAC
HOST:
- Endpoint protection
- Host-based firewall
- Hardening
- Patch management
APPLICATION:
- WAF
- Secure coding
- Input validation
- Authentication
DATA:
- Encryption
- DLP
- Access controls
- Backup/recovery
云安全
| 领域 | 控制措施 |
|---|---|
| 身份 | SSO、MFA、PAM、IAM 策略 |
| 计算 | 加固映像、容器安全 |
| 网络 | VPC、安全组、WAF |
| 存储 | 加密、访问策略、备份 |
| 日志记录 | CloudTrail、SIEM 集成 |
| 合规性 | 配置规则、自动修复 |
有关详细的安全框架(NIST、ISO 27001、CIS Controls、MITRE ATT&CK),请参阅安全框架参考。
漏洞管理
漏洞管理流程
LIFECYCLE:
1. DISCOVERY
- Asset inventory
- Vulnerability scanning
- Penetration testing
- Code analysis
2. PRIORITIZATION
- CVSS scoring
- Asset criticality
- Exploit availability
- Business context
3. REMEDIATION
- Patch management
- Configuration changes
- Compensating controls
- Risk acceptance
4. VERIFICATION
- Rescan
- Validation testing
- Documentation
- Reporting
5. REPORTING
- Executive dashboards
- Trend analysis
- Compliance reporting
- SLA tracking
CVSS 评分
| 分数 | 严重程度 | SLA 目标 |
|---|---|---|
| 9.0-10.0 | 严重 | 7 天 |
| 7.0-8.9 | 高 | 30 天 |
| 4.0-6.9 | 中 | 90 天 |
| 0.1-3.9 | 低 | 尽力而为 |
补丁管理
PATCH PROCESS:
1. IDENTIFICATION
- Vendor announcements
- Vulnerability feeds
- Security bulletins
2. ASSESSMENT
- Applicability
- Risk evaluation
- Test requirements
3. TESTING
- Lab validation
- Compatibility testing
- Rollback planning
4. DEPLOYMENT
- Pilot group
- Phased rollout
- Monitoring
5. VERIFICATION
- Confirm installation
- Functional testing
- Documentation
身份与访问管理
IAM 框架
IAM COMPONENTS:
IDENTITY LIFECYCLE:
- Provisioning
- Modification
- De-provisioning
- Certification
AUTHENTICATION:
- Password policies
- Multi-factor authentication
- Single sign-on
- Passwordless
AUTHORIZATION:
- Role-based access (RBAC)
- Attribute-based access (ABAC)
- Least privilege
- Separation of duties
GOVERNANCE:
- Access reviews
- Policy enforcement
- Audit logging
- Compliance reporting
特权访问管理
PAM CONTROLS:
VAULT:
- Credential storage
- Password rotation
- Secrets management
SESSION:
- Session recording
- Just-in-time access
- Time-limited credentials
MONITORING:
- Activity logging
- Behavioral analytics
- Alert on anomalies
GOVERNANCE:
- Access certification
- Policy enforcement
- Compliance reporting
安全意识
安全培训计划
| 主题 | 频率 | 受众 |
|---|---|---|
| 新员工安全培训 | 入职时 | 全体员工 |
| 年度复训 | 每年 | 全体员工 |
| 网络钓鱼意识培训 | 每季度 | 全体员工 |
| 开发人员安全培训 | 每年 | 开发团队 |
| 高管简报 | 每季度 | 领导层 |
| 基于角色的培训 | 按需 | 特定角色 |
网络钓鱼模拟
SIMULATION PROGRAM:
FREQUENCY: Monthly
DIFFICULTY LEVELS:
- Easy: Generic, obvious errors
- Medium: Branded, some personalization
- Hard: Targeted, well-crafted
METRICS:
- Click rate
- Report rate
- Training completion
- Trend over time
RESPONSE:
- Click → Immediate training
- Report → Positive reinforcement
- Repeat offenders → Additional training
安全指标
关键安全指标
| 类别 | 指标 | 目标 |
|---|---|---|
| 漏洞 | 严重漏洞开放超过 30 天 | 0 |
| 补丁 | 在 SLA 时限内完成补丁更新的系统 | 95%+ |
| 事件 | 平均检测时间 | <24 小时 |
| 访问权限 | 孤立账户 | 0 |
| 培训 | 完成率 | 95%+ |
| 网络钓鱼 | 点击率 | <5% |
安全仪表板
EXECUTIVE DASHBOARD:
RISK POSTURE:
- Overall risk score
- Risk trend
- Top risks
COMPLIANCE:
- Framework coverage
- Audit findings
- Remediation status
OPERATIONS:
- Incident summary
- Vulnerability status
- Patching compliance
INVESTMENT:
- Budget utilization
- Tool effectiveness
- Headcount
威胁情报
威胁情报来源
| 类型 | 来源 | 用途 |
|---|---|---|
| 战略 | 行业报告、地缘政治信息 | 高管简报 |
| 战术 | TTP、恶意软件分析 | 检测规则 |
| 行动 | IOC、攻击活动 | 主动响应 |
| 技术 | 特征码、哈希值 | 自动拦截 |
有关详细的事件响应流程和 SOC 运营,请参阅事件响应参考。
参考资料
OWASP Top 10(含代码示例)
1. 访问控制失效
# WRONG - No authorization check
@app.get("/api/users/{user_id}/data")
async def get_user_data(user_id: str):
return db.get_user_data(user_id) # Any user can access any data
# RIGHT - Verify ownership
@app.get("/api/users/{user_id}/data")
async def get_user_data(user_id: str, current_user: User = Depends(get_current_user)):
if current_user.id != user_id and not current_user.is_admin:
raise HTTPException(status_code=403, detail="Forbidden")
return db.get_user_data(user_id)
2. 加密机制失效
# WRONG - Weak hashing
import hashlib
password_hash = hashlib.md5(password.encode()).hexdigest()
# RIGHT - Use bcrypt or argon2
from passlib.context import CryptContext
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
password_hash = pwd_context.hash(password)
verified = pwd_context.verify(password, password_hash)
3. 注入
# WRONG - SQL injection via string formatting
query = f"SELECT * FROM users WHERE email = '{email}'"
cursor.execute(query)
# RIGHT - Parameterized queries
cursor.execute("SELECT * FROM users WHERE email = %s", (email,))
# WRONG - Command injection via unsanitized input
# Never pass user input to shell commands directly
# Always use subprocess with list arguments:
# RIGHT - Safe subprocess usage
import subprocess
subprocess.run(["convert", user_filename, "output.png"], check=True)
4. 不安全设计
# WRONG - No rate limiting on password reset
@app.post("/api/reset-password")
async def reset_password(email: str):
send_reset_email(email)
# RIGHT - Rate limit + CAPTCHA
@app.post("/api/reset-password")
@limiter.limit("3/hour")
async def reset_password(email: str, captcha: str):
if not verify_captcha(captcha):
raise HTTPException(400, "Invalid CAPTCHA")
send_reset_email(email)
5. 安全配置错误
# WRONG - Debug mode in production, exposing stack traces
# RIGHT - Environment-aware configuration
app = FastAPI(debug=os.getenv("ENV") == "development")
@app.exception_handler(Exception)
async def handle_error(request, exc):
logger.error(f"Unhandled error: {exc}", exc_info=True)
return JSONResponse(status_code=500, content={"error": "Internal server error"})
6. 易受攻击的组件
# Audit dependencies regularly
npm audit
pip audit
cargo audit
# Pin versions, use lockfiles (package-lock.json, Pipfile.lock, Cargo.lock)
7. 身份验证失效
// WRONG - JWT with no expiration, weak secret
const token = jwt.sign(payload, "secret123");
// RIGHT - Short expiry, strong secret, refresh tokens
const token = jwt.sign(payload, process.env.JWT_SECRET, {
expiresIn: "15m",
algorithm: "RS256",
issuer: "my-app",
});
8. 软件和数据完整性失效
# Pin action versions in GitHub Actions (not @main)
- uses: actions/[email protected]
9. 安全日志记录和监控失效
# Log security-relevant events with structured data
logger.info("auth.login.success", extra={"user_id": user.id, "ip": request.client.host})
logger.warning("auth.login.failed", extra={"email": email, "ip": request.client.host})
logger.critical("auth.bruteforce.detected", extra={"ip": request.client.host, "attempts": count})
10. 服务端请求伪造(SSRF)
# WRONG - User controls URL without validation
# RIGHT - Allowlist domains, block internal IPs
from urllib.parse import urlparse
import ipaddress
ALLOWED_HOSTS = {"api.example.com", "cdn.example.com"}
def safe_fetch(url: str) -> Response:
parsed = urlparse(url)
if parsed.hostname not in ALLOWED_HOSTS:
raise ValueError("Host not allowed")
ip = ipaddress.ip_address(socket.gethostbyname(parsed.hostname))
if ip.is_private:
raise ValueError("Internal addresses not allowed")
return requests.get(url, timeout=10)
静态应用安全测试(SAST)
| 工具 | 语言 | 集成 |
|---|---|---|
| Semgrep | 30 多种语言 | CI/CD、IDE、CLI |
| CodeQL | C/C++、Java、JS、Python、Go | GitHub Actions |
| SonarQube | 30 多种语言 | 自托管、CI/CD |
| Bandit | 仅 Python | CLI、CI/CD |
# Semgrep (recommended - fast, customizable)
semgrep scan --config auto .
semgrep scan --config p/owasp-top-ten .
semgrep scan --config p/secrets .
动态应用安全测试(DAST)
# OWASP ZAP baseline scan (passive, fast)
docker run -t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py \
-t https://your-app.com
# Full scan (active, thorough)
docker run -t ghcr.io/zaproxy/zaproxy:stable zap-full-scan.py \
-t https://your-app.com
# API scan
docker run -t ghcr.io/zaproxy/zaproxy:stable zap-api-scan.py \
-t https://your-app.com/openapi.json -f openapi
供应链安全
Sigstore(代码签名)
# Sign container images with cosign
cosign sign --key cosign.key docker.io/myapp:latest
# Verify signatures
cosign verify --key cosign.pub docker.io/myapp:latest
SLSA(软件制品供应链级别)
| 级别 | 要求 |
|---|---|
| SLSA 1 | 记录构建流程 |
| SLSA 2 | 托管构建服务、签名的来源证明 |
| SLSA 3 | 强化的构建平台、不可伪造的来源证明 |
依赖项管理
# Lock dependencies and audit regularly
npm ci # Install from lockfile only
npm audit --audit-level=high
pip-audit
cargo audit
# Use Dependabot or Renovate for automated updates
另请参阅
评论
支持 Markdown