Home Operation and Maintenance Safety How to perform static analysis in Android

How to perform static analysis in Android

May 11, 2023 pm 10:28 PM
android

Android reverse engineering is the process of decompilation. Because the result of Android forward compilation cannot be understood, the premise of static analysis in CTF is to decompile the appearing files to a layer of source code that we can understand and perform static analysis.

0X01 Basic description

The logic code of Android application is developed by Java, so the first layer is java code

Java virtual machine JVM runs java file compilation The subsequent class file

The Android virtual machine Dalvik is not the class file generated after executing the Java virtual machine JVM compilation, but the smali file compiled after executing and re-integrating the dex file generated after packaging

APK: It is the compiled Android application installation package

dex file: It is the packaging file of the class file

smali file: It is the Dalvik bytecode file

class File: It is a JVM bytecode file

0X02 Tool usage

The Android question in CTF does not necessarily give you the complete compiled APK, it may be any file type during the compilation process, as follows Brother divides the following file types and uses tools to get the java source code that Brother Dou can understand

Type 1: class file

This situation is relatively simple, the recommended tool jd-gui

Just pull the class file in and you can see the java source code.


How to perform static analysis in Android

Type 2: APK program

After the Android project is compiled, we will get the APK installation package we want. The APK file is actually A compressed package.

Change the suffix to zip and unzip it. The unzipped file is as shown below:


How to perform static analysis in Android

META-INF folder:

Stores apk signature information to ensure the integrity of the apk package and the security of the system.

res folder:

Stores resource files, including icon and xml files.

AndroidManifest.xml file:

Application configuration file, each application must be defined and included. It describes the application name, version, permissions, referenced library files and other information.

classes.dex file:

The file that can be loaded and run directly on the Dalvik virtual machine is compiled and generated by the IDE from the java file.

resources.arsc file>

Binary resource file, including strings, etc.

Recommended tools for decompiling APK: ApkIDE, JEB

1. JEB usage:

JEB directly imports the APK, and you will see the smali file after decompilation is completed.


How to perform static analysis in Android

Many Android reverse engineering tools decompile to smali files.

JEB Select the smali file and press Q to see the java file.


How to perform static analysis in Android

Advantages: The code structure of the java file decompiled from the smali file is clear.

Disadvantages: Cannot be modified.

2. Use ApkIDE:

Project->Open Apk

Wait for decompilation to complete.


How to perform static analysis in Android

See the smali file.

How to perform static analysis in Android

Select the smali file that requires Java source code and click the button below to open the Java source code.

How to perform static analysis in Android

ApkIDE is associated with jd-gui. Clicking it will jump to jd-gui.

How to perform static analysis in Android

ApkIDE decompiles the APK into class and then uses jd-gui to get the Java source code.

You can see the decompiled class file in the project directory of ApkIDE's ApkIDE_v3.3\ApkIDE\Worksrc.

How to perform static analysis in Android

#Advantages: Powerful, you can modify the decompiled smali file and recompile to generate APK.

Disadvantages: The compiled java code is not clear enough.

3. Decompilation difference

Smali files are written in Smali syntax, and Smali syntax is a loose syntax

So the decompilation process is different, the tools are different, and the java source code is definitely different

The following is the result of reversing the same APK using the above two tools:

How to perform static analysis in Android

How to perform static analysis in Android

Brother Dou is a Java Development enthusiasts like JEB's reverse engineering results, which are more comfortable to watch.

Type 3: dex file

Recommended tool dex2.jar

classes.dex file, this is a bytecode package compiled from Android source code

Try to use the dex2.jar tool to get the java source code command as follows

.\d2j-dex2jar.bat C:\Users\lin\Desktop\classes.dex


How to perform static analysis in Android

The jar file can be understood as a compressed package of the classes file, and the java virtual machine can be run directly

Use Jd-gui to open classes-dex2jar. jar, you can see the java source code


How to perform static analysis in Android

Type 4: smali file

It cannot be used when there is only a single smali file The above tools directly decompile

Brother Dou thought that ApkIDE can decompile an APK into a smali file, and add, delete, modify and check the smali file

