示例#1
0
def disas_arm(buf, array_name = '', row_width = 16, fancy = False):
	insns = struct.unpack("I"*(len(buf)/4), buf)
	out = ""
	pos = 0
	for insn in insns:
		tmp = ""

		if fancy:
			tmp += colors.fg('cyan')

		tmp += "%.8x: " % (pos)

		if fancy:
			tmp += colors.fg('red') + colors.bold()

		tmp += "%08x " % (insn)

		if fancy:
			tmp += colors.end() + colors.fg('green')

		tmp += str(darm.disasm_armv7(insn))

		if fancy:
			tmp += colors.end()

		out += "  " + tmp + "\n"

		pos = pos+4

	return out
示例#2
0
def disas_thumb(buf, array_name='', row_width=16, fancy=False):
    insns = struct.unpack("H" * (len(buf) / 2), buf)
    out = ""
    pos = 0
    for insn in insns:
        tmp = ""

        if fancy:
            tmp += colors.fg('cyan')

        tmp += "%.8x: " % (pos)

        if fancy:
            tmp += colors.fg('red') + colors.bold()

        tmp += "%08x " % (insn)

        if fancy:
            tmp += colors.end() + colors.fg('green')

        tmp += str(darm.disasm_thumb(insn))

        if fancy:
            tmp += colors.end()

        out += "  " + tmp + "\n"

        pos = pos + 2

    return out
示例#3
0
def disas_thumb(buf, array_name="", row_width=16, fancy=False):
    insns = struct.unpack("H" * (len(buf) / 2), buf)
    out = ""
    pos = 0
    for insn in insns:
        tmp = ""

        if fancy:
            tmp += colors.fg("cyan")

        tmp += "%.8x: " % (pos)

        if fancy:
            tmp += colors.fg("red") + colors.bold()

        tmp += "%08x " % (insn)

        if fancy:
            tmp += colors.end() + colors.fg("green")

        tmp += str(darm.disasm_thumb(insn))

        if fancy:
            tmp += colors.end()

        out += "  " + tmp + "\n"

        pos = pos + 2

    return out
示例#4
0
文件: lolsled.py 项目: OJ/moneyshot
def main(args):
	if len(args) != 1 and len(args) != 2:
		print "usage:"
		print "  moneyshot lolsled <length> <words>"
		print "  moneyshot lolsled <dictionary>"

		return 

	# some 'harmless' x86 insns, just inc's and dec's
	whitelist=[
		"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O"
	]

	# length?
	if args[0].isdigit():
		rs = emu(args[1])
		fstr = " CLOBBER: "
		cl = False
		for reg in rs:
			if rs[reg] != 0:
				fstr += "%s=%08x " % (reg, rs[reg])
				cl = True

		if cl == False:
			fstr += "No clobbering, yay!"

		print fstr

	# assume dictfile (find mode)
	else:
		words = open(args[0]).readlines()
		for word in words:
			ok = True
			word = word.strip().upper()

			for c in word:
				if c not in whitelist:
					ok = False

			if not ok:
				continue

			fstr = colors.fg('cyan')
			fstr += ">> "
			fstr += colors.fg('green')
			fstr += "'%15s' %s--> " % (word, colors.fg('white')+colors.bold())
			fstr += colors.end() + colors.fg('red')
			r = rop.disas_str(0, word)
			fstr += ' ; '.join(r).lower()
			rs = emu(word)
			fstr += " CLOBBER: "
			cl = False
			for reg in rs:
				if rs[reg] != 0:
					fstr += "%s=%08x " % (reg, rs[reg])
					cl = True

			print fstr

	print colors.end()
示例#5
0
def main(args):
	if len(args) != 1 and len(args) != 2:
		print "usage:"
		print "  moneyshot lolsled <length> <words>"
		print "  moneyshot lolsled <dictionary>"

		return 

	# some 'harmless' x86 insns, just inc's and dec's
	whitelist=["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O"]

	# length?
	if args[0].isdigit():
		rs = emu(args[1])
		fstr = " CLOBBER: "
		cl = False
		for reg in rs:
			if rs[reg] != 0:
				fstr += "%s=%08x " % (reg, rs[reg])
				cl = True

		if cl == False:
			fstr += "No clobbering, yay!"

		print fstr

	# assume dictfile (find mode)
	else:
		words = open(args[0]).readlines()
		for word in words:
			ok = True
			word = word.strip().upper()

			for c in word:
				if c not in whitelist:
					ok = False

			if not ok:
				continue

			fstr = colors.fg('cyan')
			fstr += ">> "
			fstr += colors.fg('green')
			fstr += "'%15s' %s--> " % (word, colors.fg('white')+colors.bold())
			fstr += colors.end() + colors.fg('red')
			r = ezrop.disas_str(0, word)
			fstr += ' ; '.join(r).lower()
			rs = emu(word)
			fstr += " CLOBBER: "
			cl = False
			for reg in rs:
				if rs[reg] != 0:
					fstr += "%s=%08x " % (reg, rs[reg])
					cl = True

			print fstr

	print colors.end()
