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
A Klipper plugin for accurate Z homing

Stable Z Homing for Klipper A Klipper plugin for accurate Z homing This plugin provides a new G-code command, STABLE_Z_HOME, which homes Z repeatedly

Matthew Lloyd 24 Dec 28, 2022
✨ Udemy Coupon Finder For Discord. Supports Turkish & English Language.

Udemy Course Finder Bot | Udemy Kupon Bulucu Botu This bot finds new udemy coupons and sends to the channel. Before Setup You must have python = 3.6

Penguen 4 May 04, 2022
This tool don't used illegal ativity

ETHICALTOOL This tool for only educational purposes don't used illegal ativity @onlinehacking this tool for pkg update && pkg upgrade && pkg install g

Mrkarthick 4 Dec 23, 2021
Module for remote in-memory Python package/module loading through HTTP/S

httpimport Python's missing feature! The feature has been suggested in Python Mailing List Remote, in-memory Python package/module importing through H

John Torakis 220 Dec 17, 2022
ThinkPHP全日志扫描工具,命令行版和BurpSuite插件版

ThinkPHP3和5日志扫描工具,提供命令行版和BurpSuite插件版,尽可能全的发掘网站日志信息 命令行版 安装 git clone https://github.com/r3change/TPLogScan.git cd TPLogScan/ pip install -r requireme

119 Dec 27, 2022
dbt adapter for Firebolt

dbt-firebolt dbt adapter for Firebolt dbt-firebolt supports dbt 0.21 and newer Installation First, download the JDBC driver and place it wherever you'

23 Dec 14, 2022
A napari plugin to inspect data within a cisTEM project

napari-cistem A plugin to inspect data within a cisTEM project This napari plugin was generated with Cookiecutter using with @napari's cookiecutter-na

Johannes Elferich 1 Nov 07, 2021
It's a repo for Cramer's rule, which is some math crap or something idk

It's a repo for Cramer's rule, which is some math crap or something idk (just a joke, it's not crap; don't take that seriously, math teachers)

Module64 0 Aug 31, 2022
Visualize Data From Stray Scanner https://keke.dev/blog/2021/03/10/Stray-Scanner.html

StrayVisualizer A set of scripts to work with data collected using Stray Scanner. Usage Installing Dependencies Install dependencies with pip -r requi

Kenneth Blomqvist 45 Dec 30, 2022
Fonts used to be an install-and-forget thing, but many of are now updated regularly.

Your font manager. Fonts used to be an install-and-forget thing, but many of are now updated regularly. fontman helps you keep track of the fonts you

Nico Schlömer 20 Feb 07, 2022
an opensourced roblox group finder writen in python 100% free and virus-free

Roblox-Group-Finder an opensourced roblox group finder writen in python 100% free and virus-free note : if you don't want install python or just use w

mollomm1 1 Nov 11, 2021
A comparison of mesh generators.

This repository creates meshes of the same domains with multiple mesh generators and compares the results.

Nico Schlömer 29 Dec 12, 2022
LinkScope allows you to perform online investigations by representing information as discrete pieces of data, called Entities.

LinkScope Client Description This is the repository for the LinkScope Client Online Investigation software. LinkScope allows you to perform online inv

108 Jan 04, 2023
Simple Crud Python vs MySQL

Simple Crud Python vs MySQL The idea came when I was studying MySQ... A desire to create a python program that can give access to a "localhost" databa

Lucas 1 Jan 21, 2022
Learn to code in any language. If

Learn to Code It is an intiiative undertaken by Student Ambassadors Club, Jamshoro for students who are absolute begineers in programming and want to

Student Ambassadors' Club at Mehran UET 15 Oct 19, 2022
Team Curie is a group of people working together to achieve a common aim

Team Curie is a group of people working together to achieve a common aim. We are enthusiasts!.... We are setting the pace!.... We offer encouragement and motivation....And we believe TeamWork makes t

4 Aug 07, 2021
Python Projects is an Open Source to enhance your python skills

Welcome! 👋🏽 Python Project is Open Source to enhance your python skills. You're free to contribute. 🤓 You just need to give us your scripts written

Tristán 6 Nov 28, 2022
A community based economy bot with python works only with python 3.7.8 as web3 requires cytoolz

A community based economy bot with python works only with python 3.7.8 as web3 requires cytoolz has some issues building with python 3.10

4 Jan 01, 2022
Traditionally, there is considerable friction for developers when setting up development environments

This self-led, half-day training will teach participants the patterns and best practices for working with GitHub Codespaces

CSE Labs at Spark 12 Dec 02, 2022
Custom SLURM wrapper scripts to make finding job histories and system resource usage more easily accessible

SLURM Wrappers Executables job-history A simple wrapper for grabbing data for completed and running jobs. nodes-busy Developed for the HPC systems at

Sara 2 Dec 13, 2021