Skip to content

Instantly share code, notes, and snippets.

@NiceRath
NiceRath / port_check.py
Created September 4, 2024 10:49
Python3 Port Check Script
#!/usr/bin/env python3
from sys import argv as sys_argv
from socket import socket, AF_INET, AF_INET6, SOCK_STREAM
if len(sys_argv) < 3:
raise ValueError("""
You need to provide two arguments:
1 > Target IP
2 > Target port (only TCP)
@NiceRath
NiceRath / ansible-decrypt-vault-pipe-to-parent-process.sh
Last active August 27, 2024 13:48
Ansible - Decrypt Vault and Pipe output to parent process
# this can be useful in CI environments if you need to process config or secrets and pipe them to the parent process in a secure manner
# example file: secrets.yml
> my_secret1: !vault |
> $ANSIBLE_VAULT;1.1;AES256
> ...
> service_xyz: !vault |
> $ANSIBLE_VAULT;1.1;AES256
> ...
@NiceRath
NiceRath / python3-write-to-os-pipe.py
Created August 27, 2024 12:32
Python3 - Write to OS pipe /dev/fd/
#!/usr/bin/env python3
# this can be useful in CI environments if you need to process config or secrets and pipe them to the parent process in a secure manner
import io
import os
from time import sleep
w = io.open(69, 'wb', 0)
w.write(b'MY SECRE3T')
@NiceRath
NiceRath / opnsense-backup-rules-to-csv.py
Last active August 26, 2024 10:06
OPNSense - Backup Rules to CSV
from csv import DictWriter
import xml.etree.ElementTree as ET
# reads unencrypted OPNSense backup file and extracts its rules in CSV format
FILE_IN = 'firewall.xml'
FILE_OUT = 'firewall.csv'
FIELDS = [
'uuid', 'type', 'interface', 'ipprotocol', 'statetype', 'descr', 'direction', 'floating', 'log', 'quick',
'protocol', 'source', 'destination', 'category', 'disabled', 'gateway', 'icmptype', 'associated-rule-id',
@NiceRath
NiceRath / chocolatey_msi_install_startup.ps1
Created August 12, 2024 13:21
Chocolatey - Install MSI Packages on Windows Startup
# NOTES:
# you need to install chocolatey first: https://community.chocolatey.org/install.ps1
# source for ChocolateyInstallPackage: https://github.com/chocolatey/choco/blob/master/src/chocolatey.resources/helpers/functions/Install-ChocolateyInstallPackage.ps1
# source for helper functions: https://github.com/chocolatey/choco/tree/master/src/chocolatey.resources/helpers/functions
# this script need to be copied to your client; it may not work if executed through a network share
# you also need to copy those helper-function (see HELPERS_INCLUDE below) to your clients (see HELPERS_PATH below)
$LOGFILE = 'C:\gpo\logs\choco.log'
$SCRIPT_PATH = 'C:\gpo\scripts\choco'
$HELPERS_PATH = "$SCRIPT_PATH\helpers"
@NiceRath
NiceRath / chocolatey_package_install_startup.ps1
Last active August 12, 2024 13:21
Chocolatey - Install Software on Windows Startup
$LOGFILE = 'C:\gpo\logs\choco.log'
# NOTES:
# you need to install chocolatey first: https://community.chocolatey.org/install.ps1
# code source: https://octopus.com/blog/automate-developer-machine-setup-with-chocolatey (heavily modified)
# packages COULD have problems installing since all of them are community-driven
# packages to install/upgrade
# KEY = Package Name ; Value = Install Flags
$APPLIST = @{
@NiceRath
NiceRath / jetbrains_youtrack_workflow_autoclose_tickets.js
Created August 12, 2024 07:29
JetBrains YouTrack - Workflow to auto-close old tickets
/*
NOTE:
You need to at least modify the 'tagIdle', 'ticketQuery' and 'closeAction' variables
*/
const entities = require('@jetbrains/youtrack-scripting-api/entities');
const week = 7 * 24 * 60 * 60 * 1000;
const notifyTime1 = 2 * week;
const notifyTime2 = 4 * week;
const closeTime = 5 * week;
@NiceRath
NiceRath / openvpn_profile_chromeos.sh
Last active July 4, 2024 06:32
OpenVPN Profile for ChromeOS (ONC Format)
#!/bin/bash
# onc file format reference: https://chromium.googlesource.com/chromium/src/+/main/components/onc/docs/onc_spec.md#OpenVPN-connections-and-types
# NOTE: it seems tls-crypt is not supported
# TLSAuth
tlsauth="$(cat tlsauth.key | sed '1,3d' | sed ':a;N;$!ba;s/\n/\\n/g')"
# CA Certificate
ca="$(cat ca.crt | sed '1,1d' | sed '$d' | sed ':a;N;$!ba;s/\n//g')"
@NiceRath
NiceRath / graylog_pipeline_rules.md
Last active May 23, 2024 07:47
Graylog Pipeline Rules to extract fields for some common Services

Graylog menu: Graylog - System - Pipelines - Manage rules

All rules will assume you pre-filter your logs on an application-basis. Else the matching will get horrible.

Use regex101.com for testing expressions. Make sure to escape all the backslashes \\ (and so on..) before adding it as Graylog rule.

GENERIC: Use lookup tables to translate IPs to Hostnames

/*
@NiceRath
NiceRath / recursive_file_checksum.sh
Created April 22, 2024 09:04
Script for recursive checksum over directory content
#!/usr/bin/env bash
# NOTES:
# perfoms md5sum on all files in the directory, sorts them and creates an overall md5sum
# WARNING: the sort order & checksum will change if you do not use the same LANG/LC_ALL!
EXCLUDES=('dir1' 'dir2/*')
set -eo pipefail