• STATISTIQUES
  • Il y a eu un total de 1 membres et 44289 visiteurs sur le site dans les dernières 24h pour un total de 44 290 personnes!


    Membres: 2 446
    Discussions: 3 572
    Messages: 32 822
    Tutoriels: 77
    Téléchargements: 38
    Sites dans l'annuaire: 58


  • ANNUAIRE
  • [FR] Hackfest
    Le Hackfest est un évènement de sécurité et de piratage informatique au Québec reg...
    Hacking
    [FR] PHP France
    Pour tout savoir sur le PHP, en français. Vous trouverez des tutoriels, des exemples, des astuces, toute la do...
    Hacking
    [FR] Microcontest
    Cryptographie: 7, Mathématiques: 8, Image Son Vidéo: 5, Intelligence artificielle: 3, Réseau: 2, Divers: 7, Phy...
    Challenges
    [EN] Bright Shadows
    JavaScript: 13, Exploit: 27, Crypto: 69, CrackIt: 52, Stegano: 67, Flash: 3, Programming: 16, Java-Applet: 10, Logic: 20...
    Challenges
    [EN] Rosecode
    Programming: 36, Math: 29, Probability: 5, Sequence: 7, Crypto: 4, Brainf**k: 13, TimeRace: 4, Hack: 9
    Challenges
    [EN] This is legal
    Basic: 10, Realistic: 5, Programming: 1, Bonus: 11, SQL: 2, Encryption: 6, Application: 4, User Contributed: 3
    Challenges
    [FR] Developpez.net
    Un forum communautaire qui se veut pour les développeurs en générale. Avec presque 500 000 membr...
    Programmation

  • DONATION
  • Si vous avez trouvé ce site internet utile, nous vous invitons à nous faire un don du montant de votre choix via Paypal. Ce don servira à financer notre hébergement.

    MERCI!




Note de ce sujet :
  • Moyenne : 0 (0 vote(s))
  • 1
  • 2
  • 3
  • 4
  • 5
[python] Buffer Overflow : EBP et EIP
25-10-2014, 12h35 (Modification du message : 25-10-2014, 13h35 par St0rn.)
Message : #1
St0rn Hors ligne
Newbie
*



Messages : 20
Sujets : 5
Points: 17
Inscription : Apr 2012
[python] Buffer Overflow : EBP et EIP
C'est un petit projet que j'ai fait après avoir étudié le plugin byakugan pour winDBG.
Une fonctionnalitée qui perméttait à partir d'une chaine générée par pattern_create.rb de metasploit, de déterminer après un sigsegv, la taille du junk qui permet d'avoir un contrôle sur EBP et EIP.

