2011-04-18 34 views
7

私は手動で(16進ダンプを見て)それを行う方法を知っています。どうすれば同じものを自動的に入手できますか? APIを使用する必要がありますか?私はwiresharkとMicrosoftネットワークモニタの両方を持っています。パケットのHTTPヘッダー長を調べる方法は?

+0

あなたは、アプリケーションから、「自動的に」とは何を意味するのですか?キャプチャのどの部分がHTTPヘッダーなどであるかを調べるだけであれば、Wiresharkは自動的にパケットを解析します。任意のHTTPデータパケットを検索し、右クリックして「Follow TCP Stream」を選択すると、ヘッダーが明瞭に読み取れるHTTPトラフィックが表示されます。 –

+0

@Tim:HTTPヘッダー長をバイトで知りたい私はHTTPの会話を見ることができますが、どのように私はHTTPヘッダーの長さを列として言うことができますか? – Bruce

+0

私はあなたが "列として"を意味するか分からない。基本的には、HTTPリクエストの始めから最初の二重改行( '\ n \ n'または' \ r \ n \ r \ n')までTCPストリームを検索する必要があります。見つかったインデックスは、ヘッダーの長さです。これをWiresharkに表示するには、プラグインなどを開発する必要があります。あなたがテーブルや何かを処理するためにデータをダンプするのであれば、説明したように長さを計算する必要があります。 –

答えて

8

これは、このスクリーンショットのように、あなたはそれのためにフィルタリングすることができ、パケットツリーにHTTPヘッダフィールドを追加しLua dissectorで簡単に達成することができます:

enter image description here

コピー本のLuaスクリプトに(例えば、${WIRESHARK_HOME}/plugins/1.4.6/http_extra.lua)、Wiresharkを再起動します(すでに実行している場合)。

do 
     local http_wrapper_proto = Proto("http_extra", "Extra analysis of the HTTP protocol"); 
     http_wrapper_proto.fields.hdr_len = ProtoField.uint32("http.hdr_len", "Header length (bytes)") 

     -- HTTP frames that contain a header usually include the HTTP 
     -- request method or HTTP response code, so declare those here 
     -- so we can check for them later in the dissector. 
     local f_req_meth = Field.new("http.request.method") 
     local f_resp_code = Field.new("http.response.code") 

     local original_http_dissector 
     function http_wrapper_proto.dissector(tvbuffer, pinfo, treeitem) 
       -- We've replaced the original http dissector in the dissector table, 
       -- but we still want the original to run, especially because we need 
       -- to read its data. Let's wrap the call in a pcall in order to catch 
       -- any unhandled exceptions. We'll ignore those errors. 
       pcall(
        function() 
         original_http_dissector:call(tvbuffer, pinfo, treeitem) 
        end 
       ) 

       -- if the request method or response code is present, 
       -- the header must be in this frame 
       if f_req_meth() or f_resp_code() then 

         -- find the position of the header terminator (two new lines), 
         -- which indicates the length of the HTTP header, and then add 
         -- the field to the tree (allowing us to filter for it) 
         local hdr_str = tvbuffer():string() 
         local hdr_len = string.find(hdr_str, "\r\n\r\n") or string.find(hdr_str, "\n\n\n\n") 
         if hdr_len ~= nil then 
          treeitem:add(http_wrapper_proto.fields.hdr_len, hdr_len):set_generated() 
         end 
       end 
     end 

     local tcp_dissector_table = DissectorTable.get("tcp.port") 
     original_http_dissector = tcp_dissector_table:get_dissector(80) -- save the original dissector so we can still get to it 
     tcp_dissector_table:add(80, http_wrapper_proto)     -- and take its place in the dissector table 
end 
+0

返信いただきありがとうございます。私はあなたの手順に従ったが、パケットの説明にhttpヘッダーの長さが表示されない。私はWindowsで作業しています。 – Bruce

+0

@ブルース:** 1。**どのバージョンのWiresharkを実行していますか? ** 2。**メニュー "Tools"に行くと、サブメニュー "Lua"が表示されますか?そうでない場合、Luaは無効になります(標準インストールではデフォルトで有効)。 ** 3。** HTTPヘッダー長フィールドは、パケットにHTTPヘッダーが含まれている場合にのみ、パケット記述に追加されます。それを確認しましたか? –

