87 lines
2.0 KiB
Org Mode
87 lines
2.0 KiB
Org Mode
* TCP - BAck to School
|
|
|
|
Challenge: https://www.root-me.org/de/Herausforderungen/Programmierung/TCP-Back-to-school
|
|
|
|
Aufgabe
|
|
|
|
Um diesen Test mit dem TCP-Protokoll zu starten, müssen Sie eine Verbindung zu einem Programm an einem Netzwerk-Socket herstellen.
|
|
|
|
- Berechne die Quadratwurzel aus Nummer 1 und multipliziere sie mit Nummer 2.
|
|
- Runden Sie dann das Ergebnis auf zwei Dezimalstellen ab.
|
|
- Sie haben 2 Sekunden Zeit, um die richtige Antwort zu senden, sobald das Programm Ihnen die Berechnung sendet.
|
|
|
|
Zugangsdaten für die Übung
|
|
|
|
Host challenge01.root-me.org
|
|
Protokoll TCP
|
|
Port 52002
|
|
|
|
---------
|
|
|
|
#+begin_src sh :results output
|
|
cat ./main.py
|
|
#+end_src
|
|
|
|
#+RESULTS:
|
|
#+begin_example
|
|
import math
|
|
import re
|
|
import socket
|
|
import time
|
|
|
|
|
|
HOST = "challenge01.root-me.org"
|
|
PORT = 52002
|
|
|
|
|
|
def solve_prompt(prompt: str) -> str:
|
|
match = re.search(
|
|
r"square root of\s*(\d+)\s*and multiply by\s*(\d+)",
|
|
prompt,
|
|
re.IGNORECASE,
|
|
)
|
|
if not match:
|
|
raise ValueError("Unsupported challenge prompt")
|
|
|
|
left = int(match.group(1))
|
|
right = int(match.group(2))
|
|
return f"{math.sqrt(left) * right:.2f}"
|
|
|
|
|
|
def main() -> None:
|
|
conn = socket.create_connection((HOST, PORT), timeout=2)
|
|
start_time = time.monotonic()
|
|
try:
|
|
prompt = conn.recv(4096).decode(errors="replace")
|
|
print(prompt, end="")
|
|
|
|
answer = solve_prompt(prompt)
|
|
conn.sendall((answer + "\n").encode())
|
|
|
|
result = conn.recv(4096).decode(errors="replace")
|
|
print(result, end="")
|
|
finally:
|
|
conn.close()
|
|
elapsed = time.monotonic() - start_time
|
|
print(f"\nConnection lifetime: {elapsed:.3f}s")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
#+end_example
|
|
|
|
#+begin_src sh :results output
|
|
python3 ./main.py
|
|
#+end_src
|
|
|
|
#+RESULTS:
|
|
:
|
|
: ====================
|
|
: GO BACK TO COLLEGE
|
|
: ====================
|
|
: You should tell me the answer of this math operation in less than 2 seconds !
|
|
:
|
|
: Calculate the square root of 535 and multiply by 2447 = [+] Good job ! Here is your flag: RM{TCP_C0nnecT_4nD_m4Th}
|
|
:
|
|
: Connection lifetime: 0.408s
|