Buffer overflow example for python

Overview

INSTALLATION

https://github.com/corelan/mona https://github.com/stephenbradshaw/vulnserver https://www.immunityinc.com/products/debugger/

REQUIREMENTS / used tools

msfvenom netcat Immunity debugger (reverse engineering)

FOLDER SHORTCUTS

/usr/share/metasploit-framework/tools/exploit ./nasm_shell.rb -> use JMP ESP code /usr/share/metasploit-framework/tools/exploit ./pattern_created.rb -> use -l (in this code -l 3000) /usr/share/spike/audits -> example spike codes

SUMMARY

Pythonla yazdığım bufferoverflow örneği;

İlk olarak https://github.com/stephenbradshaw/vulnserver ' ı indiriyoruz. Bunun sebebi zafiyetli makine üzerinden örnek göstermek için. Ardından bize en çok gerekecek olan Immunity Debugger(https://debugger.immunityinc.com/ID_register.py) aracını indiriyoruz. İkisini de yönetici olarak çalıştırmamız gerek. İmmunity debuggerdan vulnserver'ı takip etcez. Bunun için sol üstte bulunan attach kısmından vulnserver'ı seçin. Eğer gözükmüyorsa vulnserver'ı tekrar yönetici olarak çalıştırmayı deneyin. play tuşuna basarak takip edebiliriz. Çalıştığını sağ alttaki Ready/Running kısmından anlayabiliriz. immunity

fuzzingpy

İlk olarak fuzzing kodumuzu yazalım.Kodu anlatmak gerekirse socket modülü bağlantı kurmamızı sağlar. Sleep modülü programın ne kadar süre bekletileceğini ayarlar. Bekletme amacımız server'a fazla yüklenmemek. sys modülü ise sistemde yapılabilecek işlemleri yönetir.

TRUN yazan şeyi ise deneyerek bulabileceğimiz bir şey. (RTIME, GDOG, GTER, LTER gibi versiyonlar da var.) Daha fazlasını şuradan okuyabilirsiniz: https://fluidattacks.com/blog/reversing-vulnserver/ .: ise çalışması için gerekli bir kod. Kodu özet olarak anlatacak olursam, program çökene kadar 100 tane a yolluyor. Çökünce bize kaçta çöktüğünü belirtiyor. Socket.connect kısmında ise kendi local ip ve 9999 portunu kullanmamız gerek. Latin1 encode kullanma sebebimiz karakterleri byte olarak yollamamız.

crashed

Görüldüğü gibi 2009 da crashlendi.O zaman offset kısmına geçelim.

offset

Bu kodun diğer koddan tek farkı characters kısmı. 2009'da crash ettiğini bildiğimiz için kendimize 3000 karakterli pattern yapıyoruz.(Yorum satırında belirtilen yerden yapabilirsiniz. Sadece linuxta geçerlidir.) 3000 yapma sebebimiz ise 2009 dan daha sonra crash yiyebilme ihtimalimiz var. Sıradaki kısım ise kötü karakterler.

badchars

2009'da crash yediğimizi önceden biliyorduk. Şimdi ise kodun çalışıp çalışmadığını deneyelim. Bx4 4 adet B eklediğimizde görüldüğü üzere 414141 den 424242 ye geçiş yapmış, yani çalışıyor. Kötü karakterleri ekleme sebebimiz buffer overflow çalışıyor mu sorusuna cevap vermek. Bunu immunity debuggerdan takip edebilirsiniz. Bad Characters : https://www.adamcouch.co.uk/python-generate-hex-characters/

Sıradaki kısım Bufferoverflow kısmı.

bfoverflow

İlk işlemimiz https://github.com/corelan/mona ' yı indirip immunity debugger dosya konumundan PyCommands klasörüne .py uzantılı dosyayı atmak.

ffe4 Sonraki işlemimiz /usr/share/metasploit-framework/tools/exploit klasöründen nasm_shell.rb yi çalıştırıp JMP ESP yazmak. Sonra bize 4 bitlik hexadecimal sayı vercek. Bunun sebebini immunity debuggerda aşağıdaki arama kısmına verilen 4 bitlik sayı ile birlikte komutumuzu yazdığımızda öğrenceksiniz.

-s komutu ile bize verilen hexadecimal sayıyı tırnak işareti arasında yazarız. -m komutu ile açık olan dosyayı belirtiriz. Açık olduğunu ise şu şekilde anlarız; solundaki bütün değerler false ise koruması yok demektir. Görüldüğü gibi essfunc.dll değerleri false.

0x625 !mona find -s "\xff\xe4" -m essfunc.dll yazıp entera bastığımızda sonuçlar önümüze gelecektir. Gelen sonuçları deneyerek JMP ESP'nin çalıştığı sonucu bulmamız gerek. Örneğin en üstteki olan 0x625011AF den örnek verecek olursak

Kodumuzda "A"*2009 un yanına yazıyoruz ve sonuna \x90 ekliyoruz. Bunun sebebi x90 eklemediğimiz bazı zamanlar kodun çalışmadığı olabiliyor. 32 ile çarpma sebebimiz 32 bit olması.

En son kısmımız ise asıl amacımız olan kendimize bağlantı açmamız. Msfvenom ile c dilinde hexadecimal bir payload oluşturup netcat ile dinleyeceğiz. Ardından verilen hex payloadı python kodumuza yazalım. msfvenom

shellcode

En son işlem olan netcat ile nc -nvlp 4444(msfvenomda belirtilen lport) yazarak bağlantımızı oluşturmuş olduk.

