Wargame - 웹

Dreamhack - crawling

김가윤 2023. 10. 20. 00:07

단축 URL (Shortened URL)

  • 긴 URL을 단축하고 단축된 URL을 클릭하면 원래의 긴 URL로 이동하는 웹 기술이다.
  • URL Redirection 기법을 이용한다.

 

 

문제 설명

  • 드림이는 웹 크롤링 사이트를 구축했습니다. 크롤링 사이트에서 취약점을 찾고 flag를 획득하세요!

 

소스

로컬 호스트로 /admin 페이지를 접속하면 flag를 출력한다. 하지만, check_get에서 필터링을 적용한다.

#app.py
import socket
import requests
import ipaddress
from urllib.parse import urlparse
from flask import Flask, request, render_template

app = Flask(__name__)
app.flag = '__FLAG__'

def lookup(url):
    try:
        return socket.gethostbyname(url)
    except:
        return False

def check_global(ip):
    try:
        return (ipaddress.ip_address(ip)).is_global
    except:
        return False

def check_get(url):
    ip = lookup(urlparse(url).netloc)
    if ip == False or ip =='0.0.0.0':
        return "Not a valid URL."
    res=requests.get(url)
    if check_global(ip) == False:
        return "Can you access my admin page~?"
    for i in res.text.split('>'):
        if 'referer' in i:
            ref_host = urlparse(res.headers.get('refer')).netloc
            if ref_host == 'localhost':
                return False
            if ref_host == '127.0.0.1':
                return False 
    res=requests.get(url)
    return res.text

@app.route('/admin')
def admin_page():
    if request.remote_addr != '127.0.0.1':
    		return "This is local page!"
    return app.flag

@app.route('/validation')
def validation():
    url = request.args.get('url', '')
    ip = lookup(urlparse(url).netloc)
    res = check_get(url)
    return render_template('validation.html', url=url, ip=ip, res=res)

@app.route('/')
def index():
    return render_template('index.html')

if __name__=='__main__':
    app.run(host='0.0.0.0', port=3333)

 

이 부분에서 IP 주소가 공인 IP 주소면 True를 반환하고 사설 IP 주소면 False를 반환한다는 것을 알 수 있다. 이 말은 IP 주소는 127.0.0.1이 될 수 없다. 이를 통해서 공인 IP 주소를 사용하면서 127.0.0.1:3333/admin으로 요청을 보낼 방법이 필요하다는 것을 알 수 있다.

 

이를 해결하기 위해서 단축 URL을 사용해봤다.

http://127.0.0.1:3333/admin -> https://han.gl/zNvhQZ 

'Wargame - 웹' 카테고리의 다른 글

Dreamack - Dream Gallery  (0) 2023.10.23
Tomcat Manager  (0) 2023.10.18
filestorage  (0) 2023.06.03
[wargame.kr] fly me to the moon  (0) 2023.05.07
[wargame.kr] md5 password  (0) 2023.05.05