generated from sigpwny/ctf-chal-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
4 changed files
with
101 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,40 @@ | ||
from pwn import * | ||
import sympy as sp | ||
|
||
def main(): | ||
|
||
res = 18669237451167230340 | ||
conn = remote("chal.cryptoctf.sigpwny.com", 5001) | ||
|
||
conn.recvline() # [D] Welcome | ||
conn.recvline() # [D] Define a 3 x 3 Integer Matrix M | ||
|
||
# Send matrix | ||
conn.sendline(b'1') | ||
conn.sendline(b'1') | ||
conn.sendline(b'1') | ||
conn.sendline(b'0') | ||
conn.sendline(b'1') | ||
conn.sendline(b'1') | ||
conn.sendline(b'0') | ||
conn.sendline(b'0') | ||
conn.sendline(b'1') | ||
|
||
conn.recvline() | ||
# Here is number the server gives | ||
res = int(conn.recvline().decode("utf-8")[13:].strip()) | ||
conn.recvline() | ||
print(f"Challenge Accepted: {res}") | ||
|
||
# Some solutions | ||
disc = (25 - 4 * (6 - 2*int(res)))**(0.5) | ||
sec_ = (-5 + disc) // 2 | ||
print(int(sec_)) | ||
# TODO: Put some writing in here | ||
# disc = (25 - 4 * (6 - 2*int(res)))**(0.5) | ||
# secret = (-5 + disc) // 2 | ||
|
||
n = sp.Symbol('n') | ||
print(sp.solve(3 + 2*n + (n**2 + n) / 2 - res, n)[1]) | ||
|
||
secret = sp.solve(3 + 2*n + (n**2 + n) / 2 - res, n)[1] | ||
|
||
conn.sendline(str(int(secret)).encode()) # Send answer | ||
print(conn.recvline().decode("utf-8")[22:].strip()) # Print flag | ||
|
||
if __name__ == "__main__": | ||
main() |
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,53 @@ | ||
from pwn import * | ||
|
||
def main(): | ||
|
||
# Here is some starter code for those unfamiliar with pwntools | ||
# I am not good at pwntools, so there may be better ways to do this | ||
# But this is how I know how to do things | ||
|
||
# Connect to remote server | ||
conn = remote("chal.cryptoctf.sigpwny.com", 5001) | ||
|
||
conn.recvline() # [D] Welcome | ||
conn.recvline() # [D] Define a 3 x 3 Integer Matrix M | ||
|
||
# Send matrix here | ||
# Replace the 0/1's with the numbers you want | ||
conn.sendline(b'1') | ||
conn.sendline(b'0') | ||
conn.sendline(b'0') | ||
conn.sendline(b'0') | ||
conn.sendline(b'1') | ||
conn.sendline(b'0') | ||
conn.sendline(b'0') | ||
conn.sendline(b'0') | ||
conn.sendline(b'1') | ||
|
||
conn.recvline() | ||
# Here is number the server gives | ||
res = int(conn.recvline().decode("utf-8")[13:].strip()) | ||
print(f"Challenge Accepted: {res}") | ||
|
||
|
||
# TODO: Write some code to recover the secret from res! | ||
# | ||
# Bytes: | ||
# pwntools reads and sends bytes | ||
# .encode turns a string into a bytestring | ||
# .decode("utf-8") turns a bytestring into a string | ||
# | ||
# Sending and Receiving: | ||
# conn.sendline(b'#') | ||
# output = conn.recvline() | ||
# These do what you think | ||
# | ||
# Some basic string manipulation such as .strip() and slicing helps | ||
# Use alot of print statements in debugging this | ||
# Try some stuff locally as well | ||
# Have a working local solution *before* pwntools-ifying it | ||
# | ||
# pwntools is really useful, I recommend you learn it | ||
|
||
if __name__ == "__main__": | ||
main() |