# Bad DNS

### Contexte

Suite à des flux suspects détectés sur le réseau et d’après les premières investigations de votre CERT, un attaquant semble avoir mis en place un service DNS malicieux derrière le FQDN secret.dns-challenge.apssis.org. Arriverez-vous à percer sont secret ?

**Paramètres de connexion pour ce challenge :**

Serveur : dns-challenge.apssis.org Port : 666

### Découverte du serveur DNS

Je lance un dig vers le serveur :&#x20;

```
onosh@labrioche:$ nslookup dns-challenge.apssis.org
Server:         x
Address:        x

Non-authoritative answer:
Name:   dns-challenge.apssis.org
Address: 51.83.97.109

onosh@labrioche:$ dig dns-challenge.apssis.org

; <<>> DiG 9.18.0-2-Debian <<>> dns-challenge.apssis.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: FORMERR, id: 31875
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: c8940d827b815aaa (echoed)
;; QUESTION SECTION:
;dns-challenge.apssis.org.      IN      A

;; Query time: 5 msec
;; SERVER: 172.16.16.101#53(172.16.16.101) (UDP)
;; WHEN: Wed Apr 06 11:15:40 CEST 2022
;; MSG SIZE  rcvd: 65
```

### Analyse du FQDN

Il existe une technique d'injection de données/commandes via DNS basé sur les enregistrements TXT :&#x20;

![](/files/qWrYXagHHmGDX2NikACl)

{% embed url="<https://unit42.paloaltonetworks.com/dns-tunneling-how-dns-can-be-abused-by-malicious-actors>" %}

Je lance une requête dig TXT en spécifiant le serveur dns, le port et le FQDN ciblé.

On découvre un enregistrement TXT louche...

```
dig TXT @dns-challenge.apssis.org -p 666 secret.dns-challenge.apssis.org

; <<>> DiG 9.18.0-2-Debian <<>> TXT @dns-challenge.apssis.org -p 666 secret.dns-challenge.apssis.org
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 16273
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 88ab417ba1702cd910a767a9624d5b05455d84fe3a742c34 (good)
;; QUESTION SECTION:
;secret.dns-challenge.apssis.org. IN    TXT

;; ANSWER SECTION:
secret.dns-challenge.apssis.org. 604800 IN TXT  "Yr frperg qr pr punyyratr rfg : QAFZrffratre hgvyvfr qrf raertvfgerzragf QAF qr glcr GKG cbhe rkrphgre qvfpergrzrag qrf pbzznaqrf Cbjrefuryy fhe yrf znpuvarf ivpgvzrf qrchvf yrfdhryyrf vy rfg rkrphgr"

;; AUTHORITY SECTION:
secret.dns-challenge.apssis.org. 604800 IN NS   dns-challenge.apssis.org.

;; Query time: 25 msec
;; SERVER: 51.83.97.109#666(dns-challenge.apssis.org) (UDP)
;; WHEN: Wed Apr 06 11:19:01 CEST 2022
;; MSG SIZE  rcvd: 314
```

### Analyse de l'enregistrement TXT

Par réflexe, je pense à l'encodage césar :&#x20;

```
Yr frperg qr pr punyyratr rfg : QAFZrffratre hgvyvfr qrf raertvfgerzragf QAF qr glcr GKG cbhe rkrphgre qvfpergrzrag qrf pbzznaqrf Cbjrefuryy fhe yrf znpuvarf ivpgvzrf qrchvf yrfdhryyrf vy rfg rkrphgr
```

![Encodage césar](/files/Lky7kjoYikDSFMddNVLQ)

J'applique une rotation de 13 (rotation par défaut) sur le message encodé et je récupère le flag :&#x20;

```
onosh@labrioche:$ echo 'Yr frperg qr pr punyyratr rfg : QAFZrffratre hgvyvfr qrf raertvfgerzragf QAF qr glcr GKG cbhe rkrphgre qvfpergrzrag qrf pbzznaqrf Cbjrefuryy fhe yrf znpuvarf ivpgvzrf qrchvf yrfdhryyrf vy rfg rkrphgr' |tr 'A-Za-z' 'N-ZA-Mn-za-m'
Le secret de ce challenge est : DNSMessenger utilise des enregistrements DNS de type TXT pour executer discretement des commandes Powershell sur les machines victimes depuis lesquelles il est execute
```


---

# 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://book.onosh.ovh/ctf/cnssis2022/bad-dns.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.
