WEBVTT - This file was automatically generated by VIMEO

0
00:00:10.240 --> 00:00:11.690
Welcome to section six.

1
00:00:12.110 --> 00:00:14.650
In this section you will learn about Lennox host-based security.

2
00:00:15.150 --> 00:00:18.570
You explore how pluggable modules control the authentication flow on a Lennox

3
00:00:18.570 --> 00:00:21.730
host. You will also learn how to create a simple host-based firewall.

4
00:00:22.590 --> 00:00:26.330
We will discuss how you can audit a host for sessions and possible break-ins.

5
00:00:26.750 --> 00:00:29.770
And finally, you'll learn how to harden your S SSH server.

6
00:00:31.490 --> 00:00:32.170
In this video,

7
00:00:32.170 --> 00:00:35.590
you'll learn about plugable authentication modules or what is better known as

8
00:00:35.650 --> 00:00:36.483
pam.

9
00:00:37.400 --> 00:00:40.900
Our plan is to explore PAM and how users are authenticated on Linux hosts.

10
00:00:41.150 --> 00:00:45.290
We'll learn about PAM modules and the file formats they use. Finally,

11
00:00:45.350 --> 00:00:49.130
you will modify Pam s s HD file and execute a command on login.

12
00:00:51.050 --> 00:00:54.070
So Pam uses four different modules to control authentication.

13
00:00:54.760 --> 00:00:59.620
The A module controls user authentication account module validates the user

14
00:00:59.620 --> 00:01:03.080
account. The password module is used for managing passwords,

15
00:01:03.750 --> 00:01:06.890
and the session module is used for managing user sessions.

16
00:01:08.730 --> 00:01:11.230
Pam module is used to gate a success or failure.

17
00:01:12.040 --> 00:01:16.260
The PAM control flags are used to govern what happens with those results.

18
00:01:16.260 --> 00:01:19.780
From the module, there are five control flags. We'll go over here.

19
00:01:20.550 --> 00:01:23.690
The required flag means the module must be successful to continue.

20
00:01:24.070 --> 00:01:25.250
If there is an error,

21
00:01:25.350 --> 00:01:28.370
it is saved all the way to the end till all the modules are run.

22
00:01:29.400 --> 00:01:32.780
The requisite flag is just like required, but will halt the process.

23
00:01:32.880 --> 00:01:37.310
If a failure occurs, the sufficient flag will ignore the result.

24
00:01:37.450 --> 00:01:39.750
But if there are no other failures for a required,

25
00:01:39.940 --> 00:01:41.990
then this is enough to authenticate the user.

26
00:01:43.140 --> 00:01:46.760
The optional flag states that the result of the module is not important and can

27
00:01:46.760 --> 00:01:49.400
be ignored. You should use this flag sparingly.

28
00:01:50.230 --> 00:01:54.360
They include flag adds all the parameters that match a certain criterion and it

29
00:01:54.360 --> 00:01:58.030
pens them as arguments to the module. Okay,

30
00:01:58.210 --> 00:02:03.110
so this is kind of the format o of what a PAM configuration file looks

31
00:02:03.110 --> 00:02:07.470
like. All the PAM files are stored under the Etsy PAM dot D directory.

32
00:02:07.930 --> 00:02:09.630
So for every service that uses pam,

33
00:02:09.630 --> 00:02:11.790
there is a file in this directory named after it.

34
00:02:12.830 --> 00:02:16.840
Each file follow a specific format and is read from top down.

35
00:02:18.040 --> 00:02:21.260
You can see here is on the far left we have the module interface.

36
00:02:21.810 --> 00:02:25.740
This is what you had with off account session password.

37
00:02:26.580 --> 00:02:29.160
You have control flag. This is the required,

38
00:02:29.660 --> 00:02:31.880
the optional the module name,

39
00:02:32.460 --> 00:02:36.840
and these are modules that are on disk that come with Lennox and come with Pam

40
00:02:37.260 --> 00:02:40.160
for you to use. And then any arguments you need to pass to that module,

41
00:02:41.310 --> 00:02:45.750
here's the example we're using here. We have off as the module interface,

42
00:02:45.810 --> 00:02:49.950
the control flag is required and we're using the PAM underscore UNIX dot.

43
00:02:50.170 --> 00:02:53.740
So module, don't worry right now, uh,

44
00:02:53.740 --> 00:02:57.100
this will make way more sense once we look at the PAM file and the terminal.

45
00:02:57.780 --> 00:03:02.060
All right, let's get started. Okay,

46
00:03:02.280 --> 00:03:06.780
so we're gonna go review the S S H D PAM file,

47
00:03:07.240 --> 00:03:11.220
and then we're gonna add a line to it that will basically execute a command

