-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.py
301 lines (240 loc) · 11.1 KB
/
main.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#!/usr/bin/python3
import io
import os
import re
import sys
import time
import wget
import codecs
import asyncio
import pathlib
import requests
from os import walk
from zipfile import ZipFile
from time import gmtime, strftime
from pathlib import Path
from pysecuritytrails import SecurityTrails, SecurityTrailsError
api_st = os.getenv("SECURITYTRAILS_API")
st = SecurityTrails(api_st)
################################################################################
# Helper Functions
################################################################################
def generate_output_folder() -> None:
if not os.path.isdir("WhatsApp"):
os.mkdir("WhatsApp")
################################################################################
# Clean Files
################################################################################
def cleanZip() -> None:
mypath = pathlib.Path(__file__).parent.absolute()
f = []
for (dirpath, dirnames, filenames) in walk(mypath):
f.extend(filenames)
break
for item in f:
if item.endswith(".zip"):
os.remove(os.path.join(mypath, item))
################################################################################
# Save File RSC Mikrotik
################################################################################
def saveFileRSC(base_list):
listEnd = []
listEnd.append("# ============================================================" + "\n")
listEnd.append("#"+ "\n")
listEnd.append("# whatsapp_cidr_ipv4"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# ipv4 mikrotik address-list"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# List of the WhatsApp server IP addresses and ranges."+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# Maintainer : Meta"+ "\n")
listEnd.append("# Maintainer URL : https://about.meta.com/"+ "\n")
listEnd.append("# List source URL : https://developers.facebook.com/docs/whatsapp/guides/network-requirements/"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# Category : servers"+ "\n")
listEnd.append("# Version : 1"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# This File Date : " + strftime("%Y-%m-%d %H:%M:%S", gmtime()) + ""+ "\n")
listEnd.append("# Update Frequency: 24 hours"+ "\n")
listEnd.append("# Entries : " + str(len(base_list)) + ""+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# (C) 2011-" + strftime("%Y", gmtime()) + " HybridNetworks Ltd. -- All Rights Reserved"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# ============================================================"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("/ip firewall address-list"+ "\n")
for i in base_list:
listEnd.append("add list=WHATSAPP-CIDR comment=WHATSAPP-CIDR address=" + i)
finalFile = open("WhatsApp/whatsapp_cidr_ipv4.rsc", "w+", encoding='utf-8', newline='\n')
finalFile.writelines(listEnd)
finalFile.close()
################################################################################
# Save File
################################################################################
def saveFileList(base_list, format) -> None:
listEnd = []
listEnd.append("# ============================================================"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# whatsapp_cidr_ipv4"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# ipv4 hash:net ipset"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# List of the WhatsApp server IP addresses and ranges."+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# Maintainer : Meta"+ "\n")
listEnd.append("# Maintainer URL : https://about.meta.com/"+ "\n")
listEnd.append("# List source URL : https://developers.facebook.com/docs/whatsapp/guides/network-requirements/"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# Category : servers"+ "\n")
listEnd.append("# Version : 1"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# This File Date : " + strftime("%Y-%m-%d %H:%M:%S", gmtime()) + "\n")
listEnd.append("# Update Frequency: 24 hours"+ "\n")
listEnd.append("# Entries : " + str(len(base_list)) + "\n")
listEnd.append("#"+ "\n")
listEnd.append("# (C) 2011-" + strftime("%Y", gmtime()) + " HybridNetworks Ltd. -- All Rights Reserved"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# ============================================================"+ "\n")
listEnd.append("#"+ "\n")
listEnd.extend(base_list)
finalFile = open("WhatsApp/whatsapp_cidr_ipv4." + format, "w+", encoding='utf-8', newline='\n')
finalFile.writelines(listEnd)
finalFile.close()
################################################################################
# Save File List Domain
################################################################################
def saveFileListDomain(base_list, format) -> None:
listEnd = []
listEnd.append("# ============================================================"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# whatsapp_domainlist"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# subdomains.domain"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# List of the WhatsApp server domain and subdomains."+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# Maintainer : SecurityTrails"+ "\n")
listEnd.append("# Maintainer URL : https://securitytrails.com/"+ "\n")
listEnd.append("# List source URL : https://securitytrails.com/list/apex_domain/whatsapp.com"+ "\n")
listEnd.append("# List source URL : https://securitytrails.com/list/apex_domain/whatsapp.net"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# Category : domains"+ "\n")
listEnd.append("# Version : 2"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# This File Date : " + strftime("%Y-%m-%d %H:%M:%S", gmtime()) + "\n")
listEnd.append("# Update Frequency: 14th/month"+ "\n")
listEnd.append("# Entries : " + str(len(base_list)) + "\n")
listEnd.append("#"+ "\n")
listEnd.append("# (C) 2011-" + strftime("%Y", gmtime()) + " HybridNetworks Ltd. -- All Rights Reserved"+ "\n")
listEnd.append("#"+ "\n")
listEnd.append("# ============================================================"+ "\n")
listEnd.append("#"+ "\n")
listEnd.extend(base_list)
finalFile = open("WhatsApp/whatsapp_domainlist." + format, "w+", encoding='utf-8', newline='\n')
finalFile.writelines(listEnd)
finalFile.close()
################################################################################
# Download ZIP file from https://developers.facebook.com/
################################################################################
def parseTxt(intxt) -> None:
re_ip_mask = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}')
lst = []
data_list = str(intxt, 'UTF-8').split("\r\n")
for line in data_list:
ip = re.findall(re_ip_mask, line)
if ip:
lst.append(str(line) + "\n")
saveFileList(lst, "txt")
saveFileList(lst, "netset")
saveFileList(lst, "list")
saveFileRSC(lst)
def startNow() -> None:
url = 'https://developers.facebook.com/docs/whatsapp/guides/network-requirements/'
# Create the binary string html containing the HTML source
# response.read().decode('utf-8')
html = requests.get(url).content.decode('utf-8')
urls = re.findall("http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+", html)
for item in urls:
if item.find(".zip") != -1:
item = item.replace("amp;", "")
wget.download(item)
time.sleep(3)
mypath = pathlib.Path(__file__).parent.absolute()
f = []
for (dirpath, dirnames, filenames) in walk(mypath):
f.extend(filenames)
break
for fs in f:
if fs.find(".zip") != -1:
with ZipFile(fs) as zf:
for file in zf.namelist():
if "__MACOSX" not in file:
print(file)
zipa = ZipFile(fs)
txtf = zipa.read(file)
zipa.close()
cleanZip()
parseTxt(txtf)
################################################################################
# Security Trails API from https://securitytrails.com/
################################################################################
def startNowDomains() -> None:
# Check that it is working
try:
st.ping()
except SecurityTrailsError:
print('Ping failed')
sys.exit(1)
subdomains_wacom = st.domain_subdomains('whatsapp.com')
subdomains_wanet = st.domain_subdomains('whatsapp.net')
subdomains_wame = st.domain_subdomains('wa.me')
subdomains_wabiz = st.domain_subdomains('whatsapp.biz')
lst = []
try:
lstxt_wacom = re.search("'subdomains': (.+?)}", str(subdomains_wacom)).group(1)
lstxt_wacom = lstxt_wacom.replace("[", "").replace("]", "").replace("'", "").replace(",", "")
lstxt_wacom = list(lstxt_wacom.split(" "))
lstxt_wanet = re.search("'subdomains': (.+?)}", str(subdomains_wanet)).group(1)
lstxt_wanet = lstxt_wanet.replace("[", "").replace("]", "").replace("'", "").replace(",", "")
lstxt_wanet = list(lstxt_wanet.split(" "))
lstxt_wame = re.search("'subdomains': (.+?)}", str(subdomains_wame)).group(1)
lstxt_wame = lstxt_wame.replace("[", "").replace("]", "").replace("'", "").replace(",", "")
lstxt_wame = list(lstxt_wame.split(" "))
lstxt_wabiz = re.search("'subdomains': (.+?)}", str(subdomains_wabiz)).group(1)
lstxt_wabiz = lstxt_wabiz.replace("[", "").replace("]", "").replace("'", "").replace(",", "")
lstxt_wabiz = list(lstxt_wabiz.split(" "))
except Exception as e:
raise
else:
pass
finally:
pass
for line in lstxt_wacom:
lst.append(str(line) + ".whatsapp.com" + "\n")
for line in lstxt_wanet:
lst.append(str(line) + ".whatsapp.net" + "\n")
for line in lstxt_wame:
lst.append(str(line) + ".wa.me" + "\n")
for line in lstxt_wabiz:
lst.append(str(line) + ".whatsapp.biz" + "\n")
saveFileListDomain(lst, "txt")
################################################################################
# Main Function
################################################################################
async def main() -> None:
access_token = os.getenv("ACCESS_TOKEN")
if not access_token:
# access_token = os.getenv("GITHUB_TOKEN")
raise Exception("A personal access token is required to proceed!")
exclude_repos = os.getenv("EXCLUDED")
exclude_repos = ({x.strip() for x in exclude_repos.split(",")}
if exclude_repos else None)
exclude_langs = os.getenv("EXCLUDED_LANGS")
exclude_langs = ({x.strip() for x in exclude_langs.split(",")}
if exclude_langs else None)
generate_output_folder()
startNow()
if strftime("%d", gmtime()) in '14':
startNowDomains()
if __name__ == "__main__":
asyncio.run(main())