|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | + |
| 8 | +class MetasploitModule < Msf::Auxiliary |
| 9 | + |
| 10 | + def initialize(info = {}) |
| 11 | + super(update_info(info, |
| 12 | + 'Name' => 'Shodan Honeyscore Client', |
| 13 | + 'Description' => %q{ |
| 14 | + This module uses the shodan API to check |
| 15 | + if a server is a honeypot or not. The api |
| 16 | + returns a score from 0.0 to 1.0. 1.0 being a honeypot. |
| 17 | + A shodan API key is needed for this module to work properly. |
| 18 | +
|
| 19 | + If you don't have an account, go here to register: |
| 20 | + https://account.shodan.io/register |
| 21 | + For more info on how their honeyscore system works, go here: |
| 22 | + https://honeyscore.shodan.io/ |
| 23 | + }, |
| 24 | + 'Author' => |
| 25 | + [ 'thecarterb' ], # Thanks to @rwhitcroft, @h00die and @wvu-r7 for the improvements and review! |
| 26 | + 'License' => MSF_LICENSE, |
| 27 | + 'References' => |
| 28 | + [ |
| 29 | + [ 'URL', 'https://honeyscore.shodan.io/'] |
| 30 | + ] |
| 31 | + ) |
| 32 | + ) |
| 33 | + |
| 34 | + deregister_options('RHOST', 'SSL', 'DOMAIN', 'DigestAuthIIS', 'NTLM::SendLM', |
| 35 | + 'NTLM::SendNTLM', 'VHOST', 'RPORT', 'NTLM::SendSPN', 'NTLM::UseLMKey', |
| 36 | + 'NTLM::UseNTLM2_session', 'NTLM::UseNTLMv2') |
| 37 | + |
| 38 | + register_options( |
| 39 | + [ |
| 40 | + OptString.new('TARGET', [true, 'The target to get the score of']), |
| 41 | + OptString.new('SHODAN_APIKEY', [true, 'The SHODAN API key']) |
| 42 | + ], self.class) |
| 43 | + end |
| 44 | + |
| 45 | + def print_score(score) |
| 46 | + tgt = datastore['TARGET'] |
| 47 | + print_status("#{tgt} honeyscore: #{score}/1.0") |
| 48 | + end |
| 49 | + |
| 50 | + def run |
| 51 | + key = datastore['SHODAN_APIKEY'] |
| 52 | + |
| 53 | + # Check the length of the key (should be 32 chars) |
| 54 | + if key.length != 32 |
| 55 | + print_error('Invalid API key (Not long enough)') |
| 56 | + return |
| 57 | + end |
| 58 | + |
| 59 | + tgt = datastore['TARGET'] |
| 60 | + print_status("Scanning #{tgt}") |
| 61 | + cli = Rex::Proto::Http::Client.new('api.shodan.io', 443, {}, true) |
| 62 | + cli.connect |
| 63 | + req = cli.request_cgi({ |
| 64 | + 'uri' => "/labs/honeyscore/#{tgt}?key=#{key}", |
| 65 | + 'method' => 'GET' |
| 66 | + }) |
| 67 | + res = cli.send_recv(req) |
| 68 | + cli.close |
| 69 | + if res.nil? |
| 70 | + fail_with(Failure::Unknown, 'Unable to connect to shodan') |
| 71 | + end |
| 72 | + |
| 73 | + if res.code != 200 |
| 74 | + print_error('Shodan did not respond in an expected way. Check your api key') |
| 75 | + return |
| 76 | + end |
| 77 | + |
| 78 | + score = res.body.to_f # Change the score to a float to be able to determine value in the checks |
| 79 | + |
| 80 | + if score == 0 |
| 81 | + print_error("#{tgt} is not a honeypot") |
| 82 | + elsif score < 0.4 && score != 0.0 |
| 83 | + print_error("#{tgt} is probably not a honeypot") |
| 84 | + elsif score > 0.4 && score < 0.6 |
| 85 | + print_status("#{tgt} might be a honeypot") |
| 86 | + elsif score > 0.6 && score < 1.0 |
| 87 | + print_good("#{tgt} is probably a honeypot") |
| 88 | + elsif score == 1.0 |
| 89 | + print_good("#{tgt} is definitely a honeypot") |
| 90 | + else # We shouldn't ever get here as the previous checks should catch an unexpected response |
| 91 | + print_error('An unexpected error occured.') |
| 92 | + return |
| 93 | + end |
| 94 | + print_score(score) |
| 95 | + end |
| 96 | +end |
0 commit comments