Skip to content

Instantly share code, notes, and snippets.

@ammarfaizi2
Created May 5, 2025 05:38
Show Gist options
  • Save ammarfaizi2/9351fdacc366f3c3286f0fb4e0749dba to your computer and use it in GitHub Desktop.
Save ammarfaizi2/9351fdacc366f3c3286f0fb4e0749dba to your computer and use it in GitHub Desktop.
.section .rodata
msg_enter_pwd:
.string "Enter password: "
msg_pwd_wrong:
.string "Sorry, wrong password!"
msg_pwd_ok:
.string "\nPassword OK!"
msg_fmt_flag:
.string "Congratulations, you solved it!\nThe flag is: %s\n"
.section .data
encrypted_pwd:
.byte 0x32, 0x6a, 0xf, 0x6, 0x6a, 0x74, 0x27, 0x37, 0x2d, 0x24, 0xb, 0x14, 0x11, 0x2c, 0x11, 0x75, 0x3f, 0x28, 0x2e, 0x72, 0x3, 0x7c, 0x2e, 0x17, 0x1f, 0x7d, 0x71, 0x7c, 0x13, 0x8, 0x28, 0x23, 0x22, 0x12, 0x35, 0x24, 0x3, 0x2d, 0xf, 0x15, 0x74, 0x7d, 0x2d, 0x20, 0x3f, 0x7d, 0x36, 0x37, 0x31, 0x76, 0x2e, 0x24, 0x28, 0x1, 0x9, 0xd, 0x34, 0x3, 0x1f, 0x6e, 0x6a, 0x2a, 0x73, 0xf, 0x75, 0x36, 0xd, 0x2a, 0x10
encrypted_pwd_end:
encrypted_flag:
.byte 0x30, 0x61, 0x1f, 0x14, 0x6a, 0x74, 0x20, 0x9, 0xe, 0x3, 0x7f, 0x34, 0x32, 0x5b, 0x64, 0x7, 0x42, 0xb, 0x5b, 0x56, 0x25, 0x5a, 0x5c, 0x6a, 0x6e, 0xa, 0x57, 0x1, 0x34, 0x78, 0xb, 0x5f, 0x5e, 0x63, 0x43, 0x58, 0x77, 0xd, 0x2c, 0x64, 0x6, 0xa, 0x50, 0x3, 0x49, 0x5e, 0x47, 0x47, 0x47, 0xb, 0xf, 0x55, 0xc, 0x76, 0x78, 0x2a, 0x44, 0x25, 0x3f, 0x1f, 0x19, 0x9, 0x1, 0x2f, 0x9, 0x41, 0x7c, 0x57, 0x28
encrypted_flag_end:
padding:
.long 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.section .text
.global main
.extern printf
.extern puts
.extern fgets
.extern stdin
main:
pushq %rbp
movq %rsp, %rbp
subq $(16 * 100), %rsp
leaq msg_enter_pwd(%rip), %rdi
xorl %eax, %eax
call printf
xorl %eax, %eax
leaq -200(%rbp), %rdi
movl $25, %ecx
rep stosq
leaq -200(%rbp), %rdi
movl $200, %esi
movq stdin(%rip), %rdx
callq fgets
leaq -200(%rbp), %rdi
callq handle_pwd
testb %al, %al
jz 1f
leaq msg_pwd_ok(%rip), %rdi
callq puts
leaq msg_fmt_flag(%rip), %rdi
leaq encrypted_flag(%rip), %rsi
xorl %eax, %eax
callq printf
jmp 2f
1:
leaq msg_pwd_wrong(%rip), %rdi
callq puts
2:
xorl %eax, %eax
movq %rbp, %rsp
popq %rbp
retq
handle_pwd:
pushq %rbp
movq %rsp, %rbp
subq $32, %rsp
movq %rdi, -8(%rbp)
callq strlen
movq %rax, -16(%rbp)
movq -8(%rbp), %rdi
cmpb $'\n', -1(%rdi, %rax)
jne 2f
movb $0, -1(%rdi, %rax)
decq %rax
2:
movq %rax, -24(%rbp)
movq %rax, %rcx
leaq encrypted_pwd(%rip), %rdx
1:
xorb %al, -1(%rdx, %rcx)
decq %rcx
jnz 1b
movq -24(%rbp), %rcx
movq -8(%rbp), %rdi
leaq encrypted_pwd(%rip), %rdx
leaq encrypted_flag(%rip), %rsi
3:
movb -1(%rdi, %rcx), %al
cmpb -1(%rdx, %rcx), %al
jne .Lret_wrong
xorb %al, -1(%rsi, %rcx)
decq %rcx
jnz 3b
movl $1, %eax
jmp .Lret
.Lret_wrong:
xorl %eax, %eax
.Lret:
movq %rbp, %rsp
popq %rbp
retq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment