File size: 8,272 Bytes
f569489
 
 
 
 
 
 
 
 
 
 
2e0b1d5
f569489
 
 
2e0b1d5
f569489
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2e0b1d5
f569489
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2e0b1d5
f569489
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2e0b1d5
 
f569489
 
 
 
 
 
 
 
 
2e0b1d5
 
f569489
 
 
 
2e0b1d5
 
 
 
 
 
f569489
2e0b1d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f569489
2e0b1d5
f569489
 
 
 
2e0b1d5
 
 
 
 
 
f569489
2e0b1d5
f569489
 
2e0b1d5
f569489
 
 
2e0b1d5
 
 
 
 
 
 
 
 
 
f569489
 
 
2e0b1d5
f569489
 
 
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import streamlit as st
import base64
import json
import re
import html
import pandas as pd

# Set page configuration
st.set_page_config(
    page_title="Proxy Server Decoder",
    page_icon="πŸ”",
    layout="wide"
)

class ProxyServerDecoder:
    def decode_proxy_entry(self, encoded_str):
        """Decode a single proxy entry from base64 -> hex -> JSON"""
        try:
            # Add padding if needed
            padding = len(encoded_str) % 4
            if padding:
                encoded_str += '=' * (4 - padding)
            
            # 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 {
                "status": "success",
                "decoded_data": json.loads(json_string),
                "original_length": len(encoded_str)
            }
        except Exception as e:
            return {
                "status": "error", 
                "error": f"Decoding failed: {str(e)}",
                "original_length": len(encoded_str)
            }
    
    def extract_entries_from_html(self, html_content):
        """Extract base64 entries from HTML data-ss attribute"""
        try:
            unescaped_html = html.unescape(html_content)
            
            # Multiple patterns to catch different HTML formats
            patterns = [
                r'data-ss="\[(.*?)\]"',
                r"data-ss='\[(.*?)\]'",
                r'data-ss=\s*\[\s*(.*?)\s*\]'
            ]
            
            data_ss_content = None
            for pattern in patterns:
                match = re.search(pattern, unescaped_html, re.DOTALL)
                if match:
                    data_ss_content = match.group(1)
                    break
            
            if not data_ss_content:
                return []
            
            # Extract base64 strings
            base64_pattern = r'["\']([A-Za-z0-9+/=]+)["\']'
            entries = re.findall(base64_pattern, data_ss_content)
            
            return entries
        except Exception as e:
            st.error(f"Error extracting from HTML: {e}")
            return []
    
    def process_html(self, html_content):
        """Process HTML content and decode all entries"""
        entries = self.extract_entries_from_html(html_content)
        
        if not entries:
            return {
                "status": "error",
                "message": "No entries found in HTML"
            }
        
        results = []
        success_count = 0
        
        for i, entry in enumerate(entries):
            result = self.decode_proxy_entry(entry)
            result_data = {
                "entry_number": i + 1,
                "encoded_string": entry,
                "encoded_preview": f"{entry[:20]}...{entry[-10:]}" if len(entry) > 40 else entry,
                **result
            }
            results.append(result_data)
            
            if result["status"] == "success":
                success_count += 1
        
        return {
            "status": "success",
            "statistics": {
                "total_entries": len(entries),
                "successful_decodes": success_count,
                "failed_decodes": len(entries) - success_count,
                "success_rate": f"{(success_count/len(entries))*100:.1f}%"
            },
            "results": results
        }

