Linux is an operating system used for personal computer, servers and even Mobil devices. linux stands as a fundamental pillar of the cyber security for it's robustness flexibility and open-source nature. first it was created as a kernel then ultimately linux operating system started with Unix operating system release by ken Thompson. At first in 1991 linux release the first operation system by Linus Torvalds. now about 600 distribution are available. the most popular and most usage Ubuntu, Davian, Fedora, Manjaro, redhat. as it is a open source so anyone can modify it source code. the five core principal is everything is a file, small and single purpose program, Ability to chain programs together to perform complex tasks, Avoid captive user interfaces, Configuration data stored in a text file. the components are Bootloader, OS kernel, Daemons, OS shell, graphics server, utilities, windows manager . linux file system:
- / : The top-level directory is the root filesystem and contains all of the files required to boot the operating system.
- / bin: Contains essential command binaries.
- / etc: Local system configuration files. Configuration files for installed applications may be saved here as well.
- / home: Each user on the system has a subdirectory here for storage.
- / opt: Optional files such as third-party tools can be saved here.
- / root: The home directory for the root user.
- / sbin: This directory contains executables used for system administration (binary system files).
- / user: contains all executable libraries and man files.
- / var: This directory contains variable data files such as log files, email in-boxes, web application related files, cron files, and more.
shell
or command line, provides a text-based input/output (I/O) interface between users and the kernel for a computer system. The most commonly used shell in Linux is the Bourne-Again Shell
(BASH
), and is part of the GNU project. Everything we do through the GUI we can do with the shell. The shell gives us many more possibilities to interact with programs and processes to get information faster. Besides, many processes can be easily automated with smaller or larger scripts that make manual work much easier.prompt: The Bash prompt is the text displayed in the terminal that indicates the shell is ready to accept a command. It’s part of the Bash shell, which is a command-line interpreter used on Unix-based systems like Linux and macOS. ~: This represents the current directory. A tilde (~
) stands for the user's home directory. $: Indicates that commands can now be typed (it's usually $
for regular users and #
for the root user).
The prompt can be customized using special characters and variables in the shell’s configuration file (.bashrc
for the Bash shell). For example, we can use: the \u
character to represent the current username, \h
for the hostname, and \w
for the current working directory.
\d Date (Mon Feb 6), \D {%Y-%m-%d} Date (YYYY-MM-DD), \H Full hostname, \j Number of jobs managed by the shell, \n Newline, \r Carriage return, \s Name of the shell, \t Current time 24-hour (HH:MM:SS), \T Current time 12-hour (HH:MM:SS), \@ Current time, \u Current username,\w Full path of the current working directory
Customizing the prompt can be a useful way to make your terminal experience more personalized and efficient. It can also be a helpful tool for troubleshooting and problem-solving, as it can provide important information about the system’s state at any given time. some commands to get the system information;
- whoami Displays current username.
- id Returns users identity
- hostname print the current host of the system
- uname print the basic information about OS and hardware.
- pwd print the working directory
- ifconfig print the network interface address.
- ip print the routing, network interface and tunnels.
- netstat print the networks status.
- ss investigate sockets.
- ps print the process status.
- who print the who are logged in.
- env print the environment or sets and executes command
- lsblk print how many device are blocked.
- lsusb list of usb devices.
- lsof list of open file.
- lspci list of pci device.
- whatis for see tools and command info
Linux is very favorite for using it's command line use. that make it's more popular. because it's provide huge facility's for a user. you an edit , create, delete, and can many more in terminal command. lets see some command:
stderr (Standard Error)
more
and less
, you can easily scroll
through large files, search for text, and navigate forward or backward
without modifying the file itself. This is especially useful when you're
working with large logs or text files that don't fit neatly into one
screen.regex (Regular Expressions)
Regular expressions are a powerful tool to do pattern based selection. It uses special notations similar to those we've encountered already such as the * wildcard. We'll go through a couple of the most common regular expressions, these are almost universal with any programming language. They allow you to find, replace, and manipulate data with incredible precision. Think of RegEx as a highly customizable filter that lets you sift through strings of text, looking for exactly what you need—whether it's analyzing data, validating input, or performing advanced search operations. let's see some of these examples:
(^) words name : it will return Beginning of a line with start the word.
($) words name : it will return End of a line with end the words.
words name (.) : Matching any single character with using the word and .
word name [] word name : This can be a little tricky, brackets allow us to specify characters found within the bracket. you can use word in the [] bracket which word do you want to find out. like you want to find out this word which is created by d and then next word is i, l, k etc and last word is g . in this case you can do it easy way d[ilk]g. the word would be dig, dlg, dkg. you can also use rang by [a-z as you like] . but careful about case sensitive [A-Z] and [a-z] these are not similar. so the result comes different. you can also use and, or operator like (b.*passwd) . you can also use pip like (mysql | bin) it's means when any one match it will grep it.
Permission Management
In Linux, permissions are like keys that control access to files and directories. These permissions are assigned to both users and groups, much like keys being distributed to specific individuals and teams within an organization. Each user can belong to multiple groups, and being part of a group grants additional access rights, allowing users to perform specific actions on files and directories. so it's very important to us maintaining the permissions management. there are three types of permissions a file or directory. rwx means read, write and execute. The permissions can be set for the owner, group or other.
Change Permissions:
chmod
command, permission group references (u
- owner, g
- Group, o
- others, a
- All users), and either a [+
] or a [-
] to add remove the designated permissions.read
only using the octal value assignment. like chomd 777 for give all permission read write and execute. 755 ,754 etc.User Management
Package Management
git
by using apt
. let see different package installation and removal process. SSH
) is a network protocol that allows the
secure transmission of data and commands over a network. It is widely
used to securely manage remote systems and securely access remote
systems to execute commands or transfer files. In order to connect to
our or a remote Linux host via SSH, a corresponding SSH server must be
available and running. The most commonly used SSH server is the OpenSSH server. OpenSSH is a
free and open-source implementation of the Secure Shell (SSH) protocol
that allows the secure transmission of data and commands over a network. you can easily install openssh from kali repository by typing sudo apt install openssh-server-y. OpenSSH can be configured and customized by editing the file /etc/ssh/sshd_config
with a text editor. Here we can adjust settings such as the maximum
number of concurrent connections, the use of passwords or keys for
logins, host key checking, and more. However, it is important for us to
note that changes to the OpenSSH configuration file must be done
carefully. NFS
) is a network protocol that allows
us to store and manage files on remote systems as if they were stored
on the local system. It enables easy and efficient management of files
across networks. For example, administrators use NFS to store and manage
files centrally (for Linux and Windows systems) to enable easy
collaboration and management of data. For Linux, there are several NFS
servers, including NFS-UTILS (Ubuntu
), NFS-Ganesha (Solaris
), and OpenNFS (Redhat Linux
). VPN
) functions like a secure,
invisible tunnel that connects us to another network, allowing seamless
and protected access as if we were physically present within it. This is
achieved by establishing an encrypted tunnel between the client and the
server, ensuring that all data transmitted through this connection
remains confidential and safeguarded from unauthorized access. We can install the server and client with the following command: Working with Web Services
apache2ctl,
systemctl
or service
commands . There also exists an apache2
binary, but it’s generally not used to directly to start the server
(this is due to the use of environment variables in the default
configuration.) After Apache has been started, we navigate using our browser to the
default page (http://localhost). By default, Apache will serve on HTTP
port 80, and your browser will default to this port as well whenever you
enter an HTTP URI (unless otherwise specified.). If you are using the Pwnbox, you might experience an error when
attempting to start Apache; this is due to port 80 being occupied by
another service. To set an alternate port for our web server, we can
edit the /etc/apache2/ports.conf
file. Here, we have set it to port 8080. Another important aspect of working with web servers is learning how to
communicate with them using command-line tools like curl and wget. These
tools are incredibly useful when we want to systematically analyze the
content of a webpage hosted on a web server. cURL
is a tool that allows us to transfer files from the shell over protocols like HTTP
, HTTPS
, FTP
, SFTP
, FTPS
, or SCP
,
and in general, gives us the possibility to control and test websites
remotely via command line. Besides the remote servers' content, we can
also view individual requests to look at the client's and server's
communication. Usually, cURL
is already installed on most Linux systems. wget
. With this tool, we
can download files from FTP or HTTP servers directly from the terminal,
and it serves as a solid download manager. If we use wget in the same
way, the difference to curl is that the website content is downloaded
and stored locally.Backup and Restore
apt
package manager for install this package. This will install the latest version of Rsync on the system. Once the
installation is complete, we can begin using the tool to back up and
restore data.
File System Management
The best file system choice depends on the specific requirements of the application or user such as:
-
ext2
is an older file system with no journaling capabilities, which makes it less suited for modern systems but still useful in certain low-overhead scenarios (like USB drives). -
ext3
andext4
are more advanced, with journaling (which helps in recovering from crashes), and ext4 is the default choice for most modern Linux systems because it offers a balance of performance, reliability, and large file support. -
Btrfs
is known for advanced features like snapshotting and built-in data integrity checks, making it ideal for complex storage setups. -
XFS
excels at handling large files and has high performance. It is best suited for environments with high I/O demands -
NTFS
, originally developed for Windows, is useful for compatibility when dealing with dual-boot systems or external drives that need to work on both Linux and Windows systems. Linux's file system architecture is based on the Unix model, organized in a hierarchical structure. In Linux, files can be stored in one of several key types:
- Regular files
- Directories
- Symbolic links
Network Configuration
Network Access Control
Another vital component of network configuration is network access control (NAC
).
As penetration testers, we need to be well-versed in how NAC can
enhance network security and the various technologies available. Key NAC
models include:
Type | Description |
---|---|
Discretionary Access Control (DAC ) |
This model allows the owner of the resource to set permissions for who can access it. |
Mandatory Access Control (MAC ) |
Permissions are enforced by the operating system, not the owner of the resource, making it more secure but less flexible. |
Role-Based Access Control (RBAC ) |
Permissions are assigned based on roles within an organization, making it easier to manage user privileges. |
ifconfig
command is still widely used in many Linux distributions and continues to be a reliable tool for network management. we can use the route
command with the add
option. On Linux systems, this can be achieved by updating the /etc/resolv.conf
file, which is a simple text file containing the system’s DNS
information. By adding the appropriate DNS server addresses (Google's
public DNS - 8.8.8.8
or 8.8.4.4
), the system can correctly resolve domain names to IP addresses, ensuring smooth communication over the network. After completing the necessary modifications to the network
configuration, it is essential to ensure that these changes are saved to
persist across reboots. This can be achieved by editing the /etc/network/interfaces
file, which defines network interfaces for Linux-based operating
systems. Thus, it is vital to save any changes made to this file to
avoid any potential issues with network connectivity. This will open the interfaces
file in the vim editor. We can add the network configuration settings to the file like this.SELinux
, AppArmor
, and TCP wrappers
on your own. Remote Desktop Protocols in Linux
Remote desktop protocols are used in Windows, Linux, and macOS to provide graphical remote access to a system. Two of the most common protocols for this type of access are:
-
Remote Desktop Protocol
(RDP
): Primarily used in Windows environments. RDP allows administrators to connect remotely and interact with the desktop of a Windows machine as if they were sitting right in front of it. -
Virtual Network Computing
(VNC
): A popular protocol in Linux environments, although it is also cross-platform. VNC provides graphical access to remote desktops, allowing administrators to perform tasks on Linux systems in a similar way to RDP on Windows.
For these VNC connections, many different tools are used. Among them are for example:
iptables
to restrict traffic into/out of the host. Besides, there are different applications and services such as Snort, chkrootkit, rkhunter, Lynis, and others that can contribute to Linux's security. TCP wrapper is a security mechanism used in Linux systems that allows
the system administrator to control which services are allowed access to
the system. command cat /etc/hosts.allow or deny. Service | Description |
---|---|
Apache |
Access logs are stored in the /var/log/apache2/access.log file (or similar, depending on the distribution). |
Nginx |
Access logs are stored in the /var/log/nginx/access.log file (or similar). |
OpenSSH |
Access logs are stored in the /var/log/auth.log file on Ubuntu and in /var/log/secure on CentOS/RHEL. |
MySQL |
Access logs are stored in the /var/log/mysql/mysql.log file. |
PostgreSQL |
Access logs are stored in the /var/log/postgresql/postgresql-version-main.log file. |
Systemd |
Access logs are stored in the /var/log/journal/ directory. |
Security logs
These security logs and their events are often recorded in a variety
of log files, depending on the specific security application or tool in
use. For example, the Fail2ban application records failed login attempts
in the /var/log/fail2ban.log
file, while the UFW firewall records activity in the /var/log/ufw.log
file. Other security-related events, such as changes to system files or
settings, may be recorded in more general system logs such as /var/log/syslog
or /var/log/auth.log
.
As penetration testers, we can use log analysis tools and techniques to
search for specific events or patterns of activity that may indicate a
security issue and use that information to further test the system for
vulnerabilities or potential attack vectors.
0 Comments
Thanks For your comment