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)

Changing file ownership

This program will take the file provided and change the user and group ownership. This could be used in tandem with the example that finds files that you have permission to modify.

Go provides os.Chown() in the standard library, but it does not accept string values for the user and group names. The user and group must be provided as integer ID values. Fortunately, Go also comes with an os/user package that contains functions for looking up an ID based on a name. These functions are user.Lookup() and user.LookupGroup().

You could look up your own user and group information on Linux/Mac with the id, whoami, and groups commands.

Note that this does not work on Windows because ownership is treated differently. The following is the code implementation of this example:

package main

import (
"fmt"
"log"
"os"
"os/user&quot...