Preventing the use of a web shell once installed is extremely difficult, if not impossible, so prevention should focus on avoiding vulnerabilities that allow attackers to install web shells in the first place. The best way to avoid web shells is therefore to systematically find and eliminate all common web vulnerabilities that could allow for an initial attack, including RCE, LFI, RFI, SQLi, and XSS vulnerabilities.
Find out how to use Invicti to prevent web vulnerabilities.