Skip to content

Instantly share code, notes, and snippets.

View ulidtko's full-sized avatar
🤔
What it feels like, to live in a collapsing civilization?

Maxim Ivanov ulidtko

🤔
What it feels like, to live in a collapsing civilization?
View GitHub Profile
@ulidtko
ulidtko / qnap-qts-fw-cryptor.py
Last active April 19, 2024 16:45
QNAP QTS firmware encryptor/decryptor.
#!/usr/bin/env python3
import os, sys
import argparse
import struct
from functools import reduce
"""
QNAP QTS firmware encryptor/decryptor.
Based on https://pastebin.com/KHbX85nG
@ulidtko
ulidtko / LibModule.hs
Last active March 12, 2024 12:30
Cabal#9784 minimized repro case
module LibModule where
greeting = "=== Hello, Cabal! === Module Main speaking ~~~"
@ulidtko
ulidtko / README.md
Last active February 16, 2024 15:32

Mini-repro for SO question about weird TypeScript error message involving contravariance.

Steps

  • git clone git@gist.github.com:408b45c4e7b126fb7c28c69140604546.git test && cd test
  • npm ci
  • npm run build
@ulidtko
ulidtko / aws-2fa-session.py
Last active February 12, 2024 12:27
Virtual MFA device-in-a-script for AWS IAM, RFC6238 TOTP
#!/usr/bin/env python
"""
Use TOTP secret with RFC6238 algorithm for AWS MFA login.
$AWS_PROFILE is expected to be set, naming a section in ~/.aws/credentials
That same section must also contain 2 extra values for this script:
[my-awesome-shiny-aws-account]
@ulidtko
ulidtko / http-watchdog-wrapper
Last active February 6, 2024 17:49
systemd WatchDog pinging HTTP healthcheck
#!/usr/bin/env python3
"""
https://gist.github.com/ulidtko/fdd7222bd7e85480fa201614fbc42faf
"""
import os
import subprocess
import sys
from time import sleep
from urllib.error import URLError

Exploiting Lua 5.1 on x86_64

The following Lua program generates a Lua bytecode program called lua-sandbox-rce.luac, which in turn spawns a shell from within Lua 5.1 sandbox. The remainder of this document attempts to explain how this program works by a whirlwind tour of relevent bits of the Lua 5.1 virtual machine.

function outer()
  local magic -- In bytecode, the stack slot corresponding to this local is changed
  local function middle()
    local co, upval
    local ub1 = {[0] = -- Convert uint8_t to char[1]
@ulidtko
ulidtko / OverloadedSymbols.hs
Created December 10, 2023 11:38
Haskell string literals with custom compile-time validation
{-# LANGUAGE DataKinds, PolyKinds, TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
{-# LANGUAGE NoStarIsType #-}
{-# OPTIONS_GHC -Wno-orphans #-}
{-# OPTIONS_GHC -fplugin=Overloaded -fplugin-opt=Overloaded:Symbols #-}
module Main where
import Data.Fixed
import Data.Function (on)
@ulidtko
ulidtko / aws-ip-info.hs
Created November 9, 2023 15:32
Query AWS region info of IPv4/IPv6
#!/usr/bin/env runhaskell
{- cabal:
build-depends:
aeson,
attoparsec,
attoparsec-aeson,
base,
bytestring,
conduit,
conduit-aeson,
@ulidtko
ulidtko / repr.js
Last active October 29, 2023 12:22 — forked from soapie/repr.js
A repr function for JS
'use strict';
/* Python-like repr() formatter for JS types, with recursion limit. */
/* Adapted from https://gist.github.com/soapie/6407618 */
function repr(x, max, depth) {
var ELIDED = "[..]";
if (depth === undefined) depth = 0;
if (max === undefined) max = 2;
if (isPrim(x))
return showPrim(x);
if (typeof x === 'function')
@ulidtko
ulidtko / fetch-aws-ecs-env.py
Created July 20, 2023 10:42
Fetch env-file from AWS ECS Service TD (Task Definition)
#!/usr/bin/env python3
import argparse
import datetime
import sys
import os.path
import boto3
import jinja2