48
00:03:11.220 --> 00:03:16.180
every time a session is set up and that we're logged in, uh, via s ssh. Okay?

49
00:03:16.640 --> 00:03:21.060
So you're gonna need pseudo for this because we're changing a, uh,

50
00:03:21.060 --> 00:03:22.700
file that needs elevated privileges.

51
00:03:22.760 --> 00:03:27.460
So pseudo your editor of choice cam dot d ss

52
00:03:27.720 --> 00:03:32.590
hd. Okay? And so as you can see here, um, just like we looked on,

53
00:03:32.590 --> 00:03:37.160
on the slide that showed the file format, you have the left-hand side,

54
00:03:37.160 --> 00:03:40.600
the module interface, the middle column is your control flag,

55
00:03:40.820 --> 00:03:45.240
and then the far right column is the actual module name you're using.

56
00:03:45.260 --> 00:03:49.360
And as you can tell, most of them the ones that come with, uh,

57
00:03:49.860 --> 00:03:54.520
so those are shared objects that are on your Lennox host and the ones that

58
00:03:54.530 --> 00:03:56.680
don't, they're usually followed because of an include,

59
00:03:56.930 --> 00:04:00.900
which means they're grabbing another file, um,

60
00:04:01.040 --> 00:04:04.980
inside the PAM d directory and pulling that stuff in as well. Um,

61
00:04:04.980 --> 00:04:07.740
this is a way to like dry it up so you're not doing the same,

62
00:04:07.740 --> 00:04:10.220
like you're not for password authentication,

63
00:04:10.600 --> 00:04:12.460
you're not doing it in every single file.

64
00:04:12.480 --> 00:04:14.340
You've already done it in the password off file.

65
00:04:14.360 --> 00:04:18.780
So you could just include that and use that. So here,

66
00:04:18.780 --> 00:04:21.540
if we start at the top, we go through, we can see on line two,

67
00:04:21.760 --> 00:04:25.660
and let's go up to line two. You can see here we,

68
00:04:25.800 --> 00:04:29.940
the first thing we do is the, we use the module interface and we are required,

69
00:04:30.680 --> 00:04:34.700
and we can see that we use the, the PAM module right here.

70
00:04:35.400 --> 00:04:39.010
You can see also, uh, there's a sub stack. We didn't cover that,

71
00:04:39.390 --> 00:04:43.290
but if you wanted to learn more, you can use the man pages here.

72
00:04:43.750 --> 00:04:46.890
And so if you wanted to, and I'll close this really quick,

73
00:04:47.350 --> 00:04:49.010
if you wanted to look at the, uh,

74
00:04:49.560 --> 00:04:52.530
what the PAM supplement dot o module is.

75
00:04:52.830 --> 00:04:57.300
So I'll close out of my editor and then I'll use man PAM

76
00:04:57.300 --> 00:04:58.133
supplement.

77
00:04:58.200 --> 00:05:03.170
So let me clear the screen and we'll use the man do

78
00:05:04.140 --> 00:05:07.890
supplement, and then we'll remove the do so and we'll use the MAN page.

79
00:05:09.430 --> 00:05:13.210
And he tells you right here that this is the PAM module to allow deny login

80
00:05:13.360 --> 00:05:17.570
depending on EE Lennox enforcement state. So I won't go into that now,

81
00:05:17.570 --> 00:05:21.130
but I just want you to know if you see a PAM module that you don't know,

82
00:05:21.310 --> 00:05:23.650
you can use the MAN page to Gobi. So, all right,

83
00:05:23.650 --> 00:05:28.630
let's go back into the PAM dot DSS HD file

84
00:05:28.630 --> 00:05:32.480
again. And as you can see, we go through all the module interfaces,

85
00:05:32.480 --> 00:05:35.560
we go to oth, we go to account password here,

86
00:05:35.900 --> 00:05:37.880
and then we go into all these session checks.

87
00:05:38.640 --> 00:05:42.900
So what we're gonna do for our test here to show you how you can modify

88
00:05:43.530 --> 00:05:45.060
your authentication flow,

89
00:05:46.690 --> 00:05:50.790
we are going to open a new line rate after this online 18.

90
00:05:50.930 --> 00:05:53.830
So this session include post login. Uh,

91
00:05:53.830 --> 00:05:56.670
we're gonna go ahead and put our session command here,

92
00:05:57.140 --> 00:05:59.720
and I'm just gonna paste that in to make it easier.

93
00:06:03.320 --> 00:06:06.740
All right, the format's a little messed up. Let me fix that really quick.

94
00:06:11.700 --> 00:06:14.990
All right, there we go.

95
00:06:15.250 --> 00:06:18.850
Let me shift colon right to save the file.

