1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-18 04:19:00 +00:00

Add ncat_main.c facilities for -L. Currently still with the ugly

o.script name.
This commit is contained in:
david
2013-09-12 08:12:11 +00:00
parent ecd7a45ec2
commit 8d796f8981
5 changed files with 31 additions and 5 deletions

View File

@@ -201,6 +201,7 @@ void options_init(void)
o.cmdexec = NULL;
o.execmode = EXEC_PLAIN;
o.script = 0;
o.proxy_auth = NULL;
o.proxytype = NULL;

View File

@@ -195,6 +195,7 @@ struct options {
/* When execmode == EXEC_LUA, cmdexec is the name of the file to run. */
char *cmdexec;
enum exec_mode execmode;
int script;
char *proxy_auth;
char *proxytype;

View File

@@ -165,9 +165,10 @@ static int traceback (lua_State *L)
return 1;
}
void lua_setup(char *cmdexec)
void lua_setup(char *cmdexec, int script)
{
ncat_assert(cmdexec != NULL);
ncat_assert(script == 0); //TODO
lua_State **L = &luaexec_L;

View File

@@ -142,6 +142,6 @@ extern int error_handler_idx;
void lua_report(lua_State *L, char *prefix, int panic);
void dump_stack(lua_State *L, char* title);
void lua_setup(char *cmdexec);
void lua_setup(char *cmdexec, int script);
#endif

View File

@@ -149,6 +149,10 @@
#ifdef HAVE_LUA
#include "ncat_lua.h"
#include "ncat_lua_exec.h"
char** filter_filenames = NULL;
int filter_filenames_no = 0;
#endif
static int ncat_connect_mode(void);
@@ -278,6 +282,7 @@ int main(int argc, char *argv[])
#ifdef HAVE_LUA
{"lua-exec", required_argument, NULL, 0},
{"lua-exec-internal",required_argument, NULL, 0},
{"load-lua-socket-file", required_argument, NULL, 'L'},
#endif
{"max-conns", required_argument, NULL, 'm'},
{"help", no_argument, NULL, 'h'},
@@ -332,7 +337,7 @@ int main(int argc, char *argv[])
while (1) {
/* handle command line arguments */
int option_index;
int c = getopt_long(argc, argv, "46UCc:e:g:G:i:km:hp:d:lo:x:ts:uvw:n",
int c = getopt_long(argc, argv, "46UCc:e:g:G:i:km:hp:d:lo:x:ts:uvw:nL:",
long_options, &option_index);
/* That's the end of the options. */
@@ -545,9 +550,15 @@ int main(int argc, char *argv[])
#endif
ncat_assert(argc == 3);
o.cmdexec = argv[2];
lua_setup(o.cmdexec);
lua_setup(o.cmdexec, 0);
lua_run();
}
break;
case 'L':
o.script = 1;
filter_filenames_no++;
filter_filenames = (char **)safe_realloc(filter_filenames, sizeof(char *) * filter_filenames_no);
filter_filenames[filter_filenames_no-1] = Strdup(optarg);
#endif
break;
case 'h':
@@ -567,6 +578,8 @@ int main(int argc, char *argv[])
" -e, --exec <command> Executes the given command\n"
#ifdef HAVE_LUA
" --lua-exec <filename> Executes the given Lua script\n"
//This line is clearly too long. The option name, IMHO, too.
" -L --load-lua-socket-file Applies the Lua filter script\n"
#endif
" -g hop1[,hop2,...] Loose source routing hop points (8 max)\n"
" -G <n> Loose source routing hop pointer (4, 8, 12, ...)\n"
@@ -869,8 +882,18 @@ connection brokering should work.");
set_lf_mode();
#ifdef HAVE_LUA
if (o.script) {
int i;
for (i = 0; i < filter_filenames_no; i++) {
if (o.verbose)
loguser("Applying Lua filter: %s\n", filter_filenames[i]);
lua_setup(filter_filenames[i], 1);
free(filter_filenames[i]);
}
free(filter_filenames);
}
if (o.execmode == EXEC_LUA)
lua_setup(o.cmdexec);
lua_setup(o.cmdexec, 0);
#endif
if (o.listen)