Description

File: https://mercury.picoctf.net/static/ae9fdcfd0d281e10893d885eef4ee138/chall_2.S

Steps

  1. Làm tương tự ARMssembly 0ARMssembly 1, ta cũng cần phải đọc code assembly có kiến trúc là ARMv8.
  2. Hàm func giúp khởi tạo các giá trị ban đầu:
func1:
	sub	sp, sp, #32
	str	w0, [sp, 12]  # store w0 (arg = 3848786505) at *(sp+12)
	str	wzr, [sp, 24] # store wzr = 0 at *(sp+24)
	str	wzr, [sp, 28] # store wzr = 0 at *(sp+28)
	b	.L2
  1. Label .L3.L2 có chứa một vòng lặp (theo gợi ý của đề bài):
.L3:
	ldr	w0, [sp, 24] # load 9 to w0
	add	w0, w0, 3    # w0 = 9 + 3 = 12
	str	w0, [sp, 24] # store 12 at *(sp+24)
	ldr	w0, [sp, 28] # load 3 to w0
	add	w0, w0, 1    # w0 = 3 + 1 = 4
	str	w0, [sp, 28] # store 4 at *(sp+28)
.L2:
	ldr	w1, [sp, 28] # load 4 to w1
	ldr	w0, [sp, 12] # load arg to w0
	cmp	w1, w0       # compare w1 and arg, until w1 = arg = 3848786505
	bcc	.L3          # if w0 < w1 then jump to .L3
	ldr	w0, [sp, 24] # when w1 = arg, w0 = 3*w1 = 11546359515
	add	sp, sp, 32 
	ret
	.size	func1, .-func1
	.section	.rodata
	.align	3
  1. Giá trị cuối cùng của w011546359515, chuyển thành hex ta được 2B03776DB. Tuy nhiên, do đề bài yêu cầu chỉ lấy 32 bit, nên kết quả sẽ là B03776DB. Ghép với picoCTF{} ta thu được flag.

Flag

Success

picoCTF{B03776DB}