peass-ng/PEASS-ng · error · Exception

Variable '{var}' in module {path} is imported from itself

Error message

Variable '{var}' in module {path} is imported from itself

What it means

A module's '# Global Variables:' (imported/used variables) must not list a variable that the module itself declares in its '# Generated Global Variables:' metadata. The builder raises this error because a variable cannot be both produced locally and imported from elsewhere.

Source

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

            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"
        ]
        main_base = None
        
        # Base global variables don't need to be defined

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Remove the duplicated variable name from the '# Global Variables:' metadata header
  2. Or remove it from '# Generated Global Variables:' if it is genuinely imported, not generated
  3. Re-run the builder to verify the module loads

Example fix

# before
# Global Variables: PSTORAGE_CRON_FILES, AWS_KEY
# Generated Global Variables: AWS_KEY
# after
# Global Variables: PSTORAGE_CRON_FILES
# Generated Global Variables: AWS_KEY
Defensive patterns

Strategy: validation

Validate before calling

meta_vars = parse_metadata("Global Variables")
gen_vars = parse_metadata("Generated Global Variables")
assert not (set(meta_vars) & set(gen_vars)), f"Duplicated in both lists: {set(meta_vars) & set(gen_vars)}"

Type guard

def has_no_self_imported_vars(global_vars: list, generated_vars: list) -> bool:
    return not (set(global_vars) & set(generated_vars))

Prevention

When it happens

Trigger: LinpeasModule.__init__ during build when the same variable name appears in both the '# Global Variables:' and '# Generated Global Variables:' metadata headers of one module.

Common situations: Copying metadata headers between modules and leaving a generated variable in the imported list; renaming a generated variable but keeping the old name in '# Global Variables:'.

Related errors


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