/pynasm

Python to nasm compilation

Primary LanguagePython

pynasm

python to nasm assembly conversion, with cpu control.

  • x86 64bits only for now.

This allows to create:

  • shellcodes
  • PIC relocatable low-level code
  • infections (for red-teaming)
  • obfuscation

Disclaimer

Don't use this for creating malicious payloads!

Usage

generating a relocatable 64bits code blob

python3 pynasm.py shellcode.py
nasm -f bin shellcode.nasm
ls shellcode

or generating an 64bits exe

python3 pynasm.py program.py exe
nasm -f win64 program.nasm
x86_64-w64-mingw32-ld program.obj
ls a.exe

Emulate with SCEMU for testing

./scemu -f shellcode -vv -6

Demo

https://www.youtube.com/watch?v=o072bXNtxmg

Examples

check the examples folder.

WinapiAcces importing winapi lib

winapi

msgbox

Control blocks

blocks

Comparing strings

python code

emulated binary

API Call

api call

emulation

virtual allocs

emulation

Arrays and memory blobs

arrays

Documentation

https://github.com/sha0coder/pynasm/blob/main/DOCUMENTAITON.md

TODO:

  • modulus with aug assign %=
  • len(s) from a parameter
  • complex ifs and/or
  • elif
  • break
  • continue
  • structures
  • alloc 100 with: padding times 100 db 0x00