k3nn3dy commited on
Commit
d04230a
·
verified ·
1 Parent(s): ef5d442

Add Analyzing_auth.log_and_Playing_with_Grok_Filters_-_HTB_Sherlocks_-_Brutus.jsonl

Browse files
Analyzing_auth.log_and_Playing_with_Grok_Filters_-_HTB_Sherlocks_-_Brutus.jsonl ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"text": "what's going on YouTube this is ipag I'm doing Brutus from hack the box which is a very easy show lock that mainly focuses on the Unix log off. log it also lightly touches the WT file that's going to show you users that have logged into the box but I think there's going to be something for everyone in this video I'm essentially going to solve this Sherlock twice the first way we're going to go the easy way that most people did and just do a bunch of bash Fu on this log file in order to answer the questions and then after we got them all answered I'm going to take a step back and then go beyond root as we call it and use a tool called grock to parse this log convert it into Json and the reason why I want to use Gro is because that's generally how I analyze log files when I was a CIS admin we'd get a bunch of these just raw logs create a bunch of um", "start": 0.68, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
2
+ {"text": "grock rules or whatever they call them and that will extract the data out of the log so we can ingest it into elastic Splunk or whatever and make it much more searchable right so before we get into all that let's just um start off with this Sherlock um if we go over to Sherlock info it tells us a little bit about it and the whole scenario is we have a confluent server that was Brute Force via SSH after gaining access to the server the attacker performs some additional activities which we contract using au. log so yeah that's about it so let's go ahead and download the log file so I'm going to click on download files and then this should download a zip file and then the password you can click on the key but it's almost always going to be hack the blue so let's copy that download into our current directory so I'm going to copy the Brutus dotzip here", "start": 47.399, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
3
+ {"text": "and then we can unzip it and um we need to specify the password I'm going to use seven zip actually we'll do szip X Brutus doz because I know this asks me for the password right I'm sure there's something I could put in my unzip command to get that flag there but here we go we have alt. log and w temp and before I even look at the questions I always like just seeing what type of data I have I like doing some initial exploring right the W temp file this is going to be a binary format if we try to view it it's just a bunch of mess uh you can use tools like utemp dump on this so if you do utemp dump on W this will um put a bunch of data to the screen that talks about log in log out I generally don't like this just because I'm getting like information overload here even though it is very verbose and nice I like using the last command we just do last without any arguments it's going to", "start": 98.52, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
4
+ {"text": "default to the last file on our box but if we did a man on last we can see all the options so we have like full time stamps but most importantly we have file so it lets us specify what file we want to use instead of our log W temp so let's just do a last then DF and then we going to specify W Temp and and we have the output of this box now the issue is this is going to be in my current time zone if we wanted to change the time zone we can just do a I think it's Capital TZ equals UTC to put this in UTC time and then that's going to change everything so um this is something you should always just get in the habit of doing when you're a Defender making sure the time is in the same thing because a lot of logs and stuff will just use the time of a local server and if you're comparing two things with a different", "start": 157.72, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
5
+ {"text": "time zone uh you can waste a lot of time just because of that discrepancy so I always like making sure all my logs are in UTC format so now that we see something from um wtm like we can see logins the pts they were assigned IP address they came from the date of login when they logged out if we did the D capital F it would put the full Tim stamp on the log out as well instead of just putting the like relative time but now let's go look at the alt. log so if I do a less on this we're going to get a lot of data here right so the log format is going to be like the date the log Source then we have the um program this is going to be the P ID the process ID and then the log message so the first thing I want to do is just see a list of all the programs in this log because that's going to give me an idea what type of information we have so I'm going to", "start": 212.2, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
6
+ {"text": "um let's just head-1 on this al. log and I'll use a to give me what field do I want so this is 1 2 3 four five I want to get the fifth field so I'm going to do an A and then we can say print dollar5 on alt. log and now we have all of this um because the PID is going to make this unique it messes up how we want to do the next thing which is a sort and uni- C because we have all these SSH right we want to group these all in one so I can just see um what type of information in this log file so I'm going to use a said command for that so we're going to do said which is like search and replace and I'm going to search and put these open Clos brackets this is like an or so any character I put here it's going to match as an or so that would be like match A or B or C and we want to match um a Open Bracket up", "start": 270.68, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
7
+ {"text": "to um that's it that's all we have to match right CU we're only doing the fifth field so we have cron this and we just want to trim it after that so I'm going to do a said s and I'm just going to do a Open Bracket let's see Open Bracket and Then star so it matches everything after that replace it with nothing and we have a few we have colons as well so I'm going to add a colon in this ore and we have to escape that with a backslash and now we just have the log field right so now we can do a sort then uni- C and then I'm going to do a sort DN and we can see here's all the programs that are in off. log um ch FN this is change something um let's see change real username and information so we have a username being changed password being changed user being added system D doing something user being", "start": 331.28, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
8
+ {"text": "modified groups being added we have some pseudo commands um system D login a bunch of crons and a bunch of entries from sshd so if we wanted to we could just grip this log for user um let's do user to see what user was added so if I grap user ad on alt. log let's actually put that to the top of the screen so you can read the whole thing we can see that the user cyber junkie was added to this box at this time the last thing I want to do before we go to the questions is try to identify what um time zone this log is in because I did make a harp on that just a couple minutes ago so we're going to run that uh TZ command with last again and let's see we see cyber junkie logged into the system at 637 so let's GP 637 on our off.", "start": 404.56, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
9
+ {"text": "log um we have to grab 637 and let's see do we have a accepted password for cyber junkie right around the same time so this is most likely going to be in the UTC time already so we don't have to do any time zone conversions so now it's time to look at the question um before we do that let's actually save this to log programs. text just so we have a list of everything in the log so let's see after analyzing alt.", "start": 460.96, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
10
+ {"text": "log can you identify the IP address used by the attacker to carry out the Brute Force attack so to do this um we can look at the log file so I'm going to grap sshd on the log because that's the only program that will allow like remote access access so let's look at all the sshd lines so looking at this we start out with this authorized key command on ec2 I think this is how like Amazon runs a command on the box this looks like it's an ec2 box um accepted password for root we have an IP address here invalid user um let's see a lot of these Pam Unix things I don't really care that much about because this isn't giving me any information this authentication failure does give me the r host but if we look here we have invalid user here so we have the our host already so I'm going to hide everything with pamore Unix um", "start": 494.44, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
11
+ {"text": "just so it's a bit cleaner for me looking at and then if I want to add it later I can always do that but we see right off the bat this one IP has a bunch of failures and it says invalid user so I'm going to guess this is a Brute Force attack right now as we see it changing users but if we want it to be certain we could extract all the IPS out of this so to do that I'm going to use a command called grep and then we do- op because it's overpowered how this works it only shows um what we ask for instead of showing us the whole line I for exactly what the flag stands for but that's how I always remember it so we want to match for an IP address I'm going to give it a digit 0 through 9 and say it can match 1 to three times and then a period and then we're going to do that three more times because the IP can be um like four", "start": 549.56, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
12
+ {"text": "numbers and let's see we have to get rid of that escape and then we have a list of all the IPS so if I now do a sort um let's do sort uni- C we have three IP addresses this IP address it kind of looks familiar to me if we look at it that's going to be the log source so I don't want to show this one actually because that's not in the log message um so what I'm going to do is put a space before the IP address and that's going to filter that out because this always has a dash so if we just do a space right here here's all the IPS so we have one valid IP or one this one IP that just connects one time and then 165 from this and if we GT this again on off. log we can see a lot of failed attempts right so this is going to be the one that is brute forcing put a submit there and it's accepted so let's see The Brute Force attempt was successful and", "start": 607.959, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
13
+ {"text": "the attacker gained access to an account on the server what is the username the attacker got access to so let's go back into all thought log so I'm going to go before I did that one grap and we want to see what a successful login looks like right I'm just going to search for cyber junky because we know from that last command this user had a successful login and it has the word accept in it so what I'm going to do is a grip on accepted let's just do accept because maybe it's a public key actually if it's a brute force it would not be a public key for login right so we can see these are the um logins of the box this one is not the Brute Force IP so we can get rid of that we probably should have added a grap on that IP address so we only show The Brute Forces now what is the question The Brute Force", "start": 675.24, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
14
+ {"text": "was login what account did they gain access to um it's probably going to be root um from looking at the logs we knew cyber junky was added to it so if we just put root here and then submit we have it and then the other thing we know that oh other way we could have validated this was brute Forest is if we go to this log line so I think if I do let's see let's get rid of let's put the IP graph up front and then I'm going to do A- Capital A3 so this is going to show me three lines after accepted password and I do that so we can see the disconnect so we see the disconnect happens the same exact second as the accept password and this is also indicative of a successful Brute Force but there's plenty of other times this just happens naturally right if I um SSH into a box so if I did like SSH Brutus who am I it", "start": 733.04, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
15
+ {"text": "would SSH into Brutus run the command who I am I and exit so you'd also see it within the same second but because we saw this IP with a bunch of failed logins and then we see a successful login it immediately stops we know this is going to be the Brute Force attempt right so let's see um we need to put it in year year year month month day day let's see oh the attacker manually logged in so this one's going to be from the um Brute Force because it happened the same second and then if we look at the second time they log in this is probably going to be the manual one because they don't log out until like four and a half minutes after right we have 32 37 so let's put this in let's see the year I'm going to guess this is 2024 because it's not telling me the year so 2024 I want to say March is month number three watch me get that wrong now that I'm recording um 06 is that the format", "start": 798.279, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
16
+ {"text": "yes it is then hour hour so 06 3244 if we do submit it is the wrong answer so what we can also do is look at the um W temp file so let's go back to a last command and let's see when did they log in um this is the Brute Force IP and it's actually a second after so it accepted the password but probably accepted the password at like the 59th second so they weren't fully logged in until the next second so let's try putting the 45 here then click submit there we go we have the full time stamp and maybe the log file not telling us what year it is is a hint that we should be using the um W temp file because the W temp file it should show yeah it does show us the year right so let's see sh login sessions are tracked and assigned a session number upon login what is the session number assigned to the attacker", "start": 871.44, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
17
+ {"text": "session for the account from question two so question two was when they manly logged in and that's going to be around this time so we need to know the session for that so I'm going to GP session on off. log and then we have a bunch of things in KRON so let's just hide KRON so we can g-v and then let's see this Pam Unix just says session opened for uid it's not giving us a session number let's see we have login D remove session 34 so login D is going to be what we want to get probably to see sessions so if we GP system D log D on alt. log let's just put that to the top so we have a few sessions here and we said 3245 or 3244 was the login time so it's probably going to be 37 right let's see question two Bri for successful gain access oh this is probably going to be the other one it's one of these two I can't remember exactly what this question", "start": 941.72, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
18
+ {"text": "was gain access let's go back to the accepted password it's probably this one is that question two was talking about the brute force was successful so 3140 that's going to be what we want to get so session 34 let's see are we right wrong answer uh let's go back accepted password for root 3140 maybe it wants the manual log in 32 44 do 37 okay that's the one it wanted see the attacker added a new user as part of their persistent strategy on the server and gave the new user account higher privileges what is the name of this account now we kind of already answered that right if we went back to the log programs when we looked at user ad if we grap user ad on off. log we can see cyber junkie is here right so it also says um they gave this account higher privileges so again let's look at the log programs um user mod we may want to", "start": 1027.12, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
19
+ {"text": "look at so if we grap user mod on off. log let's see they added cyber junkie to the pseudo group so that's definitely going to be the answer okay okay so we need to get the miter attack um technique ID so let's Google miter attack framework ID maybe let's see going here awesome so is it talk does it tell us what the thing so we're looking for persistence so going over to miter attack persistence account manipulation um create account this is probably going to be it so if we go here let's see what is the question format T this there's a period we need this sub technique probably local account submit there we go so how long did the attacker's first SSH session last based upon previously confirmed authentication time and the time ending within off.", "start": 1122.12, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
20
+ {"text": "log so let's run this last command again let's see first SSH so 3245 to 372 four now I know it says using the time in off. log so if it's wrong we'll go back there but we can just use this time first so let's see if we added 5 minutes here we'd be at um 3745 so we definitely don't want to add five so it's adding 4 minutes and then 15 seconds that will put us at minute um 37 and 15 plus 24 would be 39 so we're at 4 minutes and 29 seconds I want to say say wait did I do that right 15+ 24 no I think it was 39 right yeah so 4 minutes and 39 seconds uh let's see and we just want seconds so that's what 120 would be 2 minutes 240 is 4 um 279 it's always frightening doing math when you're recording something live there we go so the attacker into the back door account and utilize their higher privilege to download a script what is the full command", "start": 1215.0, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
21
+ {"text": "executed so if we go back to our programs uh what do we call it cat log programs I'm going to guess PSE sudo will be the log program that gives us what commands were being ran normally alt. log doesn't give you the commands but if it's with a pseudo it does because um you do a pseudo um you run the command as part of the login with pseudo so let's grap pseudo on off.", "start": 1295.159, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
22
+ {"text": "log and then let's see um they were added here so we may want to grab pseudo colon so this only shows us those lines now cyber junkie let's see session open route here we go so they're in cat Etsy Shadow and then they're doing a user bin curl to download this lper script so let's copy this paste that and we have completed this Sherlock um I kind of want to see what the script is what is this doing um let's just do github.com CU I have not heard of this a Linux persistence toolkit so it looks like a bash script in order to do a bunch of persistence things so that is how you can solve the Box the easy way of just doing a bunch of bash food to look around a log file but I really hate doing that or at least doing that at scale it worked here because we didn't have much data but you can see just um", "start": 1323.0, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
23
+ {"text": "like how wonky that is right if we go back into off. log let's see I'm going to search for invalid we have invalid user let's see let's actually search for fail there we go so the a is going to be really challenging to just extract some data with because we have failed password for invalid user admin so if we were just trying to a it we got to like add some Fields because there's two words here before the username but the user was on the box looks like backup is a valid user on the box doesn't have invalid user so it puts it here so this was five so six seven 8 n so it's either going to be field 9 or 12 and I just hate that right this is just a unstructured log so what I like doing is converting this into Json and to do that I like using a tool called Gro because again that is going to be what a lot of seams use um and there is py grock so if you want to", "start": 1404.12, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
24
+ {"text": "do this in Python um I think pi3 grock is probably what you'll want to use but I'm going to actually go with goang because um elastic has a nice repository I think that's what it is for so if we do um what is it elastic grock GitHub see it's maybe go Gro there we go this is going to be the library I use and essentially this is just an easier way to do regular Expressions right right so the grock rule is going to look like this where we do percent and then a squiggly bracket um the identify so this is matching an IP address and then we give it the field name so this is going to be destination IP then we have a engine X separator they have defined that as either tab space comma or colon and then the next field they have will be destination Port right so we're going to write this engine x pattern and we're just going to make a bunch for off. log and I know if you Google it you", "start": 1464.72, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
25
+ {"text": "can probably find some already made grock things so you can just copy and paste and get it working but I want to show how to actually make the gro files because I find myself having to do that quite often when I was maintaining elastic or Splunk right so let us um make a directory for a goang program I'm going to call it Go Brutus and then the next step will be make um initializing it so we'll do go mod AIT and then go Brutus because that's going to be what we call it I'm going to touch main.go and then I'm going to open up visual studio code and now we can go over to main.go and then just give it the package main since this is going to be the main thing and we give the main function so we'll do Funk Main and we have to add the the go Brutus um library or not go Brutus go grock Library so I'll copy github.com and then we'll do a go getet on this and", "start": 1535.279, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
26
+ {"text": "this adds it into our project so we can begin using it um if we look at their example let's see I guess before we begin coding let's just do um grock test online and show exactly how like what a Ro pattern looks like this site's very much like regx 101 if you use it so they have samples here um let's see named group capture let's just get rid of all that and try and think of a good way to demo this let's just take a line out of.log that would be good um grab SSH off log let's go with a failed password go to the grock debugger and we have this so the grock pattern is like rag X except instead of like it's kind of a strip down version of rag X because we can only like extract words from it regex we can do a lot more manipulation but generally when you manipulate things you do that in log stash or something", "start": 1599.799, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
27
+ {"text": "else to mutate or transform the matches um grock is really just for extracting the important words so let's do the failed password and then if we said like percent word and then we could call it um day of week like it matches the first word right there are pre-built um queries so if we go all the way down here they're talking about all the things that we can match like word not space space um data is one I use a lot we have like ipv4 IPv6 IP that matches both there's a bunch of just pre-built um keywords I guess I should call it right there's also pre-built patterns so if I go into patterns and then go into the CIS log built-in patterns there is Cy log base 2 and this is going to be how I begin things so if we do CIS log base 2 let's see is that going to match it it's not matching anything because if we go over here um we have to add the Cy", "start": 1670.72, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
28
+ {"text": "log um pattern and there we go we have a time stamp so we match that then we do a space and then this is going to be the log source so I'm going to say data I'm going to call it log Source like that let's see that did not match we do space after okay so we do a space after so it knows that is what we want and then we want to match the um program so I'm going to call this um word and then we'll call it program we match that I'm going to escape a parthy and then we can say base 10 number and this will be P ID because that's the P ID that's um writing the log we can close that out put in the quote and then we want to match let's say word and we'll call this um let's see this is failed so maybe result okay um let's see this could either be probably like key or password so I'll match word again and we'll call this um", "start": 1746.76, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
29
+ {"text": "login type maybe for isn't really an important word so we won't match that then we can say another one word username actually I'm going to do data because usernames can contain like numbers and things like that I think data will still match that right like if I do back up one two well still matched but if it was on word oh it's still matched okay I thought word would require it only be Alpha numerical um from then we probably want to match IP this will be Source IP port and let's see I'll call it client port I don't know if it's supposed to be Source port or client Port but um or Source or destination but I like calling it client let's see this will be um base 10 num there we go and I'm guessing this ends with protocol I'm just that's what I'm going to call it so we'll do word and then protoc and it's a percent not a dollar and there we go we have this all", "start": 1835.24, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
30
+ {"text": "perfectly matched right so there is one let's see there was something with invalid right so we also want to be able to match that invalid okay this was the example we used that would be a pain in the butt to do with a bunch of a right because the field changes so what we can do is we can do a um is it an optional I don't know exact terminology but if we go where username is and we put some parenthesis we can put a string in and then do a question mark at the end of parentheses and what that's going to do is um an optional match so now we match them both and if we look here um I can put this over to the right so we can read it better um we have all the matches for both of them so that is Gro and a nutshell so what I want to do now is create the program so we can um go over the entire log file and parse it so let's go back", "start": 1920.519, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
31
+ {"text": "into visual studio and we're going to begin with G is equal to gr.", "start": 1992.48, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
32
+ {"text": "new okay and if we go back to their example you can see exactly how to structure a program right here so we create pattern definitions and then we can add patterns so let's see I'm going to call it pattern definitions map string like that okay and then let's see um we want to be able to use CIS log base 2 I think right so I'm just going to call this log prefix and then we will do CIS log base 2 like that and I'm just going to get this working real quick with this and then we'll start making more advanced patterns but I just want to make sure my program works so we can call add patterns did they do add pattern from map see they just did add patterns there we go and then let's see they compile then after we compile let's see I'll do log prefix I know I probably could just do log base 2 right here but I just want to make sure I'm understanding how this", "start": 2002.32, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
33
+ {"text": "pattern definition works and then we do result air PR string and then we can give it a log line so we'll give it this line like that then if a is not nil and we print the result okay so let's see if this works so we can do a go run main.go and we get pattern definition um unknown it doesn't know CIS log base 2 and this is going to be the same issue we had when we first used grock debugger because we added the CIS log entry so we have to add that pattern into um this so we can do G do add pattern and then patterns Dot and then what did they call it was it CIS loged is it Linux it's this log um I don't know why that's oh it's add patterns with an S okay so now if we run it we have a match and I know it's not Json if we wanted to we could convert this into Json so if we did a uh let's see Json", "start": 2105.0, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
34
+ {"text": "data herror Json Marshall then re F A is nil I can print that and there we have it in Json okay they call it h name and not log Source that's fine but that is going to be this and a nutshell so what I want to do is um I'm going to have two patterns we're going to call this um base patterns and we'll call it log prefix and then we also need to add um the other fields right because if I look at alt. log we're only capturing up to here I want the log prefix to capture um up to here right so we can just go back to here we call CIS log base 2 this can be did I copy the whole thing I did there we go add base patterns there we go we have matched more things so now we have the P ID and the program so there's going to be another thing like this and I'll call this log entries okay so what I want to do is", "start": 2202.68, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
35
+ {"text": "create one let's do KRON because kron's going to be pretty quickly or pretty simple um see I wonder if it's already doing the cron for us off log we can just copy when adding these I like just putting the comment of what I'm working on there and let's see we can get rid of this because that's going to be log prefix so log prefix okay and then let's see word action so that'd be session I don't know if that's correct but that should be fine um let's see session this will match open to close I'm going to call this status for user username then uid see thinking let's just see if this works real quick we add the log entries and we can do cron let's copy this go run didn't match so we do log prefix we probably have to match that right we did not do that oh let's see I thought K was going to be quick", "start": 2319.24, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
36
+ {"text": "long prefix gets us to here Pam Unix Cron session do we have to escape things see I just want to undo this and maybe I didn't save nope we do need to escape those we probably should make these fields and things like that so we purse it but you get the idea of what we're doing we don't really need the cron in order to um answer any questions so I'm not going to spend too much time there um I already spent more time than I wanted to doing that so let's see the next thing we probably want is SSH off so let's do log prefix and we need to add SSH line here actually we already have o right that's going to be this see we just want to grab that there we go okay CIS log Word program PID right here okay so here on this compile we can do an or and then we can say SSH off like this and now that's going to match either Aon", "start": 2495.72, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
37
+ {"text": "entry or SSH off copy this let's test it on the par string save it run and there we go we have it if we do JQ dot we have the login type is password the P ID of SSH result failed Source IP um the username backup 12 everything is looking good so what is the next field we probably want to do um let's see we have invalid user there I guess we can do um system D session because that was one of the questions right so we want to grab the session grap system D grap session okay new session remove session let's see how can we do this best going to copy this and we can just go straight here let's go back into this CU we want to be to match both remove and new we could write two lines for this but I want to try doing it all in one so let's see this will be percent word uh we'll call this status I guess because new and removed", "start": 2608.839, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
38
+ {"text": "session then this could be session ID this is a base 10 number okay now we want to do a big or operator of user see this will be oh there's a field username username there we go that works so we use the like conditional operator to say this is optional we match username and then we end the line with the period whenever you do the conditional operator at the end you have to match a character so if it goes to the very end of the line you would do a dollar sign to match that's end of line but in this case we could just match the period because that existed right so this this could be the system D message so we can now go back here system D session then we do log prefix paste that and we have it so I want to stop getting into this case where I keep um adding to my compile every time I create something here and we can somewhat do that so I'm going to create a", "start": 2723.44, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
39
+ {"text": "here and then we're going to Loop over all the entries so it's going to be key and then we'll do an underscore this going to be the value but we don't really care about the value right here I just want to get these pieces so we can do this then range log entries yep and then patterns yep that is right so what we're doing is creating a string going through each of these and then encasing it in this and then putting that so on this compile now I can just do patterns and it'll automatically put anything we have here and what we're matching so let's go over to this you can copy uh we probably should just do it from the whole line let's see new session route copy let's put it up so you can see it past paste like that go run oh we did not match let's see what do we have wrong so log prefix well before we assume we have something wrong it could be this thing that we just did so", "start": 2817.96, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
40
+ {"text": "let us make sure it's not that okay it is not this is our actual string is this going to be picking we have to escape that period huh let's paste that I wonder if it's because this has a dash and how we're doing the log prefix isn't going to capture that that is possible I think that's what happened so we did Word program data program there we go so word is terminated upon that Dash and that's what screwed it up so let's change this to be data probably don't need that end of line there we go that works and then I just want to make sure this works it does okay so let's do one more let's do user ad so we'll do user ad and let's see um what do we call that log programs so GP user ad all log this is going to be the line so we can copy this let's go back here see we can get rid of that so let's", "start": 2907.079, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
41
+ {"text": "see user add new user see do name is equal to then username username uid this will be base 10 num uid GID base 10 num G home this will be so path Unix path home dur comma shell and this can be Unix path again from and we can say Unix path again from there we go so we can add this let's see yeah that should be fine go back to our program past this and then we can copy this line go back here parse the string go run did not match I am not sure why I wonder if we have to terminate the Unix path into a dollar nope oh we don't have log prefix hopefully that's it there we go so grock is very very very picky with um matching things but there we go so if we looked at um program we'd have user ad and go with this so now what I want to do is um copy the off log into our directory and then we want to Loop over it and print everything so instead of doing a par", "start": 3041.52, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
42
+ {"text": "string right here we're going to read a file so I can do um file air OS open all. log if we can't open it panic okay uh D for file close then scanner is going to be buff iio new scanner file so this is going to read the file it's going to Loop over the line and we can say line is equal to scanner text and then we can parse the data that our string is just going to be on line okay go run main.go and there we have it now we're starting to grab everything so we could just easily purse this over into JQ and then do searches through this um most people at this point probably would send it over to elastic Splunk and use their language like I think Splunk is kql or Lucine or something to do searches but we can do it the old fashioned way with JQ so we can press this and then say like select um program is equal to", "start": 3221.64, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
43
+ {"text": "KRON and then if we terminate now we only selected the entries with KRON but really we probably wanted SD so we have these and then we could say uh show me let's see we probably want the username and then we'll add a colon Let's see we probably want actually before username let's do Source IP and then let's see we did Source IP username um do we call it result we did not um status what did we call it Source IP we did oh we didn't have the plus result for got the plus there as well there we go so we have IP that um we also had the client Port we probably should have put that next the IP but the client Port is changing so it's not really that interesting um every now and then some Force programs will hardcode The Client port to be a single thing and that can be very indicative of a brute force or", "start": 3307.599, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
44
+ {"text": "the same person going through things um in this case it's just using a random ephemeral thing so it's not important uh let's see what else do we want to do uh this is the IP we can see a bunch of failed and then the accepted here and they go in again um let's go back to the questions to get an idea let's see uh how long oh we can do commands we should probably grab pseudo and command um so we'll add that to the program we have to grab pseudo off log let's see here's this we definitely want run command let's go over to our grock debugger put that in get rid of that let's see I guess this needs to be optional okay we should change a program real quick add this to be optional and see if that breaks anything it should not so we put that right here like that go run okay it's still parsing that's great so let's see we probably want", "start": 3392.68, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
45
+ {"text": "a username then this will be TT Y is equal to to uh word TTY let's do data TTY space semicolon there we go bwd we need percent not dollar Unix path um p D then user I guess it's going to be Target user right TGT user usern name like that then command and let's see we're just going to grab everything I don't know greedy data and data is do data dollar that should grab everything okay see if I wasn't recording a video now I'd probably ask chat GPT what's the difference between data and greedy data but this seems to be working so now I can say um pseudo CMD like this okay then we do go run let's make sure the program doesn't die awesome and instead of doing like a um select program is equal to whatever we can always just grap d i forse sudo and then we can pipe it to JQ and this simplifies doing the syntax doing", "start": 3495.039, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
46
+ {"text": "it this way because all the Json on one line so you can do graps and g-v so we can see um this but we didn't grab the actual command we should have the command processed greedy data no let's see I wonder if it's not being terminated that way yeah it's probably got a different Terminator which honestly sucks um let's see how can I do this I wonder if I added let's see where is line Lin scanner. text is this string string plus this is going to be a hack so we're going to make sure the end of line is in there let's see do we still have the dollar like that data should work doesn't match anything did I not label it was that the issue I didn't label it I think that was the issue uh let's see get rid of that yep I did not have it labeled so that was going to be the issue oh that's embarrassing but we can", "start": 3619.92, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
47
+ {"text": "just do JQ Dot and then we can say do command and let's see we can say um dot user plus ran as TGT user username so there we have we have cyber junkie ran as rout with this command so that's pretty cool um let's go one more question and then we will end the video uh we showed kind of how we could do the Brute Force um let's do the session ID so again instead of playing all around with the JQ syntax I'm just going to GP for session and then we can go um g-v to get rid of anything with KRON we have to capitalize that there we go then we go to JQ and we can see the sessions right we could also grap on new so that's only going to show us new sessions and we have a few sessions to choose from we would look at the time stamp we want so if we knew what time stamp this was I want to say it was like 30 something probably", "start": 3784.2, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
48
+ {"text": "3140 it's either 3140 or 3244 but we can get the session IDs this way right so hope you enjoyed the extra content with grock and it wasn't too confusing again as long as you understood the first part of the video when we GPT through the file that's all you need to complete the Sherlock and Target it at the um very easy level going into grock is definitely beyond the Target demographic of the Sherlock but I think it is something all defensive people should learn just because so many applications do use grock in order to do some type of log parsing it's great when the log the application will just log straight into Json and do structured logging but that's not always the case so you'll probably find yourself having to make grock rolles and play around with them so that's going to conclude the video", "start": 3883.92, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}
49
+ {"text": "hope you guys enjoyed it take care and I'll see you all next time", "start": 3932.16, "duration": 0.0, "meta": {"video_id": "bv08UcIL1po", "title": "Analyzing auth.log and Playing with Grok Filters - HTB Sherlocks - Brutus", "url": "https://www.youtube.com/watch?v=bv08UcIL1po"}}