@sylix/coworker 2.0.10 → 2.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/slash/config.d.ts.map +1 -1
- package/dist/commands/slash/config.js +23 -5
- package/dist/commands/slash/config.js.map +1 -1
- package/dist/commands/slash/todo.js +1 -1
- package/dist/commands/slash/todo.js.map +1 -1
- package/dist/core/CoWorkerAgent.d.ts.map +1 -1
- package/dist/core/CoWorkerAgent.js +6 -3
- package/dist/core/CoWorkerAgent.js.map +1 -1
- package/dist/permissions/PermissionInterceptor.js +1 -1
- package/dist/permissions/PermissionInterceptor.js.map +1 -1
- package/dist/skills/defaults/accessibility/screen-reader-testing.md +545 -0
- package/dist/skills/defaults/accessibility/wcag-audit-patterns.md +555 -0
- package/dist/skills/defaults/ai-ml/rag.md +276 -0
- package/dist/skills/defaults/backend-development/api-design-principles.md +528 -0
- package/dist/skills/defaults/backend-development/api-design.md +285 -0
- package/dist/skills/defaults/backend-development/architecture-patterns.md +494 -0
- package/dist/skills/defaults/backend-development/async-python.md +237 -0
- package/dist/skills/defaults/backend-development/auth-implementation-patterns.md +638 -0
- package/dist/skills/defaults/backend-development/bazel-build-optimization.md +387 -0
- package/dist/skills/defaults/backend-development/billing-automation/SKILL.md +566 -0
- package/dist/skills/defaults/backend-development/code-review-excellence.md +538 -0
- package/dist/skills/defaults/backend-development/cqrs-implementation.md +554 -0
- package/dist/skills/defaults/backend-development/database-design.md +305 -0
- package/dist/skills/defaults/backend-development/debugging-strategies.md +536 -0
- package/dist/skills/defaults/backend-development/e2e-testing-patterns.md +544 -0
- package/dist/skills/defaults/backend-development/error-handling-patterns.md +641 -0
- package/dist/skills/defaults/backend-development/fastapi-templates.md +559 -0
- package/dist/skills/defaults/backend-development/fastapi.md +309 -0
- package/dist/skills/defaults/backend-development/git-advanced-workflows.md +405 -0
- package/dist/skills/defaults/backend-development/microservices-patterns.md +595 -0
- package/dist/skills/defaults/backend-development/microservices.md +284 -0
- package/dist/skills/defaults/backend-development/monorepo-management.md +623 -0
- package/dist/skills/defaults/backend-development/nodejs-backend-patterns.md +1048 -0
- package/dist/skills/defaults/backend-development/nx-workspace-patterns.md +457 -0
- package/dist/skills/defaults/backend-development/paypal-integration/SKILL.md +478 -0
- package/dist/skills/defaults/backend-development/pci-compliance/SKILL.md +480 -0
- package/dist/skills/defaults/backend-development/python-anti-patterns.md +349 -0
- package/dist/skills/defaults/backend-development/python-background-jobs.md +364 -0
- package/dist/skills/defaults/backend-development/python-code-style.md +360 -0
- package/dist/skills/defaults/backend-development/python-configuration.md +368 -0
- package/dist/skills/defaults/backend-development/python-design-patterns.md +296 -0
- package/dist/skills/defaults/backend-development/python-error-handling.md +323 -0
- package/dist/skills/defaults/backend-development/python-packaging.md +887 -0
- package/dist/skills/defaults/backend-development/python-performance-optimization.md +874 -0
- package/dist/skills/defaults/backend-development/python-project-structure.md +252 -0
- package/dist/skills/defaults/backend-development/python-resilience.md +376 -0
- package/dist/skills/defaults/backend-development/python-resource-management.md +421 -0
- package/dist/skills/defaults/backend-development/python-type-safety.md +428 -0
- package/dist/skills/defaults/backend-development/sql-optimization-patterns.md +509 -0
- package/dist/skills/defaults/backend-development/stripe-integration/SKILL.md +522 -0
- package/dist/skills/defaults/backend-development/turborepo-caching.md +376 -0
- package/dist/skills/defaults/blockchain/defi-protocol-templates.md +430 -0
- package/dist/skills/defaults/blockchain/nft-standards.md +364 -0
- package/dist/skills/defaults/blockchain/solidity-security.md +514 -0
- package/dist/skills/defaults/blockchain/web3-testing.md +360 -0
- package/dist/skills/defaults/business/competitive-landscape/SKILL.md +527 -0
- package/dist/skills/defaults/business/market-sizing-analysis/SKILL.md +451 -0
- package/dist/skills/defaults/business/startup-financial-modeling/SKILL.md +494 -0
- package/dist/skills/defaults/business/startup-metrics-framework/SKILL.md +564 -0
- package/dist/skills/defaults/business/team-composition-analysis.md +437 -0
- package/dist/skills/defaults/compliance/employment-contract-templates/SKILL.md +527 -0
- package/dist/skills/defaults/compliance/gdpr-data-handling/SKILL.md +630 -0
- package/dist/skills/defaults/data-engineering/airflow-dag-patterns.md +436 -0
- package/dist/skills/defaults/data-engineering/airflow.md +519 -0
- package/dist/skills/defaults/data-engineering/data-quality.md +583 -0
- package/dist/skills/defaults/data-engineering/dbt-transformation-patterns.md +482 -0
- package/dist/skills/defaults/data-engineering/dbt.md +556 -0
- package/dist/skills/defaults/data-engineering/ml-pipeline-workflow/SKILL.md +247 -0
- package/dist/skills/defaults/data-engineering/spark-optimization.md +348 -0
- package/dist/skills/defaults/data-engineering/spark.md +411 -0
- package/dist/skills/defaults/database/postgresql.md +202 -0
- package/dist/skills/defaults/debugging/systematic-debugging.md +249 -0
- package/dist/skills/defaults/devops/architecture-decision-records.md +448 -0
- package/dist/skills/defaults/devops/changelog-automation.md +580 -0
- package/dist/skills/defaults/devops/cicd.md +314 -0
- package/dist/skills/defaults/devops/cloud.md +263 -0
- package/dist/skills/defaults/devops/code-review-excellence.md +299 -0
- package/dist/skills/defaults/devops/cost-optimization.md +295 -0
- package/dist/skills/defaults/devops/deployment-pipeline-design.md +356 -0
- package/dist/skills/defaults/devops/docker.md +281 -0
- package/dist/skills/defaults/devops/git-workflows.md +205 -0
- package/dist/skills/defaults/devops/github-actions.md +311 -0
- package/dist/skills/defaults/devops/gitlab-ci-patterns.md +266 -0
- package/dist/skills/defaults/devops/hybrid-cloud-networking.md +241 -0
- package/dist/skills/defaults/devops/istio-traffic-management.md +327 -0
- package/dist/skills/defaults/devops/kubernetes.md +339 -0
- package/dist/skills/defaults/devops/linkerd-patterns.md +311 -0
- package/dist/skills/defaults/devops/multi-cloud-architecture.md +181 -0
- package/dist/skills/defaults/devops/observability.md +243 -0
- package/dist/skills/defaults/devops/openapi-spec-generation.md +1024 -0
- package/dist/skills/defaults/devops/postmortem-writing.md +396 -0
- package/dist/skills/defaults/devops/prometheus-configuration.md +265 -0
- package/dist/skills/defaults/devops/secrets-management.md +341 -0
- package/dist/skills/defaults/devops/service-mesh-observability.md +385 -0
- package/dist/skills/defaults/devops/terraform-module-library.md +244 -0
- package/dist/skills/defaults/finance/backtesting-frameworks/SKILL.md +663 -0
- package/dist/skills/defaults/finance/risk-metrics-calculation/SKILL.md +557 -0
- package/dist/skills/defaults/frontend/accessibility-compliance.md +420 -0
- package/dist/skills/defaults/frontend/design-system-patterns.md +337 -0
- package/dist/skills/defaults/frontend/interaction-design.md +327 -0
- package/dist/skills/defaults/frontend/javascript.md +311 -0
- package/dist/skills/defaults/frontend/modern-javascript-patterns.md +927 -0
- package/dist/skills/defaults/frontend/react-native-design.md +440 -0
- package/dist/skills/defaults/frontend/react.md +345 -0
- package/dist/skills/defaults/frontend/responsive-design.md +472 -0
- package/dist/skills/defaults/frontend/tailwind-design-system.md +337 -0
- package/dist/skills/defaults/frontend/typescript-advanced-types.md +724 -0
- package/dist/skills/defaults/frontend/typescript.md +334 -0
- package/dist/skills/defaults/frontend/visual-design-foundations.md +326 -0
- package/dist/skills/defaults/frontend/web-component-design.md +279 -0
- package/dist/skills/defaults/game-development/godot-gdscript-patterns.md +188 -0
- package/dist/skills/defaults/game-development/unity-ecs-patterns.md +594 -0
- package/dist/skills/defaults/kubernetes/gitops-workflow.md +285 -0
- package/dist/skills/defaults/kubernetes/gitops.md +280 -0
- package/dist/skills/defaults/kubernetes/helm-chart-scaffolding.md +553 -0
- package/dist/skills/defaults/kubernetes/helm.md +343 -0
- package/dist/skills/defaults/kubernetes/k8s-manifest-generator.md +501 -0
- package/dist/skills/defaults/kubernetes/k8s-security-policies.md +342 -0
- package/dist/skills/defaults/kubernetes/manifests.md +330 -0
- package/dist/skills/defaults/kubernetes/security.md +337 -0
- package/dist/skills/defaults/llm-application/embedding-strategies.md +608 -0
- package/dist/skills/defaults/llm-application/hybrid-search-implementation.md +570 -0
- package/dist/skills/defaults/llm-application/hybrid-search.md +570 -0
- package/dist/skills/defaults/llm-application/langchain-architecture.md +666 -0
- package/dist/skills/defaults/llm-application/langchain.md +259 -0
- package/dist/skills/defaults/llm-application/llm-evaluation.md +695 -0
- package/dist/skills/defaults/llm-application/prompt-engineering-patterns.md +449 -0
- package/dist/skills/defaults/llm-application/prompt-engineering.md +219 -0
- package/dist/skills/defaults/llm-application/rag-implementation.md +434 -0
- package/dist/skills/defaults/llm-application/similarity-search-patterns.md +560 -0
- package/dist/skills/defaults/llm-application/similarity-search.md +560 -0
- package/dist/skills/defaults/llm-application/vector-index-tuning.md +523 -0
- package/dist/skills/defaults/mobile/mobile-android-design.md +440 -0
- package/dist/skills/defaults/mobile/mobile-ios-design.md +266 -0
- package/dist/skills/defaults/monitoring/distributed-tracing.md +436 -0
- package/dist/skills/defaults/monitoring/grafana-dashboards.md +370 -0
- package/dist/skills/defaults/monitoring/prometheus-configuration.md +379 -0
- package/dist/skills/defaults/monitoring/slo-implementation.md +323 -0
- package/dist/skills/defaults/refactoring/code-refactoring.md +349 -0
- package/dist/skills/defaults/security/anti-reversing-techniques/SKILL.md +559 -0
- package/dist/skills/defaults/security/auditor.md +168 -0
- package/dist/skills/defaults/security/binary-analysis-patterns/SKILL.md +438 -0
- package/dist/skills/defaults/security/memory-forensics/SKILL.md +483 -0
- package/dist/skills/defaults/security/mtls-configuration.md +349 -0
- package/dist/skills/defaults/security/protocol-reverse-engineering/SKILL.md +520 -0
- package/dist/skills/defaults/security/sast-configuration.md +182 -0
- package/dist/skills/defaults/security/security.md +313 -0
- package/dist/skills/defaults/security/stride-analysis.md +273 -0
- package/dist/skills/defaults/security/threat-mitigation-mapping.md +290 -0
- package/dist/skills/defaults/systems/bash-defensive-patterns/SKILL.md +539 -0
- package/dist/skills/defaults/systems/bats-testing-patterns/SKILL.md +631 -0
- package/dist/skills/defaults/systems/go-concurrency-patterns.md +657 -0
- package/dist/skills/defaults/systems/memory-safety-patterns.md +605 -0
- package/dist/skills/defaults/systems/rust-async-patterns.md +519 -0
- package/dist/skills/defaults/systems/shellcheck-configuration/SKILL.md +456 -0
- package/dist/skills/defaults/team-collaboration/multi-reviewer-patterns.md +126 -0
- package/dist/skills/defaults/team-collaboration/parallel-feature-development.md +151 -0
- package/dist/skills/defaults/testing/javascript-testing-patterns.md +1021 -0
- package/dist/skills/defaults/testing/python-testing-patterns.md +351 -0
- package/dist/skills/defaults/testing/testing.md +332 -0
- package/dist/skills/defaults/workflows/context-driven-development.md +384 -0
- package/dist/skills/defaults/workflows/track-management.md +592 -0
- package/dist/skills/defaults/workflows/workflow-patterns.md +622 -0
- package/dist/skills/index.d.ts +11 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +129 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/utils/character.js +6 -9
- package/dist/utils/character.js.map +1 -1
- package/dist/utils/contextManager.js +3 -7
- package/dist/utils/contextManager.js.map +1 -1
- package/dist/utils/inputbar.d.ts.map +1 -1
- package/dist/utils/inputbar.js +8 -1
- package/dist/utils/inputbar.js.map +1 -1
- package/dist/utils/output.d.ts.map +1 -1
- package/dist/utils/output.js +3 -35
- package/dist/utils/output.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: protocol-reverse-engineering
|
|
3
|
+
description: Master network protocol reverse engineering including packet analysis, protocol dissection, and custom protocol documentation. Use when analyzing network traffic, understanding proprietary protocols, or debugging network communication.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Protocol Reverse Engineering
|
|
7
|
+
|
|
8
|
+
Comprehensive techniques for capturing, analyzing, and documenting network protocols for security research, interoperability, and debugging.
|
|
9
|
+
|
|
10
|
+
## Traffic Capture
|
|
11
|
+
|
|
12
|
+
### Wireshark Capture
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# Capture on specific interface
|
|
16
|
+
wireshark -i eth0 -k
|
|
17
|
+
|
|
18
|
+
# Capture with filter
|
|
19
|
+
wireshark -i eth0 -k -f "port 443"
|
|
20
|
+
|
|
21
|
+
# Capture to file
|
|
22
|
+
tshark -i eth0 -w capture.pcap
|
|
23
|
+
|
|
24
|
+
# Ring buffer capture (rotate files)
|
|
25
|
+
tshark -i eth0 -b filesize:100000 -b files:10 -w capture.pcap
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### tcpdump Capture
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Basic capture
|
|
32
|
+
tcpdump -i eth0 -w capture.pcap
|
|
33
|
+
|
|
34
|
+
# With filter
|
|
35
|
+
tcpdump -i eth0 port 8080 -w capture.pcap
|
|
36
|
+
|
|
37
|
+
# Capture specific bytes
|
|
38
|
+
tcpdump -i eth0 -s 0 -w capture.pcap # Full packet
|
|
39
|
+
|
|
40
|
+
# Real-time display
|
|
41
|
+
tcpdump -i eth0 -X port 80
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Man-in-the-Middle Capture
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# mitmproxy for HTTP/HTTPS
|
|
48
|
+
mitmproxy --mode transparent -p 8080
|
|
49
|
+
|
|
50
|
+
# SSL/TLS interception
|
|
51
|
+
mitmproxy --mode transparent --ssl-insecure
|
|
52
|
+
|
|
53
|
+
# Dump to file
|
|
54
|
+
mitmdump -w traffic.mitm
|
|
55
|
+
|
|
56
|
+
# Burp Suite
|
|
57
|
+
# Configure browser proxy to 127.0.0.1:8080
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Protocol Analysis
|
|
61
|
+
|
|
62
|
+
### Wireshark Analysis
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
# Display filters
|
|
66
|
+
tcp.port == 8080
|
|
67
|
+
http.request.method == "POST"
|
|
68
|
+
ip.addr == 192.168.1.1
|
|
69
|
+
tcp.flags.syn == 1 && tcp.flags.ack == 0
|
|
70
|
+
frame contains "password"
|
|
71
|
+
|
|
72
|
+
# Following streams
|
|
73
|
+
Right-click > Follow > TCP Stream
|
|
74
|
+
Right-click > Follow > HTTP Stream
|
|
75
|
+
|
|
76
|
+
# Export objects
|
|
77
|
+
File > Export Objects > HTTP
|
|
78
|
+
|
|
79
|
+
# Decryption
|
|
80
|
+
Edit > Preferences > Protocols > TLS
|
|
81
|
+
- (Pre)-Master-Secret log filename
|
|
82
|
+
- RSA keys list
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### tshark Analysis
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Extract specific fields
|
|
89
|
+
tshark -r capture.pcap -T fields -e ip.src -e ip.dst -e tcp.port
|
|
90
|
+
|
|
91
|
+
# Statistics
|
|
92
|
+
tshark -r capture.pcap -q -z conv,tcp
|
|
93
|
+
tshark -r capture.pcap -q -z endpoints,ip
|
|
94
|
+
|
|
95
|
+
# Filter and extract
|
|
96
|
+
tshark -r capture.pcap -Y "http" -T json > http_traffic.json
|
|
97
|
+
|
|
98
|
+
# Protocol hierarchy
|
|
99
|
+
tshark -r capture.pcap -q -z io,phs
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Scapy for Custom Analysis
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from scapy.all import *
|
|
106
|
+
|
|
107
|
+
# Read pcap
|
|
108
|
+
packets = rdpcap("capture.pcap")
|
|
109
|
+
|
|
110
|
+
# Analyze packets
|
|
111
|
+
for pkt in packets:
|
|
112
|
+
if pkt.haslayer(TCP):
|
|
113
|
+
print(f"Src: {pkt[IP].src}:{pkt[TCP].sport}")
|
|
114
|
+
print(f"Dst: {pkt[IP].dst}:{pkt[TCP].dport}")
|
|
115
|
+
if pkt.haslayer(Raw):
|
|
116
|
+
print(f"Data: {pkt[Raw].load[:50]}")
|
|
117
|
+
|
|
118
|
+
# Filter packets
|
|
119
|
+
http_packets = [p for p in packets if p.haslayer(TCP)
|
|
120
|
+
and (p[TCP].sport == 80 or p[TCP].dport == 80)]
|
|
121
|
+
|
|
122
|
+
# Create custom packets
|
|
123
|
+
pkt = IP(dst="target")/TCP(dport=80)/Raw(load="GET / HTTP/1.1\r\n")
|
|
124
|
+
send(pkt)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Protocol Identification
|
|
128
|
+
|
|
129
|
+
### Common Protocol Signatures
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
HTTP - "HTTP/1." or "GET " or "POST " at start
|
|
133
|
+
TLS/SSL - 0x16 0x03 (record layer)
|
|
134
|
+
DNS - UDP port 53, specific header format
|
|
135
|
+
SMB - 0xFF 0x53 0x4D 0x42 ("SMB" signature)
|
|
136
|
+
SSH - "SSH-2.0" banner
|
|
137
|
+
FTP - "220 " response, "USER " command
|
|
138
|
+
SMTP - "220 " banner, "EHLO" command
|
|
139
|
+
MySQL - 0x00 length prefix, protocol version
|
|
140
|
+
PostgreSQL - 0x00 0x00 0x00 startup length
|
|
141
|
+
Redis - "*" RESP array prefix
|
|
142
|
+
MongoDB - BSON documents with specific header
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Protocol Header Patterns
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
+--------+--------+--------+--------+
|
|
149
|
+
| Magic number / Signature |
|
|
150
|
+
+--------+--------+--------+--------+
|
|
151
|
+
| Version | Flags |
|
|
152
|
+
+--------+--------+--------+--------+
|
|
153
|
+
| Length | Message Type |
|
|
154
|
+
+--------+--------+--------+--------+
|
|
155
|
+
| Sequence Number / Session ID |
|
|
156
|
+
+--------+--------+--------+--------+
|
|
157
|
+
| Payload... |
|
|
158
|
+
+--------+--------+--------+--------+
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Binary Protocol Analysis
|
|
162
|
+
|
|
163
|
+
### Structure Identification
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
# Common patterns in binary protocols
|
|
167
|
+
|
|
168
|
+
# Length-prefixed message
|
|
169
|
+
struct Message {
|
|
170
|
+
uint32_t length; # Total message length
|
|
171
|
+
uint16_t msg_type; # Message type identifier
|
|
172
|
+
uint8_t flags; # Flags/options
|
|
173
|
+
uint8_t reserved; # Padding/alignment
|
|
174
|
+
uint8_t payload[]; # Variable-length payload
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
# Type-Length-Value (TLV)
|
|
178
|
+
struct TLV {
|
|
179
|
+
uint8_t type; # Field type
|
|
180
|
+
uint16_t length; # Field length
|
|
181
|
+
uint8_t value[]; # Field data
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
# Fixed header + variable payload
|
|
185
|
+
struct Packet {
|
|
186
|
+
uint8_t magic[4]; # "ABCD" signature
|
|
187
|
+
uint32_t version;
|
|
188
|
+
uint32_t payload_len;
|
|
189
|
+
uint32_t checksum; # CRC32 or similar
|
|
190
|
+
uint8_t payload[];
|
|
191
|
+
};
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Python Protocol Parser
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
import struct
|
|
198
|
+
from dataclasses import dataclass
|
|
199
|
+
|
|
200
|
+
@dataclass
|
|
201
|
+
class MessageHeader:
|
|
202
|
+
magic: bytes
|
|
203
|
+
version: int
|
|
204
|
+
msg_type: int
|
|
205
|
+
length: int
|
|
206
|
+
|
|
207
|
+
@classmethod
|
|
208
|
+
def from_bytes(cls, data: bytes):
|
|
209
|
+
magic, version, msg_type, length = struct.unpack(
|
|
210
|
+
">4sHHI", data[:12]
|
|
211
|
+
)
|
|
212
|
+
return cls(magic, version, msg_type, length)
|
|
213
|
+
|
|
214
|
+
def parse_messages(data: bytes):
|
|
215
|
+
offset = 0
|
|
216
|
+
messages = []
|
|
217
|
+
|
|
218
|
+
while offset < len(data):
|
|
219
|
+
header = MessageHeader.from_bytes(data[offset:])
|
|
220
|
+
payload = data[offset+12:offset+12+header.length]
|
|
221
|
+
messages.append((header, payload))
|
|
222
|
+
offset += 12 + header.length
|
|
223
|
+
|
|
224
|
+
return messages
|
|
225
|
+
|
|
226
|
+
# Parse TLV structure
|
|
227
|
+
def parse_tlv(data: bytes):
|
|
228
|
+
fields = []
|
|
229
|
+
offset = 0
|
|
230
|
+
|
|
231
|
+
while offset < len(data):
|
|
232
|
+
field_type = data[offset]
|
|
233
|
+
length = struct.unpack(">H", data[offset+1:offset+3])[0]
|
|
234
|
+
value = data[offset+3:offset+3+length]
|
|
235
|
+
fields.append((field_type, value))
|
|
236
|
+
offset += 3 + length
|
|
237
|
+
|
|
238
|
+
return fields
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Hex Dump Analysis
|
|
242
|
+
|
|
243
|
+
```python
|
|
244
|
+
def hexdump(data: bytes, width: int = 16):
|
|
245
|
+
"""Format binary data as hex dump."""
|
|
246
|
+
lines = []
|
|
247
|
+
for i in range(0, len(data), width):
|
|
248
|
+
chunk = data[i:i+width]
|
|
249
|
+
hex_part = ' '.join(f'{b:02x}' for b in chunk)
|
|
250
|
+
ascii_part = ''.join(
|
|
251
|
+
chr(b) if 32 <= b < 127 else '.'
|
|
252
|
+
for b in chunk
|
|
253
|
+
)
|
|
254
|
+
lines.append(f'{i:08x} {hex_part:<{width*3}} {ascii_part}')
|
|
255
|
+
return '\n'.join(lines)
|
|
256
|
+
|
|
257
|
+
# Example output:
|
|
258
|
+
# 00000000 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d HTTP/1.1 200 OK.
|
|
259
|
+
# 00000010 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 74 .Content-Type: t
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Encryption Analysis
|
|
263
|
+
|
|
264
|
+
### Identifying Encryption
|
|
265
|
+
|
|
266
|
+
```python
|
|
267
|
+
# Entropy analysis - high entropy suggests encryption/compression
|
|
268
|
+
import math
|
|
269
|
+
from collections import Counter
|
|
270
|
+
|
|
271
|
+
def entropy(data: bytes) -> float:
|
|
272
|
+
if not data:
|
|
273
|
+
return 0.0
|
|
274
|
+
counter = Counter(data)
|
|
275
|
+
probs = [count / len(data) for count in counter.values()]
|
|
276
|
+
return -sum(p * math.log2(p) for p in probs)
|
|
277
|
+
|
|
278
|
+
# Entropy thresholds:
|
|
279
|
+
# < 6.0: Likely plaintext or structured data
|
|
280
|
+
# 6.0-7.5: Possibly compressed
|
|
281
|
+
# > 7.5: Likely encrypted or random
|
|
282
|
+
|
|
283
|
+
# Common encryption indicators
|
|
284
|
+
# - High, uniform entropy
|
|
285
|
+
# - No obvious structure or patterns
|
|
286
|
+
# - Length often multiple of block size (16 for AES)
|
|
287
|
+
# - Possible IV at start (16 bytes for AES-CBC)
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### TLS Analysis
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
# Extract TLS metadata
|
|
294
|
+
tshark -r capture.pcap -Y "ssl.handshake" \
|
|
295
|
+
-T fields -e ip.src -e ssl.handshake.ciphersuite
|
|
296
|
+
|
|
297
|
+
# JA3 fingerprinting (client)
|
|
298
|
+
tshark -r capture.pcap -Y "ssl.handshake.type == 1" \
|
|
299
|
+
-T fields -e ssl.handshake.ja3
|
|
300
|
+
|
|
301
|
+
# JA3S fingerprinting (server)
|
|
302
|
+
tshark -r capture.pcap -Y "ssl.handshake.type == 2" \
|
|
303
|
+
-T fields -e ssl.handshake.ja3s
|
|
304
|
+
|
|
305
|
+
# Certificate extraction
|
|
306
|
+
tshark -r capture.pcap -Y "ssl.handshake.certificate" \
|
|
307
|
+
-T fields -e x509sat.printableString
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Decryption Approaches
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
# Pre-master secret log (browser)
|
|
314
|
+
export SSLKEYLOGFILE=/tmp/keys.log
|
|
315
|
+
|
|
316
|
+
# Configure Wireshark
|
|
317
|
+
# Edit > Preferences > Protocols > TLS
|
|
318
|
+
# (Pre)-Master-Secret log filename: /tmp/keys.log
|
|
319
|
+
|
|
320
|
+
# Decrypt with private key (if available)
|
|
321
|
+
# Only works for RSA key exchange
|
|
322
|
+
# Edit > Preferences > Protocols > TLS > RSA keys list
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
## Custom Protocol Documentation
|
|
326
|
+
|
|
327
|
+
### Protocol Specification Template
|
|
328
|
+
|
|
329
|
+
```markdown
|
|
330
|
+
# Protocol Name Specification
|
|
331
|
+
|
|
332
|
+
## Overview
|
|
333
|
+
|
|
334
|
+
Brief description of protocol purpose and design.
|
|
335
|
+
|
|
336
|
+
## Transport
|
|
337
|
+
|
|
338
|
+
- Layer: TCP/UDP
|
|
339
|
+
- Port: XXXX
|
|
340
|
+
- Encryption: TLS 1.2+
|
|
341
|
+
|
|
342
|
+
## Message Format
|
|
343
|
+
|
|
344
|
+
### Header (12 bytes)
|
|
345
|
+
|
|
346
|
+
| Offset | Size | Field | Description |
|
|
347
|
+
| ------ | ---- | ------- | ----------------------- |
|
|
348
|
+
| 0 | 4 | Magic | 0x50524F54 ("PROT") |
|
|
349
|
+
| 4 | 2 | Version | Protocol version (1) |
|
|
350
|
+
| 6 | 2 | Type | Message type identifier |
|
|
351
|
+
| 8 | 4 | Length | Payload length in bytes |
|
|
352
|
+
|
|
353
|
+
### Message Types
|
|
354
|
+
|
|
355
|
+
| Type | Name | Description |
|
|
356
|
+
| ---- | --------- | ---------------------- |
|
|
357
|
+
| 0x01 | HELLO | Connection initiation |
|
|
358
|
+
| 0x02 | HELLO_ACK | Connection accepted |
|
|
359
|
+
| 0x03 | DATA | Application data |
|
|
360
|
+
| 0x04 | CLOSE | Connection termination |
|
|
361
|
+
|
|
362
|
+
### Type 0x01: HELLO
|
|
363
|
+
|
|
364
|
+
| Offset | Size | Field | Description |
|
|
365
|
+
| ------ | ---- | ---------- | ------------------------ |
|
|
366
|
+
| 0 | 4 | ClientID | Unique client identifier |
|
|
367
|
+
| 4 | 2 | Flags | Connection flags |
|
|
368
|
+
| 6 | var | Extensions | TLV-encoded extensions |
|
|
369
|
+
|
|
370
|
+
## State Machine
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
[INIT] --HELLO--> [WAIT_ACK] --HELLO_ACK--> [CONNECTED]
|
|
374
|
+
|
|
|
375
|
+
DATA/DATA
|
|
376
|
+
|
|
|
377
|
+
[CLOSED] <--CLOSE--+
|
|
378
|
+
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
## Examples
|
|
382
|
+
### Connection Establishment
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
Client -> Server: HELLO (ClientID=0x12345678)
|
|
386
|
+
Server -> Client: HELLO_ACK (Status=OK)
|
|
387
|
+
Client -> Server: DATA (payload)
|
|
388
|
+
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### Wireshark Dissector (Lua)
|
|
394
|
+
|
|
395
|
+
```lua
|
|
396
|
+
-- custom_protocol.lua
|
|
397
|
+
local proto = Proto("custom", "Custom Protocol")
|
|
398
|
+
|
|
399
|
+
-- Define fields
|
|
400
|
+
local f_magic = ProtoField.string("custom.magic", "Magic")
|
|
401
|
+
local f_version = ProtoField.uint16("custom.version", "Version")
|
|
402
|
+
local f_type = ProtoField.uint16("custom.type", "Type")
|
|
403
|
+
local f_length = ProtoField.uint32("custom.length", "Length")
|
|
404
|
+
local f_payload = ProtoField.bytes("custom.payload", "Payload")
|
|
405
|
+
|
|
406
|
+
proto.fields = { f_magic, f_version, f_type, f_length, f_payload }
|
|
407
|
+
|
|
408
|
+
-- Message type names
|
|
409
|
+
local msg_types = {
|
|
410
|
+
[0x01] = "HELLO",
|
|
411
|
+
[0x02] = "HELLO_ACK",
|
|
412
|
+
[0x03] = "DATA",
|
|
413
|
+
[0x04] = "CLOSE"
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function proto.dissector(buffer, pinfo, tree)
|
|
417
|
+
pinfo.cols.protocol = "CUSTOM"
|
|
418
|
+
|
|
419
|
+
local subtree = tree:add(proto, buffer())
|
|
420
|
+
|
|
421
|
+
-- Parse header
|
|
422
|
+
subtree:add(f_magic, buffer(0, 4))
|
|
423
|
+
subtree:add(f_version, buffer(4, 2))
|
|
424
|
+
|
|
425
|
+
local msg_type = buffer(6, 2):uint()
|
|
426
|
+
subtree:add(f_type, buffer(6, 2)):append_text(
|
|
427
|
+
" (" .. (msg_types[msg_type] or "Unknown") .. ")"
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
local length = buffer(8, 4):uint()
|
|
431
|
+
subtree:add(f_length, buffer(8, 4))
|
|
432
|
+
|
|
433
|
+
if length > 0 then
|
|
434
|
+
subtree:add(f_payload, buffer(12, length))
|
|
435
|
+
end
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
-- Register for TCP port
|
|
439
|
+
local tcp_table = DissectorTable.get("tcp.port")
|
|
440
|
+
tcp_table:add(8888, proto)
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
## Active Testing
|
|
444
|
+
|
|
445
|
+
### Fuzzing with Boofuzz
|
|
446
|
+
|
|
447
|
+
```python
|
|
448
|
+
from boofuzz import *
|
|
449
|
+
|
|
450
|
+
def main():
|
|
451
|
+
session = Session(
|
|
452
|
+
target=Target(
|
|
453
|
+
connection=TCPSocketConnection("target", 8888)
|
|
454
|
+
)
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
# Define protocol structure
|
|
458
|
+
s_initialize("HELLO")
|
|
459
|
+
s_static(b"\x50\x52\x4f\x54") # Magic
|
|
460
|
+
s_word(1, name="version") # Version
|
|
461
|
+
s_word(0x01, name="type") # Type (HELLO)
|
|
462
|
+
s_size("payload", length=4) # Length field
|
|
463
|
+
s_block_start("payload")
|
|
464
|
+
s_dword(0x12345678, name="client_id")
|
|
465
|
+
s_word(0, name="flags")
|
|
466
|
+
s_block_end()
|
|
467
|
+
|
|
468
|
+
session.connect(s_get("HELLO"))
|
|
469
|
+
session.fuzz()
|
|
470
|
+
|
|
471
|
+
if __name__ == "__main__":
|
|
472
|
+
main()
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
### Replay and Modification
|
|
476
|
+
|
|
477
|
+
```python
|
|
478
|
+
from scapy.all import *
|
|
479
|
+
|
|
480
|
+
# Replay captured traffic
|
|
481
|
+
packets = rdpcap("capture.pcap")
|
|
482
|
+
for pkt in packets:
|
|
483
|
+
if pkt.haslayer(TCP) and pkt[TCP].dport == 8888:
|
|
484
|
+
send(pkt)
|
|
485
|
+
|
|
486
|
+
# Modify and replay
|
|
487
|
+
for pkt in packets:
|
|
488
|
+
if pkt.haslayer(Raw):
|
|
489
|
+
# Modify payload
|
|
490
|
+
original = pkt[Raw].load
|
|
491
|
+
modified = original.replace(b"client", b"CLIENT")
|
|
492
|
+
pkt[Raw].load = modified
|
|
493
|
+
# Recalculate checksums
|
|
494
|
+
del pkt[IP].chksum
|
|
495
|
+
del pkt[TCP].chksum
|
|
496
|
+
send(pkt)
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
## Best Practices
|
|
500
|
+
|
|
501
|
+
### Analysis Workflow
|
|
502
|
+
|
|
503
|
+
1. **Capture traffic**: Multiple sessions, different scenarios
|
|
504
|
+
2. **Identify boundaries**: Message start/end markers
|
|
505
|
+
3. **Map structure**: Fixed header, variable payload
|
|
506
|
+
4. **Identify fields**: Compare multiple samples
|
|
507
|
+
5. **Document format**: Create specification
|
|
508
|
+
6. **Validate understanding**: Implement parser/generator
|
|
509
|
+
7. **Test edge cases**: Fuzzing, boundary conditions
|
|
510
|
+
|
|
511
|
+
### Common Patterns to Look For
|
|
512
|
+
|
|
513
|
+
- Magic numbers/signatures at message start
|
|
514
|
+
- Version fields for compatibility
|
|
515
|
+
- Length fields (often before variable data)
|
|
516
|
+
- Type/opcode fields for message identification
|
|
517
|
+
- Sequence numbers for ordering
|
|
518
|
+
- Checksums/CRCs for integrity
|
|
519
|
+
- Timestamps for timing
|
|
520
|
+
- Session/connection identifiers
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sast-configuration
|
|
3
|
+
description: Configure Static Application Security Testing (SAST) tools for automated vulnerability detection in application code. Use when setting up security scanning, implementing DevSecOps practices, or automating code vulnerability detection.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# SAST Configuration
|
|
7
|
+
|
|
8
|
+
Static Application Security Testing (SAST) tool setup, configuration, and custom rule creation for comprehensive security scanning across multiple programming languages.
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
This skill provides comprehensive guidance for setting up and configuring SAST tools including Semgrep, SonarQube, and CodeQL. Use this skill when you need to:
|
|
13
|
+
|
|
14
|
+
- Set up SAST scanning in CI/CD pipelines
|
|
15
|
+
- Create custom security rules for your codebase
|
|
16
|
+
- Configure quality gates and compliance policies
|
|
17
|
+
- Optimize scan performance and reduce false positives
|
|
18
|
+
- Integrate multiple SAST tools for defense-in-depth
|
|
19
|
+
|
|
20
|
+
## Core Capabilities
|
|
21
|
+
|
|
22
|
+
### 1. Semgrep Configuration
|
|
23
|
+
|
|
24
|
+
- Custom rule creation with pattern matching
|
|
25
|
+
- Language-specific security rules (Python, JavaScript, Go, Java, etc.)
|
|
26
|
+
- CI/CD integration (GitHub Actions, GitLab CI, Jenkins)
|
|
27
|
+
- False positive tuning and rule optimization
|
|
28
|
+
- Organizational policy enforcement
|
|
29
|
+
|
|
30
|
+
### 2. SonarQube Setup
|
|
31
|
+
|
|
32
|
+
- Quality gate configuration
|
|
33
|
+
- Security hotspot analysis
|
|
34
|
+
- Code coverage and technical debt tracking
|
|
35
|
+
- Custom quality profiles for languages
|
|
36
|
+
- Enterprise integration with LDAP/SAML
|
|
37
|
+
|
|
38
|
+
### 3. CodeQL Analysis
|
|
39
|
+
|
|
40
|
+
- GitHub Advanced Security integration
|
|
41
|
+
- Custom query development
|
|
42
|
+
- Vulnerability variant analysis
|
|
43
|
+
- Security research workflows
|
|
44
|
+
- SARIF result processing
|
|
45
|
+
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
### Initial Assessment
|
|
49
|
+
|
|
50
|
+
1. Identify primary programming languages in your codebase
|
|
51
|
+
2. Determine compliance requirements (PCI-DSS, SOC 2, etc.)
|
|
52
|
+
3. Choose SAST tool based on language support and integration needs
|
|
53
|
+
4. Review baseline scan to understand current security posture
|
|
54
|
+
|
|
55
|
+
### Basic Setup
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Semgrep quick start
|
|
59
|
+
pip install semgrep
|
|
60
|
+
semgrep --config=auto --error
|
|
61
|
+
|
|
62
|
+
# SonarQube with Docker
|
|
63
|
+
docker run -d --name sonarqube -p 9000:9000 sonarqube:latest
|
|
64
|
+
|
|
65
|
+
# CodeQL CLI setup
|
|
66
|
+
gh extension install github/gh-codeql
|
|
67
|
+
codeql database create mydb --language=python
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Integration Patterns
|
|
71
|
+
|
|
72
|
+
### CI/CD Pipeline Integration
|
|
73
|
+
|
|
74
|
+
```yaml
|
|
75
|
+
# GitHub Actions example
|
|
76
|
+
- name: Run Semgrep
|
|
77
|
+
uses: returntocorp/semgrep-action@v1
|
|
78
|
+
with:
|
|
79
|
+
config: >-
|
|
80
|
+
p/security-audit
|
|
81
|
+
p/owasp-top-ten
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Pre-commit Hook
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# .pre-commit-config.yaml
|
|
88
|
+
- repo: https://github.com/returntocorp/semgrep
|
|
89
|
+
rev: v1.45.0
|
|
90
|
+
hooks:
|
|
91
|
+
- id: semgrep
|
|
92
|
+
args: ['--config=auto', '--error']
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Best Practices
|
|
96
|
+
|
|
97
|
+
1. **Start with Baseline**
|
|
98
|
+
- Run initial scan to establish security baseline
|
|
99
|
+
- Prioritize critical and high severity findings
|
|
100
|
+
- Create remediation roadmap
|
|
101
|
+
|
|
102
|
+
2. **Incremental Adoption**
|
|
103
|
+
- Begin with security-focused rules
|
|
104
|
+
- Gradually add code quality rules
|
|
105
|
+
- Implement blocking only for critical issues
|
|
106
|
+
|
|
107
|
+
3. **False Positive Management**
|
|
108
|
+
- Document legitimate suppressions
|
|
109
|
+
- Create allow lists for known safe patterns
|
|
110
|
+
- Regularly review suppressed findings
|
|
111
|
+
|
|
112
|
+
4. **Performance Optimization**
|
|
113
|
+
- Exclude test files and generated code
|
|
114
|
+
- Use incremental scanning for large codebases
|
|
115
|
+
- Cache scan results in CI/CD
|
|
116
|
+
|
|
117
|
+
5. **Team Enablement**
|
|
118
|
+
- Provide security training for developers
|
|
119
|
+
- Create internal documentation for common patterns
|
|
120
|
+
- Establish security champions program
|
|
121
|
+
|
|
122
|
+
## Common Use Cases
|
|
123
|
+
|
|
124
|
+
### New Project Setup
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
./scripts/run-sast.sh --setup --language python --tools semgrep,sonarqube
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Custom Rule Development
|
|
131
|
+
|
|
132
|
+
```yaml
|
|
133
|
+
# See references/semgrep-rules.md for detailed examples
|
|
134
|
+
rules:
|
|
135
|
+
- id: hardcoded-jwt-secret
|
|
136
|
+
pattern: jwt.encode($DATA, "...", ...)
|
|
137
|
+
message: JWT secret should not be hardcoded
|
|
138
|
+
severity: ERROR
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Compliance Scanning
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
# PCI-DSS focused scan
|
|
145
|
+
semgrep --config p/pci-dss --json -o pci-scan-results.json
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Troubleshooting
|
|
149
|
+
|
|
150
|
+
### High False Positive Rate
|
|
151
|
+
|
|
152
|
+
- Review and tune rule sensitivity
|
|
153
|
+
- Add path filters to exclude test files
|
|
154
|
+
- Use nostmt metadata for noisy patterns
|
|
155
|
+
- Create organization-specific rule exceptions
|
|
156
|
+
|
|
157
|
+
### Performance Issues
|
|
158
|
+
|
|
159
|
+
- Enable incremental scanning
|
|
160
|
+
- Parallelize scans across modules
|
|
161
|
+
- Optimize rule patterns for efficiency
|
|
162
|
+
- Cache dependencies and scan results
|
|
163
|
+
|
|
164
|
+
### Integration Failures
|
|
165
|
+
|
|
166
|
+
- Verify API tokens and credentials
|
|
167
|
+
- Check network connectivity and proxy settings
|
|
168
|
+
- Review SARIF output format compatibility
|
|
169
|
+
- Validate CI/CD runner permissions
|
|
170
|
+
|
|
171
|
+
## Tool Comparison
|
|
172
|
+
|
|
173
|
+
| Tool | Best For | Language Support | Cost | Integration |
|
|
174
|
+
| --------- | ------------------------ | ---------------- | --------------- | ------------- |
|
|
175
|
+
| Semgrep | Custom rules, fast scans | 30+ languages | Free/Enterprise | Excellent |
|
|
176
|
+
| SonarQube | Code quality + security | 25+ languages | Free/Commercial | Good |
|
|
177
|
+
| CodeQL | Deep analysis, research | 10+ languages | Free (OSS) | GitHub native |
|
|
178
|
+
|
|
179
|
+
## Related Skills
|
|
180
|
+
|
|
181
|
+
- `security` - For general security practices
|
|
182
|
+
- `security-auditor` - For security auditing
|