Skip to content

Instantly share code, notes, and snippets.

View lanbugs's full-sized avatar

Maximilian Thoma lanbugs

View GitHub Profile
@lanbugs
lanbugs / mail_with_attachment.py
Created April 20, 2021 19:50
Mail with attachment (python3)
# Source: https://stackoverflow.com/questions/3362600/how-to-send-email-attachments
import smtplib
from pathlib import Path
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formatdate
from email import encoders
@lanbugs
lanbugs / gitea_webhook_auth.py
Created October 8, 2021 16:31
Gitea Webhook Auth Flask
#!/usr/bin/env python3
from flask import Flask, request, abort
from pprint import pprint
import json
import hmac
app = Flask(__name__)
@app.route("/", methods=['POST'])
@lanbugs
lanbugs / ripe_cidr.py
Last active March 2, 2022 22:39
Ripe CIDR collapsed network list generator with country filter
#!/usr/bin/env python3
# ----------------------------------------------------------------------------------------------------------------------
# Ripe CIDR list generator with country filter
# --------------------------------------------
# Version 1.0
# Written by Maximilian Thoma 2022
#
# Parts used from: https://github.com/FireFart/network_info
# Only python3 required, no additional libraries
@lanbugs
lanbugs / flask_oidc_check_resource_access.py
Created June 18, 2022 16:08
Flask OIDC / Keycloak Check resource access
#!/usr/bin/env python3
#
# flask_oidc_check_resource_access.py
# Written by Maximilian Thoma 2022
# Visit https://www.lanbugs.de
# Free to use for everyone, without any warranty :-)
#
# Manual / Remarks
# I use it together with flask-oidc and Keycloak to give permission to API endpoint only to defined role.
# Its a wrapper function you can use together with @oidc.accept_token
@lanbugs
lanbugs / install_docker.sh
Created June 24, 2022 09:15
Script to install docker-ce and docker-compose on Ubuntu 18.04/20.04/22.04
#!/bin/bash
GREEN="\e[32m"
ENDCOLOR="\e[0m"
echo -e " ${GREEN}Welcome to Docker-CE installer for Ubuntu 18.04/20.04/22.04 ...${ENDCOLOR} "
echo -e " ${GREEN}---------------------------------------------------------------${ENDCOLOR} "
echo -e " ${GREEN}You will be asked for your sudo password if set.${ENDCOLOR} "
echo -e " ${GREEN}>>> Get repo update ...${ENDCOLOR} "
@lanbugs
lanbugs / teampass_shell_exporter.php
Last active October 5, 2022 07:00
Teampass shell exporter - Export all secrets from encrypted teampass database in cleartext
<?php
// Teampass Shell Exporter
// Written by Maximilian Thoma 2022
// Variables
// **************************************************
// Path to sources directory of teampass
$path = "/var/www/html/sources";
// Salt from teampass-seckey.txt
$salt = "<salt>";
@lanbugs
lanbugs / netbox_webhook_listener.py
Created December 28, 2022 11:27
Netbox Webhook Listener written with APIFlask
import hmac
from apiflask import APIFlask
import logging
from flask import request
from apiflask import Schema, abort
from apiflask.fields import String, Dict, DateTime, UUID
APP_NAME = "netbox-webhook-listener"
WEBHOOK_SECRET = "secret"
@lanbugs
lanbugs / cpl_delta.py
Created May 12, 2023 17:56
Broadcom ProxySG CPL Delta
import re
import sys
from loguru import logger
@logger.catch
def cpl_parser(lines):
root = {}
@lanbugs
lanbugs / cpl_merge.py
Created May 12, 2023 17:57
Broadcom ProxySG CPL Multimerge
import re
import yaml
from loguru import logger
import glob
from pprint import pprint
import json
from netaddr import cidr_merge
import ipaddress
@logger.catch
@lanbugs
lanbugs / merge_subnets.py
Created May 12, 2023 17:58
Compress list of subnets and ips
import sys
from netaddr import cidr_merge
def main(FILE):
with open(FILE) as f:
raw_lines = f.readlines()
subnets = []