18.12.2012 Views

O'Reilly - Practical UNIX & Internet Sec... 7015KB

O'Reilly - Practical UNIX & Internet Sec... 7015KB

O'Reilly - Practical UNIX & Internet Sec... 7015KB

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

[Chapter 10] Auditing and Logging<br />

Login name: tim In real life: Tim Hack<br />

Directory: /Users/tim Shell: /bin/csh<br />

Last login Tue Jul 12 07:49:59 on tty01<br />

No unread mail<br />

No Plan.<br />

%<br />

Some versions of System V <strong>UNIX</strong> display both the last successful login and the last unsuccessful login when a user<br />

logs into the system:<br />

login: tim<br />

password: books2sell<br />

Last successful login for tim : Tue Jul 12 07:49:59 on tty01<br />

Last unsuccessful login for tim : Tue Jul 06 09:22:10 on tty01<br />

Teach your users to check the last login time each time they log in. If the displayed time doesn't correspond to the<br />

last time they used the system, somebody else might have been using their account. If this happens, the user should<br />

immediately change the account's password and notify the system administrator.<br />

Unfortunately, the design of the lastlog mechanism is such that the previous contents of the file are overwritten at<br />

each login. As a result, if a user is inattentive for even a moment, or if the login message clears the screen, the user<br />

may not notice a suspicious time. Furthermore, even if a suspicious time is noted, it is no longer available for the<br />

system administrator to examine.<br />

One way to compensate for this design flaw is to have a cron-spawned task periodically make an on-disk copy of the<br />

file that can be examined at a later time. For instance, you could have a shell file run every six hours to do the<br />

following:<br />

mv /var/adm/lastlog.3 /var/adm/lastlog.4<br />

mv /var/adm/lastlog.2 /var/adm/lastlog.3<br />

mv /var/adm/lastlog.1 /var/adm/lastlog.2<br />

cp /var/adm/lastlog /var/adm/lastlog.1<br />

This will preserve the contents of the file in six-hour periods. If backups are done every day, then they will also be<br />

preserved to the backups for examination later.<br />

If you have saved copies of the lastlog file, you will need a way to read the contents. Unfortunately, there is no<br />

utility under standard versions of <strong>UNIX</strong> that allows you to read one of these files and print all the information.<br />

Therefore, you need to write your own. The following Perl script will work on SunOS systems, and you can modify<br />

it to work on others.[3]<br />

[3] The layout of the lastlog file is usually documented in an include file such as /usr/include/lastlog.h<br />

Example 10.1: Script that Reads lastlog File.<br />

#!/usr/local/bin/perl<br />

$fname = (shift || "/var/adm/lastlog");<br />

$halfyear = 60*60*24*365.2425/2; # pedantry abounds<br />

setpwent;<br />

while (($name, $junk, $uid) = getpwent) {<br />

$names{$uid} = $name;<br />

}<br />

endpwent;<br />

open(LASTL, $fname);<br />

file:///C|/Oreilly Unix etc/<strong>O'Reilly</strong> Reference Library/networking/puis/ch10_01.htm (4 of 9) [2002-04-12 10:44:56]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!