格式化字符串漏洞(Format String Attack)

简介: 格式化字符串漏洞(Format String Attack)

1999年6月发现并公开的

2000年下半年发现了大量软件受到影响,震惊了安全界

格式化字符串相关函数

fprintf

printf

sprintf

snprintf

vfprintf

vprintf

vsprintf

vsnprintf

setproctitile

syslog

格式化字符串常见语法

%d

%u

%s

%x

%p

控制打印宽度

%<正整数>c

打印宽度为n的字符串

关于%n,%hn,%hhn

%n将当前已打印的个数(4字节)写入参数

%hn写入2字节

%hhn 写入1字节

关于$符号

%<正整数n>$<fmt>

printf("0x%2$x:0x%1$x\n",0xddeadbeef,0xcafebabe);

打印结果:

0xcafebabe:0xddeadbeef

参数不足的情况

如果printf参数不足,会发生什么

会假设这些参数的存在,在对应的寄存器上找到这些参数,并做相应的处理

可以用于泄露栈上的数据

可用于泄露栈上的数据

%d 打印signed int

%u 打印unsigned int

%p 打印指针,极void *

%x 打印hex指针,即void *

用于任意内存泄露

%s 打印参数地址处的字符串

对于不同字长的系统

32位:函数调用时参数在栈,格式化字符可控可以泄露栈上的数据

64位:函数调用使用寄存器+栈:格式化字符可控可以泄露特定寄存器和栈上的值

相关文章
|
10月前
|
SQL 数据库
【YashanDB 知识库】导入数据时报错:YAS-00008 type convert error:literal does not match format string
【YashanDB 知识库】导入数据时报错:YAS-00008 type convert error:literal does not match format string
|
10月前
|
SQL 数据库
【YashanDB知识库】导入数据时报错:YAS-00008 type convert error:literal does not match format string
【YashanDB知识库】导入数据时报错:YAS-00008 type convert error:literal does not match format string
|
索引 Python
技巧 | 5000字超全解析Python三种格式化输出方式【% / format / f-string】
技巧 | 5000字超全解析Python三种格式化输出方式【% / format / f-string】
解决Format string is not a string literal (potentially insecure)问题
在用宏实现部分字符串格式化问题时,stringWithFormat方法会出现【Format string is not a string literal (potentially insecure)】警告
785 0
Python爬取中国最好大学排行榜报错TypeError: unsupported format string passed to NoneType.__format__
Python爬取中国最好大学排行榜报错TypeError: unsupported format string passed to NoneType.__format__
|
Python
Python f-string 风格格式化字符串
f-string 是 python3.6 之后版本添加的,称之为字面量格式化字符串,是新的格式化字符串的语法。 f-string 格式化字符串以 f 开头,后面跟着字符串,字符串中的表达式用大括号 {} 包起来,它会将变量或表达式计算后的值替换进去,实例如下:
318 0
|
Python
Python格式字符串的三种方法你都掌握了吗,%s%d%f+format()+f-string,深度测评YYDS实至名归
Python格式字符串的三种方法你都掌握了吗,%s%d%f+format()+f-string,深度测评YYDS实至名归
310 0
Python格式字符串的三种方法你都掌握了吗,%s%d%f+format()+f-string,深度测评YYDS实至名归
|
Java C# API
MessageFormat对象实现格式化字符串输出,类似C#中的string.format方法
      早在寻找java中类似string .format(str,args...)的方法来格式化字符串,前段时间在网上见过,确信有这种方法,但没有太注意!今天 在写代码中,突然要用到这个功能(方便的多),但一时想不起...
1118 0
用DateTime.ToString(string format)输出不同格式的日期
DateTime.ToString()函数有四个重载。一般用得多的就是不带参数的那个了。殊不知,DateTime.ToString(string format)功能更强大,能输出不同格式的日期。
995 0