1+ # Script Name : recyclebin.py
2+ # Author : Craig Richards
3+ # Created : 07th June 2013
4+ # Last Modified :
5+ # Version : 1.0
6+
7+ # Modifications :
8+
9+ # Description : Scans the recyclebin and displays the files in there, originally got this script from the Violent Python book
10+
11+ import os # Load the Module
12+ import optparse # Load the Module
13+ from _winreg import * # Load the Module
14+
15+ def sid2user (sid ): # Start of the function to gather the user
16+ try :
17+ key = OpenKey (HKEY_LOCAL_MACHINE , "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" + '\\ ' + sid )
18+ (value , type ) = QueryValueEx (key , 'ProfileImagePath' )
19+ user = value .split ('\\ ' )[- 1 ]
20+ return user
21+ except :
22+ return sid
23+
24+
25+ def returnDir (): # Start of the function to search through the recyclebin
26+ dirs = ['c:\\ Recycler\\ ' ,'C:\\ Recycled\\ ' ,'C:\\ $RECYCLE.BIN\\ ' ]
27+ #dirs=['c:\\$RECYCLE.BIN\\']
28+ for recycleDir in dirs :
29+ if os .path .isdir (recycleDir ):
30+ return recycleDir
31+ return None
32+
33+ def findRecycled (recycleDir ): # Start of the function, list the contents of the recyclebin
34+ dirList = os .listdir (recycleDir )
35+ for sid in dirList :
36+ files = os .listdir (recycleDir + sid )
37+ user = sid2user (sid )
38+ print '\n [*] Listing Files for User: ' + str (user )
39+ for file in files :
40+ print '[+] Found File: ' + str (file )
41+
42+ def main ():
43+ recycleDir = returnDir ()
44+ findRecycled (recycleDir )
45+
46+ if __name__ == '__main__' :
47+ main ()
0 commit comments