إذا كنت من المهتميّن بثغرات فيض المكدّس Buffer Overflow Stack-based ربما واجهتك مشكلة تحديد عدد البايتات
التي تلزمك للكتابة على المسجّل EIP أو حتى الـ SEH . كانت الحلول هي إستخدام هاشات الـ MD5 \ SAH512 أو طريقة الحصر :
AAAAAAAAAAAAABBBBBBBBBBBBBBBBBCCCCCCCCCCCDDDDDDDD AAAAAAAAAAAAABBBBBBBBBBBBBBBBBCCCCCCCCCCCDDDDDDDD AAAAAAAAAAAAABBBBBBBBBBBBBBBBBCCCCCCCCCCCDDDEEEEEE ....
لملف تستطيع إستخدامه لتضبيب "fuzzing" البرنامج المستهدف , ثمّ تشغيله تحت المنقّح .. فقط إكتب
القيمة التي تظهر لك في المسجّل , وسيستخرج لك عدد البايتات الازمة للوصول له.(هناك إحتمال تكرار
واارد , لكنه منخفظ للغاية ) بعد تعديل على الأداة لجعلها قابله للإستخدام العام :
#!/usr/bin/env python # # Copyright 2011 B4r4k47 [Barakat] <b4r4k47[at]hotmail[dot]com> # # This tool is available for free under the GNU General Public License V3 (GPL). # To read the full license, please visit: http://www.gnu.org/licenses/lgpl.html # I hope you find it useful :) # from sys import argv from random import choice def randomdata(file_name,chars_eip): if (chars_eip <= 0) : help() elif (len(str(file_name)) == 0 ): help() else : pass # If there were bad characters, you can remove them from this list : characters_list = [ "\x41", "\x42", "\x43", "\x44", "\x45", "\x46", "\x47", "\x48", "\x49", "\x4a", "\x4b", "\x4c", "\x4d", "\x4e", "\x4f", "\x50", "\x51", "\x52", "\x53", "\x54", "\x55", "\x56", "\x57", "\x58", "\x59", "\x5a", "\x61", "\x62", "\x63", "\x64", "\x65", "\x66", "\x67", "\x68", "\x69", "\x6a", "\x6b", "\x6c", "\x6d", "\x6e", "\x6f", "\x70", "\x71", "\x72", "\x73", "\x74", "\x75", "\x76", "\x77", "\x78", "\x79", "\x7a", "\x31", "\x32", "\x33", "\x34", "\x35", "\x36", "\x37", "\x38", "\x39", "\x21", "\x40", "\x23", "\x24", "\x25", "\x26"] file = open(file_name,"w") number = chars_eip while (chars_eip != 0): file.write(choice(characters_list)) chars_eip -= 1 file.close() print "\n[*] Done:",number,"charscters has been written to the file",file_name,"\n" def geteip(file_name,chars_eip): chars_eip = chars_eip.upper() char1 = chr(int(chars_eip[6:8],16)) char2 = chr(int(chars_eip[4:6],16)) char3 = chr(int(chars_eip[2:4],16)) char4 = chr(int(chars_eip[0:2],16)) eip = char1 + char2 + char3 + char4 file = open(file_name,"r").read() order = file.find(eip) if (order == -1): print "\n[!] Not found, please check that you've typed the new EIP value correctly.\n" else: print "\n[*] Done: [", order , "junk bits ] [ The next 4 bits(charscters) will overwrite the EIP ]\n" def help(): print '''\n usage: tool.py [Option: -c -g] [File name] [Charscters length / EIP Address] Options: -c :Generate random characters and write them into a file. -g :Get the characters length that's needed in order to overwrite the EIP value from an existing file. Examples: tool.py -c file.txt 1500 tool.py -g file.txt 41242A6C ''' exit() if (__name__ == "__main__"): try: option = argv[1] file_name = argv[2] chars_eip = argv[3] if (option == "-c"): chars_eip = int(chars_eip) randomdata(file_name,chars_eip) elif (option == "-g"): if (len(chars_eip) < 8): help() else: geteip(file_name,chars_eip) else: help() except: help()
usage: tool.py [Option: -c -g] [File name] [Charscters length / EIP Address] Options: -c :Generate random characters and write them into a file. -g :Get the characters length that's needed in order to overwrite the EIP value from an existing file. Examples: tool.py -c file.txt 1500 tool.py -g file.txt 41242A6C
الخيار c للتوليد والخيار g لإستخراج العدد البايتات الازمة للكتابة على العنوان.
تطبيق ,مثلأ لدي برنامج صوتيات مصاب بغرة يمكنني من تشغيل ملف m3u - play list
بعدد غير محدد من البايتات مما يتسبب بفيض في المكدّس والكتابة على عنوان العودة
لتحديد عدد البيتات الازمة للإستغلال , ننشىء ملف بالخيار c- ونحدد عدد المحرفات
التي نرغب بإتوليدها :
> python tool.py -c file.m3u 1500
بعد تشغيل الملف , سينهار البرنامج ونلاحظ قيمة كتبت على المسجّل EIP أو SEH وأن العنوان المكتوب
غير قابل للقراءة. لذا نستخدم الخيارg- ونكتب إسم , الملف الذي إستخدمناه ثمّ القيمة التي كتبت على
المسجل أو الـ SEH. وسيتخرج عدد البايتات الازمة للإستغلال.
> python tool.py -g file.m3u 696E2F65
الناتج سيكون بهذه الصيغة مثلاً :
[*] Done: [ 1223 junk bits ] [ The next 4 bits(charscters) will overwrite the EIP ]
أي أن الإستغلال يتكون من , 1223 بايت متبوعة بأربع بايتات لبداية عنوان الـشل كود .. يليها الشل كود.
صورة للبرنامج تحت المنقّح :

كما تلاحظ ظهرت القيمة , الآن لو انشأت ملف يحوي 1012 مُحرّف , وأتبعته بأربع مُحرفات @@@@ سأجد
قيمتها كتبت على الـ EIP وأصبحت قيمته 40404040.
أتمنى أن تجدها مفيدة



Menu
Cat Widget