Skip to content

Instantly share code, notes, and snippets.

@gabrielfalcao
gabrielfalcao / rsa_encryption.py
Created November 30, 2019 00:39
Using python cryptography module to generate an RSA keypair, serialize, deserialize the keys and perform encryption and decryption
import base64
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import padding
def utf8(s: bytes):
return str(s, 'utf-8')
@CasiaFan
CasiaFan / asynchronous_caching_video_stream.py
Last active March 11, 2024 20:20
Asynchronous caching and analysis of video stream with opencv and multithreading
import cv2
from redis import ConnectionPool, Redis
import numpy as np
import json, time
from multithreading import Thread, Event
redis_config = {"server": "localhost",
"passwd": '',
"port": '6379',
"db": 0}
@plembo
plembo / ConvPEMtoPKCS12.md
Last active April 15, 2023 08:52
Convert PEM Certificates to PKCS12

Convert PEM Certificates to PKCS12

Microsoft systems and the products of some Microsoft-dominated vendors (like HP and Brother) will not accept separate SSL keys and certficates. Instead, these need to be bundled together in PKCS12 format.

Converting PEM certificates to PKCS12 format is easily done with the openssl utility:

openssl pkcs12 -export -out _.example.com.pfx -inkey _.example.com.key -in _.example.com.crt

The name of the output file is specified after "-out". The original certificate key in PEM format is after "-inkey",

Installation

  1. Spin up an AWS/Azure/GCP machine (Ubuntu - 16.04)
    • ensure you know how to use the web-interface of these IaaS to open ports for an instance
    • open ports 80, 443, 8000, 8888
  2. Follow this link
  3. Create a dir (.jupyterhub) which shall contain jupyterhub specific files
    • mkdir .jupyterhub
    • cd .jupyterhub
    • jupyterhub --generate-config
    • openssl rand -hex 8 > jupyterhub_cookie_secret
@anujonthemove
anujonthemove / opencv-videocapture-useful-properties.txt
Last active April 5, 2024 14:24
A handy list of VideoCapture object parameters taken from official OpenCV docs.
CAP_PROP_POS_MSEC =0, //!< Current position of the video file in milliseconds.
CAP_PROP_POS_FRAMES =1, //!< 0-based index of the frame to be decoded/captured next.
CAP_PROP_POS_AVI_RATIO =2, //!< Relative position of the video file: 0=start of the film, 1=end of the film.
CAP_PROP_FRAME_WIDTH =3, //!< Width of the frames in the video stream.
CAP_PROP_FRAME_HEIGHT =4, //!< Height of the frames in the video stream.
CAP_PROP_FPS =5, //!< Frame rate.
CAP_PROP_FOURCC =6, //!< 4-character code of codec. see VideoWriter::fourcc .
CAP_PROP_FRAME_COUNT =7, //!< Number of frames in the video file.
CAP_PROP_FORMAT =8, //!< Format of the %Mat objects returned by VideoCapture::retrieve().
CAP_PROP_MODE =9, //!< Backend-specific value indicating the current capture mode.
@bgrewell
bgrewell / rotten_pickle.py
Last active May 13, 2021 09:18
This Gist creates payloads to exploit pythons pickle function. It is pre-setup to create reverse shells but could be tweaked for whatever fun uses you can think of.
import marshal
import urllib
import base64
import os
"""
Script: rotten_pickle.py
Date: 5/4/2018
Author: Benjamin Grewell
Purpose: This script creates a reverse shell that will be executed when the python pickle package attempts to unpickle it.
@AndrewPix
AndrewPix / serializers.py
Last active January 3, 2024 14:23
Integrate django-rest-knox with django-rest-auth
from rest_framework import serializers
from rest_auth.serializers import UserDetailsSerializer
class KnoxSerializer(serializers.Serializer):
"""
Serializer for Knox authentication.
"""
token = serializers.CharField()
@gdamjan
gdamjan / ssl-check.py
Last active April 14, 2024 07:16
Python script to check on SSL certificates
# -*- encoding: utf-8 -*-
# requires a recent enough python with idna support in socket
# pyopenssl, cryptography and idna
from OpenSSL import SSL
from cryptography import x509
from cryptography.x509.oid import NameOID
import idna
from socket import socket
@soulmachine
soulmachine / jwt-expiration.md
Last active April 9, 2024 04:12
How to deal with JWT expiration?

First of all, please note that token expiration and revoking are two different things.

  1. Expiration only happens for web apps, not for native mobile apps, because native apps never expire.
  2. Revoking only happens when (1) uses click the logout button on the website or native Apps;(2) users reset their passwords; (3) users revoke their tokens explicitly in the administration panel.

1. How to hadle JWT expiration

A JWT token that never expires is dangerous if the token is stolen then someone can always access the user's data.

Quoted from JWT RFC:

@nasrulhazim
nasrulhazim / dowload-files-from-ftp-server-using-python3.md
Last active May 6, 2024 09:45
Download Files From FTP Server using Python3
from ftplib import FTP
from datetime import datetime

start = datetime.now()
ftp = FTP('your-ftp-domain-or-ip')
ftp.login('your-username','your-password')

# Get All Files
files = ftp.nlst()