Skip to content

Commit 154c6d5

Browse files
committed
Finalize all changes: Add helper dependencies and cleanup
1 parent c8dfd96 commit 154c6d5

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

Cargo.lock

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ reqwest = { version = "0.12.24", features = ["json", "multipart"] }
2626

2727
[dev-dependencies]
2828
codecov = "0.4.1"
29+
mockito = "1.7.1"

src/server.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn create_server() {
2626
Box::new(tools::malware::reconstruction::PeFixer),
2727
Box::new(tools::malware::iat::IatFixer),
2828
Box::new(tools::malware::unpacker::OepFinder),
29+
Box::new(tools::malware::sandbox_submit::CapeSubmitter),
2930
];
3031

3132
tracing::info!("Registered {} tools", tools.len());

src/tools/malware/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ pub mod disasm;
88
pub mod reconstruction;
99
pub mod iat;
1010
pub mod unpacker;
11+
pub mod sandbox_submit;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use anyhow::Result;
2+
use serde_json::Value;
3+
use crate::tools::Tool;
4+
use async_trait::async_trait;
5+
use crate::sandbox::cape::CapeClient;
6+
7+
pub struct CapeSubmitter;
8+
9+
#[async_trait]
10+
impl Tool for CapeSubmitter {
11+
fn name(&self) -> &str { "cape_submit" }
12+
fn description(&self) -> &str { "Submits a file to CAPEv2 sandbox for analysis. Args: file_path, base_url, machine (optional), timeout (optional)" }
13+
14+
async fn execute(&self, args: Value) -> Result<Value> {
15+
let file_path = args["file_path"].as_str().ok_or(anyhow::anyhow!("Missing file_path"))?;
16+
let base_url = args["base_url"].as_str().ok_or(anyhow::anyhow!("Missing base_url"))?;
17+
let machine = args["machine"].as_str();
18+
let timeout = args["timeout"].as_u64().unwrap_or(300); // 5 mins default
19+
20+
let client = CapeClient::new(base_url, ""); // Token support can be added if args provide it
21+
22+
tracing::info!("Submitting {} to CAPE at {}", file_path, base_url);
23+
let task_id = client.submit_file(file_path, machine).await?;
24+
25+
tracing::info!("File submitted. Task ID: {}. Waiting for analysis...", task_id);
26+
27+
// Wait logic
28+
match client.wait_for_analysis(task_id, timeout).await {
29+
Ok(status) => {
30+
tracing::info!("Analysis completed with status: {}", status);
31+
32+
// Fetch report
33+
let report = client.get_report(task_id).await?;
34+
35+
// Return a simplified summary or full report?
36+
// Full report is huge. Let's return the full JSON and let the Agent parse/filter.
37+
// But add our own metadata wrapper.
38+
Ok(serde_json::json!({
39+
"status": "analysis_finished",
40+
"task_id": task_id,
41+
"cape_status": status,
42+
"report": report
43+
}))
44+
},
45+
Err(e) => {
46+
Err(anyhow::anyhow!("Analysis timeout or failed: {}", e))
47+
}
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)