Nmap Development mailing list archives

RE: NSE PJL proof of concept


From: Aaron Leininger <rilian4 () hotmail com>
Date: Fri, 10 Jul 2009 11:16:43 -0700


OK. I have the proof of concept w/ script arg support working in a rudimentary way. One little issue I can't seem to 
resolve is that I can't seem to send an argument with a space in it...even if encapsulated in quotes. 

First, here is my current code (I know it is not elegant but I am still learning lua and in context of NSE is seemingly 
hard for me to debug)

id="Printer display setting script"
description="Proof of concept that will change the display message on the target printer"
author = "Aaron Leininger <rilian4 () hotmail com>" 
license = "Same as Nmap--See http://nmap.org/book/man-legal.html";
categories = {"discovery"}

require "nmap"
require "shortport"
portrule = shortport.port_or_service(9100, "jetdirect")

action = function(host, port)
    if not nmap.registry.args.msg then
        local rdymsgarg="nmap test"
        return("Error: Please supply a message")
    else
        local rdymsgarg=nmap.registry.args.msg
        local rdymsg="@PJL RDYMSG DISPLAY = \""..rdymsgarg.."\"\r\n"
    
        local socket = nmap.new_socket()    
        socket:set_timeout(1000)
        try = nmap.new_try(function() socket:close() end)
        try(socket:connect(host.ip, port.number))
        try(socket:send(rdymsg))
        socket:close()
        return (rdymsg.."was sent to printer at "..host.ip)
    end
end
===================
If no script argument is supplied, it will kick out a statement asking for the user to supply an argument. I'd love to 
find a way to do a default ready message instead but when I tried pulling the return commands outside of the 
if-then-else statement, I got nothing to work. 

$nmap -p9100 --script-trace --script-args msg="longtest message" --script=./hptelnet3.nse printerip


If I supply an argument w/o spaces, it is sent correctly to the printer. If I supply an argument with a space, I get 
the following error:
NSE: failed to initialize the script engine:
/usr/local/share/nmap/nse_main.lua:549: Value around 'longtest me' is invalid or is unterminated by a valid seperator
stack traceback:
        [C]: in function 'error'
        /usr/local/share/nmap/nse_main.lua:549: in function 'parse_string'
        /usr/local/share/nmap/nse_main.lua:580: in function 'parse_table'
        /usr/local/share/nmap/nse_main.lua:590: in main chunk
        [C]: ?

QUITTING!
==================
Oddly enough, if I shorten the amount of characters, I get a slightly different error:
$nmap -p9100 --script-trace --script-args msg="longtest m" --script=./hptelnet3.nse printerip

...
/usr/local/share/nmap/nse_main.lua:549: Value around 'longtest m}' is invalid or is unterminated by a valid seperator
...
Note the curly brace in the error line after my text. As far as I can see from the online documentation, single quotes 
or double quotes should be usable to push an argument w/ a space. What am I doing wrong? 

Also feel free to show me better ways to accomplish what I am after. I am not adverse to suggestions. I am trying to 
learn lua syntax for use w/ NSE and it is proving to be less than intuitive so far. I can see huge potential in NSE for 
myself if I can wrap my brain around the syntax successfully. 

Thanks for your time! 
Aaron

_________________________________________________________________
Windows Liveā„¢ HotmailĀ®: Find, add, and share the best celeb pics, right from Hotmail. Check it out.
http://www.windowslive.com/Online/Hotmail/Campaign/QuickAdd?ocid=TXT_TAGLM_WL_QA_HM_celebrity_photos2_072009&cat=celebrity

_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org


Current thread: