格式化字符串漏洞,覆盖变量

时间:2018-05-07 08:50:58

标签: c string security printf format-string

我已经谷歌搜索并阅读了不同的论文,但找不到解决方案。

我编写了一个小程序,我想要覆盖函数的参数。

fff6c602 f7d61138 5658b559 0 0 fff6b698 5658b5f4 1
Segmentation fault

如果我使用此设置运行它,程序的输出如下:

val conf = new NeuralNetConfiguration.Builder()
  .updater(new Sgd(0.01))
  .graphBuilder()
  .addInputs("item_input", "user_input")
  .addLayer("item_embedding", new DenseLayer.Builder().nIn(5).nOut(5).build(), "item_input")
  .addLayer("user_embedding", new DenseLayer.Builder().nIn(5).nOut(5).build(), "user_input")
  // Something
  .build()

val net = new ComputationGraph(conf)
net.init()

1是函数的参数,我要覆盖它。但正如你可以看到我是否使用%n来覆盖它,程序崩溃了,尽管我设置了printf指针。

有谁知道,为什么会这样?

1 个答案:

答案 0 :(得分:1)

来自man - printf(3)

  

<强>%N
  到目前为止写入的字符数存储在整数中   由 * int(或variant)指针参数表示。没有争论   转换。

现在你要做的就是写一些东西来解决0x1,这肯定会导致SIGSEGV。
如果要覆盖函数的参数,则需要找到指向%n的参数的指针。

相关问题