Created
January 11, 2016 17:27
-
-
Save gcmurphy/5564658be2114355dc4b to your computer and use it in GitHub Desktop.
Find world writable configuation files, or world readable containing passwords.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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