Snippets

grimhacker Decompress .git

Created by grimhacker

File decompress_git.py Added

  • Ignore whitespace
  • Hide word diff
+#!/usr/bin/env python3
+#GrimHacker
+# Iterate through the given directory and attempt to decrompress every file.
+# Useful when you have downloaded a git repository left accessible on a webserver.
+
+import zlib
+import os
+import argparse
+
+def main():
+    parser =argparse.ArgumentParser()
+    parser.add_argument("-f", "--folder", help="folder with git objects", required=True)
+    args = parser.parse_args()
+
+    count = 0
+
+    for subdir, dirs, files in os.walk(args.folder):
+        for file_ in files:
+            count += 1
+            filename = os.path.join(subdir, file_)
+            print("Decompressing '{}'".format(filename))
+            with open(filename, "rb") as f:
+                with open("{}.decompressed".format(filename), "wb") as h:
+                    try:
+                        content = f.read()
+                        decompressed = zlib.decompress(content)
+                        #print(decompressed)
+                        print("Writing '{}'".format(filename))
+                        h.write(decompressed)
+                    except Exception as e:
+                        print("[!] Error working on '{}'. {}".format(filename, e))
+
+    if count == 0:
+        print("Didn't find any files...")
+
+if __name__ == "__main__":
+    main()