Frp intranet penetration tutorial based on http+ domain name (win server+IIS reverse proxy)

  1. foreword

I have introduced the Frp intranet penetration tutorial based on HTTP+public IP (win server) in the article. This article mainly introduces the Frp intranet penetration of http+multiple domain names (no port) Configuration tutorial.

The main purpose of writing this article is to make a record for reference when you need to configure intranet penetration again in the future. It's an honor to be of help to you.

The main software and hardware conditions involved in this paper are:

  • Extranet cloud server: Alibaba cloud server + win server + domain name + IIS reverse proxy;

  • Intranet server: win11 + desktop computer

  1. Frp introduction

frp is an open source, simple and easy-to-use, high-performance intranet penetration and reverse proxy software that supports tcp, udp, http, https and other protocols. The official website of the frp project is https://github.com/fatedier/frp

  1. Working principle of FRP

FRP is an intranet penetration tool, mainly used to expose intranet services to the public network. Its working principle can be briefly summarized as the following steps:

  1. Deploy the FRP server on the public network server, and deploy the FRP client on the internal network host.

  1. Configure a public network port on the FRP server to receive requests from the public network.

  1. Configure a local port on the FRP client and specify the service port number that needs to be exposed to the public network.

  1. When there is a request from the public network to access the public network port on the FRP server, the FRP server will forward the request to the FRP client on the intranet host, and forward the request to the local port configured on the client.

  1. After receiving the request, the FRP client will forward the request to the local service port, so as to realize the purpose of exposing the intranet service to the public network.

It should be noted that FRP can also realize the function of sharing a public network IP for the services of multiple intranet hosts by configuring reverse proxy. At this time, the FRP server will forward the request to different intranet hosts according to the domain name specified in the request, thereby realizing multiplexing of intranet services.

In short, the working principle of FRP is to establish a channel between the public network and the internal network, and forward the public network request to the service port on the internal network host, so as to realize the exposure and sharing of internal network services.

  1. configuration manual

  1. Preparation

  1. hardware equipment:

  1. Public network cloud server (server side):

  1. Alibaba Cloud Server
  1. Operating system: windows server 2012 R2
  1. IIS 8.5
  1. Aliyun and firewall exposed ports: 7000, 7001, 80
  1. domain name:
  1. web1.whqyjy.com
  1. web2.whqyjy.com
  1. Public network ip: 8.136.xx (the domain name needs to be resolved to the public network IP)
  1. The company intranet server (client side):

  1. Operating system: win11
  1. Intranet ip: 192.168.0.174
  1. Set firewall exposed ports: 7000, 7001, 9001, 9002
  1. Deploy two web sites on the intranet server

Two web sites are deployed on the intranet server to demonstrate domain name intranet penetration. I named them here: web1 and web2.

  1. IIS (cloud server side)

IIS needs to be installed separately. There are many installation tutorials on Baidu, so I won’t go into details here.

IIS is mainly used for reverse proxy (to hide the port number of the domain name), and reverse proxy can also be done with Nginx (most reverse proxy tutorials on the Internet use Nginx). But Microsoft is more domineering. Once you install IIS and deploy the website, it is difficult to transfer port 80 to Nginx. Unless IIS is uninstalled, only Nginx is used to deploy the website. I have spent a lot of time trying to transfer port 80 to Nginx, but all failed. In the end, only IIS can be used to achieve reverse proxy.

It is worth noting that IIS configuration reverse proxy requires additional installation of plug-ins, which may not be supported by earlier IIS. Here my IIS version is 8.5.

  1. FrpTools

The official download address of the Frp tool is: https://github.com/fatedier/frp/releases

Open the website, find the latest frp to download, expand the installation packages of all operating systems, and select the windows version.

After the installation package is decompressed, the following picture is shown:

frpc represents the client side and needs to be deployed on the company's intranet server;

frps represents the server side and needs to be deployed on the cloud server;

The .ini file is a configuration item;

frpc_full.ini and frps_full.ini introduce all frp configuration items, which are equivalent to documentation;

  1. cloud server

  1. 将frp软件上传到云服务器

将安装包发布到公网云服务器上,删除不需要的文件,保留frps.exe和frps.ini文件。

这里的目录为:C:\FTP\frp_0.48.0_windows_amd64

  1. 配置frps.ini

frps.ini文件配置如下:

[common]
#记得下面2个端口在服务器上放行

# 服务端frps端口,与客户端frpc一起绑定的端口
bind_port = 7000

#web服务http接口,就是你打开网址时输入的端口号,因为80端口被禁用,所以我使用了别的
vhost_http_port = 7001

[common] 表示frp的通用配置。

bind_port 表示server端frps与client端frpc绑定的端口号。

vhost_http_port 表示http绑定的接口。

  1. 运行frps.exe:

  1. 终端手动运行方式:

命令行:

C:
cd C:\FTP\frp_0.48.0_windows_amd64
frps.exe -c ./frps.ini

frps started successfully。

