人一生必定會殺一個人 為了最后讓自己死去 我們僅有一次可能性
爺爺的死沒有人能承受 最后會去往無盡的虛空
殺人 只有一次 殺了別人 把它用盡后 卻永遠無法殺死自己 作為一個人 求死不得
——空之境界·兩儀式
最近筆者獲得了一台公網服務器的root權限,按耐不住要做一些好玩的事情了。
學習GNU/Linux這么長時間了,這是筆者第一次控制一台真正的公網服務器。
請訪問http://eecs.cc:8080/測試本文最終結果,您可以使用ssh客戶端嘗試登陸並刷新頁面進行驗證。
我們開始吧!
第一步:
訪問http://www.openssh.com/下載最新的源碼包,我下的是 openssh-6.6p1.tar.gz 。
看下圖:
解壓源碼包,打開源碼根下auth2-passwd.c文件,找到上圖中 userauth_passwd 函數定義所在,添加上面紅色框中的兩行代碼。
yum install -y zlib-devel openssl openssl-devel ./configure --with-pid-dir=/usr/local/etc && make && make install
現在配置我們的 ssh daemon 的運行參數:
vim /usr/local/etc/sshd_config
# 重要參數配置 Port 22 Protocol 2 HostKey /usr/local/etc/ssh_host_rsa_key SyslogFacility AUTHPRIV LogLevel DEBUG DenyUsers * MaxAuthTries 2 PasswordAuthentication yes
啟動‘陷阱’sshd:
/usr/local/sbin/sshd
第二步:
建立web服務器:
1 import web 2 import MySQLdb 3 import commands 4 5 6 web.config.debug = False 7 render=web.template.render('templates/') 8 urls = ( 9 "/", "hello", 10 "/log","viewlog", 11 '/list','list', 12 '/secure','secure', 13 "(.*)","notfound" 14 ) 15 app = web.application(urls, globals()) 16 17 class hello: 18 def GET(self): 19 #name='Jack' 20 i=web.input(name=None) 21 bb='bobo' 22 return render.a(i.name,bb) 23 24 class viewlog: 25 def GET(self): 26 named='log' 27 bb='wa' 28 return render.a(named,bb) 29 30 class notfound: 31 def GET(self,path): 32 #name='notfound' 33 return render.notfound(path) 34 35 class list: 36 def GET(self): 37 conn=MySQLdb.connect(host='172.16.31.99',user='web',passwd='webyun',db='web') 38 cur=conn.cursor() 39 lis=cur.execute( ' show tables; ' ) 40 lis=cur.fetchall() 41 cur.close() 42 conn.close() 43 #lis=[1,2,3,'123123',123,'abc' ] 44 return render.list(lis) 45 46 class secure: 47 def GET(self): 48 try: 49 return commands.getoutput(' grep -E -C 2 ":\)" /var/log/secure ') 50 except: 51 return 'file access error :(' 52 53 if __name__ == "__main__": 54 app.run()
啟動web服務器:
nohup python web3c.py 8080 &>log &
最終效果展示:
額。。。
文章短小,卻也花費了一番精力,如有建議和看法,歡迎提出一起討論!