
اعرض معلومات عن الملفات في صيغ مختلفة وابحث عن الأدوات (gadgets) لبناء سلاسل ROP لمعماريات مختلفة (x86/x86_64, ARM/ARM64, MIPS, PowerPC, SPARC64). لفك التجميع، يستخدم روبر (ropper) إطار Capstone Framework الرائع.
يمكنك استخدام ropper لعرض معلومات حول ملفات ثنائية بتنسيقات ملفات مختلفة، ويمكنك البحث عن أدوات (gadgets) لبناء سلاسل ROP لبنى مختلفة (x86/X86_64، ARM/ARM64، MIPS/MIPS64، PowerPC/PowerPC64، SPARC64). لفك التجميع يستخدم ropper إطار العمل الرائع Capstone Framework.
قم بتثبيت Capstone باستخدام PyPi:
$ sudo pip install capstone
قم بتثبيت filebytes باستخدام PyPi:
$ sudo pip install filebytes
اختياري (ليس ضروريًا لتشغيل ropper، فقط للبحث عن الأدوات):
قم بتثبيت Keystone:
$ sudo pip install keystone-engine
قم بتثبيت وتشغيل Ropper
$ python setup.py install
$ ropper
يمكنك أيضًا تثبيت Ropper باستخدام pip
$ pip install ropper
إذا أردت، يمكنك استخدام Ropper بدون تثبيت
$ ./Ropper.py
إذا كنت لا ترغب في تثبيت filebytes، فإن filebytes هو وحدة فرعية لمستودع ropper. هذا يعني أنك لست بحاجة لتثبيت filebytes و ropper.
$ git clone https://github.com/sashs/ropper.git
$ cd ropper
$ git submodule init
$ git submodule update
$ ./Ropper.py
هذه الميزة لا تزال قيد التطوير! يحتوي Ropper على أمر بحث دلالي، يتيح إمكانية البحث عن الأدوات.
$ ropper --file <afile> --semantic "<any constraint>"
التبعيات الاختيارية التالية مطلوبة لاستخدام البحث الدلالي:
قم بتثبيت pyvex
$ sudo pip install pyvex
قم بتثبيت z3py
$ python scripts/mk_make.py
$ cd build
$ make
$ sudo make install
reg == reg - تعيين سجل لآخر
reg == number - تعيين رقم لسجل
reg == [reg] - تعيين ذاكرة لسجل
reg += number/reg/[reg]
reg -= number/reg/[reg]
reg *= number/reg/[reg]
reg /= number/reg/[reg]
eax==1 !ebx - تعيين eax إلى 1 والبحث عن أدوات لا تغير ebx

