首页
社区
课程
招聘
[原创]安卓改机技术揭秘(二) 高级攻防技巧
发表于: 2016-10-2 00:28 32807

[原创]安卓改机技术揭秘(二) 高级攻防技巧

2016-10-2 00:28
32807
收藏
免费 3
支持
分享
打赏 + 1.00雪花
打赏次数 1 雪花 + 1.00
 
赞赏  一位没有留下痕迹的看雪读者   +1.00 2019/03/23 膜拜大佬
最新回复 (60)
雪    币: 163
活跃值: (1538)
能力值: ( LV5,RANK:60 )
在线值:
发帖
回帖
粉丝
26
前面也有传
模仿取得的数据
static int dlopenAddr = 0xD028; //opendl地址
static int InitArrayAddr = 0x00049E20 - 0x1000; //此处IDA的地址总是比UE中的多0x1000
static int asmAddr = 0x4A400; //代码插入位置

libc.so And libc_ok.so,附件

libc_and_libc_ok.rar
上传的附件:
2016-10-15 20:32
0
雪    币: 241
活跃值: (226)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
27
static int asmAddr = 0x46260;

用这个值试试

另外 代码需要变动一下
第28行 插入
data[StrAddr + LibCkisSo.Length] = 0;
2016-10-15 23:01
0
雪    币: 2679
活跃值: (1576)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
28
第二种方式 xposed+libc.so   libc你修改的意义是什么呢?
2016-10-15 23:36
0
雪    币: 241
活跃值: (226)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
29
安卓有java层和jni(native)层
XPOSED只能HOOK JAVA层
那么JNI层如何HOOK?需要改 libc.so 为全局注入点的方式实现
2016-10-15 23:59
0
雪    币: 163
活跃值: (1538)
能力值: ( LV5,RANK:60 )
在线值:
发帖
回帖
粉丝
30
[QUOTE=ckis;1448424]static int asmAddr = 0x46260;

用这个值试试

另外 代码需要变动一下
第28行 插入
data[StrAddr + LibCkisSo.Length] = 0;[/QUOTE]

地址选这个位置可以,地址选择是有什么限制吗?

代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace LibcInject
{
    class Program
    {
        static int dlopenAddr = 0xD028; //opendl地址
        static int InitArrayAddr = 0x00049E20 - 0x1000; //此处IDA的地址总是比UE中的多0x1000
        static int asmAddr = 0x46260; //代码插入位置

        static byte[] asm = { 0xFF,0x40,0x2D,0xE9,0x18,0x00,0x9F,0xE5,0x00,0x10,0xA0,0xE3,0x00,0x00,0x8F,0xE0,
              0x01,0xF7,0xFF,0xEB,0xFF,0x40,0xBD,0xE8,0x08,0x00,0x9F,0xE5,0x00,0x00,0x8F,0xE0,
              0x10,0xFF,0x2F,0xE1,0x9C,0x68,0x03,0x00,0x09,0xBF,0x01,0x00,0x00,0x00,0x00,0x00};
        static int StrAddr = asmAddr + 0x40;
        static void Main(string[] args)
        {
            BinaryReader br = null;
            try
            {
                br = new BinaryReader(new FileStream("libc.so", FileMode.Open));
            }
            catch (IOException e)
            {
                Console.WriteLine(e.Message + "Cannot open file.");
                return;
            }
            int length = Convert.ToInt32(br.BaseStream.Length);
            byte[] data = br.ReadBytes(length);
            br.Close();
            byte[] LibCkisSo = System.Text.Encoding.ASCII.GetBytes("libckis.so");
            Array.ConstrainedCopy(LibCkisSo, 0, data, StrAddr, LibCkisSo.Length);
            data[StrAddr + LibCkisSo.Length] = 0; 
            int JmpReturnAddr = System.BitConverter.ToInt32(data, InitArrayAddr);
            byte[] byAsmAddr = System.BitConverter.GetBytes(asmAddr);
            Array.ConstrainedCopy(byAsmAddr, 0, data, InitArrayAddr, byAsmAddr.Length);
            byte[] JmpOffset = System.BitConverter.GetBytes(JmpReturnAddr - asmAddr - 0x24);
            Array.ConstrainedCopy(JmpOffset, 0, asm, 0x28, JmpOffset.Length);
            byte[] StrOffset = System.BitConverter.GetBytes(StrAddr - asmAddr - 0x14);
            Array.ConstrainedCopy(StrOffset, 0, asm, 0x24, StrOffset.Length);
            byte[] DlopenOffset = System.BitConverter.GetBytes((dlopenAddr - asmAddr - 0x18) / 4);
            Array.ConstrainedCopy(DlopenOffset, 0, asm, 0x10, StrOffset.Length - 1);
            Array.ConstrainedCopy(asm, 0, data, asmAddr, asm.Length);
            BinaryWriter bw = new BinaryWriter(new FileStream("libc_ok.so", FileMode.Create));
            bw.Write(data);
            bw.Close();
        }
    }
}

