Filtering .log files, with cat, grep, cut, sort, and uniq

  Рет қаралды 87,588

Hackpens

Hackpens

Күн бұрын

Пікірлер: 123
@tonyferns
@tonyferns 3 күн бұрын
One of the best video walkthroughs of all time.
@yosefberger6259
@yosefberger6259 Жыл бұрын
Great introduction to the topic, a few things that i think are worth mentioning, once people have learned the commands that were being demonstrated: If the logs your using have a variable amount of spaces between columns (to make things look nice), that can mess up using cut, to get around that you can use `sed 's/ */ /g` to replace any n spaces in a row with a single space. You can also use awk to replace the sed/cut combo, but that's a whole different topic. uniq also has the extremely useful -c flag which will add a count of how many instances of each item there were. And as an aside if people wanted to cut down on the number of commands used you can do things like `grep expression filepath` or `sort -u` (on a new enough system), but in the context of this video it is probably better that people learn about the existence of the stand alone utilities, which can be more versatile. Once you're confident in using the tools mentioned in the video, but you still find that you need more granularity than the grep/grep -v combo, you can use globbing, which involves special characters that represent concepts like "the start of a line"(^) or the wildcard "any thing"(*) (for example `grep "^Hello*World"` means any line that starts with Hello, and at some point also contains World, with anything or nothing in-between/after). If that still isn't enough you might want to look into using regular expressions with grep, but they can be even harder to wrap your mind around if you've never used them before. (If you don't understand globbing or re really are just from reading this that's fine, I'm just trying to give you the right terms to Google, because once you know something's name it becomes infinitely easier to find resources on them)
@xiMoshyx
@xiMoshyx 3 жыл бұрын
Doing this basically as a task for multiple questions in Uni. This is the only video that really made it click. Please do more tutorials, your content is fantastic!
@hackpens2246
@hackpens2246 3 жыл бұрын
Thank you mate. I work in IT. I don't get a lot of time. Any suggestions on a next video?
@whateveritwasitis
@whateveritwasitis Жыл бұрын
​@@hackpens2246we dont know wjat we dont know 😂
@msnraju97
@msnraju97 Жыл бұрын
I am checking this video 3year after upload. The video tutorial is on point and clear.
@potatochannel1948
@potatochannel1948 4 ай бұрын
this one is one of the most helpful tutorials out there that show how powerful grep and pipe are. Thanks for sharing that and I hope you make more cool stuff.
@csangeetc
@csangeetc 3 жыл бұрын
This is a wonderful video. A perfect set to be learnt in order to crack interviews.
@hackpens2246
@hackpens2246 3 жыл бұрын
Glad you think so!
@radiantmind1079
@radiantmind1079 2 жыл бұрын
that was one of the most useful and simple tutorial i've ever seen
@hackpens2246
@hackpens2246 2 жыл бұрын
Glad you think so!
@Sparooga
@Sparooga 2 жыл бұрын
This video has been hugely helpful to me when parsing through log files of numerous types manually (IPtables, Netflow, SSH). Thank you very much mate.
@hackpens2246
@hackpens2246 2 жыл бұрын
Fantastic to hear mate
@vadivelan4228
@vadivelan4228 2 жыл бұрын
I was searching for all command combinations in reading logs to extract an info. this video is great.
@fredflintstone505
@fredflintstone505 Жыл бұрын
Thanks! That was informative. The only thing I would have done differently is flip the order of uniq -d and sort. Less items to sort after uniq filters them out.
@DarwinMatosAlvarez
@DarwinMatosAlvarez 2 жыл бұрын
You are very good at Linux, hope you continue sharing your knowledge!
@Monana666
@Monana666 3 ай бұрын
this is exactly what I was looking for and even more! thank you so much!
@albinbabu4846
@albinbabu4846 11 күн бұрын
Thanks for this one. Helped a lot
@geetabasker7127
@geetabasker7127 Жыл бұрын
Concept explained well in a short video.
@basheeral-momani2032
@basheeral-momani2032 2 жыл бұрын
Thanks a lot that's very helpfull I would like to see more cases of analyzing the logs, to learn from you build more experience in that regard thanks
@genghismike6186
@genghismike6186 Жыл бұрын
Thanks.. very helpful and will be using this as a reference from now on
@Arbnor93
@Arbnor93 2 жыл бұрын
You sir are incredible at teaching
@richardazu7445
@richardazu7445 Жыл бұрын
Simple and straightforward ❤
@xiandron574
@xiandron574 2 жыл бұрын
Honestly i was looking for a long time for some good videos for linux, and sir I can tell you, your videos are gold! Thx a lot!
@hackpens2246
@hackpens2246 2 жыл бұрын
Glad to hear that!
@dune4095
@dune4095 2 жыл бұрын
Awesome tutorial on cat and grep, Thanks...
@gussta1
@gussta1 3 жыл бұрын
It would be nice to see some range greps, meaning pull out all the IP's that hit the systems between 20:00 and 22:00 or something like that
@dsdcp
@dsdcp 3 жыл бұрын
Using - -since .... - -until ....
@aravind4444
@aravind4444 3 жыл бұрын
great video, grep -v is quite useful. thanks for sharing this
@hackpens2246
@hackpens2246 3 жыл бұрын
Glad it was helpful!
@siddheshnavse1056
@siddheshnavse1056 2 жыл бұрын
Short and very usefull. Impressed :)
@messileo919
@messileo919 Жыл бұрын
Thankyou this video was exactly what i needed
@quarylaniel
@quarylaniel 3 ай бұрын
REALLY HELPED THANK YOU SO MUCH
@ben-cb5er
@ben-cb5er 2 жыл бұрын
Awesome video! Please don’t stop making Linux, bash, ethical hacking related videos. Thank you. Subscribed!! 😊
@gustavotobias7681
@gustavotobias7681 Жыл бұрын
Muy buen video, gracias por compartir, saludos desde México
@EdHatesNoobTubers
@EdHatesNoobTubers Жыл бұрын
😊 great videos 👍 thank you!!!
@just-watch-this
@just-watch-this 3 жыл бұрын
Nice tutorial. I'm interested in what you have on that server that is gaining that much attention.
@hackpens2246
@hackpens2246 3 жыл бұрын
Thank you. That server has nothing accept a redundant web site on it, but the site name has the word "hack" in it, and the hackers don't know it's not worth hacking. I feel sorry that they try haha
@whateveritwasitis
@whateveritwasitis Жыл бұрын
​@@hackpens2246so u say 😊
@nabilsoliman4640
@nabilsoliman4640 3 жыл бұрын
you have a great explanation way
@hackpens2246
@hackpens2246 2 жыл бұрын
Glad you think so!
@MAX-nv6yj
@MAX-nv6yj Жыл бұрын
thanks for the amazing video love it
@derekberthiaume5367
@derekberthiaume5367 2 ай бұрын
If I wanted to count the number of times that each unique instance showed up. What would I do for that? Would I do the unique and then do the word count for each instance by using grep for that specific phrase?
@BilalA42
@BilalA42 2 жыл бұрын
@Hackpens very informative video mate. Thanks for sharing. What is this tool you are using? Do you have any video for beginner? I really need to learn this stuff. Kindly help. Thanks again.
@XxLuvverofMusicxX
@XxLuvverofMusicxX 2 жыл бұрын
You want the duplicates if they are from different source IP addresses as this means that different people have tried the same user names to access your system
@hackpens2246
@hackpens2246 2 жыл бұрын
I like the way you think ;)
@muzamilabbasi
@muzamilabbasi 2 жыл бұрын
thank you this is very helpful
@CaribouDataScience
@CaribouDataScience 2 жыл бұрын
Back in late 90's I wrote a script to track backup take useage.
@hackpens2246
@hackpens2246 2 жыл бұрын
Please show us!
@dodokwak
@dodokwak 6 ай бұрын
You could configure fail2ban not only for sshd but also for nginx requests to catch 400-404 errors.
@subbu4754
@subbu4754 2 жыл бұрын
Very useful tutorial for me
@tamojitchatterjee3411
@tamojitchatterjee3411 3 жыл бұрын
Thanks for a great vid!
@yash1152
@yash1152 Жыл бұрын
From description: > _"I show you how to filter information from a .log file, and you find out just how important strong passwords really are."_ i always wondered that pattern matching has smth to do with password security, but then i thought, you have to have passwords to apply pattern matching on 'em right? 'cz the password input field of a site doesn't accept regex, and generating exhaustive strings from regex doesn't help either... so, what are scenario we are imagining for talking about regex in context of secure passwords?
@dodokwak
@dodokwak 6 ай бұрын
Thx. Very helpful.
@boardgamegirly
@boardgamegirly 3 жыл бұрын
thank you for this helpful video for a dummy like me!
@hackpens2246
@hackpens2246 3 жыл бұрын
Glad it was helpful!
@sirprancealott2003
@sirprancealott2003 2 жыл бұрын
Great info and an enjoyable watch 👍👏
@pjj7466
@pjj7466 Жыл бұрын
Gold sir 🔥
@varunt6846
@varunt6846 2 жыл бұрын
Hi Sir, I have a log file which I cannot see after the command cd /var/log Please give me some suggestions thank you
@hackpens2246
@hackpens2246 2 жыл бұрын
Use pwd to make sure you're in the correct directory. Then ls -a to list all the files in that directory. If its not there, its not there.
@ITsikkerhet
@ITsikkerhet 3 жыл бұрын
YES YES YES YES!! MORE OF THIS!!
@skrunkly688
@skrunkly688 2 ай бұрын
I’m on windows and I’m currently tasked with finding stuff for a log file they gave me
@ansellroman6620
@ansellroman6620 Жыл бұрын
from the ip addres can you find out their location ?
@hackpens2246
@hackpens2246 Жыл бұрын
If the user isn't using a VPN service, then yes (an approximate location) using a publicly available tool, like whatismyipaddress.com/ip-lookup
@PEDERSTEENBERG-d5h
@PEDERSTEENBERG-d5h 9 ай бұрын
hOW CAN I SEE ALL FILES ON HARD DRIVE OR USB ? AND HOW COULD DECRYPTED FILES BE ERASED OR OVERWRITE WITH SUDO SHRED ?
@TrendyTales-ep9yq
@TrendyTales-ep9yq 7 ай бұрын
sir can we use awk instead of cut?
@paaao
@paaao Жыл бұрын
Now dump all the unique IPs into a text file, and run nslookup on each one. $50 says they all are located in China or Russia. At least %98-99 of them. At least that's what I always end up finding.
@firozshaikh3739
@firozshaikh3739 2 ай бұрын
hi do you know how to copy log file from cowrie honeypot is on?
@guths
@guths 4 ай бұрын
awesome video
@comic-typ5919
@comic-typ5919 2 жыл бұрын
Hi, great videos again :D Is this amaount of tried logins normal ? If so, this is a bit scary... Is there a way to "hide" the server ? Im a beginner, pls excuse a potential dumb questions/statement.
@beyremrjeybi9978
@beyremrjeybi9978 Жыл бұрын
nice , except cut -d " " -f x not working for me , i will dig durther to figure out why..
@cainanashton
@cainanashton 11 ай бұрын
Good vid, thank you
@brahimayoada2657
@brahimayoada2657 2 жыл бұрын
16 th field from experience still blow away
@makopafruit
@makopafruit 8 ай бұрын
Thank you!
@VikasGupta-nn7sd
@VikasGupta-nn7sd 3 жыл бұрын
I learned something new, but I was searching different ting, here is that , kindly help with "How to grep a log file within a specific time period in Linux and with a specific keyword"
@hackpens2246
@hackpens2246 3 жыл бұрын
That's a nice idea for a video. thanks. In the meantime, you can use grep for dates and times. Try this, which should bring you everything in the Auth log that happened between 8pm and 9 pm on Aug 26th: pi@Node1:/var/log $ cat auth.log | grep "Aug 26 20:" Aug 26 20:00:01 Node1 CRON[14365]: pam_unix(cron:session): session opened for user pi by (uid=0) Aug 26 20:00:03 Node1 CRON[14365]: pam_unix(cron:session): session closed for user pi Aug 26 20:01:01 Node1 CRON[14380]: pam_unix(cron:session): session opened for user pi by (uid=0) Aug 26 20:01:01 Node1 sudo: pi : TTY=unknown ; PWD=/home/pi ; USER=root ; COMMAND=/usr/bin/apt-get update Aug 26 20:01:01 Node1 sudo: pam_unix(s..................................
@VikasGupta-nn7sd
@VikasGupta-nn7sd 3 жыл бұрын
@@hackpens2246 Sure, I'll try and update here
@AbdoTawdy
@AbdoTawdy 6 ай бұрын
For compressed files, zcat zgrep
@MoshNbreakz
@MoshNbreakz 2 жыл бұрын
your awesome thank you Sir
@hackpens2246
@hackpens2246 2 жыл бұрын
So are you. Thank you!
@mahendra.l861
@mahendra.l861 3 ай бұрын
Without changing directory how can we do
@mahendra.l861
@mahendra.l861 3 ай бұрын
I don't want each line content just displaying the what are log files present in all other sub directoties also
@zemoxian
@zemoxian 3 жыл бұрын
An idiom I like to use is to rank occurrences of things. If I were interested if there are repeated items, after I sorted the lines, I’d do a unique count and a numerical sort, like this: … | sort | uniq -c | sort -rn | head So I can see the top 10 repeated lines.
@hackpens2246
@hackpens2246 3 жыл бұрын
Very nice. I like that.
@Anil-vy5vy
@Anil-vy5vy 3 жыл бұрын
How to filter having above 8 character words🤔🤔
@hackpens2246
@hackpens2246 3 жыл бұрын
hi. 'm not sure what you mean. I have just run this command [ cat fail2ban.log | grep "fail2ban.actions" ] and it returned results. 16 characters...
@Anil-vy5vy
@Anil-vy5vy 3 жыл бұрын
Ok and thnks for replay
@Anil-vy5vy
@Anil-vy5vy 3 жыл бұрын
For example if iam want crack WPA password of wifi I nees only 8 character or more not less than 8 character So iam asking you to have to print only 8 characters or more not less than 8
@hackpens2246
@hackpens2246 3 жыл бұрын
@@Anil-vy5vy this is not really useful for cracking Wifi passwords. you need to look at capturing handshakes and then perhaps using aircrack-ng or johntheripper to perform a dictionary attack on the handshake. Alternatively, you could use a utility like Wifite which performs a range of different attacks for you as long as you have all of its dependencies installed.
@Anil-vy5vy
@Anil-vy5vy 2 жыл бұрын
@@hackpens2246 sorry i didnot see your message but grep helps gor shorting words also to give only certain output length example grep -E '(\w{11,})' modifided.txt > greter11.txt below one is best because we can give from certain lenght words output awk 'length >= 8 && length
@amerikraine3401
@amerikraine3401 2 жыл бұрын
I put a custom messge saying it's the FBI'S system that displays on every ssh attempt
@hackpens2246
@hackpens2246 2 жыл бұрын
Good work haha
@ashok-hg8se
@ashok-hg8se 3 жыл бұрын
How to filter logs with root user details and 200 response
@hackpens2246
@hackpens2246 3 жыл бұрын
You can switch users with "su root" if you know the root password I'm not sure I understand what you mean by "200 response"
@ashok-hg8se
@ashok-hg8se 3 жыл бұрын
@@hackpens2246 Thanks for the reply. Even I am not sure with that . How to check which ports are running in a Vm from outside?
@hackpens2246
@hackpens2246 3 жыл бұрын
@@ashok-hg8se I'm sorry, but this is a video that shows you how to filter log files. I can't offer advice about auditing networks on this video's comment section.
@waliabbas
@waliabbas 3 жыл бұрын
thank you
@hackpens2246
@hackpens2246 3 жыл бұрын
You're welcome!
@JJ-rc1ie
@JJ-rc1ie 3 жыл бұрын
*grep "a_string" filename* - there is no need to use cat in any of the two case presented in this video.
@hackpens2246
@hackpens2246 3 жыл бұрын
That's true. However, since I used cat to look at the files and decide what strings I was going to grep for, it was easier to leave that there and repeat the commend.
@JJ-rc1ie
@JJ-rc1ie 3 жыл бұрын
@@hackpens2246 Got it. In such a case I just use *grep '' filename* . Then I take a look at the file and replace *''* with the appropriate grep options and/or a string to search. Performance aside, is *grep ''* equivalent to *cat* ?
@hackpens2246
@hackpens2246 3 жыл бұрын
@@JJ-rc1ie hi. No, cat is short for concatenate... It basically outputs the content of a file. Grep is searching the file for lines containing a certain string or integer or whatever. In this case, I used cat to print the content of the file to the screen so I could look at it and decide what string I was going to filter for, then I used it to pipe the content of the file into the grep command
@JJ-rc1ie
@JJ-rc1ie 3 жыл бұрын
@@hackpens2246 Yes, I know the basics of *cat* and *grep* . But I also noticed that grepping for an empty string, i.e. *grep "" filename* seems to be equivalent to *cat* . Don't you agree? *P.S.* *''* in my earlier comment is not a typo but an empty string.
@hackpens2246
@hackpens2246 3 жыл бұрын
@@JJ-rc1ie it does the same thing. Yes, you're right 😉
@o21211671
@o21211671 3 жыл бұрын
I would suggest not to clear the screen so often. It could be helpful to see the line structure you are working on. Two or the [ Enter ] would do ...
@hackpens2246
@hackpens2246 3 жыл бұрын
I'll bear that in mind. Thank you :)
@farhan24fa
@farhan24fa 3 жыл бұрын
farhan was here
@hackpens2246
@hackpens2246 2 жыл бұрын
I'm glad you were :)
@zaidpatel4465
@zaidpatel4465 3 жыл бұрын
ain't it grep -w instead of grep -v
@hackpens2246
@hackpens2246 3 жыл бұрын
-v works. I'm not sure what you are expecting from grep -w. As far as I can see grep -w does the same thing as grep alone. The grep -v command will show lines that DON'T have the string you specify, whereas grep and grep -w show lines that DO have to string.
@bramkesseler1582
@bramkesseler1582 Жыл бұрын
6:36 someone tried Minecraft lol
@kasthurishravankumarhpc
@kasthurishravankumarhpc Жыл бұрын
Good
@heli0s359
@heli0s359 8 ай бұрын
genius
@bunnybabu1162
@bunnybabu1162 2 жыл бұрын
Cool
@amerikraine3401
@amerikraine3401 2 жыл бұрын
awk '{print $11}'
@hameedazeem
@hameedazeem 2 жыл бұрын
thank you so much for this tutorial it helped me a lot with understanding of cat, grep and sort. Are you able to tell me what this command would do "cat -rf ~/syslog | sort | grep -iaE -A 5 'cpu[1-7].*(7[0-9]|8[0-9]|100)' | tee cpu.txt" specifically the numbers after cpu which seem to me like it's a time stamp
@yosefberger6259
@yosefberger6259 Жыл бұрын
Probably a little late to be useful, but the numbers are regular expressions (enabled by the -E flag), so it means: After "cpu" there needs to be [1-7] one digit that is between 1 and 7 (inclusive). Then .* there can be any combination of any characters, of any length, that means anything, or even nothing. Then after that we need to have one of the following three options 7 followed by any digit, 8 followed by any digit, or the number 100 (so 71, 80, and 100 are all valid but 180, or 7 are not. (700 theoretically wouldn't be, but because we didn't specify what has to come after, grep will allow it since the last 0 will be considered part of whatever comes after our expression) Some things that will match it: cPu1 77 cpu6hellohowa re you100 cpu788 cpu66666666100 Things that won't: cpu0 80 coy1 70 I'm not sure if I was very clear with that description, but regular expressions can sometimes be a mess to explain in words. The -A 5 flag means that for every matching line, grep will also print out the 5 lines after the match, for added context.
@0xpurn
@0xpurn Жыл бұрын
Quick revision: #cat auth.log | grep "invalid" | cut -d " " -f 11 | sort | uniq | wc -l #cat fail2ban.log | grep "Ban" | grep -v "Restore" | cut -d " " -f 16 | sort | uniq -d > ~/uniq_ips.txt
Learning Awk Is Essential For Linux Users
20:02
DistroTube
Рет қаралды 311 М.
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
Linux Crash Course - Understanding Logging
29:10
Learn Linux TV
Рет қаралды 55 М.
Linux Monitoring and Logging | HackerSploit Linux Security
24:56
Akamai Developer
Рет қаралды 32 М.
EVERYONE Needs to Learn a Little Bit of AWK!
16:29
Gary Explains
Рет қаралды 400 М.
Demystifying "find" and "find -exec" ...Lil' Linux Lesson!
8:12
Veronica Explains
Рет қаралды 59 М.
12 GREAT command line programs YOU recommended!
16:25
The Linux Experiment
Рет қаралды 307 М.
Search For Patterns Within Files With Grep
12:42
DistroTube
Рет қаралды 29 М.
Linux Performance Troubleshooting Demos
10:51
grobelDev
Рет қаралды 74 М.
How The 'awk' Command Made Me A 10x Engineer
10:40
RobertElderSoftware
Рет қаралды 180 М.
Is this the best OSINT tool out there?!
17:10
stuffy24
Рет қаралды 374 М.
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН