admin_user 发表于 2015-3-11 14:08:26

逆向360加固等dex被隐藏的APK

1.static void Main(string[] args)
2.      {
3.      REBEGIN:
4.            Console.WriteLine("请输入gcore出来的文件路径:");
5.
6.            string filepath = Console.ReadLine();
7.
8.            if (!File.Exists(filepath))
9.            {
10.                Console.WriteLine("指定的文件不存在,请输入正确的文件路径\r\n");
11.                goto REBEGIN;
12.            }
13.
14.            new DirectoryInfo(filepath + ".dex").Create();
15.
16.            FileStream fs = new FileStream(filepath, FileMode.Open);
17.            long flen = fs.Length;
18.            BinaryReader br = new BinaryReader(fs);
19.
20.            byte[] bs = br.ReadBytes((int)flen);
21.
22.            fs.Close();
23.
24.            int bsl = bs.Length;
25.
26.
27.            for (int i = 0; i < bsl - 100; i++)
28.            {
29.                if (bs == 'd' && bs == 'e' && bs == 'x' && bs == 10 && bs == '0' && bs == '3' && bs == '5')
30.                {
31.                  string a1 = bs.ToString("x2");
32.                  string a2 = bs.ToString("x2");
33.                  string a3 = bs.ToString("x2");
34.                  string a4 = bs.ToString("x2");
35.
36.                  string hexlen = a1 + a2 + a3 + a4;
37.                  int dexlength = Int32.Parse(hexlen, System.Globalization.NumberStyles.HexNumber);
38.
39.                  byte[] dex_tmp = new byte;
40.
41.                  int h = 0;
42.                  for (int j = i; j < (i + dexlength); j++)
43.                  {
44.                        dex_tmp = bs;
45.                  }
46.
47.                  File.WriteAllBytes(filepath + ".dex\\" + i + ".dex", dex_tmp);
48.
49.
50.                }
51.            }
52.
53.            Console.WriteLine("所有的DEX文件已经输出到文件夹" + filepath + ".dex\\");
54.
55.            while (true)
56.            {
57.                Console.Read();
58.            }
59.
60.
61.      }



如果遇到apk中的lib文件夹中是这样的
http://www.heishou.com.cn/attachment/Mon_1503/157_1_29f10b7570b2c01.png?7
基本没有dex文件可以反编译,这中的dex文件一般都是加密混淆压缩后放在so中啦。
但是软件要想运行就需要解出dex字节码然后加载到手机内存中,这样就可以在软件运行过程中把dex提取出来再使用相应的软件反编译成smail啦,接着就是转成java。
好啦,第一次发帖子,以下就是干货。

首先下载附件中的
gdb.7z.001.rar (2.00 MB)   
gdb.7z.002.rar (1.21 MB)
把这两个文件的后缀名去掉使用7zip解压出来二进制文件gdb (大约13MB)
打开安卓虚拟机,把需要逆向的加壳软件安装的虚拟机中,然后启动APK。

1、使用ADB把gdb push到手机中
adb push /home/down/gdb /data/local/tmp/gdb

2、找到需要逆向的apk对应linux的进程pid
adb 中执行
adb shell
top
会显示手机中全部的进程,然后找到进程名字为apk包名的pid (在此假设pid为 482)

3、赋予gdb权限(依次执行以下命令)
adb shell
su
cd /data/local/tmp/
chmod 777 gdb

4、dump进程482的内存
./gdb --pid 482
此时进入了gdb模式
这个时候输入 gcore 会dump到当前目录 /data/local/tmp/core.482
把这个core.482的文件放到安装了.net 3.5 的电脑上(win7默认是可以得)
比如放到以下位置
D:\core.482

5、下载附件中的 DumpAllDEX.7z 解压出文件 DumpAllDEX.exe
运行





就会把所有的dex文件提取到D:\core.482.dex 文件夹中。

6、逐个反编译提取出来的dex文件,直到找到你要逆向的软件dex。这个时候就可以开开心心的转成java看源码啦。

DumpAllDEX.exe 为C#写的,源码如下:
代码:
复制代码
1.static void Main(string[] args)
2.      {
3.      REBEGIN:
4.            Console.WriteLine("请输入gcore出来的文件路径:");
5.
6.            string filepath = Console.ReadLine();
7.
8.            if (!File.Exists(filepath))
9.            {
10.                Console.WriteLine("指定的文件不存在,请输入正确的文件路径\r\n");
11.                goto REBEGIN;
12.            }
13.
14.            new DirectoryInfo(filepath + ".dex").Create();
15.
16.            FileStream fs = new FileStream(filepath, FileMode.Open);
17.            long flen = fs.Length;
18.            BinaryReader br = new BinaryReader(fs);
19.
20.            byte[] bs = br.ReadBytes((int)flen);
21.
22.            fs.Close();
23.
24.            int bsl = bs.Length;
25.
26.
27.            for (int i = 0; i < bsl - 100; i++)
28.            {
29.                if (bs == 'd' && bs == 'e' && bs == 'x' && bs == 10 && bs == '0' && bs == '3' && bs == '5')
30.                {
31.                  string a1 = bs.ToString("x2");
32.                  string a2 = bs.ToString("x2");
33.                  string a3 = bs.ToString("x2");
34.                  string a4 = bs.ToString("x2");
35.
36.                  string hexlen = a1 + a2 + a3 + a4;
37.                  int dexlength = Int32.Parse(hexlen, System.Globalization.NumberStyles.HexNumber);
38.
39.                  byte[] dex_tmp = new byte;
40.
41.                  int h = 0;
42.                  for (int j = i; j < (i + dexlength); j++)
43.                  {
44.                        dex_tmp = bs;
45.                  }
46.
47.                  File.WriteAllBytes(filepath + ".dex\\" + i + ".dex", dex_tmp);
48.
49.
50.                }
51.            }
52.
53.            Console.WriteLine("所有的DEX文件已经输出到文件夹" + filepath + ".dex\\");
54.
55.            while (true)
56.            {
57.                Console.Read();
58.            }
59.
60.
61.      }


页: [1]
查看完整版本: 逆向360加固等dex被隐藏的APK