2016-04-12 06:02:06 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
2016-04-27 00:47:00 +00:00
|
|
|
"crypto/md5"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2016-05-03 14:31:56 +00:00
|
|
|
"github.com/s-rah/onionscan/config"
|
2016-04-12 06:02:06 +00:00
|
|
|
"github.com/s-rah/onionscan/report"
|
2016-06-07 06:29:29 +00:00
|
|
|
"github.com/s-rah/onionscan/utils"
|
2016-04-27 00:47:00 +00:00
|
|
|
"golang.org/x/crypto/ssh"
|
2016-04-12 06:02:06 +00:00
|
|
|
"log"
|
2016-04-25 02:46:28 +00:00
|
|
|
"net"
|
2016-04-12 06:02:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type SSHProtocolScanner struct {
|
|
|
|
}
|
|
|
|
|
2016-05-03 14:31:56 +00:00
|
|
|
func (sps *SSHProtocolScanner) ScanProtocol(hiddenService string, onionscanConfig *config.OnionscanConfig, report *report.OnionScanReport) {
|
2016-04-12 06:02:06 +00:00
|
|
|
// SSH
|
|
|
|
log.Printf("Checking %s ssh(22)\n", hiddenService)
|
2016-06-07 06:29:29 +00:00
|
|
|
conn, err := utils.GetNetworkConnection(hiddenService, 22, onionscanConfig.TorProxyAddress, onionscanConfig.Timeout)
|
2016-04-12 06:02:06 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to connect to service on port 22\n")
|
2016-05-23 08:38:10 +00:00
|
|
|
report.SSHDetected = false
|
2016-04-12 06:02:06 +00:00
|
|
|
} else {
|
|
|
|
// TODO SSH Checking
|
2016-04-25 02:46:28 +00:00
|
|
|
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 {
|
2016-04-25 02:46:28 +00:00
|
|
|
h := md5.New()
|
|
|
|
h.Write(key.Marshal())
|
2016-04-27 00:47:00 +00:00
|
|
|
|
2016-04-25 02:46:28 +00:00
|
|
|
fBytes := h.Sum(nil)
|
2016-04-27 00:47:00 +00:00
|
|
|
fingerprint := string("")
|
2016-04-25 02:46:28 +00:00
|
|
|
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)
|
2016-04-25 02:46:28 +00:00
|
|
|
|
2016-04-12 06:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|