|
| 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 | + include Msf::Exploit::Remote::Udp |
| 11 | + include Msf::Auxiliary::Report |
| 12 | + |
| 13 | + def initialize(info = {}) |
| 14 | + super( |
| 15 | + update_info( |
| 16 | + info, |
| 17 | + 'Name' => 'Jenkins Server Broadcast Enumeration', |
| 18 | + 'Description' => %q( |
| 19 | + This module sends out a udp broadcast packet querying for |
| 20 | + any Jenkins servers on the local network. |
| 21 | + Be advised that while this module does not identify the |
| 22 | + port on which Jenkins is running, the default port for |
| 23 | + Jenkins is 8080. |
| 24 | + ), |
| 25 | + 'Author' => |
| 26 | + [ |
| 27 | + 'Adam Compton <[email protected]>', |
| 28 | + 'Matt Schmidt <[email protected]>' |
| 29 | + ], |
| 30 | + 'References' => |
| 31 | + [ |
| 32 | + [ 'URL', 'https://wiki.jenkins-ci.org/display/JENKINS/Auto-discovering+Jenkins+on+the+network' ] |
| 33 | + ], |
| 34 | + 'License' => MSF_LICENSE |
| 35 | + ) |
| 36 | + ) |
| 37 | + deregister_options('RHOST', 'RPORT') |
| 38 | + end |
| 39 | + |
| 40 | + def parse_reply(pkt) |
| 41 | + # if empty packet, exit |
| 42 | + return unless pkt[1] |
| 43 | + |
| 44 | + # strip to just the IPv4 address |
| 45 | + if pkt[1] =~ /^::ffff:/ |
| 46 | + pkt[1] = pkt[1].sub(/^::ffff:/, '') |
| 47 | + end |
| 48 | + |
| 49 | + # check for and extract the version string |
| 50 | + ver = pkt[0].scan(/version>(.*)<\/version/i).flatten.first |
| 51 | + |
| 52 | + # if a version was identified, then out and store to DB |
| 53 | + if ver |
| 54 | + print_status("#{pkt[1]} - Found Jenkins Server #{ver} Version") |
| 55 | + report_host( |
| 56 | + host: pkt[1], |
| 57 | + info: "Jenkins v.#{ver} (port typically 8080)" |
| 58 | + ) |
| 59 | + end |
| 60 | + end |
| 61 | + |
| 62 | + def run |
| 63 | + print_status('Sending Jenkins UDP Broadcast Probe ...') |
| 64 | + |
| 65 | + udp_sock = connect_udp |
| 66 | + |
| 67 | + udp_sock.sendto('\n', '255.255.255.255', 33848, 0) |
| 68 | + |
| 69 | + # loop a few times to account for multiple or slow responders |
| 70 | + iter = 0 |
| 71 | + while (r = udp_sock.recvfrom(65535, 0.1)) && (iter < 20) |
| 72 | + parse_reply(r) |
| 73 | + iter += 1 |
| 74 | + end |
| 75 | + end |
| 76 | +end |
0 commit comments