Muh*_*lah 7 python testing analysis sandbox cuckoo
对于恶意软件动态恶意软件分析,我使用的是自动恶意软件分析 - Cuckoo Sandbox.现在我想添加新的模块来分析恶意软件.我研究过cuckoo sandbox的开发文档.但目前我无法在恶意软件/样本上添加自定义脚本进行静态分析.这里有 Python脚本.
任何人都可以指导我如何在布谷鸟沙箱处理模块中添加更多模块/分析脚本.如果他们是网上的任何文章,请分享.
谢谢
根据文件:
分析包是Cuckoo Sandbox的核心组件.它们包含结构化的Python类,当在客户机中执行时,它们描述了Cuckoo的分析器组件应该如何进行分析.
因此,分析包负责执行处理文件所需的操作.
示例(在Windows客户端)
"C:\\WINDOWS\\system32\\rundll32.exe"因此,您编写Analisys包以告诉杜鹃如何打开或执行文件.处理模块,用于处理文件并提取报告的信息(报告模块).
如果要执行静态分析,则无需编写Analisis包,而是编写处理模块.如果要添加新的行为分析,则需要实现这两者.
这个答案是关于写处理模块的,因为你的问题是关于静态分析.
我使用文档的最新版本.在文档中,我发现许多有用的东西,其他的东西(比如如何在html界面中显示模块报告)我在测试和错误过程中发现了自己并且破解了代码.
要成为处理模块,您的脚本必须满足一些要求.下面,您将看到这些要求是什么以及如何将它们组合在一起以获得处理模块.
分析完成后,Cuckoo将调用modules/processing /目录中的所有可用处理模块.然后将初始化并执行每个模块,并将返回的数据附加到我们称之为全局容器的数据结构 中.这个容器只是一个庞大的Python字典,它包含由定义的键排序的所有模块生成的所有抽象结果.
处理模块的结果数据将添加到全局容器中,这样其他模块(例如报告模块)就可以访问该信息.
一个基本的处理模块(让我们称之为simple_module)可能如下所示:
# 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`.
Run Code Online (Sandbox Code Playgroud)
有几个模块类别,如果你看一下cuckoo的目录层次结构,你会modules在一些目录中找到一个名为的目录:
signature).您需要关心的目录是:处理.在那里你将放置你的新模块.
在conf/processing.conf文件中添加如下所示的seccion :
[simple_module]
enabled = yes
Run Code Online (Sandbox Code Playgroud)
在分析处理模块处理和抽象原始结果并生成全局容器(参考处理模块)之后,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, :(")
Run Code Online (Sandbox Code Playgroud)
您还需要启用此报告模块:
每个模块还应该在文件conf/reporting.conf中有一个专用部分,例如,如果您创建模块模块/ reporting/foobar.py,则必须将以下部分附加到conf/reporting.conf
[simple_report]
enabled = on
Run Code Online (Sandbox Code Playgroud)
现在你运行一个新的分析,你将能够在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)
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
内容代码(为简洁起见省略了一些代码):
<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>
Run Code Online (Sandbox Code Playgroud)
好的,很明显,我们需要添加我们的模板,让我们继续:
1-创建一个文件, web/templates/analysis/simple_module/index.html
{{analysis.simple_info}}
Run Code Online (Sandbox Code Playgroud)
在上面的行中analysis指向字典全局结果的根.简单的信息是我们的处理模块simple_module添加到这种字典的关键.
这将取代{{analysis.simple_info}}我们在Global Conatiner中为该键设置的值.另请参阅Django模板语言:适用于Python程序员.
2-更新web/templates/analysis/report.html以包含模板
添加行
<li class="active"><a href="#simple_module" data-toggle="tab">Simple Module</a></li>
Run Code Online (Sandbox Code Playgroud)
到标签部分.以及内容部分的以下几行:
<div class="tab-pane fade" id="simple_module">
{% include "analysis/simple_module/index.html" %}
</div>
Run Code Online (Sandbox Code Playgroud)
并且...... Hocus Pocus ......

重要的是要注意,如果您只想以html格式显示结果,则不必实现报表模块,只需创建相应的模板并使用相应的变量即可.