-
Notifications
You must be signed in to change notification settings - Fork 3
/
1124-osgi-info.nse
119 lines (99 loc) · 3.78 KB
/
1124-osgi-info.nse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
local string = require "string"
local nmap = require "nmap"
local shortport = require "shortport"
local stdnse = require "stdnse"
local strbuf = require "strbuf"
local table = require "table"
description = [[
Gathers information (a list of server properties) from an Eclipse Equinoxe OSGi
(Open Service Gateway initiative) console.
References:
* https://www.eclipse.org/equinox/documents/quickstart-framework.php
]]
---
-- @usage
-- nmap -p <port> <ip> --script osgi-info
--
-- @output
-- PORT STATE SERVICE REASON
-- 5555/tcp open telnet Eclipse Equinoxe OSGi Shell (direct mode)
-- | osgi-info:
-- | username: root
-- | OS Version: Linux 4.4.0-38-generic (amd64 little endian)
-- | Java Runtime: 1.8.0_101-b13 (Java(TM) SE Runtime Environment)
-- |_ Java VM: 25.101-b13 (Java HotSpot(TM) 64-Bit Server VM)
--
-- @xmloutput
-- <elem key="username">root</elem>
-- <elem key="OS Version">Linux 4.4.0-38-generic (amd64 little endian)</elem>
-- <elem key="Java Runtime">1.8.0_101-b13 (Java(TM) SE Runtime Environment)</elem>
-- <elem key="Java VM">25.101-b13 (Java HotSpot(TM) 64-Bit Server VM)</elem>
author = "Quentin Kaiser"
license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
categories = {"default", "discovery", "safe", "version"}
portrule = shortport.service('telnet')
local telnet_eol = "\r\n"
action = function(host, port)
local result = stdnse.output_table()
-- osgi prompt regular expression
local prompt_regexp = "(osgi>)"
-- properties parsing regular expression
local props_regexp = "([^=]+)=([^\r|^\n]*)"
-- command to get system properties
local props_cmd = "getprop"
local disconnect_cmd = "disconnect"
local confirm_cmd = "y"
-- socket handler
local socket = nmap.new_socket()
local catch = function() socket:close() end
local try = nmap.new_try(catch)
-- connect
try(socket:connect(host, port))
socket:set_timeout(7500)
data = try(socket:receive())
-- if we receive IAC negotiations matching the signature, we negotiate
if data == string.pack("<B<B<B<B<B<B<B<B<B<B<B<B",
0xFF, 0xFB, 0x01, 0xFF, 0xFB, 0x03, 0xFF, 0xFD, 0x1F, 0xFF, 0xFD, 0x18) then
local nego1 = string.pack("<B<B<B<B<B<B<B<B<B<B<B<B<B<B<B<B<B<B<B<B<B",
0xFF, 0xFD, 0x01, 0xFF, 0xFD, 0x03, 0xFF, 0xFB, 0x1F, 0xFF, 0xFA, 0x1F,
0x00, 0x3B, 0x00, 0x1D, 0xFF, 0xF0, 0xFF, 0xFB, 0x18)
local nego2 = string.pack("<B<B<B<B<B<B<B<B<B<B<B<B<B<B<B<B<B<B<B<B",
0xFF, 0xFA, 0x18, 0x00, 0x78, 0x74, 0x65, 0x72, 0x6D, 0x2D, 0x32, 0x35,
0x36, 0x63, 0x6F, 0x6C, 0x6F, 0x72, 0xFF, 0xF0)
try(socket:send(nego1))
try(socket:receive())
try(socket:send(nego2))
data = try(socket:receive())
end
-- we check it's actually an OSGi prompt
if not string.match(data, prompt_regexp) then
return stdnse.format_output(false, "Not an OSGi shell.")
end
-- request properties
try(socket:send(props_cmd .. telnet_eol))
data = try(socket:receive_buf(prompt_regexp, true))
-- we create an indexed array with key/values from properties dump
props = {}
for k, v in string.gmatch(data, props_regexp) do
props[k:gsub("%s+", "")] = v
end
-- we fill our results table
result["username"] = props["user.name"]
result["OS Version"] = string.format(
"%s %s (%s %s endian)", props["os.name"], props["os.version"],
props["os.arch"], props["sun.cpu.endian"]
)
result["Java Runtime"] = string.format(
"%s (%s)", props["java.runtime.version"], props["java.runtime.name"]
)
result["Java VM"] = string.format(
"%s (%s)", props["java.vm.version"], props["java.vm.name"]
)
-- graceful disconnection
try(socket:send(disconnect_cmd .. telnet_eol))
try(socket:receive_buf("Disconnect from console?([^\r|^\n]*)", true))
try(socket:send(confirm_cmd .. telnet_eol))
try(socket:receive())
socket:close()
return result
end