Skip to content

Commit 2da1636

Browse files
committed
defcon-quals-2015: add dialects
1 parent 6871f4d commit 2da1636

File tree

22 files changed

+5936
-1
lines changed

22 files changed

+5936
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/brute_hash
2+
/test
3+
/example.com.*
4+
*.o
5+
__pycache__
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
all: test brute_hash example.com.crt
2+
3+
test: test.c libchina.o
4+
gcc -no-pie $^ -o $@
5+
6+
brute_hash: brute_hash.c libchina.o libsha.o
7+
gcc -no-pie -Ofast -fopenmp $^ -o $@
8+
9+
libchina.o: libchina.asm
10+
nasm -f elf64 $< -o $@
11+
12+
libsha.o: sha512.c
13+
gcc -Ofast -c sha512.c -o libsha.o
14+
15+
example.com.crt:
16+
openssl req -newkey rsa:2048 -nodes -keyout example.com.key -x509 -subj '/CN=lol/' -days 365 -out example.com.crt
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <stdio.h>
2+
#include "libchina.h"
3+
#include <omp.h>
4+
#include <string.h>
5+
#include "sha512.h"
6+
#include <stdlib.h>
7+
8+
char sha512_test(uint8_t *buffer) {
9+
uint8_t md[128];
10+
sha512_ctx ctx;
11+
12+
sha512_init(&ctx);
13+
sha512_update(&ctx, buffer, 32);
14+
sha512_final(&ctx, md);
15+
16+
return md[0] == 0x8d && md[1] == 0x36 && md[2] == 0;
17+
}
18+
char sm3_test(uint8_t *buffer) {
19+
SM3_CTX ctx;
20+
ossl_sm3_init(&ctx);
21+
ossl_sm3_update(&ctx, buffer, 32);
22+
23+
uint8_t md[SM3_DIGEST_LENGTH];
24+
ossl_sm3_final(md, &ctx);
25+
26+
return !(md[0] | md[1] | md[2]);
27+
}
28+
29+
30+
int main() {
31+
uint8_t gbl_buffer[32];
32+
33+
puts("Algo: ");
34+
char nome[100];
35+
scanf("%s", nome);
36+
37+
char sm3 = 0;
38+
if(nome[1] == 'm') {
39+
// sm3
40+
sm3 = 1;
41+
} // outro eh sha512
42+
43+
puts("Buffer: ");
44+
for(int i = 0; i < 32; i++) scanf("%x", gbl_buffer + i);
45+
46+
//memcpy(gbl_buffer, st, 32);
47+
48+
//printf("\nLeu: ");
49+
//for(int i = 0; i < 32; i++) printf("%02x ", gbl_buffer[i]);
50+
//puts("");
51+
52+
#pragma omp parallel for
53+
for(int i = 0; i < (1<<30); i++) {
54+
uint8_t buffer[32];
55+
56+
memcpy(buffer, gbl_buffer, 32);
57+
buffer[4] = (i) & 0xff;
58+
buffer[7] = (i>>8) & 0xff;
59+
buffer[12] = (i >> 16) & 0xff;
60+
buffer[3] = (i >> 24) & 0xff;
61+
62+
if((sm3 &&sm3_test(buffer)) || (!sm3 && sha512_test(buffer))) {
63+
#pragma omp critical
64+
{
65+
printf("Achou i = %d:", i);
66+
for(int j = 0; j < 32; j++) printf("%02x", buffer[j]);
67+
puts("");
68+
}
69+
exit(0);
70+
}
71+
}
72+
73+
return 0;
74+
}
4.43 MB
Binary file not shown.
4.43 MB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
defcon{test_flag}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from pwn import *
2+
3+
def start_conn():
4+
#return process('./ctf_patch_hash')
5+
p = process('./brute_hash')
6+
p.sendlineafter(b'Algo: \n', b'sm3')
7+
p.recvuntil(b'Buffer: \n')
8+
return p
9+
10+
def get(io, nonce_todo):
11+
pay = ' '.join(map(hex, nonce_todo))
12+
print('Pay: ', pay)
13+
io.sendline(pay.encode())
14+
15+
io.recvuntil(b':')
16+
data = bytes.fromhex(io.recvline().decode().strip())
17+
18+
if len(data) == 0:
19+
print('Hash not found')
20+
exit(1)
21+
assert len(data) == 32
22+
return data
23+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from pwn import *
2+
3+
def start_conn():
4+
return remote('localhost', 1337, ssl=True)
5+
6+
7+
def get(io, key):
8+
io.recv(8)
9+
io.send(key)
10+
11+
blk = b'\x00' * 0x100
12+
io.send(blk)
13+
14+
result = io.recv(0x100)
15+
io.close()
16+
return result
17+

0 commit comments

Comments
 (0)