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
|
# File 'lib/metasploit/framework/ssh/platform.rb', line 10
def self.get_platform_info(ssh_socket, timeout: 10)
info = ''
begin
Timeout.timeout(timeout) do
info = ssh_socket.exec!("id\n").to_s
if (info =~ /id=/)
info << ssh_socket.exec!("uname -a\n").to_s
if (info =~ /JUNOS /)
info = ssh_socket.exec!("cli show version\n").split("\n")[2..4].join(', ').to_s
elsif (info =~ /Linux USG /)
info << ssh_socket.exec!("cat /etc/version\n").to_s.rstrip
end
temp_proof = ssh_socket.exec!("grep unifi.version /tmp/system.cfg\n").to_s.rstrip
if (temp_proof =~ /unifi\.version/)
info << temp_proof
info << ssh_socket.exec!("grep board.name /etc/board.info\n").to_s.rstrip
end
elsif info =~ /Unknown command or computer name/
info = ssh_socket.exec!("ver\n").to_s
elsif info =~ /unknown keyword/
info = ssh_socket.exec!("get chassis\n").to_s
elsif info =~ /unknown command: id/
info = ssh_socket.exec!("show version\n").split("\n")[2..4].join(', ').to_s
elsif info =~ /Invalid input -> id/ || info =~ /Protocol error, doesn't start with scp!/
info = ssh_socket.exec!("show version\n").to_s
if info =~ /Version:(?<os_version>.+).+HW: (?<hardware>)/mi
info = "Model: #{hardware}, OS: #{os_version}"
end
elsif info =~ /% Invalid input at line 1/
info = ssh_socket.exec!("show version\n").split("\n")[0..1]
info = info.map { |item| item.strip }
info = info.join(', ').to_s
elsif info =~ /command not found|is not recognized as an internal or external command/
info = ssh_socket.exec!("systeminfo\n").to_s
/OS Name:\s+(?<os_name>.+)$/ =~ info
/OS Version:\s+(?<os_num>.+)$/ =~ info
if os_num.present? && os_name.present?
info = "#{os_name.strip} #{os_num.strip}"
else
info = ssh_socket.exec!("ver\n").to_s.strip
end
elsif info =~ /bad command name id \(line 1 column 1\)/
info = ssh_socket.exec!("/ system resource print\n").to_s
/platform:\s+(?<platform>.+)$/ =~ info
/board-name:\s+(?<board>.+)$/ =~ info
/version:\s+(?<version>.+)$/ =~ info
if version && platform && board
info = "#{platform.strip} #{board.strip} #{version.strip}"
end
elsif info =~ /sh: id: not found/
info = ssh_socket.exec!("vmware -v\n").to_s
else
info << ssh_socket.exec!("help\n?\n\n\n").to_s
end
end
rescue Timeout::Error
end
info
end
|