Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
FAUST CTF 2024-04-27
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
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Stefan Gehr
FAUST CTF 2024-04-27
Commits
d70072f1
Commit
d70072f1
authored
1 year ago
by
david
Browse files
Options
Downloads
Patches
Plain Diff
3rd place winning commit
parent
a687a042
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
14-simpleexchange/client.py
+45
-0
45 additions, 0 deletions
14-simpleexchange/client.py
14-simpleexchange/dhexchange.py
+76
-0
76 additions, 0 deletions
14-simpleexchange/dhexchange.py
14-simpleexchange/flag.txt
+1
-0
1 addition, 0 deletions
14-simpleexchange/flag.txt
with
122 additions
and
0 deletions
14-simpleexchange/client.py
0 → 100644
+
45
−
0
View file @
d70072f1
#!/usr/bin/env python3
import
os
import
os.path
import
binascii
import
struct
import
hashlib
import
nclib
from
Crypto.Cipher
import
AES
from
Crypto.Util
import
Counter
from
Crypto
import
Random
nc
=
nclib
.
Netcat
((
'
workshop.faust.ninja
'
,
4241
))
#nc = nclib.Netcat(('localhost', 4241))
GROUP
=
28397751449611216856386152638704604893488016313021502645659640564689451285800984155346815239241212742250655876089753350891224226779660824735763769557687726166165224298016395911925566755062763818543701251112002337015420084071010338008840472534822459206106749211685814760944931574993226097212282111892063291339967344156771005250401211439632092364480222950969327623561587999071614346278120140894679593229940805561670584035225683287173673586166594382681326751471027116669859298597550318710320232871945120064041229923641516885877410465715453160092930760459475437352839750812216596284639932989271762184684269796196987536123
GENERATOR
=
2
my_secret
=
int
(
binascii
.
hexlify
(
Random
.
get_random_bytes
(
32
)),
16
)
gy
=
pow
(
GENERATOR
,
my_secret
,
GROUP
)
print
(
"
Sending
"
)
print
(
b
"
%i
\n
"
%
gy
)
nc
.
sendall
(
b
"
%i
\n
"
%
gy
)
print
(
"
Receiving
"
)
result
=
nc
.
recv
(
1024
).
strip
()
gx
=
result
gx
=
int
(
gx
,
16
)
print
(
gx
)
gxy
=
pow
(
gx
,
my_secret
,
GROUP
)
key
=
hashlib
.
sha256
(
b
"
%x
"
%
gxy
).
digest
()
response
=
binascii
.
unhexlify
(
nc
.
recv
().
strip
())
iv
=
response
[:
12
]
cipher
=
response
[
12
:]
print
(
iv
)
print
(
cipher
)
print
(
"
key
"
)
print
(
gxy
)
aesthing
=
AES
.
new
(
key
,
AES
.
MODE_CTR
,
counter
=
Counter
.
new
(
32
,
prefix
=
iv
))
print
(
aesthing
.
decrypt
(
cipher
))
This diff is collapsed.
Click to expand it.
14-simpleexchange/dhexchange.py
0 → 100644
+
76
−
0
View file @
d70072f1
#!/usr/bin/env python3
import
socketserver
from
socket
import
AF_INET6
import
os
import
os.path
import
binascii
import
struct
import
hashlib
from
Crypto.Cipher
import
AES
from
Crypto.Util
import
Counter
from
Crypto
import
Random
GROUP
=
28397751449611216856386152638704604893488016313021502645659640564689451285800984155346815239241212742250655876089753350891224226779660824735763769557687726166165224298016395911925566755062763818543701251112002337015420084071010338008840472534822459206106749211685814760944931574993226097212282111892063291339967344156771005250401211439632092364480222950969327623561587999071614346278120140894679593229940805561670584035225683287173673586166594382681326751471027116669859298597550318710320232871945120064041229923641516885877410465715453160092930760459475437352839750812216596284639932989271762184684269796196987536123
GENERATOR
=
2
class
ThreadedTCPServer
(
socketserver
.
ThreadingMixIn
,
socketserver
.
TCPServer
):
def
__init__
(
self
,
*
args
):
self
.
address_family
=
AF_INET6
self
.
allow_reuse_address
=
True
socketserver
.
TCPServer
.
__init__
(
self
,
*
args
)
def
server_activate
(
self
):
socketserver
.
TCPServer
.
server_activate
(
self
)
try
:
import
systemd.daemon
systemd
.
daemon
.
notify
(
'
READY=1
'
)
except
ImportError
:
pass
os
.
chdir
(
os
.
path
.
dirname
(
__file__
))
with
open
(
'
flag.txt
'
,
'
rb
'
)
as
flagfd
:
flag
=
flagfd
.
read
()
class
MyTCPHandler
(
socketserver
.
BaseRequestHandler
):
def
_key_exchange
(
self
):
gy_bytes
=
self
.
request
.
recv
(
1024
).
strip
()
print
(
gy_bytes
)
gy
=
int
(
gy_bytes
)
print
(
"
got gy
"
)
ephermal_secret
=
int
(
binascii
.
hexlify
(
Random
.
get_random_bytes
(
32
)),
16
)
gx
=
pow
(
GENERATOR
,
ephermal_secret
,
GROUP
)
print
(
"
gx
"
)
print
(
gx
)
self
.
request
.
sendall
(
b
"
%x
\n
"
%
gx
)
gxy
=
pow
(
gy
,
ephermal_secret
,
GROUP
)
print
(
"
gxy
"
)
print
(
gxy
)
return
hashlib
.
sha256
(
b
"
%x
"
%
gxy
).
digest
()
def
handle
(
self
):
print
(
"
handle
"
)
key
=
self
.
_key_exchange
()
iv
=
Random
.
get_random_bytes
(
12
)
cipher
=
AES
.
new
(
key
,
AES
.
MODE_CTR
,
counter
=
Counter
.
new
(
32
,
prefix
=
iv
))
self
.
request
.
sendall
(
binascii
.
hexlify
(
iv
+
cipher
.
encrypt
(
b
'
Your flag today is %s
'
%
flag
))
+
b
"
\n
"
)
if
__name__
==
"
__main__
"
:
HOST
,
PORT
=
"
::
"
,
4241
# Create the server
server
=
ThreadedTCPServer
((
HOST
,
PORT
),
MyTCPHandler
)
# Activate the server; this will keep running until you
# interrupt the program with Ctrl-C
server
.
serve_forever
()
This diff is collapsed.
Click to expand it.
14-simpleexchange/flag.txt
0 → 100644
+
1
−
0
View file @
d70072f1
flag{123}
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