Table of Contents
- [fortify 环境]
- [fortify 测试和验证]
- [对DroidBench进行测试]
- [fortify扫描过程]
- [fortify扫描结果梳理]
- [扫描规则]
- [污点分析部分]
- [fortify总结]
fortify 环境
竟然有 [Fortify SCA 20.1.1]
解压安装
复制 fortify-common-20.1.1.0007.jar 到 C:\Program Files\Fortify\Fortify_SCA_and_Apps_20.1.1\Core\lib
如果要更新本地规则,复制 ExternalMetadata, rules 到 C:\Program Files\Fortify\Fortify_SCA_and_Apps_20.1.1\Core\config
至此就可以正常使用了
fortify 测试和验证
对FlowDroid扫描,该框架核心代码倒是没有任何结果
/FlowDroid/soot-infoflow/securiBench/securibench/micro 目录下的测试样例倒是都扫描出来了,都是一些WEB程序漏洞
Cross-Site Scripting: Reflected 120
Race Condition: Singleton Member Field 12
SQL Injection 6
Open Redirect 4
Path Manipulation 4
Password Management: Hardcoded Password 3
说明该框架确实还是可以
找下其他程序,看下能不能产生污点分析的扫描结果
对DroidBench进行测试
Android Bad Practices: Missing Google Play Services Updated Security Provider 120
Privilege Management: Unnecessary Permission 61
Privilege Management: Android Messaging 50
Android Bad Practices: Missing Component Permission 18
Dynamic Code Evaluation: Unsafe Deserialization 18
Privilege Management: Android Location 8
Privacy Violation 4
Password Management: Hardcoded Password 3
Privilege Management: Android Data Storage 3
Android Bad Practices: Unnecessary Component Exposure 2
Key Management: Hardcoded Encryption Key 1
Privilege Management: Android Network 1
Privilege Management: Missing Intent Permission 1
结果涉及到了除了权限管理部分,比较有价值的是隐私泄露和不安全的反序列化部分
fortify扫描过程
.\sourceanalyzer.exe -b mybuild test.java
.\sourceanalyzer.exe -b mybuild -scan -f ./result.fpr
构建(将源码转成中间语法树nst) -> 加载检测规则(加密bin文件) -> 分析 -> 生成报告
构建过程可以通过 -b 参数指定 build_id,将一个或多个文件关联起来
fortify扫描结果梳理
对fortify扫描结果进行梳理,暂时出现的包括:
SQL注入
XSS跨站脚本
Access Control: Database(数据越权):查询语句未指定所属角色
Path Manipulation(路径篡改):非法字符引起的路径穿越问题
XML External Entity Injection(XML实体注入): 配置不当导致读取外部实体
Open Redirect(开放式重定向):URL后接非信任的重定向链接
Dynamic Code Evaluation: Code Injection(动态脚本注入):通过类似exec等函数动态加载非法命令
Password Management Hardcoded Password(密码硬编码)
Privacy Violation(隐私泄露):如将密码相关信息打印到日志文件
Null Dereference(空指针异常):未对空指针进行检测
Log Forging(日志伪造): 输出的日志存在外部不可控的变量
Portability Flaw File Separator(文件分隔符):硬编码文件分隔符
Poor Error Handling Return Inside Finally: finally 块中的返回指令会导致从 try 块中抛出的异常丢失
Portability Flaw Locale Dependent Comparison: 由于区域不同导致字符串对应的编码区别
Denial of Service Regular Expression:可非法构造的正则表达式
Insecure Randomness(不安全随机数): 弱随机数带来的安全隐患
从扫描结果看下来,误报率有点高。。。
扫描规则
所有扫描规则存储为加密的bin格式,通过逆向分析,已编写解密工具,可以解密成xml文件
<./fortify规则解密工具>
污点分析部分
污点分析的格式说明:
<DataflowSourceRule formatVersion="3.2" language="java">
<MetaInfo>
<Group name="package">Java Android</Group>
<Group name="inputsource">Private Information</Group>
<Group name="audience">dev,medium,broad,fod,targeted</Group>
</MetaInfo>
<RuleID>76035444-7AB4-4F8D-A58A-EB581E48A482</RuleID>
<TaintFlags>+PRIVATE</TaintFlags>
<FunctionIdentifier>
<NamespaceName>
<Pattern>android\.telephony(\.gsm)?</Pattern>
</NamespaceName>
<ClassName>
<Value>SmsMessage</Value>
</ClassName>
<FunctionName>
<Pattern>getDisplayMessageBody|getDisplayOriginatingAddress|getEmailBody|getEmailFrom|getMessageBody|getOriginatingAddress|getPdu|getPseudoSubject|getServiceCenterAddress|getUserData</Pattern>
</FunctionName>
<ApplyTo implements="true" overrides="true" extends="true"/>
</FunctionIdentifier>
<OutArguments>return</OutArguments>
</DataflowSourceRule>
<DataflowSinkRule formatVersion="3.2" language="java">
<MetaInfo>
<Group name="package">Java Android</Group>
...
<Group name="audience">broad</Group>
</MetaInfo>
<RuleID>E366BF7B-BC55-47D3-A87A-D6AA4052B93F</RuleID>
<VulnKingdom>Input Validation and Representation</VulnKingdom>
<VulnCategory>Setting Manipulation</VulnCategory>
<DefaultSeverity>3.0</DefaultSeverity>
<Description ref="desc.dataflow.java.setting_manipulation"/>
<Sink>
<InArguments>2</InArguments>
<Conditional>
<Not>
<TaintFlagSet taintFlag="VALIDATED_SETTING_MANIPULATION"/>
</Not>
</Conditional>
</Sink>
<FunctionIdentifier>
<NamespaceName>
<Value>android.provider</Value>
</NamespaceName>
<ClassName>
<Pattern>Settings(\.|\$)(Global|Secure|System)</Pattern>
</ClassName>
<FunctionName>
<Pattern>put(Float|Int|Long|String)|setLocationProviderEnabled</Pattern>
</FunctionName>
<ApplyTo implements="true" overrides="true" extends="true"/>
</FunctionIdentifier>
</DataflowSinkRule>
字段根据名称即可立即,其中定义的污点分析规则的两部分,
DataflowSourceRule: 污点源规则
示例中的 android.telephony.gsm.SmsMessage 类中的函数 getDisplayMessageBody 等,都是污点的来源
DataflowSinkRule: 污染点规则
示例中的 android.provider.Settings.Global(或Secure或System) 类中的函数 put 等中的第二个输入参数,都是被污染点
分析结果会将中间存在的传播路径给绘制出来
fortify总结
优点:扫描规则大而全,效率还挺高,后续增加规则也算方便
缺点:代码不开源,无法进行二次开发,误报率高,减小误报率要进行大量的规则添加工作