-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquick_audit.py
More file actions
148 lines (120 loc) · 4.53 KB
/
Copy pathquick_audit.py
File metadata and controls
148 lines (120 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python3
"""
Security Audit — simplified using Toonic presets.
Replaces 500+ lines of custom code with Toonic's built-in watchers.
Each function below is a complete, runnable security audit.
Usage:
python examples/security-audit/quick_audit.py
"""
from __future__ import annotations
def audit_code(path: str = "./examples/code-analysis/sample-project/"):
"""One-shot code security audit — finds secrets, injections, OWASP issues.
Before (continuous_monitoring.py): 524 lines, custom aiohttp, ssl, smtplib.
After: 2 lines using Toonic preset.
"""
from toonic.server.quick import security_audit
# One-liner: builds ServerConfig with security-focused goal + one-shot interval
return security_audit(path)
def audit_website(url: str = "http://obywatel.bielik.ai/"):
"""Website security audit — headers, SSL, content, endpoints.
Before (enterprise_features.py): 718 lines, custom ML, threat intel.
After: 5 lines using Toonic's built-in watchers.
"""
from toonic.server.quick import security_audit
return (
security_audit(url)
.network(url.split("//")[1].rstrip("/"))
.goal(
"web security audit: OWASP Top 10, security headers, "
"TLS config, exposed endpoints, input validation"
)
)
def continuous_monitoring(path: str = "./src/", log: str = "log:./app.log"):
"""Continuous security monitoring with triggers.
Before: custom daemon loop with asyncio.sleep, email alerts, webhook.
After: Toonic's built-in trigger scheduler + watchers handle everything.
"""
from toonic.server.quick import security_audit
return (
security_audit(path, log)
.network("api.example.com")
.process("port:5432")
.interval(300)
.goal(
"continuous security monitoring: detect new vulnerabilities, "
"suspicious log patterns, unauthorized access attempts"
)
)
def full_stack_audit(
code: str = "./src/",
logs: str = "log:./auth.log",
network: str = "api.example.com",
db: str = "db:./app.db",
):
"""Full-stack security audit: code + logs + network + database.
Before: required combining continuous_monitoring.py + enterprise_features.py
+ generate_report.py (1400+ lines total).
After: 8 lines, all watchers built-in.
"""
from toonic.server.quick import security_audit
return (
security_audit(code, logs)
.network(network)
.database(db)
.process("port:5432")
.goal(
"comprehensive security audit: code vulnerabilities, "
"auth log failures, exposed services, database security"
)
)
def demo():
"""Demo: build configs without starting server (safe to run)."""
print("=" * 60)
print(" Security Audit — Toonic Presets Demo")
print("=" * 60)
# 1. Code audit
print("\n1. Code Security Audit (1-liner)")
builder = audit_code()
cfg = builder.build_config()
print(f" Goal: {cfg.goal[:70]}...")
print(f" Sources: {len(cfg.sources)}")
for s in cfg.sources:
print(f" [{s.category}] {s.path_or_url}")
# 2. Website audit
print("\n2. Website Security Audit")
builder = audit_website("http://httpbin.org/")
cfg = builder.build_config()
print(f" Goal: {cfg.goal[:70]}...")
print(f" Sources: {len(cfg.sources)}")
for s in cfg.sources:
print(f" [{s.category}] {s.path_or_url}")
# 3. Continuous monitoring
print("\n3. Continuous Monitoring")
builder = continuous_monitoring(
"./examples/code-analysis/sample-project/",
"log:./docker/test-data/sample.logfile",
)
cfg = builder.build_config()
print(f" Goal: {cfg.goal[:70]}...")
print(f" Interval: {cfg.interval}s")
print(f" Sources: {len(cfg.sources)}")
for s in cfg.sources:
print(f" [{s.category}] {s.path_or_url}")
# 4. Full-stack
print("\n4. Full-Stack Security Audit")
builder = full_stack_audit(
code="./examples/code-analysis/sample-project/",
logs="log:./docker/test-data/sample.logfile",
)
cfg = builder.build_config()
print(f" Goal: {cfg.goal[:70]}...")
print(f" Sources: {len(cfg.sources)}")
for s in cfg.sources:
print(f" [{s.category}] {s.path_or_url}")
print("\n" + "=" * 60)
print(" To actually run any audit:")
print(" from toonic.server.quick import security_audit")
print(' security_audit("./src/").run()')
print("=" * 60)
if __name__ == "__main__":
demo()