示例#6
0
def main(args):
    if len(args) != 1 and len(args) != 2:
        print "usage: moneyshot dumpsym <filename> [filter]"
        return

    myelf = elf.fromfile(args[0])

    sym_filter = ""

    if len(args) == 2:
        sym_filter = args[1]

    if myelf.data[0:4] != "\x7F" + "ELF":
        print "[!] '%s' is not a valid ELF file :(" % (file)
        sys.exit(-1)

    if myelf.elfwidth == 64:
        sixtyfour = True
    else:
        sixtyfour = False

    dynsym = myelf.section(".dynsym")

    if dynsym == False:
        print "ERROR: could not retrieve .dynsym section"
        exit()

    dynstr = myelf.section(".dynstr")

    if dynstr == False:
        print "ERROR: could not retrieve .dynstr section"
        exit()

    symbol_names = dynstr['data'].split("\x00")
    symbol_info = {}

    i = 0

    while i < len(dynsym['data']):
        if sixtyfour == True:
            sym_entry = struct.unpack("<LQQBBH", dynsym['data'][i:(i + 24)])
            i = i + 24
        else:
            sym_entry = struct.unpack("<LLLBBH", dynsym['data'][i:(i + 16)])
            i = i + 16

        name_len = dynstr['data'][(sym_entry[0] + 1):].find("\x00")
        name = dynstr['data'][(sym_entry[0]):(sym_entry[0] + name_len + 1)]

        if sym_filter != "" and name.find(sym_filter) == -1:
            continue

        fstr = colors.fg("green") + "[" + colors.bold() + "%08x" + colors.end(
        ) + colors.fg("green") + "]" + colors.end()
        fstr += " '" + colors.fg(
            "red") + colors.bold() + "%s" + colors.end() + "'"

        print fstr % (sym_entry[1], name)
示例#7
0
def main(args):
	if len(args) != 1 and len(args) != 2:
		print "usage: moneyshot dumpsym <filename> [filter]"
		return

	myelf = elf.fromfile(args[0])

	sym_filter = ""

	if len(args) == 2:
		sym_filter = args[1]

	if myelf.data[0:4] != "\x7F"+"ELF":
		print "[!] '%s' is not a valid ELF file :(" % (file)
		sys.exit(-1)

	if myelf.elfwidth == 64:
		sixtyfour = True
	else:
		sixtyfour = False

	dynsym = myelf.section(".dynsym")

	if dynsym == False:
		print "ERROR: could not retrieve .dynsym section"
		exit()

	dynstr = myelf.section(".dynstr")
	
	if dynstr == False:
		print "ERROR: could not retrieve .dynstr section"
		exit()

	symbol_names = dynstr['data'].split("\x00")
	symbol_info = {}

	i = 0

	while i < len(dynsym['data']):
		if sixtyfour == True:
						sym_entry = struct.unpack("<LQQBBH", dynsym['data'][i:(i+24)])
						i = i+24
		else:
						sym_entry = struct.unpack("<LLLBBH", dynsym['data'][i:(i+16)])
						i = i+16

		name_len = dynstr['data'][(sym_entry[0]+1):].find("\x00")
		name = dynstr['data'][ (sym_entry[0]) : (sym_entry[0]+name_len+1) ]

		
		if sym_filter != "" and name.find(sym_filter) == -1:
			continue

		fstr  = colors.fg("green") + "[" + colors.bold() + "%08x" + colors.end() + colors.fg("green") + "]" + colors.end() 
		fstr += " '" + colors.fg("red") + colors.bold() + "%s" + colors.end() + "'" 

		print fstr % (sym_entry[1], name)
