1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

NSE libssh2 bindings: allow exec without pty

This commit is contained in:
dmiller
2024-11-11 21:07:01 +00:00
parent e2ccdb8074
commit 2d43280b16
3 changed files with 59 additions and 44 deletions

View File

@@ -57,12 +57,13 @@ end
-- Runs a shell command on the remote host.
--
-- @param cmd A command to run.
-- @param no_pty If true, skip requesting a PTY.
-- @return The command output.
function SSHConnection:run_remote (cmd)
function SSHConnection:run_remote (cmd, no_pty)
if not (self.session and self.authenticated) then
return false
end
local channel = libssh2.open_channel(self.session)
local channel = libssh2.open_channel(self.session, no_pty)
libssh2.channel_exec(self.session, channel, cmd)
libssh2.channel_send_eof(self.session, channel)
local buff = {}
@@ -71,6 +72,9 @@ function SSHConnection:run_remote (cmd)
data = libssh2.channel_read(self.session, channel)
if data then
table.insert(buff, data)
elseif no_pty then
-- PTY is responsible for sending EOF
break
end
end
return table.concat(buff)

View File

@@ -67,11 +67,12 @@ function read_publickey(publickeyfile)
-- @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
--- Opens channel on authenticated ssh2 session and optionally sets it to pseudo
-- terminal mode.
-- @param session Authenticated libssh2 session
-- @param no_pty If true, skip requesting a PTY.
-- @return libssh2 channel
function open_channel(session)
function open_channel(session, pty)
--- Reads data from stdin on libssh2 channel.
-- @param session Authenticated libssh2 session