Book Image

Security with Go

By : John Daniel Leon, Karthik Gaekwad
Book Image

Security with Go

By: John Daniel Leon, Karthik Gaekwad

Overview of this book

Go is becoming more and more popular as a language for security experts. Its wide use in server and cloud environments, its speed and ease of use, and its evident capabilities for data analysis, have made it a prime choice for developers who need to think about security. Security with Go is the first Golang security book, and it is useful for both blue team and red team applications. With this book, you will learn how to write secure software, monitor your systems, secure your data, attack systems, and extract information. Defensive topics include cryptography, forensics, packet capturing, and building secure web applications. Offensive topics include brute force, port scanning, packet injection, web scraping, social engineering, and post exploitation techniques.
Table of Contents (15 chapters)

Reading from a pcap file

Instead of opening a device for live capture, you can also open a pcap file for inspection offline. After getting a handle, whether it was from pcap.OpenLive() or pcap.OpenOffline(), the handle is treated the same. No distinction is made between a live device and a capture file once the handle is created, except that a live device will continue to deliver packets, and a file will eventually end.

You can read pcap files that were captured with any libpcap client, including Wireshark, tcpdump, or other gopacket applications. This example opens a file named test.pcap using pcap.OpenOffline() and then iterates through the packets using range and prints the basic packet information. Change the filename from test.pcap to whatever file you want to read:

package main

// Use tcpdump to create a test file
// tcpdump -w test.pcap
// or use the example above for writing...