Path: blob/master/modules/auxiliary/scanner/misc/poisonivy_control_scanner.rb
19851 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::Tcp7include Msf::Auxiliary::Report8include Msf::Auxiliary::Scanner910def initialize11super(12'Name' => 'Poison Ivy Command and Control Scanner',13'Description' => %q{14Enumerate Poison Ivy Command and Control (C&C) on ports 3460, 80, 8080 and 443. Adaptation of iTrust Python script.15},16'Author' => ['SeawolfRN'],17'License' => MSF_LICENSE18)1920register_options(21[22OptString.new('PORTS', [true, "Ports to Check", "80,8080,443,3460"]),23OptInt.new('TIMEOUT', [true, "The socket connect timeout in milliseconds", 1000]),24OptInt.new('CONCURRENCY', [true, "The number of concurrent ports to check per host", 10])25]26)2728deregister_options('RPORT')29end3031def run_host(ip)32timeout = datastore['TIMEOUT'].to_i3334ports = Rex::Socket.portspec_crack(datastore['PORTS'])3536if ports.empty?37raise Msf::OptionValidateError.new(['PORTS'])38end3940while (ports.length > 0)41t = []42r = []43begin441.upto(datastore['CONCURRENCY']) do45this_port = ports.shift46break if not this_port4748t << framework.threads.spawn("Module(#{self.refname})-#{ip}:#{this_port}", false, this_port) do |port|49begin50s = connect(false,51{52'RPORT' => port,53'RHOST' => ip,54'ConnectTimeout' => (timeout / 1000.0)55})56r << [ip, port, "open", 'Unknown']57s.puts("\x00" * 0x100, 0) # Send 0x100 zeros, wait for answer58data = s.get_once(0x100) || ''59if data.length == 0x10060data = s.get_once(0x4) || ''61if data == "\xD0\x15\x00\x00" # Signature for PIVY C&C62print_status("#{ip}:#{port} - C&C Server Found")63r << [ip, port, "open", 'Poison Ivy C&C']64end65end66rescue ::Rex::ConnectionRefused67vprint_status("#{ip}:#{port} - TCP closed")68r << [ip, port, "closed", '']69rescue ::Rex::ConnectionError, ::IOError, ::Timeout::Error70rescue ::Rex::Post::Meterpreter::RequestError71raise $!72ensure73disconnect(s) rescue nil74end75end76end77t.each { |x| x.join }78rescue ::Timeout::Error79ensure80t.each { |x| x.kill rescue nil }81end8283r.each do |res|84report_service(:host => res[0], :port => res[1], :state => res[2], :name => res[3])85end86end87end88end899091