Skip to content

Instantly share code, notes, and snippets.

@agustik
Created April 10, 2024 17:17
Show Gist options
  • Select an option

  • Save agustik/5db8ce0807a0764bafd6882c09db0084 to your computer and use it in GitHub Desktop.

Select an option

Save agustik/5db8ce0807a0764bafd6882c09db0084 to your computer and use it in GitHub Desktop.

Revisions

  1. agustik created this gist Apr 10, 2024.
    34 changes: 34 additions & 0 deletions transfer.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #!/bin/bash

    port=$(shuf -i 9000-60000 -n 1)
    file=$1
    if [[ -z "$1" ]]; then
    echo "Missing file, use $0 <file>"
    exit 1
    fi

    md5=$(md5sum $file | awk '{ print $1 }')
    name=$(basename "$file")
    primaryip=$(ip route get 1.1.1.1 | grep -oP 'src \K\S+')


    echo "Serving file on $port
    # To fetch the file use:
    # curl http://$HOSTNAME:$port -o $name
    # Or using ip
    # curl http://$primaryip:$port -o $name
    #
    # Check the content, md5sum $name it should be:
    # $md5
    # Hint, you might need to turn of your firewall
    # sudo systecmtl stop iptables
    # "

    cat <(echo "HTTP/1.1 200 OK
    Content-Type: Content-type: application/octet-stream
    E-Tag: $md5
    Content-Disposition: attachment; filename=\"$name\"
    Content-Length: $( du -b $file )
    Server: Netcat
    " ) $file | nc -l $port > /dev/null
    echo "Transfer complete"