Last active
October 25, 2019 07:56
-
-
Save kaichogamirzp/3c293c7fd96aec1bed91348822688410 to your computer and use it in GitHub Desktop.
Redact checker
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
d, _ := datasink.GetJSON(f.DataSink().Data) | |
if strings.Contains(d, "build_amex_url") { | |
random_string:= randSeq(7) | |
file_name := []string{"/Users/asishpanda/test_files/", random_string, ".txt"} | |
_ = ioutil.WriteFile(strings.Join(file_name, ""), []byte(d), 0644) | |
} |
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
from os import listdir | |
from os.path import isfile, join | |
import re | |
BASE_DIR = "/Users/asishpanda/test_files" | |
CHECK_FIELDS = ["card.number", "card.cvv", "terminal.gateway_merchant_id", "terminal.gateway_terminal_password"] | |
def get_all_files(directory_path): | |
return [f for f in listdir(directory_path) if isfile(join(directory_path, f))] | |
def read_file(file_name): | |
with open(file_name, 'rb') as file: | |
data = file.read() | |
return data.decode("utf-8", 'ignore') | |
def find(whole_string, sub_string): | |
return [m.start() for m in re.finditer(sub_string, whole_string)] | |
def print_redacted_data(cf, all_indexes, data): | |
print("CHECK FOR FIELD {}".format(cf)) | |
print("\n") | |
for i in all_indexes: | |
try: | |
print(data[i-30: i+60]) | |
except: | |
print(data[i-10: i+10]) | |
print("END FOR FIELD {}".format(cf)) | |
print("\n\n\n") | |
if __name__ == '__main__': | |
all_files = get_all_files(BASE_DIR) | |
for f in all_files: | |
print("CHECKING for FILE: {}".format(f)) | |
print("\n") | |
file_name = BASE_DIR + "/" + f | |
data = read_file(file_name) | |
for cf in CHECK_FIELDS: | |
all_indexes = find(data, cf) | |
print_redacted_data(cf, all_indexes, data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment