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.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: