Title: Stack Overflow IRC Lecture Author/Lecturer: Aelphaeis Mangarae Website: http://blackhat-forums.com Email: adam_we1shaupt@hotmail.com IRC: IRC.BlueHell.Org #BHF ------------------------------------------------------------------------------------- Learn Stack Overflow Exploitation IRC Lecture Lecturer: Aelphaeis Mangarae Topic: Win32 Stack Based Buffer Overflow Exploitation Time: 10:17 PM, Perth, Western Australia So we begin the lecture as you should of already guessed, a stack based buffer overflow is something which occurs on the stack The stack is a data structure in memory that can be used for storing temporary and initialized data The stack works on a LIFO principal that is Last In, First Out The top of the stack is at a fixed address and grows downwards If something is added to the stack, that means something is PUSHED onto the stack when this happens something is placed on the stack, and the Stack Frame Pointer is decremented (because of stack growth's direction) that is, it will point to a lower address when something is removed from the stack it is POPPED at which point the stack frame is removed and the Stack Frame Pointer is incremented * dni_ (~dni@bluehell-8A5C4F46.hsd1.fl.comcast.net) Quit (Ping timeout ) So now you have a basic understanding of how the stack works * dni_ (~dni@bluehell-8A5C4F46.hsd1.fl.comcast.net) has joined #bhf Here is a diagram of a typical stack from wikipedia http://en.wikipedia.org/wiki/Image:ProgramCallStack2.png On the win32 stack there is basicall half a dozen registers these registers contain information some important ones are: The EBP, which is the Extended Base Pointer, this points to the current stack frame (sometimes it's named Stack DATA Pointer) The EIP, the Extended Instructional Pointer, which points to where a function will return to after it is called (generally it determines the next instruction's address) The ESP, the Extended Stack Pointer which points to the "top of the stack" (more accurately the bottom of stack on x86) in some books the essayists have told that it's used to point to the next stack operation which is true and the same somehow the two most important of these registers are the ESP and the EIP. These two we will come across when exploiting our application (vulnerable to a typical Stack Overflow). * Aelphaeis sets mode: -m Any questions? no any :) so far no non no nope no nope i iam nope. how long the esp ? as long as an address i suppose each register on a 32-bit OS is 4 bytes in length (32bits/8bits=4bytes), storing 32-bit address/data at maximum. If you need less space to use you can use 16-bit and/or 8-bit registers (sometimes we are forced to use a 8-bit register for example) esp its an address of a 4bytes register hence 32bit? the esp is 4 bytes ok` Aelph? thanks * popkorn (pop_korn@bluehell-7307429E.miki.eu.org) has joined #bhf w00t i can talk :D * mIcr0s0ft (user@ping.pong.np) has joined #bhf fuck up headYY, lecture is going on sorry :( Aelphaeis? ¬http://lardcave.net/~wzdd/hype/localimages/cs9244__ia32_integer_registers.png so no more questions really? look at this guys yes me hence 32bit? and this one: ¬http://www.unixwiz.net/images/stackframe-cdecl.gif * Aelphaeis sets mode: +m So now we move onto the next bit of the lecture What Is A Stack Based Buffer Overflow * mIcr0s0ft (user@ping.pong.np) has left #bhf A stack based buffer overflow occurs when more data is transferred into a (static) buffer than what the buffer was designed to hold, therefore the buffer overflows the contents of the buffer would be stored somewhere on the stack temporarily, what would happen is the excess data would overwrite other memory locations (stack frames, registers, func ptr, ...) The fact we can overwrite registers on the stack is the important part, because this is the key to exploitation In this lecture I will demonstrate the overwriting of the EIP and how to execute shellcode by hijacking flow of the program and landing it into a NOPSLED which of course will be followed by shellcode Why Do Stack Overflows Occur? * cesnjak (cesnjak@bluehell-D2958902.adsl.net.t-com.hr) has joined #bhf Stack Overflows occur because there are functions in C/C++ that do not do "bounds checking" and will copy the contents of one buffer or inputted data into a buffer without checking how much data the buffer can hold * insanity (_th3-x@F88F3A20.8CE6CB0B.F175557F.IP) has joined #bhf functions such as strcpy() do not do bounds checking and are therefore exploitable A small list of C functions that are vulnerable are: gets() sprintf() strcat() strcpy() streadd() strecpy() strtrns() index() fscanf() scanf() sscanf() vsprintf() realpath() getopt() getpass() If I remember correctly, dni found that list through googling * Aelphaeis sets mode: -m :) Any questions? nope strlen() thankz everything's fine.. no questions maybe more functions.. no questions well you guys can find that out for yourself im making list of them.. :D no questions not like you can't use Google, unlike my retard friend Ben who acts like he can't use Google gogo`` ok... if anyone has any list..it would be nice to share it so i want to tell if someone has any question just ask, do not be quiet yeah feel free to ask ok, seems no one has any questions why does my peenii smell? ... nic`, you need to wash your penis everyday lol =\ ok thanx =D ! haah otherwise it will become vulnerable to a stack based buffer overflow lol and you will be exploited by h4x0rz hahaha lol lol pwned sperm overflow then ill get posted on steak and cheese lol lol, ok that's enough about nic` pen0r vuln one :P * Typo (~you.suck@bluehell-156E3E87.lns1-c11.dsl.pol.co.uk) has joined #bhf So now we move onto: Fuzzing Our Vulnerable Application! now, I have already compiled our target application using LCC W32 it can be found here: http://blackhat-forums.com/Aelphaeis/vuln.exe everyone download it if you haven't got a vuln.exe suitable for exploitation brb, gotta piss classic the thrill of the ride Silentz ;D heh * Balgan (~pinokavat@bluehell-574D17AD.brig.cable.ntl.com) has joined #bhf 43 and counting... lol so you all downloaded vuln.exe? or got a copy yup yes yeah, just continue yes :D it crashes to me i have download it yes Now as I should of mentioned earlier this exploitation should be done on a Windows XP box and turn back the moderated mode back on:) * nic` sets mode: +m If for some reason you have DEP enabled on applications (other than windows system files) you can turn it off by going to Control Panel -> System -> Advanced -> Performance (Settings) -> Data Execution Prevention this technology will be discussed a bit more later on I believe most 64bit CPU's support Data Execution Prevention ok now it is time to fuzz our vulnerable application Aelhaeis: can DEP stay on if its just for windows progrms and serviceS? yes, I have found you can still exploit the application that way ok in fact I also discovered today that by default that's the way it seems to be indeed Now it's time to open up our vulnerable application in Ollydbg We will be fuzzing to see how many bytes we can slam in memory before overwriting the EIP. For those you will need my Fuzzing.txt (well you could just use Perl) http://blackhat-forums.com/Aelphaeis/Fuzzing.txt * popkorn (pop_korn@bluehell-7307429E.miki.eu.org) Quit (Quit: leaving ) * r0rkty (admin@securzone.org) Quit (Ping timeout ) You can open Ollydbg and pass the A's which we will be using to fuzz our application as an argument This program takes input as an argument (named a "command-line argument" program) http://img144.imageshack.us/img144/9519/ollydbg1lf0.png Ollydbg, File -> Open then paste 262 A's into the Arguments input box Press Open Now go to Debug -> Run You should possibly notice that some bytes (2) of your EIP have been overwritten * Aelphaeis sets mode: -m * cesnjak (cesnjak@bluehell-D2958902.adsl.net.t-com.hr) Quit (Quit: ) Any questions? 4 bytes overwritten why 262 A's ? meaning the whole thing right? EIP point to 00004141 yes sm, 262 to probe Syn4pse 2 me 4 not me the buffer length is 256 why 262 can overwrite 41 and 41 well it should vary on what compiler you use yep.. that's what i asked yes well there is space between the end of the buffer and the EIP on the stack my EIP -> 41414141 so that has to be overwritten let demonstrate it: [ buffer (256) ] [ SFP (4) ] [ RET (eip) (4) ] = 264 (data needed to overwrite the eip completely) 264 - 262 (our data) = 2 => two last bytes of EIP is not overwritten 00004141 me to my EIP -> 00004141 00004141 * r0rkty (admin@ircop.bluehell.org) has joined #bhf 262 's A * Aelphaeis sets mode: +o r0rkty 00401219 ? my eip is not overwritten at ll i put 262 A's in it have you gone Debug -> Run i have to pass by parameter 260 A's yes EBP is ->41414141 try more then dni and Seven to have 2 bytes overwritten of EIP did you use my vuln.exe ? now it's working dni && seven 00004141 ok good try 260 A's EIP: 00004141 EBP: 41414141 how about you dni, what is happening? the guys that have 41414141 just probe with 260 A's no, because 4 bytes is overwritten 41414141 - it's EBP if they slamed 262 bytes in there, that means they can place 258 bytes in memory before overwriting the EIP. hmm maybe its DEP fucking with my shit yeah i konw ael well DEP marks areas of memory as non-executable so shellcode can't be executed I wouldn't think it would effect the overwrite of the EIP. dni did you use my vuln.exe? have you Run->debug ? i got it working now dni? yeah i had to put more into the buffer ahh ok right so now you guys should all have worked out how many bytes you can place in memory before overwriting the EIP. so, is there anyone lost? this will be needed to align our new address over the old one. w8 a sec one more... you said: [15:45] well there is space between the end of the buffer and the EIP on the stack how do we know how big is the space? just one question u guyz are going to put this "lecture" in the forum when it ends ? since iwasnt here since the begginin in a normal stack based overflow process that space is 4 bytes. there's one segment sfp or stack frame pointer between 'em in usual so you need to put 4 more characters in order to reach the first byte of EIP or RET. yes Balgan thx Aelphaeis :) Ok.. everything's find. continue :] ok, so everyone now knows how they can align their new address over their old one? fine* what do you mean? i ad to put 264 **had to overwrite the eip what cpu do you have? amd ok 264 's A can overwirte all eip yes EIP->41414141 two questions: do we have to keep the bytes that overflow to a minimum, i mean, if the EIP is written at exactly 262 chars, why we use 264? D4rk, well it's not overwritten completely (2 bytes is still left). Generally we don't need to overwrite our eip with a junk data (A's). we just try to determine the number of characters needed to overflow the buffer. d4rk no then we are going to use the exactly num C:\>findjmp ntdll.dll esp you are going to see it later sm, you just need to work out how many bytes you can put into memory before overwriting the EIP. dcboy, please leave the explaining to me yeah aelph, it's ok I will discuss what you are going onto later on i got it.. thanks so you all now should have worked it out ok one thing Ael yes? you told me to leave then with 41414141 but you can leave with that you may search for at least 00414141 no, I didn't. You just needed to work out as I have said numerous times to know the bytes exactly < 01~Aelphaeis > ok, so everyone now knows how they can align their new address over their old o yes so i think there are guys with 41414141 now ant it can result an error later well then you need to work out how many bytes they can put into memory before overwriting the EIP. That's what they need to work out and what you should have all worked out by now :) That's the reason we are doing the fuzzing Now, what we are going to do is put the following into memory: [JUNK DATA] [NEW RETURN ADDRESS] [NOP SLED] [SHELLCODE] The JUNK DATA will be used to overflow our buffer because as I said before strcpy() does not do bounds checking, and in our application will just copy what is receives into our char buffer[256]; the junk data will be th same has the A's we use in fuzzing aye? yes, you can use what ever you want ty but in this case we will be using A's Now it is time for us to find a suitable address, to overwrite the EIP (RET) with. the RET in its simplest fashion is a simple CALL/JMP instruction. in generally we can use the call/jmp trick to locate our data on the stack and use it to exploit the program successfully and our data here is: NOP SLED and SHELLCODE What we need is an address with a JMP ESP or a CALL ESP. If we overwrite our EIP with an address that has JMP ESP we can jump into our NOPSLED. * KZ (~kanada@bluehell-5EBF2E1A.nc.res.rr.com) has joined #bhf In this case I am not sure if the NOPSLED is actually needed, but when doing more complicated exploitation you will find you probably will need to use it but the point is that you can't use the nop sled everywhere. Sometimes the target program (buffer) is very tiny and can't waste it by using of NOP instructions. So you need to find the exact address of the shellcode to avoid using nop sled. Anyway it's not the case here in our example. when we hit the NOPSLED, the Stack Frame Pointer will be incremented as it moves along each NOP. A NOP, is a No-Operation byte (with the hexadecimal represent of 0x90), it doesn't do anything. So now, let's find our address to overwrite the EIP with. First here is the "skeleton" if you will for the exploit we will be coding to exploit the vulnerable application http://blackhat-forums.com/Aelphaeis/exploit_b0f.c Everyone get it and whack it into their C Compilers * KSURi (~ksuri@9E51E34F.E8A52DC2.B891CCD7.IP) has joined #bhf re2all before, we go on. I would like to point out that obviously you will need to change the path in exploit[] to what is suitable for your application hello, KSURi, STFU while the lecture is going on So everyone please do that now Aelphaeis just one question which is the c compiler ur using in the movie of exploiting stack overf. ? LCC W32 thx so everyone ok with where we have come so far? yes yeah yes uep yes yep question tho in b0f. c * skvoznoy (~madrish@F7E2E0C1.E2D05FA0.4BFF86AB.IP) has joined #bhf yes, continue shoudnt it be 4 bytes ess than whatever the amount it took to overwrite the EIP ? that is i told welcome skvoznoy, the lecture is currently going on if you have eip 41414141 you have to put 4bytes less cuz, dont we need to send it garbage until right before the EIP starts getting overwritten yes correct ok as I said before! if you had 00004141 2bytes less correct Syn4ps3 good day to all, it is pleasent to be here now for me, in so wonderful company :) * r0rkty- (~h4x@ircop.bluehell.org) has joined #bhf so now, we get our JMP ESP/CALL ESP address so Aelphaeis the problem i was saying before is that you have EIP 41414141 you can be overwritting another registers too we need to find one, in Windows NT as I have probably mentioned before, the addresses are static (NO ASLR) so, no problems finding one correct, but that isn't important for this ok http://blackhat-forums.com/Aelphaeis/Findjmp2.exe Findjmp2 is a program written by Hat-Squad, for finding possibly locations to JMP to For those of you who remember a while back (when he was still releasing exploits) class101 was a member of Hat-Squad * r0rkty (admin@ircop.bluehell.org) Quit (Ping timeout ) find which dll? I believe he actually wrote the program of course not written the whole, but also he has optimized it the findjump tool mainly is developed by eEye and class101 has optimized it. dcboy I will get to that sorry~ for this example, we will use kernel32.dll everyone got findjmp2.exe ? yea * phetips (~phetips@bluehell-31B75992.upc-i.chello.nl) has joined #bhf yes yep lecture over? no no, phetips we are like half way through try turning the +m mode again... it was better that way... after you're done we can ask questions doesn't bother me sm atm, not too bad anyway okay i'll just sit and read than :) we will now use findjmp2 to find an address lol drag it into cmd and pass it the following arguments [+]0x77e7ae59 call esp is this? findjmp2.exe KERNEL32.DLL esp dcboy, for the last time don't go jumping ahead of us please sorry all of you should find an address 2 * SeventotheSeven nods Balgan what operating system and service pack do you have? 2 as well xp sp 2 Win xp SP2 same 0x7C81518B call esp 0x7C8369D8 call esp same as me 2 0x7C81518B call esp 0x7C8369D8 call esp 0x7C4FEDBB call esp ok, that seems to be different from mine, but anyway hmm how strange, i've got win xp sp2 and it only has one ok, I get the point now guys. For those of you who have different language Operating Systems I think the addresses will vary same with me D4rk ye mine is in PT the KERNEL32.DLL isn't the most reliable dll to look for addresses in. ou guys put 262 right ? yup you can use any windows system dll you want that is loaded in memory for example you can use ntdll.dll too, but of course it's not the case, so forget it for now. i put 264 0x7C81518B call esp 0x7C8369D8 call esp oh sorry that's exactly the same :) me 260 I just chose to use KERNEL32.DLL so we now need to format this address correctly and add it to our exploit so we can overwrite our EIP. ok Now the amount of A's in the skeleton of an exploit I gave you is 262 so please adjust it, to what you need * lightphoenix (~chatzilla@D58CE8C0.EC497771.38CE1736.IP) has joined #bhf now let's take Syn4ps3's address (one of his) and format is correctly 010x7C8369D8 call esp first one 7C 83 69 D8 D8 69 83 7C \xD8\x69\x83\x7C Is our return address, well Syn4ps3's return address anyway you should all format yours the same way I demonstrated * insanity (_th3-x@F88F3A20.8CE6CB0B.F175557F.IP) Quit (Quit: ) you all doing that now? yeah yes y done \x5D\x39\x82\x7C done \x33\x3A\x87\x7C Balgan, wtf do you mean y? because we fucking have to ok i guess he mean yes:D yes lol sorry Aelphaeis :{ lol ok, you confused me so now we put this into char ret[] i have one question: in exploit_b0f.c the overfolw[] 's A is 262 or 260? * Warpboy (~Warpboy1@bluehell-ACB9014E.carolina.res.rr.com) has joined #bhf 262 mine is: char ret[] = "\x5D\x38\x82\x7C"; dcb0y: you had to modify it according to however many bytes it took to overflow same here 262 dcboy thanks if it took you 264 characters to overflow it,.. you would put 260 262 for me too.. but some guys needed more correct dni like dni so you all formatted your return addresses correctly and added it to your exploit? yes yes yes yep yep yes yes ok, now time to add the NOPSLED char NOPSLED[] = "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"; we then add that NOPSLED to the variable exploit under the two strcat()'s I have put in the exploit put strcat(exploit, NOPSLED); that will append the NOPSLED after the return address everyone done that? yes yes yup yep No one having any problems? nope i have question tho why the 11 bytes of noslep ? just random ko ok in the both strcat()? I don't understand sm whats the lecture on I missed the start? strcat(exploit, overflow); strcat(exploit, ret); strcat(exploit, NOPSLEP); oh k thats how you should have it so far as dni just pasted Napster911: Topic: Win32 Stack Based Buffer Overflows done but let's shhhh and let them hax ^^ ok, now time for our shellcode now, in most exploits like this we can really use any shellcode we want, that has any payload but for this we are just going to use some small shellcode that spawns a message box you can find lots of them :) Aelph: size limitaion is an issue right ?? or code yourself dni: yes you can make em to too* i have question: how long this max shellcode? ahh, with this dni I found it is, but I also found that some of the shellcode from metasploit (generated) only sometimes worked, and sometimes didnt how max long of the shellcode can input in dcboy: i beleiv its the size of the buffer well, listen here no relation to program's buffer actually. But also it depends on our main "payload size". take a look here: strcat(exploit, overflow); strcat(exploit, ret); strcat(exploit, NOPSLEP); strcat(exploit, shellcode); (gonna add this line a bit later) well, if you look this lines carefully, you'll see the "exploit" array here. Anything related to our payload is added to this buffer. So we name the "exploit" array, our PAYLOAD-HOLDING buffer. this means that the exploit stuff (junk, jmp, nop, shellcode, .) is added to this array. so if our shellcode be too long to be hold by "exploit" array, our shellcode (and thus our exploit) will fail. thus if we exceed our payload buffer space, we will see a segmentation fault message and the shellcode execution is interrupted in the middle! * lightphoenix (~chatzilla@D58CE8C0.EC497771.38CE1736.IP) has joined #bhf anyway, you can get the shellcode we are using from here: http://blackhat-forums.com/Aelphaeis/Shellcode.txt buffer - EIP - SHELLCODE - RETURN i think ah yes shellcoding is funny on linux with polymorphic engine win32 Beep Shellcode (SP1/SP2) 35 bytes - may i use that? * SubSyn (~TcpSynAck@bluehell-I-NO7-1337.ur.berrylame.ru) has joined #bhf lol Fakep i was just looking at that well Aelphaeis u said a pop up message box so win32/xp sp2 Pop up message box 110 bytes should do the job ? fakep, the SP2 version of that has a NULL byte in it (I guess they expect you to encode it.) i guess i need to find some other for my 2k oh shit sm, just find another one quiclkly lol NULL byte, probl to scare off kiddies isn't the limit simply the memory allocated to the stack? since you're writing at the end of the stack yeah maybe D4rk, but I dont think so correct phetips yes now this shellcode will only work on Windows XP SP2, as the addresses the shellcode calls are different on different Windows branches (xp, 2000, 2003, etc)/Versions/Service packs/CPU-Architectures. you can add your shellcode to your exploit by doing char shellcode[] = "\x31\xc0\x31\xdb\x31\xc9\x31\xd2\xeb\x37\x59\x88\x51\x0a\xbb" "\x77\x1d\x80\x7c" //***LoadLibraryA(libraryname) IN WinXP sp2*** "\x51\xff\xd3\xeb\x39\x59\x31\xd2\x88\x51\x0b\x51\x50\xbb" "\x28\xac\x80\x7c" //***GetProcAddress(hmodule,functionname) IN sp2*** "\xff\xd3\xeb\x39\x59\x31\xd2\x88\x51\x06\x31\xd2\x52\x51" "\x51\x52\xff\xd0\x31\xd2\x50\xb8\xa2\xca\x81\x7c\xff\xd0\xe8\xc4\xff" "\xff\xff\x75\x73\x65\x72\x33\x32\x2e\x64\x6c\x6c\x4e\xe8\xc2\xff\xff" "\xff\x4d\x65\x73\x73\x61\x67\x65\x42\x6f\x78\x41\x4e\xe8\xc2\xff\xff" "\xff\x4f\x6d\x65\x67\x61\x37\x4e"; strcat(exploit, shellcode); of course strcat(exploit, shellcode); would be placed after strcat(exploit, NOPSLED); so that your shellcode is appended to your NOPSLED everyone done that? yep ye what about non sp2 users, screwed? yup find diff shellcode use different shellcode, you should be right as long as its small http://milw0rm.com/shellcode/win32 kk thanks i have one question: if the shellcode have \x00 how to do?? remove it? yeah, i remember reading null bytes in shellcodes are a no don't, you have to do tricks like xor instead of set to 0, etc ok``use XOR``` encode the shellcode ? or that yes you would encode your shellcode in order to get around the problem of a NULL byte of course there are ways around to avoid null bytes which can be discussed in the forums. but how to decode before exec it? Ok, run the exploit you have made and you should get the following: http://img470.imageshack.us/img470/8485/exploitworkz0rxl5.png So who's exploit works? * r0rkty- (~h4x@ircop.bluehell.org) Quit (Ping timeout ) don't work i 've tried blue beep sp1 one and it doesn't works not mine ( your exploit should of looked like this: http://blackhat-forums.com/Aelphaeis/exploit2.c exploit.cpp exploit.cpp(56) : error C2065: 'execve' : undeclared identifier C:\Documents and Settings\John Blaze\My Documents\0wn3d\C_stuff> mine works dni? WTF You werent meant to use execve you were meant to use WinExec() lol ^^ hmm i think i compiled the wrong exploit.c lol for me this is just the shellcode which sux brb * SeventotheSeven (~seven@seven.to.the.seven) Quit (Ping timeout ) WinExec() is defined in windows.h btw dni, you should of used my exploit_b0f.c as a skeleton no window message for me, yet some directions to it C:\DOCUME~1\Dark\Escritorio>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA]9é|???????????1+1¦1+1??7YêQ +w??|Q ??9Y1?êQ?QP+(¼?| ??9Y1?êQ?1?RQQR ?1?P©?-ü| ??- user32.dllN?- MessageBoxAN?- Omega7N well it seems D4rk, it has jumped to the correct place, just hasnt executed the code yeah, wierd isn't it it is possible as I said, that your version of Windows has the addresses at a different location in memory therefore the shellcode doesn't work 4[ D4rk 4] just probe with diferent number of A's and it still works :) hmm let me check the addresses with arwin but without the messages no wait D4rk sorry, you may not have done it correctly mine goes same way has Dark D4rk i mean * SeventotheSeven (Seventothe@seven.to.the.seven) has joined #bhf mine = * BHF sets mode: +h SeventotheSeven nothing happened for me but i noticed something D4rk ur windows is in PT or Brazilian ? coz of C:\DOCUME~1\Dark\Escritorio * z0r (~pruebas@bluehell-8FD5E1B4.red-62-57-233.user.auna.net) has joined #bhf hi there ahh lol, its spanish ye it might have to do with that Well if you guys did everything correctly and your OS is Windows XP SP2 English it should of worked im checking the addresses since mine is in PT the addresses are not case sensitive, but the commands are i'll move to a diff dir and try again what's strange is that i've tryied omega7's shellcode before and worked good one with shorter address * matsch (~matsch@bluehell-8B7F4498.cable.fcom.ch) has joined #bhf gd mornig from switzerland good morning, the lecture is currently going on, so please be quiet * z0r (~pruebas@bluehell-8FD5E1B4.red-62-57-233.user.auna.net) Quit (Quit: z0r ) ok, well for those of you who have the appropriate software plus hardware that doesn't support DEP, or have DEP turned off it should of worked if you did it correctly For the purpose of this lecture (at the moment) we will not weed through and try and find out what you did wrong all of you now have a good grasp of how to exploit a stack based buffer overflow (assuming everything goes right) ? yup everythings find.. just need to find some shellcode:D Aelphaeis can u plz take a quick look see if i made everything right http://clientes.netvisao.pt/mariavas/myexploit.c fine* Balgan please leave it till the end of this lecture yes ok Aelphaeis now as I said, you should all have a good grasp of it now moving onto the next subject Protection Schemes and Limitations First some basic limitations didn't work ( obviously there is a limit to the shellcode you can use based on size 1 I know fakep, just wait ok A smart thing to do may be to store your NOPSLED + Shellcode inside another variable then redirect the program flow to taht * insanity (_th3-x@FAA89349.37D30F16.F175557F.IP) has joined #bhf the location of the NOPSLED should be visible in ollydbg if you know where to look shellcode cannot contain NULL bytes, as you guys should know any shellcode that does would have to be encoded before it could be used For those of you wanting to know where to get usuable shellcode, http://metasploit.com:55555/PAYLOADS You can use metasploits shellcode generator, you can tell the generator which sort of characters are not allowed Obviously, 0x00 would not be allowed (NULL byte) and of course with certain protocols there would be certain characters you would not be able to use generally, in some protocols some characters has a special means. We name them "Bad Characters". For example in ftp protocol the 0x20 character is a bad character so that it can't be used in the shellcode and the protocol treats them in a different way (it's used as blank-space.. and in ftp applications, it represents the termination of a string) Thus your shellcode execution will be stopped. * r0rkty (~h4x@ircop.bluehell.org) has joined #bhf * dcboy (~szdcboy@EAE3BC56.AD403039.C232DFAA.IP) Quit (Ping timeout ) * SubZ (~U2FsdGVkX@netadmin.bluehell.org) has joined #bhf * BHF sets mode: +v SubZ As far as protection schemes go, there are many different protection schemes For those of you wanting to venture into Linux exploitation, I will tell you (you will need to know this) since (from memory) the 2.6.12 or 2.6.11 Linux kernel, ASLR is implemented by default that is the addresses in memory are randomized, they are not static so this can pose a big problem when it comes to exploitation of course this can be bypassed because there are areas in memory in Linux which are static, one of which has a JMP ESP xD Another probably more serious and hard to bypass protection is DEP ah you and your memory hacking ;P (ASLR=>Adress Space Layout Randomization) Data Execution Prevention support for DEP was added into Windows XP when SP2 came out and into Windows Server 2003 as of Service Pack 1 * dcboy (~szdcboy@EAE3BC56.AD403039.C232DFAA.IP) has joined #bhf http://opcodes.free.fr/tmp/randomized_stack.txt <- look on linux DEP is a technology on most 64 bit CPU's that marks areas's of memory as non-executable Thank you santabug as I said earlier, there are areas in memory in Linux that are static now, DEP isn't 100% effective Aelph: not working for me dude i compiled * sarkar112 (~sarkar112@bluehell-C612ADDB.nycap.res.rr.com) has joined #bhf and i run it,. but i never get the winpopup first, who here remembers that WMF exploit that came out a while ago me me ok dni, but as I said, will help ya out later haha i remember * SeventotheSeven (Seventothe@seven.to.the.seven) Quit (Ping timeout ) so everyone please stfu ok no one else remembers? me the one few months ago? i do yes sm I believe it was k maybe a bit further back, I can't remember DEP didn't protect against that exploit Aelphaeis is the lecture already over ? no * SeventotheSeven (~seven@seven.to.the.seven) has joined #bhf * BHF sets mode: +h SeventotheSeven the reason being is that for some reason there was an area in memory that has READ, WRITE, EXECUTE permissions * LiquidWorm (~jox@7084D5A4.85A73766.880F58B.IP) Quit (Ping timeout ) lol * nic` (0wnage@i.laid.your.sister.with.a.broken.c0nd0m.us) Quit (Ping timeout ) DEP can be theoritically bypassed by calling a function in windows (forget the name off the top of my head) and allocating memory that has EXECUTE permissions and storing your shellcode in there * LiquidWorm (~jox@7084D5A4.85A73766.880F58B.IP) has joined #bhf of course this is pretty complicated Another protection mechanism used by Microsoft is the /GS Flag which is turned on by default in MSVC++ 2003 it places what is called a canary before the EIP in memory if the canary is overwritten when the application returns (from memory) the program will simply crash not allowing hijacking of the EIP. there are other protection mechanisms that are similar, that are patches for the gcc compiler many of these can be bypassed, but of course this is beyond the scope of this lecture For more information aboit MSVC++ 2003 protection mechanism : www.ngssoftware.com/papers/defeating-w2k3-stack-protection.pdf can i ask one question>? what was in SP0 I believe they fixed that in SP1 k see their protection mechanism in their compiler when they first released it was flawed David Litchfield discovered that they used their compiler (when it was "broken") to compile Windows Server 2003 SP0 and therefore the protection mechanism on Windows Server 2003 SP0 could be bypassed * dcb0y (~szdcboy@4F81535B.C351D3EE.C5C0FE80.IP) has joined #bhf *pretty much everyone buffer overflow protection scheme released can be bypassed some how* of course alot of them limit what you can do, and make exploitation a hell of alot harder The only reason protection against stack based buffer overflows is for programmers to right secure code. I will not bother covering this, as this isn't part of the lecture. and I won't gain anything from teaching people how to write secure code xD lol yes of course, those of you who understand how the vulnerability occurs could surely figure out how to write relatively secure code at least when it comes to stack overflows * dcboy (~szdcboy@EAE3BC56.AD403039.C232DFAA.IP) Quit (Ping timeout ) i have question THIS ENDS THIS IRC LECTURE wait god damnit Time: 12:07 Perth, Western Australia Greetz To htek, FRSilent, Read101, nic`, BSoD, r0rkty/John h4x, SyS64738, morning_wood, SysSpider, fritz, darkt3ch, SeventotheSeven, Predator/ill skillz, BioHunter, Digerati, butthead, PTP, felosi, wicked/aera, spiderlance, sNKenjoi, tgo, melkor, mu-tiger, royal, Wex, ksv, GoTiT4FrE, D4rk, muon, drygol, santabug, skvoznoy, SuicidalManiac, theNerd, CKD, dlab, snx, skiddieleet, ProwL, Edu19, drygol, kon, RedemptiX, dni, belgther, deca, icenix, j0sh, werx, oHawko,Cephexin/Cefixim, FLX, kingvandal, illbot, str0ke and Kenny, Blake & Stephen from GSO. # milw0rm.com [2007-01-29]