summaryrefslogtreecommitdiffstats
path: root/nselib/libssh2.luadoc
blob: 1801ead42822c343c956edc6137eaaf6b7c8f0cd (plain)
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
---
-- Provides a binding for the libssh2 library.
--
-- SSH2 is a complex protocol and libssh2 simplifies many tasks involved in
-- interacting with ssh servers. This module provides bindings for some of the
-- most commonly used libssh2 functions. You may wish to use the functionality
-- in libssh2-utility instead, which wraps many of the functions here in an easier
-- to use class, SSHConnection.
--
-- For performance reasons, the modules reuses the NSE's existing nsock socket
-- pool.
--
-- @author Devin Bjelland
-- @author Sergey Khegay
-- @copyright Same as Nmap--See https://nmap.org/book/man-legal.html

module "libssh2"

--- Creates libssh2 session and performs handshake
-- @param host Host to connect to.
-- @param port Port to connect to.
-- @return session or nil on failure
function session_open(host, port)

--- Returns SHA1 or MD5 hostkey hash of session
-- @param session Connected libssh2 session.
-- @param hashtype (optional) "sha1" or "md5" (sha1 is default)
-- @return hostkey hash of server
function hostkey_hash(session, hashtype)

--- Sets timeout of libssh2 session
-- @param session Connected libssh2 session.
-- @param timeout Timeout for session in milliseconds.
function set_timeout(session, timeout)

--- Returns list of authentication methods supported by the server
-- @param session Connected libssh2 session.
-- @return List of supported authentication methods/
function userauth_list(session)

--- Attempts to authenicate libssh2 session using provided credentials
-- @param username Username to authenicate as.
-- @param password Password to authenicate with.
-- @return true/false, depending on success
function userauth_password(session, username, password)

--- Attempts to authenticate libssh2 session using provided publickey
-- @param session Connected libssh2 session
-- @param username Username to authenicate as
-- @param privatekeyfile File containing privatekey
-- @param passphrase Passphrase for privatekey
-- @param publickeyfile File containing publickey. Not necessary if libssh2 is
-- compiled against OpenSSL
-- @return true/false, depending on success
function userauth_publickey(session, username, privatekeyfile, passphrase, publickeyfile)

--- Read publickey from id_*.pub type key file
-- @param publickeyfile File containing publickey
-- @return string containing raw key data
function read_publickey(publickeyfile)

--- Checks to see if ssh server accepts public key for authentication as given user.
--  This doesn't require the private key as it doesn't finish authenticating.
-- @param session Connected libssh2 session
-- @param username Username to authenicate as
-- @param publickeydata String containing raw publickey blob
-- @return true/false, depending on whether user can authenticate with given key
function publickey_canauth(session, username, publickeydata)

--- Opens channel on authenticated ssh2 session and sets it to pseudo
-- terminal mode.
-- @param session Authenticated libssh2 session
-- @return libssh2 channel
function open_channel(session)

--- Reads data from stdin on libssh2 channel.
-- @param session Authenticated libssh2 session
-- @param channel Open libssh2 channel
-- @return string containing data read from channel
function channel_read(session, channel)

--- Reads data from stderr on libssh2 channel.
-- @param session Authenticated libssh2 session
-- @param channel Open libssh2 channel
-- @return string containing data read from channel
function channel_read_stderr(session, channel)

--- Writes data to libssh2 channel. Not garenteed to write entire buffer.
-- @param session Authenticated libssh2 session
-- @param channel Open libssh2 channel
-- @param buffer String containing data to be written
-- @return Number of bytes written to channel
function channel_write(session, channel, buffer)

--- Executes command on libssh2 channel and returns output
-- @param session Authenticated libssh2 session
-- @param channel Open libssh2 channel
-- @param cmd String containing command to execute
-- @return String containing output from command
function channel_exec(session, channel, cmd)

--- Sends EOF on libssh2 channel. Note that the server may continue to send data
-- until it sends its own EOF (which can be checked with channel_eof()
-- @param session Authenticated libssh2 session
-- @param channel Open libssh2 channel
function channel_send_eof(session, channel)

--- Checks if server has sent EOF on libssh2 channel
-- @param channel Open libssh2 channel
-- @return true/false depending on whether server has send EOF
function channel_eof(channel)

--- Gracefully closes open libssh2 channel
-- @param session Authenticated libssh2 session
-- @param channel Open libssh2 channel
function channel_close(session, channel)

--- Gracefully closes connected libssh2 session
-- @param session Connected libssh2 session
function session_close(session)