Tencent / LuaPanda

lua debug and code tools for VS Code
Other
1.27k stars 356 forks source link

variable 'lua_extension' is not declared #126

Open yoke88 opened 3 years ago

yoke88 commented 3 years ago

Describe the bug 想在nmap 中加载debugger,手动满足了socket.core 扩展。但是加载debugger的时候,提示这个变量没有声明。这个变量是从哪里来的?

To Reproduce

vscode-debug.nse 内容如下,然后放到nmap 的scripts 目录里,执行nmap -d --script=vscode-debug 然后报错。

require("LuaPanda").start("127.0.0.1",8818);
description = [[
nmap debug lancher
]]
---—@output—Some sample output
author = "the author"
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
categories = {"external"}
prerule = function()
    return true
end

--- main function
action = function( host, port )
    print("yes")
end
PS C:\WINDOWS\system32> nmap.exe --script=vscode-debug -d
wpcap.dll present, library version: Npcap version 1.10, based on libpcap version 1.9.1
Starting Nmap 7.91 ( https://nmap.org ) at 2021-05-26 15:28 ?D1ú±ê×?ê±??
PORTS: Using top 1000 ports found open (TCP:1000, UDP:0, SCTP:0)
--------------- Timing report ---------------
  hostgroups: min 1, max 100000
  rtt-timeouts: init 1000, min 100, max 10000
  max-scan-delay: TCP 1000, UDP 1000, SCTP 1000
  parallelism: min 0, max 0
  max-retries: 10, host-timeout: 0
  min-rate: 0, max-rate: 0
---------------------------------------------
NSE: Using Lua 5.3.
NSE: Arguments from CLI:
NSE: Failed to load C:\Program Files (x86)\Nmap/scripts\vscode-debug.nse:
C:\Program Files (x86)\Nmap/nselib/LuaPanda.lua:937: variable 'lua_extension' is not declared
stack traceback:
        [C]: in function 'error'
        C:\Program Files (x86)\Nmap/nselib/strict.lua:80: in metamethod '__index'
        C:\Program Files (x86)\Nmap/nselib/LuaPanda.lua:937: in function 'LuaPanda.reGetSock'
        C:\Program Files (x86)\Nmap/nselib/LuaPanda.lua:235: in function 'LuaPanda.start'
        C:\Program Files (x86)\Nmap/scripts\vscode-debug.nse:1: in function <C:\Program Files (x86)\Nmap/scripts\vscode-debug.nse:1>
NSE: failed to initialize the script engine:
C:\Program Files (x86)\Nmap/nse_main.lua:614: could not load script
stack traceback:
        [C]: in function 'error'
        C:\Program Files (x86)\Nmap/nse_main.lua:614: in field 'new'
        C:\Program Files (x86)\Nmap/nse_main.lua:791: in global 'Entry'
        C:\Program Files (x86)\Nmap/scripts\script.db:590: in local 'db_closure'
        C:\Program Files (x86)\Nmap/nse_main.lua:804: in local 'get_chosen_scripts'
        C:\Program Files (x86)\Nmap/nse_main.lua:1312: in main chunk
        [C]: in ?

QUITTING!

Expected behavior 希望能够使用luapanda 调试nmap lua script

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

yoke88 commented 3 years ago

通过注释掉nmap nselib 目录下的strict.lua 里面的error(行),目前可以运行脚本。先执行vscode 里面的run ,这个时候会监听8818 端口,然后执行上面nmap --script=vscode-debug 后,脚本会连接上8818,这个时候就可以调试了。

但是目前来看,要在每个脚本里加这个一行有点麻烦。

还有能有什么方法,可以把这个流程串起来么?

比如listen 8818 后,额外起个任务,自动运行特定命令行以自动attach 到8818 里,现在lannch.json 里似乎只能配置一个listen 8818的任务。

yoke88 commented 3 years ago

image

还有其他两个问题:

  1. 变量在调试的时候,都是显示nil,但是在左边的varible 窗口,的upvalue 会有显示。
  2. 上图10,19行各下了一个断点,但是只有10行的断点断下来了,19行的func内部的断点没有断下来。