CoderZ.cc

Zurück   CoderZ.cc > Tutorials > Biete Tutorial


 
Themen-Optionen Ansicht
25.04.2013, 16:54   #1
dr.pepper (Offline)
Second Level User
 
 
Registriert seit: 27.11.2024
Ort: Dr. Freds Labor
Beiträge: 132
Thanks: 25
Thanked 44 Times in 25 Posts
Standard Anti-Debugging bei ELF-Dateien

Ich habe mal ein kleines C++ Tutorial zu dem Thema "Anti-Debugging bei ELF-Dateien" geschrieben.
Die hier aufgezeigt Methoden sind von Leute mit langer Erfahrung in Sachen Reverse Engineering wahrscheinlich leicht zu durchschauen. Dieses Tutorial soll auch nur einen kleinen Einblick in die Materie geben.
Falls noch jemand andere Methoden kennt...Immer raus damit !

Download: antidebug.pdf.zip
__________________
[ May the Source be with you ]
  Mit Zitat antworten
The Following 5 Users Say Thank You to dr.pepper For This Useful Post:
0x33s (25.04.2024), easysurfer (25.04.2024), Elazer (25.04.2024), middey (26.04.2024), peppy (06.11.2024)
25.04.2013, 17:32   #2
easysurfer (Offline)
Third Level User
 
 
Registriert seit: 31.10.2024
Beiträge: 430
Thanks: 69
Thanked 245 Times in 133 Posts
Standard

Nettes Paper, gefällt mir gut Danke dafür!

Mir fallen unter *nix System keinen weiteren Möglichkeiten mehr ein. Da allerdings die GDB-Crashverursacher ja publiziert sind, wird auch ein Cracker kein Problem damit haben, gdb zu aktualisieren oder selbst den Bug zu fixxen.

Greez
__________________
Gamehacking, Reversing and Security
  Mit Zitat antworten
25.04.2013, 21:42   #3
Elazer (Offline)
Coderz Mitglied
 
Registriert seit: 01.04.2024
Ort: Irgendwo :D
Beiträge: 72
Thanks: 17
Thanked 9 Times in 8 Posts
Standard

Soweit ich mich errinnern kann ist das ELF Format glaube ich für Linux naja dann muss eben VMWare her.
  Mit Zitat antworten
26.04.2013, 09:03   #4
dr.pepper (Offline)
Second Level User
 
 
Registriert seit: 27.11.2024
Ort: Dr. Freds Labor
Beiträge: 132
Thanks: 25
Thanked 44 Times in 25 Posts
Standard

Zitat von Elazer
Soweit ich mich errinnern kann ist das ELF Format glaube ich für Linux naja dann muss eben VMWare her.
Ja, ELF ist das Linux-Äquivalent zur .exe-Datei.
__________________
[ May the Source be with you ]
  Mit Zitat antworten
28.11.2013, 19:09   #5
dr.pepper (Offline)
Second Level User
 
 
Registriert seit: 27.11.2024
Ort: Dr. Freds Labor
Beiträge: 132
Thanks: 25
Thanked 44 Times in 25 Posts
Standard

Der Herr Jonathan Salwan, seines Zeichens Herscher über www.shell-storm.org hat eine recht weitere recht interessante Antidebug-Methode gefunden.

In dem von ihm verfassten Artikel Linux-process-execution-and-the-useless-ELF-header-fields macht er recht übersichtlich klar, dass manche Teile des ELF-Header bei der Ausführung keine Beachtung finden.

According to this, we can say that the following ElfX_Ehdr's fields are kinda useless: e_shoff, e_shentsize, e_shnum, e_shstrndx.
Hierzu hat er auch ein Tool veröffentlicht, welches die entsprechenden Eigenschaften der Sections auf 0 setzt.