示例#8
0
def handle_parameters(shellcode, params):
    for param in shellcode["parameters"]:
        ok = False

        while ok == False:
            if param['name'] not in params:
                params[param['name']] = param_stdin(param)

            ok = validate(param, params[param['name']])

            if ok == False:
                print "validation for parameter " + param['name'],
                print " (of type " + type_name(param['type']) + ") ",
                print "failed with input " + params[param['name']]

                del params[param['name']]

        shellcode["code"] = shellcode["code"].replace(
            param['placeholder'], output(param, params[param['name']]))

        print >> sys.stderr, "  " + colors.bold() + colors.fg(
            'green') + "++" + colors.end(),
        print >> sys.stderr, " parameter " + colors.bold(
        ) + param['name'] + colors.end(),
        print >> sys.stderr, " set to '" + colors.bold() + params[
            param['name']] + colors.end() + "'"

    return shellcode
示例#9
0
def c(buf, array_name = 'shellcode', row_width = 16, fancy = False):
	if fancy:
		name  = colors.fg('green') + "unsigned " + colors.bold() + "char " + colors.end()
		name += colors.bold() + array_name + "[]" +  colors.end()
	else:
		name = "unsigned char " + array_name + "[]"

	return code_array(buf, name, row_width, '', fancy);
示例#10
0
def c(buf, array_name = 'shellcode', row_width = 16, fancy = False):
	if fancy:
		name  = colors.fg('green') + "unsigned " + colors.bold() + "char " + colors.end()
		name += colors.bold() + array_name + "[]" +  colors.end()
	else:
		name = "unsigned char " + array_name + "[]"

	return code_array(buf, name, row_width, '', fancy);
示例#11
0
def banner():
	asquee = """
    __   __  ______.___   __  _____._  __._______._ __  ____._________
   /  \ /  \/  __  |    \|  |/  ___| \/  /\  ___/  |  |/ __  \__   __/
  /    '    \   /  |  |\    |   _|_\    /__\   \|     |   /  |  |  |
 /___\  /    \_____|__|  \__|______||__||______/|__|__|\_____|  |__|
      \/ _____\\   """

	sys.stderr.write(colors.bold() + colors.fg('cyan') + asquee + colors.end() + "\n\n")
示例#12
0
def print_codes(codes, depth = 0):
	for key in codes.keys():
		if "description" in codes[key]:
			second_col = "%s%4d%s bytes -- %s" % (colors.fg('green'), get_code_size(codes[key]), colors.end(), codes[key]['description'])
			print "  " * (depth+1) + key.ljust(40 - (depth*2)) + second_col
			
		else:
			print "  " * (depth+1) + colors.bold() + key + colors.end()
			print_codes(codes[key], depth+1)
示例#13
0
def header():
	art = """
              ___    ___   __._____  ___   __.__    __  ____. ___   __ 
             /   \  |    \|  |  __  \   \/  /|  |  |  |/ __  \    \|  |
            /  \  \ |  |\    |   /  / \    / |  |__|  |   /  |  |\    |
           /__/ \__\|__|  \__|__|\__\  |__|  |_____|__|\_____|__|  \__|
                   """

	sys.stderr.write(colors.bold() + colors.fg('cyan') + art + colors.end() + "\n\n")
示例#14
0
def banner():
    asquee = """
    __   __  ______.___   __  _____._  __._______._ __  ____._________
   /  \ /  \/  __  |    \|  |/  ___| \/  /\  ___/  |  |/ __  \__   __/
  /    '    \   /  |  |\    |   _|_\    /__\   \|     |   /  |  |  |
 /___\  /    \_____|__|  \__|______||__||______/|__|__|\_____|  |__|
      \/ _____\\   """

    sys.stderr.write(colors.bold() + colors.fg('cyan') + asquee +
                     colors.end() + "\n\n")
