Skip to content

Instantly share code, notes, and snippets.

View Exchizz's full-sized avatar

Mathias Neerup Exchizz

View GitHub Profile
@Exchizz
Exchizz / customenum.py
Created April 22, 2021 19:17
Python3.8 enum metaclass that supports inheritance (used in django 3.2)
class CustomMetaEnum(type):
def __new__(self, name, bases, namespace):
fields = {}
fields = {key:value for key, value in namespace.items() if isinstance(value, int)}
for base in bases:
fields.update(base._fields)
namespace['_fields'] = fields
@Exchizz
Exchizz / kafka_latency.py
Created February 13, 2020 13:42
kafka latency tester
#!/user/bin/python3.8
from kafka import KafkaConsumer, KafkaProducer, KafkaAdminClient
from datetime import datetime, date
from time import sleep, monotonic_ns
import argparse
import json
parser = argparse.ArgumentParser()
parser.add_argument("-b", "--kafka_broker", help="Set ip/hostname to kafka broker, host:port", type=str, required=True)
@Exchizz
Exchizz / logitec_spotlight_vibrator.py
Last active November 28, 2019 22:00
Logitech spotlight vibrator PoC written in python with pyusb
import usb.core
import usb.util
import sys
from pprint import pprint
# find our device with lsusb
# 046d:c53e
dev = usb.core.find(idVendor=0x046d, idProduct=0xc53e)
# was it found?
@Exchizz
Exchizz / downloadandextract.sh
Last active February 21, 2023 00:08
Proof-of-concept on how "docker-pull" works
#!/bin/bash
# Based on the following question from stack-exchange:
# https://devops.stackexchange.com/questions/2731/downloading-docker-images-from-docker-hub-without-using-docker
# Get token
TOKEN="$(curl --silent --header 'GET' "https://auth.docker.io/token?service=registry.docker.io&scope=repository:library/ubuntu:pull" | jq -r '.token')"
# Get manifest
echo "Manifest: "
#define _GNU_SOURCE
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
@Exchizz
Exchizz / docker-compose.yml
Created July 4, 2019 18:35
Docker haproxy
version: '2'
volumes:
mysql:
services:
gitlab_app:
image: gitlab/gitlab-ce:11.9.0-ce.0
#!/usr/bin/env python
from __future__ import print_function, absolute_import, division
import logging
import mysql.connector
from errno import ENOENT
from stat import S_IFDIR, S_IFREG
from time import time
#!/usr/local/bin/python
# Example of TCP's threeway handshake using python and scapy
# source: https://www.fir3net.com/Programming/Python/how-to-build-a-tcp-connection-in-scapy.html
# Requires:
# iptables -A OUTPUT -p tcp --tcp-flags RST RST -j DROP
# Otherwise the kernel will send a TCP RESET as the kernel is not aware of TCP connection going on.
from scapy.all import *
@Exchizz
Exchizz / Dockerfile
Last active September 12, 2018 08:20
Dockerfile for RPIimage
FROM arm32v7/debian:stretch
RUN apt-get update && apt-get install -y openssh-server sudo iptables
RUN mkdir /var/run/sshd
RUN useradd -ms /bin/bash -g sudo student
RUN echo 'student:Plz4Ch4nG3' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin no/' /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
@Exchizz
Exchizz / dnsmasSetDns.pl
Last active July 12, 2018 11:19
Script to set DNS in dnsmasq from dbus using perl.
#!/usr/bin/perl
# This is a slight variant on an example provided by Net::DBus.
use strict;
use warnings;
# Load the Net::DBus D-Bus binding.
use Net::DBus;
# Connect to the system bus.