@@ -19,6 +19,7 @@ def __init__(self, smbconnection, logger):
1919 self .onlyfiles = True
2020 self .content = False
2121 self .results = []
22+ self .no_print_results = False
2223
2324 def spider (
2425 self ,
@@ -30,6 +31,7 @@ def spider(
3031 depth = None ,
3132 content = False ,
3233 onlyfiles = True ,
34+ no_print_results = False
3335 ):
3436 if exclude_dirs is None :
3537 exclude_dirs = []
@@ -48,6 +50,7 @@ def spider(
4850 self .exclude_dirs = exclude_dirs
4951 self .content = content
5052 self .onlyfiles = onlyfiles
53+ self .no_print_results = no_print_results
5154
5255 if share == "*" :
5356 self .logger .display ("Enumerating shares for spidering" )
@@ -66,7 +69,8 @@ def spider(
6669 self .logger .fail (f"Error enumerating shares: { e } " )
6770 else :
6871 self .share = share
69- self .logger .display (f"Spidering { folder } " )
72+ if not self .no_print_results :
73+ self .logger .display (f"Spidering { folder } " )
7074 self ._spider (folder , depth )
7175
7276 return self .results
@@ -115,35 +119,39 @@ def dir_list(self, files, path):
115119 for pattern in self .pattern :
116120 if bytes (result .get_longname ().lower (), "utf8" ).find (bytes (pattern .lower (), "utf8" )) != - 1 :
117121 if not self .onlyfiles and result .is_directory ():
118- self .logger .highlight (f"//{ self .smbconnection .getRemoteHost ()} /{ self .share } /{ path } { result .get_longname ()} [dir]" )
122+ if not self .no_print_results :
123+ self .logger .highlight (f"//{ self .smbconnection .getRemoteHost ()} /{ self .share } /{ path } { result .get_longname ()} [dir]" )
119124 else :
120- self .logger .highlight (
121- "//{}/{}/{}{} [lastm:'{}' size:{}]" .format (
122- self .smbconnection .getRemoteHost (),
123- self .share ,
124- path ,
125- result .get_longname (),
126- "n\\ a" if not self .get_lastm_time (result ) else self .get_lastm_time (result ),
127- result .get_filesize (),
125+ if not self .no_print_results :
126+ self .logger .highlight (
127+ "//{}/{}/{}{} [lastm:'{}' size:{}]" .format (
128+ self .smbconnection .getRemoteHost (),
129+ self .share ,
130+ path ,
131+ result .get_longname (),
132+ "n\\ a" if not self .get_lastm_time (result ) else self .get_lastm_time (result ),
133+ result .get_filesize (),
134+ )
128135 )
129- )
130136 self .results .append (f"{ path } { result .get_longname ()} " )
131137 if self .regex :
132138 for regex in self .regex :
133139 if regex .findall (bytes (result .get_longname (), "utf8" )):
134140 if not self .onlyfiles and result .is_directory ():
135- self .logger .highlight (f"//{ self .smbconnection .getRemoteHost ()} /{ self .share } /{ path } { result .get_longname ()} [dir]" )
141+ if not self .no_print_results :
142+ self .logger .highlight (f"//{ self .smbconnection .getRemoteHost ()} /{ self .share } /{ path } { result .get_longname ()} [dir]" )
136143 else :
137- self .logger .highlight (
138- "//{}/{}/{}{} [lastm:'{}' size:{}]" .format (
139- self .smbconnection .getRemoteHost (),
140- self .share ,
141- path ,
142- result .get_longname (),
143- "n\\ a" if not self .get_lastm_time (result ) else self .get_lastm_time (result ),
144- result .get_filesize (),
144+ if not self .no_print_results :
145+ self .logger .highlight (
146+ "//{}/{}/{}{} [lastm:'{}' size:{}]" .format (
147+ self .smbconnection .getRemoteHost (),
148+ self .share ,
149+ path ,
150+ result .get_longname (),
151+ "n\\ a" if not self .get_lastm_time (result ) else self .get_lastm_time (result ),
152+ result .get_filesize (),
153+ )
145154 )
146- )
147155 self .results .append (f"{ path } { result .get_longname ()} " )
148156
149157 if self .content and not result .is_directory ():
@@ -176,34 +184,36 @@ def search_content(self, path, result):
176184 if self .pattern :
177185 for pattern in self .pattern :
178186 if contents .lower ().find (bytes (pattern .lower (), "utf8" )) != - 1 :
179- self .logger .highlight (
180- "//{}/{}/{}{} [lastm:'{}' size:{} offset:{} pattern:'{}']" .format (
181- self .smbconnection .getRemoteHost (),
182- self .share ,
183- path ,
184- result .get_longname (),
185- "n\\ a" if not self .get_lastm_time (result ) else self .get_lastm_time (result ),
186- result .get_filesize (),
187- rfile .tell (),
188- pattern ,
187+ if not self .no_print_results :
188+ self .logger .highlight (
189+ "//{}/{}/{}{} [lastm:'{}' size:{} offset:{} pattern:'{}']" .format (
190+ self .smbconnection .getRemoteHost (),
191+ self .share ,
192+ path ,
193+ result .get_longname (),
194+ "n\\ a" if not self .get_lastm_time (result ) else self .get_lastm_time (result ),
195+ result .get_filesize (),
196+ rfile .tell (),
197+ pattern ,
198+ )
189199 )
190- )
191200 self .results .append (f"{ path } { result .get_longname ()} " )
192201 if self .regex :
193202 for regex in self .regex :
194203 if regex .findall (contents ):
195- self .logger .highlight (
196- "//{}/{}/{}{} [lastm:'{}' size:{} offset:{} regex:'{}']" .format (
197- self .smbconnection .getRemoteHost (),
198- self .share ,
199- path ,
200- result .get_longname (),
201- "n\\ a" if not self .get_lastm_time (result ) else self .get_lastm_time (result ),
202- result .get_filesize (),
203- rfile .tell (),
204- regex .pattern ,
204+ if not self .no_print_results :
205+ self .logger .highlight (
206+ "//{}/{}/{}{} [lastm:'{}' size:{} offset:{} regex:'{}']" .format (
207+ self .smbconnection .getRemoteHost (),
208+ self .share ,
209+ path ,
210+ result .get_longname (),
211+ "n\\ a" if not self .get_lastm_time (result ) else self .get_lastm_time (result ),
212+ result .get_filesize (),
213+ rfile .tell (),
214+ regex .pattern ,
215+ )
205216 )
206- )
207217 self .results .append (f"{ path } { result .get_longname ()} " )
208218
209219 rfile .close ()
0 commit comments