假设我有以下代码:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
int num1 = 0;
int main(int argc, char **argv){
double num2;
int *ptr = &num1;
printf(argv[1]);
if (num1== 2527){
printf("Well done");
}
if(num2 == 4.56)
printf("You are a format string expert");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我正在努力了解如何正确行事,但我无法用互联网上的指南来组织我的思想.
它假设是这样的:
./Program %p %p %p %p
Run Code Online (Sandbox Code Playgroud)
然后
./Program $( printf "\xAA\xAA\xAA\xAA") %.2523d%n
Run Code Online (Sandbox Code Playgroud)
我只是想不出来,请帮我解决这个问题.
其重点是通过prinft函数将字符串利用到正在运行的程序中.我需要打印"完成"和"你是格式字符串专家".就我而言,通过Linux终端/ shell.正如HuStmpHrrr所注意到的:这确实应该是White Hacking - Software Security
有没有一种简单的方法来检查格式字符串是否有效?例如,以下是我们用来测试数字格式字符串的代码;
public static bool IsValidFormatStringNumber(string FormatString)
{
try
{
const decimal number = 0.056m;
var formattedNumber = number.ToString(FormatString);
return formattedNumber.Length > 0;
}
catch
{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我们试图捕获异常或确定结果字符串是否没有长度。然而,此测试失败,因为“hsibbur”(任何垃圾)的格式字符串会产生一个具有长度的“hsaibbur”字符串。
我们想对百分比和日期格式字符串进行相同的测试。
我有一个小的C程序可以被利用.而且我也理解了要执行的攻击背后的逻辑.但是,尽管我尝试过,但这对我来说并不合适.
#include <stdio.h>
#include <stdlib.h>
#define SECRET1 0x44
#define SECRET2 0x55
int main(int argc, char *argv[]) {
char user_input[100];
int *secret;
int int_input;
int a, b, c, d; /* other variables, not used here.*/
/* The secret value is stored on the heap */
secret = (int *) malloc(2*sizeof(int));
/* getting the secret */
secret[0] = SECRET1; secret[1] = SECRET2;
printf("Please enter a decimal integer\n");
scanf("%d", &int_input); /* getting an input from user */
printf("Please enter a string\n");
scanf("%s", user_input); …Run Code Online (Sandbox Code Playgroud) 我希望能够从DateTime字符串中获取格式字符串.
例如
"2012-12-08 15:00:00"=>"yyyy-MM-dd HH:mm:ss"
"2013/30/01 16:00"=>"yyyy/dd/MM HH:mm"
这可能吗?
我目前正在编写一个进行频率分析的短程序.然而,有一条线困扰着我:
"{0[0]} | " + "[]" * num_occurrences + " Total: {0[1]!s}"
Run Code Online (Sandbox Code Playgroud)
在Python中有没有一种方法可以重复某些字符而不需要连接(最好是在格式字符串中)?我不觉得我是以最恐怖的方式做这件事.
假设这段代码:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char** argv){
char fonction[50] = "/usr/bin/passwd ";
char messageAccueil[100] = "changement du mot de passe de : ";
if(argc == 1){
printf("vous devez passer un username en parametre \n");
return 1;
}
printf(messageAccueil);
printf(argv[1]); //<-- format string vulnerability here !!
if(strcmp(argv[1], "root")==0){
printf("vous ne pensiez quand meme pas pouvoir changer le mot de passe de root si facilement ?\n");
return 1;
}
printf("\n");
strncat(fonction,argv[1],38);
system(fonction);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我想通过利用格式化字符串漏洞给exec外壳,所以,我想改写strcmp …
我想在转义的花括号("{{"和"}}"之间构建具有格式化值的字符串.
我更喜欢使用格式字符串而不是ToString()方法来格式化值.
//Works fine but don't use composite format string
$"{{{Math.PI.ToString("n2")}}}" // return {3.14}
//Use composite format string but does not work
$"{{{Math.PI:n2}}} // return {n2}
//Use composite format string but does not work
$"{{{null:n2}}} // return {
//Use composite format string, work fine but I do not want extra space
$"{{{Math.PI:n2} }} // return {3.14 }
Run Code Online (Sandbox Code Playgroud) 我正在尝试开发一种要传递的格式字符串,git log --pretty以便每个日志条目以完整的提交消息结尾,但每个日志条目都由一个空行分隔。问题在于,有些完整提交消息以换行符结尾,有些则不然。
例如,假设我有两个提交abc1234和def5678,但仅abc1234在完整提交消息的末尾包含换行符。在命令行上输出原始提交内容将如下所示:
[prompt]$ git cat-file commit abc1234
(...)
Title FOO
Full commit message FOO
[prompt]$ git cat-file commit def5678
(...)
Title BAR
Full commit message BAR[prompt]$
Run Code Online (Sandbox Code Playgroud)
请注意新的 shell 提示符如何出现在最后一行输出的末尾,表明提交在完整提交消息的末尾def5678不包含换行符。
假设这def5678是父级abc1234,我想输出一个简单的日志,其中每个条目仅包含短提交哈希、标题行和完整提交消息。我可能会尝试这样的事情:
[prompt]$ git log --graph --pretty='commit %h%n%B' abc1234
* commit abc1234
| Title FOO
|
| Full commit message FOO
|
* commit def5678
| Title BAR
|
| Full commit message …Run Code Online (Sandbox Code Playgroud) KdPrint((
"Unknown IoControlCode %#x\n",
io_stack->Parameters.DeviceIoControl.IoControlCode
));
Run Code Online (Sandbox Code Playgroud)
有点奇怪。尖锐的意思是什么?
我有一个int指向另一个地址的指针int。
当使用格式说明符打印指针时%p(如 Stack Overflow 上的许多答案所建议的那样),它以十六进制表示形式打印。
如何用十进制表示打印指针的值?
代码示例
我想出了一个可以%zu从这个答案中使用的人。
int i = 1;
int *p = &i;
printf("Printing p: %%p = %p, %%zu = %zu\n", p, p);
Run Code Online (Sandbox Code Playgroud)
当我使用https://onlinegdb.com/EBienCIJnm运行该代码时
warning: format ‘%zu’ expects argument of type ‘size_t’, but argument 3 has type ‘int *’ [-Wformat=]
Printing p: %p = 0x7ffee623d8c4, %zu = 140732759529668
Run Code Online (Sandbox Code Playgroud)
有没有办法printf使用十进制表示的指针值,而没有编译器警告?