Created
March 11, 2019 13:13
-
-
Save kecs/aa3bff33919245b112b211fd8858655e to your computer and use it in GitHub Desktop.
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 os, re, sys | |
""" | |
Recursively traverse a php repo, add a line that logs fn calls. | |
Non overlapping matches! | |
Arg: output file full path | |
""" | |
OUTFILE = sys.argv[1] | |
for root, dirs, files in os.walk(os.getcwd(), topdown=False): | |
for name in files: | |
try: | |
if name.endswith('.php'): | |
filename = os.path.join(root, name) | |
with open(filename, 'r+') as f: | |
processed = re.sub('(function\s([a-zA-Z1-9\s\$\(\)-_]+){)', | |
r'\1 $f = fopen("{}", "a") or die("FUUUCK");fwrite($f, "{} :: function \2");fclose($f);'.format(OUTFILE, filename), | |
f.read()) | |
f.seek(0) | |
f.write(processed) | |
except UnicodeDecodeError as e: | |
print('[*] Unicode error at ', filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment