-
Notifications
You must be signed in to change notification settings - Fork 12
/
wiregen.py
211 lines (186 loc) · 8.95 KB
/
wiregen.py
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
#!/usr/bin/env python3
import cmd
import json
import os
import subprocess
import urllib.request as Web
import requests
import socket
import zipfile
import tempfile
import shutil
import sys
import getopt
import time
import getpass
pubK = None
prvK = None
def GenerateWG(path):
global pubK
global prvK
if os.path.isdir(path) != True:
os.mkdir(path)
if os.name == 'nt':
cmd = f"wg genkey | wtee {path}privatekey | wg pubkey > {path}publickey"
else:
cmd = f"wg genkey | tee {path}privatekey | wg pubkey > {path}publickey"
subprocess.check_output(cmd, shell=True).decode("utf-8").strip()
prvK = open(path + 'privatekey', 'r').readline().rstrip()
print(f' {colors.UNDERLINE}Private Key : {prvK}{colors.ENDC}')
pubK = open(path + 'publickey', 'r').readline().rstrip()
print(f' {colors.UNDERLINE}Public Key : {pubK}{colors.ENDC}')
def Login(user, paswd, config_path):
if os.path.isdir(config_path) != True:
os.mkdir(config_path)
url = "https://api.surfshark.com/v1/auth/login"
payload = json.dumps({"username": user, "password": paswd})
headers = {'Content-Type': 'application/json;charset=utf-8'}
response = requests.request("POST", url, headers=headers, data=payload)
if response.ok:
print(f'{colors.OKGREEN} Logged In{colors.ENDC}')
open(config_path + 'config.json', 'w').write(response.text)
else:
print(f'{colors.FAIL} Error {response.status_code}{colors.ENDC}')
exit()
def GetInfo(token):
url = "https://api.surfshark.com/v1/payment/subscriptions/current"
headers = {
'Content-Type': 'application/json;charset=utf-8',
'Accept': 'application/json',
'Authorization': f'Bearer {token}',
'Accept-Charset': 'utf-8',
'Ss-Variant-Slugs': 'test_36:b;test_34:a;test_41:b;feature_1:b;test_28:a;feature_chat_apple:b;feature_shadowsocks:b;test_50:a;test_55:b;feature_rotator:a;test108:b',
'Accept-Language': 'en-US;q=1.0',
'Accept-Encoding': 'gzip, deflate',
'User-Agent': 'Surfshark/2.24.0 (com.surfshark.vpnclient.ios; build:19; iOS 14.8.1) Alamofire/5.4.3 device/mobile'
}
response = requests.request("GET", url, headers=headers)
if response.ok:
JS = json.loads(response.text)
print(f"{colors.BOLD} Plan Details{colors.ENDC}\n Plan: {JS['name']}\n End Date: {JS['expiresAt']}")
else:
print(f' Error {response.status_code}')
exit()
def RegisterWireGuard(token, pubkey):
url = "https://api.surfshark.com/v1/account/users/public-keys"
payload = json.dumps({"pubKey": pubkey})
headers = {
'Content-Type': 'application/json;charset=utf-8',
'Accept': 'application/json',
'Authorization': f'Bearer {token}',
'Accept-Charset': 'utf-8',
'Ss-Variant-Slugs': 'test_36:b;test_34:a;test_41:b;feature_1:b;test_28:a;feature_chat_apple:b;feature_shadowsocks:b;test_50:a;test_55:b;feature_rotator:a;test108:b',
'Accept-Language': 'en-US;q=1.0',
'Accept-Encoding': 'gzip, deflate',
'User-Agent': 'Surfshark/2.24.0 (com.surfshark.vpnclient.ios; build:19; iOS 14.8.1) Alamofire/5.4.3 device/mobile'
}
response = requests.request("POST", url, headers=headers, data=payload)
if response.status_code == 200 or response.status_code == 201:
print(f" Status: OK\n Register: True\n Valid: {json.loads(response.text)['expiresAt']}")
else:
print(f" Error {response.status_code}")
sys.exit(2)
def Builder(path):
temp = tempfile.mkdtemp(prefix='wiregen-')
request = Web.Request('https://api.surfshark.com/v4/server/clusters/generic')
request.add_header("user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36")
JData = json.loads(Web.urlopen(request).read())
unique = {each['location']: each for each in JData}.values()
print(f'{colors.OKBLUE} Generating zip file{colors.ENDC}')
archive = zipfile.ZipFile(path+'Wireguard-Confs.zip', 'w', zipfile.ZIP_DEFLATED)
for i in unique:
try:
ip = socket.gethostbyname(i['connectionName'])
location = i['location'].replace(" ", "_")
with open(temp + '/' + location + '.conf', 'w') as file:
wg = f"# Script by Incognito Coder @IC_mods\n[Interface]\nPrivateKey = {prvK}\nAddress = 10.14.0.2/16\nDNS = 162.252.172.57, 149.154.159.92\n\n[Peer]\nPublicKey = {i['pubKey']}\nAllowedIps= 0.0.0.0/0\nEndpoint = {ip}:51820"
file.write(wg)
file.close()
archive.write(temp + '/' + location + '.conf', location + '.conf')
print(f"{colors.OKBLUE} {location}{colors.ENDC} Created Successfully.")
except:
print(f'{colors.FAIL}[?] {file} Invalid Hostname or Server is Down.{colors.ENDC}')
print(f'{colors.OKGREEN} Built{colors.ENDC}')
shutil.rmtree(temp)
class colors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
path = 'Wireguard-Data/'
def help():
os.system('cls' if os.name == 'nt' else 'clear')
print(
"┌───────────────────────────────────────────────────────────────────────┐\n"
f"|{colors.OKCYAN}\t ____ __ ____ _ _ {colors.ENDC}\t\t|\n"
f"|{colors.OKCYAN}\t/ ___| _ _ _ __ / _/ ___|| |__ __ _ _ __| | __{colors.ENDC}\t\t|\n"
f"|{colors.OKCYAN}\t\___ \| | | | '__| |_\___ \| '_ \ / _` | '__| |/ /{colors.ENDC}\t\t|\n"
f"|{colors.OKCYAN}\t ___) | |_| | | | _|___) | | | | (_| | | | < {colors.ENDC}\t\t|\n"
f"|{colors.OKCYAN}\t|____/ \__,_|_| |_| |____/|_| |_|\__,_|_| |_|\_\ {colors.ENDC}\t\t| \n"
f"|{colors.FAIL}\t__ _____ ____ _____ ____ _ _ _ ____ ____ {colors.ENDC}\t|\n"
f"|{colors.FAIL}\t\ \ / /_ _| _ \| ____/ ___| | | | / \ | _ \| _ \ {colors.ENDC}\t|\n"
f"|{colors.FAIL}\t \ \ /\ / / | || |_) | _|| | _| | | |/ _ \ | |_) | | | |{colors.ENDC}\t|\n"
f"|{colors.FAIL}\t \ V V / | || _ <| |__| |_| | |_| / ___ \| _ <| |_| |{colors.ENDC}\t|\n"
f"|{colors.FAIL}\t \_/\_/ |___|_| \_\_____\____|\___/_/ \_\_| \_\____/ {colors.ENDC}\t|\n"
"|\t\t\t\t\t\t\t\t\t|\n"
"├───────────────────────────────────────────────────────────────────────┤\n"
"|\t\t\t\t\t\t\t\t\t|\n"
f"|{colors.WARNING}\t Developer : Incognito Coder || Channel : T.me/IC_MODS {colors.ENDC}\t|\n"
"|\t\t\t\t\t\t\t\t\t|\n"
"├───────────────────────────────────────────────────────────────────────┤\n"
"| Version : 2.9 || GitHub : https://github.com/Incognito-Coder/Wiregen |\n"
"└───────────────────────────────────────────────────────────────────────┘"
)
print(f'{colors.HEADER}'
'[1] Create Configs\n'
'[2] Exit App'
f'{colors.ENDC}')
opt = input('> ')
if opt == '1':
email = input(f'{colors.BOLD} Enter Account Email : {colors.ENDC}')
password = getpass.getpass(prompt=f'{colors.BOLD} Enter Account Password : {colors.ENDC}')
Login(email, password, path)
GenerateWG(path)
jayson = json.load(open(f'{path}config.json'))
GetInfo(jayson['token'])
RegisterWireGuard(jayson['token'], pubK)
Builder(path)
elif opt == '2':
sys.exit(0)
else:
os.system('cls' if os.name == 'nt' else 'clear')
print('Undefined option.Exiting ...')
time.sleep(2)
def main(argv):
short_args = 'hu:p:'
long_args = ['help', 'user=', 'pass=']
username = ''
password = ''
try:
opts, args = getopt.getopt(argv, short_args, long_args)
except getopt.GetoptError:
sys.exit(2)
if argv:
for opt, arg in opts:
if opt in ('-u', '--user'):
username = arg
elif opt in ('-p', '--pass'):
password = arg
elif opt in ("-h", "--help"):
print(f'Incognito Coder SurfShark Wireguard Generator\n'
'Usage : -u TEXT -p TEXT')
sys.exit(0)
Login(username, password, path)
GenerateWG(path)
jayson = json.load(open(f'{path}config.json'))
RegisterWireGuard(jayson['token'], pubK)
Builder(path)
else:
help()
if __name__ == "__main__":
main(sys.argv[1:])