+0

@ Bruce:btw、Windows XP SP3のWireshark 1.4.6でこのスクリプトをテストしました。 –

2

残念ながら、カスタム列を作成することはできますが、その列に必要なデータは現在HTTPプロトコルデコーダによって生成されていません。もちろん、これにはまだ慣れていない他のツールがあるかもしれませんが、Wiresharkに関する限り、その機能を追加する必要があります。

http://simeonpilgrim.com/blog/2008/04/29/how-to-build-a-wireshark-plug-in/

http://www.wireshark.org/docs/wsdg_html_chunked/ChDissectAdd.html

http://www.codeproject.com/KB/IP/custom_dissector.aspx

そしてここプロトコルによって公開されていますフィールドを追加する方法を説明したビデオだ:

あり、いくつかの良いリソースは、例えば、Wiresharkのプラグインを作成することにしていますデコーダをカスタム列として使用する場合:

http://www.youtube.com/watch?v=XpUNXDkfkQg

問題は、HTTPプロトコルデコーダを再実装したくないということです。私はどうなるのか

はのためのソースコードを見つけることであるHTTPデコーダを内蔵し、ちょうどhttp.content_length既存のようにのようなhttp.header_lengthを新しいフィールドを追加することを見て:

img

私は見ていませんコードでは、私はこれを追加するのはかなり簡単なことだと思います。 Wiresharkチームにパッチを提出すれば、次のリリースで新しいフィールドを追加することになるでしょう。

0

私は「チャンク」転送エンコードのために行われたHTTPパケットの再構成で何とかinterferreチェーン内の前の解剖器具を呼び出すこの方法ということがわかりました。つまり、あなたのレスポンスに 'Transfer-Encoding:chunked'ヘッダーがある場合、元のHTTPディセクタはデータを再構築しようとします。そのようなhttp_wrapperでフックすると、再アセンブリは失敗します。

たとえば、これによりhttp統計も失敗します。統計/ HTTP /パケットカウンターはあなたに6リクエストと4レスポンスを与えるでしょう=)

'register_postdissector' API呼び出しや再アセンブリのテストでこのような種類の '付加価値'ロジックは注意深く。

2

user568493によって投稿されたコードは私にとってはまったく機能しませんでした。したがって、それをポストディセクターに変更しました。また、正しくバイト数を数えていませんでした。 IPとイーサネットのバイトも数えていました。

これは1.8.2で動作します私のバージョン、次のとおりです。

local http_wrapper_proto = Proto("http_extra", "Extra analysis of the HTTP protocol"); 
http_wrapper_proto.fields.hdr_len = ProtoField.uint32("http.hdr_len", "HTTP Header length (bytes)") 

-- HTTP frames that contain a header usually include the HTTP 
-- request method or HTTP response code, so declare those here 
-- so we can check for them later in the dissector. 
local f_req_meth = Field.new("http.request.method") 
local f_resp_code = Field.new("http.response.code") 

local original_http_dissector 
function http_wrapper_proto.dissector(tvbuffer, pinfo, treeitem) 
     -- if the request method or response code is present, 
     -- the header must be in this frame 
     if f_req_meth() or f_resp_code() then 
       local start_offset = 0 
       local end_offset = 0 
       -- find the position of the header terminator (two new lines), 
       -- which indicates the length of the HTTP header, and then add 
       -- the field to the tree (allowing us to filter for it) 
       local hdr_str = tvbuffer():string() 
       if f_req_meth() then 
        start_offset = string.find(hdr_str, "GET") 
        end_offset = string.find(hdr_str, "\r\n\r\n") 
       end 
       if f_resp_code() then 
        start_offset = string.find(hdr_str, "HTTP") 
        end_offset = string.find(hdr_str, "\r\n\r\n") 
       end 
       local hdr_len = end_offset - start_offset + 4 
       -- 4 Bytes because the \r\n\r\n are not part of the HTTP Payload, hence should be counted in the header length. 
       if hdr_len ~= nil then 
        treeitem:add(http_wrapper_proto.fields.hdr_len, hdr_len):set_generated() 
       end 
     end 
end 

register_postdissector(http_wrapper_proto) 
関連する問題