def main():
    decoder = ProxyServerDecoder()
    
    st.title("πŸ” Proxy Server Decoder")
    st.markdown("Decode base64-encoded proxy server information from HTML script tags")
    
    # Sample data
    sample_html = '''<script
    id="serverSelectorScript"
    data-u="&quot;https://adnade.net/ptp/?user=platformsincome&amp;subid=131370&quot;"
    data-d="0"
    data-ss="[&quot;N2IyMjY5NjQyMjNhMzIzMDMxMmMyMjc1NzI2YzIyM2EyMjY4NzQ3NDcwNzMzYTVjMmY1YzJmMzEzMDM4MmUzMTM4MzEyZTMxMzEyZTMxMzczMTVjMmY1ZjVmNjM3MDMyMmU3MDY4NzAyMjJjMjI2ZTYxNmQ2NTIyM2EyMjcwNzM3OTYzNjg3YTRjNmY3MzQxNmU2NzY1NmM2NTczMzI0ZDIyN2Q=&quot;,&quot;N2IyMjY5NjQyMjNhMzEzODM1MmMyMjc1NzI2YzIyM2EyMjY4NzQ3NDcwNzMzYTVjMmY1YzJmMzkzNTJlMzIzMTM0MmUzNTMzMmUzNDM4NWMyZjVmNWY2MzcwMzIyZTcwNjg3MDIyMmMyMjZlNjE2ZDY1MjIzYTIyNmQ2NTc2NTM3MDYxNjM2NTU3NjE3MjczNjE3NzUwMjI3ZA==&quot;]"
    ></script>'''
    
    # Tabs
    tab1, tab2 = st.tabs(["πŸ“„ HTML Parser", "πŸ”€ Single Entry"])
    
    with tab1:
        st.header("HTML Content Parser")
        
        html_input = st.text_area(
            "Paste your HTML content with data-ss attribute:",
            value=sample_html,
            height=300,
            help="Paste the entire HTML script tag containing data-ss attribute"
        )
        
        if st.button("πŸ” Parse HTML", type="primary"):
            if html_input.strip():
                with st.spinner("Processing HTML content..."):
                    result = decoder.process_html(html_input)
                
                if result["status"] == "success":
                    st.success(f"βœ… Processed {result['statistics']['total_entries']} entries!")
                    
                    # Display statistics
                    stats = result["statistics"]
                    col1, col2, col3, col4 = st.columns(4)
                    with col1:
                        st.metric("Total Entries", stats["total_entries"])
                    with col2:
                        st.metric("Successful", stats["successful_decodes"])
                    with col3:
                        st.metric("Failed", stats["failed_decodes"])
                    with col4:
                        st.metric("Success Rate", stats["success_rate"])
                    
                    # Display results in expandable sections
                    st.subheader("Decoded Results")
                    for entry in result["results"]:
                        with st.expander(f"Entry #{entry['entry_number']} - {entry['encoded_preview']}"):
                            if entry["status"] == "success":
                                st.json(entry["decoded_data"])
                            else:
                                st.error(f"Error: {entry['error']}")
                    
                    # Download button
                    json_str = json.dumps(result, indent=2)
                    st.download_button(
                        label="πŸ“₯ Download Results as JSON",
                        data=json_str,
                        file_name="decoded_results.json",
                        mime="application/json"
                    )
                else:
                    st.error(f"❌ {result.get('message', 'Processing failed')}")
            else:
                st.warning("Please enter HTML content")
    
    with tab2:
        st.header("Single Entry Decoder")
        
        single_input = st.text_area(
            "Enter base64 encoded string:",
            height=150,
            placeholder="Paste your base64 string here...",
            help="Enter a single base64 encoded proxy entry"
        )
        
        if st.button("πŸ” Decode Single Entry", type="primary"):
            if single_input.strip():
                with st.spinner("Decoding entry..."):
                    result = decoder.decode_proxy_entry(single_input.strip())
                
                if result["status"] == "success":
                    st.success("βœ… Entry decoded successfully!")
                    st.json(result["decoded_data"])
                    
                    # Download single result
                    json_str = json.dumps(result["decoded_data"], indent=2)
                    st.download_button(
                        label="πŸ“₯ Download Decoded Data",
                        data=json_str,
                        file_name="single_decoded.json",
                        mime="application/json"
                    )
                else:
                    st.error(f"❌ {result.get('error', 'Decoding failed')}")
            else:
                st.warning("Please enter a base64 string")

if __name__ == "__main__":
    main()