<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
  <title>thomascannon.net Blog</title>
  <subtitle>Personal Weblog of Thomas Cannon</subtitle>
  <link rel="self" href="http://thomascannon.net/blog/rss.xml" />
  <link href="http://thomascannon.net/" />
  <rights>Copyright (c) 2010-2011, Thomas Cannon</rights>
  <updated>2011-09-07T00:20:26+01:00</updated>
  <author>
    <name>Thomas Cannon</name>
    <email>mailNO_SPAM@thomascannon.net</email>
  </author>
  <id>http://thomascannon.net/</id>
  
  <entry>
    <title>Downloading APKs from Android Market</title>
    <link href="http://thomascannon.net/blog/2011/06/downloading-apks-from-android-market/" />
    <id>tag:thomascannon.net,2011-06-13:1307956475</id>
    <updated>2011-06-13T10:14:35+01:00</updated>
    <content type="html" xml:lang="en" xml:base="http://thomascannon.net/">
        &lt;p&gt;Sometimes I need to get hold of an Android application from the Market for analysis. One way to do this is to manually use the Market on an Android device or emulator, install the App, and then copy it off. For various reasons this isn&amp;#8217;t always ideal &amp;#8211; I sometimes don&amp;#8217;t want to install an App if I don&amp;#8217;t know what it does, and I may want to get it a lot faster (i.e. automate it).&lt;/p&gt;
&lt;p&gt;In this post I share what worked for me in creating a command line script to login to the Market and download the application&amp;#8217;s APK. This isn&amp;#8217;t anything particularly new as an unofficial &lt;a href=&quot;http://code.google.com/p/android-market-api/&quot;&gt;Market API&lt;/a&gt; already exists for searching the Market and Tim Strazzere posted some &lt;a href=&quot;http://strazzere.com/blog/?p=293&quot;&gt;Java source&lt;/a&gt; to emulate a download request. However, in Tim&amp;#8217;s example you have to manually specify the App&amp;#8217;s &lt;strong&gt;&lt;code&gt;assetID&lt;/code&gt;&lt;/strong&gt; and your &lt;strong&gt;&lt;code&gt;authToken&lt;/code&gt;&lt;/strong&gt; which means it isn&amp;#8217;t automated. What I wanted was a script which takes a package name as a parameter and downloads it. To achieve this I used the Market API to login, get an &lt;strong&gt;&lt;code&gt;authToken&lt;/code&gt;&lt;/strong&gt;, search for the package, get its &lt;strong&gt;&lt;code&gt;assetID&lt;/code&gt;&lt;/strong&gt;, and then submit a download request.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve documented this for interest, it isn&amp;#8217;t supported software and there isn&amp;#8217;t much error checking. If you use this it is assumed you know what you are doing.&lt;/p&gt;
&lt;p&gt;What was used:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Linux with PHP including curl support&lt;/li&gt;
	&lt;li&gt;Rooted Android phone (I used a spare development phone)&lt;/li&gt;
	&lt;li&gt;Temporary GMail account associated with phone&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;http://code.google.com/p/android-market-api-php/&quot;&gt;PHP Android Market API&lt;/a&gt; by Splitfeed&lt;/li&gt;
	&lt;li&gt;ADB from the Android SDK&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&amp;#8217;m using Ubuntu Linux and PHP with curl support. To install it you need something like this:&lt;/p&gt;
