+ All Categories
Home > Documents > Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Date post: 28-Sep-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
37
Bruce Dang Secure Windows Initiative (SWI) Microsoft 9/23/08 Bruce Dang | [email protected] | Secure Windows Initiative | Microsoft 1
Transcript
Page 1: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

BruceDangSecureWindowsInitiative(SWI)Microsoft

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 1

Page 2: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Introduction Officebinaryfileformat(<=2003) Bugs Defensivemechanisms Exploitstructures Analysistechniques Detectionmechanisms Thesurprise… Patchprocess(end‐to‐end)9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 2

Page 3: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Targetedattacks Verypopularinthelastcoupleyears Bypassesperimetersecuritydevices/software Difficulttodetect Notechnicalinformationinthepublic

Therearethingsyoucandotomitigateandstopmostoftheattacks.

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 3

Page 4: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

StructuredStorage/OLESS Filesysteminsideabinaryfile Dividedataintostorageandstreams(storage=directory,stream=file)

12‐pagespecification Application‐specificdatastoredinsidestorage/streams.

Canbefrustratingtoparsemanually

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 4

Page 5: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

StgOpenStorage()onthefile.YougetbackanIStorageobject.

IStorage‐>EnumElements()enumeratesallofthestoragesandstreams.

IStorage‐>OpenStream()opensupwhateverstreamyouwant.ReturnsanIStreamobject.

IStream‐>Stat()tellsyouthestreamsize. IStream‐>Read()readsnbytesfromthestream.

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 5

Page 6: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