So he used ApkIDE to open any complete APK and then add the smali file (the APK can be developed by yourself)


How to perform static analysis in Android

Add the smali file to the ApkIDE project.


How to perform static analysis in Android

Recompile to generate APK.

How to perform static analysis in Android

#After successful compilation, an APK will be generated in the original APK directory.


How to perform static analysis in Android

Then open it with JEB and other tools to see the Ezreal.smali file.


How to perform static analysis in Android

Other tools:

Editor: notepad, Sublime, etc.

Android emulator: Night God Simulation Device, etc.

0X04 Example analysis

Install the application into the simulator and check whether there are any prompts on the interface.

Enter characters in the text box and click the button to prompt an error. I guess it is used to determine the correct flag.


How to perform static analysis in Android

Use the JEB tool to compile it into a java file. Under the Android file is the sdk file. We want to analyze the source code file under the com package.


How to perform static analysis in Android

There are only three categories of code. First, analyze the program entry MainActivity to find the key code blocks.

This if sentence is to determine whether the flag is correct.

How to perform static analysis in Android

# Search the class to see where this method is called.

The analysis shows that arg12 is the parameter to be entered in the interface. At this time, we know that the value of v5 is the flag we want.


How to perform static analysis in Android

The onCreate function calls the checkSN method and passes in two parameters:

MainActivity.this.edit_userName.trim()

MainActivity.this.edit_sn.getText().toString().trim()

//OnCreate is a special function in Android, used to "indicate that a window is being generated" .

//It does not generate a window, but only sets the properties of the window such as style, position color, etc. before the window is displayed.

