Skip to content

Commit b1c100a

Browse files
ssh password auth
1 parent 89f42a7 commit b1c100a

File tree

2 files changed

+46
-22
lines changed

2 files changed

+46
-22
lines changed

pkg/plugins/services/ssh/ssh.go

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ func checkAlgo(data []byte) (map[string]string, error) {
196196

197197
func (p *SSHPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Target) (*plugins.Service, error) {
198198
response, err := utils.Recv(conn, timeout)
199+
passwordAuth := false
200+
199201
if err != nil {
200202
return nil, err
201203
}
@@ -223,6 +225,20 @@ func (p *SSHPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Tar
223225
return plugins.CreateServiceFrom(target, payload, false, "", plugins.TCP), nil
224226
}
225227

228+
// check auth methods
229+
conf := ssh.ClientConfig{}
230+
conf.Auth = nil
231+
conf.Auth = append(conf.Auth, ssh.Password("admin"))
232+
conf.User = "admin"
233+
conf.HostKeyCallback = ssh.InsecureIgnoreHostKey()
234+
235+
authClient, err := ssh.Dial("tcp", target.Address.String(), &conf)
236+
237+
passwordAuth = strings.Contains(err.Error(), "password")
238+
if authClient != nil {
239+
authClient.Close()
240+
}
241+
226242
sshConfig := &ssh.ClientConfig{}
227243
fullConf := *sshConfig
228244
fullConf.SetDefaults()
@@ -242,8 +258,9 @@ func (p *SSHPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Tar
242258
_, err = io.ReadFull(rand.Reader, sendMsg.Cookie[:])
243259
if err != nil {
244260
payload := plugins.ServiceSSH{
245-
Banner: banner,
246-
Algo: fmt.Sprintf("%s", algo),
261+
Banner: banner,
262+
PasswordAuthEnabled: passwordAuth,
263+
Algo: fmt.Sprintf("%s", algo),
247264
}
248265
return plugins.CreateServiceFrom(target, payload, false, "", plugins.TCP), nil
249266
}
@@ -259,8 +276,9 @@ func (p *SSHPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Tar
259276
err = ssh.PushPacket(t.HandshakeTransport, packetCopy)
260277
if err != nil {
261278
payload := plugins.ServiceSSH{
262-
Banner: banner,
263-
Algo: fmt.Sprintf("%s", algo),
279+
Banner: banner,
280+
PasswordAuthEnabled: passwordAuth,
281+
Algo: fmt.Sprintf("%s", algo),
264282
}
265283
return plugins.CreateServiceFrom(target, payload, false, "", plugins.TCP), nil
266284
}
@@ -271,8 +289,9 @@ func (p *SSHPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Tar
271289

272290
if err != nil {
273291
payload := plugins.ServiceSSH{
274-
Banner: banner,
275-
Algo: fmt.Sprintf("%s", algo),
292+
Banner: banner,
293+
PasswordAuthEnabled: passwordAuth,
294+
Algo: fmt.Sprintf("%s", algo),
276295
}
277296
return plugins.CreateServiceFrom(target, payload, false, "", plugins.TCP), nil
278297
}
@@ -293,8 +312,9 @@ func (p *SSHPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Tar
293312
t.Algorithms, err = ssh.FindAgreedAlgorithms(false, &sendMsg, otherInit)
294313
if err != nil {
295314
payload := plugins.ServiceSSH{
296-
Banner: banner,
297-
Algo: fmt.Sprintf("%s", algo),
315+
Banner: banner,
316+
PasswordAuthEnabled: passwordAuth,
317+
Algo: fmt.Sprintf("%s", algo),
298318
}
299319
return plugins.CreateServiceFrom(target, payload, false, "", plugins.TCP), nil
300320
}
@@ -310,28 +330,31 @@ func (p *SSHPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Tar
310330
result, err := ssh.Clients(t, kex, &magics)
311331
if err != nil {
312332
payload := plugins.ServiceSSH{
313-
Banner: banner,
314-
Algo: fmt.Sprintf("%s", algo),
333+
Banner: banner,
334+
PasswordAuthEnabled: passwordAuth,
335+
Algo: fmt.Sprintf("%s", algo),
315336
}
316337
return plugins.CreateServiceFrom(target, payload, false, "", plugins.TCP), nil
317338
}
318339
hostKey, err := ssh.ParsePublicKey(result.HostKey)
319340
if err != nil {
320341
payload := plugins.ServiceSSH{
321-
Banner: banner,
322-
Algo: fmt.Sprintf("%s", algo),
342+
Banner: banner,
343+
PasswordAuthEnabled: passwordAuth,
344+
Algo: fmt.Sprintf("%s", algo),
323345
}
324346
return plugins.CreateServiceFrom(target, payload, false, "", plugins.TCP), nil
325347
}
326348
fingerprint := ssh.FingerprintSHA256(hostKey)
327349
base64HostKey := base64.StdEncoding.EncodeToString(result.HostKey)
328350

329351
payload := plugins.ServiceSSH{
330-
Banner: banner,
331-
Algo: fmt.Sprintf("%s", algo),
332-
HostKey: base64HostKey,
333-
HostKeyType: hostKey.Type(),
334-
HostKeyFingerprint: fingerprint,
352+
Banner: banner,
353+
PasswordAuthEnabled: passwordAuth,
354+
Algo: fmt.Sprintf("%s", algo),
355+
HostKey: base64HostKey,
356+
HostKeyType: hostKey.Type(),
357+
HostKeyFingerprint: fingerprint,
335358
}
336359
return plugins.CreateServiceFrom(target, payload, false, "", plugins.TCP), nil
337360
}

pkg/plugins/types.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,12 @@ type ServiceStun struct {
427427
func (e ServiceStun) Type() string { return ProtoStun }
428428

429429
type ServiceSSH struct {
430-
Banner string `json:"banner"`
431-
Algo string `json:"algo"`
432-
HostKey string `json:"hostKey,omitempty"`
433-
HostKeyType string `json:"hostKeyType,omitempty"`
434-
HostKeyFingerprint string `json:"hostKeyFingerprint,omitempty"`
430+
Banner string `json:"banner"`
431+
PasswordAuthEnabled bool `json:"passwordAuthEnabled"`
432+
Algo string `json:"algo"`
433+
HostKey string `json:"hostKey,omitempty"`
434+
HostKeyType string `json:"hostKeyType,omitempty"`
435+
HostKeyFingerprint string `json:"hostKeyFingerprint,omitempty"`
435436
}
436437

437438
func (e ServiceSSH) Type() string { return ProtoSSH }

0 commit comments

Comments
 (0)