Guest User

mitm check

a guest
Jun 6th, 2011
162
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6.  
  7. main() {
  8.  
  9. unsigned char pka[5] = {"AAAA"};
  10. unsigned char pkm[5] = {"CCCC"};
  11. unsigned char pkb[5] = {"BBBB"};
  12.  
  13. unsigned char ka[5] = {"KKKK"};
  14. unsigned char km[5] = {"MMMM"};
  15. unsigned char kb[5] = {"LLLL"};
  16.  
  17. unsigned char pac[5];
  18.  
  19. unsigned int i=0;
  20. unsigned char start=0x00;
  21.  
  22. unsigned char an,bn,tempya,tempyb;
  23. unsigned char temp[5];
  24.  
  25.  
  26. memcpy(pac,pka,sizeof(pac));
  27. printf("Alice send packet to Bob %s\n",pac);
  28.  
  29.  
  30. memcpy(pac,pkm,sizeof(pac));
  31. printf("MITM changes packet and forwards it to Bob %s\n",pac);
  32.  
  33.  
  34. printf("Bob creates number\n");
  35. start = pac[0];
  36. for(i=0;i<0xff;i++) {
  37. start = start^i;
  38. if(start == kb[0]) {
  39. printf("Bob found number to use %2X\n",i);
  40. bn=i;
  41. goto skip;
  42. }
  43. }
  44. skip:
  45. memcpy(pac,pkb,sizeof(pac));
  46. printf("Bob sends packet to Alice %s\n",pac);
  47.  
  48. memcpy(pac,pkm,sizeof(pac));
  49. printf("MITM changes packet and forwards it to Alice %s\n",pac);
  50.  
  51. printf("Alice creates number\n");
  52. start = pac[0];
  53. for(i=0;i<0xff;i++) {
  54. start = start^i;
  55. if(start == ka[0]) {
  56. printf("Alice found number to use %2X\n",i);
  57. an=i;
  58. goto skip1;
  59. }
  60. }
  61. skip1:
  62.  
  63. memcpy(pac,ka,sizeof(pac));
  64. printf("Alice sends key to Bob %s\n",pac);
  65.  
  66. memcpy(pac,km,sizeof(pac));
  67. printf("MITM changes packet and forwards it to Bob %s as its key\n",pac);
  68.  
  69.  
  70. printf("Bob modfies packet to Alice using mitm key\n");
  71. start = pac[0];
  72. for(i=0;i<0xff;i++) {
  73. start = start^i;
  74. if(start == pkm[0]) {
  75. printf("bob modfied to %2X, using mitm instead of alice\n",i);
  76. tempyb=i;
  77. goto skip2;
  78. }
  79. }
  80. skip2:
  81.  
  82. temp[0] = kb[0]^tempyb;
  83. temp[1] = kb[1]^tempyb;
  84. temp[2] = kb[2]^tempyb;
  85. temp[3] = kb[3]^tempyb;
  86. memcpy(pac,temp,sizeof(pac));
  87. printf("Bob sends key to Alice %s \n",pac);
  88.  
  89. memcpy(pac,km,sizeof(pac));
  90. printf("MITM changes packet and forwards it to Bob %s as its key\n",pac);
  91.  
  92. printf("Alice modfies packet to Bob using mitm key\n");
  93. start = pac[0];
  94. for(i=0;i<0xff;i++) {
  95. start = start^i;
  96. if(start == pkm[0]) {
  97. printf("alice modfied to %2X using mitm key instead of bobs\n",i);
  98. tempya=i;
  99. goto skip3;
  100. }
  101. }
  102. skip3:
  103. temp[0] = ka[0]^tempya;
  104. temp[1] = ka[1]^tempya;
  105. temp[2] = ka[2]^tempya;
  106. temp[3] = ka[3]^tempya;
  107. memcpy(pac,temp,sizeof(pac));
  108. printf("Alice sends packet to BOB %s\n",pac);
  109.  
  110.  
  111. printf("MITM changes packet to something..ENTER DATA(4 chars :)\n");
  112. gets(pac);
  113.  
  114. printf("Bob trys to decode it\n");
  115. start = pac[0];
  116. for(i=0;i<tempyb;i++) {
  117. start = start^i;
  118. }
  119. printf("Hash check = %2X instead of %2X(bob) %2X(Alice)\n",start,tempyb,tempya);
  120.  
  121.  
  122.  
  123.  
  124. exit(1);
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141. }
RAW Paste Data