Skip to content

Commit 9581edc

Browse files
authoredDec 20, 2023
Serve html page to download cacert file (#398)
* serve html page to download cacert file * fix lint err * add favicon
1 parent 5e104c4 commit 9581edc

File tree

8 files changed

+232
-8
lines changed

8 files changed

+232
-8
lines changed
 

‎internal/runner/options.go

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package runner
22

33
import (
4-
"fmt"
54
"math"
65
"os"
76
"path/filepath"
@@ -278,7 +277,6 @@ func (options *Options) parseLoggerConfig() error {
278277
if err != nil {
279278
return err
280279
}
281-
fmt.Println(expandedData)
282280

283281
options.Kafka = config.Kafka
284282
options.Elastic = config.Elastic

‎pkg/certs/mitm.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,22 @@ func GetMitMConfig() *mitm.Config {
4343
}
4444

4545
func SaveCAToFile(filename string) error {
46-
buffer := &bytes.Buffer{}
47-
err := pem.Encode(buffer, &pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw})
46+
buffer, err := GetRawCA()
4847
if err != nil {
4948
return err
5049
}
5150
return os.WriteFile(filename, buffer.Bytes(), 0600)
5251
}
5352

53+
func GetRawCA() (*bytes.Buffer, error) {
54+
buffer := &bytes.Buffer{}
55+
err := pem.Encode(buffer, &pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw})
56+
if err != nil {
57+
return nil, err
58+
}
59+
return buffer, nil
60+
}
61+
5462
func SaveKeyToFile(filename string) error {
5563
buffer := &bytes.Buffer{}
5664
err := pem.Encode(buffer, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(pkey)})

‎proxy.go

+45-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/http"
1212
"net/http/httputil"
1313
"net/url"
14+
"os"
1415
"strconv"
1516
"strings"
1617

@@ -266,11 +267,18 @@ func (p *Proxy) Run() error {
266267
p.httpProxy.SetRequestModifier(p)
267268
p.httpProxy.SetResponseModifier(p)
268269

270+
l, err := net.Listen("tcp", p.options.ListenAddrHTTP)
271+
if err != nil {
272+
gologger.Fatal().Msgf("failed to setup listener got %v", err)
273+
}
274+
// serve web page to download ca cert
269275
go func() {
270-
l, err := net.Listen("tcp", p.options.ListenAddrHTTP)
271-
if err != nil {
272-
gologger.Fatal().Msgf("failed to setup listener got %v", err)
273-
}
276+
//fmt.Println("web page listening on", p.options.ListenAddrHTTP+"/")
277+
gologger.Fatal().Msgf("%v", serveWebPage(l))
278+
}()
279+
280+
go func() {
281+
//fmt.Println("proxy listening on", p.options.ListenAddrHTTP)
274282
gologger.Fatal().Msgf("%v", p.httpProxy.Serve(l))
275283
}()
276284
}
@@ -466,3 +474,36 @@ func NewProxy(options *Options) (*Proxy, error) {
466474
func (p *Proxy) httpTunnelDialer(ctx context.Context, network, addr string) (net.Conn, error) {
467475
return p.socks5tunnel.MakeTunnel(nil, nil, p.bufioPool, addr)
468476
}
477+
478+
func serveWebPage(l net.Listener) error {
479+
cwd, err := os.Getwd()
480+
if err != nil {
481+
return fmt.Errorf("failed to get current working directory: %v", err)
482+
}
483+
absStaticDirPath := strings.Join([]string{strings.Split(cwd, "cmd")[0], "static"}, "/")
484+
485+
mux := http.NewServeMux()
486+
serveStatic := http.FileServer(http.Dir(absStaticDirPath))
487+
mux.Handle("/", serveStatic)
488+
// download ca cert
489+
mux.HandleFunc("/cacert", func(w http.ResponseWriter, r *http.Request) {
490+
buffer, err := certs.GetRawCA()
491+
if err != nil {
492+
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
493+
gologger.Error().Msgf("failed to get raw CA: %v", err)
494+
return
495+
}
496+
w.Header().Set("Content-Type", "application/octet-stream")
497+
w.Header().Set("Content-Disposition", "attachment; filename=\"proxify.pem\"")
498+
if _, err := w.Write(buffer.Bytes()); err != nil {
499+
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
500+
gologger.Error().Msgf("failed to write raw CA: %v", err)
501+
return
502+
}
503+
})
504+
505+
server := &http.Server{
506+
Handler: mux,
507+
}
508+
return server.Serve(l)
509+
}

‎static/coding.png

14.6 KB
Loading

‎static/index.html

+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<link rel="icon" type="image/ico" href="pd-favicon.ico">
5+
<title>Proxify</title>
6+
<style>
7+
body {
8+
background:
9+
linear-gradient(to right, #080808 3px, transparent 3px),
10+
linear-gradient(to bottom, #080808 3px, transparent 3px);
11+
background-color: #000023;
12+
background-size: 6px 6px;
13+
color: white;
14+
font-family: Arial, sans-serif;
15+
text-align: center;
16+
margin: 0;
17+
animation: space 5s linear infinite;
18+
}
19+
20+
@keyframes space {
21+
0% {
22+
background-position: 0 0;
23+
}
24+
100% {
25+
background-position: 6px 6px;
26+
}
27+
}
28+
29+
.container {
30+
max-width: 800px;
31+
margin: 0 auto;
32+
padding: 20px;
33+
overflow: hidden;
34+
}
35+
36+
.top-logo {
37+
width: 130px;
38+
height: auto;
39+
padding: 10px;
40+
position: absolute;
41+
top: 10px;
42+
left: 20px;
43+
box-shadow: 0 0 0px 0px #001f3f;
44+
animation: fadeIn 3s;
45+
}
46+
47+
.top-logo:hover {
48+
transform: scale(1.1);
49+
}
50+
51+
.proxify-logo {
52+
width: 200px;
53+
height: auto;
54+
padding: 10px;
55+
position: absolute;
56+
top: 30px;
57+
left: 50%;
58+
transform: translateX(-50%);
59+
box-shadow: -1px 1px 0px 0px #001f3f;
60+
animation: fadeIn 4s;
61+
}
62+
63+
.proxify-logo:hover {
64+
box-shadow: 0px 0px 200px 0px #001f3f;
65+
animation: fadeIn 4s;
66+
}
67+
68+
.version {
69+
position: absolute;
70+
top: 50%;
71+
right: 20px;
72+
transform: translateY(-50%);
73+
color: #007BFF;
74+
}
75+
76+
.download-button {
77+
background: #000;
78+
color: white;
79+
padding: 15px 20px;
80+
text-decoration: none;
81+
border-radius: 5px;
82+
position: absolute;
83+
top: 40px;
84+
right: 20px;
85+
transition: all 0.2s ease-in-out;
86+
box-shadow: 0 0 5px 2px #001f3f;
87+
animation: fadeIn 5s;
88+
}
89+
90+
.download-button:hover {
91+
background: #fff;
92+
color: #000;
93+
transform: scale(1.1);
94+
box-shadow: 0 0 5px 7px #001f3f;
95+
}
96+
97+
.logo-link {
98+
text-decoration: none;
99+
color: white;
100+
}
101+
102+
.center-text {
103+
font-family: 'Roboto', sans-serif;
104+
font-size: 20px;
105+
color: #FFFFFF;
106+
padding: 20px;
107+
line-height: 1.6;
108+
position: absolute;
109+
top: 50%;
110+
left: 50%;
111+
transform: translate(-50%, -50%);
112+
animation: fadeIn 6s;
113+
}
114+
115+
@keyframes fadeIn {
116+
from {
117+
opacity: 0;
118+
}
119+
to {
120+
opacity: 1;
121+
}
122+
}
123+
124+
.code-book {
125+
position: absolute;
126+
bottom: 50px;
127+
right: 50px;
128+
animation: fadeIn 10s;
129+
box-shadow: 0 0 2px 2px #001f3f;
130+
border-radius: 50%;
131+
}
132+
133+
.code-book:hover {
134+
transform: scale(1.1);
135+
box-shadow: 0 0 4px 4px #001f3f;
136+
}
137+
.code-book-img {
138+
width: 55px;
139+
height: 50px;
140+
bottom: 20px;
141+
right: 20px;
142+
}
143+
144+
.code-book-link {
145+
text-decoration: none;
146+
color: white;
147+
}
148+
</style>
149+
</head>
150+
<body>
151+
<div class="container">
152+
<a href="https://github.com/projectdiscovery" class="logo-link">
153+
<img src="pd-logo.png" alt="Projectdiscovery Logo" class="top-logo">
154+
</a>
155+
156+
<a href="https://github.com/projectdiscovery/proxify#readme" class="logo-link">
157+
<img src="proxify-logo-white.png" alt="Proxify Logo" class="proxify-logo">
158+
</a>
159+
160+
<a href="/cacert" class="download-button">Download Certificate</a>
161+
162+
<div class="center-text">
163+
Swiss Army Knife Proxy for rapid deployments. <br>
164+
Supports multiple operations such as request/response dump,<br>
165+
filtering and manipulation via DSL language, upstream HTTP/Socks5 proxy.<br>
166+
Additionally, a replay utility allows to import the dumped traffic <br>
167+
(request/responses with correct domain name) into BurpSuite or <br>
168+
any other proxy by simply setting the upstream proxy to proxify.
169+
</div>
170+
171+
<div class="code-book">
172+
<a href="https://github.com/projectdiscovery/proxify" class="code-book-link">
173+
<img src="coding.png" alt="Code Book" class="code-book-img">
174+
</div>
175+
</div>
176+
</body>
177+
</html>

‎static/pd-favicon.ico

198 KB
Binary file not shown.

‎static/pd-logo.png

37.7 KB
Loading

‎static/proxify-logo-white.png

48.7 KB
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.