Agenda: exercises-securing-host.txt

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