
IPフィルターとHTTP認証のバイパス(認証なしのX-Forwarded-Forヘッダースプーフィングによる)
コマンドラインから簡単かつ高速にファイル共有ができます。このコードには、ご自身のインスタンスを作成するために必要なすべてが含まれています。
Transfer.shは現在、s3(Amazon S3)、gdrive(Google Drive)、storj(Storj)プロバイダー、およびローカルファイルシステム(local)をサポートしています。
@stefanbentenは、このリポジトリのメンテナーであると同時に、このソフトウェアのよく知られた公開インスタンスをホストしている人物です。
両者は無関係であり、公開インスタンスに関するリクエストや問題をこのリポジトリに直接送る場所ではありません。
セキュリティ上の理由から、このソフトウェアのサードパーティの公開インスタンスは、リポジトリ内で宣伝されたり言及されたりすることはありません。
メンテナーである@aspaccaとしての私の公式な立場は、このソフトウェアを使用したい場合は、ご自身でインスタンスをホストするべきである、というものです。
このセクションでは、transfer.shの使用方法を説明します。
$ curl -v --upload-file ./hello.txt https://transfer.sh/hello.txt
<br />
### 暗号化とアップロード```bash
$ gpg --armor --symmetric --output - /tmp/hello.txt | curl --upload-file - https://transfer.sh/test.txt
$ curl https://transfer.sh/1lDau/test.txt | gpg --decrypt --output /tmp/hello.txt
<br />
### Virustotal にアップロード```bash
$ curl -X PUT --upload-file nhgbhhj https://transfer.sh/test.txt/virustotal
$ curl -X DELETE
<br />
---
<br />
## リクエストヘッダー
このセクションでは、curlを使用したリクエストヘッダーの扱い方について説明します。
<br />
### Max-Downloads```bash
$ curl --upload-file ./hello.txt https://transfer.sh/hello.txt -H "Max-Downloads: 1" # Limit the number of downloads
$ curl --upload-file ./hello.txt https://transfer.sh/hello.txt -H "Max-Days: 1" # Set the number of days before deletion
<br />
### X-Encrypt-Password
#### 注意:この機能は自己ホストサーバーでのみ使用してください。サーバーサイドの暗号化をサードパーティのサービスに委ねることは自己責任となります。```bash
$ curl --upload-file ./hello.txt https://your-transfersh-instance.tld/hello.txt -H "X-Encrypt-Password: test" # Encrypt the content server side with AES256 using "test" as password
$ curl https://your-transfersh-instance.tld/BAYh0/hello.txt -H "X-Decrypt-Password: test" # Decrypt the content server side with AES256 using "test" as password
<br />
---
<br />
## レスポンスヘッダー
このセクションでは、レスポンスヘッダーの扱い方について説明します:
<br />
### X-Url-Delete
ファイルの削除を要求するために使用され、レスポンスヘッダーとして返されるURL:```bash
curl -sD - --upload-file ./hello.txt https://transfer.sh/hello.txt | grep -i -E 'transfer\.sh|x-url-delete'
x-url-delete: https://transfer.sh/hello.txt/BAYh0/hello.txt/PDw0NHPcqU
https://transfer.sh/hello.txt/BAYh0/hello.txt
良い使用例は examples.md を参照してください。
直接ダウンロードリンクを作成:
https://transfer.sh/1lDau/test.txt --> https://transfer.sh/get/1lDau/test.txt
インラインファイル:
https://transfer.sh/1lDau/test.txt --> https://transfer.sh/inline/1lDau/test.txt
Let's Encrypt証明書を使用してTLSを利用する場合は、lets-encrypt-hostsにドメインを設定し、tls-listenerを :443 に設定し、force-httpsを有効にしてください。
独自の証明書を使用してTLSを利用する場合は、tls-listenerを :443 に設定し、force-https、tls-cert-file、tls-private-keyを設定してください。
GO111MODULEに切り替えました```bash go run main.go --provider=local --listener :8080 --temp-path=/tmp/ --basedir=/tmp/
<br />
---
<br />
## ビルド```bash
$ git clone [email protected]:dutchcoders/transfer.sh.git
$ cd transfer.sh
$ go build -o transfersh main.go
簡単なデプロイのために、公式Dockerコンテナを作成しました。プロセスを実行するユーザーのみが異なる2つのバリアントがあります。
デフォルトのものは root として実行されます:
[!WARNING]
latestタグを WatchTower または類似のツールで使用することは推奨されません。latestタグは未リリースの開発版、テストビルド、古いバージョンのパッチリリースを参照する可能性があります。transfer.sh がメジャーバージョンまたはマイナーバージョンのタグをサポートするまでは、実際のバージョンタグを使用してください。```bash docker run --publish 8080:8080 dutchcoders/transfer.sh:latest --provider local --basedir /tmp/
<br />
### 非ルート
`-noroot`タグは、アプリケーションが侵害された場合に備えて攻撃対象領域を減らすために、最小権限で実行されるイメージビルドを示します。
> [!NOTE]
> `-noroot` の使用は **推奨** されます。
<br />
接尾辞 `-noroot` が付いたものは、UID と GID の両方に `5000` を使用します。```bash
docker run --publish 8080:8080 dutchcoders/transfer.sh:latest-noroot --provider local --basedir /tmp/
[!NOTE] 開発履歴の詳細はこちら:
コンテナを自分でビルドすることもできます。これにより、使用するUID/GIDを選択できます(例:NFSマウントを使用する場合など)。```bash
docker build -t transfer.sh-noroot --build-arg RUNAS=doesntmatter --build-arg PUID=1337 --build-arg PGID=1338 .
<br />
---
<br />
## S3 の使い方
AWS S3 バケットを使用するには、以下のオプションを指定するだけです:
- provider `--provider s3`
- aws-access-key _(フラグまたは環境変数 `AWS_ACCESS_KEY` で指定)_
- aws-secret-key _(フラグまたは環境変数 `AWS_SECRET_KEY` で指定)_
- bucket _(フラグまたは環境変数 `BUCKET` で指定)_
- s3-region _(フラグまたは環境変数 `S3_REGION` で指定)_
s3-region を指定すれば、正しいエンドポイントが自動的に使用されるため、エンドポイント URL を設定する必要はありません。
<br />
### カスタム S3 プロバイダー
非 AWS のカスタム S3 プロバイダーを使用するには、クラウドプロバイダーによって定義されたエンドポイントを指定する必要があります。
<br />
---
<br />
## Storj ネットワークプロバイダー
Storj ネットワークをストレージプロバイダーとして使用するには、以下のフラグを指定する必要があります:
- provider `--provider storj`
- storj-access _(フラグまたは環境変数 STORJ_ACCESS で指定)_
- storj-bucket _(フラグまたは環境変数 STORJ_BUCKET で指定)_
<br />
### バケットとスコープの作成
準備として、アクセス権限(または uplink の設定からコピー)とバケットを作成する必要があります。
開始するには、アカウントにログインし、アクセス権限メニューに移動して、右上のウィザードを開始してください。
任意のアクセス権限名を入力し、*Next* をクリックして、必要に応じて制限を設定します。
その後、CLI またはブラウザ内で続行します。次に、暗号化キーとして使用するパスフレーズを求められます。
**安全な場所に保存してください。これがないと、ファイルを復号できなくなります!**
その後、アクセス権限をコピーし、transfer.sh エンドポイントの起動を開始できます。
セキュリティを強化するために、アクセス権限とバケット名の両方を環境変数として指定することをお勧めします。
例:```
export STORJ_BUCKET=<BUCKET NAME>
export STORJ_ACCESS=<ACCESS GRANT>
transfer.sh --provider storj
Google Drive を使用するには、次のオプションを指定する必要があります:
console.cloud.google.com から OAuth クライアント ID を作成し、ファイルをダウンロードして、安全なディレクトリに配置する必要があります。
go run main.go --provider gdrive --basedir /tmp/ --gdrive-client-json-filepath /[credential_dir] --gdrive-local-config-path [directory_to_save_config] transfer() (if [ $# -eq 0 ]; then printf "引数が指定されていません。\n使用法:\n transfer <file|directory>\n ... | transfer <file_name>\n">&2; return 1; fi; file_name=$(basename "$1"); if [ -t 0 ]; then file="$1"; if [ ! -e "$file" ]; then echo "$file: そのようなファイルまたはディレクトリはありません">&2; return 1; fi; if [ -d "$file" ]; then cd "$file" || return 1; file_name="$file_name.zip"; set -- zip -r -q - .; else set -- cat "$file"; fi; else set -- cat; fi; url=$("$@" | curl --silent --show-error --progress-bar --upload-file "-" "https://transfer.sh/$file_name"); echo "$url"; )```
<br />
#### Now you can use transfer function
$ transfer hello.txt```
transfer()
{
local file
declare -a file_array
file_array=("${@}")
if [[ "${file_array[@]}" == "" || "${1}" == "--help" || "${1}" == "-h" ]]
then
echo "${0} - Upload arbitrary files to \"transfer.sh\"."
echo ""
echo "Usage: ${0} [options] [<file>]..."
echo ""
echo "OPTIONS:"
echo " -h, --help"
echo " show this message"
echo ""
echo "EXAMPLES:"
echo " Upload a single file from the current working directory:"
echo " ${0} \"image.img\""
echo ""
echo " Upload multiple files from the current working directory:"
echo " ${0} \"image.img\" \"image2.img\""
echo ""
echo " Upload a file from a different directory:"
echo " ${0} \"/tmp/some_file\""
echo ""
echo " Upload all files from the current working directory. Be aware of the webserver's rate limiting!:"
echo " ${0} *"
echo ""
echo " Upload a single file from the current working directory and filter out the delete token and download link:"
echo " ${0} \"image.img\" | awk --field-separator=\": \" '/Delete token:/ { print \$2 } /Download link:/ { print \$2 }'"
echo ""
echo " Show help text from \"transfer.sh\":"
echo " curl --request GET \"https://transfer.sh\""
return 0
else
for file in "${file_array[@]}"
do
if [[ ! -f "${file}" ]]
then
echo -e "\e[01;31m'${file}' could not be found or is not a file.\e[0m" >&2
return 1
fi
done
unset file
fi
local upload_files
local curl_output
local awk_output
du -c -k -L "${file_array[@]}" >&2
# be compatible with "bash"
if [[ "${ZSH_NAME}" == "zsh" ]]
then
read $'upload_files?\e[01;31mDo you really want to upload the above files ('"${#file_array[@]}"$') to "transfer.sh"? (Y/n): \e[0m'
elif [[ "${BASH}" == *"bash"* ]]
then
read -p $'\e[01;31mDo you really want to upload the above files ('"${#file_array[@]}"$') to "transfer.sh"? (Y/n): \e[0m' upload_files
fi
case "${upload_files:-y}" in
"y"|"Y")
# for the sake of the progress bar, execute "curl" for each file.
# the parameters "--include" and "--form" will suppress the progress bar.
for file in "${file_array[@]}"
do
# show delete link and filter out the delete token from the response header after upload.
# it is important to save "curl's" "stdout" via a subshell to a variable or redirect it to another command,
# which just redirects to "stdout" in order to have a sane output afterwards.
# the progress bar is redirected to "stderr" and is only displayed,
# if "stdout" is redirected to something; e.g. ">/dev/null", "tee /dev/null" or "| <some_command>".
# the response header is redirected to "stdout", so redirecting "stdout" to "/dev/null" does not make any sense.
# redirecting "curl's" "stderr" to "stdout" ("2>&1") will suppress the progress bar.
curl_output=$(curl --request PUT --progress-bar --dump-header - --upload-file "${file}" "https://transfer.sh/")
awk_output=$(awk \
'gsub("\r", "", $0) && tolower($1) ~ /x-url-delete/ \
{
delete_link=$2;
print "Delete command: curl --request DELETE " "\""delete_link"\"";
gsub(".*/", "", delete_link);
delete_token=delete_link;
print "Delete token: " delete_token;
}
END{
print "Download link: " $0;
}' <<< "${curl_output}")
# return the results via "stdout", "awk" does not do this for some reason.
echo -e "${awk_output}\n"
# avoid rate limiting as much as possible; nginx: too many requests.
if (( ${#file_array[@]} > 4 ))
then
sleep 5
fi
done
;;
"n"|"N")
return 1
;;
*)
echo -e "\e[01;31mWrong input: '${upload_files}'.\e[0m" >&2
return 1
esac
}```
</p></details>
#### Sample output
```bash
$ ls -lh
total 20M
-rw-r--r-- 1 <some_username> <some_username> 10M Apr 4 21:08 image.img
-rw-r--r-- 1 <some_username> <some_username> 10M Apr 4 21:08 image2.img
$ transfer image*
10240K image2.img
10240K image.img
20480K total
上記のファイル(2つ)を本当に"transfer.sh"にアップロードしますか?(Y/n):
######################################################################################################################################################################################################################################## 100.0%
削除コマンド:curl --request DELETE "https://transfer.sh/wJw9pz/image2.img/mSctGx7pYCId"
削除トークン:mSctGx7pYCId
ダウンロードリンク:https://transfer.sh/wJw9pz/image2.img
######################################################################################################################################################################################################################################## 100.0%
削除コマンド:curl --request DELETE "https://transfer.sh/ljJc5I/image.img/nw7qaoiKUwCU"
削除トークン:nw7qaoiKUwCU
ダウンロードリンク:https://transfer.sh/ljJc5I/image.img
$ transfer "image.img" | awk --field-separator=": " '/Delete token:/ { print $2 } /Download link:/ { print $2 }'
10240K image.img
10240K total
上記のファイル(1つ)を本当に"transfer.sh"にアップロードしますか?(Y/n):
######################################################################################################################################################################################################################################## 100.0%
tauN5dE3fWJe
https://transfer.sh/MYkuqn/image.img```
<br />
---
<br />
## Contributions
Contributions are welcome.
<br />
---
<br />
## Creators
**Remco Verhoef**
- <https://twitter.com/remco_verhoef>
- <https://twitter.com/dutchcoders>
**Uvis Grinfelds**
<br />
---
<br />
## Maintainers
- **Andrea Spacca**
- **Stefan Benten**
<br />
---
<br />
## Copyright and License
Code and documentation copyright 2011-2018 Remco Verhoef.
Code and documentation copyright 2018-2020 Andrea Spacca.
Code and documentation copyright 2020- Andrea Spacca and Stefan Benten.
Code released under [the MIT license](https://github.com/dutchcoders/transfer.sh/blob/HEAD/LICENSE).
| パラメータ | 説明 | 値 | 環境変数 |
|---|
| listener | HTTPで使用するポート (:80) | LISTENER | |
| profile-listener | プロファイラで使用するポート (:6060) | PROFILE_LISTENER | |
| force-https | HTTPSにリダイレクト | false | FORCE_HTTPS |
| tls-listener | HTTPSで使用するポート (:443) | TLS_LISTENER | |
| tls-listener-only | TLSリスナーのみを有効にするフラグ | TLS_LISTENER_ONLY | |
| tls-cert-file | TLS証明書へのパス | TLS_CERT_FILE | |
| tls-private-key | TLS秘密鍵へのパス | TLS_PRIVATE_KEY | |
| http-auth-user | アップロード時の基本HTTP認証のユーザー | HTTP_AUTH_USER | |
| http-auth-pass | アップロード時の基本HTTP認証のパスワード | HTTP_AUTH_PASS | |
| http-auth-htpasswd | アップロード時の基本HTTP認証用htpasswdファイルのパス | HTTP_AUTH_HTPASSWD | |
| http-auth-ip-whitelist | 認証チャレンジなしでアップロードを許可するIPのカンマ区切りリスト | HTTP_AUTH_IP_WHITELIST | |
| virustotal-key | VirusTotal APIキー | VIRUSTOTAL_KEY | |
| ip-whitelist | サービスへの接続を許可するIPのカンマ区切りリスト | IP_WHITELIST | |
| ip-blacklist | サービスへの接続を許可しないIPのカンマ区切りリスト | IP_BLACKLIST | |
| temp-path | 一時フォルダへのパス | システムの一時領域 | TEMP_PATH |
| web-path | 静的Webファイルへのパス(開発用またはカスタムフロントエンド用) | WEB_PATH | |
| proxy-path | サービスがプロキシの背後で実行されるときのパスプレフィックス(先頭の/はトリムされます) | PROXY_PATH | |
| proxy-port | サービスがプロキシの背後で実行されるときのプロキシポート | PROXY_PORT | |
| email-contact | フロントエンドのメール連絡先 | EMAIL_CONTACT | |
| ga-key | フロントエンドのGoogle Analyticsキー | GA_KEY | |
| provider | 使用するストレージプロバイダ | (s3, storj, gdrive または local) | |
| uservoice-key | フロントエンドのUserVoiceキー | USERVOICE_KEY | |
| aws-access-key | AWSアクセスキー | AWS_ACCESS_KEY | |
| aws-secret-key | AWSシークレットキー | AWS_SECRET_KEY | |
| bucket | AWSバケット | BUCKET | |
| s3-endpoint | カスタムS3エンドポイント | S3_ENDPOINT | |
| s3-region | S3バケットのリージョン | eu-west-1 | S3_REGION |
| s3-no-multipart | S3マルチパートアップロードを無効化 | false | S3_NO_MULTIPART |
| s3-path-style | パススタイルURLを強制(Minioで必要) | false | S3_PATH_STYLE |
| storj-access | プロジェクトのアクセス権 | STORJ_ACCESS | |
| storj-bucket | プロジェクト内で使用するバケット | STORJ_BUCKET | |
| basedir | ローカル/gdriveプロバイダのストレージパス | BASEDIR | |
| gdrive-client-json-filepath | gdriveプロバイダ用OAuthクライアントJSON設定ファイルへのパス | GDRIVE_CLIENT_JSON_FILEPATH | |
| gdrive-local-config-path | gdriveプロバイダ用ローカルtransfer.sh設定キャッシュを保存するパス | GDRIVE_LOCAL_CONFIG_PATH | |
| gdrive-chunk-size | gdriveアップロードのチャンクサイズ(MB単位)。利用可能メモリより小さくする必要があります(8 MB) | GDRIVE_CHUNK_SIZE | |
| lets-encrypt-hosts | Let's Encrypt証明書に使用するホスト(カンマ区切り) | HOSTS | |
| log | ログファイルへのパス | LOG | |
| cors-domains | CORS用ドメインのカンマ区切りリスト(設定するとCORSが有効になります) | CORS_DOMAINS | |
| clamav-host | ClamAV機能のホスト | CLAMAV_HOST | |
| perform-clamav-prescan | ClamAVを使用してすべてのアップロードを事前スキャン(clamav-hostはローカルのclamd Unixソケットである必要があります) | PERFORM_CLAMAV_PRESCAN | |
| rate-limit | 1分間あたりのリクエスト数 | RATE_LIMIT | |
| max-upload-size | 最大アップロードサイズ(キロバイト) | MAX_UPLOAD_SIZE | |
| purge-days | アップロードが自動的に削除される日数 | PURGE_DAYS | |
| purge-interval | 自動削除を実行する間隔(時間)(S3とStorjは対象外) | PURGE_INTERVAL | |
| random-token-length | アップロードパス用のランダムトークンの長さ(削除パスでは2倍になります) | 6 | RANDOM_TOKEN_LENGTH |
| 名前 | 使用方法 |
|---|
| latest | 最新のCIビルド。ナイトリー、コミット時、タグ時などがあります。 |
| latest-noroot | 最新のCIビルド。ナイトリー、コミット時、タグ時などがあります。[no root]を使用 |
| nightly | 毎日UTC真夜中に予定されたCIビルド |
| nightly-noroot | 毎日UTC真夜中に予定されたCIビルド。[no root]を使用 |
| edge | mainへのコミットごとの最新のCIビルド |
| edge-noroot | mainへのコミットごとの最新のCIビルド。[no root]を使用 |
vx.y.z | リリースのタグ付け後のCIビルド |
vx.y.z-noroot | リリースのタグ付け後のCIビルド。[no root]を使用 |