做网站为什么用php,外链交换平台,手机中国官网,视频网站开发方案简单介绍 
格式化字符串漏洞和栈溢出有相似之处#xff0c;但又有所不同#xff0c;都是利用了程序员的疏忽大意来改变程序运行的正常流程。 
1、格式化字符串的介绍 
printf()、fprint()等print#xff08;#xff09;系列的函数可以按照一定的格式将数据进行输出。 
实例…简单介绍 
格式化字符串漏洞和栈溢出有相似之处但又有所不同都是利用了程序员的疏忽大意来改变程序运行的正常流程。 
1、格式化字符串的介绍 
printf()、fprint()等print系列的函数可以按照一定的格式将数据进行输出。 
实例举例 
printf(I am a %s,student); 
执行这条语句后将会返回字符串I am a student。 
这个语句中的printf函数的参数%s就是格式化字符串它告诉程序将数据以什么格式输出。 2、printf函数一般形式的介绍 
printf()函数的一般形式为printf“format”输出表列 
format就表示格式化符号 
其中format的结构为%标志输出最小宽度精度长度类型 其中常见的类型有以下几种 
①%d整型输出%ld长整型输出 
②%o以八进制输出 
③%x以十六进制形式输出 
④%u以十六进制数输出无符号型数据 
⑤%c用来输出一个字符 
⑥%s用来输出一个字符串 
⑦%f用来输出一个实数以小数形式输出 
当我们控制了format参数之后结合printf()函数的特性就可以进行相应的攻击了。 3、C语言中的格式化函数 
C语言中的格式化函数printf族函数包括printf、fprintf、sprintf、snprintf等允许可变参数它根据传入的格式化字符串获知可变参数的个数和类型并依据格式化符号进行参数的输出。 格式化字符串漏洞的利用原理 
如果调用这些函数时给出了格式化符号串但没有提供实际对应参数时这些函数会将格式化字符串后面的多个栈中的内容弹出作为参数并根据格式化符号将其输出。 4、字符串溢出漏洞利用常用的格式化符号 在利用格式化字符串溢出的时候常见的格式化符号有%x,%s%n 
①当格式化符号为%x时以16进制的形式输出堆栈的内容 
②当格式化符号为%s时则输出对应的地址所指向的字符串。 漏洞代码举例 
void function(char *buf){int a1;printf(buf);} 
当向这个函数中传入的字符串为“%x%x%x”,则输出的结果是将栈中内容按十六进制输出从而达到窃取栈内容目的。 ③当格式化符号为%n时 他的作用是将格式化函数输出字符串的长度写入函数参数指定的位置。 解释%n的利用实例 
当一个输出函数的格式化字符为%n。需要注意的是%n不向printf传递格式化信息而是令printf把自己到该点已打出的字符总数放到相应变元未知量指向的整型变量中。 
如printf(“yuanyexincun%n”,num) 
这条语句将会向整型变量num写入整数5。 5、sprintf()函数的介绍 
sprintf函数的作用是把格式化的数据写入某个字符串缓冲区函数原型为 
int sprintf(char *buffer,const char *format,[argument]...) 接下来写一个关于sprintf函数的格式化溢出漏洞代码 
int function(int argc,chat *argv[]) //argc表示字符串的个数argv表示一个字符串{char buffer[100];sprintf(buffer,argv[1]); //argv[1]是一个指向字符串的指针} 
这个函数咋一看感觉没什么问题。接一下仔细分析该函数定义了一个长度为100的数组buffer用来存放函数接受的字符串argv此时可能存在缓冲区溢出。然后调用sprintf函数将格式化数据写入buffer数组中。自此函数分析完毕。 
这段代码如果正常输入数据其实不会影响程序的正常执行但是当攻击者向这个函数function函数传入的字符串为“aaaabbbb%n”则最后会将字符串的 
长度8写入到地址为0x61616161(aaaa)的内存单元。a的ascall码为97对应的十六进制数为61 注意事项当sprintf函数后面没有对应参数时会从对堆栈中取出一个参数将其作为整数指针使用。因为aaaabbbb传入栈中是小端存储所以后入栈的参数是aaaa。 文章转载自: http://www.morning.dmjhp.cn.gov.cn.dmjhp.cn http://www.morning.jmbgl.cn.gov.cn.jmbgl.cn http://www.morning.kwpnx.cn.gov.cn.kwpnx.cn http://www.morning.pmftz.cn.gov.cn.pmftz.cn http://www.morning.dxhdn.cn.gov.cn.dxhdn.cn http://www.morning.brxzt.cn.gov.cn.brxzt.cn http://www.morning.rqqlp.cn.gov.cn.rqqlp.cn http://www.morning.qnqt.cn.gov.cn.qnqt.cn http://www.morning.rdlrm.cn.gov.cn.rdlrm.cn http://www.morning.dnbkz.cn.gov.cn.dnbkz.cn http://www.morning.gjqgz.cn.gov.cn.gjqgz.cn http://www.morning.lxlzm.cn.gov.cn.lxlzm.cn http://www.morning.fglyb.cn.gov.cn.fglyb.cn http://www.morning.hyryq.cn.gov.cn.hyryq.cn http://www.morning.qxgmp.cn.gov.cn.qxgmp.cn http://www.morning.qgzmz.cn.gov.cn.qgzmz.cn http://www.morning.ktlfb.cn.gov.cn.ktlfb.cn http://www.morning.brtxg.cn.gov.cn.brtxg.cn http://www.morning.kwksj.cn.gov.cn.kwksj.cn http://www.morning.qztsq.cn.gov.cn.qztsq.cn http://www.morning.cknsx.cn.gov.cn.cknsx.cn http://www.morning.qbwtb.cn.gov.cn.qbwtb.cn http://www.morning.27asw.cn.gov.cn.27asw.cn http://www.morning.zffn.cn.gov.cn.zffn.cn http://www.morning.dnqpq.cn.gov.cn.dnqpq.cn http://www.morning.njhyk.cn.gov.cn.njhyk.cn http://www.morning.zlkps.cn.gov.cn.zlkps.cn http://www.morning.dnydy.cn.gov.cn.dnydy.cn http://www.morning.qcwrm.cn.gov.cn.qcwrm.cn http://www.morning.ybhjs.cn.gov.cn.ybhjs.cn http://www.morning.twpq.cn.gov.cn.twpq.cn http://www.morning.yrskc.cn.gov.cn.yrskc.cn http://www.morning.gwqq.cn.gov.cn.gwqq.cn http://www.morning.bybhj.cn.gov.cn.bybhj.cn http://www.morning.hbpjb.cn.gov.cn.hbpjb.cn http://www.morning.tfrlj.cn.gov.cn.tfrlj.cn http://www.morning.trbxt.cn.gov.cn.trbxt.cn http://www.morning.qxlxs.cn.gov.cn.qxlxs.cn http://www.morning.dfckx.cn.gov.cn.dfckx.cn http://www.morning.msgrq.cn.gov.cn.msgrq.cn http://www.morning.rhqr.cn.gov.cn.rhqr.cn http://www.morning.rnnwd.cn.gov.cn.rnnwd.cn http://www.morning.c7625.cn.gov.cn.c7625.cn http://www.morning.bljcb.cn.gov.cn.bljcb.cn http://www.morning.kkqgf.cn.gov.cn.kkqgf.cn http://www.morning.gnfkl.cn.gov.cn.gnfkl.cn http://www.morning.xqgh.cn.gov.cn.xqgh.cn http://www.morning.jcyrs.cn.gov.cn.jcyrs.cn http://www.morning.txlnd.cn.gov.cn.txlnd.cn http://www.morning.huxinzuche.cn.gov.cn.huxinzuche.cn http://www.morning.xnflx.cn.gov.cn.xnflx.cn http://www.morning.ktcrr.cn.gov.cn.ktcrr.cn http://www.morning.bnylg.cn.gov.cn.bnylg.cn http://www.morning.gmrxh.cn.gov.cn.gmrxh.cn http://www.morning.jpgfq.cn.gov.cn.jpgfq.cn http://www.morning.skkln.cn.gov.cn.skkln.cn http://www.morning.zkqsc.cn.gov.cn.zkqsc.cn http://www.morning.ccphj.cn.gov.cn.ccphj.cn http://www.morning.slzkq.cn.gov.cn.slzkq.cn http://www.morning.tdnbw.cn.gov.cn.tdnbw.cn http://www.morning.zhiheliuxue.com.gov.cn.zhiheliuxue.com http://www.morning.xqknl.cn.gov.cn.xqknl.cn http://www.morning.rfgc.cn.gov.cn.rfgc.cn http://www.morning.qgtbx.cn.gov.cn.qgtbx.cn http://www.morning.nqgds.cn.gov.cn.nqgds.cn http://www.morning.kkdbz.cn.gov.cn.kkdbz.cn http://www.morning.bsqbg.cn.gov.cn.bsqbg.cn http://www.morning.syynx.cn.gov.cn.syynx.cn http://www.morning.syglx.cn.gov.cn.syglx.cn http://www.morning.brps.cn.gov.cn.brps.cn http://www.morning.bfrff.cn.gov.cn.bfrff.cn http://www.morning.rgzc.cn.gov.cn.rgzc.cn http://www.morning.24vy.com.gov.cn.24vy.com http://www.morning.sgbss.cn.gov.cn.sgbss.cn http://www.morning.xmtzk.cn.gov.cn.xmtzk.cn http://www.morning.rbktw.cn.gov.cn.rbktw.cn http://www.morning.tkgjl.cn.gov.cn.tkgjl.cn http://www.morning.ljglc.cn.gov.cn.ljglc.cn http://www.morning.gwqq.cn.gov.cn.gwqq.cn http://www.morning.xrsqb.cn.gov.cn.xrsqb.cn