iOS 安全攻防系列(一):HelloWorld

这几天公司在做个产品,牵涉到iPhone需要越狱,需要拿到手机上的数据,在网上搜索了一遍,关于iOS安全攻防的文章少之又少,发现只有念茜的一系列文章,废话不多说。

首先介绍一下我的环境:Mac系统为OSX Yosemite,Xcode7,iPhoneOS9.0.SDK,手机系统为iOS8.2。基本上都是最新的。

在学习安全攻防之前,最好先了解一下类Linux系统,我们都知道iOS系统是基于UNIX系统的。

一些常用的工具:

ps:显示进程状态,包括cpu使用情况,内存使用情况,进程标志位、内存限制,常驻进程数、处理时间等等

top:动态查看进程状态,包括cpu 使用情况,cpu空闲率、进程优先级等等

nice 和renice:用于为你的应用软件分配更高或更低优先级

lsof: 列举你的而应用软件打开的所有文件,使用的IP地址和打开的socket以及他们的状态

tcpdump:数据包抓取分析工具,相似的还有wireshark等

ifconfig:网络配置查看工具,windows 是ipconfig

route:查看或者配置路由

netstat:查看网络统计数据,打开端口、连接状态的工具

sysctl: 查看和修改内核状态的工具

最重要一个命令:man,可以查看所有命令的使用方法、参数

otool:otool(object file displaying tool 的缩写)工具(对象文件显示工具)在Mac OS X桌面系统自带,它被移植到arm架构下,提供一系列的机制来查看对象文件和动态库文件的信息。这个有用的工具可以用于判断内存偏移值、段大小、目标加密等信息,枚举动态加载依赖性等。可以与调试器(例如gdb)结合起来解密并分析你的应用软件,也是用于反汇编 的重要工具

nm:这是一个查看符号表的工具,可以查看包括函数和方法名,以及他们的加载地址。这些信息可以用于在使用调试器时在内存中定位代码

cycript :cycript是javascript的一个实现,并且可以与Object-C类和目标进行交互,前几篇文章对它有重点介绍。

好了说了这么多,先来点干货

编译HelloWorld

首先找到编译器

$ ls -l /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/

total 8

drwxrwxr-x  8 root  wheel  272 10 10 07:34 iPhoneOS.sdk

lrwxr-xr-x  1 root  wheel   12 10 27 11:48 iPhoneOS9.1.sdk -> iPhoneOS.sdk


这是我的SDK版本

在https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_5_0.html#//apple_ref/doc/uid/TP40012953-SW18 这篇文章中有这么一句话

Note: LLVM-GCC is not included in Xcode 5.


从Xcode5 开始,苹果开始抛弃LLVM-GCC编译器,改用clang

只要涨了Xcode ,便自带了clang 编译器,可以来确认一下

$ clang

clang: error: no input files


好了,确认有clang

来个经典的

$ vim helloworld.c

#include<stdio.h>

int main(){

        printf("hello world!!\n");

        return 0;

}

然后编译

$ clang -arch armv7 -isysroot `xcrun --sdk iphoneos --show-sdk-path` -o helloworld helloworld.c


产生一个叫HelloWorld 的二进制文件

$ file helloworld

helloworld: Mach-O executable arm


这里一定要是arm ,才能安装到手机上

然后用otool 工具来看看它的汇编代码

$ otool -tV helloworld -p _main

helloworld:

(__TEXT,__text) section

_main:

0000bf98     b580 push {r7, lr}

0000bf9a     466f mov r7, sp

0000bf9c     b082 sub sp, #0x8

0000bf9e f2400042 movw r0, #0x42

0000bfa2 f2c00000 movt r0, #0x0

0000bfa6     4478 add r0, pc

0000bfa8     2100 movs r1, #0x0

0000bfaa     9101 str r1, [sp, #0x4]

0000bfac f000e826 blx 0xbffc @ symbol stub for: _printf

0000bfb0     2100 movs r1, #0x0

0000bfb2     9000 str r0, [sp]

0000bfb4     4608 mov r0, r1

0000bfb6     b002 add sp, #0x8

0000bfb8     bd80 pop {r7, pc}


再来看看这个二进制文件依赖的动态库

$ otool -L helloworld

helloworld:

/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)


字符窜搜索

刚刚我们在程序有个打印动作。我们想看看打印的是什么东西,但这个是arm架构下的程序,在Mac OS下运行不了。这时我们就可以用字符窜搜索对这个二进制文件做字符窜转储。字符窜转储是从一个二进制文件中寻找可打印字符窜,这有助于发现被编译软件中的资源数据,例如,网站URL、查询字符窜,硬编码密码等

$ strings helloworld

hello world!!


我们都知道Linux系统下有个grep 命令

$ strings helloworld |grep -i hello

hello world!!


以上都是一些基础命令和工具

现在来测试一下刚刚编译好的那个二进制文件

把这个文件scp 到越狱手机上

首先对文件签名

$ldid -S helloworld


$./helloworld

好了第一个程序跑起来了


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
// // main.m // Hello World_Code // #import #import "AppDelegate.h" int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } } // // AppDelegate.h // Hello World_Code // #import @interface AppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window; @end // // AppDelegate.m // Hello World_Code // #import "AppDelegate.h" @implementation AppDelegate - (void)dealloc { [_window release]; [super dealloc]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(320/2.0 - 140/2.0, 80, 140, 40)]; // 1 label.text = @"Hello World"; label.backgroundColor = [UIColor cyanColor]; label.textAlignment = NSTextAlignmentCenter; [self.window addSubview:label]; // 2 [label release]; // 1 return YES; } - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值