mirror of
https://github.com/shadow1ng/fscan.git
synced 2025-07-14 13:22:35 +08:00
Update ssh.go
This commit is contained in:
parent
29beca41d0
commit
6cd1ee75f5
@ -3,25 +3,24 @@ package Plugins
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/shadow1ng/fscan/common"
|
"github.com/shadow1ng/fscan/common"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SshScan(info common.HostInfo, flags common.Flags) (tmperr error) {
|
func SshScan(info *common.HostInfo) (tmperr error) {
|
||||||
if flags.IsBrute {
|
if common.IsBrute {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
starttime := time.Now().Unix()
|
starttime := time.Now().Unix()
|
||||||
for _, user := range common.Userdict["ssh"] {
|
for _, user := range common.Userdict["ssh"] {
|
||||||
for _, pass := range common.Passwords {
|
for _, pass := range common.Passwords {
|
||||||
pass = strings.Replace(pass, "{user}", user, -1)
|
pass = strings.Replace(pass, "{user}", user, -1)
|
||||||
flag, err := SshConn(info, flags, user, pass)
|
flag, err := SshConn(info, user, pass)
|
||||||
if flag && err == nil {
|
if flag == true && err == nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
errlog := fmt.Sprintf("[-] ssh %v:%v %v %v %v", info.Host, info.Ports, user, pass, err)
|
errlog := fmt.Sprintf("[-] ssh %v:%v %v %v %v", info.Host, info.Ports, user, pass, err)
|
||||||
@ -30,11 +29,11 @@ func SshScan(info common.HostInfo, flags common.Flags) (tmperr error) {
|
|||||||
if common.CheckErrs(err) {
|
if common.CheckErrs(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if time.Now().Unix()-starttime > (int64(len(common.Userdict["ssh"])*len(common.Passwords)) * flags.Timeout) {
|
if time.Now().Unix()-starttime > (int64(len(common.Userdict["ssh"])*len(common.Passwords)) * common.Timeout) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if flags.SshKey != "" {
|
if common.SshKey != "" {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -42,12 +41,12 @@ func SshScan(info common.HostInfo, flags common.Flags) (tmperr error) {
|
|||||||
return tmperr
|
return tmperr
|
||||||
}
|
}
|
||||||
|
|
||||||
func SshConn(info common.HostInfo, flags common.Flags, user string, pass string) (flag bool, err error) {
|
func SshConn(info *common.HostInfo, user string, pass string) (flag bool, err error) {
|
||||||
flag = false
|
flag = false
|
||||||
Host, Port, Username, Password := info.Host, info.Ports, user, pass
|
Host, Port, Username, Password := info.Host, info.Ports, user, pass
|
||||||
var Auth []ssh.AuthMethod
|
var Auth []ssh.AuthMethod
|
||||||
if flags.SshKey != "" {
|
if common.SshKey != "" {
|
||||||
pemBytes, err := os.ReadFile(flags.SshKey)
|
pemBytes, err := ioutil.ReadFile(common.SshKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.New("read key failed" + err.Error())
|
return false, errors.New("read key failed" + err.Error())
|
||||||
}
|
}
|
||||||
@ -63,7 +62,7 @@ func SshConn(info common.HostInfo, flags common.Flags, user string, pass string)
|
|||||||
config := &ssh.ClientConfig{
|
config := &ssh.ClientConfig{
|
||||||
User: Username,
|
User: Username,
|
||||||
Auth: Auth,
|
Auth: Auth,
|
||||||
Timeout: time.Duration(flags.Timeout) * time.Second,
|
Timeout: time.Duration(common.Timeout) * time.Second,
|
||||||
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
|
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
@ -77,17 +76,17 @@ func SshConn(info common.HostInfo, flags common.Flags, user string, pass string)
|
|||||||
defer session.Close()
|
defer session.Close()
|
||||||
flag = true
|
flag = true
|
||||||
var result string
|
var result string
|
||||||
if flags.Command != "" {
|
if common.Command != "" {
|
||||||
combo, _ := session.CombinedOutput(flags.Command)
|
combo, _ := session.CombinedOutput(common.Command)
|
||||||
result = fmt.Sprintf("[+] SSH:%v:%v:%v %v \n %v", Host, Port, Username, Password, string(combo))
|
result = fmt.Sprintf("[+] SSH %v:%v:%v %v \n %v", Host, Port, Username, Password, string(combo))
|
||||||
if flags.SshKey != "" {
|
if common.SshKey != "" {
|
||||||
result = fmt.Sprintf("[+] SSH:%v:%v sshkey correct \n %v", Host, Port, string(combo))
|
result = fmt.Sprintf("[+] SSH %v:%v sshkey correct \n %v", Host, Port, string(combo))
|
||||||
}
|
}
|
||||||
common.LogSuccess(result)
|
common.LogSuccess(result)
|
||||||
} else {
|
} else {
|
||||||
result = fmt.Sprintf("[+] SSH:%v:%v:%v %v", Host, Port, Username, Password)
|
result = fmt.Sprintf("[+] SSH %v:%v:%v %v", Host, Port, Username, Password)
|
||||||
if flags.SshKey != "" {
|
if common.SshKey != "" {
|
||||||
result = fmt.Sprintf("[+] SSH:%v:%v sshkey correct", Host, Port)
|
result = fmt.Sprintf("[+] SSH %v:%v sshkey correct", Host, Port)
|
||||||
}
|
}
|
||||||
common.LogSuccess(result)
|
common.LogSuccess(result)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user