Skip to content

Instantly share code, notes, and snippets.

@masthoon
masthoon / test_reloc_pefile.py
Last active August 11, 2017 17:26
pefile optimization (get_memory_mapped_image)
import pefile
"""
$ python test_reloc_pefile.py
Test with ntdll.dll - with bytearray and custom setter
Parse PE : 0.054 seconds
574 relocs to handle !
Relocate it : 0.048 seconds
Test with ntdll.dll - with classic buffer
Parse PE : 0.053 seconds
@masthoon
masthoon / wu.md
Last active June 27, 2019 01:38
Write up for Defcon Quals 2018

stumbler

This challenge is a reverse / exploit composed of 5 binaries (ELF 64 bits).

We were unable to launch it locally (wrong libboost version) so, we solved the challenge directly on the remote side.

When you connect to the challenge, it send you a 32 bytes hex-encoded random string.

By looking at Stumbler binary, we found and reversed the generation and verification of the proof of work.

@masthoon
masthoon / lsass.py
Created February 2, 2019 07:28
Add users / groups listing & privileges
import windows.rpc
from windows.rpc import ndr
import windows.generated_def as gdef
import ctypes
class PLSAPR_OBJECT_ATTRIBUTES(ndr.NdrStructure):
MEMBERS = [ndr.NdrLong,
ndr.NdrUniquePTR(ndr.NdrWString),
ndr.NdrUniquePTR(ndr.NdrLong), # We dont care of the subtype as we will pass None
@masthoon
masthoon / sparc_emu.py
Created May 25, 2020 19:42
Sun? On my Sat? unicorn sparc emulation
import sys
import lief # py2.7 v0.9.0
from unicorn import *
from unicorn.sparc_const import *
import capstone
'''
Sample output with mu.input = FLAG_EXPLOIT_CMD:
puts(Configuration Server: Running)
sleep()
@masthoon
masthoon / mssymbol.py
Last active August 10, 2020 07:08
MS Symbol helper (wrapper around dbghelp)
from ctypes import *
from ctypes import wintypes
from collections import namedtuple
import os
import tempfile
# CONFIG SYMBOLS
SYMBOLS_PATH = os.environ.get('_NT_SYMBOL_PATH')
if not SYMBOLS_PATH:
CACHE_PDB_PATH = os.path.join(tempfile.gettempdir(), "symbols")
@masthoon
masthoon / MichaelStorage.py
Created November 29, 2020 20:23
MichaelStorage Exploit HITCON 2020
import time
from pwintools import *
# Interact with binary
def act_alloc(type, size):
proc.sendline('1')
proc.recvuntil(':')
proc.sendline(str(type))
proc.recvuntil(':')
proc.sendline(str(size))
@masthoon
masthoon / launch_wsl.py
Created February 10, 2018 16:14
Launch a WSL process from Python (Windows)
import sys
import windows
import windows.winproxy
import windows.generated_def as gdef
# List distro: wslconfig /l
class WSLAPIProxy(windows.winproxy.ApiProxy):
APIDLL = "wslapi"
default_error_check = staticmethod(windows.winproxy.no_error_check)
@masthoon
masthoon / extract_fw_rfu.py
Created August 18, 2021 18:36
Extract and decompress parts of RFU firmware
import sys
import struct
import lzma
PJL_ESC = b'\x1b%-12345X'
def parse_pjl_command(fw):
assert(fw[0] == 0x20)
cmd, info = fw[1:256].split(b' ', 1)
name, value = info.split(b'=', 1)
@masthoon
masthoon / bgrep.c
Created April 30, 2022 20:39
bgrep.c
// dirty stolen code
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdlib.h>
@masthoon
masthoon / seccomp_bypass_x32_compat.c
Last active December 17, 2022 16:55
Demo of seccomp-BPF blacklist bypass on systemd - Ubuntu
/*
root@ubuntu:/# gcc seccomp_bypass_x32_compat.c -w -static -o test
root@ubuntu:/# cat /etc/systemd/system/test.service
[Unit]
Description=Test attack
[Service]
Type=oneshot
# Remove IO from the service
SystemCallFilter=~@basic-io
# Limit ABI to x64 only