Build a SOC Lab with Wazuh: File Integrity Monitor + Rules (Part 5)
Transcript
Machine-transcribed by YouTube. Expect errors in names, commands and version numbers.
Welcome to part five of seven of the Wazuh SOC Analyst Challenge. In today's video, we are going to be doing two things. First, we'll set up file integrity monitoring so that Wazuh tells us the moment a file gets changed, added, or deleted. Second, you are going to be creating your own custom detection rule. By the end, we'll test the new rule just to prove that it works, which again is deliverable number two. And don't worry if writing a rule sounds intimidating, I am going to show you how you can use AI to help you build it because that is a tool that you should be leaning on rather than avoiding.
Let's get right into it. All right, let's go ahead and configure file integrity monitoring. So, the first thing that we want to do, we want to head over to our Windows virtual machine, which I am currently RDP'd into from our Windows host. Again, my virtual machine IP is 192.168.136.130, as you can see over at the top, and this is my virtual machine.
So, let's go into our C drive, and what I'll do is I'll create a new directory
called company data. And just for fun, let's go ahead and create a text file called payroll.
And in this file, we are going to say, "This is super secret. Please do not touch." Go ahead and save it and exit it out. Cool. So, now we have a new directory and also a new file. What we're going to be doing here is open up Notepad as an administrator, click on yes, and then we want to head over to our ossec.conf file because we do need to configure our file integrity monitoring here, and that is this right here. Let's go and zoom in just a bit. And now, if we scroll down, we should see a file integrity monitoring setting. Currently, it is set to not disabled and
the frequency that Syscheck is executed by default is every 12 hours. In other words, 43,200 seconds. It is going to go and check these settings. As you can see here, it is default files to be monitored. You'll take a look at these 32-bit programs. And you might also notice that there's a setting called directories real time equals yes. Now, just based off of the wording, you might already know what that means. But in case you aren't aware, this setting is essentially looking at this particular directory in real time. So, if there were anything that was added into the startup directory, then the file integrity monitoring will kick off and you will actually see an event. Now, what if I wanted to perform real-time monitoring for our company data? How would I do that? If you said, "Well, why don't we just copy and paste it?"
You are correct. I mean, why work hard when you can work smarter, right? So, we can go ahead and copy and paste where the directories real time equals yes. And then we can simply change this directory path to C: backslash
company data. Go ahead and save this. And remember, whenever we modify our ossec.conf file, we must restart the
service. Specifically, the Wazuh service. So, go ahead and restart that. Now, let's head over to our Wazuh dashboard. So, over here, I'm going to select active and I'm going to click into our agent. So, in our case, it is the My D for Windows agent. Head over to file integrity monitoring. And as you can see, over the last 6 hours, well, we don't really see anything. So, that's not too fun, right? So, instead, let's force an an Going back over to my Windows virtual machine, under the company data, let's open up the payroll. And let's type in 1
2 3. Go ahead and save that. Go back over to our Wazuh dashboard, and hopefully we should see an event. Well, silly me, not under dashboard, but under events. So, there you go. We actually have one hit. So, this path is our C company data, and it's looking at the payroll.text file. And you can see here, it says integrity checksum changed. In other words, you can kind of think of this as a file hash change. Now, what happens if we were to delete it? Do you think an event will generate? Well, if the answer was yes, then you are correct. If we go and refresh this, take a look. File deleted.
Or right here. File deleted. Now, Wazuh does have amazing documentation when it comes to file integrity monitoring. And I do highly recommend taking a look and see what are the other options that you can use to configure FIM, aka file integrity
monitoring. So, for example here, we do have the real-time monitoring, and this is pretty much what we configured. And if you take a look here, you can also see the file attributes that FIM records. And you can just do a bunch of pretty cool things using FIM. So, whatever your use case is, I would highly recommend taking a look at the documentation and go from there. So, that is the Windows side of things. How do we do this on Ubuntu? Well, let's go into my Ubuntu server, which I am currently SSH'd into from my host. And we are currently under Ubuntu. So, the first thing I'm going to do is type in sudo su dash.
This is going to promote me to my root account. And let's create a new directory called company data. Why not? We'll place this under the opt company-data. And within this directory, let's just say echo payroll data. And then we'll put that into a file under our opt company data called let's
do test.text. Now that that's created, let's go and configure our ossec.conf. I'll type in nano /var/ossec
/etc and we want to point it over to ossec.conf. Now if we scroll all the way down here, we should see a file integrity monitoring setting. And similar to what we did with Windows, I am going to add in the directories real time equals yes and we're going to point it over to opt company-data.
Go ahead and close out the directories.
And that's pretty much it. So let's go ahead and hold control X, Y to save and enter. Now as a proof of concept, let's go back into our Wazuh dashboard and let's go back into the agents and we'll select Linux, go into file integrity monitoring, go into events. Within the last 6 hours, we do not see anything. So now that we configured our ossec.conf, the last thing to do is restart our Wazuh agent service because we are currently on our Ubuntu virtual machine. Now let's double-check our dashboard, make sure there's nothing there. And now let's go ahead and modify our file. So this is
company data test.text. And we'll just include 1 2 3. Go ahead and save that. And in our dashboard, there you go. We have one hit. So, the same thing, integrity checksum changed because we did add some data, and if we were to remove it, just like so, we should now see a file deletion event. Perfect. So, that right there is how you configure FIM on both Windows and Linux.
The next thing that we're going to be doing is creating ourselves a custom rule, which is going to look for any guest accounts that have been enabled. So, if you recall, by default in a Windows environment, guest accounts are disabled. So, before we do anything, let's go back into our Windows virtual machine, and if you're following along, head over to computer management, open up the local users and group, go into users, your guest account should be enabled. So, let's go ahead and disable it by right-clicking, go into properties, and select account is disabled. Click on apply, and okay. Now,
we should see a down arrow right here. Cool. Let's go back over to our Wazuh dashboard, and to create our rule, you want to click into the hamburger icon, scroll down, and you want to select server management. So, this right here. Go ahead and select rules, and pretty much, we are going to create our rule here. But, actually, before we do that, let's pause and think about this. To see the events of a guest account being enabled, we do need to create a query for it. So, what would our query look like in order to identify that kind of activity? Well, if you mentioned something about looking for the guest account, and maybe looking at the event ID of when an account was enabled, then you'd be correct. So, if we open up the hamburger icon, and I am going to right-click discover and open link in a new tab, that way I don't lose this page. I'll click into the Wazuh archives
and if we were to type in something like guest, we do have 80 hits. Now, if we
search up event ID account enabled, what
is that? That is 4722. So, what if we say and 4722,
we have one hit. Why do we have one hit? Well, we did enable the guest account once upon a time. So, we do want to be a little bit more granular in this case and we can do that by specifying the exact field name, which in this case is the data.win.eventdata.targetusername.
Let's copy that and we'll paste it in. Let's also include the event ID field,
so this right here.
Just like so. By doing this, it is going to look specifically for this guest account under this field name and this specific event ID, which again is an account enabled under this field name. So, this query looks pretty good to me. I'm going to copy it and now we'll go back over to our rules and what we want to do is click into custom rules, so
right here. From here, you want to click into the local rules.xml and now we build it out. Now, you might be questioning, well Steven, I'm not entirely sure how to create a rule and that's okay. What we can do is utilize AI to our advantage. How? Well, if we open up a new tab and go into something like ChatGPT or choose whichever frontier model you want, go into it and then say can you please, well, it's important to ask nicely, can you please build a Wazuh rule
looking for guest enabled accounts in a
Windows environment. Here is a sample query.
Then paste it in and hit enter. Isn't that pretty cool? So I was like, "Hey, here you go. Here's an example rule that you can use." Now, just in case AI is incorrect, which by the way happens more often than you might think, what we can do is have it reference our rule file.
So for example, this right here is the rules syntax. So under the documentation, go into user manual, under data analysis, rule set XML, click into rules syntax. Now, what we can do with this is copy the URL, head over to ChatGPT and say, "Make sure to reference this URL."
Now, there is additional recommendations that ChatGPT has provided, but the first one should suffice. Go ahead and copy this, head over to our Wazuh, and let's
go ahead and paste it in. So now we have a group name, a rule identifier, the field name, which is what we provided, the target username, which ends in guest, and the description. So this right here is your deliverable number two, where you'll add in the mydefer-name, which in my case is Steven. Now, from here, I am going to click into save. Actually, before I click into save, let's talk about the level really quickly. So with Wazuh, there's actually, I believe, 15 levels. Well, let me double-check that. Yeah, scrolling down, we see the level allowed values is actually 0 to 16. The higher
the level, the more severe it is. So if we go into the rules and select rules classification, we can see the level right here. So level 0 is ignored. There's no level one, but there's a level two system low priority. And currently, our rule level, anyways, is set to 12. So, what does that mean? That means it is a high importance event. And 15 is a severe attack. So, if you're ever wondering how do you set the severity, that is the level right here.
And you can also include the MITRE attack IDs if you want. Now, of course, the more information you provide the rule, the better. That way other analysts can understand what this rule is trying to do. But, let's go ahead and click on save. And it says, "Changes will not take effect until a reload is performed." Go ahead and click on reload, and we'll just wait a bit. This is essentially restarting the Wazuh manager service in the background. Now that that is done, let's go back into our discover, click on refresh, and actually, you know what? Let's go into alerts, and we are going to say, "Mm,
let's do last 15 minutes." So, we shouldn't see any results here. Go into our Windows virtual machine, and under our guest account, let's go ahead and double-click it, or you can right-click and select properties. Go ahead and uncheck the account is disabled, and click on apply. Click on okay. And let's go into the Wazuh dashboard. Hopefully, if our rule is correct, it should trigger an alert. And here you go. We do have one hit. Go ahead and expand it. Is this the rule that was triggered? No, it was not. The rule that was triggered is user account enabled or created. Now, you might be wondering what was the point of creating a custom alert looking specifically at the guest account when there's already alert created called user account enabled or created. Well, to answer that, we wanted to look specifically for the guest account. This alert is looking for any account that was enabled or created. So, in our case, it's a little bit more niche. It's a little bit more deeper, per se, or specific. So, that is why we wanted to create the guest alert that we just did.
But now I am questioning why it is not showing. So, let's go ahead and refresh this one more time, and we do not see anything. Okay. Let's remove it all, and our alert, or
rule, was actually under the rule description. So, what we can do from here is actually toggle this particular field name as a column. So, I'll do that, scroll all the way up, minimize the event, and we should see the rule description in the table. So, here's the user account changed, user account enabled or created, and yeah, we do not see our newly created rule. So, now it's time to do a little bit of troubleshooting. Why is that? Go back over to our local rules, and let's take a look. So, there is a rule ID here. Go ahead and copy that, and let's see if we can actually filter for that. I'll type in rule.id.
is and then paste that in.
So, yeah, we actually don't see it here. So, to do some troubleshooting, I went ahead and removed our filter, expanded our user account created rule, and let's take a look at the rule groups. So, we do see it as Windows, Windows_security,
and account_changed. Now, if we head over to our Wazuh local rules, what we can do from here is actually utilize AI again. So, I'll go ahead and copy this, go back into ChatGPT, and ask, "Why did my rule not
fire for the guest account?"
Go ahead and paste it in and send it off. Now, of course, with AI, you need to be very careful with sensitive information, but because this is just a challenge {slash} project, we should be okay. Take a look at the first comment here. It says, "Check the decoded event. Run the event through Wazuh log test or inspect the JSON in the alert." The decoded field is actually the win.system.eventid D rather than data.win.
So, what we are actually using is the data.win. So, why don't we actually try this field name? But, actually before we do that let's go back over to our discover and I am going to expand the user account changed and let's find the rule ID, which is this right here. 60110.
Go ahead and copy that. I'll click on back and let's paste that in. So, this is our rule that triggered. If we click into the XML file, take a look at the field name. What do they use? So, if I hold control F and paste it in, this is our rule ID. Again, 60110.
And look at the field name. It's actually using win.system.eventid rather than data.win.system. Let's go ahead and click on back, go into custom rules. From here, let's click into the local rules. And now, let's just remove our data. and keep it as is. And I am going to include the Windows_Security because if we go back over to the rules and search for the 60110,
take a look at the groups. We have account changed, Windows, and Windows_Security. In fact, I'm actually going to change the account management to account score
changed and if we go into the rule of
60109, this is a user account enabled or created and there is an additional group as well, which is add user. So that is something that I'm going to add as well. And you know what? Just to make sure that we are good to go, I am going to click into this XML file, do a control F
60109 and take a look. It also has a if Sid is
6013 and I am going to include this as well. So by including the if Sid, it's essentially matching a built-in was our rule. Let's go and add that under the rule identifier. And that looks to be good. Okay, now let's save it out, do a reload and let's try this one more time. Go ahead and disable the guest account and then re-enable it. Go into our discover and refresh. We should now see the rule description right here. The my differ-steven Windows guest account was enabled and if you're following along for the giveaway, do make sure that you screenshot this rule description. Now I know we did jump around quite a bit. So as a recap, for this rule to trigger, we made sure that it matched the group name of our Windows security rule of a user account enabled or created. We also took a look at the user account changed and we did include the if Sid 60103.
By doing this again, the event is going to match a built-in was our rule. And if we want to know what rule that is, we can simply scroll up and find it right here. So this is essentially just looking at the field name of severity value where the value is audit success.
And by including the Windows and the Windows _security group name along with
the account changed and add user, we were then able to trigger this rule. That goes to show that although yes, you can use AI as a starting point, you could also use it as a troubleshooting tool, but it is not always correct. You do need to double-check and verify its output to make sure that it's actually working as expected. Otherwise, if we never tested this and something were to go off, well, you might catch it by the default Wazuh rule, but you could imagine if you were to create a custom rule simply based off of AI, you might be missing a lot of things, especially if you don't test. Awesome, you just created your first custom detection rule. By now, you should have FIM watching your files and your own my D for alert firing when that guest account gets enabled. Now, if you are entering the giveaway, by the way, that alert firing is deliverable number two. So, do screenshot it with the my D for name showing. In the next video, we are going to go one step further and we're going to make Wazuh actually take an action on its own when it detects an attack. 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.





