Research | Practice

Showing posts with label Encryption. Show all posts
Showing posts with label Encryption. Show all posts

2017-01-09

[How to] GPG and Signing Data

Monday, January 09, 2017 Posted by Unknown , , , , , No comments
GNU Privacy Guard (GPG) uses public and private keys to secure communications (public-key cryptography). Many people use it to encrypt their email or other documents. An email encrypted with a user's public key can then only be decrypted with the same user's private key. This provides end-to-end encryption of the message, meaning that it is impractical for anyone that is listening in on the conversation to get the message in transit.


This is, of course, good and bad. For example, Google and other email providers use email text to gain intelligence about the user, sell user information and do better ad targeting. This revenue stream keeps these services free, but users pay for it in terms of 'sold' privacy. Email using end-to-end encryption cannot be analyzed for useful marketing information. Because of this, these providers don't want to make it easy for mass encryption.

On the other hand, criminals also use Cloud-based email services. Making encryption somewhat difficult means that sloppy criminals are less likely to use encryption. If so, they may be easier to detect and catch.

Related Book: Lucas, Michael. PGP & GPG: Email for the Practical Paranoid. No Starch Press. 2006.

Whether you are paranoid and want all your emails encrypted (good luck), or you are trying to implement a personal or business data classification policy, GPG can help with encryption requirements.

Beyond encryption, GPG is useful for signing data. This is not exactly a signature that you would put on a document. Instead it is a signature that verifies that the data is correct. The video below describes how to sign data.



Signing data lets your contacts know that the data has not been modified from the time it left your possession. Signing is NOT encryption. Everyone could see the contents. Singing just allows your contact to know the data came from you, and it is in it's original state.

2015-07-02

[How-To] Using GnuPG to verify data using detached signatures

Thursday, July 02, 2015 Posted by Unknown , , , No comments
GnuPG logo

Many software downloads come with a signature file. You normally need to download this signature file separately. Signatures are a great way to let people know that you are the person / company that is making the software available, and that no one else has changed the data since its release.

Tails linux ISO and signature download links with SHA256 checksum
Fig 1: Tails ISO and signature file download
We are going to use Tails Linux as an example. On their download page, you will find a link to download the Tails ISO image. This is the data we are interested in running. Think of it like the main program that we want to install / use.

Next, we are given a link to the "Tails 1.4 signature". This is signature file that the distributor created. With this signature we can verify that the Tails ISO Image has not been modified by anyone else.

Tails also provides a "SHA256 Checksum". This is a less-rigorous way than signatures to verify the data has not changed.

First, download the ISO file AND the signature file. The signature file will almost always end with ".sig". Make sure both files are in the same directory.


Once you had both files, open the command line / terminal and navigate to that directory. Next we need to use gpg to verify the signature. If we try to verify now, we may get the following results:

gpg2 --verify tails-i386-1.4.iso.sig gpg: assuming signed data in 'tails-i386-1.4.iso'
gpg: Signature made Tue 12 May 2015 02:56:27 AM KST using RSA key ID 752A3DB6
gpg: Can't check signature: No public key

In this case, we also need to get the public key of the person that created the signature. From the tails website, I find the ID of their signing key, so now we need to import.

gpg2 --recv-keys A490D0F4D311A4153E2BB7CADBB802B258ACD84F
gpg: key 58ACD84F: public key "Tails developers (offline long-term identity key) " imported
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   2  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u
gpg: next trustdb check due at 2017-01-09
gpg: Total number processed: 1
gpg:               imported: 1

Make sure we have the right key:

gpg2 --list-keys
pub   rsa4096/58ACD84F 2015-01-18 [expires: 2016-01-11]
uid       [ unknown] Tails developers (offline long-term identity key) 
sub   rsa4096/752A3DB6 2015-01-18 [expires: 2016-01-11]
sub   rsa4096/2F699C56 2015-01-18 [expires: 2016-01-11]

Now verify the signature again:

