Filter Evasion

Filter/WAF Detection

We can see that if we try the previous operators we tested, like (;, &&, ||), we get the error message invalid input:

If the error message displayed a different page, with information like our IP and our request, this may indicate that it was denied by a WAF.

Identifying Blacklisted Character

We know that the (127.0.0.1) payload does work, so let us start by adding the semi-colon (127.0.0.1;):

Bypassing Space Filters and Spaces

Using Tabs

Using tabs (%09) as both Linux and Windows accept commands with tabs between arguments. So, let us try to use a tab instead of the space character (127.0.0.1%0a%09) and see if our request is accepted:

Using $IFS

Using the ($IFS) Linux Environment Variable may also work since its default value is a space and a tab. So, if we use ${IFS} where the spaces should be, the variable should be automatically replaced with a space, and our command should work.

Let us use ${IFS} and see if it works (127.0.0.1%0a${IFS}):

Using Brace Expansion

By using brace expansion on our command arguments, like (127.0.0.1%0a{ls,-la}). To discover more space filter bypasses, check out the PayloadsAllTheThingsarrow-up-right page on writing commands without spaces.

Bypassing Other Blacklisted Characters

Linux

Get a slash (/):

  • The $PATH variable usually starts with /, e.g., /usr/local/bin:/usr/bin:/bin.

  • So ${PATH:0:1} extracts the first character, which is /.


Get a semi-colon (;):

  • The $LS_COLORS variable often includes formatting values like di=01;34:, and the ; appears early in the string.

  • So this substring gives you a ;.


Get a space:

  • ${IFS} stands for Internal Field Separator.

  • By default, this is a space in Bash.

PoCs - Questions

Use what you learned in this section to find name of the user in the '/home' folder. What user did you find?

In this case, first we need identificate the command injection, we need try all simple and encoder characters -->

The I can see, with the character "%0a" == New Line == \n with out encode, the peticion found

Now we need go to the /home directory, we can do it out too methods

Method 1 - Path Traversal:

The with "&0a" we can put a command, for example, "ls" and it print the current directory, and we can too write anothers metods for do a path traversal, the objective is to make == "ls ../../../home" but it, block the backend. We can use operators:

Method 3 - Command Ejecution

We can use a similar method with too ${PWD:0:1}

Bypassing Blacklisted Commands

Commands Blacklist

A basic command blacklist filter in PHP would look like the following:

Linux & Windows

if we want to obfuscate the whoami command, we can insert single quotes between its characters, as follows:

The important things to remember are that we cannot mix types of quotes and the number of quotes must be even. We can try one of the above in our payload (127.0.0.1%0aw'h'o'am'i) and see if it works:

Windows Only

PoCs - Questions

Use what you learned in this section find the content of flag.txt in the home folder of the user you previously found.

Use the begains techniques, we can found the flag.txt into the 1nj3c70r directory:

Now, we need only read it -->

Advanced Command Obfuscation

Case Manipulation

Reversed Commands

Encoded Commands

Tip: Note that we are using <<< to avoid using a pipe |, which is a filtered character.

Evasion Tools

We can start by simply providing the command we want to obfuscate with the -c flag:

PoCs - Questions

Find the output of the following command using one of the techniques you learned in this section: find /usr/share/ | grep root | grep mysql | tail -n 1

We need encode first the payload: echo -n 'find /usr/share/ | grep root | grep mysql | tail -n 1' | base64 then, use the malicuos payload and add into spaces %09

Last updated