Skip to content

Commit 2cb85c9

Browse files
author
bspar
committed
Fix some shit
1 parent d1864a4 commit 2cb85c9

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ Currently supported functions:
1212
* `recv`
1313
* `read`
1414
* `printf`
15+
16+
----
17+
18+
Creditz to ColdHeat, modified by bspar because <3

main.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,20 @@ def calculate_buffer_size(ea):
8484
instr = idc.GetDisasm(ea)
8585
buf = instr.split(',')[1].strip()
8686
if "+" in buf:
87-
size = hex2int(buf[buf.find('+')+1:len(buf)-1])
88-
return stack_offset(ea) - size
87+
try:
88+
size = hex2int(buf[buf.find('+')+1:len(buf)-1])
89+
except ValueError:
90+
old = buf[buf.find('+')+1:len(buf)]
91+
idc.OpHex(ea, -1)
92+
instr = idc.GetDisasm(ea)
93+
buf = instr.split(',')[1].strip()
94+
size = hex2int(buf[buf.find('-')+1:len(buf)-1])
95+
return size
96+
# return stack_offset(ea) - size
8997
elif "-" in buf:
9098
size = hex2int(buf[buf.find('-')+1:len(buf)-1])
91-
return stack_offset(ea) + size
99+
return size
100+
# return stack_offset(ea) + size
92101

93102
BUFFER_SIZE = 0
94103
def stack_calc(function):
@@ -134,11 +143,13 @@ def test_fgets(ea):
134143
try:
135144
if "offset" in arg_dict['s']:
136145
section = arg_dict['s'].split(' ')[1]
137-
arg_dict['s'] = bss[section]
146+
arg_dict['s'] = bss[section]
138147
except TypeError:
139148
arg_dict['s'] = calculate_buffer_size(arg_dict['s'])
140149

141150
if arg_dict['s'] < arg_dict['n']:
151+
print 'Found vulnerable fgets'
152+
print 'buf Size: ' + str(arg_dict['s'])
142153
return True, hex(ea), arg_dict
143154
else:
144155
return False, hex(ea), arg_dict
@@ -222,9 +233,9 @@ def test_read(ea):
222233
while item != BADADDR:
223234
next = idc.NextHead(item, end)
224235
if next != BADADDR:
225-
bss[idc.Name(item)] = next - item
236+
bss[idc.Name(item)] = next - item
226237
else:
227-
bss[idc.Name(item)] = end - item
238+
bss[idc.Name(item)] = end - item
228239
item = next
229240

230241
### Populate Functions
@@ -272,4 +283,6 @@ def test_read(ea):
272283
for x in find_calls('read'):
273284
res = test_read(x)
274285
print '\t', res
275-
if res[0]: idc.SetColor(res[1], CIC_ITEM, 0x0000ff)
286+
if res[0]: idc.SetColor(int(res[1], 16), CIC_ITEM, 0x0000ff)
287+
288+

0 commit comments

Comments
 (0)