Description

File: https://mercury.picoctf.net/static/56a2cea908a525745578feff8b94719f/chall_1.S

Steps

  1. Tương tự ARMssembly 0, ta cần phải đọc code hợp ngữ của file chall_1.S.
  2. Đọc luồng thực thi của hàm func, viết chú giải cho từng dòng lệnh, ta được đoạn code sau đây:
func:
	sub	sp, sp, #32
	str	w0, [sp, 12] # store w0 (may be arg) at *(sp+12)
	mov	w0, 85	     # w0 = 85
	str	w0, [sp, 16] # store 85 at *(sp+16)
	mov	w0, 6  	 	 # w0 = 6
	str	w0, [sp, 20] # store 6 at *(sp+20)
	mov	w0, 3		 # w0 = 3
	str	w0, [sp, 24] # store 3 at *(sp+24)
	ldr	w0, [sp, 20] # load 6 to w0
	ldr	w1, [sp, 16] # load 85 to w1
	lsl	w0, w1, w0   # shift left 85 for 6 (= 5440)
	str	w0, [sp, 28] # store 5440 at *(sp+28)
	ldr	w1, [sp, 28] # load 5440 to w1
	ldr	w0, [sp, 24] # load 3 to w0
	sdiv w0, w1, w0  # w0 = 5440 / 3 = 1813
	str	w0, [sp, 28] # store 1813 at *(sp+28)
	ldr	w1, [sp, 28] # load 1813 to w1
	ldr	w0, [sp, 12] # load arg to w0
	sub	w0, w1, w0   # w0 = 1813 - arg
	str	w0, [sp, 28] # store w0 at *(sp+28)
	ldr	w0, [sp, 28] # load 1813 - arg to w0
	add	sp, sp, 32
	ret
  1. Đọc đoạn code thực thi của hàm main, thấy có dòng lệnh cmp w0 0 có nghĩa là so sánh w00. Ở phía dưới dòng lệnh này là instruction bne .L4 (branch if not equal) và ở trong label .L4 thì chương trình sẽ nhảy đến .L0 để xuất ra You win.
  2. Do đó, ta cần nhập vào arg là một số sao cho 1813 - arg = 0. Nói cách khác, arg sẽ là 1813.
  3. Ta dùng lệnh '{:x}'.format(1813) của Python để tìm ra giá trị hexa và suy ra flag.

Flag

Success

picoCTF{00000715}