Skip to content

Commit

Permalink
Merge branch 'http1_updates' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Ne0nd0g committed Aug 19, 2019
2 parents 45c83c5 + d43108a commit ace580b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 14 deletions.
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ XBUILD=-X main.build=${BUILD} -X github.com/Ne0nd0g/merlin/pkg/agent.build=${BUI
URL ?= https://127.0.0.1:443
XURL=-X main.url=${URL}
PSK ?= merlin
PROXY ?=
XPROXY = -X main.proxy=$(PROXY)
XPSK=-X main.psk=${PSK}
LDFLAGS=-ldflags "-s -w ${XBUILD} ${XURL} ${XPSK} ${XPROXY} -buildid="
WINAGENTLDFLAGS=-ldflags "-s -w ${XBUILD} ${XURL} ${XPSK} ${XPROXY} -H=windowsgui -buildid="
PROXY ?=
XPROXY =-X main.proxy=$(PROXY)
HOST ?=
XHOST =-X main.host=$(HOST)
PROTO ?= h2
XPROTO =-X main.protocol=$(PROTO)
LDFLAGS=-ldflags "-s -w ${XBUILD} ${XPROTO} ${XURL} ${XHOST} ${XPSK} ${XPROXY} -buildid="
WINAGENTLDFLAGS=-ldflags "-s -w ${XBUILD} ${XPROTO} ${XURL} ${XHOST} ${XPSK} ${XPROXY} -H=windowsgui -buildid="
# TODO Update when Go1.13 is released https://stackoverflow.com/questions/45279385/remove-file-paths-from-text-directives-in-go-binaries
GCFLAGS=-gcflags=all=-trimpath=$(GOPATH)
ASMFLAGS=-asmflags=all=-trimpath=$(GOPATH)# -asmflags=-trimpath=$(GOPATH)
Expand Down
5 changes: 3 additions & 2 deletions cmd/merlinagent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (

// GLOBAL VARIABLES
var url = "https://127.0.0.1:443"
var protocol = "h2"
var build = "nonRelease"
var psk = "merlin"
var proxy = ""
Expand All @@ -45,7 +46,7 @@ func main() {
debug := flag.Bool("debug", false, "Enable debug output")
flag.StringVar(&url, "url", url, "Full URL for agent to connect to")
flag.StringVar(&psk, "psk", psk, "Pre-Shared Key used to encrypt initial communications")
protocol := flag.String("proto", "h2", "Protocol for the agent to connect with [h2, hq, https/1.1]")
flag.StringVar(&protocol, "proto", protocol, "Protocol for the agent to connect with [https (HTTP/1.1), h2 (HTTP/2), hq (QUIC or HTTP/3.0)]")
flag.StringVar(&proxy, "proxy", proxy, "Hardcoded proxy to use for http/1.1 traffic only that will override host configuration")
flag.StringVar(&host, "host", host, "HTTP Host header")
sleep := flag.Duration("sleep", 30000*time.Millisecond, "Time for agent to sleep")
Expand All @@ -59,7 +60,7 @@ func main() {
}

// Setup and run agent
a, err := agent.New(*protocol, url, host, psk, proxy, *verbose, *debug)
a, err := agent.New(protocol, url, host, psk, proxy, *verbose, *debug)
if err != nil {
if *verbose {
color.Red(err.Error())
Expand Down
2 changes: 1 addition & 1 deletion cmd/prism/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func main() {
flag.BoolVar(&debug, "debug", false, "Enable debug output")
flag.StringVar(&url, "url", url, "Full URL for agent to connect to")
flag.StringVar(&psk, "psk", psk, "Pre-Shared Key used to encrypt initial communications")
protocol := flag.String("proto", "h2", "Protocol for the agent to connect with [h2, hq]")
protocol := flag.String("proto", "h2", "Protocol for the agent to connect with [https (HTTP/1.1), h2 (HTTP/2), hq (QUIC or HTTP/3.0)]")
flag.StringVar(&proxy, "proxy", proxy, "Hardcoded proxy to use for http/1.1 traffic only that will override host configuration")
flag.StringVar(&host, "host", host, "HTTP Host header")
flag.Usage = usage
Expand Down
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
go.dedis.ch/fixbuf v1.0.3 h1:hGcV9Cd/znUxlusJ64eAlExS+5cJDIyTyEG+otu5wQs=
go.dedis.ch/fixbuf v1.0.3/go.mod h1:yzJMt34Wa5xD37V5RTdmp38cz3QhMagdGoem9anUalw=
go.dedis.ch/kyber v0.0.0-20170824083343-8f53a63e87fd h1:tuKhSPASZIyBYK+wcd403NJfOXd+2hny39q+ufdZPYY=
go.dedis.ch/kyber v0.0.0-20170824083343-8f53a63e87fd+incompatible h1:AAAaZPJwirRhDa0UFezb2UAZA+isQOfu2TgY4nXENnA=
go.dedis.ch/kyber v0.0.0-20170824083343-8f53a63e87fd/go.mod h1:X2QdOMFu0WkZABwU1fvI+GQSkXIazv2I9qCVL+Tx1Wc=
go.dedis.ch/kyber v0.0.0-20170824083343-8f53a63e87fd+incompatible h1:AAAaZPJwirRhDa0UFezb2UAZA+isQOfu2TgY4nXENnA=
go.dedis.ch/kyber v0.0.0-20170824083343-8f53a63e87fd+incompatible/go.mod h1:X2QdOMFu0WkZABwU1fvI+GQSkXIazv2I9qCVL+Tx1Wc=
go.dedis.ch/kyber v0.0.0-20180509082236-f066f8d2cd58 h1:7z4wJ1qona0Jczun7WPDjOD07V0E3VAyelGBd0TlcfU=
go.dedis.ch/kyber v0.0.0-20180509082236-f066f8d2cd58/go.mod h1:X2QdOMFu0WkZABwU1fvI+GQSkXIazv2I9qCVL+Tx1Wc=
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func getClient(protocol string, proxyURL string) (*http.Client, error) {
TLSClientConfig: TLSConfig,
}
return &http.Client{Transport: transport}, nil
case "http/1.1":
case "https":
if proxyURL != "" {
rawURL, errProxy := url.Parse(proxyURL)
if errProxy != nil {
Expand Down
7 changes: 4 additions & 3 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,11 @@ func menuAgent(cmd []string) {
for k, v := range agents.Agents {
// Convert proto (i.e. h2 or hq) to user friendly string
var proto string
if v.Proto == "h2" {
if v.Proto == "https" {
proto = "HTTP/1.1 (https)"
} else if v.Proto == "h2" {
proto = "HTTP/2 (h2)"
}
if v.Proto == "hq" {
} else if v.Proto == "hq" {
proto = "QUIC (hq)"
}

Expand Down
10 changes: 8 additions & 2 deletions pkg/servers/http2/http2.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (s *Server) agentHandler(w http.ResponseWriter, r *http.Request) {
var errValidate error

// Set return headers
w.Header().Set("Content-Type", "application/octet-stream")
//w.Header().Set("Content-Type", "application/octet-stream")

// Validate JWT using HTTP interface JWT key; Given to authenticated agents by server
agentID, errValidate = validateJWT(strings.Split(token, " ")[1], s.jwtKey)
Expand Down Expand Up @@ -441,6 +441,9 @@ func (s *Server) agentHandler(w http.ResponseWriter, r *http.Request) {
return
}

// Set return headers
w.Header().Set("Content-Type", "application/octet-stream")

// Encode JWE into gob
errJWEBuffer := gob.NewEncoder(w).Encode(jwe)
if errJWEBuffer != nil {
Expand All @@ -450,7 +453,7 @@ func (s *Server) agentHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404)
return
}
w.WriteHeader(404)

return
}
if core.Verbose {
Expand Down Expand Up @@ -577,6 +580,9 @@ func (s *Server) agentHandler(w http.ResponseWriter, r *http.Request) {
message("warn", errJWE.Error())
}

// Set return headers
w.Header().Set("Content-Type", "application/octet-stream")

// Encode JWE to GOB and send it to the agent
errEncode := gob.NewEncoder(w).Encode(jwe)
if errEncode != nil {
Expand Down

0 comments on commit ace580b

Please sign in to comment.