Linux Incident
Linux Incident
https://app.letsdefend.io/training/lesson_detail/users-and-groups 2/24
09/01/2024, 18:13 Users and Groups - LetsDefend
Most system administrators won’t periodically conduct check-up’s regarding the devices under their responsibility. Thus, when a
user is taken over or a new user Home
is addedLearn
into the operating system, itPricing
is very rarely recognized.
free trialSince the7 possibility of it being
recognized is very low, attackers frequently Practice
choose this method in order toStart
Challenge a 1-day
maintain persistence.
In addition, since the passwords that are included for users by default are not changed/forgotten during set-up, attackers can
easily access the operating system.
If the general anatomy of a cyber attack is examined, attackers access the system as a result of exploiting the vulnerability on a
service that is open to the Internet, and since these services are mostly unauthorized service accounts, the attackers compromise
the users on the operating system in order to increase their privileges on the system.
As an incident responder, we must be able to detect the users that have been taken over, added or removed from the operating
system by the cyber-attackers.
“Everything is a file”
Everything is a file describes one of the defining features of Unix, and its derivatives—that a wide range of input/output resources
such as documents, directories, hard-drives, modems, keyboards, printers and even some inter-process and network
communications are simple streams of bytes exposed through the filesystem name space. (Wikipedia)
The UNIX file system contains critical files that contain information about users and groups. As an incident responder, it is
necessary to gain the ability to detect the existence of these files, their file structures, and the anomaly on these files.
The files containing the information of users and groups are as seen below:
/etc/passwd
Undoubtedly, one of the most crucial files in UNIX operating systems is /etc/passwd. This file contains usernames, the user's
password (depracated), UID/GID, the user's home directory and the user's shell information.
https://app.letsdefend.io/training/lesson_detail/users-and-groups 3/24
09/01/2024, 18:13 Users and Groups - LetsDefend
At first glance, the /etc/passwd file may seem confusing. However, each line in this file has a specific format.
https://app.letsdefend.io/training/lesson_detail/users-and-groups 4/24
09/01/2024, 18:13 Users and Groups - LetsDefend
https://app.letsdefend.io/training/lesson_detail/users-and-groups 5/24
09/01/2024, 18:13 Users and Groups - LetsDefend
You may think that including user passwords in a file may pose a security risk. The shadow file is readable only by the root user
and users in the shadow group and passwords are kept encrypted. Reading this file doesn't make any sense on its own. An
attacker who wants to discover a user's password must brute force it to find the password.
https://app.letsdefend.io/training/lesson_detail/users-and-groups 6/24
09/01/2024, 18:13 Users and Groups - LetsDefend
The section after the eighth colon is created for future use but is left empty because it is not currently used
Home Learn Practice Challenge PricingStart a 1-day free trial 7
/etc/group
The /etc/group file contains the groups and information about which users are included in these groups.
Identifying compromised users is not enough to understand the risk in a cybersecurity incident. User groups should also be
checked.
If a special configuration is not made, the www-data user is a user with low privilege. However, when determining the risk of a
cyber incident, it would be wrong to adopt a point of view such as "The www-data user has been compromised, but the risk is low
since the level of privileges is low". If the attacker includes the www-data user in an high privilege group, the www-data user can
have almost as much privilege as the root user.
The file named group belongs to the root user and everyone has read permission. For this reason, even if the attacker accesses
the system through the user with the lowest privileges, they can still collect information about the groups on the device.
https://app.letsdefend.io/training/lesson_detail/users-and-groups 8/24
09/01/2024, 18:13 Users and Groups - LetsDefend
Let’s take a look at the file format.Home Learn Practice Challenge PricingStart a 1-day free trial 7
Unlike other files, the sudoers file contains comments about the file format by default.
https://app.letsdefend.io/training/lesson_detail/users-and-groups 10/24
09/01/2024, 18:13 Users and Groups - LetsDefend
Incident Response
Analyze
Determining the Users on the System
https://app.letsdefend.io/training/lesson_detail/users-and-groups 11/24
09/01/2024, 18:13 Users and Groups - LetsDefend
https://app.letsdefend.io/training/lesson_detail/users-and-groups 12/24
09/01/2024, 18:13 Users and Groups - LetsDefend
Attackers prefer names such as support, service, dev, admin and sysadmin for the users they create in order to prevent
themselves from being detected.Home We should
LearnpayPractice
attentionChallenge
to users with these
PricingStartnames.
a 1-day free trial 7
If the passwd file has incorrect permissions, users can be compromised by editing the passwd file. Attackers can take over users
by replacing the "x" value next to their username with the password they created. For this reason, the information in the password
field in the passwd file should be carefully checked during the incident response.
In addition, the shell information of the users should be checked. Shell information of users who should not have shell should be
double-checked.
If the attacker has not cleaned the auth.log file, it is possible to detect newly created users via the auth.log file.
tail /var/log/auth.log
You can find newly created users by searching for the word “useradd” in the auth.log file.
https://app.letsdefend.io/training/lesson_detail/users-and-groups 13/24
09/01/2024, 18:13 Users and Groups - LetsDefend
You can identify users whose passwords have been changed by searching for the word “passwd” in the Auth.log file.
grep passwd /var/log/auth.log
cat /etc/group
Home Learn Practice Challenge PricingStart a 1-day free trial 7
While conducting our examinations, we must pay attention to the critical groups and the users included in these groups. Users
who should not be included in these groups should be identified. For example, the www-data user being included in the sudo
group is certainly suspicious. Some of the critical groups are as stated below:
root
adm
shadow
sudo
Another file that needs to be checked in order to understand the authorizations of users or groups is “/etc/sudoers”. There is
information on which users and groups can use sudo authority to what extent on this file.
cat /etc/sudoers
https://app.letsdefend.io/training/lesson_detail/users-and-groups 15/24
09/01/2024, 18:13 Users and Groups - LetsDefend
In the sudoers file, unauthorized users and the sudo authorizations that may cause a system compromise should not be defined.
In addition, incorrect configurations on this file should be determined.
You can list group processes by searching for the words “groupadd” and “usermod” in the auth.log file. Listing the group changes
in the date range of the attack will make it easier to track the actions taken by the attacker.
grep groupadd /var/log/auth.log
https://app.letsdefend.io/training/lesson_detail/users-and-groups 17/24
09/01/2024, 18:13 Users and Groups - LetsDefend
The last command obtains this information from the "/var/log/wtmp" file. You can get the same information by reading this file, but
the last command provides it in a more readable format.
cat /var/log/wtmp
https://app.letsdefend.io/training/lesson_detail/users-and-groups 18/24
09/01/2024, 18:13 Users and Groups - LetsDefend
The /var/log/auth.log file can be examined to detect users logged into the system via SSH. This file includes successful logins as
well as unsuccessful logons. In this
Homeway,Learn
we canPractice
detect brute-force
Challenge attacks fromawithin
PricingStart 1-daythe
freeauth.log
trial file. 7
You can list the failed login attempts with the following command.
grep "Failed password" /var/log/auth.log
As an alternative, failed SSH logins can be determined with the journalctl command.
journalctl _SYSTEMD_UNIT=ssh.service | egrep "Failed|Failure"
Identification of Users That Can Conduct SSH
During the incident response it may be necessary to detect users who can remotely conduct SSH to the device. You can learn
about users who can conduct RDP on Windows operating systems by listing the users included in the "Remote Desktop Users"
group. However, there is no similar group on Linux. The following steps should be followed in order to detect users who can
conduct SSH.
1. By reading the /etc/passwd file, the users on the system are detected.
2. Users who do not have a valid shell are removed from the list.
https://app.letsdefend.io/training/lesson_detail/users-and-groups 19/24
09/01/2024, 18:13 Users and Groups - LetsDefend
3. Users who do not have valid passwords are removed from the list.
4. Users with SSH permissionsHome
are detected in /etc/ssh/sshd_config. If "AllowUsers" is specified in this7 file, it means that other
users cannot use the SSH service. Learn Practice Challenge PricingStart a 1-day free trial
Eradication
At the end of the incident response, the system must be restored to its working condition in a way that has not been affected by
the cyber-attack.
Users added by the attacker should be deleted from the system. You can delete the user and the user's home directory with the
following command.
userdel -r USERNAME
Unauthorized users should be removed from groups with high authorizations. You can remove the user from the group with the
command below.
gpasswd -d USERNAME GROUP
https://app.letsdefend.io/training/lesson_detail/users-and-groups 20/24
09/01/2024, 18:13 Users and Groups - LetsDefend
The sudo authorization given to the user must be removed. You can edit sudo authorizations with the visudo command.
Home Learn Practice Challenge PricingStart a 1-day free trial 7
visudo
Passwords of users that should not be deleted should be changed and their SSH keys should be regenerated.
You can use the passwd command to change the user's password.
passwd USERNAME
https://app.letsdefend.io/training/lesson_detail/users-and-groups 21/24
09/01/2024, 18:13 Users and Groups - LetsDefend
In order to regenerate the user's SSH Keys, the old keys must be deleted first. Then a new SSH Key must be created.
Lab Environment
Connect
Questions Progress
Examine the /etc/passwd file. What is the name of the compromised account?
Answer Format: **** Submit
Hint
https://app.letsdefend.io/training/lesson_detail/users-and-groups 22/24
09/01/2024, 18:13 Users and Groups - LetsDefend
Back Next
LetsDefend
Social
Resources
Support
Community
https://app.letsdefend.io/training/lesson_detail/users-and-groups 23/24
09/01/2024, 18:13 Users and Groups - LetsDefend
Plans
Home Learn Practice Challenge PricingStart a 1-day free trial 7
Roles
https://app.letsdefend.io/training/lesson_detail/users-and-groups 24/24