@@ -196,6 +196,8 @@ func checkAlgo(data []byte) (map[string]string, error) {
196
196
197
197
func (p * SSHPlugin ) Run (conn net.Conn , timeout time.Duration , target plugins.Target ) (* plugins.Service , error ) {
198
198
response , err := utils .Recv (conn , timeout )
199
+ passwordAuth := false
200
+
199
201
if err != nil {
200
202
return nil , err
201
203
}
@@ -223,6 +225,20 @@ func (p *SSHPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Tar
223
225
return plugins .CreateServiceFrom (target , payload , false , "" , plugins .TCP ), nil
224
226
}
225
227
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
+
226
242
sshConfig := & ssh.ClientConfig {}
227
243
fullConf := * sshConfig
228
244
fullConf .SetDefaults ()
@@ -242,8 +258,9 @@ func (p *SSHPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Tar
242
258
_ , err = io .ReadFull (rand .Reader , sendMsg .Cookie [:])
243
259
if err != nil {
244
260
payload := plugins.ServiceSSH {
245
- Banner : banner ,
246
- Algo : fmt .Sprintf ("%s" , algo ),
261
+ Banner : banner ,
262
+ PasswordAuthEnabled : passwordAuth ,
263
+ Algo : fmt .Sprintf ("%s" , algo ),
247
264
}
248
265
return plugins .CreateServiceFrom (target , payload , false , "" , plugins .TCP ), nil
249
266
}
@@ -259,8 +276,9 @@ func (p *SSHPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Tar
259
276
err = ssh .PushPacket (t .HandshakeTransport , packetCopy )
260
277
if err != nil {
261
278
payload := plugins.ServiceSSH {
262
- Banner : banner ,
263
- Algo : fmt .Sprintf ("%s" , algo ),
279
+ Banner : banner ,
280
+ PasswordAuthEnabled : passwordAuth ,
281
+ Algo : fmt .Sprintf ("%s" , algo ),
264
282
}
265
283
return plugins .CreateServiceFrom (target , payload , false , "" , plugins .TCP ), nil
266
284
}
@@ -271,8 +289,9 @@ func (p *SSHPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Tar
271
289
272
290
if err != nil {
273
291
payload := plugins.ServiceSSH {
274
- Banner : banner ,
275
- Algo : fmt .Sprintf ("%s" , algo ),
292
+ Banner : banner ,
293
+ PasswordAuthEnabled : passwordAuth ,
294
+ Algo : fmt .Sprintf ("%s" , algo ),
276
295
}
277
296
return plugins .CreateServiceFrom (target , payload , false , "" , plugins .TCP ), nil
278
297
}
@@ -293,8 +312,9 @@ func (p *SSHPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Tar
293
312
t .Algorithms , err = ssh .FindAgreedAlgorithms (false , & sendMsg , otherInit )
294
313
if err != nil {
295
314
payload := plugins.ServiceSSH {
296
- Banner : banner ,
297
- Algo : fmt .Sprintf ("%s" , algo ),
315
+ Banner : banner ,
316
+ PasswordAuthEnabled : passwordAuth ,
317
+ Algo : fmt .Sprintf ("%s" , algo ),
298
318
}
299
319
return plugins .CreateServiceFrom (target , payload , false , "" , plugins .TCP ), nil
300
320
}
@@ -310,28 +330,31 @@ func (p *SSHPlugin) Run(conn net.Conn, timeout time.Duration, target plugins.Tar
310
330
result , err := ssh .Clients (t , kex , & magics )
311
331
if err != nil {
312
332
payload := plugins.ServiceSSH {
313
- Banner : banner ,
314
- Algo : fmt .Sprintf ("%s" , algo ),
333
+ Banner : banner ,
334
+ PasswordAuthEnabled : passwordAuth ,
335
+ Algo : fmt .Sprintf ("%s" , algo ),
315
336
}
316
337
return plugins .CreateServiceFrom (target , payload , false , "" , plugins .TCP ), nil
317
338
}
318
339
hostKey , err := ssh .ParsePublicKey (result .HostKey )
319
340
if err != nil {
320
341
payload := plugins.ServiceSSH {
321
- Banner : banner ,
322
- Algo : fmt .Sprintf ("%s" , algo ),
342
+ Banner : banner ,
343
+ PasswordAuthEnabled : passwordAuth ,
344
+ Algo : fmt .Sprintf ("%s" , algo ),
323
345
}
324
346
return plugins .CreateServiceFrom (target , payload , false , "" , plugins .TCP ), nil
325
347
}
326
348
fingerprint := ssh .FingerprintSHA256 (hostKey )
327
349
base64HostKey := base64 .StdEncoding .EncodeToString (result .HostKey )
328
350
329
351
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 ,
335
358
}
336
359
return plugins .CreateServiceFrom (target , payload , false , "" , plugins .TCP ), nil
337
360
}
0 commit comments