-
I tried using chat GPT to get this VQL the way I need it, but it keeps using inner joins and other things that dont work in VQL, and my SQL\VQL is terrible (but I know you can't use inner joins in VQL). Basically, I have a client event artifact that will monitor removable drives smaller than 3.2 terabytes when attached to an agent host (artifact 1), and another artifact that will alert on writes larger than 2 GB (artifact 2). The problem I am trying to solve is to trigger when more than 10 files of any size are copied in a period (say 30 seconds) as opposed to what it is doing now, which is triggering on size greater than 2GB. This is basically to monitor for data exfiltration's for a client from employees. (It would also be nice to filter the alerting on file type if you can include and example for that. Also I realize I am no expert in this area, so any additonal items anyone wants to suggest to accomplish this goal that I am not thinking of, by all means, please let me know them. I realize this is a big long annoying question, so thank you very much in advanceARTFACT1:name: Custom.Windows.Detection.Thumbdrives.List This artifact watches for any removable drives and provides a We exclude very large removable drives since they might have too type: CLIENT_EVENT parameters:
sources:
ARTIFACT 2name: Custom.Server.Alerts.ThumbDriveUseMorethan2GB type: SERVER_EVENT parameters:
sources:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
What you are asking for is actually quite complex and it is unlikely that chat GPT has seen enough such examples (remember it is basically a search engine not AI :-). The trick here is that you are asking about correlating multiple events over time - so imagine I am writing 5 files to the removable drive then another 5 - so if your limit is 10 it should trigger right? So what we need here is correlation across time. So this is how that works. I will show you how to develop this in steps:
The first thing is to open a notebook inside SELECT OSPath, Size
FROM glob(globs="C:/watched_dir/*") Here the query just lists all the files in the watched directory and their size. You can run the query and copy files into it and see the results. This is not useful because it is not an EVENT query - it just runs once and that's it. So we want to turn a regular query into an event query so we know when something happens.
SELECT *
FROM diff(
key="Key",
period=10,
query={
SELECT OSPath, Size,
format(format="%v_%v", args=[OSPath, Size]) AS Key
FROM glob(globs="C:/watched_dir/*")
}) In the above example I copy notepad.exe and remove notepad.exe from this directory. You can see the diff() plugin tells us if the file was added or removed between periodic checks. This is great for the query that looks at the size and reports if the size is larger than the limit (which is the example you have seen). But we actually want to correlate rows across time here - if the diff() plugin reports 5 rows added now and 5 rows in 2 minutes, then we are talking about 10 rows all up and we can trigger an alert!
The To give you an example how that looks like: LET AddedFiles = SELECT OSPath, Size
FROM diff(
key="Key",
period=2,
query={
SELECT OSPath, Size,
format(format="%v_%v", args=[OSPath, Size]) AS Key
FROM glob(globs="C:/watched_dir/*")
})
WHERE Diff = "added"
SELECT * FROM sequence(added_files=AddedFiles, max_age=60,
query={
SELECT SEQUENCE AS Files, len(list=SEQUENCE) AS Total
FROM scope()
WHERE Total >= 2
}) In this example I made the numbers really small so it is easy to test:
So we ran the diff() query we did before, which emits a row for every added file. Say the user wrote 1 file at time 1, and one file at time 3 (the diff plugin will check at time 2 and time 4 - every 2 seconds):
Now that we consider than an alert was raised, if the user copies one more file we do not send a new alert (i.e. the counter is reset). This is still not ideal as if the user copied 100 files we will send 10 alerts (1 for each 10 files) but generally this is how the sequence plugin can correlate results from multiple sources in a time sequence. You can see this effect here: |
Beta Was this translation helpful? Give feedback.
What you are asking for is actually quite complex and it is unlikely that chat GPT has seen enough such examples (remember it is basically a search engine not AI :-).
The trick here is that you are asking about correlating multiple events over time - so imagine I am writing 5 files to the removable drive then another 5 - so if your limit is 10 it should trigger right? So what we need here is correlation across time.
So this is how that works. I will show you how to develop this in steps: