Update ssh.go

This commit is contained in:
影舞者 2023-11-13 11:27:01 +08:00 committed by GitHub
parent 29beca41d0
commit 6cd1ee75f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,25 +3,24 @@ package Plugins
import (
"errors"
"fmt"
"net"
"os"
"strings"
"time"
"github.com/shadow1ng/fscan/common"
"golang.org/x/crypto/ssh"
"io/ioutil"
"net"
"strings"
"time"
)
func SshScan(info common.HostInfo, flags common.Flags) (tmperr error) {
if flags.IsBrute {
func SshScan(info *common.HostInfo) (tmperr error) {
if common.IsBrute {
return
}
starttime := time.Now().Unix()
for _, user := range common.Userdict["ssh"] {
for _, pass := range common.Passwords {
pass = strings.Replace(pass, "{user}", user, -1)
flag, err := SshConn(info, flags, user, pass)
if flag && err == nil {
flag, err := SshConn(info, user, pass)
if flag == true && err == nil {
return err
} else {
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) {
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
}
}
if flags.SshKey != "" {
if common.SshKey != "" {
return err
}
}
@ -42,12 +41,12 @@ func SshScan(info common.HostInfo, flags common.Flags) (tmperr error) {
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
Host, Port, Username, Password := info.Host, info.Ports, user, pass
var Auth []ssh.AuthMethod
if flags.SshKey != "" {
pemBytes, err := os.ReadFile(flags.SshKey)
if common.SshKey != "" {
pemBytes, err := ioutil.ReadFile(common.SshKey)
if err != nil {
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{
User: Username,
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 {
return nil
},
@ -77,17 +76,17 @@ func SshConn(info common.HostInfo, flags common.Flags, user string, pass string)
defer session.Close()
flag = true
var result string
if flags.Command != "" {
combo, _ := session.CombinedOutput(flags.Command)
result = fmt.Sprintf("[+] SSH:%v:%v:%v %v \n %v", Host, Port, Username, Password, string(combo))
if flags.SshKey != "" {
result = fmt.Sprintf("[+] SSH:%v:%v sshkey correct \n %v", Host, Port, string(combo))
if common.Command != "" {
combo, _ := session.CombinedOutput(common.Command)
result = fmt.Sprintf("[+] SSH %v:%v:%v %v \n %v", Host, Port, Username, Password, string(combo))
if common.SshKey != "" {
result = fmt.Sprintf("[+] SSH %v:%v sshkey correct \n %v", Host, Port, string(combo))
}
common.LogSuccess(result)
} else {
result = fmt.Sprintf("[+] SSH:%v:%v:%v %v", Host, Port, Username, Password)
if flags.SshKey != "" {
result = fmt.Sprintf("[+] SSH:%v:%v sshkey correct", Host, Port)
result = fmt.Sprintf("[+] SSH %v:%v:%v %v", Host, Port, Username, Password)
if common.SshKey != "" {
result = fmt.Sprintf("[+] SSH %v:%v sshkey correct", Host, Port)
}
common.LogSuccess(result)
}