コンテンツにスキップ

本文と multipart

フォーム URL エンコード以外の本文パターンです。

res = send_request_cgi(
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'api', 'v1', 'run'),
'ctype' => 'application/json',
'data' => {
'code' => cmd,
'timeout' => 5
}.to_json
)

vars_post と data は同時に使わない方が安全です。どちらか一方にします。

フォームログイン後に JSON API へ送信する場合、ログイン時に keep_cookies を指定しておけば、後続のリクエストに cookie キーは不要です。保存された Cookie は自動で添付されます。手順は 認証と Cookie を参照してください。

POST で ctype を省略すると application/x-www-form-urlencoded が付きます。JSON を送る場合は 'ctype' => 'application/json' を明示します。サーバーが応答のコンテンツネゴシエーションを要求する場合は、headers に 'Accept' => 'application/json' も追加します。ctype は送信する本文の形式、Accept は受け取りたい応答の形式を指定します。

res = send_request_cgi(
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'ingest'),
'ctype' => 'application/xml',
'data' => "<ping>#{cmd}</ping>"
)
res = send_request_cgi(
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'upload'),
'ctype' => 'application/octet-stream',
'data' => payload.encoded
)

Rex::MIME::Message(古典的 multipart)

Section titled “Rex::MIME::Message(古典的 multipart)”
data = Rex::MIME::Message.new
data.add_part(payload.encoded, 'application/octet-stream', 'binary', 'form-data; name="file"; filename="uploaded.bin"')
data.add_part('example', nil, nil, 'form-data; name="_wpnonce"')
res = send_request_cgi(
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'async-upload.php'),
'ctype' => "multipart/form-data; boundary=#{data.bound}",
'data' => data.to_s,
'keep_cookies' => true
)

example_webapp.rb と同じ形です。

新しいモジュールでは vars_form_data が使えます。Array of Hash です。

vars_form_data = [
{
'name' => 'bigUploadFile',
'data' => file_contents,
'filename' => file_name,
'content_type' => 'application/octet-stream'
},
{
'name' => 'path',
'data' => '/tmp'
}
]
res = send_request_cgi(
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'upload.php'),
'vars_form_data' => vars_form_data,
'vars_get' => { 'action' => 'post-unsupported' }
)
フィールドキー意味
nameフォーム欄名
data本文(String など)
filenameファイル名(あれば attachment)
content_typepart の Content-Type(client_request.rb が見るキー)
encodingtransfer encoding

実在例: modules/exploits/linux/http/chamilo_bigupload_webshell.rb(フィールド配列の形)。キー名は実装どおり content_type を使います。

boundary を固定したい稀なケースでは vars_form_data_boundary を渡せます。通常は自動生成で十分です。

ファイルアップロード後の後片付け

Section titled “ファイルアップロード後の後片付け”
register_file_for_cleanup(file_name)

FileDropper を include しておきます。