
{"id":7927,"date":"2012-12-02T16:36:24","date_gmt":"2012-12-02T16:36:24","guid":{"rendered":"http:\/\/www.beautifulwork.org\/?p=7927"},"modified":"2012-12-02T16:36:24","modified_gmt":"2012-12-02T16:36:24","slug":"etcpasswd-file","status":"publish","type":"post","link":"https:\/\/www.trueangle.org\/index.php\/2012\/12\/02\/etcpasswd-file\/","title":{"rendered":"Examining \/etc\/passwd file in Typical Unix-like OS"},"content":{"rendered":"<p>ABOUT  \/etc\/passwd file<\/p>\n<pre>\nThe \/etc\/passwd file is a text-based database of information about users that may log into the system or other operating system user identities that own running processes.\n\nIn many operating systems this file is just one of many possible back-ends for the more general passwd name service.\n\nThe file's name originates from one of its initial functions as it contained the data used to verify passwords of user accounts. However, on modern Unix systems the security-sensitive password information is instead often stored in a different file using shadow passwords, or other database implementations.\n\nThe \/etc\/passwd file typically has file system permissions that allow it to be readable by all users of the system (world-readable), although it may only be modified by the superuser or by using a few special purpose privileged commands.\n\nThe \/etc\/passwd file is a text file with one record per line, each describing a user account. Each record consists of seven fields separated by colons. The ordering of the records within the file is generally unimportant.\n\n\nThe fields, in order from left to right, are:\n\nUser name: the string a user would type in when logging into the operating system: the logname. Must be unique across users listed in the file.\n\nInformation used to validate a user's password; in most modern uses, this field is usually set to \"x\" (or \"*\", or some other indicator) with the actual password information being stored in a separate shadow \npassword file. On Linux systems, setting this field to an asterisk (\"*\") is a common way to disable direct logins to an account while still preserving its name, while another possible value is \"*NP*\" which indicates to use an NIS server to obtain the password.[2] Without password shadowing in effect, this field would typically contain a cryptographic hash of the user's password (in combination with a salt).\n\nuser identifier number, used by the operating system for internal purposes. It need not be unique.\n\ngroup identifier number, which identifies the primary group of the user; all files that are created by this user may initially be accessible to this group.\n\nGecos field, commentary that describes the person or account. Typically, this is a set of comma-separated values including the user's full name and contact details.\n\nPath to the user's home directory.\n\nProgram that is started every time the user logs into the system. For an interactive user, this is usually one of the system's command line interpreters (shells).\n<\/pre>\n<p><u>RELATED SHELL SESSION EXPOSURE<\/u><\/p>\n<p>[bash]<br \/>\n$cat \/etc\/passwd<br \/>\nroot:x:0:0:root:\/root:\/bin\/bash<br \/>\ndaemon:x:1:1:daemon:\/usr\/sbin:\/bin\/sh<br \/>\nbin:x:2:2:bin:\/bin:\/bin\/sh<br \/>\nsys:x:3:3:sys:\/dev:\/bin\/sh<br \/>\nsync:x:4:100534:sync:\/bin:\/bin\/sync<br \/>\ngames:x:5:60:games:\/usr\/games:\/bin\/sh<br \/>\nman:x:6:12:man:\/var\/cache\/man:\/bin\/sh<br \/>\nlp:x:7:7:lp:\/var\/spool\/lpd:\/bin\/sh<br \/>\nmail:x:8:8:mail:\/var\/mail:\/bin\/sh<br \/>\nnews:x:9:9:news:\/var\/spool\/news:\/bin\/sh<br \/>\nuucp:x:10:10:uucp:\/var\/spool\/uucp:\/bin\/sh<br \/>\nproxy:x:13:13:proxy:\/bin:\/bin\/sh<br \/>\nwww-data:x:33:33:www-data:\/var\/www:\/bin\/sh<br \/>\nbackup:x:34:34:backup:\/var\/backups:\/bin\/sh<br \/>\nlist:x:38:38:Mailing List Manager:\/var\/list:\/bin\/sh<br \/>\nirc:x:39:39:ircd:\/var\/run\/ircd:\/bin\/sh<br \/>\ngnats:x:41:41:Gnats Bug-Reporting System (admin):\/var\/lib\/gnats:\/bin\/sh<br \/>\nnobody:x:100534:100534:nobody:\/nonexistent:\/bin\/sh<br \/>\nlibuuid:x:100:101::\/var\/lib\/libuuid:\/bin\/sh<br \/>\njeffrin:x:1000:1000:Jeffrin Jose Thalakkottoor,,,:\/home\/jeffrin:\/bin\/bash<br \/>\nmessagebus:x:101:103::\/var\/run\/dbus:\/bin\/false<br \/>\navahi:x:102:105:Avahi mDNS daemon,,,:\/var\/run\/avahi-daemon:\/bin\/false<br \/>\nfestival:x:103:29::\/home\/festival:\/bin\/false<br \/>\nusbmux:x:104:46:usbmux daemon,,,:\/home\/usbmux:\/bin\/false<br \/>\nsaned:x:106:113::\/home\/saned:\/bin\/false<br \/>\ngdm:x:107:114:Gnome Display Manager:\/var\/lib\/gdm:\/bin\/false<br \/>\nsshd:x:108:100534::\/var\/run\/sshd:\/usr\/sbin\/nologin<br \/>\nhaldaemon:x:110:116:Hardware abstraction layer,,,:\/var\/run\/hald:\/bin\/false<br \/>\nDebian-exim:x:111:118::\/var\/spool\/exim4:\/bin\/false<br \/>\nmysql:x:112:119:MySQL Server,,,:\/var\/lib\/mysql:\/bin\/false<br \/>\npulse:x:109:115:PulseAudio daemon,,,:\/var\/run\/pulse:\/bin\/false<br \/>\nrtkit:x:113:124:RealtimeKit,,,:\/proc:\/bin\/false<br \/>\njetty:x:114:125::\/usr\/share\/jetty:\/bin\/false<br \/>\nklog:x:115:127::\/home\/klog:\/bin\/false<br \/>\nsyslog:x:116:128::\/home\/syslog:\/bin\/false<br \/>\ncolord:x:117:129:colord colour management daemon,,,:\/var\/lib\/colord:\/bin\/false<br \/>\nvde2-net:x:118:132::\/var\/run\/vde2:\/bin\/false<br \/>\nfetchmail:x:119:100534::\/var\/lib\/fetchmail:\/bin\/false<br \/>\nlibvirt-qemu:x:120:131:Libvirt Qemu,,,:\/var\/lib\/libvirt:\/bin\/false<br \/>\nspeech-dispatcher:x:121:29:Speech Dispatcher,,,:\/var\/run\/speech-dispatcher:\/bin\/sh<br \/>\nDebian-gdm:x:105:111:Gnome Display Manager:\/var\/lib\/gdm3:\/bin\/false<br \/>\nkdm:x:122:100534::\/home\/kdm:\/bin\/false<br \/>\nsnmp:x:123:134::\/var\/lib\/snmp:\/bin\/false<br \/>\n$<\/p>\n<p>[\/bash]<\/p>\n<p><u>RELATED SOURCE CODE EXPOSURE<\/u><\/p>\n<p>[code lang=&#8221;c&#8221;]<br \/>\n\/*<br \/>\n * new_password &#8211; validate old password and replace with new (both old and<br \/>\n * new in global &quot;char crypt_passwd[128]&quot;)<br \/>\n *\/<br \/>\nstatic int new_password (const struct passwd *pw)<br \/>\n{<br \/>\n\tchar *clear;\t\t\/* Pointer to clear text *\/<br \/>\n\tchar *cipher;\t\t\/* Pointer to cipher text *\/<br \/>\n\tconst char *salt;\t\/* Pointer to new salt *\/<br \/>\n\tchar *cp;\t\t\/* Pointer to getpass() response *\/<br \/>\n\tchar orig[200];\t\t\/* Original password *\/<br \/>\n\tchar pass[200];\t\t\/* New password *\/<br \/>\n\tint i;\t\t\t\/* Counter for retries *\/<br \/>\n\tbool warned;<br \/>\n\tint pass_max_len = -1;<br \/>\n\tconst char *method;<\/p>\n<p>#ifdef HAVE_LIBCRACK_HIST<br \/>\n\tint HistUpdate (const char *, const char *);<br \/>\n#endif\t\t\t\t\/* HAVE_LIBCRACK_HIST *\/<\/p>\n<p>\t\/*<br \/>\n\t * Authenticate the user. The user will be prompted for their own<br \/>\n\t * password.<br \/>\n\t *\/<\/p>\n<p>\tif (!amroot &amp;&amp; (&#8216;&#092;&#048;&#8217; != crypt_passwd[0])) {<br \/>\n\t\tclear = getpass (_(&quot;Old password: &quot;));<br \/>\n\t\tif (NULL == clear) {<br \/>\n\t\t\treturn -1;<br \/>\n\t\t}<\/p>\n<p>\t\tcipher = pw_encrypt (clear, crypt_passwd);<\/p>\n<p>\t\tif (NULL == cipher) {<br \/>\n\t\t\tstrzero (clear);<br \/>\n\t\t\tfprintf (stderr,<br \/>\n\t\t\t         _(&quot;%s: failed to crypt password with previous salt: %s\\n&quot;),<br \/>\n\t\t\t         Prog, strerror (errno));<br \/>\n\t\t\tSYSLOG ((LOG_INFO,<br \/>\n\t\t\t         &quot;Failed to crypt password with previous salt of user &#8216;%s&#8217;&quot;,<br \/>\n\t\t\t         pw-&gt;pw_name));<br \/>\n\t\t\treturn -1;<br \/>\n\t\t}<\/p>\n<p>\t\tif (strcmp (cipher, crypt_passwd) != 0) {<br \/>\n\t\t\tstrzero (clear);<br \/>\n\t\t\tstrzero (cipher);<br \/>\n\t\t\tSYSLOG ((LOG_WARN, &quot;incorrect password for %s&quot;,<br \/>\n\t\t\t         pw-&gt;pw_name));<br \/>\n\t\t\t(void) sleep (1);<br \/>\n\t\t\t(void) fprintf (stderr,<br \/>\n\t\t\t                _(&quot;Incorrect password for %s.\\n&quot;),<br \/>\n\t\t\t                pw-&gt;pw_name);<br \/>\n\t\t\treturn -1;<br \/>\n\t\t}<br \/>\n\t\tSTRFCPY (orig, clear);<br \/>\n\t\tstrzero (clear);<br \/>\n\t\tstrzero (cipher);<br \/>\n\t} else {<br \/>\n\t\torig[0] = &#8216;&#092;&#048;&#8217;;<br \/>\n\t}<\/p>\n<p>\t\/*<br \/>\n\t * Get the new password. The user is prompted for the new password<br \/>\n\t * and has five tries to get it right. The password will be tested<br \/>\n\t * for strength, unless it is the root user. This provides an escape<br \/>\n\t * for initial login passwords.<br \/>\n\t *\/<br \/>\n\tmethod = getdef_str (&quot;ENCRYPT_METHOD&quot;);<br \/>\n\tif (NULL == method) {<br \/>\n\t\tif (!getdef_bool (&quot;MD5_CRYPT_ENAB&quot;)) {<br \/>\n\t\t\tpass_max_len = getdef_num (&quot;PASS_MAX_LEN&quot;, 8);<br \/>\n\t\t}<br \/>\n\t} else {<br \/>\n\t\tif (   (strcmp (method, &quot;MD5&quot;)    == 0)<br \/>\n#ifdef USE_SHA_CRYPT<br \/>\n\t\t    || (strcmp (method, &quot;SHA256&quot;) == 0)<br \/>\n\t\t    || (strcmp (method, &quot;SHA512&quot;) == 0)<br \/>\n#endif\t\t\t\t\/* USE_SHA_CRYPT *\/<br \/>\n\t\t    ) {<br \/>\n\t\t\tpass_max_len = -1;<br \/>\n\t\t} else {<br \/>\n\t\t\tpass_max_len = getdef_num (&quot;PASS_MAX_LEN&quot;, 8);<br \/>\n\t\t}<br \/>\n\t}<br \/>\n\tif (!qflg) {<br \/>\n\t\tif (pass_max_len == -1) {<br \/>\n\t\t\t(void) printf (_(<br \/>\n&quot;Enter the new password (minimum of %d characters)\\n&quot;<br \/>\n&quot;Please use a combination of upper and lower case letters and numbers.\\n&quot;),<br \/>\n\t\t\t\tgetdef_num (&quot;PASS_MIN_LEN&quot;, 5));<br \/>\n\t\t} else {<br \/>\n\t\t\t(void) printf (_(<br \/>\n&quot;Enter the new password (minimum of %d, maximum of %d characters)\\n&quot;<br \/>\n&quot;Please use a combination of upper and lower case letters and numbers.\\n&quot;),<br \/>\n\t\t\t\tgetdef_num (&quot;PASS_MIN_LEN&quot;, 5), pass_max_len);<br \/>\n\t\t}<br \/>\n\t}<\/p>\n<p>\twarned = false;<br \/>\n\tfor (i = getdef_num (&quot;PASS_CHANGE_TRIES&quot;, 5); i &gt; 0; i&#8211;) {<br \/>\n\t\tcp = getpass (_(&quot;New password: &quot;));<br \/>\n\t\tif (NULL == cp) {<br \/>\n\t\t\tmemzero (orig, sizeof orig);<br \/>\n\t\t\treturn -1;<br \/>\n\t\t}<br \/>\n\t\tif (warned &amp;&amp; (strcmp (pass, cp) != 0)) {<br \/>\n\t\t\twarned = false;<br \/>\n\t\t}<br \/>\n\t\tSTRFCPY (pass, cp);<br \/>\n\t\tstrzero (cp);<\/p>\n<p>\t\tif (!amroot &amp;&amp; (!obscure (orig, pass, pw) || reuse (pass, pw))) {<br \/>\n\t\t\t(void) puts (_(&quot;Try again.&quot;));<br \/>\n\t\t\tcontinue;<br \/>\n\t\t}<\/p>\n<p>\t\t\/*<br \/>\n\t\t * If enabled, warn about weak passwords even if you are<br \/>\n\t\t * root (enter this password again to use it anyway).<br \/>\n\t\t * &#8211;marekm<br \/>\n\t\t *\/<br \/>\n\t\tif (amroot &amp;&amp; !warned &amp;&amp; getdef_bool (&quot;PASS_ALWAYS_WARN&quot;)<br \/>\n\t\t    &amp;&amp; (!obscure (orig, pass, pw) || reuse (pass, pw))) {<br \/>\n\t\t\t(void) puts (_(&quot;\\nWarning: weak password (enter it again to use it anyway).&quot;));<br \/>\n\t\t\twarned = true;<br \/>\n\t\t\tcontinue;<br \/>\n\t\t}<br \/>\n\t\tcp = getpass (_(&quot;Re-enter new password: &quot;));<br \/>\n\t\tif (NULL == cp) {<br \/>\n\t\t\tmemzero (orig, sizeof orig);<br \/>\n\t\t\treturn -1;<br \/>\n\t\t}<br \/>\n\t\tif (strcmp (cp, pass) != 0) {<br \/>\n\t\t\t(void) fputs (_(&quot;They don&#8217;t match; try again.\\n&quot;), stderr);<br \/>\n\t\t} else {<br \/>\n\t\t\tstrzero (cp);<br \/>\n\t\t\tbreak;<br \/>\n\t\t}<br \/>\n\t}<br \/>\n\tmemzero (orig, sizeof orig);<\/p>\n<p>\tif (i == 0) {<br \/>\n\t\tmemzero (pass, sizeof pass);<br \/>\n\t\treturn -1;<br \/>\n\t}<\/p>\n<p>\t\/*<br \/>\n\t * Encrypt the password, then wipe the cleartext password.<br \/>\n\t *\/<br \/>\n\tsalt = crypt_make_salt (NULL, NULL);<br \/>\n\tcp = pw_encrypt (pass, salt);<br \/>\n\tmemzero (pass, sizeof pass);<\/p>\n<p>\tif (NULL == cp) {<br \/>\n\t\tfprintf (stderr,<br \/>\n\t\t         _(&quot;%s: failed to crypt password with salt &#8216;%s&#8217;: %s\\n&quot;),<br \/>\n\t\t         Prog, salt, strerror (errno));<br \/>\n\t\treturn -1;<br \/>\n\t}<\/p>\n<p>#ifdef HAVE_LIBCRACK_HIST<br \/>\n\tHistUpdate (pw-&gt;pw_name, crypt_passwd);<br \/>\n#endif\t\t\t\t\/* HAVE_LIBCRACK_HIST *\/<br \/>\n\tSTRFCPY (crypt_passwd, cp);<br \/>\n\treturn 0;<br \/>\n}<\/p>\n<p>[\/code]<\/p>\n<p>SOURCE CODE FROM DEBIAN SOURECE PACKAGE NAMED &#8220;shadow&#8221;<\/p>\n<p>LINKS (SOURCE AND OTHER)<\/p>\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Passwd\">https:\/\/en.wikipedia.org\/wiki\/Passwd<\/a><br \/>\n<a href=\"https:\/\/www.ibm.com\/support\/knowledgecenter\/en\/ssw_aix_72\/com.ibm.aix.security\/passwords_etc_passwd_file.htm\">https:\/\/www.ibm.com\/support\/knowledgecenter\/en\/ssw_aix_72\/com.ibm.aix.security\/passwords_etc_passwd_file.htm<\/a><br \/>\n<a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-use-passwd-and-adduser-to-manage-passwords-on-a-linux-vps\">https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-use-passwd-and-adduser-to-manage-passwords-on-a-linux-vps<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ABOUT \/etc\/passwd file The \/etc\/passwd file is a text-based database of information about users that may log into the system or other operating system user identities that own running processes. In many operating systems this file is just one of many possible back-ends for the more general passwd name service. The file&#8217;s name originates from &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.trueangle.org\/index.php\/2012\/12\/02\/etcpasswd-file\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Examining \/etc\/passwd file in Typical Unix-like OS&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[83],"tags":[251,1235,1236],"_links":{"self":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/7927"}],"collection":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/comments?post=7927"}],"version-history":[{"count":0,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/7927\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/media?parent=7927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/categories?post=7927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/tags?post=7927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}