示例#15
0
def do_ropfind(file, match_string):
	gadgets = []

	myelf = elf.fromfile(file)

	if myelf.data[0:4] != "\x7F"+"ELF":
		print "[!] '%s' is not a valid ELF file :(" % (file)
		sys.exit(-1)


	# figure out parameter
	if re.search("^[0-9a-f\?]+$", match_string) != None:
		pattern = match_string
	else:
		pattern = assemble_str(match_string)


	print "[!] pattern: '%s'" % pattern

	for section_name in myelf.strtable:
		if section_name == "":
			continue

		section = myelf.section(section_name)

		# check for PROGBITS type
		if section['type'] != 1:
			continue

		matches = findstr(section['data'], pattern)

		if len(matches) == 0:
			continue

		pstr  = colors.fg('cyan') + ">> section '" + colors.bold() + section_name + colors.end()
		pstr += colors.fg('cyan') + "' [" + colors.bold() + str(len(matches)) + colors.end()
		pstr += colors.fg('cyan') + " hits]"

		m = 0

		for match in matches:
			if match[1] in gadgets:
				continue

			if m == 0:
				print pstr
				m = 1

			disas = disas_str(section['addr'] + match[0], binascii.unhexlify(match[1]))
			fstr =  colors.fg('cyan') + " \_ " + colors.fg('green') + "%08x [" + colors.bold() + match[1] + colors.end()
			fstr += colors.fg('green') + "] "+ colors.bold() + "-> " + colors.end()
			fstr += colors.fg('red') + ' ; '.join(disas).lower() + colors.end()
			print fstr % (section['addr'] + match[0])

			gadgets.append(match[1])

		if m == 1:
			print ""
示例#16
0
def print_codes(codes, depth=0):
    for key in codes.keys():
        if "description" in codes[key]:
            second_col = "%s%4d%s bytes -- %s" % (
                colors.fg('green'), get_code_size(
                    codes[key]), colors.end(), codes[key]['description'])
            print "  " * (depth + 1) + key.ljust(40 - (depth * 2)) + second_col

        else:
            print "  " * (depth + 1) + colors.bold() + key + colors.end()
            print_codes(codes[key], depth + 1)
示例#17
0
def code_array(buf, array_name = 'shellcode', row_width = 16, line_delimiter = '', fancy = False):
	lines = []
	out = array_name +" = \n"

	for i in range(0, len(buf), row_width):
		j = 0
		linebuf = ''
		while (j < row_width and (i+j) < len(buf)):
			linebuf += "\\x%02x" % ( ord(buf[i+j]) )
			j = j + 1

		lines.append(linebuf);

	for i in range(0, len(lines)-1):
		if fancy:
			out += "\t" + colors.bold() + colors.fg('magenta') + "\""
			out += colors.fg("red") + lines[i]
			out += colors.fg('magenta') + "\"" + colors.end()
			out += line_delimiter + "\n"
		else:
			out += "\t\"%s\"%s\n" % ( lines[i], line_delimiter )

	if fancy:
		out += "\t" + colors.bold() + colors.fg('magenta') + "\""
		out += colors.fg("red") + lines[len(lines)-1]
		out += colors.fg('magenta') + "\"" + colors.end() + ";"
		out += "\n\n"
		# out += "\t\"%s\";\n\n" % ( lines[len(lines)-1] )
	else:
		out += "\t\"%s\";\n\n" % ( lines[len(lines)-1] )

	return out
示例#18
0
def code_array(buf, array_name = 'shellcode', row_width = 16, line_delimiter = '', fancy = False):
	lines = []
	out = array_name +" = \n"

	for i in range(0, len(buf), row_width):
		j = 0
		linebuf = ''
		while (j < row_width and (i+j) < len(buf)):
			linebuf += "\\x%02x" % ( ord(buf[i+j]) )
			j = j + 1

		lines.append(linebuf);

	for i in range(0, len(lines)-1):
		if fancy:
			out += "\t" + colors.bold() + colors.fg('magenta') + "\""
			out += colors.fg("red") + lines[i]
			out += colors.fg('magenta') + "\"" + colors.end()
			out += line_delimiter + "\n"
		else:
			out += "\t\"%s\"%s\n" % ( lines[i], line_delimiter )

	if fancy:
		out += "\t" + colors.bold() + colors.fg('magenta') + "\""
		out += colors.fg("red") + lines[len(lines)-1]
		out += colors.fg('magenta') + "\"" + colors.end() + ";"
		out += "\n\n"
		# out += "\t\"%s\";\n\n" % ( lines[len(lines)-1] )
	else:
		out += "\t\"%s\";\n\n" % ( lines[len(lines)-1] )

	return out
示例#19
0
def disas(buf, array_name = '', row_width = 16, fancy = False, sixtyfour = False):
	parser = optparse.OptionParser()

	if sixtyfour == True:
		parser.set_defaults(dt=distorm3.Decode64Bits)
	else:
		parser.set_defaults(dt=distorm3.Decode32Bits)

	options, args = parser.parse_args([])

	disas = distorm3.Decode(0, buf, options.dt)
	out = ''

	for (offset, size, instruction, hexdump) in disas:
		tmp = ''

		if fancy:
			tmp += colors.fg('cyan')

		tmp += "%.8x: " % (offset)

		if fancy:
			tmp += colors.fg('red')

		tmp += hexdump
		tmp += " " * (20-len(hexdump))

		if fancy:
			tmp += colors.fg('green')

		tmp += instruction

		if fancy:
			tmp += colors.end()

		out += "  " + tmp + "\n"

	return out.lower()
