做 iOS 安全测试之前你应该知道的工具 (一)

顺便提一句,iOS的国内安全书我也是遍历了一遍,简直是shit,我只能遍历国外的去了,国内的全部放弃。

前言

前言还是让我吐槽爽一把吧。我已经碰见很多人上来就问我,用什么工具啊,有没有扫一下就出来的啊,我真的无力吐槽了。我只想说,那你们就不要学习了,也不要上学,更不要上班,就到处讨讨饭不是蛮好的么?多省力啊。专项已经不是那种用工具看一下,扫一下就能够出现结果的了,安全就更不要说了。就一点,要结合产品的业务特性以及技术实现细节、架构等等才能够分析出来的,不要指望工具,否则你就不要做测试了,做不长久的

idb

第一个来介绍的就是idb,idb可以说是我用过到现在最最友好的了,因为有GUI界面。不过安全貌似不是那么的方便,大家自己去Google吧。我从来不认为小白就需要手把手。谁都是小白,就看谁会Google,就这句话。

首先我们需要在终端中输入idb,只要安装顺利的话,大家会看到如下界面:

是不是觉得就很亲民,我们通过usb或者ssh连接上之后就可以开始使用idb的功能了。(ssh默认密码是alpine)我这里由于之前测试的时候环境没有了,所以我只能用之前的老图了,大家见谅。首先来看下这个。


这里拿点评作为案例,大家可以看到app在device中的基础信息都是已经显示了出来。当然这才是开始。
如下图,我们会看到一个url header的list。这个意思我解释一下,其实就是说现在应用中很多都是通过scheme唤起容器或者Activity的,又或者直接通过url打开某些web。那么这里就是说在这个应用中会调用到的url的header,比如dianping://xxxx这样一类就是其中的调用。通过idb可以直接去mock这些url。如下图:

再来看这个,类似于sandbox,从图中我们也可以看出来ipa沙箱中的目录结构以及每个文件中的数据结构,当然双击这些数据结构中的数据还是能够看到detail的,大部分是不会加密的。包括字段名字,长度等。这些信息也是能够给予我们很大的帮助
Android可以反编译,iOS也是一样的。idb可以说集成了iOS反编译的一些工具让我们直接可以对ipa进行反编译,不过这里都是.h,并没有.m,我估计应该是调用工具的关系,理论上都是可以反编译的。

idb还能够截图,抓包等,简直就是多功能一体机啊。我这里就不多说了,大家自己去体会吧。

otool

好吧,我承认我low了,我以为这是一个要安装的工具,没有想到是mac自带的。

官方描述

 The   otool  command  displays  specified  parts  of  object  files  or
       libraries.  If the -m option is not used the file arguments may  be  of
       the  form  libx.a(foo.o), to request information about only that object
       file and not the entire library.   (Typically  this  argument  must  be
       quoted,  ``libx.a(foo.o)'',  to  get  it past the shell.)  Otool under-
       stands both Mach-O (Mach object)  files  and  universal  file  formats.
       Otool can display the specified information in either its raw (numeric)
       form (without the -v flag), or in a symbolic form using macro names  of
       constants, etc. (with the -v or -V flag).

