【问题标题】:sending protobufs file to an API endpoint将 protobufs 文件发送到 API 端点
【发布时间】:2019-10-25 06:09:41
【问题描述】:

所以我有一个 API 端点,它应该获取 protobufs bin 文件。 它是用 C# 编写并使用 protobufs-net。

当我尝试将文件发送到此端点时,我收到以下错误:

RUnexpected end-group in source data; this usually means the source data is corrupt

我尝试了以下请求(从 bin 文件中解码):

POST /api/protobufs HTTP/1.1
Host: xyz
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-protobuf
Connection: close
Upgrade-Insecure-Requests: 1
Content-Length: 3555

1 {
  1: "4f81b7bb-d8bd-e911-9c1f-06ec640006bb"
  2: 0x404104bc4ed047ac
  3: 0x4049c4fee8a8cb66
  4: 0x40400000
  5 {
    1: "53f8afde-04c6-e811-910e-4622e9d1766e"
    2 {
      1: "e993fba0-8fc9-e811-9c15-06ec640006bb"
    }
    2 {
      1: "9a7c7210-3aca-e811-9c15-06ec640006bb"
      2: 1
    }
    2 {
      1: "2d7d12f1-2bc9-e811-9c15-06ec640006bb"
    }
    3: 18446744073709551615
  }
  6: 159
  7: 1571059251000
}
1 {
  1: "4f81b7bb-d8bd-e911-9c1f-06ec640006bb"
  2: 0x404104d746a35280
  3: 0x4049c5125c231685
  4: 0x40400000
  5 {
    1: "53f8afde-04c6-e811-910e-4622e9d1766e"
    2 {
      1: "e993fba0-8fc9-e811-9c15-06ec640006bb"
    }
    2 {
      1: "9a7c7210-3aca-e811-9c15-06ec640006bb"
      2: 1
    }
    2 {
      1: "2d7d12f1-2bc9-e811-9c15-06ec640006bb"
    }
    3: 18446744073709551615
  }
  6: 95
  7: 1571059255000
}

当我尝试上传 bin 文件本身时,我收到以下错误:


Invalid wire-type; this usually means you have over-written a file without truncating or setting the length; see https://stackoverflow.com/q/2152978/23354

请求是:

POST /api/protobufs HTTP/1.1
Host: xyz
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0
Accept: application/x-protobuf,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Content-Type: application/octet-stream
Upgrade-Insecure-Requests: 1
Content-Length: 2029


õ
$4f81b7bb-d8bd-e911-9c1f-06ec640006bb ¬GÐN¼ A@ f˨èþÄI@%��@@*«
$53f8afde-04c6-e811-910e-4622e9d1766e &
$e993fba0-8fc9-e811-9c15-06ec640006bb (
$9a7c7210-3aca-e811-9c15-06ec640006bb &
$2d7d12f1-2bc9-e811-9c15-06ec640006bb ÿÿÿÿÿÿÿÿÿ 0Ÿ 8¸î¶ÓÜ-

我尝试使用 application/x-protobufapplication/octet-stream 的内容类型

我发送正确吗?我怎样才能发送文件。 (这部分我使用了 burp 套件)

【问题讨论】:

    标签: protocol-buffers protobuf-net protobuf-c protobuf-java protobuf-csharp-port


    【解决方案1】:

    我尝试了以下请求(从 bin 文件中解码)

    我怀疑括号中的位是问题所在。那是protoc 的人类可读控制台输出,它的存在只是为了帮助您理解 protobuf 有效负载中的内容;它实际上不是 protobuf。 protobuf 是您之前拥有的不可读的二进制块。

    从上一个问题来看,您似乎正在尝试编辑 protobuf 有效负载的内容。为此,通常的过程是:

    1. 获取 .proto 架构(或从上一个问题对其进行逆向工程)
    2. 使用适当的工具将 .proto 架构 (#1) 转换为以您选择的语言/框架表示模型的代码
    3. 使用模型 (#2) 将有效负载反序列化为一些对象图,即数据
    4. 从 (#3) 改变对象图
    5. 使用模型 (#2) 序列化变异对象图 (#4)

    然后您将从 #5 上传二进制文件

    一些库和框架允许您跳过第 1 步和第 2 步,使用“代码优先”的方法来定义模型,但结果是相同的。

    【讨论】:

      猜你喜欢
      • 2018-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多