在大多数iOS应用中,一些工具,比如Clutch,class-dump,cycript,lldb,theos.对应用程序的结构,代码逻辑,运行流程,可以做到很容易的分析。然后进行应用的破解,篡改,重签名。所以很有必要对代码做一些保护。
4.中间人攻击 :https, 证书验证, 数据加密
比如这种字符串,我们看看其反汇编代码:
0000000100006794 sub sp, sp, #0x30 ; Objective C Implementation defined at 0x1000080f8 (instance method), DATA XREF=0x1000080f8
0000000100006798 stp x29, x30, [sp, #0x20]
000000010000679c add x29, sp, #0x20
00000001000067a0 mov x8, sp
00000001000067a4 adrp x9, #0x100008000
00000001000067a8 add x9, x9, #0xc88 ; @selector(viewDidLoad)
00000001000067ac adrp x10, #0x100008000
00000001000067b0 add x10, x10, #0xca8 ; 0x100008ca8
00000001000067b4 stur x0, [x29, #-0x8]
00000001000067b8 str x1, [sp, #0x10]
00000001000067bc ldur x0, [x29, #-0x8]
00000001000067c0 str x0, sp
00000001000067c4 ldr x10, x10
00000001000067c8 str x10, [sp, #0x8]
00000001000067cc ldr x1, x9
00000001000067d0 mov x0, x8
00000001000067d4 bl imp___stubs__objc_msgSendSuper2
00000001000067d8 adrp x0, #0x100008000 ; argument #1 for method imp___stubs__NSLog
00000001000067dc add x0, x0, #0x60 ; @"Hello CR25"
00000001000067e0 bl imp___stubs__NSLog
00000001000067e4 ldp x29, x30, [sp, #0x20]
00000001000067e8 add sp, sp, #0x30
00000001000067ec ret
CR25明文,如果我们这里是程序的敏感信息的话,分析者就会很容易找到我们的敏感信息。这里需要给字符串加密,然后运行时进行动态解密。
这里为了举例,我只做了简单的异或,具体算法你可以根据需求自己选择。
字符串加密后源码:
再看看反汇编:
-[ViewController viewDidLoad]:
0000000100006660 sub sp, sp, #0x40 ; Objective C Implementation defined at 0x1000080e0 (instance method), DATA XREF=0x1000080e0
0000000100006664 stp x29, x30, [sp, #0x30]
0000000100006668 add x29, sp, #0x30
000000010000666c add x8, sp, #0x10
0000000100006670 adrp x9, #0x100008000
0000000100006674 add x9, x9, #0xc70 ; @selector(viewDidLoad)
0000000100006678 adrp x10, #0x100008000
000000010000667c add x10, x10, #0xca8 ; 0x100008ca8
0000000100006680 stur x0, [x29, #-0x8]
0000000100006684 stur x1, [x29, #-0x10]
0000000100006688 ldur x0, [x29, #-0x8]
000000010000668c str x0, [sp, #0x10]
0000000100006690 ldr x10, x10
0000000100006694 str x10, [sp, #0x18]
0000000100006698 ldr x1, x9
000000010000669c mov x0, x8
00000001000066a0 bl imp___stubs__objc_msgSendSuper2
00000001000066a4 adrp x8, #0x100008000 ; argument #1 for method __B97DE2E4_175_F0C445_2D3_29549CFFE480
00000001000066a8 add x0, x8, #0xd58 ; __7VA7EOJRUDOSFIS
00000001000066ac bl __B97DE2E4_175_F0C445_2D3_29549CFFE480
00000001000066b0 mov x29, x29
00000001000066b4 bl imp___stubs__objc_retainAutoreleasedReturnValue
00000001000066b8 mov x1, x0
00000001000066bc str x0, [sp, #0x8]
00000001000066c0 mov x0, x1
00000001000066c4 bl imp___stubs__NSLog
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!