iPhone application directory structure
In iOS, applications are treated as a bundle
represented within a directory. The bundle groups all the application
resources, binaries and other related files into a directory. In iPhone,
applications are executed within a jailed environment (sandbox or seatbelt)
with mobile user privileges. Unlike Android UID based segregation, iOS
applications runs as one user. Each and almost every application has access to
the contents of its own sandbox but cannot access other applications’. When an
application is first installed on a device, the system creates the
application’s home directory, sets up some key subdirectories, and sets up the
security privileges for the sandbox“. A sandbox is a restricted environment
that prevents applications from accessing unauthorized resources; however, upon
iPhone JailBreak, sandbox protection gets disabled.
When an application is installed on the iPhone,
it creates a directory with a unique identifier under /var/mobile/Applications
directory. Everything that is required for an application to execute will be
contained in the created home directory. Typical iPhone application home
directory structure is listed below
In iPhone, information could be stored in any of the locations listed below :
1. Plist
files
2.
Keychain
3.
Application’s home directory
4. Cache
5.
Logs.
Property list files
Itis a structured binary formatted file which
contains the essential configuration of a bundle executable in nested key value
pairs. These files are used to store the user preferences and the configuration
information of an application. For example, Gaming applications usually store
game levels and game scores in the Plist files. In general, applications store
the Plist files under [Application's Home Directory]/documents/preferences
folder. Plist can either be in XML format or in binary format. As XML files are
not the most efficient means of storage, most of the applications use binary
formatted Plist files. Binary formatted data stored in the Plist files can be
easily viewed or modified using Plist editors (ex: plutil). Plist editors
convert the binary formatted data into an XML formatted data, later it can be
edited easily. Plist files are primarily designed to store the user preferences
& application configuration; however, the applications may use Plist files
to store clear text usernames, passwords and session related information. So,
while penetration testing, view all the Plist files available under application’s
home directory and look for sensitive information, like usernames, passwords,
user’s personal information and session cookies, etc… Developers can assign any
extension to the Plist files. A Plist file can be easily identified by looking
at the file contents using cat command. The content of a Plist file starts with
bplist’.
Along with the sensitive information storage,
application may also take authentication & authorization decisions based on
the values stored in Plist files. For example, if you notice a Plist entry like
admin=0 during penetration testing, change the admin key value to 1 and open
the application. If the application does not validate the user input properly
and takes the authorization decision based on the Plist entry, you may log into
the application as an administrator. Development best practice is to not store
any sensitive information in Plist files. Also, do not take authentication
& authorization decisions based on the information stored in Plist files.
Plist files contain user controlled input, and it should be validated properly
like any other user input.
WordPress iPhone application used to store clear
text username and password in a Plist file. The video below here demonstrates
the WordPress vulnerability. This vulnerability was reported by SANS and
WordPress fixed it immediately.
Plist can be viewed and modified in both
JailBroken and non JailBroken iPhones.Below are examples of both of them.
Tampering Plist files on a non JailBroken iPhone:
On a non JailBroken iPhone, Plist files can be
viewed & modified using tools like iExplorer and iBackupBot.
Modifying Plist entries with iExplorer
iExplorer (iPhone Explorer) gives access to the
iPhone in disk mode and allows browsing all the folders on the iPhone directly.
Stick Cricket iPhone game is used for the
example.
Stick Cricket iPhone game stores the game score
in a Plist file under application’s home directory. As the application is
storing the game score locally in a Plist file, it can be altered by editing
the Plist file.
Screenshot shown below displays the actual score
before the Plist modification.
Steps shown below will tellthe usage of iExplorer
tool to modify the game scores stored in the Plist file -
1. On your workstation download and install
iExplorer.
2. Connect the iPhone to the workstation over
USB.
3. In iExplorer, browse to Apps->com.sticksports.stickcricket
folder.
4. Navigate to stick cricket
Library->Preferences folder.
5. Copy com.sticksports.stickcricket.Plist file
to the workstation by dragging it to the desktop.
6. On the workstation, open the Plist file using
a Plist editor and modify the yourBest5Overs key value.
7. From iExplorer, delete the
com.sticksports.stickcricket.Plist on the iPhone and drag the newly saved file
onto the iPhone.
8. In iPhone, terminate the Stick Cricket
application and reopen it. The Stick Cricket welcome screen now displays the
modified score as shown in the screenshot below.
Modifying Plist entries with iBackupBot
When the iPhone is connected to a computer,
iTunes takes a backup of everything on the phone including configuration files
(Plist files). iBackupBot tool can be used to view and modify the Plist file
entries on the iPhone backup and restore the modified backup onto the iPhone..
Steps shown below will tell the use of iBackupBot
tool to modify the game scores stored in the Plist file -
1.
Connect
the iPhone to the workstation over USB cable.
2.
On
Workstation, open iTunes and take a backup of the iPhone.
3.
Close
iTunes.
4.
Open
iBackupBot. It automatically identifies the existing backups and displays the
files inside the backup to the user.
5.
Click
on Stick Cricket and open /Library/Preferences/com.sticksports.stickcricket.Plist
file.
6.
Modify
the score stored in the Plist file.
7.
Click
on Export icon to save the modified Plist file.
8.
Click
the restore icon in iBackupBot toolbar. It will restore the iPhone with the
modified backup. Now on iPhone, reopening the Stick Cricket game will display
the modified score.
Tampering Plist files on a JailBroken iPhone:
On a JailBroken iPhone, Plist files can be viewed
& modified using tools like plutil and iFile. Both these tools can be
downloaded from Cydia (packages – com.eric.tool & iFile). iFile would allow
to modify the Plist files directly on the iPhone.
The iPhone camera application is used for the
demo. In iOS camera application, Apple has hidden the panorama mode feature and
planned to include this feature in future iOS versions. Panorama mode basically
allows the users to take continuous photos while panning the camera from left
to right. Apple stored the panorama mode switch in a Plist file. iOS hackers
Conard & Chpwn exposed the panorama mode in iOS 5 by modifying an entry in
com.apple.mobileslideshow.Plist file.
Screenshot shown below displays the list of
options available in the iPhone camera application.
Steps shown below will tell the usage of plutil
tool to change the panorama switch stored in the Plist file -
1.
SSH
to the iPhone and login as a root user (password: alpine).
2.
Navigate
to /private/var/mobile/Library/Preferences/ directory.
3.
View
com.apple.mobileslideshow.Plist file content with the help of plutil
tool.
Plutil
com.apple.mobileslideshow.plist
4.
Add
‘EnableFirebreak’ key to the com.apple.mobileslideshow.plist file with
the below command.
Plutil –key
EnableFirebreak –value yes com.apple.mobileslideshow.plist
5.
It
turns on the panorama feature in the iPhone camera application.
Screenshot below shows different options available in
the iPhone camera after the modification
Hope you all enjoyed this tutorial and if you have any problem or question then you may ask in comments.