AgendaTrack1: exercises-securing-host.txt

File exercises-securing-host.txt, 22.4 KB (added by admin, 7 years ago)
Line 
1% Host Security Exercise
2%
3% Security Topics
4
5# Introduction
6
7These exercices demonstrate some of the tools used for tasks that every
8system administrator should perform when installing or hardening a
9system.
10
11# Goals
12
13* Learn to figure out which services are running
14* Disable unnecessary services
15* Scan ports to see how the machine is seen by others
16* Configure automatic updates
17* Use file integrity and rootkit checking tools to detect possible
18  compromises
19* Install a tool to keep a log of executed commands
20
21# Notes
22
23* Commands preceded with "$" imply that you should execute the command as
24  a general user - not as root.
25* Commands preceded with "#" imply that you should be working as root.
26* Commands with more specific command lines (e.g. "RTR-GW>" or "mysql>")
27  imply that you are executing commands on remote equipment, or within
28  another program.
29
30# Let's install a few tools first
31
32~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33# apt-get install lsof
34~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35
36# What's running?
37
38First you can see what is running on your machine by typing something like:
39
40~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41$ ps auxwww
42~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43
44You will see lots and lots of stuff go by. So, let's look at this a bit more
45closely:
46
47~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48$ ps auxwww | less
49~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50
51(press [spacebar] to go one page down, and [b] to go one page up)
52
53Now, browsing through all this we can see there are a bunch of initial system
54processes that start to support our hardware (items in "[ ]") as well as lots
55of processes associated with the Gnome Display Manager (gdm and gnome). Let's
56filter all of this out and see what we are left with:
57
58~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59$ ps auxwww | grep -v "\[" | grep -v gdm | grep -v gnome
60~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61
62(Hint: You might want to copy and paste this in to a command window)
63
64What's left?
65
66Have a look and see if you can identify everything in the remaining list.
67Your list of processes should look something like:
68
69~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
71root         1  0.0  0.0   2644  1552 ?        Ss   Jun29   0:01 /sbin/init
72root       429  0.0  0.0   2152   756 ?        S    Jun29   0:00 upstart-udev-bridge --daemon
73root       431  0.0  0.0   2624  1020 ?        S<s  Jun29   0:00 udevd --daemon
74root       613  0.0  0.0   2620   984 ?        S<   Jun29   0:00 udevd --daemon
75root       614  0.0  0.0   2620   984 ?        S<   Jun29   0:00 udevd --daemon
76root       780  0.0  0.0   1852   548 ?        Ss   Jun29   0:00 dd bs=1 if=/proc/kmsg of=/var/run/rsyslog/kmsg
77syslog     782  0.0  0.0  33832  1748 ?        Sl   Jun29   0:00 rsyslogd -c4
78104        803  0.0  0.0   2860  1104 ?        Ss   Jun29   0:00 dbus-daemon --system --fork
79105        806  0.0  0.1   5352  3280 ?        Ss   Jun29   0:00 hald --daemon=yes
80root       824  0.0  0.1  19412  2932 ?        Ssl  Jun29   0:00 /usr/sbin/console-kit-daemon
81root       887  0.0  0.0   3344  1196 ?        S    Jun29   0:00 hald-runner
82root       975  0.0  0.0   1704   552 tty4     Ss+  Jun29   0:00 /sbin/getty -8 38400 tty4
83root       991  0.0  0.0   1704   548 tty5     Ss+  Jun29   0:00 /sbin/getty -8 38400 tty5
84root       995  0.0  0.0   3420  1140 ?        S    Jun29   0:00 hald-addon-input: Listening on /dev/input/event0 /dev/input/event1 /dev/input/event4 /dev/input/event5
85root       996  0.0  0.0   3420  1152 ?        S    Jun29   0:00 hald-addon-storage: polling /dev/sr0 (every 2 sec)
86root      1001  0.0  0.0   1704   552 tty2     Ss+  Jun29   0:00 /sbin/getty -8 38400 tty2
87root      1002  0.0  0.0   1704   556 tty3     Ss+  Jun29   0:00 /sbin/getty -8 38400 tty3
88root      1005  0.0  0.0   5364  1100 ?        Ss   Jun29   0:00 /usr/sbin/sshd
89root      1006  0.0  0.0   1704   548 tty6     Ss+  Jun29   0:00 /sbin/getty -8 38400 tty6
90105       1017  0.0  0.0   3264  1120 ?        S    Jun29   0:00 hald-addon-acpi: listening on acpi kernel interface /proc/acpi/event
91root      1036  0.0  0.0   2092   880 ?        Ss   Jun29   0:00 cron
92daemon    1037  0.0  0.0   1964   416 ?        Ss   Jun29   0:00 atd
93root      1063  0.0  0.1   6692  2332 ?        Ss   Jun29   0:00 /usr/sbin/cupsd -C /etc/cups/cupsd.conf
94root      1170  0.0  0.2   6704  4816 ?        Ss   Jun29   0:00 /usr/sbin/munin-node
95root      1245  0.0  0.0   1704   552 tty1     Ss+  Jun29   0:00 /sbin/getty -8 38400 tty1
96root      1278  0.0  0.1   5168  2580 ?        S    Jun29   0:00 /usr/lib/devicekit-power/devkit-power-daemon
97root     10340  0.0  0.1   8588  2972 ?        Ss   00:07   0:00 sshd: root@pts/0
98root     10400  0.0  0.0   4352  1872 pts/0    Ss   00:07   0:00 -bash
99root     10556  0.0  0.0   2644  1024 pts/0    R+   00:13   0:00 ps auxwww
100~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101
102You can type "man" or search in Google to figure out what all this is.
103For instance:
104
105~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106$ man udevd
107$ man hald
108$ man getty
109$ man cupsd
110$ man atd
111$ man cron
112$ man sshd
113~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114
115Etc, etc.
116
117Once you feel pretty comfortable with what's running on your system you might
118consider if you need each item. If there is something running that is
119unnecessary, then you should consider uninstalling the software:
120
121~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
122# apt-get remove <pkg_name>
123~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
124
125or stopping the associated service:
126
127~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
128# update-rc.d <pkg_service> remove
129~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130
131The next step is to see if any of these services are listening to the network
132for connections:
133
134~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135# lsof -i
136~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
137
138You'll see something like:
139
140~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
141COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
142sshd       1005 root    3u  IPv4   5150      0t0  TCP *:ssh (LISTEN)
143sshd       1005 root    4u  IPv6   5152      0t0  TCP *:ssh (LISTEN)
144cupsd      1063 root    5u  IPv6   5318      0t0  TCP localhost:ipp (LISTEN)
145cupsd      1063 root    6u  IPv4   5319      0t0  TCP localhost:ipp (LISTEN)
146sshd      10340 root    3r  IPv4  18747      0t0  TCP pc4.pacnog.bluesky.as:\
147ssh->noc.pacnog.bluesky.as:34634 (ESTABLISHED)
148~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
149
150Again, Google and man to figure out what is going on:
151
152~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
153$ man sshd
154$ man cupsd
155~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
156
157What's cupsd? is this necessary on every server?
158
159Notice that sshd is listening to all incoming connection requests (the "*").
160This is a typical, potential security hole.
161
162In our case, we will leave ssh up, but we are aware they are running and need
163to be patched for security updates as they come out.
164
165For example, it is a good idea to lock down sshd a bit by not allowing the
166root user to log in with a passwords.
167
168As you are not printing, let's turn off the cups printing service. Do you
169remember how to do this?
170
171~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
172# ls /etc/init.d       <-- to find the service script name
173# service cups stop
174# lsof -i
175~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
176
177Now we only see:
178
179~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
180COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
181sshd       1005 root    3u  IPv4   5150      0t0  TCP *:ssh (LISTEN)
182sshd       1005 root    4u  IPv6   5152      0t0  TCP *:ssh (LISTEN)
183sshd      10340 root    3r  IPv4  18747      0t0  TCP pc4.pacnog.bluesky.as:\
184ssh->noc.pacnog.bluesky.as:34634 (ESTABLISHED)
185~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
186
187To prevent this service to start when the machine is rebooted, type:
188
189~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190# update-rc.d cups remove
191~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
192
193# Scan your machine remotely using nmap
194
195It's usually a good idea to see how your machine looks to other users.
196
197Log in to a PC different than yours. For example:
198
199~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
200$ ssh sysadm@pcX
201~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
202
203Make sure that nmap is installed by doing:
204
205~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
206# apt-get install -y nmap
207~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
208
209Now let's scan your machine using the nmap command:
210
211~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
212# nmap -sV pcX          [Where "pcX" is _your_ pc]
213~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
214
215You should see something like:
216
217~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
218Starting Nmap 5.00 ( http://nmap.org ) at 2010-06-30 09:59 SST
219Interesting ports on pc2.pacnog.bluesky.as (67.218.55.102):
220Not shown: 998 closed ports
221PORT   STATE SERVICE VERSION
22222/tcp open  ssh     OpenSSH 5.1p1 Debian 6ubuntu2 (protocol 2.0)
22325/tcp open  smtp    Postfix smtpd
224MAC Address: 00:0F:1F:E6:62:94 (WW Pcba Test)
225Service Info: Host:  pc2.pacnog.bluesky.as; OS: Linux
226
227Service detection performed. Please report any incorrect results at \
228http://nmap.org/submit/ .
229Nmap done: 1 IP address (1 host up) scanned in 1.76 seconds
230~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
231
232This looks reasonable. The machine is exposing smtp and ssh to the world as
233well as the type of OS that it is running.
234
235Now let's scan a bit more aggressively:
236
237~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
238# nmap -A -T4 pcX
239~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
240
241Take a look at the information presented. This will take some time, but it
242will contain more detail.
243
244Now, remember to log out of your classmate's PC!
245
246~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
247$ exit
248~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
249
250You can use nmap to scan entire networks and find all the machines and
251services that are running. This is what network attack scripts do - but, they
252usually scan for a specific port and service, then they launch an attack when
253they find a service that they think they can break.
254
255Be careful with nmap! If you scan aggressively or against an entire network
256you will likely set off detection alarms and you could get in trouble.
257Let people know before you scan if you are not in charge of the remote
258machines.
259
260Now read about nmap to understand what -sV, -A, -T4 and -F are doing:
261
262~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
263$ man nmap
264~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
265
266# Install a filesystem integrity checker
267
268## fcheck
269
270Let's install fcheck. This is an intrusion detection tool that is very simple
271to set up and is preconfigured to do most of what you want:
272
273~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
274# apt-get install fcheck
275~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
276
277Once this is done you can look around to see how fcheck is configured. By
278default Ubuntu installs and configures fcheck in a reasonable manner and you
279probably don't need to do anything else.
280
281~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
282$ man fcheck
283~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
284
285Configuration of check is in /etc/fcheck/fcheck.cfg. Let's have a look:
286
287~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
288# EDITOR /etc/fcheck/fcheck.cfg
289~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
290
291Read through the file to see what directories fcheck is checking, which
292directories are excluded, etc. The check process is run once every two hours
293on the 1/2 hour. You can view this by looking at:
294
295~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
296$ less /etc/cron.d/fcheck
297~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
298
299The text that reads:
300
301~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30230 */2 * * *
303~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
304
305is telling our system cron process to run the long check command listed in
306the file once every 2 hours on the 1/2 hour.
307
308Now force fcheck to run for the first time and create a database:
309
310~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
311# fcheck -ac
312~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
313
314Look at the baseline file that fcheck has created:
315
316~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
317# less /var/lib/fcheck/fcheck.dbf
318~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
319
320Now let's make a change to a file in one of the directories that fcheck is
321checking.
322
323~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
324# editor /etc/hosts
325~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
326
327Add a blank line at the end of the file. Save the file.
328
329Now do another forced run of fcheck:
330
331~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
332# fcheck -a
333~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
334
335You'll see lots of stuff go by on the screen.
336
337you see something like:
338
339~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
340PROGRESS: validating integrity of /etc/
341STATUS:
342        WARNING: [cv-macbook] /etc/hosts
343        [Sizes: 257 - 258, Times: Jul 22 21:36 2010 - Mar 14 16:10 2012]
344~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
345
346This tells you that the file /etc/hosts has changed. The cron job installed
347by Ubuntu will e-mail these kinds of reports to you.
348
349## incrond
350
351Inotify in the kernel can provide real-time notification of filesystem
352changes. Install the incron package and configure incrond to monitor
353important filesystems.
354
355~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
356# apt-get install incron
357# tail /var/log/syslog
358# cd /etc/incron.d
359# EDITOR globals       
360
361add the following line (one line) to the globals file:
362
363/etc IN_MODIFY,IN_CLOSE_WRITE,IN_CREATE,IN_DELETE /usr/bin/logger -p
364news.warn "$% $@/$#"
365~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
366
367For a description of the syntax of incron table files, see:
368
369~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
370$ man 5 incrontab
371~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
372
373That's it.  The changes you make to incron are updated automatically.
374Because incron can recognize changes, it even recognizes when you change
375the configuration for incron, and it updates.
376
377Now add a file to the /etc directory:
378
379~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
380# touch /etc/dog
381~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
382
383Take a look at /var/log/syslog.  What does it say???
384
385~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
386# tail /var/log/syslog
387~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
388
389From now on, any changes you make in the /etc directory will
390generate syslog messages.
391
392# Turn on automatic installation of security updates
393
394There is a meta package called unattended-upgrades to do this. To install:
395
396~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
397# apt-get install unattended-upgrades
398~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
399
400That's it. Any time a security update is placed in the Ubuntu repositories it
401will be automatically installed on your system. You will probably want to look
402at how unattended-upgrades is configured.
403
404~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
405# cd /etc/apt/apt.conf.d
406~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
407
408This package is configured in the file 50unattended-upgrades. Let's have a
409look and we will make a change to the configuration:
410
411~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
412# vi 50unattended-upgrades
413~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
414
415Note at the very top of the file. If you were to change this:
416
417~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
418// Automatically upgrade packages from these (origin, archive) pairs
419Unattended-Upgrade::Allowed-Origins {
420        "Ubuntu lucid-security";
421//      "Ubuntu lucid-updates";
422};
423~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
424
425To look like:
426
427~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
428// Automatically upgrade packages from these (origin, archive) pairs
429Unattended-Upgrade::Allowed-Origins {
430        "Ubuntu lucid-security";
431        "Ubuntu lucid-updates";
432};
433~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
434
435then all software package updates would be installed as well. You may, or may
436not, want to do this. This is generally safer for user desktops than for
437servers.
438
439Let's change this line:
440
441~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
442//Unattended-Upgrade::Mail "root@localhost";
443~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
444
445To be:
446
447~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
448Unattended-Upgrade::Mail "root@localhost";
449~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
450
451That way your root account will get an email when an update is installed.
452
453Note that you can even have your machine automatically reboot if required
454after an update.
455
456Save the file and exit.
457
458That's it. If a security update is applied you will be notified.
459
460# Run a rootkit checker
461
462There is a nice tool called "chkrootkit" - This is used to see if a machine
463has been compromised with known software kits that install once security has
464been breached. You can read about this software here:
465<http://www.chkrootkit.org/>
466
467To install, do this:
468
469~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
470# apt-get install chkrootkit
471~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
472
473To use it, do:
474
475~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
476# chkrootkit
477~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
478
479You should not see anything found or infected (hopefully!). However, it's
480possible for the tool to give you some false positives. You can go back to
481the http://www.chkrootkit.org/ web site for more information in the README and
482FAQ pages and you should use Google. If you don't see other people reporting
483false positivies like yours, then you probably need to format your hard drive,
484reinstall and restore data from backups.
485
486Let's do something to make chkrootkit give you a warning:
487
488Place your ethernet interfaces in to promiscuous mode (i.e. it listens for
489_all_ packets on the network, not just packets coming to your machine).
490
491~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
492# ifconfig lo promisc
493~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
494
495Now let's re-run chkrootkit:
496
497~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
498# chkrootkit
499~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
500
501and you will see that it detects that the loopback network interface (lo) is
502now in promiscuous mode. To just see this vs. all the other messages do:
503
504~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
505# chkrootkit | grep PROMISC
506~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
507
508If your PC is running a DHCP client daemon, you may also see that eth0 is in
509promiscuous mode:
510
511~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
512eth0: PROMISC PACKET SNIFFER(/sbin/dhclient3[564])
513~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
514
515Turn off promiscuous mode for lo:
516
517~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
518# ifconfig lo -promisc
519~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
520
521# Enable System Accounting
522
523System accounting gives us logs of all the commands that
524have run and terminated on the system.  Let's see if we
525have the acct package:
526
527~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
528$ which sa
529~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
530
531Did "which" find the command?  If not install the package:
532
533~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
534# apt-get install acct
535
536$ which sa
537~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
538
539Let's run a command and see if acct records it.
540
541~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
542$ whoami
543
544# sa -u
545~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
546
547Did "sa" show a record for the command?
548
549Let's try the "lastcomm" command as well:
550
551~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
552$ lastcomm sysadm
553~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
554       
555--End