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