Finally, I saw a video of Muts running through the process of creating a code cave to hide code and bypass AV. I think it was called something like "I'll piss on your AV" (no offense intended to anyone!). He used ncx99.exe, as demonstrated in your second link.
They actually incorporated that into the OSCE course... The problem with the code cave is that a lot of the AV vendors will pick up the "stub" but there are ways around that too!
Just use your own implementation of the code cave and the "stub", don't use exactly the same as shown during the CTP course.
Also, creating a new section within an exectuable / PE file, can has it ups and downs.
Try adding your stub to already existing space within e.g., the main segment if possible, and make damn sure you change the flags to what you require as well.
(If you add executable code, into a segment that does not contain executable code, you need to make that segment executable, which could have some strange outcome as well, but it can work.)
If your stub is trying to decode a segment, which does not have write permission but only read and execute, then it should not be possible either, and you will most likely get an access violation error. Easy to fix, make that segment writeable
It's a few common mistakes. Another important thing is to make sure that all instructions you overwrite, are re-introduced later on and that the stack appears to the same as it was to begin with. Better safe than sorry in the long run if you're modifying a file heavily.
If you use some sort of encryption scheme where you ship the encryption key with the file, some AV's will not detect the file until you run it, and that's where heuristic detection comes into play, which is a bit harder to bypass.
How could you bypass an AV-scanner, that looks for certain calls in memory? Fool the AV to believe it's a legit file, perhaps a Windows file. That is one way