详解APK静态分析引擎`quark-engine`的5大功能
1. 引入
2020年8月,在DEFCON 28大会上(参考3),发布了一个开源的"Android malware analysis engine",名字叫quark-engine
(参考1)。这是台湾“財團法人電信技術中心”(参考2)开发的一个工具。该项目的开发者列表见参考7,目前主要活跃的开发者(负责人)是JunWei Song(参考3,参考5)。
这个APK静态分析引擎,有以下几个特点:
- scoring system,能直接给出恶意度得分
- neglect certain cases of obfuscation,对特定的一些混淆有抗混淆能力
- 方便使用,windows和linux平台都兼容。目前是基于androguard实现的
本文在windows上安装quark-engine并进行测试,给出测试结果。因为笔者动手测试时,还未见有类似的中文相关资料,所以记录下来供参考。
2. 安装
安装系统为64位的 windows 10 。
- 用conda新建虚拟python3.8环境
conda create --name env_quark_py38 python=3.8
- 安装quark-engine
pip install -U quark-engine
- 安装graphviz
- 在https://graphviz.org/download/,下载 stable_windows_10_cmake_Release_x64_graphviz-install-2.46.1-win64.exe
- 双击exe安装
- 运行命令 :
conda install -c anaconda graphviz
至此,quark-engine安装完毕,安装过程非常简单。
3. 功能1:给出apk分析概述报告
用一条命令,就可以给出summary report
quark -a xxx.apk -s
-s,就是summary的缩写,命令运行后,结果如下(考虑篇幅有限,这里只给出部分结果示例):
[!] WARNING: Moderate Risk
[*] Total Score: 153
+---------------------------------------------------------------------------+------------+-------+--------+
| Rule | Confidence | Score | Weight |
+---------------------------------------------------------------------------+------------+-------+--------+
| Initialize bitmap object and compress data (e.g. JPEG) into bitmap object | 60% | 1 | 0.25 |
| Open the camera and take picture | 20% | 1 | 0.0625 |
| Put the compressed bitmap data into JSON object | 60% | 1 | 0.25 |
| Get filename and put it to JSON object | 60% | 1 | 0.25 |
| Get absolute path of file and put it to JSON object | 60% | 1 | 0.25 |
| Scheduling recording task | 40% | 1 | 0.125 |
| Use absolute path of directory for the output media file path | 40% | 1 | 0.125 |
| Check if successfully sending out SMS | 40% | 1 | 0.125 |
| Put data in cursor to JSON object | 60% | 1 | 0.25 |
| Read sensitive data(SMS, CALLLOG) and put it into JSON object | 60% | 1 | 0.25 |
| Query data from URI (SMS, CALLLOGS) | 100% | 1 | 1.0 |
| Read data and put it into a buffer stream | 100% | 1 | 1.0 |
| Read file and put it into a stream | 60% | 1 | 0.25 |
| Read file into a stream and put it into a JSON object | 60% | 1 | 0.25 |
| Put buffer stream (data) to JSON object | 40% | 1 | 0.125 |
| Get location info of the device and put it to JSON object | 100% | 1 | 1.0 |
| Get Location of the device and append this info to a string | 100% | 1 | 1.0 |
| Get JSON object prepared and fill in location info | 60% | 1 | 0.25 |
输入命令到得出结果,大概用了20秒,可以说是静态分析中比较快的了。
这条命令能给出的结果有
- Risk的等级,比如这里是"Moderate Risk"
- Risk得分,比如这里是 153
- 匹配上的各条rule,以及 Confidence 和 这条规则的权重Weight
4. 功能2:给出apk分析详细报告(静态规则匹配)
用一条命令,就可以给出summary report
quark -a xxx.apk -d
-d,就是detail的缩写,命令运行后,结果如下(考虑篇幅有限,这里只给出部分结果示例):
C:\xxx/.quark-engine/quark-rules\00017.jsonConfidence: 100%[✓]1.Permission Request[✓]2.Native API Usage(Landroid/location/Location;, getLatitude)(Ljava/lang/StringBuilder;, append)[✓]3.Native API Combination(Landroid/location/Location;, getLatitude)(Ljava/lang/StringBuilder;, append)[✓]4.Native API SequenceSequence show up in:Lorg/wikipedia/util/GeoUtil; sendGeoIntent (Landroid/app/Activity; Landroid/location/Location; Ljava/lang/String;)V[✓]5.Native API Use Same ParameterLorg/wikipedia/util/GeoUtil; sendGeoIntent (Landroid/app/Activity; Landroid/location/Location; Ljava/lang/String;)V
[+] DONE: OK
这条命令,会根据参考4中的quark-rules,去做静态匹配。比如这里匹配到100%的满足规则00017.json
,而这条规则的内容如下:
{"crime": "Get Location of the device and append this info to a string","x1_permission": [],"x2n3n4_comb": [{"class": "Landroid/location/Location;","method": "getLatitude","descriptor": "()D"},{"class": "Ljava/lang/StringBuilder;","method": "append","descriptor": "(D)Ljava/lang/StringBuilder;"}],"yscore": 1,"label": ["location","collection"]
}
各条json规则中,给出了详细的
- API定义
- 规则含义:“Get Location of the device and append this info to a string”
- 规则的权重:yscore,行为越恶意,则yscore值越高(通过SMS泄露地理位置的yscore是4)
这条规则定义的是静态获取location的行为。
这条命令跑完需要1分钟左右。
5. 功能3:给出静态行为对应的代码位置
用一条命令,就可以给出各个静态行为,及其在DEX中的具体代码位置(借助JEB进行进一步分析)。
quark -a xxx.apk -s -c
命令运行后,结果如下(考虑篇幅有限,这里只给出部分结果示例):
+-------------------+--------------------------------------------------------+
| Parent Function | Lnet/hockeyapp/android/PaintActivity;determineFilename |
+-------------------+--------------------------------------------------------+
| Crime Description | * Read sensitive data(SMS, CALLLOG, etc) |
+-------------------+--------------------------------------------------------+
可以得到各个行为对应到DEX代码中的具体位置。这个功能也是各个静态分析工具的必备功能(常用功能)。
6. 功能4:画出CFG图
用一条命令,就可以画出call graph
quark -a xxx.apk -s -g
-g,就是graph的缩写,命令运行后,会生成一个call_graph_image
文件夹,其中给出了各个CFG的png图片,这里给出一个示例:
[PIC-1]
png图片的文件名,也指定了这个CFG对应的行为,比如 sendGeoIntent_getLatitude_append.png。
7. 功能5:python支持
能直接在python代码里调用quark-engine进行分析,并获取分解结果,示例步骤如下:
- pip安装quark-engine
pip install -U quark-engine==21.3.2
- 下载quark-rules
下载地址见参考4,下载后保存到本地文件夹。
这里有个小坑,笔者已经提了issue(参考8),但只要按照本文的版本安装进行测试,就不会遇到这个问题了。
- 使用如下py代码
from quark.report import ReportAPK_PATH = "xxx.apk"
RULE_PATH = "quark-rules-master/"report = Report()'''
RULE_PATH can be a directory with multiple rules inside
EX: "rules/"
OR special json rule file, such as "sendLocation_SMS.json"
'''
report.analysis(APK_PATH, RULE_PATH)
json_report = report.get_report("json")
print(json_report)
得到的分析结果如下:
{'md5': 'xxx','apk_filename': 'xxx.apk','size_bytes': 22842706,'threat_level': 'Moderate Risk','total_score': 153,'crimes': [{'crime': 'Initialize bitmap object and compress data (e.g. JPEG) into bitmap object','score': 1,'weight': 0.25,'confidence': '60%','permissions': [],'native_api': [{'class': 'Landroid/graphics/BitmapFactory;','method': 'decodeByteArray'}, {'class': 'Landroid/graphics/Bitmap;','method': 'compress'}],'combination': [{'class': 'Landroid/graphics/BitmapFactory;','method': 'decodeByteArray','descriptor': '([B I I)Landroid/graphics/Bitmap;'}, {'class': 'Landroid/graphics/Bitmap;','method': 'compress','descriptor': '(Landroid/graphics/Bitmap$CompressFormat; I Ljava/io/OutputStream;)Z'}],'sequence': [],'register': []}, {'crime': 'Open the camera and take picture','score': 1,'weight': 0.0625,'confidence': '20%','permissions': [],'native_api': [],'combination': [],'sequence': [],'register': []}, {'crime': 'Put the compressed bitmap data into JSON object','score': 1,'weight': 0.25,'confidence': '60%','permissions': [],'native_api': [{'class': 'Landroid/graphics/Bitmap;','method': 'compress'}, {'class': 'Lorg/json/JSONObject;','method': 'put'}],'combination': [{'class': 'Landroid/graphics/Bitmap;','method': 'compress','descriptor': '(Landroid/graphics/Bitmap$CompressFormat; I Ljava/io/OutputStream;)Z'}, {'class': 'Lorg/json/JSONObject;','method': 'put','descriptor': '(Ljava/lang/String; Z)Lorg/json/JSONObject;'}],'sequence': [],'register': []}, {'crime': 'Send binary data over HTTP','score': 1,'weight': 0,'confidence': '0%','permissions': [],'native_api': [],'combination': [],'sequence': [],'register': []}]
}
能很清晰的看到它的结果,方便用python做批量测试。关于这个python包更具体的用法,见参考6。
8. 参考
- https://github.com/quark-engine/quark-engine
- https://www.ttc.org.tw/mobile/index.php?apps=news&action=more&id=367
- https://forum.defcon.org/node/234086
- https://github.com/quark-engine/quark-rules
- https://krnick.github.io/about/
- https://quark-engine.readthedocs.io/en/latest/integration.html
- https://quark-engine.readthedocs.io/en/latest/contribution.html
- https://github.com/quark-engine/quark-engine/issues/145
详解APK静态分析引擎`quark-engine`的5大功能相关推荐
- Android系列教程之七:EditText使用详解-包含很多教程上看不到的功能演示
写道 标题有点大,说是详解,其实就是对EditText的一些常用功能的介绍,包括密码框,电话框,空白提示文字等等的讲解,尽量的介绍详细一点,也就是所谓的详解了..呵呵 广告一下我的应用"我团 ...
- mysql 设置 server id_详解Mysql存储引擎
1.libmysql相关API介绍 MYSQL *mysql_init(MYSQL *mysql) 函数功能:分配或初始化MYSQL对象,若mysql是NULL,将分配,初始化,并返回新对象.否则,直 ...
- php配合jade使用,详解基于模板引擎Jade的应用
本文小编就为大家分享一篇基于模板引擎Jade的应用详解,具有很好的参考价值,希望对大家有所帮助.一起跟随小编过来看看吧,希望能帮助到大家. 有用的符号: | 竖杠后的字符会被原样输出 · 点表示下一级 ...
- java 8 新功能详解_Java 8和Java 14之间的新功能
java 8 新功能详解 从版本9开始,Java每6个月就有一次新功能,因此很难跟踪这些新更改. 互联网上的大多数信息都描述了最近2个Java版本之间的变化. 但是,如果您的情况与我相似,则说明您使用 ...
- 合成大西瓜漏洞作弊详解,教你如何生成三个大西瓜
网红游戏合成大西瓜漏洞作弊详解,教你如何生成轻松三个大西瓜 声明 先决条件 打开chrome 打开chrome开发者工具 打开src目录下的 project.js文件 点击左下角花括号,优化显示格式 ...
- php读音量大小,Android_Android中实时获取音量分贝值详解,基础知识
度量声音强度,大 - phpStudy...
Android中实时获取音量分贝值详解 基础知识 度量声音强度,大家最熟悉的单位就是分贝(decibel,缩写为dB).这是一个无纲量的相对单位,计算公式如下: 分子是测量值的声压,分母是参考值的声压 ...
- mysql的存储引擎详解_Mysql存储引擎详解
存储引擎的介绍 关系型数据库表是用来存储和组织信息的数据结构,可以将表理解为由行和列组成的表格. 由于表的类型不同,我们在实际开发过程中,就有可能需要各种各样的表,不同的表就意味着存储不同类型的数据, ...
- 深入详解Apk编译打包流程
前言 身为一个Android开发,一定要了解apk编译打包流程; 那么今天我们就来学习下; apk的编译流程 1.apk文件 apk是Android Package的缩写; 解压apk文件后包含And ...
- mysql 储存引擎_详解mysql存储引擎的标准
浅谈选择mysql存储引擎的标准 主要存储引擎的介绍 1.InnoDB存储引擎 InnoDB是MySQL的默认事务型引擎,它被设计用来处理大量的短期(short-lived)事务.除非有非常特别的原因 ...
最新文章
- 科学计算机程序 字表处理软件都是,计算机应用基础知识_计算机应用基础试题及答案【最新资料】.doc...
- JavaScript规范和工具 JSlint
- 欢迎来怼---作业要求 20171015 beta冲刺贡献分分配规则
- app把信息添加到mysql_如何将数据库表中的数据添加到ListView C#Xamarin Android App
- Spring 3.1和Hibernate的持久层
- angular7.2构建包如何兼容ie_Python 小技巧:如何实现操作系统兼容性打包?
- 解决python中TypeError: not enough arguments for format string
- ssis导入xml_SSIS XML目标
- 手机怎么用java9_java9_java9官方版 32位64位 最新版_天天下载手机版
- 组态软件mcgs入库mysql_昆仑通态专题(四):MCGS嵌入版组态软件的数据报表
- C语言求cidr,点分十进制子网掩码与CIDR相互转换详解
- Android屏幕、坐标系、Padding、Margin
- logistic回归详解
- Java是什么,Java是什么意思
- 全部重点排污企业名录(整理成Excel更新至2021年)
- 个人使用华为云服务器的经验分享
- 用户计算机名更改为英文,win10将用户名改为英文怎么改_win10如何更改用户名为英文图文教程-系统城...
- frame组件+pack()来布局定位组件,实例讲解
- 轻流整体调研-v 1.0
- launch4j使用