frps tcp 绑定到7000端口上,http 服务绑定到7001端口上。

  1. bat脚本运行方式:

新建run.bat文件,用记事本打开,输入以下命令:

C:
cd C:\FTP\frp_0.48.0_windows_amd64
frps.exe -c ./frps.ini

保存后,鼠标单击run.bat即可手动运行。

如上图表示server端运行成功。

  1. 配置frps开机自启

配置frps开机自启动的方式:

将bat文件复制到:C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup下,重命名为:frp内网穿透开机自启.bat。

这样以后,只要云服务器开机之后就会自动运行frps.exe文件。

  1. 公司内网服务器端

  1. 将frp软件拷贝到公司内网服务器上

将安装包发布到公司内网服务器上,删除不需要的文件,保留frpc.exe和frpc.ini文件。

这里的目录为:G:\frp\frp_0.48.0_windows_amd64

  1. 配置frpc.ini

frpc.ini文件配置如下:

[common]
#外部云服务器地址+设置的端口
server_addr = 8.136.x.x
server_port = 7000

#第一个web网站,端口号为内部对应端口,及对应访问网址,这个网址需要在外部云服务器上绑定
[web1]
type = http
local_port = 9001
custom_domains = web1.whqyjy.com

#第二个web网站,端口号为内部对应端口,及对应访问网址,这个网址需要在外部云服务器上绑定
[web2]
type = http
local_port = 9002
custom_domains = web2.whqyjy.com

[common] 表示frp的通用配置;

server_addr 表示server端的公网ip地址;

server_port 表示server端frps绑定的端口;

[web1] 这里的[web1]表示一个网站的名称,可以自定义;

type表示请求的类型,我们用的是http;

local_port 表示本机端口,也就是网站web1在本机绑定的端口号;

custom_domains 表示用户通过浏览器访问网站web1的域名;

web2同理。

  1. 运行frpc.exe:

  1. 终端手动运行方式:

命令行:

G:
cd G:\qainyuhui\frp_0.48.0_windows_amd64
frpc.exe -c ./frpc.ini
  1. bat脚本运行方式:

新建run.bat文件,用记事本打开,输入一下命令:

G:
cd G:\qainyuhui\frp_0.48.0_windows_amd64
frpc.exe -c ./frpc.ini

保存后,鼠标单击run.bat即可手动运行。

如上图表示client端运行成功,并且成功登陆到server端,网站[web1]、[web2]成功加入到协议中。

与此同时,云服务器(server端)也会输出同样的日志信息:

  1. 配置frpc开机自启

配置frpc开机自启动的方式:

将bat文件复制到:C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup下,重命名为:frpc内网穿透开机自启.bat。

这样以后,只要内网服务器开机之后就会自动运行frpc.exe文件。

  1. 通过域名+7001端口访问网站

内网穿透已经配置成功,我们现在可以在外网环境中通过域名+端口的形式访问web1和web2:web1.whqyjy.com:7001web2.whqyjy.com

至此,frp的职责已经完成了。剩下的工作就要交给反向代理去将7001端口隐藏掉。

  1. 反向代理隐藏端口(IIS)

云服务器端,可以通过反向代理隐藏掉7001端口。

这里我使用IIS进行反向代理操作。参考文章:IIS的反向代理

  1. IIS插件安装

IIS配置反向代理需要依靠两个插件:Application Request Routing(ARRv3.0)Url-Rewite。如果您的IIS中没有安装需要单独安装插件。安装教程可参考IIS的反向代理

  1. 反向代理设置

IIS中打开占用服务器80端口的网站(IIS默认中是Default Web Site),点击右上角浏览Default Web Site所在文件夹。

windows中Default Web Site的默认地址一般为:C:\inetpub\wwwroot。我们需要修改web.config进行反向代理的配置。配置之前请确保您已经安装好Application Request Routing(ARRv3.0)Url-Rewite这两个插件,否则配置无法生效。

默认情况下web.config内容如下:

我们在<system.webServer>节点中添加重写规则:

<rewrite>
        <rules>
             <rule name="web1.whqyjy.com">
                    <match url="^(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^web1.whqyjy.com$" />
                    </conditions>
                    <action type="Rewrite" url="http://web1.whqyjy.com:7001/{R:1}" />
            </rule>
            <rule name="web2.whqyjy.com">
                <match url="^(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^web2.whqyjy.com$" />
                </conditions>
                <action type="Rewrite" url="http://web2.whqyjy.com:7001/{R:1}" />
            </rule>
        </rules>
</rewrite>

意思就是说:让云服务器上的IIS将用户输入的URL:【web1.whqyjy.com】转成【http://web1.whqyjy.com:7001】,web2同理。

保存web.config,重启Default Web Site 网站。即可生效。

  1. 大功告成

配置完成之后,我们在外网环境中访问http://web1.whqyjy.comhttp://web2.whqyjy.com.就可以访问内网中的web1和web2了。

Guess you like

Origin blog.csdn.net/guigenyi/article/details/129658156