Method of injection mitigation is utilizing blacklisted characters + words on the backend to detect injection attempts and deny the request if any request contained them. On top of this, WAFs apply here too, and may have a broader scope + various methods of injection detection to prevent various other attacks like SQLi or XSS.
Command injection Filter/WAF Detection

Let's attempt a simple command injection here with BURP.
To review, front-end (easily bypassed) detection looks like this: 
With WAF/ filter applied we get error text like the following: 
- indicates something in the request triggered a security mechanism (or some other mechanism aside from the frontend validation)
- err could be displayed in various ways, in this case we rendered in the browser it's displayed in the field output would typically be returned
- this means it was detected + prevented by the PHP webapplication itself
- If the error msg displayed a different page, with information like our IP and our request, this may indicate it was denied by WAF!
- this means it was detected + prevented by the PHP webapplication itself
- It's likely the webapplication detected a blacklisted character, or command.
Bypassing blacklisted operators
In our example %0a (the newline character) isn't blacklisted, as it may be needed in the payload itself.
We know new-line chars work to append commands in both linux/windows. Let's use it as our injection operator.

However:

Spaces are often blacklisted!
This is the same behavior if we only specify 127.0.0.1%0a+ using + as a space.
In such a scenario, Tab character can be used instead.
- both linux / win accept commands with tabs btwn args and they are executed the same.
Tab Url-encoded:
%09

In Linux the $IFS env var may also work, its' default value is a space and a tab, which would work between command args.
If we use ${IFS} where the spaces should be, the variable should be automatically replaced with a space and our command would work.
127.0.0.1%0a${IFS}
Brace Expansion
Many other ways to bypass space filters. Bash Brace Expansion is another method. It automatically adds spaces between arguments wrapped between braces. for example:
{ls,-la} executes ls -la without spaces. we can use the same method for cmd injection filter bypasses.
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Command%20Injection#bypass-without-space 
Other blacklisted characters
Very commonly blacklisted characters also include / and \
- necessary to specify directories in both linux/windows
- several techniques can be used to produce any character we want while avoiding the use of blacklisted chars
LINUX EX1)
- Replacing slashes, or any other character is through linux env vars like we did with
${IFS}- While IFS replaces with space, there's no such env var for slashes or semicolons. However these chars may be used in an envvar and we can specify start/length of our string to exactly match this character.
- Take for example the
$PATHenvvarecho ${PATH}->/usr/local/bin:/usr/bin:/bin:/usr/games- If we start at
0index and only take length of 1 we end up with/which we can use in payload. echo ${PATH:0:1}prints ->/
- The same general practice applies to all other envvars.
$HOMEand$PWD
- For a semi-colon:
echo ${LS_COLORS:10:1}->;
So, let's try to use environment variables to add a semi-colon and a space to our payload (127.0.0.1${LS_COLORS:10:1}${IFS})
(it works protip)
Windows
The same exact concept works in Windows.
i.e.
echo a Windows var %HOMEPATH% -> \Users\htb-student
Specify starting position and negative end position.
echo %HOMEPATH:~6,-11%
Above is in a command prompt. Same applies to powershell.
$env:HOMEPATH[0] -> \
$env:PROGRAMFILES[10] -> (space char)

PS get-childitem
Get-ChildItem Env: returns all environment variables + picks one of them to produce a character we need.
Character shifting to bypass character blacklisting
In linux, the following command shifts the character we pass by 1.
echo $(tr '!-}' '"-~'<<<[)
Validate this with man ascii
- the character
\is on92; before it is[on91

Able to use powershell to achieve this same result in Windows though the command may be quite longer than linux
All of the above put together to find the name of the user in /home directory:
