|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Maintain health of passwd file
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hello guys I am about to write a script that is based on "The Linux Administration Handbook" The exercise is as follows: Write a shell script to help monitor the health of the /etc/passwd file. Find entries that have UID0 Find entries that have no password (needs /etc/shadow) Find any sets of entries that have duplicate UID's Find entries that have duplicate login names find entries that have no expiration date (needs /etc/shadow) I finished point 1,3, and 4. What I am not able to figure out is how to access the shadow file without being root. I thought maybe by exec su | sh, and then access the file. But the user shouldn't have to interact with the script. Here is what I have so far Any ideas, hints, advice etc. is greatly appreciated. Thank you. -Daniel 2. Relevant commands, code, scripts, algorithms: reg expr., flow control, branch statements, iteration through file, mechanism to provide shadow file check without user interference. 3. The attempts at a solution (include all code and scripts): Code:
#!/usr/bin/sh
#
# SCRIPT: lab5
# AUTHOR:
# DATE: 8/15/2012
# REV: 1.0A
# PLATFORM: Linux
# PURPOSE: Maintain Health of the /etc/passwd file by checking for
# duplicate UID's, root ID, duplicate login names,
# expiration date, entries with no password.
#
#
# REV LIST:
# DATE: 8/16/2012
# BY:
# MDIFICATION: add awk for duplicate UID and login name check.
#
#
#
###############################################################################
##################### DEFINE FILES AND VARIABLES HERE #########################
###############################################################################
# NO VARIABLES
###############################################################################
######################### DEFINE FUNCTIONS HERE ###############################
###############################################################################
# NO FUNCTIONS
###############################################################################
######################### BEGINNING OF MAIN ###################################
###############################################################################
# This line checks for the root ID. It notifies the user if the root ID
# exists or not.
echo "Check for root uid..."
awk -F: '$1 = ~/root/ {print "Found Root ID"} ' /etc/passwd
# Check for duplicate UID by reading the records into an awk array
# and compare the predecessor with the successor. If the comparison
# result is greater as 1 print the duplicate value.
echo "Check for duplicate UID's..."
awk -F: 'uname[$3]++ && uname[$3]>1 {print "duplicate user:", $1} ' /etc/passwd
echo "Duplicate UID check done"
# Check for duplicate UID by reading the records into an awk array
# and compare the predecessor with the successor. If the comparison
# result is greater as 1 print the duplicate value.
echo "Check for duplicate user names..."
awk -F: 'uid[$3]++ && uid[$3]>1 {print "duplicate uid:", $3}' /etc/passwd
echo "Duplicate user name check done."
echo "Check for passwords..."
# I am not sure about that one !
#`exec su | sh | awk -F: '$2 ~/$\d$/ {print "User $1 has password}' /etc/shadow | exit`
exit 0
# End of Script4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course): University of Chicago, Chicago (Illinois), Prof. Anthony Packart, CMSC 23000 Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it). |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
My 2 cents:
-About root: its not because your login name is root that you are... - Finding entries without password, can be more tricky than you imagine: Some UID e.g. bin, lp have no... what are you to look at? all or true users without ? Quote:
Is there a reason why you doing all using only awk? e.g. looking for root accounts: grep :0: /etc/passwd or grep :0:0: /etc/passwd ... |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Quote:
Quote:
Quote:
Quote:
|
|
#4
|
|||
|
|||
|
Quote:
Code:
root:*:0:0:System Administrator:/var/root:/bin/sh with root as the user name, but what vbe was saying is that an entry like: Code:
super:*:0:0:System Administrator:/var/super:/bin/sh has exactly the same privileges as root in the entry you're looking for, but your script won't notice it. Some accounts are set up so that they can never be used to login. They may have an entry in the password field in the shadow file like NOPASSWD, NOLOGIN, or any other string that can never match an encrypted password. From the statement of the problem, it isn't clear whether you should be looking for an MD5 password or just looking for a field that is not empty. This is intended to answer your 2nd and 3rd questions. You can use grep -c or grep with stdout redirected and check the exit status to determine whether or not at least one line matches your search pattern. When you post to a forum like this, we assume that you're asking for suggestions on how to do the job you're trying to do. If what you are using is grossly inefficient or overly complex, why don't you want to know about alternative methods to accomplish what you're trying to do? There is no way to ACCESS THE SHADOW FILE FOR REG EXPR COMPARISON WITHOUT ROOT PRIVILEGES . Or, if there is, your system's security mechanisms have been disabled and any user that can access your system can hack it to do anything they want. It sounds like your assignment is to determine a way to get the privileges needed to access that file. Some possibilities could include using a setuid root shell script (which you would have to be root to setup), su to root before running your script (which would require you to know root's password and find secure way to enter it from a shell script), or sudo. (Note also that some systems use an open directory or other authentication system and don't even have a traditional shadow file.) I don't think anybody here is going to give you a script that will do any of these, but this may give you some ideas to investigate. Also note that ways to do this may vary considerably from system to system. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
I could check for UID 0, that might yield the root account in a variety of circumstances such as root and super as you described. I certainly understand the security threat this script might produce, I even don't understand why this book even thinks that this might be a good exercise. But I think the safest way is to execute this script while the user has root privileges already. I tried running the
Quote:
|
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Quote:
Code:
awk -F: '$1 = ~/root/ {print "Found Root ID"} ' /etc/passwdwhich is not looking for UID 0; it is a syntax error on the awk I use. It looked like you were trying to say something like: Code:
awk -F: '$1 ~ "root" {print "Found Root ID"} ' /etc/passwdwhich isn't correct either since it will not only find root but also find cvsroot on my system (and only one of those has UID 0). (You need to use anchors in your matching pattern if you're looking for root, and you need to match something on another field if you're looking for UID 0.) If you look at your su(1M) or su(1) man page, you should find that you can use it to run another script if the root authorization succeeds. I don't see anything in you assignment that says that the entire script has to be in a single file. (I'm not suggesting that you use su, but your argument for not using it shows that you don't understand how su works.) I agree that being root when you run the script is probably a good idea. But any shell script that is to be run by root needs to do a LOT of extra security checks to be sure that a hacker hasn't set up a $PATH that will cause your script to run alternative utilities to capture root privileges when an unsuspecting administrator runs an insecure script. Your script doesn't take any steps to prevent these types of attacks. (Your instructions on how to run your script might obviate the need for this, but beware that you need to be especially careful when running shell scripts with extended privileges. Check out the APPLICATION USAGE and EXAMPLES sections of the POSIX command utility's man page for a discussion on some of the issues that need to be considered when writing scripts to run with extended privileges. Some systems have a utility named pwdck or (something similar to containing "pw", "pass", or "passwd" preceded by or followed by "ck" or" chk"). It sounds like your instructor is asking you to write a similar utility as a shell script. Last edited by zaxxon; 08-19-2012 at 04:42 AM.. Reason: corrected a closing code tag |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
The utility mentioned above for checking the passwd file is called
pwck . There is a similar utility for checking the group file called
grpck .
If these utilities are available on your Operating System (whatever that is?), they are very useful. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Maintain health of passwd file | Learn4Life | Shell Programming and Scripting | 4 | 08-19-2012 04:47 AM |
| When did AIX start using /etc/security/passwd instead of /etc/passwd to store encrypted passwords? | Anne Neville | AIX | 1 | 03-09-2012 08:05 PM |
| Script to maintain file versions | vskr72 | Shell Programming and Scripting | 2 | 12-18-2011 06:39 PM |
| passwd cmd reenables passwd aging in shadow entry | BG_JrAdmin | Solaris | 3 | 01-04-2011 03:28 PM |
| sed a file and maintain date stamp and permissions | andyatit | UNIX for Dummies Questions & Answers | 3 | 08-13-2010 11:47 AM |
|
|