public void onCreate(Bundle arg3) {

super.onCreate(arg3);

this.setContentView(0x7F040019);

this.setTitle( 0x7F06001D);

this.edit_userName = "Tenshine";

this.edit_sn = this.findViewById(0x7F0C0051);

this.btn_register = this.findViewById(0x7F0C0052) ;

this.btn_register.setOnClickListener(new View$OnClickListener() {

public void onClick(View arg5) {

if(!MainActivity.this.checkSN(MainActivity .this.edit_userName.trim(), MainActivity.this.edit_sn.getText().toString().trim())) {

               Toast.makeText(MainActivity.this, 0x7F06001E, 0).show( );

}

Else {

Toast.maketext (mainactivity.this, 0x7f06001b, 0) .Show ();

## MainActivity.this. btn_register.setEnabled(false);

MainActivity.this.setTitle(0x7F060019);

}

});

}

Analyze the value of v5. v5 is generated by v3 and v4. v4 is an int and is directly assigned to 0 for looping. You can use it directly

and v3 is the toHexString method. The return value needs to be passed in, v1 is v1.update(arg11.getBytes()); generated

arg11 is the passed in parameter "Tenshine"

private boolean checkSN(String arg11, String arg12) {

   boolean v7 = false;

   if(arg11 != null) {

       try {

           if(arg11.length() == 0) {

               return v7;

           }

           if(arg12 == null) {

               return v7;

           }

           if(arg12.length() != 22) {

               return v7;

           }

           MessageDigest v1 = MessageDigest.getInstance("MD5");

           v1.reset();

           v1.update(arg11.getBytes());

           String v3 = MainActivity.toHexString(v1.digest(), "");

           StringBuilder v5 = new StringBuilder();

           int v4;

           for(v4 = 0; v4

               v5.append(v3.charAt(v4));

           }

           if(!"flag{" v5.toString() "}".equalsIgnoreCase(arg12)) {

               return v7;

           }

       }

       catch(NoSuchAlgorithmException v2) {

           goto label_40;

       }

       v7 = true;

   }

   return v7;

label_40:

   v2.printStackTrace();

   return v7;

}

将上面的分析结果,取出生成v5的关系代码

都是纯java代码,不需要Android的包引入,只需引入java的依赖包。

import java.security.MessageDigest;

import java.security.NoSuchAlgorithmException;

public class Code {

   static String toHexString(byte[] arg8, String arg9) {

       StringBuilder v3 = new StringBuilder();

       byte[] v0 = arg8;

       int v5 = v0.length;

       int v4;

       for(v4 = 0; v4

           String v2 = Integer.toHexString(v0[v4] & 255);

           if(v2.length() == 1) {

               v3.append('0');

           }

           v3.append(v2).append(arg9);

       }

       return v3.toString();

   }

   public static void main(String[] args)throws NoSuchAlgorithmException{

       MessageDigest v1 = MessageDigest.getInstance("MD5");

       v1.reset();

       v1.update("Tenshine".getBytes());

       String v3 = Code.toHexString(v1.digest(), "");

       StringBuilder v5 = new StringBuilder();

       int v4;

       for(v4 = 0; v4

           v5.append(v3.charAt(v4));

       }

       System.out.println("flag{" v5.toString() "}");

   }

}

用IDEA编辑运行,拿到flag。


How to perform static analysis in Android

The above is the detailed content of How to perform static analysis in Android. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1667
14
PHP Tutorial
1273
29
C# Tutorial
1255
24
New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades Sep 12, 2024 pm 12:23 PM

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

Samsung Galaxy S25 Ultra leaks in first render images with rumoured design changes revealed Samsung Galaxy S25 Ultra leaks in first render images with rumoured design changes revealed Sep 11, 2024 am 06:37 AM

OnLeaks has now partnered with Android Headlines to provide a first look at the Galaxy S25 Ultra, a few days after a failed attempt to generate upwards of $4,000 from his X (formerly Twitter) followers. For context, the render images embedded below h

IFA 2024 | TCL\'s NXTPAPER 14 won\'t match the Galaxy Tab S10 Ultra in performance, but it nearly matches it in size IFA 2024 | TCL\'s NXTPAPER 14 won\'t match the Galaxy Tab S10 Ultra in performance, but it nearly matches it in size Sep 07, 2024 am 06:35 AM

Alongside announcing two new smartphones, TCL has also announced a new Android tablet called the NXTPAPER 14, and its massive screen size is one of its selling points. The NXTPAPER 14 features version 3.0 of TCL's signature brand of matte LCD panels

Vivo Y300 Pro packs 6,500 mAh battery in a slim 7.69 mm body Vivo Y300 Pro packs 6,500 mAh battery in a slim 7.69 mm body Sep 07, 2024 am 06:39 AM

The Vivo Y300 Pro just got fully revealed, and it's one of the slimmest mid-range Android phones with a large battery. To be exact, the smartphone is only 7.69 mm thick but features a 6,500 mAh battery. This is the same capacity as the recently launc

Samsung Galaxy S24 FE billed to launch for less than expected in four colours and two memory options Samsung Galaxy S24 FE billed to launch for less than expected in four colours and two memory options Sep 12, 2024 pm 09:21 PM

Samsung has not offered any hints yet about when it will update its Fan Edition (FE) smartphone series. As it stands, the Galaxy S23 FE remains the company's most recent edition, having been presented at the start of October 2023. However, plenty of

New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades New report delivers damning assessment of rumoured Samsung Galaxy S25, Galaxy S25 Plus and Galaxy S25 Ultra camera upgrades Sep 12, 2024 pm 12:22 PM

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

Xiaomi Redmi Note 14 Pro Plus arrives as first Qualcomm Snapdragon 7s Gen 3 smartphone with Light Hunter 800 camera Xiaomi Redmi Note 14 Pro Plus arrives as first Qualcomm Snapdragon 7s Gen 3 smartphone with Light Hunter 800 camera Sep 27, 2024 am 06:23 AM

The Redmi Note 14 Pro Plus is now official as a direct successor to last year'sRedmi Note 13 Pro Plus(curr. $375 on Amazon). As expected, the Redmi Note 14 Pro Plus heads up the Redmi Note 14 series alongside theRedmi Note 14and Redmi Note 14 Pro. Li

Motorola Razr 50s shows itself as possible new budget foldable in early leak Motorola Razr 50s shows itself as possible new budget foldable in early leak Sep 07, 2024 am 09:35 AM

Motorola has released countless devices this year, although only two of them are foldables. For context, while most of the world has received the pair as the Razr 50 and Razr 50 Ultra, Motorola offers them in North America as the Razr 2024 and Razr 2

See all articles