Created
January 21, 2023 19:37
-
-
Save queencitycyber/5b6492b8df8279865ea3d8d14e7939db to your computer and use it in GitHub Desktop.
dumb python script to parse exchanger output
This file contains hidden or 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
''' | |
parses impacket-exchanger output to put useful results in a table | |
https://github.com/fortra/impacket/blob/master/examples/exchanger.py | |
''' | |
import click | |
from rich.console import Console | |
from rich.table import Table | |
import re | |
# load the file | |
def load_file(filename): | |
with open(filename) as f: | |
data = f.read() | |
return data | |
# search for values matching the specified format | |
def search_values(data): | |
pattern = r'(\w+): (.+)' | |
values = re.findall(pattern, data) | |
return values | |
# create a table | |
def create_table(values): | |
table = Table() | |
table.add_column("Field", justify="left") | |
table.add_column("Value", justify="left") | |
for field, value in values: | |
if field in ["mail", "name", "title"]: | |
table.add_row(field, value) | |
return table | |
# print the table | |
def print_table(table): | |
console = Console() | |
console.print(table) | |
# main function | |
@click.command() | |
@click.argument("filename", type=click.Path(exists=True)) | |
def main(filename): | |
data = load_file(filename) | |
values = search_values(data) | |
table = create_table(values) | |
print_table(table) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment