Skip to content

Commit 252b64e

Browse files
authored
rewamp htmlreport and bootstrap5 (kevoreilly#2784)
1 parent 557ac1f commit 252b64e

File tree

189 files changed

+81314
-8998
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+81314
-8998
lines changed

SKILLS.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# CAPE Sandbox Developer Skills & Architecture Guide
2+
3+
This document outlines the architectural structure, core concepts, and development patterns for the CAPE Sandbox (v2). It serves as a guide for extending functionality, debugging, and maintaining the codebase.
4+
5+
## 1. Project Overview
6+
CAPE (Config And Payload Extraction) is a malware analysis sandbox derived from Cuckoo Sandbox. It focuses on automated malware analysis with a specific emphasis on extracting payloads and configuration from malware.
7+
8+
**Core Tech Stack:**
9+
- **Language:** Python 3
10+
- **Web Framework:** Django
11+
- **Database:** PostgreSQL (SQLAlchemy) for task management, MongoDB/Elasticsearch for results storage.
12+
- **Virtualization:** KVM/QEMU (preferred), VirtualBox, VMWare.
13+
- **Frontend:** HTML5, Bootstrap, Jinja2 Templates.
14+
15+
## 2. Directory Structure Key
16+
| Directory | Purpose |
17+
| :--- | :--- |
18+
| `agent/` | Python script (`agent.py`) running *inside* the Guest VM to handle communication. |
19+
| `analyzer/` | Core analysis components running *inside* the Guest VM (monitor, analyzers). |
20+
| `conf/` | Configuration files (`cuckoo.conf`, `reporting.conf`, `web.conf`, etc.). |
21+
| `data/` | Static assets, yara rules, monitor binaries, and HTML templates (`data/html`). |
22+
| `lib/cuckoo/` | Core logic (Scheduler, Database, Guest Manager, Result Processor). |
23+
| `modules/` | Pluggable components (Signatures, Processing, Reporting, Auxiliary). |
24+
| `web/` | Django-based web interface (Views, URLs, Templates). |
25+
| `utils/` | Standalone CLI utilities (`process.py`, `cleaners.py`, `rooter.py`). |
26+
27+
## 3. Core Workflows
28+
29+
### A. The Analysis Lifecycle
30+
1. **Submission:** User submits file/URL via WebUI (`web/submission/`) or API (`web/api/`).
31+
2. **Scheduling:** Task is added to SQL DB. `lib/cuckoo/core/scheduler.py` picks it up.
32+
3. **Execution:**
33+
* VM is restored/started.
34+
* `analyzer` is uploaded to VM.
35+
* Sample is injected/executed.
36+
* Behavior is monitored via API hooking (CAPE Monitor).
37+
4. **Result Collection:** Logs, PCAP, and dropped files are transferred back to Host.
38+
5. **Processing:** `modules/processing/` parses raw logs into a structured dictionary.
39+
6. **Signatures:** `modules/signatures/` runs logic against the processed data.
40+
7. **Reporting:** `modules/reporting/` exports data (JSON, HTML, MongoDB, MAEC).
41+
42+
### B. Web Interface Architecture
43+
The Web UI is split into two distinct rendering logic paths:
44+
1. **Django Views (`web/analysis/views.py`):** Handles URL routing, authentication, and context generation. It fetches data from MongoDB/Elasticsearch.
45+
2. **Jinja2 Templates:**
46+
* **Web Templates (`web/templates/`):** Standard Django templates for the UI.
47+
* **Report Templates (`data/html/`):** Standalone Jinja2 templates used by the `reporthtml` module to generate static HTML reports. *Note: Changes here affect the downloadable HTML report, not necessarily the Web UI.*
48+
49+
## 4. Development Guides
50+
51+
### How to Add a Detection Signature
52+
Signatures live in `modules/signatures/`.
53+
```python
54+
from lib.cuckoo.common.abstracts import Signature
55+
56+
class MyMalware(Signature):
57+
name = "my_malware_behavior"
58+
description = "Detects specific bad behavior"
59+
severity = 3
60+
categories = ["trojan"]
61+
authors = ["You"]
62+
63+
def on_call(self, call, process):
64+
# Inspect individual API calls
65+
if call["api"] == "CreateFileW" and "evil.exe" in call["arguments"]["filepath"]:
66+
return True
67+
```
68+
69+
### How to Add a Processing Module
70+
Processing modules (`modules/processing/`) run after analysis to extract specific data (e.g., Static analysis of a file).
71+
```python
72+
from lib.cuckoo.common.abstracts import Processing
73+
74+
class MyExtractor(Processing):
75+
def run(self):
76+
self.key = "my_data" # Key in the final report JSON
77+
result = {}
78+
# ... logic ...
79+
return result
80+
```
81+
82+
### How to Modify the Web Report
83+
1. **Locate the Template:** Look in `web/templates/analysis/`.
84+
* `overview/index.html`: Main dashboard.
85+
* `overview/_info.html`: General details.
86+
* `overview/_summary.html`: Behavioral summary.
87+
2. **Edit:** Use Django template language (`{% if %}`, `{{ variable }}`).
88+
3. **Context:** Data is usually passed as `analysis` object. Access fields like `analysis.info.id`, `analysis.network`, `analysis.behavior`.
89+
90+
## 5. Troubleshooting & Debugging
91+
92+
### Common Issues
93+
* **"Waiting for container":** Usually a network configuration issue in `conf/cuckoo.conf` or `conf/auxiliary.conf`.
94+
* **Report Empty:** Check `reporting.conf`. If using MongoDB, ensure `mongodb` is enabled.
95+
* **Template Errors:** Use `{% if variable %}` guards aggressively. Missing keys in MongoDB documents cause Jinja2 crashes.
96+
97+
### Important Commands
98+
* `poetry run python cuckoo.py -d`: Run CAPE in debug mode (verbose logs).
99+
* `poetry run python utils/process.py -r <task_id>`: Re-run processing and reporting for a specific task without restarting the VM.
100+
* `poetry run python utils/cleaners.py --clean`: Wipe all tasks and reset the DB.
101+
102+
### Database Querying (MongoDB)
103+
CAPE stores unstructured analysis results in the `analysis` collection.
104+
```bash
105+
mongo cuckoo
106+
db.analysis.find({"info.id": 123}, {"behavior.summary": 1}).pretty()
107+
```
108+
109+
## 6. Best Practices
110+
1. **Conditionally Render:** Always check if a dictionary key exists in templates before rendering to avoid UI breaks on different analysis types (Static vs Dynamic).
111+
2. **Keep Views Light:** Perform heavy data crunching in `modules/processing`, not in Django views.
112+
3. **Modular CSS/JS:** Keep custom styles in `web/static/` rather than inline in templates when possible.

changelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
### [16.01.2026] CAPE v2.5
2+
* Bootstrap 5 upgrade and some visual WEBGUI rewamp. Some improvements still might come soon!
3+
* htmlreport - rewamp!
4+
* cape2.sh - Libvirt + YARA python libraries install without external scripts.
5+
* Datatime UTC normalization on tasks/VMs changes.
6+
* Added check on startup for enable firewall.
7+
* Volatility3 - more modules added. Test them and let us know if you have any issue.
8+
* Filedescripts leaks fixed.
9+
* Stucked VM monitoring and kill. [PR](https://github.com/kevoreilly/CAPEv2/pull/2809)
10+
11+
PS no changes required to CAPA library to support CAPE v2.5 ;)
12+
113
### [02.01.2026]
214
* CAPE installer:
315
* now support custom destination folder env variable:

conf/default/integrations.conf.default

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ hwp = no
1414
# Number of workers for pool to run them in parallel
1515
max_workers = 6
1616

17-
[mandiant_intel]
18-
enabled = no
19-
api_access =
20-
api_secret =
21-
2217
# Create your apikey: https://threatfox.abuse.ch/api/#auth_key
2318
# MalwareBazaar uses this key too
2419
[abusech]

conf/default/memory.conf.default

Lines changed: 148 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,80 +10,76 @@ delete_memdump = no
1010
# Delete memory dump in the event of a volatility exception
1111
delete_memdump_on_exception = no
1212

13+
# Masks. Data that should not be logged
14+
# Just get this information from your plain VM Snapshot (without running malware)
15+
# This will filter out unwanted information in the logs
16+
[mask]
17+
enabled = no
18+
pid_generic =
19+
20+
1321
# List of available modules
1422
# enabled: enable this module
1523
# filter: use filters to remove benign system data from the logs
1624
# Filters are defined in the mask section at below
1725

1826
# Scans for hidden/injected code and dlls
19-
# http://code.google.com/p/volatility/wiki/CommandReferenceMal23#malfind
2027
[malfind]
2128
enabled = no
2229
filter = on
2330

2431
# Lists official processes. Does not detect hidden processes
25-
# https://github.com/volatilityfoundation/volatility/wiki/Command-Reference#pslist
2632
[pslist]
2733
enabled = no
2834
filter = off
2935

3036
# Process listing in tree form. Does not detect hidden processes (Don't work currently in CAPE)
31-
# https://github.com/volatilityfoundation/volatility/wiki/Command-Reference#pstree
3237
[pstree]
3338
enabled = no
3439
filter = off
3540

3641
# Lists hidden processes. Enumerate processes in the Kernel memory using pool tag scanning _POOL_HEADER
37-
# https://github.com/volatilityfoundation/volatility/wiki/Command-Reference#psscan
3842
[psscan]
3943
enabled = no
4044
filter = off
4145

4246

4347
# Show callbacks
44-
# http://code.google.com/p/volatility/wiki/CommandReferenceMal23#callbacks
4548
[callbacks]
4649
enabled = no
4750
filter = off
4851

4952
# Show sids
50-
# http://code.google.com/p/volatility/wiki/CommandReference23#getsids
5153
[getsids]
5254
enabled = no
5355
filter = off
5456

5557
# Show privileges
56-
# http://code.google.com/p/volatility/wiki/CommandReference23#privs
5758
[privs]
5859
enabled = no
5960
filter = off
6061

6162
# Display processes' loaded DLLs- Does not display hidden DLLs
62-
# http://code.google.com/p/volatility/wiki/CommandReference23#dlllist
6363
[dlllist]
6464
enabled = no
6565
filter = on
6666

6767
# List open handles of processes
68-
# http://code.google.com/p/volatility/wiki/CommandReference23#handles
6968
[handles]
7069
enabled = no
7170
filter = on
7271

7372
# Scan for Mutexes (whole system)
74-
# http://code.google.com/p/volatility/wiki/CommandReference23#mutantscan
7573
[mutantscan]
7674
enabled = no
7775
filter = on
7876

7977
# Scan for services
80-
# http://code.google.com/p/volatility/wiki/CommandReferenceMal23#svcscan
8178
[svcscan]
8279
enabled = no
8380
filter = on
8481

8582
# Scan for kernel drivers (includes hidden, unloaded)
86-
# http://code.google.com/p/volatility/wiki/CommandReference23#modscan
8783
[modscan]
8884
enabled = no
8985
filter = on
@@ -106,9 +102,144 @@ filter = off
106102
enabled = no
107103
filter = off
108104

109-
# Masks. Data that should not be logged
110-
# Just get this information from your plain VM Snapshot (without running malware)
111-
# This will filter out unwanted information in the logs
112-
[mask]
105+
# Not tested module below
106+
107+
[info]
113108
enabled = no
114-
pid_generic =
109+
filter = off
110+
111+
[psxview]
112+
enabled = no
113+
filter = off
114+
115+
[ldrmodules]
116+
enabled = no
117+
filter = off
118+
119+
[cmdline]
120+
enabled = no
121+
filter = off
122+
123+
[envars]
124+
enabled = no
125+
filter = off
126+
127+
[modules]
128+
enabled = no
129+
filter = off
130+
131+
[driverscan]
132+
enabled = no
133+
filter = off
134+
135+
[driverirp]
136+
enabled = no
137+
filter = off
138+
139+
[verinfo]
140+
enabled = no
141+
filter = off
142+
143+
[filescan]
144+
enabled = no
145+
filter = off
146+
147+
[vadinfo]
148+
enabled = no
149+
filter = off
150+
151+
[timers]
152+
enabled = no
153+
filter = off
154+
155+
[hivelist]
156+
enabled = no
157+
filter = off
158+
159+
[hashdump]
160+
enabled = no
161+
filter = off
162+
163+
[lsadump]
164+
enabled = no
165+
filter = off
166+
167+
[cachedump]
168+
enabled = no
169+
filter = off
170+
171+
[symlinkscan]
172+
enabled = no
173+
filter = off
174+
175+
[thrdscan]
176+
enabled = no
177+
filter = off
178+
179+
[hollowprocesses]
180+
enabled = no
181+
filter = off
182+
183+
[processghosting]
184+
enabled = no
185+
filter = off
186+
187+
[suspiciousthreads]
188+
enabled = no
189+
filter = off
190+
191+
[devicetree]
192+
enabled = no
193+
filter = off
194+
195+
[consoles]
196+
enabled = no
197+
filter = off
198+
199+
[cmdscan]
200+
enabled = no
201+
filter = off
202+
203+
[amcache]
204+
enabled = no
205+
filter = off
206+
207+
[shimcache]
208+
enabled = no
209+
filter = off
210+
211+
[userassist]
212+
enabled = no
213+
filter = off
214+
215+
[unloadedmodules]
216+
enabled = no
217+
filter = off
218+
219+
[iat]
220+
enabled = no
221+
filter = off
222+
223+
[skeletonkey]
224+
enabled = no
225+
filter = off
226+
227+
[unhookedsyscalls]
228+
enabled = no
229+
filter = off
230+
231+
[etwpatch]
232+
enabled = no
233+
filter = off
234+
235+
[mftscan]
236+
enabled = no
237+
filter = off
238+
239+
[svclist]
240+
enabled = no
241+
filter = off
242+
243+
[svcdiff]
244+
enabled = no
245+
filter = off

0 commit comments

Comments
 (0)