Ετήσια αρχεία: 2023


Create an HTTPS server in Python 3

To create an HTTPS server in Python 3 and serve a specific directory, you can use the http.server module along with the http.server.SimpleHTTPRequestHandler class. However, you’ll need to generate SSL/TLS certificates to make it an HTTPS server. You can use the http.server module in combination with the ssl module to achieve this. Here’s a step-by-step guide:

Generate SSL/TLS certificates (self-signed in this example):

You can use the openssl command-line tool to generate self-signed certificates for testing purposes:

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365;

Create a Python script to serve a directory via HTTPS:

import http.server
import socketserver
import ssl

# Set the path to the directory you want to serve
directory_to_serve = "/path/to/your/directory"

# Set the port for your HTTPS server
port = 443

# Specify the SSL/TLS certificate and key files
certfile = "cert.pem"
keyfile = "key.pem"

# Create a custom handler to use the SSL context
class MyHandler(http.server.SimpleHTTPRequestHandler):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, directory=directory_to_serve, **kwargs)

# Create an SSL context
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ssl_context.load_cert_chain(certfile=certfile, keyfile=keyfile)

# Create the HTTPS server
with socketserver.TCPServer(("0.0.0.0", port), MyHandler) as httpd:
    httpd.socket = ssl_context.wrap_socket(httpd.socket, server_side=True)
    print(f"Serving directory at https://localhost:{port}")
    httpd.serve_forever()

Replace /path/to/your/directory with the absolute path to the directory you want to serve, and adjust the port, certfile, and keyfile variables as needed.

Run this Python script to create an HTTPS server that serves files from the specified directory over HTTPS on the specified port. Access it in your web browser using https://localhost:443 (or any other IP your machine is configured to use).

Remember that this example uses a self-signed certificate, suitable for testing but not recommended for production use. In a production environment, you should obtain a valid SSL/TLS certificate from a certificate authority. If we were serving certificates from LetsEncrypt, then the respective variables in the file above would be as follows:

certfile = "/certificates/api.bytefreaks.net/fullchain.pem"
keyfile = "/certificates/api.bytefreaks.net/privkey.pem"

In this example, we used port 443. This port requires elevated rights, so you should execute the above script with sudo. If you use another port like 8443, then sudo is not required.


How to Keep Firefox Windows on Top in Ubuntu 18.04LTS and Newer

If you’re a frequent user of Mozilla Firefox on Ubuntu 18.04LTS or newer versions (tested up to Ubuntu Desktop 22.04LTS and 23.04), you might have encountered situations where you wished you could keep your Firefox window on top of all other open applications. This can be particularly useful when you want to reference information from a web page while working on other tasks. In this blog post, we’ll guide you through the steps to set Firefox windows on top using native GNOME features.

Gnome has a built-in feature that lets you keep any window on top of others. Here’s how to do it with Firefox:

  1. Open Firefox: Launch Firefox by clicking on its icon in the Ubuntu application launcher or by pressing Super (Windows key) and searching for “Firefox.”
  2. Open the webpage you want to keep on top.
  3. While holding down the Super (Windows key), Right-click on the Firefox application.
  4. The usual menu with the options to manage the window will appear. Select the option “Always on top”.

Please note that the “Always on top” option will appear grayed out if your window is maximized.


Upgrade O.MG Cable Firmware in Ubuntu GNU/Linux

The O.MG Cable is a popular tool for security professionals and enthusiasts, offering a covert way to gain access to a target device. To ensure its optimal performance and take advantage of new features and security enhancements, it’s important to keep the firmware up to date. In this blog post, we will guide you through the process of upgrading the firmware of an O.MG Cable on a GNU/Linux Ubuntu system using a set of simple commands.

Step 1: Installing pySerial

The first step is to install the pySerial library, which allows communication with serial ports. Open a terminal and execute the following command:

sudo pip3 install pyserial;

This command will install pySerial and its dependencies on your system. You may be prompted to enter your password to proceed with the installation.

Step 2: Cloning the O.MG-Firmware Repository

