Forem Creators and Builders 🌱

Cover image for Basic Cybersecurity Concepts in Python
Mariah Dominique Rucker
Mariah Dominique Rucker

Posted on • Updated on

Basic Cybersecurity Concepts in Python

It is imperative to understand the various threats that exist in cyberspace prior to discussing cybersecurity techniques. The need for cyber security is growing with every passing day as we spend more time on the internet. We continue sharing our personal data from social media, through online shopping or even at bank systems leaving ourselves exposed to cybercriminals.

This tutorial will cover the basics of cybersecurity and how to use it in accessing your digital accounts using Python code demonstrations.

Top Cybersecurity Threats

Here are some common threats that you may encounter:

  1. Phishing attacks: These types of attacks, known as phishing attacks are aimed at tricking you into revealing personal data. They often pretend to be genuine emails and web pages albeit they are fake. This may include a text warning you about an account update from your bank. Upon clicking the link provided in the email, you are directed to a phony website where your data is obtained by fraudulent means.

  2. Malware: This is a variety of malicious software called malware which may damage your computer or take away your personal information. The worm may be a virus, trojan or a piece of spyware which is sent via an email or as an attachment, a shared file or a file download or a malicious site.

  3. Password attacks: In password attacks, hackers try to break into your online accounts through password cracking and guessing. These can be achieved using either brute force attack, where an individual tries all possible combinations of character until they get the correct one, or social engineering where someone deceives another for them to give their password.

Basic Cybersecurity Concepts

You know some common dangers to online security; now let us discuss a few key cybersecurity principles that may help shield you from them.

  • Use strong passwords: Using one-of-a-kind strong password for each account is one of the easiest yet effective tips on maintaining security of the internet accounts. The ideal strength for such a password is above twelve and it has both the small and capitalized letters, and special characters.

Password Brute Force

  • Enable two-factor authentication: Apart from this, two factor authentication will add another security precautionary measure that takes into account two forms of identification for one to gain access to these accounts. A complex one can be, for instance, a password plus a code (either by SMS or e-mail) that is hard to steal for would-be hackers.

  • Keep your software up to date: You should also update your operating system, web browser, and other software regularly because software updates often contain security patches that could prevent cyber criminals from making use of them.

Generating Strong Passwords

In python, we can use secrets module to produce a random character string for a very good strong password.

import string
import secrets

alphabet = string.ascii_letters + string.digits + string.punctuation
password = ''.join(secrets.choice(alphabet) for i in range(12))
print(password)
Enter fullscreen mode Exit fullscreen mode

Generates a 12-characters password that is composed of letters, figures and special characters.

Enabling Two-Factor Authentication

Amongst numerous other online services are Google, Facebook and Twitter also support two factor authentication.

Two Factor Authentication Illustration

Please follow the procedures given by the service in order to enable two-factor authentication for your accounts. When logging in, it is common for you to provide either your phone number or email address before entering the access code that has been forwarded to you.

Software Updates

To achieve that, you will need to use the subprocess module of python, a software package used for executing system commands.

import subprocess

subprocess.run(['sudo', 'apt', 'update'])
subprocess.run(['sudo', 'apt', 'upgrade'])
Enter fullscreen mode Exit fullscreen mode

Upgrades the existing software in a Linux system by running the β€˜apt update’ and β€˜apt upgrade’ commands.

Checking for Malware

There are also malware scanners for scanning your computer which can be written using a programming language such as python.

import os

def scan_directory(path):
    for file in os.listdir(path):
        file_path = os.path.join(path, file)
        if os.path.isfile(file_path):
            if is_infected(file_path):
                print(f'{file_path} is infected!')
        else:
            scan_directory(file_path)

def is_infected(file_path):
    # Perform malware check here
    return False

scan_directory('/home/user/Documents')
Enter fullscreen mode Exit fullscreen mode

Uses the is_infected() function on every file in the /home/user/Documents directory in order to scan the directory for malware. It prints a message to the console if the file contains any malware.

These are not all inclusive, however a start at fundamental cybersecurity implementation provided through these examples. Therefore, one must always read current news on security and should never take anything for granted as far as digital security is concerned.

GitHub: github.com/mariahrucker
LinkedIn: linkedin.com/in/mariahrucker
Instagram: instagram.com/techmariah
Other: linktr.ee/mariahrucker

Top comments (0)