Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/exploits/CVE-2016-4655/create_bin.rb
Views: 11780
#!/usr/bin/env ruby1# -*- coding: binary -*-23require 'macho'45stager_file = ARGV[0]6data = File.binread(stager_file)7macho = MachO::MachOFile.new_from_bin(data)8main_func = macho[:LC_MAIN].first9entry_offset = main_func.entryoff1011start = -112min = -113max = 014for segment in macho.segments15next if segment.segname == MachO::LoadCommands::SEGMENT_NAMES[:SEG_PAGEZERO]16puts "segment: #{segment.segname} #{segment.vmaddr.to_s(16)}"17if min == -1 or min > segment.vmaddr18min = segment.vmaddr19end20if max < segment.vmaddr + segment.vmsize21max = segment.vmaddr + segment.vmsize22end23end2425puts "data: #{min.to_s(16)} -> #{max.to_s(16)} #{(max - min).to_s(16)}"26output_data = "\x00" * (max - min)2728for segment in macho.segments29#next if segment.segname == MachO::LoadCommands::SEGMENT_NAMES[:SEG_PAGEZERO]30puts "segment: #{segment.segname} off: #{segment.offset.to_s(16)} vmaddr: #{segment.vmaddr.to_s(16)} fileoff: #{segment.fileoff.to_s(16)}"31for section in segment.sections32puts "section: #{section.sectname} off: #{section.offset.to_s(16)} addr: #{section.addr.to_s(16)} size: #{section.size.to_s(16)}"33flat_addr = section.addr - min34section_data = data[section.offset, section.size]35#file_section = section.offset36#puts "info: #{segment.fileoff.to_s(16)} #{segment.offset.to_s(16)} #{section.size.to_s(16)} #{file_section.to_s(16)}"37#puts "?: #{data.size.to_s(16)} #{file_section.to_s(16)}"38if section_data39puts "flat_addr: #{flat_addr.to_s(16)} (#{section_data.size.to_s(16)})"40if start == -1 or start > flat_addr41start = flat_addr42end43output_data[flat_addr, section_data.size] = section_data44end45end46end4748puts "start: #{start.to_s(16)}"49output_data = output_data[start..-1]50File.binwrite(stager_file + ".bin", output_data)51525354