Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ______ ___ _____ ___.______ ________ _______ _________ ______ _____ ___.
- / ___/( /_\ \\ : \\ __ /_ _\ ___ // _ /__/ ___/__\ \\ :
- _\ _/ |\/ // . \ | _ \ _ \\ . /_____/__/ _\ _/ | . \ |
- \ | / : | / \ / \ : | \_ \ | : |
- \______:__//____|____|_________/_______/ |____:__________\_______:____|____|
- /_____|
- KLPD Cybercrime Challenge 2013 -- Alternative solution for IRC C&C
- Instead of fishing the /passphrase/ from the memorydump, this utility
- searches for the raw 256bit key in memory. It simply treats every 32-
- byte block as a key, decrypts the given ciphertext and checks if the
- deciphered block consists of pure 7bit ascii characters. This is a
- pretty effective way to find "candidates" for possibly correct keys.
- To thwart some more false candidates we do a basic entropy check on
- the candidate key before letting it pass.
- This might sound quite expensive, but it churns to through the
- entire 512 megabyte memorydump within 2 minutes on an average desktop
- computer. Leaving you with only one candidate that matches all of
- the given basic constraints: the correct AES key :-)
- This AES key can be used to encrypt/decrypt any further messages!
- -- EINDBAZEN / 2013-03-31
- sample run:
- $ gcc -o keyfinder keyfinder.c -lcrypto
- $ time ./keyfinder memory.raw \
- `echo dfI8J5hkgaQ6vtYtKK2d7Qlou650S9m1FZ697bZ01TCOTnCTWtyCzqyZe9UV4bBHZN9nkm4j/2Py|base64 -d`
- 1ca16c00..
- FOUND POSSIBLE KEY: 6c99160e2cdd68f68b9e09938453fc499ca6ab9df2eed14399663e1cb2461b40 --> 'supported comman'
- 20000000..
- real 1m46.199s
- user 1m44.187s
- sys 0m1.004s
- */
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <openssl/aes.h>
- int decrypt(unsigned char *k, unsigned char *d, int dlen) {
- AES_KEY aes_key;
- unsigned char iv[0x10], plaintext[0x20], ent_buf[256];
- int i;
- memset(iv, 0, 16);
- AES_set_decrypt_key(k, 256, &aes_key);
- AES_cbc_encrypt(d, plaintext, 0x20u, &aes_key, iv, AES_DECRYPT);
- // all plaintext 7bit ascii?
- for(i = 0; i < 16; i++) {
- if (plaintext[i] < 0x20 || plaintext[i] > 0x7e)
- return -1;
- }
- // somewhat legit entropy?
- memset(ent_buf, 0, 256);
- for(i=0;i<32;i++) {
- ent_buf[ k[i] ]++;
- }
- for (i=0;i<256;i++) {
- if (ent_buf[i] > 2)
- return -1;
- }
- // yep!
- printf("\n\nFOUND POSSIBLE KEY: ");
- for(i=0;i<32;i++) {
- printf("%02x", k[i]);
- }
- printf(" --> '");
- for(i=0; i<16; i++) {
- printf("%c", plaintext[i]);
- }
- printf("'\n");
- return 0;
- }
- int main(int argc, char *argv[]) {
- unsigned char *blob;
- FILE *fp;
- struct stat st;
- int pos=0;
- if (stat(argv[1], &st) < 0) {
- perror("stat");
- return -1;
- }
- fp=fopen(argv[1], "rb");
- blob = malloc(st.st_size);
- fread(blob, st.st_size, 1, fp);
- fclose(fp);
- while(pos < st.st_size) {
- decrypt(blob+pos, (unsigned char*)argv[2], 32);
- pos += 4;
- if ((pos % (1024)) == 0) {
- printf("%08x..\r", pos);
- fflush(stdout);
- }
- }
- free(blob);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment