pwntools-level-2.6

1 min read
Objective:
This level requires you to write an assembly code snippet to meet the following condition to bypass the check, and use the asm API from pwntools to compile the assembly code and complete the challenge. The condition for this challenge is:
Write a `for` loop to calculate a specific formula.(refer to the `trace` method of the `ASMChallenge` class)
In short: We have to write asm that do sum from 1 to rcx
Core Code:
def trace(self):
self.start()
return self.rax == sum(range(self.init_rcx + 1))
Solution Code:
from pwn import *
context.arch = "amd64"
context.os = "linux"
context.log_level = "debug"
binary = "/challenge/pwntools-tutorials-level2.6"
p = process(binary)
payload = asm("""
mov rax, rcx
inc rcx
imul rax, rcx
shr rax, 1
""")
p.sendafter(b"Please give me your assembly in bytes", payload)
print(p.recvall().decode())
I directly used sum of natural number formuale for it.
mov rax, rcx ; rax = rcx
inc rax ; rax = rcx + 1
imul rax, rcx ; rax = rcx * (rcx + 1)
shr rax, 1 ; rax /= 2
Flag:
0
Subscribe to my newsletter
Read articles from Sangharsha directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Sangharsha
Sangharsha
Aspiring developer and security enthusiast.