![]() |
|
[For beginners] Shellcode Encryption and Why? | Static Scan Evasion - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Hacks, Exploits, and Various Discussions (https://hackforums.net/forumdisplay.php?fid=45) +--- Forum: Blackhat • Red Team • Offensive Security (https://hackforums.net/forumdisplay.php?fid=447) +---- Forum: Cryptography, Encryption, and Decryption (https://hackforums.net/forumdisplay.php?fid=126) +---- Thread: [For beginners] Shellcode Encryption and Why? | Static Scan Evasion (/showthread.php?tid=6258912) |
[For beginners] Shellcode Encryption and Why? | Static Scan Evasion - Tentco - Dec 19, 2023 Usually while using certain shellcode loader or Cobalt Strike beacon loaders, you might've noticed they are usually encrypted with various Encryptions, for eg - AES, XOR, RC4/5, Base64 etc... question is Why? The answer is quite simple we encrypt the raw shellcode to evade/bypass shellcode signature. Note - This will somewhat work on weak memory scanners, since this is only suitable for entropy hiding and static detection evasion, since you will need to decrypt it sometime in memory. There's not much about this topic, you can use any sort of encryption, recommended to use AES. XOR - A key is chosen and used to XOR each byte of the shellcode. To decrypt the shellcode, the same key is used to XOR each byte again, which reverses the encryption and recovers the original shellcode, this encryption is not strong. There're tons of Encrypters available on Github, so I won't discuss about them here. For XOR, https://github.com/DcardosoGH/ShellCode-Encrypt Usage is quite simple generate your shellcode(.bin) -> Encrypt it -> Add the generated key and shellcode encrypted bytes/data into your program, don't forget to use Runtime string obfuscation on your decryption key like SkCrypt or XorStr. Code char key[] = "Your Key";The decryption routine in this program performs an XOR operation on each byte of the encrypted shellcode using a secret key. The routine uses a for loop with an index variable i to iterate through each byte of the encrypted shellcode. The index variable k is used to access each byte in the key array. If k reaches the end of the key array (indicated by k == sizeof key - 1), it is reset to 0. This ensures that the process of combining the encrypted shellcode with the key can continue indefinitely. The result of the XOR operation is stored in a new character array shellcode_decrypt, which is a decrypted version of the original encrypted shellcode. The routine is somewhat same for AES, take encrypted shell code, decrypt It and allocate into a process’s virtual address space. You can find various encryption and loaders template on Github about this too, same goes for RC4 and vice-versa. Bonus - We can manually add some junk instruction in our shellcode, let's see how. 1. Using Ndisasm to get instructions format out of our shellcode alternatively use https://defuse.ca/online-x86-assembler.htm#disassembly2 for your shellcode bytes. 2. Code cldAdding junk instructions like nop and mov eax, eax that does nothing but server as placeholders are useful as they can avoid sig scan, you can easily write a program that does so, after that re-encrypt your shellcode and use it again. In the next thread if I've time we will discuss about analyzing some samples using encrypted shellcode. Again, shellcode encryption is nothing heavy just a light term for basic static scan evasion. Keep in mind to, Encrypt your decryption key. You can also decrypt the shellcode for a fraction of time and encrypt it back again. RE: [For beginners] Shellcode Encryption and Why? | Static Scan Evasion - BiNBo - Dec 19, 2023 A wonderful guide and explanation, I would love to see more content like this in this sub-forum! Thank-you! RE: [For beginners] Shellcode Encryption and Why? | Static Scan Evasion - Nightmare - Dec 19, 2023 HQ!! Whenever i see Tentco creating a thread i know it is HQ!!Thank you for this great Info! RE: [For beginners] Shellcode Encryption and Why? | Static Scan Evasion - Euaggelistes - Dec 19, 2023 Thank you so much for providing this information! Please keep up the great work. RE: [For beginners] Shellcode Encryption and Why? | Static Scan Evasion - osn64698 - Dec 19, 2023 Good tutorial, A few suggestions: 1. Code char key[] = "Your Key";The if logic can probably be replaced by a simple (++k % sizeof(key - 1)) 2. Junk code wise, you can also push registers into the stack, save them, and recover later on, this gives a lot more control then simple "NOP" and "MOV EAX,EAX". BUMP - Stanley - Dec 25, 2023 I'm Stanley HF's helper bot. The OP (original poster) of this thread wants everyone to see this page and has elected to bump it to the top of the showthread listing. Since HF doesn't want a ton of LQP (Low Quality Posts) this is the best method of bumping your content. There is a small βyte fee for each bump. Any OP can bump any of their threads on HF from the linked icon on the top of their first post. If you haven't already read the first post of this thread we encourage you to do so. Thanks, Stanley |