def test_listPath(self): smb = SMBConnection('*SMBSERVER', self.machine, preferredDialect=self.dialects) smb.login(self.username, self.password, self.domain) smb.listPath(self.share, '*') smb.logoff()
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
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
def test_listPath(self): smb = SMBConnection('*SMBSERVER', self.machine, preferredDialect = self.dialects ) smb.login(self.username, self.password, self.domain) smb.listPath(self.share, '*') smb.logoff()
def test_listPath(self): smb = SMBConnection("*SMBSERVER", self.machine, preferredDialect=self.dialects) smb.login(self.username, self.password) smb.listPath(self.share, "*") smb.logoff()