Skip to content

Instantly share code, notes, and snippets.

View itdaniher's full-sized avatar

itdaniher itdaniher

  • mosslandia
View GitHub Profile
@itdaniher
itdaniher / nuitka compilation fail
Last active January 3, 2018 04:47
nuitka compilation fail
Nuitka:DEBUG:print.py:1 : new_expression : Using original '__file__' value.
Nuitka:DEBUG:print.py:5 : new_builtin_ref : Module variable 'print' found to be built-in reference.
Nuitka:DEBUG:print.py:6 : new_builtin_ref : Module variable 'print' found to be built-in reference.
Nuitka:DEBUG:print.py:7 : new_builtin_ref : Module variable 'print' found to be built-in reference.
Nuitka:DEBUG:print.py:8 : new_builtin_ref : Module variable 'print' found to be built-in reference.
Nuitka:DEBUG:print.py:9 : new_builtin_ref : Module variable 'print' found to be built-in reference.
Nuitka:DEBUG:print.py:10 : new_builtin_ref : Module variable 'print' found to be built-in reference.
Nuitka:DEBUG:print.py:12 : new_constant : Replaced read-only module attribute '__name__' with constant value.
Nuitka:DEBUG:print.py:12 : new_constant : Comparison of constant arguments. Predicted constant result.
Nuitka:DEBUG:print.py:13 : new_builtin_ref : Module variable 'range' found to be built-in reference.
@itdaniher
itdaniher / elfid.py
Created January 3, 2018 15:08
archid via elftools
try:
from elftools.elf.elffile import ELFFile
except:
ELFFile = None
if ELFFile is not None:
import sys
elf_file=open(sys.argv[1], 'rb')
machine = ELFFile(elf_file).get_machine_arch().lower()
print(machine)
@itdaniher
itdaniher / dump_mem.py
Created January 3, 2018 15:11
find and print all strings in mapped memory for a given pid
import ctypes
import re
import sys
import glob
import os
c_ptrace = ctypes.CDLL(None).ptrace
c_pid_t = ctypes.c_int32
c_ptrace.argtypes = [ctypes.c_int, c_pid_t, ctypes.c_void_p, ctypes.c_void_p]
@itdaniher
itdaniher / imfux.py
Created January 6, 2018 04:14
imfux.py
import matplotlib
import numpy as np
import phase1
from scipy import misc
im_raw = misc.imread('image2.png')
nearest = lambda array, value: array[(np.abs(array-value)).argmin()]
im_flat = im_raw.reshape(im_raw.shape[0]*im_raw.shape[1], im_raw.shape[2])
colours_top = [x[1] for x in sorted(phase1.rle(sorted([tuple(x) for x in im_flat], reverse=True)), reverse=True)][:4]
colours_list = [tuple(x) for x in colours_top]
im_top_flat = np.array([nearest(colours_top, colour) if tuple(colour) not in colours_list else colour for colour in im_flat])
@itdaniher
itdaniher / compile.py
Last active October 28, 2023 20:33
compile python script to ELF on Linux via cython and gcc
import subprocess
import sys
import tempfile
from Cython.Compiler import Main, CmdLine, Options
in_file_name = sys.argv[1]
source = open(in_file_name).read()
out_file_name = in_file_name.replace('.py', '.out')
temp_py_file = tempfile.NamedTemporaryFile(suffix='.py', delete=False)
@itdaniher
itdaniher / test.py
Created January 22, 2018 16:35
setns leaks FDs
import sys
import traceback
import pyroute2.netns
i = 0
while True:
try:
pyroute2.netns.setns('/proc/1/ns/net')
except:
traceback.print_exc(file=sys.stderr)
print(i)
@itdaniher
itdaniher / test.py
Created January 23, 2018 15:26
functools.lru caches fds
import os
import sys
import traceback
import pyroute2.netns
i = 0
import functools
@functools.lru_cache(maxsize=1024)
def get_fd_from_netnspath(netnspath):
@itdaniher
itdaniher / dns.py
Created January 23, 2018 19:03 — forked from infra-0-0/dns.py
python3.5 asyncio dns resolver, based on code from who knows where
import os
import socket
import struct
import asyncio
import logging
DNS_SERVER = '8.8.8.8'
DNS_PORT = 53
def encode_header(packet_id):
@itdaniher
itdaniher / pastebin.py
Created January 30, 2018 02:56
a dumb poc - worked better when py2.7 was a thing
import sys
import os
from urllib.request import urlopen
from urllib.parse import urlencode
from time import time
from copy import copy
from re import findall
PASTEBIN_URL = 'https://pastebin.com/api/api_post.php'
PASTEBIN_LOGIN_URL = 'https://pastebin.com/api/api_login.php'
@itdaniher
itdaniher / start_redis.py
Created February 1, 2018 21:50
spawn a memcached-like redis instance
def start_redis_server(redis_socket_path = "/tmp/redis.sock"):
conf = b"""port 0
databases 1
unixsocket %s
maxmemory 100mb
maxmemory-policy volatile-lru
save ''""" % redis_socket_path.encode()
logging.debug('launching redis with conf: %s' % conf)
redis_process = subprocess.Popen(['redis-server', "-"], stdin = subprocess.PIPE, start_new_session=True)
try: