Skip to content

Instantly share code, notes, and snippets.

@aayla-secura
aayla-secura / getpaid-sync-related-items-stock.php
Last active June 7, 2023 01:41
GetPaid Wordpress plugin: Code snippet to synchronise the stock levels of related items (parents, children)
@aayla-secura
aayla-secura / getpaid-item-purchases.php
Last active June 6, 2023 21:33
GetPaid Wordpress plugin: Code snippet to list users who've purchased an item (or any of its children)
<?php
add_action( 'add_meta_boxes', 'add_getpaid_item_invoices_meta_box', 50 );
function add_getpaid_item_invoices_meta_box() {
add_meta_box( 'wpinv_item_invoices', __( 'Item Purchases', 'invoicing' ), 'show_getpaid_item_purchases', 'wpi_item', 'normal' );
}
function show_getpaid_item_purchases( $post ) {
// get this post and all children
$posts = get_children( array(
@aayla-secura
aayla-secura / getpaid-assign-user-roles.php
Last active June 6, 2023 21:33
GetPaid Wordpress plugin: Code snippet to assign user roles per subscription
<?php
function subscription_user_role_dbg_log( $data ) {
// error_log( print_r( $data, true ) );
}
function edit_member_role( $method, $subscription ) {
$roles = array(
// <name of item> => <slug of wordpress user role>
"Class Membership" => "class_member",
"Centre Membership" => "centre_member",
@aayla-secura
aayla-secura / JSON_to_URL_encoded_form.py
Last active January 2, 2023 02:31
Convert JSON data to URL encoded form (application/x-www-form-urlencoded)
#!/usr/bin/env python3
import json
from urllib.parse import quote, quote_plus
import sys
import os
import argparse
parser = argparse.ArgumentParser(
@aayla-secura
aayla-secura / pretty_print_table.awk
Last active October 28, 2022 04:48
Format (pretty print) a table using awk. Automatically adjusts column widths. Somewhat customisable output.
# Tested with GNU awk v4.2.1 and above
# Copyright 2021 aayla-secura
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CO
@aayla-secura
aayla-secura / time_response.py
Last active September 29, 2022 00:38
Measure the average delay between sending an HTTP request and receiving the response
#!/usr/bin/env python3
# NO LONGER MAINTAINED, CURRENT CODE NOW LIVES HERE
# https://github.com/aurainfosec/time_http_response
#
# Measure the average delay between sending an HTTP request and receiving the response.
# Use for time-based attacks or just to check the server load.
#
# Features
# - GET with URL parameters and no body
# - POST with application/x-www-form-urlencoded body and no URL parameters
@aayla-secura
aayla-secura / magicdict.py
Last active September 29, 2022 00:38
A magic dictionary which never raises KeyError, can set default values for keys based on regex and can filter based on regex
# EXAMPLE USAGE
# import json
#
# mdorder = MagicDict()
# mdorder.configure(
# defaults={'^price$': 0, '_address$': 'No such street, PO 000'})
# create a default order
# mdorder['price']
# mdorder['shipping_address']
# mdorder['billing_address']
@aayla-secura
aayla-secura / jwt_rs256_as_hs256.py
Last active March 20, 2022 12:15
JWT RS256 to HS256 re-signing attack
#!/usr/bin/env python2
#############################################################
# @AaylaSecura1138, github.com/aayla-secura
# Modify and distribute as you wish
#############################################################
# NO LONGER MAINTAINED: CURRENT CODE LIVES HERE:
# https://github.com/aurainfosec/jwt_resign_asym_to_sym
#############################################################
# Some JWT libraries are vulnerable to a known attack which changes
# the type of a JWT from an asymmetric (e.g. RS256) to a symmetric
#!/usr/bin/env python3
import logging
import math
import string
import sys
import argparse
from collections.abc import Mapping, MutableMapping
from collections import Counter
import re
@aayla-secura
aayla-secura / rbash_funcs.sh
Last active June 11, 2021 00:45
Functions to do useful stuff in a restricted bash shell; Uses only bash built-ins
#!/bin/bash
# Uses only bash built-ins allowed in restricted mode
# Also includes a few functions that require some external commands, see
# FUNCTIONS THAT REQUIRE SOME EXTERNAL COMMANDS at the end
# TODO check for # of arguments; or an argument parser
function _echoarray {
# print array elements one per line
local IFS=$'\n'
echo "$*"