Club Hack Mag - Dec 2010

  • Published on

  • View

  • Download

Embed Size (px)


1st Indian "Hacking" Magazine


<p>Issue 2 Mar 2010 | Page - 1</p> <p>Issue 11 Dec2010 | Page - 2</p> <p>Issue 11 Dec2010 | Page - 3</p> <p>Android Reverse Engineering - A Kick StartIntroductionRecently, the open source mobile operating system Android has a large community of developers writing application programs that extend the functionality of supporting devices. It seems a lot of people are getting crazy about the Android platform these days (everyone is trying to buy an Android phone!). I dont have an Android cell phone but still, I did manage to learn a few tricks on this Linux + java clean room engineered platform. In this article I shall explain you with an example, the simple technique of reverse engineering a normal android application.</p> <p>published by Deurus and explained the steps involved to legally reverse engineer this application. And our objective (Dont get the wrong idea friends!) is to break the licensing scheme of this application. So to begin our journey we first need to get geared up. First we need the Android SDK and then the necessary tools. You can download the necessary files from these locations: Android SDK: ml Smali and baksmali: Dex2jar: Java decompiler: Deurus Android crackme 03: crackme03/</p> <p>Setting up the GroundFor the purpose of a demonstration, I have chosen an Android crackme application</p> <p>Issue 11 Dec2010 | Page - 4</p> <p>Getting Started with the GameDownload all these files to your hard disk. Unzip Android SDK to C:\. Unzip rest of the tools to C:\ android-sdk-windows\RE. If everything is in order you can start Android SDK manager from C:\android-sdkwindows\. Now it will give you a list of packages to download and install. We need to select at least one SDK platform to continue our quest. After downloading and installing, we can move on to creating a new Android Virtual Device.</p> <p>Issue 11 Dec2010 | Page - 5</p> <p>After creating AVD, we can start emulation by selecting AVD and clicking the start button. Within a few minutes we can see the emulator booting up and showing the phone screen. Thats it! We have our emulator up and running. Now we need to install the software (crackme, its legal!) to the emulator. For that you may have to get acquainted with Android debug bridge (adb). Installing an apk file is pretty simple; all you have to do is to run two commands from the Android SDK directory/tools.</p> <p>After the installation you can see the crackme icon from application menu.</p> <p>Issue 11 Dec2010 | Page - 6</p> <p>Now run the crackme by clicking on it. If everything went as expected you will see the crackme application on the screen. Now lets try to play with it a bit, pressing the check button with no inputs pops a message 'Min 4 chars', and if the check button is pressed with a proper name it pops up a message 'Bad boy'. Do remember these strings because we will be using them as our search keys when we deassemble the apk (actually the dex) files. Also note that we have two hardware ids and we need to find out what those exactly mean.</p> <p>Now for real Reverse EngineeringAs our crackme is up and running in the emulator, we can now move on to the reversing part. If you have read the apk file format, you can somewhat visualize it as an extended JAR file which essentially is a zip file. Now you can change the crackme file name from Crackme03.apk to and decompress it to any folder.</p> <p>Issue 11 Dec2010 | Page - 7</p> <p>Now the interesting file for us is the classes.dex, which contains the compiled virtual machine (vm) codes. We are now going to deassemble the dex file with baksmali. The commands are pretty simple as mentioned in the screen shots below.</p> <p>Our aim is now to understand the serial checking function and write a keygen for it. For which we have to know all the dalvik opcodes that are used here. You can visit this page ( vik_opcodes.html) to understand the opcodes and after that you can convert the disassembled code to much higher language constructs. Here, I will provide a brief code snippet which actually implements the algorithm. The two hardware ids used are the IMEI and the sim serial number. 01 //Read name from text box 02 const v23, 0x7f050004 03 invoke-virtual/range {v22 .. v23}, Lcom/example/helloandroid/HelloAndroid; -&gt;findViewById(I)Landroid/view/View; 04 move-result-object v9 05 06 //Read serial from text box 07 const v23, 0x7f050006 08 invoke-virtual/range {v22 .. v23}, Lcom/example/helloandroid/HelloAndroid; -&gt;findViewById(I)Landroid/view/View; 09 move-result-object v21 10 11 //Checking whether the name is of length greater than 4 12 const/16 v22, 0x4 13 move v0, v11 14 move/from16 v1, v22 15 if-ge v0, v1, :cond_51 16 17 //Popup showing Min 4 chars 18 const-string v23, "Min 4 chars" 19 const/16 v24, 0x1 20 .line 86</p> <p>If everything worked fine, we will have a folder structure similar to Java packages. Interesting .smali files are located at '\com\example\helloandroid'. Open all the .smali files into your favorite text editor(I use Notepad++). If you have never done anything related to reverse engineering/esoteric programming/assembly(IL) programming, dont start sweating. We have just opened a disassembled dex file. Next, if you are thinking that how on earth can someone find the correct location of a checking function, Well I hope you remember those pop up strings I told earlier. Yeah, 'Min 4 chars' and 'Bad boy'. It is time to use those strings as our search keys. After searching the Min 4 chars in all the opened .smali files, we will find a hit in the file HelloAndroid$2.smali, quite specifically line 130.</p> <p>Issue 11 Dec2010 | Page - 8</p> <p>21 invoke-static/range {v22 .. v24}, Landroid/widget/Toast;&gt;makeText(Landroid/content/Context;Ljav a/lang/CharSequence;I)Landroid/widget/T oast; 22 move-result-object v13 23 .line 88 24 .local v13, notificacionToast:Landroid/widget/Toast; 25 invoke-virtual {v13}, Landroid/widget/Toast;-&gt;show()V 26 27 //There is a little exception trick to make integer string from username 28 //It converts aaaa to 97979797 which is ascii equivalent 29 invoke-virtual {v10, v5}, Ljava/lang/String;-&gt;charAt(I)C 30 move-result v3 31 32 //Getting first 5 chars from ascii converted name 33 const/16 v22, 0x0 34 const/16 v23, 0x5 35 move-object v0, v12 36 move/from16 v1, v22 37 move/from16 v2, v23 38 invoke-virtual {v0, v1, v2}, Ljava/lang/String;&gt;substring(II)Ljava/lang/String; 39 40 //Converting it into integer and xoring with 0x6B016 - Serial part 1 41 invoke-static {v12}, Ljava/lang/Integer;&gt;parseInt(Ljava/lang/String;)I 42 move-result v22 43 const v23, 0x6b016 44 xor-int v22, v22, v23 45 46 //Getting IMEI from TelephonyManager 47 // Android/telephony/TelephonyManager.htm l 48 invoke-virtual {v8}, Landroid/telephony/TelephonyManager;&gt;getDeviceId()Ljava/lang/String; 49 move-result-object v6 50 .line 102 51 .local v6, imei2:Ljava/lang/String; 52</p> <p>53 //Getting sim serial 54 invoke-virtual {v8}, Landroid/telephony/TelephonyManager;&gt;getSimSerialNumber()Ljava/lang/String; 55 move-result-object v16 56 .line 103 57 .local v16, simsn:Ljava/lang/String; 58 59 //Getting first 6 chars from IMEI, and similarly from sim serial (IMEI.Substring(0,6) will be used as Serial part 3) 60 const/16 v22, 0x0 61 const/16 v23, 0x6 62 move-object v0, v6 63 move/from16 v1, v22 64 move/from16 v2, v23 65 invoke-virtual {v0, v1, v2}, Ljava/lang/String;&gt;substring(II)Ljava/lang/String; 66 67 //Converting them to integer and xoring - Serial part2 68 invoke-static/range {v19 .. v19}, Ljava/lang/Integer;&gt;parseInt(Ljava/lang/String;)I 69 move-result v22 70 invoke-static/range {v20 .. v20}, Ljava/lang/Integer;&gt;parseInt(Ljava/lang/String;)I 71 move-result v23 72 xor-int v22, v22, v23 73 74 //Making a new StringBuilder object and formatting the string to part1-part2-part3 75 new-instance v22, Ljava/lang/StringBuilder; 76 invoke-static {v12}, Ljava/lang/String;&gt;valueOf(Ljava/lang/Object;)Ljava/lang/St ring; 77 move-result-object v23 78 invoke-direct/range {v22 .. v23}, Ljava/lang/StringBuilder;&gt;(Ljava/lang/String;)V 79 const-string v23, "-" 80 invoke-virtual/range {v22 .. v23}, Ljava/lang/StringBuilder;&gt;append(Ljava/lang/String;)Ljava/lang/Str ingBuilder; 81 move-result-object v22 82 invoke-static/range {v17 .. v18},</p> <p>Issue 11 Dec2010 | Page - 9</p> <p>Ljava/lang/String;&gt;valueOf(J)Ljava/lang/String; 83 move-result-object v23 84 invoke-virtual/range {v22 .. v23}, Ljava/lang/StringBuilder;&gt;append(Ljava/lang/String;)Ljava/lang/Str ingBuilder; 85 move-result-object v22 86 const-string v23, "-" 87 invoke-virtual/range {v22 .. v23}, Ljava/lang/StringBuilder;&gt;append(Ljava/lang/String;)Ljava/lang/Str ingBuilder; 88 move-result-object v22 89 move-object/from16 v0, v22 90 move-object/from16 v1, v19 91 invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;&gt;append(Ljava/lang/String;)Ljava/lang/Str ingBuilder; 92 move-result-object v22 93 94 //Checking whether user entered serial and program made serials are equal. 95 invoke-virtual {v14, v15}, Ljava/lang/String;&gt;equals(Ljava/lang/Object;) As you can see, the algorithm is pretty straight forward. It is using name and two hardware ids as input and doing some operations on them to make a serial. We can quite easily recode it in any programming language that we prefer to make it as a keygen. Anyways, I am not posting any keygen sources as it will spoil the whole phun!</p> <p>At first 'aaaaa' will be converted to '9797979797', from which we will take first 5 letters and convert it into integer 97979 This will be xored with 0x6B016 resulting 511661 and this will be the first part of serial. For the second part, we will take the first 6 letters from HW ID1 and HW ID2, convert them to integer and xor, resulting 000000^890141 = 890141. For the third part we will use the first 6 characters from HW ID1. Formatting with the specified delimiter the serial will become '511661-890141-000000'.</p> <p>Decoding the AlgorithmA demonstrative serial calculation routine is given below: Name: aaaaa HW ID1: 0000000000000000 HW ID2: 89014103211118510720 Here are stepwise instructions generating final serial number on</p> <p>Issue 11 Dec2010 | Page - 10</p> <p>Final Verification of ReversingNow let us put the same magic number into our Crackme application. Bingo! Everything worked as expected. Now, for all those who think it is pretty hard to read all those deassembled instructions and manually converting them to higher language constructs, there are other options. As dalvik is based on the design of Java, it is also susceptible to decompilation. There is no decompiler available at this moment, but there is a hope. For now we can use another utility which converts dex files to jar files so that we can use Java decompilers to see much more abstracted code. From the starting of this article you may have noticed a tool dex2jar. You can use the dex2jar to convert classes.dex to classes.dex.dex2jar.jar. Open it in a Java decompiler and you can see much better output than dalvik disassembly. Please note that dex2jar is still in a development phase and the output you get could be meaningless in many</p> <p>places. This should be used only to get a quick understanding of all the functions.</p> <p>ConclusionIn this introductory article, I explained reversing of an Android application using the emulator and all available tools in sequence with pictorial elaborative steps. It is mainly based to set up your ground for further reversing work on Android Platform. Well, thats it! We have analyzed an Android program and defeated its protection. Cheerio!</p> <p>Dhanesh kDhanesh is a software engineer specialized in .NET programming. In his spare time he works on Win32 reversing and malware analysis.</p> <p>Issue 11 Dec2010 | Page - 11</p> <p>Android Security AppsAndroid is creating some (a lot actually!) buzz all over with all its awesome user friendly features and apps. Millions of applications and games are available to choose from. Our phones have all sorts of personal data messages, photos, etc. At some point these apps access your data. And as we all know data=money, so lets have a look at some apps that will help you protect your data and privacy.</p> <p>provides anti-virus protection, malware and spyware blocking functions. It also scans every app installed on your phone thus preventing you from using those apps in future.</p> <p>If you loose your phone, you can track your phones location via locate phone on map feature. It basically sounds an alarm from the device itself when asked to track it. Another good feature of this app is that it allows you to backup and restore your data, like contact, photos, text messages and emails etc. All in one package huh! And guess what? It is a freeware! You can get it here</p> <p>Malware and Theft Protection AppsHere are few apps that will help you protect your data, privacy.</p> <p>1. Lookout Mobile SecurityThis is one of the good apps protecting your phone from viruses, data loss, etc. This app</p> <p>Issue 11 Dec2010 | Page - 12</p> <p>2. WaveSecureAnother good all-in-one app that protects your data and privacy. It can track the location of your phone incase its stolen or misplaced by you. It basically sends a sms alert to a pre-defined contact. It has this</p> <p>amazing ability to locate, lock and wipe a device remotely. Yes! you can WIPE your data remotely if your phone is not found. Though it does not provide anti-virus protection, it does provide backup and restore facility. Recently, WaveSecure was McAfee. acquired by</p> <p>The Protector allows users to password protect various Android apps including Chat, Notepad, Calendar, Photos, Setting, Email, Gmail and even their SMS inbox. One negative aspect of this app is that it does not provide a pin recovery service. So it can create a lot of problems if you forget or lose your pin code. And one more good thing its FREE!! URL: -</p> <p>URL: android.aspx</p> <p>4. Norton Mobile SecurityThis app has got almost same features as that of apps mentioned above. Like tracking, remote lock-and-wipe ability, anti-virus etc.</p> <p>3. ProtectorIt enables users to password protect any application stored on their phone. This security app takes it one step further by enabling users to even password protect any feature of an existing app on your phone. Many users will experience the benefits of this security app.</p> <p>Issue 11 Dec2010 | Page - 13</p> <p>In addition to this, you can block or control incoming calls and sms of some person from your call log. Again, its free! URL: -</p> <p>URL: - Few more app you can use Smobile AntiTheft, aFirewall. I hope this will help you decide which app to use and protect your data. Be Safe </p> <p>5. SMobile Security ShieldThis app comes in two flavors one with Anti-Vir...</p>