本文整理汇总了Python中lib.cuckoo.common.utils.TimeoutServer.get_status方法的典型用法代码示例。如果您正苦于以下问题:Python TimeoutServer.get_status方法的具体用法?Python TimeoutServer.get_status怎么用?Python TimeoutServer.get_status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.cuckoo.common.utils.TimeoutServer
的用法示例。
在下文中一共展示了TimeoutServer.get_status方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _status
# 需要导入模块: from lib.cuckoo.common.utils import TimeoutServer [as 别名]
# 或者: from lib.cuckoo.common.utils.TimeoutServer import get_status [as 别名]
def _status(self, label):
"""Gets current status of a physical machine.
@param label: physical machine name.
@return: status string.
"""
# For physical machines, the agent can either be contacted or not.
# However, there is some information to be garnered from potential
# exceptions.
log.debug("Getting status for machine: %s.", label)
machine = self._get_machine(label)
# The status is only used to determine whether the Guest is running
# or whether it is in a stopped status, therefore the timeout can most
# likely be fairly arbitrary. TODO This is a temporary fix as it is
# not compatible with the new Cuckoo Agent, but it will have to do.
url = "http://{0}:{1}".format(machine.ip, CUCKOO_GUEST_PORT)
server = TimeoutServer(url, allow_none=True, timeout=60)
try:
status = server.get_status()
except xmlrpclib.Fault as e:
# Contacted Agent, but it threw an error.
log.debug("Agent error: %s (%s) (Error: %s).",
machine.id, machine.ip, e)
return self.ERROR
except socket.error as e:
# Could not contact agent.
log.debug("Agent unresponsive: %s (%s) (Error: %s).",
machine.id, machine.ip, e)
return self.STOPPED
except Exception as e:
# TODO Handle this better.
log.debug("Received unknown exception: %s.", e)
return self.ERROR
# If the agent responded successfully, then the physical machine
# is running
if status:
return self.RUNNING
return self.ERROR
示例2: OldGuestManager
# 需要导入模块: from lib.cuckoo.common.utils import TimeoutServer [as 别名]
# 或者: from lib.cuckoo.common.utils.TimeoutServer import get_status [as 别名]
class OldGuestManager(object):
"""Old and deprecated Guest Manager.
This class handles the communications with the old agent running in the
virtual machine.
"""
def __init__(self, vm_id, ip, platform, task_id):
"""@param ip: guest's IP address.
@param platform: guest's operating system type.
"""
self.id = vm_id
self.ip = ip
self.platform = platform
self.task_id = task_id
self.cfg = Config()
# initialized in start_analysis so we can update the critical timeout
# TODO, pull options parameter into __init__ so we can do this here
self.timeout = None
self.server = None
def wait(self, status):
"""Waiting for status.
@param status: status.
@return: always True.
"""
log.debug("%s: waiting for status 0x%.04x", self.id, status)
end = time.time() + self.timeout
self.server._set_timeout(self.timeout)
while db.guest_get_status(self.task_id) == "starting":
# Check if we've passed the timeout.
if time.time() > end:
raise CuckooGuestError("{0}: the guest initialization hit the "
"critical timeout, analysis "
"aborted.".format(self.id))
try:
# If the server returns the given status, break the loop
# and return.
if self.server.get_status() == status:
log.debug("%s: status ready", self.id)
break
except:
pass
log.debug("%s: not ready yet", self.id)
time.sleep(1)
self.server._set_timeout(None)
return True
def upload_analyzer(self, monitor):
"""Upload analyzer to guest.
@return: operation status.
"""
zip_data = analyzer_zipfile(self.platform, monitor)
log.debug(
"Uploading analyzer to guest (id=%s, ip=%s, monitor=%s, size=%d)",
self.id, self.ip, monitor, len(zip_data))
# Send the zip containing the analyzer to the agent running inside
# the guest.
try:
self.server.add_analyzer(xmlrpclib.Binary(zip_data))
except socket.timeout:
raise CuckooGuestError("{0}: guest communication timeout: unable "
"to upload agent, check networking or try "
"to increase timeout".format(self.id))
def start_analysis(self, options, monitor):
"""Start analysis.
@param options: options.
@return: operation status.
"""
# TODO Deal with unicode URLs, should probably try URL encoding.
# Unicode files are being taken care of.
self.timeout = options["timeout"] + self.cfg.timeouts.critical
url = "http://{0}:{1}".format(self.ip, CUCKOO_GUEST_PORT)
self.server = TimeoutServer(url, allow_none=True, timeout=self.timeout)
try:
# Wait for the agent to respond. This is done to check the
# availability of the agent and verify that it's ready to receive
# data.
self.wait(CUCKOO_GUEST_INIT)
# Invoke the upload of the analyzer to the guest.
self.upload_analyzer(monitor)
# Give the analysis options to the guest, so it can generate the
# analysis.conf inside the guest.
try:
self.server.add_config(options)
#.........这里部分代码省略.........
示例3: OldGuestManager
# 需要导入模块: from lib.cuckoo.common.utils import TimeoutServer [as 别名]
# 或者: from lib.cuckoo.common.utils.TimeoutServer import get_status [as 别名]
class OldGuestManager(object):
"""Old and deprecated Guest Manager.
This class handles the communications with the old agent running in the
virtual machine.
"""
def __init__(self, vm_id, ip, platform="windows"):
"""@param ip: guest's IP address.
@param platform: guest's operating system type.
"""
self.id = vm_id
self.ip = ip
self.platform = platform
self.cfg = Config()
self.timeout = self.cfg.timeouts.critical
url = "http://{0}:{1}".format(ip, CUCKOO_GUEST_PORT)
self.server = TimeoutServer(url, allow_none=True,
timeout=self.timeout)
def wait(self, status):
"""Waiting for status.
@param status: status.
@return: always True.
"""
log.debug("%s: waiting for status 0x%.04x", self.id, status)
end = time.time() + self.timeout
self.server._set_timeout(self.timeout)
while True:
# Check if we've passed the timeout.
if time.time() > end:
raise CuckooGuestError("{0}: the guest initialization hit the "
"critical timeout, analysis "
"aborted.".format(self.id))
try:
# If the server returns the given status, break the loop
# and return.
if self.server.get_status() == status:
log.debug("%s: status ready", self.id)
break
except:
pass
log.debug("%s: not ready yet", self.id)
time.sleep(1)
self.server._set_timeout(None)
return True
def upload_analyzer(self, hashes_path):
"""Upload analyzer to guest.
@return: operation status.
"""
zip_data = StringIO()
zip_file = ZipFile(zip_data, "w", ZIP_STORED)
# Select the proper analyzer's folder according to the operating
# system associated with the current machine.
root = os.path.join(CUCKOO_ROOT, "analyzer", self.platform)
root_len = len(os.path.abspath(root))
if not os.path.exists(root):
log.error("No valid analyzer found at path: %s", root)
return False
# Walk through everything inside the analyzer's folder and write
# them to the zip archive.
for root, dirs, files in os.walk(root):
archive_root = os.path.abspath(root)[root_len:]
for name in files:
path = os.path.join(root, name)
archive_name = os.path.join(archive_root, name)
zip_file.write(path, archive_name)
if hashes_path:
zip_file.write(hashes_path, "hashes.bin")
zip_file.close()
data = xmlrpclib.Binary(zip_data.getvalue())
zip_data.close()
log.debug("Uploading analyzer to guest (id=%s, ip=%s)",
self.id, self.ip)
# Send the zip containing the analyzer to the agent running inside
# the guest.
try:
self.server.add_analyzer(data)
except socket.timeout:
raise CuckooGuestError("{0}: guest communication timeout: unable "
"to upload agent, check networking or try "
"to increase timeout".format(self.id))
def start_analysis(self, options):
"""Start analysis.
#.........这里部分代码省略.........
示例4: __init__
# 需要导入模块: from lib.cuckoo.common.utils import TimeoutServer [as 别名]
# 或者: from lib.cuckoo.common.utils.TimeoutServer import get_status [as 别名]
class GuestManager:
"""Guest Mananager.
This class handles the communications with the agents running in the
machines.
"""
def __init__(self, vm_id, ip, platform="windows"):
"""@param ip: guest's IP address.
@param platform: guest's operating system type.
"""
self.id = vm_id
self.ip = ip
self.platform = platform
self.cfg = Config()
self.timeout = self.cfg.timeouts.critical
url = "http://{0}:{1}".format(ip, CUCKOO_GUEST_PORT)
self.server = TimeoutServer(url, allow_none=True,
timeout=self.timeout)
def wait(self, status):
"""Waiting for status.
@param status: status.
@return: always True.
"""
log.debug("%s: waiting for status 0x%.04x", self.id, status)
# Create an event that will invoke a function to stop the loop when
# the critical timeout is h it.
abort = Event()
abort.clear()
def die():
abort.set()
# Initialize the timer.
timer = Timer(self.timeout, die)
timer.start()
self.server._set_timeout(self.timeout)
while True:
# Check if the timer was hit and the abort event was set.
if abort.is_set():
raise CuckooGuestError("{0}: the guest initialization hit the "
"critical timeout, analysis "
"aborted".format(self.id))
try:
# If the server returns the given status, break the loop
# and return.
if self.server.get_status() == status:
log.debug("%s: status ready", self.id)
break
except:
pass
log.debug("%s: not ready yet", self.id)
time.sleep(1)
self.server._set_timeout(None)
return True
def upload_analyzer(self):
"""Upload analyzer to guest.
@return: operation status.
"""
zip_data = StringIO()
zip_file = ZipFile(zip_data, "w", ZIP_STORED)
# Select the proper analyzer's folder according to the operating
# system associated with the current machine.
root = os.path.join("analyzer", self.platform)
root_len = len(os.path.abspath(root))
if not os.path.exists(root):
log.error("No valid analyzer found at path: %s", root)
return False
# Walk through everything inside the analyzer's folder and write
# them to the zip archive.
for root, dirs, files in os.walk(root):
archive_root = os.path.abspath(root)[root_len:]
for name in files:
path = os.path.join(root, name)
archive_name = os.path.join(archive_root, name)
zip_file.write(path, archive_name)
zip_file.close()
data = xmlrpclib.Binary(zip_data.getvalue())
zip_data.close()
log.debug("Uploading analyzer to guest (id=%s, ip=%s)",
self.id, self.ip)
# Send the zip containing the analyzer to the agent running inside
# the guest.
try:
self.server.add_analyzer(data)
#.........这里部分代码省略.........
示例5: __init__
# 需要导入模块: from lib.cuckoo.common.utils import TimeoutServer [as 别名]
# 或者: from lib.cuckoo.common.utils.TimeoutServer import get_status [as 别名]
class GuestManager:
"""Guest Mananager.
This class handles the communications with the agents running in the
machines.
"""
def __init__(self, vm_id, ip, platform="windows"):
"""@param ip: guest's IP address.
@param platform: guest's operating system type.
"""
self.id = vm_id
self.ip = ip
self.platform = platform
self.cfg = Config()
self.timeout = self.cfg.timeouts.critical
url = "http://{0}:{1}".format(ip, CUCKOO_GUEST_PORT)
self.server = TimeoutServer(url, allow_none=True, timeout=self.timeout)
def wait(self, status):
"""Waiting for status.
@param status: status.
@return: always True.
"""
log.debug("%s: waiting for status 0x%.04x", self.id, status)
# Create an event that will invoke a function to stop the loop when
# the critical timeout is h it.
abort = Event()
abort.clear()
def die():
abort.set()
# Initialize the timer.
timer = Timer(self.timeout, die)
timer.start()
self.server._set_timeout(self.timeout)
while True:
# Check if the timer was hit and the abort event was set.
if abort.is_set():
raise CuckooGuestError(
"{0}: the guest initialization hit the " "critical timeout, analysis " "aborted".format(self.id)
)
try:
# If the server returns the given status, break the loop
# and return.
if self.server.get_status() == status:
log.debug("%s: status ready", self.id)
break
except:
pass
log.debug("%s: not ready yet", self.id)
time.sleep(1)
self.server._set_timeout(None)
return True
def upload_analyzer(self):
"""Upload analyzer to guest.
@return: operation status.
"""
zip_data = StringIO()
zip_file = ZipFile(zip_data, "w", ZIP_STORED)
# Select the proper analyzer's folder according to the operating
# system associated with the current machine.
root = os.path.join("analyzer", self.platform)
root_len = len(os.path.abspath(root))
if not os.path.exists(root):
log.error("No valid analyzer found at path: %s", root)
return False
# Walk through everything inside the analyzer's folder and write
# them to the zip archive.
for root, dirs, files in os.walk(root):
archive_root = os.path.abspath(root)[root_len:]
for name in files:
path = os.path.join(root, name)
archive_name = os.path.join(archive_root, name)
zip_file.write(path, archive_name)
zip_file.close()
data = xmlrpclib.Binary(zip_data.getvalue())
zip_data.close()
log.debug("Uploading analyzer to guest (id=%s, ip=%s)", self.id, self.ip)
# Send the zip containing the analyzer to the agent running inside
# the guest.
try:
self.server.add_analyzer(data)
except socket.timeout:
raise CuckooGuestError(
#.........这里部分代码省略.........