Skip to content

Commit

Permalink
fix: unexpected behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxilly committed May 8, 2021
1 parent 466d5b1 commit 4f8ae1c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 32 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,5 @@ dkms.conf


# Project exclude paths
/cmake-build-debug/
/cmake-build-wsl/
/cmake-build-ubuntu/
/cmake-build-*/

4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ include_directories("/usr/local/include")

add_executable(ua2f src/ua2f.c)
add_executable(test test/test.c)
add_executable(nf-queue src/nf-queue.c)
add_executable(nf-queue ref/nf-queue.c)
add_executable(clocktest test/clocktest.c)
add_executable(nfct-event src/nfct-event.c)
add_executable(nfct-event ref/nfct-event.c)
add_executable(nfq test/nfq.c)

target_link_libraries(ua2f mnl netfilter_queue ipset)
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=UA2F
PKG_VERSION:=3.6
PKG_VERSION:=3.7

PKG_RELEASE:=9
PKG_RELEASE:=10


PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
Expand Down
File renamed without changes.
File renamed without changes.
45 changes: 20 additions & 25 deletions src/ua2f.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <time.h>
#include <wait.h>
Expand All @@ -35,12 +36,10 @@ static struct mnl_socket *nl;
static const int queue_number = 10010;

static long long UAcount = 0;
//static long long httpnouacount = 0;
static long long tcpcount = 0;
static long long UAmark = 0;
static long long noUAmark = 0;
static long long oldhttpcount = 4;
//static long long http1_0count = 0;

static time_t start_t, current_t;

Expand Down Expand Up @@ -183,7 +182,6 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data) {
nfg = mnl_nlmsg_get_payload(nlh);

if (attr[NFQA_PACKET_HDR] == NULL) {
// fputs("metaheader not set\n", stderr);
syslog(LOG_ERR, "metaheader not set");
return MNL_CB_ERROR;
}
Expand Down Expand Up @@ -263,47 +261,44 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data) {
char *uapointer = memmem(tcppkpayload, tcppklen, "\r\nUser", 6);
if (uapointer) {
uapointer = memmem(tcppkpayload, tcppklen, "\r\nUser-Agent:", 13);
if (!uapointer){
if (!uapointer) {
uapointer = memmem(tcppkpayload, tcppklen, "\r\nUser-agent:", 13);
}
} else {
uapointer = memmem(tcppkpayload, tcppklen, "\r\nuser-agent:", 13);
}

if (uapointer) {
debugflag++; //flag5
uaoffset = uapointer - tcppkpayload + 14;

debugflag++; //flag6
if (uaoffset >= tcppklen) {
syslog(LOG_WARNING, "Offset overflow");
pktb_free(pktb);
return MNL_CB_OK;
}

uaoffset = uapointer - tcppkpayload + 14;
for (int i = 0; i < tcppklen - uaoffset - 2; ++i) {
if (*(uapointer + 14 + i) == '\r') {
ualength = i;
break;
}
}

debugflag++; //flag7

if (uaoffset && ualength) {
if (ualength + uaoffset > tcppklen) {
syslog(LOG_WARNING, "UA overflow");
pktb_free(pktb);
return MNL_CB_OK;
}

if (uaoffset >= tcppklen) {
syslog(LOG_ERR, "Offset overflow");
exit(EXIT_FAILURE);
}
if (ualength >= tcppklen) {
syslog(LOG_ERR, "UA overflow");
exit(EXIT_FAILURE);
}
if (nfq_tcp_mangle_ipv4(pktb, uaoffset, ualength, str, ualength) == 1) {
UAcount++; //记录修改包的数量
noUA = false;
} else {
pktb_free(pktb);
return MNL_CB_ERROR;
}
if (nfq_tcp_mangle_ipv4(pktb, uaoffset, ualength, str, ualength) == 1) {
UAcount++; //记录修改包的数量
noUA = false;
} else {
pktb_free(pktb);
return MNL_CB_ERROR;
}


debugflag++; //flag8
} else {
noUA = true;
Expand Down

0 comments on commit 4f8ae1c

Please sign in to comment.