2016-10-17 09:42
0
雪    币: 241
活跃值: (226)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
31
位置没什么限制 应该是ELF文件格式的问题 你之前选的地址是在 data段的 但我给出的例子 是rodata段的 在text段arm机器码执行的偏移位置不一样

如果按你之前的地址 代码里需要+0x1000即可
2016-10-17 13:22
0
雪    币: 0
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
32
谢谢分享
2016-10-31 18:01
0
雪    币: 204
活跃值: (20)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
33
感谢分享,学习一下思路
2016-10-31 23:56
0
雪    币: 3
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
34
Mark下,感谢楼主分享
2016-11-4 07:26
0
雪    币: 2679
活跃值: (1576)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
35
libc修改了后,怎么拦截jni层呢?是否有样例代码?
2016-11-14 09:58
0
雪    币: 241
活跃值: (226)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
36
http://www.weibo.com/ele7enxxh
https://github.com/ele7enxxh/Android-Inline-Hook
2017-1-16 14:09
0
雪    币: 48
活跃值: (27)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
37
感谢分享
2017-2-17 11:12
0
雪    币: 220
活跃值: (47)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
38
楼主分析相当仔细,感觉分享
2017-2-17 17:05
0
雪    币: 1553
活跃值: (482)
能力值: ( LV6,RANK:80 )
在线值:
发帖
回帖
粉丝
39
mark
2017-5-23 17:53
0
雪    币: 0
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
40
如果有一些JNI层比较丰富的hook实例就棒棒了,不过还是非常感谢
2017-5-29 02:26
0
雪    币: 202
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
41
楼主说的hook  JNI层,说的是hook  native方法吗?xposed不是支持native方法的hook吗?哪位大神解惑一下,非常感谢!!
2017-6-7 11:45
0
雪    币: 195
活跃值: (29)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
42
感谢楼主,能否解析下static  byte[]  asm这个数组的意思和怎样生成的呢?
2017-6-16 15:15
0
雪    币: 35
活跃值: (30)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
43
 
2017-6-18 01:17
0
雪    币: 139
活跃值: (225)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
44
第二种懵懵懂懂
2017-6-19 17:55
0
雪    币: 241
活跃值: (226)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
45
vurtneye 我之前一直研究探探,发现探探会检测java层的钩子,因为xpose是把hook的java方法改成native属性,探探会检测出来你是否hook,所以对于目前你说的这两种方案应该无法避过检测
把他要检测的Method的Native属性去掉  会吗?
2017-6-20 17:44
0
雪    币: 1
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
46
楼主,看了你得帖子很是受启发,可以帮我在安卓cydia框架上写个hook插件吗?报酬丰厚,QQ416359880
2017-6-21 10:55
0
雪    币: 35
活跃值: (30)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
47
ckis 把他要检测的Method的Native属性去掉 会吗?
这个检测的我已经去掉,但是还是被检测出来使用了xpose,看来自己功力不够深厚,还需要继续研究才行,看你的文章收益不少,感谢
2017-6-23 20:33
0
雪    币: 9479
活跃值: (757)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
48
xposed是classloader被检测到的。
2017-6-23 20:49
0
雪    币: 6818
活跃值: (153)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
49
感谢分享!!!!
2017-6-23 22:39
0
雪    币: 89
活跃值: (19)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
50

