Article Title: Internal and External: backdoor and log tools in Linux. 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.
After attacking the Linux system, many intruders often get lost. Another reason is that the technical requirements are higher. Next, let's take a look at some common classic tools.
1. Extend from here: backdoors and connection tools
(1) Httptunnel
Tunnel is a Tunnel. Generally, HTTPTunnel is called an HTTP channel. Its principle is to disguise data as HTTP data to pass through the firewall. In fact, it creates a two-way virtual data connection in the HTTP request to penetrate the firewall. To put it simply, a conversion program is set up on both sides of the firewall to encapsulate the packets that were originally sent or accepted into the format of HTTP requests and cheat the firewall, therefore, it does not need other proxy servers to directly penetrate the firewall.
HTTPTunnel includes two programs: htc and hts, where htc is the client and hts is the server. Now let's take a look at how I use them. For example, if the IP address of the FTP host is 192.168.10.231 and the IP address of the local host is 192.168.10.226, the local host cannot be connected to the FTP host due to firewall reasons. What should I do? Now we can consider using HTTPTunnel. The process is as follows:
Step 1: Start the HTTPTunnel client on the local machine. Use Netstat to check the current port opened on the local machine, and you will find that port 8888 is listening.
Step 2: Start the HTTPTunnel server on the other machine and run the command "hts-f localhost: 21 80". This command means, all data sent from port 21 of the local machine is forwarded through port 80, port 80 is opened as the listening port, and then Neststat is used to check its machine, port 80 is now listening.
Step 3: use FTP to connect to port 8888 of the local machine, and you will find that the machine has been connected to the other machine. So why do people see 127.0.0.1 instead of 192.168.10.231? Because we are now connecting to port 8888 of the local machine, the firewall will certainly not respond. If the packet is not sent out, the firewall of the local area network will not know. After connecting to port 8888 of the local machine, the FTP data packets, whether control information or data information, are disguised as HTTP data packets by htc and then sent to the firewall. This is normal data, it is equivalent to spoofing the firewall.
It should be noted that the use of this trick requires the cooperation of other machines, that is, to start an hts on his machine and put the services provided by him, for example, redirect FTP to the port 80 allowed by the firewall to bypass the firewall! Someone may ask, if the other machine has the WWW Service itself, that is to say, its port 80 is listening, will this conflict? The advantage of HTTPTunnel is that even if the previous port 80 of his machine is open, there will be no problems now, and the redirection tunnel service will be unobstructed!
(2) Tcp_wrapper
Tcp_wrapper is a free software developed by Wietse Venema. The birth of Tcp_wrapper has a small story. In 1990, the server of the university where the author was located was repeatedly infiltrated by a foreign hacker, because the hard disk data of the victim host was repeatedly erased by the rm-rf/command, therefore, it was extremely difficult to find clues until one night when the author accidentally discovered that the hacker was constantly suffering the host from finger and peeking into the work of the victim. Therefore, an idea was born: design a software that allows it to intercept the IP address, user name, and other information that initiates the finger request. Venema was quickly put into work, and Tcp_wrapper was born! Since then, Tcp_wrapper has gradually become a standard security tool with its wide application. The Administrator monitors and filters various inetd services.
After Tcp_wrapper is compiled and installed successfully, a tcpd program is generated, which can be found in inetd. replace in. conf in the control file. the location of telnetd. In this way, whenever a telnet connection request is sent, tcpd intercepts the request and first reads the access control file set by the Administrator, the connection will be transferred to the real in. telnetd program, composed of in. telnetd completes subsequent work. If the ip address initiated by the connection does not comply with the settings in the access control file, the connection request is interrupted and the telnet service is rejected. The implementation of Tcp_wrapper access control relies on two files: hosts. allow and hosts. deny. If we add the log record function when editing the/etc/syslog. conf file, that is:
# Tcp wrapper log
Local3.info/var/log/tcplog
After editing, save the file and generate the tcplog file under/var/log. Note that the read/write attribute of this file should only have the read/write permission on the root user. Then ps-ef | grep syslogd, find the syslogd process number, and kill-HUP and restart the syslogd process to make the change take effect. Here, we can take a look at the content of the tcplog file generated in advance, as follows:
Jul 31 22:00:52 www.test.org in. telnetd [4365]: connect from 10.68.32.1
Jul 31 22:02:10 www.test.org in. telnetd [4389]: connect from 10.68.32.5
Jul 31 22:04:58 www.test.org in. ftpd [4429]: connect from 10.68.32.3
Aug 2 02:11:07 www.test.org in. rshd [13660]: connect from 10.68.32.5
Aug 2 02:11:07 www.test.org in. rlogind [13659]: connect from 10.68.32.1 |
From the above we can see that on the host where Tcp_wrapper is installed, Tcp_wrapper records every connection of the system, including time, service, status, ip address, etc, this is of great reference value for attacks. However, remember to clear the logs.
(3) rootkit tool: LRK
Rootkit appeared in early 1990s. It is a tool used by attackers to hide their traces and retain root access permissions. Generally, attackers obtain system access permissions through remote attacks or password guesses. Then, the attacker will install the rootkit In the compromised host, and then he will check the system through the backdoor of the rootkit to see if other users have logged on, the attacker began to clean up the relevant information in the log. Attackers can exploit this information to access other systems after obtaining the users and passwords of other systems through the rootkit sniffer.
If attackers can correctly install rootkit and properly clear log files, the system administrator will be hard to detect that the system has been intruded, it is not until the administrator of another system contacts him or fills up all the disks with the logs of the sniffer on a certain day that he will notice that the cause of the disaster is imminent. However, most common commands such as ps, df, and ls are no longer credible during system recovery and cleaning. Many rootkit have a program called FIX. Before installing rootkit, attackers can use this program to create a snapshot of the system binary code and then install the replacement program. The FIX can forge three timestamps (atime, ctime, mtime), date, permission, owner, and user group of the substitution program based on the original program. If attackers can accurately use these excellent applications and exercise caution when installing rootkit, it will make it difficult for system administrators to discover.
Next we will introduce a typical Linux LRK version 6. Linux Rootkit 6 is an open-source rootkit. After years of development, Linux Rootkit has become more and more fully functional and has more and more features. Next, we will briefly introduce various Linux Rootkit tools.
First, the program that hides the whereabouts of intruders. In order to hide the whereabouts of intruders, the author of Linux Rootkit IV can be described as painstaking machines. He has compiled many substitution programs for system commands and used these programs to replace original system commands to hide the whereabouts of intruders. These programs include:
| Ls, find, du |
These programs will prevent the display of intruders files and calculate the space occupied by the intruders files. Before compilation, intruders can use ROOTKIT_FILES_FILE to set the location of their files. The default value is/dev/ptyr. Note that if the SHOWFLAG option is used during compilation, you can use the ls-/command to list all files. These programs can automatically hide all files named ptyr, hack. dir, and W4r3z. |
| Ps, top, pidof |
These programs are used to hide all processes related to intruders. |
| Netstat |
Hides the network data stream range of the specified IP address or port. |
| Killall |
The process hidden by intruders will not be killed. |
| Ifconfig |
If the attacker starts the sniffer, the program will block the display of the PROMISC flag, making it difficult for the system administrator to find that the network interface is already in mixed mode. |
| Crontab |
Hide crontab entries related to attackers. |
| Tcpd |
Blocks logging certain connections to logs. |
| Syslogd |
Filter out some connection information in the log. |
The second is the backdoor program. The trojan program can provide backdoors for local users. The Trojan network monitoring program can provide remote users with backdoor services such as inetd, rsh, and ssh, depending on the version. With the upgrade of the version, Linux Rootkit IV has become more and more powerful and has more and more features. It generally includes the following network service programs:
| Chfn |
Programs that increase the permissions of common local users. Run chfn. When it prompts you to enter a new user name, if the user enters the rookit password, his permissions will be promoted to root. |
| Chsh |
Programs that increase local user permissions. Run chsh. When it prompts you to enter a new shell, if the user enters the rootkit password, his permissions will be promoted to root. |
| Passwd |
The role of the above two programs is the same. When you are prompted to enter the new password, if you enter the rookit password, the permission can be changed to root. |
| Login |
Allow Logon using any account with the rootkit password. If the root account is denied, try rewt. When a backdoor is used, this program can disable recording of command history. |
| Inetd |
The trojan inetd program provides remote access services for attackers. |
| Rshd |
Provides remote shell services for attackers. Attackers can use the rsh-l rootkitpassword host command to start a remote root shell. |
| Sshd |
Backdoor programs that provide ssh services for attackers. |
Then there is the tool program. All programs that do not belong to the above types can belong to this type. They implement functions such as log cleaning, packet sniffing, and remote shell port binding, including:
| Fix |
File property forgery program. |
| Linsniffer |
Packet sniffing program. |
| Sniffchk |
A simple bash shell script to check whether a sniffer is running in the system. |
| Login |
Allow Logon using any account with the rootkit password. If the root account is denied, try rewt. When a backdoor is used, this program can disable recording of command history. |
| Z2 |
Utmp/wtmp/lastlog log cleanup tool. You can delete all entries related to a user name in the utmp/wtmp/lastlog log file. However, for Linux systems, you need to manually modify the source code and set the location of the log file. |
| Bindshell |
Bind a shell service to a port. The default port is 12497. Provides shell services for remote attackers. |
(4) netcat
This is a simple and useful tool that can read and write data through a TCP or UDP network connection. It is designed as a stable backdoor tool that can be easily driven by other programs and scripts. At the same time, it is also a powerful network debugging and testing tool that can establish almost all types of network connections you need, and there are several interesting built-in functions.
2. search for clues in Linux: log tools
For a brilliant attacker, after entering the system, he should also understand his "clues" and clear these traces. Naturally, he must understand some log tools.
(1) logcheck
Logchek can automatically check log files and regularly check log files to detect violations of security rules and abnormal activities. It first removes normal log information, keeps some problematic logs, and then sends the information to the system administrator. Logcheck uses the logtail program to remember the location of the log file that has been read last time, and then starts processing new log information from this location. Logcheck mainly consists of the following main files:
| Logcheck. sh |
Execute script files, record logcheck to check those log files, etc. We can add it to crontab for regular operation. |
| Logcheck. hacking |
Is the mode file for logcheck check. And the following files are executed in the order from top to bottom. This file indicates the pattern of the intrusion activity. |
| Logcheck. violations |
This file indicates that there is a problem and a pattern of activity that violates common sense. The priority is smaller than the mode file above. |
| Logcheck. violations. ignore |
This file is opposite to the above logcheck. violations, and is a mode file that we don't care about. |
| Logcheck. ignore |
This is the last mode file to be checked. If it does not match or match the first three mode files, it is output to the report. |
| Logtail |
Record the log file information. |
When Logcheck is run for the first time, it reads all the content of the relevant log file. Logtail creates a logfile for each log file under the directory of the log file. offset file, so that the next check starts from this offset. When Logcheck is executed, unignored content is sent to the user specified by the system administrator in logcheck. sh by email.
(2) logrotate
This tool is usually provided in Linux releases. It can automatically cycle logs and delete the logs that have been stored for the longest time. Its configuration file is/etc/logrotate. conf. You can set the log cycle, log backup quantity, and how to back up logs in this file. In/etc/logrotate. d directory, including the log loop setting files of some tools, such as syslog. In these files, specify how to perform logrotate according to/etc/logrotate. conf is used for log loop. You can also add other files here to cycle logs of other services.
(3) swatch
Swatch is a real-time log monitoring tool. We can set events of interest. Swatch can run in two ways: one can exit after the Check log is complete, and the other can continuously monitor new information in the log. Swatch provides many notification methods, including email, ringing, terminal output, and various colors. Before installation, ensure that the system supports perl. The focus of the swatch software is the configuration file swatchmessage, which tells swatch what logs to monitor, what triggers to search for, and what actions to execute when triggered. When swatch finds that it is consistent with the trigger regular expression defined in swatchmessage, it will execute the Notification Program defined in swatchrc.
Of course, the software mentioned above is just a few beautiful shells in the Linux sea. As more and more users join the Linux army, we believe that there will be more and more excellent Hack, in turn, this will also promote the gradual maturity of the Linux operating system. We will wait and see.