输入otool我们可以看到很多的参数,如下:

Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool [-arch arch_type] [-fahlLDtdorSTMRIHGvVcXmqQjCP] [-mcpu=arg] [--version] <object file> ...
    -f print the fat headers
    -a print the archive header
    -h print the mach header
    -l print the load commands
    -L print shared libraries used
    -D print shared library id name
    -t print the text section (disassemble with -v)
    -p <routine name>  start dissassemble from routine name
    -s <segname> <sectname> print contents of section
    -d print the data section
    -o print the Objective-C segment
    -r print the relocation entries
    -S print the table of contents of a library
    -T print the table of contents of a dynamic shared library
    -M print the module table of a dynamic shared library
    -R print the reference table of a dynamic shared library
    -I print the indirect symbol table
    -H print the two-level hints table
    -G print the data in code table
    -v print verbosely (symbolically) when possible
    -V print disassembled operands symbolically
    -c print argument strings of a core file
    -X print no leading addresses or headers
    -m don't use archive(member) syntax
    -B force Thumb disassembly (ARM objects only)
    -q use llvm's disassembler (the default)
    -Q use otool(1)'s disassembler
    -mcpu=arg use `arg' as the cpu for disassembly
    -j print opcode bytes
    -P print the info plist section as strings
    -C print linker optimization hints
    --version print the version of /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool

这里不难看出,原来是xcode自带的commond tool。首先我们来看下怎么用,开始其实我并不知道这个命令后面到底跟的是什么文件类型。然后otool一直提示需要提供object file,最后我才明白这个object file是个什么东西,这里以JD的ipa为例。

如果是debug签名的.app那么我们右键之后可以看到包的展开,但线上下来的.app默认是没有这个选项的。我们需要先解压缩之后看到如下的界面,这个.app是可以有包展开的。

展开之后我们可以看到很多文件,需要找到如下高亮的文件,这个文件就是otool可以识别的object file,这点大家要注意。


找到了这个可以执行的文件之后,我们就开始落地尝试了。首先我们输入

otool -L ~/Payload/JD4iPhone.app/JD4iPhone

这条命令可以让我们知道这个ipa中引用了哪些库并且是什么版本的,结果如下:

    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 104.2.0)
    /System/Library/Frameworks/LocalAuthentication.framework/LocalAuthentication (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/CoreData.framework/CoreData (compatibility version 1.0.0, current version 519.15.0)
    /System/Library/Frameworks/AdSupport.framework/AdSupport (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/Foundation.framework/Foundation (compatibility version 300.0.0, current version 1144.17.0)
    /System/Library/Frameworks/CoreAudio.framework/CoreAudio (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 53.1.0)
    /System/Library/Frameworks/CoreTelephony.framework/CoreTelephony (compatibility version 1.0.0, current version 2651.0.0)
    /System/Library/Frameworks/Accelerate.framework/Accelerate (compatibility version 1.0.0, current version 4.0.0)
    /System/Library/Frameworks/CoreImage.framework/CoreImage (compatibility version 1.0.0, current version 4.0.0)
    /System/Library/Frameworks/CoreMotion.framework/CoreMotion (compatibility version 1.0.0, current version 1756.0.20)
    /System/Library/Frameworks/AssetsLibrary.framework/AssetsLibrary (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/AddressBookUI.framework/AddressBookUI (compatibility version 1.0.0, current version 33.0.0)
    /System/Library/Frameworks/AddressBook.framework/AddressBook (compatibility version 1.0.0, current version 30.0.0)
    /System/Library/Frameworks/CoreLocation.framework/CoreLocation (compatibility version 1.0.0, current version 1756.0.20)
    /System/Library/Frameworks/MessageUI.framework/MessageUI (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
    /System/Library/Frameworks/CoreText.framework/CoreText (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/ImageIO.framework/ImageIO (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/UIKit.framework/UIKit (compatibility version 1.0.0, current version 3347.44.0)
    /System/Library/Frameworks/CoreGraphics.framework/CoreGraphics (compatibility version 64.0.0, current version 600.0.0)
    /System/Library/Frameworks/QuartzCore.framework/QuartzCore (compatibility version 1.2.0, current version 1.11.0)
    /usr/lib/libsqlite3.dylib (compatibility version 9.0.0, current version 169.2.0)
    /System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration (compatibility version 1.0.0, current version 700.20.6)
    /System/Library/Frameworks/CFNetwork.framework/CFNetwork (compatibility version 1.0.0, current version 711.3.18)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
    /usr/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.9.0)
    /System/Library/Frameworks/Security.framework/Security (compatibility version 1.0.0, current version 0.0.0)
    /System/Library/Frameworks/MobileCoreServices.framework/MobileCoreServices (compatibility version 1.0.0, current version 66.0.0)
    /System/Library/Frameworks/OpenGLES.framework/OpenGLES (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/AudioToolbox.framework/AudioToolbox (compatibility version 1.0.0, current version 492.0.0)
    /System/Library/Frameworks/OpenAL.framework/OpenAL (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/AVFoundation.framework/AVFoundation (compatibility version 1.0.0, current version 2.0.0)
    /System/Library/Frameworks/CoreMedia.framework/CoreMedia (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/CoreVideo.framework/CoreVideo (compatibility version 1.2.0, current version 1.8.0)
    /System/Library/Frameworks/MapKit.framework/MapKit (compatibility version 1.0.0, current version 14.0.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1214.5.1)
    /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation (compatibility version 150.0.0, current version 1144.17.0)

当然,这些是不够的,我们继续来看一下这条命令。

otool -v -arch armv7 -s __TEXT __cstring ~/Payload/JD4iPhone.app/JD4iPhone > ipa_Str.txt

我们打开txt之后可以看到如下的内容:

0187be4a  addNewAddress
0187be58  addressDefault
0187be67  kShowPickSitesMap
0187be79  kPickViewWillApperNotifaction
0187be97  kPickViewWillDisapperNotifaction
0187beb8  kOrderPaymentTypeChangedNotification
0187bedd  OrderPickSieTypeChangedNotification
0187bf01  kToOrderPickSieTypeVcNotification
0187bf23  kSelectedPickSiteNotification
0187bf41  PayAndShipmentTypeViewController
0187bf62  DeliveryPayType_Confirm
0187bf7a  complatePayAndShiment
0187bf90  OrderInfoViewController
0187bfa8  pickSites
0187bfb2  kUpdatePickSiteLocation
0187bfca  paymentType

这其实是会将ipa中在代码中hard code或者配置文件中的字符串都拉出来,一般有几万行,这里的字符串其实就如同Android中我们查看logcat中有没有敏感词是一样的,这里我们也可以去看看在代码中有没有什么私钥或者其他的敏感信息。我们可以通过一些小技巧来做过滤,比如我们在sublime text中find的时候打开正则匹配,使用正则表达式之后可以简单的找到一些符合我们规律的字符串

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,736评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,167评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,442评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,902评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,302评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,573评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,847评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,562评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,260评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,531评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,021评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,367评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,016评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,068评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,827评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,610评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,514评论 2 269

推荐阅读更多精彩内容