【发布时间】:2020-09-25 02:32:21
【问题描述】:
主机: 45.77.245.244
端口: 5006
它是 CTF 挑战赛的主持人。但是我不需要解决它。我想在 python 中自动化它。
连接到服务器时。服务器将返回 2 条消息
1:编程.....
2:n =? \NAnwser:
并听取用户输入的答案。
Netcat:
toor@MSI:~$ nc 45.77.245.244 5006
PROGRAMING - WHITEHAT 2019:
--> Coungting the triangles <--
HOW MANY TRIANGLE IS CREATED BY N (1..N) NUMBER. N < 10^6
Example: with N = 5
OUTPUT : 3
(2,3,4),(3,4,5),(2,4,5)
................/\...................|\...................
.............../ \..................| \..................
............../ \.................| \.................
............./ \................| \................
............/ \...............| \...............
.........../ \..............| \..............
........../____________\.............|______\.............
n = 99
Answer: 4
Wrong answer. I can't trust you anymore :'<
我编写了一段代码,它连接并返回“n”并返回所需的结果:Wrong answer. I can't trust you anymore: '<
我的 Python 代码:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('45.77.245.244', 5006))
print('Server:', str(s.recv(1024)))
while True:
data = s.recv(1024).strip()
if data:
data = str(data)
print('Server:', data)
n = ''.join([i for i in data if i.isdigit()])
n = bytes(n, 'ascii')
s.send(n)
print('Client: ', n)
s.close()
输出:
Server: b'\nPROGRAMING - WHITEHAT 2019:\n\n--> Coungting the triangles <--\n\nHOW MANY TRIANGLE IS CREATED BY N (1..N) NUMBER. N < 10^6\n\nExample: with N = 5\nOUTPUT : 3 \n\n(2,3,4),(3,4,5),(2,4,5)\n................/\\...................|\\...................\n.............../ \\..................| \\..................\n............../ \\.................| \\.................\n............./ \\................| \\................\n............/ \\...............| \\...............\n.........../ \\..............| \\..............\n........../____________\\.............|______\\.............\n\t\n'
Server: b'n = 25\nAnswer:'
Client: b'25'
在send(n)和print('send:', n)确保发送成功后,使用netcat时没有得到我想要的输出。
输出:Wrong answer. I can't trust you anymore :'<
我哪里做错了?有办法解决吗?
【问题讨论】:
标签: python sockets networking netcat