/*
**  Copyright (C) 2013 - Jonathan Salwan - http://twitter.com/JonathanSalwan
** 
**  This program is free software: you can redistribute it and/or modify
**  it under the terms of the GNU General Public License as published by
**  the Free Software Foundation, either version 3 of the License, or
**  (at your option) any later version.
** 
**  This program is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**  GNU General Public License for more details.
**
**  You should have received a copy of the GNU General Public License
**  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include <elf.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <stdlib.h>
Elf32_Ehdr    *pElf_Header;
Elf32_Phdr    *pElf32_Phdr;
Elf32_Shdr    *pElf32_Shdr;
char          *pMapElf;
struct stat   filestat;
static unsigned char *set_header(char *file)
{
  int fd;
  unsigned char *data;
  fd = open(file, O_RDONLY, 0644);
  stat(file, &filestat);
  printf("[+] Binary size : %d octets\n", (int)filestat.st_size);
  data = malloc(filestat.st_size * sizeof(char));
  read(fd, data, filestat.st_size);
  pMapElf = mmap(0, filestat.st_size, PROT_READ, MAP_SHARED, fd, 0);
  pElf_Header = (Elf32_Ehdr *)data;
  pElf32_Shdr = (Elf32_Shdr *)((char *)data + pElf_Header->e_shoff);
  pElf32_Phdr = (Elf32_Phdr *)((char *)data + pElf_Header->e_phoff);
  close(fd);
  return (data);
}
int main(int argc, char **argv)
{
  unsigned char *data;
  unsigned nb_section;
  Elf32_Shdr *current;
  int i, fd;
  if (argc < 2){
    printf("Syntax: ./%s <bin>\n", argv[0]);
    return -1;
  }
  data = set_header(argv[1]);
  printf("--- Step 1 ---\n");
  printf("[+] Clean sections...\n");
  nb_section = pElf_Header->e_shnum;
  for (i = 0 ; i < nb_section ; i++){
    pElf32_Shdr->sh_name = 0;
    pElf32_Shdr->sh_type = 0;
    pElf32_Shdr->sh_flags = 0;
    pElf32_Shdr->sh_addr = 0;
    pElf32_Shdr->sh_offset = 0;
    pElf32_Shdr->sh_size = 0;
    pElf32_Shdr->sh_link = 0;
    pElf32_Shdr->sh_info = 0;
    pElf32_Shdr->sh_addralign = 0;
    pElf32_Shdr->sh_entsize = 0;
    pElf32_Shdr++;
  }
  printf("[+] Clean section [DONE]\n");
  printf("--- Step 2 ---\n");
  printf("[+] Clean elf header...\n");
  pElf_Header->e_shnum = 0;
  pElf_Header->e_shstrndx = 0;
  pElf_Header->e_shentsize = 0;
  pElf_Header->e_version = 0;
  pElf_Header->e_ehsize = 0;
  pElf_Header->e_shoff = 123;
  printf("[+] Clean elf header [DONE]\n");
  printf("--- Step 3 ---\n");
  printf("[+] Writting binary...\n");
  fd = open(argv[1], O_WRONLY, 0644);
  write(fd, data, filestat.st_size);
  close(fd);
  printf("[+] Writting binary [DONE]\n");
  free(data);
  return 0;
}
Und die Programme sind danach immer noch ausführbar?
Kurze Antwort: Ja!

Beispiel an einer kleinen Hello_World Anwendung:
#include <stdio.h>
int main()
{
	printf("Hello World\n");
	return 0;
}
./hello_world
Hello World
file hello_world
hello_world: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x76996acaebdeb479499ffdafe8dc7392c907a342, not stripped
readelf -t hello_world
There are 30 section headers, starting at offset 0x113c:
Section Headers:
  [Nr] Name
       Type            Addr     Off    Size   ES   Lk Inf Al
       Flags
  [ 0] 
       NULL            00000000 000000 000000 00   0   0  0
       [00000000]: 
  [ 1] .interp
       PROGBITS        08048154 000154 000013 00   0   0  1
       [00000002]: ALLOC
  [ 2] .note.ABI-tag
       NOTE            08048168 000168 000020 00   0   0  4
       [00000002]: ALLOC
  [ 3] .note.gnu.build-id
       NOTE            08048188 000188 000024 00   0   0  4
       [00000002]: ALLOC
  [ 4] .gnu.hash
       GNU_HASH        080481ac 0001ac 000020 04   5   0  4
       [00000002]: ALLOC
...
ELF HEADER:
e_ident:		7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
e_ident[EI_CLASS]:	ELFCLASS32
e_ident[EI_DATA]:	ELFDATA2LSB
e_ident[EI_VERSION]:	EV_CURRENT
e_ident[EI_OSABI]:	ELFOSABI_SYSV
e_ident[EI_ABIVERSION]:	0x0
e_type:			ET_EXEC
e_machine:		EM_386
e_version:		EV_CURRENT
e_entry:		0x08048320
e_phoff:		0x00000034	(52)
e_shoff:		0x0000113c	(4412)
e_ehsize:		0x00000034	(52)
e_phentsize:		0x00000020	(32)
e_phnum:		0x00000009	(9)
e_shentsize:		0x00000028	(40)
e_shnum:		0x0000001e	(30)
e_shstrndx:		0x0000001b	(27)
nach der Bearbeitung mit dem Section-Cleaner-Tool:
./hello_world
Hello World
file hello_world 
hello_world_2: ELF 32-bit LSB executable, Intel 80386, invalid version (SYSV), for GNU/Linux 2.6.24, dynamically linked (uses shared libs), corrupted section header size
readelf -t hello_world
There are no sections in this file.
ELF HEADER:
e_ident:		7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
e_ident[EI_CLASS]:	ELFCLASS32
e_ident[EI_DATA]:	ELFDATA2LSB
e_ident[EI_VERSION]:	EV_CURRENT
e_ident[EI_OSABI]:	ELFOSABI_SYSV
e_ident[EI_ABIVERSION]:	0x0
e_type:			ET_EXEC
e_machine:		EM_386
e_version:		EV_NONE
e_entry:		0x08048320
e_phoff:		0x00000034	(52)
e_shoff:		0x00000000	(0)
e_ehsize:		0x00000000	(0)
e_phentsize:		0x00000020	(32)
e_phnum:		0x00000009	(9)
e_shentsize:		0x00000000	(0)
e_shnum:		0x00000000	(0)
e_shstrndx:		0x00000000	(0)

Fazit: ich finde das sehr interessant und ich denke mal, dass eine ELF ohne Sections schon den einen oder anderen Reverser stutzig machen würde...
__________________
[ May the Source be with you ]

Geändert von dr.pepper (28.11.2024 um 21:03 Uhr)
  Mit Zitat antworten


Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 
Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.

Gehe zu


Alle Zeitangaben in WEZ +2. Es ist jetzt 05:54 Uhr.

Powered by vBulletin®
Copyright ©2008 - 2017
Template-Modifikationen durch TMS