Skip to content

Instantly share code, notes, and snippets.

==== Server ===
In [1]: from opcua import ua, server
...:
...: s = server.server.Server()
...: s.load_certificate("/etc/pki/tls/certs/mycert.pem")
...: s.load_private_key("/etc/pki/tls/certs/mykeykey.der")
...:
...: # allow Basic256Sha256_SignAndEncrypt
...: # s.get_endpoint() would return only that security policy
@ZuZuD
ZuZuD / testing
Created January 22, 2020 18:12
Testing opcua Client.Signature
==== Server ====
In [1]: from opcua import ua, server
...:
...: s = server.server.Server()
...: s.load_certificate("/etc/pki/tls/certs/mycert.pem")
...: s.load_private_key("/etc/pki/tls/certs/mykey.key.der")
...:
...: # allow Basic256Sha256_SignAndEncrypt
...: # s.get_endpoint() would return only that security policy
@ZuZuD
ZuZuD / exhaust_ephemeral_ports.py
Last active December 9, 2022 15:22
Simulate an ephemeral port exhaustion on a Linux client.
import socket
import time
import argparse
import subprocess
import shlex
"""
Usage: python3 exhaust_ephemeral_ports.py <dst> <dport> <optional:loop>
Example: python3 exhaust_ephemeral_ports.py 172.31.23.144 80
Help: exhaust_ephemeral_ports.py --help
@ZuZuD
ZuZuD / tracer-for-ssm.service
Created July 4, 2019 13:59
systemd_unit to strace amazon-ssm-agent.service
[Unit]
Description=stracer for SSM
After=amazon-ssm-agent.service
PartOf=amazon-ssm-agent.service
[Service]
ExecStart=/usr/bin/bash -l -c '/bin/strace -p $(pidof amazon-ssm-agent) > /var/log/strace_ssm_agent.log 2>&1'
[Install]
WantedBy=multi-user.target
@ZuZuD
ZuZuD / tcp_syn_ack.py
Last active July 28, 2018 20:24
TCP states break down with Scappy
from scapy.all import *
import time
import random
def sendit(src=None, dst=None, dport=None):
"""
See the different status of a TCP connection
Was initially written to identify a docker-proxy bug: https://github.com/moby/moby/issues/27539
I suggest to keep a netstat running from the server side: $ watch -0.1 'netstat -laptn|grep 80'
@ZuZuD
ZuZuD / gist:aa94ed6ed831b69d85c8e08cec05316b
Last active April 11, 2018 00:12
Python pprint from bash
alias pprint="python -c \"import pprint, sys, json; pprint.pprint(json.loads(''.join([x.strip() for x in sys.stdin.readlines()]))) \""
@ZuZuD
ZuZuD / alias_kodi.sh
Created April 2, 2018 22:52
Kodi bash alias
kodi_ip=192.168.0.100
function cpkodi {
scp $@ root@$kodi_ip:/storage/tvshows
}
function lskodi {
ssh root@$kodi_ip ls -ltrh /storage/tvshows
}
function rmkodi {
ssh root@$kodi_ip "cd /storage/tvshows && rm $@"
@ZuZuD
ZuZuD / gist:68725dd8e2227be0d35e0e3b69798d3a
Last active March 27, 2018 17:19
ElasticCache auto discovery PHP 7.0 - POC non-consistency getAllKeys() method
<?php
function printkv($store) {
if (is_array($store)) {
foreach($store as $item) {
echo "Key: ".$item['key']." Value: ".$item['value']."\n";
}
}
}
@ZuZuD
ZuZuD / gist:c281df71a79a4a14137c187715988b3d
Created March 27, 2018 17:10
ElasticCache memcached (memcached.so) PHP5 auto-discovery getAllKeys() workaround
# workaround for bug on getallKeys() on version superior to 1.4.22
# https://bugs.launchpad.net/libmemcached/+bug/1534062
<?php
function listKeys($srv,$max)
{
foreach($srv as $node) {
echo "Host: ".$node['host']." Port: ".$node['port']."\n";
$mem = new Memcached();
$mem->addServer($node['host'], $node['port']);
@ZuZuD
ZuZuD / gist:66decbe330ec560ac8e57e87150891b8
Created January 17, 2018 22:57
Parse /boot/grub/grub.cfg to help set GRUB_DEFAULT opts in /etc/default/grub
#!/bin/bash
export GRUB_CONFIG=`sudo find /boot -name "grub.cfg"`
awk 'BEGIN {submenu=0;menu=0};$1 ~ /submenu/ {submenu+=1;menu=0;sub(/\$.*$/,"");print submenu" " $0};/menuentry / && /Linux/ {gsub(/menuentry/,"");gsub(/--class.*$/,"");gsub(/\047/,"");print " "submenu">"menu " " $0;menu+=1}' $GRUB_CONFIG
# 1 submenu 'Advanced options for Ubuntu 3.19'
# 1>0 Ubuntu, with Linux 3.19.0-75-generic
# 1>1 Ubuntu, with Linux 3.19.0-75-generic (recovery mode)
# 1>2 Ubuntu, with Linux 3.13.0-139-generic
# 1>3 Ubuntu, with Linux 3.13.0-139-generic (recovery mode)
# 2 submenu 'Advanced options for Ubuntu 4.2'