0

I'm using an Ubuntu system to download suspicious/suspected malware files for analysis. I need to zip each file and password protect it to prevent accidentally infecting other systems when transferring the files. the

0

This may not be exactly what you wanted; I wasn't quite sure what you meant? My code assumes 3 things: you only have 1 file (or set of files) you wish to place into a single archive, you save the virus file in your user's "Downloads" folder, and you have created a folder called "Viruses" in your user's home folder that contains a sub-folder called "Saved"; this is where the finished file will be.

Upon running the command the virus file will be put into a password protected .zip archive (you will be prompted to pick a password), moved to the "Viruses" folder and renamed virus.zip, and then moved to the "Viruses/Saved" folder. The original virus file will be deleted from "Downloads" (as well as anything else you have in that folder!!!).

When you download another virus, and run the command again. The current "virus.zip" will be named "virus.zip~1~" and the new file will be named virus.zip. If you run the command again the current "virus.zip" will be named "virus.zip~1~", the current "virus.zip~1~" will be named "virus.zip~2~", and the new virus archive will be named virus.zip. This will happen everytime you run the command.

To see these files you will need to allow showing hidden files. To open them just rename the extension to .zip.

You can run the command as many times as you need. As mentioned before this is only if you are downloading the files 1 at a time, or they will all be put in a single archive.

Steps:

  1. Download a virus

  2. Run this command :

    cd ~/Downloads && zip -e -0 Downloads * && mv *.zip ~/Viruses/virus.zip && rm * && mv --backup=t ~/Viruses/virus.zip ~/Viruses/Saved/virus.zip

  3. Repeat

0

You have two options with zip:

  -e
  --encrypt
          Encrypt  the  contents of the zip archive using a password which
          is entered on the terminal in response to a  prompt  (this  will
          not  be  echoed;  if  standard error is not a tty, zip will exit
          with an error).  The password prompt is  repeated  to  save  the
          user from typing errors.
  -P password
  --password password
          Use password to encrypt  zipfile  entries  (if  any).   THIS  IS
          INSECURE!   Many  multi-user  operating systems provide ways for
          any user to see the current command line of any other user; even
          on  stand-alone  systems there is always the threat of over-the-
          shoulder peeking.  Storing the plaintext password as part  of  a
          command  line  in  an  automated script is even worse.  Whenever
          possible, use  the  non-echoing,  interactive  prompt  to  enter
          passwords.   (And  where security is truly important, use strong
          encryption such as Pretty Good Privacy instead of the relatively
          weak standard encryption provided by zipfile utilities.)

So if you really wish to script this, you'll need to use -P, since -e forces the manual entry of passwords. Do so only if you are the only user in your environment, or if /proc was mounted with appropriate permissions (even then root will be able to see the password). This command should do the trick:

cd <path_to_directory>
find . -type f -printf "../%f.zip\0%f\0" | xargs -0n 2 zip -P pass

This will create zip files of each file, with the same name as that file (i.e., blah.doc will create blah.doc.zip) in the parent directory, each protected by the password pass.

  • Thanks for the help. This script works but, it puts the zip file in a directory above the one that it was run under. So if the files are located in Downloads the resulting zip files are now located under Home. – porkfatist Jul 9 '14 at 5:27
  • @porkfatist yes. I did say it will create zip files in the parent directory. The other way would be to generate a list of files first and then read from that list to zip. I'm sure you can modify the script to do that. – muru Jul 9 '14 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.