edfed
Joined: 20 Feb 2006
Posts: 4353
Location: Now
|
that's the goal of win32, clic clic clic!
and here the preliminary test for a return value exploitation.
macro func n
{
align 32
db n
align 32
}
NULL=8000'0000h
;final results that are NULL are errors(overflow, infinite, NULL as operand)
;operation result that is =NULL is incremented to fit the valid scale.
org 100h
@@:
mov esi,MAIN
mov eax,NULL
call caller
cmp eax,NULL
jne @b
ret
align 4
MAIN:
TEST_if_then_else:
dd f.if,.read,.then,.else
.read: dd f.read,.char
.write: dd f.write,.char
.char: dd 10000041h
.then: dd f.read,0
.else: dd f.node,@f-$-4
dd .print,.write,.dec
@@:
.dec: dd f.dec,.char
.print: dd f.putc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
func 'flist '
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
f: ;function list
.NULL dd 0
.if dd _if
.puts dd _puts
.putc dd _putc
.read dd _read
.write dd _write
.node dd _node
.add dd _add
.sub dd _sub
.neg dd _neg
.inc dd _inc
.dec dd _dec
align 32
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
func 'caller '
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
caller:
.call=0
;esi=object to call
push ebx
or esi,esi
je @f
mov ebx,[esi+.call]
or ebx,ebx
je @f
nop
mov ebx,[ebx]
nop
or ebx,ebx
je @f
call bx
@@:
pop ebx
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
func 'inc '
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_inc:
.call=0
.op=4
push esi
mov esi,[esi+.op]
call caller
inc eax
pop esi
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
func 'dec '
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_dec:
.call=0
.op=4
push esi
mov esi,[esi+.op]
call caller
dec eax
pop esi
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
func 'add '
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_add:
.call=0
.op1=4
.op2=8
push ebx esi
mov ebx,esi
mov esi,[ebx+.op1]
call caller
mov esi,[ebx+.op2]
mov ebx,eax
call caller
add eax,ebx
pop esi ebx
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
func 'sub '
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_sub:
.call=0
.op1=4
.op2=8
push ebx esi
mov ebx,esi
mov esi,[ebx+.op2]
call caller
mov esi,[ebx+.op1]
mov ebx,eax
call caller
sub eax,ebx
pop esi ebx
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
func 'neg '
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_neg:
.call=0
.op=4
push esi
mov esi,[esi+.op]
call caller
neg eax
pop esi
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
func 'node '
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_node:
.call=0
.size=4
push ebx
mov ebx,[esi+.size]
shr ebx,2
jl .end
@@:
push esi
mov esi,[esi+.size+ebx*4]
call caller
pop esi
dec ebx
jg @b
.end:
pop ebx
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
func 'putc '
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_putc:
.call=0
;eax=char to print at cursor
push eax edi es word 0b800h
pop es
movzx edi,word[.cursor]
mov ah,4fh
mov [es:edi*2],ax
inc edi
cmp edi,25*80*2
jl @f
xor edi,edi
@@:
mov [.cursor],edi
pop es edi eax
ret
.cursor dd 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
func 'puts '
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_puts:
.call=0
.string=4
;uses putc via eax
push eax esi
mov esi,[esi+.string]
@@:
lodsb
cmp al,0
je @f
call _putc
jmp @b
@@:
pop esi eax
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
func 'ife '
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_if:
.call=0
.cond=4
.then=8
.else=12
push ebx esi
mov ebx,esi
mov esi,[ebx+.cond]
call caller
mov esi,[ebx+.then]
or eax,eax ;if eax=0
je @f
mov esi,[ebx+.else]
@@:
call caller
pop esi ebx
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
func 'read '
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_read:
.call=0
.ptr=4
push ebx
mov ebx,[esi+.ptr]
mov eax,NULL
or ebx,ebx
je @f
mov eax,[ebx]
@@:
pop ebx
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
func 'write '
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_write:
.call=0
.ptr=4
push ebx
mov ebx,[esi+.ptr]
or ebx,ebx
je @f
mov [ebx],eax
@@:
pop ebx
ret
it doesn't work somewhere between the if and the caller. but where?
...
and now, it works really good
macro _1op i
{
.call=0
.op=4
push esi
_call [esi+.op]
i eax
pop esi
ret
}
macro _2op i
{
.call=0
.op1=4
.op2=8
push ebx esi
mov ebx,esi
_call [ebx+.op1]
mov esi,[ebx+.op2]
mov ebx,eax
call _caller
i eax,ebx
pop esi ebx
ret
}
macro debug c
{
push eax
mov al,c
call _putc
pop eax
}
macro _call a
{
if ~ a eq
if a eq esi
else
mov esi,a
end if
end if
call _caller
}
macro _func a
{
align 32
db a
align 32
}
NULL=8000'0000h
org 100h
@@:
mov eax,NULL
_call _MAIN
cmp eax,NULL
jne @b
ret
align 4
_MAIN:
TEST_if_then_else:
dd f.if,.read,.then,.else
.else: dd f.node,@f-$-4
dd .print,.write,.dec
@@:
.read: dd f.read,.char
.write: dd f.write,.char
.char: dd '9'
.then: dd f.read,0
.dec: dd f.dec,.read
.inc: dd f.inc,.read
.print: dd f.putc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_func 'flist '
f: ;_function list
.NULL dd 0
.if dd _if
.puts dd _puts
.putc dd _putc
.read dd _read
.write dd _write
.node dd _node
.add dd _add
.sub dd _sub
.neg dd _neg
.inc dd _inc
.dec dd _dec
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_func 'caller '
;esi=object to call
_caller:
.call=0
push ebx esi
or esi,esi
je .null
mov ebx,[esi+.call]
or ebx,ebx
je @f
mov ebx,[ebx]
or ebx,ebx
je @f
call bx
@@:
pop esi ebx
ret
.null:
mov eax,NULL
jmp @b
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_func 'node '
;executes childs in list from last to first
_node:
.call=0
.list=4
push ebx
mov ebx,[esi+.list]
shr ebx,2
jl .end
@@:
push esi
_call [esi+.list+ebx*4]
pop esi
dec ebx
jg @b
.end:
pop ebx
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_func 'ife '
;returns eax as else, then, or cc
_if:;eax = 0
.call=0
.cc=4
.then=8
.else=12
push ebx esi
mov ebx,esi
_call [ebx+.cc]
mov esi,[ebx+.then]
or eax,eax ;if eax=0
je @f
mov esi,[ebx+.else]
@@:
_call
pop esi ebx
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_func 'putc '
;eax=char to print at cursor
_putc:
.call=0
push eax edi es word 0b800h
pop es
mov edi,[.cursor]
mov ah,4fh
mov [es:edi*2],ax
inc edi
cmp edi,25*80
jl @f
xor edi,edi
@@:
mov [.cursor],edi
pop es edi eax
ret
.cursor dd 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_func 'puts '
;uses putc via eax
_puts:
.call=0
.string=4
push eax esi
mov esi,[esi+.string]
@@:
lodsb
cmp al,0
je @f
call _putc
jmp @b
@@:
pop esi eax
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_func 'read '
;returns value in eax or NULL if ptr=0
_read:
.call=0
.ptr=4
push ebx
mov ebx,[esi+.ptr]
mov eax,NULL
or ebx,ebx
je @f
mov eax,[ebx]
@@:
pop ebx
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_func 'write '
;returns nothing, preserve eax
_write:
.call=0
.ptr=4
push ebx
mov ebx,[esi+.ptr]
or ebx,ebx
je @f
mov [ebx],eax
@@:
pop ebx
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_func 'inc '
_inc: _1op inc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_func 'dec '
_dec: _1op dec
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_func 'neg '
_neg: _1op neg
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_func 'add '
_add: _2op add
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_func 'sub '
_sub: _2op sub
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|