Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import glob
- import argparse
- import linecache
- import shutil
- import re
- import sys
- from hashlib import sha512
- if __name__ == '__main__':
- parser = argparse.ArgumentParser(description='file filter')
- parser.add_argument('-k', '--kill', help='terminate the programm execution', default=False, action='store_true')
- args = parser.parse_args()
- directory = '/home/kali/Desktop/lab1'
- password = input('enter password: ').encode()
- hash = sha512(password).hexdigest()
- try:
- if not args.kill:
- if not os.access("template.tbl", os.W_OK):
- print('Dont change P4ss')
- sys.exit(0)
- open('names.txt', 'x')
- for filename in os.listdir(directory):
- f = os.path.join(directory, filename)
- with open('names.txt', 'a') as the_file:
- the_file.write(filename)
- the_file.write("\n")
- with open('names.txt', 'r') as f:
- old_data = f.read()
- new_data = old_data.replace('lab1.py\n', '')
- with open('names.txt', 'w') as f:
- f.write(new_data)
- with open('names.txt', 'r') as f:
- old_data = f.read()
- new_data = old_data.replace('names.txt\n', '')
- with open('names.txt', 'w') as f:
- f.write(new_data)
- with open('names.txt', 'r') as f:
- old_data = f.read()
- new_data = old_data.replace('template.tbl\n', '')
- with open('names.txt', 'w') as f:
- f.write(new_data)
- with open('template.tbl', 'r') as the_file:
- myString = linecache.getline('names.txt', 1)
- if not myString:
- os.remove('names.txt')
- raise KeyError
- with open('template.tbl', 'w') as the_file:
- the_file.write(hash)
- with open('template.tbl', 'a') as the_file:
- the_file.write("\n")
- with open('template.tbl', "a") as concat_file:
- shutil.copyfileobj(open('names.txt', "r"), concat_file)
- file1 = open("names.txt", "r")
- while True:
- line = file1.readline()
- if not line:
- break
- os.chmod(line.strip(), 0o000)
- print(line.strip() + ' is cl0seD')
- file1.close()
- os.chmod('template.tbl', 0o0400)
- print('template.tbl file is open for the creator to read only')
- os.chmod('lab1.py', 0o0400)
- print('lab1.py file is open for the creator to read only')
- os.remove('names.txt')
- else:
- with open('template.tbl', 'r') as the_file:
- myString = linecache.getline('template.tbl', 1)
- myString1 = myString.rstrip()
- if hash != myString1:
- raise ValueError
- if hash == myString1:
- open('names1.txt', 'x')
- for filename in os.listdir(directory):
- f = os.path.join(directory, filename)
- with open('names1.txt', 'a') as the_file:
- the_file.write(filename)
- the_file.write("\n")
- file1 = open("names1.txt", "r")
- while True:
- line = file1.readline()
- if not line:
- break
- os.chmod(line.strip(), 0o777)
- print(line.strip() + ' is 0p3n')
- if os.path.isfile('names1.txt'):
- os.remove('names1.txt')
- if os.path.isfile('names.txt'):
- os.remove('names.txt')
- except KeyError:
- print('no files in directory...')
- except ValueError:
- print('invalid pass...')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement