Skip to content
This repository was archived by the owner on Mar 10, 2023. It is now read-only.

Commit c15dcfd

Browse files
author
Sanjay C
committed
added example of the Compiled problem class
1 parent ed7e57f commit c15dcfd

File tree

6 files changed

+104
-0
lines changed

6 files changed

+104
-0
lines changed

Diff for: auth1/Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
all:
2+
gcc -Wall -m32 -pedantic --std=gnu99 -o radix auth1.c
3+
4+
clean:
5+
rm radix

Diff for: auth1/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This is an example of the Compiled problem_template
2+
3+
This is useful when trying to build binaries dynamically for multiple instances
4+
5+
One can specify a makefile or compiler sources/flags to compile the source files AFTER the flask substitution has been made for variables defined in challenge.py
6+
7+
The prog_name should be defined as well so that the proper executable will be marked with the right permissions

Diff for: auth1/auth1.c

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <unistd.h>
5+
#include <sys/types.h>
6+
7+
static char alphabet[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
8+
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
9+
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
10+
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
11+
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
12+
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
13+
'w', 'x', 'y', 'z', '0', '1', '2', '3',
14+
'4', '5', '6', '7', '8', '9', '+', '/'};
15+
16+
static int mod[] = {0, 2, 1};
17+
18+
char check_password(char *input) {
19+
int input_length = strlen(input);
20+
int output_length = 4 * ((input_length + 2) / 3);
21+
22+
char encoded_data[output_length+1];
23+
24+
for (int i = 0, j = 0; i < input_length;) {
25+
26+
unsigned int octet_a = i < input_length ? (unsigned char)input[i++] : 0;
27+
unsigned int octet_b = i < input_length ? (unsigned char)input[i++] : 0;
28+
unsigned int octet_c = i < input_length ? (unsigned char)input[i++] : 0;
29+
30+
unsigned int triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c;
31+
32+
encoded_data[j++] = alphabet[(triple >> 3 * 6) & 0x3F];
33+
encoded_data[j++] = alphabet[(triple >> 2 * 6) & 0x3F];
34+
encoded_data[j++] = alphabet[(triple >> 1 * 6) & 0x3F];
35+
encoded_data[j++] = alphabet[(triple >> 0 * 6) & 0x3F];
36+
}
37+
38+
for (int i = 0; i < mod[input_length % 3]; i++) {
39+
encoded_data[output_length - 1 - i] = '=';
40+
}
41+
return strncmp(encoded_data, "{{pwd}}", output_length);
42+
}
43+
44+
int main(int argc, char **argv){
45+
// Set the gid to the effective gid
46+
// gid_t gid = getegid();
47+
// setresgid(gid, gid, gid);
48+
49+
setvbuf(stdout, NULL, _IONBF, 0);
50+
51+
if (argc < 2) {
52+
printf("Please provide a password!\n");
53+
return -1;
54+
}
55+
56+
if (!check_password(argv[1])) {
57+
printf("Congrats, now where's my flag?\n");
58+
return 0;
59+
}
60+
else {
61+
printf("Incorrect Password!\n");
62+
return -1;
63+
}
64+
}

Diff for: auth1/challenge.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from hacksport.problem_templates import Compiled
2+
import base64
3+
4+
class Problem(Compiled):
5+
makefile = "Makefile"
6+
program_name = "radix"
7+
8+
def generate_flag(self, random):
9+
bf = "picoCTF{bAsE_64_eNCoDiNg_iS_EAsY_}"
10+
hexdigits = "{:08}".format(random.randrange(16**8))
11+
while (((len(bf) + len(hexdigits))*8) % 6 != 0):
12+
hexdigits = hexdigits[:-1]
13+
return "picoCTF{bAsE_64_eNCoDiNg_iS_EAsY_%s}" % hexdigits
14+
15+
def initialize(self):
16+
self.pwd = base64.b64encode((self.flag).encode()).decode()

Diff for: auth1/problem.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "Radix's Terminal",
3+
"category": "Reversing",
4+
"description" : "Can you find the password to {{url_for(\"radix\", display=\"Radix's login\")}}? You can also find the executable in {{directory}}?",
5+
"hints" : ["https://en.wikipedia.org/wiki/Base64"],
6+
"score" : 1,
7+
"author": "speeeday",
8+
"organization": "picoCTF"
9+
}

Diff for: auth1/writeup.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
If we look at the check_password function we see that they are comparing the obfuscated input to 'cGljb0NURntiQXNFXzY0X2VOQ29EaU5nX2lTX0VBc1l9'
2+
3+
If we pop that into a base64 decoder we get picoCTF{bAsE_64_eNCoDiNg_iS_EAsY}

0 commit comments

Comments
 (0)