diff --git a/codegrab/imphash.py b/codegrab/imphash.py new file mode 100755 index 0000000..4c8a54c --- /dev/null +++ b/codegrab/imphash.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 +import pefile +import sys +pe=pefile.PE(sys.argv[1]) +print(pe.get_imphash()) diff --git a/codegrab/ltop.py b/codegrab/ltop.py new file mode 100755 index 0000000..f9ce9b6 --- /dev/null +++ b/codegrab/ltop.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +import sys +import curses +from operator import itemgetter +import time + +# Number of top items to be displayed +N = 10 + + +def gen_output(item_dict, N=10): + """ + Generate a formatted output string for the top N items in item_dict. + + :param item_dict: A dictionary containing items and their counts + :param N: The number of top items to be displayed + :return: A generator yielding formatted strings for each of the top N items + """ + top_items = dict(sorted(item_dict.items(), key=itemgetter(1), reverse=True)[:N]) + count_length = len(str(max(top_items.values()))) + + for i, key in enumerate(top_items): + yield i, f'{i + 1:3} : [{top_items[key]:{count_length}}] {key}' + + +def main(screen): + """ + Main function to read input lines, maintain a count of each unique line, and + periodically display the top N lines with the highest counts using curses. + + :param screen: A curses window object + """ + if not sys.stdin.isatty(): # Check if the input comes from a pipe + # Initialize an empty dictionary to store unique input lines and their counts + toplist = {} + + # Set the next screen update time + t_update = time.time() + 1 + + for line in sys.stdin: + line = line.strip() + + # Increment the count for each unique input line + if line in toplist: + toplist[line] += 1 + else: + toplist[line] = 1 + + # Periodically update the screen with the top N lines + if time.time() > t_update: + for idx, line in gen_output(toplist): + screen.addstr(idx, 0, line) + screen.refresh() + t_update = time.time() + 1 + + # Clean up the curses environment and print the final top N lines + curses.endwin() + for idx, line in gen_output(toplist): + print(line) + else: + print("Usage: cat input_file.txt | ./top_lines.py") + print("Or: ./top_lines.py < input_file.txt") + +# Initialize the curses library, run the main function, and restore the terminal state +curses.wrapper(main) diff --git a/codegrab/smtpbanner.py b/codegrab/smtpbanner.py new file mode 100644 index 0000000..e3bea2d --- /dev/null +++ b/codegrab/smtpbanner.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +# banner.py + +import sys +import socket +import argparse + +def grab(ip, port): + """Connects to the specified IP and port, retrieves data and returns the decoded response.""" + try: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # TCP + sock.settimeout(5) # Set a timeout of 5 seconds + sock.connect((ip, port)) + ret = sock.recv(1024) + return ret.strip().decode() + except socket.error as e: + return f"Connection error: {e}" + finally: + sock.close() + +def main(): + parser = argparse.ArgumentParser(description="Retrieve banner information from the specified IP and port.") + parser.add_argument("ip", help="The target IP address") + parser.add_argument("-p", "--port", type=int, default=25, help="The target port (default: 25)") + + args = parser.parse_args() + + ip = args.ip + port = args.port + + print(grab(ip, port)) + +if __name__ == "__main__": + main() diff --git a/codegrab/uniq.py b/codegrab/uniq.py new file mode 100755 index 0000000..30e0c0e --- /dev/null +++ b/codegrab/uniq.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 +import sys + +hashes=set() +for line in sys.stdin: + h = hash(line) + if not h in hashes: + hashes.add(h) + print(line,end="") diff --git a/tools/uniqrs b/tools/uniqrs new file mode 100755 index 0000000..2f5f633 Binary files /dev/null and b/tools/uniqrs differ