Hello and welcome back
to this video.
So in this lesson, we are going to learn about how
to use search and do pattern matching.
Alright, so let's quickly begin.
So as you can see on the terminal I'm into
the directory, which is UFO net and you
can see I have listed to see what is
inside it. Now. Let me quickly go
into the directory, which is Rohit and you can see there
is a file called as hack dot txt.
Now. What I'm going to do currently is
I'm going to add some data or
content into this file. So I'm going to add random
things just to show you
how to do pattern matching or how to
extract a specific pattern out of
this file. So, let me just add some
more random data.
And let's say hack hacking hacks hacker apple.com microsoft.com,
etc, etc.
Once I have completed adding random
words into this I'm going to do a pattern match and
identify for a specific keyword. Now.
This is a very very handy and helpful
in terms of identifying a specific
keyword into files.
For that I'm going to use the command which is cat hack.txt through
which we are basically reading the
file and then I'm going to use grep.
Hack Now by doing this you can
see the output over here.
It has grabbed those words which
contains the pattern hack as you
can see hacking D hack hacking hacks
hacker hacks hacks. I
hope you guys understood how to use grab to
identify a pattern into a
file. Alright.
Now let's move ahead grip is also
useful to identify patterns not
only into files but into directories as
well. So let's quickly see that how
you can search recursively for a
pattern in a directory using the command grip.
For that you can simply type grip hyphen R
and the pattern so let's say hack and
the directory name. So let's say the directory is
root UFO net and hit enter.
And you can see it has matched the
pattern hack into the whole directory in all
the files that exist as you can
see root here for net build file. So these
are all the configuration files which contains
the keyword hack as you can see. It is
matching into this Javascript file, etc. Etc.
Now this is again very helpful in case you want to identify a
specific keyword related pattern into
a directory where there are multiple files and
you can just identify that sensitive
content for instance now, let
us move ahead.
Now we are going to find files and directories by
their names for that. We are going to use the
command which is locate.
So there's a file called a super hack which is created into
the user share metasprite framework
and I'm going to locate that file as
you can see the command is very simple locate and
the file name that you want or the directory name
that you want and it is able to successfully locate
it. This is again pretty simple, but
very very handy.
Let's move ahead. Now. Now we are going
to find a files in the directory that
starts with a prefix. So
this time let's identify or find
a file into the
root directory into the UFO
net which is inside the root directory and let's
specify the name. So the name of the file that we
created was hack dot txt. So
we do not get anything on hack because there is no such
file but when we change the
name to hack.txt we're able
to identify that yes hack.txt exist in
this path. So now remember whenever
you're playing ctfs at that time, you always
try to find the flags. So this can be helpful this
command find will automatically find
the flag files into any of the directory which
will make your work much more easier. These are
small hacks that are very very helpful.
And these tricks make your work much more
faster.
Let's move ahead. So now let's say you want to
find files which are larger than 100 MB for
instance into a specific directory. So
for that also, you can use the command find the directory
name where you want to identify the file,
which is greater than the size hundred MB.
So you can specify find slash root
hyphen size plus 100 MB
and these are the files which are greater than 100 MB
as you can see. These are some of the word list, which
I have created to brute force on various websites.
So I hope you guys understood how you
can do pattern matching as well as search. Thank
you.