tremblerz

commits

Jun 23rd, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 22.38 KB | None | 0 0
  1. commit e5f0581649ca5ad8d9f7dab05decef4bbdfdd153
  2. Author: batrick <batrick@e0a8ed71-7df4-0310-8962-fdc924857419>
  3. Date:   Wed Jul 30 20:49:19 2014 +0000
  4.  
  5.     Use ssize_t for read return.
  6.    
  7.    
  8.     git-svn-id: https://svn.nmap.org/nmap-exp/devin/nse-debugger@33385 e0a8ed71-7df4-0310-8962-fdc924857419
  9.  
  10. diff --git a/nmap_tty.cc b/nmap_tty.cc
  11. index b223b36..ab9fb81 100644
  12. --- a/nmap_tty.cc
  13. +++ b/nmap_tty.cc
  14. @@ -379,8 +379,7 @@ bool keyWasPressed()
  15.    return false;
  16.  }
  17.  
  18. -int tty_read(char *buffer, size_t length) {
  19. -  int num_chars;
  20. +ssize_t tty_read(char *buffer, size_t length) {
  21.  #ifdef __CYGWIN32__
  22.    fd_set set;
  23.    struct timeval tv;
  24. @@ -391,10 +390,9 @@ int tty_read(char *buffer, size_t length) {
  25.      FD_ZERO(&set); FD_SET(tty_fd, &set);
  26.      tv.tv_sec = 0; tv.tv_usec = 0;
  27.      if (select(tty_fd + 1, &set, NULL, NULL, &tv) <= 0)
  28. -    return -1;
  29. +        return -1;
  30.  #endif
  31. -    num_chars = read(tty_fd, buffer, length);
  32. -    return num_chars;
  33. +    return read(tty_fd, buffer, length);
  34.    }  
  35.    return -1;    
  36.  }
  37. diff --git a/nmap_tty.h b/nmap_tty.h
  38. index 187297e..921b92d 100644
  39. --- a/nmap_tty.h
  40. +++ b/nmap_tty.h
  41. @@ -134,6 +134,6 @@ void tty_init();
  42.     calling method should print a status message */
  43.  bool keyWasPressed();
  44.  
  45. -int tty_read(char *buffer, size_t length);
  46. +ssize_t tty_read(char *buffer, size_t length);
  47.  
  48.  void set_tty_echo(int echo_on);
  49. diff --git a/nse_main.cc b/nse_main.cc
  50. index 3afd5fa..c45748b 100644
  51. --- a/nse_main.cc
  52. +++ b/nse_main.cc
  53. @@ -165,7 +165,7 @@ static int key_was_pressed (lua_State *L)
  54.  
  55.  static int l_read_tty (lua_State *L) {
  56.    char buf[4096];
  57. -  int bytes_read = tty_read(buf, sizeof(buf));
  58. +  ssize_t bytes_read = tty_read(buf, sizeof(buf));
  59.    if (bytes_read > 0) {
  60.      lua_pushlstring(L, buf, bytes_read);
  61.      return 1;
  62.  
  63. commit 672a74def54d7345be06afcbde24db5ae85e9dd1
  64. Author: batrick <batrick@e0a8ed71-7df4-0310-8962-fdc924857419>
  65. Date:   Mon Jun 23 21:59:42 2014 +0000
  66.  
  67.     Fix some bugs I made.
  68.    
  69.    
  70.     git-svn-id: https://svn.nmap.org/nmap-exp/devin/nse-debugger@33052 e0a8ed71-7df4-0310-8962-fdc924857419
  71.  
  72. diff --git a/nse_main.lua b/nse_main.lua
  73. index 7cae80e..5bbe685 100644
  74. --- a/nse_main.lua
  75. +++ b/nse_main.lua
  76. @@ -245,7 +245,7 @@ do
  77.      end
  78.      local line, leftover = match(buff, "(.-)\n(.*)")
  79.      if line then
  80. -      buf = leftover
  81. +      buff = leftover
  82.      end
  83.      return line
  84.    end
  85. @@ -1009,12 +1009,13 @@ local function run (threads_iter, hosts)
  86.            if script_to_kill then
  87.              for co, thread in pairs(all) do
  88.                if thread.id == script_to_kill then
  89. -                all[co], waiting[co], running[co], pending[co] = nil, nil, nil, nil
  90. +                all[co], waiting[co], running[co], pending[co], num_threads = nil, nil, nil, nil, num_threads-1;
  91.                  debug_out("Killed script %s: %s\n", script_to_kill, co)
  92. +                thread:close(timeouts, "killed");
  93.                end
  94.              end
  95.            end
  96. -        else
  97. +        elseif cmd then
  98.            debug_out("Command not recognized: '" .. cmd .. "'\n")
  99.          end
  100.          debug_out(">>")
  101.  
  102. commit 63e3a252bf1b04876aef8234575365bc3fcf021b
  103. Author: batrick <batrick@e0a8ed71-7df4-0310-8962-fdc924857419>
  104. Date:   Mon Jun 23 21:32:39 2014 +0000
  105.  
  106.     Simplify bit flag generation.
  107.    
  108.    
  109.     git-svn-id: https://svn.nmap.org/nmap-exp/devin/nse-debugger@33051 e0a8ed71-7df4-0310-8962-fdc924857419
  110.  
  111. diff --git a/output.h b/output.h
  112. index 7ff3bc9..c0a6e29 100644
  113. --- a/output.h
  114. +++ b/output.h
  115. @@ -131,17 +131,17 @@
  116.  #ifndef OUTPUT_H
  117.  #define OUTPUT_H
  118.  
  119. -#define LOG_NUM_FILES 4 /* # of values that actual files (they must come first */
  120. -#define LOG_FILE_MASK 15 /* The mask for log types in the file array */
  121. -#define LOG_NORMAL 1
  122. -#define LOG_MACHINE 2
  123. -#define LOG_SKID 4
  124. -#define LOG_XML 8
  125. -#define LOG_STDOUT 1024
  126. -#define LOG_STDERR 2048
  127. -#define LOG_SKID_NOXLT 4096
  128. -#define LOG_DEBUGOUT 8192
  129. -#define LOG_DEBUGERR 16384
  130. +#define LOG_NUM_FILES       4 /* # of values that actual files (they must come first). */
  131. +#define LOG_FILE_MASK  (0x0f) /* The mask for log types in the file array. */
  132. +#define LOG_NORMAL     (1<<0)
  133. +#define LOG_MACHINE    (1<<1)
  134. +#define LOG_SKID       (1<<2)
  135. +#define LOG_XML        (1<<3)
  136. +#define LOG_STDOUT     (1<<10)
  137. +#define LOG_STDERR     (1<<11)
  138. +#define LOG_SKID_NOXLT (1<<12)
  139. +#define LOG_DEBUGOUT   (1<<13)
  140. +#define LOG_DEBUGERR   (1<<14)
  141.  #define LOG_MAX LOG_DEBUGERR /* The maximum log type value */
  142.  
  143.  #define LOG_PLAIN LOG_NORMAL|LOG_SKID|LOG_STDOUT
  144.  
  145. commit 97c0998269882a59c98867e63da54598a6a9b770
  146. Author: batrick <batrick@e0a8ed71-7df4-0310-8962-fdc924857419>
  147. Date:   Sat Jun 14 22:57:09 2014 +0000
  148.  
  149.     More minor code changes.
  150.    
  151.    
  152.     git-svn-id: https://svn.nmap.org/nmap-exp/devin/nse-debugger@33013 e0a8ed71-7df4-0310-8962-fdc924857419
  153.  
  154. diff --git a/nse_main.lua b/nse_main.lua
  155. index aacfdb1..7cae80e 100644
  156. --- a/nse_main.lua
  157. +++ b/nse_main.lua
  158. @@ -218,13 +218,13 @@ end
  159.  
  160.  ---
  161.  -- Writes to stdout if NSE debugger is enabled
  162. -function debug_out(fmt, ...)
  163. +local function debug_out(fmt, ...)
  164.    log_write_raw("debugout", format(fmt, ...))
  165.  end
  166.  
  167.  ---
  168.  -- Writes to stderr if NSE debugger is enabled
  169. -function debug_err(fmt, ...)
  170. +local function debug_err(fmt, ...)
  171.    log_write_raw("debugerr", format(fmt, ...))
  172.  end
  173.  
  174. @@ -233,23 +233,21 @@ end
  175.  -- It does this by reading bytes incrementally, and returning nil until it has
  176.  -- collected an entire line to return. Meant to be called when NmapOpts.nse_dubugger_active
  177.  -- is set because otherwise calls to keywaspressed() will result in the tty being flushed.
  178. +local readline;
  179.  do
  180.    local buff = ""
  181.    function readline()
  182.      if not find(buff, "\n") then
  183. -      local bytes = cnse.read_tty(128)
  184. +      local bytes = cnse.read_tty()
  185.        if bytes then
  186.          buff = buff .. bytes
  187.        end
  188.      end
  189. -    if find(buff, "\n") then
  190. -      local index = find(buff, "\n")
  191. -      local line = sub(buff, 1, index)
  192. -      buff = sub(buff, index+1, -1)
  193. -      return line
  194. -    else
  195. -      return nil
  196. +    local line, leftover = match(buff, "(.-)\n(.*)")
  197. +    if line then
  198. +      buf = leftover
  199.      end
  200. +    return line
  201.    end
  202.  end
  203.  
  204. @@ -989,6 +987,7 @@ local function run (threads_iter, hosts)
  205.      end
  206.  
  207.      local nr, nw = table_size(running), table_size(waiting);
  208. +    -- TODO support tab-completion (requires turning echo off), EOF for "exit", "help"
  209.      if cnse.debugger_enabled() then
  210.        local line = readline()
  211.        if line then
  212.  
  213. commit 29ac46c750356bfd428ff5cec8ae78fa361b9398
  214. Author: batrick <batrick@e0a8ed71-7df4-0310-8962-fdc924857419>
  215. Date:   Sat Jun 14 22:54:55 2014 +0000
  216.  
  217.     Some code simplification.
  218.    
  219.    
  220.     git-svn-id: https://svn.nmap.org/nmap-exp/devin/nse-debugger@33012 e0a8ed71-7df4-0310-8962-fdc924857419
  221.  
  222. diff --git a/nse_main.cc b/nse_main.cc
  223. index bb925b3..3afd5fa 100644
  224. --- a/nse_main.cc
  225. +++ b/nse_main.cc
  226. @@ -164,19 +164,14 @@ static int key_was_pressed (lua_State *L)
  227.  }
  228.  
  229.  static int l_read_tty (lua_State *L) {
  230. -  const int max_bytes = luaL_checkint(L, 1);
  231. -  luaL_Buffer b;
  232. -  char *buff = new char[max_bytes];
  233. -  int bytes_read = tty_read(buff, max_bytes);
  234. +  char buf[4096];
  235. +  int bytes_read = tty_read(buf, sizeof(buf));
  236.    if (bytes_read > 0) {
  237. -    luaL_buffinitsize(L, &b, bytes_read);
  238. -    luaL_addlstring(&b, buff, bytes_read);  
  239. -    luaL_pushresultsize(&b, bytes_read-1);
  240. +    lua_pushlstring(L, buf, bytes_read);
  241. +    return 1;
  242.    } else {
  243. -    lua_pushnil(L);
  244. +    return nseU_safeerror(L, "%s", strerror(errno));
  245.    }
  246. -  delete[] buff;  
  247. -  return 1;
  248.  }
  249.  
  250.  static int l_debugger_enabled(lua_State *L) {
  251. @@ -188,9 +183,8 @@ static int l_debugger_enabled(lua_State *L) {
  252.  }
  253.  
  254.  static int l_set_debugger(lua_State *L) {
  255. -  bool val = lua_toboolean(L,1);
  256. -  o.nse_debugger_enabled = val;
  257. -  set_tty_echo(val);
  258. +  o.nse_debugger_enabled = lua_toboolean(L,1);
  259. +  set_tty_echo(o.nse_debugger_enabled);
  260.    return 0;
  261.  }
  262.  
  263.  
  264. commit 581d7cc8faa90fe12b84ebac7f4624e1fc78139a
  265. Author: batrick <batrick@e0a8ed71-7df4-0310-8962-fdc924857419>
  266. Date:   Sat Jun 14 22:53:36 2014 +0000
  267.  
  268.     Use size_t/int.
  269.    
  270.     Forgot to add this to previous commit.
  271.    
  272.    
  273.     git-svn-id: https://svn.nmap.org/nmap-exp/devin/nse-debugger@33011 e0a8ed71-7df4-0310-8962-fdc924857419
  274.  
  275. diff --git a/nmap_tty.cc b/nmap_tty.cc
  276. index 24a09e8..b223b36 100644
  277. --- a/nmap_tty.cc
  278. +++ b/nmap_tty.cc
  279. @@ -379,7 +379,7 @@ bool keyWasPressed()
  280.    return false;
  281.  }
  282.  
  283. -int tty_read(char *buffer, int length) {
  284. +int tty_read(char *buffer, size_t length) {
  285.    int num_chars;
  286.  #ifdef __CYGWIN32__
  287.    fd_set set;
  288. @@ -399,7 +399,7 @@ int tty_read(char *buffer, int length) {
  289.    return -1;    
  290.  }
  291.  
  292. -void set_tty_echo(bool echo_on) {
  293. +void set_tty_echo(int echo_on) {
  294.    if (!tty_fd) return;
  295.  
  296.    struct termios ti;
  297.  
  298. commit 379e2cae5cefc4d97e51ac2bcd40365b65ba5c4e
  299. Author: batrick <batrick@e0a8ed71-7df4-0310-8962-fdc924857419>
  300. Date:   Sat Jun 14 22:52:58 2014 +0000
  301.  
  302.     Use size_t and int.
  303.    
  304.    
  305.     git-svn-id: https://svn.nmap.org/nmap-exp/devin/nse-debugger@33010 e0a8ed71-7df4-0310-8962-fdc924857419
  306.  
  307. diff --git a/nmap_tty.h b/nmap_tty.h
  308. index b7e6b56..187297e 100644
  309. --- a/nmap_tty.h
  310. +++ b/nmap_tty.h
  311. @@ -134,6 +134,6 @@ void tty_init();
  312.     calling method should print a status message */
  313.  bool keyWasPressed();
  314.  
  315. -int tty_read(char* buffer, int length);
  316. +int tty_read(char *buffer, size_t length);
  317.  
  318. -void set_tty_echo(bool echo_on);
  319. +void set_tty_echo(int echo_on);
  320.  
  321. commit 9973b9c514f257b0bdf737973ec766368eafb55a
  322. Author: devin <devin@e0a8ed71-7df4-0310-8962-fdc924857419>
  323. Date:   Fri Jun 13 04:45:58 2014 +0000
  324.  
  325.     Prototype of NSE debugger, demonstrates changes to the tty.
  326.    
  327.    
  328.     git-svn-id: https://svn.nmap.org/nmap-exp/devin/nse-debugger@33007 e0a8ed71-7df4-0310-8962-fdc924857419
  329.  
  330. diff --git a/NmapOps.cc b/NmapOps.cc
  331. index 24fc1d0..835e8bc 100644
  332. --- a/NmapOps.cc
  333. +++ b/NmapOps.cc
  334. @@ -359,6 +359,7 @@ void NmapOps::Initialize() {
  335.    numhosts_up = 0;
  336.    numhosts_scanning = 0;
  337.    noninteractive = false;
  338. +  nse_debugger_enabled = false;
  339.    current_scantype = STYPE_UNKNOWN;
  340.    ipoptions = NULL;
  341.    ipoptionslen = 0;
  342. diff --git a/NmapOps.h b/NmapOps.h
  343. index 89eb41d..65c876b 100644
  344. --- a/NmapOps.h
  345. +++ b/NmapOps.h
  346. @@ -401,6 +401,7 @@ class NmapOps {
  347.    stype current_scantype;
  348.    bool noninteractive;
  349.  
  350. +  bool nse_debugger_enabled;
  351.    bool release_memory; /* suggest to release memory before quitting. used to find memory leaks. */
  352.   private:
  353.    int max_os_tries;
  354. diff --git a/nmap_tty.cc b/nmap_tty.cc
  355. index 463b364..24a09e8 100644
  356. --- a/nmap_tty.cc
  357. +++ b/nmap_tty.cc
  358. @@ -307,7 +307,7 @@ bool keyWasPressed()
  359.    static struct timeval stats_time = { 0 };
  360.    int c;
  361.  
  362. -  if (o.noninteractive)
  363. +  if (o.noninteractive || o.nse_debugger_enabled)
  364.      return false;
  365.  
  366.    if ((c = tty_getchar()) >= 0) {
  367. @@ -327,6 +327,10 @@ bool keyWasPressed()
  368.      } else if (c == 'D') {
  369.         if (o.debugging > 0) o.debugging--;
  370.         log_write(LOG_STDOUT, "Debugging Decreased to %d.\n", o.debugging);
  371. +    } else if (c == 'n') {
  372. +       o.nse_debugger_enabled = true;
  373. +       log_write(LOG_DEBUGOUT, "NSE Debugger enabled.\n>>");
  374. +       set_tty_echo(true);
  375.      } else if (c == 'p') {
  376.         o.setPacketTrace(true);
  377.         log_write(LOG_STDOUT, "Packet Tracing enabled.\n");
  378. @@ -374,3 +378,37 @@ bool keyWasPressed()
  379.  
  380.    return false;
  381.  }
  382. +
  383. +int tty_read(char *buffer, int length) {
  384. +  int num_chars;
  385. +#ifdef __CYGWIN32__
  386. +  fd_set set;
  387. +  struct timeval tv;
  388. +#endif
  389. +
  390. +  if (tty_fd && tcgetpgrp(tty_fd) == getpgrp()) {
  391. +#ifdef __CYGWIN32__
  392. +    FD_ZERO(&set); FD_SET(tty_fd, &set);
  393. +    tv.tv_sec = 0; tv.tv_usec = 0;
  394. +    if (select(tty_fd + 1, &set, NULL, NULL, &tv) <= 0)
  395. +    return -1;
  396. +#endif
  397. +    num_chars = read(tty_fd, buffer, length);
  398. +    return num_chars;
  399. +  }  
  400. +  return -1;    
  401. +}
  402. +
  403. +void set_tty_echo(bool echo_on) {
  404. +  if (!tty_fd) return;
  405. +
  406. +  struct termios ti;
  407. +  tcgetattr(tty_fd, &ti);
  408. +  if (echo_on) {
  409. +        ti.c_lflag |= ECHO;
  410. +  }
  411. +  else {
  412. +        ti.c_lflag &= ~( ECHO);
  413. +  }
  414. +  tcsetattr(tty_fd, TCSANOW, &ti);
  415. +}
  416. diff --git a/nmap_tty.h b/nmap_tty.h
  417. index 944d916..b7e6b56 100644
  418. --- a/nmap_tty.h
  419. +++ b/nmap_tty.h
  420. @@ -134,3 +134,6 @@ void tty_init();
  421.     calling method should print a status message */
  422.  bool keyWasPressed();
  423.  
  424. +int tty_read(char* buffer, int length);
  425. +
  426. +void set_tty_echo(bool echo_on);
  427. diff --git a/nse_main.cc b/nse_main.cc
  428. index 362d167..bb925b3 100644
  429. --- a/nse_main.cc
  430. +++ b/nse_main.cc
  431. @@ -163,6 +163,37 @@ static int key_was_pressed (lua_State *L)
  432.    return 1;
  433.  }
  434.  
  435. +static int l_read_tty (lua_State *L) {
  436. +  const int max_bytes = luaL_checkint(L, 1);
  437. +  luaL_Buffer b;
  438. +  char *buff = new char[max_bytes];
  439. +  int bytes_read = tty_read(buff, max_bytes);
  440. +  if (bytes_read > 0) {
  441. +    luaL_buffinitsize(L, &b, bytes_read);
  442. +    luaL_addlstring(&b, buff, bytes_read);  
  443. +    luaL_pushresultsize(&b, bytes_read-1);
  444. +  } else {
  445. +    lua_pushnil(L);
  446. +  }
  447. +  delete[] buff;  
  448. +  return 1;
  449. +}
  450. +
  451. +static int l_debugger_enabled(lua_State *L) {
  452. +  if (o.nse_debugger_enabled)
  453. +    lua_pushboolean(L, true);
  454. +  else
  455. +    lua_pushboolean(L, false);
  456. +  return 1;
  457. +}
  458. +
  459. +static int l_set_debugger(lua_State *L) {
  460. +  bool val = lua_toboolean(L,1);
  461. +  o.nse_debugger_enabled = val;
  462. +  set_tty_echo(val);
  463. +  return 0;
  464. +}
  465. +
  466.  static int scp (lua_State *L)
  467.  {
  468.    static const char * const ops[] = {"printStats", "printStatsIfNecessary",
  469. @@ -200,13 +231,13 @@ static int scan_progress_meter (lua_State *L)
  470.     scripts. */
  471.  static int l_log_write(lua_State *L)
  472.  {
  473. -  static const char *const ops[] = {"stdout", "stderr", NULL};
  474. -  static const int logs[] = {LOG_STDOUT, LOG_STDERR};
  475. +  static const char *const ops[] = {"stdout", "stderr", "debugout", "debugerr", NULL};
  476. +  static const int logs[] = {LOG_STDOUT, LOG_STDERR, LOG_DEBUGOUT, LOG_DEBUGERR};
  477.    int log = logs[luaL_checkoption(L, 1, NULL, ops)];
  478.    log_write(log, "%s", luaL_checkstring(L, 2));
  479.    return 0;
  480.  }
  481. -
  482. +
  483.  static int l_xml_start_tag(lua_State *L)
  484.  {
  485.    const char *name;
  486. @@ -355,6 +386,9 @@ static void open_cnse (lua_State *L)
  487.      {"fetchfile_absolute", fetchfile_absolute},
  488.      {"fetchscript", fetchscript},
  489.      {"key_was_pressed", key_was_pressed},
  490. +    {"read_tty", l_read_tty},
  491. +    {"debugger_enabled", l_debugger_enabled},
  492. +    {"set_debugger", l_set_debugger},
  493.      {"scan_progress_meter", scan_progress_meter},
  494.      {"timedOut", timedOut},
  495.      {"startTimeOutClock", startTimeOutClock},
  496. diff --git a/nse_main.lua b/nse_main.lua
  497. index c2a1fc1..aacfdb1 100644
  498. --- a/nse_main.lua
  499. +++ b/nse_main.lua
  500. @@ -115,6 +115,7 @@ local gsub = string.gsub;
  501.  local lower = string.lower;
  502.  local match = string.match;
  503.  local sub = string.sub;
  504. +local gmatch = string.gmatch
  505.  
  506.  local table = require "table";
  507.  local concat = table.concat;
  508. @@ -215,6 +216,43 @@ local function log_error (fmt, ...)
  509.    log_write("stderr", format(fmt, ...));
  510.  end
  511.  
  512. +---
  513. +-- Writes to stdout if NSE debugger is enabled
  514. +function debug_out(fmt, ...)
  515. +  log_write_raw("debugout", format(fmt, ...))
  516. +end
  517. +
  518. +---
  519. +-- Writes to stderr if NSE debugger is enabled
  520. +function debug_err(fmt, ...)
  521. +  log_write_raw("debugerr", format(fmt, ...))
  522. +end
  523. +
  524. +
  525. +--- Trys to read a line from the tty in a non-blocking manner
  526. +-- It does this by reading bytes incrementally, and returning nil until it has
  527. +-- collected an entire line to return. Meant to be called when NmapOpts.nse_dubugger_active
  528. +-- is set because otherwise calls to keywaspressed() will result in the tty being flushed.
  529. +do
  530. +  local buff = ""
  531. +  function readline()
  532. +    if not find(buff, "\n") then
  533. +      local bytes = cnse.read_tty(128)
  534. +      if bytes then
  535. +        buff = buff .. bytes
  536. +      end
  537. +    end
  538. +    if find(buff, "\n") then
  539. +      local index = find(buff, "\n")
  540. +      local line = sub(buff, 1, index)
  541. +      buff = sub(buff, index+1, -1)
  542. +      return line
  543. +    else
  544. +      return nil
  545. +    end
  546. +  end
  547. +end
  548. +
  549.  local function table_size (t)
  550.    local n = 0; for _ in pairs(t) do n = n + 1; end return n;
  551.  end
  552. @@ -951,6 +989,38 @@ local function run (threads_iter, hosts)
  553.      end
  554.  
  555.      local nr, nw = table_size(running), table_size(waiting);
  556. +    if cnse.debugger_enabled() then
  557. +      local line = readline()
  558. +      if line then
  559. +        local words = gmatch(line, "[^%s]+")
  560. +        local cmd = words()
  561. +        if cmd == "status" then
  562. +          debug_out("Active NSE Script Threads: %d (%d waiting)\n",
  563. +              nr+nw, nw);
  564. +        elseif cmd == "exit" then
  565. +          debug_out("NSE debugger disabled.\n")
  566. +          cnse.set_debugger(false)
  567. +        elseif cmd == "list" then
  568. +          debug_out("Running threads: \n")
  569. +          for co, thread in pairs(all) do
  570. +            debug_out(thread.info .. '\n')
  571. +          end
  572. +        elseif cmd == "kill" then
  573. +          local script_to_kill = words()
  574. +          if script_to_kill then
  575. +            for co, thread in pairs(all) do
  576. +              if thread.id == script_to_kill then
  577. +                all[co], waiting[co], running[co], pending[co] = nil, nil, nil, nil
  578. +                debug_out("Killed script %s: %s\n", script_to_kill, co)
  579. +              end
  580. +            end
  581. +          end
  582. +        else
  583. +          debug_out("Command not recognized: '" .. cmd .. "'\n")
  584. +        end
  585. +        debug_out(">>")
  586. +      end
  587. +    end
  588.      if cnse.key_was_pressed() then
  589.        print_verbose(1, "Active NSE Script Threads: %d (%d waiting)\n",
  590.            nr+nw, nw);
  591. diff --git a/output.cc b/output.cc
  592. index 66b0ec1..695c77e 100644
  593. --- a/output.cc
  594. +++ b/output.cc
  595. @@ -958,12 +958,31 @@ void log_vwrite(int logt, const char *fmt, va_list ap) {
  596.  
  597.      switch (logtype) {
  598.        case LOG_STDOUT:
  599. -        vfprintf(o.nmap_stdout, fmt, ap);
  600. -        break;
  601. +        if (o.nse_debugger_enabled) break;
  602. +        else {
  603. +          vfprintf(o.nmap_stdout, fmt, ap);
  604. +          break;
  605. +        }
  606.  
  607.        case LOG_STDERR:
  608. -        fflush(stdout); // Otherwise some systems will print stderr out of order
  609. -        vfprintf(stderr, fmt, ap);
  610. +        if (o.nse_debugger_enabled) break;
  611. +        else {
  612. +          fflush(stdout); // Otherwise some systems will print stderr out of order
  613. +          vfprintf(stderr, fmt, ap);
  614. +          break;
  615. +        }
  616. +
  617. +      case LOG_DEBUGOUT:
  618. +        if (o.nse_debugger_enabled)
  619. +          vfprintf(o.nmap_stdout, fmt, ap);
  620. +          fflush(stdout);
  621. +        break;
  622. +
  623. +      case LOG_DEBUGERR:
  624. +        if (o.nse_debugger_enabled) {
  625. +          fflush(stdout); // Otherwise some systems will print stderr out of order
  626. +          vfprintf(stderr, fmt, ap);
  627. +        }
  628.          break;
  629.  
  630.        case LOG_SKID_NOXLT:
  631. diff --git a/output.h b/output.h
  632. index 72eab63..7ff3bc9 100644
  633. --- a/output.h
  634. +++ b/output.h
  635. @@ -140,7 +140,9 @@
  636.  #define LOG_STDOUT 1024
  637.  #define LOG_STDERR 2048
  638.  #define LOG_SKID_NOXLT 4096
  639. -#define LOG_MAX LOG_SKID_NOXLT /* The maximum log type value */
  640. +#define LOG_DEBUGOUT 8192
  641. +#define LOG_DEBUGERR 16384
  642. +#define LOG_MAX LOG_DEBUGERR /* The maximum log type value */
  643.  
  644.  #define LOG_PLAIN LOG_NORMAL|LOG_SKID|LOG_STDOUT
  645.  
  646.  
  647. commit 98952a8e03942d41938c4b7b9d2c2171c5548694
  648. Author: devin <devin@e0a8ed71-7df4-0310-8962-fdc924857419>
  649. Date:   Thu Jun 12 21:17:23 2014 +0000
  650.  
  651.     NSE debugger initial commit
  652.    
  653.    
  654.     git-svn-id: https://svn.nmap.org/nmap-exp/devin/nse-debugger@33005 e0a8ed71-7df4-0310-8962-fdc924857419
  655.  
  656. diff --git a/BSDmakefile b/BSDmakefile
  657. new file mode 100644
  658. index 0000000..ecfe32b
  659. --- /dev/null
  660. +++ b/BSDmakefile
  661. @@ -0,0 +1,9 @@
  662. +# $Id$
  663. +# Redirect BSD make to GNU gmake for convenience
  664. +
  665. +USE_GNU:
  666. +       @gmake $(.TARGETS)
  667. +
  668. +$(.TARGETS): USE_GNU
  669. +
  670. +.PHONY: USE_GNU
  671. diff --git a/CHANGELOG b/CHANGELOG
  672. new file mode 100644
  673. index 0000000..169746a
  674. --- /dev/null
  675. +++ b/CHANGELOG
  676. @@ -0,0 +1,13870 @@
  677. +# Nmap Changelog ($Id$); -*-text-*-
  678. +
  679. +o Modify the included libpcap configure script to disable certain unused
  680. +  features: bluetooth, usb, usb-can, and dbus sniffing. Dbus support caused a
  681. +  build problem on CentOS 6.5. [Daniel Miller]
  682. +
  683. +o Added new option --noscript to turn off NSE. Useful to avoid running
  684. +  version-category scripts during a quick -sV scan. [Daniel Miller]
  685. +
  686. +o [NSE] Add bacnet-info script to get device information from SCADA/ICS devices
  687. +  via BACnet (Building Automation and Control Networks) [Stephen Hilt, Michael
  688. +  Toecker]
  689. +
  690. +o [NSE] Add Cisco Anyconnect library and scripts http-cisco-anyconnect,
  691. +  http-vuln-cve2014-2126, http-vuln-cve2014-2127, http-vuln-cve2014-2128 and
  692. +  http-vuln-cve2014-2129. [Patrik Karlsson]
  693. +
  694. +o [NSE] Add enip-info script to get device information from SCADA/ICS devices
  695. +  via EtherNet/IP [Stephen Hilt]
  696. +
  697. +o Fixed a bug which caused Nmap to be unable to have any runtime interaction
  698. +  when called from sudo or from a shell script. [Jay Bosamiya]
  699. +
  700. +o Improvements to whois-ip.nse: fix an unhandled error when a referred-to
  701. +  response could not be understood; add a new pattern to recognise a
  702. +  LACNIC "record not found" type of response and update the way ARIN is
  703. +  queried. [jah]
  704. +
  705. +Nmap 6.46 [2014-04-18]
  706. +
  707. +o [NSE] Made numerous improvements to ssl-heartbleed to provide
  708. +  more reliable detection of the vulnerability.
  709. +
  710. +o [Zenmap] Fixed a bug which caused this crash message:
  711. +     IOError: [Errno socket error] [Errno 10060] A connection attempt failed
  712. +     because the connected party did not properly respond after a period of
  713. +     time, or established connection failed because connected host has
  714. +     failed to
  715. +     respond
  716. +  The bug was caused by us adding a DOCTYPE definition to Nmap's XML
  717.          break;
  718.  
  719.        case LOG_SKID_NOXLT:
  720. diff --git a/output.h b/output.h
  721. index 72eab63..7ff3bc9 100644
  722. --- a/output.h
  723. +++ b/output.h
  724. @@ -140,7 +140,9 @@
  725.  #define LOG_STDOUT 1024
  726.  #define LOG_STDERR 2048
  727.  #define LOG_SKID_NOXLT 4096
  728. -#define LOG_MAX LOG_SKID_NOXLT /* The maximum log type value */
  729. +#define LOG_DEBUGOUT 8192
  730. +#define LOG_DEBUGERR 16384
  731. +#define LOG_MAX LOG_DEBUGERR /* The maximum log type value */
  732.  
  733.  #define LOG_PLAIN LOG_NORMAL|LOG_SKID|LOG_STDOUT
  734.  
  735.  
  736. commit 98952a8e03942d41938c4b7b9d2c2171c5548694
  737. Author: devin <devin@e0a8ed71-7df4-0310-8962-fdc924857419>
  738. Date:   Thu Jun 12 21:17:23 2014 +0000
  739.  
  740.     NSE debugger initial commit
  741.    
  742.    
  743.     git-svn-id: https://svn.nmap.org/nmap-exp/devin/nse-debugger@33005 e0a8ed71-7df4-0310-8962-fdc924857419
Add Comment
Please, Sign In to add comment