summaryrefslogtreecommitdiff
path: root/set2
diff options
context:
space:
mode:
authorBenedict <benedict@0xb8000.de>2016-07-31 21:20:35 +0200
committerBenedict <benedict@0xb8000.de>2017-02-21 13:00:25 +0100
commit8c6d8449d8f9fed6f009f38878a80f17fcc778f2 (patch)
treeb5289249272dc102438c5f6eed6ba637536d8523 /set2
parent4ed371cc378a3b579d46ed89a2677769a6d5ea24 (diff)
completed set 2 challenge 13
Diffstat (limited to 'set2')
-rw-r--r--set2/Makefile8
-rw-r--r--set2/task11.c61
-rw-r--r--set2/task13.c53
3 files changed, 66 insertions, 56 deletions
diff --git a/set2/Makefile b/set2/Makefile
index 9c5f43e..a2d66d4 100644
--- a/set2/Makefile
+++ b/set2/Makefile
@@ -3,7 +3,7 @@ CC=gcc
CFLAGS := -g $(CFLAGS)
CLIBS=`pkg-config --cflags --libs libcrypto`
-all: task9 task10 task15
+all: task9 task10 task11 task12 task13 task15
task9:
$(CC) $(CFLAGS) task9.c $(LIB) $(CLIBS) -o task9
@@ -11,7 +11,11 @@ task10:
$(CC) $(CFLAGS) task10.c $(LIB) $(CLIBS) -o task10
task11:
$(CC) $(CFLAGS) task11.c $(LIB) $(CLIBS) -o task11
+task12:
+ $(CC) $(CFLAGS) task12.c $(LIB) $(CLIBS) -o task12
+task13:
+ $(CC) $(CFLAGS) task13.c $(LIB) $(CLIBS) -o task13
task15:
$(CC) $(CFLAGS) task15.c $(LIB) $(CLIBS) -o task15
clean:
- rm task9 task10 task15
+ rm task9 task10 task11 task12 task13 task15
diff --git a/set2/task11.c b/set2/task11.c
index 60483e0..e344a60 100644
--- a/set2/task11.c
+++ b/set2/task11.c
@@ -1,83 +1,36 @@
#include "../lib/lib2.h"
#include "../lib/lib.h"
-int random_number_between(int min, int max)
-{
- return (rand() % (max-min) + min);
-}
-
-
-int generate_random_bytes(char *buf, int length_key_bytes)
-{
- int random_number;
- int i;
- for(i=0;i<length_key_bytes;i++) {
- buf[i] = (char) random_number_between(0,255);
- }
-
-}
-
-char *encrypt_with_random_bytes(char *toencrypt, int length, int ecb)
-{
- int toappend_before = random_number_between(5,10);
- int toappend_after= random_number_between(5,10);
-
- char random_bytes[10];
- char key[16];
-
- char *result = malloc(length+toappend_before+toappend_after+1);
- char *ciphertext = malloc(length+toappend_before+toappend_after+1);
-
- generate_random_bytes(random_bytes, toappend_before);
-
- memcpy(result, random_bytes, toappend_before);
- memcpy(&result[toappend_before], toencrypt, length);
-
- generate_random_bytes(random_bytes, toappend_after);
-
- memcpy(&result[length+toappend_before], random_bytes, toappend_after);
-
- generate_random_bytes(key, 16);
-
-
- if(ecb)
- aes_ecb(result, (length+toappend_before+toappend_after), ciphertext, key, 128, 1);
- else {
- char iv[16];
- memset(iv, 0, 16);
- aes_cbc(result, (length+toappend_before+toappend_after), ciphertext, key, iv, 1);
- }
-
- return ciphertext;
-}
int main(int argc, char **argv)
{
- // set seed
+
// srand(1);
int i;
// encrypt ecb mode
char *cleartext = "Ok, dann mach ich mal einen richtigen Satz. Vielleicht ist das ECB mit so vielen gleichen Bloecken total ueberfordert. Oder der Satz muss einfach laenger sein. Man brauch also wirklich wohl erstmal ein bisschen Text, bevor man ECB erkennen kann";
char *ciphertext;
char *ciphertext_cbc;
- char iv[16];
+ char iv[17];
memset(iv, 0, 16);
-
ciphertext = encrypt_with_random_bytes(cleartext, strlen(cleartext), 1);
ciphertext_cbc = encrypt_with_random_bytes(cleartext, strlen(cleartext), 0);
- //aes_ecb(cleartext, strlen(cleartext), ciphertext, "BUMMS", 128, 1);
- //aes_cbc(cleartext, strlen(cleartext), ciphertext_cbc, "BUMMS", iv, 1);
+// aes_ecb(cleartext, strlen(cleartext), ciphertext, "BUMMS", 128, 1);
+// aes_cbc(cleartext, strlen(cleartext), ciphertext_cbc, "BUMMS", iv, 1);
if(string_is_ecb_encrypted(ciphertext_cbc, strlen(cleartext), 16))
printf("Das ist wohl ECB (ist es aber nicht!)\n");
if(string_is_ecb_encrypted(ciphertext, strlen(cleartext), 16))
printf("Das ist wohl ECB (richtig)\n");
+
/*
for(i=0;i<strlen(cleartext);i++)
printf("%c", ciphertext_cbc[i]);
*/
+ free(ciphertext);
+ free(ciphertext_cbc);
return 0;
}
diff --git a/set2/task13.c b/set2/task13.c
new file mode 100644
index 0000000..3b4a7ef
--- /dev/null
+++ b/set2/task13.c
@@ -0,0 +1,53 @@
+#include "../lib/lib2.h"
+#include "../lib/lib.h"
+
+
+/**
+ * One can request profiles by calling the function profile_for.
+ * This function ensures, that all created profiles are user profiles
+ * Since the profiles are encrypted and only the other side knows the
+ * key one cannot change the profile normally.
+ *
+ * But by making to special requst and combine them one can get a profile
+ * with the role admin (since it is encrypted with ECB mode)
+ *
+ * First Request:
+ * Create a profile such that one blocks ends with role=
+ * Create profile for bobi@test.com results in:
+ * email=bobi@test.com&uid=10&role=user
+ * Encrypted this results in three blocks
+ * The first encrypted block ist:
+ * email=bobi@test.
+ * The sencond is:
+ * com&uid=10&role=
+ * The third is not interesting for us
+ *
+ * Second Request:
+ * Create a profile such that a block start with admin. Combine it with
+ * the block which ends with role= concat them an we are admin!
+ * Create profile for bobi@test.admin
+ * First block is agian:
+ * email?bpbo@test.
+ * Second block is:
+ * admin&uid=10&rol
+ *
+ * When using a strict paser he maybe would not accept the string
+ * because of the second role=user
+ *
+ */
+
+int main(int argc, char **argv)
+{
+ // initialize key
+ generate_random_bytes(key, 16);
+
+ char *encrypted_user1 = profile_for("bobi@test.com");
+ char *encrypted_user2 = profile_for("bobi@test.admin");
+ char admin_user[50];
+ // create new user from the two above
+ memcpy(admin_user, encrypted_user1, 32);
+ memcpy(&admin_user[32], &encrypted_user2[16], 16);
+
+ // send new user to server
+ send_user(admin_user, 48);
+}