mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Convenience function to request shell on SSH2 channel
This commit is contained in:
@@ -786,8 +786,13 @@ static int channel_request (lua_State *L, int status, lua_KContext ctx) {
|
||||
static int l_channel_request (lua_State *L) {
|
||||
request_context *ctx = (request_context *)safe_zalloc(sizeof(request_context));
|
||||
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);
|
||||
/* 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);
|
||||
}
|
||||
|
||||
@@ -948,6 +953,7 @@ static const struct luaL_Reg libssh2[] = {
|
||||
{ "channel_read_stderr", l_channel_read_stderr},
|
||||
{ "channel_write", l_channel_write},
|
||||
{ "channel_exec", l_channel_exec},
|
||||
{ "channel_shell", l_channel_request},
|
||||
{ "channel_send_eof", l_channel_send_eof},
|
||||
{ "channel_eof", l_channel_eof},
|
||||
{ "channel_close", l_channel_close},
|
||||
|
||||
@@ -95,10 +95,10 @@ function channel_write(session, channel, buffer)
|
||||
|
||||
--- Sends a request on libssh2 channel.
|
||||
--
|
||||
-- For example, request a shell with
|
||||
-- <code>channel_request(s, c, "shell")</code>. The equivalent of
|
||||
-- <code>channel_request(s, c, "exec", cmd)</code>
|
||||
-- is <code>channel_exec(s, c, cmd)</code>.
|
||||
-- Examples:
|
||||
-- * request a shell: <code>channel_request(s, c, "shell")</code> (equivalent to <code>channel_shell(s, c)</code).
|
||||
-- * execute a command: <code>channel_request(s, c, "exec", cmd)</code> (equivalent to <code>channel_exec(s, c, cmd)</code>).
|
||||
-- * open a subsystem: <code>channel_request(s, c, "subsystem", "sftp")</code>
|
||||
-- @param session Authenticated libssh2 session
|
||||
-- @param channel Open libssh2 channel
|
||||
-- @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
|
||||
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
|
||||
-- until it sends its own EOF (which can be checked with channel_eof()
|
||||
-- @param session Authenticated libssh2 session
|
||||
|
||||
Reference in New Issue
Block a user