Skip to content

Instantly share code, notes, and snippets.

@Silva97
Created March 15, 2023 21:36
Show Gist options
  • Save Silva97/188e1b0e5915d6a521648a991e18c6da to your computer and use it in GitHub Desktop.
Save Silva97/188e1b0e5915d6a521648a991e18c6da to your computer and use it in GitHub Desktop.
Class to make sigreturn frame to exploit SROP
# By Luiz Felipe Silva (https://github.com/Silva97)
## References ##
# sys_rt_sigreturn: https://elixir.bootlin.com/linux/latest/source/arch/x86/um/signal.c#L560
# sigframe: https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/sigframe.h
# ucontext: https://elixir.bootlin.com/linux/latest/source/include/uapi/asm-generic/ucontext.h
# sigcontext: https://elixir.bootlin.com/linux/latest/source/arch/x86/include/uapi/asm/sigcontext.h#L324
import struct
class SigReturnFrame:
r8 = 0
r9 = 0
r10 = 0
r11 = 0
r12 = 0
r13 = 0
r14 = 0
r15 = 0
rdi = 0
rsi = 0
rbp = 0
rbx = 0
rdx = 0
rax = 0
rcx = 0
rsp = 0
rip = 0
eflags = 0
cs = 0
gs = 0
fs = 0
ss = 0
err = 0
trapno = 1
oldmask = 0
cr2 = 0
fpstate = 0
reserved = 0
siginfo = 0
def pack(self):
padding = b'Z' * 24
return padding \
+ struct.pack('<Q', self.r8) \
+ struct.pack('<Q', self.r9) \
+ struct.pack('<Q', self.r10) \
+ struct.pack('<Q', self.r11) \
+ struct.pack('<Q', self.r12) \
+ struct.pack('<Q', self.r13) \
+ struct.pack('<Q', self.r14) \
+ struct.pack('<Q', self.r15) \
+ struct.pack('<Q', self.rdi) \
+ struct.pack('<Q', self.rsi) \
+ struct.pack('<Q', self.rbp) \
+ struct.pack('<Q', self.rbx) \
+ struct.pack('<Q', self.rdx) \
+ struct.pack('<Q', self.rax) \
+ struct.pack('<Q', self.rcx) \
+ struct.pack('<Q', self.rsp) \
+ struct.pack('<Q', self.rip) \
+ struct.pack('<Q', self.eflags) \
+ struct.pack('<H', self.cs) \
+ struct.pack('<H', self.gs) \
+ struct.pack('<H', self.fs) \
+ struct.pack('<H', self.ss) \
+ struct.pack('<Q', self.err) \
+ struct.pack('<Q', self.trapno) \
+ struct.pack('<Q', self.oldmask) \
+ struct.pack('<Q', self.cr2) \
+ struct.pack('<Q', self.fpstate) \
+ struct.pack('<Q', self.reserved) \
+ struct.pack('<Q', self.siginfo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment