scapy で生成されたネットワーク パケットをレスト サービスに転送しようとしていますが、受信側 (レスト サービス側) でなぜかパケットが壊れてしまいます。
scapy を使用してネットワーク パケットを作成しました。
0000 1a 0b 0c 14 05 16 00 00 00 00 00 00 08 00 45 00 ..............E.
0010 01 10 00 01 00 00 40 11 f0 d2 05 05 05 04 7f 00 ......@.........
0020 00 01 00 44 00 43 00 fc 85 7f 01 00 00 00 00 00 ...D.C..........
0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0110 00 00 00 00 00 00 63 82 53 63 35 01 01 ff ......c.Sc5...
Python コードを使用して、キャプチャした scapy パケットを Web サービスに転送しました。
h = httplib2.Http(".cache")
h.add_credentials("user","passworkd")
data = urllib.urlencode({"packet":pack})
resp, content = h.request(url, "POST", data, headers={'Content-Type': 'applicatoin/x-www-form-urlencodede'})
サーバー側(Javaで実装)で、取得したパケット(バイトストリーム)を出力しました。次の出力が表示されます(送信パケットとは異なります):
1a0b0c140516000000000000080045000110000100004011efbfbdefbfbd050505047f0000010044004300efbfbd7f010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000063efbfbd5363350101efbfbd
編集:
Java サーバー側の処理:
@Path("/test")
@POST
@StatusCodes({
@ResponseCode(code = 200, condition = "Destination reachable"),
@ResponseCode(code = 503, condition = "Internal error"),
@ResponseCode(code = 503, condition = "Destination unreachable") })
public Response rcvDHCPPkt(@FormParam("packet") String packet) {
String pkt_decode = URLDecoder.decode(packet, "UTF-8"); // tried with and without it.
// here it shows the packet corruption. I tried to print packet also it has same problem.
System.out.println("packet received:" + byteArrayToHex(packet_decode.getBytes()));
次の関数を使用して、同等の16進数を出力しました。
public static String byteArrayToHex(byte[] a) {
StringBuilder sb = new StringBuilder(a.length * 2);
for(byte b: a)
sb.append(String.format("%02x", b & 0xff));
return sb.toString();
}
何か不足している場合は、私に提案してください。私は 2 つの問題の urlencoding またはネットワークのバイト順を疑っています。