Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: cuckoobox/cuckoo
base: 6b6a854b12
...
head fork: cuckoobox/cuckoo
compare: 12d07fa03f
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
1  docs/AUTHORS
@@ -17,6 +17,7 @@ CONTRIBUTORS:
Thorsten Sick
Adam Pridgen
Mike Tu
+Loic Jaquemet
BUG REPORTERS/ADVISORS:
Giacomo Milani
View
2  lib/cuckoo/core/guest.py
@@ -103,7 +103,7 @@ def start_analysis(self, options):
self.server.add_malware(data, options["file_name"])
self.server.execute()
- except socket.timeout:
+ except (socket.timeout, socket.error):
raise CuckooGuestError("%s: guest communication timeout, check networking or try to increase timeout" % self.id)
def wait_for_completion(self):
View
35 lib/cuckoo/core/scheduler.py
@@ -24,6 +24,8 @@
mmanager = None
machine_lock = Lock()
+db_lock = Lock()
+
class AnalysisManager(Thread):
"""Analysis manager thread."""
@@ -158,11 +160,13 @@ def launch_analysis(self):
os.remove(self.task.file_path)
except OSError as e:
log.error("Unable to delete original file at path \"%s\": %s" % (self.task.file_path, e))
-
- # Stop machine
- mmanager.stop(vm.label)
- # Release the machine from lock
- mmanager.release(vm.label)
+ try:
+ # Stop machine
+ mmanager.stop(vm.label)
+ # Release the machine from lock
+ mmanager.release(vm.label)
+ except CuckooMachineError as e:
+ log.error("Unable to release vm %s, reason %s. You have to fix it manually" % (vm.label, e))
# Check analysis file size to avoid memory leaks.
try:
@@ -182,9 +186,6 @@ def run(self):
"""Run manager thread."""
success = True
- db = Database()
- db.lock(self.task.id)
-
try:
self.launch_analysis()
except CuckooMachineError as e:
@@ -194,7 +195,7 @@ def run(self):
log.error(e)
success = False
finally:
- db.complete(self.task.id, success)
+ Database().complete(self.task.id, success)
class Scheduler:
"""Task scheduler."""
@@ -252,13 +253,17 @@ def start(self):
if mmanager.availables() == 0:
#log.debug("No machines available, try again")
continue
-
+ db_lock.acquire()
task = self.db.fetch()
- if not task:
+ if task:
+ self.db.lock(task.id)
+ db_lock.release()
+ # Go with analysis.
+ analysis = AnalysisManager(task)
+ analysis.daemon = True
+ analysis.start()
+ else:
#log.debug("No pending tasks, try again")
- continue
+ db_lock.release()
- analysis = AnalysisManager(task)
- analysis.daemon = True
- analysis.start()
View
42 modules/machinemanagers/virtualbox.py
@@ -22,6 +22,8 @@ class VirtualBox(MachineManager):
SAVED = "saved"
RUNNING = "running"
POWEROFF = "poweroff"
+ ABORTED = "aborted"
+ ERROR = "machete"
def _initialize_check(self):
"""Runs all checks when a machine manager is initialized.
@@ -73,14 +75,19 @@ def stop(self, label):
@raise CuckooMachineError: if unable to stop.
"""
log.debug("Stopping vm %s" % label)
- try:
- if subprocess.call([self.options.virtualbox.path, "controlvm", label, "poweroff"],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE):
- raise CuckooMachineError("VBoxManage exited with error powering off the machine")
- except OSError as e:
- raise CuckooMachineError("VBoxManage failed powering off the machine: %s" % e)
- self._wait_status(label, self.POWEROFF)
+
+ status = self._status(label)
+ if status == self.POWEROFF or status == self.ABORTED:
+ log.debug("Trying to stop an already stopped vm %s" % label)
+ else:
+ try:
+ if subprocess.call([self.options.virtualbox.path, "controlvm", label, "poweroff"],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE):
+ log.debug("VBoxManage exited with error powering off the machine")
+ except OSError as e:
+ raise CuckooMachineError("VBoxManage failed powering off the machine: %s" % e)
+ self._wait_status(label, self.POWEROFF)
def _list(self):
"""Lists virtual machines installed.
@@ -111,7 +118,6 @@ def _status(self, label):
"""Gets current status of a vm.
@param label: virtual machine name.
@return: status string.
- @raise CuckooMachineError: if unable to enumerate status.
"""
log.debug("Getting status for %s"% label)
try:
@@ -124,31 +130,39 @@ def _status(self, label):
output, err = proc.communicate()
if proc.returncode != 0:
- raise CuckooMachineError("VBoxManage returns error checking status for machine %s: %s"
+ # It's quite common for virtualbox crap utility to exit with:
+ # VBoxManage: error: Details: code E_ACCESSDENIED (0x80070005)
+ # So we just log to debug this.
+ log.debug("VBoxManage returns error checking status for machine %s: %s"
% (label, err))
+ return self.ERROR
except OSError as e:
- raise CuckooMachineError("VBoxManage failed to check status for machine %s: %s"
+ log.warning("VBoxManage failed to check status for machine %s: %s"
% (label, e))
+ return self.ERROR
for line in output.split("\n"):
state = re.match(r"VMState=\"(\w+)\"", line, re.M|re.I)
if state:
status = state.group(1)
log.debug("Machine %s status %s" % (label, status))
- return status
+ return status.lower()
raise CuckooMachineError("Unable to get status for %s" % label)
def _wait_status(self, label, state):
"""Waits for a vm status.
@param label: virtual machine name.
- @param state: virutal machine status.
+ @param state: virtual machine status.
@raise CuckooMachineError: if default waiting timeout expire.
"""
+ # This block was originally suggested by Loic Jaquemet.
waitme = 0
- while state != self._status(label):
+ current = self._status(label)
+ while state != current and current != self.ERROR:
log.debug("Waiting %i cuckooseconds for vm %s to switch to status %s" % (waitme, label, state))
if waitme > int(self.options.virtualbox.timeout):
self.stop(label)
raise CuckooMachineError("Waiting too much for vm %s status change. Stopping vm and aborting" % label)
time.sleep(1)
waitme += 1
+ current = self._status(label)
View
18 modules/machinemanagers/vmware.py
@@ -1,17 +1,7 @@
-# Copyright (C) 2012 Mike Tu (@mt00at)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# Copyright (C) 2010-2012 Cuckoo Sandbox Developers.
+# This file was originally produced by Mike Tu.
+# This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org
+# See the file 'docs/LICENSE' for copying permission.
import logging
import subprocess

No commit comments for this range

Something went wrong with that request. Please try again.