一些二进制学习笔记和题目WP
一、查看文件类型PE32 无壳二、HOOK原理1.什么是hook(钩子)对于Windows系统,它是建立在事件驱动机制上的,说白了就是整个系统都是通过消息传递实现的。hook(钩子)是一种特殊的消息处理机制,它可以监视系统或者进程中的各种事件消息,截获发往目标窗口的消息并进行处理。所以说,我们可以在系统中自定义钩子,用来监视系统中特定事件的发生,完成特定功能,如屏幕取词,监视日志,截获键盘、鼠标输入等等。 钩子的种类很多,每种钩子可以截获相应的消息,如键盘钩子可以截获键盘消息,外壳钩子可以截取、启动和关闭应用程序的消息等。钩子可以分为线程钩子和系统钩子,线程钩子可以监视指定线程的事件消息,系统钩子监视系统中的所有线程的事件消息。因为系统钩子会影响系统中所有的应用程序,所以钩子函数必须放在独立的动态链接库(DLL) 中。 所以说,hook(钩子)就是一个Windows消息的拦截机制,可以拦截单个进程的消息(线程钩子),也可以拦截所有进程的消息(系统钩子),也可以对拦截的消息进行自定义的处理。Windows消息带了一些程序有用的信息,比如Mouse类信息,就带有鼠标所在窗体句柄、鼠标位置
从题目中可以看出,本题应该是一个没有提供system函数地址的栈溢出题目,那么我们本题的考点应该是从libc中提取system函数地址。照例检查保护机制root@mypwn:/ctf/work/python# checksec level3 [*] '/ctf/work/python/level3'Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8048000)只是开启了NX,那就没错了,可以执行栈溢出。打开ida看下反编译c语言代码:int __cdecl main(int argc, const char **argv, const char **envp) { vulnerable_function(); write(1, "Hello, World!\n", 0xEu); return 0; } ssize_t vulnerable_function() {
1.查看文件保护64位,开启了NX(数据不可执行)、Canary(栈保护)和Full RELRO(无法修改GOT表)运行程序图画之后的提示中有两个secretsecret[0] is 12b32a0secret[1] is 12b32a4用户输入名字后,出现一大段故事,接着有两次选择:(1)east or up?选up后会让用户重新选择,所以只能选east(2)选east后:there(1)or leave(0)?输入0选择leave,则程序输出一段字符后程序退出输入1后程序提示用户输入一个地址和一个愿望,接着程序输出一段字符后退出2.IDA静态分析(1)main程序逻辑分析:1)启动计时器后执行sub_400996,接着定义数组v4,且v4[0]=68,v4[1]=852)第13、14行给出的secret是v4[0](68)和v4[1](85)的地址3)输出一系列字符串后执行sub_400D72(2)sub_400996输出off_603010,跟进后发现为asc_400F98,内容为龙的图画(3)sub_400D72判断角色名长度小于0x28,执行之后三个函数1)sub_400A7
1.查看文件保护32位,只开启了NX(数据不可执行)kali中运行程序一个留言板程序,用户可以输出名字和一条信息。2.IDA静态分析(1)main(2)hello第29行fgets接收用户输入到变量name中,双击跟进发现其在.bss段,地址为0804A080函数末尾发现gets()函数,并且数组s与ebp的位移为0x26,因此写0x26+4个字节后即可覆盖返回地址(3)查看字符串窗口没有发现/bin/sh字符串,但是左侧函数窗口中有system函数,地址为08048420还找到一个pwn函数,执行系统命令输出字符串,由此得call __system地址为0804855A因此构造一个/bin/sh作为system执行的参数即可getshell(4)思路整理利用fgets函数溢出后返回地址修改成system()函数,内容用/bin/sh覆盖EXP代码如下:from pwn import * p = remote('61.147.171.105', 63915) payload=b'a'*(0x26+4)+p32(0x0804855A)+p32(0x0804A080) # 或者是直接调
1.查看文件保护题目名提示为整数溢出ELF32 开启了NX(数据不可执行)运行程序欢迎提示后是一个选项,选1则要求输入名字和密码,判断后输出提示,退出程序;选2则直接退出程序2.IDA静态分析(1)main较为简单的程序逻辑:选1后执行login()(2)login()接收长度为0x19的username并在Hello中输出再接收一个为0x199的passwd返回中执行check_passwd()跟进check_passwd()passwd长度为3-7时提示成功,在范围之外提示失败,并且在输出提示后清空输出缓冲区,最后执行strcpy将passwd复制给dest并返回用来存储passwd的变量v3类型为无符号的int8,范围为[0,255],超出255就会发生整数溢出,而程序读入passwd输入时,大小为0x199,远远超出此范围,因此可以利用。(3)查看字符串窗口看到关键字符cat flag跟进并查看交叉引用找到一个what_is_this()函数,其内容为执行系统命令输出flag内容,其地址为0804868B(4)思路整理构建一个指定长度的串,传入函数,整数溢出突破if函数的判断,
Norman1z