Skip to content

Instantly share code, notes, and snippets.

@metall0id
Created May 18, 2014 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metall0id/472285c77f2a62ccd61a to your computer and use it in GitHub Desktop.
Save metall0id/472285c77f2a62ccd61a to your computer and use it in GitHub Desktop.
Transfer files inline once you have command execution on Linux/AIX/Android
#
# Author : Tyrone Erasmus
# Version : 1.0
# Description: Transfer files inline once you have command execution
#
# Linux: echo -n -e "\x41"
# AIX: echo "\0101\c"
# Android: echo -n -e "\0101"
# TODO: Windows?
#!/usr/bin/python
import os
import argparse
import binascii
# Read arguments
parser = argparse.ArgumentParser(description='This script converts a binary into text that can be pasted into a shell for inline file transfer.')
parser.add_argument('format', help='linux|aix|android')
parser.add_argument('sourcePath', help='Path of file to convert')
parser.add_argument('outputPath', help='Output path')
args = parser.parse_args()
# Read local file
in_file = open(args.sourcePath, "rb")
bytes = in_file.read()
in_file.close()
# Build command for specified platform
finalCmd = "echo "
if (args.format == "linux"):
finalCmd += "-n -e \""
finalCmd += "".join("\\x%s" % byte.encode("hex") for byte in bytes)
finalCmd += "\""
elif (args.format == "aix"):
finalCmd += "\""
finalCmd += "".join("\\%s" % str(oct(ord(byte))).zfill(4) for byte in bytes)
finalCmd += "\\c\""
elif (args.format == "android"):
finalCmd += "-n -e \""
finalCmd += "".join("\\%s" % str(oct(ord(byte))).zfill(4) for byte in bytes)
finalCmd += "\""
finalCmd += ">" + args.outputPath
print finalCmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment