【问题标题】:Lua popen with string arguments带有字符串参数的 Lua popen
【发布时间】:2014-12-19 04:01:15
【问题描述】:

我正在尝试使用 popen 将包含多个引号的字符串通过管道传输到 netcat。我有一个运行良好的 Python 命令,但我正在将其转换为 nmap 脚本。我对 Lua 不太熟悉。

Python 版本:

python -c 'print "\x1b%-12345X@PJL FSDIRLIST NAME=\"0:\\..\\..\\..\\\" ENTRY=1 COUNT=999999\x0d\x0a\x1b%-12345X\x0d\x0a"' | nc 192.168.0.1 9100

Lua 尝试的版本:

local handle = assert(io.popen("python -c 'print \"\x1b%-12345X@PJL FSDIRLIST NAME=\"0:\\..\\..\\..\\\" ENTRY=1 COUNT=999999\x0d\x0a\x1b%-12345X\x0d\x0a\"' | nc " .. host .. " " .. port, "r"))

这会导致以下错误:

File "<string>", line 1
    print "2345X@PJL FSDIRLIST NAME="0:\..\..\..\" ENTRY=1 COUNT=999999

有没有办法组织该字符串以便 Lua 接受它?

【问题讨论】:

    标签: lua


    【解决方案1】:

    尝试使用长字符串

    [[python -c 'print "\x1b%-12345X@PJL FSDIRLIST NAME=\"0:\\..\\..\\..\\\" ENTRY=1 COUNT=999999\x0d\x0a\x1b%-12345X\x0d\x0a"' | nc 192.168.0.1 9100]]
    

    【讨论】:

    • 我试过了,得到了错误SyntaxError: unexpected character after line continuation character。这发生在最后一个双引号 print \"\x1b%-12345X@PJL FSDIRLIST NAME=\"0:\\..\\..\\..\\\" ENTRY=1 COUNT=999999\x0d\x0a\x1b%-12345X [11] 0:bash* \x0d\x0a\" 上。我尝试转义字符串中的单引号,但这会导致 EOL while scanning string literal 错误。
    • 我从双引号、单引号和百分号中删除了转义字符。这现在有效。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2012-06-13
    • 2010-12-19
    • 2017-05-23
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多