Update app.py
Browse files
app.py
CHANGED
|
@@ -3,51 +3,44 @@ import base64
|
|
| 3 |
import json
|
| 4 |
import re
|
| 5 |
import html
|
| 6 |
-
from typing import Dict, List, Union, Any
|
| 7 |
|
| 8 |
-
def decode_proxy_entry(encoded_str
|
| 9 |
-
"""Decode a single proxy entry with better error handling"""
|
| 10 |
try:
|
| 11 |
-
#
|
| 12 |
-
padding = len(encoded_str) % 4
|
| 13 |
-
if padding:
|
| 14 |
-
encoded_str += '=' * (4 - padding)
|
| 15 |
-
|
| 16 |
decoded_bytes = base64.b64decode(encoded_str)
|
|
|
|
|
|
|
| 17 |
hex_string = decoded_bytes.decode('ascii')
|
| 18 |
json_string = bytes.fromhex(hex_string).decode('ascii')
|
|
|
|
|
|
|
| 19 |
return json.loads(json_string)
|
| 20 |
except Exception as e:
|
| 21 |
-
return {"error": f"Decoding failed: {str(e)}"
|
| 22 |
|
| 23 |
-
def
|
| 24 |
-
"""Extract and decode all entries from HTML with improved parsing"""
|
| 25 |
try:
|
|
|
|
| 26 |
unescaped_html = html.unescape(html_content)
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
r"data-ss='\[(.*?)\]'",
|
| 32 |
-
r'data-ss=\s*\[\s*(.*?)\s*\]'
|
| 33 |
-
]
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
match = re.search(pattern, unescaped_html, re.DOTALL)
|
| 38 |
-
if match:
|
| 39 |
-
data_ss_content = match.group(1)
|
| 40 |
-
break
|
| 41 |
|
| 42 |
-
|
| 43 |
-
return "No data-ss attribute found in the HTML"
|
| 44 |
|
| 45 |
-
#
|
| 46 |
-
|
| 47 |
-
entries = re.findall(base64_pattern, data_ss_content)
|
| 48 |
|
|
|
|
| 49 |
if not entries:
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
results = []
|
| 53 |
for i, entry in enumerate(entries):
|
|
@@ -55,156 +48,82 @@ def extract_and_decode_html(html_content: str) -> Union[str, List[Dict]]:
|
|
| 55 |
result = decode_proxy_entry(entry)
|
| 56 |
results.append({
|
| 57 |
"entry": i + 1,
|
| 58 |
-
"
|
| 59 |
-
"decoded_data": result,
|
| 60 |
-
"status": "success"
|
| 61 |
})
|
| 62 |
except Exception as e:
|
| 63 |
results.append({
|
| 64 |
"entry": i + 1,
|
| 65 |
-
"
|
| 66 |
-
"error": f"Failed to decode: {str(e)}",
|
| 67 |
-
"status": "error"
|
| 68 |
})
|
| 69 |
|
| 70 |
-
return results
|
| 71 |
except Exception as e:
|
| 72 |
-
return f"Error processing HTML: {str(e)}"
|
| 73 |
|
| 74 |
-
def
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
return {"error":
|
| 80 |
-
|
| 81 |
-
# Add statistics
|
| 82 |
-
success_count = sum(1 for r in results if r.get('status') == 'success')
|
| 83 |
-
error_count = sum(1 for r in results if r.get('status') == 'error')
|
| 84 |
-
|
| 85 |
-
formatted_results = {
|
| 86 |
-
"statistics": {
|
| 87 |
-
"total_entries": len(results),
|
| 88 |
-
"successful_decodes": success_count,
|
| 89 |
-
"failed_decodes": error_count
|
| 90 |
-
},
|
| 91 |
-
"entries": {}
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
for result in results:
|
| 95 |
-
formatted_results["entries"][f"Entry {result['entry']}"] = result
|
| 96 |
-
|
| 97 |
-
return formatted_results
|
| 98 |
|
| 99 |
-
#
|
| 100 |
-
|
| 101 |
id="serverSelectorScript"
|
| 102 |
-
data-
|
| 103 |
-
data-d="0"
|
| 104 |
-
data-ss="["N2IyMjY5NjQyMjNhMzIzMDMxMmMyMjc1NzI2YzIyM2EyMjY4NzQ3NDcwNzMzYTVjMmY1YzJmMzEzMDM4MmUzMTM4MzEyZTMxMzEyZTMxMzczMTVjMmY1ZjVmNjM3MDMyMmU3MDY4NzAyMjJjMjI2ZTYxNmQ2NTIyM2EyMjcwNzM3OTYzNjg3YTRjNmY3MzQxNmU2NzY1NmM2NTczMzI0ZDIyN2Q=","N2IyMjY5NjQyMjNhMzEzODM1MmMyMjc1NzI2YzIyM2EyMjY4NzQ3NDcwNzMzYTVjMmY1YzJmMzkzNTJlMzIzMTM0MmUzNTMzMmUzNDM4NWMyZjVmNWY2MzcwMzIyZTcwNjg3MDIyMmMyMjZlNjE2ZDY1MjIzYTIyNmQ2NTc2NTM3MDYxNjM2NTU3NjE3MjczNjE3NzUwMjI3ZA==",...]"
|
| 105 |
></script>'''
|
| 106 |
|
| 107 |
-
#
|
| 108 |
-
|
| 109 |
-
gr.
|
| 110 |
-
|
| 111 |
-
Decode base64-encoded proxy server information from HTML script tags.
|
| 112 |
-
""")
|
| 113 |
-
|
| 114 |
-
with gr.Tab("🧩 Single Entry Decoder"):
|
| 115 |
-
gr.Markdown("Decode a single base64 encoded proxy entry")
|
| 116 |
-
with gr.Row():
|
| 117 |
-
with gr.Column():
|
| 118 |
-
single_input = gr.Textbox(
|
| 119 |
-
label="Base64 Encoded String",
|
| 120 |
-
placeholder="Paste your base64 string here...",
|
| 121 |
-
lines=3,
|
| 122 |
-
max_lines=5
|
| 123 |
-
)
|
| 124 |
-
single_decode_btn = gr.Button("🚀 Decode Entry", variant="primary")
|
| 125 |
-
with gr.Column():
|
| 126 |
-
single_output = gr.JSON(label="Decoded Result")
|
| 127 |
-
|
| 128 |
-
with gr.Tab("🌐 HTML Parser"):
|
| 129 |
-
gr.Markdown("Parse HTML and extract all proxy entries from data-ss attribute")
|
| 130 |
-
with gr.Row():
|
| 131 |
-
with gr.Column():
|
| 132 |
-
html_input = gr.Textbox(
|
| 133 |
-
label="HTML Script Tag",
|
| 134 |
-
value=your_html_data,
|
| 135 |
-
lines=15,
|
| 136 |
-
max_lines=20
|
| 137 |
-
)
|
| 138 |
-
html_parse_btn = gr.Button("🔍 Parse HTML and Decode All Entries", variant="primary")
|
| 139 |
-
with gr.Column():
|
| 140 |
-
html_output = gr.JSON(label="Decoded Results")
|
| 141 |
-
|
| 142 |
-
with gr.Tab("🧪 Test Your Data"):
|
| 143 |
-
gr.Markdown("Test the decoder with the provided sample data")
|
| 144 |
-
with gr.Row():
|
| 145 |
-
test_btn = gr.Button("🧪 Test with Provided HTML Data", variant="secondary")
|
| 146 |
-
clear_btn = gr.Button("🗑️ Clear Results")
|
| 147 |
-
test_output = gr.JSON(label="Test Results")
|
| 148 |
-
|
| 149 |
-
with gr.Tab("📚 About"):
|
| 150 |
-
gr.Markdown("""
|
| 151 |
-
## About This Tool
|
| 152 |
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
-
#
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
></script>
|
| 167 |
-
```
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
""")
|
| 175 |
-
|
| 176 |
-
# Event handlers
|
| 177 |
-
single_decode_btn.click(
|
| 178 |
-
fn=decode_proxy_entry,
|
| 179 |
-
inputs=single_input,
|
| 180 |
-
outputs=single_output
|
| 181 |
-
)
|
| 182 |
-
|
| 183 |
-
html_parse_btn.click(
|
| 184 |
-
fn=process_html_input,
|
| 185 |
-
inputs=html_input,
|
| 186 |
-
outputs=html_output
|
| 187 |
-
)
|
| 188 |
-
|
| 189 |
-
def test_with_provided_data():
|
| 190 |
-
return process_html_input(your_html_data)
|
| 191 |
-
|
| 192 |
-
test_btn.click(
|
| 193 |
-
fn=test_with_provided_data,
|
| 194 |
-
outputs=test_output
|
| 195 |
-
)
|
| 196 |
-
|
| 197 |
-
def clear_all():
|
| 198 |
-
return None, None, None
|
| 199 |
|
| 200 |
-
|
| 201 |
-
fn=clear_all,
|
| 202 |
-
outputs=[single_output, html_output, test_output]
|
| 203 |
-
)
|
| 204 |
|
|
|
|
| 205 |
if __name__ == "__main__":
|
|
|
|
| 206 |
demo.launch(
|
| 207 |
server_name="0.0.0.0",
|
| 208 |
server_port=7860,
|
| 209 |
-
share=False
|
|
|
|
|
|
|
| 210 |
)
|
|
|
|
| 3 |
import json
|
| 4 |
import re
|
| 5 |
import html
|
|
|
|
| 6 |
|
| 7 |
+
def decode_proxy_entry(encoded_str):
|
|
|
|
| 8 |
try:
|
| 9 |
+
# Step 1: Base64 decode
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
decoded_bytes = base64.b64decode(encoded_str)
|
| 11 |
+
|
| 12 |
+
# Step 2: Convert hex to ASCII
|
| 13 |
hex_string = decoded_bytes.decode('ascii')
|
| 14 |
json_string = bytes.fromhex(hex_string).decode('ascii')
|
| 15 |
+
|
| 16 |
+
# Step 3: Parse JSON
|
| 17 |
return json.loads(json_string)
|
| 18 |
except Exception as e:
|
| 19 |
+
return {"error": f"Decoding failed: {str(e)}"}
|
| 20 |
|
| 21 |
+
def process_html_input(html_content):
|
|
|
|
| 22 |
try:
|
| 23 |
+
# First, unescape HTML entities
|
| 24 |
unescaped_html = html.unescape(html_content)
|
| 25 |
|
| 26 |
+
# Extract data-ss array using regex
|
| 27 |
+
pattern = r'data-ss="\[(.*?)\]"'
|
| 28 |
+
match = re.search(pattern, unescaped_html, re.DOTALL)
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
if not match:
|
| 31 |
+
return {"error": "No data-ss attribute found in the HTML"}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
data_ss_content = match.group(1)
|
|
|
|
| 34 |
|
| 35 |
+
# Extract individual base64 strings
|
| 36 |
+
entries = re.findall(r'"([A-Za-z0-9+/=]+)"', data_ss_content)
|
|
|
|
| 37 |
|
| 38 |
+
# If no matches with ", try regular quotes
|
| 39 |
if not entries:
|
| 40 |
+
entries = re.findall(r'"([A-Za-z0-9+/=]+)"', data_ss_content)
|
| 41 |
+
|
| 42 |
+
if not entries:
|
| 43 |
+
return {"error": "No base64 encoded entries found in data-ss attribute"}
|
| 44 |
|
| 45 |
results = []
|
| 46 |
for i, entry in enumerate(entries):
|
|
|
|
| 48 |
result = decode_proxy_entry(entry)
|
| 49 |
results.append({
|
| 50 |
"entry": i + 1,
|
| 51 |
+
"decoded_data": result
|
|
|
|
|
|
|
| 52 |
})
|
| 53 |
except Exception as e:
|
| 54 |
results.append({
|
| 55 |
"entry": i + 1,
|
| 56 |
+
"error": f"Failed to decode: {str(e)}"
|
|
|
|
|
|
|
| 57 |
})
|
| 58 |
|
| 59 |
+
return {"results": results, "total_entries": len(results)}
|
| 60 |
except Exception as e:
|
| 61 |
+
return {"error": f"Error processing HTML: {str(e)}"}
|
| 62 |
|
| 63 |
+
def decode_single_entry(encoded_string):
|
| 64 |
+
try:
|
| 65 |
+
result = decode_proxy_entry(encoded_string)
|
| 66 |
+
return result
|
| 67 |
+
except Exception as e:
|
| 68 |
+
return {"error": str(e)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
# Test HTML data (shortened for performance)
|
| 71 |
+
test_html = '''<script
|
| 72 |
id="serverSelectorScript"
|
| 73 |
+
data-ss="["N2IyMjY5NjQyMjNhMzIzMDMxMmMyMjc1NzI2YzIyM2EyMjY4NzQ3NDcwNzMzYTVjMmY1YzJmMzEzMDM4MmUzMTM4MzEyZTMxMzEyZTMxMzczMTVjMmY1ZjVmNjM3MDMyMmU3MDY4NzAyMjJjMjI2ZTYxNmQ2NTIyM2EyMjcwNzM3OTYzNjg3YTRjNmY3MzQxNmU2NzY1NmM2NTczMzI0ZDIyN2Q="]"
|
|
|
|
|
|
|
| 74 |
></script>'''
|
| 75 |
|
| 76 |
+
# Create a much simpler interface
|
| 77 |
+
def create_simple_interface():
|
| 78 |
+
with gr.Blocks(title="Proxy Decoder", css=".gradio-container {max-width: 1200px !important}") as demo:
|
| 79 |
+
gr.Markdown("# Proxy Server Decoder")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
+
with gr.Tab("Single Entry"):
|
| 82 |
+
with gr.Row():
|
| 83 |
+
with gr.Column():
|
| 84 |
+
single_input = gr.Textbox(
|
| 85 |
+
label="Base64 String",
|
| 86 |
+
placeholder="Paste base64 string here...",
|
| 87 |
+
lines=3
|
| 88 |
+
)
|
| 89 |
+
single_btn = gr.Button("Decode", variant="primary")
|
| 90 |
+
with gr.Column():
|
| 91 |
+
single_output = gr.JSON(label="Result")
|
| 92 |
|
| 93 |
+
with gr.Tab("HTML Parser"):
|
| 94 |
+
with gr.Row():
|
| 95 |
+
with gr.Column():
|
| 96 |
+
html_input = gr.Textbox(
|
| 97 |
+
label="HTML Content",
|
| 98 |
+
value=test_html,
|
| 99 |
+
lines=10
|
| 100 |
+
)
|
| 101 |
+
html_btn = gr.Button("Parse HTML", variant="primary")
|
| 102 |
+
with gr.Column():
|
| 103 |
+
html_output = gr.JSON(label="Results")
|
| 104 |
|
| 105 |
+
# Connect functions
|
| 106 |
+
single_btn.click(
|
| 107 |
+
decode_single_entry,
|
| 108 |
+
inputs=single_input,
|
| 109 |
+
outputs=single_output
|
| 110 |
+
)
|
|
|
|
|
|
|
| 111 |
|
| 112 |
+
html_btn.click(
|
| 113 |
+
process_html_input,
|
| 114 |
+
inputs=html_input,
|
| 115 |
+
outputs=html_output
|
| 116 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
+
return demo
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
# Launch directly without complex setup
|
| 121 |
if __name__ == "__main__":
|
| 122 |
+
demo = create_simple_interface()
|
| 123 |
demo.launch(
|
| 124 |
server_name="0.0.0.0",
|
| 125 |
server_port=7860,
|
| 126 |
+
share=False,
|
| 127 |
+
inbrowser=True,
|
| 128 |
+
show_error=True
|
| 129 |
)
|