LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 05-21-2005, 12:19 AM   #1
icefairy83
LQ Newbie
 
Registered: May 2005
Posts: 1

Rep: Reputation: 0
scrpit for finding out new entries in /etc/passwd


can some one please help me....I need to write a script which finds out if there is a new entry in /etc/passwd i.e if a new user has been created.
This script will run everyday through Cron.

Last edited by icefairy83; 05-21-2005 at 01:30 AM.
 
Old 05-21-2005, 12:41 AM   #2
freakyg
Member
 
Registered: Apr 2005
Distribution: LFS 5.0 and 6.1
Posts: 705

Rep: Reputation: 30
Code:
#!/usr/bin/perl

$file = '/etc/passwd';		
open(INFO, $file);		
@lines = <INFO>;		
close(INFO);			
print @lines;
this opens the file, puts the contents into an array and prints to screen...........you'll have to do your
own cron job............
 
Old 05-21-2005, 11:18 PM   #3
sigsegv
Senior Member
 
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 47

Why go to all that trouble? Wouldn't cat /etc/passwd be a tad more efficient?

Of course, neither of the above help anything if you have a couple thousand users ... Probably something more along the lines of ls -l /etc/passwd is more helpful. When you get that email from cron every day, you just have to know "Hey! I didn't add any users yesterday!!!"

Easy right?

Of course, since it's pretty trivial to alter the modification time on a file, you could get all fancy and take an MD5 of the passwd file and store it someplace and then have a shell script that compares your stored MD5 with the MD5 of the passwd file.

But really, assuming it's all done on the same host, it's all fairly pointless. If a user has the swing to add a user account, he can manage to thwart your checks too
 
Old 05-22-2005, 12:44 AM   #4
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
Another option is to back up /etc/passwd somewhere secure every day (like root's home directory) and the next time the script runs just do a diff between yesterday's /etc/passwd and today's. If you have many many users, you can see exactly which were added in the last 24 hours.
 
Old 05-22-2005, 03:38 AM   #5
sigsegv
Senior Member
 
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 47
Again ... If the invading user can modify /etc/passwd, he can modify your copy in /root as well (and the job that does the checking for that matter ...).

I'd probably deal with it by having the cron job mail me an MD5 and the file itself, tehn having my procmailrc call another script that takes that mail apart and compares it to the previous day's. It would silently bitbucket the mail if there were no changes and if it did find changes it would mail a summary of them to me.

That way, unless the intruder got both my machines, I'd still be able to catch 'em.
 
Old 05-22-2005, 03:52 AM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Another tool you could use is the "comm" program. It is part of the core-utils package.
comm -3 /etc/passwd /root/oldpasswd
 
Old 05-22-2005, 04:18 PM   #7
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
If you really want to be thorough about it, send /etc/passwd to a convenient printer located in a physically secure location as part of the script. That way, so long as the physical access is not breached, you'll have a record of accounts. If you have thousands of users, it may be more convenient to store it to WORM media (e.g. a tape or CD-R) and then eject the media.

It all depends on how paranoid you want to be, which will depend on your own internal risk management metrics (and if you work at a large company/organization) there should be a defined risk management policy.
 
Old 05-25-2005, 07:42 PM   #8
stakhous
Member
 
Registered: May 2003
Location: PA
Posts: 82

Rep: Reputation: 15
Program a script to save copies of the passwd file periodically. Another script to display the output of "diff" between the old and the new passwd file.
 
Old 05-27-2005, 11:35 AM   #9
jillande
Member
 
Registered: Oct 2003
Location: fargoh eh.
Distribution: slackware
Posts: 94

Rep: Reputation: 15
i'm monitoring the status of a few system files not for security purposes (several systems are to be synced together so if one system changes the rest need to too), but the end need is the same--i have to determine if a file has been modified. my script also runs once per second so persistent status is not a major problem.

in any event, i make the assumption that if the date modified time has changed, the file has changed and then the rest of the script runs when the file date modified has run. you can check the last modified time with stat, i.e.
stat -c=%Y /etc/passwd
and when that value increases (the date gets newer) the file has been updated.

ok, so the "last modified time" can be changed so this would be completely inappropriate if the goal is to determine whether or not a file has been compromised.


if you just want to determine if there are new users added or old ones removed (and the actual usernames themselves are not viewed as confidential/security-important), you could also read /etc/passwd, munge the data to contain only usernames (chomp lines, split at ":", write to a new file) and then diff two different day's user list and see who was removed and who was added.



really the purpose of why you want to monitor this file is relevant.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unix scrpit simplification kirmet Programming 2 10-05-2005 05:53 AM
Best way to copy passwd entries rtcary Linux - Newbie 3 07-17-2005 01:42 PM
hcl entries berrance LQ Suggestions & Feedback 3 03-03-2005 03:51 AM
entries in securitylog pippet Linux - Security 1 08-05-2004 05:51 AM
Default entries in /etc/passwd - Slackware J.W. Linux - Security 1 09-23-2003 04:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 10:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration