About
Articles
Book Store
Distributed RCE
Downloads
Event Calendar
Forums
Live Discussion
Reference Library
RSS Feeds
Search
Users
What's New
Customize Theme
bluegrey
blackgreen
metal
simple
Flag:
Tornado!
Hurricane!
Login:
Password:
Remember Me
Register
Blogs
>>
lin0xx
's Blog
Created: Thursday, February 4 2010 20:38.25 CST
Printer Friendly ...
User-supplied Array Index Exploitation Simplified.. sort of.
Author:
lin0xx
# Views:
2208
Have you ever ran into a case where you controlled an index into an array, but then were tasked with the annoying prospect of massaging the overwrite to suit your needs?
For example, from http://labs.idefense.com/intelligence/vulnerabilities/display.php?id=5 :
#define RFC2231_MAX 64
...
char *pieces[RFC2231_MAX];
and indexed by the signed integer variable 'n':
if(n < RFC2231_MAX){
pieces[n] = parms->value;
^^ Note: parms->value is a pointer to user data.
Say you do some reversing and find out that 'pieces' is 300 bytes away from the stored return address. From the array write, we can tell that overwriting the return address would totally be exploitable (assuming no N^X) since it's overwritten with a pointer to data supplied by you.
We need the following: a negative integer that when multiplied by 4 (assuming a 32 bit architecture here), will yield 300.
Well, I'm not the most k-awesome bithax0r in the world, so I find the prospect of finding a negative integer to exploit this bug to be quite annoying. I know what I want, I just don't want to waste time telling some stupid imperative language how to give it to me! What could possibly solve my quandary? Hmmm, STP.. a constraint solver.. that sounds like just the thing!
Throw this into a file:
dummy: BITVECTOR(32);
overflow : BITVECTOR(64);
multiplyOverflow : BITVECTOR(64);
notDummy : BITVECTOR(32);
evilIndex : BITVECTOR(32);
% Make sure the number is negative via two's compliment ninjutsu
ASSERT(notDummy = ~dummy);
ASSERT(evilIndex = BVPLUS(32, notDummy, 0hex00000001));
% Make sure it's signed too
ASSERT(evilIndex & 0hex80000000 = 0hex80000000);
% Need a bigger bit width to express the overflow
ASSERT(overflow[31:0] = evilIndex);
ASSERT(multiplyOverflow = BVMULT(64, overflow, 0hex0000000000000004));
% We want evilIndex*4 == 300
ASSERT(multiplyOverflow[31:0] = 0hex0000012C);
QUERY(FALSE);
Now feed it to the solver...
$ stp -p array.access.stp
ASSERT( v_solver_0 = 0x00000000 );
ASSERT( overflow = 0x00000000C000004B );
ASSERT( multiplyOverflow = 0x000000030000012C );
ASSERT( evilIndex = 0xC000004B );
ASSERT( notDummy = 0xC000004A );
ASSERT( dummy = 0x3FFFFFB5 );
Invalid.
Well, there you have it: 0xC000004B. Compare this to the alternative (from: http://milw0rm.org/exploits/99 ) :
unsigned int num(int dist) {
int tmp = -1-dist;
unsigned int border = tmp;
int neg = (border/4)*(-1);
unsigned int res;
res = 0xffffffff+neg;
return res;
}
I checked the output of my formula against the return value for num() here - they matched.
Well, I know which method looks more intuitive to me.
Hope someone finds this useful!
Add New Comment
Comment:
There are
28,220
total registered users.
Recently Created Topics
Reverse Engineering ...
Jan/23
Career: DoD Agency I...
Jan/22
"Disappearing&q...
Jan/17
Career: Software Sec...
Jan/11
Where is the call st...
Jan/07
IDA Pro 6.1 Breakpoi...
Jan/01
How to create data s...
Dec/30
can i search all mod...
Dec/23
IDA symbol table exp...
Dec/20
An anti-attach trick
Dec/17
Recent Forum Posts
Reverse Engineering ...
NirIzr
"Disappearing&q...
NirIzr
Reverse Engineering ...
charlie
"Disappearing&q...
charlie
An anti-attach trick
Bass
An anti-attach trick
waleeda...
An anti-attach trick
Bass
An anti-attach trick
waleeda...
An anti-attach trick
Bass
Looking for value in...
NirIzr
Recent Blog Entries
waleedassar
Feb/06
OllyDbg v1.10 And Hardware ...
waleedassar
Jan/31
Yet Another Anti-Debug Trick
RolfRolles
Jan/22
Finding Bugs in VMs with a ...
waleedassar
Jan/13
An OllyDbg Bug Disables Sof...
waleedassar
Jan/01
Another OllyDbg Anti-Debug ...
More ...
Recent Blog Comments
NirIzr
on:
Feb/05
Yet Another Anti-Debug Trick
trolotou
on:
Feb/05
Doudoune Moncler -Pennies F...
waleedassar
on:
Feb/01
Yet Another Anti-Debug Trick
NirIzr
on:
Jan/31
Yet Another Anti-Debug Trick
jackchen
on:
Jan/10
nike mercurial vapor iii
More ...
Imagery
SoySauce Blueprint
Jun 6, 2008
[+] expand
View Gallery
(11) /
Submit