1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-07 21:21:31 +00:00

Convenience function to request shell on SSH2 channel

This commit is contained in:
dmiller
2025-06-10 21:10:03 +00:00
parent 0e966ad45f
commit 0f491ac2d4
2 changed files with 16 additions and 5 deletions

View File

@@ -786,8 +786,13 @@ static int channel_request (lua_State *L, int status, lua_KContext ctx) {
static int l_channel_request (lua_State *L) { static int l_channel_request (lua_State *L) {
request_context *ctx = (request_context *)safe_zalloc(sizeof(request_context)); request_context *ctx = (request_context *)safe_zalloc(sizeof(request_context));
ctx->channel = (LIBSSH2_CHANNEL *) lua_touserdata(L, 2); ctx->channel = (LIBSSH2_CHANNEL *) lua_touserdata(L, 2);
ctx->request = luaL_checklstring(L, 3, &ctx->request_len); ctx->request = lua_tolstring(L, 3, &ctx->request_len);
ctx->message = lua_tolstring(L, 4, &ctx->message_len); ctx->message = lua_tolstring(L, 4, &ctx->message_len);
/* Convenience: if no extra args, treat it as libssh2_channel_shell */
if (ctx->request == NULL) {
ctx->request = "shell";
ctx->request_len = sizeof("shell") - 1;
}
return channel_request(L, 0, (lua_KContext)ctx); return channel_request(L, 0, (lua_KContext)ctx);
} }
@@ -948,6 +953,7 @@ static const struct luaL_Reg libssh2[] = {
{ "channel_read_stderr", l_channel_read_stderr}, { "channel_read_stderr", l_channel_read_stderr},
{ "channel_write", l_channel_write}, { "channel_write", l_channel_write},
{ "channel_exec", l_channel_exec}, { "channel_exec", l_channel_exec},
{ "channel_shell", l_channel_request},
{ "channel_send_eof", l_channel_send_eof}, { "channel_send_eof", l_channel_send_eof},
{ "channel_eof", l_channel_eof}, { "channel_eof", l_channel_eof},
{ "channel_close", l_channel_close}, { "channel_close", l_channel_close},

View File

@@ -95,10 +95,10 @@ function channel_write(session, channel, buffer)
--- Sends a request on libssh2 channel. --- Sends a request on libssh2 channel.
-- --
-- For example, request a shell with -- Examples:
-- <code>channel_request(s, c, "shell")</code>. The equivalent of -- * request a shell: <code>channel_request(s, c, "shell")</code> (equivalent to <code>channel_shell(s, c)</code).
-- <code>channel_request(s, c, "exec", cmd)</code> -- * execute a command: <code>channel_request(s, c, "exec", cmd)</code> (equivalent to <code>channel_exec(s, c, cmd)</code>).
-- is <code>channel_exec(s, c, cmd)</code>. -- * open a subsystem: <code>channel_request(s, c, "subsystem", "sftp")</code>
-- @param session Authenticated libssh2 session -- @param session Authenticated libssh2 session
-- @param channel Open libssh2 channel -- @param channel Open libssh2 channel
-- @param request String identifier for the request, e.g. "shell", "exec", "subsystem" -- @param request String identifier for the request, e.g. "shell", "exec", "subsystem"
@@ -124,6 +124,11 @@ function channel_request_pty_ex(session, channel, term, modes,
-- @param cmd String containing command to execute -- @param cmd String containing command to execute
function channel_exec(session, channel, cmd) function channel_exec(session, channel, cmd)
--- Requests a shell on libssh2 channel
-- @param session Authenticated libssh2 session
-- @param channel Open libssh2 channel
function channel_shell(session, channel)
--- Sends EOF on libssh2 channel. Note that the server may continue to send data --- 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() -- until it sends its own EOF (which can be checked with channel_eof()
-- @param session Authenticated libssh2 session -- @param session Authenticated libssh2 session