SELAMAT DATANG DI BLOG ILHO-HITTER

Sabtu, 18 Desember 2010

Advanced Shellcoding Teknik


This paper assumes a working knowledge of basic shellcoding techniques, and x86 assembly, I will not rehash these in this paper.  I hope to teach you some of the lesser known shellcoding techniques that I have picked up, which will allow you to write smaller and better shellcodes.  I do not claim to have invented any of these techniques, except for the one that uses the div instruction. Makalah ini mengasumsikan pengetahuan teknik shellcoding dasar, dan perakitan x86, aku tidak akan pengulangan ini dalam tulisan ini. saya berharap untuk mengajarkan Anda beberapa teknik yang kurang shellcoding diketahui bahwa saya telah mengambil, yang akan memungkinkan Anda untuk menulis lebih kecil dan shellcodes lebih baik saya lakukan. tidak mengklaim telah menemukan salah satu teknik, kecuali salah satu yang menggunakan instruksi div.


The multiplicity of mul Banyaknya mul

This technique was originally developed by Sorbo of darkircop.net.  The mul instruction may, on the surface, seem mundane, and it's purpose obvious.  However, when faced with the difficult challenge of shrinking your shellcode, it proves to be quite useful.  First some background information on the mul instruction itself. Teknik ini awalnya dikembangkan oleh Sorbo dari darkircop.net Instruksi mul dapat, di permukaan, tampak biasa,. dan itu tujuan jelas. Namun, ketika dihadapkan dengan tantangan yang sulit menyusut shellcode Anda, itu terbukti cukup berguna. Pertama beberapa informasi latar belakang instruksi mul itu sendiri.

mul performs an unsigned multiply of two integers.  It takes only one operand, the other is implicitly specified by the %eax register.  So, a  common mul instruction might look something like this: mul melakukan suatu unsigned kalikan dua bilangan bulat Dibutuhkan hanya satu operan, yang lain secara implisit ditentukan oleh% eax register Jadi, instruksi mul umum akan terlihat seperti ini..:

movl $0x0a,%eax movl $ 0x0a,% eax
mul $0x0a $ 0x0a mul

This would multiply the value stored in %eax by the operand of mul, which in this case would be 10*10.  The result is then implicitly stored in EDX:EAX.  The result is stored over a span of two registers because it has the potential to be considerably larger than the previous value, possibly exceeding the capacity of a single register(this is also how floating points are stored in some cases, as an interesting sidenote). Hal ini akan kalikan nilai yang tersimpan dalam eax% oleh operan dari mul, yang dalam hal ini akan 10 * 10 Hasilnya kemudian implisit disimpan dalam EDX:. EAX Hasilnya adalah disimpan selama rentang dua register karena memiliki. potensi untuk menjadi jauh lebih besar dari nilai sebelumnya, mungkin melebihi kapasitas register tunggal (ini juga bagaimana titik mengambang disimpan dalam beberapa kasus, sebagai sidenote menarik).

So, now comes the ever-important question.  How can we use these attributes to our advantage when writing shellcode?  Well, let's think for a second, the instruction takes only one operand, therefore, since it is a very common instruction, it will generate only two bytes in our final shellcode.  It multiplies whatever is passed to it by the value stored in %eax, and stores the value in both %edx and %eax, completely overwriting the contents of both registers, regardless of whether it is necessary to do so, in order to store the result of the multiplication.  Let's put on our mathematician hats for a second, and consider this, what is the only possible result of a multiplication by 0?  The answer, as you may have guessed, is 0.  I think it's about time for some example code, so here it is: Jadi, sekarang muncul pertanyaan yang pernah-penting. Bagaimana kita bisa menggunakan atribut-atribut ini untuk keuntungan kita ketika menulis shellcode Yah, mari kita berpikir sejenak?, Instruksi yang hanya membutuhkan satu operand, oleh karena itu, karena ini adalah instruksi yang sangat umum, maka akan umum hanya dua byte di shellcode terakhir kami. Hal mengalikan apa pun yang dilewati oleh nilai yang disimpan di% eax, dan menyimpan nilai dalam kedua eax% edx dan%, benar-benar Timpa isi dari kedua register, terlepas dari apakah perlu untuk melakukannya, dalam rangka untuk menyimpan hasil perkalian Mari kita memakai topi ahli matematika kami untuk kedua,. dan mempertimbangkan ini, apa adalah hasil hanya mungkin dari perkalian dengan 0 Jawabannya,? seperti yang bisa Anda duga, adalah . 0 Saya pikir sudah waktunya untuk beberapa contoh kode, jadi di sini adalah:

xorl %ecx,%ecx xorl% ecx,% ecx
mul %ecx mul% ecx

