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)

Creating a custom layer

You are not restricted to the most common layers, such as Ethernet, IP, and TCP. You can create your own layers. This has limited use for most people, but in some extremely rare cases it may make sense to replace the TCP layer with something customized to meet specific requirements.

This example demonstrates how to create a custom layer. This is good for implementing a protocol that is not already included with gopacket/layers package. There are over 100 layer types already included with gopacket. You can create custom layers at any level.

The first thing this code does is to define a custom data structure to represent our layer. The data structure not only holds our custom data (SomeByte and AnotherByte) but also needs a byte slice to store the rest of the actual payload, along with any other layers (restOfData):

package main

import (