示例#20
0
def disas(buf, array_name='', row_width=16, fancy=False, sixtyfour=False):
    parser = optparse.OptionParser()

    if sixtyfour == True:
        parser.set_defaults(dt=distorm3.Decode64Bits)
    else:
        parser.set_defaults(dt=distorm3.Decode32Bits)

    options, args = parser.parse_args([])

    disas = distorm3.Decode(0, buf, options.dt)
    out = ''

    for (offset, size, instruction, hexdump) in disas:
        tmp = ''

        if fancy:
            tmp += colors.fg('cyan')

        tmp += "%.8x: " % (offset)

        if fancy:
            tmp += colors.fg('red')

        tmp += hexdump
        tmp += " " * (20 - len(hexdump))

        if fancy:
            tmp += colors.fg('green')

        tmp += instruction

        if fancy:
            tmp += colors.end()

        out += "  " + tmp + "\n"

    return out.lower()
示例#21
0
def do_ezrop(text):
    i = 0
    while i < len(text['data']):
        if text['data'][i] == "\xc3":
            block_len = 10

            while block_len > 1:
                start = i - block_len
                end = start + block_len + 1
                disas = distorm3.Decode(text['addr'] + start,
                                        text['data'][start:end], options.dt)

                if disas[len(disas) - 1][2] == "RET" and match_disas(
                        disas, sys.argv[2]) and ok_disas(disas):
                    found_start = False

                    for (offset, size, instruction, hexdump) in disas:
                        if instruction.find(sys.argv[2]) != -1:
                            found_start = True

                        if found_start == True:
                            out = colors.fg('cyan')
                            out += "%.8x: " % (offset)
                            out += colors.fg('red')
                            out += hexdump
                            out += " " * (20 - len(hexdump))
                            out += colors.fg('green')
                            out += instruction + colors.end()
                            print out

                    print "=" * 50

                    i = i + block_len
                    break

                block_len = block_len - 1

        i = i + 1
示例#22
0
文件: rop.py 项目: blasty/moneyshot
def do_ezrop(text):
	i = 0
	while i < len(text['data']):
		if text['data'][i] == "\xc3":
			block_len = 10

			while block_len > 1:
				start = i - block_len
				end   = start + block_len + 1
				disas = distorm3.Decode(text['addr'] + start, text['data'][start:end], options.dt)

				if disas[len(disas)-1][2] == "RET" and match_disas(disas, sys.argv[2]) and ok_disas(disas):
					found_start = False

					for (offset, size, instruction, hexdump) in disas:
						if instruction.find(sys.argv[2]) != -1:
							found_start = True

						if found_start == True:
							out = colors.fg('cyan')
							out += "%.8x: " % (offset)
							out += colors.fg('red')
							out += hexdump
							out += " " * (20-len(hexdump))
							out += colors.fg('green')
							out += instruction + colors.end()
							print out

					print "=" * 50

					i = i + block_len
					break

				block_len = block_len - 1

		i = i + 1
示例#23
0
def do_ropfind_raw(file, match_string, single):
    gadgets = []

    sixtyfour = True

    data = open(file).read()

    # figure out parameter
    if re.search("^[0-9a-f\?]+$", match_string) != None:
        pattern = match_string
    else:
        pattern = assemble_str(match_string, sixtyfour)

    print "[!] pattern: '%s'" % pattern

    matches = findstr(data, pattern)

    if len(matches) == 0:
        return

    pstr = colors.fg(
        'cyan') + ">> section '" + colors.bold() + "RAW" + colors.end()
    pstr += colors.fg('cyan') + "' [" + colors.bold() + str(
        len(matches)) + colors.end()
    pstr += colors.fg('cyan') + " hits]"

    m = 0

    for match in matches:
        if single and match[1] in gadgets:
            continue

        if m == 0:
            print pstr
            m = 1

        disas = disas_str(match[0], binascii.unhexlify(match[1]), sixtyfour)
        fstr = colors.fg('cyan') + " \_ " + colors.fg(
            'green') + "%08x [" + colors.bold() + match[1] + colors.end()
        fstr += colors.fg(
            'green') + "] " + colors.bold() + "-> " + colors.end()
        fstr += colors.fg('red') + ' ; '.join(disas).lower() + colors.end()
        print fstr % (match[0])

        gadgets.append(match[1])

    if m == 1:
        print ""
