2011-06-08 51 views
0

我試圖做一個簡單的小密碼程序(爲了進一步擴展我的知識),我只是無法得到它的工作。問題是即使我輸入正確的密碼,它也不會跳轉到標籤「good」。ASM(at&t系統V 32位異或)

我的驗證密碼的方式是將用戶提交的密碼與內置密碼進行異或,如果它返回0表示它們是相同的。 (因爲任何異或者是0)

所以我的錯誤很可能在cmpl和je命令或我的xoring本身內。任何幫助將是很好,我根本無法找到我的錯誤。

.section .data 

hmm: 
.ascii "Enter the password\n\0" 

password: 
.ascii "abgirl" 

success: 
.ascii "Password is right\n\0" 

bad: 
.ascii "password is wrong\n\0" 

.section .bss 

.equ buffer_size, 500 

.lcomm buffer_data, buffer_size 

.section .text 

.global _start 

_start: 

pushl $hmm 
call printf      #print $hmm 

movl $0, %ebx 
movl $buffer_data, %ecx 
movl $buffer_size, %edx 
movl $3, %eax 
int $0x80      #get user input 

movl $password, %eax 
xorl $buffer_data, %eax   #xor the passwords (value stored in eax) 

cmpl $0, %eax     #compare 
je good       #jump if equal 

pushl $bad 
call printf      #print bad pass if not equal 
jmp end       #jump to exit 

good: 
pushl $success 
call printf      #print $success 

end: 
movl $0, %ebx 
movl $1, %eax 
int $0x80      #cleanup and exit 

回答

1

你的問題是比較。

movl $password, %eax 
xorl $buffer_data, %eax 

美元符號表示您正在處理變量的地址,而不是內容。由於密碼和緩衝區位於不同的位置,所以比較將始終爲假。你想要的是比較密碼和緩衝區中每個位置的字符。爲此,您需要知道密碼的時間。

password: 
.ascii "abgirl\0" 
.set password_len, . - password 

請注意,我還添加了一個空字節您的密碼,這樣,如果輸入的密碼越長,比較會失敗。現在,您需要更改比較來檢查每個字節。

movl $password, %ebx 
    movl $buffer_data, %edx 
    movl $password_len, %ecx 
0: 
    movb (%ebx), %al 
    xorb (%edx), %al 
    jnz bad 
    inc %ebx 
    inc %edx  # Go to next byte 
    dec %ecx 
    jnz 0b 
    jmp good 
+0

非常感謝我得到它與您的幫助。雖然有一種方法來一次完整的密碼,因爲我聽說過超時強制攻擊:如果密碼是「布魯斯」,你可以嘗試「a」需要0.2ms嘗試「b」需要0.4ms,所以你知道b是在通過然後嘗試所有「r」(每個取0.4ms)然後它需要0.6ms,所以你知道r是它的一部分,等等(比喻時間) – abduct 2011-06-08 21:47:53

+0

不,沒有。在剩餘4個字節的情況下,您可以比較長時間,這意味着只有在前4個字符正確時纔會更改時間。您也可以嘗試對其進行編程,以便檢查每個字符,即使第一個字符是錯誤的。 – ughoavgfhw 2011-06-09 00:46:27