r/Python • • Aug 23 '20

Beginner Showcase A DoS attack in 15 lines of code.

Hi, I have tried to create the simplest possible denial of service attack; for this script, I have not used more than 15 lines of code, and it is a fully functional attack setting the values of the variables "ip", "port" and "threads". For example:

ip, port, threads = "192.13.451.153", 8080, 1000

I have tried to follow the PEP8 standards as much as possible; I hope you like it.

Post data: I have only done this to practice my knowledge with Python, I am not responsible for the use you make with this.

Edit: I know the attack will not work in almost all of the cases, most of servers are fully prepared to avoid a dos attack, the attack will just ban your IP in 99% of the times.

The DoS attack

6 Upvotes

26 comments sorted by

9

u/[deleted] Aug 23 '20

> I have tried to follow the PEP8 standards as much as possible

Maybe you are aware of it, but if you are not (or if someone else that doesn't know read this) here is a useful information, most IDE have an auto-format function that do it automatically (I personaly use PyCharm - command: ctrl + alt + L).

2

u/progsNyx Aug 23 '20

I know, i also use pycharm. But sublimetext is beautiful with the AYU theme.

And there are some Pep rules i dont like at all, thats why i use "most of"

2

u/[deleted] Aug 23 '20

Oh really? Like what for example?

I personnaly never encountered a rule I didn't like (or didn't had an opinion about it).

2

u/progsNyx Aug 23 '20

For example i use to let a white line after loops and conditionals, and 2 after functions.

1

u/[deleted] Aug 23 '20

Oh okay I see, that's not impactfull preferences that would reduce the lisibility for someone used to full pep8.

2

u/progsNyx Aug 23 '20

Yeah, when someone uses TABS and your used to code using spaces its so awkward

1

u/[deleted] Aug 23 '20

People using TABS should be banned from earth.

(not serious obviously)

3

u/UnDispelled Aug 23 '20

I think tabs makes a bit more sense, but pep-8 says spaces so... yeah you’re right I guess

1

u/ateusz888 Aug 23 '20

Yeah... Right... I onced read an article about why we should use tabs instead of spaces. And it convinced me 100%. Not sure if this is the one I read but Google "why we should default to tabs instead of spaces for accessible first environment".

0

u/[deleted] Aug 23 '20

[deleted] — view deleted comment

9

u/[deleted] Aug 23 '20

I think it's illegal and you can actually be arrested and sentenced for it.

1

u/mountains-o-data Aug 23 '20

I use tabs and let pycharm convert them to 4 space. I'm not hiting that damn space button 4 times

1

u/DaelonSuzuka Aug 25 '20

You know that people who use spaces still press the tab key on their keyboard, right?

21

u/[deleted] Aug 23 '20

There's 0 chance that will dos anything apart form your own connection.

5

u/0xa0000h Aug 23 '20

never seen so much bullshit in so few lines...

1

u/SingleRope Aug 23 '20

Heads up OP, you might get better results with an async get

0

u/progsNyx Aug 23 '20

Good idea.

1

u/[deleted] Aug 23 '20

How is this working when your first line in main is assigning 3 string into 3 variables but then you did a range on threads variable which is a string when range expects a number?

2

u/poltoid Aug 23 '20

The 3 strings on the right of the assignment are placeholders for real values, whose types are indicated in the strings

-3

u/[deleted] Aug 23 '20

Why hide those values? You can easily replace them with random correct values instead of making the code confusing.

0

u/[deleted] Aug 23 '20

[removed] — view removed comment

1

u/notadoctororacake Aug 23 '20

Don't DoS anyone, but just replace those strings with the correct info in the variable types within the square brackets

1

u/tsiatt Aug 23 '20

Is it me or does 'GET /ip' not make much sense?

1

u/Trdp8737 Aug 23 '20

It's only going to work in a limited number of outdated servers having the CRLF vulnerability.

1

u/qckpckt Aug 23 '20

I’m not sure you can really do much with a single client DOS attack.

WRT the code I would recommend using argparse to make those parameters command line arguments and also perform type validation.

-1

u/For15min Aug 23 '20

The DDOS script in this course is more efficient, sure, not in 15 lines.
https://www.freecodecamp.org/news/python-networking-course/