Build a SOC Lab with Wazuh: Active Response (Part 6)
Transcript
Machine-transcribed by YouTube. Expect errors in names, commands and version numbers.
Welcome to part six of seven of the Wazuh SOC Analyst Challenge. Up until now, Wazuh has been telling us when something happens. In today's video, we'll make it actually do something about it. We are going to be setting it up so that when Wazuh detects repeated failed SSH logins against our Ubuntu server, it automatically blocks the source. Let's get started. To get started, we want to head over to our Windows virtual machine and we want to open up PowerShell. So, I'm going to hold shift, right click, and open PowerShell window here. What I'll do is SSH into my Ubuntu
virtual machine, which is under 168 .136.129.
And from here, I am going to intentionally fail three times.
That is one. That is two. And that is three. So, we get a permission denied. Now, let's head over to our Wazuh dashboard. From here, I'll click on the hamburger icon, select discover, and I'm going to change this to the last 15 minutes. Let's make sure that we filter for the my differ Linux agent name. I'll go ahead and expand the first event, scroll down to the rule description, select the toggle column in table, and I just want to take a look at what are some of the rules that triggered. So, we have a syslog user missed the password more than one time, there's an SSH connection reset, authentication failed, and PAM user login failed. But there isn't anything that specifies like a brute force attempt. I mean, we do have a syslog right here where it says user missed the password more than one time. But what if I wanted to track, I don't know, say three failed logons and have that generate a single rule. Because currently, again, we don't have that. We have authentication failures, and three of them in fact, so one, two, and three, and they did happen pretty much within seconds of each other, but I do want to create a custom rule that says something along the lines of three failed SSH logons within, say, five or two minutes.
So, how do we do that? Well, I am going to head over to the hamburger icon, scroll down, and select rules. I am going to open it up in a new tab. And then from here, I'll select custom rules, and we want to click into the local_rules.xml. And from here, I am going to paste in a rule that ChatGPT had created for me. Essentially, I used a prompt that says, "Create a rule where greater than or equal to three SSH login failures were observed." And this is pretty much what it gave me. I am going to paste all of this into the free community, so you can simply copy and paste it and test it for yourself. All right. So, now, let's go ahead and test it out. So, I'll click on save, and it says, "Changes will not take effect until a reload is performed." Click on reload, and while that's doing its thing, take a look at the description. It says, "Multiple SSH login failures observed from the same source IP." And that's pretty much what I wanted to say. So, if we happen to see three failed login attempts within a 120
seconds, this custom rule should
trigger. Going back over to our discover, and instead of last 15 minutes, let's do last five minutes, and
we have no results. Let's go and generate this one more time.
Fail once, fail twice, and the last one. Perfect. Now, in theory, our custom rule should now trigger. Let's go go and refresh, and here we go. Multiple SSH
login failures observed from the same source IP. So, now that we have this, we can now configure active response, so Wazuh can perform some automated actions. To do this, you want to head over to the Wazuh manager, and you can see that we are currently under the Wazuh manager right here. I am going to type in sudo nano/var/ossec
/etc/ossec.conf.
Type in the password, and here we go. From here, you want to scroll all the way down until we find the configuration
related to active response. So, this right here is file integrity monitoring, which is what we configured earlier, and eventually we get into active response. So, this right here. Now, take a look at the commands that are available. We have disable account, there's restart Wazuh, firewall drop, host deny, route null,
win route null, and net sh. Now, if you're wondering, what do these commands do? Well, we can search up Wazuh, and type in active response. So, Wazuh does have some pretty decent documentation when it comes to active response, and if we click into the default active response scripts, we should see the disable account, and the firewall drop, and the other scripts that we saw earlier. So, disable account, well, disables a user account, firewall drop adds an IP address to the IP tables deny list, and firewall d drop adds an IP address to the firewall d drop list. And of course, there's many others down here. So, I'll leave this link in the free community as well. That way again, you just have all of the resources there. In our demo, we are going to be using the firewall drop active response
script. So, that is this one right here.
To enable it, we simply need to scroll down just a bit and do make sure that we remove the arrow with the exclamation
mark {dash} {dash} because this right here is telling Wazuh that this is a comment. In other words, it's not going to work unless you either remove it or you simply create a new block either above or below it. But, in my case, I'm simply just going to remove it just like so. And under the active response block here, I'm going to type in disabled
no. And then I'm going to say command. This is going to be the firewall {dash} drop. And it has to match the script name which is right here. So, if I wanted to use something like host deny, then I need to make sure that I put in host {dash} deny. All right, so that is firewall drop. Let's close out the command. And for the location, I am going to say local.
That is essentially telling Wazuh to run the script on the agent that generated the alert. So, in other words, when this triggers, this firewall {dash} drop script is going to run on our Ubuntu server because our Ubuntu server was the one responsible for generating that alert or generating that rule. The last thing that I'm going to do is type in the rules_id. And then we want to specify the rule ID of our new custom rule. Go back into our Wazuh dashboard and under our rule ID,
we have 100 101. And just to confirm,
let's expand our multiple SSH login failures and let's find our rule ID
which is this right here and it is indeed 100 101. So, now I'll type that
in, 100 101. Go ahead and close out the rules {underscore} ID, and that's pretty much it. So, just a quick recap, we said disabled is no, so that means active response is active. We're instructing the active response to run the firewall-drop script. We are instructing it to run on the local agent. In other words, that agent that was responsible for generating that alert/rule. Now, what rule are we talking about? We are talking about the 100 101. All right, all we need to do is hold control X, Y to save, and enter. Now, let's go ahead and type in sudo system CTL restart wazuh-manager,
and hit enter. Once that is done, we can verify to see what is loaded. To do that, I am going to change into the root account, and the binary of interest is under the var ossec bin, and it's called agent_control.
If I hit enter without anything, this says control remote agents, and the {dash} capital L is going to list the available active response. So, if I hit the up arrow and do a {dash} capital L, we can see that there is a response name called firewall-drop,
and that is the one that we just configured. All right, now let's do a quick proof of concept. So, I am going to minimize our RDP session, and let's
see we can do it this way. I think this should be okay. So, over on the left, we have our Windows computer, and I am going to ping our Linux virtual machine. So, 192.168.136.129,
and we do have connectivity. So, let's do an infinite ping by adding in a {dash} t. As you can see, it is pinging, pinging, and pinging. So, now let's open up another PowerShell, and we are going to SSH into my differ
at 192.168.136.129.
Just to make sure. Yes, that is correct. Hit enter. And let's fail three times. Perfect. We get a permission denied. Now, in theory, our ping should stop. We
now get a request timed out. So, there is no longer connectivity from our Windows computer towards our Linux/Ubuntu virtual machine. Isn't that cool? Now, if we head over to our Wazuh, take a look. The second event is our rule. Right? We see a multiple SSH login failures. A look at right above, the first event from the top. Host blocked by firewall {dash} drop active response. I don't know about you, but that is pretty awesome. Now, the last thing to do before we close this out is Well, you might be questioning, well, how do we restore connectivity? Because I definitely was. So, in order to restore it, all you need to do is type in iptables.
But actually, you don't want to do it here because we are currently under the Wazuh server. You want to do this over on your Ubuntu virtual machine. So, we can type in sudo iptables {dash} capital L {dash} n {dash} {dash}
line {dash} numbers. Type in our password. And here you go. So, we can see that the input and forward has our Windows IP of 192.168.136.130
as drop. So, to remove them, we simply type in pseudo iptables -D and then we want to put in our chain. So, in this case, input and forward. So, I'll type in input and then type in the line number of interest. Since we only have a one entry, we have a number of one. So, let's put in one. Go ahead and hit enter and that's good. Now, if we were to run the iptables again, take a look under input. It no longer has that entry. So, let's do the same for forward.
So, instead of input, I will say forward. Let me clear the screen and let's rerun it. Now, we do not have our Windows IP here. So, in theory, our Windows computer should now have connectivity back to our Linux / Ubuntu virtual machine. We see that it is timed out here, but let's go ahead and hit enter and there you go. >> Great job. By now, you should have watched Wazuh detect an attack and respond to it completely on its own. Now, really quickly, what we just did is a safe lab-scoped version of active response. If you want to see this in a modern SOC workflow, that is where the forge comes in. In there, we show you how to spin up your own command and control server and we take the same kind of scenario and run it through a real SOC workflow using Tines and AI to automatically draft a report, push it to Slack, and do a human approved block where AI recommends the action, you confirm it, and then Wazuh carries it out. It is already built and running in there, but it's totally optional. The project that you are building here is still portfolio worthy on its own. Link is in the description if you are curious. In the next and final video, we are going to be taking everything that we have done and turn it into a real sock investigation. And that is going to be your final deliverable. That is it for the video, and I hope that you found that informative. If you did, let me know by hitting that like button and subscribe if you want to. Remember to stay curious and do things differently.





