()
Check if systemd PATH is writeable
Check if systemd PATH is writeable
Check if systemd PATH is writeable
def uptux_check_systemd_paths():
    """Check if systemd PATH is writeable"""
    # Define the bash command.
    command = 'systemctl show-environment'
    output = shell_exec(command)

    # Define the regex to find in the output.
    regex = re.compile(r'PATH=(.*$)')

    # Take the output from bash and split it into a list of paths.
    output = re.findall(regex, output)

    # This command may fail in some environments, only proceed if we have
    # a good match.
    if output:
        output = output[0].split(':')

        # Check each path - if it is writable, add it to a list.
        writeable_paths = []
        for item in output:
            if os.access(item, os.W_OK):
                writeable_paths.append(item)
    else:
        writeable_paths = False

    # Write the status to the console and log.
    if writeable_paths:
        tee("The following systemd paths are writeable. THIS IS ODD!\n"
            "See if you can combine this with a relative path Exec statement"
            " for privesc:",
            box='vuln')
        for path in writeable_paths:
            tee("  {}".format(path))
        global SYSTEMD_PATH_WRITABLE
        SYSTEMD_PATH_WRITABLE = True
    else:
        tee("No systemd paths are writeable. This is expected...",
            box='note')
def uptux_check_systemd_paths ( ) : # Define the bash command. command = 'systemctl show-environment' output = shell_exec ( command ) # Define the regex to find in the output. regex = re . compile ( r'PATH=(.*$)' ) # Take the output from bash and split it into a list of paths. output = re . findall ( regex , output ) # This command may fail in some environments, only proceed if we have # a good match. if output : output = output [ 0 ] . split ( ':' ) # Check each path - if it is writable, add it to a list. writeable_paths = [ ] for item in output : if os . access ( item , os . W_OK ) : writeable_paths . append ( item ) else : writeable_paths = False # Write the status to the console and log. if writeable_paths : tee ( "The following systemd paths are writeable. THIS IS ODD!\n" "See if you can combine this with a relative path Exec statement" " for privesc:" , box = 'vuln' ) for path in writeable_paths : tee ( "  {}" . format ( path ) ) global SYSTEMD_PATH_WRITABLE SYSTEMD_PATH_WRITABLE = True else : tee ( "No systemd paths are writeable. This is expected..." , box = 'note' )