Chinaunix
标题:
不敲击密码进入超级用户的笨方法
[打印本页]
作者:
megalomania
时间:
2004-04-20 16:54
标题:
不敲击密码进入超级用户的笨方法
功能:通过telnet登陆避免tty检查,从而实现su脚本交互。
参照:
http://chinaunix.net/jh/24/201364.html
主要管道操作部分都是参照来的。灌水目的在于抛砖引玉,希望有大虾改进最后一段。至于什么问题,试一下就知道了。
#===========agent_sh===============
#!/bin/bash
# 2004-0419
#==================================
# doexpect outstr instr
doexpect()
{
tmp="" ;
until [[ $tmp != "" ]]
do
tmp=`tail $outputfile -n 1 |grep $1 |awk '{ print $1 }'` ;
done
echo $2 >> $inputfile ;
return ;
}
ip="localhost"
user="tlntuser"
pass="tlntpass"
supass="supass";
inputfile=in
outputfile=out
rm -fr $inputfile
rm -fr $outputfile
mknod $inputfile p
touch $outputfile
exec 7<>$outputfile
exec 8<>$inputfile
tail $outputfile -f -n 0 &
telnet $ip <&8 >&7 &
doexpect "login" $user ;
doexpect "
assword" $pass ;
doexpect $user "su" ;
doexpect "
assword" $supass ;
while true
do
read str
if [[ $str = "quit" || $str = "exit" || $str = "logout" ]]
then echo $str >> $inputfile ; exit
else echo $str >> $inputfile ;
fi
done
#==================================
[/url]
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2