Nmap Development mailing list archives
Re: [nmap-svn] r31387 - nmap-exp/d33tah/ncat-lua-with/ncat
From: Jacek Wielemborek <wielemborekj1 () gmail com>
Date: Wed, 17 Jul 2013 19:30:12 +0200
2013/7/17 <commit-mailer () nmap org>:
Author: d33tah
Date: Wed Jul 17 17:32:16 2013
New Revision: 31387
Log:
implement basic support for passing command-line arguments to scripts.
Modified:
nmap-exp/d33tah/ncat-lua-with/ncat/ncat_lua.c
nmap-exp/d33tah/ncat-lua-with/ncat/ncat_lua.h
nmap-exp/d33tah/ncat-lua-with/ncat/ncat_main.c
nmap-exp/d33tah/ncat-lua-with/ncat/ncat_posix.c
Modified: nmap-exp/d33tah/ncat-lua-with/ncat/ncat_lua.c
==============================================================================
--- nmap-exp/d33tah/ncat-lua-with/ncat/ncat_lua.c (original)
+++ nmap-exp/d33tah/ncat-lua-with/ncat/ncat_lua.c Wed Jul 17 17:32:16 2013
@@ -219,13 +219,18 @@
return 0;
}
-void lua_setup(void)
+void lua_setup(char *dostring)
{
ncat_assert(o.cmdexec!=NULL);
L = luaL_newstate();
luaL_openlibs(L);
+ if (dostring != NULL) {
+ if (luaL_dostring(L, dostring))
+ report("Error parsing the command-line");
+ }
+
if (luaL_loadfile(L,o.cmdexec) != 0)
report("Error loading the Lua script");
@@ -286,10 +291,11 @@
lua_close(L);
}
-void script_list_add_filename(struct script_list_node **list, char *filename)
+void script_list_add_filename(struct script_list_node **list, char *filename, char *args)
{
struct script_list_node *node = (struct script_list_node *) safe_malloc(sizeof(*node));
node->filename = filename;
+ node->args = args;
node->next = *list;
*list = node;
}
Modified: nmap-exp/d33tah/ncat-lua-with/ncat/ncat_lua.h
==============================================================================
--- nmap-exp/d33tah/ncat-lua-with/ncat/ncat_lua.h (original)
+++ nmap-exp/d33tah/ncat-lua-with/ncat/ncat_lua.h Wed Jul 17 17:32:16 2013
@@ -106,16 +106,17 @@
}
#endif
-void lua_setup(void);
+void lua_setup(char *dostring);
void lua_add_pipe(int fd, char *varname, char* mode);
void lua_run(void);
void lua_shutdown(void);
struct script_list_node {
char *filename;
+ char *args;
struct script_list_node *next;
};
-void script_list_add_filename(struct script_list_node **list, char *filename);
+void script_list_add_filename(struct script_list_node **list, char *filename, char *args);
#endif
Modified: nmap-exp/d33tah/ncat-lua-with/ncat/ncat_main.c
==============================================================================
--- nmap-exp/d33tah/ncat-lua-with/ncat/ncat_main.c (original)
+++ nmap-exp/d33tah/ncat-lua-with/ncat/ncat_main.c Wed Jul 17 17:32:16 2013
@@ -514,20 +514,28 @@
http://seclists.org/nmap-dev/2013/q2/492 */
ncat_assert(argc == 3);
o.cmdexec = argv[2];
- lua_setup();
+ lua_setup(NULL);
lua_run();
}
else if (strcmp(long_options[option_index].name, "lua-extensions") == 0) {
o.lua_extensions = 1;
}
else if (strcmp(long_options[option_index].name, "with") == 0) {
- char *script_name;
- int name_len;
+ char *script_name, *script_args, *args_expr = NULL;
+ int name_len, args_expr_len;
if (o.scripts != NULL && o.execmode != EXEC_SCRIPT)
bye("Cannot mix --with command-line switch with --lua-exec,"
" --sh-exec or --exec.");
+ if (script_args = strstr(optarg,",")) {
+ optarg[script_args-optarg] = '\0';
+ script_args++; //skip the comma
+ args_expr_len = strlen("args = {") + strlen(script_args) + 16;
+ args_expr = (char*) safe_zalloc(args_expr_len);
+ Snprintf(args_expr, args_expr_len, "args = {%s}\n", script_args);
+ }
+
/* at the moment the search directory is hardcoded. */
name_len = strlen("scripts/") + strlen(optarg) + strlen(".lua") + 32;
script_name = (char*) safe_malloc(name_len);
@@ -540,9 +548,9 @@
logdebug("Registering script name %s\n", script_name);
o.cmdexec = script_name;
- lua_setup();
+ lua_setup(NULL);
lua_shutdown();
- script_list_add_filename(&o.scripts, script_name);
+ script_list_add_filename(&o.scripts, script_name, args_expr);
o.execmode = EXEC_SCRIPT;
o.lua_extensions = 1;
@@ -879,7 +887,7 @@
bye("--lua-extensions requires --lua-exec to work.");
}
if (o.execmode == EXEC_LUA)
- lua_setup();
+ lua_setup(NULL);
#endif
if (o.listen)
Modified: nmap-exp/d33tah/ncat-lua-with/ncat/ncat_posix.c
==============================================================================
--- nmap-exp/d33tah/ncat-lua-with/ncat/ncat_posix.c (original)
+++ nmap-exp/d33tah/ncat-lua-with/ncat/ncat_posix.c Wed Jul 17 17:32:16 2013
@@ -448,7 +448,7 @@
/* Discard the pipes possibly created before calling netexec(),
in ncat_connect.c/ncat_listen.c. This has to be tested or
redesigned. */
- lua_setup(); //Actually load the script.
+ lua_setup(current->args); //Actually load the script.
if (current->next != NULL) {
/* Only close the other sides of the pipe if it's not the
topmost script - otherwise, they weren't created. */
_______________________________________________
Sent through the svn mailing list
http://nmap.org/mailman/listinfo/svn
Since the branch feels kind of doomed now, I thought I'd commit the patch I had in stash. _______________________________________________ Sent through the dev mailing list http://nmap.org/mailman/listinfo/dev Archived at http://seclists.org/nmap-dev/
Current thread:
- Re: [nmap-svn] r31387 - nmap-exp/d33tah/ncat-lua-with/ncat Jacek Wielemborek (Jul 17)
