irenicus09

Flash Grab Version 1.0

Jun 10th, 2011
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.01 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. __author__     = 'Irenicus09'
  4. __date__       = '10th June 2011'
  5. __license__    = 'GPL'
  6. __version__    = '1.0'
  7.  
  8. ###############################################################################
  9. #                                                                             #  
  10. #                          FLASH GRAB Version 1.0                             #
  11. #                                                                             #
  12. #    Flash Grab is a utility for Linux to access flash files cached by your   #
  13. #    browser. It can grab flash files regardless of the browser being used,   #
  14. #    also supports multiple instances of the same or different browser.       #
  15. #    It uses unique ID to keep track of different videos, so that multiple    #
  16. #    copies of the same video are not stored.                                 #
  17. #                                                                             #
  18. #    Usage: ./FlashGrab.py [Destination Directory]                            #
  19. #                                                                             #
  20. #    For more info visit:                                                     #
  21. #    http://irenicus09.wordpress.com/2011/06/10/flash-grab/                   #
  22. #                                                                             #
  23. ###############################################################################
  24.  
  25.  
  26. import subprocess, getpass, os, shutil, sys
  27. from time import sleep
  28.  
  29.  
  30. def Main():
  31.    
  32.     # Checking for invalid arguments
  33.     if (len(sys.argv) != 2):
  34.         print '[-] Usage: %s [Destination directory]' % sys.argv[0]
  35.         sys.exit(1)
  36.     elif (os.path.exists(sys.argv[1]) == False):
  37.         print '[-] Destination path is not valid'
  38.         sys.exit(1)
  39.        
  40.     # Edit Destination Directory if necessary [Hard Coding]
  41.     absDestPath = sys.argv[1]
  42.  
  43.     # Get username
  44.     usrname = getpass.getuser().strip()
  45.  
  46.     # Get base directories for searching
  47.     cmd1 = subprocess.Popen('ps aux | grep "%s" | grep "flash"' % usrname, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  48.     pid = (cmd1.communicate()[0].strip().split('\n'))
  49.  
  50.     # Declaring count to keep track of videos found
  51.     count = 0
  52.  
  53.     for i in pid:
  54.         srcPath = '/proc/%s/fd/' % (i.split()[1])
  55.         try:
  56.             os.chdir(srcPath)
  57.         except (Exception):
  58.             pass
  59.  
  60.         # Get List of valid Flash file names which are represented locally as numbers, such as 18, 32
  61.         cmd4 = subprocess.Popen('ls -l | grep "Flash" | cut -f9 --delimiter=" "', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  62.         srcFileName = (cmd4.communicate()[0].strip().split())
  63.  
  64.         # Parse individual Flash files and strip their unique ID for renaming
  65.         cmd5 = subprocess.Popen('ls -l | grep "Flash" | cut -f11 --delimiter=" " | cut --delimiter="/" -f3', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  66.         destFileName = (cmd5.communicate()[0].strip().split())
  67.    
  68.         # Individually copy all files into destination directory,
  69.         # renaming them according to their unique Flash ID.
  70.         if (len(srcFileName) != 0):
  71.             for i in range(len(srcFileName)):
  72.                 try:
  73.                     absSrcPath = '%s%s' % (srcPath, srcFileName[i])
  74.                     shutil.copy(absSrcPath, absDestPath)
  75.                     os.chdir(absDestPath)
  76.                     os.rename(srcFileName[i], destFileName[i])
  77.                     count += 1
  78.                     print '[*] Found file %s, moved to %s' % (destFileName[i], absDestPath)
  79.                     sleep(0.3)
  80.                 except (Exception):
  81.                     pass
  82.        
  83.     if (count >= 1):
  84.         print '[+] %d file(s) found and moved Successfully!' % count
  85.         sys.exit(0)
  86.     else:
  87.         print '[-] No relevant process found'
  88.         print '[?] Make sure you have browsers open'
  89.         print '[*] Quitting'
  90.         sys.exit(1)
  91.  
  92. if __name__ == '__main__':
  93.     Main()
Advertisement
Add Comment
Please, Sign In to add comment