iPhone Honeypot Project

July 15, 2010

Capturing SSH Keystrokes (Continued)

So, the test on my macbook from the previous post worked nicely. I contacted my supervisor to get his opinion on the method I decided upon. Porting this method over to the iPhone was a little messy but seems to be working nicely. Firstly, I set up my macbook as a central logging server. This was done by modifying the /etc/syslog.conf.

Firstly, we move the existing syslog.conf to a backup file to restore later:

mv /etc/syslog.conf /etc/syslog.conf.bak; touch /etc/syslog.conf

I then copy the following configuration into /etc/syslog.conf using an editor:

*.* /var/log/logclient.log

And finally, restart the syslog service:

launchctl unload /System/Library/LaunchDaemon/com.apple.syslog.plist

launch load /System/Library/LaunchDaemon/com.apple.syslog.plist

At this point, I opened up a terminal and ran tail -f /var/log/logclient.log to keep an eye (in real time) of the logs being generated (if any). Setting up the iPhone as a client was a different story. On OSX systems, the plist file (the configuration) file is stored as a plist at /System/Library/LaunchDaemons/com.apple.syslogd.plist in XML. However, on the iPhone, it’s stored as a binary file and the iOS base doesn’t include plutil to convert it back to XML for modification. To circumvent this problem, I decided to create my own config instead. This was done by creating a /etc/syslog.conf file and adding the following configuration:

*.* @192.168.1.100

To load this configuration, I restart syslog on the iPhone.

launchctl unload /System/Library/LaunchDaemon/com.apple.syslog.plist

launch load /System/Library/LaunchDaemon/com.apple.syslog.plist

Obviously, in the above, the IP of the central logging server (my macbook) is at 192.168.1.100. At this point, I generated some alerts by opening SMS, sending an email, launching a third-party application to ensure logs were being generated and sent over the network via syslog.

Jul 15 16:33:34 192.168.1.102 abnev-ip1 MobileSMS[489]: MS:Notice: Installing: com.apple.MobileSMS [MobileSMS] (478.52)
Jul 15 16:33:34 192.168.1.102 abnev-ip1 MobileSMS[489]: MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/MailToAttachmentMessageUI.dylib
Jul 15 16:33:34 192.168.1.102 abnev-ip1 UIKitApplication: com.apple.MobileSMS[0xe734][489]: MS:Warning: message not found [NSFileManager rawDirectoryContentsAtPath:]
Jul 15 16:33:34 192.168.1.102 abnev-ip1 MobileSMS[489]: *** _NSAutoreleaseNoPool(): Object 0x10c210 of class NSPathStore2 autoreleased with no pool in place – just leaking\nStack: (0x326edf87 0x326c2135 0x326c3bb3 0x326c4b15 0x326c47c3 0x326c4639 0x326c5f33 0x336079c5 0x33477b27 0x3347ce93 0x3347a245 0x33477a11 0x33477747 0x334784df 0x33477337 0x334774ef 0x47408 0x47a7c 0x43c14 0x2fe0be0d 0x2fe0be31 0x2fe09d7f 0x2fe0a16d 0x2fe01dd9 0x2fe08247 0x328c4975 0xa038 0x2fe0bd7d 0x2fe0be39 0x2fe09d7f 0x2fe0a16d 0x2fe0228b 0x2fe06a15 0x2fe016fd 0x2fe01050)
Jul 15 16:33:34 192.168.1.102 abnev-ip1 MobileSMS[489]: *** _NSAutoreleaseNoPool(): Object 0x10c710 of class NSPathStore2 autoreleased with no pool in place – just leaking\nStack: (0x326edf87 0x326c2135 0x326c3bb3 0x326c31a7 0x326c5b9d 0x326c46f3 0x326c5f33 0x336079c5 0x33477b27 0x3347ce93 0x3347a245 0x33477a11 0x33477747 0x334784df 0x33477337 0x334774ef 0x47408 0x47a7c 0x43c14 0x2fe0be0d 0x2fe0be31 0x2fe09d7f 0x2fe0a16d 0x2fe01dd9 0x2fe08247 0x328c4975 0xa038 0x2fe0bd7d 0x2fe0be39 0x2fe09d7f 0x2fe0a16d 0x2fe0228b 0x2fe06a15 0x2fe016fd 0x2fe01050)
Jul 15 16:33:34 192.168.1.102 abnev-ip1 UIKitApplication: com.apple.MobileSMS[0xe734][489]: MS:Warning: message not found [MailComposeController _setupForMessageWithURL:]
Jul 15 16:33:34 192.168.1.102 abnev-ip1 MobileSMS[489]: MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/WinterBoard.dylib
Jul 15 16:33:34 192.168.1.102 abnev-ip1 MobileSMS[489]: WB:Notice: WinterBoard
Jul 15 16:33:34 192.168.1.102 abnev-ip1 MobileSMS[489]: MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/iNoRotate.dylib
Now that the syslog was working correctly, It was necessary to get bash logging keystrokes. I originally thought about writing a patch but then thought using logger would be easier. Unfortunately, logger isn’t part of the base iOS so alternitives were looked at such as script(1) and tee(1). However, to ensure the correct functionality as per the previous post, it was necessary to have logger working.
To achieve this, I checked out the source of FreeBSD 8 and found logger.c in /usr/src/usr.sbin/logger/logger.c which included a Makefile. I tar’ed this up and moved it onto my macbook. After unpacking the files, I attempted to compile on OSX. This failed due to the following errors:
logger.c:47: error: expected declaration specifiers or ‘…’ before string constant
logger.c:47: warning: data definition has no type or storage class
Inspecting line 47 showed:
47 __FBSDID(“$FreeBSD: src/usr.bin/logger/logger.c,v 1.17.2.1.2.1 2009/10/25 01:10:29 kensmith Exp $”);
I removed this line and attempted to copile suing gcc -o logger logger.c omitting the -DINET6 flag as specified in the Makefile for IPV6 support. This compiled fine. Using my script, gcc2 from previous posts, I cross-compiled logger.c for use on the iPhone. This compiled without errors. I sftp’ed the binary up to the iPhone and tested it by executing on the command line over SSH. Once it produced the usage output, I copied it over to /usr/sbin on the iPhone filesystem and modified the /etc/profile script to include the following:
# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi

