You are on page 1of 119

Cyber

Public
School
OSCP
PRACTICE
PART 01

https://cyberpublicschool.com/
OSCP
PRACTICE
PART 01

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
LINUX FILE SYSTEM
Linux file system is a hierarchical directory structure used
by Linux operating systems to organize and manage files
and directories. The file system is typically mounted on a
root directory, represented by the forward slash character
(/).
▪ /bin: Contains essential system binaries and commands
required for booting and basic system functionality.
▪ /dev: Contains device files that represent hardware
devices such as disks, printers, and network interfaces.
▪ /etc: Contains system configuration files, including
network settings, startup scripts, and user account
information.
▪ /home: Contains user home directories where users
store their personal files and data.
▪ /lib: Contains libraries used by system programs and
shared by different applications.
▪ /mnt: Contains mount points for external file systems or
storage devices.
▪ /proc: A virtual file system that provides system
information and process data.
▪ /root: The home directory for the root user.
▪ /sbin: Contains system binaries and commands used for
system administration tasks.
▪ /tmp: A temporary directory used for storing temporary
files and data.
▪ /usr: Contains user-related programs and data, including
user applications, libraries, and documentation.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
▪ /var: Contains system files that change frequently, such
as log files, mail spools, and database files.
Overall, the Linux file system provides a flexible and robust
structure for managing files and directories on Linux
systems, allowing for efficient organization and
management of data.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Basic Linux Commands
Here are some basic Linux commands:
1. ls: This command lists the contents of the current
directory.
2. cd: This command changes the current directory. For
example, cd /home/user changes the directory to
/home/user.
3. mkdir: This command creates a new directory. For
example, mkdir my_folder creates a new directory
called "my_folder".

4. rm: This command removes a file or directory. For


example, rm myfile.txt removes the file "myfile.txt". If
you want to remove a directory and its contents, use
the -r option, like rm -r my_folder.

5. cp: This command copies a file or directory. For


example, cp myfile.txt /home/user copies the file
"myfile.txt" to the directory "/home/user".

6. mv: This command moves or renames a file or directory.


