In Linux, system attacks are detected and prevented-Linux Enterprise applications-Linux server applications. For more information, see the following section. When Linux is installed on a PC, you have a powerful, advanced, and multitasking network operating system. However, the system is somewhat more powerful. Some released versions start many services by default (such as rlogind, inetd, httpd, innd, fingerd, timed, rhsd, and so on ). As a system administrator, you need to be familiar with these services. If the machine is connected to the Internet, you need to disable the security of your system.
Most of the attackers are not new. They often use the latest published system tool technology to break through a detected or new security vulnerability. However, as a manager, you can access the official site of Linux
Www.redhat.com and www.calderasystems.com can obtain the latest security vulnerabilities and corresponding patches. You can also set
Visit Security Vulnerability notification sites such as www.securityfocus.com and www.cert.org.
The most convenient way to control the access server is through a program called TCP wrapper. In most Release versions, this program is often installed without additional resources. With TCP wrapper, You can restrict access to some of the services mentioned above. In addition, the TCP wrapper record file records all attempts to access your system. Run the last command to view the log of the program. The administrator can find out who is trying to connect to your system.
In the Linux/etc directory, there is an inetd. conf file, which is the configuration file of TCP wrapper and defines which services can be started by TCP wrapper. For example, to remove the finger service, comment out the line of the finger service (Add "#" in front );
# Inetd. Conf This file describes the services that will be available
# Through the INETD TCP/IP super server. To re-configure
# The running INETD process, edit this file, then send
# INETD process a SIGHUP signal.
#
Ftp stream tcp nowait root/usr/sbin/tcpd in. ftpd-l-
Telnet stream tcp nowait root/usr/sbin/tcpd in. telnetd
# Finger, login at and netstat give out user information which may be
...............
But for services such as sendmail and named, because they are not like finger and telnet services, when requests arrive, the inet daemon starts the corresponding process to provide services, but when the system starts, run as a daemon. In slackware Linux, comment out the command line that starts sendmail by modifying the startup configuration file rc. M in the/etc/rc. d directory:
#! /Bin/sh
# Rc. M This file is executed by init (8) when the system is being
# Initialized for one of the "multi user" run levels (I. E.
# Levels 1 through 6). It usually does mounting of file
# Systems et al.
# Start the sendmail daemon:
# If [-x/usr/sbin/sendmail]; then
# Echo "Starting sendmail daemon (/usr/sbin/sendmail-bd-q 15 m )... "
#/Usr/sbin/sendmail-bd-q 15 m
# Fi
............
(Note: For redhat release, you can consolidate the chkconfig command or linuxconfig command to manage whether to start a service, for example: chkconfig -- level 345 sendmail on to enable the system to automatically start sendmail at the 345 running level.) for other services such as named, you can also comment out the corresponding startup commands in the corresponding STARTUP configuration file in the same directory, so that when you restart the machine, the corresponding service will not start. For a later version of redhat linux, A linuxconfig command is provided to interactively set whether to run related services at startup on the GUI. However, for telnet, ftp, and other services, If you disable them together, it will be inconvenient for administrators to remotely manage them.
Linux provides another more flexible and effective method to restrict Service Request users, so that users can use various services with trust on the basis of ensuring security.
In the/etc directory, there are two files: hosts. deny hosts. allow. By configuring these two files, you can specify which machines can use these services and which cannot use these services. These two files are configured using a simple access control language. The basic format of the access control statement is: program name list, host name/IP address list.
The program name list specifies the names of one or more programs that provide the corresponding services. The names are separated by commas (,) or spaces. check the program name that provides the corresponding service in the conf file: in the example above, the last line of the telent is the required program name: in. the telnetd host name/IP address list specifies the identity of one or more hosts that allow or prohibit the use of the service. The host names are separated by commas or spaces. The program name and host address can both use wildcards to conveniently specify multiple services and multiple hosts. When a service request arrives at the server, the access control software queries the two files in the following order until a matching occurs:
1. When an item in/etc/hosts. allow matches the host address of the request service, the host is allowed to obtain the service.
2. Otherwise, if an item in/etc/hosts. deny matches the host address of the request service, the host is prohibited from using the service.
3. otherwise, if the corresponding configuration file does not exist, the access control software considers it as an empty file. Therefore, you can delete or remove the configuration file to disable all services for all hosts.
In a file, blank lines or rows starting with # are ignored. You can add the # Real-Time annotation function before the row. Linux provides the following flexible methods to specify the process or host list:
1. a domain name string starting with ".", such as .amms.ac.cn, then www.amms.ac.cn matches this one successfully.
2. If the IP string ending with '.' Is 202.37.152. The host with the IP address 202.37.152 matches this field.
3. the format is n. n. n. n/m. m. m. m indicates the Network/mask. If the IP address and mask bit of the host requesting the service are equal to n. n. n. n. Then the host matches this item.
4. ALL indicates matching ALL possibilities
5. Ignore CT indicates removing the host defined later. For example, list_1 EXCEPT list_2 indicates that the host listed in list_1 host list is excluded from List_2.
6. LOCAL indicates that the methods above the hosts that match all host names that do not contain '.' are only provided by Linux, but it is sufficient for our general applications.
Here are several examples to illustrate this problem:
Example 1: We only want to allow machines on the same LAN to use the ftp function of the server, but disable ftp service requests on the secondary Wan. The local LAN consists of 202.39.154., 202.39.153. and 202.39.152. consists of three CIDR blocks. In hosts. in the deny file, we define to prohibit ALL machines from requesting ALL services: ALL in hosts. in the allow file, we define that only the LAN can access the ftp function: in. ftpd-l-a: 202.39.154 202.39.153. 202.39.152. in this way, machines outside the LAN will be rejected when requesting the ftp service. Lan machines can use the ftp service. ALL: ALL and restart your inetd process:/etc/rc. d/init. d/inet restart but hosts. the deny file can only control/etc/inetd. access to services contained in the conf file is managed by/usr/bin/tcpd. TCP wrapper listens to the access network request, compares it with the service in hosts. allow and hosts. deny, and then makes a decision to allow or reject the request. However, for services not included in wrapper, you need to use other methods.
II,
The simplest and most effective way to protect your system is to use TCP wrapper. Linux to track a large number of access records on your machine.
Work. While wrapper rejects some access to your system, the system adds some information in some LOG files. In/var/log
Directory, you can see the following files:
You can see that some LOG files have extensions such as 1 and 2. This is because the system runs cron. daily. Actually, cron. daily is
Sub-directories under/etc contain many script files automatically run by the system. You do not need to participate. These scripts implement some
Task automation: such as rotating log files so that they do not become too large. As an administrator, you should be familiar with how to modify these scripts.
Run the program. Of course, there are now many well-functional log File analyzer in text mode or graphic mode to automatically detect dangerous attacks
Signs, and then sends a letter like a manager. Many such tools can be found in http://www.freshmeat.net/tucows etc.
From the attacker's point of view, they are most interested in the security files on your server. If you disable the external network for your server
. You may encounter the following situation:
[Root @ linux/] # grep refused/var/log/secure *
Sep 12 07:52:42 netgate in. rlogind [7138]: refused
Connect from 2 ??.?. 5 ?.? 42
Sep 12 07:52:52 netgate in. rshd [7139]: refused
Connect from 2 ??.?. 5 ?.? 42
Sep 12 07:52:55 netgate in. rexmcm [7144]: refused
Connect from 2 ??.?. 5 ?.? 42
Sep 12 07:52:59 netgate imapd [7146]: refused connect
From 2 ??.?. 5 ?. 42
Sep 12 07:52:59 netgate in. fingerd [7142]: refused
Connect from 2 ??.?. 5 ?.? 42
Sep 12 07:53:00 netgatipop3d [7143]: refused
Connect from 2 ??.?. 5 ?.? 42
Sep 12 07:53:07 netgate in. ftpd [7147]: refused
Connect from 2 ??.?. 5 ?.? 42
Sep 12 07:53:10 netgate gn [7145]: refused connect
From 2 ??.?. 5 ?.? 42
Sep 12 07:53:22 netgate in. telnetd [7149]: refused
Connect from 2 ??.?. 5 ?.? 42
Sep 12 07:56:34 netgate imapd [7150]: refused connect
From 2 ??.?. 5 ?.? 42
As you can see, attackers have attempted to connect several ports on the server. However, because the server shuts down the inetd startup
All services, so the LOG system records these Access denied. If such a denial of service is not found on your machine, it cannot indicate your machine.
Is not attacked. The maillog file stores the email information forwarded by the server. Xferlog stores ftp log information and so on.
If you want to view wtmp, you can use the last command
# Last | more fishduck ttyp6 nexus Tue Sep 28 still logged in birdrat ttyp5 speedy Tue Sep 28 still logged in root tty1 Tue Sep 28 still logged in will show who will log in when?, how long has it been logged in. You can find illegal login information by checking the information. You can also view the previous wtmp file, such as wtmp.1. You can run the following command: # last-f/var/log/wtmp.1 | more, but pay attention to the status information of your log file, if it is very small or the size is 0, it indicates that an attacker may have entered the system and modified the file. To prevent users from modifying certain files, such as adding and deleting log files, you can use Linux Intrusion Detection System to prevent attackers from modifying the password file of LOG files. This tool can decide whether to allow modifications to certain files when starting lilo. For details about the tool, visit www.soaring-bird.com.cn/oss_proj/lids/index.html. The grandfather process of all processes of the system is called "init", and its process ID is 1. You can view the init process information through the following command. # Ps ax | grep init 1? S init system at startup the init process will start the "inetd" process. As mentioned above, the process listens to network requests through the network port number. For example, when you telnet to your linux server, you actually request the inetd process to start the process in. telnetd on port 23 to process your access requests for communication. Then, the in. telnetd process starts a process that asks for your username and password, and then you log on to the machine. Inetd listens to multiple ports at the same time to wait for access requests, and then activates the program that completes related services. You can view the/etc/services file to see which service uses which port. From the perspective of resource saving, it makes sense to use a process instead of a process corresponding to each service. When an attacker visits your site for the first time, they often use a tool that becomes a port scanner. Using this tool, attackers can view the system services that you have opened. A well-known port scanner in LInux is nmap. http://www.insecure.org/nmap/index.html Download the software. The latest version even has a graphical interface nmapfe. Next let's run nmap to see what results we can get: The option '- ss' refers to the use of tcp syn, that is, semi-connection half-pen scan, '-O ', only the OS o of the system to be scanned is detected at the same time. (For more information, see http://www.isbase.com/book/showQueryL.asp?libID=271 Attackers can find common vulnerabilities in the operating system they use.
# Nmap-sS-O localhost
Starting nmap V. 2.3BETA5 by Fyodor (fyodor@dhp.com,
Www.insecure.org/nmap /)
Interesting ports on localhost (127.0.0.1 ):
Port State Protocol Service
21 open tcp ftp
23 open tcp telnet
25 open tcp smtp
53 open tcp domain
79 open tcp finger
80 open tcp http
98 open tcp linuxconf
111 open tcp sunrpc
113 open tcp Authenticate
139 open tcp netbios-ssn
513 open tcp login
514 open tcp shell
515 open tcp printer
TCP Sequence Prediction: Class = random positive increments
Difficulty = 4360068 (Good luck !)
Remote operating system guess: Linux 2.1.122-2.2.12
Nmap run completed -- 1 IP address (1 host up) scanned in 2
Seconds
These opened ports are intrusion points. After you modify the inetd. conf file to disable some services and start inetd again, you can use nmap to find that the commented-Out Service scan fails.
Of course, administrators can also use some other security scanning tools, such as satan or Nessus, to detect the security and reliability of their systems.
Before the attacker discovers the vulnerabilities of his or her system, the attacker can make up for them.
III,
In a joke, a thief enters a house and steals everything in the house, but uses the same thing instead of stealing.
. However, in the online world, this may happen. An attacker uses a system vulnerability to illegally intrude into your system.
When you use the ps command to list all processes in the system, there is no evidence of exceptions. You can view your password file,
Everything is so normal. What happened? After the system enters your system, the first step is to replace
Some specific files on the system, such as the netstat command. When you use the netstat-a command, the system will not display the presence of attackers.
Information. Of course, the attacker will replace all the files that may leak their existing files. In the linux environment, the next famous toolkit name is
Rootkit. You can search for the keyword rootkit in any search engine to obtain hundreds of results. These tools generally include:
Ps netstat top .....
Because these files have been replaced. Therefore, simply using the ls command to view these files does not show any flaws. There are several ways for you
It can verify the integrity of system files. If you have installed Red Hat, Caldera, TurboLinux or any system that uses RPM. You can
To use RPM to verify the integrity of system files: first you should find out which software package of your files you need to view, use
Run the rpm command to find out if a file belongs to a certain package: # rpm-qf/bin/netstat net-tools-1.51-3 and then scan
Check the changes in the entire rpm package. If you use this command for a packet that has not changed, there will be no output information, as shown below:
# Rpm-V net-tools
Replace the binary executable file of netstat 5.2 with version 6.0 and then use the following command:
... T/bin/netstat
This indicates that the/bin/netstat/file has been modified. If I use the rpm-qf command to test the ps and top command, we can get that it belongs to the package procps, and then
Verify the integrity of the procps package. The following is the result of a site hacked:
Attackers intrude into the system and use their own ps and top commands to replace the commands in our system. So that the Administrator does not see it
A running process may be a sniffer to listen to all the user's data in and out of the network and find the password information. Below is a small
To scan all rpm libraries in your system, and check whether all packages have been tampered. However, it should be noted that not all of the scripts
The reported problems indicate that the system file was damaged by attackers. For example, your password file must be different from your system installation:
#! /Bin/bash
#
# Run through rpm database and report inconsistencies
# For rpmlist in 'rpm-qa'
# These quotes are back quotes
Do echo "----- $ rpmlist -----";
Rpm-V $ rpmlist done>/tmp/rpmverify. out
When you run the scripts, the output is directed to the file/tmp/rpmverify. out. You can use the less command to view the file. However
Because text files such as/etc/passwd and/etc/inetd. conf may be displayed as modified. But how do you know that these are administrators?
Do you modify it by yourself or by intruders? The method is:
When you make sure that your system is clean and not infiltrated by attackers, you create fingerprints for these system files. When you suspect your system
These fingerprints are used to determine whether the system is intruded. The fingerprint information of the created file is implemented by running the md5sum command:
These data are the fingerprints of files on my system. The fingerprint information of files on different systems is generally different.
Use md5sum to calculate the fingerprint information of the system file. The following are some files for which you should create fingerprint information;
/Usr/bin/passwd/sbin/portmap/bin/login/bin/ls/usr/bin/top/etc/inetd. conf/etc/services
You can use fingerprint information to determine whether a system file has been tampered.
IV,
As mentioned in the previous section, when commands such as netstat and ls are modified to discover that the system has been intruded, what should we do next? Based on the importance of your system
You have many options. However, we recommend that you back up your directories, passwords, and other key system files. And then try again
Install the system. But do not copy the backup files to the new system as they may be hidden by attackers.
You can also use TCP wrapper to restrict access to the host and disable non-critical network services without re-installing the system. Then update
The affected package. Restarting a "clean" system is very important, but it is not easy to achieve this. If you find the procps or net-tools Package
The package has been modified by the attacker. The first thing is to reinstall the clean package to replace the package left by the attacker. Generally, it is best
The system publisher obtains the latest package to reinstall it.
Once attackers enter the system, they will store some tools in the system and hide them, making it hard for you to discover. Below is an attack
System instance. When the system is intruded by attackers, the server is restricted to network access and replaces all affected packets. Then
You need to carefully check the log file to find repeated attempts to enter the system. View the/etc/passwd file and find an invalid user.
Go to the user's directory:/home/jon and run "ls-l" to get the following content:
... Bashrc. bash_history. screenrc emech.tar.gz
In addition to a file named emech.tar.gz, no exception is found. But observe carefully, and you will find that the system has two
".." Directory. It is really strange that I use the command "cd .." to enter the/home directory. Original
The subdirectory name contains a space after two dots. ("...") You can find out through the following command:
After careful observation, we can find that each subdirectory is separated by a space, and there are two spaces between the second "..." And. bashrc. This is
This means that the second subdirectory ".." is actually a dot-space. Enter the directory below:
# Cd ".."
Then list the contents in the directory:
# Ls
Randfiles mech. set mech. pid checkmech cpu. memory
Mech. help mech. usage mech. levels emech. users psdevtab
Next, check whether the file is hidden elsewhere:
# Find/-user jon-print
In addition to the/home/jon directory, the following content is also found;
/Usr/local/bin/. httpd
/Tmp/cl
/Tmp/. l/bcast
/Tmp/. l/. l
/Tmp/. l/imapd
/Tmp/. l/log
/Tmp/. l/pscan
/Tmp/. l/pscan. c
/Tmp/. l/rpc
/Tmp/. l/slice2
/Tmp/. l/sniffer
/Tmp/. l/sxploit
/Tmp/. l/thc
/Tmp/. l/ufs. c
The hacker has installed Sniffers and port scanners on the system, and he has created a good "home" for himself ". Viewing
A terrible file named "tcp. log" was found in a valid user directory. This document contains several hundred presidents, including each
Telnet and ftp access to the system! In addition to notifying that the administrator of a machine that may have been infiltrated in this file should reinstall
Outside of the system, I also told them to update the passwords of all users in the system.
Here are some examples to help you search for hidden dangers. First, view the file with "suid" or "guid" in the user directory. These
The executable attribute of the component is s rather than x. For example:
The "s" in the fourth digit of the Property indicates that the actual valid user ID of the process becomes the root user when the command is executed. To allow normal users to repair
Change your password. This is required. If the value of x in the seventh digit is s, it indicates that other groups of users run the program, and the program has all groups of users.
Valid group ID. It is not harmful to make a program impersonate a specific user or group. However, in general, non-administrator users are under their directories.
The root-suid program should not be used. We can use the following command to search for such a file:
# Find/home-perm-4000-o-perm-2000-print
Next we will continue to look for programs and files left by intruders, so we need a quick way to find hidden directories. The following method is as follows:
Find a hidden directory such as ". kde. You can also find directories such as "..." or "...": cracker.
# Find/-type d-name ". *"-print
The "-type d" option means to list only directories. This command will not list "." or.
V,
As a good system manager, the best way to defeat attackers is to understand their operating principles and mechanisms. It
They used tools, how they operated on intrusions, and so on. Therefore, it is necessary to thoroughly understand the various network tools I have explained here.
As mentioned above, an attacker uses sniffer to listen to network streams to collect user names and passwords. Below we
It details how sniffer works. To put it simply, sniffer is a function that enables you to detect all the numbers received by your network interface.
It is reported. Generally, the computer only accepts the datagram whose destination address is itself, while sniffer enables the network interface to enter the error mode,
This allows you to accept all the datagram packets received by the network adapter.
If you run the ifconfig eth0 command, the following result is displayed:
Open two terminals and run sniffer-sniffit in one terminal;
# Sniffit-I
In another virtual terminal, you can run ifconfig eth0 again. You will find the following content in the output:
Up broadcast running promisc multicast mtu: 1500 Metric: 1
Note that, in comparison with the above, a word "PROMISC" is added, which is short for the promiscuous mode,
Sniffit is a lightweight, terminal-based sniffer. You can
Http://reptile.rug.ac.be /~ Coder/sniffit/sniffit.html to get it.
Another similar sniffer is netwatch, you can get from http://www.slctech.org /~ You can get it from macay/netwatch.html.
If you do not want to install another sniffer in the system, you can use the tool tcpdump in the system.
Not as gorgeous as the previous two tools, but she can do all the same functions.
# Tcpdump host www.linuxjournal.com-l | tee/tmp/tcpdump. out
-L indicates that tcpdump stores the output data into a file. The output content is as follows:
In Linux, there are many sniffer types. Attackers may use the modified ps command to hide their operations after they intrude into the system.
The sniffer of the row. Or change it to the name of a process that looks normal.
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