&lt;pre class=&quot;console&quot;&gt;
sudo apt-get install php5-curl
&lt;/pre&gt;
&lt;p&gt;The first step is to get the Android Market &lt;strong&gt;&lt;code&gt;userID&lt;/code&gt;&lt;/strong&gt; which is required in the download request for APKs. I&amp;#8217;m not aware of an easy way to get this at the moment but it is simple enough to sniff from the real Market App and only needs to be done once. Tim Strazzere comes to the rescue again with a nice tip for easily &lt;a href=&quot;http://strazzere.com/blog/?p=286&quot;&gt;sniffing traffic&lt;/a&gt; on Android.&lt;/p&gt;
&lt;p&gt;Open up the Market App on the device and find an app to install, start the following ADB command and then click install:&lt;/p&gt;
&lt;pre class=&quot;console&quot;&gt;
adb shell tcpdump -vv -s 0 -w /sdcard/output.cap
&lt;/pre&gt;
&lt;p&gt;After install hit &lt;strong&gt;&lt;code&gt;Ctrl+C&lt;/code&gt;&lt;/strong&gt; to to stop sniffing. Open up the &lt;strong&gt;&lt;code&gt;.cap&lt;/code&gt;&lt;/strong&gt; file in something like wireshark and look for a GET request which contains the &lt;strong&gt;&lt;code&gt;deviceID&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;userID&lt;/code&gt;&lt;/strong&gt; parameters and make a note of them. I found that on my phone the GET request was different from the one in Tim&amp;#8217;s post, it had extra parameters and when I manually emulated it I was given a 302 redirect to download the file. However, using the older GET request as per Tim&amp;#8217;s post and ignoring the extra parameters seems to still work and leads to the direct download of the APK.&lt;/p&gt;
&lt;p&gt;Download &lt;a href=&quot;http://code.google.com/p/android-market-api-php/&quot;&gt;PHP Android Market API&lt;/a&gt; and unzip it somewhere. In the subfolder &lt;strong&gt;&lt;code&gt;examples&lt;/code&gt;&lt;/strong&gt; create a file called &lt;strong&gt;&lt;code&gt;local.php&lt;/code&gt;&lt;/strong&gt; with the following contents (replacing my values with yours):&lt;/p&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;idl&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class=&quot;pd&quot;&gt;define&lt;/span&gt;(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;GOOGLE_EMAIL&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;,&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;youremail@gmail.com&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;);
&lt;span class=&quot;pd&quot;&gt;define&lt;/span&gt;(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;GOOGLE_PASSWD&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;,&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;yourpassword&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;);
&lt;span class=&quot;c&quot;&gt;// Use a random number with the same number of digits:&lt;/span&gt;
&lt;span class=&quot;pd&quot;&gt;define&lt;/span&gt;(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;ANDROID_DEVICEID&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;,&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;0000000000000000&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;);
&lt;span class=&quot;c&quot;&gt;// Use your real deviceID here that you sniffed:&lt;/span&gt;
&lt;span class=&quot;pd&quot;&gt;define&lt;/span&gt;(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;ANDROID_REALID&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;,&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;0000000000000000000&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;);
&lt;span class=&quot;c&quot;&gt;// Use your sniffed userID parameter here:&lt;/span&gt;
&lt;span class=&quot;pd&quot;&gt;define&lt;/span&gt;(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;ANDROID_USERID&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;,&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;00000000000000000000&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;);
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;I found that the Market API worked with a fake &lt;strong&gt;&lt;code&gt;deviceID&lt;/code&gt;&lt;/strong&gt; but not my real one, and the APK download request worked with my real &lt;strong&gt;&lt;code&gt;deviceID&lt;/code&gt;&lt;/strong&gt; but not the fake one. I didn&amp;#8217;t look into it too much as it seems to work okay as above.&lt;/p&gt;
&lt;p&gt;Download &lt;a href=&quot;/blog/2011/06/downloading-apks-from-android-market/test_download.php.txt&quot;&gt;test_download.php.txt&lt;/a&gt; and save it in the &lt;strong&gt;&lt;code&gt;examples&lt;/code&gt;&lt;/strong&gt; folder as &lt;strong&gt;&lt;code&gt;test_download.php&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Edit &lt;strong&gt;&lt;code&gt;MarketSession.php&lt;/code&gt;&lt;/strong&gt; in &lt;strong&gt;&lt;code&gt;/Market&lt;/code&gt;&lt;/strong&gt; so this line:&lt;/p&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;r&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;lv&quot;&gt;$authSubToken&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Becomes:&lt;/p&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
&lt;pre&gt;&lt;span class=&quot;r&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;lv&quot;&gt;$authSubToken&lt;/span&gt; = &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Okay that is the preparation. We can now use the script to grab any free app from the Market by passing the package name as a parameter. In this example I found a &lt;a href=&quot;https://market.android.com/details?id=bander.notepad&quot;&gt;Notepad application&lt;/a&gt; on Android Market and saw the package name in the URL was &lt;strong&gt;&lt;code&gt;bander.notepad&lt;/code&gt;&lt;/strong&gt;, so:&lt;/p&gt;
&lt;pre class=&quot;console&quot;&gt;
user@linux:~/market-api/examples$ php test_download.php bander.notepad
* About to connect() to android.clients.google.com port 80 (#0)
*   Trying 74.125.71.139... * connected
* Connected to android.clients.google.com (74.125.71.139) port 80 (#0)
&amp;gt; POST /market/api/ApiRequest HTTP/1.1
User-Agent: Android-Market/2 (sapphire PLAT-RC33); gzip
Host: android.clients.google.com
Accept: */*
Cookie: ANDROID=DQAAAREDACTED
Content-Type: application/x-www-form-urlencoded
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Content-Length: 586

&amp;lt; HTTP/1.1 200 OK
&amp;lt; Content-Type: application/binary
&amp;lt; Date: Sun, 12 Jun 2011 23:34:37 GMT
&amp;lt; Expires: Sun, 12 Jun 2011 23:34:37 GMT
&amp;lt; Cache-Control: private, max-age=0
&amp;lt; X-Content-Type-Options: nosniff
&amp;lt; X-Frame-Options: SAMEORIGIN
&amp;lt; X-XSS-Protection: 1; mode=block
&amp;lt; Content-Length: 140
&amp;lt; Server: GSE
&amp;lt; 
* Connection #0 to host android.clients.google.com left intact
* Closing connection #0

Downloading Notepad (3073103588488610805)

user@linux:~/market-api/examples$ ls -hl *.apk
-rw-r--r-- 1 user user 45K 2011-06-13 00:34 bander.notepad.apk
&lt;/pre&gt;
&lt;p&gt;And now we have the APK. The Market API is actually really good and it can also get other data about the app such as author, version, what permissions it needs, screenshots, etc. It would be a fairly trivial enhancement to get the script to save this extra metadata at the same time as the APK if needed.&lt;/p&gt;
    </content>
  </entry>
  
  <entry>
    <title>Developments on Android Security and Forensics</title>
    <link href="http://thomascannon.net/blog/2011/03/developments-on-android-security-and-forensics/" />
    <id>tag:thomascannon.net,2011-03-27:1301222550</id>
    <updated>2011-03-27T11:42:30+01:00</updated>
    <content type="html" xml:lang="en" xml:base="http://thomascannon.net/">
        &lt;p&gt;It has been a little while since I&amp;#8217;ve had the chance to blog and a few things have been going on so I thought I&amp;#8217;d sneak in an update.&lt;/p&gt;
&lt;p&gt;While I was in the Caribbean, the annual &lt;a href=&quot;http://www.zdnet.com/blog/security/pwn2own-2011-blackberry-falls-to-webkit-browser-attack/8401&quot;&gt;Pwn2Own&lt;/a&gt; competition happened. There were several contestants lined up to exploit the Android device but in the end none of them stepped up. The first was security expert Jon Oberheide who I learned just before the competition had a working exploit, but unfortunately he informed Google who patched it before the event. Now that Jon has revealed details about how he &lt;a href=&quot;http://jon.oberheide.org/blog/2011/03/07/how-i-almost-won-pwn2own-via-xss/&quot;&gt;almost won Pwn2Own&lt;/a&gt; everyone can see he was going to use a simple XSS in the Android Market! I discussed the same type of attack after my initial look at the Market security &lt;a href=&quot;/blog/2011/02/android-market-security/&quot;&gt;here&lt;/a&gt; and remember a lot of people dismissing it. Well, Jon actually went ahead and developed the attack, and it was a shame he didn&amp;#8217;t get to show off the fantastic work he had done at Pwn2Own. Google were fast to rectify as usual and their site was combed over for a new XSS before the competition with no luck. They have really enhanced the security since the first time I looked. Still, the case remains that users are one XSS flaw away from having software installed and run on their device!&lt;/p&gt;
&lt;p&gt;I haven&amp;#8217;t published much new research recently in part because my free time has been spent developing the next version of an Android Forensics tool for a mobile forensics company. Due to NDAs and such I am not able to give details, but it is looking really good, and it is scary to see what data we can extract from Android phones!&lt;/p&gt;
&lt;p&gt;Speaking of Android forensics, there is a new book coming out shortly by Andrew Hoog, CIO of &lt;a href=&quot;http://viaforensics.com/&quot;&gt;viaForensics&lt;/a&gt;, about Android Security and Forensics. I&amp;#8217;ve been lucky enough to get an early preview and it looks very good and very detailed, and the best resource on the subject I&amp;#8217;ve seen to date. Some of my research is referenced a couple of times as well!&lt;/p&gt;
    </content>
  </entry>
  
  <entry>
    <title>Android Lock Screen Bypass</title>
    <link href="http://thomascannon.net/blog/2011/02/android-lock-screen-bypass/" />
    <id>tag:thomascannon.net,2011-02-10:1297296357</id>
    <updated>2011-02-10T00:05:57+00:00</updated>
    <content type="html" xml:lang="en" xml:base="http://thomascannon.net/">
        &lt;p&gt;&lt;img src=&quot;/images/blog/lockscreen.png&quot; style=&quot;float:left;margin:0 10px 8px 0;&quot; title=&quot;Android Lock Screen&quot; alt=&quot;Android Lock Screen&quot; /&gt;So far I have tried out 5 Android devices here in the UK (test device, personal phone, and those of friends). They all lack the same feature &amp;#8211; if you forget your PIN or pattern code, there doesn&amp;#8217;t seem to be a way to reset it. You are effectively locked out of your device. Searching online I see that some people are able to reset it after a certain number of attempts by entering their GMail credentials, but I am unable to do so on mine or others I have tried.&lt;/p&gt;
&lt;p&gt;We now have the fantastic web based Android Market, and I wrote about a few minor security findings &lt;a href=&quot;/blog/2011/02/android-market-security/&quot;&gt;here&lt;/a&gt;. One of the common responses I saw to articles talking about the threat of malware distribution was that when remotely installed, an application doesn&amp;#8217;t automatically run and the user would have to manually launch the malware. This is not actually correct, and to demonstrate I decided to create a legitimate utility which can be deployed to a locked phone, executed remotely, and set to disable the lock screen. This will yield access to a locked device so that the user may go in and backup their data.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How it works&lt;/strong&gt;&lt;br /&gt;
Quite simple really. Android sends out a number of broadcast messages which an application can receive, such as SMS received or WiFi disconnected. An application has to register its receiver to receive broadcast messages and this can be done at run time, or for some messages, at install time. When a relevant message comes in it is sent to the application and if the application is not running it will be started automatically.&lt;/p&gt;
&lt;p&gt;After testing out various broadcast messages the best one I found for the purpose of this utility was &lt;strong&gt;&lt;code&gt;android.intent.action.PACKAGE_ADDED&lt;/code&gt;&lt;/strong&gt;. This exists in all APIs since version 1 and is triggered when an application is installed. So to get the application to execute remotely, we first deploy it from the Android Market, then deploy any other application which will cause the first one to launch.&lt;/p&gt;
&lt;p&gt;Once launched it is just a matter of calling the &lt;code&gt;disableKeyguard()&lt;/code&gt; method in &lt;code&gt;KeyguardManager&lt;/code&gt;. This is a legitimate API to enable applications to disable the screen lock when, say, an incoming phone call is detected. After finishing the call the app ought to enable the screen lock again, but we just keep it disabled.&lt;/p&gt;
&lt;div class=&quot;info&quot;&gt;Get the Screen Lock Bypass application: &lt;a href=&quot;https://market.android.com/details?id=se.curity.android.screenlockbypass&quot;&gt;Android Market&lt;/a&gt;&lt;/div&gt;
    </content>
  </entry>
  
  <entry>
    <title>Android Market Security</title>
    <link href="http://thomascannon.net/blog/2011/02/android-market-security/" />
    <id>tag:thomascannon.net,2011-02-05:1296901550</id>
    <updated>2011-02-05T10:25:50+00:00</updated>
    <content type="html" xml:lang="en" xml:base="http://thomascannon.net/">
        &lt;p&gt;While I was in the middle of writing this post and a proof of concept this morning, Google &lt;a href=&quot;http://twitter.com/thomas_cannon/status/33866844112683009&quot;&gt;seemed to fix&lt;/a&gt; a vulnerability I was going to talk about, so this post is no longer as interesting. I decided to post it anyway because some of the findings are still relevant.&lt;/p&gt;
&lt;p&gt;A few days ago Google announced the &lt;a href=&quot;https://market.android.com/&quot;&gt;Android Market&lt;/a&gt; website. This site allows users to browse for apps and when they click &amp;#8220;install&amp;#8221; it will remotely trigger the install on the user&amp;#8217;s phone without any further interaction. Vanja Svajcer from Sophos wrote a &lt;a href=&quot;http://nakedsecurity.sophos.com/2011/02/04/android-market-web-store-backdoor-phone-hackers/&quot;&gt;post&lt;/a&gt; about how it could open a back door for phone hackers. I thought this article was a little over-dramatic at first, since to do that they would need your Google Account password to login, and if they had your password then there is all manner of damage they could do anyway. It was risk versus convenience and I personally like the convenience and power to be able to easily deploy apps to my phone.&lt;/p&gt;
&lt;p&gt;I decided I ought to take a closer look at how apps were deployed to my phone just in case, and I found a few interesting things:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Any free app can be deployed to a phone by making 1 post request. The request doesn&amp;#8217;t need your Google password but must contain a couple of security tokens.&lt;/li&gt;
	&lt;li&gt;All required tokens can be read by JavaScript and posted to an external site (think XSS). &lt;strong&gt;Update:&lt;/strong&gt; While running my &lt;acronym title=&quot;Proof of Concept&quot;&gt;POC&lt;/acronym&gt; it suddenly stopped working and it seems a change was made to prevent this which I will talk about below.&lt;/li&gt;
	&lt;li&gt;The app name can be whatever you want to deploy, regardless of what permissions it needs.&lt;/li&gt;
	&lt;li&gt;If you log out of the website, the post request with the old tokens still works in deploying apps.&lt;/li&gt;
	&lt;li&gt;If you log out, change your Google Account password, the post request with the old tokens &lt;strong&gt;still&lt;/strong&gt; works in deploying apps.&lt;/li&gt;
	&lt;li&gt;I do not know if there is an expiry on the tokens, but after 3 days they are still working, meaning I have retained access to an account with no apparent way to revoke that access?&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Post Request&lt;/strong&gt;&lt;br /&gt;
The http post below, when filled with the correct values, will deploy an app (in this case a stopwatch app) to a phone:&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
SERVER: market.android.com:443

REQUEST:
POST /install HTTP/1.1
Host: market.android.com
Cookie: androidmarket=&amp;lt;310 char market token&amp;gt;
Content-Type: application/x-www-form-urlencoded
Content-Length: 107

id=com.android.stopwatch&amp;amp;device=&amp;lt;19 digit phone ID&amp;gt;&amp;amp;xhr=1&amp;amp;token=&amp;lt;41 char token&amp;gt;
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Stealing the Tokens&lt;/strong&gt;&lt;br /&gt;
&lt;del&gt;Tokens can be read&lt;/del&gt;. Oh well, there goes a cool little demo. While I was refining the code, a cookie that held one of the tokens (androidmarket) seemed to change so as to include the &lt;em&gt;httponly&lt;/em&gt; flag. This means it will only be transmitted by the browser when making a request, and can&amp;#8217;t be read by JavaScript in a XSS attack like regular cookies. I don&amp;#8217;t know if this was due to a misconfiguration, response to someone reporting it or something else.&lt;/p&gt;
&lt;p&gt;Still, to see the other bits of data we were going to use you can manually trigger the following (while logged in to the Android Market of course):&lt;/p&gt;
&lt;pre class=&quot;commands&quot;&gt;
javascript:alert(initProps['userEmail'] + ' | ' + initProps['token'] + ' | ' + initProps['selectedDeviceId']);
&lt;/pre&gt;
&lt;p&gt;It should pop up a message box with your email address, security token and phone ID. Without the androidmarket authentication token stored in the cookie they aren&amp;#8217;t much good so an attacker will have to look at another way to get it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Deploying Malware&lt;/strong&gt;&lt;br /&gt;
If an attacker harvested all tokens they could deploy malware with full permissions en masse. Even when I changed my Google Account password I was still able to automatically deploy software days later with a script and the same tokens.&lt;/p&gt;
&lt;p&gt;Since I can&amp;#8217;t test this on a large scale I do not know if Google have a mechanism to detect such shenanigans, it may be that they do. Certainly they seem to be keeping on top of things security wise.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;m currently coming down with a cold so that&amp;#8217;s all for now :-)&lt;/p&gt;
    </content>
  </entry>
  
  <entry>
    <title>Ryanair Insecurity</title>
    <link href="http://thomascannon.net/blog/2011/02/ryanair-insecurity/" />
    <id>tag:thomascannon.net,2011-02-02:1296605154</id>
    <updated>2011-02-02T00:05:54+00:00</updated>
    <content type="html" xml:lang="en" xml:base="http://thomascannon.net/">
        &lt;p&gt;Economy airline &lt;a href=&quot;http://www.ryanair.com/en&quot;&gt;Ryanair&lt;/a&gt; sees good security as &amp;#8220;superfluous&amp;#8221; according to a &lt;a href=&quot;http://www.h-online.com/security/news/item/Report-Ryanair-s-booking-system-is-insecure-1181896.html&quot;&gt;report by The H Security&lt;/a&gt;. Newspaper &lt;a href=&quot;http://www.tagesspiegel.de/wirtschaft/sicherheitsluecke-bei-ryanair/3788552.html&quot;&gt;Der Tagesspiegel&lt;/a&gt; discovered that Ryanair&amp;#8217;s &lt;a href=&quot;https://www.bookryanair.com/SkySales/FRManageBooking.aspx?culture=en-gb&amp;amp;lc=en-gb&quot;&gt;booking system&lt;/a&gt; gives a user three ways to verify their identity in order to modify their booking. One of those ways is by entering only three pieces of information:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Date of flight&lt;/li&gt;
	&lt;li&gt;Email address&lt;/li&gt;
	&lt;li&gt;Origin and destination of flight&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;As &lt;em&gt;Der Tagesspiegel&lt;/em&gt; points out, it is not hard to guess these details about someone you know based on their Facebook updates or simply asking them when they are going away.&lt;/p&gt;
&lt;p&gt;Ryanair rejects concerns: &amp;#8220;The experts consulted by the Tagesspiegel talking complete rubbish,&amp;#8221; said Daniel de Carvalho, a spokesman for Ryanair&lt;/p&gt;
&lt;p&gt;He emphasised that it is each passenger&amp;#8217;s responsibility to keep their personal information secure. Umm&amp;#8230;okay.&lt;/p&gt;
&lt;p&gt;Most airlines have implemented this functionality properly, by using a unique piece of data only known by the airline and the passenger, such as a password or booking reference. And this is why they do that:&lt;/p&gt;
&lt;p&gt;First of all, an email address is usually not considered secret, otherwise nobody would be able to email you. It may be on your business card, your website, your social networking profile and so on.&lt;/p&gt;
&lt;p&gt;With regards to the other pieces of information, assuming the user does indeed keep them secure, how easy is it to guess them?&lt;/p&gt;
&lt;p&gt;Let us start with the origin and destination of a flight. Each airport has a limited number of routes to other airports, so for example from Aberdeen you can only fly to Dublin, and from Dublin you can fly to 75 other airports. These routes are on the Ryanair web page in a JavaScript array called &amp;#8220;Stations&amp;#8221;. Running the following Ruby command on the data told me how many permutations of origin and destination there are:&lt;/p&gt;
&lt;pre class=&quot;console&quot;&gt;
ruby -e 'n=0; File.readlines(&quot;stations.txt&quot;).each {|lines| n+= lines.scan(/&quot;[A-Z]{3}&quot;/).size-2}; puts n' 
&lt;/pre&gt;
&lt;p&gt;The answer was 2488. If we knew someone&amp;#8217;s email address and were to write a script that programatically submitted requests to the Ryanair website at a relatively slow rate of 4 per second, it would take just over 10 minutes to check every flight permutation for a flight on a single date. To brute force every permutation against an email address for the whole of next month it would take just over 5 hours.&lt;/p&gt;
&lt;p&gt;We haven&amp;#8217;t optimised it of course. Say you knew someone&amp;#8217;s email address, and knew they were based in the UK. It is a good bet they will be departing from an airport on the UK mainland. Running the Ruby command again for UK airports got it down to 394 permutations. Meaning you could scan next months flights for a target email address in about 49 minutes. Clearly it gets worse if the target lives in, say, Latvia, as the limited number of destinations means someone could scan the next six months worth of flights for a booking in about 10 minutes.&lt;/p&gt;
&lt;p&gt;So, I think I will have to agree with the experts consulted by &lt;em&gt;Der Tagesspiegel&lt;/em&gt;.&lt;/p&gt;
    </content>
  </entry>
  
  <entry>
    <title>Update on Android Vulnerability</title>
    <link href="http://thomascannon.net/blog/2011/01/update-on-android-vulnerability/" />
    <id>tag:thomascannon.net,2011-01-25:1295998356</id>
    <updated>2011-01-25T23:32:36+00:00</updated>
    <content type="html" xml:lang="en" xml:base="http://thomascannon.net/">
        &lt;p&gt;In many ways I concluded the &lt;a href=&quot;http://thomascannon.net/blog/2010/11/android-data-stealing-vulnerability/&quot;&gt;Android Data Stealing advisory&lt;/a&gt; not long after I&amp;#8217;d released it. The media interest and resulting debates achieved what I&amp;#8217;d hoped, which was to warn users and put some focus on the issue of poor update frequencies for Android devices. A few interesting things have happened since the release, however, and I wanted to round them up into an update post.&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Google released a patch for the specific exploit I created.&lt;/li&gt;
	&lt;li&gt;The patch won&amp;#8217;t be rolled out until some time after Android 2.3 as originally advised. Users may then have to wait for their device manufacturer and carrier to get the update to them. Some customers, such as those who own shiny new (and expensive) Sony Xperia X10 phones, &lt;a href=&quot;http://www.engadget.com/2011/01/06/sony-ericsson-no-os-updates-for-xperia-x10-beyond-android-2-1/&quot;&gt;won&amp;#8217;t ever be getting&lt;/a&gt; an official update.&lt;/li&gt;
	&lt;li&gt;Pulser, a developer from the group &lt;a href=&quot;http://www.villainrom.co.uk/forum/content.php?240-When-did-you-last-get-a-Security-Update-for-your-Phone&quot;&gt;VillainROM&lt;/a&gt; who make custom Android ROMs, confirmed that the fix was ported into the Froyo Cyanogenmod sources. This means that many users of custom ROMs are already protected. Pulser/VillainROM were the only people to get in touch regarding the safety of their end users and how to protect them, kudos to them!&lt;/li&gt;
	&lt;li&gt;jduck contacted me about writing an exploit, and subsequently developed it into a Metasploit module. Read his great &lt;a href=&quot;http://blog.metasploit.com/2011/01/mobile-device-security-and-android-file.html&quot;&gt;blog post&lt;/a&gt; about it.&lt;/li&gt;
	&lt;li&gt;Ludovic Courgnaud from CONIX Security developed an exploit for the vulnerability to demonstrate his XSSF module for Metasploit. He &lt;a href=&quot;http://www.conixsecurity.com/2011/01/14/xssf-la-sensibilisation-par-la-demonstration-episode-1/&quot;&gt;wrote a post about it&lt;/a&gt; (in French) along with an absolutely &lt;a href=&quot;http://www.vimeo.com/18645356&quot;&gt;fantastic video demo&lt;/a&gt;. He really pushed the limits of what is possible with this simple vulnerability.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And that is pretty much it. For future reference I&amp;#8217;ve listed below a small selection of articles or bulletins about it that I thought were worth saving:&lt;br /&gt;
&lt;a href=&quot;http://www.securityfocus.com/bid/45048/info&quot;&gt;SecurityFocus&lt;/a&gt; | &lt;a href=&quot;http://www.h-online.com/security/news/item/Android-vulnerability-permits-data-theft-1141200.html&quot;&gt;Heise&lt;/a&gt; | &lt;a href=&quot;http://www.androidpolice.com/2010/11/23/new-vulnerability-affecting-all-versions-of-android-allows-unauthorized-remote-sd-card-access/&quot;&gt;Android Police&lt;/a&gt; | &lt;a href=&quot;http://www.pcworld.com/businesscenter/article/211623/android_browser_flaw_exposes_user_data.html&quot;&gt;PC World&lt;/a&gt; | &lt;a href=&quot;http://www.theinquirer.net/inquirer/news/1900274/android-sd-card-exploit-exposed&quot;&gt;The Inquirer&lt;/a&gt; | &lt;a href=&quot;http://www.theregister.co.uk/2010/11/24/android_data_pickpocket_risk/&quot;&gt;The Register&lt;/a&gt; | &lt;a href=&quot;http://www.maximumpc.com/article/news/data_stealing_exploit_found_android&quot;&gt;Maximum PC&lt;/a&gt; | &lt;a href=&quot;http://derstandard.at/1289608620045/Luecke-in-Android-ermoeglicht-Zugriff-auf-Benutzerdaten&quot;&gt;Der Standard&lt;/a&gt; | &lt;a href=&quot;http://news.softpedia.com/news/Data-Stealing-Vulnerability-Identified-in-Android-Browser-168477.shtml&quot;&gt;SoftPedia&lt;/a&gt; | &lt;a href=&quot;http://mobile.slashdot.org/story/10/11/27/213219/Security-Expert-Warns-of-Android-Browser-Flaw&quot;&gt;Slashdot&lt;/a&gt; | &lt;a href=&quot;http://nakedsecurity.sophos.com/2010/11/26/android-how-security-can-work-while-failing/&quot;&gt;Sophos&lt;/a&gt; | &lt;a href=&quot;http://blog.mylookout.com/2010/11/android-browser-flaw-discovered/&quot;&gt;Lookout&lt;/a&gt; | &lt;a href=&quot;http://www.informationweek.com/news/security/vulnerabilities/showArticle.jhtml?articleID=228400108&quot;&gt;Information Week&lt;/a&gt;&lt;/p&gt;
    </content>
  </entry>
  
  <entry>
    <title>Android Data Stealing Vulnerability</title>
    <link href="http://thomascannon.net/blog/2010/11/android-data-stealing-vulnerability/" />
    <id>tag:thomascannon.net,2010-11-23:1290470400</id>
    <updated>2010-11-23T00:00:00+00:00</updated>
    <content type="html" xml:lang="en" xml:base="http://thomascannon.net/">
        &lt;p&gt;While doing an application security assessment one evening I found a general vulnerability in Android which allows a malicious website to get the contents of any file stored on the SD card. It would also be possible to retrieve a limited range of other data and files stored on the phone using this vulnerability.&lt;/p&gt;
&lt;p&gt;The vulnerability is present because of a combination of factors. I&amp;#8217;ve been asked nicely to remove some details from the following section, and as my intention is to inform people about the risk, not about how to exploit users, I&amp;#8217;ve agreed:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;The Android browser doesn&amp;#8217;t prompt the user when downloading a file, for example &lt;strong&gt;&lt;code&gt;&quot;payload.html&quot;&lt;/code&gt;&lt;/strong&gt;, it automatically downloads to &lt;strong&gt;&lt;code&gt;/sdcard/download/payload.html&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
	&lt;li&gt;It is possible, using JavaScript, to get this payload to automatically open, causing the browser to render the local file.&lt;/li&gt;
	&lt;li&gt;When opening an HTML file within this local context, the Android browser will run JavaScript without prompting the user.&lt;/li&gt;
	&lt;li&gt;While in this local context, the JavaScript is able to read the contents of files (and other data).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Then, once the JavaScript has the contents of a file it can post it back to the malicious website. This is a simple exploit involving JavaScript and redirects, meaning it should also work on multiple handsets and multiple Android versions without any effort.&lt;/p&gt;
&lt;p&gt;One limiting factor of this exploit is that you have to know the name and path of the file you want to steal. However, a number of applications store data with consistent names on the SD card, and pictures taken on the camera are stored with a consistent naming convention too. It is also not a root exploit, meaning it runs within the Android sandbox and cannot grab all files on the system, only those on the SD card and a limited number of others.&lt;/p&gt;
&lt;p&gt;A demonstration of the proof of concept exploit in action can be seen in the video embedded below. The demo uses the Android emulator with Android 2.2 (Froyo) and I have also successfully tested it on an HTC Desire with Android 2.2. In the demo I first create a file on the SD card of the Android device, then I visit the malicious page and it grabs the file and uploads it to the server automatically.&lt;/p&gt;
&lt;p style=&quot;text-align:center;&quot;&gt;&lt;iframe src=&quot;http://player.vimeo.com/video/17030639?title=0&amp;amp;byline=0&amp;amp;portrait=0&quot; width=&quot;496&quot; height=&quot;335&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;a href=&quot;http://vimeo.com/17030639&quot;&gt;View on Vimeo&lt;/a&gt; or &lt;a href=&quot;/blog/2010/11/android-data-stealing-vulnerability/data_steal_poc.mp4&quot;&gt;download original&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I notified the Android Security Team on 19-Nov-2010 and to their credit they responded within 20 minutes, took it seriously, and started an investigation into the issue. They have since updated me to say they are aiming for a fix to go into a Gingerbread maintenance release after Gingerbread (Android 2.3) becomes available. I have been advised that I can also mention an initial patch has already been developed, which is being evaluated.&lt;/p&gt;
&lt;p&gt;Responsible disclosure would normally prevent me from publishing the advisory while there is a chance the users will get a fix in a reasonable time frame. However, despite the speed at which Google has worked to develop a patch I don&amp;#8217;t believe this can happen. The reason is that Android OS updates usually rely on OEMs and carriers to provide an update for their devices. Not all OEMs are providing Android OS updates to all of their devices, and the ones that are we have seen are not always doing it in a timely fashion. There may be legitimate reasons for this but the bottom line is there will still be a great deal of devices exposed for quite some time or perhaps forever, including my own.&lt;/p&gt;
&lt;p&gt;Better that we know now and have the chance to protect ourselves, or at least understand the risk. I don&amp;#8217;t expect to see the exploitation of this issue become widespread, but if you are really worried about it there are a few things you can do to identify it or prevent it:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;When the payload is downloaded it generates a notification in the notification area, so watch for any suspicious automatic downloads. It shouldn&amp;#8217;t happen completely silently.&lt;/li&gt;
	&lt;li&gt;You can disable JavaScript in the browser (uncheck &amp;#8220;Settings &amp;gt; Enable JavaScript&amp;#8221;)&lt;/li&gt;
	&lt;li&gt;You can use a browser such as Opera Mobile for two reasons: 1) It prompts you before downloading the payload 2) If a vulnerability is found you can easily update a 3rd party browser after they release a fix.&lt;/li&gt;
	&lt;li&gt;Google have advised that another option is to unmount the SD card (&amp;#8220;Settings &amp;gt; SD &amp;amp; phone storage&amp;#8221;). This could have an impact on the usability of the device but for some situations, perhaps in organisations, I can see this could work. It has not been fully tested, however.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A word of caution though, you may prevent the automatic exploit this way, but as always you will still need to be vigilant and watch for other vectors, such as an HTML file sent through email.&lt;/p&gt;
&lt;p&gt;For those of you who assess the security of products for use in a corporate environment, you&amp;#8217;ll know that this kind of advisory is essential in making accurate risk assessments and informed decisions before your business commits to a direction which will later leave it vulnerable. I do not mean to say Android is not a suitable platform for corporate use, like any mobile technology it entirely depends on the use case, compensating controls, risk appetite and so on. I hope this information helps you in the decisions you may be facing right now and goes some way to suggesting a suitable mitigation.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update 1:&lt;/strong&gt; I&amp;#8217;d like to thank &lt;a href=&quot;http://www.heise.de/newsticker/meldung/Android-Luecke-ermoeglicht-Datenklau-1140932.html&quot;&gt;Heise Security&lt;/a&gt; for their help to independently validate the issue on a couple of their devices.&lt;br /&gt;
&lt;strong&gt;Update 2:&lt;/strong&gt; Sophos understands the real issue here (that devices are not getting timely updates) and has written a good &lt;a href=&quot;http://nakedsecurity.sophos.com/2010/11/26/android-how-security-can-work-while-failing/&quot;&gt;response to this post&lt;/a&gt;. To take a real example, Motorola &lt;a href=&quot;https://supportforums.motorola.com/thread/41025&quot;&gt;has just announced&lt;/a&gt; that their Milestone XT720 will remain on Android 2.1 and not get an update, despite it only being a few months old. They have published a &lt;a href=&quot;https://supportforums.motorola.com/community/manager/softwareupgrades&quot;&gt;list of handsets&lt;/a&gt; with the updates they are getting, and the number of devices that are no longer going to receive official security patches is alarming.&lt;/p&gt;
    </content>
  </entry>
  
  <entry>
    <title>UK Cyber Security Challenge</title>
    <link href="http://thomascannon.net/blog/2010/08/uk-cyber-security-challenge/" />
    <id>tag:thomascannon.net,2010-08-08:1281229245</id>
    <updated>2010-08-08T02:00:45+01:00</updated>
    <content type="html" xml:lang="en" xml:base="http://thomascannon.net/">
        &lt;p&gt;The UK Government recently launched a &lt;a href=&quot;https://cybersecuritychallenge.org.uk/cipher.html&quot;&gt;Cyber Security Challenge&lt;/a&gt; to help get interested and talented people into the industry. Their first challenge was quite easy and the results have now been released. The first step was a string of characters which was clearly base64 encoded. Decoding that gave a binary output and the header indicated it was a jpg. The jpg was an XKCD cartoon strip. Apparently many people thought this was the solution and submitted their answer. However, the border of the image contained a binary message which lead to another URL. At this URL was a string of hex characters and decoding this was the final challenge.&lt;/p&gt;
&lt;p&gt;Unfortunately I heard about this several days after it went live and it was already solved (although the answers hadn&amp;#8217;t been published yet.) I managed to decode the final message with only one line of Ruby which I thought was quite neat and wanted to share:&lt;/p&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
&lt;pre&gt;print &lt;span class=&quot;co&quot;&gt;File&lt;/span&gt;.read(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;cipher.txt&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;).scan(&lt;span class=&quot;rx&quot;&gt;&lt;span class=&quot;dl&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;/&lt;/span&gt;&lt;/span&gt;).map { |pair| pair.reverse.hex.div(&lt;span class=&quot;i&quot;&gt;2&lt;/span&gt;).chr }.join
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;I had noticed the distribution of hex characters was far from random (indicating it wasn&amp;#8217;t encrypted with an algorithm like AES or DES.) I started to solve it as a basic substitution cipher and after a couple of obvious characters and referring to an ASCII chart I noticed the pattern and came up with the code above.&lt;/p&gt;
&lt;p&gt;It opens a file containing the cipher text, reading 2 characters at a time it flips the 2 characters, treating the 2 characters as a single hex byte it divides by 2 and then prints out the ASCII representation of each byte, revealing the secret message. All in one line of easy-to-understand code! On reflection it should have been just a circular bitshift of the data by 3 bits but I didn&amp;#8217;t find an easy way to do that in one line of Ruby anyway.&lt;/p&gt;
    </content>
  </entry>
  
</feed>