用ida看区段.rodata与.data中的插入代码一样的,但是.rodata可以hook,.data无法hook。

libc.so中.init_array:

libc_rodata中asmAddr:

libc_data中asmAddr:

生成代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace LibcInject
{
    class Program
    {
        static int dlopenAddr = 0xCF14; //opendl地址
        static int InitArrayAddr = 0x48E20 - 0x1000; //此处IDA的地址总是比UE中的多0x1000
        static int idaAsmAddr = 0x49350; //代码插入位置(带入插入的是.data区段)
        static int offAsmAddr = idaAsmAddr - 0x1000;
        static byte[] asm = { 0xFF,0x40,0x2D,0xE9,0x18,0x00,0x9F,0xE5,0x00,0x10,0xA0,0xE3,0x00,0x00,0x8F,0xE0,
                            0x01,0xF7,0xFF,0xEB,0xFF,0x40,0xBD,0xE8,0x08,0x00,0x9F,0xE5,0x00,0x00,0x8F,0xE0,
                            0x10,0xFF,0x2F,0xE1,0x9C,0x68,0x03,0x00,0x09,0xBF,0x01,0x00,0x00,0x00,0x00,0x00};
        static int idaStrAddr = idaAsmAddr + 0x40;
        static int offStrAddr = offAsmAddr + 0x40;
        static void Main(string[] args)
        {
            BinaryReader br = null;
            try
            {
                br = new BinaryReader(new FileStream("libc.so", FileMode.Open));
            }
            catch (IOException e)
            {
                Console.WriteLine(e.Message + "Cannot open file.");
                return;
            }
            int length = Convert.ToInt32(br.BaseStream.Length);
            byte[] data = br.ReadBytes(length);
            br.Close();
            byte[] LibCkisSo = System.Text.Encoding.ASCII.GetBytes("libckis.so");
            Array.ConstrainedCopy(LibCkisSo, 0, data, offStrAddr, LibCkisSo.Length);
            data[offStrAddr + LibCkisSo.Length] = 0;
            int JmpReturnAddr = System.BitConverter.ToInt32(data, InitArrayAddr);
            byte[] byAsmAddr = System.BitConverter.GetBytes(idaAsmAddr);
            Array.ConstrainedCopy(byAsmAddr, 0, data, InitArrayAddr, byAsmAddr.Length);
            byte[] JmpOffset = System.BitConverter.GetBytes(JmpReturnAddr - idaAsmAddr - 0x24);
            Array.ConstrainedCopy(JmpOffset, 0, asm, 0x28, JmpOffset.Length);
            byte[] StrOffset = System.BitConverter.GetBytes(idaStrAddr - idaAsmAddr - 0x14);
            Array.ConstrainedCopy(StrOffset, 0, asm, 0x24, StrOffset.Length);
            byte[] DlopenOffset = System.BitConverter.GetBytes((dlopenAddr - idaAsmAddr - 0x18) / 4);
            Array.ConstrainedCopy(DlopenOffset, 0, asm, 0x10, StrOffset.Length - 1);
            Array.ConstrainedCopy(asm, 0, data, offAsmAddr, asm.Length);
            BinaryWriter bw = new BinaryWriter(new FileStream("libc_ok.so", FileMode.Create));
            bw.Write(data);
            bw.Close();
        }
    }
}

求指点为什么.data的不行,找了好久没找到原因。



上传的附件:
2017-6-25 22:27
0
游客
登录 | 注册 方可回帖
返回
//