diff --git a/lib/rex/proto/pjl.rb b/lib/rex/proto/pjl.rb index 338a4f9153..990ce64868 100644 --- a/lib/rex/proto/pjl.rb +++ b/lib/rex/proto/pjl.rb @@ -1,2 +1,16 @@ -require "rex/proto/pjl/constants" -require "rex/proto/pjl/client" +# https://en.wikipedia.org/wiki/Printer_Job_Language +# See external links for PJL spec + +module Rex::Proto::PJL + + require "rex/proto/pjl/client" + + UEL = "\e%-12345X" # Universal Exit Language + PREFIX = "@PJL" + + INFO_ID = "#{PREFIX} INFO ID" + INFO_STATUS = "#{PREFIX} INFO STATUS" + + RDYMSG_DISPLAY = "#{PREFIX} RDYMSG DISPLAY" + +end diff --git a/lib/rex/proto/pjl/client.rb b/lib/rex/proto/pjl/client.rb index e4c1122bd1..b37fd1bb4c 100644 --- a/lib/rex/proto/pjl/client.rb +++ b/lib/rex/proto/pjl/client.rb @@ -1,95 +1,80 @@ -# # https://en.wikipedia.org/wiki/Printer_Job_Language -# # See external links for PJL spec -# - -module Rex -module Proto -module PJL +module Rex::Proto::PJL class Client def initialize(sock) @sock = sock end - # # Begin PJL job # - def pjl_begin_job - command = "#{PJL_UEL}#{PJL_PREFIX}\n" + # @return [void] + def begin_job + command = "#{UEL}#{PREFIX}\n" @sock.put(command) end - # # End PJL job # - def pjl_end_job - command = "#{PJL_UEL}\n" + # @return [void] + def end_job + command = "#{UEL}\n" @sock.put(command) end - # # Send INFO request and receive response # # @param category [String] INFO category # @return [String] INFO response - # - def pjl_get_info(category) + def get_info(category) case category - when :id - command = "#{PJL_INFO_ID}\n" - when :status - command = "#{PJL_INFO_STATUS}\n" + when :id + command = "#{INFO_ID}\n" + when :status + command = "#{INFO_STATUS}\n" end - pjl_begin_job + begin_job @sock.put(command) - pjl_end_job + end_job @sock.get_once end - # # Get version information # # @return [String] Version information - # - def pjl_get_info_id + def get_info_id id = nil - response = pjl_get_info(:id) + response = get_info(:id) if response =~ /"(.*)"/ id = $1 end return id end - # # Get ready message # # @return [String] Ready message - # - def pjl_get_rdymsg + def get_rdymsg rdymsg = nil - response = pjl_get_info(:status) + response = get_info(:status) if response =~ /DISPLAY="(.*)"/ rdymsg = $1 end return rdymsg end - # # Set ready message # # @param message [String] Ready message - # - def pjl_set_rdymsg(message) - command = %Q{#{PJL_RDYMSG_DISPLAY} = "#{message}"\n} - pjl_begin_job + # @return [void] + def set_rdymsg(message) + command = %Q{#{RDYMSG_DISPLAY} = "#{message}"\n} + begin_job @sock.put(command) - pjl_end_job + end_job end end end -end -end diff --git a/lib/rex/proto/pjl/constants.rb b/lib/rex/proto/pjl/constants.rb deleted file mode 100644 index 3e2187d720..0000000000 --- a/lib/rex/proto/pjl/constants.rb +++ /dev/null @@ -1,26 +0,0 @@ -# -# https://en.wikipedia.org/wiki/Printer_Job_Language -# -# See external links for PJL spec -# - -module Rex -module Proto -module PJL - -# Miscellaneous constants -PJL_PREFIX = "@PJL" - -# Kernel commands -PJL_UEL = "\e%-12345X" - -# Status readback commands -PJL_INFO_ID = "#{PJL_PREFIX} INFO ID" -PJL_INFO_STATUS = "#{PJL_PREFIX} INFO STATUS" - -# Device attendance commands -PJL_RDYMSG_DISPLAY = "#{PJL_PREFIX} RDYMSG DISPLAY" - -end -end -end diff --git a/modules/auxiliary/scanner/printer/printer_ready_message.rb b/modules/auxiliary/scanner/printer/printer_ready_message.rb index f7f80200e4..1da41fff54 100644 --- a/modules/auxiliary/scanner/printer/printer_ready_message.rb +++ b/modules/auxiliary/scanner/printer/printer_ready_message.rb @@ -8,9 +8,9 @@ require "rex/proto/pjl" class Metasploit4 < Msf::Auxiliary - include Msf::Auxiliary::Scanner - include Msf::Auxiliary::Report include Msf::Exploit::Remote::Tcp + include Msf::Auxiliary::Report + include Msf::Auxiliary::Scanner def initialize(info = {}) super(update_info(info, @@ -39,11 +39,11 @@ class Metasploit4 < Msf::Auxiliary def run_host(ip) connect pjl = Rex::Proto::PJL::Client.new(sock) - rdymsg = pjl.pjl_get_rdymsg + rdymsg = pjl.get_rdymsg if datastore["CHANGE"] message = datastore["MESSAGE"] - pjl.pjl_set_rdymsg(message) - rdymsg = pjl.pjl_get_rdymsg + pjl.set_rdymsg(message) + rdymsg = pjl.get_rdymsg end disconnect diff --git a/modules/auxiliary/scanner/printer/printer_version.rb b/modules/auxiliary/scanner/printer/printer_version.rb index 65fe4bd8b2..efa324c5c3 100644 --- a/modules/auxiliary/scanner/printer/printer_version.rb +++ b/modules/auxiliary/scanner/printer/printer_version.rb @@ -8,9 +8,9 @@ require "rex/proto/pjl" class Metasploit4 < Msf::Auxiliary - include Msf::Auxiliary::Scanner - include Msf::Auxiliary::Report include Msf::Exploit::Remote::Tcp + include Msf::Auxiliary::Report + include Msf::Auxiliary::Scanner def initialize(info = {}) super(update_info(info, @@ -37,7 +37,7 @@ class Metasploit4 < Msf::Auxiliary def run_host(ip) connect pjl = Rex::Proto::PJL::Client.new(sock) - id = pjl.pjl_get_info_id + id = pjl.get_info_id disconnect if id