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

Added ipv4cat service to help inspect breakouts #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
53 changes: 47 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"io/ioutil"
"log"
"math/rand"
"net"
"bufio"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -52,6 +54,7 @@ type service struct {
var services = map[string]service{
"letmeout": service{url: "go-out.letmeoutofyour.net", match: "w00tw00t"},
"allports": service{url: "allports.exposed", match: "<p>Open Port</p>"},
"ipv4cat": service{url: "ipv4.cat", match: ""},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets extract TCP services to their own type.

}

// maxedWaitGroup is a type to control the maximum
Expand Down Expand Up @@ -132,7 +135,7 @@ func (service *service) testHTTPEgress(port int) {
if *invertPtr {
_, err := client.Get(url.String())
if err != nil {
fmt.Printf("[!] Looks like we have no egress using %s on port %d\n", url.String(), port)
fmt.Printf("[!] Looks like we have no egress using %s on port %d.\n", url.String(), port)
}
return
}
Expand All @@ -146,19 +149,52 @@ func (service *service) testHTTPEgress(port int) {
panic(err)
}
if strings.Contains(string(body), service.match) && !*invertPtr {
fmt.Printf("[!] Looks like we have egress using %s on port %d\n", url.String(), port)
fmt.Printf("[!] Looks like we have egress using %s on port %d.\n", url.String(), port)
}
}

// testTCPEgress tests if a specific port is allowed to connect
// to the internet via a raw TCP connection by and keeps note of the
// breakout IP address
func (service *service) testTCPEgress(port int) {

timeout := time.Duration(*timeoutPtr) * time.Second

connection := net.Dialer{Timeout: timeout}

conn, err := connection.Dial("tcp", service.url + ":" + strconv.Itoa(port))

if err != nil {
if *invertPtr {
_, err := connection.Dial("tcp", service.url + ":" + strconv.Itoa(port))
if err != nil {
fmt.Printf("[!] Looks like we have no TCP egress using %s on port %d.\n", service.url, port)
}
return
}

return // if the first one errored already, don't continue
}

message, _ := bufio.NewReader(conn).ReadString('\n')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets check the error here in case we never reach the \n.


addr := net.ParseIP(strings.TrimSuffix(message, "\n"))

if addr.To4() != nil && addr.To16() != nil && !*invertPtr {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To16() may be enough for v4 && v6 checking.

fmt.Printf("[!] Looks like we have TCP egress using %s on port %d and it broke out from %s\n", service.url, port, strings.TrimSuffix(message, "\n"))
}

}

func validateFlags() bool {

// Flag Validation
if !validService(servicePtr) {
fmt.Printf("%s is an invalid service. Please choose 'letmeout' or 'allports'\n", *servicePtr)
fmt.Printf("%s is an invalid service. Please choose 'letmeout', 'allports' or 'ipv4cat'.\n", *servicePtr)
return false
}

if *useHTTPSPtr && *servicePtr != "letmeout" {
if *useHTTPSPtr && *servicePtr != "letmeout" && *servicePtr != "ipv4cat" {
fmt.Println("Only the 'letmeout' service supports HTTPS, disabling HTTPS checking.")
*useHTTPSPtr = false
}
Expand All @@ -183,7 +219,7 @@ func validateFlags() bool {

func main() {

servicePtr = flag.String("service", "letmeout", "Use 'letmeout' or 'allports' for this run.")
servicePtr = flag.String("service", "letmeout", "Use 'letmeout', 'allports' or 'ipv4cat' for this run.")
startPortPtr = flag.Int("start", 1, "The start port to use.")
endPortPtr = flag.Int("end", 65535, "The end port to use.")
concurrentPtr = flag.Int("w", 5, "Number of concurrent workers to spawn.")
Expand Down Expand Up @@ -255,7 +291,12 @@ func main() {
time.Sleep(time.Second * time.Duration(rand.Intn(10)))
}

tester.testHTTPEgress(p)
if *servicePtr == "ipv4cat" {
tester.testTCPEgress(p)
} else {
tester.testHTTPEgress(p)
}

atomic.AddInt64(&status.Done, 1)
atomic.AddInt64(&status.Updated, 1)
bar.Render(os.Stdout)
Expand Down