问题标签 [format-string]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
2510 浏览

c - 以格式字符串漏洞攻击访问数组的第二个元素

我正在研究一个格式字符串漏洞实验室,在那里我们得到了以下代码:

我们根本不应该修改代码。仅使用输入,我们有 4 个目标:使程序崩溃,打印 secret[1] 处的值,修改 secret[1] 处的值,以及将 secret[1] 处的值修改为预定值。

我得到的示例输出是:

因此,通过输入 8 "%08x"s,我打印了 secret + 4 的地址,然后我打印了整数 a、b、c 和 d 的地址——但由于我从未给它们一个值,所以它们没有指向任何地方,只显示0。接下来是我输入的小数点,选择这样“ffff”将清晰可见。接下来是 secret[0] 的地址,然后我进入程序中存储的其他值。

如果我要输入AAAA.%08x.%08x.%08x.%08x.%08x.%08x.%08x%08x..0804a008 之后将是 .41414141,因为字符串输入中的 A 将存储在那里。

程序很容易崩溃:字符串输入上足够的 %s 会导致段错误。不过,现在我需要读取 secret[1] 的值,我完全迷失了。我试图以某种方式将地址放在堆栈上,方法是将其放在字符串的开头,如下所示:\xd0\xe7\xff\xbf_%08x.%08x.%08x.%08x.%08x.%08x.%s,但地址没有被推送到任何地方,我只是打印 secret[0] (好奇的是'D')。我尝试了各种地址,但过了一会儿我意识到我只是将它们全部存储为一个字符串,这些 A 之前出现过。他们没有被转换为十六进制或任何东西。

我在 SA 和其他地方看到了很多关于此代码的讨论,但我还没有看到有人谈论你如何在 secret[1] 上获得这些值。

任何帮助将不胜感激。

0 投票
1 回答
1342 浏览

wpf - 如何在 WPF 中将逗号添加到自定义 DateTime StringFormat

我有一个日期和时间显示在文本块中。它目前使用此代码显示“Jun. 21 2013 10:30 AM”

我希望它在一个月中的某天之后用逗号显示:“Jun. 21, 2013 10:30 AM”

只需在“dd”之后添加一个逗号,就会产生无法识别尾随格式字符串的错误。有没有办法在这个自定义 StringFormat 中添加逗号?

0 投票
1 回答
161 浏览

c# - 我的正则表达式有什么问题?

我的正则表达式代码不起作用我得到如下结果。任何想法

我的代码错误:

改句的条件

  1. 如果 MINVALUE 在句子中具有正值,则使开头的值与 MINVALUE 相同...
  2. 如果 MINVALUE 在句子中具有负值,则使开始的值与 MAXVALUE 相同

在我的数据库中,我有 3 句话需要更改...

结果应该如下所示

我的代码:

0 投票
4 回答
152 浏览

c# - 我是否遗漏了什么,或者这段代码是荒谬的?

在探索我们遗留代码的潮湿地下墓穴和尘土飞扬的地牢时,我遇到了这个问题:

我错过了什么,还是我对此的反应,即:formatString 怎么能包含任何东西?什么都没有分配给它......它总是-1 ,假设表示'未找到'“正确吗?

更新

为了回答评论中明显的普遍困惑,我认为 FormatString 是一些乱七八糟的石器时代的 .NET 东西(这个项目使用 .NET 1.1),但你是对的 - 这是一个本土类。这是构造函数:

...和 ​​containsAlpha() 方法:

现在我问你:“FormatString”是这个类的错误名称,还是什么?我发现它非常具有误导性(显然)。

0 投票
4 回答
7829 浏览

c# - 解析 DateTime 格式得到 Format String

我希望能够从 DateTime 字符串中获取格式字符串。

例如

"2012-12-08 15:00:00" => "yyyy-MM-dd HH:mm:ss"

"2013/30/01 16:00" => "yyyy/dd/MM HH:mm"

这可能吗?

0 投票
2 回答
10053 浏览

c - Format strings and using %n to overwrite memory address with specific value

I am reading about and trying to learn format string vulnerabilities. I have a vulnerable function and I understand the gist of what I have to do with my format string.

Basically, this is what I want to do. Pass in my format string which contains some shellcode as part of it. I also need to format my string so that the return address of the vulnerable function gets replaced so that it points to my shellcode on the stack. Hence, when the function returns, it will jump to my shellcode on the stack and open a shell.

