peass-ng/PEASS-ng · error · Exception

Global Variables ' ' in module are not defined inside the…

Error message

Global Variables '{', '.join(not_defined_global_vars)}' in module {path} are not defined inside the 'Generated Global Variables' metadata

What it means

The builder statically scans the module's shell code for $VARIABLE references and requires every non-builtin variable to be declared either in '# Global Variables:', '# Generated Global Variables:', the linux_global_vars allowlist, the PSTORAGE_ namespace, or the base variables module. Undeclared variables would be empty at runtime, silently producing wrong results, so the builder refuses to compile the module.

Solutions

  1. Add the variable to the module's '# Generated Global Variables:' metadata and generate/emit it in the code
  2. Or add it to '# Global Variables:' if it comes from another module/base part
  3. Fix the typo if the variable name in code does not match the declared one
  4. Move shared variables into linpeas_parts/linpeas_base/0_variables_base.sh

Example fix

# before
echo "Found: $FOUND binaries"
# after
# (metadata)
# Generated Global Variables: FOUND
# (code)
FOUND=$(echo "$FOUND" | sed 's/ /,/g')
echo "Found: $FOUND binaries"
Defensive patterns

Strategy: validation

Validate before calling

import re
code = open(module_path).read()
used_vars = {v for v in re.findall(r'\$(\w+)', code) if len(v) > 2}
declared = set(parse_metadata("Global Variables")) | set(parse_metadata("Generated Global Variables"))
missing = {v for v in used_vars if v not in declared and not v.startswith("PSTORAGE_")}
assert not missing, f"Undeclared: {missing}"

Try / catch

try:
    LinpeasModule(path)
except Exception as e:
    print(f"Module {path} failed validation: {e}")
    # add missing vars to metadata and retry

Prevention

When it happens

Trigger: LinpeasModule.__init__ during build when module code references e.g. '$MY_VAR' with len>2, not in linux_global_vars, not in either metadata variable list, not prefixed PSTORAGE_, and not defined in 0_variables_base.sh.

Common situations: Adding new shell code that uses a variable without updating the '# Generated Global Variables:' header; typo-ing a variable name so it no longer matches the declared one; relying on a variable that only exists in another module instead of the base file.

Related errors


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

Appendix: source

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

            "IDENTITY_HEADER",
            "KUBERNETES_SERVICE_PORT_HTTPS",
            "KUBERNETES_SERVICE_HOST"
        ]
        main_base = None
        
        # Base global variables don't need to be defined
        if self.id != "BS_variables_base":
            main_base = LinpeasModule(os.path.join(os.path.dirname(__file__), "..", "linpeas_parts", "linpeas_base", "0_variables_base.sh"))
        
        not_defined_global_vars = []
        for var in self.extract_variables(self.sh_code):
            if len(var) > 2 and not var in linux_global_vars and var not in self.global_variables and var not in self.generated_global_variables:
                if not var.startswith("PSTORAGE_"):
                    if not main_base or var not in main_base.generated_global_variables:
                        not_defined_global_vars.append("$"+var)
        
        if not_defined_global_vars:
            raise Exception(f"Global Variables '{', '.join(not_defined_global_vars)}' in module {path} are not defined inside the 'Generated Global Variables' metadata")
            

    def __eq__(self, other):
        # Check if other object is an instance of LinpeasModule
        if isinstance(other, LinpeasModule):
            return self.id == other.id
        return NotImplemented  # Return NotImplemented for unsupported comparisons

    def extract_function_names(self):
        # This regular expression pattern matches function definitions in sh code
        pattern = r'\b(\w+)\s*\(\s*\)\s*{'
        return re.findall(pattern, self.sh_code)

    def extract_variables(self, sh_code):
        # This regex pattern matches variables in the form $VAR_NAME or ${VAR_NAME}
        pattern = r'\$({?([a-zA-Z_][a-zA-Z0-9_]*)}?)'
        matches = re.findall(pattern, sh_code)
        # Extract the variable name from each match

View on GitHub (pinned to 53fb989abc)