Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve html page to download cacert file #398

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions internal/runner/options.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package runner

import (
"fmt"
"math"
"os"
"path/filepath"
Expand Down Expand Up @@ -278,7 +277,6 @@ func (options *Options) parseLoggerConfig() error {
if err != nil {
return err
}
fmt.Println(expandedData)

options.Kafka = config.Kafka
options.Elastic = config.Elastic
Expand Down
12 changes: 10 additions & 2 deletions pkg/certs/mitm.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,22 @@ func GetMitMConfig() *mitm.Config {
}

func SaveCAToFile(filename string) error {
buffer := &bytes.Buffer{}
err := pem.Encode(buffer, &pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw})
buffer, err := GetRawCA()
if err != nil {
return err
}
return os.WriteFile(filename, buffer.Bytes(), 0600)
}

func GetRawCA() (*bytes.Buffer, error) {
buffer := &bytes.Buffer{}
err := pem.Encode(buffer, &pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw})
if err != nil {
return nil, err
}
return buffer, nil
}

func SaveKeyToFile(filename string) error {
buffer := &bytes.Buffer{}
err := pem.Encode(buffer, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(pkey)})
Expand Down
49 changes: 45 additions & 4 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"os"
"strconv"
"strings"

Expand Down Expand Up @@ -266,11 +267,18 @@ func (p *Proxy) Run() error {
p.httpProxy.SetRequestModifier(p)
p.httpProxy.SetResponseModifier(p)

l, err := net.Listen("tcp", p.options.ListenAddrHTTP)
if err != nil {
gologger.Fatal().Msgf("failed to setup listener got %v", err)
}
// serve web page to download ca cert
go func() {
l, err := net.Listen("tcp", p.options.ListenAddrHTTP)
if err != nil {
gologger.Fatal().Msgf("failed to setup listener got %v", err)
}
//fmt.Println("web page listening on", p.options.ListenAddrHTTP+"/")
gologger.Fatal().Msgf("%v", serveWebPage(l))
}()

go func() {
//fmt.Println("proxy listening on", p.options.ListenAddrHTTP)
gologger.Fatal().Msgf("%v", p.httpProxy.Serve(l))
}()
}
Expand Down Expand Up @@ -466,3 +474,36 @@ func NewProxy(options *Options) (*Proxy, error) {
func (p *Proxy) httpTunnelDialer(ctx context.Context, network, addr string) (net.Conn, error) {
return p.socks5tunnel.MakeTunnel(nil, nil, p.bufioPool, addr)
}

func serveWebPage(l net.Listener) error {
cwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("failed to get current working directory: %v", err)
}
absStaticDirPath := strings.Join([]string{strings.Split(cwd, "cmd")[0], "static"}, "/")

mux := http.NewServeMux()
serveStatic := http.FileServer(http.Dir(absStaticDirPath))
mux.Handle("/", serveStatic)
// download ca cert
mux.HandleFunc("/cacert", func(w http.ResponseWriter, r *http.Request) {
buffer, err := certs.GetRawCA()
if err != nil {
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
gologger.Error().Msgf("failed to get raw CA: %v", err)
return
}
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", "attachment; filename=\"proxify.pem\"")
if _, err := w.Write(buffer.Bytes()); err != nil {
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
gologger.Error().Msgf("failed to write raw CA: %v", err)
return
}
})

server := &http.Server{
Handler: mux,
}
return server.Serve(l)
}
Binary file added static/coding.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
177 changes: 177 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<!DOCTYPE html>
<html>
<head>
<link rel="icon" type="image/ico" href="pd-favicon.ico">
<title>Proxify</title>
<style>
body {
background:
linear-gradient(to right, #080808 3px, transparent 3px),
linear-gradient(to bottom, #080808 3px, transparent 3px);
background-color: #000023;
background-size: 6px 6px;
color: white;
font-family: Arial, sans-serif;
text-align: center;
margin: 0;
animation: space 5s linear infinite;
}

@keyframes space {
0% {
background-position: 0 0;
}
100% {
background-position: 6px 6px;
}
}

.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
overflow: hidden;
}

.top-logo {
width: 130px;
height: auto;
padding: 10px;
position: absolute;
top: 10px;
left: 20px;
box-shadow: 0 0 0px 0px #001f3f;
animation: fadeIn 3s;
}

.top-logo:hover {
transform: scale(1.1);
}

.proxify-logo {
width: 200px;
height: auto;
padding: 10px;
position: absolute;
top: 30px;
left: 50%;
transform: translateX(-50%);
box-shadow: -1px 1px 0px 0px #001f3f;
animation: fadeIn 4s;
}

.proxify-logo:hover {
box-shadow: 0px 0px 200px 0px #001f3f;
animation: fadeIn 4s;
}

.version {
position: absolute;
top: 50%;
right: 20px;
transform: translateY(-50%);
color: #007BFF;
}

.download-button {
background: #000;
color: white;
padding: 15px 20px;
text-decoration: none;
border-radius: 5px;
position: absolute;
top: 40px;
right: 20px;
transition: all 0.2s ease-in-out;
box-shadow: 0 0 5px 2px #001f3f;
animation: fadeIn 5s;
}

.download-button:hover {
background: #fff;
color: #000;
transform: scale(1.1);
box-shadow: 0 0 5px 7px #001f3f;
}

.logo-link {
text-decoration: none;
color: white;
}

.center-text {
font-family: 'Roboto', sans-serif;
font-size: 20px;
color: #FFFFFF;
padding: 20px;
line-height: 1.6;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation: fadeIn 6s;
}

@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}

.code-book {
position: absolute;
bottom: 50px;
right: 50px;
animation: fadeIn 10s;
box-shadow: 0 0 2px 2px #001f3f;
border-radius: 50%;
}

.code-book:hover {
transform: scale(1.1);
box-shadow: 0 0 4px 4px #001f3f;
}
.code-book-img {
width: 55px;
height: 50px;
bottom: 20px;
right: 20px;
}

.code-book-link {
text-decoration: none;
color: white;
}
</style>
</head>
<body>
<div class="container">
<a href="https://github.com/projectdiscovery" class="logo-link">
<img src="pd-logo.png" alt="Projectdiscovery Logo" class="top-logo">
</a>

<a href="https://github.com/projectdiscovery/proxify#readme" class="logo-link">
<img src="proxify-logo-white.png" alt="Proxify Logo" class="proxify-logo">
</a>

<a href="/cacert" class="download-button">Download Certificate</a>

<div class="center-text">
Swiss Army Knife Proxy for rapid deployments. <br>
Supports multiple operations such as request/response dump,<br>
filtering and manipulation via DSL language, upstream HTTP/Socks5 proxy.<br>
Additionally, a replay utility allows to import the dumped traffic <br>
(request/responses with correct domain name) into BurpSuite or <br>
any other proxy by simply setting the upstream proxy to proxify.
</div>

<div class="code-book">
<a href="https://github.com/projectdiscovery/proxify" class="code-book-link">
<img src="coding.png" alt="Code Book" class="code-book-img">
</div>
</div>
</body>
</html>
Binary file added static/pd-favicon.ico
Binary file not shown.
Binary file added static/pd-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/proxify-logo-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading