コード例 #1
0
def smbComOpenAndX(packet, packetNum, SMBCommand, questions, replies):

    # Test return code is always 0, otherwise leave before doing anything
    if packet['ErrorCode'] != 0:
        return True

    print "SMB_COM_OPEN_ANDX ",
    try:
        if (packet['Flags1'] & smb.SMB.FLAGS1_REPLY) == 0:
            # Query

            openAndXParameters = smb.SMBOpenAndX_Parameters(
                SMBCommand['Parameters'])
            openAndXData = smb.SMBOpenAndX_Data(SMBCommand['Data'])

        else:
            # Response
            openFileResponse = SMBCommand
            openFileParameters = smb.SMBOpenAndXResponse_Parameters(
                openFileResponse['Parameters'])

    except Exception, e:
        print "ERROR: %s" % e
        print "Command: 0x%x" % packet['Command']
        print "Packet: %d %r" % (packetNum, packet.getData())
        return True
コード例 #2
0
ファイル: chain.py プロジェクト: yinhui1150/impacket
    def do_lots(self, user, pwd_ansi, share, filename, domain=''):
        pkt = smb.NewSMBPacket()
        pkt['Flags1'] = 8

        sessionSetup = smb.SMBCommand(self.SMB_COM_SESSION_SETUP_ANDX)
        sessionSetup['Parameters'] = smb.SMBSessionSetupAndX_Parameters()
        sessionSetup['Data'] = smb.SMBSessionSetupAndX_Data()

        sessionSetup['Parameters']['MaxBuffer'] = 65535
        sessionSetup['Parameters']['MaxMpxCount'] = 2
        sessionSetup['Parameters']['VCNumber'] = os.getpid()
        sessionSetup['Parameters']['SessionKey'] = self.get_session_key()
        sessionSetup['Parameters']['AnsiPwdLength'] = len(pwd_ansi)
        sessionSetup['Parameters']['UnicodePwdLength'] = len('')
        sessionSetup['Parameters']['Capabilities'] = self.CAP_RAW_MODE

        sessionSetup['Data']['AnsiPwd'] = pwd_ansi
        sessionSetup['Data']['UnicodePwd'] = ''
        sessionSetup['Data']['Account'] = str(user)
        sessionSetup['Data']['PrimaryDomain'] = str(domain)
        sessionSetup['Data']['NativeOS'] = str(os.name)
        sessionSetup['Data']['NativeLanMan'] = 'pysmb'

        # This is an example of how to use chained ANDX commands

        treeConnect = smb.SMBCommand(self.SMB_COM_TREE_CONNECT_ANDX)
        treeConnect['Parameters'] = smb.SMBTreeConnectAndX_Parameters()
        treeConnect['Data'] = smb.SMBTreeConnectAndX_Data()
        treeConnect['Parameters']['PasswordLength'] = 1
        treeConnect['Data']['Password'] = '******'
        treeConnect['Data']['Path'] = share
        treeConnect['Data']['Service'] = smb.SERVICE_ANY

        openFile = smb.SMBCommand(self.SMB_COM_OPEN_ANDX)
        openFile['Parameters'] = smb.SMBOpenAndX_Parameters()
        openFile['Parameters']['DesiredAccess'] = smb.SMB_ACCESS_READ
        openFile['Parameters']['OpenMode'] = smb.SMB_O_OPEN
        openFile['Parameters']['SearchAttributes'] = 0
        openFile['Data'] = smb.SMBOpenAndX_Data()
        openFile['Data']['FileName'] = filename

        readAndX = smb.SMBCommand(self.SMB_COM_READ_ANDX)
        readAndX['Parameters'] = smb.SMBReadAndX_Parameters()
        readAndX['Parameters']['Offset'] = 0
        readAndX['Parameters']['Fid'] = 0
        readAndX['Parameters']['MaxCount'] = 4000

        pkt.addCommand(sessionSetup)
        pkt.addCommand(treeConnect)
        pkt.addCommand(openFile)
        pkt.addCommand(readAndX)

        # This is an example of how to make a loop with the chained commands
        # treeConnect['Parameters']['AndXCommand'] = self.SMB_COM_TREE_CONNECT_ANDX
        # treeConnect['Parameters']['AndXOffset'] = 72

        self.sendSMB(pkt)

        pkt = self.recvSMB()