freeBuf
主站

分类

漏洞 工具 极客 Web安全 系统安全 网络安全 无线安全 设备/客户端安全 数据安全 安全管理 企业安全 工控安全

特色

头条 人物志 活动 视频 观点 招聘 报告 资讯 区块链安全 标准与合规 容器安全 公开课

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

使用Needle进行ios安全测试
2020-03-03 10:07:08


一、Needle介绍

测试iOS应用有时需要很多工具,每种工具都是针对特定需求而开发的,并且都具有完全不同的操作模式和语法。
Needle是一款iOS安全测试框架。它是一个开源模块化框架,旨在简化对iOS应用进行安全评估的整个过程。鉴于其模块化,Needle易于扩展,并且可以以python脚本的形式添加新模块。
Needle覆盖的测试领域包括:数据存储进程通信网络通信静态代码分析hook和二进制保护
相关链接
needle文档说明:https://github.com/FSecureLABS/needle

二、Needle安装

本次使用iphone5s系统为IOS10.3的越狱机器进行安装,并装有以下依赖项:

1、Cydia
2、OpenSSH
3、Apt 0.7 Strict
4、Needle Agent — server
5、Frida    #可选依赖项,某些Needle模块会使用
6、Clutch2  #可选依赖项,解密二进制应用程序的工具

安装Needle Agent

新版的Needle引入了一个由Objective-C编写的本机代理。Needle Agent是与Needle通信的iOS应用程序。
1、将以下存储库添加到Cydia源:
http://mobiletools.mwrinfosecurity.com/cydia/
https://build.frida.re
15829841365153.jpg


2、安装Needle AgentFridaClutch2

15829842252710.jpg


3、Needle Agent启动界面
15830664200898.jpg

PC端设置

Needle官方给出了macOSKali Linux的安装方法。当然也可以在Ubuntu上运行该工具。下面为macOS系统的安装过程。
1、首先获取Needle

git clone https://github.com/mwrlabs/needle.git

2、安装依赖项

brew install python
brew install libxml2
xcode-select --install

# 安装python packages
sudo -H pip install --upgrade --user readline
sudo -H pip install --upgrade --user paramiko
sudo -H pip install --upgrade --user sshtunnel
sudo -H pip install --upgrade --user frida
sudo -H pip install --upgrade --user biplist

# sshpass
brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb

# mitmproxy
wget https://github.com/mitmproxy/mitmproxy/releases/download/v0.17.1/mitmproxy-0.17.1-osx.tar.gz
tar -xvzf mitmproxy-0.17.1-osx.tar.gz
sudo cp mitmproxy-0.17.1-osx/mitm* /usr/local/bin/

三、Needle使用

启动Needle,可看到命令行界面如下:
15829868482601.jpg主要选项说明:

AGENT_PORT:设备上安装的NeedleAgent正在侦听的端口
APP:需要分析的app包名。如果不知道,可以先留空。
DEBUG:如果设置为True,将启用调试日志记录
HIDE_SYSTEM_APPS:如果设置为True,则仅显示第三方应用程序
USERNAME:测试设备的SSH用户名,默认为root
PASSWORD:测试设备的SSH密码,默认为alpine
AGENT_PORT:测试设备上安装的Needle Agent正在侦听的端口
SAVE_HISTORY:如果设置为True,则命令历史记录将在会话之间保留
VERBOSE:如果设置为True,将启用详细日志记录

Needle模块用法

使用show modules命令可列出框架中可用的模块。
15829884844742.jpg

search 用于搜索和查询匹配的模块
use 使用模块 
info 用于显示特定模块的详细信息
set 进行编辑
run 启动
show source 检查所选模块的实际源代码

以下为Needle常用模块的介绍:

