peass-ng/PEASS-ng · error · Exception

Function '{func}' in module {path} is imported from itself

Error message

Function '{func}' in module {path} is imported from itself

What it means

LinpeasModule validates that a module's '# Functions Used:' metadata does not overlap with functions actually defined inside the module's own shell code. If a function listed as an external dependency is defined by the module itself, the builder raises this error, since importing a function from itself is a metadata mistake that would break the dependency-based build ordering.

Source

Thrown at linPEAS/builder/src/linpeasModule.py:193

        self.defined_funcs = self.extract_function_names()

        # Check if the indicated dependencies are actually being used
        for func in self.functions_used:
            if func not in self.sh_code and func not in self.initial_functions and not "peass{" in self.sh_code:
                raise Exception(f"Used function '{func}' in module {path} doesn't exist in the module code")
        
        for var in self.global_variables:
            if var not in self.sh_code and not "peass{" in self.sh_code:
                raise Exception(f"Used variable '{var}' in module {path} doesn't exist in the module code")
        
        for var in self.generated_global_variables:
            if var not in self.sh_code:
                raise Exception(f"Generated variable '{var}' in module {path} doesn't exist in the module code")
        
        # Check for funcs and vars imported from itself
        for func in self.defined_funcs:
            if func in self.functions_used:
                raise Exception(f"Function '{func}' in module {path} is imported from itself")
        
        for var in self.global_variables:
            if var in self.generated_global_variables:
                raise Exception(f"Variable '{var}' in module {path} is imported from itself")
        
        # Check if all variables are correctly defined
        linux_global_vars = [
            "OPTARG",
            "PID",
            "PPID",
            "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI",
            "AWS_LAMBDA_RUNTIME_API",
            "ECS_CONTAINER_METADATA_URI",
            "ECS_CONTAINER_METADATA_URI_v4",
            "IDENTITY_ENDPOINT",
            "IDENTITY_HEADER",
            "KUBERNETES_SERVICE_PORT_HTTPS",
            "KUBERNETES_SERVICE_HOST"

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Remove the self-defined function name from the module's '# Functions Used:' metadata header
  2. Or rename the function defined in the module code if it actually clashes with an imported one
  3. Re-run the linPEAS builder to confirm the module passes validation

Example fix

# before
# Functions Used: check_critial_root_procs, exec_with_jf
check_critial_root_procs() { ... }
# after
# Functions Used: exec_with_jf
check_critial_root_procs() { ... }
Defensive patterns

Strategy: validation

Validate before calling

import re
code = open(module_path).read()
defined = set(re.findall(r'\b(\w+)\s*\(\s*\)\s*{', code))
used = extract_metadata_list(code, "Functions Used")
assert not (defined & set(used)), f"Functions imported from itself: {defined & set(used)}"

Type guard

def is_valid_module_metadata(meta: dict) -> bool:
    return not (set(meta.get("Functions Used", [])) & set(extract_function_names(meta["code"])))

Prevention

When it happens

Trigger: Instantiating LinpeasModule(path) during the linPEAS build when a module's sh code contains a definition like 'myfunc() {' AND 'myfunc' is also listed in the module's '# Functions Used:' metadata header.

Common situations: Contributors write a new .sh module, copy a function name into the '# Functions Used:' list thinking it's documentation, or refactor a module to define a function locally but forget to remove it from the imported-functions metadata.

Related errors


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/5a9193cb1d3658b4. Report an issue: GitHub.