What is this shellcode doing?  Well, it 0's out the %ecx register using the xor instruction, so we now know that %ecx is 0.  Then it does a mul %ecx, which as we just learned, multiplies it's operand by the value in %eax, and then proceeds to store the result of this multiplication in EDX:EAX.  So, regardless of %eax's previous contents, %eax must now be 0.  However that's not all, %edx is 0'd now too, because, even though no overflow occurs, it still overwrites the %edx register with the sign bit(left-most bit) of %eax.  Using this technique we can zero out three registers in only three bytes, whereas by any other method(that I know of) it would have taken at least six. Apa ini shellcode melakukan Yah, itu 0 itu keluar ecx% mendaftar menggunakan instruksi xor, jadi kami sekarang tahu bahwa ecx% adalah 0. Kemudian melakukan ecx% mul, yang seperti kita pelajari, mengalikan itu operan dengan nilai? di eax%, dan kemudian hasil untuk menyimpan hasil perkalian ini dalam EDX:.. EAX Jadi, terlepas dari isi sebelumnya% eax's, eax% sekarang harus 0 Namun itu tidak semua, edx% adalah 0'd sekarang juga, karena , meskipun overflow tidak terjadi, masih menimpa% edx mendaftarkan dengan bit tanda (paling kiri bit) dari% eax. Dengan menggunakan teknik ini kita bisa nol tiga register hanya dalam tiga byte, sedangkan dengan metode lainnya (yang saya tahu) itu akan diambil di sedikitnya enam.


The div instruction Instruksi div

Div is very similar to mul, in that it takes only one operand and implicitly divides the operand by the value in %eax.  Also like, mul it stores the result of the divide in %eax.  Again, we will require the mathematical side of our brains to figure out how we can take advantage of this instruction.  But first, let's think about what is normally stored in the %eax register.  The %eax register holds the return value of functions and/or syscalls.  Most syscalls that are used in shellcoding will return -1(on failure) or a positive value of some kind, only rarely will they return 0(though it does occur).  So, if we know that after a syscall is performed, %eax will have a non-zero value, and that  the instruction divl %eax will divide %eax by itself, and then store the result in %eax, we can say that executing the divl %eax instruction after a syscall will put the value 1 into %eax.  So...how is this applicable to shellcoding? Div sangat mirip dengan mul, dalam hal ini hanya membutuhkan satu operan dan implisit membagi operan dengan nilai dalam eax%. Selain itu seperti, mul menyimpan hasil membagi dalam eax% Sekali lagi,. Kita akan memerlukan sisi matematis otak kita untuk mengetahui bagaimana kita bisa mengambil keuntungan dari instruksi ini Namun pertama-tama., mari kita berpikir tentang apa yang biasanya disimpan dalam eax% register. Register eax% memegang nilai kembali fungsi dan / atau syscalls Kebanyakan syscalls. yang digunakan di shellcoding akan kembali -1 (pada kegagalan) atau nilai positif dari beberapa jenis, hanya jarang akan mereka kembali 0 (meskipun hal itu terjadi). Jadi, jika kita tahu bahwa setelah dilakukan suatu syscall, eax% akan memiliki non- nilai nol, dan bahwa instruksi% eax divl akan membagi eax% dengan sendirinya, dan kemudian menyimpan hasilnya dalam eax%, kita dapat mengatakan bahwa melaksanakan instruksi% eax divl setelah syscall akan meletakkan nilai 1 ke eax%. Jadi. .. bagaimana ini berlaku untuk shellcoding? Well, their is another important thing that %eax is used for, and that is to pass the specific syscall that you would like to call to int $0x80.  It just so happens that the syscall that corresponds to the value 1 is exit().  Now for an example: Nah, mereka merupakan hal penting yang eax% digunakan untuk, dan itu adalah untuk lulus syscall spesifik yang Anda ingin untuk panggilan ke int $ 0x80. Kebetulan bahwa syscall bahwa sesuai dengan nilai 1 adalah keluar () sekarang untuk contoh.:


xorl %ebx,%ebx xorl% ebx,% ebx
mul %ebx mul% ebx
push %edx push edx%
pushl   $0x3268732f pushl $ 0x3268732f
pushl   $0x6e69622f pushl $ 0x6e69622f
mov %esp, %ebx mov% esp,% ebx
push %edx push edx%
push %ebx push ebx%
mov %esp,%ecx mov% esp,% ecx
movb $0xb, %al  #execve() syscall, doesn't return at all unless it fails, in which case it returns -1 movb $ 0xb,% al # execve () syscall, tidak kembali sama sekali kecuali gagal, dalam hal ini mengembalikan -1
int $0x80 int $ 0x80

divl %eax  # -1 / -1 = 1 divl% eax # -1 / -1 = 1
int $0x80 int $ 0x80

