Skip to content

Instantly share code, notes, and snippets.

@dreilly369
Created January 17, 2019 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreilly369/feb510c9b5ce3f1cc7ebdd93f3b6431d to your computer and use it in GitHub Desktop.
Save dreilly369/feb510c9b5ce3f1cc7ebdd93f3b6431d to your computer and use it in GitHub Desktop.
Find potentially active Git Hooks and print their SHA256 value
import os
import hashlib
import json
def sha256sum(filename):
h = hashlib.sha256()
b = bytearray(128*1024)
mv = memoryview(b)
with open(filename, 'rb', buffering=0) as f:
for n in iter(lambda : f.readinto(mv), 0):
h.update(mv[:n])
return h.hexdigest()
print("Collecting Repos")
repos = []
hook_hashes = {}
for root, dirs, files in os.walk("/"):
#print(root)
if ".git" in dirs:
#print(("%s/.git/ found" % root))
loc = os.path.join(root, ".git", "hooks")
repos.append(loc)
print("Found %d repos" % len(repos))
print("checking git hooks")
for hook_dir in repos:
for root, dirs, files in os.walk(hook_dir):
for f in files:
if ".sample" in f:
continue
fp = os.path.join(root, f)
fh = sha256sum(fp)
print(fp)
print(fh)
print("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment