- All right, well this looks like a long one.
Let's read it, so that we understand,
and we can make a plan.
So, we need to create a file that contains list of all files
on your system that have the SUID permission set.
And, that is SUID files based on txt.
Okay, that sounds doable.
Find minus perm, slash 4,000.
Then we add the file /tmp/runme,
and ensure that it has SUID as well as execute.
That's pretty straightforward as well.
Then we need to run the appropriate command
to create a file that contains the list of all files
on your system that have SUID set.
And we need to call it /root/suid date.
So we need date, the date command.
Some command substitution here.
And then the highlight, is to generate a list
of differences between these two files.
Sounds like diff.
And write differences found to /tmp/suid-differences.
There's date.
Okay, and generate a scheduled job
that will automatically do this once a day.
Well, sounds like a lot.
But really what we want to do, we want to do some find,
we want to do some diff, and we want to do some cron.
Sounds doable.
Let's go there step by step.
The first part, is where we create a file
that contains a list of all files that have set user ID.
Find slash.
Minus perm.
Slash 4,000.
That's what we need.
And there we go.
These are all the files that have set user ID set.
Okay, and we need to redirect the output to
slash root,
slash suid,
files dot txt.
So this is kind of the baseline,
the starting point that we want to compare.
Next, I need to create a file /tmp/runme.
And we need to ensure that it has set user ID,
as well as execute.
So,
that means chmod,
u plus s,
on /tmp/runme.
I'm going for the relative mode, by the way.
Because the exercise,
is only talking about set user ID and execute,
and not about the other permissions.
So, I don't want to change the other permissions.
And that's why I'm using the relative mode
and not the absolute mode.
So, chmod plus x on /tmp/runme.
And then, ls minus l on /tmp/runme is showing,
that it has the little s on the position of the first x.
It's marked in red, so this is all good.
Next, we need to run the appropriate command
to create a file that contains a list of all files
that have set user ID set.
That's the same command as what we've done before.
But, we need to have the date in there.
And this date should automatically be set,
based on the date of the day.
I need to try this before.
I think it is date plus percent,
d,
dash percent m,
dash percent uppercase Y.
Yes, that is the one that we need.
I just wanted to make sure.
So, we create this file, which is date extension.
And we get a date extension, by using command substitution.
So, dollar parenthesis,
date plus percent d,
dash percent m,
dash percent uppercase Y.
There we go.
And let's run it,
so that we can check that it worked out all right.
Now, we need to generate a list of difference
between the two files,
and write the differences found to,
suid differences dot txt.
So, I'm using diff,
on suid-files,
dot txt.
And suid-files,
dash,
date dot txt.
First I want to know what is going on.
And there we can see, yeah /tmp/runme
was added in the second file.
That's exactly what we needed to do.
And we need to write the output to,
slash tmp,
slash suid,
differences,
dash,
with command substitution,
date,
plus percent d,
dash percent m,
dash percent Y,
dot txt.
Just an ls minus l on /tmp/suid,
to figure out that it worked.
Well, the tab completion is showing a long list,
but the first one is what we needed.
Now, we need to create a scheduled job
that will automatically do this once a day.
So, how are we going to do that?
Well, we put it in cron.
Right now, you can make a choice
between cron and a systemd timer.
Crontab minus e, is definitely easier.
And that's my big advice for the exam.
Make it easy.
So, this is going to do it.
Diff suid files, oh.
This is almost going to do it.
We do need to build in the flexibility,
that it is taking the file of the day.
So, we also need to command substitution right here.
So, date plus percent d, dash percent m,
dash percent Y.
Is that looking okay?
That's looking okay.
Now, this is a cron job.
So, this being a cron job, we need the cron specification.
I need to run it once a day.
Let's run it at,
a minute 0, hour 1,
on every day.
And there we go, it's installing the new crontab.
And, that's all.