> For the complete documentation index, see [llms.txt](https://aas-s3curity.gitbook.io/cheatsheet/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aas-s3curity.gitbook.io/cheatsheet/internalpentest/active-directory/reconnaissance/enumerating-services.md).

# Enumerating Services

### SMB

To make our life easier during exploitation and post-exploitation, machines with port 445 open must be enumerated.

```bash
sudo nmap -Pn -p 445 -iL targets_rfc1918.txt -oA targets_smb ;
cat targets_smb.gnmap | grep "445/open" | cut -d" " -f 2 > targets_smb.txt
```

### Databases Ports

You can enumerate SQL services with:

```bash
sudo nmap -Pn -p 1433,3306,5432 -iL targets_rfc1918.txt -oA targets_sql ;
cat targets_sql.gnmap | grep "1433/open" | cut -d" " -f 2 > targets_sqlserver.txt ;
cat targets_sql.gnmap | grep "3306/open" | cut -d" " -f 2 > targets_mysql.txt ;
cat targets_sql.gnmap | grep "5432/open" | cut -d" " -f 2 > targets_postgresql.txt
```

### Administrative Ports

It is interesting to enumerate administrative services:

```bash
sudo nmap -Pn -p 21,22,23,88,3389,5900 -iL targets_rfc1918.txt -oA targets_adm ;
cat targets_sql.gnmap | grep "21/open" | cut -d" " -f 2 > targets_ftp.txt ;
cat targets_sql.gnmap | grep "22/open" | cut -d" " -f 2 > targets_ssh.txt ;
cat targets_sql.gnmap | grep "23/open" | cut -d" " -f 2 > targets_telnet.txt ;
cat targets_sql.gnmap | grep "3389/open" | cut -d" " -f 2 > targets_rdp.txt ;
cat targets_sql.gnmap | grep "5900/open" | cut -d" " -f 2 > targets_vnc.txt
```

### Web Ports

Enumerating web services is important to test for sensitive web applications exposure (administrative applications, vulnerable applications, etc).

```bash
sudo nmap -Pn -p 80,443,8080,8443,9006,7001,7002,8081,49153,10000 -iL targets_rfc1918.txt -oA targets_web
```

All these scans give us valuable information.

{% hint style="info" %}
When a blacklist is provided by client, simply use:

* **zmap:**
  * \--blacklist-file
* **nmap:**
  * \--excludefile
    {% endhint %}

## Automating

This script automatize previous steps.

```bash
sudo nmap -Pn -p 445 -iL targets_rfc1918.txt -oA targets_smb ;
cat targets_smb.gnmap | grep "445/open" | cut -d" " -f 2 > targets_smb.txt ;
sudo nmap -Pn -p 1433,3306,5432 -iL targets_rfc1918.txt -oA targets_sql ;
cat targets_sql.gnmap | grep "1433/open" | cut -d" " -f 2 > targets_sqlserver.txt ;
cat targets_sql.gnmap | grep "3306/open" | cut -d" " -f 2 > targets_mysql.txt ;
cat targets_sql.gnmap | grep "5432/open" | cut -d" " -f 2 > targets_postgresql.txt ;
sudo nmap -Pn -p 21,22,23,88,3389,5900 -iL targets_rfc1918.txt -oA targets_adm ;
cat targets_adm.gnmap | grep "21/open" | cut -d" " -f 2 > targets_ftp.txt ;
cat targets_adm.gnmap | grep "22/open" | cut -d" " -f 2 > targets_ssh.txt ;
cat targets_adm.gnmap | grep "23/open" | cut -d" " -f 2 > targets_telnet.txt ;
cat targets_adm.gnmap | grep "3389/open" | cut -d" " -f 2 > targets_rdp.txt ;
cat targets_adm.gnmap | grep "5900/open" | cut -d" " -f 2 > targets_vnc.txt ;
sudo nmap -Pn -p 80,443,8080,8443,9006,7001,7002,8081,49153,10000 -iL targets_rfc1918.txt -oA targets_web
```


---

# 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, and the optional `goal` query parameter:

```
GET https://aas-s3curity.gitbook.io/cheatsheet/internalpentest/active-directory/reconnaissance/enumerating-services.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
