-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCuckooClient.java
More file actions
59 lines (48 loc) · 2.03 KB
/
CuckooClient.java
File metadata and controls
59 lines (48 loc) · 2.03 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
package com.malware;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.util.Properties;
public class CuckooClient {
private String apiUrl;
private String apiKey;
public CuckooClient() {
Properties properties = new Properties();
try {
properties.load(getClass().getClassLoader().getResourceAsStream("config.properties"));
this.apiUrl = properties.getProperty("cuckoo.api.url");
this.apiKey = properties.getProperty("cuckoo.api.key");
} catch (IOException e) {
e.printStackTrace();
}
}
public String submitSample(String filePath) throws IOException {
CloseableHttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(apiUrl + "/tasks/create/file");
// Set headers
post.setHeader("Authorization", "Bearer " + apiKey);
post.setHeader("Content-Type", "application/json");
// Set the body
String json = "{\"file\": \"" + filePath + "\"}";
post.setEntity(new StringEntity(json));
// Execute the request
CloseableHttpResponse response = client.execute(post);
String result = EntityUtils.toString(response.getEntity());
client.close();
return result;
}
public String getTaskReport(int taskId) throws IOException {
CloseableHttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(apiUrl + "/tasks/view/" + taskId);
post.setHeader("Authorization", "Bearer " + apiKey);
post.setHeader("Content-Type", "application/json");
CloseableHttpResponse response = client.execute(post);
String result = EntityUtils.toString(response.getEntity());
client.close();
return result;
}
}