Skip to content

Instantly share code, notes, and snippets.

View santa4nt's full-sized avatar
💭
😬

Santoso santa4nt

💭
😬
  • Los Angeles, CA
View GitHub Profile
@santa4nt
santa4nt / HelloJNI.java
Last active December 19, 2023 22:50
Sample JNI/C++ HelloWorld
public class HelloJNI {
static {
System.loadLibrary("hello"); // loads libhello.so
}
private native void sayHello(String name);
public static void main(String[] args) {
new HelloJNI().sayHello("Dave");
}
@santa4nt
santa4nt / ioctl.py
Last active May 28, 2023 11:31
A Python-ctypes script to dispatch IOCTL in Windows
#!C:\Python27\python.exe
# The MIT License (MIT)
#
# Copyright © 2014-2016 Santoso Wijaya <santoso.wijaya@gmail.com>
#
# 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, sub-license, and/or sell copies of the Software,
@santa4nt
santa4nt / arp_scapy.py
Created February 28, 2013 19:23
Some quick-n-dirty sample code and functions to manipulate ARP packets (for network filter testing).
from scapy.all import *
# change this to your test machine's MAC address
SELF_MAC = '00:0c:29:67:22:c2'
BCAST_MAC = 'ff:ff:ff:ff:ff:ff'
# this will send a PROBE ARP request packet to the supplied IP address argument
@santa4nt
santa4nt / patch_basehttpserver.py
Created April 21, 2010 23:57
A patch for slow BaseHTTPServer's default handler.
# This is a hack to patch slow socket.getfqdn calls that
# BaseHTTPServer (and its subclasses) make.
# See: http://bugs.python.org/issue6085
# See: http://www.answermysearches.com/xmlrpc-server-slow-in-python-how-to-fix/2140/
import BaseHTTPServer
def _bare_address_string(self):
host, port = self.client_address[:2]
return str(host)
@santa4nt
santa4nt / Makefile
Last active January 3, 2020 07:08
Heapsort implementation in C++.
CC = gcc
CFLAGS = -Wall -g -x c++
LFLAGS = -lstdc++ -lm -lboost_unit_test_framework
DEFINES = -D TOPDOWN -D USE_BOOST_UT
OBJDIR = obj
BINDIR = bin
TARGET = main
@santa4nt
santa4nt / dnsfuzz.py
Last active October 3, 2017 12:48
Implement a DNS server/forwarder using Twisted that intercepts responses and fuzz them before relaying them back to the original requesting client.
# http://notmysock.org/blog/hacks/a-twisted-dns-story.html
# https://gist.github.com/johnboxall/1147973
# twistd -y dnsfuzz.py
import sys
import socket
from twisted.python import log
from twisted.internet.protocol import Factory, Protocol
from twisted.internet import reactor
@santa4nt
santa4nt / decrypt_aes_ctr.py
Created November 29, 2012 22:59
A toy decryption algorithm using AES in CTR mode.
from Crypto.Cipher import AES, XOR # from pycrypto library (https://www.dlitz.net/software/pycrypto/)
block_size = AES.block_size
def decrypt(key, ciphertext):
# assume: len(key) == len(IV) == 16 bytes; no padding
iv = ciphertext[:block_size]
ciph = ciphertext[block_size:]
@santa4nt
santa4nt / scapy_frag_icmpv6.py
Created July 12, 2012 00:13
Send a fragmented ICMPv6 Echo Request with scapy
from scapy.all import *
# XXX: make sure conf.route6 includes the target IPv6 address in its route table;
# you can do so by first calling ping6 so that a neighbor solicitation is done
sip = 'fe80::20c:29ff:fe67:22c2'
dip = 'fe80::700d:da7e:80bb:aca9'
packets = fragment6(IPv6(src=sip, dst=dip) / IPv6ExtHdrFragment() / ICMPv6EchoRequest(data='A'*5000), 1024)
send(packets)
@santa4nt
santa4nt / sudoers
Created January 8, 2014 17:56
Using truecrypt without prompting for user's sudoer password at each mount
# add with `sudo visudo`:
username ALL=(root) NOPASSWD:/usr/bin/truecrypt
# obviously change 'username'
@santa4nt
santa4nt / genrandints.py
Last active December 16, 2015 08:48
Combine the last three gists: generate random ints, sort them by chunking, and verify sorted final output.
#!/usr/bin/env python
import os
import sys
import array
import struct
NUMRANDS = 10 ** 6 # the number of random integers we want to generate (one million)
BUFSIZE = 1000 # the number of integers we buffer internally before flushing to output