最近了解了Port Knocking的概念。可以使用跟踪打开和关闭客户端连接的持续时间而不是打开端口吗?例如,发送 SOS(…………)
- 打开 3 个连接 100 毫秒:...
- 打开 3 个连接 300 毫秒:---
- 打开 3 个连接 100 毫秒:...
MSVC 示例
// Morse Knocking - Connection Duration: 100ms = dot, 300ms = dash.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#pragma comment (lib, "Ws2_32.lib")
#pragma warning(disable : 4996)
#define dot 100
#define dash 300
int __cdecl main(int argc, char** argv)
{
SOCKET client_socket;
const int SIZE = 3;
// Morse code distress signal ...---...
char morse[SIZE] = { 'S', 'O', 'S'};
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);
struct sockaddr_in server;
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons(80);
server.sin_addr.s_addr = inet_addr("127.0.0.1");
for (int i = 0; i < SIZE; i++)
{
switch (morse[i])
{
case 'S':
for (int j = 0; i < 3; j++)
{
client_socket = socket(AF_INET, SOCK_STREAM, 0);
connect(client_socket, (struct sockaddr*)&server, sizeof server);
Sleep(dot);
closesocket(client_socket);
}
case 'O':
for (int j = 0; j < 3; j++)
{
client_socket = socket(AF_INET, SOCK_STREAM, 0);
connect(client_socket, (struct sockaddr*)&server, sizeof server);
Sleep(dash);
closesocket(client_socket);
}
default:
exit(0);
}
}
return 0;
}