This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# unix-privesc-check - Checks Unix system for simple privilege escalations | |
# Copyright (C) 2008 [email protected] | |
# Copyright (C) 2009 [email protected] | |
# | |
# | |
# License | |
# ------- | |
# This tool may be used for legal purposes only. Users take full responsibility | |
# for any actions performed using this tool. The author accepts no liability |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
General purpose visitor pattern base implementation. | |
""" | |
from typing import Callable, Generic, Iterable, TypeVar | |
T = TypeVar("T") | |
# Visitor pattern. This is a mix of ast.NodeVisitor and docutils.nodes.NodeVisitor | |
# https://github.com/python/cpython/blob/main/Lib/ast.py#L386 | |
# https://sourceforge.net/p/docutils/code/HEAD/tree/tags/docutils-0.17.1//docutils/nodes.py#l1968 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import ast | |
_QUOTED_STR_REGEX = re.compile(r'(^\"(?:\\.|[^\"\\])*\"$)|' | |
r'(^\'(?:\\.|[^\'\\])*\'$)') | |
# older version (not very strong): (^\'\'\'(\s+)?(((?!\'\'\').)*)?(\s+)?\'\'\'$) | |
_TRIPLE_QUOTED_STR_REGEX = re.compile(r'(^\"\"\"(\s+)?(([^\"]|\"([^\"]|\"[^\"]))*(\"\"?)?)?(\s+)?(?:\\.|[^\"\\])?\"\"\"$)|' | |
# Unescaped quotes at the end of a string generates | |
# "SyntaxError: EOL while scanning string literal", | |
# so we don't account for those kind of strings as quoted. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
All the methods were generated based on the list of nodes from the | |
"Green Tree Snakes" guide: | |
https://greentreesnakes.readthedocs.io/en/latest/index.html | |
""" | |
import ast | |
class Visitor(ast.NodeVisitor): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
from collections import defaultdict | |
import sys | |
from textwrap import dedent | |
from typing import Any | |
from unittest import TestCase | |
import ast, inspect |