Commit 7ee7cba009ad5ff75ff98306045dfe905d93633d
0 parents
Exists in
master
first commit
Showing
2 changed files
with
239 additions
and
0 deletions
Show diff stats
1 | +++ a/README.md | |
... | ... | @@ -0,0 +1,36 @@ |
1 | +# ngrok - Introspected tunnels to localhost ([homepage](https://ngrok.com)) | |
2 | +### "I want to securely expose a web server to the internet and capture all traffic for detailed inspection and replay" | |
3 | + | |
4 | + | |
5 | +## What is ngrok? | |
6 | +ngrok is a reverse proxy that creates a secure tunnel between from a public endpoint to a locally running web service. | |
7 | +ngrok captures and analyzes all traffic over the tunnel for later inspection and replay. | |
8 | + | |
9 | +## What can I do with ngrok? | |
10 | +- Expose any http service behind a NAT or firewall to the internet on a subdomain of ngrok.com | |
11 | +- Expose any tcp service behind a NAT or firewall to the internet on a random port of ngrok.com | |
12 | +- Inspect all http requests/responses that are transmitted over the tunnel | |
13 | +- Replay any request that was transmitted over the tunnel | |
14 | + | |
15 | + | |
16 | +## What is ngrok useful for? | |
17 | +- Temporarily sharing a website that is only running on your development machine | |
18 | +- Demoing an app at a hackathon without deploying | |
19 | +- Developing any services which consume webhooks (HTTP callbacks) by allowing you to replay those requests | |
20 | +- Debugging and understanding any web service by inspecting the HTTP traffic | |
21 | +- Running networked services on machines that are firewalled off from the internet | |
22 | + | |
23 | + | |
24 | +## Downloading and installing ngrok | |
25 | +ngrok has _no_ runtime dependencies. Just download a single binary for your platform and run it. Some premium features | |
26 | +are only available by creating an account on ngrok.com. If you need them, [create an account on ngrok.com](https://ngrok.com/signup). | |
27 | + | |
28 | +- [Linux](https://dl.ngrok.com/linux_386/ngrok.zip) | |
29 | +- [Mac OSX](https://dl.ngrok.com/darwin_386/ngrok.zip) | |
30 | +- [Windows](https://dl.ngrok.com/windows_386/ngrok.zip) | |
31 | + | |
32 | +## Install | |
33 | +- One click Install ngrok | |
34 | + | |
35 | +wget http://soft.clang.cn/ngrok/ngrok_install.sh && bash ./ngrok_install.sh | |
36 | + | ... | ... |
1 | +++ a/ngrok_install.sh | |
... | ... | @@ -0,0 +1,203 @@ |
1 | +#!/bin/bash | |
2 | +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin | |
3 | +export PATH | |
4 | +shell_run_start=`date "+%Y-%m-%d %H:%M:%S"` #shell run start time | |
5 | +# Check if user is root | |
6 | +function rootness(){ | |
7 | + if [[ $EUID -ne 0 ]]; then | |
8 | + echo "Error:This script must be run as root!" 1>&2 | |
9 | + exit 1 | |
10 | + fi | |
11 | +} | |
12 | + | |
13 | +get_char() | |
14 | +{ | |
15 | + SAVEDSTTY=`stty -g` | |
16 | + stty -echo | |
17 | + stty cbreak | |
18 | + dd if=/dev/tty bs=1 count=1 2> /dev/null | |
19 | + stty -raw | |
20 | + stty echo | |
21 | + stty $SAVEDSTTY | |
22 | +} | |
23 | + | |
24 | +function fun_clangcn.com(){ | |
25 | +echo "" | |
26 | +echo "#############################################################" | |
27 | +echo "# One click Install Ngrok" | |
28 | +echo "# Intro: http://clang.cn/blog/" | |
29 | +echo "#" | |
30 | +echo "# Author: Clang <admin@clangcn.com>" | |
31 | +echo "# version:1.0" | |
32 | +echo "#############################################################" | |
33 | +echo "" | |
34 | +} | |
35 | + | |
36 | +# Check OS | |
37 | +function checkos(){ | |
38 | + if [ ! -z "`cat /etc/issue | grep bian`" ];then | |
39 | + OS=Debian | |
40 | + elif [ ! -z "`cat /etc/issue | grep Ubuntu`" ];then | |
41 | + OS=Ubuntu | |
42 | + else | |
43 | + echo "Not support OS, Please reinstall OS and retry!" | |
44 | + exit 1 | |
45 | + fi | |
46 | +} | |
47 | + | |
48 | +# Disable selinux | |
49 | +function disable_selinux(){ | |
50 | + if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then | |
51 | + sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config | |
52 | + setenforce 0 | |
53 | + fi | |
54 | +} | |
55 | + | |
56 | + | |
57 | + | |
58 | +function fun_set_ngrok_domain(){ | |
59 | + # Set ngrok domain | |
60 | + NGROK_DOMAIN="" | |
61 | + read -p "Please input domain for Ngrok(e.g.:ngrok.clang.cn):" NGROK_DOMAIN | |
62 | + check_input | |
63 | +} | |
64 | + | |
65 | +function fun_set_ngrok_pass(){ | |
66 | + # Set ngrok pass | |
67 | + ngrok_pass="" | |
68 | + read -p "Please input password for Ngrok:" ngrok_pass | |
69 | +} | |
70 | + | |
71 | +function check_input(){ | |
72 | + # check ngrok domain | |
73 | + if [ "$NGROK_DOMAIN" = "" ]; then | |
74 | + echo -e "Your input is empty,please input again..." | |
75 | + fun_set_ngrok_domain | |
76 | + else | |
77 | + echo -e "Your domain: \033[41;37m "${NGROK_DOMAIN}" \033[0m." | |
78 | + fun_set_ngrok_pass | |
79 | + fi | |
80 | + # check ngrok pass | |
81 | + if [ "$ngrok_pass" = "" ]; then | |
82 | + echo -e "Your input is empty,please input again..." | |
83 | + fun_set_ngrok_pass | |
84 | + else | |
85 | + echo -e "Your ngrok pass: \033[41;37m "${ngrok_pass}" \033[0m." | |
86 | + echo -e "\033[32m \033[05mPress any key to start...\033[0m" | |
87 | + char=`get_char` | |
88 | + pre_install | |
89 | + fi | |
90 | +} | |
91 | + | |
92 | +function config_runshell_ngrok(){ | |
93 | +cat > /root/.ngrok_config.sh <<EOF | |
94 | +#!/bin/bash | |
95 | +# -------------config START------------- | |
96 | +dns="${NGROK_DOMAIN}" | |
97 | +pass="${ngrok_pass}" | |
98 | +http_port=80 | |
99 | +https_port=443 | |
100 | +remote_port=4443 | |
101 | +srtCRT=server.crt | |
102 | +strKey=server.key | |
103 | +# -------------config END------------- | |
104 | +EOF | |
105 | +wget http://soft.clang.cn/ngrok/ngrok.sh -O /root/ngrok.sh | |
106 | +chmod 500 /root/ngrok.sh /root/.ngrok_config.sh | |
107 | +} | |
108 | + | |
109 | +function fun_install_ngrok(){ | |
110 | + clear | |
111 | + fun_clangcn.com | |
112 | + checkos | |
113 | + rootness | |
114 | + disable_selinux | |
115 | + fun_set_ngrok_domain | |
116 | +} | |
117 | + | |
118 | +function pre_install(){ | |
119 | + echo "install ngrok,please wait..." | |
120 | + apt-get update -y | |
121 | + apt-get install -y build-essential mercurial git nano screen curl openssl libcurl4-openssl-dev | |
122 | + cd /root | |
123 | + # Download shadowsocks chkconfig file | |
124 | + if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then | |
125 | + if [ ! -s /root/go1.6.linux-amd64.tar.gz ]; then | |
126 | + if ! wget http://www.golangtc.com/static/go/1.6/go1.6.linux-amd64.tar.gz; then | |
127 | + echo "Failed to download go1.6.linux-386.tar.gz file!" | |
128 | + exit 1 | |
129 | + fi | |
130 | + fi | |
131 | + tar zxvf go1.6.linux-amd64.tar.gz | |
132 | + else | |
133 | + if [ ! -s /root/go1.6.linux-386.tar.gz ]; then | |
134 | + if ! wget http://www.golangtc.com/static/go/1.6/go1.6.linux-386.tar.gz; then | |
135 | + echo "Failed to download go1.6.linux-386.tar.gz file!" | |
136 | + exit 1 | |
137 | + fi | |
138 | + fi | |
139 | + tar zxvf go1.6.linux-386.tar.gz | |
140 | + fi | |
141 | + mv go/ /usr/local/ | |
142 | + rm -f /usr/bin/go /usr/bin/godoc /usr/bin/gofmt | |
143 | + ln -s /usr/local/go/bin/* /usr/bin/ | |
144 | + cd /usr/local/ | |
145 | + git clone https://github.com/koolshare/ngrok-1.7.git ngrok | |
146 | + export GOPATH=/usr/local/ngrok/ | |
147 | + cd ngrok | |
148 | + sed -i 's;code.google.com\/p\/log4go;github.com\/keepeye\/log4go;g' src/ngrok/log/logger.go | |
149 | + openssl genrsa -out rootCA.key 2048 | |
150 | + openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=$NGROK_DOMAIN" -days 5000 -out rootCA.pem | |
151 | + openssl genrsa -out server.key 2048 | |
152 | + openssl req -new -key server.key -subj "/CN=$NGROK_DOMAIN" -out server.csr | |
153 | + openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 5000 | |
154 | + rm -f assets/client/tls/ngrokroot.crt assets/server/tls/snakeoil.crt assets/server/tls/snakeoil.key | |
155 | + cp rootCA.pem assets/client/tls/ngrokroot.crt | |
156 | + cp server.crt assets/server/tls/snakeoil.crt | |
157 | + cp server.key assets/server/tls/snakeoil.key | |
158 | + cd /usr/local/ngrok/src/github.com/gorilla | |
159 | + git clone https://github.com/gorilla/mux.git | |
160 | + git clone https://github.com/gorilla/context.git | |
161 | + cd /usr/local/ngrok/src/github.com/peterbourgon | |
162 | + git clone https://github.com/peterbourgon/diskv.git | |
163 | + cd /usr/local/ngrok/src/github.com/petar | |
164 | + git clone https://github.com/petar/GoLLRB.git | |
165 | + if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then | |
166 | + cd /usr/local/go/src | |
167 | + GOOS=linux GOARCH=amd64 ./make.bash | |
168 | + cd /usr/local/ngrok/ | |
169 | + GOOS=linux GOARCH=amd64 make release-server | |
170 | + else | |
171 | + cd /usr/local/go/src | |
172 | + GOOS=linux GOARCH=386 ./make.bash | |
173 | + cd /usr/local/ngrok/ | |
174 | + GOOS=linux GOARCH=386 make release-server | |
175 | + fi | |
176 | + if [ -s /usr/local/ngrok/bin/ngrokd ]; then | |
177 | + config_runshell_ngrok | |
178 | + clear | |
179 | + fun_clangcn.com | |
180 | + echo "Congratulations, Ngrok install completed!" | |
181 | + echo -e "Please run script \033[32m\033[01m/root/ngrok.sh\033[0m start ngrok." | |
182 | + echo -e "Your Domain: \033[32m\033[01m${NGROK_DOMAIN}\033[0m" | |
183 | + echo -e "Your Ngrok password: \033[32m\033[01m${ngrok_pass}\033[0m" | |
184 | + echo -e "Default http_port:\033[32m\033[01m80\033[0m,https_port:\033[32m\033[01m443\033[0m,remote_port:\033[32m\033[01m4443\033[0m" | |
185 | + echo "Welcome to visit:http://clang.cn/blog/" | |
186 | + echo "Enjoy it!" | |
187 | + else | |
188 | + echo "" | |
189 | + echo "Shadowsocks install failed! please view $HOME/ngrok_install.log." | |
190 | + exit 1 | |
191 | + fi | |
192 | + | |
193 | + shell_run_end=`date "+%Y-%m-%d %H:%M:%S"` #shell run end time | |
194 | + time_distance=$(expr $(date +%s -d "$shell_run_end") - $(date +%s -d "$shell_run_start")); | |
195 | + hour_distance=$(expr ${time_distance} / 3600) ; | |
196 | + hour_remainder=$(expr ${time_distance} % 3600) ; | |
197 | + min_distance=$(expr ${hour_remainder} / 60) ; | |
198 | + min_remainder=$(expr ${hour_remainder} % 60) ; | |
199 | + echo -e "Shell run time is \033[32m \033[01m${hour_distance} hour ${min_distance} min ${min_remainder} sec\033[0m" | |
200 | +} | |
201 | +rm -f $HOME/ngrok_install.log | |
202 | +fun_install_ngrok 2>&1 | tee $HOME/ngrok_install.log | |
203 | +exit 0 | ... | ... |