内网穿透工具总结frp

前言

之前写了一篇搭建http隧道的文章,用来总结在不出网的情况下如何内网渗透。所以这里就再总结一下在出网的情况下用来内网穿透的好用工具。

frp

frp 简介

frp 使用go语言开发,是一款高性能的反向代理应用,可以轻松地进行内网穿透,对外网提供服务。frp支持 TCP、UDP、KCP、HTTP、HTTPS等协议类型。

frp 下载

https://github.com/fatedier/frp/releases?after=v0.31.0 下载amd文件,测试使用0.28.2版本

frp 配置文件

下载好后,先看一下frp的相关文件
服务段frps.ini

 

[common]
# 通用设置
bind_addr = 0.0.0.0
bind_port = 7000
# frp 监听地址
bind_udp_port = 7001
# 配置udp端口
kcp_bind_port = 7000
# 用于kcp协议的udp端口,如果未设置,则在frps中禁用kcp
proxy_bind_addr = 127.0.0.1
# 代理服务器绑定地址
vhost_http_port = 80
vhost_https_port = 443
# 配置http与https端口
dashboard_addr = 0.0.0.0
dashboard_port = 7500
dashboard_user = admin
dashboard_pwd = admin
# 配置dashboard以查看仪表盘与登陆信息
enable_prometheus = true
# 普罗米修斯运维服务
log_file = ./frps.log
# 日志路径
log_level = info
log_max_days = 3
# 日志信息和日志记录最大时间
disable_log_color = false
# 禁用日志颜色,默认值为false
detailed_errors_to_client = true
# 是否将错误信息发送到frpc。默认情况下true。
authentication_method = token
# 授权验证方式
authenticate_heartbeats = false
# 是否在发送到frp的心跳中包含身份验证令牌,默认false
authenticate_new_work_conns = false
# 是否在发送到frp的新工作连接中包含身份验证令牌。默认false
token = 12345678
# 秘钥
oidc_client_id =
# 用于在OIDC身份验证中获取令牌的客户端ID
oidc_client_secret = 
# 用于在OIDC身份验证中获取令牌的客户端密码
oidc_audience = 
# 指定OIDC身份验证中令牌的访问群体
oidc_token_endpoint_url = 
# 如果AuthenticationMethod =="oidc",它将用于获取OIDC令牌
allow_ports = 2000-3000,3001,3003,4000-50000
# 允许的端口
max_pool_count = 5
# 仅允许frpc绑定您列出的端口
max_ports_per_client = 0
# pool_count的最大值
tls_only = false
# tlsonly指定是否仅接受TLS加密连接,默认false
subdomain_host = frps.com
# 当测试子域时,路由使用的主机
tcp_mux = true
# 使用tcp流多路复用,默认为true
[plugin.user-manager]
addr = 127.0.0.1:9000
path = /handler
ops = Login
# 插件管理
[plugin.port-manager]
addr = 127.0.0.1:9001
path = /handler
ops = NewProxy
# 插件管理

客户端frpc.ini

 

[common]
# 通用设置
server_addr = 0.0.0.0
server_port = 7000
# 服务端配置
http_proxy = http://user:passwd@192.168.1.128:8080
# 通过http代理或socks5代理连接frps
log_file = ./frps.log
# 日志路径
log_level = info
log_max_days = 3
# 日志信息和日志记录最大时间
disable_log_color = false
# 禁用日志颜色,默认值为false
token = 12345678
# 用于身份验证
admin_addr = 127.0.0.1
admin_port = 7400
admin_user = admin
admin_pwd = admin
# 通过api设置frpc控制台
pool_count = 5
# 连接将提前建立,默认值为零
tcp_mux = true
# 使用tcp流多路复用,默认为"true"
user = your_name
# 更改代理名称
login_fail_exit = true
# 第一次登录失败时是否退出程序,默认true
protocol = TCP
# 用于连接服务器的通信协议,支持tcp,kcp,websocket。默认tcp协议。
tls_enable = true
# 如果tls_enable为true,则frpc将通过tls连接frps
dns_server = 8.8.8.8
# 指定一个dns服务器,因此frpc将使用此服务器代替默认服务器
meta_var1 = 123
meta_var2 = 234
# 客户端的其他元信息