Next, we need to obtain the O.MG-Firmware repository from GitHub. Change to the desired directory in the terminal and execute the following command:

git clone https://github.com/O-MG/O.MG-Firmware;

This command will create a local copy of the O.MG-Firmware repository on your machine.

Step 3: Navigating to the O.MG-Firmware Directory

Change into the newly created O.MG-Firmware directory by running the following command:

cd O.MG-Firmware/;

This command ensures that you are in the correct directory to proceed with the firmware upgrade.

Step 4: Plugging in the O.MG Cable

Before flashing the firmware, plug in the O.MG Cable to your computer’s USB port. Ensure that the cable is properly connected and recognized by the system.

Step 5: Flashing the Firmware

To initiate the firmware upgrade process, execute the following command:

sudo python3 ./flash.py;

This command triggers the firmware flashing script using Python 3 and grants it the necessary privileges to access the USB port. You may be prompted to enter your password.

You will see progress updates and notifications on the terminal during the flashing process. Do not disconnect or interrupt the cable while the firmware is being flashed.

Once the flashing process completes, the O.MG Cable will install the latest firmware, ensuring optimal performance and security.

Conclusion: In this blog post, we provided a step-by-step guide on upgrading the firmware of an O.MG Cable on a GNU/Linux Ubuntu system. By following these commands, you can keep your O.MG Cable up to date, benefit from new features, and enhance its security. Remember to exercise caution during the firmware flashing process and avoid interrupting it. Enjoy exploring the capabilities of your upgraded O.MG Cable!


How to Use Gmail to Send Email with Postfix on Ubuntu

Introduction

In today’s digital age, email has become integral to our personal and professional lives. While numerous email clients are available, Gmail remains a popular choice due to its user-friendly interface and powerful features. In this blog post, we will guide you through configuring Postfix, a famous mail transfer agent (MTA), to send emails using your Gmail account on an Ubuntu system. Let’s dive in!

Prerequisites:

Before we begin, make sure you have the following prerequisites in place:

  1. An Ubuntu system with administrative privileges.
  2. A Gmail account.
  3. A basic understanding of the Linux command line.

Step 1: Install Postfix

  1. Open the terminal on your Ubuntu system.
  2. Update the package lists by running the command:
sudo apt update;

Install Postfix by running the command:

sudo apt install postfix;

During the installation process, you will be prompted to configure Postfix. Select “Internet Site” and press Enter. Provide your system’s mail name when prompted.

Step 2: Configure Postfix to Use Gmail

Open the main Postfix configuration file using a text editor:

sudo nano /etc/postfix/main.cf;

Locate the following lines and modify them as shown below:

relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

Save the changes and exit the text editor.

Step 3: Configure Gmail Account Credentials

Create a file to store your Gmail account credentials:

sudo nano /etc/postfix/sasl_passwd;

Add the following line to the file:

[smtp.gmail.com]:587 [email protected]:your_app_password

Note: Replace “[email protected]” with your actual Gmail address and “your_app_password” with the application-specific password you generated for Postfix in your Google Account settings. Save the file and exit the text editor. Secure the credentials file by running the command:

sudo chmod 600 /etc/postfix/sasl_passwd;

Update the Postfix lookup table for the credentials file by running the command:

sudo postmap /etc/postfix/sasl_passwd;

Step 4: Restart Postfix and Test

Restart the Postfix service to apply the changes:

sudo systemctl restart postfix;

Test the email configuration by sending a test email using the following command:

echo "This is a test email." | mail -s "Test Email" [email protected];

Note: Replace “[email protected]” with the email address where you want to send the test email.

Check the recipient’s mailbox to ensure the test email was delivered successfully.

Conclusion

By configuring Postfix to use Gmail on your Ubuntu system, you can harness the power of both platforms to send emails seamlessly. This integration allows you to leverage Gmail’s advanced features while benefiting from Postfix’s reliability and customization options. With the steps outlined in this blog post, you can easily set up the connection and streamline your email communication. Happy emailing!