第三章 系統設計與實作
3.2 Proposed 驗證認證協定演算法
3.2.2 尋找攻擊的目標 Item( 重要的 Item )
在我們想好驗證認證協定演算法的設計概念之後,接著就開始設計我們的驗 證認證協定演算法,首先就是要先找出 3.1 節裡提到的攻擊的目標 Item( 重要的 Item )和找出可以利用的資源。只有找好這些資料後才可以來尋找認證協定是否 存在漏洞。
我們先將認證協定裡的每一個 Message、每一個 Item 讀取、parsing 後建成 3.2.1 節中的 Data Structure 並且同時將這些資料一一的串接起來。接下來我們 利用建好的 Structure 根據下面的方法(analyze 和 include 這兩個 function)來尋
找攻擊的目標 Item( 重要的 Item )。
void analyze( Message protocol )
{ /* 參數 protocol 代表建好的認證協定 Message 和 Item 的資料串列 */
int numberOfImportant = 0; //記錄找到多少個重要的 Item Item important; //Item is a linked list;
Item nextItem;
Item item_temp;
Boolean flag = false;
Item itemUsingKab;
Message message_now = protocol;
/* 找出最後一個 Message */
while( message_now.next != null )
message_now = message_now.next;
item_temp = message_now.item;
/* 處理最後一個 Message */
while(item_temp != NULL ) {
if( item_temp is ciphertext ) {
if( item_temp.key is not session key) {
item_temp.important = true;
copy the item_temp to important;
//copy 代表將這個 item 複製到 important(不包含 Structure 裡的 next 欄位)。
numberOfImportant++;
flag = true;
} else
copy item_temp to itemUsingKab;
}
item_temp = item_temp.next;
}
if( flag == true && itemUsingKab != null) {
itemUsingKab.important = true;
copy itemUsingKab to important;
numberOfImportant++;
flag = true;
}
/* 處理倒數第二個到第一個 Message */
while( message_now != protocol ) {
/* 找出前一個 Message */
Message Pre_message = protocol;
if( Pre_message != message_now )
while( Pre_message.next != message_now ) Pre_message = Pre_message.next;
message_now = Pre_message;
nextItem = message_now.next.item;
item_temp = message_now.item;
while( item_temp != NULL ) {
boolean add = false;
if( item_temp is ciphertext ) {
if( item_temp.key is not session key) {
/* 將目前分析的 Message 跟他之後的所有 Message 比對 */
if( nextItem 是目前分析的 Message 的下一個 Message) {
if( include(nextItem, item_temp) == false ) {
item_temp.important = true;
copy the item_temp to important;
//copy 代表將這個 item 複製到 important(不包含 Structure 裡的 next 欄位)。
numberOfImportant++;
add = true;
} }
if( include(nextItem, item_temp) == true ) {
if( the item which include this item_temp is the important item)
{
item_temp.important = true;
copy the item_temp to important;
//copy 代表將這個 item 複製到 important(不包含 Structure 裡的 next 欄位)。
numberOfImportant++;
add = true;
item_temp = item_temp.next;
}
if( flag == false && add == true ) {
itemUsingKab.important = true;
copy itemUsingKab to important;
numberOfImportant++;
flag = true;
} }
if( numberOfImportant == 0 )
The Protocol does not have any encrypted data。
}
Analyze function 的用意就是要找出攻擊的目標 Item( 重要的 Item ),這個 function 會先找到認證協定的最後一個 Message,然後找出這個 Message 中所有
有加密而且用來加密的 key 不是 session key 的 Item,之後將這些 Item 記錄在 important 並同時遞增 numberOfImportant。如果一個 Message 中找到用 session key 加密的 Item,那麼是否要記錄下來?只有當此 Message 中有不是用 session key 加密的 Item 被記錄到 important 裡的時候才要記錄到 important 裡,否則不理會。
接著找出認證協定的倒數第二個 Message,將這個 Message 中所有有加密而 且用來加密的 key 不是 session key 的 Item 找出來,接下來利用 include function 來判斷找到的這些 Item 是否出現在這個 Message 之後的 Message,如果沒有出現 在下一個 Message 中就將 Item 記錄到 important 並同時遞增 numberOfImportant;
如果有出現在下一個 Message 或是在下一個 Message 之後的 Message 中,就要看 這些 Message 中包含這個 Item 的 Item 是否已經被記錄在 important 裡,如果已經 在 important 中,那麼這個 Item 也要記錄在 important 裡並同時遞增
numberOfImportant,如果不在 important 裡,那麼這麼 Item 就不用記錄在 important 中。跟分析最後一個 Message 一樣,找出用 session key 加密的 Item,如果有不 是用 session key 加密的 Item 被記錄到 important 裡,那麼這個 Item 也要記錄到 important 裡。倒數第二個 Message 分析完後就分析倒數第三個然後倒數第四個 一直到第一個 Message 都分析完為止。
最後如果 numberOfImportant 等於 0,那麼就代表這個認證協定沒有任何加 密的資料,因為都沒有加密的 Item,因此可以得知這個認證協定不安全。
boolean include(Item item1, Item item2) {
while(item1!= null ) {
if( item1.content.indexof(item2.content) != -1 )
//判斷是否包含 item2。如果 item1、item2 是密文,那麼 item1.content、item2.content //代表加密的全部資料。
//indexof function 執行字串比對,如果在 item1.content 中找到 item2.content 就會 //回傳在 item1.content 的位置,如果找不到就回傳-1。
return true;
item1= item1.next;
}
return false;
}
include function 是用來找出參數 item1 是否包含 item2,包含的意思是指 item1 的 content 中有 item2 的 content 存在(item1 的內容和 item2 的內容是一樣的或 item2 的內容是 item1 的內容的一部分)。在這個 function 中要注意的地方:如果 item1、item2 是明文,那麼 if( item1.content.indexof(item2.content) != -1 ) 這個判 斷式中的 item1.content、item2.content 很明顯指的就是儲存在 Structure Item 裡面 的 content 變數中的值;但是如果 item1、item2 是密文,那麼 item1.content、
item2.content 指的就是 item1、item2 的全部資料,雖然這時候 item1.content、
item2.content 儲存的資料是 NULL(ex: 如果 item1 代表的資料內容是{A, Na, {Nb}Kbs}Kas,那麼判斷式裡的 item1.content 指的意義是{A, Na, {Nb}Kbs}Kas,
雖然實際內容儲存的是 NULL,item2 也是如此)。
z Forward:第一類就是 Forward,顧名思義就是從某一個參與者中收到某個 Item 之後,不對它做任何處理而直接將它夾雜在之後的訊息中傳遞給其它參
與者。
z Produce:第二類就是 Produce,顧名思義就是某個 Item 是由參與者根據收 到的資料、或是因為一開始要送出什麼資料所產生出來要傳遞給其它參與者 Item )。而這也是我們在 analyze function 中要從最後一個 Message 分析到第一個 Message 的原因,因為只有這樣才可以找出 Item Produce 之後卻被接收的參與者 做 Forward 的動作。 者已經成功交換 session key,那麼我們攻擊這個用 session key 加密的 item
是沒用的(請記得我們只探討認證協定邏輯上的缺陷,而不探討加解密演算 法的缺陷),但是我們發現用 session key 加密的 Item 有一種情況也是被用來 確認身分的 Item,這種情況是當某個參與者收到資料取得 session key 之後,
會用 session key 加密一個亂數或是其他資料傳送給對方,以此來確認對方真 的擁有這個 session key,所以這種情況的 Item 也要記錄下來。
z 第二個是找出沒有出現在下一個 Message 中有加密而且加密的 key 不是 session key 的 Item。(也就是 Produce 的情況):
z 第三個是找出有出現在下一個 Message 中有加密的 Item,而且下一個 Message 中包含這個 Item 的 Item 是攻擊的目標 Item( 重要的 Item )。(也就 是 Produce 但卻被接收的參與者做 Forward 的動作的情況下)