MediaDomain
, and a relative path within the domain to identify each file. A specific directory is fixed to each domain, and the combination of the path to this directory and the relative path to the file gives the full path. Evasi0n creates all work files in the MediaDomain
domain, so all files have a working prefix of /var/mobile/Media
. directory: Media/ directory: Media/Recordings/ symlink: Media/Recordings/.haxx -> /var/mobile directory: Media/Recordings/.haxx/DemoApp.app/ file: Media/Recordings/.haxx/DemoApp.app/Info.plist file: Media/Recordings/.haxx/DemoApp.app/DemoApp file: Media/Recordings/.haxx/DemoApp.app/Icon.png file: Media/Recordings/.haxx/DemoApp.app/Icon@2x.png file: Media/Recordings/.haxx/DemoApp.app/Icon-72.png file: Media/Recordings/.haxx/DemoApp.app/Icon-72@2x.png file: Media/Recordings/.haxx/Library/Caches/com.apple.mobile.installation.plist
/var/mobile/Media
, but using a symbolic link, files actually fall into /var/mobile
. This approach has already been used in jails and earlier.DemoApp.app
, a regular iOS application, is created in /var/mobile
. This is a regular application, with icons and other accompanying files. The com.apple.mobile.installation.plist
file is also updated, where Springboard stores the cache of application paths so that the DemoApp icon appears among the rest. #!/bin/launchctl submit -l remount -o /var/mobile/Media/mount.stdout -e /var/mobile/Media/mount.stderr -- /sbin/mount -v -t hfs -o rw /dev/disk0s1s1
com.apple.mobile.installation.plist
environment for running DemoApp is slightly modified: <key>EnvironmentVariables</key> <dict> <key>LAUNCHD_SOCKET</key> <string>/private/var/tmp/launchd/sock</string> </dict>
directory: Media/ directory: Media/Recordings/ symlink: Media/Recordings/.haxx -> /var/db symlink: Media/Recordings/.haxx/timezone -> /var/tmp/launchd
/var/db/timezone
to the file /var/tmp/launchd
. Typical access rights to /var/tmp/launchd
are: drwx------ 2 root wheel 102 Feb 4 12:17 launchd
lockdownd
, by sending an incorrectly formed PairRequest
. Lockdownd is the main daemon that performs USB communication, it is also used to start / stop other services, such as MobileBackup and AFC (Apple File Connection, a service that allows you to share files with iTunes). Since lockdownd
works as root user and the user can communicate with it, abuse of its capabilities or vulnerabilities has become popular in the latest jails.PairRequest
package causes lockdownd
to change the access rights to /var/db/timezone
to 777, thus making /var/tmp/launchd
accessible to all users. It is not clear whether this is directly a lockdownd
or some of the libraries that it uses./var/tmp/launchd
and modifies the access rights so that the launchd
socket becomes available to the average user. Also at this stage the symbolic link to the timezone is updated: symlink: Media/Recordings/.haxx/timezone -> /var/tmp/launchd/sock
/var/tmp/launchd/sock
available to the mobile user. #!/bin/launchctl submit -l remount -o /var/mobile/Media/mount.stdout -e /var/mobile/Media/mount.stderr -- /sbin/mount -v -t hfs -o rw /dev/disk0s1s1
LAUNCHD_SOCKET = /private/var/tmp/launchd/sock
launchctl
man, you can find out that the submit command is described as follows: submit -l label [-p executable] [-o path] [-e path] -- command [args] A simple way of submitting a program to run without a configura- tion file. This mechanism also tells launchd to keep the program alive in the event of failure. -l label What unique label to assign this job to launchd. -p program What program to really execute, regardless of what fol- lows the -- in the submit sub-command. -o path Where to send the stdout of the program. -e path Where to send the stderr of the program.
launchd
specified: ENVIRONMENTAL VARIABLES LAUNCHD_SOCKET This variable is exported when invoking a command via the launchd command line. It informs launchctl how to find the correct launchd to talk to.
launchd
IPC is based on unix sockets. There are also several launchd
processes — one for each active user. On iOS, one works with root rights, the other with mobile rights. The mobile user executes launchctl
via DemoApp, but this launchctl
does not communicate with the launchd
mobile user, instead it communicates with the launchd
root user because of the explicitly specified path to the socket and the extended access rights obtained through the vulnerability with /var/db/timezone
.launchd
root user, the task will be executed as root, which allows it to remount the system partition with write access to allow Evasi0n to make changes to the system to perform them in an early boot environment. directory: Media/ directory: Media/Recordings/ symlink: Media/Recordings/.haxx -> / symlink: Media/Recordings/.haxx/private/etc/launchd.conf -> /private/var/evasi0n/launchd.conf directory: Media/Recordings/.haxx/var/evasi0n file: Media/Recordings/.haxx/var/evasi0n/evasi0n file: Media/Recordings/.haxx/var/evasi0n/amfi.dylib file: Media/Recordings/.haxx/var/evasi0n/udid file: Media/Recordings/.haxx/var/evasi0n/launchd.conf
/var/evasi0n
with the application and library, as well as the new launchd.conf
, which stores the commands that are executed when the system boots. bsexec .. /sbin/mount -u -o rw,suid,dev / setenv DYLD_INSERT_LIBRARIES /private/var/evasi0n/amfi.dylib load /System/Library/LaunchDaemons/com.apple.MobileFileIntegrity.plist bsexec .. /private/var/evasi0n/evasi0n unsetenv DYLD_INSERT_LIBRARIES bsexec .. /bin/rm -f /private/var/evasi0n/sock bsexec .. /bin/ln -f /var/tmp/launchd/sock /private/var/evasi0n/sock
otool
, it turns out that there is no __text section in it (example of a translator: the machine code is stored in the __text section of the __TEXT segment ). And if there is no __text section, then there is nothing to sign, and verification for a digital signature will not be performed. Amfi.dylib works with late linking information: $ dyldinfo -export amfi.dylib export information (from trie): [re-export] _kMISValidationOptionValidateSignatureOnly (_kCFUserNotificationTokenKey from CoreFoundation) [re-export] _kMISValidationOptionExpectedHash (_kCFUserNotificationTimeoutKey from CoreFoundation) [re-export] _MISValidateSignature (_CFEqual from CoreFoundation)
If we can force MISValidateSignature () to always return 0, any files will pass the test. This function is part of libmis.dylib, which is now stored in a shared cache, so it's hard to patch the function itself. Replacing the implementation of this feature using MobileSubstrate would be great, but no matter how I tried, MS could not replace it. Then I used the trick: I created a “proxy” library that redirects MISValidateSignature ().
CFEqual()
) are re-exported as other functions with identical arguments, which causes MISValidateSignature()
always return 0, allowing any executable file to be executed./var/db/timezone
vulnerability, it accesses launchd
and modifies MobileFileIntegrity so that it always confirms that digital signatures are correct.Source: https://habr.com/ru/post/168373/
All Articles