96
00:06:19.350 --> 00:06:23.170
So what we've done here in line 19 is in our session phase.

97
00:06:23.370 --> 00:06:24.970
Remember this file's read top down.

98
00:06:25.070 --> 00:06:28.850
So after we've passed all the other required, we've made it this far.

99
00:06:28.870 --> 00:06:31.650
And so what we're gonna do here is, uh, we've, we've got the optional here.

100
00:06:31.650 --> 00:06:34.210
And the reason why I put optional, even though I said use sparingly,

101
00:06:34.470 --> 00:06:37.850
is because if anything happens with the script, it could fail.

102
00:06:37.850 --> 00:06:40.130
If I put a required here or requisite,

103
00:06:40.550 --> 00:06:43.650
it would fail your login and you be locked out of your e c two host.

104
00:06:43.750 --> 00:06:47.250
So I just wanted to show you what's possible that you can do different things

105
00:06:47.480 --> 00:06:48.770
with different PAM modules.

106
00:06:49.270 --> 00:06:52.650
And so executing a script obviously is an easy way for us to test this.

107
00:06:53.070 --> 00:06:57.410
So as you can see here, we're using the pam_exec.so module,

108
00:06:57.950 --> 00:07:02.410
and basically it will execute a script or a command, if you will,

109
00:07:02.960 --> 00:07:06.040
upon success. And so here, optional, remember,

110
00:07:06.060 --> 00:07:08.720
it doesn't matter if this part is, uh, success or not,

111
00:07:08.720 --> 00:07:10.920
it'll move on to line 21 once we're done.

112
00:07:11.500 --> 00:07:16.400
So here we're gonna use the user local bin test dot underscore pandora h file.

113
00:07:16.470 --> 00:07:19.840
I've included this in the section six inside the repo.

114
00:07:20.340 --> 00:07:24.560
So let's go ahead and copy that over until, until you use a local bin.

115
00:07:24.560 --> 00:07:27.160
So we can do that. All right, so I am gonna quit.

116
00:07:27.190 --> 00:07:30.200
I've already written this file, so I'm just gonna quit out of it.

117
00:07:31.190 --> 00:07:35.770
And then I'm gonna use pseudo here because we need to copy use a local business.

118
00:07:35.830 --> 00:07:37.170
Uh, you need elevated privileges.

119
00:07:37.710 --> 00:07:41.090
So what we'll do is we'll do the repo,

120
00:07:41.090 --> 00:07:43.450
which is the hands-on lenux for DevOps cloud engineers.

121
00:07:43.980 --> 00:07:48.330
We'll do section six and I'll do test pam.sh

122
00:07:48.990 --> 00:07:51.730
and we'll copy that to user local bin.

123
00:07:54.170 --> 00:07:57.620
Okay, so now what I'll do is I will,

124
00:07:58.530 --> 00:08:03.380
I'll clear the screen here. Okay, so let's go look at this file now.

125
00:08:06.570 --> 00:08:08.940
Okay, so as you can see here, um,

126
00:08:08.940 --> 00:08:11.380
it's a basic bash script and you should remember this,

127
00:08:11.380 --> 00:08:13.860
this should look somewhat familiar from our, our Bash series.

128
00:08:15.300 --> 00:08:18.370
We're basically go ahead and we're just printing out.

129
00:08:18.670 --> 00:08:22.330
So when Pam executes our PAM module,

130
00:08:23.190 --> 00:08:24.370
it provides, um,

131
00:08:24.440 --> 00:08:29.370
some unique and specific environment variables to our script that make

132
00:08:29.370 --> 00:08:32.210
it, uh, that are available to us only upon, uh, execution.

133
00:08:32.210 --> 00:08:34.730
And you can see here we have Pam underscore our host,

134
00:08:34.730 --> 00:08:38.770
which is the real host that you're actually logging in from Pam, our user,

135
00:08:39.150 --> 00:08:42.410
as if, if you're logging in, uh, you're assuming re identity,

136
00:08:42.680 --> 00:08:45.890
this will give you the real user versus the current user.

137
00:08:46.160 --> 00:08:49.690
This will be empty in our list because we're just using the e C two user.

138
00:08:50.270 --> 00:08:53.850
PAM service is what service module Oh, where you're going to, um,

139
00:08:53.850 --> 00:08:55.580
and we'll see what the output looks like.

140
00:08:55.900 --> 00:09:00.680
Pam user here is the actual user that is authenticating with

141
00:09:00.780 --> 00:09:04.600
Pam and then the PAM type. And as you can see, we are

142
00:09:06.190 --> 00:09:10.890
pending to a file inside the temp slash temp directory.

143
00:09:11.310 --> 00:09:14.690
And every time you log in or log out, you should have an entry in there. Okay,

