02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

How to prevent brute force attacks

In this session we will talk about how you can avoid brute force attacks and keep your server fast and secure.

Video Transcript

00:00Alrighty, so it's time for me to scare you, you know, we're, we've been protecting ourselves
00:04and we've been doing a really great job at that.
00:07But there's still one more thing that could keep us really unsafe, and that is brute
00:13force attack.
00:15Brute force attacks don't have to succeed to slow down your server, even if they can't
00:20figure out our passcode, passphrases.
00:22All they have to do is attack our site, you know, attack our SSH connection hundreds
00:27of times a second, thousands of times a second from a few different computers, and they could
00:31slow down our server to a level where we could not really function.
00:36So what we want to do is we want to add a firewall to our server, but a really, really weak firewall.
00:42We don't want to build a firewall that is overly protective because then we might lock
00:47ourselves out of our firewall.
00:50Now if you're working in a firm and you're working in this large company and you're
00:54working in a place where you have you only work from your desktop in the office and you
00:58want to make sure that only people in your office could log into your site, then do consult
01:04with with back end server guide to help you configure your settings.
01:10It's not that hard, but the scary thing is is that you might create a damage and lock
01:15yourself out, which you would never want to do that.
01:17So it's not a bad idea to consult with someone or read up on it.
01:21If you really feel that you want to secure your site in a level where only people that
01:26are your server, only people that are working inside of the building where you're working
01:31could access your server.
01:32For me, I like traveling around the world with my laptop and my IP is changing all the
01:36time.
01:37And I also work on different computer site don't really want to block myself.
01:41What I do want to do is I want to show you a way to protect yourself really, really
01:47well against brute force attacks.
01:50It was written by Jeff McCabby.
01:53It's an article.
01:54He's the CEO of rackade and he wrote a fantastic article, which you could find in this link,
02:00which will, I will post it inside of our description of the course on the bottom there.
02:06But if you're ready to type right now, it's rackade.com slash block slash how to block
02:11SSH, brutal force attacks with dashes all over.
02:15All right.
02:16So with that said, without introduction of Jeff, how could be that's all I'm not going
02:20to show it any further, but I'm going to jump right into our into our terminal.
02:25And let's talk about IP tables.
02:27Now IP tables is basically your IP table is basically the table that says who could enter
02:33and who cannot enter your site.
02:36Now by default, everyone's allowed to enter.
02:38So if you just type IP tables.
02:43Minus L, you'll get it.
02:44Oh, because we're not the root, I have to sue to it, right?
02:48So sue to IP tables minus L and put in my password.
02:53And we'll see by default, there is nothing there.
02:55There's a list of input, forward and output.
02:58But really, we're not saying there are no rules.
03:00And there were none.
03:01No rules basically says everyone could enter, which is fantastic.
03:04That's exactly how we want it to be because we don't want to overly protect our server.
03:08We already did quite a lot of stuff to protect it.
03:10But what we do want to do is we want to monitor and record every person that tries
03:15to gain access to our site and not only record every user that tries to gain access to our
03:21site.
03:22Well, mainly every new user that we've never authenticated, we want to store it to a new
03:26user is trying to gain access here and count how many times they're trying to access.
03:32And if the user tries to access more than X amount of times in 60 seconds, let's say,
03:39then we want to break him apart.
03:41We don't want him to access.
03:43So let's see the rules.
03:44So first of all, and by the way, I'm not going to describe the rules themselves.
03:49You're going to go into his site and just roll down here after you read the article, which
03:53is a great article and just copy line one and copy line two and paste them in one after
03:58each other.
03:59Just get rid of the you could get rid of that and start with sudu before because we
04:03need sudu access to be able to because we're not accessing it from the root directly.
04:07OK, so I'm going to write sudu and I'm going to paste the first line.
04:13And I'm going to write sudu again, and I'm going to paste the next line.
04:21And if I didn't put enter, I would put enter there, but I copied it with the with the
04:25break line.
04:26So it wrote it in.
04:28Now, if I go into my tables again and I want to look at my tables again, I'm going to
04:33see that my rules are now defined.
04:35Now, these rules are not really good for us because remember, we change our default port.
04:40So what we want to do is really want to do is change this port from 22 to our actual
04:45new value and our new value that we said it, I believe, was twelve eighty two.
04:50We make sure I have it written here somewhere.
04:52No, I don't have it written, but I remember it was twelve eighty two.
04:56So I want to change it to twelve eighty two.
04:57So to do that, what I'm going to do is I'm going to delete what the changes I've made.
05:01So to do that, I'm going to instead of sudu itables list, I'm going to call the
05:05uppercase R or sorry, our uppercase F for flush.
05:10So we're going to flush out all the all the new rules that we put in place.
05:13And if we look at the list again, we'll see there's no rules again.
05:17All right. So this time around, I'm going to before I paste the rules inside,
05:21I'm going to grab my rules and I'm just going to
05:24let me just come right up here.
05:26I'm going to put this up here and I'm going to change my IP to twelve eighty two
05:31and change IP here also to twelve eighty two.
05:34And now I'm ready to copy line one.
05:37And we're going to sudu.
05:42And I want to do the same thing for line number two.
05:45So I'm going to just copy line two here.
05:48I'm just going to move that away now and paste that right in there.
05:52And again, I by mistake did not put inside.
05:54I didn't start my line with sudu.
05:56So I'm going to put that sudu inside and we're we're fine.
05:59So if we now look at our list again, we look at our list again.
06:02We'll see that now we have our rule.
06:04And what this rule is doing, line one is it's storing to say that
06:08something new came in, which is this line, it says it stores a change that happens
06:13and it checks to see if a user if within 60 seconds user tried four times to log in,
06:20then just automatically say no.
06:23Now automatically say no for as long as it's the last 60 seconds or only every 60 seconds
06:28you could try four times.
06:30Now, if you want, you could add even more strict rules such as putting it every 120 seconds.
06:34And don't forget that this is only for new users.
06:37So if the user is trying to log in for the first time from a new computer
06:41with a different IP address than his normal IP address, and he fails to log in four times,
06:46then his access will be denied for the next 60 seconds.
06:50And obviously, you can make this even more sophisticated by saying, hey, if the user
06:53tried to log in and failed four times within even five minutes, then don't let them in
06:59for five minutes.
07:00So you can decide how strict you want your rules to be.
07:02But this will be not annoying for your users, but still denying access to a brute attack
07:09that's going to try to attack your site very fast.
07:12Now with that said, if someone is specifically targeting targeting you and try to gain access
07:17to your site, they might try for the next three months and just take their time.
07:21So it's not going to prevent them from attacking slowly, but it's not going to affect the
07:25performance of your site as they're trying to attack you.
07:28But what you could do if you want to make it even more secure and say you don't want
07:32you want to slow down their process because they're going to use algorithms and it could
07:35take forever for them to figure out if you put a really good password or really good
07:39key chain, it could take them forever to figure it out.
07:42Just a prolonged that delay of time.
07:46So four attempts without succeeding is good enough and say, hey, for the next 15 minutes,
07:50if you didn't succeed, you just can't log in.
07:52And if you're only using it yourself, then you just know if you didn't, if you want
07:56a new computer and you tried to log in and you did not succeed for four times in
07:59a row, now for 15 minutes, you can't do anything.
08:02And that's something that you could definitely do.
08:03So the higher the number is.
08:05And if I just bring this up again in my screen here, you could just go right here
08:08and go into the seconds and change the value of seconds to be a much larger number,
08:13like 600, if you want it to be 600 seconds.
08:16OK, now, once you've configured it and by the way, we made sure that our default
08:21is to accept our default is accepting.
08:24We're not going to talk into how do we default to not accept because we don't
08:28want you to play around with these IP tables if you're not a pro.
08:33And if you are a pro, then you know what you're doing.
08:34You don't want it.
08:35You don't need to watch this video.
08:36But if you need something more sophisticated than this, then I do strongly
08:40encourage you to consult a professional.
08:43All right.
08:43Now, last but not least, what I want to do is I want to I want to save the changes
08:48because right now these changes are only going to be valid for this session.
08:52Once I once I my SSH restarts, it's all going to be deleted.
08:57So for it not to be deleted, I want to go to my service and I'm going to.
09:03Oh, I want to start with Sudu as always.
09:06You know, let's what am I doing?
09:09Let me clear so we're on the top of the screen because that's always nicer.
09:13OK, so Sudu service IP tables and we want to save our IP table once I do that.
09:22And there we go.
09:22Our IP tables is saved.
09:24The rules are saved and we're set and we're good.
09:27And now every time a user tries a new user that tries to log into our system.
09:33But does not succeed four times in a row and they're new.
09:36That means they have a new IP address and they are not known to our system.
09:40Their device is not known to our system.
09:42They're going to be automatically denied after four times, 60 seconds at a time.
09:47Now, if you know you're only going to be one user, then I strongly recommend,
09:50hey, turn it even to 600, because if you're only one user,
09:53you don't need to give that level of access of even every 60 seconds.
09:57If you have a lot of users that price 60 seconds, don't want to annoy people.
10:0060 seconds is probably good enough for people to wait.
10:04All right. So that's that's our advice here.
10:06And again, so if you're not happy with the rule at any time,
10:09you could type IP tables minus F to delete everything, uppercase F,
10:16your IP tables minus uppercase L to show things and those two rules.
10:20And we'll make sure that we paste them into our description of our course as well
10:23and leave you a link to read that article, which I think is great.
10:26It gives you a really great overview of the advantage of working in this way.
10:31So that's it. That's another security.
10:32And we just prevented brute attackers from gaining access into our SSH.
10:37At least we're going to make it really, really hard for them to do that.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!