Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Polimorfni kod

[es] :: Zaštita :: Polimorfni kod

[ Pregleda: 2510 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Vojislav Milunovic

Član broj: 25
Poruke: 2117
*.verat.net



+1 Profil

icon Polimorfni kod 30.06.2001. u 21:43 - pre 277 meseci
Da li se neko petljao sa ovim?
Ja pokusavam nesto da uradim na tu temu pa cim uradim saljem kod u C ;o) (ako zavrsim)
 
Odgovor na temu

Vojislav Milunovic

Član broj: 25
Poruke: 2117
*.verat.net



+1 Profil

icon Re: Polimorfni kod 30.06.2001. u 22:47 - pre 277 meseci
Code:

#include<sys/types.h>
#include<sys/stat.h>
#include<sys/mman.h>
#include<elf.h>
#include<unistd.h>
#include<fcntl.h>
#include<stdlib.h>

/*
 * Polymorph code ;o)
 */
char call[] ="xe8x00x00x00x00";
char nop[]  ="x90x90x90x90x90";
char jmp[]  ="x90x90x90xebx00";

[blue]#define MAGIC_CODE 321[/blue]

char *code[]={call,nop,jmp,NULL};

int main(int argc,char **argv){
 int fd,fd1,i,text,offset;
 char data[8],tmp[]="/tmp/code.XXXX"; 
 void *addr;
 struct stat buf;
 Elf32_Ehdr elf_data;
 Elf32_Shdr *section;
 int elen = sizeof( Elf32_Ehdr), slen = sizeof( Elf32_Shdr);
 /* This will be polymorph code */
 __asm__(" nopn nop n nopn nop n nop n");

 fd=open(argv[0],O_RDONLY);

 read(fd,&elf_data,elen);

 section = malloc( elf_data.e_shnum * slen);
 lseek(fd,elf_data.e_shoff,SEEK_SET);
 read(fd,section,elf_data.e_shnum * slen);

 /* text section ??? */
 for ( i = 0; i < elf_data.e_shnum; i++ )
   if ( elf_data.e_entry == section[text=i].sh_addr ){
      printf("[+] Found text segment n");
      break;
   }
 printf("%pn",elf_data.e_entry);
 /* Now little magic */

 offset = section[text].sh_offset + MAGIC_CODE;
 printf("File offset %pn",offset);
 lseek(fd,offset,SEEK_SET);
 read(fd,data,5);
 printf("%p%xn",*(int*)data,data[4] & 0xff);

 fd1=mkstemp(tmp);
 /* copy this to temp file */
 stat(argv[0],&buf);
 addr = mmap(0,buf.st_size,PROT_READ,MAP_PRIVATE,fd,0);
 write(fd1,addr,buf.st_size);
 munmap(addr,buf.st_size);

/*
 * Ok I have now offset of my polymorph code in file ;o)...the way we go ;o)
 */
 for ( i = 0 ; i <= 3 ; i++ ){
    if ( memcmp(data,code[ i ],5) == 0 ){
      if ( code[i + 1] == NULL ) {
        lseek(fd1,offset,SEEK_SET);
        write(fd1,code[0],5);
      }else{
         lseek(fd1,offset,SEEK_SET);
         write(fd1,code[i+1],5);
      }
      break;
    }
 }
 rename(tmp,argv[0]);
 chmod(argv[0],buf.st_mode);
}


Ovo sto sam uokviro je vrednost koju morate pronaci sami uz pomoc GDBa.Evo vam moj
typescript kako sam ja to radio :

Code:

Script started on Sat Jun 30 22:56:23 2001
root@scorpion :~/polymorph$ gdb poly
GNU gdb 4.18
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-unknown-freebsd"...
(no debugging symbols found)...
(gdb) x/i _start
[blue]0x8048634[/blue] <_start>:     push   %ebp
(gdb) disass main
Dump of assembler code for function main:
0x8048740 <main>:       push   %ebp
0x8048741 <main+1>:     mov    %esp,%ebp
0x8048743 <main+3>:     sub    $0xe0,%esp
0x8048749 <main+9>:     push   %edi
0x804874a <main+10>:    push   %esi
0x804874b <main+11>:    lea    0xffffffd4(%ebp),%eax
0x804874e <main+14>:    lea    0xffffffd4(%ebp),%edi
0x8048751 <main+17>:    mov    $0x8048ac3,%esi
0x8048756 <main+22>:    cld
0x8048757 <main+23>:    mov    $0x3,%ecx
0x804875c <main+28>:    repz movsl %ds:(%esi),%es:(%edi)
0x804875e <main+30>:    movsw  %ds:(%esi),%es:(%edi)
0x8048760 <main+32>:    movsb  %ds:(%esi),%es:(%edi)
0x8048761 <main+33>:    movl   $0x34,0xffffff34(%ebp)
0x804876b <main+43>:    movl   $0x28,0xffffff30(%ebp)
[blue]0x8048775[/blue] <main+53>:    nop
0x8048776 <main+54>:    nop
0x8048777 <main+55>:    nop
0x8048778 <main+56>:    nop
0x8048779 <main+57>:    nop
0x804877a <main+58>:    add    $0xfffffff8,%esp
0x804877d <main+61>:    push   $0x0
0x804877f <main+63>:    mov    0xc(%ebp),%eax
---Type <return> to continue, or q <return> to quit---q
Quit
(gdb) quit
root@scorpion :~/polymorph$ bc
bc 1.05
Copyright 1991, 1992, 1993, 1994, 1997, 1998 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
ibase=16
8048775-8048634
321
quit
root@scorpion :~/polymorph$




[Ovu poruku je menjao predator dana 07-01-2001 u 08:59 PM GMT]
 
Odgovor na temu

[es] :: Zaštita :: Polimorfni kod

[ Pregleda: 2510 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.