示例#24
0
文件: rop.py 项目: blasty/moneyshot
def do_ropfind_raw(file, match_string, single):
	gadgets = []

	sixtyfour = True

	data = open(file).read()

	# figure out parameter
	if re.search("^[0-9a-f\?]+$", match_string) != None:
		pattern = match_string
	else:
		pattern = assemble_str(match_string, sixtyfour)


	print "[!] pattern: '%s'" % pattern

	matches = findstr(data, pattern)

	if len(matches) == 0:
		return

	pstr  = colors.fg('cyan') + ">> section '" + colors.bold() + "RAW" + colors.end()
	pstr += colors.fg('cyan') + "' [" + colors.bold() + str(len(matches)) + colors.end()
	pstr += colors.fg('cyan') + " hits]"

	m = 0

	for match in matches:
		if single and match[1] in gadgets:
			continue

		if m == 0:
			print pstr
			m = 1

		disas = disas_str(match[0], binascii.unhexlify(match[1]), sixtyfour)
		fstr =  colors.fg('cyan') + " \_ " + colors.fg('green') + "%08x [" + colors.bold() + match[1] + colors.end()
		fstr += colors.fg('green') + "] "+ colors.bold() + "-> " + colors.end()
		fstr += colors.fg('red') + ' ; '.join(disas).lower() + colors.end()
		print fstr % (match[0])

		gadgets.append(match[1])


	if m == 1:
		print ""
示例#25
0
def python(buf, array_name='shellcode', row_width=16, fancy=False):
    lines = []
    out = ""

    for i in range(0, len(buf), row_width):
        j = 0
        linebuf = ''
        while (j < row_width and (i + j) < len(buf)):
            linebuf += "\\x%02x" % (ord(buf[i + j]))
            j = j + 1

        lines.append(linebuf)

    for i in range(0, len(lines) - 1):
        if fancy:
            if i == 0:
                out += array_name + " =  " + colors.bold() + colors.fg(
                    'magenta') + "\""
            else:
                out += array_name + " += " + colors.bold() + colors.fg(
                    'magenta') + "\""

            out += colors.fg("red") + lines[i]
            out += colors.fg('magenta') + "\"\n" + colors.end()
        else:
            if i == 0:
                out += array_name + "  = \"%s\"\n" % (lines[i])
            else:
                out += array_name + " += \"%s\"\n" % (lines[i])

    if fancy:
        out += array_name + " += " + colors.bold() + colors.fg(
            'magenta') + "\""
        out += colors.fg("red") + lines[len(lines) - 1]
        out += colors.fg('magenta') + "\"" + colors.end() + ";"
        out += "\n\n"
        # out += "\t\"%s\";\n\n" % ( lines[len(lines)-1] )
    else:
        out += array_name + " += \"%s\";\n\n" % (lines[len(lines) - 1])

    return out
示例#26
0
def handle_parameters(shellcode, params):
    for param in shellcode["parameters"]:
        ok = False

        while ok == False:
            if param["name"] not in params:
                params[param["name"]] = param_stdin(param)

            ok = validate(param, params[param["name"]])

            if ok == False:
                print "validation for parameter " + param["name"],
                print " (of type " + type_name(param["type"]) + ") ",
                print "failed with input " + params[param["name"]]

                del params[param["name"]]

        shellcode["code"] = shellcode["code"].replace(param["placeholder"], output(param, params[param["name"]]))

        print >> sys.stderr, "  " + colors.bold() + colors.fg("green") + "++" + colors.end(),
        print >> sys.stderr, " parameter " + colors.bold() + param["name"] + colors.end(),
        print >> sys.stderr, " set to '" + colors.bold() + params[param["name"]] + colors.end() + "'"

    return shellcode
