首页
论坛
课程
招聘
[分享]分析xx输入法
2022-2-24 23:26 19941

[分享]分析xx输入法

2022-2-24 23:26
19941

分析xxx输入法

解包与封包

  • 解包

    1
    java -jar apktool_2.6.0.jar d xxx_lastold.apk -o bdold

    image-20220211212405835

  • 封包

    1
    java -jar apktool_2.6.0.jar b bdold -o xxx.apk

    封包后发现执行会崩溃。

    经过调试后发现存在反调试,删除掉反调试的代码。

过签名检验

xxx输入法v4.2.1.32

总体思想:
app本身没有做太多的防护,只有一个签名校验。
签名校验的位置在inputcore_20131125文件中的Java_com_xxx_input_PlumCore_PlInit函数中。

 

image-20220211213158042

 

image-20220211215054587

 

image-20220211215427962

PlInit为inputcore_20131125中的原生函数。

 

image-20220211215956165

注释掉checkState函数。

原来的汇编指令:
03 F0 DD F9 BL _Z10checkStatei ; checkState(int)
将这句话注释掉,修改为:
00 00 MOVS R0, R0
00 00 MOVS R0, R0

xxx输入法v5.0.1.6

和v4一致.

 

修改前

 

修改后

 

注释checkState函数。

1
2
3
4
5
6
原汇编:
03 F0 41 F9 BL      _Z10checkStatei ; checkState(int)
 
修改为:
00 00       MOVS    R0, R0
00 00       MOVS    R0, R0

xxx输入法v10.9.5.25

主要过程和v4差不多。在lib中分析libiptcore.so

 

搜索字符串signature很容易定位到下面的代码。

 

计算Hash

 

调用计算Hash

 

这里的代码逻辑非常的清晰,想要去除Hash校验的方法有很多,例如:

  • if条件取反。
  • if-else代码全部删除,在调用sub_38DB8,直接给定参数0

我这里简单一点,直接修改if跳转。

 

修改前

 

修改后

 

重新打包后,安装进手机发现能够正常运行了。

修改原包名

xxx输入法v4.2.1.32

总体思想:

修改AndroidManifest.xml和smali汇编中有关包名这部分的内容。

注意:

  1. 修改完AndroidManifest.xml和smali汇编后封包的时候可能有些错误。这是由于资源中包名的部分没有修改,根据提示进行修改。
  2. 在so中可能存在反射调用的问题,需要在so中进行同步修改。
 

这里将原包名com.xxx.input修改为com.xxx.imput

AndroidManifest.xml

  • Line 1

    1
    <?xml version="1.0" encoding="utf-8" standalone="no"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="internalOnly" package="com.xxx.imput">
  • Line 56

    1
    <activity android:configChanges="keyboardHidden|orientation|screenSize" android:excludeFromRecents="true" android:name=".ImeCellManActivity" android:taskAffinity="com.xxx.imput.cell" android:theme="@android:style/Theme.NoTitleBar"/>
  • Line 57

    1
    <activity android:configChanges="keyboardHidden|orientation|screenSize" android:excludeFromRecents="true" android:name=".ImeThemeActivity" android:taskAffinity="com.xxx.imput.theme" android:windowSoftInputMode="adjustPan"/>
  • Line 61

    1
    <activity android:configChanges="keyboardHidden|orientation|screenSize" android:excludeFromRecents="true" android:name=".ImeListEditorActivity" android:noHistory="true" android:taskAffinity="com.xxx.imput.listeditor" android:theme="@android:style/Theme.Dialog"/>
  • Line 78

    1
    <action android:name="com.xxx.imput.action.INSTALL"/>

res

重新封包时发现以下错误:

1
2
3
W: G:\nom\bd_bugai\res\layout\emoji_detail.xml:17: error: No resource identifier found for attribute 'textSize' in package 'com.xxx.input'
W:
W: G:\nom\bd_bugai\res\layout\emoji_item.xml:13: error: No resource identifier found for attribute 'textSize' in package 'com.xxx.input'
emoji_detail.xml
  • Line 4

    1
    xmlns:xxx="http://schemas.android.com/apk/res/com.xxx.imput">
  • Line 15

    1
    <com.xxx.imput.layout.widget.PageGalleryView android:id="@id/gallery" android:layout_width="0.0dip" android:layout_height="0.0dip" android:layout_marginLeft="32.0dip" android:layout_marginRight="32.0dip" />
  • Line 16

    1
    <com.xxx.imput.layout.widget.HintSelectionView android:id="@id/hint" android:layout_width="fill_parent" android:layout_height="6.0dip" android:layout_marginLeft="82.0dip" android:layout_marginTop="12.0dip" android:layout_marginRight="82.0dip" android:layout_marginBottom="24.0dip" />
  • Line 17

    1
    <com.xxx.imput.layout.widget.DownloadButton android:id="@id/button" android:background="@drawable/guide_btef" android:layout_width="fill_parent" android:layout_height="34.0dip" android:layout_marginLeft="36.0dip" android:layout_marginRight="36.0dip" xxx:textSize="14.0dip" />
