Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Security with Go
Security with Go

Security with Go: Explore the power of Golang to secure host, web, and cloud services

Arrow left icon
Profile Icon John Daniel Leon Profile Icon Gaekwad
Arrow right icon
₹799.99 ₹2621.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (6 Ratings)
eBook Jan 2018 340 pages 1st Edition
eBook
₹799.99 ₹2621.99
Paperback
₹3276.99
Subscription
Free Trial
Renews at ₹800p/m
Arrow left icon
Profile Icon John Daniel Leon Profile Icon Gaekwad
Arrow right icon
₹799.99 ₹2621.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (6 Ratings)
eBook Jan 2018 340 pages 1st Edition
eBook
₹799.99 ₹2621.99
Paperback
₹3276.99
Subscription
Free Trial
Renews at ₹800p/m
eBook
₹799.99 ₹2621.99
Paperback
₹3276.99
Subscription
Free Trial
Renews at ₹800p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Security with Go

The Go Programming Language

Before diving into the more complex examples of using Go for security, it is important to have a solid foundation. This chapter provides an overview of the Go programming language so that you have the knowledge necessary to follow the subsequent examples.

This chapter is not an exhaustive treatise of the Go programming language, but will give you a solid overview of the major features. The goal of this chapter is to provide you with the information you need to understand and follow the source code if you have never used Go before. If you are already familiar with Go, this chapter should be a quick and easy review of things you already know, but perhaps you will learn a new piece of information.

This chapter specifically covers the following topics:

  • The Go language specification
  • The Go playground
  • A tour of Go
  • Keywords
  • Notes about source code
  • Comments...

Go language specification

The entire Go language specification can be found online at https://golang.org/ref/spec. Much of the information in this chapter comes from the specification, as this is the one true documentation of the language. The rest of the information here is short examples, tips, best practices, and other things that I have learned during my time with Go.

The Go playground

The Go playground is a website where you can write and execute Go code without having to install anything. In the playground, https://play.golang.org, you can test pieces of code to explore the language and fiddle with things to understand how the language works. It also allows you to share your snippet by creating a unique URL that stores your snippet. Sharing code through the playground can be much more helpful than a plaintext snippet, since it allows the reader to actually execute the code and tinker with the source if they have any questions about how it works:

The preceding screenshot shows a simple program being run in the playground. There are buttons at the top to run, format, add import statements, and share the code with others.

A tour of Go

Another resource provided by the Go team is A Tour of Go. This website, https://tour.golang.org, is built on top of the playground mentioned in the previous section. The tour was my first introduction to the language, and when I completed it, I felt well-equipped to start tackling projects in Go. It walks you through the language step by step along with working code examples so that you can run and modify the code to get familiar with the language. It is a practical way to introduce a newcomer to Go. If you have never used Go at all, I encourage you to check it out.

The preceding screenshot shows the first page of the tour. On the right-hand side, you will have a small embedded playground with the code sample relevant to the short lesson shown on the left-hand side. Each lesson comes with a short code example that you can run and tinker with.

...

Keywords

To emphasize how simple Go is, here is a breakdown of all its 25 keywords. You probably already know most of them if you are familiar with other programming languages. The keywords are grouped together to examine them according to their use.

Data types:

var

This defines a new variable

const

This defines a constant value that does not change

type

This defines a new data type

struct

This defines a new structured data type that contains multiple variables

map

This defines a new map or hash variable

interface

This defines a new interface

Functions:

func

This defines a new function

return

This exits a function, optionally returning values

Packages:

import

This imports an external package in the current package

package

This specifies what package a file belongs to

Program flow:

if

This is used...

Notes about source code

Go source code files should have the .go extension. The source code of Go files is encoded in UTF-8 Unicode. This means that you can use any Unicode characters in your code, like hardcoding Japanese characters in a string.

Semicolons are optional at the end of a line and typically omitted. Semicolons are only required when separating multiple statements or expressions on a single line.

Go does have a code formatting standard which can easily be adhered to by running go fmt on source code files. The code formatting should be followed, but it is not strictly enforced by the compiler the way Python requires exact formatting to execute properly.

Comments

Comments follow a C++ style allowing the double slash and the slash-asterisk wrapped style:

// Line comment, everything after slashes ignored
/* General comment, can be in middle of line or span multiple lines */

Types

The built-in data types are named intuitively enough. Go comes with a set of integer and unsigned integer types with varying bit lengths. There are also floating point numbers, Booleans, and strings, which should come as no surprise.

There are a few types like runes that are not common in other languages. This section covers all of the different types.

Boolean

The Boolean type represents a true or false value. Some languages don't provide a bool type, and you have to use an integer or define your own enumeration, but Go conveniently comes with a predeclared bool type. The true and false constants are also predefined and used in all lowercase. Here is an example of creating a Boolean:

var customFlag bool = false...

Control structures

