473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

PHP Password / Linux Admin Password Comparison

i have an application that should allow acces to linux administrators
only.

iow, i want to code a php script that will be able to compare the
entered password with the linux adminstrator's password on the fedora
core 4 linux box.

can this be done? if so, how?

tia...

Feb 22 '06 #1
4 2295
is that possible since the passwords in UNIX are hidden in a file that
cannot be accessed by anyone other than the system? I believe it's a
"Shadow" file, that's what it's called. I'm not possitive on that
though...

~aspirany

Feb 22 '06 #2
Your passwords in Linux are in /etc/shadow and are encrypted. In any
Linux distro that has been setup properly your web server/php process
will NOT have access to this file. Come to think of it I cannot tell
you how bad an idea I think this really is, even if you succeed I sure
hope you are running a system as localhost in a closet somewhere with
no Internet connection.

Now here is a better idea: create a MySQL database and track your user
privileges and passwords through it. You can use md5 or crypt PHP
functions to one-way encrypt your passwords and store them in MySQL.

Exposing Linux system passwords over the web is a bad, very bad idea.
If the world has access to the web page, or even a hacker gets through,
they could brute force your web application into discovering the root
password.

My 2 cents

Alex
http://prepared-statement.blogspot.com

Feb 22 '06 #3
Alright tia

First I have to say Alex's idea of using mysql to track usernames is a
better idea than mine and far safer than what I came up with. I urge
you to do what he suggested.

But if you think security is for wimps you could do the following

Use a script that calls the su command to try and change to an user,
then use whoami to see if the user name has changed to what you wanted.
If the username has changed then the password was correct.

This script will do it for you...

<?php

//Change these two
$username = "root";
$password = "yeahright";

//next line not necessary, just for the test
exec( "whoami" , $whoamiThen );

$desc = array(
0 => array("pipe","r"), //stdin for sending password to su command
1 => array("pipe","w"), //stdout, to collect the result of whoami
);

//execute su command and open stdin/stdout pipes
$pr = proc_open( "/bin/su $username -c \"whoami\"" , $desc , $pipes );

//su will be now waiting for a password,
fwrite( $pipes[0] , "$password\n" );
fclose( $pipes[0] );

//only if password is correct the whoami command is now run ( from the
commandline option '-c "whoami"' in 1st argument to proc_open )
$whoamiNow = fgets( $pipes[1] );
fclose( $pipes[1] );

//close process
$ret = proc_close($pr);

print "I was {$whoamiThen[0]}<br>I am now $whoamiNow\n<br>";
echo "Returned: $ret";

if( $whoamiNow == $username ) {
//password is good
} else {
//at least track i.p. address, time and especially limit to 3
incorrect attempts then block ip/username from more tries
}

?>

On my system the result was:

I was wwwrun
I am now root
Returned: 0

This script is very very risky, as it is now it allows anyone on the
net unlimited attempts to guess the root password.

If you use it then use get_magic_quotes and addslashes to prevent code
injection with the $username and make sure people are blocked after a
few incorrect attempts, delayed in between attempts and log everything.
It would be best if you block everyone not on a trusted i.p. address.

Tim

Feb 22 '06 #4
thaks for the input. i agree this is a security nightmare, but the
product engineer wants to do this. the product is a stand alone
product. the laptop is hooked up directly to the product and the
product has no internet access. however, if the laptiop was wirelessly
on a network while accessing the product, security might be an issue.

i think the goal of the product engineer is as follows:

1. only allow a person who has root access to access the product's
program.
2. if the root password is changed, the password for the program should
be changed, too - thus enabling the root password holder access w/o the
pain of setting the password twice.

i am using a xml file as a db, however, that wouldn't meet criteria #2
above, unless there was a way to automatically update the password in
the file when the root password was updated.

obviously, i wouldn't want this in plain text. ;-)

my thought is to get the encrypted value of the root password into php
(not the actual password, mind you) into php and then compare it to the
encrypted value of the user input.

1. i'd need to have access to the encrypted root password (link,
symlink, maybe).
2. i'd need to know the encryption method so i could duplicate the
process in php and compare the encrypted password values.

is this doable?

i will mull over tihu's code and see if it applies to this case. the
product shouldn't be connected to the net, but i don't know if the
accessing laptop will be connected to the internet while accessing the
product.

Feb 22 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: D E | last post by:
When using my web application manager (http://localhost:8080/admin) I forgot my password. Is there an XML file i can look at to remember/obtain (possibly even set). Thanks
10
by: Max | last post by:
Hello all, I am trying to protect a page within my site with a JS password scheme. Now I know JS can be quite easily "circumvented", but I came by a code below. My question is: 1. Is there...
3
by: Mike Wiseley | last post by:
I created a desktop shortcut with "C:\Program Files\Microsoft Office\MSAccess.exe" "C:\My Documents\CopyAToB.mdb" /pwd "password: The trouble is that when running this shortcut, it prompts first...
3
by: Whitey | last post by:
I have a password secured database. After the password is entered the user has a form that I created that allows them to search the database and retrieve information. The problem is that the...
6
by: chsadaki | last post by:
Hello I have a problem in retrieving a row form a table that I created in mysql db. I insert these values in the table 'Bell',password('123'). But the problem is in my php application I cant...
1
by: =?Utf-8?B?UHJveQ==?= | last post by:
I have a slightly older computer running windows 2000, with some files on there that I would really like to see, but I am logged on as a guest and can't. First, I tried logging out, but it just...
6
by: kmd | last post by:
Hi I make simple script and ive made admin panel. Login and password are in config.php file. Im using form to log in. And my question is: Is security of this code high or low or medium? :) In...
1
by: aradhanathawait | last post by:
Hi all Please tell me the default Login Id and password for Tomcat5.0 Admin. I have installed tomcat5 on Red hat linux 4, it didn't ask for admin password during installlation. Thanx and...
10
dlite922
by: dlite922 | last post by:
Hey guys, I have a PC that is loaded with a program that restores the Windows XP image (Linux based, don't know the name) which restores the the OS from an image with each reboot, similar to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.