use binary/info/checksums  #检测校验APP:MD5,SHA1,SHA224,SHA256,SHA384,SHA512
use binary/info/compilation_checks  #检测受保护的PIE,ARC,二进制文件
use binary/info/metadata  #显示应用程序数据(UUID,app名称、版本,捆绑软件名称、数据、目录、签名、体系结构等
use binary/info/provisioning_profile  #检测应用程序的配置文件,然后解析嵌入式证书
use binary/installation/install  #自动上传并在设备上安装IPA
use binary/info/pull_ipa  #从设备解密并提取应用程序的IPA 
use binary/reversing/class_dump_frida_enum-all-methods  #枚举应用程序中所有类的方法
use binary/reversing/class_dump_frida_enum-classes  #枚举可用的类
use binary/reversing/class_dump_frida_find-class-enum-methods  #查找指定的目标类并枚举其方法
use binary/reversing/shared_libraries  #列出应用程序使用的共享库
use binary/reversing/strings    #在砸壳后的应用程序资源中找到字符串
use comms/certs/delete_ca  #删除设备上安装的证书
use comms/certs/export_ca  #导出设备上安装的证书
use comms/certs/install_ca_burp  #在设备上安装Burp的CA证书
use comms/certs/install_ca_mitm  #在设备上安装MitmProxy的CA证书
use comms/proxy/pinning_bypass_frida  #Frida绕过证书绑定
use comms/proxy/proxy_regular  #拦截设备产生的流量
use device/dependency_installer  #检测安装依赖项
use dynamic/detection/jailbreak_detection#检测该APP能否在越狱设备运行
use dynamic/detection/script_jailbreak-detection-bypass  #Frida越狱检测绕过
use dynamic/monitor/pasteboar  #监测系统粘贴板并转储内容
use dynamic/watch/syslog  #实时查看系统日志
use hooking/frida/frida_launcher  #运行Frida脚本
use hooking/frida/frida_shell  #生成附加到目标app的Frida进程
use hooking/frida/frida_trace  #使用frida-trace跟踪指定的函数
use hooking/frida/script_hook-all-methods-of-class  #hook指定类的所有方法
use hooking/frida/script_hook-method-of-class  #hook特定类的特定方法 
use hooking/theos/list_tweaks  #列出使用Needle安装的所有Tweaks
use static/code_checks  #对app源代码进行静态分析
use storage/data/files_plist  #列出应用程序文件夹中包含的plist文件及其数据保护等级
use storage/data/files_sq  #列出应用程序文件夹中包含的SQL文件

检测APP基本信息

如下使用metadata模块检测APP基本信息

use binary/info/metadata
run

15830391409356.jpg返回结果如下:

[needle] > use binary/info/metadata
[needle][metadata] > run
[*] Checking connection with device...
[V] Connection not present, creating a new instance
[V] [AGENT] Connecting to agent (192.168.0.198:4444)...
[+] [AGENT] Successfully connected to agent (192.168.0.198:4444)...
[V] [SSH] Connecting (192.168.0.198:22)...
[+] [SSH] Connected (192.168.0.198:22)
[*] Target app not selected. Launching wizard...
[+] Apps found:
        0 - com.ppjb.carrier102.gr-b2a4274fd7effad67acd1f5b146e8691903c0cac-1500288363.35
        1 - com.highaltitudehacks.dvia
        2 - com.atebits.Tweetie2
        3 - vx710.vx710
        4 - qaqqqq222.yueyu
        5 - rn.notes.best
[>][QUESTION] Please select a number: 1
[+] Target app: com.highaltitudehacks.dvia
[*] Retrieving app's metadata...
[*] Pulling: /private/var/containers/Bundle/Application/9CE2809B-AD4F-4FBF-AB18-198062E39903/DamnVulnerableIOSApp.app/Info.plist -> /root/.needle/tmp/plist
[+] Name                : DVIA                          
[+] Binary Name         : DamnVulnerableIOSApp          
[+] Bundle Executable   : DamnVulnerableIOSApp          
[+] Bundle ID           : com.highaltitudehacks.dvia    
[+] Bundle Type         : User                          
[+] UUID                : 9CE2809B-AD4F-4FBF-AB18-198062E39903
[+] Team ID             :                               
[+] Signer Identity     : Apple iPhone OS Application Signing
[+] Bundle Directory    : /private/var/containers/Bundle/Application/9CE2809B-AD4F-4FBF-AB18-198062E39903
[+] Binary Directory    : /private/var/containers/Bundle/Application/9CE2809B-AD4F-4FBF-AB18-198062E39903/DamnVulnerableIOSApp.app
[+] Binary Path         : /private/var/containers/Bundle/Application/9CE2809B-AD4F-4FBF-AB18-198062E39903/DamnVulnerableIOSApp.app/DamnVulnerableIOSApp
[+] Data Directory      : /private/var/mobile/Containers/Data/Application/09ACB084-A5A6-45F2-B421-5AF4BE3A1E0B
[+] Bundle Package Type : APPL                          
[+] App Version         : 2.0                           
[+] Architectures       : arm64                         
[+] Platform Version    : 9.2                           
[+] SDK Version         : 9.2                           
[+] Minimum OS          : 7.0                           
[+] URL Handlers        
[+]         ['dvia']
[+] Apple Transport Security Settings
[!]         NSAllowsArbitraryLoads                  : 1                   
[+] Entitlements        
[+]          application-identifier                  : com.highaltitudehacks.dvia
[*] No Application Extensions found

