Skip to content

Instantly share code, notes, and snippets.

View drmalex07's full-sized avatar

MichailAlexakis drmalex07

  • IMIS "Athena" Research Center
  • Athens, Greece
View GitHub Profile
@drmalex07
drmalex07 / README-fail2ban-keycloak.md
Last active March 1, 2024 17:14
Use fail2ban to block brute-force attacks to keycloak server. #keycloak #fail2ban #brute-force-attack

Add regular-expression filter under /etc/fail2ban/filter.d/keycloak.conf:

[INCLUDES]

before = common.conf

[Definition]

_threadName = [a-z][-_0-9a-z]*(\s[a-z][-_0-9a-z]*)*
_userId = (null|[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})
@drmalex07
drmalex07 / gnuplot-py-example.py
Created December 24, 2014 17:06
A simple example for Gnuplot.py. #python #gnuplot
import numpy
import Gnuplot
def rainfall_intensity_t10(t):
return 11.23 * (t**(-0.713))
def rainfall_intensity_t50(t):
return 18.06 * (t**(-0.713))
g = Gnuplot.Gnuplot()
@drmalex07
drmalex07 / README-fail2ban-openvpn.md
Created March 3, 2019 13:34
Block unauthorized requests to OpenVPN using fail2ban. #openvpn #fail2ban

Block unauthorized requests to OpenVPN using fail2ban.

The following is based on https://stefan.angrick.me/block-unauthorized-openvpn-logins-using-fail2ban.

1. Create filter confifuration

Add a filter configuration under /etc/fail2ban/filter.d/openvpn.conf. The contents would be something like (regular expressions may need adjustments):

[INCLUDES]
before = common.conf
@drmalex07
drmalex07 / helloworld-win32-service.py
Created April 12, 2014 20:08
An example Windows service implemented with pywin32 wrappers. #python #windows-service #pywin32
import win32serviceutil
import win32service
import win32event
import servicemanager
import socket
import time
import logging
logging.basicConfig(
filename = 'c:\\Temp\\hello-service.log',
@drmalex07
drmalex07 / use-string-stream-1.c
Created March 17, 2017 10:04
An example of a string stream in C. #c #fmemopen #stream #string-stream
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (void) {
int c,nbytes;
char buffer[128];
@drmalex07
drmalex07 / README-python-service-on-systemd-activated-socket.md
Last active January 13, 2024 12:53
An example network service with systemd-activated socket in Python. #systemd #python #socket #socket-activation

README

The example below creates a TCP server listening on a stream (i.e. SOCK_STREAM) socket. A similar approach can be followed to create a UDP server on a datagram (i.e. SOCK_DGRAM) socket. See man systemd.socket for details.

An example server

Create an simple echo server at /opt/foo/serve.py.

@drmalex07
drmalex07 / README-setup-socket-activated-systemd-service.md
Last active December 26, 2023 05:13
An example inetd-like socket-activated service. #systemd #inetd #systemd.socket

README

This is an example of a socket-activated per-connection service (which is usually referred to as inetd-like service). A thorough explanation can be found at http://0pointer.de/blog/projects/inetd.html.

Define a socket unit

The key point here is to specify Accept=yes, which will make the socket accept connections (behaving like inetd) and pass only the resulting connection socket to the service handler.

@drmalex07
drmalex07 / use-shared-memory-1.c
Created March 17, 2017 09:47
An example of using shared memory in a POSIX system. #c #linux #shmem #shm_open #shared-memory
// Note: Link with -lrt
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h> /* For mode constants */
#include <fcntl.h> /* For O_* constants */
#include <unistd.h>
#include <string.h>
@drmalex07
drmalex07 / openssl-examples.md
Last active November 28, 2023 11:20
Several openssl examples and recipes. #openssl #certificate

Create a new key

Generate a new RSA private key (in PEM format) with 4096 bits:

openssl genrsa -out server.key 4096

You can generate a key protected with a passphrase e.g. by using DES3 encryption:

openssl genrsa -des3 -out server.key.des3 4096
@drmalex07
drmalex07 / README-List-Directory-in-WebDAV.md
Last active November 22, 2023 16:58
List directory in WebDav #webdav

Readme - List directory in WebDAV

1. An example request

To list properties of a directory we must use the PROPFIND method of WebDAV protocol and provide a request body with properties we are interested into. We must also provide the Depth header (otherwise the request is rejected as 403 Forbidden).

To retrieve basic properties as size and type, prepare a request body (say propfind-basic.xml) as: