Skip to content

Commit

Permalink
- Added custom headers to curl-style command and IP address recovery …
Browse files Browse the repository at this point in the history
…to netcat-related command
  • Loading branch information
JayBeale committed Aug 14, 2020
1 parent 7cb254e commit 09caca3
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 3 deletions.
41 changes: 41 additions & 0 deletions http_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"net"
"net/http"
)

Expand Down Expand Up @@ -132,3 +133,43 @@ func GetRequest(url string, headers []HeaderLine, ignoreTLSErrors bool) string {

return string(reponse)
}

// GetMyIPAddressesNative gets a list of IP addresses available via Golang's Net library
func GetMyIPAddressesNative() []string {

var ipAddresses []string

ifaces, err := net.Interfaces()
if err != nil {
println("ERROR: could not get interface list")
return nil
}
for _, iface := range ifaces {
addrs, err := iface.Addrs()
if err != nil {
println("ERROR: could not get interface information")
return nil
}

var allIPs []net.IP

for _, addr := range addrs {
var ip net.IP
switch v := addr.(type) {
case *net.IPNet:
ip = v.IP
case *net.IPAddr:
ip = v.IP
}

ipString := ip.String()
if ipString != "127.0.0.1" {
println(ipString)
ipAddresses = append(ipAddresses, ipString)
allIPs = append(allIPs, ip)
}

}
}
return ipAddresses
}
53 changes: 50 additions & 3 deletions peirates.go
Original file line number Diff line number Diff line change
Expand Up @@ -995,8 +995,8 @@ Off-Menu +
[91] Make an HTTP request (GET or POST) to a user-specified URL [curl]
[exit] Exit Peirates
----------------------------------------------------------------
Peirates:># `)
----------------------------------------------------------------`)
fmt.Printf("Peirates:># ")

// Banner items to implement

Expand Down Expand Up @@ -1237,6 +1237,11 @@ Leave off the "kubectl" part of the command. For example:
// [20] Gain a reverse rootshell by launching a hostPath / pod
case "20", "attack-pod-hostpath-mount", "attack-hostpath-mount", "attack-pod-mount", "attack-hostmount-pod":
allPods := getPodList(connectionString)
// TODO: Tell the user what IP address they are on:
// ip addr | grep inet | grep -v inet6 | grep -v "host lo" | awk '{print $2}' | awk -F\/ '{print $1}'
println("Your IP addresses: ")
GetMyIPAddressesNative()

println("What IP and Port will your netcat listener be listening on?")
var ip, port string
println("IP:")
Expand Down Expand Up @@ -1541,6 +1546,9 @@ Leave off the "kubectl" part of the command. For example:
}
}

// TODO: Can we abstract the HTTP portion of this into http_utils.go
// the way we did with GetRequest()?

// Set up an http client
httpClient := &http.Client{}
if httpsPresent {
Expand All @@ -1567,7 +1575,6 @@ Leave off the "kubectl" part of the command. For example:
// Request a parameter name

fmt.Println("[+] Enter a parameter or a blank line to finish entering parameters: ")

input, _ = readLine()

inputParameter = strings.TrimSpace(input)
Expand All @@ -1583,6 +1590,34 @@ Leave off the "kubectl" part of the command. For example:

}

// Store the headers in a list
var headers []HeaderLine

inputHeader := "undefined"

fmt.Println("[+] Specify custom header lines, if desired, entering the Header name, hitting Enter, then the Header value.")
for inputHeader != "" {
// Request a header name

fmt.Println("[+] Enter a header name or a blank line if done: ")
input, _ = readLine()

inputHeader = strings.TrimSpace(input)

if inputHeader != "" {
// Request a header rhs (value)
fmt.Println("[+] Enter a value for " + inputHeader + ":")
input, _ = readLine()

// Add the header value to the list
var header HeaderLine
header.LHS = inputHeader
header.RHS = input
headers = append(headers, header)
}

}

// Store a URL starting point
urlWithData := fullURL

Expand Down Expand Up @@ -1623,9 +1658,21 @@ Leave off the "kubectl" part of the command. For example:

fmt.Println("[+] Using method " + method + " for URL " + urlWithData)

// Build the request, adding in any headers found so far.
request, err := http.NewRequest(method, fullURL, nil)
for _, header := range headers {
request.Header.Add(header.LHS, header.RHS)
}

// For posts, we replace the request -- can we combine the code
// just above with this code by getting the request variable scoped
// outside this if block?
if method != "GET" {
request, err = http.NewRequest(method, fullURL, dataSection)
for _, header := range headers {
request.Header.Add(header.LHS, header.RHS)
}

request.Header.Add("Content-Length", contentLength)
}

Expand Down

0 comments on commit 09caca3

Please sign in to comment.