#!/usr/bin/env python # This file is part of Responder, a network take-over set of tools # created and maintained by Laurent Gaffie. # email: laurent.gaffie@gmail.com # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import sys if (sys.version_info > (3, 0)): from socketserver import BaseRequestHandler else: from SocketServer import BaseRequestHandler from packets import LDAPSearchDefaultPacket, LDAPSearchSupportedCapabilitiesPacket, LDAPSearchSupportedMechanismsPacket, LDAPNTLMChallenge, CLDAPNetlogon from utils import * import struct import codecs import random def CalculateDNSName(name): if isinstance(name, bytes): name = name.decode('latin-1') name = name.split(".") DomainPrefix = struct.pack('B', len(name[0])).decode('latin-1')+name[0] Dnslen = '' for x in name: if len(x) >=1: Dnslen += struct.pack('B', len(x)).decode('latin-1')+x return Dnslen, DomainPrefix def ParseCLDAPNetlogon(data): try: Dns = data.find(b'DnsDomain') if Dns == -1: return False DnsName = data[Dns+9:] DnsGuidOff = data.find(b'DomainGuid') if DnsGuidOff == -1: return False Guid = data[DnsGuidOff+10:] if Dns: DomainLen = struct.unpack(">B", DnsName[1:2])[0] DomainName = DnsName[2:2+DomainLen] if Guid: DomainGuidLen = struct.unpack(">B", Guid[1:2])[0] DomainGuid = Guid[2:2+DomainGuidLen] return DomainName, DomainGuid except: pass def ParseSearch(data): TID = data[8:9].decode('latin-1') if re.search(b'Netlogon', data): NbtName = settings.Config.MachineName TID = NetworkRecvBufferPython2or3(data[8:10]) if TID[1] == "\x63": TID = "\x00"+TID[0] DomainName, DomainGuid = ParseCLDAPNetlogon(data) DomainGuid = NetworkRecvBufferPython2or3(DomainGuid) t = CLDAPNetlogon(MessageIDASNStr=TID ,CLDAPMessageIDStr=TID, NTLogonDomainGUID=DomainGuid, NTLogonForestName=CalculateDNSName(DomainName)[0],NTLogonPDCNBTName=CalculateDNSName(NbtName)[0], NTLogonDomainNBTName=CalculateDNSName(NbtName)[0],NTLogonDomainNameShort=CalculateDNSName(DomainName)[1]) t.calculate() return str(t) if re.search(b'(?i)(objectClass0*.*supportedSASLMechanisms)', data): return str(LDAPSearchSupportedMechanismsPacket(MessageIDASNStr=TID,MessageIDASN2Str=TID)) elif re.search(b'(?i)(objectClass0*.*supportedCapabilities)', data): return str(LDAPSearchSupportedCapabilitiesPacket(MessageIDASNStr=TID,MessageIDASN2Str=TID)) elif re.search(b'(objectClass)', data): return str(LDAPSearchDefaultPacket(MessageIDASNStr=TID)) def ParseLDAPHash(data,client, Challenge): #Parse LDAP NTLMSSP v1/v2 SSPIStart = data.find(b'NTLMSSP') SSPIString = data[SSPIStart:] LMhashLen = struct.unpack(' 60: SMBHash = SSPIString[NthashOffset:NthashOffset+NthashLen] SMBHash = codecs.encode(SMBHash, 'hex').upper().decode('latin-1') DomainLen = struct.unpack('i',data[2:6])[0] if Operation == b'\x84': Operation = data[9:10] sasl = data[20:21] OperationHeadLen = struct.unpack('>i',data[11:15])[0] LDAPVersion = struct.unpack('i',data[2:6])[0] MessageSequence = struct.unpack('i',data[11:15])[0] LDAPVersion = struct.unpack('