Fix the problem that linked list inversion does not take effect.

This commit is contained in:
aixiao 2022-03-25 04:34:07 -03:00
parent 890afe93c8
commit 5e3b8d0194
6 changed files with 53 additions and 48 deletions

View File

@ -8,7 +8,7 @@ global {
}
http {
http_ip="2001:19f0:4401:2f:5400:3ff:fec4:e376";
http_ip="174.137.54.215";
http_port=129;
http_del="Host,";
http_first="[M] [U] [V]\r\nHost: [H]\r\n";
@ -21,13 +21,16 @@ http {
}
https {
https_ip="2001:19f0:4401:2f:5400:3ff:fec4:e376";
https_ip="174.137.54.215";
https_port=129;
https_del="Host,host,x-online-host";
https_first="[M] [U] [V]\r\nHost: [host]\r\n";
strrep="Windows NT 10.0" -> "Linux";
strrep="Linux" -> "aixiao.me";
strrep="aixiao.me" -> "AIXIAO.ME";
strrep="Windows NT 10.0" -> "aaaaaaaaaaaaaaaaaaa";
strrep="aaaaaaaaaaaaaaaaaaa" -> "bbbbbbbbbbbbbbbb";
strrep="bbbbbbbbbbbbbbbb" -> "cccccccccccccccccc";
strrep="cccccccccccccccccc" -> "ddddddddddddddddddddddd";
regrep="Host*.+?" -> "host: [host]:443";
regrep="host*.+?" -> "Host: [H]";
regrep="host*.+?" -> "Host: [host]";

View File

@ -17,7 +17,6 @@ http {
strrep="aixiao.me" -> "AIXIAO.ME";
regrep="Accept-Encoding*.+?" -> "Accept-Encoding: GZIP, deflate";
regrep="Connection*.+?" -> "Connection: KEEP-alive";
}
https {

View File

@ -23,8 +23,8 @@
## Help Information
CProxy proxy server
Author: aixiao@aixiao.me
C Proxy Server
Author: AIXIAO@AIXIAO.ME
Usage: [-?h] [-s signal] [-c filename]
Options:

View File

@ -544,6 +544,7 @@ static char *delete_head(char *head, const char *needle, int string)
static char *conf_handle_strrep(char *str, int str_len, tcp *temp)
{
tcp *p = temp;
while (p) {
if (p->strrep) {
str = replace(str, &str_len, p->strrep_s, p->strrep_s_len, p->strrep_t, p->strrep_t_len);
@ -613,10 +614,13 @@ char *request_head(conn_t * in, conf * configure)
splice_head(incomplete_head, "\n", configure->https_first);
incomplete_head_len = strlen(incomplete_head); // 更新HTTPS HEADER长度
incomplete_head = conf_handle_strrep(incomplete_head, incomplete_head_len, https_head_strrep);
incomplete_head_len = strlen(incomplete_head) + 1; // 更新HTTPS HEADER长度
incomplete_head = conf_handle_regrep(incomplete_head, incomplete_head_len, https_head_regrep);
incomplete_head_len = strlen(incomplete_head); // 更新HTTPS HEADER长度
incomplete_head = replace(incomplete_head, &incomplete_head_len, "[M]", 3, http_request->method, http_request->method_len);
incomplete_head = replace(incomplete_head, &incomplete_head_len, "[method]", 8, http_request->method, http_request->method_len);

View File

@ -71,12 +71,16 @@ static int createRspFd(info_t * client)
setsockopt(client->responseClientFd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
setsockopt(client->responseClientFd, SOL_IP, IP_TRANSPARENT, &opt, sizeof(opt));
//切换root伪装源目标地址
seteuid(0);
setegid(0);
if (-1 == seteuid(0))
perror("seteuid");
if (-1 == setegid(0))
perror("setegid");
bind(client->responseClientFd, (struct sockaddr *)&client->toaddr, sizeof(struct sockaddr_in));
//切换回用户设置的uid
setegid(global.uid);
seteuid(global.uid);
if (-1 == setegid(global.uid))
perror("setegid");
if (-1 == seteuid(global.uid))
perror("seteuid");
return 0;
}

65
main.c
View File

@ -29,7 +29,6 @@ int epollfd, server_sock, server_sock6, local_port, process;
conn_t cts[MAX_CONNECTION];
char local_host[CACHE_SIZE];
int create_server_socket(int port)
{
int server_sock;
@ -235,7 +234,7 @@ int process_signal(int signal, char *process_name)
DIR *dir;
struct dirent *ptr;
pid_t self_pid;
self_pid = getpid();
dir = opendir("/proc");
bzero(bufer, 0);
@ -246,7 +245,7 @@ int process_signal(int signal, char *process_name)
continue;
if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0 || atoi(ptr->d_name) == self_pid)
continue;
sprintf(comm, "/proc/%s/comm", ptr->d_name);
if (access(comm, F_OK) == 0) {
fp = fopen(comm, "r");
@ -269,12 +268,11 @@ int process_signal(int signal, char *process_name)
}
}
closedir(dir);
if (signal == SERVER_TYPE_STATUS)
;
if (signal == SERVER_TYPE_STATUS) ;
else if (signal == SERVICE_TYPE_STATUS_NOT_PRINT)
return 1;
return 0;
}
@ -412,7 +410,7 @@ void thread_loop(conf * configure)
if (pthread_sigmask(SIG_BLOCK, &signal_mask, NULL) != 0) {
printf("block sigpipe error\n");
}
if (global.timeout_m)
pthread_create(&thread_id, NULL, &timeout_check, NULL);
@ -444,8 +442,6 @@ void thread_loop(conf * configure)
*/
}
void _main(int argc, char *argv[])
{
int opt;
@ -459,29 +455,6 @@ void _main(int argc, char *argv[])
memset(configure, 0, sizeof(struct CONF));
read_conf(inifile, configure);
// 反转链表,使读取的配置正序
http_head_strrep = local_reverse(http_head_strrep);
http_head_regrep = local_reverse(http_head_regrep);
https_head_strrep = local_reverse(https_head_strrep);
https_head_regrep = local_reverse(https_head_regrep);
/*
print_tcp(https_head_strrep);
print_tcp(https_head_regrep);
free_tcp(&https_head_strrep);
free_tcp(&https_head_regrep);
print_tcp(http_head_strrep);
print_tcp(http_head_regrep);
free_tcp(&http_head_strrep);
free_tcp(&http_head_regrep);
free_conf(configure);
free(configure);
exit(0);
*/
sslEncodeCode = 0; // 默认SSL不转码
if (configure->sslencoding > 0) // 如果配置文件有sslencoding值,优先使用配置文件读取的值
@ -553,7 +526,7 @@ void _main(int argc, char *argv[])
}
if (strcasecmp(optarg, "restart") == 0 || strcasecmp(optarg, "reload") == 0) {
process_signal(SERVER_TYPE_STOP, executable_filename);
while (process_signal(SERVICE_TYPE_STATUS_NOT_PRINT, executable_filename) == 0);
while (process_signal(SERVICE_TYPE_STATUS_NOT_PRINT, executable_filename) == 0) ;
}
if (strcasecmp(optarg, "status") == 0)
exit(process_signal(SERVER_TYPE_STATUS, executable_filename));
@ -567,9 +540,31 @@ void _main(int argc, char *argv[])
;
}
}
server_ini(); // 守护进程
// 反转链表,使读取的配置正序
http_head_strrep = local_reverse(http_head_strrep);
http_head_regrep = local_reverse(http_head_regrep);
https_head_strrep = local_reverse(https_head_strrep);
https_head_regrep = local_reverse(https_head_regrep);
/*
print_tcp(https_head_strrep);
print_tcp(https_head_regrep);
free_tcp(&https_head_strrep);
free_tcp(&https_head_regrep);
print_tcp(http_head_strrep);
print_tcp(http_head_regrep);
free_tcp(&http_head_strrep);
free_tcp(&http_head_regrep);
free_conf(configure);
free(configure);
exit(0);
*/
rt.rlim_max = rt.rlim_cur = MAX_CONNECTION * 2; // 设置每个进程允许打开的最大文件数
if (setrlimit(RLIMIT_NOFILE, &rt) == -1)