Saturday, 1 December 2012

What is Android application licensing?

I ran into this permission this morning:

What it means is that the app will check with Google play (aka android marketplace) that the app was bought by the user that is now running it. The application holds the public key and uses this to check the "check_license" response from Google.

Is it possible to mess with this process? Well it would depend on where the public key is stored and how Google implements the process (including obviously security of transmission).

One thing that immediately stands out is this following piece of advice from Android themselves:

A typical implementation would extract some or all fields from the license response and store the data locally to a persistent store, such as through SharedPreferences storage, to ensure that the data is accessible across application invocations and device power cycles. For example, a Policy would maintain the timestamp of the last successful license check, the retry count, the license validity period, and similar information in a persistent store, rather than resetting the values each time the application is launched.
Sharedpreferences is only secured by using the sandbox model. This means any rooted devices would permit the user to alter these values simple by editing the .xml file.

What Google have done to allow developers to defend against this is to create AESObfuscator. This encrypts the data using the Android ID as the key. Obviously this is still recoverable by the user, but certainly makes it take a little longer to perform.

I can foresee two attacks coming out of this.
 #1 - Applications on 3rd party app stores stating they can "unlock" licensed applications. They would require a r00ted device to work and could do all sorts of nefarious things in the background. Because they would not be allowed on Google Play, they would have no checking and could contain malware.

#2 - Applications implementing their own obfuscation/ trusting license info input. Their is a long history of Android applications assuming the best about files in their own sandbox and implementing their own logic and functions when using the data contained. It allows attackers who can overcome the sandbox (say by running on a rooted device) to inject data that is then used in the context of the app.

Wednesday, 31 October 2012

On the road with Arduino

Well the Arduino UNO kit has arrived and I'm very impressed. Lots of things to try and I'm already well beyond the flashing LED tutorial that is the electronics version of HelloWorld.

Some quick experimenting has shown that the servo is easy to position using this example. Similarly I have built up a quick serial communication app that replies to a specific string (based on this). Interestingly you need to tweak PUTTY to talk to it correctly

// Command line variables
String command; // String input from command prompt
String temp1,temp2; // temporary strings
char inByte; // Byte input from command prompt
char carray[6]; // character array for string to int // manipulation
int a,b,c; // temporary numbers