查看返回的关键信息:

data directory — 包含APP数据的目录,
binary directory — 包含APP文件的目录,
URL Handlers — 应用程序使用的URL方案,
Apple Transport Security Settings — 设置强制使用HTTPS,
Entitlements — APP的权限.

Class Dump

APP包自身也暴露了一些信息。可以轻松了解app的结构。
运行binary/reversing/class_dump_frida_enum-all-methods模块并使用Frida可读取APP中的类和方法名。

[needle] > exec_command /usr/sbin/frida-server -D
[*] Checking connection with device...
[+] Already connected to: 192.168.0.198
[*] Executing: /usr/sbin/frida-server -D
[needle] > use binary/reversing/class_dump_frida_enum-all-methods
[needle][class_dump_frida_enum-all-methods] > run
[*] Checking connection with device...
[+] Already connected to: 192.168.0.198
[+] Target app: com.swaroop.iGoat
[*] Setting up local port forwarding to enable communications with the Frida server...
[*] Launching the app...
[V] Retrieving the PID...
[V] PID found: 1069
[*] Attaching to process: 1068
[*] Parsing payload
[?] Script terminated abruptly
[?] timeout was reached
[+] "Class: FigIrisAutoTrimmerMotionSampleExport"
[+] {
    "class": "FigIrisAutoTrimmerMotionSampleExport",
    "method": "+ initialize"
}
[+] "Class: _CNZombie_"
[+] {
    "class": "_CNZombie_",
    "method": "+ initialize"
}

越狱检测

使用Needle这款工具内的script_jailbreak-detection-bypass模块来尝试绕过越狱检测:

dynamic/detection/script_jailbreak-detection-bypass

15830651547692.jpg发现并不能绕过越狱检测,找到script_jailbreak-detection-bypass.py该文件,发现虽然有hookstat这个函数,但是返回值作者写的有问题,借鉴了其他工具的写法,我们修改needlescript_jailbreak-detection-bypass的代码如下:
15830662263252.jpg可以成功绕过越狱检测
15830651862320.jpg更多模块的用法可以参考Needlewiki
地址:https://github.com/FSecureLABS/needle/wiki/Modules-Usage

四、问题归类:

1、安装问题

Needlecydia仓库不在维护,可以从Github上下载最新的releaseNeedleAgent.deb,将该文件拷贝到iOS设备中。
地址:https://github.com/FSecureLABS/needle-agent/releases
15827864891207.jpgssh链接iOS设备,找到deb文件传输目录(/User/Media)
执行如下命令进行安装:

dpkg -i NeedleAgent.deb

15830684638973.jpg

2、模块报错

当使用特定的模块时,有时会报错如下:

[needle][pull_ipa] > run
[] Checking connection with device...
[+] Already connected to: 127.0.0.1
[+] Target app: com.chnologies.ani
[] Decrypting the binary...
[?] The app might be already decrypted. Trying to retrieve the IPA...
[!] KeyError: 'IPAINSTALLER'.

根据作者的回复,发现缺少依赖,可以使用该模块进行安装依赖:

use device/dependency_installer

15830689111030.jpg

3、其它

Needle框架的两个设置选项,官方没有提供修改的方式,只能本地重新编译仓库源码。
一、设置选择进程的时候隐藏iOS自己的APP
二、默认设置APP启动方式是spawn(否则每次都要重新设置),

grep命令:
grep -rn "HIDE_SYSTEM_APPS" needle
grep -rn "spawn" needle

15830690395195.jpg

15830690481616.jpg

五、总结

Needle框架目前没人维护,最后一次更新是在2018年,bug过多不建议新手入坑。
Needle的作者在2018年离开了F-Secure公司,并表示不会再回坑了。。。

六、参考资料

https://labs.f-secure.com/archive/needle-how-to/
https://github.com/FSecureLABS/needle

# 移动安全
本文为 独立观点,未经允许不得转载,授权请联系FreeBuf客服小蜜蜂,微信:freebee2022
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
相关推荐
  • 0 文章数
  • 0 关注者