Created
August 1, 2013 21:39
-
-
Save turnersr/6135602 to your computer and use it in GitHub Desktop.
Code used to submit jobs to Cuckoobox via the REST API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pycurl | |
import cStringIO | |
import json | |
import urllib | |
from collections import defaultdict | |
from time import sleep | |
import glob as g | |
base_api_url = "http://localhost:8090/" | |
machines_list = "machines/list" | |
task_list = "tasks/list" | |
cmd_machine_list = base_api_url + machines_list | |
cmd_task_list = base_api_url + task_list | |
def insert_sample(file_loc): | |
command = "http://localhost:8090/tasks/create/file" | |
pf = [("file", (pycurl.FORM_FILE, file_loc))] | |
buf = cStringIO.StringIO() | |
c = pycurl.Curl() | |
c.setopt(c.URL, command) | |
c.setopt(c.WRITEFUNCTION, buf.write) | |
c.setopt(c.HTTPPOST, pf) | |
c.perform() | |
c.setopt(c.VERBOSE, 1) | |
json_data = buf.getvalue() | |
data = json.loads(json_data) | |
buf.close() | |
return data | |
def run_cmd(command): | |
buf = cStringIO.StringIO() | |
c = pycurl.Curl() | |
c.setopt(c.URL, command) | |
c.setopt(c.WRITEFUNCTION, buf.write) | |
c.perform() | |
json_data = buf.getvalue() | |
data = json.loads(json_data) | |
buf.close() | |
return data | |
def get_malware(dir_loc): | |
x = g.glob(dir_loc + "*.exe") | |
return x | |
def main_job_insert(files): | |
for x in files: | |
print "Inserting", x | |
r = insert_sample(x) | |
h = check_jobs() | |
def check_jobs(): | |
p = 1 | |
c = 0 | |
while (p): | |
p,sc = check_tasks() | |
sleep(60) | |
if c % 5 == 0: | |
print "Current State:", p, sc | |
c += 1 | |
return 1 | |
def check_tasks(): | |
task_list = run_cmd(cmd_task_list) | |
status_counter = defaultdict(int) | |
for t in task_list["tasks"]: | |
status_counter[t['status']] += 1 | |
#print status_counter | |
return status_counter['processing'] + status_counter['pending'], status_counter | |
main_dir = "/var/tmp" | |
m = get_malware(main_dir) | |
print len(m) | |
pres = main_job_insert(m) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment