コンテンツにスキップ

HTTP メソッドとパラメータ

HTTP メソッドと GET / POST パラメータのパターンです。

res = send_request_cgi(
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'search'),
'vars_get' => {
'q' => 'admin',
'page' => '1'
}
)
# GET /app/search?q=admin&page=1
res = send_request_cgi(
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'login.php'),
'vars_post' => {
'username' => datastore['USERNAME'],
'password' => datastore['PASSWORD']
}
)
# Content-Type: application/x-www-form-urlencoded が自動で付く

method が POST で ctype を省略すると、application/x-www-form-urlencoded が自動で付きます。登録・ログインのフォーム POST では ctype の指定は不要です。JSON を送る場合は vars_post ではなく、data と 'ctype' => 'application/json' を使います。詳細は 本文と multipart を参照してください。

res = send_request_cgi(
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'login.php'),
'vars_get' => { 'lang' => 'en' },
'vars_post' => {
'username' => 'admin',
'password' => 'admin'
}
)
# POST /login.php?lang=en

vars_get を使わず、既に組んだ query を載せる場合です。

res = send_request_cgi(
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'x'),
'query' => 'a=1&b[]=2&b[]=3'
)

既定値は true で、名前と値を URI エンコードします。二重エンコードを避けたい、またはサーバが raw を要求する場合は無効化します。

res = send_request_cgi(
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'ping'),
'encode_params' => false,
'vars_get' => {
'ip' => '127.0.0.1;id'
}
)
send_request_cgi(
'method' => 'PUT',
'uri' => normalize_uri(target_uri.path, 'api', 'item', '1'),
'ctype' => 'application/json',
'data' => { 'name' => 'x' }.to_json
)
send_request_cgi(
'method' => 'DELETE',
'uri' => normalize_uri(target_uri.path, 'api', 'item', '1')
)

Hash の値が配列の場合、実装は繰り返し出力します。ネストした構造が必要なら JSON data か、自分で query 文字列を組んで query に渡します。

'vars_get' => {
'id[]' => ['1', '2']
}

ヘッダで HTTP メソッドを指定する例

Section titled “ヘッダで HTTP メソッドを指定する例”

一部 WAF 回避やトンネルではメソッドは POST のまま、実メソッドをヘッダに載せます。

send_request_cgi(
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'api'),
'headers' => {
'X-HTTP-Method-Override' => 'DELETE'
},
'vars_post' => { 'id' => '1' }
)

ペイロードをパラメータへ載せる

Section titled “ペイロードをパラメータへ載せる”
'vars_get' => { 'cmd' => payload.encoded }
'vars_post' => { 'template' => payload.encoded }
'headers' => { 'X-Forwarded-For' => payload.encoded }

command injection なら execute_command に閉じ込めると再利用しやすいです。