Find the latest Linux 64-bit version for the x86-64 architecture, as shown below. Note the file name and the SHA265 checksum, outlined in green in the image below.
On your Linux server, in a Terminal window, execute these commands, adjusting the filename to match the filename you found in the previous step:
wget https://go.dev/dl/go1.18.3.linux-amd64.tar.gz
sha256sum go1.*
Make sure the SHA256 value matches the value on the
website,
as shown below.
On your Linux server, in a Terminal window, execute these commands, adjusting the filename to match the filename you found in the previous step:
tar xvf go1.*
sudo chown -R root:root ./go
sudo mv go /usr/local
echo export GOPATH=$HOME/work >> ~/.profile
echo export PATH=\$PATH:/usr/local/go/bin:\$GOPATH/bin >> ~/.profile
source ~/.profile
go env -w GO111MODULE=auto
go
Go runs, showing a help message,
as shown below.
mkdir work
mkdir -p work/src/my_project/hello
nano work/src/my_project/hello/hello.go
In nano, enter this code,
as shown below.
package main
import "fmt"
func main() {
fmt.Printf("Hello, World!\n")
}
Save the file with Ctrl+X, Y, Enter.
Execute these commands to compile the program and run it:
go install my_project/hello
hello
The program runs,
as shown below.
On your Linux server, in a Terminal window, execute these commands:
mkdir -p work/src/my_project/portscan1
nano work/src/my_project/portscan1/portscan1.go
In nano, enter this code,
as shown below.
package main
import (
"net"
"fmt"
"strconv"
)
func main() {
for i := 1; i < 65535; i++ {
port := strconv.FormatInt(int64(i), 10)
conn, err := net.Dial("tcp", "127.0.0.1:" + port)
if err == nil {
fmt.Println("Port",i, "open")
conn.Close()
}
}
}
Save the file with Ctrl+X, Y, Enter.
Execute these commands to compile the program and run it:
go install my_project/portscan1
portscan1
The program runs,
as shown below.
On your Linux server, in a Terminal window, execute these commands:
mkdir -p work/src/my_project/portscan2
nano work/src/my_project/portscan2/portscan2.go
In nano, enter this code,
as shown below.
package main
import (
"net"
"fmt"
"strconv"
)
func main() {
for i := 20; i < 25; i++ {
port := strconv.FormatInt(int64(i), 10)
conn, err := net.Dial("tcp", "target1.bowneconsulting.com:" + port)
fmt.Println("Scanning Port",i)
if err == nil {
fmt.Println("Port",i, "open")
Buffer := make([]byte, 1024)
numBytesRead, err := conn.Read(Buffer)
if err == nil {
fmt.Printf("Banner: %s\n", Buffer[0:numBytesRead])
}
conn.Close()
}
}
}
Save the file with Ctrl+X, Y, Enter.
Execute these commands to compile the program and run it:
go install my_project/portscan2
portscan2
The program runs,
as shown below.
mkdir -p work/src/my_project/portscan3
nano work/src/my_project/portscan3/portscan3.go
In nano, enter this code,
as shown below.
package main
import (
"net"
"fmt"
"strconv"
)
func main() {
for i := 20; i < 30; i++ {
port := strconv.FormatInt(int64(i), 10)
conn, err := net.Dial("tcp", "target1.bowneconsulting.com:" + port)
fmt.Println("Scanning Port",i)
if err == nil {
fmt.Println("Port",i, "open")
Buffer := make([]byte, 1024)
numBytesRead, err := conn.Read(Buffer)
if err == nil {
fmt.Printf("Banner: %s\n", Buffer[0:numBytesRead])
}
conn.Close()
}
}
}
This is the same as the banner grabber,
but it goes from port 20 to 29.
Save the file with Ctrl+X, Y, Enter.
Execute these commands to compile the program and run it:
go install my_project/portscan3
portscan3
The program runs to port 24,
but freezes there,
as shown below.
To do that, on your Linux server, in a Terminal window, execute this command:
mkdir -p work/src/my_project/portscan4
nano work/src/my_project/portscan4/portscan4.go
In nano, enter this code,
as shown below.
package main
import (
"net"
"fmt"
"strconv"
"time"
)
func main() {
for i := 20; i < 30; i++ {
port := strconv.FormatInt(int64(i), 10)
conn, err := net.DialTimeout("tcp", "target1.bowneconsulting.com:" + port, 1*time.Second)
fmt.Println("Scanning Port",i)
if err == nil {
fmt.Println("Port",i, "open")
Buffer := make([]byte, 1024)
numBytesRead, err := conn.Read(Buffer)
if err == nil {
fmt.Printf("Banner: %s\n", Buffer[0:numBytesRead])
}
conn.Close()
} else {
fmt.Println("Error: ",err)
}
}
}
Save the file with
Ctrl+X, Y,
Enter.
Execute these commands to compile the program and run it:
go install my_project/portscan4
portscan4
Hint: Substring: How to Split a String
Hint: 3 ways to split a string into a slice
Updated for Go 16.6 7-16-2021
Updated 6-22-22