gpg2 --verify tails-i386-1.4.iso.sig gpg: assuming signed data in 'tails-i386-1.4.iso'
gpg: Signature made Tue 12 May 2015 02:56:27 AM KST using RSA key ID 752A3DB6
gpg: Good signature from "Tails developers (offline long-term identity key) " [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: A490 D0F4 D311 A415 3E2B  B7CA DBB8 02B2 58AC D84F
     Subkey fingerprint: BA2C 222F 44AC 00ED 9899  3893 98FE C6BC 752A 3DB6

Here we can see when the signature was made, and the ID of that key. Next we see "Good signature" which means that the signature does verify the data.

Remember, we were given the SHA256 value of the ISO file. Get the SHA256 hash with the following command (linux):

sha256sum tails-i386-1.4.iso
339c8712768c831e59c4b1523002b83ccb98a4fe62f6a221fee3a15e779ca65d  tails-i386-1.4.iso

Now can can compare this hash value to the one on the website, and we see that they are the same.

If I can just check the hash value, why verify with a signature?

Hash values do allow you to make sure that the data has not changed, however, there are a number of weaknesses. For example, someone intercepting your network traffic could deliver the web page to you with an altered ISO link AND an altered hash value on the page. This means that the hash value will be valid, but the source of the information cannot be trusted.

Signatures help this in a number of ways. Because the signature is generated by a developer's private key, and we are verifying it with their public key, it is nearly impossible for someone to pretend to be the developer. Also, since we did not download the public key from the webpage, but looked it up on a different server, it is slightly more difficult for someone to trick us into download the wrong key. Further, we can try to use the Web of Trust to make sure we are getting the right key. In our case, we can see who has signed this key by going to a keyserver checking.

2015-06-25

Seoul Tech Society Crypto Event

Thursday, June 25, 2015 Posted by Unknown , , , No comments
On June 24th, Seoul Tech Society held an 'introduction to cryptography' event. First, Artem Lenskiy gave an overview of how symmetric and asymmetric encryption works. Followed by Joshua James with a hands-on tutorial about using GnuPG for electronic document signing and encryption. Finally, Max Goncharov talked about the new Paranoid.EMAIL service. This was all rounded out with pizza and libations.

Overall, attendees got a quick (but intense) overview of theoretical and practical encryption. We had a lot of great questions from the audience, and almost everyone left with their own GPG keypair.


For anyone who didn't make it, the presentations can be found here:

If you are in Korea, check out Seoul Tech Society's Meetup page to catch our next event.









2015-06-22

GPG Key Signing Party in Seoul 2015/06/24

Monday, June 22, 2015 Posted by Unknown , , , No comments
Seoul Tech Society is having an introduction to Public Key Infrastructure (PKI) Wednesday, June 24th at D.CAMP in Seoul. We will give an introduction to PKI, followed by a tutorial for generating your own keys with GPG. We will cover electronically signing documents and software distributions, verifying signatures, basic encryption and authentication using your keys.


After, we will talk about - and play with - paranoid.email, which allows you to force partial encrypted email transmission, even when others are not using PKI.

Once all that has been covered, and everyone has their own GPG keys, we will have a GPG Key-signing PaRtY!~ Help improve the Web of Trust and have free drinks and light snacks at the same time!

Please RSVP at Meetup.com

If you are thinking about running a key-signing party, please check out this guide.

2015-01-04

Attacking Zip File Passwords from the Command Line

Sunday, January 04, 2015 Posted by Unknown , , No comments
There was recently a question on SuperUser linking back to CybercrimeTech's article about cracking passwords, with an issue about zip files using ZipCrypto, and never finding the password. I left an answer, saying that I guess zip2john does not know how to accurately extract the hash from zip files using that particular algorithm.

In such a case, you can either 1) figure out the data structure, and update zip2john (https://github.com/magnumripper/JohnTheRipper), or use the same approach that we have used before with LUKS to attack the file directly from the command line.

Definitely, attempting to crack the hash is faster, but if you are stuck and don't have time to reverse engineer a new file type, this would *eventually* work for you.

See the code below as an example of having John generate the password then passing it to 7zip to try. This should work regardless of chosen encryption, unless you have to specify it when opening the archive. It is not clean, but it should be enough to illustrate.

    #!/bin/bash
    # Using john the ripper to brute-force a zip container
    startTime=$(date)
    if [ $(file $1 | grep -c "Zip archive data") ]; then
        john -i --stdout | while read i; do   # this is john generating password to stdout
            echo -ne "\rtrying \"$i\" "\\r
            7z -p$i -so e $1 2>&1> /dev/null     # this is your zip command
            STATUS=$?
            if [ $STATUS -eq 0 ]; then
                echo -e "\nPassword is: \"$i\""
                break                         # if successful, print the password and quit
            fi
        done
        echo "Start time $startTime"
        echo "End time $(date)"
    else
        echo "The file does not appear to be a zip file"
    fi


This approach should work when you are unable to extract the hash, but is much, much slower (not really practical for most applications). See the results below.

    ...
    trying "pmc"
    7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-1
    Processing archive: test.zip
    Extracting  Sample_memo.pdf     Data Error in encrypted file. Wrong password?
    **Sub items Errors: 1**
 
    trying "1234"
    7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
    Processing archive: test.zip
    Extracting  Sample_memo.pdf
    **Everything is Ok**
    Size:       60936
    Compressed: 51033
 
    Password is: "1234"
    Start time 2015. 01. 03. (토) 19:02:51 KST
    End time 2015. 01. 03. (토) 19:02:51 KST

2014-08-11

[How to] Brute forcing password cracking devices (LUKS)

Monday, August 11, 2014 Posted by Unknown , , 1 comment
We have written in the past about how to crack passwords on password-protected RAR and ZIP files, but in those cases someone wrote a program to extract the password hashes from the RAR and ZIP files first. After that, we could use John the Ripper to generate passwords (or use a dictionary) to attack the password hashes. In this case, John the Ripper generates a password, then hashes the password with the same hashing/salting method as the hash we are attacking. If the hash matches, then we have the clear-text password.

However, in some situations, we don't have a password hash to attack, or maybe we don't know what algorithm is used. Either way, we may not be able to extract a hash for whatever reason. In this case, we can still brute-force the password using the standard authentication mechanism.

In this tutorial, I will be brute-force attacking a LUKS encrypted file using John the Ripper. A LUKS encrypted file is similar to a truecrypt container. It could be used to encrypt a disk, partition, or file.

Let's assume that an investigator extracted all files from a suspect disk. By looking at the file headers, we find the following:

encrypted: LUKS encrypted file, ver 1 [aes, xts-plain64, sha1] UUID: 811f8a08-85da-4f7d-b50f-3e64ed7a66f4

Maybe the investigator has no memory image of the suspect device or any other information regarding the file, but still needs to get into it....

To mount a LUKS file from the (linux) command line, you have to use cryptsetup . The command usually looks like cryptsetup luksOpen container mountpoint . When you attempt to mount, by default it will ask for a password 3 times if the attempts are incorrect. We cannot pass the password directly to cryptsetup as an option, it will always ask for a password.

Regardless of some challenges, cryptsetup does have some useful options, such as -T which controls how many times it will ask for a password before giving up. And also the option --test-passphrase, which will see if the password worked without actually opening the device. So right now we have the following command to open the LUKS device:

cryptsetup luksOpen $1 x --test-passphrase -T1


Now we can use John the Ripper in incremental mode sending the output to standard out to generate our password list.

john -i --stdout


Now we just need a small script to capture the output of JtR and test the cryptsetup password:

#!/bin/bash

# Using john the ripper to brute-force a luks container
startTime=$(date)
if [ $(file $1 | grep -c "LUKS encrypted file") ]; then
    john -i --stdout | while read i; do
        echo -ne "\rtrying \"$i\" "\\r
        # as root
        echo $i | cryptsetup luksOpen $1 x --test-passphrase -T1 2> /dev/null
        STATUS=$?
        if [ $STATUS -eq 0 ]; then
          echo -e "\nPassword is: \"$i\""
          break
        fi
    done
    echo "Start time $startTime"
    echo "End time $(date)"
else
        echo "The file does not appear to be a LUKS encrypted file"
fi


This bash script first uses file to check whether the input is recognized as a LUKS encrypted file. If so, it will run JtM in incremental mode, and output to stdout. A while loop is used to capture the generated password as a variable "i". We then echo the password, and pipe it to the luksOpen command. That way, when cryptsetup asks for a password it will use the password we have piped to it. The status will be either 0 if it worked or 2 if the password failed. If the status is 0, then we print the password, and how long it took. If the status is not 0, we get a new password and try again.

Now, if you start to run this script you may notice that it is very, very, very slow. Generating passwords with JtM is relatively quick, but trying the passwords on a LUKS device is designed to be slow.

This process will likely take a very long time, but 1) it will eventually crack any type of device and 2) it can be used when you have no other option.