示例#27
0
def python(buf, array_name = 'shellcode', row_width = 16, fancy = False):
	lines = []
	out = ""

	for i in range(0, len(buf), row_width):
		j = 0
		linebuf = ''
		while (j < row_width and (i+j) < len(buf)):
			linebuf += "\\x%02x" % ( ord(buf[i+j]) )
			j = j + 1

		lines.append(linebuf);

	for i in range(0, len(lines)-1):
		if fancy:
			if i == 0:
				out += array_name + " =  " + colors.bold() + colors.fg('magenta') + "\""
			else:
				out += array_name + " += " + colors.bold() + colors.fg('magenta') + "\""

			out += colors.fg("red") + lines[i]
			out += colors.fg('magenta') + "\"\n" + colors.end()
		else:
			if i == 0:
				out += array_name + "  = \"%s\"\n" % ( lines[i] )
			else:
				out += array_name + " += \"%s\"\n" % ( lines[i] )

	if fancy:
		out += array_name + " += " + colors.bold() + colors.fg('magenta') + "\""
		out += colors.fg("red") + lines[len(lines)-1]
		out += colors.fg('magenta') + "\"" + colors.end() + ";"
		out += "\n\n"
		# out += "\t\"%s\";\n\n" % ( lines[len(lines)-1] )
	else:
		out += array_name + " += \"%s\";\n\n" % ( lines[len(lines)-1] )

	return out
示例#28
0
def python(buf, array_name="shellcode", row_width=16, fancy=False):
    lines = []
    out = ""

    for i in range(0, len(buf), row_width):
        j = 0
        linebuf = ""
        while j < row_width and (i + j) < len(buf):
            linebuf += "\\x%02x" % (ord(buf[i + j]))
            j = j + 1

        lines.append(linebuf)

    for i in range(0, len(lines) - 1):
        if fancy:
            if i == 0:
                out += array_name + " =  " + colors.bold() + colors.fg("magenta") + '"'
            else:
                out += array_name + " += " + colors.bold() + colors.fg("magenta") + '"'

            out += colors.fg("red") + lines[i]
            out += colors.fg("magenta") + '"\n' + colors.end()
        else:
            if i == 0:
                out += array_name + '  = "%s"\n' % (lines[i])
            else:
                out += array_name + ' += "%s"\n' % (lines[i])

    if fancy:
        out += array_name + " += " + colors.bold() + colors.fg("magenta") + '"'
        out += colors.fg("red") + lines[len(lines) - 1]
        out += colors.fg("magenta") + '"' + colors.end() + ";"
        out += "\n\n"
        # out += "\t\"%s\";\n\n" % ( lines[len(lines)-1] )
    else:
        out += array_name + ' += "%s";\n\n' % (lines[len(lines) - 1])

    return out
示例#29
0
def hexdump(buf, array_name='shellcode', row_width=16, fancy=False):
    # build horizontal marker
    out = "           | "

    for i in range(0, row_width):
        if fancy:
            out += "%02x " % (i)
            #out += colors.bold() + colors.fg('yellow') + ("%02x " % (i)) + colors.end()
        else:
            out += "%02x " % (i)

    out += "|\n"

    delim_row = "  +--------+"
    delim_row += "-" * (row_width * 3 + 1) + "+" + "-" * (row_width + 1) + "-+"

    if fancy:
        out += colors.bold() + delim_row + colors.end() + "\n"
    else:
        out += delim_row + "\n"

    for i in range(0, len(buf), row_width):
        if fancy:
            out += colors.bold() + "  | " + colors.fg("cyan") + (
                "%06x" % (i)) + " | " + colors.end()
        else:
            out += "  | %06x | " % (i)

        for j in range(0, row_width):
            if i + j < len(buf):
                if fancy:
                    str = colors.fg('red') + ("%02x " % (ord(buf[i + j])))

                    if (i + j) % 8 >= 4:
                        out += colors.bold() + str + colors.end()
                    else:
                        out += str + colors.end()
                else:
                    out += "%02x " % (ord(buf[i + j]))
            else:
                out += "   "

        asciiz = ''

        for j in range(0, row_width):
            if i + j < len(buf):
                c = ord(buf[i + j])

                if c >= 0x20 and c <= 0x7e:
                    asciiz += buf[i + j]
                else:
                    asciiz += '.'
            else:
                asciiz += ' '

        if fancy:
            out += colors.bold() + "| " + colors.fg(
                'green') + asciiz + colors.end() + colors.bold(
                ) + " |" + colors.end() + "\n"
        else:
            out += "| " + asciiz + " |\n"

    if fancy:
        out += colors.bold() + delim_row + colors.end() + "\n"
    else:
        out += delim_row + "\n"

    return out
