VAITP Dataset

← Back to the dataset

CVE-2021-23556

Guake < 3.8.5 Vulnerable: Exposed D-Bus Method allows arbitrary commands

  • CVSS 8.0
  • CWE-284: Improper Access Control
  • Input Validation and Sanitization
  • Remote

The package guake before 3.8.5 are vulnerable to Exposed Dangerous Method or Function due to the exposure of execute_command and execute_command_by_uuid methods via the d-bus interface, which makes it possible for a malicious user to run an arbitrary command via the d-bus method. **Note:** Exploitation requires the user to have installed another malicious program that will be able to send dbus signals or run terminal commands.

CVSS base score
8.0
Published
2022-03-17
OWASP
A05 Security Misconfiguration
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Command Injection
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
guake
Fixed by upgrading
Yes

Solution

Update guake to version 3.8.5 or higher.

Vulnerable code sample

import dbus
import dbus.service
import dbus.mainloop.glib
from gi.repository import GLib

class VulnerableGuakeService(dbus.service.Object):
    def __init__(self, bus_name):
        self.bus_name = bus_name
        dbus.service.Object.__init__(self, bus_name, '/com/example/guake')

    @dbus.service.method('com.example.guake', in_signature='s', out_signature='s')
    def execute_command(self, command):
        # Directly execute the command without validation
        import subprocess
        result = subprocess.run(command, shell=True, capture_output=True, text=True)
        return result.stdout

def main():
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
    bus_name = dbus.service.BusName('com.example.guake', bus=dbus.SessionBus())
    service = VulnerableGuakeService(bus_name)
    loop = GLib.MainLoop()
    loop.run()

Patched code sample

import dbus
import dbus.service
import dbus.mainloop.glib
from gi.repository import GLib

class SecureGuakeService(dbus.service.Object):
    def __init__(self, bus_name):
        self.bus_name = bus_name
        dbus.service.Object.__init__(self, bus_name, '/com/example/guake')

    @dbus.service.method('com.example.guake', in_signature='s', out_signature='s')
    def execute_command(self, command):
        # Validate the command before execution
        if self.is_command_safe(command):
            # Execute the command securely
            return self.run_command(command)
        else:
            raise dbus.DBusException('Command not allowed')

    def is_command_safe(self, command):
        # Implement logic to check for allowed commands
        allowed_commands = ['ls', 'pwd']  # Example of safe commands
        return command in allowed_commands

    def run_command(self, command):
        # Safely execute the command and return the output
        import subprocess
        result = subprocess.run(command, shell=True, capture_output=True, text=True)
        return result.stdout

def main():
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
    bus_name = dbus.service.BusName('com.example.guake', bus=dbus.SessionBus())
    service = SecureGuakeService(bus_name)
    loop = GLib.MainLoop()
    loop.run()

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

Cite this entry

@misc{vaitp:cve202123556,
  title        = {{Guake < 3.8.5 Vulnerable: Exposed D-Bus Method allows arbitrary commands}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2022},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2021-23556},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-23556/}}
}

Download this entry as JSON Download the whole dataset

Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.