Try to use the script to play around with other password-protected files/devices.

2013-08-15

Sending a manually encrypted email using a public key

Thursday, August 15, 2013 Posted by Unknown , , No comments
Some web-based email services don't have an encryption client available, but if you still want to be able to encrypt an email using someone's public key, you can do it in the following way.

First, get GPG.

  • There is GPG4Win: http://www.gpg4win.org/ (I've not used it, but I assume there is a command line client)
  • GPGTools for Mac: https://gpgtools.org/ (I've used, and liked very well)
  • For Linux there are few different options, so see this for more information.


Once you have GPG installed, you should be able to run the command 'gpg' from a terminal.

*note - On Windows or Mac the commands may be slightly different than what is shown here.

For this tutorial, you will be encrypting an email using someone's public key. I will not show you how to create your own keys in this post.

Once you can run gpg, we need to try to find the public key of the person you will send the message to. If they have uploaded their key to a public key server you can query the server with
gpg --list-keys email@address.com
You can then import the key you have found using --recv-keys with the key's ID. For example, my key looks like: pub   2048R/606B15C4 2013-01-09 [expires: 2017-01-09]. The key's ID is 606B15C4.
gpg --recv-keys 606B15C4 
Once we have successfully imported the key, we can use it to encrypt messages that only the holder of the associated private key can decrypt. So, for example, if you use my public key to encrypt a file, then only my private key can be used to decrypt the file.

