Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ctf-re
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GovanifY
ctf-re
Commits
388b2519
Commit
388b2519
authored
5 years ago
by
GovanifY
Browse files
Options
Downloads
Patches
Plain Diff
simple_rop_2 is fixed in a hacky way
parent
4355b0ad
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
chals/simple_rop_2/setup.py
+47
-35
47 additions, 35 deletions
chals/simple_rop_2/setup.py
libchals.py
+20
-2
20 additions, 2 deletions
libchals.py
with
67 additions
and
37 deletions
chals/simple_rop_2/setup.py
+
47
−
35
View file @
388b2519
...
...
@@ -3,14 +3,16 @@ import os
import
sys
# chals_out/chal_name/team_name so 3
sys
.
path
.
insert
(
1
,
os
.
path
.
join
(
sys
.
path
[
0
],
'
../../..
'
))
from
libchals
import
*
from
pwn
import
*
import
shutil
from
libchals
import
write_junk_calls
,
write_junk_body
,
fail_test
from
pwn
import
context
,
ELF
,
ROP
,
p64
context
.
log_level
=
'
error
'
FNULL
=
open
(
os
.
devnull
,
'
w
'
)
def
make_binary
():
# junk code generation
write_junk_calls
(
"
main.c
"
,
31
,
2
)
write_junk_calls
(
"
main.c
"
,
31
,
2
,
reset
=
True
)
write_junk_calls
(
"
main.c
"
,
22
)
write_junk_body
(
"
main.c
"
,
16
)
...
...
@@ -18,7 +20,6 @@ subprocess.call("make", stdout=FNULL, stderr=FNULL)
from
pwn
import
*
# input correction
elf
=
ELF
(
"
simple_rop_2
"
)
rop
=
ROP
(
elf
)
...
...
@@ -48,10 +49,21 @@ try:
except
Exception
as
e
:
output
=
str
(
e
.
output
)
if
not
flag
in
output
:
fail_test
()
return
-
1
else
:
return
0
while
True
:
shutil
.
copy
(
"
main.c
"
,
"
main.c.org
"
)
if
(
make_binary
()
==
0
):
break
else
:
#fail_test()
# unstable binary simple_rop_2, retrying entropy until
# rng jesus is happy
shutil
.
copy
(
"
main.c.org
"
,
"
main.c
"
)
os
.
remove
(
"
main.c
"
)
os
.
remove
(
"
main.c.org
"
)
os
.
remove
(
"
Makefile
"
)
os
.
remove
(
"
setup.py
"
)
# solution
...
...
This diff is collapsed.
Click to expand it.
libchals.py
+
20
−
2
View file @
388b2519
...
...
@@ -10,7 +10,10 @@ Some limitations:
You must write junk code from bottom to top, aka first junk calls,
then junk definition, from the bottom up.
"""
HASH_ROUND
=-
1
def
rng
(
index
):
global
HASH_ROUND
BUF_SIZE
=
65536
sha2
=
hashlib
.
sha256
()
...
...
@@ -21,6 +24,8 @@ def rng(index):
break
sha2
.
update
(
data
)
hash_final
=
bytes
.
fromhex
(
sha2
.
hexdigest
())
for
i
in
range
(
0
,
HASH_ROUND
):
hash_final
=
bytes
.
fromhex
(
hashlib
.
sha256
(
hash_final
).
hexdigest
())
rng
=
hash_final
[
index
]
return
rng
...
...
@@ -226,7 +231,14 @@ VAR_NAME=(VAR_NAME/VAR_NAME)*2;
fun_names
=
[]
junk_called
=
0
def
write_junk_body
(
fd
,
line
):
def
write_junk_body
(
fd
,
line
,
reset
=
False
):
global
junk_called
global
fun_names
global
HASH_ROUND
if
(
reset
==
True
):
fun_names
=
[]
junk_called
=
0
HASH_ROUND
+=
1
# junk generator!!
dont_gen_name
=
False
junk_count
=
rng
(
0
)
%
len
(
junk
)
...
...
@@ -240,9 +252,15 @@ def write_junk_body(fd, line):
write_line
(
fd
,
line
,
junk
[
junk_to_add
].
replace
(
"
FUNCTION_NAME
"
,
fun_names
[
i
]))
def
write_junk_calls
(
fd
,
line
,
count
=-
1
):
def
write_junk_calls
(
fd
,
line
,
count
=-
1
,
reset
=
False
):
# junk generator!!
global
junk_called
global
fun_names
global
HASH_ROUND
if
(
reset
==
True
):
fun_names
=
[]
junk_called
=
0
HASH_ROUND
+=
1
junk_count
=
rng
(
0
)
%
len
(
junk
)
if
(
count
==-
1
):
count
=
junk_count
+
1
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment