Table of Content
- Introduction
- Learning Objectives
- Room Prerequisites
- Prerequisites Done ✅
- Basic System Information
- Network Troubleshooting
- Files and Disk Management
- Task and Process Management
- Conclusion
Introduction
Everyone prefers a graphical user interface (GUI) until they master a command-line interface (CLI).
There are many reasons for that. One reason is that GUIs are usually intuitive. If someone offers you a GUI interface you are unfamiliar with, you can quickly poke around and discover a non-trivial part. Compare this with dealing with a CLI, i.e., a prompt.
CLI need to have a learning curve; however as u master the CLI its the most efficient way to do a work, for and example how many click do u need to view the IP address? u can view IP address using CLI with one word and enter.
There are many other advantages to using a CLI besides speed and efficiency. We will mention a few:
- Lower resource usage: CLIs require fewer system resources than graphics-intensive GUIs. In other words, you can run your CLI system on older hardware or systems with limited memory. If you are using cloud computing, your system will require lower resources, which in turn will lower your bill.
- Automation: While you can automate GUI tasks, creating a batch file or script with the commands you need to repeat is much easier.
- Remote management: CLI makes it very convenient to use SSH to manage a remote system such as a server, router, or an IoT device. This approach works well on slow network speeds and systems with limited resources.
Learning Objectives
The purpose of this room is to teach you how to use MS Windows Command Prompt cmd.exe
, the default command-line interpreter in the Windows environment. We will learn how to use the command line to:
- Display basic system information
- Check and troubleshoot network configuration
- Manage files and folders
- Check running processes
Room Prerequisites
Before starting this room, you should have finished the Windows and AD Fundamentals module.
Prerequisites not met lol, gotta do the Windows and AD Fundamentals and come back xD Here is theWindows and AD Fundamentals >>>
Prerequisites Done ✅
You can use the SSH client on the AttackBox to connect to MACHINE_IP
with the following credentials:
- Username:
user
- Password:
Tryhackme123!
Establishing an SSH Connection from the AttackBox
If this is the first time you initiate an SSH connection from the AttackBox to a target system, the steps are shown in the screenshot below, and they are the following:
- Start the AttackBox’s terminal by clicking the terminal icon marked with 1.
- To connect to the target VM, issue the command
ssh user@MACHINE_IP
asuser
is the username in this case. - Because this is your first time connecting to this target VM, you will be asked to trust this connection. Answer with yes as marked with 3.
- Enter your password
Tryhackme123!
. Please note that the password will not appear as you type it.
Questions
- What is the default command line interpreter in the Windows environment?
- cmd.exe
Basic System Information
set
Understanding the Path
Environment Variable in Windows
The Path
environment variable in Windows tells the system where to look for executable files when you run a command in the terminal. If a command or program isn’t in one of the directories listed in the Path
, Windows won’t recognize it unless you provide the full path.
How It Works
- When you type a command (e.g.,
python
), Windows looks in the directories listed in thePath
environment variable, in the order they appear. - If the executable file (e.g.,
python.exe
) is found, the command runs. - If it’s not found, you get an error:
Viewing the Path
You can use the set
command to view your current Path
:
Adding to the Path
Temporary (Current Session Only)
You can add a directory to the Path temporarily: set Path=C:\MyCustomDir;%Path%
Permanent
To make the change permanent, use the setx command: setx Path "C:\MyCustomDir;%Path%"
Why is the Path Important?
Without the correct directories in the Path, you would need to type the full path to run programs. For example:
With C:\Python39 in the Path, you can just type:
ver
Let’s use the ver
command to determine the operating system (OS) version. The terminal below shows an example output.
systeminfo
We can run the systeminfo
command to list various information about the system such as OS information, system details, processor and memory. The terminal below shows a snippet of the displayed output.
Tips
Before moving on, it is good to mention a couple of tricks.
First, you can pipe it through more
if the output is too long. Then, you can view it page after page by pressing the space bar button. To demonstrate this, try running driverquery
and compare it with running driverquery | more
. In the latter, you can display the output page by page and you can exit it using CTRL + C
.
help
- Provides help information for a specific commandcls
- Clears the Command Prompt screen.
Questions
- What is the OS version of the Windows VM?
- 10.0.20348.2655
- What is the hostname of the Windows VM?
- WINSRV2022-CORE
Network Troubleshooting
Most of us are used to looking up MS Windows network configuration from the GUI interface. The command-line interface provides many networking-related commands to look up your current configuration, check ongoing connections, and troubleshoot networking issues.
Network Configuration
You can check your network information using ipconfig
. The terminal output below shows our IP address, subnet mask, and default gateway.
You can also use ipconfig /all
for more information about your network configuration. As shown in the terminal below, we can view our DNS servers and confirm that DHCP is enabled.
Network Troubleshooting
One common troubleshooting task is checking if the server can access a particular server on the Internet. The command syntax is ping target_name
. Inspired by ping-pong, we send a specific ICMP packet and listen for a response. If a response is received, we know that we can reach the target and that the target can reach us.
Let’s find out if we reach example.com
. In the terminal output below, we can see that we have successfully received four replies. Furthermore, we got some statistics; for instance, the average round trip time is 78 milliseconds.
Another valuable tool for troubleshooting is tracert
, which stands for trace route. The command tracert target_name
traces the network route traversed to reach the target. Without getting into more details, it expects the routers on the path to notify us if they drop a packet because its time-to-live (TTL) has reached zero. The terminal output below shows that we passed through 15 routers before reaching our target.
More Networking Commands
One networking command worth knowing is nslookup
. It looks up a host or domain and returns its IP address. The syntax nslookup example.com
will look up example.com
using the default name server; however, nslookup example.com 1.1.1.1
will use the name server one.one.one.one
. The terminal below shows the output of both commands. The results are identical; however, you can see that the answers were retrieved from different name servers.
Terminal
The final networking command we will cover in this room is netstat
. This command displays current network connections and listening ports. A basic netstat
command with no arguments will show you established connections, as shown below. In this case, we only have one SSH connection; we figured out it is SSH because it is bound to port 22.
Terminal
If you are curious about the other options, you can run netstat -h
, where -h
displays the help page. We opted for the following options:
-a
displays all established connections and listening ports-b
shows the program associated with each listening port and established connection-o
reveals the process ID (PID) associated with the connection-n
uses a numerical form for addresses and port numbers
We combine these four options and execute the netstat -abon
command. The result is quite long, but we display the first few lines in the terminal below. It is clear now that the executable sshd.exe
is responsible for listening for incoming connections on port 22, as shown in the first line. We can also see the process ID (PID) associated with each connection.
Terminal
Questions
- Which command can we use to look up the server’s physical address (MAC address)?
- ipconfig /all
- What is the name of the process listening on port 3389?
- TermService
- What is the subnet mask?
- 255.255.0.0
Files and Disk Management
I. Directory Management
cd
(change directory): Navigates the file system.cd
: Shows the current directory.cd target_directory
: Changes to the specified directory.cd ..
: Moves up one directory level.
dir
(directory): Lists files and subdirectories.dir /a
: Shows hidden and system files.dir /s
: Shows files and subdirectories recursively.
tree
: Displays a hierarchical tree view of directories.mkdir
(make directory): Creates a new directory.rmdir
(remove directory): Deletes an empty directory.
II. File Management
type filename
: Displays the contents of a text file (usemore
for large files).copy source destination
: Copies a file. (e.g.,copy file1.txt file2.txt
)move source destination
: Moves a file. (e.g.,move file1.txt new_folder
)del
orerase filename
: Deletes a file.- Wildcard Characters (
*
): Use*
to specify multiple files (e.g.,copy *.txt backup_folder
copies all.txt
files).
Example:
This concisely covers the core command-line commands for file and directory manipulation in Windows. Remember to use caution when deleting files or directories using del
and rmdir
, as these actions are irreversible without backups.
Questions
- What are the file’s contents in C:\Treasure\Hunt?
- THM{CLI_POWER}
Task and Process Management
I. Listing Processes
The tasklist
command displays a list of currently running processes. The output includes the process name, process ID (PID), session information, and memory usage.
Because the output can be lengthy, filtering options are available. Use /FI
to specify filter criteria. For example:
Use tasklist /?
to see all available filter options.
II. Terminating Processes
To terminate a process, use the taskkill
command with the /PID
option, followed by the process ID.
This forcefully terminates the process. If the process doesn’t respond, it might require a forced termination. You can add the /F
option for this:
Caution: Terminating crucial system processes can lead to system instability. Exercise caution when using taskkill
.
III. Example Scenario
- List all running processes:
tasklist
- Find processes named
chrome.exe
:tasklist /FI "IMAGENAME eq chrome.exe"
- Identify the PID of a specific
chrome.exe
instance (e.g., PID 5678). - Terminate that Chrome instance:
taskkill /F /PID 5678
Questions
- What command would you use to find the running processes related to notepad.exe?
- tasklist /FI “imagename eq notepad.exe”
- What command can you use to kill the process with PID 1516?
- taskkill /PID 1516
Conclusion
In this room, we focused on the most practical commands for accessing a networked system over the command line.
We intentionally omitted a few common commands as we didn’t see a real value for including them in a beginner room. We mention them below so that you know that the command line can be used for other tasks.
chkdsk
: checks the file system and disk volumes for errors and bad sectors.driverquery
: displays a list of installed device drivers.sfc /scannow
: scans system files for corruption and repairs them if possible.
It is important to remember all the commands covered in the previous tasks; moreover, it is equally important to know that /?
can be used with most commands to display a help page.
In this room, we used the command more
in two ways:
- Display text files:
more file.txt
- Pipe long output to view it page by page:
some_command | more
Equipped with this knowledge, we now know how to display the help page of a new command and how to display long output one page at a time.
Now that you know the Windows command line, it is time to move to the Windows PowerShell room.
Questions
- The command
shutdown /s
can shut down a system. What is the command you can use to restart a system?- shutdown /r
- What command can you use to abort a scheduled system shutdown?
- shutdown /a