Library ssh2

Functions for the SSH-2 protocol.

Author:

  • Sven Klemm <sven@c3d2.de>

Copyright © Same as Nmap--See https://nmap.org/book/man-legal.html

Source: https://svn.nmap.org/nmap/nselib/ssh2.lua

Functions

check_packet_length (buffer)

Retrieve the size of the packet that is being received and checks if it is fully received

fetch_host_key (host, port, key_type)

Fetch an SSH-2 host key.

transport.build (payload)

Build an SSH-2 packet.

transport.kex_init (options)

Build a kex_init packet.

transport.kexdh_gex_init (e)

Build a kexdh_gex_init packet.

transport.kexdh_init (e)

Build a kexdh_init packet.

transport.pack_mpint (bn)

Pack a multiprecision integer for sending.

transport.parse_kex_init (payload)

Parse a kexinit package.

transport.payload (packet)

Extract the payload from a received SSH-2 packet.

transport.receive_packet (socket)

Receives a complete SSH packet, even if fragmented

Functions

check_packet_length (buffer)

Retrieve the size of the packet that is being received and checks if it is fully received

This function is very similar to the function generated with match.numbytes(num) function, except that this one will check for the number of bytes on-the-fly, based on the written on the SSH packet.

Parameters

buffer
The receive buffer

Return value:

packet_length, packet_length or nil the return is similar to the lua function string:find()
fetch_host_key (host, port, key_type)

Fetch an SSH-2 host key.

Parameters

host
Nmap host table.
port
Nmap port table.
key_type
key type to fetch.

Return value:

A table with the following fields: key, key_type, fp_input, bits, full_key, algorithm, and fingerprint.
transport.build (payload)

Build an SSH-2 packet.

Parameters

payload
Payload of the packet.

Return value:

Packet to send on the wire.
transport.kex_init (options)

Build a kex_init packet.

Parameters

options
 
transport.kexdh_gex_init (e)

Build a kexdh_gex_init packet.

Parameters

e
 
transport.kexdh_init (e)

Build a kexdh_init packet.

Parameters

e
 
transport.pack_mpint (bn)

Pack a multiprecision integer for sending.

Parameters

bn
openssl bignum.

Return value:

Packed multiprecision integer.
transport.parse_kex_init (payload)

Parse a kexinit package.

Returns an empty table in case of an error

Parameters

payload
 
transport.payload (packet)

Extract the payload from a received SSH-2 packet.

Parameters

packet
Received SSH-2 packet.

Return value:

Payload of the SSH-2 packet.
transport.receive_packet (socket)

Receives a complete SSH packet, even if fragmented

This function is an abstraction layer to deal with checking the packet size to know if there is any more data to receive.

Parameters

socket
The socket used to receive the data

Return values:

  1. status True or false
  2. packet The packet received