Skip to content

Commit

Permalink
Restrict solutions to be in range A..Z
Browse files Browse the repository at this point in the history
  • Loading branch information
jakespringer committed Jul 25, 2017
1 parent 805a7b5 commit 2784f5d
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 88 deletions.
3 changes: 1 addition & 2 deletions 00_angr_find/00_angr_find.c.templite
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ userdef = ''.join(random.choice(userdef_charset) for _ in range(8))
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ptrace.h>

#define USERDEF "${ userdef }$"
#define LEN_USERDEF ${ write(len(userdef)) }$
Expand All @@ -21,7 +20,7 @@ void print_msg() {
}

int complex_function(int value, int i) {
#define LAMBDA 31
#define LAMBDA 3
if (!('A' <= value && value <= 'Z')) {
printf("Try again.\n");
exit(1);
Expand Down
11 changes: 6 additions & 5 deletions 01_angr_avoid/01_angr_avoid.c.templite
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
${
import random, os
random.seed(os.urandom(8))
userdef_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
userdef_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
userdef = ''.join(random.choice(userdef_charset) for _ in range(8))

def check_string_recursive(array0, array1, random_list, bit):
Expand All @@ -28,7 +28,6 @@ def check_string_recursive(array0, array1, random_list, bit):
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/syscall.h>

#define USERDEF "${ userdef }$"
#define LEN_USERDEF ${ write(len(userdef)) }$
Expand All @@ -46,10 +45,12 @@ void print_msg() {
}

int complex_function(int value, int i) {
if (!(33 < value && value < (33+94))) {
printf("Try again.\n"); exit(1);
#define LAMBDA 5
if (!('A' <= value && value <= 'Z')) {
printf("Try again.\n");
exit(1);
}
return (((value - 33 + 3*i) % 94) + 33);
return ((value - 'A' + (LAMBDA * i)) % ('Z' - 'A' + 1)) + 'A';
}

void avoid_me() {
Expand Down
1 change: 0 additions & 1 deletion 01_angr_avoid/generate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env pypy

import sys, random, os, tempfile
from templite import Templite

Expand Down
20 changes: 14 additions & 6 deletions 02_angr_find_condition/02_angr_find_condition.c.templite
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ${
import random, os
random.seed(os.urandom(8))

userdef_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
userdef_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
userdef = ''.join(random.choice(userdef_charset) for _ in range(8))

def generate_true_statement(variable, value):
Expand Down Expand Up @@ -32,7 +32,6 @@ def recursive_if_else(variable, value, depth):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ptrace.h>

#define USERDEF "${ userdef }$"
#define LEN_USERDEF ${ write(len(userdef)) }$
Expand All @@ -43,6 +42,15 @@ void print_msg() {
printf("%s", msg);
}

int complex_function(int value, int i) {
#define LAMBDA 31
if (!('A' <= value && value <= 'Z')) {
printf("Try again.\n");
exit(1);
}
return ((value - 'A' + (LAMBDA * i)) % ('Z' - 'A' + 1)) + 'A';
}

int main(int argc, char* argv[]) {
char buffer[20];
char password[20];
Expand All @@ -56,12 +64,12 @@ int main(int argc, char* argv[]) {

strncpy(password, USERDEF, LEN_USERDEF);

password[0] ^= password[1];
password[1] ^= password[0];
password[0] ^= password[1];

printf("Enter the password: ");
scanf("%8s", buffer);

for (int i=0; i<LEN_USERDEF; ++i) {
buffer[i] = complex_function(buffer[i], i+8);
}

${ recursive_if_else('x', 0xDEADBEEF, 8) }$
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def randomly_modify(var):

#include <stdio.h>
#include <stdlib.h>
#include <sys/ptrace.h>

register int eax asm("eax");
register int ebx asm("ebx");
Expand Down
1 change: 0 additions & 1 deletion 04_angr_symbolic_stack/04_angr_symbolic_stack.c.templite
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ userdef = [random.randint(0, 0xFFFFFFFF) for i in xrange(4)]

#include <stdio.h>
#include <stdlib.h>
#include <sys/ptrace.h>
#include <stdint.h>
#include <string.h>

Expand Down
11 changes: 6 additions & 5 deletions 05_angr_symbolic_memory/05_angr_symbolic_memory.c.templite
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ ${
import random, os
random.seed(os.urandom(8))

userdef_charset = [chr(i) for i in range(33, 127)]
userdef_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
userdef = repr(''.join(random.choice(userdef_charset) for _ in range(32)))[1:-1].replace('\"', '\\\"')
}$

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ptrace.h>
#define USERDEF "${ userdef }$"

char padding0[ ${ padding0 }$ ];
Expand All @@ -23,10 +22,12 @@ void print_msg() {
}

int complex_function(int value, int i) {
if (!(33 < value && value < (33+94))) {
printf("Try again.\n"); exit(1);
#define LAMBDA 9
if (!('A' <= value && value <= 'Z')) {
printf("Try again.\n");
exit(1);
}
return (((value - 33 + 17*i) % 94) + 33);
return ((value - 'A' + (LAMBDA * i)) % ('Z' - 'A' + 1)) + 'A';
}

int main(int argc, char* argv[]) {
Expand Down
56 changes: 36 additions & 20 deletions 06_angr_symbolic_heap/06_angr_symbolic_heap.c.templite
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
${
import random, os
random.seed(os.urandom(8))
userdef_charset = [chr(i) for i in range(33, 127)]
userdef = repr(''.join(random.choice(userdef_charset) for _ in range(32)))[1:-1].replace('\"', '\\\"')
userdef_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
userdef0 = ''.join([random.choice(userdef_charset) for _ in range(8)])
userdef1 = ''.join([random.choice(userdef_charset) for _ in range(8)])
userdef2 = ''.join([random.choice(userdef_charset) for _ in range(8)])
userdef3 = ''.join([random.choice(userdef_charset) for _ in range(8)])
}$

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ptrace.h>
#define USERDEF "${ userdef }$"
#define USERDEF0 "${ userdef0 }$"
#define USERDEF1 "${ userdef1 }$"
#define USERDEF2 "${ userdef2 }$"
#define USERDEF3 "${ userdef3 }$"

char padding2[${ padding2 }$];
char* padding0;
char* buffer;
char* padding1;
char padding2[${ padding }$];
char* buffer0;
char* buffer1;
char* buffer2;
char* buffer3;

char msg[] = "${ description }$";

Expand All @@ -23,34 +29,44 @@ void print_msg() {
}

int complex_function(int value, int i) {
if (!(33 < value && value < (33+94))) {
printf("Try again.\n"); exit(1);
#define LAMBDA 13
if (!('A' <= value && value <= 'Z')) {
printf("Try again.\n");
exit(1);
}
return (((value - 33 + 19*i) % 94) + 33);
return ((value - 'A' + (LAMBDA * i)) % ('Z' - 'A' + 1)) + 'A';
}

int main(int argc, char* argv[]) {
padding0 = malloc(${ write(random.randint(0, 2**26)) }$);
buffer = malloc(33);
padding1 = malloc(${ write(random.randint(0, 2**26)) }$);
buffer0 = malloc(9);
buffer1 = malloc(9);
buffer2 = malloc(9);
buffer3 = malloc(9);

memset(buffer, 0, 33);
memset(buffer0, 0, 9);
memset(buffer1, 0, 9);
memset(buffer2, 0, 9);
memset(buffer3, 0, 9);

print_msg();
printf("Enter the password: ");
scanf("%8s %8s %8s %8s", buffer, &buffer[8], &buffer[16], &buffer[24]);
scanf("%8s %8s %8s %8s", buffer0, buffer1, buffer2, buffer3);

for (int i=0; i<32; ++i) {
buffer[i] = complex_function(buffer[i], i);
}

if (strncmp(buffer, USERDEF, 32)) {
if (strncmp(buffer0, USERDEF0, 8)
|| strncmp(buffer1, USERDEF1, 8)
|| strncmp(buffer2, USERDEF2, 8)
|| strncmp(buffer3, USERDEF3, 8)) {
printf("Try again.\n");
} else {
printf("Good Job.\n");
}

free(padding1);
free(buffer);
free(padding0);
free(buffer0);
free(buffer1);
free(buffer2);
free(buffer3);
}
2 changes: 1 addition & 1 deletion 06_angr_symbolic_heap/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def generate(argv):
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'description.txt'), 'r') as desc_file:
description = desc_file.read().encode('string_escape').replace('\"', '\\\"')

padding2 = random.randint(0, 2**26)
padding = random.randint(0, 2**26)

template = open(os.path.join(os.path.dirname(os.path.realpath(__file__)), '06_angr_symbolic_heap.c.templite'), 'r').read()
c_code = Templite(template).render(description=description, padding2=padding2)
Expand Down
11 changes: 6 additions & 5 deletions 07_angr_symbolic_file/07_angr_symbolic_file.c.templite
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
${
import random, os
random.seed(os.urandom(8))
userdef_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
userdef_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
userdef0 = ''.join(random.choice(userdef_charset) for _ in range(8))
}$

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ptrace.h>
#define USERDEF0 "${ userdef0 }$"
#define USERDEF1 "${ userdef1 }$.txt"
#define FILESIZE 64
Expand All @@ -24,10 +23,12 @@ void print_msg() {
}

int complex_function(int value, int i) {
if (!(33 < value && value < (33+94))) {
printf("Try again.\n"); exit(1);
#define LAMBDA 17
if (!('A' <= value && value <= 'Z')) {
printf("Try again.\n");
exit(1);
}
return (((value - 33 + 23*i) % 94) + 33);
return ((value - 'A' + (LAMBDA * i)) % ('Z' - 'A' + 1)) + 'A';
}

void write_string_to_file(char* buffer, int length) {
Expand Down
2 changes: 1 addition & 1 deletion 07_angr_symbolic_file/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def generate(argv):
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'description.txt'), 'r') as desc_file:
description = desc_file.read().encode('string_escape').replace('\"', '\\\"')

userdef_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
userdef_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
userdef1 = ''.join(random.choice(userdef_charset) for _ in range(8))
template = open(os.path.join(os.path.dirname(os.path.realpath(__file__)), '07_angr_symbolic_file.c.templite'), 'r').read()
c_code = Templite(template).render(description=description, userdef1=userdef1)
Expand Down
1 change: 0 additions & 1 deletion 08_angr_constraints/08_angr_constraints.c.templite
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import random, os
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/ptrace.h>

#define USERDEF0 "${ userdef0 }$"
#define USERDEF1 "${ userdef1 }$"
Expand Down
11 changes: 6 additions & 5 deletions 09_angr_hooks/09_angr_hooks.c.templite
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
${
import random, os
random.seed(os.urandom(8))
userdef_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
userdef_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
userdef = [''.join(random.choice(userdef_charset) for _ in range(8)) for _ in range(4)]
}$

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/ptrace.h>

#define USERDEF0 "${ userdef[0] }$"
#define USERDEF1 "${ userdef[1] }$"
Expand All @@ -27,10 +26,12 @@ void print_msg() {
}

int complex_function(int value, int i) {
if (!(33 < value && value < (33+94))) {
printf("Try again.\n"); exit(1);
#define LAMBDA 23
if (!('A' <= value && value <= 'Z')) {
printf("Try again.\n");
exit(1);
}
return (((value - 33 + 31*i) % 94) + 33);
return ((value - 'A' + (LAMBDA * i)) % ('Z' - 'A' + 1)) + 'A';
}

int main(int argc, char* argv[]) {
Expand Down
11 changes: 6 additions & 5 deletions 10_angr_sim_procedures/10_angr_sim_procedures.c.templite
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
${
import random, os
random.seed(os.urandom(16))
userdef_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
userdef_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
userdef = [''.join(random.choice(userdef_charset) for _ in range(8)) for _ in range(4)]
def generate_true_statement(variable, value):
random_int = random.randint(0, 0xFFFFFFFF)
Expand Down Expand Up @@ -31,7 +31,6 @@ def recursive_if_else(variable, value, end_statement, depth):
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/ptrace.h>

#define USERDEF0 "${ userdef[0] }$"
#define USERDEF1 "${ userdef[1] }$"
Expand All @@ -52,10 +51,12 @@ void print_msg() {
}

int complex_function(int value, int i) {
if (!(33 < value && value < (33+94))) {
printf("Try again.\n"); exit(1);
#define LAMBDA 29
if (!('A' <= value && value <= 'Z')) {
printf("Try again.\n");
exit(1);
}
return (((value - 33 + 7*i) % 94) + 33);
return ((value - 'A' + (LAMBDA * i)) % ('Z' - 'A' + 1)) + 'A';
}

int main(int argc, char* argv[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import random, os
random.seed(os.urandom(16))

def generate_str_int():
userdef_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
userdef_charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
result = 0
for i, c in enumerate([random.choice(userdef_charset) for _ in xrange(4)]):
result |= ord(c) << (i * 8)
Expand All @@ -23,7 +23,6 @@ def expanded_switch_statement(variable, miss_statement, hit_statement, samples):
#include <string.h>
#include <stdint.h>
#include <signal.h>
#include <sys/ptrace.h>

char msg[] = "${ description }$";
char strcpy_buffer[8 + 4];
Expand Down Expand Up @@ -57,6 +56,8 @@ int main(int argc, char* argv[]) {
printf("Enter the password: ");
scanf("%u %32s", &key, user_buffer);

/* todo: add complex function */

${
hit_statement = """
strcpy(strcpy_buffer, user_buffer);
Expand Down
Loading

0 comments on commit 2784f5d

Please sign in to comment.