Étant jaloux de ne pas l'avoir sur linux, j'ai recrée cette fonctionnalitée (j'ai aussi recrée pattern_create.rb dans le script) en un script python.

/!\ Le script utilise python-ptrace /!\

Voici le dépot github (l'adresse de téléchargement de python-ptrace y est):

https://github.com/St0rn/pentest-project...checkfault

Code PYTHON :

#Checkfault
#Author: St0rn
#Use python-ptrace
#
#Usage: checkfault.py [Type] [Binary] [Length]
#
#!/usr/bin/env python

import os
import sys
from ptrace.debugger.debugger import PtraceDebugger
from ptrace.debugger.child import createChild
from ptrace.tools import locateProgram

def generatejunk(length):
    taba = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    tabb = "abcdefghijklmnopqrstuvwxyz"
    tabc = "0123456789"

    junk = ""
    a = 0
    b = 0
    c = 0

    while len(junk) < length:
        junk += taba[a] + tabb[b] + tabc[c]
        c += 1
        if c == len(tabc):
            c = 0
            b += 1
        if b == len(tabb):
            b = 0
            a += 1
        if c == len(tabc):
            a = 0
    return junk

#Find EIP control offset Function
def checkfault(binary, types, length):
    #types = arg, get
    def trace(program):
        env = None
        return createChild(program, False, env)

    if types == "arg":
        junk = generatejunk(length)
        payload = []
       
        payload.append(locateProgram(binary))
        payload.append(junk)
        pid = trace(payload)
       
        debug = PtraceDebugger()
        ps = debug.addProcess(pid, True)
       
        ps.cont()
        try:
            signal = ps.waitSignals()
            print "\n%s Detected!" % signal
            addr_eip = hex(ps.getInstrPointer())
            addr_ebp = hex(ps.getFramePointer())
            ebp = addr_ebp[8] + addr_ebp[9] + addr_ebp[6] + addr_ebp[7] + addr_ebp[4] + addr_ebp[5] + addr_ebp[2] + addr_ebp[3]
            eip = addr_eip[8] + addr_eip[9] + addr_eip[6] + addr_eip[7] + addr_eip[4] + addr_eip[5] + addr_eip[2] + addr_eip[3]
        except:
            print "\nNo SIGSEGV detected!\nMaybe the program is not vulnerable\nOr try with more bytes\n"
            debug.quit()
            sys.exit()

        try:
            print "\nControl of EBP after " + str(junk.index(ebp.decode("hex"))) + " Bytes"
        except:
            print "\nNo Control of EBP"

        try:
            print "Control of EIP after " + str(junk.index(eip.decode("hex"))) + " Bytes\n"
        except:
            print "No Control of EIP\n"

    if types == "get":
        junk = generatejunk(length)
        payload = []
       
        payload.append(locateProgram(binary))
        pid = trace(payload)
       
        debug = PtraceDebugger()
        ps = debug.addProcess(pid, True)
       
        ps.cont()
        try:
            f = open("/tmp/junk" , "w")
            f.write(junk)
            f.close()
            print "\n File /tmp/junk has been created\n"
            signal = ps.waitSignals()
            print "\n%s Detected!" % signal
            addr_eip = hex(ps.getInstrPointer())
            addr_ebp = hex(ps.getFramePointer())
            ebp = addr_ebp[8] + addr_ebp[9] + addr_ebp[6] + addr_ebp[7] + addr_ebp[4] + addr_ebp[5] + addr_ebp[2] + addr_ebp[3]
            eip = addr_eip[8] + addr_eip[9] + addr_eip[6] + addr_eip[7] + addr_eip[4] + addr_eip[5] + addr_eip[2] + addr_eip[3]
        except:
            print "\nNo SIGSEGV detected!\nMaybe the program is not vulnerable\nOr try with more bytes\n"
            os.system("rm /tmp/junk")
            debug.quit()
            sys.exit()

        os.system("rm /tmp/junk")
        try:
            print "\nControl of EBP after " + str(junk.index(ebp.decode("hex"))) + " Bytes"
        except:
            print "\nNo Control of EBP"

        try:
            print "Control of EIP after " + str(junk.index(eip.decode("hex"))) + " Bytes\n"
        except:
            print "No Control of EIP\n"

    if len(sys.argv) == 4:
        checkfault(sys.argv[2], sys.argv[1], int(sys.argv[3]))
    else:
        print "\nUsage: %s [Type] [Binary] [Junk_Length]\nType:\n arg = If the binary use argv\n get = If the binary use gets(), scanf() or other\n" % sys.argv[0]
 
+1 (6) -1 (0) Répondre


Sujets apparemment similaires…
Sujet Auteur Réponses Affichages Dernier message
  [Python]Situer mon niveau. InforMods 19 10,729 10-11-2016, 00h03
Dernier message: ZeR0-@bSoLu
  [PYTHON] un bot IRC basique darcosion 1 1,925 13-06-2016, 20h40
Dernier message: Yttrium
  [python] ANBU ::: TCP Session Hunter St0rn 2 2,323 25-02-2016, 18h45
Dernier message: otherflow
  [Python] Une autre façon de gérer les Virtualenv et Packages thxer 2 2,145 18-01-2016, 12h06
Dernier message: thxer
  [Python] rot script ark 9 5,221 08-03-2015, 00h37
Dernier message: ark
  [Python] Todo Manager ark 5 3,267 03-03-2015, 10h55
Dernier message: ark
  [python] Un décorateur pour inventorier les objets b0fh 1 2,167 04-12-2014, 17h50
Dernier message: thxer
  [python] UPnP Scanner St0rn 2 2,190 29-10-2014, 14h50
Dernier message: St0rn
  [Python] QuickHex thxer 9 4,865 15-08-2014, 20h26
Dernier message: sakiir
  Python : QuickBIn octarin 1 1,823 13-08-2014, 19h05
Dernier message: thxer

Atteindre :


Utilisateur(s) parcourant ce sujet : 1 visiteur(s)
N-PN
Accueil | Challenges | Tutoriels | Téléchargements | Forum | Retourner en haut