【发布时间】:2022-09-28 13:25:20
【问题描述】:
我正在尝试创建一个键盘快捷键,以自动将我的 shell 升级为用于反向 shell 的完全交互式 TTY。
目前,我在 Konsole 中配置了一个快捷方式来将其添加到我的标准输入:python3 -c \"import pty;pty.spawn(\'/bin/bash\');\"。然后我需要按 ctrl-z 两次,一次暂停正在运行的进程,再一次执行以下快捷方式(改编自 Jonathan Hodgson\'s blogpost):
## Upgrade shells with keyboard shortcut (also configured in Konsole settings)
function fg-bg() {
if [[ $#BUFFER -eq 0 ]]; then
local backgroundProgram=\"$(jobs | tail -n 1 | awk \'{print $4}\')\"
case \"$backgroundProgram\" in
\"nc\"|\"ncat\"|\"netcat\")
# Make sure that /dev/tty is given to the stty command by doing </dev/tty
local columns=$(stty -a < /dev/tty | grep -oE \'columns [0-9]+\' | cut -d\' \' -f2)
local rows=$(stty -a < /dev/tty | grep -oE \'rows [0-9]+\' | cut -d\' \' -f2)
notify-send \"Terminal dimensions\" \"Rows: $rows\\nColumns: $columns\\nstty command on clipboard\"
stty raw -echo < /dev/tty; fg; zle -U \"stty rows $rows cols $columns
export TERM=\\\"xterm-256color\\\"\"
;;
*)
fg
;;
esac
fi
}
zle -N fg-bg
bindkey \'^Z\' fg-bg
这工作正常,但我希望通过消除快速连续按下三个快捷方式的需要来使其变得更好。我认为可能可以更改 Konsole 的快捷方式以使进程暂停,例如通过将 \\r\\n^Z\\r\\nzle fg-bg\\r\\n 添加到 python3 快捷方式,但这只是按字面意思添加文本(回车除外)。
标签: zsh penetration-testing konsole reverse-shell zsh-zle