mirror of
https://github.com/hufrea/byedpi.git
synced 2024-12-22 14:25:44 +00:00
Get family by address, accept4
This commit is contained in:
parent
4b48ba353f
commit
8bba9ee3eb
61
desync.c
61
desync.c
@ -27,17 +27,32 @@
|
|||||||
#include <packets.h>
|
#include <packets.h>
|
||||||
|
|
||||||
|
|
||||||
|
static inline int get_family(struct sockaddr *dst)
|
||||||
|
{
|
||||||
|
if (dst->sa_family == AF_INET6) {
|
||||||
|
struct sockaddr_in6 *d6 = (struct sockaddr_in6 *)dst;
|
||||||
|
static char *pat = "\0\0\0\0\0\0\0\0\0\0\xff\xff";
|
||||||
|
|
||||||
|
if (!memcmp(&d6->sin6_addr, pat, 12)) {
|
||||||
|
return AF_INET;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dst->sa_family;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int setttl(int fd, int ttl, int family) {
|
int setttl(int fd, int ttl, int family) {
|
||||||
int _ttl = ttl;
|
int _ttl = ttl;
|
||||||
|
|
||||||
if (family == AF_INET) {
|
if (family == AF_INET) {
|
||||||
if (setsockopt(fd, IPPROTO_IP, IP_TTL,
|
if (setsockopt(fd, IPPROTO_IP,
|
||||||
&_ttl, sizeof(_ttl)) < 0) {
|
IP_TTL, &_ttl, sizeof(_ttl)) < 0) {
|
||||||
perror("setsockopt IP_TTL");
|
perror("setsockopt IP_TTL");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS,
|
else if (setsockopt(fd, IPPROTO_IPV6,
|
||||||
&_ttl, sizeof(_ttl)) < 0) {
|
IPV6_UNICAST_HOPS, &_ttl, sizeof(_ttl)) < 0) {
|
||||||
perror("setsockopt IPV6_UNICAST_HOPS");
|
perror("setsockopt IPV6_UNICAST_HOPS");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -45,7 +60,8 @@ int setttl(int fd, int ttl, int family) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int fake_attack(int sfd, char *buffer, ssize_t n, int cnt, int pos, int fa)
|
int fake_attack(int sfd, char *buffer,
|
||||||
|
size_t n, int cnt, int pos, int fa)
|
||||||
{
|
{
|
||||||
struct packet pkt = cnt != IS_HTTP ? fake_tls : fake_http;
|
struct packet pkt = cnt != IS_HTTP ? fake_tls : fake_http;
|
||||||
size_t psz = pkt.size;
|
size_t psz = pkt.size;
|
||||||
@ -98,7 +114,8 @@ int fake_attack(int sfd, char *buffer, ssize_t n, int cnt, int pos, int fa)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int disorder_attack(int sfd, char *buffer, ssize_t n, int pos, int fa)
|
int disorder_attack(int sfd, char *buffer,
|
||||||
|
ssize_t n, int pos, int fa)
|
||||||
{
|
{
|
||||||
int bttl = 1;
|
int bttl = 1;
|
||||||
if (setttl(sfd, bttl, fa) < 0) {
|
if (setttl(sfd, bttl, fa) < 0) {
|
||||||
@ -125,7 +142,7 @@ int desync(int sfd, char *buffer,
|
|||||||
int pos = params.split;
|
int pos = params.split;
|
||||||
char *host = 0;
|
char *host = 0;
|
||||||
int len = 0, type = 0;
|
int len = 0, type = 0;
|
||||||
int fa = dst->sa_family;
|
int fa = get_family(dst);
|
||||||
|
|
||||||
if ((len = parse_tls(buffer, n, &host))) {
|
if ((len = parse_tls(buffer, n, &host))) {
|
||||||
type = IS_HTTPS;
|
type = IS_HTTPS;
|
||||||
@ -141,11 +158,12 @@ int desync(int sfd, char *buffer,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (host && params.split_host)
|
if (host && params.split_host) {
|
||||||
pos += (host - buffer);
|
pos += (host - buffer);
|
||||||
else if (pos < 0)
|
}
|
||||||
|
else if (pos < 0) {
|
||||||
pos += n;
|
pos += n;
|
||||||
|
}
|
||||||
LOG(LOG_L, "split pos: %d, n: %ld\n", pos, n);
|
LOG(LOG_L, "split pos: %d, n: %ld\n", pos, n);
|
||||||
|
|
||||||
if (pos <= 0 || pos >= n ||
|
if (pos <= 0 || pos >= n ||
|
||||||
@ -180,31 +198,26 @@ int desync(int sfd, char *buffer,
|
|||||||
|
|
||||||
|
|
||||||
int desync_udp(int fd, char *buffer,
|
int desync_udp(int fd, char *buffer,
|
||||||
ssize_t n, struct sockaddr_in6 *dst)
|
ssize_t n, struct sockaddr *dst)
|
||||||
{
|
{
|
||||||
char is_mv4 = 1;
|
int fa = get_family(dst);
|
||||||
|
socklen_t s = dst->sa_family == AF_INET6 ?
|
||||||
|
sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in);
|
||||||
|
|
||||||
if (dst->sin6_family == AF_INET6) {
|
|
||||||
static char *pat = "\0\0\0\0\0\0\0\0\0\0\xff\xff";
|
|
||||||
is_mv4 = !memcmp(&dst->sin6_addr, pat, 12);
|
|
||||||
}
|
|
||||||
if (params.desync_udp & DESYNC_UDP_FAKE) {
|
if (params.desync_udp & DESYNC_UDP_FAKE) {
|
||||||
if (setttl(fd, params.ttl,
|
if (setttl(fd, params.ttl, fa) < 0) {
|
||||||
is_mv4 ? AF_INET : dst->sin6_family) < 0) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (sendto(fd, fake_udp.data, fake_udp.size,
|
if (sendto(fd, fake_udp.data,
|
||||||
0, (struct sockaddr *)dst, sizeof(*dst)) < 0) {
|
fake_udp.size, 0, dst, s) < 0) {
|
||||||
perror("sendto");
|
perror("sendto");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (setttl(fd, params.def_ttl,
|
if (setttl(fd, params.def_ttl, fa) < 0) {
|
||||||
is_mv4 ? AF_INET : dst->sin6_family) < 0) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ssize_t ns = sendto(fd,
|
ssize_t ns = sendto(fd, buffer, n, 0, dst, s);
|
||||||
buffer, n, 0, (struct sockaddr *)dst, sizeof(*dst));
|
|
||||||
if (ns < 0) {
|
if (ns < 0) {
|
||||||
perror("sendto");
|
perror("sendto");
|
||||||
return -1;
|
return -1;
|
||||||
|
2
desync.h
2
desync.h
@ -1,2 +1,2 @@
|
|||||||
int desync(int sfd, char *buffer, ssize_t n, struct sockaddr *dst);
|
int desync(int sfd, char *buffer, ssize_t n, struct sockaddr *dst);
|
||||||
int desync_udp(int fd, char *buffer, ssize_t n, struct sockaddr_in6 *dst);
|
int desync_udp(int fd, char *buffer, ssize_t n, struct sockaddr *dst);
|
2
main.c
2
main.c
@ -13,7 +13,7 @@
|
|||||||
#include <proxy.h>
|
#include <proxy.h>
|
||||||
#include <packets.h>
|
#include <packets.h>
|
||||||
|
|
||||||
#define VERSION 1
|
#define VERSION 2
|
||||||
|
|
||||||
struct packet fake_tls = {
|
struct packet fake_tls = {
|
||||||
sizeof(tls_data), tls_data
|
sizeof(tls_data), tls_data
|
||||||
|
9
proxy.c
9
proxy.c
@ -461,18 +461,24 @@ static inline int on_accept(struct poolhd *pool, struct eval *val)
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
socklen_t len = sizeof(client);
|
socklen_t len = sizeof(client);
|
||||||
|
#ifdef __linux__
|
||||||
|
int c = accept4(val->fd, &client.sa, &len, SOCK_NONBLOCK);
|
||||||
|
#else
|
||||||
int c = accept(val->fd, &client.sa, &len);
|
int c = accept(val->fd, &client.sa, &len);
|
||||||
|
#endif
|
||||||
if (c < 0) {
|
if (c < 0) {
|
||||||
if (errno == EAGAIN)
|
if (errno == EAGAIN)
|
||||||
break;
|
break;
|
||||||
perror("accept");
|
perror("accept");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#ifndef __linux__
|
||||||
if (fcntl(c, F_SETFL, O_NONBLOCK) < 0) {
|
if (fcntl(c, F_SETFL, O_NONBLOCK) < 0) {
|
||||||
perror("fcntl");
|
perror("fcntl");
|
||||||
close(c);
|
close(c);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
int one = 1;
|
int one = 1;
|
||||||
if (setsockopt(c, IPPROTO_TCP,
|
if (setsockopt(c, IPPROTO_TCP,
|
||||||
TCP_NODELAY, (char *)&one, sizeof(one))) {
|
TCP_NODELAY, (char *)&one, sizeof(one))) {
|
||||||
@ -641,11 +647,12 @@ int on_udp_tunnel(struct eval *val, char *buffer, size_t bfsize)
|
|||||||
buffer + skip + offs, n - offs, 0, &addr.sa, asz);
|
buffer + skip + offs, n - offs, 0, &addr.sa, asz);
|
||||||
else {
|
else {
|
||||||
ns = desync_udp(val->fd,
|
ns = desync_udp(val->fd,
|
||||||
buffer + skip + offs, n - offs, &addr.in6);
|
buffer + skip + offs, n - offs, &addr.sa);
|
||||||
val->flag |= FLAG_CONN;
|
val->flag |= FLAG_CONN;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
map_fix(&addr, 0);
|
map_fix(&addr, 0);
|
||||||
|
|
||||||
offs = s_set_addr(buffer + skip, skip, &addr, 1);
|
offs = s_set_addr(buffer + skip, skip, &addr, 1);
|
||||||
if (offs < 0 || offs > skip) {
|
if (offs < 0 || offs > skip) {
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user