onionscan/protocol/ssh_scanner.go

54 lines
1.4 KiB
Go
Raw Normal View History

package protocol
import (
2016-04-27 00:47:00 +00:00
"crypto/md5"
"errors"
"fmt"
"github.com/s-rah/onionscan/config"
"github.com/s-rah/onionscan/report"
"github.com/s-rah/onionscan/utils"
2016-04-27 00:47:00 +00:00
"golang.org/x/crypto/ssh"
"log"
"net"
)
type SSHProtocolScanner struct {
}
func (sps *SSHProtocolScanner) ScanProtocol(hiddenService string, onionscanConfig *config.OnionscanConfig, report *report.OnionScanReport) {
// SSH
log.Printf("Checking %s ssh(22)\n", hiddenService)
conn, err := utils.GetNetworkConnection(hiddenService, 22, onionscanConfig.TorProxyAddress, onionscanConfig.Timeout)
if err != nil {
log.Printf("Failed to connect to service on port 22\n")
report.SSHDetected = false
} else {
// TODO SSH Checking
report.SSHDetected = true
2016-04-27 00:47:00 +00:00
config := &ssh.ClientConfig{
HostKeyCallback: func(hostname string, addr net.Addr, key ssh.PublicKey) error {
h := md5.New()
h.Write(key.Marshal())
2016-04-27 00:47:00 +00:00
fBytes := h.Sum(nil)
2016-04-27 00:47:00 +00:00
fingerprint := string("")
for i := 0; i < len(fBytes); i++ {
if i+1 != len(fBytes) {
fingerprint = fmt.Sprintf("%s%0.2x:", fingerprint, fBytes[i])
} else {
fingerprint = fmt.Sprintf("%s%0.2x", fingerprint, fBytes[i])
}
}
report.SSHKey = fingerprint
log.Printf("Found SSH Key %s\n", fingerprint)
// We don't want to continue
return errors.New("error")
},
}
2016-04-27 00:47:00 +00:00
ssh.NewClientConn(conn, hiddenService+":22", config)
}
}