How to decrypt 3DES in ECB mode (using a wordlist)?
Question: I have some encrypted texts (encrypted with 3DES in ECB mode without salt).

**My question: How can I decrypt them using a wordlist? (or without one?)**

Example:

Encrypted text:

    
    
    Xfi+h4Ir6l7zXCP+N4EPvQ==
    

The wordlist for this:

    
    
    foo
    bar
    marketing
    

The original text was before encrypting was: "marketing" (just to make the
example full).

I tried with the commented python script:

    
    
    $ cat 3des.py 
     #!/usr/local/bin/python
    
    from pyDes import *
    
    data = "marketing"
    k = des("DESCRYPT", CBC, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
    d = k.encrypt(data)
    print "Encrypted: %r" % d
    print "Decrypted: %r" % k.decrypt(d)
    assert k.decrypt(d, padmode=PAD_PKCS5) == data
    

testing it:

    
    
    $ python 3des.py 
    Encrypted: '\xabd\xfc\x98x\x86\x8d\xb5A\xba\x8e\x12,\x1f\x83\xb5'
    Decrypted: 'marketing'
    $ 
    

A little help please?


Answer: If you're going to use pyDES, you'll first have to configure your the script
to use 3DES... Here's the provided pyDES example, modified to use 3DES:

    
    
    from pyDes import *
    
    data = "marketing"
    k = triple_des("DESCRYPTDESCRYPT", ECB, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
    d = k.encrypt(data)
    print "Encrypted: %r" % d
    print "Decrypted: %r" % k.decrypt(d)
    assert k.decrypt(d, padmode=PAD_PKCS5) == data
    

To break it down...

The following line contains the class initialization information:

    
    
    k = triple_des("DESCRYPTDESCRYPT", ECB, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
    

From the documentation, the params are as follows:

    
    
    (key, [mode], [IV], [pad], [padmode])
    
    key     -> Bytes containing the encryption key. 8 bytes for DES, 16 or 24 bytes
           for Triple DES
    mode    -> Optional argument for encryption type, can be either
           pyDes.ECB (Electronic Code Book) or pyDes.CBC (Cypher Block Chaining)
    IV      -> Optional Initial Value bytes, must be supplied if using CBC mode.
           Length must be 8 bytes.
    pad     -> Optional argument, set the pad character (PAD_NORMAL) to use during
           all encrypt/decrpt operations done with this instance.
    padmode -> Optional argument, set the padding mode (PAD_NORMAL or PAD_PKCS5)
           to use during all encrypt/decrpt operations done with this instance.
    

So, in my modified example, I've configured the params like this...

    
    
    Key: DESCRYPTDESCRYPT
    Mode: ECB
    IV: "\0\0\0\0\0\0\0\0"
    pad: None
    padmode: PAD_PKCS5
    

So, from here, you'll need to change the 'data' variable above to the
ciphertext you want to decrypt and then load your wordlist into an array, set
up a loop to iterate the values in the array through the 'key' param...

