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
The calculator on Python.

Calculator Contributors: Delitanast An official website. Information Hello! I am Damir. It`s my first Python project. I think you want see this. I imp

3 Mar 13, 2022
Master Duel Card Translator Project

Master Duel Card Translator Project A tool for translating card effects in Yu-Gi-Oh! Master Duel. Quick Start (for Chinese version only) Download the

67 Dec 23, 2022
Repositório de código de curso de Djavue ministrado na Python Brasil 2021

djavue-python-brasil Repositório de código de curso de Djavue ministrado na Python Brasil 2021 Completamente baseado no curso Djavue. A diferença está

Buser 15 Dec 26, 2022
Resizing using nnedi3/znedi3/nnedi3cl with center alignment and correct chroma placement

nnedi3_resample A VapourSynth script for easy resizing using nnedi3/znedi3/nnedi3cl with center alignment and correct chroma placement. Requirements n

Home Of VapourSynth Evolution 12 Sep 08, 2022
Mommas-cookbook - A Repository About Mom's Recipes

Mommas Cookbook A Repository for Mom's Recipes Contents bacalhau à Gomes de Sá Beef-Rendang bacalhau à Gomes de Sá, recommended by @s0undt3ch One of t

1 Jan 08, 2022
Framework for creating efficient data processing pipelines

Aqueduct Framework for creating efficient data processing pipelines. Contact Feel free to ask questions in telegram t.me/avito-ml Key Features Increas

avito.tech 137 Dec 29, 2022
tg-nearby Trilateration of nearby Telegram users as described in my corresponding article.

tg-nearby Trilateration of nearby Telegram users as described in my corresponding article. Setup If you want to toy with the code in this repository

Maximilian Jugl 75 Dec 26, 2022
Python / C++ based particle reaction-diffusion simulator

ReaDDy (Reaction Diffusion Dynamics) is an open source particle based reaction-diffusion simulator that can be configured and run via Python. Currentl

ReaDDy 46 Dec 09, 2022
Jannik Ramrath 1 Feb 05, 2022
Install JetBrains Toolbox

ansible-role-jetbrains-toolbox Install JetBrains Toolbox Example Playbook This example is taken from molecule/default/converge.yml and is tested on ea

Antoine Mace 2 Feb 04, 2022
A script to download all the challenges and files from the CTFd instance.

Python CTFd Downloader A script to download all the challenges and files from the CTFd instance. Installation Clone this repo: git clone https://githu

Jacob Elliott 19 Dec 16, 2022
rebalance is a simple Python 3.9+ library for rebalancing investment portfolios

rebalance rebalance is a simple Python 3.9+ library for rebalancing investment portfolios. It supports cash flow rebalancing with contributions and wi

Darik Harter 5 Feb 26, 2022
Data-driven Computer Science UoB

COMS20011_2021 Data-driven Computer Science UoB Staff Laurence Aitchison [ 6 May 16, 2022

PORTSCANNING-IN-PYTHON - A python threaded portscanner to scan websites and ipaddresses

PORTSCANNING-IN-PYTHON This is a python threaded portscanner to scan websites an

1 Feb 16, 2022
Snakemake worflow to process and filter long read data from Oxford Nanopore Technologies.

Nanopore-Workflow Snakemake workflow to process and filter long read data from Oxford Nanopore Technologies. It is designed to compare whole human gen

5 May 13, 2022
Platform Tree for Xiaomi Redmi Note 7/7S (lavender)

The Xiaomi Redmi Note 7 (codenamed "lavender") is a mid-range smartphone from Xiaomi announced in January 2019. Device specifications Device Xiaomi Re

MUHAMAD KHOIRON 2 Dec 20, 2021
Make your functions return something meaningful, typed, and safe!

Make your functions return something meaningful, typed, and safe! Features Brings functional programming to Python land Provides a bunch of primitives

dry-python 2.5k Jan 03, 2023
This is a batch script created to WEB-DL.

widevine-L3-WEB-DL-Script This is a batch script created to WEB-DL. Works well with .mpd files , for m3u8 please use n_m3u8 program (not included in t

Paranjay Singh 312 Dec 31, 2022
Pre-commit hook for upgrading type hints

This is a pre-commit hook configured to automatically upgrade your type hints to the new native types implemented in PEP 585.

snok 54 Nov 14, 2022
The last walk-through project in code institute diploma course

Welcome Rocky.C, This is the Code Institute student template for Gitpod. We have preinstalled all of the tools you need to get started. It's perfectly

Rocky.C 1 Jan 31, 2022