Skip to content

Commit

Permalink
Fixes timeout decorator issues and radare2 parsing problems
Browse files Browse the repository at this point in the history
  • Loading branch information
pufi656 committed Jun 23, 2024
1 parent 4d2ca42 commit 01aa693
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
6 changes: 3 additions & 3 deletions zeratool_lib/formatDetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def checkFormat(binary_name, inputType):
# Lame way to do a timeout
try:

@timeout_decorator.timeout(1200)
@timeout_decorator.timeout(1200, use_signals=False)
def exploreBinary(simgr):
simgr.explore(find=lambda s: "type" in s.globals)
return simgr.explore(find=lambda s: "type" in s.globals)

exploreBinary(simgr)
simgr = exploreBinary(simgr)
if "found" in simgr.stashes and len(simgr.found):
end_state = simgr.found[0]
run_environ["type"] = end_state.globals["type"]
Expand Down
6 changes: 3 additions & 3 deletions zeratool_lib/formatExploiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ def rediscoverAndExploit(binary_name, properties, stack_position, leak_format):
# Lame way to do a timeout
try:

@timeout_decorator.timeout(1200)
@timeout_decorator.timeout(1200, use_signals=False)
def exploreBinary(simgr):
simgr.explore(find=lambda s: "type" in s.globals)
return simgr.explore(find=lambda s: "type" in s.globals)

exploreBinary(simgr)
simgr = exploreBinary(simgr)
if "found" in simgr.stashes and len(simgr.found):
end_state = simgr.found[0]
run_environ["type"] = end_state.globals["type"]
Expand Down
6 changes: 3 additions & 3 deletions zeratool_lib/overflowDetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def checkOverflow(binary_name, inputType):
# Lame way to do a timeout
try:

@timeout_decorator.timeout(120)
@timeout_decorator.timeout(120, use_signals=False)
def exploreBinary(simgr):
simgr.explore(
return simgr.explore(
find=lambda s: "type" in s.globals, step_func=overflow_detect_filter
)

exploreBinary(simgr)
simgr = exploreBinary(simgr)
if "found" in simgr.stashes and len(simgr.found):
end_state = simgr.found[0]
run_environ["type"] = end_state.globals["type"]
Expand Down
12 changes: 11 additions & 1 deletion zeratool_lib/overflowExploitSender.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import os
import stat

from overflowExploiter import exploitOverflow
from pwn import ELF, gdb, process, u32, u64
Expand All @@ -14,8 +16,16 @@ def sendExploit(
):
send_results = {}

radare2_binary_name = "/radare2_binary"
fin = open(binary_name, "rb")
fout = open(radare2_binary_name, "wb")
fout.write(fin.read())
fin.close()
fout.close()
os.chmod(radare2_binary_name, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)

# Create local process
proc = process(binary_name)
proc = process(radare2_binary_name)
if debug:
gdb.attach(
proc,
Expand Down
13 changes: 11 additions & 2 deletions zeratool_lib/overflowExploiter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import stat

import angr
import claripy
Expand Down Expand Up @@ -54,6 +55,14 @@ def getOneGadget(properties):

def exploitOverflow(binary_name, properties, inputType):

radare2_binary_name = "/radare2_binary"
fin = open(binary_name, "rb")
fout = open(radare2_binary_name, "wb")
fout.write(fin.read())
fin.close()
fout.close()
os.chmod(radare2_binary_name, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)

run_environ = properties["pwn_type"].get("results", {})
run_environ["type"] = run_environ.get("type", None)

Expand Down Expand Up @@ -104,7 +113,7 @@ def exploitOverflow(binary_name, properties, inputType):
if inputType == "STDIN":
entry_addr = p.loader.main_object.entry
if not has_pie:
reg_values = getRegValues(binary_name, entry_addr)
reg_values = getRegValues(radare2_binary_name, entry_addr)
state = p.factory.full_init_state(
args=argv,
add_options=extras,
Expand Down Expand Up @@ -146,7 +155,7 @@ def exploitOverflow(binary_name, properties, inputType):
simgr.explore(find=lambda s: "type" in s.globals, step_func=step_func)
try:

@timeout_decorator.timeout(1200)
@timeout_decorator.timeout(1200, use_signals=False)
def exploreBinary(simgr):
simgr.explore(find=lambda s: "type" in s.globals, step_func=step_func)

Expand Down
2 changes: 1 addition & 1 deletion zeratool_lib/overflowRemoteLeaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def leak_remote_functions(binary_name, properties, inputType):
# Lame way to do a timeout
try:

@timeout_decorator.timeout(1200)
@timeout_decorator.timeout(1200, use_signals=False)
def exploreBinary(simgr):
simgr.explore(
find=lambda s: "libc" in s.globals, step_func=leak_remote_libc_functions
Expand Down

0 comments on commit 01aa693

Please sign in to comment.