Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Wednesday, November 19, 2014

Access to an attachment Gmail regards as a virus

How To Retrieve Blocked Gmail Attachments ?

I was using Gmail as my backup solutions.

Recently, I wanted to retrieve one of these backups, a .rar (which includes .exe files) ,containing the complete source code .

I sent/forward these files many time (last was almost one year back).

But , now Gmail blocked the access to these attachments saying
"Anti-virus warning - 1 attachment contains a virus or blocked file. Downloading this attachment is disabled".



Is there any way to get access to an attachment Gmail regards as a virus?

Please help.
-----------------------------------------------------------------
Have you ever been going through such a question ?
If YES, you can retrieve it using a software called "Python".
Here is the step below : 
=============================================================================

STEP : A - Install "Python"


Firstly, download Python v3.4.2 from here. Once you’ve downloaded the file, install the program by running the file and following the on screen instructions.

Double click on the downloaded file . Then you can see ,


Click "Run" .Then install the software, as per the instructions given.
Wait till installation completed.


Click "Finish".

Open Python from the Start menu (or from the desired location).

You can see a command prompt , as given below : 


Keep this file, opened  your Gmail . 

STEP : B - Open your Gmail

  • Open your Gmail, containing Virus attachment (You must be sure that , this is actually not infected by a virus. As per Google's new privasy-policy , this attachment is now considered as a virus).


  • And click on the right drop down arrow from the mail , and select "Show original" from the drop-down menu .

  • A pop-up will appear with what appears to be garbled text. This is actually your email and attachment as a text file, encoded in base64 , as gievn below : 


Means , the whole attachment was contained in that text file , encoded in base64! Now we just needed to extract it from the email and convert it back to binary.We will use a Python script to convert it back to binary. Copy the entire text to clipboard (Ctrl+A, Ctrl+C).
  • Paste it in a text file and save it with any generic name ending in *.txt.

  • I created a Folder named "Gmail Backup" and save that text file in it .



  • Now , Do the same for the below given script file, copy the script and paste it in a text file.
  Copy this script file and paste it in a text file.

# Get your files that Gmail block. Warning message:
# "Anti-virus warning - 1 attachment contains a virus or blocked file. Downloading this attachment is disabled."
# Based on: http://spapas.github.io/2014/10/23/retrieve-gmail-blocked-attachments/
# Go to your emails, click the arrow button in the top right, "Show original", save to the same directory as this script.

import email
import sys
import os

if __name__ == '__main__':
  if len(sys.argv) < 2:
    print("Press enter to process all files with .txt extension.")
    input()
    files = [ f for f in os.listdir('.') if os.path.isfile(f) and f.endswith('.txt') ]
  else:
    files = sys.argv[1:]

  print("Files: %s" % ', '.join(files))
  print()

  for f in files:
    msg = email.message_from_file(open(f))
    print("Processing %s" % f)
    print("Subject: %s" % msg['Subject'])
    for pl in msg.get_payload():
      fn = pl.get_filename()
      if fn:
        print("Found %s" % fn)
        if os.path.isfile(fn):
          print("The file %s already exists! Press enter to overwrite." % fn)
          input()
        open(fn, 'wb').write(pl.get_payload(decode=True))
    print()


Paste it in a text file , as given below : 


  • Save it in the same folder (Gmail Backup) with any generic name ending in *.py and Python should automatically recognise it as a Python script.

  • Double click the python script file named "extract" , to run. And press Enter when prompted.

Press "Enter" as prompted (No further action needed here).
  • Now , open the folder "Gmail Backup" 


Thats it...!!!

You can see the attachment there....

Depending on the file size, the attachment should appear immediately in the same location as the script and text file.

(Hats off to Lutfi's Blog) .

No comments: