请问有人能指导我如何在Cuckoo Sandbox处理模块中添加更多模块/分析脚本吗?如果网络上有任何文章,请分享。
谢谢
根据文档:
分析包是Cuckoo Sandbox的核心组件之一。它们由结构化的Python类组成,当在客户机上执行时,描述了Cuckoo的分析器组件应该如何进行分析。
因此,分析包负责执行所需的操作以处理文件。
示例(在Windows客户机上)
"C:\\WINDOWS\\system32\\rundll32.exe"
执行一个dll因此,您编写一个分析包来告诉cuckoo如何打开或执行文件。一个处理模块用于处理文件并提取报告信息(报告模块)。
如果您想执行静态分析,您不需要编写分析包而是处理模块。如果您想添加新的行为分析,您需要同时实现两者。# simple_module.py
from lib.cuckoo.common.abstracts import Processing
class SimpleModule(Processing): # A class inheriting Processing.
def run(self): # A run() function
self.key = "simple_info" # The name that will have the returned data in the global container.
data = "This is the data returned by simple_module."
return data # A set of data (list, dictionary or string etc.) that will be appended to the global container.
# under the key secified in `self.key`.
有几个模块类别,如果您查看cuckoo的目录层次结构,您会发现一个名为modules
的目录和一些子目录:
signature
的含义有不同的理解)。您需要关心的目录是:processing。在那里,您将放置您的新模块。
向conf/processing.conf
文件添加以下类似的部分:
[simple_module]
enabled = yes
在分析原始结果经过处理模块并生成全局容器(参见处理模块)后,Cuckoo会将其传递给所有可用的报告模块,这些模块将对其进行一些处理,并以不同的格式使其可访问和可消费。
是的!我们需要其他模块才能够查看新处理模块的输出。最简单的方法是将结果记录到文件中:
您可以查看报告模块文档,其中会有以下示例:
让我们为我们的处理模块simple_module实现一个报告:
# simple_report.py
import os
from lib.cuckoo.common.abstracts import Report
from lib.cuckoo.common.exceptions import CuckooReportError
class SimpleReport(Report):
def run(self, results): # IMPORTANT!! Here the parameter result will be the Global Container we saw before
try:
report = open(os.path.join(self.reports_path, "simple_report.txt"), "w")
report.write(results["simple_info"]) # We add our information to the Global Container under the key: simple_info
# now we are querying that info to write it down to a file.
report.close()
except (TypeError, IOError) as e:
raise CuckooReportError("Failed to make a simple report, :(")
您还需要启用此报告模块:
每个模块都应该在文件conf/reporting.conf中有一个专门的部分,例如如果您创建了一个名为module/reporting/foobar.py的模块,则必须将以下部分添加到conf/reporting.conf中
[simple_report]
enabled = on
storage/analyses/<analysis-number>/reports
文件夹中找到一个名为“simple_report.txt”的文件。
嗯...这有点复杂。如果您查看文件modules/reporting/reporthtml.py
,您会发现一个名为ReportHtml
的类,在某些时候它会有以下代码:
try:
tpl = env.get_template("report.html") # Ahhhh, so cuckoo is using a template for this.
html = tpl.render({"results": results}) # Look, the template receives the Global Container (this dude again!!!, it must be a VIP).
except Exception as e:
raise CuckooReportError("Failed to generate HTML report: %s" % e)
try:
with codecs.open(os.path.join(self.reports_path, "report.html"), "w", encoding="utf-8") as report:
report.write(html)
except (TypeError, IOError) as e:
raise CuckooReportError("Failed to write HTML report: %s" % e)
web/templates/analysis
,您可以在那里找到report.html
。阅读该文件,您会注意到两个重要的代码块:<ul class="nav nav-tabs">
<li class="active"><a href="#overview" data-toggle="tab">Quick Overview</a></li>
<li><a href="#static" data-toggle="tab">Static Analysis</a></li>
{% if analysis.behavior.processes %}<li><a href="#behavior" data-toggle="tab" id="graph_hook">Behavioral Analysis</a></li>{% endif %}
<li><a href="#network" data-toggle="tab">Network Analysis</a></li>
<li><a href="#dropped" data-toggle="tab">Dropped Files</a></li>
{% if analysis.procmemory %}<li><a href="#procmemory" data-toggle="tab">Process Memory</a></li>{% endif %}
{% if analysis.memory %}<li><a href="#memory" data-toggle="tab">Memory Analysis</a></li>{% endif %}
<li><a href="#admin" data-toggle="tab">Admin</a></li>
</ul>
我会在下面提供相关的编程代码(为了简洁起见,一些代码被省略):
<div class="tab-content">
<div class="tab-pane fade in active" id="overview">
{% include "analysis/overview/index.html" %}
</div>
<div class="tab-pane fade" id="static">
{% include "analysis/static/index.html" %}
</div>
{% if analysis.behavior.processes %}
<div class="tab-pane fade" id="behavior">
{% include "analysis/behavior/index.html" %}
</div>
{% endif %}
...
...
</div>
好的,很明显,我们需要添加我们的模板,让我们继续:
1- 创建一个文件,web/templates/analysis/simple_module/index.html
{{analysis.simple_info}}
analysis
指向字典Global Results的根。而simple info是由我们的process模块simple_module添加到该字典中的键。{{analysis.simple_info}}
。还请参见The Django template language: for Python programmers。web/templates/analysis/report.html
以包含您的模板。<li class="active"><a href="#simple_module" data-toggle="tab">Simple Module</a></li>
<div class="tab-pane fade" id="simple_module">
{% include "analysis/simple_module/index.html" %}
</div>
而且...变戏法...
#analizer.py
...
# If no analysis package was specified at submission, we try to select
# one automatically.
if not self.config.package:
log.debug("No analysis package specified, trying to detect "
"it automagically.")
...
Nika: 脚本将在客户端或主机上执行?
我想你指的是“访客”而不是“客户端”。
脚本是在访客中“执行”的,如果您查看agent.py
的代码,您会看到类似于以下内容:
from SimpleXMLRPCServer import SimpleXMLRPCServer
def add_analyzer(self, data):
"""Add analyzer.
@param data: analyzer data.
@return: operation status.
"""
data = data.data
if not self._initialize():
return False
try:
zip_data = StringIO()
zip_data.write(data)
with ZipFile(zip_data, "r") as archive:
archive.extractall(ANALYZER_FOLDER)
finally:
zip_data.close()
self.analyzer_path = os.path.join(ANALYZER_FOLDER, "analyzer.py")
return True
def execute(self):
"""Execute analysis.
@return: analyzer PID.
"""
global ERROR_MESSAGE
global CURRENT_STATUS
if not self.analyzer_path or not os.path.exists(self.analyzer_path):
return False
try:
proc = subprocess.Popen([sys.executable, self.analyzer_path],
cwd=os.path.dirname(self.analyzer_path))
self.analyzer_pid = proc.pid
except OSError as e:
ERROR_MESSAGE = str(e)
return False
self.dropped_path
中的文件,对其进行处理并将信息添加到全局容器中。