-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
119 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <stdio.h> | ||
|
||
void segfault() { | ||
*(volatile int*)0 = 0; | ||
} | ||
|
||
int main() { | ||
printf("Hello, World!\n"); | ||
segfault(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from pyda import * | ||
from pwnlib.elf.elf import ELF | ||
from pwnlib.util.packing import u64 | ||
import string | ||
import sys, time | ||
|
||
p = process() | ||
|
||
e = ELF(p.exe_path) | ||
e.address = p.maps[p.exe_path].base | ||
|
||
excepted = False | ||
try: | ||
p.run() | ||
except FatalSignalError as err: | ||
assert err.args[0] is not None | ||
excepted = True | ||
|
||
assert excepted | ||
|
||
print("Exception 1") | ||
|
||
# Now, after the exception, redirect execution to main again | ||
p.regs.rip = e.symbols["main"] | ||
excepted = False | ||
try: | ||
p.run() | ||
except FatalSignalError as err: | ||
assert err.args[0] is not None | ||
excepted = True | ||
|
||
assert excepted | ||
|
||
print("Exception 2") | ||
|
||
# Finally, let's try calling out to the function as a callable | ||
excepted = False | ||
try: | ||
p.callable(e.symbols["segfault"])() | ||
except FatalSignalError as err: | ||
assert err.args[0] is not None | ||
excepted = True | ||
|
||
assert excepted | ||
|
||
print("Exception 3") | ||
|
||
p.regs.rsp += 0x18 | ||
p.regs.rip = e.symbols["main"] + 0x26 | ||
p.run() | ||
print("pass") |