emoji_item.xml
  • Line 4

    1
    xmlns:xxx="http://schemas.android.com/apk/res/com.xxx.imput">
  • Line 13

    1
    <com.xxx.imput.layout.widget.DownloadButton android:id="@id/button" android:background="@drawable/guide_btef" android:layout_width="fill_parent" android:layout_height="26.0dip" android:layout_marginTop="20.0dip" android:layout_below="@id/thumb" android:layout_alignLeft="@id/thumb" android:layout_alignRight="@id/thumb" xxx:textSize="12.0dip" />

smali汇编

  • 需要修改的smali文件的数量特别多,采用代码修改。

  • 在smali汇编中包名中的.被替换成/

    1
    2
    3
    4
    5
    6
    public class Main {
        public static void main(String[] args) {
            UpdateFile updateFile = new UpdateFile("G:\\nom\\bd_bugai\\smali\\com", "Lcom/xxx/input", "Lcom/xxx/imput");
            updateFile.updateFiles();
        }
    }
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    import java.io.*;
    import java.util.List;
     
    public class UpdateFile {
        private String mCWD;
        private String mOldPkgName;
        private String mNewPkgName;
     
        UpdateFile(String cwd, String oldPkg, String newPkg) {
            mCWD = cwd;
            mOldPkgName = oldPkg;
            mNewPkgName = newPkg;
        }
     
        public void updateFiles() {
            updateFiles(mCWD);
        }
        private void updateFiles(String dir) {
            File file = new File(dir);
            File[] files = file.listFiles();
            for (File f : files) {
                if (f.isDirectory()) {
                    updateFiles(f.getAbsolutePath());
                } else {
                    System.out.println(f.getAbsolutePath());
                    update(f.getAbsolutePath());
                }
            }
        }
     
        private void update(String filePath) {
            BufferedReader br = null;
            String line = null;
            StringBuffer buf = new StringBuffer();
            try {
                // 根据文件路径创建缓冲输入流
                br = new BufferedReader(new FileReader(filePath));
                // 循环读取文件的每一行, 对需要修改的行进行修改, 放入缓冲对象中
                int lineNum = 1;
                while ((line = br.readLine()) != null) {
                    // 此处根据实际需要修改某些行的内容
                    if (line.contains(mOldPkgName)) {
                        String update = line.replaceAll(mOldPkgName, mNewPkgName);
                        buf.append(update);
                        System.out.println("    ["+lineNum+"]"+line);
                        System.out.println("    ["+lineNum+"]"+update);
                        System.out.println();
                    }
                    // 如果不用修改, 则按原来的内容回写
                    else {
                        buf.append(line);
                    }
                    buf.append("\n");
                    lineNum++;
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                // 关闭流
                if (br != null) {
                    try {
                        br.close();
                    } catch (IOException e) {
                        br = null;
                    }
                }
            }
     
            BufferedWriter bw = null;
            try {
                // 根据文件路径创建缓冲输出流
                bw = new BufferedWriter(new FileWriter(filePath));
                // 将内容写入文件中
                bw.write(buf.toString());
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                // 关闭流
                if (bw != null) {
                    try {
                        bw.close();
                    } catch (IOException e) {
                        bw = null;
                    }
                }
            }
        }
    }

so文件修改

image-20220211221005093

 

搜索字符串,然后可以把这些字符串进行修改。然后封包发现终于可以正常运行了。


系统0day安全 - 二进制漏洞攻防

收藏
点赞2
打赏
分享
最新回复 (1)
雪    币: 18
活跃值: 活跃值 (82)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
无名小姐 活跃值 2022-4-5 20:05
2
0
666
游客
登录 | 注册 方可回帖
返回