ROP: How to make comparisons ?

Marco Ramilli
Date
3 August 2011
Read
Share
Folks, a quick and dirty post on how to compare using Return Oriented Programming.

Lets say we simply want to compare two operands:

cmp %ax, %cx
Doing it by using a simple compare is pretty easy, but when we are dealing with ROP it's pretty rare having a straight cmp %ax, %cx. So what is the alternative ? cmp (like many other commands) once compared the two operands sets a number of flags in the EFLAGS register. Luckily many other instructions set flags as side effect !!
For example we can use an instruction called neg. neg %ax calculates two's complements and sets a carry flag (CF) is the argument is not zero. So, do you want test for equality ? neg is your guy ! Another great example comes from the function sub. sub %ax, %cx subtraces the source (%cx) operator from the destiny (%ax) and sets the Carry Flag once destiny is bigger then source. You might use it to compare if a number is greater then another.
Of course these are only a couple of ways to perform comparisons but are the most frequent ones. By searching on the imported libraries you will find a lot of neg and/or sub. Now you know how to use them ;).
Marco Ramilli
Date
3 August 2011
Read
Share
← Go back
Latest Posts

i-SOON Data Leak: Key Points

Introduction i-SOON (上海安洵), a prominent contractor for various Chinese government agencies such […]

Date
26.02.2024
Duration
5 min
Text
Marco Ramilli

X Gold Badges: a new proliferating market

When I saw a threat actor hijacking the X account of Google's […]

Date
08.01.2024
Duration
5 min
Text
Marco Ramilli

Technical Data Sheet: LOCKBIT 3.0

LOCKBIT 3.0 is a notorious Ransomware Group that was first identified on […]

Date
20.12.2023
Duration
5 min
Text
Marco Ramilli
1 2 3 236
Back to Top
magnifier