Advertisement
Guest User

Untitled

a guest
Dec 25th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. #!/usr/bin/python2
  2. from binascii import unhexlify
  3. from struct import pack, unpack
  4.  
  5. from Crypto.Cipher import ARC4
  6. from impacket import ntlm
  7. from impacket.dcerpc.v5 import transport, epm, nrpc
  8. from impacket.dcerpc.v5.dtypes import NULL
  9.  
  10. print('ddd')
  11.  
  12. class xxx(object):
  13. def __init__(self):
  14. self.username = 'mmarkk'
  15. self.domain = 'in.ideco.ru'
  16. self.serverName = 'dc.in.ideco.ru'
  17. self.password = 'HUYTEBE'
  18. self.machine = '10.80.60.10'
  19. self.hashes = ''
  20. # print epm.hept_map(self.machine, samr.MSRPC_UUID_SAMR, protocol = 'ncacn_ip_tcp')
  21.  
  22. # TCP: self.stringBinding = epm.hept_map(self.machine, nrpc.MSRPC_UUID_NRPC, protocol='ncacn_ip_tcp')
  23. self.stringBinding = r'ncacn_np:%s[\PIPE\netlogon]' % self.machine
  24.  
  25. def connect(self):
  26. print 'sss'
  27. rpctransport = transport.DCERPCTransportFactory(self.stringBinding)
  28. if len(self.hashes) > 0:
  29. lmhash, nthash = self.hashes.split(':')
  30. else:
  31. lmhash = ''
  32. nthash = ''
  33. if hasattr(rpctransport, 'set_credentials'):
  34. # This method exists only for selected protocol sequences.
  35. rpctransport.set_credentials(self.username, self.password, self.domain, lmhash, nthash)
  36. dce = rpctransport.get_dce_rpc()
  37. # dce.set_auth_level(RPC_C_AUTHN_LEVEL_PKT_INTEGRITY)
  38. print 'qwe'
  39. dce.connect()
  40. print 'asd'
  41. dce.bind(nrpc.MSRPC_UUID_NRPC)
  42. resp = nrpc.hNetrServerReqChallenge(dce, NULL, self.serverName + '\x00', '12345678')
  43. resp.dump()
  44. serverChallenge = resp['ServerChallenge']
  45.  
  46. if self.hashes == '':
  47. ntHash = None
  48. else:
  49. ntHash = unhexlify(self.hashes.split(':')[1])
  50.  
  51. self.sessionKey = nrpc.ComputeSessionKeyStrongKey(self.password, '12345678', serverChallenge, ntHash)
  52.  
  53. ppp = nrpc.ComputeNetlogonCredential('12345678', self.sessionKey)
  54.  
  55. try:
  56. resp = nrpc.hNetrServerAuthenticate3(dce, NULL, self.username + '\x00',
  57. nrpc.NETLOGON_SECURE_CHANNEL_TYPE.WorkstationSecureChannel,
  58. self.serverName + '\x00', ppp, 0x600FFFFF)
  59. resp.dump()
  60. except Exception, e:
  61. if str(e).find('STATUS_DOWNGRADE_DETECTED') < 0:
  62. raise
  63.  
  64. self.clientStoredCredential = pack('<Q', unpack('<Q', ppp)[0] + 10)
  65.  
  66. # dce.set_auth_type(RPC_C_AUTHN_NETLOGON)
  67. # dce.set_auth_level(RPC_C_AUTHN_LEVEL_PKT_INTEGRITY)
  68. # dce2 = dce.alter_ctx(nrpc.MSRPC_UUID_NRPC)
  69. # dce2.set_session_key(self.sessionKey)
  70.  
  71. return dce, rpctransport
  72.  
  73. def qwe(self):
  74. dce, rpctransport = self.connect()
  75. request = nrpc.NetrLogonSamLogonEx()
  76. request['LogonServer'] = '\x00'
  77. request['ComputerName'] = self.serverName + '\x00'
  78. request['LogonLevel'] = nrpc.NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveInformation
  79. request['LogonInformation']['tag'] = nrpc.NETLOGON_LOGON_INFO_CLASS.NetlogonInteractiveInformation
  80. request['LogonInformation']['LogonInteractive']['Identity']['LogonDomainName'] = self.domain
  81. request['LogonInformation']['LogonInteractive']['Identity'][
  82. 'ParameterControl'] = 2 + 2 ** 14 + 2 ** 7 + 2 ** 9 + 2 ** 5 + 2 ** 11
  83. request['LogonInformation']['LogonInteractive']['Identity']['UserName'] = self.username
  84. request['LogonInformation']['LogonInteractive']['Identity']['Workstation'] = ''
  85. if len(self.hashes) > 0:
  86. lmhash, nthash = self.hashes.split(':')
  87. lmhash = unhexlify(lmhash)
  88. nthash = unhexlify(nthash)
  89. else:
  90. lmhash = ntlm.LMOWFv1(self.password)
  91. nthash = ntlm.NTOWFv1(self.password)
  92.  
  93. rc4 = ARC4.new(self.sessionKey)
  94. lmhash = rc4.encrypt(lmhash)
  95. rc4 = ARC4.new(self.sessionKey)
  96. nthash = rc4.encrypt(nthash)
  97.  
  98. request['LogonInformation']['LogonInteractive']['LmOwfPassword'] = lmhash
  99. request['LogonInformation']['LogonInteractive']['NtOwfPassword'] = nthash
  100. request['ValidationLevel'] = nrpc.NETLOGON_VALIDATION_INFO_CLASS.NetlogonValidationSamInfo4
  101. request['ExtraFlags'] = 1
  102. resp = dce.request(request)
  103. resp.dump()
  104.  
  105. xxx().qwe()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement