forked from Drushti21/Osint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mac.py
541 lines (480 loc) · 23.2 KB
/
mac.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
#!/usr/bin/python3
# Importing some important libraries
import argparse
import socket
import sys
import subprocess
from os import system, name, popen
from time import sleep
amc_project_version = '2.0.0.6'
amc_project_build = 'BETA-KALI_LINUX_2022.1-05052022AM0920'
amc_project_license = 'CC0 1.0 Universal'
amc_project_ide_name = 'PyCharm (Community Edition)'
amc_project_ide_version = '11.0.14.1+1-b2043.25 amd64'
amc_project_programming_language = 'Python3'
amc_project_programming_language_version = '3.9'
def clear():
"""
:return: this function helps to clear terminal window.
"""
if name == 'nt':
_ = system('cls')
else:
_ = system('clear')
def display_error(error_code, error_message, critical_error):
try:
clear()
print("######################################################################")
print("# ERROR : {:<58} #".format(error_code))
print("######################################################################")
print("# ERROR MESSAGE #")
print("######################################################################")
print("# {:<66} #".format(str(error_message)))
print("######################################################################")
if critical_error:
sys.exit()
except Exception as display_errors:
clear()
print("######################################################################")
print("# ERROR : {:<58} #".format("CE0000X0001"))
print("######################################################################")
print("# ERROR MESSAGE #")
print("######################################################################")
print("# {:<66} #".format(str(display_errors)))
print("######################################################################")
sys.exit()
try:
"""
Command line colour options
"""
G = '\033[92m' # green
Y = '\033[93m' # yellow
B = '\033[94m' # blue
R = '\033[91m' # red
W = '\033[0m' # white
except Exception as no_colour_error:
G = Y = B = R = W = ''
def welcome_message():
"""
welcome message: display common welcome message after every cleaning of command line.
:return: nothing
"""
clear()
print("%s######################################################################" % W)
print(
"%s# Automatic Media Access Control [MAC] Address Spoofing Tool #" % G)
print("%s######################################################################" % W)
print("%s# {:<20} | {:<43} #".format("Version", amc_project_version) % Y)
print("%s# {:<20} | {:<43} #".format("Build", amc_project_build) % Y)
print("%s######################################################################" % W)
print("%s# Information: This script helps you to change your MAC Address #" % B)
print("%s# automatically to spoof your Original MAC Address. #" % B)
print("%s######################################################################" % W)
print("%s# Warning: If you receive any legal warrant from Cyber Branch #" % R)
print("%s# then we are not responsible for consequences. #" % R)
print("%s######################################################################" % W)
print("%s# Made for Educational purpose only. #" % Y)
print("%s######################################################################" % W)
def reset_mac(network_interface):
"""
This function is use to reset mac address to there original one.
:param network_interface: network interface name Ex. eth0, wlan0
:return: Nothing
"""
try:
clear()
welcome_message()
print("# Please wait... #")
""" enable this if network manager service need to restart.
subprocess.call(["service", "NetworkManager", "stop"], shell=False)
subprocess.call(["ifconfig", network_interface, "down"], shell=False)
"""
print("# Flushing default MAC Address... #")
command_line_process(
f"macchanger -p {network_interface}", network_interface)
print("# Resetting network manager... #")
""" enable this if network manager service need to restart.
subprocess.call(["ifconfig", network_interface, "up"], shell=False)
subprocess.call(["service", "NetworkManager", "start"], shell=False)
"""
print("# Connecting to Internet... #")
print("######################################################################")
sleep(2)
except Exception as reset_mac_error:
display_error('RM0000X0001', reset_mac_error, True)
def exit_msg(network_interface):
"""
To display exit message
:return: Nothing
"""
try:
reset_mac(network_interface)
clear()
welcome_message()
print("# We hope you like Automatic MAC Address Changer. #")
print("# If you have any suggestions please comment us on Github. Thanks ! #")
print("######################################################################")
print("# Made with love by Alchemists Open Source Community. #")
print("######################################################################")
sys.exit()
except Exception as exit_error:
display_error('EE0000X0001', exit_error, False)
def command_line_process(command, network_interface):
"""
This function read command line outputs.
:param network_interface:
:param command: any terminal based command.
:return: command line strings.
"""
try:
network_interface = network_interface
command = command.split()
p = subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
for line in iter(p.stdout.readline, b''):
# print(f'#{line.decode("utf-8").strip()}#')
print("# {:<66} #".format(line.decode('UTF-8').strip()))
sleep(0.1)
except Exception as command_line_process_error:
display_error('CLPE00X0001', command_line_process_error, False)
except KeyboardInterrupt:
exit_msg(network_interface)
def flash_new_mac(network_interface):
"""
This function will flash new mac address to network_interface
:param network_interface: network hardware (interface)
:return: nothing
"""
try:
clear()
welcome_message()
print("# Please wait, do not close or cancel this process... #")
""" enable this if network manager service need to restart.
print("# Turning off network manager service... #")
subprocess.call(["service", "NetworkManager", "stop"], shell=False)
print("# Turning off {:<10} #".format(network_interface + "..."))
subprocess.call(["ifconfig", network_interface, "down"], shell=False)
"""
print("# Flashing new MAC address... #")
command_line_process(
f"macchanger -a {network_interface}", network_interface)
""" enable this if network manager service need to restart.
print("# Turning on {:<10} #".format(network_interface + "..."))
subprocess.call(["ifconfig", network_interface, "up"], shell=False)
print("# Turning on network manager service... #")
subprocess.call(["service", "NetworkManager", "start"], shell=False)
"""
print("######################################################################")
print("# MAC address for {:<32} #".format(
network_interface + " successfully changed."))
print("######################################################################")
print("# Please wait, reconnecting to the network .... #")
print("######################################################################")
sleep(0.5)
except Exception as flash_new_mac_error:
display_error('CLPE00X0001', flash_new_mac_error, True)
except KeyboardInterrupt:
exit_msg(network_interface)
def display_network_interface():
"""
To display all available network interface.
:return: nothing
"""
clear()
welcome_message()
print("# Sr. Number | Network Interface Name | MAC Address #")
print("######################################################################")
list_of_network_interface = socket.if_nameindex()
read_mac_address = []
for index, network_interface in list_of_network_interface:
read_mac_address.append(popen(
"cat /sys/class/net/{}/address".format(network_interface)).read().split("\n"))
list_of_mac_address = [i[0] for i in read_mac_address]
for (index, network_interface), mac_address in zip(list_of_network_interface, list_of_mac_address):
print("# {:<10} | {:<25} | {:<25} #".format(
index, network_interface, mac_address))
print("######################################################################")
sys.exit()
def check_network_interface(network_interface):
"""
check available interface
:param network_interface: network hardware (interface).
:return: if network interface available return True.
"""
try:
for index, interface in socket.if_nameindex():
if network_interface == interface:
return True
except Exception as check_network_interface_error:
display_error('CNI000X0001', check_network_interface_error, True)
def check_change_time(change_time):
"""
to check timeout time is between 30 to 60 or not.
:param change_time: int value input given by user
:return: if time is between 30 to 60 return True
"""
try:
if int(change_time) < 30:
clear()
welcome_message()
print(
"%s# Yes ! privacy is important. But changing MAC address often, #" % G)
print(
"%s# it will damage your Network Manager Service. #" % G)
print(
"%s# Please enter the time between 30 sec to 60 sec. #" % G)
print(
"%s######################################################################" % W)
sys.exit()
elif int(change_time) > 60:
clear()
welcome_message()
print(
"%s# Are you serious ? there no use of AMC. The time you entered it #" % G)
print(
"%s# will take more then 1 min to change your MAC Address. #" % G)
print(
"%s# Please enter the time between 30 sec to 60 sec. #" % G)
print(
"%s######################################################################" % W)
sys.exit()
else:
return True
except ValueError:
display_error('CCT000X0001', ValueError, False)
except Exception:
parser_error('Error: argument -t/--time: expected one argument')
def amc_display(network_interface, time_left):
"""
To display current process and left time.
:param network_interface: network hardware name
:param time_left: time to change mac
:return: nothing
"""
try:
clear()
welcome_message()
print("# Your MAC address of {:<27}{:<18} #".format(network_interface + " will be change in next ",
str(time_left) + " Sec."))
print("######################################################################")
command_line_process(
f"macchanger -s {network_interface}", network_interface)
print("######################################################################")
print("# To exit use Ctrl + C #")
print("######################################################################")
except Exception as amc_display_error:
display_error('AD0000X0001', amc_display_error, False)
except KeyboardInterrupt:
exit_msg(network_interface)
def run_amc(change_time, network_interface):
"""
main function to run amc
:param network_interface: network hardware name
:param change_time: time to change mac
:return: nothing
"""
try:
flash_new_mac(network_interface)
time_increment = 0
while True:
time_left = change_time - time_increment
if time_left == 0:
time_increment = 0
flash_new_mac(network_interface)
else:
time_increment += 1
amc_display(network_interface, time_left)
sleep(1)
except KeyboardInterrupt:
exit_msg(network_interface)
def display_license():
clear()
welcome_message()
print("%s# Copyright 2022 Team Alchemists #\n"
"%s######################################################################\n"
"%s# A Automatic Media Access Control [MAC] Address Changer (c) 2022, #\n"
"# This work is marked with CC0 1.0 Universal. #\n"
"# To view a copy of this license, visit #\n"
"# #\n"
"# http://creativecommons.org/publicdomain/zero/1.0 #\n"
"# #\n"
"# Unless required by applicable law or agreed to in writing, #\n"
"# software distributed under the License is distributed on an #\n"
"# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND. #\n"
"# either express or implied. See the License for the specific #\n"
"# language governing permissions and limitations under the License. #\n"
"%s######################################################################\n" % (G, W, G, W))
def about_alchemists():
clear()
banner()
print("%s######################################################################" % W)
print("%s# About Alchemists Community #\n"
"%s######################################################################\n"
"%s# Alchemists, is cyber enthusiasm community. Who focus to make aware #\n"
"# people about cyber security and develop open-source security tools.#\n"
"%s######################################################################\n"
"%s# Use -j/ --join to join Alchemists Community. #\n"
"%s######################################################################\n" % (G, W, G, W, B, W))
def join_alchemist():
clear()
banner()
print("%s######################################################################" % W)
print("%s# Join Alchemists Community #\n"
"%s######################################################################\n"
"%s# Tweet us: hexdee606, Paradox_044, Itachi_9197, Athena_74047 #\n"
"%s######################################################################\n"
"%s# To join email us on: open.alchemists.community@gmail.com #\n"
"%s######################################################################\n" % (G, W, G, W, G, W))
def version_amc():
clear()
banner()
print("%s######################################################################" % W)
print(
"%s# Automatic Media Access Control [MAC] Address Spoofing Tool #" % G)
print("%s######################################################################" % W)
print("%s# {:<20} | {:<43} #".format("Version", amc_project_version) % Y)
print("%s# {:<20} | {:<43} #".format("Build", amc_project_build) % Y)
print("%s# {:<20} | {:<43} #".format("License", amc_project_license) % Y)
print("%s# {:<20} | {:<43} #".format("IDE Name", amc_project_ide_name) % Y)
print("%s# {:<20} | {:<43} #".format(
"IDE Version", amc_project_ide_version) % Y)
print("%s# {:<20} | {:<43} #".format(
"Programed in", amc_project_programming_language) % Y)
print("%s# {:<20} | {:<43} #".format(amc_project_programming_language + " Version",
amc_project_programming_language_version) % Y)
print("%s######################################################################" % W)
def parser_error(errmsg):
welcome_message()
print("# Usage: python3 {:<51} #".format(
sys.argv[0] + " [Options] use -h for help."))
print("%s# Error: {:<59} #".format(errmsg) % R)
print("%s######################################################################" % W)
sys.exit()
def parse_args():
# parse the arguments
Selection = 1
while True:
print('')
print("1. Username Scan")
print("2. Phone Number")
print("3. Email")
print("4. Network Scanner")
print("4. MAC Address Spoofer")
print("5. Advance Port Scanner")
print("6. Network Scanner")
print("7. Website Scraper")
print("8. Subdomain Scanner")
print("9. DNS Scanner")
print("10. Exit")
print('')
Selection = int(input(">> "))
print('')
parser = argparse.ArgumentParser(
epilog='\tExample: \r\npython3 ' + sys.argv[0] + " -i eth0 -t 30")
parser.error = parser_error
# parser._optionals.title = "OPTIONS"
parser.add_argument('-a', '--about', help='show what is alchemist community.', metavar="", default=False,
type=isboolean, const=True, nargs='?')
parser.add_argument(
'-i', '--interface', help="network interface name to change mac address.", metavar="", type=str)
parser.add_argument('-j', '--join', help='show how to join alchemists community.', default=False, metavar="",
type=isboolean, const=True, nargs='?')
parser.add_argument('-l', '--license', help='show open source license information.', default=False, metavar="",
type=isboolean, const=True, nargs='?')
parser.add_argument('-n', '--network', help='show available network interface list.', metavar="", default=False,
type=isboolean, const=True, nargs='?')
parser.add_argument(
'-t', '--time', help='time to change mac address automatically.', metavar="", type=int)
parser.add_argument('-v', '--version', help='show version information.', default=False, metavar="", type=isboolean,
const=True, nargs='?')
return parser.parse_args()
def isboolean(boolean_value):
if isinstance(boolean_value, bool):
return boolean_value
elif boolean_value.lower() in ('yes', 'true', 't', 'y', '1'):
return True
elif boolean_value.lower() in ('no', 'false', 'f', 'n', '0'):
return False
else:
parser_error('boolean value expected')
exit()
def amc_main():
try:
args = parse_args()
about_alchemist = args.about
network_hardware = args.interface
join_alchemists = args.join
amc_license = args.license
hardware_list = args.network
interval_time = args.time
amc_version = args.version
if isboolean(about_alchemist):
about_alchemists()
return None
elif isboolean(join_alchemists):
join_alchemist()
return None
elif isboolean(amc_license):
display_license()
return None
elif isboolean(hardware_list):
display_network_interface()
return None
elif isboolean(amc_license):
display_license()
return None
elif isboolean(amc_version):
version_amc()
return None
elif network_hardware == 'lo':
clear()
welcome_message()
print(
"%s# The software loopback network interface is a software loopback #" % B)
print(
"# mechanism which may be used for performance analysis, software #")
print(
"# testing, and/or local communication. As with other network #")
print(
"# interfaces, the loopback interface must have network addresses #")
print(
"# assigned for each address family with which it is to be used. #")
print(
"%s######################################################################" % W)
print(
"%s# AMC unable to change MAC address of loopback network interface #" % R)
print(
"%s# use -n/--network True for available network interface list. #" % G)
print(
"%s######################################################################" % W)
return None
elif not check_network_interface(network_hardware):
clear()
welcome_message()
print("# Sorry there is no {:<48} #".format(
network_hardware + ' interface found.'))
print(
"# use -n/--network True for available network interface list. #")
print(
"######################################################################")
show_network_list = input(
"%s# Do you want to see available network interface? (Y/n) #\n" % R)
if isboolean(show_network_list):
display_network_interface()
print(
"%s######################################################################" % W)
return None
elif check_network_interface(network_hardware) and check_change_time(interval_time):
run_amc(interval_time, network_hardware)
return None
else:
parser_error(
'Following arguments are required: -i/--interface, -t/--time')
return None
except Exception:
parser_error(
'Following arguments are required: -i/--interface, -t/--time')
return None
if __name__ == "__main__":
amc_main()
sys.exit()