Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/cuckoobox/cuckoo int…
Browse files Browse the repository at this point in the history
…o development
  • Loading branch information
jekil committed May 18, 2012
2 parents 1ab56ed + abe0932 commit 8b38142
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
4 changes: 3 additions & 1 deletion analyzer/windows/lib/core/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ def choose_package(file_type):
return "pdf"
elif "Rich Text Format" in file_type:
return "doc"
elif "Microsoft Excel" in file_type:
return "xls"
else:
return None
return None
18 changes: 18 additions & 0 deletions analyzer/windows/packages/xls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from lib.common.abstracts import Package
from lib.api.process import Process

class XLS(Package):
def run(self, path):
arg = "\"%s\"" % path
p = Process()
p.execute(path="C:\\Program Files\\Microsoft Office\\Office12\\EXCEL.EXE", args=arg, suspended=True)
p.inject()
p.resume()

return p.pid

def check(self):
return True

def finish(self):
return True
36 changes: 22 additions & 14 deletions lib/cuckoo/core/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
import shutil
import logging
from multiprocessing import Process
from threading import Thread, Lock

from lib.cuckoo.common.exceptions import CuckooAnalysisError, CuckooMachineError
from lib.cuckoo.common.abstracts import Dictionary, MachineManager
Expand All @@ -18,14 +18,14 @@
log = logging.getLogger(__name__)

mmanager = None
machine_lock = Lock()

class AnalysisManager(Process):
class AnalysisManager(Thread):
def __init__(self, task):
Process.__init__(self)
Process.daemon = True
Thread.__init__(self)
Thread.daemon = True
self.task = task
self.cfg = Config()
self.db = Database()
self.analysis = Dictionary()

def init_storage(self):
Expand Down Expand Up @@ -78,12 +78,14 @@ def launch_analysis(self):
raise CuckooAnalysisError("The file to analyze does not exist at path \"%s\", analysis aborted" % self.task.file_path)

while True:
machine_lock.acquire()
vm = mmanager.acquire(label=self.task.machine, platform=self.task.platform)
machine_lock.release()
if not vm:
log.debug("No machine available")
time.sleep(1)
else:
log.info("Acquired machine %s" % vm.label)
log.info("Acquired machine %s (Label: %s)" % (vm.id, vm.label))
break

self.init_storage()
Expand All @@ -94,36 +96,42 @@ def launch_analysis(self):
sniffer = Sniffer(self.cfg.cuckoo.tcpdump)
sniffer.start(interface=self.cfg.cuckoo.interface, host=vm.ip, file_path=os.path.join(self.analysis.results_folder, "dump.pcap"))
# Start machine
mmanager.start(vm.label)
try:
mmanager.start(vm.label)
except CuckooMachineError as e:
raise CuckooAnalysisError(e.message)
# Initialize guest manager
guest = GuestManager(vm.ip, vm.platform)
# Launch analysis
guest.start_analysis(options)
# Wait for analysis to complete
guest.wait_for_completion()
success = guest.wait_for_completion()
# Stop sniffer
sniffer.stop()
if not success:
raise CuckooAnalysisError("Analysis failed, review previous errors")
# Save results
guest.save_results(self.analysis.results_folder)
# Stop machine
#mmanager.stop(vm.label)
mmanager.stop(vm.label)
# Release the machine from lock
#mmanager.release(vm.label)
# Stop sniffer
sniffer.stop()
mmanager.release(vm.label)
# Launch reports generation
Reporter(self.analysis.results_folder).run(Processor(self.analysis.results_folder).run())

def run(self):
success = True

self.db.lock(self.task.id)
db = Database()
db.lock(self.task.id)

try:
self.launch_analysis()
except CuckooAnalysisError as e:
log.error(e.message)
success = False
finally:
self.db.complete(self.task.id, success)
db.complete(self.task.id, success)

class Scheduler:
def __init__(self):
Expand Down

0 comments on commit 8b38142

Please sign in to comment.