netcat/nc/telnet은 수신된 데이터에 대해 수학적 연산을 수행한 다음 출력합니다.

netcat/nc/telnet은 수신된 데이터에 대해 수학적 연산을 수행한 다음 출력합니다.

저는 bash 전문가가 아니므로 미리 죄송합니다. 고등학교 CTF 대회에서는 3개의 숫자를 읽고 그에 대해 연산을 수행한 다음 그 값을 다시 서버에 출력해야 합니다.

의사코드에서는 다음과 같습니다.

connect to service
receive 17 bytes
parse 3 nums out of bytes
solution = num1 * num2 / num3
send solution
receive secret_message (if fast enough)

그런데 연결하는 순간 타이머가 시작되고 0.1초 안에 솔루션을 보내게 됩니다.

Python 스크립트를 사용하려는 첫 번째 시도는 꽤 가까워졌습니다.

import socket
from timeit import default_timer

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.connect(("services.cyberprotection.agency", 9999))
t = default_timer()
data = s.recv(17)
print(data)
l = data.split(b"\n")
solution = int(int(l[0]) * int(l[1]) / int(l[2]))
s.sendall(bytes(solution) + b"\n")
t2 = default_timer() - t
print("Too slow by ", round(t2 - 0.1, 4), "seconds")
secret_message = s.recv(128)
print(secret_message)
$ python3 connect.py
b'66044\n50899\n49665\n'
Too slow by  0.0239 seconds

내 요구에 맞게 충분히 빠른 쉘 스크립트를 통해 이 작업을 수행할 수 있는 방법이 있다고 생각합니다.

netcat 출력을 스크립트로 파이프한 다음 다시 netcat으로 파이프하려면 어떻게 해야 합니까?

netcat의 출력을 다른 스크립트로 파이프한 다음 다시 netcat으로 파이프하는 방법을 잘 모르겠습니다.

netcat services.cyberprotection.agency 9999 > out.txt
netcat services.cyberprotection.agency 9999 | somemagic | somehow_back_to_netcat

다음을 사용하여 연결했습니다.

  • 인터넷 고양이
  • CNC
  • 원격 로그인

따라서 이러한 도구는 모두 작동합니다.

이 SE 링크는 유용해 보이지만 어떻게 반환합니까?netcat에서 받은 데이터를 매개변수로 다른 스크립트에 전달하는 방법은 무엇입니까?

exec 3<>/dev/tcp/services.cyberprotection.agency/9999
start=`date +%s.%N`
out="$(head -3 <&3)"
out2="$out"
array=($out2)
var=$((array[0]*array[1]/array[2]))
echo $var >&3
end=`date +%s.%N`
slowtime=$( echo "$end - $start - 0.1" | bc -l )
echo "$slowtime too slow"

답변이 있지만 여전히 너무 느립니다.

답변1

알고 보니 제한 요인은 내 컴퓨터가 아니라 인터넷이었습니다.

exec 3<>/dev/tcp/services.cyberprotection.agency/9999
out="$(head -3 <&3)"
out2="$out"
array=($out2)
var=$((array[0]*array[1]/array[2]))
echo $var >&3
# Now get secret message
cat <&3

관련 정보