if [ “${BASH-no}” != “no” ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi

function log2syslog
{
declare COMMAND
COMMAND=$(fc -ln -0)
logger -p local1.notice -t bash -i — “${USER}:${COMMAND}”
}
trap log2syslog DEBUG
Modifying the user accounts to launch bash was necessary. As a quick fix, I sym-linked using ln(1) /bin/sh to /bin/bash (bash was installed form Cydia). I then restarted syslog and logged out of the shell and reestablished the connection to the iPhone on the root account.
launchctl unload /System/Library/LaunchDaemons/com.apple.syslog.plist
launch load /System/Library/LaunchDaemons/com.apple.syslog.plist
exit
On establishing the SSH connection, I tried out some simple commands, e.g. ls(1), cd(1), uname(1) etc. and checked the /var/log/logclient.log on my macbook to ensure the keystrokes were being sent as expected. The following were the contents:
Jul 15 16:19:27 192.168.1.102 abnev-ip1 bash[474]: root: ls -al
Jul 15 16:19:32 192.168.1.102 abnev-ip1 bash[477]: root: cat /etc/profile
Jul 15 16:19:33 192.168.1.102 abnev-ip1 bash[480]: root: ls -al
Jul 15 16:19:34 192.168.1.102 abnev-ip1 bash[483]: root: w
Success. I’ll await to see my supervisors response, but I think this is very promising. I may be ready to run a pilot tonight. In the meantime, I’ll charge up my old-skool Nokia phone to swap out the SIM, backup the iPhone using iTunes and create a host of fake contacts and information to place on the iPhone.

June 17, 2010

GCC on iPhone – Progress? (Continued)

Filed under: bash,Darwin,gcc,libpcap,scripe,SDK — abnev @ 2:05 pm
Tags: , , , , , ,

I EVENTUALLY managed to get back to where I was yesterday after I hit a bump in the road where I stepped back and could no longer compile simple applications on my Mac OSX destined for the iPhone arch. This time, I have created a simple script called ‘gcc2’ which sets all the appropriate options.

#!/bin/sh

GCC=”/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc”

ISYSROOT=”/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk”      #3.1.3

EXPECTED_ARGS=3

# check num of args supplied

if [ $# -ne $EXPECTED_ARGS ]

then

#print usage

echo “Usage: `basename $0`: no input files”

exit -1      #exit on error

fi

# e.g. gcc -arch armv6 -isysroot $ISYSROOT -o test test.c

$GCC -arch armv6 -isysroot $ISYSROOT $1 $2 $3

Additionally, I have attached my bash_history file for setting up the environment etc.
abnev-lpt2:iphone-gcc abnev$ cat test.c
#include <stdio.h>
int main() {
printf(“Hello, World!\n”);
return(0);
}
abnev-lpt2:iphone-gcc abnev$ /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/
abnev-lpt2:iphone-gcc abnev$ /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk -o test test.c
abnev-lpt2:iphone-gcc abnev$ cd ~
abnev-lpt2:~ abnev$ mkdir bin
abnev-lpt2:~ abnev$ cd bin
abnev-lpt2:bin abnev$ pico gcc2
abnev-lpt2:bin abnev$ PATH=$PATH:/Users/abnev/bin
abnev-lpt2:bin abnev$ chmod 755 gcc2
abnev-lpt2:bin abnev$ gcc2
arm-apple-darwin10-gcc-4.2.1: no input files
abnev-lpt2:bin abnev$ cp ~/test.c .
abnev-lpt2:bin abnev$ gcc2 -o test test.c
abnev-lpt2:bin abnev$ ./test
-bash: ./test: Bad CPU type in executable
abnev-lpt2:bin abnev$

Just an extra note, to make sure the environment would be set up after reboots etc I modified my ~/.profile to include the correct PATH environment variables pointing towards ~/bin where gcc2 now resides. This was done by adding/changing the line:

export PATH=/opt/bin:/opt/local/bin:/opt/local/sbin:$PATH

to

export PATH=/Users/abnev/bin:/opt/bin:/opt/local/bin:/opt/local/sbin:$PATH

I’ll continue trying to get it to compile using libpcap.

June 7, 2010

Fundamentals

Around Christmas I bought myself a brand new shiny iPhone 3GS which currently running  OS version 3.1.3 (7E18), Carrier O2 5.1. I have decided to use this phone within this project which requires a few tests and a little hacking. To begin, access to the file system must be granted. To do this, the phone is jailbroken and a number of tools are installed to enable remote SSH access for ease during the project.

Until recently, @geohot‘s blackra1n only offered an tethered jailbreak for the iPhone. This meant that if the phone died or was switched off, it was necessary to hook up the phone to a system which could run blackra1n to inject the exploit code again. Luckily for me, an untethered jailbreak was released which eased the process. This application is called Spirit and is a quick plug-in and click job. It is important to note that this application doesn’t offer any carrier unlock but as I’m already on O2 this is fine.

Once unlocked, Cydia (a package management application) is upgraded and installed. Using this we can install OpenSSH as per http://www.hackthatphone.com/2x/open_ssh.html. This allowed me open an SSH connection to the iPhone from Terminal.app thus gaining access to the filesystem.

As a side note, there are two usable accounts on all iPhones by default. Inspecting the /etc/passwd file shows:

root:*:0:0:System Administrator:/var/root:/bin/sh
mobile:*:501:501:Mobile User:/var/mobile:/bin/sh

Note, the root password by default is “alpine” and is used as the system administrator account. The mobile account is used for standard usage (launching applications from the UI etc) and can be accessed via SSH or by logging in as root and issuing “su — mobile” on the command line. If logged in as the mobile user, use “login -pf root” to become root.

At this point, I played around with the filesystem and explored the various commands available. Being familiar with BSD 4.4 FS (Thank you FreeBSD!) and Darwin (Thank you Macbook), a lot of the basic commands were missing: ps, man, netstat, text editor, etc. Exploring Cydia, I found some of these tools were easily downloadable.

Blog at WordPress.com.