-
Notifications
You must be signed in to change notification settings - Fork 7
/
wpr.py
1281 lines (1208 loc) · 64.7 KB
/
wpr.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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Script to automate, when possible, the passive reconnaissance performed a website prior to an assessment.
Also used to guide the reconnaissance phase by defining all steps (manual or automated).
See README.md file for API Key INI file example.
"""
import colorama
import argparse
import collections
import configparser
import dns.resolver
import requests
import time
import sys
import socket
import datetime
import json
import os
import tldextract
import git
import urllib.parse
import base64
import re
from termcolor import colored
from dns.resolver import NoAnswer
from dns.resolver import NoNameservers
from dns.resolver import NXDOMAIN
from requests.exceptions import ProxyError, RequestException
from googlesearch import search
from urllib.error import HTTPError
from tabulate import tabulate
from dnsdumpster.DNSDumpsterAPI import DNSDumpsterAPI
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
MOBILE_APP_STORE_COUNTRY_STORE_CODE = "LU" # Luxembourg
DEFAULT_CALL_TIMEOUT = 30
WAPPALYZER_MAX_MONTHS_RESULT_OLD = 6
INTERESTING_FILE_EXTENSIONS = ["pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "pps", "odp", "ods", "odt", "rtf",
"java", "cs", "vb", "py", "rb", "zip", "tar", "gz", "7z", "eml", "msg", "sql", "ini",
"xml", "back", "txt", "csv"]
# See issue https://github.com/righettod/website-passive-reconnaissance/issues/89
RCE_PRONE_PARAMETERS_DORK = "inurl:cmd | inurl:exec= | inurl:query= | inurl:code= | inurl:do= | inurl:run= | inurl:read= | inurl:ping= inurl:& site:%s"
def get_bing_dork_results(dork, api_key, http_proxy):
try:
web_proxies = configure_proxy(http_proxy)
infos = []
# See https://azure.microsoft.com/en-us/try/cognitive-services/?api=search-api-v7
# For API key including trial one
search_url = "https://api.cognitive.microsoft.com/bing/v7.0/search"
request_headers = {"Ocp-Apim-Subscription-Key": api_key, "User-Agent": USER_AGENT}
params = {"q": dork, "textFormat": "HTML", "count": 50, "safeSearch": "Off"}
response = requests.get(search_url, params=params, headers=request_headers, proxies=web_proxies, verify=(
http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
if response.status_code == 200:
data = response.json()
if "webPages" in data:
record_count = data["webPages"]["totalEstimatedMatches"]
infos.append(f"Estimated records count: {record_count}")
for result in data["webPages"]["value"]:
link = result["url"]
infos.append(f"Record found: {link}")
else:
url_encoded_dork = urllib.parse.quote(dork)
infos.clear()
infos.append(f"Bing respond 'HTTP Error {response.status_code}: {response.reason}' => Check your API key or use the Dork in a browser using the following url:")
infos.append(f"https://www.bing.com/search?q={url_encoded_dork}")
return infos
except RequestException as e:
return [f"Error during web call: {str(e)}"]
def get_google_dork_results(dork, http_proxy):
try:
infos = []
try:
# The module Google use urllib and it uses the environment
# variable "http_proxy" to determine which HTTP proxy to use
if http_proxy is not None:
os.environ["http_proxy"] = http_proxy
# Leverage the module Google to do the search via the dork
# Cleanup any exisiting Google cookies jar file
google_cookies_file = ".google-cookie"
if os.path.exists(google_cookies_file):
os.remove(google_cookies_file)
# Issue the on Google.com
search_results = search(
dork, tld="com", num=100, stop=100, pause=2, user_agent=USER_AGENT)
for result in search_results:
infos.append(f"Record found: {result}")
infos.sort()
except HTTPError as err:
if err.code == 429:
url_encoded_dork = urllib.parse.quote(dork)
infos.clear()
infos.append("Google respond 'HTTP Error 429: Too Many Requests' => Use another IP address or use the Dork in a browser using the following url:")
infos.append(f"https://www.google.com/search?q={url_encoded_dork}")
else:
raise
return infos
except RequestException as e:
return [f"Error during web call: {str(e)}"]
def get_intelx_infos(ip_or_domain, api_key, http_proxy):
try:
web_proxies = configure_proxy(http_proxy)
infos = []
# Intelligence X free API have hits credtis depending on the service consumed
# A new account must be created after consumed all credits
# See https://intelx.io/account?tab=developer
request_headers = {"User-Agent": USER_AGENT, "x-key": api_key}
payload = {
"term": ip_or_domain,
"buckets": [],
"lookuplevel": 0,
"maxresults": 100,
"timeout": 0,
"datefrom": "",
"dateto": "",
"sort": 4,
"media": 0,
"terminate": []
}
# First we must do a search
service_url = f"https://2.intelx.io/intelligent/search"
response = requests.post(service_url, data=json.dumps(payload), headers=request_headers, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
if response.status_code != 200:
infos.append(f"HTTP response code {response.status_code} received for the search!")
return infos
# Then get the result for the search
search_id = str(response.json()["id"])
service_url += f"/result?id={search_id}"
response = requests.get(service_url, headers=request_headers, proxies=web_proxies, verify=(
http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
# Count result by bucket
if response.status_code != 200:
infos.append(f"HTTP response code {response.status_code} received for the result of the search!")
return infos
data = response.json()
buckets = {}
pasties = {}
if "records" in data:
for record in data["records"]:
if "bucket" in record:
bucket_name = record["bucket"]
# Special processing for Pasties, we extract URL and added date...
if bucket_name.lower() == "pastes" and "keyvalues" in record:
for paste in record["keyvalues"]:
value = paste["value"] # Contains the paste URL
pasties[value] = record["added"]
if bucket_name not in buckets:
buckets[bucket_name.lower()] = 0
buckets[bucket_name.lower()] += 1
# Add the information
for bucket_name in buckets:
infos.append(f"{buckets[bucket_name]} records for bucket {bucket_name}")
for paste in pasties:
infos.append(f"Paste '{paste}' added on {pasties[paste]}")
return infos
except RequestException as e:
return [f"Error during web call: {str(e)}"]
def extract_infos_from_virus_total_response(http_response):
try:
infos = []
if http_response.status_code != 200:
if http_response.status_code != 204:
infos.append(f"HTTP response code {http_response.status_code} received!")
else:
infos.append(f"Request rate limit exceeded: Wait one minute and re-run the script!")
else:
results = http_response.json()
# From VT API doc regarding the "response_code" property:
# If the item you searched for was not present in VirusTotal's dataset this result will be 0.
# If the requested item is still queued for analysis it will be -2.
# If the item was indeed present and it could be retrieved it will be 1.
# See https://developers.virustotal.com/reference#api-responses
rc = results["response_code"]
msg = results["verbose_msg"]
infos.append(f"Presence = {msg}")
if rc == 1:
urls_detected_count = 0
urls_undetected_count = 0
samples_detected_download_count = 0
samples_undetected_download_count = 0
if "detected_urls" in results:
urls_detected_count = len(results["detected_urls"])
if "undetected_urls" in results:
urls_undetected_count = len(results["undetected_urls"])
if "detected_downloaded_samples" in results:
samples_detected_download_count = len(results["detected_downloaded_samples"])
if "undetected_downloaded_samples" in results:
samples_undetected_download_count = len(results["undetected_downloaded_samples"])
infos.append(f"URLs at this IP address that have at least one detection on a URL scan = {urls_detected_count}")
infos.append(f"URLs at this IP address with no detections on a URL scan = {urls_undetected_count}")
infos.append(f"Files that have been downloaded from this IP address with at least one AV detection = {samples_detected_download_count}")
infos.append(f"Files that have been downloaded from this IP address with zero AV detections = {samples_undetected_download_count}")
elif rc == -2:
infos.append(f"Pending analysis for this item.")
return infos
except RequestException as e:
return [f"Error during web call: {str(e)}"]
def get_main_domain_without_tld(domain):
domain_infos = tldextract.extract(domain)
return domain_infos.domain
def configure_proxy(http_proxy):
web_proxies = {}
if http_proxy is not None:
web_proxies["http"] = http_proxy
web_proxies["https"] = http_proxy
return web_proxies
def test_proxy_connectivity(http_proxy):
msg = ""
try:
web_proxies = {"http": http_proxy, "https": http_proxy}
service_url = "https://perdu.com/"
response = requests.get(service_url, headers={"User-Agent": USER_AGENT}, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
if response.status_code == 200:
msg = "Succeed"
else:
msg = f"Failed (HTTP response code = {response.status_code})"
except ProxyError as e:
msg = f"Failed ({str(e)})"
return msg
def print_infos(info_list, prefix=""):
if len(info_list) == 0:
print(f"{prefix}No data found")
else:
for info in info_list:
print(f"{prefix}{info}")
def print_infos_as_table(data):
if len(data) == 1:
print(f" No data found")
else:
print(tabulate(data, headers="firstrow", tablefmt="github", numalign="left", stralign="left"))
def do_whois_request(ip, whois_server):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((whois_server, 43))
s.send((ip + "\r\n").encode())
response = b""
while True:
data = s.recv(4096)
response += data
if not data:
break
s.close()
return response.decode("utf-8", "ignore")
def do_whois(ip):
whois_org = ["arin", "lacnic", "afrinic", "ripe", "apnic"]
whois_server_tpl = "whois.%s.net"
# First try with ARIN
whois_response = do_whois_request(ip, whois_server_tpl % "arin")
for line in whois_response.splitlines():
if line.strip().startswith("Ref:"):
# IP block is not managed by ARIN so we call the provided org in the Ref link
link = line[4:].strip(" ")
org = link.split("/")[-1]
if org.lower() in whois_org:
whois_response = do_whois_request(ip, whois_server_tpl % org)
break
return whois_response
def get_ip_addresses(domain, name_server, record_types):
ips = []
resolver = dns.resolver.Resolver(configure=True)
if name_server is not None:
resolver.nameservers = [name_server]
for record_type in record_types:
try:
answer = resolver.resolve(domain, record_type)
for data in answer:
ips.append(data.to_text())
except NoAnswer:
pass
except NoNameservers:
pass
except NXDOMAIN:
pass
return ips
def get_cnames(domain, name_server):
cnames = []
resolver = dns.resolver.Resolver(configure=True)
if name_server is not None:
resolver.nameservers = [name_server]
try:
answer = resolver.resolve(domain, "CNAME")
for data in answer:
cnames.append(data.target.to_text())
except NoAnswer:
pass
return cnames
def get_active_shared_hosts(ip, http_proxy, viewdns_api_key):
try:
web_proxies = configure_proxy(http_proxy)
infos = []
# HackerTarget API is limited of 50 queries per day
# See https://hackertarget.com/ip-tools/
service_url = f"https://api.hackertarget.com/reverseiplookup/?q={ip}"
response = requests.get(service_url, headers={"User-Agent": USER_AGENT}, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
if response.status_code != 200:
infos.append(f"HTTP response code {response.status_code} received!")
return infos
vhosts = response.text
for vhost in vhosts.splitlines():
if vhost != ip:
infos.append(vhost)
# See https://viewdns.info/api/
if viewdns_api_key is not None:
service_url = f"https://api.viewdns.info/reverseip/?host={ip}&apikey={viewdns_api_key}&output=json"
response = requests.get(service_url, headers={"User-Agent": USER_AGENT}, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
if response.status_code != 200:
infos.append(f"HTTP response code {response.status_code} received from ViewDNS API !")
else:
results = response.json()
if "response" in results and "domains" in results["response"]:
for result in results["response"]["domains"]:
vhost = result["name"]
if vhost not in infos:
infos.append(vhost)
else:
service_url = f"https://viewdns.info/reverseip/?host={ip}&t=1"
response = requests.get(service_url, headers={"User-Agent": USER_AGENT}, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
if response.status_code != 200:
infos.append(f"HTTP response code {response.status_code} received from ViewDNS site !")
else:
results = response.text
vhosts = re.findall(r'<td>([a-zA-Z0-9\-\.]+)<\/td>', results)
for vhost in vhosts:
if "." in vhost and vhost not in infos:
infos.append(vhost.strip(' \r\t\n'))
infos.sort()
return infos
except RequestException as e:
return [f"Error during web call: {str(e)}"]
def get_passive_shared_hosts(ip, http_proxy):
try:
web_proxies = configure_proxy(http_proxy)
infos = []
# See https://www.threatminer.org/api.php
service_url = f"https://api.threatminer.org/v2/host.php?q={ip}&rt=2"
response = requests.get(service_url, headers={"User-Agent": USER_AGENT}, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
if response.status_code != 200:
infos.append(f"HTTP response code {response.status_code} received from ThreatMiner API !")
else:
results = response.json()
if results["status_code"] == "200":
for result in results["results"]:
vhost = result["domain"].split(":")[0]
if vhost not in infos:
infos.append(vhost)
infos.sort()
return infos
except RequestException as e:
return [f"Error during web call: {str(e)}"]
def get_ip_owner(ip, http_proxy):
try:
infos = []
data = do_whois(ip)
records = data.splitlines()
records_skip_prefix = ["Ref:", "OrgTech", "OrgAbuse", "OrgNOC", "tech-c", "admin-c", "remarks", "e-mail", "abuse", "Comment", "#", "%"]
for record in records:
if len(record.strip()) == 0:
continue
skip_it = False
for prefix in records_skip_prefix:
if record.startswith(prefix):
skip_it = True
break
if not skip_it:
infos.append(record)
return infos
except RequestException as e:
return [f"Error during web call: {str(e)}"]
def get_shodan_ip_infos(ip, api_key, http_proxy):
try:
web_proxies = configure_proxy(http_proxy)
infos = []
# See https://developer.shodan.io/api
service_url = f"https://api.shodan.io/shodan/host/{ip}?key={api_key}&minify=true"
response = requests.get(service_url, headers={"User-Agent": USER_AGENT}, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
if response.status_code != 200:
infos.append(f"HTTP response code {response.status_code} received!")
return infos
data = response.json()
value = data["last_update"]
infos.append(f"Last scan date = {value}")
value = data["isp"]
infos.append(f"ISP = {value}")
value = data["org"]
infos.append(f"Organization = {value}")
value = " , ".join(data["hostnames"])
infos.append(f"Hostnames = {value}")
value = data["ports"]
infos.append(f"Ports = {value}")
return infos
except RequestException as e:
return [f"Error during web call: {str(e)}"]
def get_shodan_cpe_cve_infos(ip, api_key, http_proxy):
try:
web_proxies = configure_proxy(http_proxy)
infos = []
# See https://developer.shodan.io/api
# Note: Historical IP lookups require a membership or API subscription
service_url = f"https://api.shodan.io/shodan/host/{ip}?key={api_key}&history=false"
response = requests.get(service_url, headers={"User-Agent": USER_AGENT}, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
if response.status_code != 200:
infos.append(
f"HTTP response code {response.status_code} received!")
return infos
data = response.json()
if "data" in data:
# Extract the whole list of CPE and CVE detected by Shodan gathered by scan date
cpe_cve_collection = collections.OrderedDict()
for record in data["data"]:
if "cpe" in record or "vulns" in record:
timestamp = record["timestamp"]
if timestamp not in cpe_cve_collection:
cpe_cve_collection[timestamp] = {"CPE": [], "CVE": []}
if "cpe" in record:
cpe_cve_collection[timestamp]["CPE"].extend(
record["cpe"])
if "vulns" in record and len(record["vulns"]) > 0:
cves = []
vulns = record["vulns"]
for vuln_id in vulns:
summary = vulns[vuln_id]["summary"]
if len(summary) > 100:
summary = summary[:100] + "..."
cves.append(
"CVSS " + str(vulns[vuln_id]["cvss"]) + " - " + vuln_id + " - " + summary)
cves.sort(reverse=True) # Highest CVSS score on top
cpe_cve_collection[timestamp]["CVE"].extend(cves)
# Extract interesting infos by showing detected CPE with their associated CVE
cpe_already_extracted = []
cve_already_extracted = []
for cpe_cve_record in cpe_cve_collection:
scan_date_already_added = False
for cpe in cpe_cve_collection[cpe_cve_record]["CPE"]:
if cpe not in cpe_already_extracted:
if not scan_date_already_added:
infos.append(f"Scan date {cpe_cve_record}:")
scan_date_already_added = True
value = f" Detected software: '{cpe}'"
infos.append(value)
cpe_already_extracted.append(cpe)
for cve in cpe_cve_collection[cpe_cve_record]["CVE"]:
if cve not in cve_already_extracted:
infos.append(f" Detected CVE: {cve}")
cve_already_extracted.append(cve)
return infos
except RequestException as e:
return [f"Error during web call: {str(e)}"]
def get_qualys_sslscan_cached_infos(domain, ip, http_proxy):
try:
web_proxies = configure_proxy(http_proxy)
infos = []
# See https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md
service_url = f"https://api.ssllabs.com/api/v3/getEndpointData?host={domain}&s={ip}&fromCache=on"
response = requests.get(service_url, headers={"User-Agent": USER_AGENT}, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
if "errors" not in response.text and "statusMessage" not in response.text:
infos.append(f"HTTP response code {response.status_code} received!")
return infos
data = response.json()
if "errors" in data:
error_msg = ""
for error in data["errors"]:
error_msg += error["message"]
infos.append(f"{error_msg}")
if "statusMessage" in data and data["statusMessage"] == "Ready":
if "ipAddress" in data:
value = data["ipAddress"]
infos.append(f"IPAddress = {value}")
if "serverName" in data:
value = data["serverName"]
infos.append(f"ServerName = {value}")
if "grade" in data:
value = data["grade"]
infos.append(f"Grade = {value}")
if "details" in data:
details = data["details"]
value = datetime.datetime.fromtimestamp(
details["hostStartTime"]/1000.0).strftime("%Y-%d-%mT%H:%M:%S")
infos.append(f"AssessmentStartingTime = {value}")
value = details["vulnBeast"]
infos.append(f"BEAST = {value}")
value = details["heartbleed"]
infos.append(f"HEARTBLEED = {value}")
value = details["poodle"]
infos.append(f"POODLE = {value}")
value = details["freak"]
infos.append(f"FREAK = {value}")
value = details["logjam"]
infos.append(f"LOGJAM = {value}")
if "drownVulnerable" in details:
value = details["drownVulnerable"]
infos.append(f"DROWN = {value}")
value = (details["ticketbleed"] == 2)
infos.append(f"TICKETBLEED = {value}")
value = (details["bleichenbacher"] ==
2 or details["bleichenbacher"] == 3)
infos.append(f"ROBOT = {value}")
return infos
except RequestException as e:
return [f"Error during web call: {str(e)}"]
def get_hybrid_analysis_report_infos(query, api_key, http_proxy):
try:
web_proxies = configure_proxy(http_proxy)
infos = []
# See https://www.hybrid-analysis.com/docs/api/v2
service_url = f"https://www.hybrid-analysis.com/api/search?query={query}"
response = requests.get(service_url, headers={"User-Agent": "Falcon", "api-key": api_key}, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
if response.status_code != 200:
infos.append(f"HTTP response code {response.status_code} received!")
return infos
data = response.json()
rc = data["response_code"]
if rc == 0:
if len(data["response"]["result"]) > 0:
result = data["response"]["result"][0]
infos.append(f"Verdict = {result['verdict'].capitalize()}")
infos.append(f"Analysis time = {result['start_time']}")
else:
infos.append("No report found")
else:
infos.append(f"Call to API failed (RC = {rc})")
return infos
except RequestException as e:
return [f"Error during web call: {str(e)}"]
def get_virus_total_report_infos(domain, ip_list, api_key, http_proxy):
try:
web_proxies = configure_proxy(http_proxy)
infos = {}
# See https://developers.virustotal.com/reference
# Note: As VT as a limit of 4 requests by minute then this function
# handle globally the retrieval of infos from VT and handle this limitation
# Get info for the domain
vt_call_count = 0
service_url = f"https://www.virustotal.com/vtapi/v2/domain/report?apikey={api_key}&domain={domain}"
response = requests.get(service_url, headers={"User-Agent": USER_AGENT}, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
vt_call_count += 1
infos[domain] = extract_infos_from_virus_total_response(response)
# Get info for the IPs
for ip in ip_list:
if vt_call_count > 4:
time.sleep(60)
vt_call_count = 0
service_url = f"https://www.virustotal.com/vtapi/v2/ip-address/report?apikey={api_key}&ip={ip}"
response = requests.get(service_url, headers={"User-Agent": USER_AGENT}, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
vt_call_count += 1
infos[ip] = extract_infos_from_virus_total_response(response)
return infos
except RequestException as e:
msg = [f"Error during web call: {str(e)}"]
infos = {}
infos[domain] = msg
for ip in ip_list:
infos[ip] = msg
return infos
def get_certificate_transparency_log_subdomains(domain, http_proxy):
try:
web_proxies = configure_proxy(http_proxy)
infos = []
# See https://crt.sh
service_url = f"https://crt.sh/?q=%.{domain}&output=json"
response = requests.get(service_url, headers={"User-Agent": USER_AGENT}, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
if response.status_code != 200:
infos.append(f"HTTP response code {response.status_code} received!")
return infos
results = response.json()
for entry in results:
cert_name = f"{entry['name_value']} ({entry['issuer_name']})"
if cert_name not in infos:
infos.append(cert_name)
return infos
except RequestException as e:
return [f"Error during web call: {str(e)}"]
def get_github_repositories(domain_or_ip, http_proxy):
try:
web_proxies = configure_proxy(http_proxy)
infos = []
# See https://developer.github.com/v3/search/#search-repositories
term = f"%22{domain_or_ip}%22"
service_url = f"https://api.github.com/search/repositories?q=size:%3E0+{term}&sort=updated&order=desc"
response = requests.get(service_url, headers={"User-Agent": USER_AGENT}, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
if response.status_code != 200:
infos.append(f"HTTP response code {response.status_code} received!")
return infos
results = response.json()
for repo in results["items"]:
html_url = repo["html_url"]
is_fork = repo["fork"]
forks = repo["forks"]
watchers = repo["watchers"]
infos.append(
f"{html_url} (IsFork: {is_fork} - Forks: {forks} - Watchers: {watchers})")
return infos
except RequestException as e:
return [f"Error during web call: {str(e)}"]
def get_softwareheritage_infos(domain_or_ip, http_proxy):
try:
web_proxies = configure_proxy(http_proxy)
infos = {"DATA": [], "LIMIT": "NA"}
# See https://archive.softwareheritage.org/api
service_url = f"https://archive.softwareheritage.org/api/1/origin/search/{domain_or_ip}/?limit=1000&with_visit=true"
# Set a long timeout (up to 4 minutes) because the response take a while to reply
response = requests.get(service_url, headers={"User-Agent": USER_AGENT}, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
if response.status_code != 200:
infos["DATA"].append(f"HTTP response code {response.status_code} received!")
return infos
results = response.json()
remaining_allowed_call_for_current_hour = response.headers["X-RateLimit-Remaining"]
next_call_count_reset = datetime.datetime.fromtimestamp(int(response.headers["X-RateLimit-Reset"]))
infos["LIMIT"] = f"{remaining_allowed_call_for_current_hour} call(s) can still be performed in the current hours (reseted at {next_call_count_reset})."
for entry in results:
infos["DATA"].append(entry["url"])
return infos
except RequestException as e:
infos = {"DATA": [f"Error during web call: {str(e)}"], "LIMIT": "NA"}
return infos
def get_wpr_version():
version = "NA"
try:
repo = git.Repo(search_parent_directories=False)
sha = repo.head.object.hexsha
if sha is not None and len(sha.strip(" ")) > 0:
version = sha[0:7]
except:
pass
return version
def is_valid(domain):
parsed = urllib.parse.urlparse(domain)
return (len(parsed.scheme) == 0 and len(parsed.params) == 0 and len(parsed.query) == 0 and len(parsed.fragment) == 0)
def get_mobile_app_infos(domain, http_proxy):
try:
web_proxies = configure_proxy(http_proxy)
infos = {"DATA": [], "ERROR": None}
domain_infos = tldextract.extract(domain)
base_domain = f"{domain_infos.domain}.{domain_infos.suffix}"
base_domain_name = f"{domain_infos.domain}"
# iOS platform
# See https://performance-partners.apple.com/search-api
# See https://stackoverflow.com/a/16903522
found = False
service_url = f"https://itunes.apple.com/search?term={base_domain_name}&entity=software&country={MOBILE_APP_STORE_COUNTRY_STORE_CODE}"
response = requests.get(service_url, headers={"User-Agent": USER_AGENT}, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
if response.status_code != 200:
infos["DATA"].append(f"HTTP response code {response.status_code} received!")
return infos
results = response.json()
for entry in results["results"]:
if "sellerUrl" in entry and base_domain.lower() in entry["sellerUrl"].lower():
infos["DATA"].append(f"iOS app found with TrackName '{entry['trackName']}' and BundleId '{entry['bundleId']}'.")
found = True
if not found:
infos["DATA"].append("No iOS app found.")
# Android platform
service_url = f"https://play.google.com/store/search?q={base_domain_name}&c=apps&hl=en&gl={MOBILE_APP_STORE_COUNTRY_STORE_CODE}"
response = requests.get(service_url, headers={"User-Agent": USER_AGENT}, proxies=web_proxies, verify=(http_proxy is None), timeout=DEFAULT_CALL_TIMEOUT)
if response.status_code != 200:
infos["DATA"].append(f"HTTP response code {response.status_code} received!")
return infos
results = response.text
android_bundle_regex = f"id=({domain_infos.suffix}\\.{domain_infos.domain}\\.[a-z0-9A-Z\\.\\-_]+)"
bundles = re.findall(android_bundle_regex, results)
for bundle in bundles:
infos["DATA"].append(f"Android app found with PackageId '{bundle}'.")
if len(bundles) == 0:
infos["DATA"].append("No Android app found.")
except Exception as e:
infos["ERROR"] = f"Error during web call: {str(e)}"
infos["DATA"].clear()
return infos
def get_dns_dumpster_infos(domain, http_proxy):
infos = {"DATA": [], "XLS": None, "IMG": None, "ERROR": None}
try:
web_proxies = configure_proxy(http_proxy)
req_session = requests.Session()
req_session.headers.update({"User-Agent": USER_AGENT})
req_session.proxies.update(web_proxies)
req_session.verify = (http_proxy is None)
results = DNSDumpsterAPI(session=req_session).search(domain)
if len(results) > 0:
data = results["dns_records"]
for entry in data["dns"]:
infos["DATA"].append(f"[DNS ]: IP \"{entry['ip']}\" - Domain \"{entry['domain']}\" - ReverseDNS \"{entry['reverse_dns']}\" - AS \"{entry['as']}\"")
for entry in data["mx"]:
infos["DATA"].append(f"[MX ]: IP \"{entry['ip']}\" - Domain \"{entry['domain']}\" - ReverseDNS \"{entry['reverse_dns']}\" - AS \"{entry['as']}\"")
for entry in data["txt"]:
infos["DATA"].append(f"[TXT ]: {entry}")
for entry in data["host"]:
infos["DATA"].append(f"[HOST]: IP \"{entry['ip']}\" - Domain \"{entry['domain']}\" - ReverseDNS \"{entry['reverse_dns']}\" - AS \"{entry['as']}\"")
if results["xls_data"] != None:
infos["XLS"] = base64.b64decode(results["xls_data"])
if results["image_data"] != None:
infos["IMG"] = base64.b64decode(results["image_data"])
infos["DATA"].sort()
except Exception as e:
infos["ERROR"] = f"Error during web call: {str(e)}"
infos["DATA"].clear()
infos["XLS"] = None
infos["IMG"] = None
return infos
def get_grayhatwarfare_infos(domain, api_key, http_proxy):
infos = {"DATA": [], "ERROR": None}
service_url_files = f"https://buckets.grayhatwarfare.com/api/v2/files?keywords={domain}&limit=1000"
service_url_buckets = f"https://buckets.grayhatwarfare.com/api/v2/buckets?keywords={domain}&limit=1000"
try:
web_proxies = configure_proxy(http_proxy)
req_session = requests.Session()
req_session.headers.update({"User-Agent": USER_AGENT, "Authorization": f"Bearer {api_key}"})
req_session.proxies.update(web_proxies)
req_session.verify = (http_proxy is None)
# Extract data for files
response = req_session.get(service_url_files)
if response.status_code != 200:
infos["ERROR"] = f"HTTP response code {response.status_code} received (files)!"
infos["DATA"].clear()
return infos
results = response.json()
if len(results["files"]) > 0:
for file in results["files"]:
infos["DATA"].append(f"[FILE ]: {file['url']} ({file['size']} bytes)")
# Extract data for buckets
response = req_session.get(service_url_buckets)
if response.status_code != 200:
infos["ERROR"] = f"HTTP response code {response.status_code} received (buckets)!"
infos["DATA"].clear()
return infos
results = response.json()
if len(results["buckets"]) > 0:
for bucket in results["buckets"]:
if "container" in bucket:
infos["DATA"].append(f"[BUCKET]: '{bucket['bucket']}' in container '{bucket['container']}' ({bucket['fileCount']} files)")
else:
infos["DATA"].append(f"[BUCKET]: '{bucket['bucket']}' ({bucket['fileCount']} files)")
infos["DATA"].sort()
except Exception as e:
infos["ERROR"] = f"Error during web call: {str(e)}"
infos["DATA"].clear()
return infos
def get_wayback_machine_infos(domain, http_proxy):
infos = {"DATA": [], "ERROR": None}
# See https://archive.org/help/wayback_api.php
service_url = f"https://archive.org/wayback/available?url={domain}"
try:
web_proxies = configure_proxy(http_proxy)
req_session = requests.Session()
req_session.headers.update({"User-Agent": USER_AGENT})
req_session.proxies.update(web_proxies)
req_session.verify = (http_proxy is None)
# Extract data for files
response = req_session.get(service_url)
if response.status_code != 200:
infos["ERROR"] = f"HTTP response code {response.status_code} received!"
infos["DATA"].clear()
return infos
results = response.json()
if "closest" in results["archived_snapshots"]:
url = results["archived_snapshots"]["closest"]["url"]
last_scan_date = "N/A"
if "timestamp" in results["archived_snapshots"]["closest"]:
# Ex: 20220603141821
last_scan_date = datetime.datetime.strptime(results["archived_snapshots"]["closest"]["timestamp"], "%Y%m%d%H%M%S").strftime("%d/%m/%Y at %H:%M:%S")
infos["DATA"].append(f"URL to access to the history: {url}")
infos["DATA"].append(f"Most recent archived snapshot taken on {last_scan_date}.")
except Exception as e:
infos["ERROR"] = f"Error during web call: {str(e)}"
infos["DATA"].clear()
return infos
def get_pgp_users_infos(domain, http_proxy):
infos = {"DATA": [], "ERROR": None}
# See https://openpgp.circl.lu
service_url = f"https://openpgp.circl.lu/pks/lookup?search={domain}&options=mr&op=index"
try:
web_proxies = configure_proxy(http_proxy)
req_session = requests.Session()
req_session.headers.update({"User-Agent": USER_AGENT})
req_session.proxies.update(web_proxies)
req_session.verify = (http_proxy is None)
response = req_session.get(service_url)
if response.status_code != 200:
infos["ERROR"] = f"HTTP response code {response.status_code} received!"
infos["DATA"].clear()
return infos
results = response.text
for entry in results.splitlines():
if entry.startswith("uid:"):
v = entry.split(":")[1]
if v not in infos["DATA"]:
infos["DATA"].append(v)
infos["DATA"].sort()
except Exception as e:
infos["ERROR"] = f"Error during web call: {str(e)}"
infos["DATA"].clear()
return infos
def get_leakix_info(field_type, field_value, http_proxy):
infos = {"DATA": [], "ERROR": None}
# See https://files.leakix.net/p/api
service_url = f"https://files.leakix.net/json?q={field_type}:{field_value}"
try:
web_proxies = configure_proxy(http_proxy)
req_session = requests.Session()
req_session.headers.update({"User-Agent": USER_AGENT})
req_session.proxies.update(web_proxies)
req_session.verify = (http_proxy is None)
response = req_session.get(service_url)
if response.status_code != 200:
infos["ERROR"] = f"HTTP response code {response.status_code} received!"
infos["DATA"].clear()
return infos
results = response.json()
status = results["status"]
if status == "success":
for entry in results["data"]:
last_changed = entry["last-modified"].split("T")[0]
file_url = entry["url"]
v = f"{last_changed}: {file_url}"
if v not in infos["DATA"]:
infos["DATA"].append(v)
infos["DATA"].sort()
else:
infos["ERROR"] = f"Status '{status}' received!"
infos["DATA"].clear()
except Exception as e:
infos["ERROR"] = f"Error during web call: {str(e)}"
infos["DATA"].clear()
return infos
def get_napalm_ftp_indexer_info(domain, http_proxy):
infos = {"DATA": [], "ERROR": None}
# See https://www.searchftps.net/
service_url = f"https://www.searchftps.net/"
expected_response_marker = "showing results"
regex_results_count = r'Showing\s+results\s+\d+\s+to\s+\d+\s+of\s+about\s+(\d+)'
try:
web_proxies = configure_proxy(http_proxy)
req_session = requests.Session()
req_session.headers.update({"User-Agent": USER_AGENT, "Content-Type": "application/x-www-form-urlencoded"})
req_session.proxies.update(web_proxies)
req_session.verify = (http_proxy is None)
form_data = {"action": "result", "args": f"k={domain}&t=and&o=date-desc&s=0"}
response = req_session.post(url=service_url, data=form_data)
if response.status_code != 200:
infos["ERROR"] = f"HTTP response code {response.status_code} received!"
infos["DATA"].clear()
return infos
results = response.text
if expected_response_marker not in results.lower():
with open("debug.tmp", mode="w", encoding="utf-8") as f:
f.write(results)
infos["ERROR"] = f"Non expected response received, marker '{expected_response_marker}' not found, see 'debug.tmp' file generated."
infos["DATA"].clear()
return infos
results_count = re.findall(regex_results_count, results, re.IGNORECASE | re.MULTILINE)
if len(results_count) > 0 and int(results_count[0]) > 0:
infos["DATA"].append(f"{results_count[0]} entries present on the site.")
except Exception as e:
infos["ERROR"] = f"Error during web call: {str(e)}"
infos["DATA"].clear()
return infos
def get_proxynova_comb_info(domain, http_proxy):
infos = {"DATA": [], "ERROR": None}
# See proxynova
service_url = f"https://api.proxynova.com/comb?query={domain}&start=0&limit=100"
try:
web_proxies = configure_proxy(http_proxy)
req_session = requests.Session()
req_session.headers.update({"User-Agent": USER_AGENT})
req_session.proxies.update(web_proxies)
req_session.verify = (http_proxy is None)
response = req_session.get(url=service_url)
if response.status_code != 200:
infos["ERROR"] = f"HTTP response code {response.status_code} received!"
infos["DATA"].clear()
return infos
results = response.json()
if results["count"] > 0:
for line in results["lines"]:
infos["DATA"].append(line)
except Exception as e:
infos["ERROR"] = f"Error during web call: {str(e)}"
infos["DATA"].clear()
return infos
if __name__ == "__main__":
requests.packages.urllib3.disable_warnings()
colorama.init()
start_time = time.time()
parser = argparse.ArgumentParser()
required_params = parser.add_argument_group("required arguments")
required_params.add_argument("-d", action="store", dest="domain_name", help="Domain to analyse (ex: righettod.eu).", required=True)
parser.add_argument("-a", action="store", dest="api_key_file", default=None, help="Configuration INI file with all API keys (ex: conf.ini).", required=False)
parser.add_argument("-n", action="store", dest="name_server", default=None, help="Name server to use for the DNS query (ex: 8.8.8.8).", required=False)
parser.add_argument("-p", action="store", dest="http_proxy", default=None, help="HTTP proxy to use for all HTTP call to differents services (ex: http://88.198.50.103:9080).", required=False)
parser.add_argument("-s", action="store_true", dest="store_filetype_dork_result", default=False, help="Save the result of the Google/Bing Dork searching for interesting files to the file 'filetype_dork_result.txt'.", required=False)
parser.add_argument("-t", action="store", dest="request_timeout", type=int, default=DEFAULT_CALL_TIMEOUT, help="Delay in seconds allowed for a HTTP request to reply before to fall in timeout (ex: 20).", required=False)
parser.add_argument("-m", action="store", dest="mobile_app_store_country_code", default=MOBILE_APP_STORE_COUNTRY_STORE_CODE, help="Country code to define in which store mobile app will be searched (ex: LU).", required=False)
args = parser.parse_args()
api_key_config = configparser.ConfigParser()
api_key_config["API_KEYS"] = {}
http_proxy_to_use = args.http_proxy
wpr_version = get_wpr_version()
print(colored("####################################################", "blue", attrs=["bold"]))
print(colored("### WEB PASSIVE RECONNAISSANCE", "blue", attrs=["bold"]))
print(colored(f"### COMMIT VERSION : {wpr_version}", "blue", attrs=["bold"]))
print(colored(f"### TARGET DOMAIN : {args.domain_name.upper()}", "blue", attrs=["bold"]))
print(colored(f"####################################################", "blue", attrs=["bold"]))
if not is_valid(args.domain_name):
print(colored(f"A domain must be provided and not a URL!", "red", attrs=["bold"]))
print(colored(f".::Reconnaissance aborted::.", "red", attrs=["bold"]))
sys.exit(1)
if args.api_key_file is not None:
api_key_config.read(args.api_key_file)
api_keys_names = " / ".join(api_key_config["API_KEYS"].keys())
print(colored(f"[CONF] API key file '{args.api_key_file}' loaded: {api_keys_names}.", "white", attrs=["bold"]))
if args.name_server is not None:
print(colored(f"[CONF] Name server '{args.name_server}' used for all DNS queries.", "white", attrs=["bold"]))
else:
print(colored(f"[CONF] System default name server used for all DNS queries.", "white", attrs=["bold"]))
if args.request_timeout is not None and args.request_timeout > 1:
DEFAULT_CALL_TIMEOUT = args.request_timeout
print(colored(f"[CONF] Request reply timeout set to {DEFAULT_CALL_TIMEOUT} seconds.", "white", attrs=["bold"]))
if http_proxy_to_use is not None:
print(colored(f"[CONF] HTTP proxy '{http_proxy_to_use}' used for all HTTP requests.", "white", attrs=["bold"]))
if args.api_key_file is not None:
print(colored(f"[WARNING] Be aware that your API keys will be visible by the specified proxy!", "yellow", attrs=["bold"]))
print("Test proxy connectivity...", end='')
msg = test_proxy_connectivity(http_proxy_to_use)
if msg.startswith("Succeed"):
print(colored(msg, "green", attrs=[]))
else:
print(colored(msg, "red", attrs=[]))
print(colored(f".::Reconnaissance aborted::.", "red", attrs=["bold"]))
sys.exit(1)
else:
print(colored(f"[CONF] No HTTP proxy used for all HTTP requests.", "white", attrs=["bold"]))