import re import sys import socket import struct import string import logging from network import HostFinger from model.host import VictimHost from odict import odict import select SMB_PORT = 445 SMB_SERVICE = 'tcp-445' LOG = logging.getLogger(__name__) class Packet(): fields = odict([ ("data", ""), ]) def __init__(self, **kw): self.fields = odict(self.__class__.fields) for k,v in kw.items(): if callable(v): self.fields[k] = v(self.fields[k]) else: self.fields[k] = v def __str__(self): return "".join(map(str, self.fields.values())) ##### SMB Packets ##### class SMBHeader(Packet): fields = odict([ ("proto", "\xff\x53\x4d\x42"), ("cmd", "\x72"), ("errorcode", "\x00\x00\x00\x00"), ("flag1", "\x00"), ("flag2", "\x00\x00"), ("pidhigh", "\x00\x00"), ("signature", "\x00\x00\x00\x00\x00\x00\x00\x00"), ("reserved", "\x00\x00"), ("tid", "\x00\x00"), ("pid", "\x00\x00"), ("uid", "\x00\x00"), ("mid", "\x00\x00"), ]) class SMBNego(Packet): fields = odict([ ("wordcount", "\x00"), ("bcc", "\x62\x00"), ("data", "") ]) def calculate(self): self.fields["bcc"] = struct.pack("i", len(''.join(Packet)))+Packet s.send(Buffer) data = s.recv(2048) if data[8:10] == "\x72\x00": Header = SMBHeader(cmd="\x73",flag1="\x18",flag2="\x17\xc8",uid="\x00\x00") Body = SMBSessionFingerData() Body.calculate() Packet = str(Header)+str(Body) Buffer = struct.pack(">i", len(''.join(Packet)))+Packet s.send(Buffer) data = s.recv(2048) if data[8:10] == "\x73\x16": length = struct.unpack('