@@ -156,7 +156,7 @@ def manage_advanced_options():
156156 if 'historic' in args :
157157 constant .ie_historic = args ['historic' ]
158158
159- if 'drive' in args :
159+ if args [ 'drive' ] :
160160 drive = args ['drive' ].upper ()
161161 # drive letter between A and Z
162162 if drive != constant .drive :
@@ -201,37 +201,41 @@ def write_in_file(result):
201201
202202# Get user list to retrieve their passwords
203203def get_user_list_on_filesystem (impersonated_user = []):
204+
204205 # Check users existing on the system (get only directories)
205- all_users = os .walk ('%s:\\ Users' % constant .drive ).next ()[1 ]
206-
207- # Remove default users
208- for user in ['All Users' , 'Default User' , 'Default' , 'Public' ]:
209- if user in all_users :
210- all_users .remove (user )
206+ user_path = u'%s:\\ Users' % constant .drive
207+ all_users = []
208+ if os .path .exists (user_path ):
209+ all_users = os .listdir (user_path )
210+
211+ # Remove default users
212+ for user in ['All Users' , 'Default User' , 'Default' , 'Public' , 'desktop.ini' ]:
213+ if user in all_users :
214+ all_users .remove (user )
211215
212- # Removing user that have already been impersonated
213- for imper_user in impersonated_user :
214- if imper_user in all_users :
215- all_users .remove (imper_user )
216+ # Removing user that have already been impersonated
217+ for imper_user in impersonated_user :
218+ if imper_user in all_users :
219+ all_users .remove (imper_user )
216220
217221 return all_users
218222
219223def set_env_variables (user = getpass .getuser (), toImpersonate = False ):
220224 constant .username = user
221225 if not toImpersonate :
222- constant .profile ['APPDATA' ] = os .environ .get ('APPDATA' , '%s:\\ Users\\ %s\\ AppData\\ Roaming\\ ' % (constant .drive , user ))
223- constant .profile ['USERPROFILE' ] = os .environ .get ('USERPROFILE' , '%s:\\ Users\\ %s\\ ' % (constant .drive , user ))
224- constant .profile ['HOMEDRIVE' ] = os .environ .get ('HOMEDRIVE' , '%s:' % constant .drive )
225- constant .profile ['HOMEPATH' ] = os .environ .get ('HOMEPATH' , '%s:\\ Users\\ %s' % (constant .drive , user ))
226- constant .profile ['ALLUSERSPROFILE' ] = os .environ .get ('ALLUSERSPROFILE' , '%s:\\ ProgramData' % constant .drive )
227- constant .profile ['COMPOSER_HOME' ] = os .environ .get ('COMPOSER_HOME' , '%s:\\ Users\\ %s\\ AppData\\ Roaming\\ Composer\\ ' % (constant .drive , user ))
228- constant .profile ['LOCALAPPDATA' ] = os .environ .get ('LOCALAPPDATA' , '%s:\\ Users\\ %s\\ AppData\\ Local' % (constant .drive , user ))
226+ constant .profile ['APPDATA' ] = unicode ( os .environ .get ('APPDATA' , u '%s:\\ Users\\ %s\\ AppData\\ Roaming\\ ' % (constant .drive , user ) ))
227+ constant .profile ['USERPROFILE' ] = unicode ( os .environ .get ('USERPROFILE' , u '%s:\\ Users\\ %s\\ ' % (constant .drive , user ) ))
228+ constant .profile ['HOMEDRIVE' ] = unicode ( os .environ .get ('HOMEDRIVE' , u '%s:' % constant .drive ) )
229+ constant .profile ['HOMEPATH' ] = unicode ( os .environ .get ('HOMEPATH' , u '%s:\\ Users\\ %s' % (constant .drive , user ) ))
230+ constant .profile ['ALLUSERSPROFILE' ] = unicode ( os .environ .get ('ALLUSERSPROFILE' , u '%s:\\ ProgramData' % constant .drive ) )
231+ constant .profile ['COMPOSER_HOME' ] = unicode ( os .environ .get ('COMPOSER_HOME' , u '%s:\\ Users\\ %s\\ AppData\\ Roaming\\ Composer\\ ' % (constant .drive , user ) ))
232+ constant .profile ['LOCALAPPDATA' ] = unicode ( os .environ .get ('LOCALAPPDATA' , u '%s:\\ Users\\ %s\\ AppData\\ Local' % (constant .drive , user ) ))
229233 else :
230- constant .profile ['APPDATA' ] = '%s:\\ Users\\ %s\\ AppData\\ Roaming\\ ' % (constant .drive , user )
231- constant .profile ['USERPROFILE' ] = '%s:\\ Users\\ %s\\ ' % (constant .drive , user )
232- constant .profile ['HOMEPATH' ] = '%s:\\ Users\\ %s' % (constant .drive , user )
233- constant .profile ['COMPOSER_HOME' ] = '%s:\\ Users\\ %s\\ AppData\\ Roaming\\ Composer\\ ' % (constant .drive , user )
234- constant .profile ['LOCALAPPDATA' ] = '%s:\\ Users\\ %s\\ AppData\\ Local' % (constant .drive , user )
234+ constant .profile ['APPDATA' ] = u '%s:\\ Users\\ %s\\ AppData\\ Roaming\\ ' % (constant .drive , user )
235+ constant .profile ['USERPROFILE' ] = u '%s:\\ Users\\ %s\\ ' % (constant .drive , user )
236+ constant .profile ['HOMEPATH' ] = u '%s:\\ Users\\ %s' % (constant .drive , user )
237+ constant .profile ['COMPOSER_HOME' ] = u '%s:\\ Users\\ %s\\ AppData\\ Roaming\\ Composer\\ ' % (constant .drive , user )
238+ constant .profile ['LOCALAPPDATA' ] = u '%s:\\ Users\\ %s\\ AppData\\ Local' % (constant .drive , user )
235239
236240# print user when verbose mode is enabled (without verbose mode the user is printed on the write_output python file)
237241def print_user (user ):
@@ -247,7 +251,7 @@ def clean_temporary_files():
247251 except :
248252 pass
249253
250- def runLaZagne (category_choosed = 'all' ):
254+ def runLaZagne (category_choosed = 'all' , check_specific_drive = False ):
251255
252256 # ------ Part used for user impersonation ------
253257
@@ -256,7 +260,12 @@ def runLaZagne(category_choosed='all'):
256260 constant .finalResults = {'User' : current_user }
257261 print_user (current_user )
258262 yield 'User' , current_user
259- set_env_variables ()
263+
264+ if check_specific_drive :
265+ set_env_variables (toImpersonate = True )
266+ else :
267+ set_env_variables ()
268+
260269 for r in runModule (category_choosed ):
261270 yield r
262271 stdoutRes .append (constant .finalResults )
@@ -272,7 +281,7 @@ def runLaZagne(category_choosed='all'):
272281 # Not save the current user's SIDs
273282 if current_user != sid [3 ].split ('\\ ' , 1 )[1 ]:
274283 impersonateUsers .setdefault (sid [3 ].split ('\\ ' , 1 )[1 ], []).append (sid [2 ])
275-
284+
276285 for user in impersonateUsers :
277286 if 'service ' in user .lower () or ' service' in user .lower ():
278287 continue
@@ -333,18 +342,18 @@ def runLaZagne(category_choosed='all'):
333342 PPoptional = argparse .ArgumentParser (add_help = False , formatter_class = lambda prog : argparse .HelpFormatter (prog , max_help_position = constant .MAX_HELP_POSITION ))
334343 PPoptional ._optionals .title = 'optional arguments'
335344 PPoptional .add_argument ('-v' , dest = 'verbose' , action = 'count' , default = 0 , help = 'increase verbosity level' )
336- PPoptional .add_argument ('-quiet' , dest = 'quiet' , action = 'store_true' , default = False , help = 'quiet mode: nothing is printed to the output' )
337- PPoptional .add_argument ('-drive' , dest = 'drive' , action = 'store' , default = 'C' , help = 'drive to perform the test (default: C)' )
338- PPoptional .add_argument ('-path' , dest = 'path' , action = 'store' , help = 'path of a file used for dictionary file' )
339- PPoptional .add_argument ('-b' , dest = 'bruteforce' , action = 'store' , help = 'number of character to brute force' )
345+ PPoptional .add_argument ('-quiet' , dest = 'quiet' , action = 'store_true' , default = False , help = 'quiet mode: nothing is printed to the output' )
346+ PPoptional .add_argument ('-drive' , dest = 'drive' , action = 'store' , default = False , help = 'drive to perform the test (default: C)' )
347+ PPoptional .add_argument ('-path' , dest = 'path' , action = 'store' , help = 'path of a file used for dictionary file' )
348+ PPoptional .add_argument ('-b' , dest = 'bruteforce' , action = 'store' , help = 'number of character to brute force' )
340349
341350
342351 # Output
343352 PWrite = argparse .ArgumentParser (add_help = False , formatter_class = lambda prog : argparse .HelpFormatter (prog , max_help_position = constant .MAX_HELP_POSITION ))
344353 PWrite ._optionals .title = 'Output'
345- PWrite .add_argument ('-oN' , dest = 'write_normal' , action = 'store_true' , help = 'output file in a readable format' )
346- PWrite .add_argument ('-oJ' , dest = 'write_json' , action = 'store_true' , help = 'output file in a json format' )
347- PWrite .add_argument ('-oA' , dest = 'write_all' , action = 'store_true' , help = 'output file in all format' )
354+ PWrite .add_argument ('-oN' , dest = 'write_normal' , action = 'store_true' , help = 'output file in a readable format' )
355+ PWrite .add_argument ('-oJ' , dest = 'write_json' , action = 'store_true' , help = 'output file in a json format' )
356+ PWrite .add_argument ('-oA' , dest = 'write_all' , action = 'store_true' , help = 'output file in all format' )
348357
349358 # ------------------------------------------- Add options and suboptions to all modules -------------------------------------------
350359 all_subparser = []
@@ -395,6 +404,10 @@ def runLaZagne(category_choosed='all'):
395404 arguments = parser .parse_args ()
396405 category_choosed = args ['auditType' ]
397406
407+ check_specific_drive = False
408+ if args ['drive' ]:
409+ check_specific_drive = True
410+
398411 quiet_mode ()
399412
400413 # Print the title
@@ -407,7 +420,7 @@ def runLaZagne(category_choosed='all'):
407420
408421 start_time = time .time ()
409422
410- for r in runLaZagne (category_choosed ):
423+ for r in runLaZagne (category_choosed , check_specific_drive = check_specific_drive ):
411424 pass
412425
413426 clean_temporary_files ()
0 commit comments