curl
基礎
コマンド
telnet で 25 接続
$ curl -v telnet://10.0.12.10:25
basic 認証
# curl --basic --user id:password http://example.com
- ダイジェスト認証の場合には、--digest となる
ホストをつける
# curl -H 'HOST: wiki.renoretriever.net' 158.199.143.102
対応しているSSL暗号化スイートを確認する
RC4-MD5 は対応
$ curl -kI https://example.net/wordpress/ --ciphers RC4-MD5 HTTP/1.1 200 OK Date: Tue, 08 May 2018 02:29:54 GMT Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.4.16 X-Powered-By: PHP/5.4.16 Set-Cookie: HttpOnly;Secure Content-Type: text/html; charset=UTF-8
EXP-RC4-MD5 は未対応
$ curl -I https://hb-training-local.net/wordpress/ --ciphers EXP-RC4-MD5 curl: (59) failed setting cipher list: EXP-RC4-MD5
NIC 指定
- --interface eth0
-w オプション
yahoo トップページのサイズ確認
# curl -L -s -o /dev/null http://yahoo.co.jp -w '%{size_download}\n' 19494
time_starttransfer
オプション
オプション 用途 -d, --data, --data-ascii テキストデータ(エスケープ済)
Content-Type: application/x-www-form-urlencoded がセットされる--data-urlencode テキストデータ(エスケープは curl コマンドが行なう) --data-binary バイナリデータ -T or -d @ファイル名 送付したいデータをファイルから読み込む
ファイル名は送信されず、ファイルの内容が展開されて送信される-f 通信に失敗したら検知 -A 'iPhone' ユーザエージェント指定 -H HTTP ヘッダーを指定 -i HTTP ヘッダーを含めて表示 -I HTTP ヘッダーのみ表示 -k SSL 証明書のエラーを無視する --limit-rate 1k 帯域制限
1kb にてファイルを GET する-L 30X 系が返された時に、Location ヘッダーの URL にアクセスを行う -o [filename] ファイル名を指定して保存 -O URL 上のファイルと同じ名前で保存する
ファイル test.txt を multipart/form-data としてファイルアップロード
$ curl -F attachement-file@text.txt http://example.com/
- -d オプションとは併用不可
404 などのエラーが発生した時に $? の値を取得したい
オプション無し
$ curl 10.0.12.20/yrdy/ <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>404 Not Found</title> </head><body> <h1>Not Found</h1> <p>The requested URL /yrdy/ was not found on this server.</p> </body></html> $ echo $status 0
オプションあり(-f)
$ curl -f 10.0.12.20/yrdy/ curl: (22) The requested URL returned error: 404 Not Found $ echo $status 22
証明証確認
$ curl --cert-status https://www.google.co.jp/
TLS ネゴシエーション時に指定のバージョンでつなぐように強制(TLSv1.0 〜 1.3)
curl --tlsv1.0 --tlsv1.1 --tlsv1.2 --tlsv1.3 https://www.google.co.jp/
サーバ側で SSL version3 を不許可にしているときの動作
$ curl --sslv3 https://hoge.test.test -k curl: (35) error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure
チャンクサイズ指定
$ curl -T test.txt -H "Transfer-Encoding: chunked" http://example.com
proxy 経由してのアクセス
$ docker run -d -p 3128:3128 --name squid poklet/squid
接続
$ curl --proxy http://localhost:3128 -v https://yahoo.com
http2 で送信
$ curl --http2 -v https://www.google.co.jp -o /dev/null 2>&1 | grep "HTTP/2 200"
セッション情報のセット
$ curl --cookie "SSID=user1" http://192.168.33.10/index.php
cookie を送信し、セッション情報を引き継ぐ
curl -c cookie.txt -d "user=kuboon" -d "pass=password" "http://example.com/login" curl -b cookie.txt "http://exapmle.com/admin/get_data"