Skip to content

Commit

Permalink
new: add support for redirecting HTTP to HTTPS #29
Browse files Browse the repository at this point in the history
  • Loading branch information
ohpe committed Jul 27, 2020
1 parent ee15c6c commit c3fbb85
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 5 deletions.
6 changes: 5 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

"listener": {
"ip": "0.0.0.0",
"port": 443,
"port": 8443,
"HTTPtoHTTPS": {
"enabled": true,
"HTTPport": 8080
}
},

"skipContentType": [
Expand Down
1 change: 1 addition & 0 deletions config/dropbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"listener": {
"ip": "0.0.0.0",
"port": 443,
"HTTPtoHTTPS": true
},

"skipContentType": [
Expand Down
1 change: 1 addition & 0 deletions config/github.com.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"listener": {
"ip": "0.0.0.0",
"port": 443,
"HTTPtoHTTPS": true
},

"skipContentType": [
Expand Down
1 change: 1 addition & 0 deletions config/google.com.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"listener": {
"ip": "0.0.0.0",
"port": 443,
"HTTPtoHTTPS": true
},

"skipContentType": [
Expand Down
10 changes: 6 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ func main() {
s.HandleFood(w, r)
})




listeningAddress := fmt.Sprintf("%s:%d", sess.Config.Proxy.Listener.IP, sess.Config.Proxy.Listener.Port)
lline := fmt.Sprintf("Muraena is alive on %s\n[ %s ] ==> [ %s ]", tui.Green(listeningAddress),
tui.Yellow(sess.Config.Proxy.Phishing), tui.Green(sess.Config.Proxy.Target))
Expand All @@ -116,6 +113,12 @@ func main() {
CertPool: sess.Config.TLS.Root,
}

if sess.Config.Proxy.Listener.HTTPtoHTTPS.Enabled {
// redirect HTTP > HTTPS
listingHTTP := fmt.Sprintf("%s:%d", sess.Config.Proxy.Listener.IP, sess.Config.Proxy.Listener.HTTPtoHTTPS.HTTPport)
go http.ListenAndServe(listingHTTP, proxy.RedirectToHTTPS(sess.Config.Proxy.Listener.Port))
}

if err := tlsServer.ServeTLS(listeningAddress); err != nil {
log.Fatal("Error binding Muraena on HTTPS: %s", err)
}
Expand All @@ -126,5 +129,4 @@ func main() {
}
}


}
18 changes: 18 additions & 0 deletions proxy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -45,6 +46,23 @@ type SessionType struct {
Replacer *Replacer
}

func RedirectToHTTPS(port int) http.HandlerFunc {

return func(w http.ResponseWriter, req *http.Request) {

var re = regexp.MustCompile(`(:\d+)$`)
host := re.ReplaceAllString(req.Host, "")

newURL := fmt.Sprintf("https://%s%s", host, req.URL.String())
if port != 443 {
newURL = fmt.Sprintf("https://%s:%d%s", host, port, req.URL.String())
}

log.Info("Redirecting HTTP to HTTPS: %s", newURL)
http.Redirect(w, req, newURL, http.StatusMovedPermanently)
}
}

func (muraena *MuraenaProxy) RequestBodyProcessor(request *http.Request, track *tracking.Trace, base64 Base64) (err error) {
if request.Body != nil {

Expand Down
4 changes: 4 additions & 0 deletions session/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ type Configuration struct {
Listener struct {
IP string `json:"IP"`
Port int `json:"port"`
HTTPtoHTTPS struct {
Enabled bool `json:"enabled"`
HTTPport int `json:"HTTPport"`
} `json:"HTTPtoHTTPS"`
} `json:"listener"`

SkipContentType []string `json:"skipContentType"`
Expand Down

0 comments on commit c3fbb85

Please sign in to comment.