Control structures are used to control the flow of program execution. The most common forms are the if statements, for loops, and switch statements. Go also supports the goto statement, but should be reserved for cases of extreme performance and not used regularly. Let's look briefly at each of these to understand the syntax.

if

The if statement comes with the if, else if, and else clauses, just like most other languages. The one interesting feature that Go has is the ability to put a statement before the condition, creating temporary variables that are discarded after the if statement has completed.

This example demonstrates the various ways to use an if statement:

package main

import (
"fmt...

Defer

By deferring a function, it will run whenever the current function is exited. This is a convenient way to ensure that a function will get executed before exiting, which is useful for cleaning up or closing files. It is convenient because a deferred function will get executed no matter where the surrounding function exits if there are multiple return locations.

Common use cases are deferring calls to close a file or database connection. Right after opening a file, you can defer a call to close. This will ensure that a file is closed whenever the function is exited, even if there are multiple return statements and you can't be sure about when and where the current function will exit.

This example demonstrates a simple use case for the defer keyword. It creates a file and then defers a call to file.Close():

package main

import (
"log"
"os"
)

func main...

Packages

Packages are just directories. Every directory is its own package. Creating subdirectories creates a new package. Having no subpackages leads to a flat hierarchy. Subdirectories are used just for organizing code.

Packages should be stored in the src folder of your $GOPATH variable.

A package name should match the folder name or be named main. A main package means that it is not intended to be imported into another application, but meant to compile and run as a program. Packages are imported using the import keyword.

You can import packages individually:

import "fmt" 

Alternatively, you can import multiple packages at once by wrapping them with parenthesis:

import (
"fmt"
"log"
)

Classes

Go technically does not have classes, but there are only a few subtle distinctions that keep it from being called an object-oriented language. Conceptually, I do consider it an object-oriented programming language, though it only supports the most basic features of an object-oriented language. It does not come with all of the features many people have come to associate with object-oriented programming, such as inheritance and polymorphism, which are replaced with other features such as embedded types and interfaces. Perhaps you could call it a microclass system, because it is a minimalistic implementation with none of the extra features or baggage, depending on your perspective.

Throughout this book, the terms object and class may be used to illustrate a point using familiar terms, but be aware that these are not formal terms in Go. A type definition in combination with...

Goroutines

Goroutines are lightweight threads built into the language. You simply have to put the word go in front of a function call to have the function execute in a thread. Goroutines may also be referred to as threads in this book.

Go does provide mutexes, but they are avoidable in most cases and will not be covered in this book. You can read more about mutexes in the sync package documentation at https://golang.org/pkg/sync/. Channels should be used instead for sharing data and communicating between threads. Channels were covered earlier in this chapter.

Note that the log package is safe to use concurrently, but the fmt package is not. Here is a short example of using goroutines:

package main

import (
"log"
"time"
)

func countDown() {
for i := 5; i >= 0; i-- {
log.Println(i)
time.Sleep(time.Millisecond * 500)
}
}

func main() {
// Kick...

Getting help and documentation

Go has both online and offline help documentation. The offline documentation is built-in for Go and is the same documentation that is hosted online. These next sections will walk you through accessing both forms of documentation.

Online Go documentation

Offline Go documentation

...

Summary

After reading this chapter you should have a basic understanding of Go fundamentals such as what the keywords are, what they do, and what basic data types are available. You should also feel comfortable creating functions and custom data types.

The goal is not to memorize all of the preceding information, but to be aware of what tools are available in the language. Use this chapter as a reference if necessary. You can find more information about the Go language specification at https://golang.org/ref/spec.

In the next chapter, we will look at working with files in Go. We will cover basics such as getting file information, seeing whether a file exists, truncating files, checking permissions, and creating new files. We will also cover the reader and writer interfaces, as well as a number of ways to read and write data. In addition to this, we will cover things such as archiving...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • First introduction to Security with Golang
  • Adopting a Blue Team/Red Team approach
  • Take advantage of speed and inherent safety of Golang
  • Works as an introduction to security for Golang developers
  • Works as a guide to Golang security packages for recent Golang beginners

Description

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.

Who is this book for?

Security with Go is aimed at developers with basics in Go to the level that they can write their own scripts and small programs without difficulty. Readers should be familiar with security concepts, and familiarity with Python security applications and libraries is an advantage, but not a necessity.

What you will learn

  • • Learn the basic concepts and principles of secure programming
  • • Write secure Golang programs and applications
  • • Understand classic patterns of attack
  • • Write Golang scripts to defend against network-level attacks
  • • Learn how to use Golang security packages
  • • Apply and explore cryptographic methods and packages
  • • Learn the art of defending against brute force attacks
  • • Secure web and cloud applications

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 31, 2018
Length: 340 pages
Edition : 1st
Language : English
ISBN-13 : 9781788622257
Vendor :
Google
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jan 31, 2018
Length: 340 pages
Edition : 1st
Language : English
ISBN-13 : 9781788622257
Vendor :
Google
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
₹800 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
₹4500 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₹400 each
Feature tick icon Exclusive print discounts
₹5000 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₹400 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 10,650.97
Go Standard Library Cookbook
₹4096.99
Distributed Computing with Go
₹3276.99
Security with Go
₹3276.99
Total 10,650.97 Stars icon

Table of Contents

15 Chapters
Introduction to Security with Go Chevron down icon Chevron up icon
The Go Programming Language Chevron down icon Chevron up icon
Working with Files Chevron down icon Chevron up icon
Forensics Chevron down icon Chevron up icon
Packet Capturing and Injection Chevron down icon Chevron up icon
Cryptography Chevron down icon Chevron up icon
Secure Shell (SSH) Chevron down icon Chevron up icon
Brute Force Chevron down icon Chevron up icon
Web Applications Chevron down icon Chevron up icon
Web Scraping Chevron down icon Chevron up icon
Host Discovery and Enumeration Chevron down icon Chevron up icon
Social Engineering Chevron down icon Chevron up icon
Post Exploitation Chevron down icon Chevron up icon
Conclusions Chevron down icon Chevron up icon
Another Book You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(6 Ratings)
5 star 33.3%
4 star 50%
3 star 0%
2 star 16.7%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Antonio Aguilar Sep 14, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I ordered this book direct from Packt and found it to be a good, concise overview of the go programming language. It's not overly long, but gives enough basics for anyone to start writing the code. From there the author dives into a number of different security topics. The code examples tend to work (something that Packt has a problem with sometimes) and there aren't grammar issues or typos that I've noticed.
Amazon Verified review Amazon
Amazon Customer Feb 14, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is an excellent book that I recommend to anyone that is looking to get started with writing code in Go, not just security enthusiasts or professionals. It has a nice primer on the history of Go and its origins, and provides useful external resources for later reference.
Amazon Verified review Amazon
Robert Lavery Mar 19, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
"Security with Go" is an excellent resource for security-minded professionals looking to get started with the Go programming language.Although I am not an experienced Go programmer, I found this book easy to follow and fun to digest. The covered topics include basic file and network operations, cryptographic functions, SSL/TLS certificates, and web application security.This book is aimed at readers who are at least somewhat familiar with one programming language. As you read this book, you will want to get your hands dirty at a terminal by following along with the given examples. By the time you've finished the book, you'll have a small arsenal of network penetration testing software, as well as a good understanding of Go best practices and idioms.Some chapters are stronger than others: Chapter 4, "Forensics," was the weakest chapter, and left me wanting more (I would have liked to see some discussion of filesystems and the spooky things they get up to when nobody's looking.) Chapters 6 ("Cryptography") and 9 ("Web Applications") are far stronger, and I will be referring to them as references as I build more things with Go. It's very nice to have the essentials in one place with handy examples.I share much of the author's philosophy when it comes to security. Discussions in this book range from the ethics of authorized spearphishing exercises to the efficacy of obscurity as a security layer. Little of this should come as any surprise to a seasoned sysadmin, but it is worthy material for review as well as required reading for anyone beginning in the field of security research.The formatting for the book is good, but not perfect. It would be nice if the code blocks were formatted so that they didn't tend to be ever-so-slightly misaligned with the pages of the book, an effect which I found frustratingly distracting, but not to the point of unreadability.All in all, this book is worth a read if you think you'll be writing programs in Go anytime soon, or if you're a programmer who's new to information security and would like to build a powerful and flexible toolkit for security work.
Amazon Verified review Amazon
el duderino Mar 22, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
"Security with Go" is an excellent primer for security researchers who are new to Go, or experienced programmers who want to learn more about security topics that Go provides compelling solutions for. There are many programming languages that can be used to solve problems in the security space but a language such as Go excels at a few things that make it stand out from other, more convenient languages like Python. The ability to process and inject packets is a good example of something that Go does well and an interpreted language struggles with. I was pleased to see this area covered in detail in the book. The recipes included in this book will be useful to individuals working in the security space. Many of the use cases will be valuable to penetration testers or red teams. Overall, I found this good to be a good value and I think it will be useful to those working in the security space.
Amazon Verified review Amazon
Jeff Char Aug 15, 2020
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I think you learn the most by doing and mistakes. Most of the code works correctly. I didn't like the Github download that put "boring" in the src file, set up an OpenSSL. Github has a lot of hackers manipulating the code, better to write it yourself. I liked the pace, brief descriptions of how it works and jumping write into writing code, I would stay away from the Github downloads. Unfortunately most developers place their code there and Google isn't going to give you up to date software. Don't know why most of these books don't show installation until towards the end or updating modules. Think it would be helpful at the beginning and descriptions of what you are getting. Golang.org has older versions that work but you want something beyond 2012-2014 with the compiler built in.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.