Book Image

Security with Go

By : John Daniel Leon
Book Image

Security with Go

By: John Daniel Leon

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)

Converting bytes to and from packets

In some cases, there may be raw bytes that you want to convert into a packet or vice versa. This example creates a simple packet and then obtains the raw bytes that make up the packet. The raw bytes are then taken and converted back into a packet to demonstrate the process.

In this example, we will create and serialize a packet using gopacket.SerializeLayers(). The packet consists of several layers: Ethernet, IP, TCP, and payload. During serialization, if any of the packets come back as nil, this means that it could not decode it into the proper layer (malformed or incorrect packet type). After serializing the packet into a buffer, we will get a copy of the raw bytes that make up the packet with buffer.Bytes(). With the raw bytes, we can then decode the data layer by layer using gopacket.NewPacket(). By taking advantage of SerializeLayers(...