示例#30
0
def hexdump(buf, array_name = 'shellcode', row_width = 16, fancy = False):
	# build horizontal marker
	out = "           | "

	for i in range(0, row_width):
		if fancy:
			out += "%02x " % (i)
			#out += colors.bold() + colors.fg('yellow') + ("%02x " % (i)) + colors.end()
		else:
			out += "%02x " % (i)

	out += "|\n"

	delim_row  = "  +--------+";
	delim_row += "-" * (row_width*3 + 1) + "+" + "-" * (row_width+1) + "-+"

	if fancy:
		out += colors.bold() + delim_row + colors.end() + "\n"
	else:
		out += delim_row + "\n"

	for i in range(0, len(buf), row_width):
		if fancy:
			out += colors.bold() + "  | " + colors.fg("cyan") + ("%06x" % (i)) + " | " + colors.end()
		else:
			out += "  | %06x | " % (i)

		for j in range(0, row_width):
			if i+j < len(buf):
				if fancy:
					str = colors.fg('red') + ("%02x " % (ord(buf[i+j])))

					if (i+j)%8 >= 4:
						out += colors.bold() + str + colors.end()
					else:
						out += str + colors.end()
				else:
					out += "%02x " % (ord(buf[i+j]))
			else:
				out += "   "

		asciiz = ''

		for j in range(0, row_width):
			if i+j < len(buf):
				c = ord(buf[i+j])

				if c >= 0x20 and c <= 0x7e:
					asciiz += buf[i+j]
				else:
					asciiz += '.'
			else:
				asciiz += ' '

		if fancy:
			out += colors.bold() + "| " + colors.fg('green') + asciiz + colors.end() + colors.bold() + " |" + colors.end() + "\n"
		else:
			out += "| " + asciiz + " |\n"

	if fancy:
		out += colors.bold() + delim_row + colors.end() + "\n"
	else:
		out += delim_row + "\n"

	return out
示例#31
0
def do_ropfind(file, match_string):
    gadgets = []

    myelf = elf.fromfile(file)

    if myelf.data[0:4] != "\x7F" + "ELF":
        print "[!] '%s' is not a valid ELF file :(" % (file)
        sys.exit(-1)

        # figure out parameter
    if re.search("^[0-9a-f\?]+$", match_string) != None:
        pattern = match_string
    else:
        pattern = assemble_str(match_string)

    print "[!] pattern: '%s'" % pattern

    for section_name in myelf.strtable:
        if section_name == "":
            continue

        section = myelf.section(section_name)

        # check for PROGBITS type
        if section["type"] != 1:
            continue

        matches = findstr(section["data"], pattern)

        if len(matches) == 0:
            continue

        pstr = colors.fg("cyan") + ">> section '" + colors.bold() + section_name + colors.end()
        pstr += colors.fg("cyan") + "' [" + colors.bold() + str(len(matches)) + colors.end()
        pstr += colors.fg("cyan") + " hits]"

        m = 0

        for match in matches:
            if match[1] in gadgets:
                continue

            if m == 0:
                print pstr
                m = 1

            disas = disas_str(section["addr"] + match[0], binascii.unhexlify(match[1]), True)
            fstr = colors.fg("cyan") + " \_ " + colors.fg("green") + "%08x [" + colors.bold() + match[1] + colors.end()
            fstr += colors.fg("green") + "] " + colors.bold() + "-> " + colors.end()
            fstr += (
                colors.fg("red")
                + "("
                + colors.bold()
                + "Thumb"
                + colors.end()
                + colors.fg("red")
                + ") "
                + " ; ".join(disas).lower()
                + colors.end()
            )
            print fstr % (section["addr"] + match[0] + 1)

            gadgets.append(match[1])
            if (len(binascii.unhexlify(match[1])) % 4) == 0:
                disas = disas_str(section["addr"] + match[0], binascii.unhexlify(match[1]), False)
                fstr = (
                    colors.fg("cyan") + " \_ " + colors.fg("green") + "%08x [" + colors.bold() + match[1] + colors.end()
                )
                fstr += colors.fg("green") + "] " + colors.bold() + "-> " + colors.end()
                fstr += (
                    colors.fg("red")
                    + "("
                    + colors.bold()
                    + "ARM"
                    + colors.end()
                    + colors.fg("red")
                    + "  ) "
                    + " ; ".join(disas).lower()
                    + colors.end()
                )

                if not (len(disas) == 1 and (disas[0] == "" or disas[0] == "None")):
                    print fstr % (section["addr"] + match[0])

                    gadgets.append(match[1])

        if m == 1:
            print ""