🤬
  • ■ ■ ■ ■ ■ ■
    LICENSE
     1 +The MIT License (MIT)
     2 + 
     3 +Copyright (c) 2014-2018 DutchCoders.
     4 +Copyright (c) 2018-2020 Andrea Spacca.
     5 +Copyright (c) 2020- Andrea Spacca and Stefan Benten.
     6 +Author: https://github.com/dutchcoders
     7 +Porting: from transfer.sh by crash.directory
     8 + 
     9 +Permission is hereby granted, free of charge, to any person obtaining a copy
     10 +of this software and associated documentation files (the "Software"), to deal
     11 +in the Software without restriction, including without limitation the rights
     12 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     13 +copies of the Software, and to permit persons to whom the Software is
     14 +furnished to do so, subject to the following conditions:
     15 + 
     16 +The above copyright notice and this permission notice shall be included in
     17 +all copies or substantial portions of the Software.
     18 + 
     19 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     20 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     21 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     22 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     23 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     24 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     25 +THE SOFTWARE.
     26 + 
  • ■ ■ ■ ■ ■ ■
    README.md
     1 +# crash.directory
     2 + 
     3 +Easy and fast file sharing from the command-line.
     4 + 
     5 +## Warning
     6 + 
     7 +Downloads on [crash.directory](https://crash.directory) are public and unrestricted but, in order to prevent abuses, the file uploads are protected by the HTTPS basic auth header.
     8 +Replace “user:pass” in the examples below with your provided credentials, you can try to ask for them on [crash.contact](https://crash.contact)
     9 + 
     10 +Alternatively, for unauthenticated uploads, if you don't mind NOT using crash.directory, you can go with the official public instance of the underlying sofware: transfer.sh
     11 + 
     12 +## Usage
     13 + 
     14 +### Upload:
     15 +```bash
     16 +$ curl --upload-file ./hello.txt https://user:[email protected]/hello.txt
     17 +```
     18 + 
     19 +### Encrypt & Upload:
     20 +```bash
     21 +$ cat /tmp/hello.txt|gpg -ac -o-|curl -X PUT --upload-file "-" https://user:[email protected]/test.txt
     22 +````
     23 + 
     24 +### Download & Decrypt:
     25 +```bash
     26 +$ curl https://crash.directory/1lDau/test.txt|gpg -o- > /tmp/hello.txt
     27 +```
     28 + 
     29 +### Upload to Virustotal:
     30 +```bash
     31 +$ curl -X PUT --upload-file nhgbhhj https://user:[email protected]/test.txt/virustotal
     32 +```
     33 + 
     34 +### Deleting
     35 +```bash
     36 +$ curl -X DELETE <X-Url-Delete Response Header URL>
     37 +```
     38 + 
     39 +## Request Headers
     40 + 
     41 +### Max-Downloads
     42 +```bash
     43 +$ curl --upload-file ./hello.txt https://user:[email protected]/hello.txt -H "Max-Downloads: 1" # Limit the number of downloads
     44 +```
     45 + 
     46 +### Max-Days
     47 +```bash
     48 +$ curl --upload-file ./hello.txt https://user:[email protected]/hello.txt -H "Max-Days: 1" # Set the number of days before deletion
     49 +```
     50 + 
     51 +## Response Headers
     52 + 
     53 +### X-Url-Delete
     54 + 
     55 +The URL used to request the deletion of a file and returned as a response header.
     56 +```bash
     57 +curl -sD - --upload-file ./hello https://user:[email protected]/hello.txt | grep -i 'X-Url-Delete'
     58 +X-Url-Delete: https://crash.directory/hello.txt/BAYh0/hello.txt/PDw0NHPcqU
     59 +```
     60 + 
     61 +## Examples
     62 + 
     63 +See good usage examples on [examples.md](examples.md)
     64 + 
     65 +## Link aliases
     66 + 
     67 +Create direct download link:
     68 + 
     69 +https://crash.directory/1lDau/test.txt --> https://crash.directory/get/1lDau/test.txt
     70 + 
     71 +Inline file:
     72 + 
     73 +https://crash.directory/1lDau/test.txt --> https://crash.directory/inline/1lDau/test.txt
     74 + 
     75 + 
     76 +## Shell functions
     77 + 
     78 +### Bash and zsh (multiple files uploaded as zip archive)
     79 +##### Add this to .bashrc or .zshrc or its equivalent
     80 +```bash
     81 +transfer(){ if [ $# -eq 0 ];then echo "No arguments specified.\nUsage:\n transfer <file|directory>\n ... | transfer <file_name>">&2;return 1;fi;if tty -s;then file="$1";file_name=$(basename "$file");if [ ! -e "$file" ];then echo "$file: No such file or directory">&2;return 1;fi;if [ -d "$file" ];then file_name="$file_name.zip" ,;(cd "$file"&&zip -r -q - .)|curl --progress-bar --upload-file "-" "https://user:[email protected]/$file_name"|tee /dev/null,;else cat "$file"|curl --progress-bar --upload-file "-" "https://user:[email protected]/$file_name"|tee /dev/null;fi;else file_name=$1;curl --progress-bar --upload-file "-" "https://user:[email protected]/$file_name"|tee /dev/null;fi;}
     82 +```
     83 + 
     84 +#### Now you can use transfer function
     85 +```
     86 +$ transfer hello.txt
     87 +```
     88 + 
     89 + 
     90 +### Bash and zsh (with delete url, delete token output and prompt before uploading)
     91 +##### Add this to .bashrc or .zshrc or its equivalent
     92 + 
     93 +<details><summary>Expand</summary><p>
     94 + 
     95 +```bash
     96 +transfer()
     97 +{
     98 + local file
     99 + declare -a file_array
     100 + file_array=("${@}")
     101 + 
     102 + if [[ "${file_array[@]}" == "" || "${1}" == "--help" || "${1}" == "-h" ]]
     103 + then
     104 + echo "${0} - Upload arbitrary files to \"crash.directory\"."
     105 + echo ""
     106 + echo "Usage: ${0} [options] [<file>]..."
     107 + echo ""
     108 + echo "OPTIONS:"
     109 + echo " -h, --help"
     110 + echo " show this message"
     111 + echo ""
     112 + echo "EXAMPLES:"
     113 + echo " Upload a single file from the current working directory:"
     114 + echo " ${0} \"image.img\""
     115 + echo ""
     116 + echo " Upload multiple files from the current working directory:"
     117 + echo " ${0} \"image.img\" \"image2.img\""
     118 + echo ""
     119 + echo " Upload a file from a different directory:"
     120 + echo " ${0} \"/tmp/some_file\""
     121 + echo ""
     122 + echo " Upload all files from the current working directory. Be aware of the webserver's rate limiting!:"
     123 + echo " ${0} *"
     124 + echo ""
     125 + echo " Upload a single file from the current working directory and filter out the delete token and download link:"
     126 + echo " ${0} \"image.img\" | awk --field-separator=\": \" '/Delete token:/ { print \$2 } /Download link:/ { print \$2 }'"
     127 + echo ""
     128 + echo " Show help text from \"crash.directory\":"
     129 + echo " curl --request GET \"https://crash.directory\""
     130 + return 0
     131 + else
     132 + for file in "${file_array[@]}"
     133 + do
     134 + if [[ ! -f "${file}" ]]
     135 + then
     136 + echo -e "\e[01;31m'${file}' could not be found or is not a file.\e[0m" >&2
     137 + return 1
     138 + fi
     139 + done
     140 + unset file
     141 + fi
     142 + 
     143 + local upload_files
     144 + local curl_output
     145 + local awk_output
     146 + local filename
     147 + 
     148 + du --total --block-size="K" --dereference "${file_array[@]}" >&2
     149 + # be compatible with "bash"
     150 + if [[ "${ZSH_NAME}" == "zsh" ]]
     151 + then
     152 + read $'upload_files?\e[01;31mDo you really want to upload the above files ('"${#file_array[@]}"$') to "crash.directory"? (Y/n): \e[0m'
     153 + elif [[ "${BASH}" == *"bash"* ]]
     154 + then
     155 + read -p $'\e[01;31mDo you really want to upload the above files ('"${#file_array[@]}"$') to "crash.directory"? (Y/n): \e[0m' upload_files
     156 + fi
     157 + 
     158 + case "${upload_files:-y}" in
     159 + "y"|"Y")
     160 + # for the sake of the progress bar, execute "curl" for each file.
     161 + # the parameters "--include" and "--form" will suppress the progress bar.
     162 + for file in "${file_array[@]}"
     163 + do
     164 + filename="${file##*/}"
     165 + # show delete link and filter out the delete token from the response header after upload.
     166 + # it is important to save "curl's" "stdout" via a subshell to a variable or redirect it to another command,
     167 + # which just redirects to "stdout" in order to have a sane output afterwards.
     168 + # the progress bar is redirected to "stderr" and is only displayed,
     169 + # if "stdout" is redirected to something; e.g. ">/dev/null", "tee /dev/null" or "| <some_command>".
     170 + # the response header is redirected to "stdout", so redirecting "stdout" to "/dev/null" does not make any sense.
     171 + # redirecting "curl's" "stderr" to "stdout" ("2>&1") will suppress the progress bar.
     172 + curl_output=$(curl --request PUT --progress-bar --dump-header - --upload-file "${file}" "https://user:[email protected]/${filename}")
     173 + awk_output=$(awk \
     174 + 'gsub("\r", "", $0) && tolower($1) ~ /x-url-delete/ \
     175 + {
     176 + delete_link=$2;
     177 + print "Delete command: curl --request DELETE " "\""delete_link"\"";
     178 + 
     179 + gsub(".*/", "", delete_link);
     180 + delete_token=delete_link;
     181 + print "Delete token: " delete_token;
     182 + }
     183 + 
     184 + END{
     185 + print "Download link: " $0;
     186 + }' <<< "${curl_output}")
     187 + 
     188 + # return the results via "stdout", "awk" does not do this for some reason.
     189 + echo -e "${awk_output}\n"
     190 + 
     191 + # avoid rate limiting as much as possible; nginx: too many requests.
     192 + if (( ${#file_array[@]} > 4 ))
     193 + then
     194 + sleep 5
     195 + fi
     196 + done
     197 + ;;
     198 + 
     199 + "n"|"N")
     200 + return 1
     201 + ;;
     202 + 
     203 + *)
     204 + echo -e "\e[01;31mWrong input: '${upload_files}'.\e[0m" >&2
     205 + return 1
     206 + esac
     207 +}
     208 +```
     209 + 
     210 +</p></details>
     211 + 
     212 +#### Sample output
     213 +```bash
     214 +$ ls -lh
     215 +total 20M
     216 +-rw-r--r-- 1 <some_username> <some_username> 10M Apr 4 21:08 image.img
     217 +-rw-r--r-- 1 <some_username> <some_username> 10M Apr 4 21:08 image2.img
     218 +$ transfer image*
     219 +10240K image2.img
     220 +10240K image.img
     221 +20480K total
     222 +Do you really want to upload the above files (2) to "crash.directory"? (Y/n):
     223 +######################################################################################################################################################################################################################################## 100.0%
     224 +Delete command: curl --request DELETE "https://crash.directory/wJw9pz/image2.img/mSctGx7pYCId"
     225 +Delete token: mSctGx7pYCId
     226 +Download link: https://crash.directory/wJw9pz/image2.img
     227 + 
     228 +######################################################################################################################################################################################################################################## 100.0%
     229 +Delete command: curl --request DELETE "https://crash.directory/ljJc5I/image.img/nw7qaoiKUwCU"
     230 +Delete token: nw7qaoiKUwCU
     231 +Download link: https://crash.directory/ljJc5I/image.img
     232 + 
     233 +$ transfer "image.img" | awk --field-separator=": " '/Delete token:/ { print $2 } /Download link:/ { print $2 }'
     234 +10240K image.img
     235 +10240K total
     236 +Do you really want to upload the above files (1) to "crash.directory"? (Y/n):
     237 +######################################################################################################################################################################################################################################## 100.0%
     238 +tauN5dE3fWJe
     239 +https://crash.directory/MYkuqn/image.img
     240 +```
     241 + 
     242 +## Creators
     243 + 
     244 +**Remco Verhoef**
     245 +- <https://twitter.com/remco_verhoef>
     246 +- <https://twitter.com/dutchcoders>
     247 + 
     248 +**Uvis Grinfelds**
     249 + 
     250 +## Maintainer
     251 + 
     252 +**Andrea Spacca**
     253 + 
     254 +**Stefan Benten**
     255 + 
     256 +## Copyright and License
     257 + 
     258 +Code and documentation copyright 2011-2018 Remco Verhoef.
     259 +Code and documentation copyright 2018-2020 Andrea Spacca.
     260 +Code and documentation copyright 2020- Andrea Spacca and Stefan Benten.
     261 + 
     262 +Code released under [the MIT license](LICENSE).
     263 + 
  • ■ ■ ■ ■ ■ ■
    examples.md
     1 +# Table of Contents
     2 + 
     3 +* [Aliases](#aliases)
     4 +* [Uploading and downloading](#uploading-and-downloading)
     5 +* [Archiving and backups](#archiving-and-backups)
     6 +* [Encrypting and decrypting](#encrypting-and-decrypting)
     7 +* [Scanning for viruses](#scanning-for-viruses)
     8 +* [Uploading and copy download command](#uploading-and-copy-download-command)
     9 + 
     10 +## Aliases
     11 +<a name="aliases"/>
     12 + 
     13 +## Add alias to .bashrc or .zshrc
     14 + 
     15 +### Using curl
     16 +```bash
     17 +transfer() {
     18 + curl --progress-bar --upload-file "$1" https://user:[email protected]/$(basename "$1") | tee /dev/null;
     19 + echo
     20 +}
     21 + 
     22 +alias transfer=transfer
     23 +```
     24 + 
     25 +### Using wget
     26 +```bash
     27 +transfer() {
     28 + wget -t 1 -qO - --method=PUT --body-file="$1" --header="Content-Type: $(file -b --mime-type "$1")" https://user:[email protected]/$(basename "$1");
     29 + echo
     30 +}
     31 + 
     32 +alias transfer=transfer
     33 +```
     34 + 
     35 +## Add alias for fish-shell
     36 + 
     37 +### Using curl
     38 +```fish
     39 +function transfer --description 'Upload a file to crash.directory'
     40 + if [ $argv[1] ]
     41 + # write to output to tmpfile because of progress bar
     42 + set -l tmpfile ( mktemp -t transferXXXXXX )
     43 + curl --progress-bar --upload-file "$argv[1]" https://user:[email protected]/(basename $argv[1]) >> $tmpfile
     44 + cat $tmpfile
     45 + command rm -f $tmpfile
     46 + else
     47 + echo 'usage: transfer FILE_TO_TRANSFER'
     48 + end
     49 +end
     50 + 
     51 +funcsave transfer
     52 +```
     53 + 
     54 +### Using wget
     55 +```fish
     56 +function transfer --description 'Upload a file to crash.directory'
     57 + if [ $argv[1] ]
     58 + wget -t 1 -qO - --method=PUT --body-file="$argv[1]" --header="Content-Type: (file -b --mime-type $argv[1])" https://user:[email protected]/(basename $argv[1])
     59 + else
     60 + echo 'usage: transfer FILE_TO_TRANSFER'
     61 + end
     62 +end
     63 + 
     64 +funcsave transfer
     65 +```
     66 + 
     67 +Now run it like this:
     68 +```bash
     69 +$ transfer test.txt
     70 +```
     71 + 
     72 +## Add alias on Windows
     73 + 
     74 +Put a file called `transfer.cmd` somewhere in your PATH with this inside it:
     75 +```cmd
     76 +@echo off
     77 +setlocal
     78 +:: use env vars to pass names to PS, to avoid escaping issues
     79 +set FN=%~nx1
     80 +set FULL=%1
     81 +powershell -noprofile -command "$(Invoke-Webrequest -Method put -Infile $Env:FULL https://user:[email protected]/$Env:FN).Content"
     82 +```
     83 + 
     84 +## Uploading and Downloading
     85 +<a name="uploading-and-downloading"/>
     86 + 
     87 +### Uploading with wget
     88 +```bash
     89 +$ wget --method PUT --body-file=/tmp/file.tar https://user:[email protected]/file.tar -O - -nv
     90 +```
     91 + 
     92 +### Uploading with PowerShell
     93 +```posh
     94 +PS H:\> invoke-webrequest -method put -infile .\file.txt https://user:[email protected]/file.txt
     95 +```
     96 + 
     97 +### Upload using HTTPie
     98 +```bash
     99 +$ http https://user:[email protected]/ -vv < /tmp/test.log
     100 +```
     101 + 
     102 +### Uploading a filtered text file
     103 +```bash
     104 +$ grep 'pound' /var/log/syslog | curl --upload-file - https://user:[email protected]/pound.log
     105 +```
     106 + 
     107 +### Downloading with curl
     108 +```bash
     109 +$ curl https://crash.directory/1lDau/test.txt -o test.txt
     110 +```
     111 + 
     112 +### Downloading with wget
     113 +```bash
     114 +$ wget https://crash.directory/1lDau/test.txt
     115 +```
     116 + 
     117 +## Archiving and backups
     118 +<a name="archiving-and-backups"/>
     119 + 
     120 +### Backup, encrypt and transfer a MySQL dump
     121 +```bash
     122 +$ mysqldump --all-databases | gzip | gpg -ac -o- | curl -X PUT --upload-file "-" https://user:[email protected]/test.txt
     123 +```
     124 + 
     125 +### Archive and upload directory
     126 +```bash
     127 +$ tar -czf - /var/log/journal | curl --upload-file - https://user:[email protected]/journal.tar.gz
     128 +```
     129 + 
     130 +### Uploading multiple files at once
     131 +```bash
     132 +$ curl -i -F filedata=@/tmp/hello.txt -F filedata=@/tmp/hello2.txt https://user:[email protected]/
     133 +```
     134 + 
     135 +### Combining downloads as zip or tar.gz archive
     136 +```bash
     137 +$ curl https://crash.directory/(15HKz/hello.txt,15HKz/hello.txt).tar.gz
     138 +$ curl https://crash.directory/(15HKz/hello.txt,15HKz/hello.txt).zip
     139 +```
     140 + 
     141 +### Transfer and send email with link (using an alias)
     142 +```bash
     143 +$ transfer /tmp/hello.txt | mail -s "Hello World" [email protected]
     144 +```
     145 +## Encrypting and decrypting
     146 +<a name="encrypting-and-decrypting"/>
     147 + 
     148 +### Encrypting files with password using gpg
     149 +```bash
     150 +$ cat /tmp/hello.txt | gpg -ac -o- | curl -X PUT --upload-file "-" https://user:[email protected]/test.txt
     151 +```
     152 + 
     153 +### Downloading and decrypting
     154 +```bash
     155 +$ curl https://crash.directory/1lDau/test.txt | gpg -o- > /tmp/hello.txt
     156 +```
     157 + 
     158 +### Import keys from [keybase](https://keybase.io/)
     159 +```bash
     160 +$ keybase track [them] # Encrypt for recipient(s)
     161 +$ cat somebackupfile.tar.gz | keybase encrypt [them] | curl --upload-file '-' https://user:[email protected]/test.txt # Decrypt
     162 +$ curl https://crash.directory/sqUFi/test.md | keybase decrypt
     163 +```
     164 + 
     165 +## Scanning for viruses
     166 +<a name="scanning-for-viruses"/>
     167 + 
     168 +### Scan for malware or viruses using Clamav
     169 +```bash
     170 +$ wget http://www.eicar.org/download/eicar.com
     171 +$ curl -X PUT --upload-file ./eicar.com https://user:[email protected]/eicar.com/scan
     172 +```
     173 + 
     174 +### Upload malware to VirusTotal, get a permalink in return
     175 +```bash
     176 +$ curl -X PUT --upload-file nhgbhhj https://user:[email protected]/test.txt/virustotal
     177 +```
     178 +## Uploading and copy download command
     179 + 
     180 +Download commands can be automatically copied to the clipboard after files are uploaded using crash.directory.
     181 + 
     182 +It was designed for Linux or macOS.
     183 + 
     184 +### 1. Install xclip or xsel for Linux, macOS skips this step
     185 + 
     186 +- install xclip see https://command-not-found.com/xclip
     187 + 
     188 +- install xsel see https://command-not-found.com/xsel
     189 + 
     190 +Install later, add pbcopy and pbpaste to .bashrc or .zshrc or its equivalent.
     191 + 
     192 +- If use xclip, paste the following lines:
     193 + 
     194 +```sh
     195 +alias pbcopy='xclip -selection clipboard'
     196 +alias pbpaste='xclip -selection clipboard -o'
     197 +```
     198 + 
     199 +- If use xsel, paste the following lines:
     200 + 
     201 +```sh
     202 +alias pbcopy='xsel --clipboard --input'
     203 +alias pbpaste='xsel --clipboard --output'
     204 +```
     205 + 
     206 +### 2. Add Uploading and copy download command shell function
     207 + 
     208 +1. Open .bashrc or .zshrc or its equivalent.
     209 + 
     210 +2. Add the following shell script:
     211 + 
     212 + ```sh
     213 + transfer() {
     214 + curl --progress-bar --upload-file "$1" https://user:[email protected]/$(basename "$1") | pbcopy;
     215 + echo "1) Download link:"
     216 + echo "$(pbpaste)"
     217 +
     218 + echo "\n2) Linux or macOS download command:"
     219 + linux_macos_download_command="wget $(pbpaste)"
     220 + echo $linux_macos_download_command
     221 +
     222 + echo "\n3) Windows download command:"
     223 + windows_download_command="Invoke-WebRequest -Uri "$(pbpaste)" -OutFile $(basename $1)"
     224 + echo $windows_download_command
     225 +
     226 + case $2 in
     227 + l|m) echo $linux_macos_download_command | pbcopy
     228 + ;;
     229 + w) echo $windows_download_command | pbcopy
     230 + ;;
     231 + esac
     232 + }
     233 + ```
     234 + 
     235 + 
     236 +### 3. Test
     237 + 
     238 +The transfer command has two parameters:
     239 + 
     240 +1. The first parameter is the path to upload the file.
     241 + 
     242 +2. The second parameter indicates which system's download command is copied. optional:
     243 + 
     244 + - This parameter is empty to copy the download link.
     245 + 
     246 + - `l` or `m` copy the Linux or macOS command that downloaded the file.
     247 + 
     248 + - `w` copy the Windows command that downloaded the file.
     249 + 
     250 +For example, The command to download the file on Windows will be copied:
     251 + 
     252 +```sh
     253 +$ transfer ~/temp/a.log w
     254 +######################################################################## 100.0%
     255 +1) Download link:
     256 +https://crash.directory/y0qr2c/a.log
     257 + 
     258 +2) Linux or macOS download command:
     259 +wget https://crash.directory/y0qr2c/a.log
     260 + 
     261 +3) Windows download command:
     262 +Invoke-WebRequest -Uri https://crash.directory/y0qr2c/a.log -OutFile a.log
     263 +```
     264 + 
Please wait...
Page is in error, reload to recover