Skip to content

Instantly share code, notes, and snippets.

@gcmurphy
Created January 11, 2016 17:27
Show Gist options
  • Save gcmurphy/5564658be2114355dc4b to your computer and use it in GitHub Desktop.
Save gcmurphy/5564658be2114355dc4b to your computer and use it in GitHub Desktop.
Find world writable configuation files, or world readable containing passwords.
import re
import sys
import os
import stat
def search(directory):
pattern = re.compile("(?i)pass|secret|key")
for rootdir, subdirs, files in os.walk(directory):
for filename in files:
path = os.path.join(rootdir, filename)
finfo = os.stat(path)
if finfo.st_mode & stat.S_IROTH:
content = open(path).read()
if pattern.match(content):
print("{} contains password!".format(path))
if finfo.st_mode & stat.S_IWOTH:
print("{} world writable!".format(path))
if __name__ == "__main__":
for arg in sys.argv[1:]:
search(arg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment