Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. extern puts
  3. extern printf
  4.  
  5. section .data
  6. filename: db "/home/cami/Anul2/IOCLA/Tema2/iocla-tema2-resurse/input.dat",0
  7. inputlen: dd 2263
  8. fmtstr: db "Key: %d",0xa,0
  9.  
  10.  
  11.  
  12.     print db "strlen('') = %d", 10, 0
  13.  
  14. section .text
  15. global main
  16.  
  17. ; TODO: define functions and helper functions
  18. xor_strings:
  19.     push ebp
  20.     mov ebp, esp
  21.    
  22.     xor eax, eax
  23.     xor ebx, ebx
  24.     mov eax, [ebp + 16] ;mesajul
  25.     mov ebx, [ebp + 12] ;cheia
  26.     mov edx, [ebp + 8] ;lungimea
  27.     xor ecx, ecx
  28.          
  29.     push edx
  30.         push print
  31.         call printf
  32.     decode_xor_strings:
  33.         xor ecx, ecx
  34.         mov ecx, [ebx + edx - 1]
  35.         mov eax, [eax + edx - 1]
  36.        
  37.         xor eax, ecx
  38.  
  39.         dec edx
  40.         cmp edx, 0
  41.         jg decode_xor_strings
  42.    
  43.     leave
  44.     ret
  45.    
  46. strlen:
  47.    push ebp
  48.    mov ebp, esp
  49.     xor eax, eax
  50.     cld              
  51.     mov al, 0    
  52.     mov edi,[ebp + 8]
  53.     repne scasb
  54.     sub edi, [ebp + 8]
  55.     dec edi
  56.     mov eax, edi
  57.     leave
  58.     ret
  59.  
  60. main:
  61.     push ebp
  62.     mov ebp, esp
  63.     sub esp, 2300
  64.    
  65.     ; fd = open("/home/cami/Anul2/IOCLA/Tema2/iocla-tema2-resurse/input.dat", O_RDONLY);
  66.     mov eax, 5
  67.     mov ebx, filename
  68.     xor ecx, ecx
  69.     xor edx, edx
  70.     int 0x80
  71.    
  72.     ; read(fd, ebp-2300, inputlen);
  73.     mov ebx, eax
  74.     mov eax, 3
  75.     lea ecx, [ebp-2300]
  76.     mov edx, [inputlen]
  77.     int 0x80
  78.  
  79.     ; close(fd);
  80.     mov eax, 6
  81.     int 0x80
  82.  
  83.         xor edx, edx
  84.     ; all input.dat contents are now in ecx (address on stack)
  85.  
  86.     ; TASK 1: Simple XOR between two byte streams
  87.     ; TODO: compute addresses on stack for str1 and str2
  88.     ; TODO: XOR them byte by byte
  89.        
  90.  
  91.         push ecx
  92.         call strlen
  93.         add esp, 4
  94.  
  95.         add edx, eax
  96.    
  97.         push ecx ;mesajul
  98.         lea ecx, [ecx + edx + 1]
  99.        
  100.        
  101.         add esp, 8
  102.         push ecx ;cheia
  103.         push edx ;lungimea mesajului
  104.  
  105.        ; add edx, eax ;pozitia curenta
  106.        ; add edx, 2
  107.        ; xor eax, eax
  108.        
  109.         call xor_strings
  110.        
  111.         add esp, 12
  112.        
  113.  
  114.        ;push eax
  115.        ;call puts
  116.        ;add esp, 4
  117.  
  118.        
  119.     ;push addr_str2
  120.     ;push addr_str1
  121.     ;call xor_strings
  122.     ;add esp, 8
  123.  
  124.     ; Print the first resulting string
  125.     ;push addr_str1
  126.     ;call puts
  127.     ;add esp, 4
  128.  
  129.     ; TASK 2: Rolling XOR
  130.     ; TODO: compute address on stack for str3
  131.     ; TODO: implement and apply rolling_xor function
  132.     ;push addr_str3
  133.     ;call rolling_xor
  134.     ;add esp, 4
  135.  
  136.     ; Print the second resulting string
  137.     ;push addr_str3
  138.     ;call puts
  139.     ;add esp, 4
  140.  
  141.    
  142.     ; TASK 3: XORing strings represented as hex strings
  143.     ; TODO: compute addresses on stack for strings 4 and 5
  144.     ; TODO: implement and apply xor_hex_strings
  145.     ;push addr_str5
  146.     ;push addr_str4
  147.     ;call xor_hex_strings
  148.     ;add esp, 8
  149.  
  150.     ; Print the third string
  151.     ;push addr_str4
  152.     ;call puts
  153.     ;add esp, 4
  154.    
  155.     ; TASK 4: decoding a base32-encoded string
  156.     ; TODO: compute address on stack for string 6
  157.     ; TODO: implement and apply base32decode
  158.     ;push addr_str6
  159.     ;call base32decode
  160.     ;add esp, 4
  161.  
  162.     ; Print the fourth string
  163.     ;push addr_str6
  164.     ;call puts
  165.     ;add esp, 4
  166.  
  167.     ; TASK 5: Find the single-byte key used in a XOR encoding
  168.     ; TODO: determine address on stack for string 7
  169.     ; TODO: implement and apply bruteforce_singlebyte_xor
  170.     ;push key_addr
  171.     ;push addr_str7
  172.     ;call bruteforce_singlebyte_xor
  173.     ;add esp, 8
  174.  
  175.     ; Print the fifth string and the found key value
  176.     ;push addr_str7
  177.     ;call puts
  178.     ;add esp, 4
  179.  
  180.     ;push keyvalue
  181.     ;push fmtstr
  182.     ;call printf
  183.     ;add esp, 8
  184.  
  185.     ; TASK 6: Break substitution cipher
  186.     ; TODO: determine address on stack for string 8
  187.     ; TODO: implement break_substitution
  188.     ;push substitution_table_addr
  189.     ;push addr_str8
  190.     ;call break_substitution
  191.     ;add esp, 8
  192.  
  193.     ; Print final solution (after some trial and error)
  194.     ;push addr_str8
  195.     ;call puts
  196.     ;add esp, 4
  197.  
  198.     ; Print substitution table
  199.     ;push substitution_table_addr
  200.     ;call puts
  201.     ;add esp, 4
  202.  
  203.     ; Phew, finally done
  204.     xor eax, eax
  205.     leave
  206.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement