Search code examples
pythonsocketsportdenial-of-service

Python - Sending packets to an Internet Protocol without open ports?


Well, I was reading about how people can launch DoS attacks without open ports on their target. I want to see how this is in code, because with socket programming to send an packet you must first make the connection.

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #You could use UDP protocol, but that gets lost on the way if it cant send the packet through that port.
s.connect(("target", 80)) #You can't do the next command without this
s.send("IP packet")

If I am confused with something, please explain to me either way how this works.


Solution

  • Merely trying to connect sends a packet. So you can simply try to connect over and over again, getting ECONNREFUSED or whatever each time.

    You could also use UDP, which is connectionless. That way you can send packets up to about 1500 bytes at any time, and the target will have to discard them, wasting precious electricity.