For example, mv myfile.txt /home/user moves the file
"myfile.txt" to the directory "/home/user", while mv
myfile.txt newname.txt renames the file to
"newname.txt".

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
7. cat: This command displays the contents of a file. For
example, cat myfile.txt shows the contents of the file
"myfile.txt".
8. echo: This command displays a message on the screen.
For example, echo "Hello, World!" displays the message
"Hello, World!" on the screen.
9. grep: This command searches for a pattern in a file. For
example, grep "error" myfile.log searches for the word
"error" in the file "myfile.log".
10. chmod: This command changes the permissions of a file
or directory. For example, chmod 755 myfile.txt sets the
file "myfile.txt" to be readable, writable, and executable
by the owner, and readable and executable by everyone
else.
These are just a few basic Linux commands, but there are
many more that you can learn to make your Linux
experience more efficient and enjoyable.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Linux command man page
In Linux, the man command is used to display the manual
pages for other commands. Here's how to use the man
command:
1. Open the terminal.
2. Type man followed by the name of the command you
want to learn about. For example, to learn about the ls
command, type man ls and press enter.
3. The manual page for the command will be displayed.
Use the arrow keys to scroll up and down, and press the
q key to exit the manual page.
The manual page typically includes a description of the
command, its syntax, available options and arguments, and
examples of how to use it. It can also provide additional
information, such as the author and version of the
command.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Apropos
In Linux, the apropos command is used to search the
manual pages for a keyword or a phrase. Here's how to use
the apropos command:
1. Open the terminal.
2. Type apropos followed by a keyword or a phrase you
want to search for. For example, to search for
commands related to "network", type apropos network
and press enter.
3. The command will display a list of manual pages that
contain the keyword or phrase. Use the arrow keys to
scroll up and down the list, and press the q key to exit
the command.
The apropos command is useful when you're not sure
about the name of the command you need to use, but you
know what it does or what it's related to. It can help you
find the appropriate command to use by searching through
the manual pages.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Listing Files
In Linux, there are several commands that you can use to
list files in a directory:
ls - lists the names of the files and directories in the current
directory.
Example: ls
ls -l - lists the files and directories in the current directory in
long format, which includes additional information such as
file permissions, owner, size, and creation/modification
date and time.
Example: ls -l
ls -a - lists all files and directories in the current directory,
including hidden files (files whose names start with a dot).
Example: ls -a
ls -lh - lists the files and directories in the current directory
in long format, but shows the sizes of the files in a human-
readable format (e.g. KB, MB, GB).
Example: ls -lh
ls -R - lists all files and directories in the current directory
and all subdirectories recursively.
Example: ls -R
These are some of the most commonly used commands for
listing files in Linux, but there are many other options and
variations available.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Moving Around
In Linux, there are several commands that you can use to
move around in the terminal:
cd - changes the current directory to the specified directory.
Example: cd /home/user/Documents
pwd - prints the current working directory (i.e. the directory
you're currently in).
Example: pwd
ls - lists the files and directories in the current directory.
Example: ls
cd .. - moves up one directory level (i.e. to the parent
directory).
Example: cd ..
cd ~ or cd - changes the current directory to your home
directory.
Example: cd ~
cd - - switches to the previous working directory.
Example: cd -
pushd - adds the current directory to the directory stack
and changes the current directory to the specified
directory.
Example: pushd /home/user/Downloads

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
popd - removes the top directory from the directory stack
and changes the current directory to the next directory in
the stack.
Example: popd
These are some of the most commonly used commands for
moving around in Linux, but there are many other options
and variations available.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Creating Directories
In Linux, there are several commands that you can use to
create directories:
mkdir - creates a new directory with the specified name.
Example: mkdir directory_name
mkdir -p - creates a new directory and any necessary parent
directories in the specified path.
Example: mkdir -p /path/to/new/directory
mkdir -m - creates a new directory with the specified
permissions (i.e. file mode).
Example: mkdir -m 755 directory_name
mkdir --version - displays the version of the mkdir
command.
Example: mkdir --version
These are some of the most commonly used commands for
creating directories in Linux, but there are many other
options and variations available.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Finding Files in Kali Linux
Kali Linux is a popular operating system used for
cybersecurity and ethical hacking purposes. Finding files in
Kali Linux can be done using a variety of commands and
tools.
Using the 'find' command:
The 'find' command can be used to search for files and
directories recursively in the system. The basic syntax is as
follows:
css

find [directory] -name [filename]

For example, to search for a file named "passwords.txt" in


the home directory, use the following command:
arduino

find /home -name passwords.txt

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Using the 'locate' command:
The 'locate' command can be used to quickly search for files
in the system. The syntax is as follows:
css

locate [filename]

For example, to search for a file named "passwords.txt" in


the system, use the following command:

locate passwords.txt

Note that the 'locate' command searches a database of files


that is updated periodically, so it may not show recently
added files.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Using the 'grep' command:
The 'grep' command can be used to search for a specific
pattern in files. The syntax is as follows:
css

grep [pattern] [filename]

For example, to search for the word "password" in a file


named "passwords.txt", use the following command:
perl

grep password passwords.txt

Using the GUI file manager:


Kali Linux comes with several GUI file managers that can be
used to browse and search for files. Some popular file
managers include Nautilus, Thunar, and PCManFM. To use
the file manager, simply open it and navigate to the
directory where you want to search for files.
Overall, there are several methods to find files in Kali Linux,
depending on your preference and the specific use case.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Which
Finding files in Kali Linux can be done using a variety of
commands and tools, such as the 'find' command, the
'locate' command, the 'grep' command, and the GUI file
manager. These methods can help you quickly and easily
search for files in your Kali Linux system.

Locate
The 'locate' command can be used in finding files in Kali
Linux. The 'locate' command is a tool for searching files by
name in a database that contains a list of all files on the
system.
To use the 'locate' command, simply type 'locate' followed
by the name of the file you want to find. For example, to
find a file named "example.txt" in Kali Linux, you can use
the following command:

locate example.txt

The 'locate' command will then search the database and


display a list of all files on the system that match the
specified file name. Note that the 'locate' command may
not show recently added files as the database is updated
periodically. In this case, you may want to use the 'find'
command to locate the file.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Find
the 'find' command is a powerful tool for finding files in Kali
Linux. It searches for files and directories in a directory
hierarchy based on different criteria such as file name, type,
size, and modification time.
The basic syntax of the 'find' command is:
css

find [directory] [expression]

where '[directory]' is the starting directory for the search


and '[expression]' is the search expression used to specify
the criteria for the search.
For example, to find all files with the name "example.txt" in
the home directory, you can use the following command:
arduino

find /home -name example.txt

This will search the 'home' directory and its subdirectories


for all files with the name 'example.txt'.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
You can also combine different search criteria with the 'find'
command. For example, to find all files with the name
"example.txt" that were modified in the last 24 hours, you
can use the following command:
arduino

find /home -name example.txt -mtime -1

This will search the 'home' directory and its subdirectories


for all files with the name 'example.txt' that were modified
in the last 24 hours.
Overall, the 'find' command is a powerful tool that can be
used to search for files based on various criteria in Kali
Linux.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Exercises
Here are some exercises to help you practice finding files in
Kali Linux using different methods:
Using the 'find' command:
Search for all files with the extension '.log' in the /var/log
directory.
Find all directories with the name 'backup' in the /home
directory.
Find all files in the /etc directory that were modified in the
last 7 days.
Using the 'locate' command:
Find all files with the name 'passwords.txt' on the system.
Find all files with the extension '.conf' in the /etc directory.
Find all files with the name 'index.html' in the /var/www
directory.
Using the GUI file manager:
Open the file manager and navigate to the /var/log
directory. Find all files with the extension '.log'.
Navigate to the /home directory and find all directories
with the name 'backup'.
Navigate to the /etc directory and find all files that were
modified in the last 7 days.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Managing Kali Linux Services
Kali Linux is a powerful and popular Linux distribution used
for penetration testing, digital forensics, and other security-
related tasks. Managing services in Kali Linux is an essential
task to ensure that all the required services are running and
functioning correctly. Here are the steps to manage Kali
Linux services:
Start/Stop/Restart Services: The easiest way to manage Kali
Linux services is by using the command line interface. You
can use the following commands to start, stop or restart a
service:
To start a service, use the command service
<service_name> start
To stop a service, use the command service
<service_name> stop
To restart a service, use the command service
<service_name> restart
Enable/Disable Services: You may also need to enable or
disable services on boot, depending on your system
requirements. You can use the following commands to
enable or disable a service:
To enable a service, use the command systemctl enable
<service_name>
To disable a service, use the command systemctl disable
<service_name>

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Check Service Status: You can check the status of a service
by using the following command:
To check the status of a service, use the command service
<service_name> status
Edit Service Configuration: You can edit the configuration of
a service by modifying the configuration file of the service.
The location of the configuration file varies depending on
the service. Typically, the configuration file is located in the
/etc/<service_name>/ directory.
Install/Uninstall Services: You can install or uninstall
services on Kali Linux using the apt-get command. For
example, to install the Apache web server, you can use the
following command: apt-get install apache2. To uninstall a
service, use the command apt-get remove <service_name>.
By following these steps, you can manage Kali Linux
services and ensure that your system is running smoothly.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
SSH Service
SSH (Secure Shell) is a network protocol used for secure
remote access to a computer or server. It is commonly used
to manage and administer servers remotely. In Kali Linux,
the SSH service is installed and enabled by default, but you
may need to manage it for security or other reasons.
Here are the steps to manage the SSH service in Kali Linux:
1. Check SSH Status: To check the status of the SSH
service, use the command systemctl status ssh. This will
show you whether the SSH service is running or not.
2. Start/Stop/Restart SSH Service: To start, stop or restart
the SSH service, use the following commands:
• To start the SSH service, use the command systemctl
start ssh
• To stop the SSH service, use the command systemctl
stop ssh
• To restart the SSH service, use the command systemctl
restart ssh
3. Enable/Disable SSH Service: To enable or disable the
SSH service, use the following commands:
• To enable the SSH service to start on boot, use the
command systemctl enable ssh
• To disable the SSH service from starting on boot, use the
command systemctl disable ssh

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
4. Configure SSH: You can configure the SSH service by
modifying the configuration file located in
/etc/ssh/sshd_config. This file contains various settings
for the SSH service, such as port number, allowed users,
authentication methods, etc. Be careful when editing
this file as incorrect settings can compromise the
security of your system.
By managing the SSH service in Kali Linux, you can ensure
that remote access to your system is secure and controlled.
It is recommended to use strong passwords and limit access
to the SSH service to authorized users only.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
HTTP Service
To manage HTTP services on Kali Linux, you can use a
variety of tools depending on your specific needs. Here are
a few options:
1. Apache HTTP Server: Apache is a widely used web
server that is available on Kali Linux. You can install it
using the command "apt-get install apache2". Once
installed, you can start, stop, and restart the service
using the commands "service apache2 start", "service
apache2 stop", and "service apache2 restart",
respectively.
2. Nginx: Nginx is another popular web server that you
can use on Kali Linux. You can install it using the
command "apt-get install nginx". Once installed, you
can start, stop, and restart the service using the
commands "service nginx start", "service nginx stop",
and "service nginx restart", respectively.
3. Systemctl: Systemctl is a command-line tool that allows
you to manage system services, including HTTP services.
To check the status of an HTTP service, you can use the
command "systemctl status [service-name]". To start,
stop, or restart a service, you can use the commands
"systemctl start [service-name]", "systemctl stop
[service-name]", and "systemctl restart [service-name]".

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
4. GUI tools: If you prefer a graphical interface, Kali Linux
provides several GUI tools for managing HTTP services,
including Apache and Nginx. For example, you can use
the "apache2ctl" command to access the Apache
control panel, or the "nginx.conf" file to configure
Nginx. You can also install web-based control panels like
Webmin or Cockpit to manage your HTTP services
through a web browser.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Exercises
Here are some exercises that you can try to practice
managing services on Kali Linux:
Install Apache HTTP server and start the service using the
command line.
sql

sudo apt-get update


sudo apt-get install apache2
sudo systemctl start apache2

Check the status of Apache using systemctl.


lua

sudo systemctl status apache2

Configure Apache to start automatically at boot time.


bash

sudo systemctl enable apache2

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Install Nginx and start the service using the command line.
sql

sudo apt-get update


sudo apt-get install nginx
sudo systemctl start nginx

Check the status of Nginx using systemctl.


lua
sudo systemctl status nginx

Configure Nginx to start automatically at boot time.

bash
sudo systemctl enable nginx

Stop the Apache service.


arduino
sudo systemctl stop apache2

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Stop the Nginx service.
arduino

sudo systemctl stop nginx

Restart the Apache service.

sudo systemctl restart apache2

Restart the Nginx service.

sudo systemctl restart nginx

These exercises will give you some practice in managing


services on Kali Linux. Depending on your specific needs,
you may need to use different commands or tools to
manage different types of services.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Searching, Installing, and Removing Tools
Here's a general guide on how to search, install, and
remove tools on various operating systems:
Searching for Tools
Windows
For Windows, the easiest way to search for tools is to use
the built-in Windows Store app. Simply search for the tool
you need in the search bar, and the app should provide you
with a list of results. You can also search for tools on the
web and download them from their respective websites.
macOS
On macOS, you can search for tools in the App Store app or
on the web. If you prefer to use the command line, you can
use a package manager like Homebrew to search for and
install tools.
Linux
On Linux, the most common way to search for tools is
through a package manager like apt, yum, or pacman,
depending on the distribution you're using. Simply use the
command line and type apt search <tool_name> (or yum
search <tool_name> or pacman -Ss <tool_name>) to
search for the tool you need.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Installing Tools
Windows
To install a tool on Windows, simply download the installer
from the website or the Windows Store app and run it.
Follow the installation wizard, and the tool should be
installed on your system.
macOS
On macOS, you can install a tool by downloading the app
from the App Store app or from the web. If you're using a
package manager like Homebrew, you can install tools
through the command line by typing brew install
<tool_name>.
Linux
On Linux, you can install a tool through the package
manager by typing sudo apt install <tool_name> (or sudo
yum install <tool_name> or sudo pacman -S
<tool_name>). If you're downloading the tool from a
website, you can usually install it by running the installer
with root privileges (sudo ./install.sh).
Removing Tools
Windows
To remove a tool on Windows, simply go to the Control
Panel and click on "Uninstall a program". Find the tool you
want to remove, click on it, and click on "Uninstall".

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
macOS
On macOS, you can remove a tool by dragging the app to
the Trash. If you're using a package manager like
Homebrew, you can remove tools through the command
line by typing brew uninstall <tool_name>.
Linux
On Linux, you can remove a tool through the package
manager by typing sudo apt remove <tool_name> (or sudo
yum remove <tool_name> or sudo pacman -R
<tool_name>). If you installed the tool from a website, you
can usually uninstall it by running the uninstaller with root
privileges (sudo ./uninstall.sh).

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
apt update
apologies for missing that! You're correct, running apt
update is an important step before installing any tools on
Linux using apt. Here's an updated guide:
Searching for Tools
Windows
For Windows, the easiest way to search for tools is to use
the built-in Windows Store app. Simply search for the tool
you need in the search bar, and the app should provide you
with a list of results. You can also search for tools on the
web and download them from their respective websites.
macOS
On macOS, you can search for tools in the App Store app or
on the web. If you prefer to use the command line, you can
use a package manager like Homebrew to search for and
install tools.
Linux
On Linux, the most common way to search for tools is
through a package manager like apt, yum, or pacman,
depending on the distribution you're using. Before
searching for tools using apt, it's important to run sudo apt
update to ensure that your package list is up-to-date. Once
you've done that, you can use the command line and type
apt search <tool_name> (or yum search <tool_name> or
pacman -Ss <tool_name>) to search for the tool you need.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Installing Tools
Windows
To install a tool on Windows, simply download the installer
from the website or the Windows Store app and run it.
Follow the installation wizard, and the tool should be
installed on your system.
macOS
On macOS, you can install a tool by downloading the app
from the App Store app or from the web. If you're using a
package manager like Homebrew, you can install tools
through the command line by typing brew install
<tool_name>.
Linux
On Linux, you can install a tool through the package
manager by typing sudo apt install <tool_name> (or sudo
yum install <tool_name> or sudo pacman -S
<tool_name>). If you're downloading the tool from a
website, you can usually install it by running the installer
with root privileges (sudo ./install.sh).
Removing Tools
Windows
To remove a tool on Windows, simply go to the Control
Panel and click on "Uninstall a program". Find the tool you
want to remove, click on it, and click on "Uninstall".

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
macOS
On macOS, you can remove a tool by dragging the app to
the Trash. If you're using a package manager like
Homebrew, you can remove tools through the command
line by typing brew uninstall <tool_name>.
Linux
On Linux, you can remove a tool through the package
manager by typing sudo apt remove <tool_name> (or sudo
yum remove <tool_name> or sudo pacman -R
<tool_name>). If you installed the tool from a website, you
can usually uninstall it by running the uninstaller with root
privileges (sudo ./uninstall.sh).

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Apt install
apt install is a command used on Debian-based Linux
distributions (such as Ubuntu) to install packages from the
distribution's official repositories or from third-party
repositories that have been added to the system.
To use apt install, you first need to make sure that your
package list is up-to-date by running the command sudo
apt update. This will fetch the latest information about
available packages from the repositories.
After running sudo apt update, you can use apt install to
install a package by typing sudo apt install
<package_name>. For example, to install the text editor
nano, you can type sudo apt install nano.
If the package is found in the repository and there are no
issues with dependencies, apt will download the package
and its dependencies (if any) and install them on your
system.
You can also install multiple packages at once by separating
the package names with a space. For example, to install
both nano and vim, you can type sudo apt install nano vim.
After installation, you can run the installed package by
typing its name in the terminal. For example, to open nano,
you can simply type nano in the terminal.
I hope this helps! Let me know if you have any other
questions.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
apt remove –purge
apt remove is a command used on Debian-based Linux
distributions to remove a package from the system. When
you use apt remove, the package is removed but any
configuration files associated with the package are left
behind on the system.
On the other hand, apt remove --purge removes both the
package and its configuration files, effectively wiping all
traces of the package from the system. This can be useful if
you want to completely remove a package and its
associated configuration files, and want to start fresh with a
new installation.
To use apt remove --purge, you can simply type sudo apt
remove --purge <package_name> in the terminal. For
example, to remove the nano text editor and its
configuration files, you can type sudo apt remove --purge
nano.
Note that this command permanently removes the package
and its configuration files from the system. It's
recommended to use this command with caution and only
when you are sure that you want to completely remove the
package and its configuration files.
I hope this helps! Let me know if you have any other
questions.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Dpkg
dpkg is a command-line tool used on Debian-based Linux
distributions (such as Ubuntu) to install, manage, and
remove individual software packages.
Unlike apt, which manages packages and their
dependencies, dpkg deals with the individual .deb package
files themselves. dpkg is a lower-level tool than apt, and is
generally used when more control over the package
management process is required.
Here are a few common use cases for dpkg:
To install a .deb package, you can use the command sudo
dpkg -i <package_file.deb>. For example, to install the nano
text editor from a .deb file named nano.deb, you can type
sudo dpkg -i nano.deb.
To remove a package, you can use the command sudo dpkg
-r <package_name>. For example, to remove the nano text
editor, you can type sudo dpkg -r nano.
To remove a package and its configuration files, you can use
the command sudo dpkg -P <package_name>. For
example, to completely remove the nano text editor, you
can type sudo dpkg -P nano.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
To list all installed packages, you can use the command
dpkg -l. This will show a list of all packages installed on the
system, along with their version numbers and other
information.
To see information about a specific package, you can use
the command dpkg -s <package_name>. This will show
information about the specified package, including its
version number, description, and installed size.
Note that when using dpkg to install or remove packages,
you may need to manually install or remove dependencies
as well. This can be a more involved process than using apt,
which automatically handles dependencies.
I hope this helps! Let me know if you have any other
questions.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Exercises
here are some exercises related to searching, installing, and
removing tools in Ubuntu:
1. Search for the package that provides the ping command
using apt search.
2. Install the tree command using apt install.
3. Remove the tree command using apt remove.
4. Completely remove the tree command, including its
configuration files, using apt remove --purge.
5. Search for the package that provides the htop
command using apt search.
6. Install the htop command using apt install.
7. Remove the htop command using apt remove.
8. Completely remove the htop command, including its
configuration files, using apt remove --purge.
9. Install the nano text editor using dpkg.
10. Remove the nano text editor using dpkg.
Note that you may need to use sudo before each command
to run them as a superuser and gain the necessary
permissions to install or remove packages.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Command Line Fun
here are some fun things you can do on the command line:
Play a game of Tetris: You can install the "bastet" package
on Linux and play Tetris on your terminal.
Generate random passwords: You can use the "pwgen"
command to generate random passwords of various lengths
and complexity.
Create ASCII art: You can use tools like "figlet" and "toilet"
to create ASCII art of text.
Make your terminal look cool: You can customize your
terminal with tools like "oh-my-zsh" and "powerline" to
make it look more stylish and functional.
Display a matrix rain animation: You can use the "cmatrix"
command to display a matrix rain animation on your
terminal.
Create a random quote generator: You can create a script
that generates random quotes and displays them on your
terminal every time you open it.
Use the "cowsay" command to create ASCII art of a cow
saying anything you want.
These are just a few examples, but there are many more
fun things you can do on the command line!

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
The Bash Environment
The Bash environment refers to the collection of variables,
settings, and configurations that are used by the Bash shell,
which is the default shell on most Unix-based operating
systems. The Bash environment includes various
components that control how the shell operates and
interacts with the user and the system. Here are some key
components of the Bash environment:
1. Environment variables: These are variables that are set
by the shell and used by various programs and scripts.
Some common environment variables include PATH,
which specifies the directories that the shell searches
for executable files, and HOME, which specifies the
user's home directory.
2. Shell options: These are settings that control the
behavior of the shell. For example, the "set -o
noclobber" option prevents files from being overwritten
by redirection.
3. Aliases: These are shorthand commands that are
defined by the user. For example, an alias can be
created for a long command that is frequently used.
4. Functions: These are named sets of commands that are
defined by the user. Functions can be used to simplify
complex commands or to perform repetitive tasks.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
5. Startup files: These are scripts that are executed when
the shell starts up. The most commonly used startup
files are .bashrc and .bash_profile.
Understanding the Bash environment is important for
customizing and optimizing the behavior of the shell to suit
your needs. You can modify the environment variables,
shell options, aliases, and functions to create a personalized
command-line experience that is efficient and convenient.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Environment Variables
Environment variables are a type of variable in the Bash
environment that hold information about the current
environment. They are used to store values such as user
preferences, system settings, and paths to important
directories. Environment variables are accessed by many
programs and scripts, and can be modified by the user or
the system.
Some common environment variables in the Bash
environment include:
1. PATH: This variable contains a list of directories
separated by colons, which are searched by the shell for
executable files. When you type a command in the
terminal, the shell looks for the executable file in each
directory listed in the PATH variable, in the order they
are listed.
2. HOME: This variable contains the path to the user's
home directory.
3. USER: This variable contains the username of the
currently logged in user.
4. PS1: This variable contains the prompt string that is
displayed in the terminal. You can customize the prompt
string by setting the PS1 variable to a desired value.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
5. LANG: This variable determines the language and
character encoding used by programs that support
internationalization.
6. TERM: This variable specifies the type of terminal being
used.
You can view the current value of an environment variable
using the "echo" command, like this: echo
$VARIABLE_NAME. You can set the value of an
environment variable using the "export" command, like
this: export VARIABLE_NAME=value. The changes made to
an environment variable using the "export" command will
only be applied to the current shell session, so if you want
the changes to be permanent, you should add the "export"
command to one of the Bash startup files, such as .bashrc
or .bash_profile.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Tab Completion
Tab completion is a feature in the Bash shell that allows you
to quickly complete commands, filenames, and other
arguments by pressing the "Tab" key. When you start typing
a command or filename, the shell will try to autocomplete
it based on what is already in the command line. If there is
only one possible completion, the shell will automatically
complete it for you. If there are multiple possible
completions, you can press "Tab" again to see a list of
options, or you can type more characters to narrow down
the list of options.
Here are some examples of how tab completion can be
used:
Completing filenames: If you are trying to open a file in the
current directory, you can type the first few characters of
the filename and then press "Tab" to autocomplete it. For
example, if you have a file called "example.txt" in the
current directory, you can type "vi ex" and then press "Tab"
to autocomplete the filename.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Completing command names: If you are trying to run a
command, you can type the first few letters of the
command and then press "Tab" to autocomplete it. For
example, you can type "cd /u/l/b" and then press "Tab" to
autocomplete the command to "cd /usr/local/bin".
Completing options: If you are trying to use a command
with an option, you can type the option and then press
"Tab" to autocomplete it. For example, if you are trying to
use the "ls" command with the "-l" option, you can type "ls
-" and then press "Tab" to autocomplete the option.
Tab completion is a very useful feature that can save time
and reduce typing errors. It works not only for commands
and filenames, but also for variables, options, and many
other types of arguments.

Here are some command on tab Completion :

kali@kali:~$ ls D[TAB]
Desktop/ Documents/ Downloads/
kali@kali:~$ ls De[TAB]sktop/
kali@kali:~$ ls Desktop/

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Bash History Tricks
Here are some Bash history tricks that you can use with
specific commands to make your command-line experience
more efficient:
grep history: You can use the "grep" command to search
your command history for a specific keyword. For example,
if you want to find all the commands you have run that
involve "python", you can type "history | grep python". This
will show you all the commands that contain the word
"python" in your history.
!$: Typing "!$" in a command line will insert the last
argument of the previous command. For example, if you
ran the command "ls -l /usr/local/bin", typing "cd !$" would
change your directory to "/usr/local/bin".
!n:p: Adding ":p" to the end of "!n" will print the command
instead of executing it. This is useful if you want to see the
command before running it. For example, "!5:p" will print
the fifth command in your history, but not execute it.
!!:s/old/new/: You can use the "!!:s/old/new/" command
to replace the old text with new text in the previous
command. For example, if you ran the command "ls -l
/usr/local/bin", typing "!!:s/local/opt/" would change the
command to "ls -l /usr/opt/bin".

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
!$ and !!: You can combine the !$ and !! commands to
quickly repeat and modify a previous command. For
example, if you ran the command "sudo apt-get install
python3-pip", typing "vi !$" would open the file "python3-
pip" for editing.
These are just a few of the many Bash history tricks that can
make your command-line experience more efficient. By
combining these tricks with your knowledge of Bash
commands and shortcuts, you can become a more effective
and efficient command-line user.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Exercises
here are some exercises to help you practice using the Bash
command line and some of the concepts we've discussed:
1. Create a new directory called "mydir" in your home
directory using the "mkdir" command.
2. Change to the "mydir" directory using the "cd"
command.
3. Create a new file called "mytext.txt" using the "touch"
command.
4. Use the "echo" command to add some text to
"mytext.txt". For example, you could type "echo 'Hello,
world!' > mytext.txt" to add the text "Hello, world!" to
the file.
5. Use the "cat" command to view the contents of
"mytext.txt". For example, you could type "cat
mytext.txt" to see the text you added in the previous
step.
6. Use the "history" command to view your command
history. Try using some of the Bash history tricks we
discussed earlier to navigate and search through your
history.
7. Use the "cp" command to make a copy of "mytext.txt"
and call it "mytext_copy.txt".
8. Use the "rm" command to delete "mytext.txt".

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
9. Use the "mv" command to rename "mytext_copy.txt" to
"newtext.txt".
10. Use the "ls" command to list the contents of the
"mydir" directory. You should see "newtext.txt" but not
"mytext.txt".
These exercises should give you a good foundation for
working with the Bash command line. Once you feel
comfortable with these concepts, you can continue to
explore the many other commands, shortcuts, and tricks
that are available.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Piping and Redirection
In Unix-based operating systems, piping and redirection are
used to manipulate input and output streams of commands
and processes.
Piping allows you to take the output of one command and
use it as input for another command. This is done using the
vertical bar (|) character. For example, the following
command will list all the files in the current directory and
then sort the output alphabetically:
bash
ls | sort

Redirection allows you to redirect the input or output of a


command to a file or another location. This is done using
the greater than (>) and less than (<) characters. For
example, the following command will take the output of
the ls command and save it to a file named "filelist.txt":

bash
ls > filelist.txt

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Similarly, the following command will take the contents of
the "input.txt" file and pass it as input to the sort
command, and then save the output to a file named
"output.txt":
lua

sort < input.txt > output.txt

There are also other forms of redirection, such as


appending to a file using the double greater than (>>)
character, or redirecting error messages using the 2> or 2>>
characters.
Piping and redirection are powerful tools that allow you to
combine and manipulate the output and input of
commands and processes in many ways. They are essential
for working with Unix-based operating systems, and can
greatly simplify complex tasks.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Redirecting to a New File
In Unix-based operating systems, you can redirect the
output of a command or process to a new file using the
greater than (>) character. This will create a new file or
overwrite an existing one with the output of the command.
For example, let's say you want to save the output of the ls
command to a new file called "filelist.txt". You can use the
following command:
bash
ls > filelist.txt

This will redirect the output of the ls command to the


"filelist.txt" file. If the file does not exist, it will be created. If
it already exists, its contents will be overwritten with the
new output.
You can also redirect the output of multiple commands to
the same file. For example, let's say you want to list all the
files in the current directory and then sort them
alphabetically, and save the output to the same "filelist.txt"
file. You can use the following command:
bash

ls | sort > filelist.txt

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
This will redirect the output of the sort command (which is
the sorted list of files) to the "filelist.txt" file.
It's important to note that when you redirect output to a
new file, any existing contents of the file will be
overwritten. If you want to append the output to an
existing file instead, you can use the double greater than
(>>) character. For example:
bash

ls >> filelist.txt

This will append the output of the ls command to the end


of the "filelist.txt" file, rather than overwriting its contents.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Redirecting to an Existing File
When you redirect the output of a command to a file using
the greater than (>) character, it will overwrite the contents
of an existing file with the new output. If you want to add
the new output to the existing contents of the file instead
of overwriting it, you can use the double greater than (>>)
character for file redirection.
For example, let's say you have a file called "output.txt"
that already contains some data. If you want to append the
output of a command to the end of this file, you can use
the following command:
bash

command >> output.txt

This will append the output of the command to the end of


the "output.txt" file. If the file does not exist, it will be
created.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
It's important to note that when you append output to a
file, the new output will be added to the end of the existing
contents of the file, without affecting the existing data.
Also, if you redirect the output of multiple commands to
the same file using the >> operator, the output of each
command will be appended to the end of the file in the
order that the commands were executed.
You can also use the >> operator to append the output of
one file to another file. For example, let's say you have a file
called "input.txt" and you want to append its contents to
the end of a file called "output.txt". You can use the
following command:
lua

cat input.txt >> output.txt

This will append the contents of "input.txt" to the end of


"output.txt".

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Redirecting from a File
In Unix-based operating systems, you can redirect the input
of a command or process from a file using the less than (<)
character. This will take the contents of the file and use it as
input for the command or process.
For example, let's say you have a file called "input.txt" that
contains a list of names, and you want to sort the names
alphabetically. You can use the following command:
lua

sort < input.txt

This will take the contents of "input.txt" and use it as input


for the sort command, which will then sort the names
alphabetically and output the result to the console.
You can also redirect the input of multiple commands from
the same file. For example, let's say you have a file called
"commands.txt" that contains a list of commands, one per
line, and you want to execute all of them. You can use the
following command:
arduino
while read line; do $line; done < commands.txt

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
This will read each line from "commands.txt" and execute
the command on that line. The while loop reads the file line
by line, assigns each line to the variable $line, and then
executes the command on that line.
It's important to note that when you redirect input from a
file, the contents of the file will be used as input for the
command or process, without affecting the file itself. Also,
if you redirect input from a file that does not exist, you will
get an error.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Redirecting STDERR
In Unix-based operating systems, you can redirect the
standard error (STDERR) output of a command or process
using the greater than symbol followed by the ampersand
(>&) characters. This allows you to redirect the error output
to the same destination as the regular output, or to a
separate file.
To redirect the STDERR output of a command to the same
destination as the regular output (STDOUT), you can use
the following syntax:
bash
command > output.txt 2>&1

This will redirect the regular output of command to the


"output.txt" file, and then redirect the STDERR output to
the same destination as the regular output.
To redirect the STDERR output to a separate file, you can
use the following syntax:
lua

command > output.txt 2> error.txt

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
This will append the regular output of command to the
"output.txt" file, and append the STDERR output to the
same destination as the regular output.
It's important to note that when you redirect STDERR
output, it will not be displayed on the console or terminal.
Instead, it will be redirected to the specified destination.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Piping
Piping is a mechanism in Unix-based operating systems that
allows you to connect the output of one command to the
input of another command, creating a data pipeline. This
allows you to combine multiple commands to perform
more complex operations, and is a powerful feature of
Unix-based operating systems.
The pipe symbol (|) is used to connect the output of one
command to the input of another command. For example,
let's say you have a file called "data.txt" that contains a list
of numbers, and you want to sort the numbers in
descending order. You can use the following command:
bash
cat data.txt | sort -r

This will use the cat command to output the contents of


"data.txt", and then pipe that output to the sort command
with the -r option to sort the numbers in reverse order.
You can also pipe the output of multiple commands
together to create more complex operations. For example,
let's say you have a directory that contains a large number
of files, and you want to find all the files that contain a
certain keyword. You can use the following command:

https://cyberpublicschool.com/
OSCP PRACTICE PART 01

bash

grep -r "keyword" /path/to/directory | cut -d: -f1

This will use the grep command to search for the keyword
in all the files in the specified directory, and then pipe that
output to the cut command to extract only the file names.
It's important to note that when you pipe the output of one
command to another command, the output is not saved to
a file or displayed on the console. Instead, it is sent directly
to the input of the next command in the pipeline.
Additionally, the output of the first command must be
compatible with the input of the second command.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Exercises
Here are some exercises to practice using piping and
redirection in Unix-based operating systems:
Write a command to count the number of lines in a file
called "myfile.txt".
Write a command to find all files in the current directory
that have the extension ".log".
Write a command to find all files in the current directory
and its subdirectories that contain the word "error".
Write a command to display the 10 most frequently
occurring words in a file called "mytextfile.txt".
Write a command to search for the word "important" in all
files in the current directory and its subdirectories, and
redirect the output to a file called "important_files.txt".
Answers:
wc -l myfile.txt
find . -name "*.log"
grep -r "error" .
cat mytextfile.txt | tr '[:space:]' '[\n*]' | sort | uniq -c |
sort -nr | head -n 10
grep -r "important" . > important_files.txt

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Text Searching and Manipulation
Text searching and manipulation can be important skills for
security professionals who are performing these types of
tasks.
In terms of text searching, there are a few tools that can be
useful in the OSCP certification program:
grep: grep is a command-line utility for searching through
text files. It can be used to search for specific strings,
regular expressions, or patterns within files.
find: find is another command-line utility that can be used
to search for files and directories based on various criteria,
such as name, size, and modification time.
ack: ack is a tool similar to grep, but it is optimized for
searching through source code and other text files. It
supports searching through multiple files and directories
simultaneously and can use regular expressions for more
complex searches.
When it comes to text manipulation, there are also several
tools that can be helpful:

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
sed: sed (short for "stream editor") is a command-line
utility for performing text transformations on input
streams. It can be used for tasks such as replacing text,
deleting lines, and inserting text.
awk: awk is another command-line utility that can be used
for text manipulation. It is particularly useful for processing
structured text data, such as CSV files, and can be used to
perform calculations, extract specific fields, and more.
tr: tr is a command-line utility for translating characters in
input streams. It can be used for tasks such as converting
text to lowercase or uppercase, removing certain
characters, and replacing characters with other characters.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Grep
grep is a command-line utility in Unix-like operating systems
that allows you to search for a specific pattern in a file or
multiple files. The name grep stands for "Global Regular
Expression Print".
The basic syntax of the grep command is as follows:
perl

grep pattern filename

Here, pattern is the regular expression or search string that


you want to search for, and filename is the name of the file
or files in which you want to search.
For example, if you want to search for the word "apple" in a
file called fruits.txt, you can use the following command:

ls -la /usr/bin | grep zip

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Find
find is a powerful command-line utility in Linux/Unix
systems that helps to search for files and directories in a
specific directory hierarchy based on different search
criteria. It recursively searches through the specified
directory and all its subdirectories, finding all files and
directories that match the specified criteria.
Here's the basic syntax of the find command:
css

find [path] [expression]

path: Specifies the starting directory for the search. If no


path is specified, find will start the search in the current
directory.
expression: Specifies the search criteria. This can include
options such as -name, -type, -size, -mtime, -exec, and
more.
Here are a few examples of how to use the find command:
To find all files with a specific name in the current directory
and its subdirectories:
arduino

find . -name "filename.txt"

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
This will search for all files with the name filename.txt in
the current directory and all its subdirectories.
o find all directories with a specific name in a specific
directory:
arduino

find /home/user -type d -name "mydir"

This will search for all directories with the name mydir in
the directory /home/user.

To find all files larger than a specific size:


arduino

find . -type f -size +10M

This will search for all files larger than 10 megabytes in the
current directory and all its subdirectories.
These are just a few examples of the many ways the find
command can be used to search for files and directories
based on different criteria. It's a very powerful tool and can
be very useful for finding specific files or directories in a
large directory hierarchy.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Sed
sed is a command-line utility in Linux/Unix systems that
stands for "stream editor". It is used to perform text
transformations on an input stream (a file, or standard
input) and print the result to standard output. sed is often
used to automate editing tasks, such as replacing text,
deleting lines, or inserting text into a file.
Here's the basic syntax of the sed command:
arduino

sed [options] 's/regexp/replacement/g' filename

options: Specifies any command-line options for sed. Some


common options include -i (edit files in place) and -n
(suppress automatic printing of output).
s/regexp/replacement/g: The s command specifies a
substitution operation. regexp is a regular expression
pattern that matches the text you want to replace, and
replacement is the text you want to replace it with. The g
flag means that the substitution should be global (i.e., all
occurrences of regexp in the input stream should be
replaced).
filename: Specifies the name of the file to read input from.
If no file name is specified, sed reads input from standard
input.

Here arehttps://cyberpublicschool.com/
a few examples of how to use the sed command:
OSCP PRACTICE PART 01
To replace all occurrences of a string in a file:

arduino
sed 's/oldstring/newstring/g' filename.txt

To delete a specific line in a file:


arduino

sed '3d' filename.txt

To insert text before or after a specific line in a file:


arduino

sed '2iNew Text' filename.txt


sed '2aNew Text' filename.txt
Example :

~$ echo "I need to try hard" | sed 's/hard/harder/'

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Cut
Cut is a command-line utility in Linux/Unix systems that is
used to extract sections from each line of a file or from
standard input. It can be used to cut out specific columns or
fields from a file or to extract parts of a line based on a
delimiter character.
Here's the basic syntax of the cut command:
css
cut [options] [file(s)]

options: Specifies any command-line options for cut. Some


common options include -d (specifies the delimiter
character), -f (specifies the field or column to extract), and -
c (specifies the character range to extract).
file(s): Specifies the name(s) of the file(s) to extract sections
from. If no file name is specified, cut reads input from
standard input.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Here are a few examples of how to use the cut command:
To extract a specific column or field from a file:

bash

cut -d',' -f3 filename.csv

To extract a specific range of characters from a line:


bash

echo "Hello World" | cut -c1-5

To extract multiple columns or fields from a file:


bash

cut -d',' -f1,3 filename.csv

Example :

~$ echo "I hack binaries,web apps,mobile apps, and


just about anything else"
| cut -f 2 -d ","

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Awk
awk is a command-line utility in Linux/Unix systems that is
used for text processing and data extraction. It is an
interpreted programming language that allows you to
manipulate and process data in a file or from standard
input.
Here's the basic syntax of the awk command:
css

awk [options] 'pattern {action}' [file(s)]


options: Specifies any command-line options for awk. Some
common options include -F (specifies the field separator), -
v (defines a variable), and -f (specifies a file containing awk
code).
pattern: Specifies a pattern to match against the input data.
This can be a regular expression, a string, or a logical
expression.
{action}: Specifies an action to perform when the pattern is
matched. This can be a simple command, a block of
commands enclosed in curly braces, or a function call.
[file(s)]: Specifies the name(s) of the file(s) to process. If no
file name is specified, awk reads input from standard input.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Here are a few examples of how to use the awk command:
To extract a specific column or field from a file:

arduino

awk -F',' '{print $3}' filename.csv

To print lines that match a specific pattern:


arduino

awk '/pattern/ {print}' filename.txt

To perform arithmetic operations on fields in a file:


arduino

awk -F',' '{total += $3} END {print total}' filename.csv

Example :

echo "hello::there::friend" | awk -F "::" '{print $1, $3}'

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Ack
ack is a tool for searching for files that match a given
pattern, similar to the grep command, but with additional
features and optimizations for programmers. It is designed
to be faster and more user-friendly than grep.
Some of the features of ack include:
It automatically ignores backup files, version control
directories, and other common file types that are not likely
to contain code.
It can search recursively through directories and display the
results in a color-coded format that makes it easy to
identify matches.
It can search multiple files at once and display the results in
a unified format.
It supports regular expressions and can search for complex
patterns, including lookaheads and lookbehinds.
Here's the basic syntax of the ack command:
css

ack [options] PATTERN [FILES OR DIRECTORIES]

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
To search for a pattern in a single file:
sql

ack pattern filename.txt

To search for a pattern in multiple files:


sql

ack pattern *.txt

To search for a pattern recursively in a directory:


bash
ack pattern /path/to/directory

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Tr
tr is a command-line utility in Linux/Unix systems that is
used for translating, deleting, or squeezing characters. It
takes input from standard input or from a file, performs the
specified translation or deletion, and then outputs the
result to standard output or to a file.
Here's the basic syntax of the tr command:
css

tr [options] SET1 [SET2]

Here are a few examples of how to use the tr command:


To translate all lowercase letters to uppercase:

bash

echo "Hello, world!" | tr '[:lower:]' '[:upper:]'

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
To delete all whitespace characters:

bash

echo " Hello, world! " | tr -d '[:space:]'

To squeeze repeated characters:

bash

echo "Hello, world!!!" | tr -s '!'

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Practical example
Let’s take a look at a practical example that ties together
many of the commands we have explored
so far.
We are given an Apache HTTP server log
(http://www.offensive-
security.com/pwk files/access_log.txt.gz), that contains
evidence of an attack. Our task is to use Bash commands to
inspect the file and discover various pieces of information,
such as who the attackers were and
what exactly happened on the server.
First, we’ll use the head and wc commands to take a quick
peek at the log file to understand its
structure. The head command displays the first 10 lines in a
file and the wc command, along with
the -l option, displays the total number of lines in a file.

~$ gunzip access_log.txt.
~$ mv access_log.txt access.log
~$ head access.log

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Editing Files From The Command Line
Editing files from the command line can be done in several
ways, depending on the operating system and the tools
available. Here are a few common methods:
Nano editor: Nano is a simple and user-friendly command-
line text editor that comes pre-installed on many Unix-
based operating systems. To open a file with Nano, type
"nano" followed by the file name or path. For example:

nano myfile.txt

Vim editor: Vim is a more advanced text editor for the


command line, which provides more features than Nano,
but also has a steeper learning curve. To open a file with
Vim, type "vim" followed by the file name or path. For
example:

vim myfile.txt

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Sed command: Sed is a powerful stream editor for filtering
and transforming text from the command line. It can be
used to edit files as well, by piping the file content to the
sed command and specifying the desired edits using regular
expressions. For example, to replace all occurrences of
"foo" with "bar" in a file named "myfile.txt", you can use
the following command:
arduino

sed 's/foo/bar/g' myfile.txt

arduino

sed -i 's/foo/bar/g' myfile.txt

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Nano
Nano is a text editor for the command line that is designed
to be easy to use and learn, making it a good choice for
beginners or those who prefer a simpler interface. It is
included in many Unix-based operating systems, such as
Linux and macOS.
To open a file with Nano, you can type "nano" followed by
the file name or path in the terminal. For example:

nano myfile.txt

Some common keyboard shortcuts in Nano include:


Ctrl+O: save the file
Ctrl+X: exit Nano
Ctrl+G: display the help menu
Ctrl+W: search for text
Ctrl+K: cut a line of text
Ctrl+U: paste a line of text

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Nano also supports syntax highlighting for various
programming languages, which can help make the code
easier to read and understand. To enable syntax
highlighting, you can use the "-Y" flag followed by the name
of the language. For example:

nano -Y sh script.sh

Example :

nano intro_to_nano.txt

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Vi
Vi is a text editor for the command line that is designed for
efficiency and power, making it a popular choice among
developers and advanced users. Vi is included in most Unix-
based operating systems, such as Linux and macOS.
To open a file with Vi, you can type "vi" followed by the file
name or path in the terminal. For example:

vi myfile.txt

vi intro_to_vi.txt

Some common commands and shortcuts in Vi include:


➢ i: enter insert mode to start typing text
➢ Esc: exit insert mode and return to command mode
➢ :w: save the file
➢ :q: quit Vi
➢ :wq: save and quit Vi
➢ :q!: quit Vi without saving changes
➢ :set nu: display line numbers
➢ /text: search for the specified text

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
➢ n: move to the next occurrence of the search text
➢ N: move to the previous occurrence of the search text
➢ dd: delete a line of text
➢ yy: copy a line of text
➢ p: paste the copied or cut text

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Comparing Files
To compare files, you can use various tools and techniques
depending on the operating system and the type of files
you want to compare. Here are some common methods:
1. File comparison software: You can use file comparison
software like WinMerge (for Windows) or Meld (for
Linux) to compare two files. These tools highlight the
differences between the files, making it easy to see
where changes have been made.
2. Text editors: You can also use a text editor like
Notepad++ or Sublime Text to compare files. Open both
files in the text editor and use the "compare" or "diff"
feature to see the differences between the files.
3. Command-line tools: You can use command-line tools
like "diff" (for Linux) or "fc" (for Windows) to compare
files. These tools compare the contents of two files and
display the differences.
4. Online tools: There are many online tools available to
compare files. Simply upload the two files and the tool
will highlight the differences between them.
Regardless of the method you choose, it's important to
carefully review the differences between the files to ensure
you understand them fully.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Comm
comm is a command-line utility in Unix-like operating
systems that is used to compare two sorted files line by
line. Its name stands for "compare and merge". The comm
command can be used to find the lines that are common to
two files, the lines that are unique to the first file, and the
lines that are unique to the second file.
The comm command takes two input files as arguments
and produces three columns of output, separated by tabs:
Lines only in the first file
Lines only in the second file
Lines in both files
The output can be customized using command-line options.
For example, the -1 option suppresses the output of lines
unique to the first file, the -2 option suppresses the output
of lines unique to the second file, and the -3 option
suppresses the output of lines common to both files.
Here is an example usage of the comm command:

https://cyberpublicschool.com/
OSCP PRACTICE PART 01

shell

$ cat file1
apple
banana
cherry
durian
$ cat file2
banana
cherry
date
elderberry
$ comm file1 file2
apple
durian
date
elderberry
apple
banana
cherry

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Example :

cat scan-a.txt
cat scan-b.txt
comm scan-a.txt scan-b.txt
comm -12 scan-a.txt scan-b.txt

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Diff
diff is a command-line utility in Unix-like operating systems
that is used to compare two files line by line and display the
differences between them. Its name stands for "difference".
The diff command can be used to find the lines that are
added, deleted, or changed between two files.
The diff command takes two input files as arguments and
produces a set of instructions that can be used to transform
the first file into the second file. By default, the output is
displayed in a unified diff format, which shows the
differences between the files in a compact and readable
way.
Here is an example usage of the diff command:
yaml
$ cat file1
apple
banana
cherry
$ cat file2
apple
date
cherry
$ diff file1 file2
2c2
< banana
---
> date

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Vim diff
In Vim, you can use the vimdiff command to compare and
edit two files side-by-side. vimdiff is a built-in feature of
Vim that allows you to see the differences between two
files in a visual way, and to edit the files in place as needed.
Here's how to use vimdiff to compare two files:
1. Open Vim and type vimdiff followed by the names of
the two files you want to compare. For example:
ruby

$ vimdiff file1.txt file2.txt

2. Vim will split the window into two panes and display
the contents of each file. The differences between the
files will be highlighted in different colors.
3. Use the arrow keys or the Ctrl-w command to navigate
between the two panes. You can also use the ]c and [c
commands to jump to the next and previous
differences, respectively.
4. To edit the files, navigate to the line you want to change
and enter "insert" mode by pressing the i key. Make
your changes, then press Esc to return to "command"
mode.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
5. Once you have made all your changes, save the files and
quit Vim by typing :wqa and pressing Enter.
Using vimdiff is a powerful way to compare and edit files,
especially when you need to see the differences between
two versions of a file in a visual way.
Let’s look at an example:

~$ vimdiff scan-a.txt scan-b.txt

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Managing processes
Managing processes involves overseeing the flow of
activities and tasks within an organization to ensure that
goals and objectives are achieved efficiently and effectively.
It involves planning, organizing, controlling, and leading the
resources and activities needed to accomplish specific tasks
and achieve organizational goals.
Here are some key aspects of managing processes:
Planning: This involves setting objectives, developing
strategies, and creating action plans to achieve
organizational goals. Planning requires a clear
understanding of the resources available and the
constraints that may affect the process.
Organizing: This involves creating a structure and assigning
responsibilities to individuals or teams involved in the
process. It involves creating a system for communication,
coordination, and collaboration among team members.
Controlling: This involves monitoring the progress of the
process and making adjustments as needed to ensure that
goals are met. It involves identifying potential problems and
taking corrective action to keep the process on track.
Leading: This involves motivating, directing, and guiding
team members to achieve the goals of the process. It
involves building a positive work environment and fostering
a culture of collaboration and continuous improvement.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Managing processes with commands

often involves using the command line interface (CLI) or


terminal to interact with the operating system and manage
running processes. Here are some commonly used
commands for managing processes:
ps: This command displays a list of currently running
processes, along with their process IDs (PIDs) and other
information such as the amount of CPU and memory
resources they are using.
kill: This command allows you to terminate a running
process by sending a signal to its process ID (PID). The
default signal is SIGTERM, which gracefully terminates the
process. You can also use the SIGKILL signal to forcefully
terminate a process.
top: This command displays real-time information about
the processes running on the system, including their CPU
and memory usage. It can be used to monitor system
performance and identify processes that are consuming too
many resources.
renice: This command allows you to change the priority of a
running process, which can be useful for allocating
resources to critical processes. You can adjust the process
priority by specifying a new priority level from -20 (highest)
to 19 (lowest).

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
bg/fg: These commands allow you to move a running
process to the background or foreground. You can use the
bg command to move a process to the background and
continue running it while you perform other tasks, and the
fg command to bring a background process back to the
foreground.
Command
Backgrounding Processes (bg) :

ping -c 400 localhost > ping_results.txt &

ping -c 400 localhost > ping_results.txt


^Z
bg

Jobs Control: jobs and fg :

~$ping -c 400 localhost > ping_results.txt


^Z
~$find / -name sbd.exe
^Z
~$ jobs
~$fg %1
^C
~$jobs
~$fg

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Process Control: ps and kill :

ps -ef

ps -fC leafpad

kill 1307

Top :
Process listing: The "top" command displays a list of all the
processes currently running on the system, along with their
process ID (PID), owner, status, and resource usage
statistics.
Resource usage: The "top" command shows real-time
statistics about the resource usage of each process,
including CPU usage, memory usage, and I/O usage.
Sorting: You can sort the process list based on different
criteria, such as CPU usage, memory usage, process name,
and process ID.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Process management: You can use the "top" command to
manage processes by sending signals to them or killing
them.
Configuration: You can customize the behavior of the "top"
command by changing its configuration options. For
example, you can change the update interval, toggle display
of different columns, and filter the process list by user or
process name.
Renice :
Find the process ID (PID) of the process whose priority you
want to change using the "ps" command or any other
process monitoring tool.
Use the "renice" command followed by the priority value
and the process ID. For example, to increase the priority of
a process with PID 1234 to 10, you can run the following
command:
renice 10 1234
Note that you need root privileges or be the owner of the
process to change its priority.
The new priority value will take effect immediately, and the
process will receive more or less CPU time depending on
the new priority value.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
File and Command Monitoring
File monitoring and command monitoring are two types of
monitoring systems that are commonly used in computer
systems.
File monitoring is the process of monitoring changes to files
and directories on a computer system. This can include
changes to the content of files, the creation or deletion of
files, and changes to the permissions or ownership of files.
File monitoring is often used for security purposes, such as
detecting unauthorized access or changes to critical system
files.
There are various tools available for file monitoring, such as
the Linux inotify tool, Windows File System Watcher, and
the macOS FSEvents API. These tools allow administrators
to monitor specific files or directories and receive alerts
when changes occur.
Command monitoring, on the other hand, is the process of
monitoring the commands executed on a computer system.
This can include monitoring the commands executed by
users, as well as system-level commands executed by
privileged users or system services. Command monitoring is
often used for security and auditing purposes, to detect
unauthorized or suspicious activity on a system.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
There are several tools available for command monitoring,
such as the Linux auditd tool, Windows PowerShell logging,
and macOS audit subsystem. These tools allow
administrators to capture information about commands
executed on a system, including the user who executed the
command, the time and date of execution, and any
parameters passed to the command.
Both file monitoring and command monitoring are
important tools for system administrators and security
professionals, as they provide valuable insights into the
activity occurring on a system and help detect and prevent
security breaches.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Tail
The tail command is a Linux/Unix command that is used to
display the last few lines of a file or output. The tail
command can be useful for monitoring logs or other files
that are frequently updated.
Here are some examples of how to use the tail command:
Display the last 10 lines of a file:

bash
tail file.txt

Display the last 20 lines of a file:


bash

tail -n 20 file.txt

Display the last 10 lines of a file and continuously monitor


for changes:
bash

tail -f file.txt

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Display the last 10 lines of multiple files:

bash

tail file1.txt file2.txt

Display the last 10 lines of a file and include line numbers:

bash

tail -n +1 -v file.txt

Example :

sudo tail -f /var/log/apache2/access.log

https://cyberpublicschool.com/
OSCP PRACTICE PART 01

Watch
The watch command is a Linux/Unix command that is used
to repeatedly execute a command and display the output in
the terminal. The watch command can be useful for
monitoring changes to system resources or for running
commands that need to be executed repeatedly.
Here are some examples of how to use the watch
command:
Execute the ls command every 2 seconds and display the
output:
bash
watch -n 2 ls

Monitor changes to the system log file in real-time:


bash

watch tail /var/log/syslog

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Monitor changes to the output of a command that takes
parameters:

arduino
watch 'netstat -an | grep :80 | wc -l'

In all of these examples, the watch command is used to


repeatedly execute a command and display the output in
the terminal. The -n option is used to specify the interval
between executions of the command.
Note that in example 3, the command being executed
(netstat -an | grep :80 | wc -l) is enclosed in single quotes.
This is because the command contains special characters
that need to be interpreted by the shell, and enclosing the
command in quotes prevents the shell from interpreting
those characters.
Example :

watch -n 5 w

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Downloading files
Download a file from the internet, you generally need to
follow these steps:
1. Open your web browser and navigate to the website
that has the file you want to download.
2. Find the link to the file you want to download. This
might be a button that says "Download" or a link that
points to a file (e.g., a .zip or .exe file).
3. Click on the link to start the download. Depending on
your browser and settings, you may be prompted to
choose a location on your computer to save the file.
4. Wait for the file to download. This may take anywhere
from a few seconds to several minutes or longer,
depending on the size of the file and the speed of your
internet connection.
5. Once the download is complete, navigate to the folder
where the file was saved on your computer. You can
then open, extract, or run the file as needed.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Wget
wget is a command-line tool used for downloading files
from the internet. It is commonly available on Linux and
Unix-based systems, but there are also versions for
Windows and other operating systems.
The basic syntax of wget is:
css
wget [options] [URL]

Here, [options] are optional parameters that modify the


behavior of wget, and [URL] is the web address of the file to
be downloaded.
Some commonly used options with wget are:
• -O or --output-document: specifies the output filename
or path of the downloaded file
• -c or --continue: resumes a partially downloaded file
• -r or --recursive: downloads files recursively from the
specified URL and its subdirectories
• -P or --directory-prefix: specifies the directory where
the downloaded file will be saved
• -q or --quiet: runs wget in quiet mode, suppressing
output to the console
• -b or --background: runs wget in the background,
allowing the terminal to be used for other tasks

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
For example, to download a file named example.zip from
the website https://example.com/downloads/ and save it in
the current directory, you could use the following
command:
arduino

wget https://example.com/downloads/example.zip

Or to download the same file and save it with a different


name (newname.zip) in a specific directory
(/home/user/downloads/), you could use:
ruby

wget https://example.com/downloads/example.zip
-O /home/user/downloads/newname.zip

Note that wget may not be installed by default on all


systems, so you may need to install it first using your
system's package manager or by downloading it manually.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Curl
curl command to download files from a URL. The basic
syntax for using curl to download a file is:

mathematica

curl -O [URL]

For example, to download a file named "example.txt" from


a website, you can run the following command:
arduino

curl -O https://www.example.com/example.txt

This will download the file and save it with the same name
in your current working directory.
You can also specify a different filename for the
downloaded file using the -o option:
css

curl -o [filename] [URL]

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
For example, to download the same "example.txt" file and
save it as "my-example.txt", you can run the following
command:

perl
curl -o my-example.txt
https://www.example.com/example.txt

curl -o report.pdf https://www.offensive-


security.com/reports/penetration
-testing-sample-report-2013.pdf

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Axel
Axel is a command-line download accelerator for Linux and
Unix-based systems that allows you to download files faster
by using multiple connections. It splits a single file into
multiple segments and downloads them simultaneously,
which can significantly increase download speeds,
especially for large files.
To install Axel on Ubuntu, Debian or their derivatives, you
can use the following command:

arduino

sudo apt-get install axel

Once installed, you can use Axel to download a file by


running the following command:
css

axel [URL]

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
For example, to download a file named "example.txt" from
a website using Axel, you can run the following command:
arduino

axel https://www.example.com/example.txt

Axel will split the file into multiple segments and download
them simultaneously, which can result in faster download
speeds. By default, Axel uses 4 connections, but you can
change this using the -n option followed by the number of
connections you want to use. For example, to use 8
connections, you can run the following command:
arduino

axel -n 8 https://www.example.com/example.txt

Example :

axel -a -n 20 -o report_axel.pdf
https://www.offensive-security.com/repor
ts/penetration-testing-sample-report-2013.pdf

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Customizing the Bash Environment
The Bash environment can be customized in various ways to
suit the user's preferences and needs. Here are some ways
to customize the Bash environment:
Aliases: Aliases are shortcuts for frequently used
commands. They can be created by adding the following
line to the ~/.bashrc file: alias alias_name='command'. For
example, alias ll='ls -alF' will create an alias for ls -alF
command as ll.
Environment Variables: Environment variables are variables
that are used to store information that can be accessed by
programs running in the shell. They can be set using the
export command. For example, export
PATH=$PATH:/usr/local/bin will add /usr/local/bin to the
PATH environment variable.
Prompt: The prompt can be customized by setting the PS1
variable in the ~/.bashrc file. For example, export
PS1='\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\$ ' will set
the prompt to display the username, hostname, and
working directory in green and yellow colors.
Functions: Functions can be created to perform complex
operations or to automate a sequence of commands. They
can be defined in the ~/.bashrc file. For example, function
extract() { if [ -f $1 ]; then tar xvf $1; else echo "File not
found"; fi; } will create a function named extract that
extracts a tar file if it exists.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
History: The history of the commands entered in the shell
can be customized by setting the HISTSIZE and HISTFILESIZE
environment variables. For example, export HISTSIZE=1000
and export HISTFILESIZE=2000 will set the history size to
1000 commands in memory and 2000 commands in the
history file.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Bash History Customization
Customizing the Bash history with commands:
To ignore specific commands from being saved in the
history, you can use the history -d command. For example,
to ignore the previous ls command, run the following
command: history -d $(history | tail -n 2 | head -n 1 | awk
'{print $1}'). This will delete the previous ls command from
the history.
To exclude duplicates from being saved in the history, you
can use the HISTCONTROL environment variable with the
ignoredups option. For example, to exclude duplicates, add
the following line to the ~/.bashrc file: export
HISTCONTROL=ignoredups.
To search the history using a specific keyword, you can use
the history | grep command. For example, to search for all
commands containing the word git, run the following
command: history | grep git.
To clear the entire history, use the history -c command. For
example, to clear the entire history, run the following
command: history -c.
To save the history immediately after executing a
command, you can use the history -a command. For
example, to save the history immediately after executing a
command, add the following line to the ~/.bashrc file:
export PROMPT_COMMAND='history -a'.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Example :

export HISTCONTROL=ignoredups

"&:ls:[bf]g:exit:history"
mkdir test
cd test
/test$ ls
/test$ pwd
/test
/test$ ls
/test$ history

export HISTTIMEFORMAT='%F %T '


history

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Alias
In Bash, an alias is a shortcut for a command or set of
commands. Creating aliases can help you save time and
improve productivity by reducing the amount of typing you
have to do. Here's how to create and use aliases in Bash:
Creating an alias: To create an alias, use the following
command: alias alias_name='command_to_alias'. For
example, to create an alias for the ls -la command, run the
following command: alias ll='ls -la'.
Listing aliases: To list all currently defined aliases, use the
alias command without any arguments. For example, to list
all defined aliases, run the following command: alias.
Removing an alias: To remove an alias, use the unalias
command followed by the alias name. For example, to
remove the ll alias created earlier, run the following
command: unalias ll.
Using an alias: To use an alias, simply type the alias name in
the terminal followed by any arguments. For example, to
use the ll alias created earlier, run the following command:
ll.

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Creating persistent aliases: To make an alias persistent so
that it is available every time you open a new terminal
window, add the alias command to your ~/.bashrc file. For
example, to make the ll alias persistent, add the following
line to the ~/.bashrc file: alias ll='ls -la’.
Using aliases with arguments: You can use an alias with
arguments by using the $1, $2, etc. variables to represent
the arguments. For example, to create an alias for the
mkdir command that creates a directory and then cd's into
it, run the following command: alias mkcd='mkdir -p "$1"
&& cd "$1"'. Then, to use the mkcd alias to create and
change to a directory called mydir, run the following
command: mkcd mydir.
Example :

alias lsa='ls -la'


lsa

alias mkdir='ping -c 1 localhost'


mkdir

https://cyberpublicschool.com/
OSCP PRACTICE PART 01

unalias mkdir
mkdir

persistent bash customization


The behavior of interactive shells in Bash is determined by
the system-wide bashrc file located in /etc/bash.bashrc.
The system-wide Bash settings can be overridden by editing
the .bashrc file located in any user’s home directory.
In the previous section, we explored the alias command,
which sets an alias for the current terminal session. We can
also insert this command into the .bashrc file in a user’s
home directory to set a persistent alias. The .bashrc script is
executed any time that user logs in. Since this file is a shell
script, we can insert any command that could be executed
from the command prompt.

cat ~/.bashrc

https://cyberpublicschool.com/
OSCP PRACTICE PART 01
Define functions: Functions are similar to aliases, but they
allow you to define more complex commands. For example,
you can create a function that searches for a file in a
specific directory and opens it in your favorite editor. To
define a function, you can add the following lines to your
.bashrc file:

bash

function edit_file() {
cd /path/to/files
vim $1
}

https://cyberpublicschool.com/
OSCP PRACTICE PART 01

Contacts us
https://cyberpublicschool.com/

https://www.instagram.com/cyberpublicschool/

Phone no.: +91 9631750498 India


+61 424866396 Australia

Our Successful Oscp Student.

https://cyberpublicschool.com/

You might also like