Build a Cybersecurity Link-Analyzer with Go
Tags: go, cybersecurity, security, programming
Published: 2023-11-16 11:54:31

<p data-pm-slice="1 3 []">Ransomware has become one of the most dangerous cybersecurity threats facing organizations and individuals today.</p>
Ransomware is caused by clicking on malicious links, which leads them to install malware that encrypts their systems and asks for ransom.

This malware encrypts files and systems, demanding payment to restore access. One of the most prolific strains is Qakbot (also known as Qbot or Pinkslipbot). Active since 2007, it has infected hundreds of thousands of systems globally through evolving infection vectors and capabilities.

I created a Link-Analyzer that analyzes a link to check if it is malicious and gives details of what the link leads to.

This tutorial is the first of many to come with building our program using Golang.
<h2>Prerequisite</h2>
<ul>
 	<li>Code Editor preferable <a class="attrlink" href="https://code.visualstudio.com/download" target="_blank" rel="noreferrer nofollow noopener">VScode </a></li>
 	<li>install <a class="attrlink" href="https://go.dev/doc/install" target="_blank" rel="noreferrer nofollow noopener">Go</a> on your machine</li>
 	<li>Install all extensions from <a class="attrlink" href="https://marketplace.visualstudio.com/items?itemName=golang.go" target="_blank" rel="noreferrer nofollow noopener">Vscode - Go </a></li>
</ul>
<h2>Getting Started</h2>
Go is an open-source programming language developed by Google that has been gaining popularity for its simplicity, performance, and ease of building robust applications.

This article will look at a simple Go program that analyzes links users enter and keeps track of how many free link credits they have left.

Fork the <a class="attrlink" href="https://github.com/Scofield-Idehen/go_project.git" target="_blank" rel="noreferrer nofollow noopener">repo</a> and get started.
<h2>Introduction</h2>
The goal of this program is to prompt the user to enter links, analyze each link to verify if it is valid, and keep a count of how many free link credits the user has remained out of an initial set amount.

Go is a great fit for building small utility programs like this, given its focus on high performance, ease of maintenance, and built-in features allowing quick parsing, manipulation, and analysis of text or strings.

While Go has been widely adopted for large-scale distributed systems and services at companies like Google, it can also be useful for crafting standalone tools like this link analyzer.
<h2>Setting up the Program</h2>
We first need to initialize some variables to configure the program:
<pre><code class="language-go">var confrenceName = "go confrence"
const Free_UserLink = 3 
var remain_link = 3</code></pre>
The <code>confrenceName</code> will store the name of the conference to customize the messaging.

Free_UserLink is declared a constant set to 3 since we want to give each user 3 free link credits. remain_link will be used to track how many free credits the user has left.

Next, we print out a welcome message displaying the conference name from the <code>confrenceName</code> variable and initialize the rem<code>a</code>inder of their free links:
<pre><code class="language-go">fmt.Printf("Welcome to %v Link Analyser\n", confrenceName)
fmt.Print("You have only 3 free", Free_UserLink) 
fmt.Print("your remaining links are", remain_link)</code></pre>
The <code>fmt.Printf</code> function allows us to insert the conference name variable into the printed string.

We then prompt the user to enter a link to analyze:

<code>fmt.Println("Insert your Link here: ")</code>
<h2>Collecting User Input</h2>
To store the user's input, we need to declare variables and arrays:
<pre><code class="language-go">var bookings = [50]string
var first_Name string
var last_Name string 
var email_address string
var userTicket int</code></pre>
This allows us to store up to 50 bookings in the bookings array and variables for the user's name, email, and the link they enter.

We can then use <code>fmt.Scan</code> to read input from the user when prompted:
<pre><code class="language-go">println("Enter your name: ")
fmt.Scan(&amp;first_Name)

println("Enter your last_name: ")  
fmt.Scan(&amp;last_Name)

println("Enter your Email: ")
fmt.Scan(&amp;email_address) 

println("Enter your Link: ")
fmt.Scan(&amp;userTicket)</code></pre>
This will collect the user's first name, last name, and email and link to the respective variables.
<h2>Analyzing the Link</h2>
Once we have the user's link input, we can deduct 1 from their remaining free links:

<code>remain_link = remain_link - userTicket</code>

We also store their name and link used in the bookings array for tracking:

<code>bookings[0] = first_Name + " " + last_Name</code>

Finally, we can print out a confirmation message displaying their details:
<pre><code class="language-go">fmt.Printf("%v %v has used %v freelink \n", first_Name, last_Name, userTicket)
fmt.Printf("You have %v Link_verifier remaining ", remain_link) </code></pre>
This shows the user their name, the link they entered, and how many free links they have left.
<h2>Summary</h2>
This short program demonstrates how Go can quickly build small but useful command line tools.

By leveraging Go's strong text manipulation features and simplicity, we could parse user input, analyze links, and track usage without too much code.

The full power of Go really shines when building complex, concurrent applications and services. But it's also a great language for crafting standalone scripts and utilities like this one.

While our program was basic, it could easily be expanded with additional features like reading links from a file, validating different types of links, allowing unlimited paid links, or storing data in a database.

If you find this post exciting, find more exciting posts on the <a class="attrlink" href="http://blog.learnhub.africa/" target="_blank" rel="noreferrer nofollow noopener">Learnhub Blog</a>; we write everything tech from <a class="attrlink" href="https://blog.learnhub.africa/category/cloud-computing/" target="_blank" rel="noreferrer nofollow noopener">Cloud computing</a> to <a class="attrlink" href="https://blog.learnhub.africa/category/frontend/" target="_blank" rel="noreferrer nofollow noopener">Frontend Dev</a>, <a class="attrlink" href="https://blog.learnhub.africa/category/security/" target="_blank" rel="noreferrer nofollow noopener">Cybersecurity</a>, <a class="attrlink" href="https://blog.learnhub.africa/category/data-science/" target="_blank" rel="noreferrer nofollow noopener">AI</a>, and <a class="attrlink" href="https://blog.learnhub.africa/category/blockchain/" target="_blank" rel="noreferrer nofollow noopener">Blockchain</a>.
<h2>Resource</h2>
<ul>
 	<li><a class="attrlink" href="https://go.dev/doc/" target="_blank" rel="noreferrer nofollow noopener">Go documentation </a></li>
 	<li><a class="attrlink" href="https://www.educative.io/blog/golang-tutorial" target="_blank" rel="noreferrer nofollow noopener">Getting started with Golang</a></li>
</ul>