Chrooting background service and system Program Guidance
Source: Internet
Author: User
Article title: Chrooting background service and system program guidance. 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.
Directory
Part 1: Introduction to Chrooting
* 1.1 What is chrooting?
* 1.2 When should I use chroot?
* 1.3 can all background programs use chroot?
* 1.4 what are the consequences of chrooting?
* What does chrooting need?
Part 2: System data collection
* 2.1 can we run the chroot process?
* 2.2 Introduction to trss, lsof, and ldd
* 2.3 search for the dependent data file
* 2.4 strategically establish data files
* 2.5 search for the Library file used
* 2.6 look for a good prison location (jail home)
Part 3: establish a chrooted environment
* 3.1 create a new prison
* 3.2 copy program files, data files, and set cron
* 3.3 Copy database data files
* 3.4 establish devices (install the device driver)
* 3.5 Alternate startup script
* 3.6 finished products
Part 4: Glossary
Part 1
1.1 What is chrooting?
The command chroot is short for "change root". It is designed for the root system environment of the switch. That is, the/(root directory) changes accordingly. For example, the path of a file is actually/home/wuming/hello.txt in the existing system. My current chroot/home/wuming directory, the path of this file in my chrooted environment is/hello.txt
The purpose of Chroot itself is to establish a hard (theoretically) "prison-like" protective layer. You are not allowed to access any external file data in a chroot environment. For example, in the/home/wuming directory of chroot, I cannot access any files other than/home/wuming. In general, a user is restricted from accessing system files in a multi-user system. Chroot can also be used to restrict various types of background programs to avoid hacker intrusion. Or it is more difficult for intruders to obtain root permissions. For example, if the system uses a remote service with a vulnerability, a hacker may intrude into the system to obtain a shell, but this shell is not included in the system itself, thus preventing hackers from accessing other system files. Although many people claim to be able to break through the chroot jail, most of the time it was broken through from a shell. This problem does not exist in the examples we have discussed, so it is very difficult to break the daemon environment.
1.2 When should I use chroot?
Chroot daemons is a very practical method to add different layers to the system to protect your existing system. Many system processes and third-party software have security measures for vulnerabilities. There are also many processes that use non-root users, which also makes it more difficult for users to intrude into the root user.
The network security layer includes firewall, TCP wrappers, filter layer and other additional programs. Like them, chrooting can be used properly in most environments without compromising its functions.
* 1.3 can all background programs use chroot?
Technically speaking, you can chroot everything, or even your girlfriend's radio. But in other cases, if chrooting is the best solution, then it is possible. Some daemon may cause many problems, which should be considered. For example, sendmail cannot read the. forward file in the user directory in the chroot environment. this is a good example. Therefore, to solve the chroot sendmail problem, we should first carefully plan all the details. Of course, in this example I mentioned, it is best to use smrsh (sendmail restricted shell) instead of chroot. In any case, we just need to work a little bit to secure many chroot systems daemons.
* 1.4 what are the consequences of chrooting?
If everything is correctly set, your users should not feel any system changes. The system itself has not changed. Instead, it creates a prison environment on the existing system. Here we will not discuss any secure ftp or ssh daemons. There are similar methods for them, but they are much more complicated. This section describes how to bring greater security to common services.
* What does chrooting need?
There is a step for various daemon of Chroot, basically as follows:
# Create a "prison-like" directory
# Copy the service software and other required documents
# Copy the required system library file
# Change the startup script to make the system start the correct environment
Steps 2 and 3 are basically at the same time. However, in the second step, more considerations are required. for example, a mail service must be able to access all mail directories, however, copying all the mail directories to the jail directory is not a comprehensive solution. The following describes how to solve the problem.
Part 2
* 2.1 can we run the chroot process?
Before creating a directory or generating a file, let's first consider whether the chroot environment can be created. I will introduce three examples of system processes. we should consider three problems. # Is the daemon data accessed in a common directory? # Can I copy files elsewhere or use cron for replacement periodically? # Can I use caution to generate a prison environment in these specified file directories?
If you cannot answer the above questions, it is possible that chroot is not a good solution. Let's take a look at the following example:
Eudora Qpopper
# Is the daemon data accessed in a common directory?
First, a mail service system should be able to access the user's mail directory, and some files in/etc, such as the passwd file, should be used to confirm the user. So the answer to this question is yes. Because the main file is usually under/var/mail.
# Can I copy files elsewhere or use cron for replacement periodically?
Copying a mailbox is not a good idea. this will easily cause instability in your mailbox.
# Can I use caution to generate a prison environment in these specified file directories?
Of course we can. here we have two options: one is to move these implicated files to the prison environment, and the other is to regenerate them. Symbolic links can be used for original connections, a common file directory solution in Linux.
Sun's RPCBIND
# Is the daemon data accessed in a common directory? Mainly access some small files in/etc
# Can I copy files elsewhere or use cron for replacement periodically?
Most files are small and rarely updated. it is sufficient to copy them once a day using cron.
# Can I use caution to generate a prison environment in these specified file directories?
Chroot in/etc is not a good idea. It provides useful information for many files in etc. A separate prison environment should be generated to copy files to this environment.
Sendmail
# Is the daemon data accessed in a common directory?
No, Sendmail contains several different directories and files. For example,/var/spool/mqueue and/var/mail include some files under/etc/mail, and some files under the user directory.
# Can I copy files elsewhere or use cron for replacement periodically?
Theoretically, it is acceptable, but it seems that the workload is greater than we think. For example, in the user directory. Forward file or other files. It seems unrealistic in practice.
# Can I use caution to generate a prison environment in these specified file directories?
First, we should impose jail restrictions in the mail directory. if we lose the write permission on spool, we should jail the entire/var, leading to other problems. Therefore, whether or not to create a mirror directory is not ideal. Therefore, we do not recommend using chroot for sendmail.
Although I'm sure sendmail can be chroot, I have seen Qmail from chroot, but those who are specialized in LINUX security systems are their own software and require careful consideration. This test is not recommended for beginners.
* 2.2 Introduction to trss, lsof, and ldd
Truss
If you use man truss, you can see that truss is a tool for tracking system CILS and signals. System CILS includes library files and reverse data files. Truss is a good tool to measure which files are used. It's easy to use truss, as shown in truss.
Lsof
Lsof is another tool to see which files are used by daemon. With lsof, you can see which daemons are running. Many other information such as the ports will be prompted. Can be downloaded from www.sunfreeware.com, or through FTP to ftp://vic.cc.purdue.edu/pub/tools/unix/lsof.
Ldd
Ldd is a tool that helps you find out which library files are used by programs. Ldd is the abbreviation of list dynamicdependencies. Using ldd can give you a list of database files that should be copied to the prison environment.
* 2.3 search for the dependent data file
As described in section 2.1, we should first find all the files used by daemon. Some can be found directly, and some must create a new prison environment. Two of the above three examples are completely feasible. (Eudora Qpopper and sun rpcbind) and there have been many security vulnerabilities some time ago. Here we will introduce how to implement chroot for them.
Eudora Qpopper
/Var/mail/* (inside the prison)
The following files under/etc should be periodically copied:
Hosts. allow
Hosts. deny
Netconfig
Nsswitch. conf
Passwd
Resolv. conf
Services
Shadow
Sun RPCBIND
The following files under/etc should be periodically copied:
Hosts
Netconfig
Nsswitch. conf
Resolv. conf
Services
Time zone file/usr/local/zoneinfo or/usr/share/zoneinfo and a tmp directory.
* 2.4 strategically establish data files
When you have a list of files used by daemon, what kind of jail should we consider? Do you want to use periodic system copies or create prison controls on the directory of your own data files? Of course, it is absolutely not necessary to implement prison control in its own system, such as/etc, which means that no control is established. If you circle and draw on paper to see which files belong to the system and which should be included in prison controls, you will have a good relationship pattern between the framework file systems. The designed prison framework is the first step for us to do a good job in the security system.
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