Pentester's Promiscuous Notebook
search
Ctrlk
TwitterGitHubBlog
  • README
  • ⚒️Pentest
    • C2chevron-right
    • Infrastructurechevron-right
    • OSINTchevron-right
    • Password Brute Forcechevron-right
    • Perimeterchevron-right
    • Shellschevron-right
    • Webchevron-right
    • Wi-Fichevron-right
  • ⚔️Red Team
    • Basics
    • Infrastructure
    • Developmentchevron-right
      • API Hashing
      • API Hooking
      • BOF / COFF
      • CFG
      • Code Injectionchevron-right
      • DLL Hijacking
      • Golang
      • Kernel Mode
      • PIC / Shellcode
      • Nim
      • Sandbox Evasion
      • Syscalls
      • Windows API
  • 🐞Exploit Dev
    • BOFchevron-right
    • RE
    • WinDbg
  • ⚙️Admin
    • Git
    • Linuxchevron-right
    • Networkingchevron-right
    • Virtualizationchevron-right
    • Windows
gitbookPowered by GitBook
block-quoteOn this pagechevron-down
  1. ⚔️Red Teamchevron-right
  2. Development

PIC / Shellcode

Position-Independent Code / Shellcode

  • https://www.ired.team/offensive-security/code-injection-process-injection/writing-and-compiling-shellcode-in-carrow-up-right

  • https://www.codeproject.com/Articles/5304605/Creating-Shellcode-from-any-Code-Using-Visual-Studarrow-up-right

LogoGitHub - silentwarble/PIC-Library: A collection of position independent coding resourcesGitHubchevron-right

Compile runner with nasm & MinGW (stolen from PIC-Get-Privilegesarrow-up-right) for testing purposes:

Automated with Bash (like shcode2exearrow-up-right):

hashtag
Development Frameworks

  • https://github.com/thefLink/C-To-Shellcode-Examplesarrow-up-right

  • https://github.com/rainerzufalldererste/windows_x64_shellcode_templatearrow-up-right

  • https://github.com/oldboy21/SHGenObarrow-up-right

  • https://github.com/Print3M/epicarrow-up-right

  • https://github.com/winterknife/SILVERPICKarrow-up-right

hashtag
Startust-based

  • https://5pider.net/blog/2024/01/27/modern-shellcode-implant-designarrow-up-right

  • https://github.com/Cracked5pider/Stardustarrow-up-right

  • https://github.com/Octoberfest7/Secure_Stagerarrow-up-right

  • https://github.com/safedv/Rustic64arrow-up-right

  • https://github.com/NtDallas/Svartalfheimarrow-up-right

hashtag
Tools

hashtag
Binary Ninja Shellcode Compiler (SCC)

  • https://scc.binary.ninja/arrow-up-right

  • https://github.com/Vector35/sccarrow-up-right

Last updated 1 month ago

  • Development Frameworks
  • Startust-based
  • Tools
  • Binary Ninja Shellcode Compiler (SCC)
runShellcode.asm
; Compile with:
; nasm -f win64 runShellcode.asm -o runShellcode.o
; x86_64-w64-mingw32-ld runShellcode.o -o runShellcode.exe

Global Start

Start:
    incbin "shellcode.bin"
bin2compile.sh
#!/usr/bin/env bash

# Usage:
#   bin2compile.sh {32|64} <INPUT_BIN> [OUTPUT_EXE]
# Examples:
#   msfvenom -p windows/x64/exec CMD=calc.exe -f raw -o calc.bin
#   bin2compile.sh 64 calc.bin calc.exe

ARCH="${1}"
SC_PATH=`realpath "${2}"`
SC_NAME=`basename "${SC_PATH}"`
SC_NAME="${SC_NAME%.*}"
[[ "${#}" -gt 2 ]] && EXE_NAME="${3}" || EXE_NAME="${SC_NAME}.exe"

cat << EOT > "/tmp/${SC_NAME}.asm"
    global _start
    section .text
_start:
    incbin "${SC_PATH}"
EOT

if [[ "${ARCH}" == "32" ]]; then
    NASM_ARCH="win32"
    LD_ARCH="i386pe"
elif [[ "${ARCH}" == "64" ]]; then
    NASM_ARCH="win64"
    LD_ARCH="i386pep"
fi

echo "[*] Compiling x${ARCH}"
echo "[*] Compilation time: `date "+%F %H:%M:%S"`"

nasm -f "${NASM_ARCH}" -o "/tmp/${SC_NAME}.obj" "/tmp/${SC_NAME}.asm"
ld -m "${LD_ARCH}" -o "${EXE_NAME}" "/tmp/${SC_NAME}.obj" #-s --subsystem=windows
#strip "${EXE_NAME}"

if [[ "$?" -ne 1 ]]; then
    echo "[+] Success"
    echo "[+] Output size: `stat -c %s ${EXE_NAME} | numfmt --to=iec`"
else
    echo "[-] Failed"
fi

rm -f /tmp/${SC_NAME}.{asm,obj}