2-way authentication reflection attack
#include<conio.h>
#include<stdio.h>
struct A
{
int shared_key;
int response;
int response_got;
int Ra;
int Ra1;
int challenge;
}A;
struct B
{
int shared_key;
int response_got;
int response;
int challenge;
}B;
void main()
{
int i;
int ch,ch1;
int session1[2],session2[2];
clrscr();
A.shared_key=accept_shared_key();
B.shared_key=A.shared_key;
printf("\n want to send request (1.Yes/2.No) :: ");
scanf("%d",&ch);
if(ch==1)
{
delay(1000);
printf("\n Is receiver ready to communicate (1.Yes/2.No) :: ");
scanf("%d",&ch1);
//msg3
A.challenge=random_number();
A.Ra=A.challenge;
B.challenge=A.challenge;//msg3
session1[0]=B.challenge;//store Ra
//Trudy communicate with Alice
//session 1
A.challenge=session1[0];//msg4
delay(1000);
printf("\n Trudy send the same challenge as new challenge received in previous session on the place on response the that session.");
B.response_got=A.challenge+A.shared_key;//msg5
session1[1]=B.response_got;//save Kab[Ra]
A.challenge=random_number();
B.challenge=A.challenge;//msg6
//new session i.e. session 2
B.response=session1[1];
A.response_got=B.response;//msg7
if(A.Ra==A.response_got-A.shared_key)
{
delay(1000);
printf("\n Trudy has sent the right response to Alice using session-2");
}
else
{
printf("\n communication aborted!!!");
goto exit;
}
B.challenge=random_number();
A.challenge=B.challenge;//msg8
delay(1000);
printf("\n Trudy has sent the same challenge which she got in previous session. ");
A.response=A.shared_key+A.challenge;//msg9
B.response=A.response;//same as msg9
//session 1
A.response_got=B.response;
delay(1000);
printf("\n Trudy has successfully establishes the connection with use of 2-session.");
}
else
{
printf("\n communication abored!!!");
}
exit:
getch();
}
int accept_shared_key()
{
int a;
printf("\n enter the shared key :: ");
scanf("%d",&a);
return (a);
}
int random_number()
{
int a;
a=rand()%10;
return (a);
}
OUTPUT;
enter the shared key :: 4
want to send request (1.Yes/2.No) :: 1
Is receiver ready to communicate (1.Yes/2.No) :: 1
Trudy send the same challenge as new challenge received in previous session on
the place on response the that session.
Trudy has sent the right response to Alice using session-2
Trudy has sent the same challenge which she got in previous session.
Trudy has successfully establishes the connection with use of 2-session.