File size: 4,304 Bytes
8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc 7ef9917 8a72bbc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
import gradio as gr
import base64
import json
import re
import html
def decode_proxy_entry(encoded_str):
try:
# Step 1: Base64 decode
decoded_bytes = base64.b64decode(encoded_str)
# Step 2: Convert hex to ASCII
hex_string = decoded_bytes.decode('ascii')
json_string = bytes.fromhex(hex_string).decode('ascii')
# Step 3: Parse JSON
return json.loads(json_string)
except Exception as e:
return {"error": f"Decoding failed: {str(e)}"}
def process_html_input(html_content):
try:
# First, unescape HTML entities
unescaped_html = html.unescape(html_content)
# Extract data-ss array using regex
pattern = r'data-ss="\[(.*?)\]"'
match = re.search(pattern, unescaped_html, re.DOTALL)
if not match:
return {"error": "No data-ss attribute found in the HTML"}
data_ss_content = match.group(1)
# Extract individual base64 strings
entries = re.findall(r'"([A-Za-z0-9+/=]+)"', data_ss_content)
# If no matches with ", try regular quotes
if not entries:
entries = re.findall(r'"([A-Za-z0-9+/=]+)"', data_ss_content)
if not entries:
return {"error": "No base64 encoded entries found in data-ss attribute"}
results = []
for i, entry in enumerate(entries):
try:
result = decode_proxy_entry(entry)
results.append({
"entry": i + 1,
"decoded_data": result
})
except Exception as e:
results.append({
"entry": i + 1,
"error": f"Failed to decode: {str(e)}"
})
return {"results": results, "total_entries": len(results)}
except Exception as e:
return {"error": f"Error processing HTML: {str(e)}"}
def decode_single_entry(encoded_string):
try:
result = decode_proxy_entry(encoded_string)
return result
except Exception as e:
return {"error": str(e)}
# Test HTML data (shortened for performance)
test_html = '''<script
id="serverSelectorScript"
data-ss="["N2IyMjY5NjQyMjNhMzIzMDMxMmMyMjc1NzI2YzIyM2EyMjY4NzQ3NDcwNzMzYTVjMmY1YzJmMzEzMDM4MmUzMTM4MzEyZTMxMzEyZTMxMzczMTVjMmY1ZjVmNjM3MDMyMmU3MDY4NzAyMjJjMjI2ZTYxNmQ2NTIyM2EyMjcwNzM3OTYzNjg3YTRjNmY3MzQxNmU2NzY1NmM2NTczMzI0ZDIyN2Q="]"
></script>'''
# Create a much simpler interface
def create_simple_interface():
with gr.Blocks(title="Proxy Decoder", css=".gradio-container {max-width: 1200px !important}") as demo:
gr.Markdown("# Proxy Server Decoder")
with gr.Tab("Single Entry"):
with gr.Row():
with gr.Column():
single_input = gr.Textbox(
label="Base64 String",
placeholder="Paste base64 string here...",
lines=3
)
single_btn = gr.Button("Decode", variant="primary")
with gr.Column():
single_output = gr.JSON(label="Result")
with gr.Tab("HTML Parser"):
with gr.Row():
with gr.Column():
html_input = gr.Textbox(
label="HTML Content",
value=test_html,
lines=10
)
html_btn = gr.Button("Parse HTML", variant="primary")
with gr.Column():
html_output = gr.JSON(label="Results")
# Connect functions
single_btn.click(
decode_single_entry,
inputs=single_input,
outputs=single_output
)
html_btn.click(
process_html_input,
inputs=html_input,
outputs=html_output
)
return demo
# Launch directly without complex setup
if __name__ == "__main__":
demo = create_simple_interface()
demo.launch(
server_name="0.0.0.0",
server_port=7860,
share=False,
inbrowser=True,
show_error=True
) |