Golang For Pentesters
AI Generated Summary
AI Generated Content Disclaimer
Note: This summary is AI-generated and may contain inaccuracies, errors, or omissions. If you spot any issues, please contact the site owner for corrections. Errors or omissions are unintended.
This deck is “Golang for Pentesters / RedTeamers”, presented at c0c0n 12 (2019). Across 32 slides it makes the case for Go as a practical language for offensive security tooling, catalogs existing Go based security tools, walks through environment setup and Go fundamentals, demonstrates essential modules for pentesting tasks (command line parsing, DNS lookups, port scanning, JSON handling, web scraping), and closes with binary size reduction, scratch container deployment, cross-compilation, code security with gosec, dependency management, Makefile automation, reversing considerations, and reproducible builds.
Summary
The deck opens with a disclaimer: the talk is focused on Go or Golang, will not do performance comparisons or debate other languages. The “Why Golang” slide argues Go combines the ease of programming of an interpreted dynamically typed language with the efficiency and safety of a statically typed, compiled language. The offensive advantages listed are cross platform output (Windows, Linux, Mac), fat static binaries by default, no 3rd party dependency not even runtime, and bare docker runs or execution directly above the kernel. The counterweight slide, “Why Not Golang”, is candid: very young ecosystem, dependent on github, large binaries, not so great GUI libraries, and monolithic binaries. A catalog of existing Go security tools follows, discoverable further through github’s pentesting topic with a Go filter. Environment setup covers downloading the binary from golang.org/dl or installing via apt or yum, and understanding GOPATH versus GOROOT.
The modules section sets the philosophy in one line: now a days we dont write programs, we collect modules and stick them together, language is as good as the modules it provides. argparse is positioned as useful for taking command line inputs. The net package demonstrates DNS lookup functions, with the tip that if a domain is registered it will always have a NS record. publicsuffix uses the Public Suffix List data to make an accurate guess of the registered domain. JSON encoding converts Arrays into JSON objects. Port scanning uses net.Dial or net.DialTimeout, with github.com/anvie/port-scanner as the noted alternative. Web requests use soup, inspired by Python’s Beautiful Soup, covering Get, Header and Cookie, HTMLParse, Find and FindAll, sibling navigation, Children, Text and FullText; an example fetches xkcd.com and prints all comic links.
The closing third covers operational concerns. Go follows a uniform code formatting syntax (gofmt). Binary size reduction explains that fat binaries are basically FAT because of the runtime integration: compiler flags omit the symbol table, debug information and DWARF symbol table, plus UPX compression (“Some fat can be trimmed”). Docker deployment shows fat binaries running in Scratch DockerFile with FROM scratch / COPY binary / ENTRYPOINT. Cross-compilation is demonstrated with env GOOS=linux GOARCH=amd64 go build and friends. Securing your code introduces gosec: you can run periodic checks on your own code, gosec is one good code review tool for golang, plus a note that Snyk has recently introduced Go module dependency Checks. A complete Makefile automates linux, windows, mac, docker, clean, check, updatedep, all and complete targets. Reversing Go applications notes FAT binaries are hard to reverse engineer, with case studies suggested as reading. Golang reproducible builds close the deck: byte for byte matching binaries at different systems require a consistent build environment, provided by docker build.
Key Themes
- Why Go for Pentesters: The ease of programming of an interpreted dynamically typed language combined with the efficiency and safety of a statically typed compiled language, aimed to be modern with support for networked and multicore computing.
- Offensive Advantages: Cross platform output (Windows, Linux, Mac), fat static binaries by default, no third party dependency or runtime, and execution in bare docker containers or directly above the kernel.
- Why Not Go: A very young ecosystem, dependence on github for packages, large binaries, weak GUI library support, and monolithic binary output.
- Existing Go Security Tools: Gobuster, Bettercap, GoBot2, GoAT, Cracklord, GoCrack, Merlin, Vuls and more, discoverable through github’s pentesting topic with a Go filter.
- Environment Setup: Binary download or apt/yum install, GOPATH versus GOROOT semantics, and adding the local go path to the system PATH.
- Essential Modules: argparse for command line inputs, net for DNS lookups, publicsuffix for domain guessing, encoding/json for structured output, net.Dial based port scanning, and soup for web scraping.
- Code Quality and Binary Size: Uniform formatting via gofmt, and size trimming through compiler flags (-s, -w) plus UPX compression against the runtime-integration overhead.
- Deployment, Security and Automation: Scratch Dockerfiles exploiting zero runtime dependencies, cross-compilation via GOOS/GOARCH, gosec checks with rule selection, Snyk Go dependency checks, go get -u refreshes, a Makefile automating multi-platform builds, the reversing difficulty of fat binaries, and Docker-based reproducible builds.
Notable Points
- Existing Go security tools cataloged: Gobuster (directory/DNS brute-forcing), Bettercap (network reconnaissance and MITM), GoBot2 (bot framework), GoAT (Go Application Testing), Cracklord and GoCrack (password cracking), Merlin (cross-platform post-exploitation C2), Vuls (vulnerability scanner), plus https://github.com/topics/pentesting with a Go filter.
- Environment setup: install Go via binary download (golang.org/dl) or via apt/yum package manager; GOPATH is where packages will be installed (typically ~/go); GOROOT is the default installation location (typically /usr/lib); the local go path must be added to PATH. Alternate Go versions run side by side: go get golang.org/dl/go1.13.1; go1.13.1 download; go1.13.1 version.
- Running versus building: go run HelloWorld.go executes directly; go build produces a compiled binary.
- net package DNS functions demonstrated: LookupIP, LookupCNAME, LookupAddr, LookupNS, LookupMX, LookupTXT; the slide tip states a registered domain will always have an NS record.
- publicsuffix (golang.org/x/net/publicsuffix) uses Public Suffix List data and its EffectiveTLDPlusOne function to guess the domain from an arbitrary string.
- Port scanning uses net.Dial or net.DialTimeout with “tcp domainname:portnumber” arguments; DialTimeout times out after Timeout seconds, with github.com/anvie/port-scanner as the alternative library.
- soup (github.com/anaskhan96/soup), inspired by Python’s Beautiful Soup, exposes Get, Header, Cookie, HTMLParse, Find, FindAll, FindNextSibling/FindNextElementSibling/FindPrevSibling/FindPrevElementSibling, Children, Text and FullText; the demo scrapes comic links from xkcd.com.
- Binary size reduction: go build -ldflags ‘-s -w’ helloworld.go omits the symbol table, debug information and DWARF symbol table; UPX compression of binaries further reduces size after compilation.
- Scratch container deployment: a Dockerfile with FROM scratch, COPY of the fat binary, and ENTRYPOINT produces a minimal image built with docker build -t ${PROJECT}; cross-compilation one-liners: env GOOS=linux GOARCH=amd64 go build, env GOOS=windows GOARCH=amd64 go build, env GOOS=darwin GOARCH=amd64 go build.
- The Makefile automates linux, windows and mac builds with -ldflags ‘-s -w’, the docker target, clean, check (gosec), updatedep (go get -u), all (linux mac windows) and complete (all docker) targets; gosec (github.com/securego/gosec) runs periodic code checks with rule selection and exclusion, and Snyk has introduced Go module dependency Checks.
Notable Quotes
“Language is as good as the modules it provides”
“Fat Static Binary by default”
“no 3rd party dependency not even runtime”
“If a domain is registered it will always have a NS Record”
“This is by no means exhaustive list”
“gosec is one good code review tool for golang”