Likewise, if I use my private key to encrypt a file, then only my public key can be used to decrypt the file. This is a good way to show that you are the originator of the information.

OK - so let's make some text to send in our email. I will create a text file as a simple file container.
echo "Question: Can security students encrypt their email?" >> encryption_test.txt
echo "Hypothesis: Security students are too lazy to encrypt their email." >> encryption_test.txt
So now I have a plain text file called "encryption_test.txt" with two lines in it.

(In Linux) I can read the contents of the file using 'cat', and pipe the output into gpg for encryption.
cat encryption_test.txt | gpg --encrypt --armor -r 606B15C4
The first command takes the contents of the file "encryption_test.txt" and send it to gpg, which encrypts the text with the public key 606B15C4. The output is as follows:

-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.4.11 (GNU/Linux)

hQEMA999TJtS1eU1AQgAn09ngR2pGDGCfFH0aKUazQInd+HtYqqFq6UmFyszb5RX
OS5mWB3gEKMh3Ki0Qvgs2tA9nBx1+uzyxvkLoXrLwkfVg7mu821bjkh9OMsFO9hb
EeKkZjAAHHcf1rkpWKgc9mcmYyaNBEexyDJy648osWiGyDfedVMKog0k44NFf9iG
aBNsrrqmS+S6SllCgUhbMtkJYB4+BbCBIDA0laWQF+wcKGIsQfk3XxYdJUAfTFIK
vJwKyyPd9JBwG70XYaycBVIPMYhflmNB0MKVV65iQXQslN0dlTMu9CZGRYDJ4IMD
eC89NDsSVwVBWGPxo76cE19McXC5EHQvEBZk9XUIY9KQAaqZOu8vJlz5kehprSnm
OsYY24fuvsbZ4tglgQQ2FC7QLwB+rMLXNWPXor/EjUUYfeRAtbADfpFgNX/Kyzf8
9CxHSRO0ARj/caQQHCjfothIcR6J+vSGe5z+QA9IG9LhvRYOQkbyqoz9ZxRmBgrG
zD++fpC+hgv56WRHe5BzSBq4iaYJ+M1FGb5YbpCBzrPI
=Umsn
-----END PGP MESSAGE-----


If I copy from ---BEGIN PGP MESSAGE --- to ---END PGP MESSAGE--- and paste that into the body of my email, and send it to the person who owns the private key - they should be able to decrypt it.

2013-02-27

Encrypted backup and the importance of redundancy

Wednesday, February 27, 2013 Posted by Unknown , No comments
As more online storage is made available, it is often convenient to store our personal documents on the web to share between devices or with friends, family, co-workers, etc. How much you trust these services is entirely up to you. There are many benefits such as convenience and accessibility, as well as drawbacks, such as privacy concerns, denial of service and others.

I have noticed that with online storage, more people are backing up their documents (consciously or not), than were before online storage became so seamless. There is also an assumption that their data will be available when they want/need it. The important thing to remember, however, is that no backup solution is perfect. Be it online storage in the Cloud or backup to a local disk, there are potential risks to access and integrity of your data.

In my case, I rarely use Cloud-based storage services. I find that I don't always have access to an Internet connection, and many of the files I want to back up are unlikely to be accessed in the short term. Basically, I am archiving some of my data, and there is really no benefit for me to archive to the Cloud. So for backup and archiving I have two external drives that I keep synced with rsync.

Both disks use full disk encryption. I do not keep personal information or secrets per se, but in 2010 I had an unencrypted disk stolen (and miraculously recovered). When it went missing, I was not worried about the information about me that was on the disk. I found that I was more worried about the pictures and movies of my friends and family (especially my niece and nephew), and what someone could potentially do with them. It is unlikely that a thief would use the pictures, but that was still my concern.

Since then most of my data is encrypted. However, there are still potential risks to the data, which I was reminded of recently. For data backup I have a primary backup drive to which the local machine is backed up daily, and a secondary drive that gets synced from the primary weekly.

Last week my system crashed while the computer was apparently in the process of backing up. Either the encrypted device or the file system got corrupted, and the backed-up data was effectively lost. Recovery might have been possible, but I didn't take the time to do an analysis. This is because I could just recreate the primary encrypted disk, rsync from the secondary backup, then backup the local system like normal. Without the secondary backup, my current working documents would still exist, but I would potentially loose some archived information of sentimental value.

Long story short, no matter how you decide backup your data if you care about the data, keep at least a secondary backup in another location. This can minimize the risks to the access and integrity of your data since you never know what might happen.


Image courtesy of Renjith Krishnan / FreeDigitalPhotos.net