tor

prep

apt -y install tor deb.torproject.org-keyring
apt -y install torsocks
apt -y install socat
apt -y install expect

configuration

/etc/tor/torrc #may not need to modify it.

service up

service tor start

torsocks :test

torsocks ssh bbsu@ptt.cc -p 22

socat :test

socat TCP-LISTEN:4141 SOCKS4A:localhost:ptt.cc:22,socksport=9050 &
netstat -antup|grep socat #上一行使用9050的tor在4141建立起socket導向到ptt.cc:22
ssh bbsu@localhost -p 4141
netstat -antup|grep socat #port4141用後即毀

expectPtt.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/expect
set BBS_ID "tabenyaki"
set BBS_PW "taroyaki"
set timeout 60
#log_file -noappend $env(HOME)/expectPtt.log
log_file $env(HOME)/expectPtt.log
#spawn ssh -oBatchMode=no -oStrictHostKeyChecking=no bbsu@ptt.cc
spawn ssh -oBatchMode=no -oStrictHostKeyChecking=no bbsu@localhost -p 4141
expect {
"請輸入代號" { send "$BBS_ID\r" ; exp_continue }
"請輸入您的密碼" { send "$BBS_PW\r" ; exp_continue }
"您想刪除其他重複登入的連線嗎" { send "N\r" ; exp_continue }
"您要刪除以上錯誤嘗試的記錄嗎" { send "N\r" ; exp_continue }
"任意鍵繼續" { send "q\r" ; exp_continue }
"密碼不對喔" { exit }
"裡沒有這個人啦" { exit }
"請勿頻繁登入以免造成系統過度負荷" { send "\r" ; exp_continue }
"請按任意鍵繼續" { send "\r" ; exp_continue }
"oodbye" { interact }
"批踢踢實業坊" {exit}
}
exit

cron and log

socatPttDaily.sh

1
2
3
4
5
6
#!/bin/sh
socat TCP-LISTEN:4141 SOCKS4A:localhost:ptt.cc:22,socksport=9050 &
netstat -antup|grep socat
#ssh bbsu@localhost -p 4141
#netstat -antup|grep socat
/home/tabenyaki/expectPtt.sh

crontab -e

1
* */3 * * * /home/tabenyaki/socatPttDaily.sh

crontab -l
cat /var/spool/cron/crontabs/tabenyaki

cat /var/log/cron.log
grep CRON /var/log/syslog