void setup(){

void loop(){

    // Input serial information:
    if (Serial.available() > 0){
       inByte =;
        // only input if a letter, number, =,?,+ are typed!
        if ((inByte >= 65 && inByte <= 90) || (inByte >=97 && inByte <=122) || (inByte >= 48 &&     inByte <=57) || inByte == 43 || inByte == 61 || inByte == 63) {

     }// end serial.available
     // Process command when NL/CR are entered:
     if (inByte == 10 || inByte == 13){
       if (command.equalsIgnoreCase("hey")){
         Serial.println("hello there!");
       }       command="";      }

Friday, 26 October 2012

ASCII only exploiting

So an interesting problem was given to a group of us this week. The vulnerable function in IE was controlled using an ASCII string. Most people took this as a sign that heap spraying was required and therefore used a string like "   " to point to heap space and hopefully their NOP sled.

I took the "crafty" approach and instead decided that the whole shell code could be contained in the string, not just the pointer.

msfencode (part of Metasploit) has an excellent encoder option that will encode only using alphanumeric characters. Unfortunately when you try this, you will get non alpha characters mixed in wherever it fails to find the right commands.

msfpayload windows/exec CMD=calc.exe R | ./msfencode -e x86/alpha_mixed

In this case, you will need to find a ROP gadget to move the address of the start of your shell code in to one of the registers. If you're lucky it will already be in one. You can then give it to msfencode as an argument:
 msfpayload windows/exec CMD=calc.exe R | ./msfencode BufferRegister=EAX -e x86/alpha_mixed
 If you need to go searching for ROP gadget there are a couple of tools that may help you. First check out Immunity's !gadget  command. Alternatively there's Mona, a Python add-on ( These were enough to go searching through for a non-ASLR'd gadget that moved the right value to the right register.

Thursday, 25 October 2012

R00t beer fridge

So as an update to the previous post, I've been doing some research over the last couple of days and found that:
a) servos are weird things that require crazy Pulse Width Modulation (PWM) to control them. This is not something Raspberry Pis do out of the box. I've seen a few cases where they use an in between piece of hardware to work around this.
b) arduinos can be made to do some crazy stuff. Like run a web server

For these two reasons I have (sadly) moved over to using Arduino. I would love to use a Pi but it's horses for courses and although I think it's possible to use a Pi for a project like this, it's just too much effort.

The Arduino will be delivered tomorrow so I can get to grips with the basics over the weekend and have the first photos next week.

It looks like the locking mechanism will be best done with Meccano. Using servos to move the locks into place will mean that they can be used without a second power source and won't "fail open" if someone was to pull the plug. It will either be a sliding bar, or a latch.

Saturday, 20 October 2012

Raspi: zero to hero.

So I'm at step zero here. Let me just give a quick intro first to what I want to do along with a little background.

The goal is to create a hacking challenge for some friends. The prize is a can of "r00t" beer. This beer will be locked away in a fridge. The lock is controlled by a Raspberry Pi. There will be several stages to pass before the fridge will unlock and the prize will be gained.

Now the background. I have owned a Raspi for about 2 months. In that time I have rather sadly not done much with it. It currently sits as a XMBC server for my television, but it's lack of YouTube support and limited Codecs means that it's not all that great. I know that Raspis have support for electronics but my electronics know how is very "trial and error" (see the Glone if you don't believe me).

My goal of blogging about this is I feel my position now is very similar to many people out there. We have a Pi, we want to build something cool, but we don't know where to start. Well I will try to get this project seen through to completion and along the way blog about the various resources and mistakes I run into that may help you all out there.

So... the first step. I want to get a raspi installed with a *nix build that will support the IO functionality. A basic layout is here. If I can get an LED to turn on and off with a command then that's level 1 completed. The next step will be getting it to drive a motor. Stay tuned :-)

Monday, 6 August 2012

Cross App Request Forgery in Android - CARF

An interesting thing about Android application security is that it is all very "What if?". Most scenarios I hear involve malicious apps. Malicious apps get installed by unsuspecting users and run in the guise of some innocent game whilst maliciously harvesting or installing other bits and pieces. The usual goal is to recover important data from another application or to use premium rate services or as botnets.
Normally the idea of malware specifically targeting other apps on a user's device would seem ludicrous but given the nature of some of the apps coming out on to the market place (sorry, Google Play), this seems more and more likely a vector in these more extreme cases.
This article has two points: The flaw in the root attack theory, and a potentially unthought of and certainly overlooked attack vector, the cross app request forgery (CARF)

Attacking an app with root.

I've often heard of a scenario in which malware elevates to root, and then attacks the flaws in the Manifest or file system of a specific app. Often android manifest writers overlook the fact that just because the action isn't exported it doesn't mean that it can't be run by other users. Root users may run all actions (including your precious providers), whether or not they are exported, unless they are explicitly not exported (exported=0x0).
But this is a bad argument for an attack vector. If you have root, why go after the app? You can access all the files, allowing you to grab the db files and everything else. If the db is encrypted, switch out the binary and trick the user into giving out the information you need to decrypt it. When you're done, switch the apps back, send off the data and disappear. This is far simpler to write (and portable to attack any app), than trying to pick apart and exploit specific vulnerabilities in others' apps.

Protecting against root?

When it comes to protecting against this vector there are three answers, keep the information off of the device (best), use the secure element, or encrypt information with a decent user entered password.
Keeping information off the phone means interacting with a server. Ideally the user sends up a hashed password, the server checks and responds with the information, allowing authentication and no chance for offline brute force attacks.
Secondly, the secure element is a purpose built secure vault with lock-out and no public bypasses. This is limited by having to partner with either a device (for an on-device secure element), or a network provider (if it's on the SIM).
Finally there's user passwords. These are used to encrypt the data on the file system. This is obviously limited as no one likes typing in long passwords on phones, and still vulnerable to social engineering.


The inability of many developers to control cross app communications securely leads to some unusual attack vectors. Normally these vectors are too complicated for the minimal rewards achieved for the amount of work, but given the nature of more high risk apps turning up on the market, the rewards are increasing.
An app may export several actions but it's careful only show up the login screen to outside attackers. Unable to login, the vector is closed right?
Well maybe. I was rather surprised on this one. Several apps developers are assuming that this is game over for the attacker and stop the protection there. I assume the point of this is that the phone user is using one app, passes some info across to the secure app at which point there is a prompt for password, limiting what information gets passed to only that which the user has permitted.
The issue is that if the user is already logged in, they are not prompted for their password. So if a user session exists, the doors are open to any app sending through information in this window. This could be done by an app without root permissions, so far more likely to make it through app store checks.
Either the app could try to indirectly monitor for when the app is in use, such as reading the log files, or just blindly hit the app every 5 minutes.


 Firstly Exported=0x0 is your friend. Everything should be explicitly not exported unless absolutely required.
 Secondly, always require user interaction before doing anything. Even validating the input before asking the user to confirm it allows for foreign arguments to be processed in your app. One mistake in this area of code means a vulnerability that could be exploited. If the user is using the phone, having one simple confirmation pop up won't hurt user experience, and scuppers the attack.

Wednesday, 6 June 2012

Alternative to DirBuster -

Often when testing, I need to run an automated scan for common directories on a web site. The traditionally recommended tool for brute forcing directories is DirBuster. Unfortunately along with occasionally crashing, it also kept filling the results with irritating 500 error files and other bad results requiring manually sifting.
After getting annoyed once too often with DirBuster, I went ahead and built one that was tailored to my own needs. It has the following useful features:
- selecting file types to search for
- HTTP return codes to ignore
- Depth to search to
- All the usual functions

The python source can be grabbed here and an example list of directories and files to try can be downloaded here. Hopefully it will provide a few of you with a much needed alternative.

Tuesday, 5 June 2012

PS3 HDMI fix

Well it takes suffering to learn things. I just hope this one was worth it. I've just spent the best part of an hour trying to fix my PS3 after installing a bf3 update. The screen went blank and there was no sound or video.

"Oh God it's broken my PS3!"

Well close but no cigar. It actually broke the HDMI connection between the PS3 and my television. So to fix it turn off (i.e. unplug) both the PS3 AND the television. Restart and fixed.

Tuesday, 22 May 2012

CMS exploits

A path to experience

CMS exploit development has been running rampant around places like exploit-db for ages. I took to doing a few of my own with positive results a few months back. But why is it so popular? And is it really worth doing?

CMS sploiting for fun '; -- and profit

Content Management Systems (CMS), are used to make developing and running web sites simple. They come fully loaded with useful tools and db plugins, giving a quick, professional look. No wonder they are used in their droves to produce many of the web sites we visit. There are many to choose from and range from the strictly amateur to the professional/expensive.
Exploit development has been a serious past-time for the following reasons:
    - Many of them are open source
    - They can be set up offline, speeding up/legalising the hacking process
    - They are used in real life, so the results of finding vulns are more rewarding

CMSs are therefore a cheap, easy way to get into web exploit development and source code review. No wonder juniors everywhere are using them to cut their teeth on web app pen testing and exploit development.

But surely they have been done to death. Is it still worth it? Are their vulnerabilities out there?

CMS 2012

Certainly finding straight SQL injection on the home page is only going to be the case if you're looking at an old, poorly maintained or infrequently used CMS. Not really rewarding and unless you are just starting out, not very educational. You therefore have two options:
 #1 - Find low risk vulns (reflected XSS, CSRF)
 #2 - Dive into source code

I'm not going to talk about #1 aside from the fact that I'm not a fan. Instead I wanted to run through a better CMS analysis method. I'm afraid you will need to look at the source. This may take the fun out of it for most, but if you want to find a worthwhile vuln that is actually respectable, then you need to broaden your game.
    1. Start by grepping
        You need to know key functions that will give you the big wins. Things like exec(), sql_query() and fopen() are gold. If you can find these in the files, then you have a starting point.
    2. Find out their variables
        Do they take variables? If so start following the breadcrumbs. There are some basic tools for this but they aren't particularly good and may lead to false negatives. In any case, this is a learning process so take the time to do it by hand, at least at first. Are they in functions or classes? Are these functions or classes called anywhere?
    3. Edit the script to make life easier
        The joy of offline analysis is that you can change the code. Add in a few extra echos to help follow through the code as it gets executed. It won't be like that in the end, but then you will have the exploit ready and no longer need them.

That's really it. I wanted to write this because there is so much good development in the CMS community and they're getting stronger and stronger for it. It's also infinitely more rewarding to get code execution from a CMS that is really out there and being used. Far better than dull little unrealistic test sites. Just be ethical with your disclosure!

Wednesday, 9 May 2012

CSRF - improving the basic attack

CSRF is a low risk vuln for script kiddies

I think Cross site request forgery (CSRF, which I've always been alone in calling see-surf) gets a pretty bad rap, not least because script kiddies are flooding exploitdb with boring CSRF attacks against CMSs that no-one uses. But let's not write off CSRF as a bland client-side attack just because people are using it poorly. CSRF actually has very viable and useful applications that takes a little longer to create, but the results are totally worth it.

It all revolves around how we are trusted when we log in. Normally this means C-surfers go looking for all the functions that doesn't require creds or authentication to complete. Most half decent apps will therefore check and protect against this. But quite often they make a mistake.

A better surf

Lets take an example:
 Joe's email web portal allows users to log in and then allows passwords to be changed. Fearful of CSRFing, they make the user include their old password in the request. Solved! But of course the user is who they say they are, so don't limit them on retries when they get the password wrong....

Yep. We can run dictionary attacks through CSRF.

So is this so great? It's a little slow (maybe a couple of minutes to run through a decent dictionary and ultimately still limited to having people visit your site that have to be logged in to the site you want to hit to be vulnerable. So yes it's still a limited client side attack, but it's one that works on some pretty popular apps.
Just load a dictionary into a JavaScript array and run it in a loop. JavaScript can handle GET and POST.

The only problem is that it's blind. We could change 50 people's passwords with this attack, but how do we know it's worked, and to whom?

Consequences....did it work?

Obviously this is easy if there's other attack vectors, like XSS but then if you've got cross site, then you hardly need CSRFing. The important point here is that other lower vulns can be used alongside this one to build a more valid attack vector.

Enumeration of usernames allows trying the altered password against the list. As you're only trying one password on each account, it shouldn't cause a lockout.

CSRFing multiple points can make the attack victims more visible. Changing a profile value may be pretty lame by itself, but if it is done along side the password change, it would become a flag to compromised accounts.

Wednesday, 25 April 2012

SQLite Injection

There does seem to be a lack of information regarding SQLite injection. This is probably because SQLite is so limited compared to other SQL databases. However, it does seem that given Android (and iOS?) interest in using them, there is something to be said for writing up some basics and findings that I've had so far.

 I will try to write this from a more general SQLite injection angle rather than OS specific. First enumeration. Getting out the master database is fairly straight forward as long as your injection is early on. If you can get results posted to the screen the enumerating the database structure is easy:


The SQLITE_MASTER database holds descriptions of all the tables so is a quick win for enumeration. From there, more select statements will get you the rest.

If the injection point is not at the WHERE or SELECT clause then things may get a little more difficult. More particularly interesting when the injection is at the ORDER BY clause. This means that not only can you not add in the table to select from, but you also can't use a UNION statement to join it to a fresh select statement. I've yet to find a good way to solve this one so please, answers on a postcard.

This is just an introductory post. I want to cover effective manual blind SQLite injection but this will have to wait until next time.

The other area that I want to look into is the use of the "." commands. SQLite seems to have many extra functions, which I'm guessing can not be used through API calls. Perhaps the PHP exec() function might? It would certainly be good to know where, if anywhere, these values could be used, as it would allow inclusions of other files.

Finally I want to take a look at whether the values can be overwritten with long/specially formatted strings. The .db file could then be manipulated into becoming something else (okay so this one's a long shot, but worth taking a look at).

Stay tuned

Thursday, 2 February 2012

vmware quick fix

Quick solution to the "Taking ownership of this virtual machine failed" Error.

Go to the vmware image's folder and delete the .lck file