usage: Ropper.py [-h] [--help-examples] [-v] [--console]
[-f <file> [<file> ...]] [-r] [-a <arch>]
[--section <section>] [--string [<string>]] [--hex]
[--asm [<asm> [H|S|R] ...]] [--disasm <opcode>]
[--disassemble-address <address:length>] [-i] [-e]
[--imagebase] [-c] [-s] [-S] [--imports] [--symbols]
[--set <option>] [--unset <option>] [-I <imagebase>] [-p]
[-j <reg>] [--stack-pivot] [--inst-count <n bytes>]
[--search <regex>] [--quality <quality>] [--opcode <opcode>]
[--instructions <instructions>] [--type <type>] [--detailed]
[--all] [--cfg-only] [--chain <generator>] [-b <badbytes>]
[--nocolor] [--clear-cache] [--no-load] [--analyse <quality>]
[--semantic constraint]
[--count-of-findings <count of gadgets>] [--single]
يمكنك استخدام ropper لعرض معلومات حول ملفات ثنائية بتنسيقات ملفات مختلفة
ويمكنك البحث عن أدوات لبناء سلاسل ROP لبنى مختلفة
أنواع الملفات المدعومة:
ELF
PE
Mach-O
Raw
البنى المدعومة:
x86 [x86]
x86_64 [x86_64]
MIPS [MIPS, MIPS64]
ARM/Thumb [ARM, ARMTHUMB]
ARM64 [ARM64]
PowerPC [PPC, PPC64]
SPARC [SPARC64]
مولدات سلسلة ROP المتاحة:
execve (execve[=<cmd>], الافتراضي /bin/sh) [Linux x86, x86_64]
mprotect (mprotect=<address>:<size>) [Linux x86, x86_64]
virtualprotect (virtualprotect=<address iat vp>:<size>) [Windows x86]
الخيارات:
-h, --help عرض رسالة المساعدة هذه والخروج
--help-examples طباعة الأمثلة
-v, --version طباعة الإصدار
--console بدء سطر الأوامر التفاعلي
-f <file> [<file> ...], --file <file> [<file> ...]
الملف المطلوب تحميله
-r, --raw تحميل الملف كملف خام
-a <arch>, --arch <arch>
بنية الملف المحمل
--section <section> طباعة بيانات هذا القسم
--string [<string>] البحث عن السلسلة <string> في جميع أقسام البيانات
--hex طباعة الأقسام المحددة بصيغة سداسية عشرية
--asm [<asm> [H|S|R] ...]
سلسلة لتجميعها وتنسيق الإخراج
(H=HEX, S=STRING, R=RAW, الافتراضي: H)
--disasm <opcode> Opcode لفك التجميع (مثال: ffe4, 89c8c3, ...)
--disassemble-address <address:length>
فك تجميع التعليمات عند العنوان <address>
(0x12345678:L3). يمكن تحديد عدد التعليمات لفك التجميع
(0x....:L...)
-i, --info عرض رأس الملف [ELF/PE/Mach-O]
-e عرض نقطة الدخول
--imagebase عرض قاعدة الصورة [ELF/PE/Mach-O]
-c, --dllcharacteristics
عرض خصائص DLL [PE]
-s, --sections عرض أقسام الملف [ELF/PE/Mach-O]
-S, --segments عرض أجزاء الملف [ELF/Mach-O]
--imports عرض الاستيرادات [ELF/PE]
--symbols عرض الرموز [ELF]
--set <option> تعيين خيارات. الخيارات المتاحة: aslr nx
--unset <option> إلغاء تعيين خيارات. الخيارات المتاحة: aslr nx
-I <imagebase> استخدام قاعدة الصورة هذه للأدوات
-p, --ppr البحث عن تعليمات 'pop reg; pop reg; ret'
[فقط x86/x86_64]
-j <reg>, --jmp <reg>
البحث عن تعليمات 'jmp reg' (-j reg[,reg...])
[فقط x86/x86_64]
--stack-pivot طباعة جميع أدوات stack pivot
--inst-count <n bytes>
تحديد أقصى عدد من التعليمات في الأداة
(الافتراضي: 6)
--search <regex> البحث عن الأدوات
--quality <quality> جودة الأدوات التي يتم العثور عليها عن طريق البحث (1 =
الأفضل)
--opcode <opcode> البحث عن opcodes (مثال: ffe4 أو ffe? أو ff??)
--instructions <instructions>
البحث عن تعليمات (مثال: "jmp esp", "pop eax;
ret")
--type <type> تعيين نوع الأدوات [rop, jop, sys, all]
(الافتراضي: all)
--detailed طباعة الأدوات بتفاصيل أكثر
--all عدم إزالة الأدوات المكررة
--cfg-only تصفية الأدوات التي تفشل في فحص Microsoft CFG.
فقط لملفات PE المترجمة مع تمكين فحص CFG (تحقق من DllCharachteristics) [PE]
--chain <generator> توليد سلسلة ROP [generator parameter=value[
parameter=value]]
-b <badbytes>, --badbytes <badbytes>
تعيين البايتات التي لا ينبغي أن تكون موجودة في الأدوات
--nocolor تعطيل الإخراج الملون
--clear-cache مسح الذاكرة المخبأة
--no-load عدم تحميل الأدوات تلقائيًا عند بدء وحدة التحكم (--console)
--analyse <quality> يستخدم فقط لتطبيق البحث الدلالي
--semantic constraint
البحث الدلالي عن الأدوات
--count-of-findings <count of gadgets>
أقصى عدد من الأدوات التي ستتم طباعتها باستخدام البحث الدلالي (0 = غير محدد، الافتراضي: 5)
--single لا يتم استخدام عمليات متعددة لمسح الأدوات
أمثلة على الاستخدام:
[عام]
./Ropper.py
./Ropper.py --file /bin/ls --console
[معلومات]
./Ropper.py --file /bin/ls --info
./Ropper.py --file /bin/ls --imports
./Ropper.py --file /bin/ls --sections
./Ropper.py --file /bin/ls --segments
./Ropper.py --file /bin/ls --set nx
./Ropper.py --file /bin/ls --unset nx
./Ropper.py --file /bin/ls --inst-count 5
./Ropper.py --file /bin/ls --search "sub eax" --badbytes 000a0d
./Ropper.py --file /bin/ls --search "sub eax" --detail
./Ropper.py --file /bin/ls --filter "sub eax"
./Ropper.py --file /bin/ls --inst-count 5 --filter "sub eax"
./Ropper.py --file /bin/ls --opcode ffe4
./Ropper.py --file /bin/ls --opcode ffe?
./Ropper.py --file /bin/ls --opcode ??e4
./Ropper.py --file /bin/ls --detailed
./Ropper.py --file /bin/ls --ppr --nocolor
./Ropper.py --file /bin/ls --jmp esp,eax
./Ropper.py --file /bin/ls --type jop
./Ropper.py --file /bin/ls --chain execve
./Ropper.py --file /bin/ls --chain "execve cmd=/bin/sh" --badbytes 000a0d
./Ropper.py --file /bin/ls --chain "mprotect address=0xbfdff000 size=0x21000"
./Ropper.py --file /bin/ls /lib/libc.so.6 --console
[تجميع/فك تجميع]
./Ropper.py --asm "jmp esp"
./Ropper.py --asm "mov eax, ecx; ret"
./Ropper.py --disasm ffe4
[بحث]
./Ropper.py --file /bin/ls --search <searchstring>
? أي حرف
% أي سلسلة
مثال:
./Ropper.py --file /bin/ls --search "mov e?x"
0x000067f1: mov edx, dword ptr [ebp + 0x14]; mov dword ptr [esp], edx; call eax
0x00006d03: mov eax, esi; pop ebx; pop esi; pop edi; pop ebp; ret ;
0x00006d6f: mov ebx, esi; mov esi, dword ptr [esp + 0x18]; add esp, 0x1c; ret ;
0x000076f8: mov eax, dword ptr [eax]; mov byte ptr [eax + edx], 0; add esp, 0x18; pop ebx; ret ;
./Ropper.py --file /bin/ls --search "mov [%], edx"
0x000067ed: mov dword ptr [esp + 4], edx; mov edx, dword ptr [ebp + 0x14]; mov dword ptr [esp], edx; call eax;
0x00006f4e: mov dword ptr [ecx + 0x14], edx; add esp, 0x2c; pop ebx; pop esi; pop edi; pop ebp; ret ;
0x000084b8: mov dword ptr [eax], edx; ret ;
0x00008d9b: mov dword ptr [eax], edx; add esp, 0x18; pop ebx; ret ;
./Ropper.py --file /bin/ls --search "mov [%], edx" --quality 1
0x000084b8: mov dword ptr [eax], edx; ret ;; ret ;
#!/usr/bin/env python
from ropper import RopperService
# not all options need to be given
options = {'color' : False, # if gadgets are printed, use colored output: default: False
'badbytes': '00', # bad bytes which should not be in addresses or ropchains; default: ''
'all' : False, # Show all gadgets, this means to not remove double gadgets; default: False
'inst_count' : 6, # Number of instructions in a gadget; default: 6
'type' : 'all', # rop, jop, sys, all; default: all
'detailed' : False} # if gadgets are printed, use detailed output; default: False
rs = RopperService(options)
##### change options ######
rs.options.color = True
rs.options.badbytes = '00'
rs.options.badbytes = ''
rs.options.all = True
##### open binaries ######
# it is possible to open multiple files
rs.addFile('test-binaries/ls-x86')
rs.addFile('ls', bytes=open('test-binaries/ls-x86','rb').read()) # other possiblity
rs.addFile('ls_raw', bytes=open('test-binaries/ls-x86','rb').read(), raw=True, arch='x86')
##### close binaries ######
rs.removeFile('ls')
rs.removeFile('ls_raw')
# Set architecture of a binary, so it is possible to look for gadgets for a different architecture
# It is useful for ARM if you want to look for ARM gadgets or Thumb gadgets
# Or if you opened a raw file
ls = 'test-binaries/ls-x86'
rs.setArchitectureFor(name=ls, arch='x86')
rs.setArchitectureFor(name=ls, arch='x86_64')
rs.setArchitectureFor(name=ls, arch='ARM')
rs.setArchitectureFor(name=ls, arch='ARMTHUMB')
rs.setArchitectureFor(name=ls, arch='ARM64')
rs.setArchitectureFor(name=ls, arch='MIPS')
rs.setArchitectureFor(name=ls, arch='MIPS64')
rs.setArchitectureFor(name=ls, arch='PPC')
rs.setArchitectureFor(name=ls, arch='PPC64')
rs.setArchitectureFor(name=ls, arch='SPARC64')
rs.setArchitectureFor(name=ls, arch='x86')
##### load gadgets ######
# load gadgets for all opened files
rs.loadGadgetsFor()
# load gadgets for only one opened file
ls = 'test-binaries/ls-x86'
rs.loadGadgetsFor(name=ls)
# change gadget type
rs.options.type = 'jop'
rs.loadGadgetsFor()
rs.options.type = 'rop'
rs.loadGadgetsFor()
# change instruction count
rs.options.inst_count = 10
rs.loadGadgetsFor()
##### print gadgets #######
rs.printGadgetsFor() # print all gadgets
rs.printGadgetsFor(name=ls)
##### Get gadgets ######
gadgets = rs.getFileFor(name=ls).gadgets
##### search pop pop ret ######
pprs = rs.searchPopPopRet(name=ls) # looks for ppr only in 'test-binaries/ls-x86'
pprs = rs.searchPopPopRet() # looks for ppr in all opened files
for file, ppr in pprs.items():
for p in ppr:
print p
##### load jmp reg ######
jmp_regs = rs.searchJmpReg(name=ls, regs=['esp', 'eax']) # looks for jmp reg only in 'test-binaries/ls-x86'
jmp_regs = rs.searchJmpReg(regs=['esp', 'eax'])
jmp_regs = rs.searchJmpReg() # looks for jmp esp in all opened files
for file, jmp_reg in jmp_regs.items():
for j in jmp_reg:
print j
##### search opcode ######
ls = 'test-binaries/ls-x86'
gadgets_dict = rs.searchOpcode(opcode='ffe4', name=ls)
gadgets_dict = rs.searchOpcode(opcode='ffe?')
gadgets_dict = rs.searchOpcode(opcode='??e4')
for file, gadgets in gadgets_dict.items():
for g in gadgets:
print g
##### search instructions ######
ls = 'test-binaries/ls-x86'
for file, gadget in rs.search(search='mov e?x', name=ls):
print file, gadget
for file, gadget in rs.search(search='mov [e?x%]'):
print file, gadget
result_dict = rs.searchdict(search='mov eax')
for file, gadgets in result_dict.items():
print file
for gadget in gadgets:
print gadget
##### assemble instructions ######
hex_string = rs.asm('jmp esp')
print '"jmp esp" assembled to hex string =', hex_string
raw_bytes = rs.asm('jmp esp', format='raw')
print '"jmp esp" assembled to raw bytes =', raw_bytes
string = rs.asm('jmp esp', format='string')
print '"jmp esp" assembled to string =',string
arm_bytes = rs.asm('bx sp', arch='ARM')
print '"bx sp" assembled to hex string =', arm_bytes
##### disassemble bytes #######
arm_instructions = rs.disasm(arm_bytes, arch='ARM')
print arm_bytes, 'disassembled to "%s"' % arm_instructions
# Change the imagebase, this also change the imagebase for all loaded gadgets of this binary
rs.setImageBaseFor(name=ls, imagebase=0x0)
# reset image base
rs.setImageBaseFor(name=ls, imagebase=None)
gadgets = rs.getFileFor(name=ls).gadgets
# gadget address
print hex(gadgets[0].address)
# get instruction bytes of gadget
print bytes(gadgets[0].bytes).encode('hex')
# remove all gadgets containing bad bytes in address
rs.options.badbytes = '000a0d' # gadgets are filtered automatically






