forked from praetorian-inc/fingerprintx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.go
131 lines (116 loc) · 4.44 KB
/
export.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package ssh
import (
"io"
)
func NewTransport(rwc io.ReadWriteCloser, rand io.Reader, isClient bool) *transport {
return newTransport(rwc, rand, isClient)
}
var SupportedHostKeyAlgos = []string{
CertAlgoRSASHA512v01, CertAlgoRSASHA256v01,
CertAlgoRSAv01, CertAlgoDSAv01, CertAlgoECDSA256v01,
CertAlgoECDSA384v01, CertAlgoECDSA521v01, CertAlgoED25519v01,
KeyAlgoECDSA256, KeyAlgoECDSA384, KeyAlgoECDSA521,
KeyAlgoRSASHA512, KeyAlgoRSASHA256,
KeyAlgoRSA, KeyAlgoDSA,
KeyAlgoED25519,
}
type Algorithms struct {
Kex string
HostKey string
w directionAlgorithms
r directionAlgorithms
}
type HandshakeTransport struct {
handshakeTransport
HandshakeTransport *handshakeTransport
Config *Config
SessionID []byte
Algorithms *Algorithms
ServerVersion []byte
ClientVersion []byte
}
func NewHandshakeTransport(onn keyingTransport, config *Config, clientVersion, serverVersion []byte) *HandshakeTransport {
HandshakeTransportRet := newHandshakeTransport(onn, config, clientVersion, serverVersion)
return &HandshakeTransport{HandshakeTransport: HandshakeTransportRet,
Config: HandshakeTransportRet.config,
SessionID: HandshakeTransportRet.sessionID,
ServerVersion: HandshakeTransportRet.serverVersion,
ClientVersion: HandshakeTransportRet.clientVersion,
}
}
type KexInitMsg struct {
Cookie [16]byte `sshtype:"20"`
KexAlgos []string
ServerHostKeyAlgos []string
CiphersClientServer []string
CiphersServerClient []string
MACsClientServer []string
MACsServerClient []string
CompressionClientServer []string
CompressionServerClient []string
LanguagesClientServer []string
LanguagesServerClient []string
FirstKexFollows bool
Reserved uint32
}
type HandshakeMagics struct {
ClientVersion, ServerVersion []byte
ClientKexInit, ServerKexInit []byte
}
func PushPacket(t *handshakeTransport, p []byte) error {
return t.pushPacket(p)
}
func FindAgreedAlgorithms(isClient bool, clientKexInit, serverKexInit *KexInitMsg) (algs *Algorithms, err error) {
ClientKexInit := kexInitMsg{
Cookie: clientKexInit.Cookie,
KexAlgos: clientKexInit.KexAlgos,
ServerHostKeyAlgos: clientKexInit.ServerHostKeyAlgos,
CiphersClientServer: clientKexInit.CiphersClientServer,
CiphersServerClient: clientKexInit.CiphersServerClient,
MACsClientServer: clientKexInit.MACsClientServer,
MACsServerClient: clientKexInit.MACsServerClient,
CompressionClientServer: clientKexInit.CompressionClientServer,
CompressionServerClient: clientKexInit.CompressionServerClient,
LanguagesClientServer: clientKexInit.LanguagesClientServer,
LanguagesServerClient: clientKexInit.LanguagesServerClient,
FirstKexFollows: clientKexInit.FirstKexFollows,
Reserved: clientKexInit.Reserved,
}
ServerKexInit := kexInitMsg{
Cookie: serverKexInit.Cookie,
KexAlgos: serverKexInit.KexAlgos,
ServerHostKeyAlgos: serverKexInit.ServerHostKeyAlgos,
CiphersClientServer: serverKexInit.CiphersClientServer,
CiphersServerClient: serverKexInit.CiphersServerClient,
MACsClientServer: serverKexInit.MACsClientServer,
MACsServerClient: serverKexInit.MACsServerClient,
CompressionClientServer: serverKexInit.CompressionClientServer,
CompressionServerClient: serverKexInit.CompressionServerClient,
LanguagesClientServer: serverKexInit.LanguagesClientServer,
LanguagesServerClient: serverKexInit.LanguagesServerClient,
FirstKexFollows: serverKexInit.FirstKexFollows,
Reserved: serverKexInit.Reserved,
}
algorithm, err := findAgreedAlgorithms(isClient, &ClientKexInit, &ServerKexInit)
if err != nil {
return nil, err
}
algorithmRet := Algorithms{Kex: algorithm.kex, HostKey: algorithm.hostKey, w: algorithm.w, r: algorithm.r}
return &algorithmRet, err
}
type KexAlgorithm interface {
kexAlgorithm
}
func GetKex(kex string) KexAlgorithm {
kexStr := kexAlgoMap[kex]
return kexStr
}
func Clients(t *HandshakeTransport, kex KexAlgorithm, magics *HandshakeMagics) (*kexResult, error) {
magic := handshakeMagics{clientVersion: magics.ClientVersion, clientKexInit: magics.ClientKexInit,
serverVersion: magics.ServerVersion, serverKexInit: magics.ServerKexInit}
result, err := kex.Client(t.HandshakeTransport.conn, t.Config.Rand, &magic)
if err != nil {
return nil, err
}
return result, nil
}