Presented at c0c0n 12 (2019), “Golang for Pentesters / RedTeamers” introduces the Go programming language as a practical tool for offensive security work. Across 32 slides, the deck covers why Go suits pentesting and red teaming (cross-platform compiled binaries, no runtime dependencies, rich standard library, active security tooling ecosystem), walks through setting up a Go development environment, and demonstrates essential modules for pentesting tasks such as DNS lookups, port scanning, web scraping, and JSON handling. It closes with building and cross-compiling binaries, Docker deployment, code security with gosec, dependency management, binary size reduction, and automating the entire build process with Makefiles.
Summary
The talk opens with a disclaimer: it is focused on Golang or the Go programming language, will not do performance comparisons or debate other languages, and will not deep dive but rather explore golang to give people a headstart. The why section frames Go as combining the ease of programming of an interpreted, dynamically typed language with the efficiency and safety of a statically typed, compiled one. For pentesters the pitch is concrete: cross-platform across Windows, Linux, and Mac, a fat static binary by default with no third-party dependency, not even a runtime, and the ability to run in bare dockers or directly above the kernel. A tools catalogue grounds the argument in what pentesters already use: Gobuster, Bettercap 2.0, GoBot2, GoAT, Cracklord, GoCrack, Merlin, and Vuls, with more findable via the github pentesting topic page filtered on Go.
The setup section covers installing Go from binaries at golang.org/dl or via apt/yum, and the two paths that confuse newcomers: GOPATH (where packages are installed, typically under the user home in go) and GOROOT. Hello World demonstrates package main, import fmt, and func main, run via go run or compiled via go build.
The modules section opens with the philosophy that these days we do not write programs but collect modules and stick them together, so a language is as good as the modules it provides. The walkthrough covers argparse for command-line inputs; the net package for DNS lookups with the tip that a registered domain always has an NS record; publicsuffix for pulling effective TLD plus one out of arbitrary strings like blog.abc.com; encoding/json for marshaling structured output; port scanning via net.Dial and net.DialTimeout with timeouts; and soup, inspired by Python’s BeautifulSoup, for scraping.
The optimization and operations arc covers gofmt applying a uniform formatting syntax and ending formatting debates, binary size reduction via go build -ldflags ‘-s -w’ followed by UPX compression, Docker deployment in a scratch container, and cross-compiling with env GOOS=linux GOARCH=amd64 style commands.
The closing sections turn to hygiene and automation. Secure your code: run periodic checks with gosec, recursively or with specific or excluded rule sets, with a note that Snyk has recently introduced Go module dependency checks. Update management: build after updating the dependency (go get -u against the module URL) to ensure building against latest. A complete Makefile then automates everything: linux, windows, and mac builds, a docker target building the scratch image, clean, check, updatedep, and combined all and complete targets. The final slides note that fat binaries are hard to reverse engineer, suiting red team tooling, and that reproducible builds, producing byte-by-byte matching binaries, are achieved by maintaining a consistent build environment, provided via Docker builds.
Key Themes
- Why Go for pentesters (and why not): Go combines the ease of an interpreted dynamically-typed language with the efficiency and safety of a statically-typed compiled one, offering cross-platform support, fat static binaries by default with no third-party dependencies or runtime, and scratch Docker execution; the honest counterpoint is a young ecosystem, GitHub dependence, large monolithic binaries, and weak GUI libraries.
- Existing security tools written in Go: Gobuster, Bettercap, GoBot2, GoAT, Cracklord, GoCrack, Merlin, and Vuls, with more available via the GitHub pentesting topic filtered on Go.
- Environment setup and fundamentals: installing Go via binary downloads or package managers, configuring GOPATH (typically ~/go) and GOROOT (/usr/lib default), adding the local Go path to PATH, and running Hello World via go run or go build.
- Essential modules for pentesting: argparse for command-line parsing, the net package for DNS lookups with the NS record tip, publicsuffix for domain parsing, encoding/json for structured output, net.Dial/net.DialTimeout for port scanning, and soup for web scraping, with Colly as an alternative.
- Code quality and binary size reduction: gofmt enforces uniform formatting and ends formatting debates; -ldflags ‘-s -w’ trims symbol and DWARF tables, with UPX compression as a further step.
- Docker deployment and cross-compilation: fat binaries with no dependencies run in a scratch (empty) Docker container with a minimal Dockerfile, and cross-compilation uses GOOS/GOARCH environment variables for Linux, Windows, and Mac.
- Code security and dependency management: periodic gosec checks with configurable rule sets, Snyk’s Go module dependency checks, and dependency updates via go get -u followed by a build.
- Build automation, reversing, and reproducible builds: a complete Makefile automates multi-platform builds, Docker packaging, dependency updates, and security checks; fat binaries are hard to reverse engineer, which suits red team implants, and reproducible builds come from a consistent build environment, ideally Docker-based.
Notable Points
- Takeaway: set up a Go development environment and start by building simple pentesting utilities (port scanners, DNS enumerators, web scrapers) using the modules covered: net, soup, argparse, and leverage cross-compilation to build for all target platforms from a single codebase with GOOS/GOARCH environment variables.
- Takeaway: use scratch Docker containers for deploying Go-based tools, creating minimal attack surface and tiny container images since Go binaries have zero runtime dependencies.
- Takeaway: reduce binary sizes with -ldflags ‘-s -w’ compiler flags and UPX compression to make tools less conspicuous for red team operations.
- Takeaway: integrate gosec into your development workflow (and CI/CD via Makefile) to catch security issues in your own pentesting tools before deployment.
- Takeaway: explore existing Go security tools (Gobuster, Bettercap, Merlin, Cracklord) both as ready-to-use utilities and as reference implementations, and take advantage of Go’s difficult-to-reverse-engineer binaries for red team implants and post-exploitation tools where operational security matters.
- The tools catalogue cites specific repositories: github.com/OJ/gobuster, github.com/bettercap/bettercap, github.com/SaturnsVoid/GoBot2, github.com/petercunha/GoAT, github.com/jmmcatee/cracklord, github.com/fireeye/gocrack, github.com/Ne0nd0g/merlin, github.com/future-architect/vuls, plus github.com/topics/pentesting?l=go.
- Go environments hinge on GOPATH (packages installed under ~/go) and GOROOT (/usr/lib default); alternate toolchains install with go get golang.org/dl/go1.13.1, go1.13.1 download, then go1.13.1 version.
- DNS work uses net.LookupIP, net.LookupCNAME, net.LookupAddr, net.LookupNS, net.LookupMX, and net.LookupTXT, with the tip that a registered domain always has an NS record; publicsuffix.EffectiveTLDPlusOne maps blog.abc.com to google.com and test.abc.co.in to abc.co.in.
- Port scanning uses net.Dial or net.DialTimeout (the timeout fires after Timeout seconds; alternative github.com/anvie/port-scanner); gosec runs recursively via gosec ./…, specific rules via gosec -include=G101,G203,G401, exclusions via gosec -exclude=G303.
- The Makefile exposes linux, windows, mac, docker, clean, check, updatedep, all, and complete targets, and the reproducible-builds reference is blog.filippo.io/reproducing-go-binaries-byte-by-byte.
Notable Quotes
“Language is as good as the modules it provides”
“Fat Static Binary by default”
“no 3rd party dependency not even runtime”
“As fat binaries have no dependencies they can run in Scratch”
“gosec is one good code review tool for golang”
“The trick is maintain a consistent build environment”