DEV Community

Cover image for Creating a Simple a Virus using Python
Isaeus "Asi" Guiang
Isaeus "Asi" Guiang

Posted on

Creating a Simple a Virus using Python

Image description

Imagine this scenario: You’re working late, focused on a critical task, and suddenly, your browsers close, a cryptic pop-up appears on your screen, and a suspicious webpage opens, urging you to make a purchase. Panic sets in as you wonder what just happened.

Image description

This script demonstrates how easily such disruptions can be engineered using everyday programming tools. It serves as a cautionary tale, reminding us of the importance of cybersecurity, ethical programming practices, and the responsibility developers hold in safeguarding digital environments.

Through this analysis, we aim to understand the mechanics behind the code, not to encourage harm but to foster awareness of how vulnerabilities can be exploited—and how they can be prevented. As with any powerful tool, programming demands ethical stewardship to harness its potential for good.

Now, let’s examine how this script operates and how its techniques might be repurposed for positive applications in cybersecurity and system management.


This Python script combines system commands, GUI pop-ups, and web interactions to simulate malicious behavior.

You may access the code of the virus on my GitHub repo:
https://github.com/asiguiang/Creating-Simple-Virus/blob/main/SimpleEthicalVirus.py


Overview

This script is an educational example of how Python can be used for potentially malicious purposes, like disrupting system activity, displaying warnings, and opening URLs. It demonstrates methods to:

  • Interact with system processes.
  • Create pop-ups with urgent messages.
  • Open web links automatically.

Dependencies

  • Python 3.x
  • Libraries: webbrowser, os, platform, ctypes, tkinter

Image description

Functions

Function Description
close_other_browsers Closes active browser processes based on the operating system.
show_popup Displays a pop-up dialog box with a message using tkinter.
open_pup_website Opens a specific URL in the user's default web browser using webbrowser.open().

Platforms Supported

  • Windows
  • Linux
  • macOS (Darwin)

Security Concerns

  • Disruption: Terminates browser processes, which can result in loss of unsaved data.
  • Psychological Impact: Displays a fear-inducing pop-up.
  • Coercion: Opens a webpage that might attempt to scam the user.

Execution Flow

  1. close_other_browsers():
    • Detect the operating system.
    • Close browser processes.
  2. open_pup_website():
    • Open the specified URL.
  3. show_popup():
    • Display the threatening message.

Legal and Ethical Use

This script is provided for educational purposes only and should not be used to harm systems or coerce individuals. Misuse of this code could result in legal consequences.

Improvements for Educational Value

  • Replace malicious elements with benign actions to teach functionality safely.
    • Example: Use a harmless pop-up message like "System Check Complete."
    • Redirect to a safe webpage instead of a suspicious link.
    • Demonstrate proper browser process handling for managing application resources.

Code Explanation

  1. Imports:
    • webbrowser: Used to open a web page in the default web browser.
    • os: Provides a way to interact with the operating system for task and process management.
    • platform: Determines the current operating system.
    • ctypes: Enables low-level Windows system calls (not explicitly used here but potentially for further malicious behavior).
    • tkinter: Creates GUI elements, specifically the pop-up message.

Image description

  1. Functions:

    • close_other_browsers():
      • Detects the operating system using platform.system().
      • On Windows:
      • Uses taskkill to terminate browsers: Chrome, Firefox, and Edge.
      • On Linux:
      • Uses pkill to terminate browser processes.
      • On macOS (Darwin):
      • Uses pkill to terminate Safari processes.
      • Effect: Disrupts user browsing activity.
    • show_popup():
      • Creates a pop-up window using tkinter.
      • Displays a threatening message ("YOU HAVE BEEN HACKED, 36 HOURS LEFT! BUY NOW!") in a dialog box.
    • open_pup_website():
      • Opens a provided URL in the default browser using webbrowser.open().
      • URL is a link to a supposed antivirus purchase page.
  2. Main Functionality:

    • Executes the functions sequentially:
      1. Closes browser processes.
      2. Opens the specified website.
      3. Shows the threatening pop-up.

Image description

  1. Purpose:
    • The script simulates ransomware-like behavior by disrupting browsing, coercing a purchase, and presenting an alarming message. It may be designed to force users into purchasing a product or falling victim to a scam.

Disclaimer

The script simulates malicious activity and should only be used in a controlled environment for learning purposes. Any unauthorized use on third-party systems is unethical and potentially illegal.

Isaeus "Asi" Guiang
Image description
Regional Captain of AWS Cloud Clubs Philippines and a dedicated student at the Polytechnic University of the Philippines. With a strong passion for cloud computing and cybersecurity, Asi has played pivotal roles as the Former Captain, of AWS Cloud Club - PUP Manila, driving collaboration and innovation in the tech community.

Currently pursuing a Bachelor of Science in Computer Science, Asi has a wealth of experience, including being an AWS re/Start Course Coordinator Intern and a Soft Skills Review Instructor. He teaches practical AWS workshops and is now a Security Risk Assessment and Compliance Intern at Globe, enhancing his expertise in the field.

Currently studying and focusing on Cloud Financial Operations and Security Compliance.

Top comments (0)