NOT: Bu şekilde hata alıyorsanız yönetici olarak çalıştırmayı deneyiniz. fuzzing

NOT 2: Local IP'lerin farklı olmasının sebebi biri Linux'un diğeri Windows'un IP'si.

NOT 3: msfvenom kısmında EXITFUNC=thread yazdık fakat process de kullanabilirdik. Fakat öyle bir durum olsaydı multi/handler ile dinlememiz gerekirdi. Biz burada netcat ile dinledik.

NOT 4: Kodumuzda A, B gibi karakterler kullanarak açık bulmayı denedik. Linuxta bazı hazır spike kodları var. Spike kodları hakkında daha fazla bilgi sahibi olmak istiyorsanız https://resources.infosecinstitute.com/topic/intro-to-fuzzing/ sitesini ziyaret edebilirsiniz. https://null-byte.wonderhowto.com/how-to/hack-like-pro-build-your-own-exploits-part-3-fuzzing-with-spike-find-overflows-0162789/

Okuduğunuz için teşekkürler. Yanlış belirttiğim yer fark ederseniz [email protected] adresinden iletişime geçebilirsiniz.

Owner
Mehmet
Mehmet
This app is to use algorithms to find the root of the equation

In this repository, I made an amazing app with tkinter python language and other libraries the idea of this app is to use algorithms to find the root of the equation I used three methods from numeric

Mohammad Al Jadallah 3 Sep 16, 2022
An open-source hyper-heuristic framework for multi-objective optimization

MOEA-HH An open-source hyper-heuristic framework for multi-objective optimization. Introduction The multi-objective optimization technique is widely u

Hengzhe Zhang 1 Feb 10, 2022
Youtube Channel Website

Videos-By-Sanjeevi Youtube Channel Website YouTube Channel Website Features: Free Hosting using GitHub Pages and open-source code base in GitHub. It c

Sanjeevi Subramani 5 Mar 26, 2022
Simple yet flexible natural sorting in Python.

natsort Simple yet flexible natural sorting in Python. Source Code: https://github.com/SethMMorton/natsort Downloads: https://pypi.org/project/natsort

Seth Morton 712 Dec 23, 2022
Run python scripts and pass data between multiple python and node processes using this npm module

Run python scripts and pass data between multiple python and node processes using this npm module. process-communication has a event based architecture for interacting with python data and errors ins

Tyler Laceby 2 Aug 06, 2021
Experiments with Tox plugin system

The project is an attempt to add to the tox some missing out of the box functionality. Basically it is just an extension for the tool that will be loa

Volodymyr Vitvitskyi 30 Nov 26, 2022
☘️ Projet Voltaire Solver in Python3

☘️ Projet Voltaire Solver in Python3

Bidouffe 8 Dec 02, 2022
Old versions of Deadcord that are problematic or used as reference.

⚠️ Unmaintained and broken. We have decided to release the old version of Deadcord before our v1.0 rewrite. (which will be equiped with much more feat

Galaxzy 1 Feb 10, 2022
Table (Finnish Taulukko) glued together to transform into hands-free living.

taulukko Table (Finnish Taulukko) glued together to transform into hands-free living. Installation Preferred way to install is as usual (for testing o

Stefan Hagen 2 Dec 14, 2022
Library management using python & MySQL

Library management using python & MySQL Dev/Editor: Pavan Ananth Sharma & MK Akash Introduction: This is an intermediate project which is a user-frie

Pavan Ananth Sharma 2 Jul 05, 2022
Chemical equation balancer

Chemical equation balancer Balance your chemical equations with ease! Installation $ git clone

Marijan Smetko 4 Nov 26, 2022
SuperCollider library for Python

SuperCollider library for Python This project is a port of core features of SuperCollider's language to Python 3. It is intended to be the same librar

Lucas Samaruga 65 Dec 22, 2022
Packaging tools for shanty services.

parcel Packaging tools for shanty services. What? Services are docker containers deployed by shanty on a hosting appliance. Each service consists of t

0 Jan 20, 2022
Self sustained producer-consumer(prosumer) policy study using Python and Gurobi

Prosumer Policy This project aims to model the optimum dispatch behaviour of households with PV and battery systems under different policy instrument

Tom Xu 3 Aug 31, 2022
The earliest beta version of pytgcalls on Linux x86_64 and ARM64! Use in production at your own risk!

Public beta test. Use in production at your own risk! tgcalls - a python binding for tgcalls (c++ lib by Telegram); pytgcalls - library connecting pyt

Il'ya 21 Jan 13, 2022
Push a record and you will receive a email when that date

Push a record and you will receive a email when that date

5 Nov 28, 2022
TinyBar - Tiny MacOS menu bar utility to track price dynamics for assets on TinyMan.org

📃 About A simple MacOS menu bar app to display current coins from most popular

Al 8 Dec 23, 2022
A simple script that can watch a list of directories for change and does some action

plot_watcher A simple script that can watch a list of directories and does some action when a specific kind of change happens In its current implement

Charaf Errachidi 12 Sep 10, 2021
Improving the Transferability of Adversarial Examples with Resized-Diverse-Inputs, Diversity-Ensemble and Region Fitting

Improving the Transferability of Adversarial Examples with Resized-Diverse-Inputs, Diversity-Ensemble and Region Fitting

Junhua Zou 7 Oct 20, 2022
A collection of Workflows samples for various use cases

Workflows Samples Workflows allow you to orchestrate and automate Google Cloud and HTTP-based API services with serverless workflows.

Google Cloud Platform 76 Jan 07, 2023