Skip to content

Instantly share code, notes, and snippets.

@mietek
Created March 1, 2012 13:34
Show Gist options
  • Save mietek/1949846 to your computer and use it in GitHub Desktop.
Save mietek/1949846 to your computer and use it in GitHub Desktop.
DTrace contest source
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define CODE_LEN 16
const unsigned char ENCRYPTED[][CODE_LEN + 1] = {
// ad8b0a518f4e717b
{0xcb, 0xcf, 0x90, 0xcb, 0x9e, 0xce, 0x99, 0x9c, 0x9a, 0xc5, 0x94, 0xc4, 0x91, 0x96, 0x93, 0xc7, 0x00},
// b96fce77a01aa3f1
{0xc9, 0x93, 0x9f, 0xce, 0xcc, 0xcb, 0x9a, 0x9b, 0xc2, 0x92, 0x90, 0xc1, 0xc6, 0x95, 0xc3, 0x95, 0x00},
// c27c4c97a2cca1e5
{0xcb, 0x9b, 0x9d, 0xc8, 0x98, 0xce, 0x97, 0x98, 0xc1, 0x93, 0xc1, 0xc0, 0xc5, 0x94, 0xc3, 0x92, 0x00},
// da2c30abab3f9ba0
{0xcd, 0xc9, 0x99, 0xc9, 0x9e, 0x9c, 0xce, 0xcc, 0xc0, 0xc2, 0x90, 0xc4, 0x9c, 0xc6, 0xc6, 0x96, 0x00},
// e92ae02dda5d7947
{0xcb, 0x96, 0x9e, 0xcc, 0xcf, 0x9b, 0x9a, 0xcd, 0xc2, 0xc6, 0x91, 0xc1, 0x95, 0x9a, 0x94, 0x96, 0x00},
// fd328a9f4ffbe5cb
{0xc9, 0xca, 0x9e, 0x9e, 0x93, 0xcb, 0x90, 0xce, 0x93, 0xc0, 0xc3, 0xc6, 0xc6, 0x97, 0xc2, 0xc2, 0x00}
};
void endecrypt(unsigned char *dst, const unsigned char *src, int val) {
int i;
for (i = 0; i < CODE_LEN; i++)
dst[i] = src[i] ^ val ^ i;
dst[CODE_LEN] = 0;
}
void target_0() {}
void target_1() {}
void target_2() {}
void target_3() {}
void target_4() {}
void target_5() {}
void target_6() {}
void target_7() {}
void target_8() {}
void target_9() {}
void target_a() {}
void target_b() {}
void target_c() {}
void target_d() {}
void target_e() {}
void target_f() {}
void target(char c) {
switch (c) {
case '0': target_0(); break;
case '1': target_1(); break;
case '2': target_2(); break;
case '3': target_3(); break;
case '4': target_4(); break;
case '5': target_5(); break;
case '6': target_6(); break;
case '7': target_7(); break;
case '8': target_8(); break;
case '9': target_9(); break;
case 'a': target_a(); break;
case 'b': target_b(); break;
case 'c': target_c(); break;
case 'd': target_d(); break;
case 'e': target_e(); break;
case 'f': target_f(); break;
}
}
unsigned char *another_target() {
unsigned char *code = malloc(CODE_LEN + 1);
endecrypt(code, ENCRYPTED[5], 0xaa ^ 5);
return code;
}
int main() {
int i;
unsigned long code_d_1 = 0xda2c30ab ^ 0xaaaaaaaa;
unsigned long code_d_2 = 0xab3f9ba0 ^ 0xaaaaaaaa;
unsigned char code[CODE_LEN + 1], c[2], *code_f;
// code a
const char *code_a = "ad8b0a518f4e717b";
code_a = code_a;
// code b
endecrypt(code, ENCRYPTED[1], 0xaa ^ 1);
open((char *)code, O_RDONLY);
// code c
endecrypt(code, ENCRYPTED[2], 0xaa ^ 2);
c[1] = 0;
for (i = 0; i < CODE_LEN; i++) {
c[0] = code[i];
write(-1, c, 1);
}
// code d
calloc(code_d_1 ^ 0xaaaaaaaa, code_d_2 ^ 0xaaaaaaaa);
// code e
endecrypt(code, ENCRYPTED[4], 0xaa ^ 4);
for (i = 0; i < CODE_LEN; i++)
target(code[i]);
// code f
code_f = another_target();
for (i = 0; i < CODE_LEN; i++)
code_f[i] = 0;
free(code_f);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment