def test_connectTree(self):
     smb = SMBConnection('*SMBSERVER',
                         self.machine,
                         preferredDialect=self.dialects)
     smb.login(self.username, self.password, self.domain)
     tid = smb.connectTree(self.share)
     UNC = '\\\\%s\\%s' % (self.machine, self.share)
     tid = smb.connectTree(UNC)
Beispiel #2
0
 def test_createFile(self):
     smb = SMBConnection("*SMBSERVER", self.machine, preferredDialect=self.dialects)
     smb.login(self.username, self.password)
     tid = smb.connectTree(self.share)
     fid = smb.createFile(tid, self.file)
     smb.closeFile(tid, fid)
     smb.deleteFile(self.share, self.file)
     smb.disconnectTree(tid)
     smb.logoff()
 def test_loginKerberosAES(self):
     lmhash, nthash = self.hashes.split(':')
     smb = SMBConnection('*SMBSERVER', self.machine, preferredDialect = self.dialects)    
     smb.kerberosLogin(self.username, '', self.domain, '', '', self.aesKey)
     credentials = smb.getCredentials()
     self.assertTrue( credentials == (self.username, '', self.domain, '','',self.aesKey, None, None) )
     UNC = '\\\\%s\\%s' % (self.machine, self.share)
     tid = smb.connectTree(UNC)
     smb.logoff()
 def test_createFile(self):
     smb = SMBConnection('*SMBSERVER', self.machine, preferredDialect = self.dialects)
     smb.login(self.username, self.password, self.domain)
     tid = smb.connectTree(self.share)
     fid = smb.createFile(tid, self.file)
     smb.closeFile(tid,fid)
     smb.rename(self.share, self.file, self.file + '.bak')
     smb.deleteFile(self.share, self.file + '.bak')
     smb.disconnectTree(tid)
     smb.logoff()
Beispiel #5
0
def smbwalk(smb, share, regex, path='\\', tid=None, *args, **kwargs):
    max_size = kwargs.get("max_size") or 100*1024
    ip = smb.getRemoteHost()
    try:
        if tid is None:
            tid = smb.connectTree(share)

    except Exception as e:
        if verbose:
            logger.warn("Failed to connect to tree '{}': {}".format(share, e))
        return

    path = ntpath.normpath(path)

    try:
        gen = smb.listPath(share, ntpath.join(path, '*'))
    except Exception as e:
        if verbose:
            logger.warn("Failed to list share '{}'".format(share, e))
        return

    for f in gen:
        cur_path = ntpath.join(path, f.get_longname())
        if f.is_directory() and f.get_longname() not in (".", ".."):
            try:
                smbwalk(smb, share, regex, cur_path + "\\", tid)
            except Exception as e:
                if verbose:
                    logger.warn("Failed to list path '{}': {}".format(cur_path, e))
            continue

        if f.get_longname() in (".", ".."):
            continue


        if regex is None or regex.search(cur_path):
            try:
                entry = [ip, share, cur_path,]
                fhandle = smb.openFile(tid, cur_path, desiredAccess=FILE_READ_DATA, shareMode=FILE_SHARE_READ)
                fdata = smb.readFile(tid, fhandle, offset=0, bytesToRead=max_size)
                fmagic = magic.from_buffer(fdata)
                smb.closeFile(tid, fhandle)
                entry.append(fmagic)
            except Exception as e:
                if verbose:
                    logger.warn("Failed to retrieve file: {}".format(e))
                entry.append("")

            if verbose:
                logger.info( "\\\\" + " -> ".join(entry) )

            q.append( entry )

    return tid
Beispiel #6
0
def smbwalk(smb, share, regex, path="\\", tid=None, *args, **kwargs):
    max_size = kwargs.get("max_size") or 100 * 1024
    ip = smb.getRemoteHost()
    try:
        if tid is None:
            tid = smb.connectTree(share)

    except Exception as e:
        if verbose:
            logger.warn("Failed to connect to tree '{}': {}".format(share, e))
        return

    path = ntpath.normpath(path)

    try:
        gen = smb.listPath(share, ntpath.join(path, "*"))
    except Exception as e:
        if verbose:
            logger.warn("Failed to list share '{}'".format(share, e))
        return

    for f in gen:
        cur_path = ntpath.join(path, f.get_longname())
        if f.is_directory() and f.get_longname() not in (".", ".."):
            try:
                smbwalk(smb, share, regex, cur_path + "\\", tid)
            except Exception as e:
                if verbose:
                    logger.warn("Failed to list path '{}': {}".format(cur_path, e))
            continue

        if f.get_longname() in (".", ".."):
            continue

        if regex is None or regex.search(cur_path):
            try:
                entry = [ip, share, cur_path]
                fhandle = smb.openFile(tid, cur_path, desiredAccess=FILE_READ_DATA, shareMode=FILE_SHARE_READ)
                fdata = smb.readFile(tid, fhandle, offset=0, bytesToRead=max_size)
                fmagic = magic.from_buffer(fdata)
                smb.closeFile(tid, fhandle)
                entry.append(fmagic)
            except Exception as e:
                if verbose:
                    logger.warn("Failed to retrieve file: {}".format(e))
                entry.append("")

            if verbose:
                logger.info("\\\\" + " -> ".join(entry))

            q.append(entry)

    return tid
Beispiel #7
0
    def test_readwriteFile(self):
        smb = SMBConnection("*SMBSERVER", self.machine, preferredDialect=self.dialects)
        smb.login(self.username, self.password)
        tid = smb.connectTree(self.share)
        fid = smb.createFile(tid, self.file)
        smb.writeFile(tid, fid, "A" * 65535)
        data = smb.readFile(tid, fid, 0, 65535)
        self.assertTrue(len(data) == 65535)
        self.assertTrue(data == "A" * 65535)
        smb.closeFile(tid, fid)
        smb.deleteFile(self.share, self.file)
        smb.disconnectTree(tid)

        smb.logoff()
Beispiel #8
0
    def test_readwriteFile(self):
        smb = SMBConnection('*SMBSERVER',
                            self.machine,
                            preferredDialect=self.dialects)
        smb.login(self.username, self.password)
        tid = smb.connectTree(self.share)
        fid = smb.createFile(tid, self.file)
        smb.writeFile(tid, fid, "A" * 65535)
        data = smb.readFile(tid, fid, 0, 65535)
        self.assertTrue(len(data) == 65535)
        self.assertTrue(data == "A" * 65535)
        smb.closeFile(tid, fid)
        smb.deleteFile(self.share, self.file)
        smb.disconnectTree(tid)

        smb.logoff()
Beispiel #9
0
 def test_connectTree(self):
     smb = SMBConnection('*SMBSERVER', self.machine, preferredDialect = self.dialects)
     smb.login(self.username, self.password, self.domain)
     tid = smb.connectTree(self.share)
     UNC = '\\\\%s\\%s' % (self.machine, self.share)
     tid = smb.connectTree(UNC)