Last active
October 14, 2016 16:37
-
-
Save fidiego/d30beb7365ed167c858833a6dae91a94 to your computer and use it in GitHub Desktop.
A little script for searching mono secrets.
This file contains hidden or 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
#!/bin/python | |
import getpass | |
import os | |
import sys | |
import envoy | |
def get_secret_files(): | |
secret_files = {} | |
for subdir, dirs, files in os.walk('/opt/buzzfeed/mono'): | |
gpg_files = list() | |
for file in files: | |
if file.split('.')[-1] == 'gpg': | |
gpg_files.append(file) | |
if gpg_files: | |
secret_files[subdir] = gpg_files | |
return secret_files | |
def search_secret_files(term, gpg_files, password): | |
output = {} | |
for subdir, files in gpg_files.items(): | |
results = [] | |
for file in files: | |
print '\t searching in file {}/{}'.format(subdir, file) | |
# decrpyt file and get output | |
cmd = 'gpg --batch --passphrase "{}" -d {}/{}'.format(password, subdir, file) | |
response = envoy.run(cmd) | |
# search output for term | |
if term in response.std_out: | |
results.append(file) | |
if results: | |
output[subdir] = results | |
return output | |
def main(): | |
term = raw_input('Search Term: ') | |
password = getpass.getpass('Your GPG passphrase: ') | |
print 'searching /opt/buzzfeed/mono/**/*.gpg for {}'.format(term) | |
results = search_secret_files(term, get_secret_files(), password) | |
print 'Found term "{}" in the following files'.format(term) | |
for subdir, files in results.items(): | |
print subdir | |
for file in files: | |
print '\t{}'.format(file) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment