コード例 #1
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)
コード例 #2
0
ファイル: test_smb.py プロジェクト: kanzure/impacket
 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()
コード例 #3
0
 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()
コード例 #4
0
 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()
コード例 #5
0
ファイル: smbwalk.py プロジェクト: hugsy/stuff
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
コード例 #6
0
ファイル: smbwalk.py プロジェクト: hugsy/stuff
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
コード例 #7
0
ファイル: test_smb.py プロジェクト: kanzure/impacket
    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()
コード例 #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()
コード例 #9
0
ファイル: test_smb.py プロジェクト: DarkGreising/impacket
 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)