Skip to content

Instantly share code, notes, and snippets.

@queencitycyber
Created January 21, 2023 19:37
Show Gist options
  • Save queencitycyber/5b6492b8df8279865ea3d8d14e7939db to your computer and use it in GitHub Desktop.
Save queencitycyber/5b6492b8df8279865ea3d8d14e7939db to your computer and use it in GitHub Desktop.
dumb python script to parse exchanger output
'''
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