Now, we have a 3 byte exit function, where as before it was 5 bytes.  However, there is a catch, what if a syscall does return 0?  Well in the odd situation in which that could happen, you could do many different things, like inc %eax, dec %eax, not %eax anything that will make %eax non-zero.  Some people say that exit's are not important in shellcode, because your code gets executed regardless of whether or not it exits cleanly.  They are right too, if you really need to save 3 bytes to fit your shellcode in somewhere, the exit() isn't worth keeping.  However, when your code does finish, it will try to execute whatever was after your last instruction, which will most likely produce a SIG ILL(illegal instruction) which is a rather odd error, and will be logged by the system.  So, an exit() simply adds an extra layer of stealth to your exploit, so that even if it fails or you can't wipe all the logs, at least this part of your presence will be clear. Sekarang, kami memiliki fungsi 3 keluar byte, sedangkan sebelum 5 byte. Namun, ada menangkap, bagaimana jika syscall yang tidak kembali 0? Nah dalam situasi aneh di mana yang bisa terjadi, Anda bisa melakukan banyak hal yang berbeda , seperti inc eax%, eax% Desember, tidak% apapun eax yang akan membuat eax% non-nol Beberapa orang mengatakan bahwa keluar adalah tidak penting dalam shellcode, karena kode Anda dijalankan terlepas dari apakah atau tidak keluar bersih.. Mereka benar juga, jika Anda benar-benar perlu menyimpan 3 byte untuk menyesuaikan kode kamu di suatu tempat, keluar () tidak layak disimpan. Namun, ketika kode Anda tidak selesai, ia akan mencoba untuk melaksanakan apa pun yang setelah instruksi terakhir Anda, yang akan kemungkinan besar menghasilkan SIG SAKIT (instruksi ilegal) yang merupakan kesalahan agak aneh, dan akan dicatat oleh sistem. Jadi, keluar () hanya menambahkan lapisan ekstra stealth untuk Anda mengeksploitasi, sehingga bahkan jika gagal atau Anda tidak bisa menghapus semua log, setidaknya ini bagian dari keberadaan Anda akan jelas.


Unlocking the power of leal Membuka kunci kekuatan Leal

The leal instruction is an often neglected instruction in shellcode, even though it is quite useful.  Consider this short piece of shellcode. Instruksi Leal adalah instruksi sering diabaikan dalam shellcode, meskipun cukup berguna. Pertimbangkan ini bagian pendek shellcode.

xorl %ecx,%ecx xorl% ecx,% ecx
leal 0x10(%ecx),%eax Leal 0x10 (% ecx),% eax

This will load the value 17 into eax, and clear all of the extraneous bits of eax.  This occurs because the leal instruction loads a variable of the type long into it's desitination operand.  In it's normal usage, this would load the address of a variable into a register, thus creating a pointer of sorts.  However, since ecx is 0'd and 0+17=17, we load the value 17 into eax instead of any kind of actual address.  In a normal shellcode we would do something like this, to accomplish the same thing: Hal ini akan memuat nilai 17 ke eax, dan jelas semua bit asing dari eax ini terjadi karena beban instruksi Leal sebuah variabel dari tipe yang panjang menjadi itu operan desitination.. Di dalamnya itu penggunaan normal, hal ini akan memuat alamat dari variabel ke dalam register, sehingga menciptakan sebuah penunjuk dari macam. Namun, karena ecx adalah 0'd dan 0 +17 = 17, kita load nilai 17 ke eax bukan segala jenis alamat yang sebenarnya. Dalam sebuah shellcode normal kita akan melakukan sesuatu seperti ini, untuk mencapai hal yang sama:

xorl %eax,%eax xorl% eax,% eax
movb $0x10,%eax movb $ 0x10,% eax

I can hear you saying, but that shellcode is a byte shorter than the leal one, and you're quite right.  However, in a real shellcode you may already have to 0 out a register like ecx(or any other register), so the xorl instruction in the leal shellcode isn't counted.  Here's an example: Saya dapat mendengar Anda berkata, tetapi shellcode yang byte lebih pendek daripada yang Leal, dan Anda cukup benar. Namun, dalam shellcode sebenarnya Anda sudah mungkin harus 0 dari sebuah register seperti ecx (atau register yang lain), sehingga instruksi xorl dalam shellcode Leal tidak dihitung Berikut ini contohnya.:

xorl    %eax,%eax xorl% eax,% eax
xorl    %ebx,%ebx xorl% ebx,% ebx
movb    $0x17,%al movb $ 0x17,% al
int    $0x80 int $ 0x80

xorl %ebx,%ebx xorl% ebx,% ebx
leal 0x17(%ebx),%al Leal 0x17 (% ebx), al%
int $0x80 int $ 0x80

Both of these shellcodes call setuid(0), but one does it in 7 bytes while the other does it in 8.  Again, I hear you saying but that's only one byte it doesn't make that much of a difference, and you're right, here it doesn't make much of a difference(except for in shellcode-size pissing contests =p), but when applied to much larger shellcodes, which have many function calls and need to do things like this frequently, it can save quite a bit of space. Kedua shellcodes panggilan setuid (0), tetapi seseorang dalam 7 bytes sementara yang lain melakukannya di 8 Sekali lagi, saya mendengar Anda berkata, tapi itu hanya satu byte itu tidak membuat bahwa banyak perbedaan., Dan Anda kanan kembali, ini tidak membuat banyak perbedaan (kecuali untuk kontes ukuran shellcode kencing = p), tetapi ketika diterapkan pada shellcodes jauh lebih besar, yang memiliki banyak fungsi panggilan dan perlu melakukan hal-hal seperti ini sering, dapat menyimpan sedikit ruang.

0 komentar:

Posting Komentar

Twitter Delicious Facebook Digg Stumbleupon Favorites More