144
00:09:14.910 --> 00:09:18.090
so let me close the file, just do shift colon Q for Vim.

145
00:09:19.560 --> 00:09:23.380
And what I'll do here is I'll pause the video, I'm gonna log out, log back in,

146
00:09:23.640 --> 00:09:26.220
and then we'll go ahead and take a look at the log file.

147
00:09:29.190 --> 00:09:31.130
So I've logged out and logged back in.

148
00:09:31.150 --> 00:09:33.570
So we should have two entries in our log file, like I was stating.

149
00:09:33.910 --> 00:09:38.880
So let's go ahead and open up the PAM underscore

150
00:09:38.910 --> 00:09:41.360
test log. Now for some reason,

151
00:09:41.420 --> 00:09:43.800
if you log back in and this direct file is not there,

152
00:09:44.350 --> 00:09:49.320
make sure you check where that you put the line correctly in your S S H D file

153
00:09:49.660 --> 00:09:52.880
and make sure that it's lined up and everything looks right and you didn't add

154
00:09:52.950 --> 00:09:56.560
it's no typos because it's optional. It just will quietly fail,

155
00:09:56.560 --> 00:09:59.840
but there is a debug on, so if you look in the logs, you should be able to find,

156
00:10:00.060 --> 00:10:03.940
um, any errors. All right, so let's take a look at it. Okay,

157
00:10:03.940 --> 00:10:06.780
so here you can see the echo line that we saw in the script.

158
00:10:07.240 --> 00:10:11.740
As you see here on the R host. I've used the a fake one instead of, but if, uh,

159
00:10:11.740 --> 00:10:16.380
one yours, it'll be your real IP address that you're SSHing in from the,

160
00:10:16.380 --> 00:10:17.260
our user is,

161
00:10:17.440 --> 00:10:20.500
is empty because we're not using any different type of user we're using.

162
00:10:20.500 --> 00:10:24.630
And the only user we're using PAM service is the SS HD service,

163
00:10:24.630 --> 00:10:29.110
which what we expect the TT Y is SSH because we're logging in B SS H.

164
00:10:29.890 --> 00:10:32.390
Um, and you can see what's besides the PAM user,

165
00:10:32.390 --> 00:10:35.830
which we know is our e C two user. You see the pan type, the close session.

166
00:10:35.930 --> 00:10:40.070
So when I logged out, the close session was the PAM type.

167
00:10:40.170 --> 00:10:44.490
And then when I logged back in, we have the open session, okay, let me, uh,

168
00:10:44.910 --> 00:10:48.010
get out of this. And I used the command less to look in that.

169
00:10:48.010 --> 00:10:50.490
You could have used the, the, the CAT command as well.

170
00:10:51.000 --> 00:10:55.410
Less is like a paging app, uh, utility where it'll show, um,

171
00:10:55.550 --> 00:10:58.450
up to one full screen's worth. Of course, there's only two lines,

172
00:10:58.450 --> 00:11:01.320
so we didn't get that. Okay?

173
00:11:01.860 --> 00:11:06.240
So you could see that using this type of approach for PAM and how you can handle

174
00:11:06.240 --> 00:11:09.160
authentications, you could do some unique things. Like for example,

175
00:11:09.180 --> 00:11:12.680
if you have users when they log in, they need to have a, uh,

176
00:11:12.730 --> 00:11:16.240
drive mounted with sensitive information or something along those lines,

177
00:11:16.380 --> 00:11:19.120
or you need them to set up your, their development environment,

178
00:11:19.120 --> 00:11:22.920
like pulling in the latest and greatest of code or something like that. Um,

179
00:11:23.020 --> 00:11:25.720
you could see how you could do simple things like that. Obviously,

180
00:11:25.840 --> 00:11:29.120
I touched one, uh, PAM module. There's tons of them.

181
00:11:29.340 --> 00:11:31.960
You should explore more by the man page as well.

182
00:11:32.260 --> 00:11:35.990
And take a look what's inside the Etsy PAM dot D director. Okay,

183
00:11:36.040 --> 00:11:40.730
let's go do a recap of what we did. Okay, so let's talk about what we did.

184
00:11:40.730 --> 00:11:44.570
In this video, you learn about how Pam provides authentication on a Lennox host.

185
00:11:45.140 --> 00:11:49.160
You also introduced a concepts like module types and control flags that create

186
00:11:49.160 --> 00:11:51.350
an off flow in Pam. Finally,

187
00:11:51.450 --> 00:11:54.750
you modified Pam S S H D to execute a test script.

188
00:11:54.780 --> 00:11:59.180
Once a s SSH session was set up in the next video,

189
00:11:59.480 --> 00:12:03.500
you will create a simple host-based firewall using IP table. See you soon.
