Skip to content

Instantly share code, notes, and snippets.

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
@tristanlatr
tristanlatr / ast_visitor_template.py
Created June 22, 2022 19:48 — forked from jtpio/ast_visitor_template.py
Template for visiting all Python AST nodes
"""
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):
@tristanlatr
tristanlatr / unquote_str.py
Created March 17, 2022 20:36
Utility function to unquote a string. It supports all kinds of python quotes.
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.
@tristanlatr
tristanlatr / visitor.py
Created August 14, 2021 21:00
General purpose visitor pattern Python implementation
"""
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
#!/bin/sh
# unix-privesc-check - Checks Unix system for simple privilege escalations
# Copyright (C) 2008 pentestmonkey@pentestmonkey.net
# Copyright (C) 2009 timb@nth-dimension.org.uk
#
#
# 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