Reverse agent software ngrok

Posted by tex1820 on Mon, 02 Dec 2019 12:50:36 +0100

Reverse agent software: ngrok 1.7 (not open source after 2.0)
Function: through the construction of ngrok intranet penetration server, you can realize the localization of web server, tcp, udp forwarding, simply speaking, you can make your local service
Exposed on the Internet, accessible through the Internet
Environment: CentOS Linux release 7.4.1708 (Core)
I. domain name resolution
A record: ngrok.xfs.com.cn -- x.x.x.x
Pan analysis *. ngrok.xfs.com.cn -x.x.x.x

II. go environment construction
yum install go
III. install git environment
yum install git
IV. get the source code of ngrok
Get source code:
git clone https://github.com/inconshreveable/ngrok.git
Five. Compile

cd
cd ngrok
export NGROK_DOMAIN="ngrok.xfs.com.cn"

2). Generate self signed ssl certificate

openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=$NGROK_DOMAIN" -days 5000 -out rootCA.pem
openssl genrsa -out device.key 2048
openssl req -new -key device.key -subj "/CN=$NGROK_DOMAIN" -out device.csr
openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000

3). Replacement certificate

\cp rootCA.pem assets/client/tls/ngrokroot.crt
\cp device.crt assets/server/tls/snakeoil.crt
\cp device.key assets/server/tls/snakeoil.key

4). Set variable:
GOOS=linux GOARCH=amd64
32-bit system, GOARCH=386
5). Generate server and client
make release-server release-client
After compiling, two executable files will be generated in the bin directory of the ngrok source code: ngrokd and ngrok. Ngrokd is the server program of ngrok, and ngrok is the client program of ngrok.
Vi. startup and use of ngrokd service
1) start the ngrokd server
Temporary start:

cd ngrok
bin/ngrokd -domain="ngrok.xfs.com.cn" -httpAddr=":80"

Analysis:

Usage of ./ngrokd:
-domain string
Domain where the tunnels are hosted (default "ngrok.com")
-httpAddr string
Public address for HTTP connections, empty string to disable (default ":80")
-httpsAddr string
Public address listening for HTTPS connections, emptry string to disable (default ":443")
-log string
Write log messages to this file. 'stdout' and 'none' have special meanings (default "stdout")
-log-level string
The level of messages to log. One of: DEBUG, INFO, WARNING, ERROR (default "DEBUG")
-tlsCrt string
Path to a TLS certificate file
-tlsKey string
Path to a TLS key file
-tunnelAddr string
Public address listening for ngrok client (default ":4443")
2).start-up ngrokd Client
//Create ngrok.cfg configuration file
server_addr: "ngrok.xfs.com:4443"
trust_host_root_certs: false

Client resolution:

Options:
-authtoken string
Authentication token for identifying an ngrok.com account
-config string
Path to ngrok configuration file. (default: $HOME/.ngrok)
-hostname string
Request a custom hostname from the ngrok server. (HTTP only) (requires CNAME of your DNS)
-httpauth string
username:password HTTP basic auth creds protecting the public tunnel endpoint
-log string
Write log messages to this file. 'stdout' and 'none' have special meanings (default "none")
-log-level string
The level of messages to log. One of: DEBUG, INFO, WARNING, ERROR (default "DEBUG")
-proto string
The protocol of the traffic over the tunnel {'http', 'https', 'tcp'} (default: 'http+https') (default "http+https")
-subdomain string
Request a custom subdomain from the ngrok server. (HTTP only)
Examples:
ngrok 80
ngrok -subdomain=example 8080
ngrok -proto=tcp 22
ngrok -hostname="example.com" -httpauth="user:password" 10.0.0.1

Advanced usage: ngrok [OPTIONS] <command> [command args] [...]
Commands:
ngrok start [tunnel] [...] Start tunnels by name from config file
ngork start-all Start all tunnels defined in config file
ngrok list List tunnel names from config file
ngrok help Print help
ngrok version Print ngrok version
Examples:
ngrok start www api blog pubsub
ngrok -log=stdout -config=ngrok.yml start ssh
ngrok start-all
ngrok version

Client profile:

server_addr: "ngrok.xfs.com.cn:4443"
tunnels:
mstsc:
remote_port: 1494
proto:
tcp: ":1494"
web: 
subdomain: citirx
proto:
http: ":8172"

windows batch

cd %cd%
ngrok start mstsc citrix

Topics: Linux OpenSSL git Web Server