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
Blender-3D-SH-Dma-plugin - Import and export Sonic Heroes Delta Morph animations (.anm) into Blender 3D

io_scene_sonic_heroes_dma This plugin for Blender 3D allows you to import and ex

Psycrow 3 Mar 22, 2022
Data Science Course at Dept. of Computer Engineering, Chula 2022

2110446 Data Science Course at Chula 2022 Short links for exercises: Week1: Intro to Numpy, Pandas Numpy: https://colab.research.google.com/github/kao

Kao Panboonyuen 17 Nov 27, 2022
A tool to allow New World players to calculate the best place to put their Attribute Points for their build and level

New World Damage Simulator A tool designed to take a characters base stats including armor and weapons, level, and base damage of their items (slash d

Joseph P Langford 31 Nov 01, 2022
Programa que organiza pastas automaticamente

📂 Folder Organizer 📂 Programa que organiza pastas automaticamente Requisitos • Como usar • Melhorias futuras • Capturas de Tela Requisitos Antes de

João Victor Vilela dos Santos 1 Nov 02, 2021
用于导出墨墨背单词的词库,并生成适用于 List 背单词,不背单词,欧陆词典等的自定义词库

maimemo-export 用于导出墨墨背单词的词库,并生成适用于 List 背单词,欧陆词典,不背单词等的自定义词库。 仓库内已经导出墨墨背单词所有自带词库(暂不包括云词库),多达 900 种词库,可以在仓库中选择需要的词库下载(下载单个文件的方法),也可以去 蓝奏云(密码:666) 下载打包好

ourongxing 293 Dec 29, 2022
Cardano SundaeSwap ISO SPO vote ranking script

Cardano SundaeSwap ISO SPOs vote ranking This Python 3 script uses the database populated by cardano-db-sync from the Cardano blockchain to generate a

SM₳UG 1 Nov 17, 2021
An extended, game oriented, turtle

Burtle A Better TURTLE. Makes making games easier. write less do more!! Documentation & guide: https://alannxq.github.io/burtle/ Installation pip inst

5 May 19, 2022
A minimalist personal blogging system that natively supports Markdown, LaTeX, and code highlighting.

December Welcome to the December blogging system's code repository! Introduction December is a minimalist personal blogging system that natively suppo

TriNitroTofu 10 Dec 05, 2022
ASVspoof 2021 Baseline Systems

ASVspoof 2021 Baseline Systems Baseline systems are grouped by task: Speech Deepfake (DF) Logical Access (LA) Physical Access (PA) Please find more de

91 Dec 28, 2022
A sage package for working with circular genomes represented by signed or unsigned permutations

Circular genome tools (cgt) A sage package for working with circular genomes represented by signed or unsigned permutations. It includes tools for con

Joshua Stevenson 1 Mar 10, 2022
Extend the maya channel box with searchability and colour

channel-box-plus will add search-ability over its attributes, and it will colour user defined attributes, making them easier to distinguish.

Robert Joosten 12 Jun 08, 2022
Tutorials on advanced python topics, and literate programming framework to write them.

Advanced course on Python3 This course covers several topics Python decorators The python object system / meta classes Also see my text on Python impo

Michael Moser 59 Dec 19, 2022
プレヤフHackUチーム「キャット・タン」が作成したアプリ「illustection」

cat_tongue_illustection プレヤフHackUチーム「キャット・タン」が作成した, プライバシー保護アプリ「illustection」です! デモ動画 https://youtu.be/z3I7LuB_i58 機能 アップロードされた画像をいい感じのイラストやの素材に置き換える(

4 Jul 03, 2021
Supply Chain will be a SAAS platfom to provide e-logistic facilites with most optimal

Shipp It Welcome To Supply Chain App [ Shipp It ] In "Shipp It" we are creating a full solution[web+app] for a entire supply chain from receiving orde

SAIKAT_CLAW 25 Dec 26, 2022
Get a list of all offline/online members in a discord server

Discord server insights Get a list of all offline/online members in a discord server. Uses Selenium to crawl invite links. Config Download Chrome driv

Prakhar Gurunani 3 Oct 21, 2022
Nextstrain build targeted to Omicron

About This repository analyzes viral genomes using Nextstrain to understand how SARS-CoV-2, the virus that is responsible for the COVID-19 pandemic, e

Bedford Lab 9 May 25, 2022
Extract continuous and discrete relaxation spectra from G(t)

pyReSpect-time Extract continuous and discrete relaxation spectra from stress relaxation modulus G(t). The papers which describe the method and test c

3 Nov 03, 2022
This repository contains Python games that I've worked on. You'll learn how to create python games with AI. I try to focus on creating board games without GUI in Jupyter-notebook.

92_Python_Games 🎮 Introduction 👋 This repository contains Python games that I've worked on. You'll learn how to create python games with AI. I try t

Milaan Parmar / Милан пармар / _米兰 帕尔马 166 Jan 01, 2023
CarolinaCon CTF Online

CarolinaCon Online CTF CTF challenges from CarolinaCon Online April 23 through April 25, 2021. All challenges from the CTF will eventually be here. Co

49th Security Division 6 May 04, 2022
A basic notes app to store your notes.

Notes Webapp A basic notes webapp to keep your notes.You can add, edit and delete notes after signing up. To add a note type your note in the text box

2 Oct 23, 2021