HRESULT hr;IStorage *is;IStream *stream;IEnumSTATSTG *penum;STATSTG statstg;StgOpenStorage(L“foo.ppt", NULL, STGM_DIRECT |

STGM_READ | STGM_SHARE_EXCLUSIVE, NULL, 0, &is);is->EnumElements(NULL, NULL, NULL, &penum);hr = penum->Next(1, &statstg, 0);while( hr == S_OK) {

wprintf(L"name = %s\tsize = 0x%08x\n”,statstg.pwcsName, statstg.cbSize);

...is->OpenStream(statstg.pwcsName, NULL, STGM_READ |

STGM_SHARE_EXCLUSIVE, 0, &stream);stream->Read(data, statstg.cbSize, NULL);... parse data ...

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 6

Page 7: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Abitsimpler.Goodforexperiments.from pythoncom import *ostore = StgOpenStorage(sys.argv[1], None, 0x10, None, 0)estat = ostore.EnumElements()str = estat.Next()while str != ():

if str[0][0] == "PowerPoint Document":len = str[0][2]

str = estat.Next()ostream = ostore.OpenStream("PowerPoint Document", None,

0x10, 0)data = ostream.Read(len)...parse data...

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 7

Page 8: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Storesdatainthe“PowerPointDocument”stream.OpenStream(L“PowerPoint Document”, ...)

TwotypesofPowerPointdatastructures Container–a“directory”▪ Containsothercontaineroratoms.

Atom–a“file” RecordsfollowTLVstyle MSOobjectsfollowthesameformat

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 8

Page 9: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

1structtorulethemalltypedef struct{ uint2 recVer:4; uint2 recInstance:12; uint2 recType; uint4 recLen;} PPTRHDR_t;

IfrecVer=0xF,thentherecordisacontainer;else,itisanatom

recTypereferstotherecordtype.Thereare~100oftheseinPowerPoint.Youcanlookthemupthefileformatspecification.

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 9

Page 10: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 10

typedef struct{ uint2 recVer:4; uint2 recInstance:12; uint2 recType; uint4 recLen;} PPTRHDR_t;

Page 11: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 11

Page 12: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 12

*Datafromthestream*

Documentcontainer

Documentatom

Slidecontainer

Slidecontainer

UserEditAtomatom(usuallylast)

1slidecontainerperslide

Environmentcontainer

Page 13: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Dataisstoredinsidethe“Workbook”stream Nocontainers/atoms.JustplainBIFFrecords. BIFFrecordsalsofollowTLVformat Recorddatahasanupperboundof~2000‐8000bytes(BIFFversiondependent).Iflonger,useaCONTINUErecord

Datainsidethe“Workbook”streamisorganizedlike:BOF<data>EOFBOF<data>EOFBOF<data>EOF…

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 13

Page 14: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Nothingoutoftheordinary:integerover/underflow,off‐by‐one,doublefree,uninitializedvariables,badpointerreuse,stack/heapoverflow,…

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 14

Page 15: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 15

Page 16: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

UseMOICE Free ItrequiresOffice2003 ItonlyworksonOLEstructuredstoragefiles ItusestheOffice2007compatibilitypack ItconvertsyourbinaryfileformattothenewXMLformatandopensitup

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 16

Page 17: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Office2003SP3 Free Resultofamajorsecurity/SDLpush IfyouhadOffice2003SP3,thenyouwouldnotbeaffectedbyanyoftheOfficezero‐daysacknowledgedinthepublicsince.

IfyouhaveOffice2003,installSP3

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 17

Page 18: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Office2003SP3andMOICEactuallyeliminates/mitigatesmostoftheOfficevulns.

Alwayshavethelatestpatches.

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 18

Page 19: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

UseOffice2007

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 19

Page 20: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Notoutoftheordinary Basicstructure

Shellcode Malware Cleandocument

Techniques

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 20

Page 21: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 21

Everythingisincludedinthedocument Therecanbevariations

Multipleshellcodestages Multipletrojans Obfuscationoftrojans/doc

Page 22: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Techniques StandardGetEIP/PIC Customencoders PEBretrieval Filehandlebruteforce Applicationrelaunch

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 22

Page 23: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Whyfilehandlebruteforce? Exploitmustfinditselfinmemory(thisisnotthesameasGetEIP)

Exploitcannotsimplyscantheentireprocessaddressspacelookingforitself(speed)

Veryeasy/shortimplementationinassembly.It’sliterally:int fh;for (fh=0; fh < 65536; fh += 4){

if (GetFileSize(fh, NULL) == mysize) return fh;}

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 23

Page 24: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Whatitdoes(therecanbevariations) Shellcodedecodesitselfandruns Buildsupalistoffunctionpointers Findsitselfinmemory(filehandle) Readdatafromspecificlocationsinthefile Extractthetrojanandthecleandocument Runthetrojanandrelaunchtheapptoopenthenewfile

Exitthecurrentprocess SetFilePointer,ReadFile,WriteFile,CloseFile,WinExec,ExitProcess.

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 24

Page 25: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Tools Hexeditor Disassembler Optional:Debugger(WinDBGissufficient)

Objectives Identifytheshellcode Understandit Extractthemaliciouscomponents [Identifytheexactvuln]

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 25

Page 26: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Howmanydoyourecognize? EB 10 5B 4B 33 C9 66 B9 96 03 8034 0B FD E2 FA EB 05 E8 EB FF FFFF

64 A1 30 00 00 00 64 8B 1D 30 00 00 00 D9 74 24 F4

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 26

Page 27: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

DebugDOC/XLS/PPT? Staticmethod

Decodetheshellcodeandreadit Dynamicmethod

Abitmoreinteresting

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 27

Page 28: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Method1 Identifytheshellcode,patchthefirstfewbytesto0xCC

StartupOffice,attachWinDBGtoitand‘g’ Openupthedocument Ifyoudiditright,youshouldhittheint 3 andthensinglestepasneeded.Ifnotthenyouprobablygotinfected.

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 28

Page 29: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Method2 Pickananyexecutable Copytheshellcodeandputitinthebinaryandseteipthere.

Singlestepjustlikeanyanexecutable.

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 29

Page 30: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Method3 Savethefile,i.e.,“c:\temp\sc.bin” Openupnotepad.exe,calc.exe,whatever. AttachWinDBGtoit. .dvalloc<sizeofsc.bin> .readmemc:\temp\sc.binaddr<sizeofsc.bin> Realshellcodeaddress=<addr+scoffset> reip=<addr+scoffset>;t(not‘g’)

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 30

Page 31: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 31

Page 32: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Method4(bestone) Savethefileas“c:\temp\sc.bin” Openthefileinaneditor(notepad,vim,…);anythingthatopensthefile.

AttachWinDBGtoit. .dvalloc<sizeofsc.bin> .readmemc:\temp\sc.binaddr<sizeofsc.bin> Realshellcodeaddress=<addr+scoffset> reip=<addr+scoffset>;t(not‘g’)

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 32

Page 33: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

YouneedtobeabletofingerprintanOLEstructurestoragefile D0 CF 11 E0 A1 B1 1A E1

Getthestreamnametodeterminethefiletype(DOC,PPT,XLS)

Readthestreamcontentandparseitasweshowedearlier

Determinewhatrecordsareaffectedanddetectthem

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 33

Page 34: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

WereleasedthefileformatspecificationsforDOC,XLS,PPT,andMSO http://www.microsoft.com/interop/docs/OfficeBinaryFormats.mspx

Giventheinformationhereandthosespecifications,youcanactuallywritecodetoparseandcheckthevalidityoftherecords.

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 34

Page 35: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

TowritegoodIDS/AVsignatures,youusuallyhavetounderstandthevulnerabilities. Reverseengineerthepatches Wewillgiveyouthevulnerabilitydetails

MAPP(MicrosoftActiveProtectionProgram)

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 35

Page 36: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Informationavailableat5pmPSTMonday Whatisincluded?

Atechnicaldescriptionofthevulnerability Areprofile/packettrace Crashdump/stacktrace/disassembly Detectionlogic

Howtogetthedata?

9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 36

Page 37: Bruce Dang Secure Windows Initiative (SWI) Microsoft · Introduction Office binary file format (

Myteam’sblog(SWIblog):http://blogs.technet.com/swi Wetalkaboutvulnerabilitydetailsthere Itiswrittenbypeoplewhotriagethevulnerability

[email protected] GotinterestingOfficesamplesandwantsomehelpintriagingthem?Sendthemtous.

Myemail:[email protected] 0x3f…9/23/08 BruceDang|[email protected]|SecureWindowsInitiative|Microsoft 37


Recommended