Currently, I am at the point where I can see my shellcode on the stack, and I am able to write to the return address to change it. Problem is, I am using %n as my way of overwriting the return address and am not sure how to get %n to overwrite with a specific value. Of course, %n simply prints the number of bytes written so far to the specified address on the stack. I've read a couple of things on how you can manipulate %n to write the exact address/value you want, but I am lost on how to do that.

Can anyone shed some light?

Edit: I've tried padding my format string with things such as '%500d" and "%.500d" as well as "%nu" for some n values. (I've tried much smaller values as well) but that just brings about a segmentation fault.

To clear up some confusion, here's a quick example I wrote in response to a comment:

Okay, I'll try to be a little more clear. I have a vulnerable program. The vulnerable point is "printf(input);". I want to exploit this by passing in a format string. Now for example, I have a format string

This format string, when passed into the vulnerable function, will overwrite the memory address of 0xffbfde0c with the number of bytes written. I am looking to find out how I can modify that format string so that I can make %n overwrite with a specific value by somehow padding the number of bytes written before the %n.

0 投票
1 回答
3313 浏览

c - 格式化字符串漏洞利用 - 打开根 shell

我在禁用堆栈随机化的环境中运行它,并使用与 AlephOne 的缓冲区溢出兼容的 gcc 版本 - 效果很好!

我试图用包含我的 shellcode 的数组的地址覆盖指令指针寄存器(eip)。不过,我总是以分段错误告终。以下是我试图利用的一个片段:

我通过 execve() 调用这个函数。格式字符串就是这里的argv[0],成功传递给上面的函数。

我有这个格式字符串:

其次是 200 个 NOP、shellcode 和剩余的带有 NOP 的数组。

shellcode 是 Aleph One 的代码:

"\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b" "\x89\xf3\x8d\x4e\x08\x8d\x56\ x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd" "\x80\xe8\xdc\xff\xff\xff/bin/sh";

回到格式字符串,我将 4 个地址 0xffbfdc0c 覆盖到 0xffbfdc0f。0xffbfdc0c 是我通过在顶部提到的 print_version() 函数上设置断点找到的保存的 eip 地址。

我正在尝试用地址 0xffbfdcd4 替换它,它比 print_version 中 txt[] 数组的基地址高 150 个字节(计算函数中 txt[] 的初始字符和之后的格式字符串,希望它可以着陆在 shellcode 之前的 NOP 中的某处)。

我只是以 SEG 故障告终。我不确定如何进一步进行或我应该如何调试以查看它是否实际上覆盖了预期地址的值。

编辑:我使用正确的格式字符串吗?

谁能告诉我如何在我的程序产生段错误之后或在段错误之前但在地址更改之后使用 gdb 检查地址?

谢谢。

0 投票
1 回答
1128 浏览

matlab - Matlab 表格语法

matlab 新手,我无法理解我得到的一些代码:

该程序是牛顿方法,用于查找我理解的方程的根。

我不明白的是这部分:

问题:

  1. 为什么第二行的最后一位除以n?
  2. 第二行中的数字是多少,即 %1i、%12.8f 等?
  3. 这如何与后面写的“count, x, f”一起工作?

谢谢

0 投票
7 回答
1129 浏览

c - printf() 中的格式说明符要求 int 何时应为 char

我正在使用 Pelles C ide 并且正在学习 C,我以为我了解到 %c 是 printf() 中 char 的格式说明符,但它认为我正在尝试使用 int?我该如何纠正这个问题。

这是代码:

}

这是错误: 在此处输入图像描述

0 投票
1 回答
556 浏览

c# - 在没有管道功能的情况下以格式字符串利用输入地址的技巧是什么?

注意:这仅用于教育用途。有问题的程序适用于我的应用安全课程,旨在具有格式字符串漏洞。

作业的场景是在邪恶政权的服务器上插入 shell 代码。虽然我的问题只是当我不能使用管道功能将十六进制值插入到 ASCII 范围之外的原始字符串中时如何存储地址。

程序的格式字符串易受攻击的部分要求输入,并且只能通过程序内部的几个选项访问。

如何在原始字符串中存储地址?格式字符串易受攻击程序的源代码是隐藏的。由于易受攻击的字符串嵌入在程序中,因此我无法通过管道进入易受攻击的字符串。

我目前正在尝试通过将以下输入复制并粘贴到程序中:

这给出了以下结果:

它似乎一次读取一个字符。我知道下一步用 %d 和 %n 更改地址的值。

我应该尝试将地址存储在其他地方吗?是否有一些技巧可以输入 ASCII 范围之外的字符?我应该考虑什么来尝试正确存储地址?这有一个技巧,但我只是不知道。