[ssh]
# 支持 tcp | udp | http | https | stcp | xtcp,默认为tcp
type = tcp
local_ip = 127.0.0.1
local_port = 22
# 限制此代理的带宽
use_encryption = false
# 对frps和frpc之间的消息进行加密,默认为false
use_compression = false
# 是否压缩,默认fasle
remote_port = 6001
# 设置远程监听端口

group = test_group
# 设置组
group_key = 123456
# 设置组密码
health_check_type = TCP
# frpc连接本地服务的端口以检测其健康状态
health_check_timeout_s = 3
# 设置检查连接超时时间
health_check_max_failed = 3
# 设置连续3次失败,则代理将从frps中删除
health_check_interval_s = 10
# 设置每10秒进行一次健康检查
meta_var1 = 123
meta_var2 = 234
# 每个代理的其他元信息

以下就是一些实例:
[ssh_random]
[range:tcp_port]
[DNS]
[range:udp_port]
[web01]
[web02]

frp使用

搭建socks5隧道

frps.ini

 

[common]
bind_addr = 0.0.0.0
# 绑定的ip,为本机
bind_port = 7000
# 绑定的端口
dashboard_addr = 0.0.0.0
# 管理地址
dashboard_port = 4000
# 管理端口
dashboard_user = root
# 管理的用户名
dashboard_pwd  = 1qaz2wsx
# 管理用户的密码
token = 1qaz2wsx
# 客户端服务端连接的密码
heartbeat_timeout = 90
# 心跳超时时间
max_pool_count = 5
# 最大同时连接数

服务端运行命令

 

./frps -c  frps.ini
image.png

frpc.ini

 

[common]
server_addr = 106.53.97.7
server_port = 7000
# 服务器绑定的端口
token = 1qaz2wsx
# 连接的密码
tls_enable = true
# 启用tls
pool_count = 5        
protocol = tcp
# 协议类型
health_check_type = tcp
health_check_interval_s = 100
# 设置健康检查时间

[test] 
remote_port = 2333
# 代理的端口
plugin = socks5
# 使用的协议
use_encryption = true
# 是否加密
use_compression = true
# 是否压缩

先对流量加密,再用TLS加密,保障传输安全。
客户端运行

 

./frpc -c  frpc.ini
image.png

对应上面test设置的socks5代理。

image.png

使用SocksCap64设置firefox浏览内网网页。

image.png

这里的socks5代理没有设置用户名、密码。
如果设置,需要增加两个配置项。

 

plugin_user = cseroad
plugin_passwd = cseroad123

再推荐几个配置项

 

tls_enable = true      # 从0.25.0版本开始 frp 支持通过 TLS 协议加密传输
use_encryption = true  # 通信内容加密传输
use_compression = true # 是否压缩

wireshark抓取未配置这几项之前的通信流量。

image.png

可以显而易见看到来源地址,目的地址,通信的端口,以及正在访问的网页。

添加上面几项后,再次抓取数据包,可以看到通信内容已经加密。

image.png

防护手法:可以在流量设备上禁止gryphon协议,因为frp每次连接都会有gryphon协议的包去认证frp服务器。

搭建tcp隧道

frps.ini

 

[common]
bind_addr = 0.0.0.0
# 绑定的ip,为本机
bind_port = 7000
# 绑定的端口
dashboard_addr = 0.0.0.0
# 管理地址
dashboard_port = 4000
# 管理端口
dashboard_user = root
# 管理的用户名
dashboard_pwd  = 1qaz2wsx
# 管理用户的密码
token = 1qaz2wsx
# 客户端服务端连接的密码
heartbeat_timeout = 90
# 心跳超时时间
max_pool_count = 5
# 最大同时连接数

frpc.ini

 

[common]
server_addr = 109.xxx.xxx.9
server_port = 7000
token = 1qaz2wsx
tls_enable = true

[test]
type = tcp
local_ip = 127.0.0.1
local_port = 3389
remote_port = 33389
use_encryption = true
use_compression = true

访问公网的33389即可访问客户端的3389端口,完美实现端口转发。

image.png

补充:
linux后台运行

 

nohup ./frps -c frps.ini >/dev/null 2>&1 &

停止方式

 

ps -aux|grep frp| grep -v grep  # 找到进程
kill -9 进程号   # 杀死进程

frp 的缺点是需要落地配置文件。
当然,uknowsec 大佬改造出了配置文件不落地的方案。https://github.com/uknowsec/frpModify