{% extends "introduction/base.html" %} {% load static %} {% block content %} {% block title %}
This lab helps us to understand how command injection is exploitable in scenarios where inputs are sent
to exec,eval,sys etc.
The user on accessing the lab is provided with a feature to perform a name server lookup on the given
domain.
A domain name has to be provided after which the server would perform a ns lookup and return back to the
client.
If the user is running the lab, based on the OS they can select Windows or Linux.
Exploiting the Bug
domain && [any cmd]google.com && dir and choose windows.dirdomain; [any cmd]google.com; dir and choose windows.dir
Lets first see how the name server lookup is performed
command="nslookup {}".format(domain)
Here the domain is the user input domain. This command variable is then sent to exec function and the
output is displayed.
If the user inputs google.com the command variable will hold nslookup google.com.
How CMD injection works
Method 1
Now when the user enters google.com && dir The command variable will hold
nslookup google.com && dir.
The && means and.
The system will execute nslookup google.com
first and then dir
Method 2
When the user enters google.com ; dir The command variable will hold
nslookup google.com ; dir.
The ; implies the completion of the command before it, in this case the nslookup
command.
The system will execute nslookup google.com first and then dir