--fake on Windows

This commit is contained in:
ruti 2024-03-18 02:23:10 +03:00
parent 6b39efdd7a
commit 3da60eb357
5 changed files with 103 additions and 9 deletions

View File

@ -7,7 +7,7 @@ all:
$(CC) $(CFLAGS) $(SOURCES) -I . -o $(TARGET) $(CC) $(CFLAGS) $(SOURCES) -I . -o $(TARGET)
windows: windows:
$(CC) $(CFLAGS) $(SOURCES) -I . -lws2_32 -o $(TARGET).exe $(CC) $(CFLAGS) $(SOURCES) -I . -lws2_32 -lmswsock -o $(TARGET).exe
clean: clean:
rm -f $(TARGET) *.o rm -f $(TARGET) *.o

View File

@ -24,6 +24,7 @@
#include <winsock2.h> #include <winsock2.h>
#include <windows.h> #include <windows.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#include <mswsock.h>
#endif #endif
#include <params.h> #include <params.h>
@ -124,6 +125,100 @@ int send_fake(int sfd, char *buffer,
} }
#endif #endif
#ifdef _WIN32
int send_fake(int sfd, char *buffer,
int cnt, long pos, int fa, int ttl)
{
struct packet pkt = cnt != IS_HTTP ? fake_tls : fake_http;
size_t psz = pkt.size;
char path[MAX_PATH + 1];
int ps = GetTempPath(sizeof(path), path);
if (!ps) {
uniperror("GetTempPath");
return -1;
}
if (!GetTempFileName(path, "t", 0, path)) {
uniperror("GetTempFileName");
return -1;
}
LOG(LOG_L, "temp file: %s\n", path);
HANDLE hfile = CreateFileA(path, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hfile == INVALID_HANDLE_VALUE) {
uniperror("CreateFileA");
return -1;
}
OVERLAPPED ov = {};
int status = -1;
while (status) {
ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!ov.hEvent) {
uniperror("CreateEvent");
break;
}
if (!WriteFile(hfile, pkt.data, psz < pos ? psz : pos, 0, 0)) {
uniperror("WriteFile");
break;
}
if (psz < pos) {
if (SetFilePointer(hfile, pos, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
uniperror("SetFilePointer");
break;
}
if (!SetEndOfFile(hfile)) {
uniperror("SetFileEnd");
break;
}
}
if (SetFilePointer(hfile, 0, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
uniperror("SetFilePointer");
break;
}
if (setttl(sfd, ttl, fa) < 0) {
break;
}
if (!TransmitFile(sfd, hfile, pos, pos, &ov,
NULL, TF_USE_KERNEL_APC | TF_WRITE_BEHIND)) {
if ((GetLastError() != ERROR_IO_PENDING)
&& (WSAGetLastError() != WSA_IO_PENDING)) {
uniperror("TransmitFile");
break;
}
}
delay(params.sfdelay);
if (SetFilePointer(hfile, 0, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
uniperror("SetFilePointer");
break;
}
if (!WriteFile(hfile, buffer, pos, 0, 0)) {
uniperror("WriteFile");
break;
}
if (setttl(sfd, params.def_ttl, fa) < 0) {
break;
}
status = 0;
}
if (!CloseHandle(hfile)) {
uniperror("CloseHandle hfile");
}
if (!CloseHandle(ov.hEvent)) {
uniperror("CloseHandle hEvent");
}
if (!DeleteFile(path)) {
uniperror("DeleteFile");
}
return status;
}
#endif
int send_oob(int sfd, char *buffer, int send_oob(int sfd, char *buffer,
ssize_t n, long pos) ssize_t n, long pos)
{ {
@ -263,7 +358,7 @@ int desync(int sfd, char *buffer, size_t bfsize,
int s = 0; int s = 0;
switch (part.m) { switch (part.m) {
#ifdef __linux__ #ifdef FAKE_SUPPORT
case DESYNC_FAKE: case DESYNC_FAKE:
s = send_fake(sfd, s = send_fake(sfd,
buffer + lp, type, pos - lp, fa, dp.ttl ? dp.ttl : 8); buffer + lp, type, pos - lp, fa, dp.ttl ? dp.ttl : 8);

6
main.c
View File

@ -16,15 +16,9 @@
#include <unistd.h> #include <unistd.h>
#include <netdb.h> #include <netdb.h>
#include <fcntl.h> #include <fcntl.h>
#ifdef __linux__
#define FAKE_SUPPORT 1
#define TIMEOUT_SUPPORT 1
#endif
#else #else
#include <ws2tcpip.h> #include <ws2tcpip.h>
#define close(fd) closesocket(fd) #define close(fd) closesocket(fd)
#define TIMEOUT_SUPPORT 1
#endif #endif
#define VERSION 6 #define VERSION 6

View File

@ -7,6 +7,11 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#endif #endif
#if defined(__linux__) || defined(_WIN32)
#define FAKE_SUPPORT 1
#define TIMEOUT_SUPPORT 1
#endif
#define OFFSET_SNI 1 #define OFFSET_SNI 1
#define OFFSET_HOST 2 #define OFFSET_HOST 2