"In the beginner's mind there are many possibilities, but in the expert's there are few." "In den Anfänger-Geist gibt es viele Möglichkeiten, aber in dem Sachverständigen gibt es nur wenige."- Shunryu Suzuki - Shunryu Suzuki
Published by: apples , on 2008-04-05 22:18:00 Veröffentlicht von: Äpfel, auf 2008-04-05 22:18:00
shellcode for beginners Shellcode für Anfänger by apples von Äpfeln
pre-requisites: Voraussetzungen: -basic x86 assembly knowledge -Basic x86 Montage Wissen -buffer overflow techniques (for implementation of the shellcode) Buffer-Overflow-Techniken (für die Umsetzung der Shellcode) -common sense -der gesunde Menschenverstand
okay, so you just found a buffer overflow in the latest application. okay, so dass Sie nur einen Pufferüberlauf in der neuesten Anwendung. you overwrite the EIP, and..suddenly you realize you need code to execute. Sie überschreiben die EIP, und plötzlich .. Sie erkennen, benötigen Sie Code, der ausgeführt werden. AND, this code has to be small enough to work in your newfound vulnerability. UND, dieser Code muss klein genug, um Arbeiten in Ihrem neu gefundenen Schwachstellen. so, what do you use? ja, was machen Sie?shellcode, of course! Shellcode, natürlich!
shellcode can be very modular, meaning that it can be used in many different areas, Shellcode kann sehr modular, was bedeutet, dass es kann verwendet werden, in vielen verschiedenen Bereichen, as long it meets some basic requirements, such as the architecture type and operating system. so lange es einige grundlegende Anforderungen, wie z. B. die Architektur und Betriebssystem. shellcode is written in assembly, which means that while it's more difficult to create, Shellcode ist in der Montage, was bedeutet, dass, während es schwieriger zu erstellen, it's much smaller, due to the lack of abstraction. Es ist viel kleiner, durch den Mangel an Abstraktion.so, let's get started, shall wee? so, let's get begonnen, so Wee?
our first shellcode will perform something very simple. unsere erste Shellcode wird etwas sehr einfach.it will call the Es ruft die exit() syscall in linux. exit () syscall in Linux.first, let's take a look at the syntax of the ersten, let's werfen Sie einen Blick auf die Syntax der syscall itself. syscall sich.
CODE : CODE:
int sys_exit(int status)int sys_exit (int Status) -terminates the current process-beendet den laufenden Prozess -status is the return code-Status ist der Return-Code
here's the code that i wrote to call exit(). Hier ist der Code, den ich geschrieben habe, um exit ().(this code is for use in NASM) (Dieser Code ist für den Einsatz in NASM) CODE : CODE:
section .textAbschnitt. Text .global _start. globalen _start
this is equivalent to the following code in C: dies entspricht dem folgenden Code in C: CODE : CODE:
void main()void main () {( exit(0);exit (0); })
write those in your favorite text editor, then assemble it and link it. schreiben diese in Ihrem Lieblings-Text-Editor, dann montieren sie und verknüpfen sie. here's what i did. hier ist es, was ich habe.
finally, we start to see some results from our work! schließlich, wir starten, um zu sehen, einige Ergebnisse aus unserer Arbeit!the shellcode is der Shellcode ist "xb8x01x00x00x00xbbx00x00x00x00xcdx80" ! "xb8x01x00x00x00xbbx00x00x00x00xcdx80"!but, there's an aber, es gibt ein obvious problem with this shellcode, and anyone who uses strings in C offensichtliche Problem mit diesem Shellcode, und alle Anwender und alle, Streicher in C will see it instantly. werden sehen, es sofort.strings cannot contain NULL bytes, because a NULL Es kann keine NULL-Bytes, da ein NULL - byte is used to signify the end of the string. Byte wird verwendet, um das Ende des Strings.which means, the was bedeutet, die vulnerable program would stop reading after "xb8x01". angreifbare Programm würde Lesung nach "xb8x01".this is a very Dies ist ein sehr bad thing indeed. schlechte Sache der Tat.let's try writing one again, with this knowledge. Lassen Sie uns versuchen Sie erneut schriftlich ein, mit diesem Wissen.
first, we notice that 'mov eax, 1' generated 3 null bytes. erstes stellen wir fest, daß "mov eax, 1 'generiert 3 Null-Bytes.now, think jetzt, glaube about why this would happen. darüber, warum dies geschieht.eax is a 32-bit register, and we're only EAX ist eine 32-Bit-Register, und wir sind nur changing 1 byte with our value of 1. verändernden 1 Byte mit unseren Wert von "1".think about it this way: denken Sie daran: CODE : CODE:
now you can see where the problem might arise. Jetzt können Sie sehen, wo das Problem entstehen könnten.on another note, the auf einem anderen Kenntnis, die lower 16 bits of eax can be divided into two 8-bit registers, known as unteren 16 Bits von eax lassen sich in zwei 8-Bit-Register, bekannt als ah and al. ah und al.as you might be able to tell, ah is the high 8 bits, and al is wie du vielleicht in der Lage zu sagen, ah ist die hohe 8 Bit, und al ist the low 8 bits. die geringe 8 Bit.since 1 only takes up one byte, then we can simply move seit dem 1. nimmt nur ein Byte, dann können wir einfach it to al. sie al.
now, we still have the second command to worry about. nun, wir haben noch die zweite Befehl zu kümmern.how can we set ebx Wie können wir ebx to 0 without moving the value of 0 to it? auf 0, ohne den Wert von 0 bis sie?the answer lies within the Die Antwort liegt in der bitwise operator XOR. bitweise XOR Betreiber.here's a table on how it works: Hier ist eine Tabelle auf, wie es funktioniert:
a | b | c A | B | C ----------------------------------- 0 | 0 = 0 0 | 0 = 0 1 | 0 = 1 1 | 0 = 1 0 | 1 = 1 0 | 1 = 1 1 | 1 = 0 1 | 1 = 0
when a and b are the same value, then it returns 0. wenn a und b sind die gleichen Wert, dann wird 0 zurückgegeben.when they are wenn sie different, it returns 1. anders, es gibt 1 zurück.now, think about how this can be applied to jetzt darüber nachdenken, wie diese angewandt werden kann, um ebx. if you XOR ebx with itself, it will create 0, since ebx has the Wenn Sie XOR ebx mit sich selbst, wird es schaffen, 0, da ebx hat die same value as ebx (duh?! :P) gleichen Wert wie ebx (duh?!: P)
make the following changes to your shellcode, and re-assemble and link die folgenden Änderungen an Ihrer Shellcode, und wieder montieren und Link it. es.then run 'objdump -d exit' again, and this should be your shiny new Führen Sie anschließend "objdump-d Ausfahrt" wieder, und dies sollte dein glänzende neue output: Ausgang: CODE : CODE:
exit: file format elf32-i386Ausfahrt: Datei-Format elf32-i386
Disassembly of section .text:Demontage des Abschnitts. Text:
08048080 <_start>:08048080 <_start>: 8048080: b0 01 mov $0x1,%al8048080: b0 01 mov $ 0x1,% al 8048082: 31 db xor %ebx,%ebx8048082: 31 db xor% ebx,% ebx 8048084: cd 80 int $0x808048084: cd 80 int $ 0x80
thus, our new shellcode is "xb0x01x31xdbxcdx80" ! damit, unseren neuen Shellcode ist "xb0x01x31xdbxcdx80"!and, it's NULL und, es ist NULL free! frei!next, try using these techniques to create shellcode that spawns a nächsten, versuchen Sie es mit dieser Techniken zu schaffen, dass Shellcode Spawns ein shell. Shell.
Cast your vote on this article Stimmen Sie jetzt zu diesem Artikel *Note: the order of the votes has been reversed. * Hinweis: Die Reihenfolge der Stimmen wurde rückgängig gemacht.
Nines - 03:42 am Sunday April 06th, 2008Nines - 03.42 Uhr Sonntag 06. April, 2008
The original was better cause it contained slashes :P Well done bud, good article. Das Original war besser dazu führen, dass es enthielt Schrägstriche: P Well done Knospe, guten Artikel.
Karec - 08:52 am Sunday April 06th, 2008Karec - 08.52 Uhr Sonntag 06. April, 2008
Good things: Gute Dinge: 1. I liked the truth table. Mir gefiel die Wahrheit Tabelle.(Digital Sytems class reference) (Digital Sytems Klasse Referenz) 2. The article flows very well information wise. Der Artikel fließt sehr gut Informationen klug.
Bad Things: Bad Things: 1. Lack of captialization or capitalisation (depending if you are US or European) at all in the article. Mangel an captialization oder Kapitalisierung (je, wenn Sie sind in den USA oder europäischen) auf alle in dem Artikel. 2. Bad grammar as far as going comma happy. Bad Grammatik so weit wie gehen Komma glücklich.
7/10 7 / 10
KSEboom - 12:33 pm Sunday April 06th, 2008KSEboom - 12.33 Uhr Sonntag 06. April, 2008
Not bad! Nicht schlecht!
signsoft - 01:38 am Monday April 14th, 2008Signsoft - 01.38 Uhr Montag 14. April, 2008
Nice article, simple and explaining. Nizza Artikel, einfach und erklären.Really good job. Wirklich gute Arbeit geleistet. I have one suggestion though: Ich habe ein Vorschlag wenn: MOV EAX,1 and MOV EAX, 1 und MOV AL,1 aren't equal. MOV AL, 1 sind nicht gleich. MOV AL,1 only alters 8 lowest bits and leaves the upper 24 unchanged. MOV AL, 1 nur verändert niedrigsten 8 Bits und lässt die oberen 24 unverändert.Whatever was there will stay there and in effect you can end with something other than 1 in EAX. Was auch immer war es dort und in der Tat können Sie mit etwas anderes als 1 von EAX. Placing XOR EAX,EAX in front of Platzierung XOR EAX, EAX vor MOV AL,1 solves the problem. MOV AL, 1 löst das Problem.
bitchasshoe - 05:22 pm Wednesday April 23rd, 2008bitchasshoe - 05.22 Uhr Mittwoch 23. April, 2008
nice, simple and straight to the point. schön, einfach und direkt auf den Punkt.
sikes - 09:19 am Friday May 02nd, 2008sikes - 09.19 Uhr Freitag 02. Mai, 2008
Nice Nett
VARUNmca123 - 04:51 am Monday May 12th, 2008VARUNmca123 - 04.51 Uhr Montag 12. Mai, 2008
not very hard to understand! nicht sehr schwer zu verstehen!
herotrojanz - 11:28 am Thursday June 05th, 2008herotrojanz - 11.28 Uhr Donnerstag 05 Juni, 2008
understood and gud job writing the article verstanden und gud Job Schreiben der Artikel
rohit_007 - 02:24 am Monday October 13th, 2008rohit_007 - 02.24 Uhr Montag 13. Oktober, 2008
abyss - 02:25 am Saturday November 01st, 2008Abgrund - 02.25 Uhr Samstag 01. November, 2008
WICKED! Thanks for that Indeed! Vielen Dank für diese Tat!
This site is the collective work of the HackThisSite staff. Diese Website ist die kollektive Arbeit der HackThisSite Personal.Please don't reproduce in part or whole without permission. Bitte nicht reproduzieren teilweise oder ganz ohne Erlaubnis. Page Generated: Mon, 01 Dec 2008 19:57:39 -0500 Exec: 10 Page Generated: Mon, 01 Dec 2008 19:57:39 -0500 Exec: 10 Page loaded in 0.13266 seconds!Diese Seite wurde geladen in 0,13266 Sekunden!
The original was better cause it contained slashes :P Well done bud, good article. Das Original war besser dazu führen, dass es enthielt Schrägstriche: P Well done Knospe, guten Artikel.