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