1.修改hjack读取profile文件方式

2.命中query替换规则后,http2适配http修改
3.添加URI测试用例
This commit is contained in:
fengweihao
2019-06-03 15:12:59 +08:00
parent 044d512184
commit d272087565
4 changed files with 136 additions and 56 deletions

View File

@@ -667,16 +667,10 @@ void ma_hijack_profile_table_new_cb(int table_id, const char* key, const char* t
return;
}
struct manipulate_profile* ply_profile=ALLOC(struct manipulate_profile, 1);
memset(ply_profile, 0, sizeof(struct manipulate_profile));
ply_profile->profile_id=profile_id;
ply_profile->ref_cnt=1;
ply_profile->profile_msg = execute_read_file(profile_path, &ply_profile->msg_len);
if (ply_profile->profile_msg == NULL)
{
TFE_LOG_ERROR(g_pangu_rt->local_logger, "Read file failed %d:%s:%s", profile_id, profile_name, profile_path);
}
ply_profile->profile_id=profile_id;
ply_profile->profile_msg=tfe_strdup(profile_path);
ply_profile->profile_name=tfe_strdup(hijack_name);
ply_profile->profile_type=tfe_strdup(formate);
@@ -1378,7 +1372,6 @@ void http_replace(const struct tfe_stream * stream, const struct tfe_http_sessio
rewrite_sz = execute_replace_rule(__http_body, __http_body_len, r_zone,
rep_ctx->rule, rep_ctx->n_rule, &rewrite_buff);
if (rewrite_sz >0 )
{
tfe_http_half_append_body(rep_ctx->replacing, rewrite_buff, rewrite_sz, 0);
@@ -1564,22 +1557,35 @@ static void http_hijack(const struct tfe_http_session * session, enum tfe_http_e
return;
}
char * hijack_buff=NULL; size_t hijack_size=0;
hijack_buff = execute_read_file(hijack_profile->profile_msg, &hijack_size);
if (NULL == hijack_buff){
TFE_LOG_ERROR(g_pangu_rt->local_logger, "read hijack file faild, path = %s", hijack_profile->profile_msg);
ctx->action = PG_ACTION_NONE;
return;
}
struct tfe_http_session * to_write_sess = NULL;
char cont_len_str[16];
to_write_sess = tfe_http_session_allow_write(session);
response = tfe_http_session_response_create(to_write_sess, 200);
int hijack_len = strlen(hijack_profile->profile_name)+strlen("filename=\"\"")+1;
char *hijack_name = ALLOC(char, hijack_len);
snprintf(hijack_name, hijack_len, "filename=\"%s\"", hijack_profile->profile_name);
tfe_http_nonstd_field_write(response, "Content-Disposition", hijack_name);
FREE(&hijack_name);
if (0!=strcasecmp(hijack_profile->profile_name, "null"))
{
int hijack_file_len = strlen(hijack_profile->profile_name)+strlen("filename=\"\"")+1;
char *hijack_file_name = ALLOC(char, hijack_file_len);
snprintf(hijack_file_name, hijack_file_len, "filename=\"%s\"", hijack_profile->profile_name);
tfe_http_nonstd_field_write(response, "Content-Disposition", hijack_file_name);
FREE(&hijack_file_name);
}
tfe_http_std_field_write(response, TFE_HTTP_CONT_TYPE, hijack_profile->profile_type);
snprintf(cont_len_str, sizeof(cont_len_str), "%lu", hijack_profile->msg_len);
snprintf(cont_len_str, sizeof(cont_len_str), "%lu", hijack_size);
tfe_http_std_field_write(response, TFE_HTTP_CONT_LENGTH, cont_len_str);
tfe_http_half_append_body(response, hijack_profile->profile_msg, hijack_profile->msg_len, 0);
tfe_http_half_append_body(response, hijack_buff, hijack_size, 0);
tfe_http_half_append_body(response, NULL, 0, 0);
tfe_http_session_response_set(to_write_sess, response);
tfe_http_session_detach(session);

View File

@@ -231,6 +231,7 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg)
break;
}
cJSON_AddNumberToObject(common_obj, "direction", 0); //0域内->域外1域外->域内描述的是CLIENT_IP信息
cJSON_AddNumberToObject(common_obj, "Link_id", 0);
cJSON_AddNumberToObject(common_obj, "stream_dir", 3); //1:c2s, 2:s2c, 3:double
cJSON_AddStringToObject(common_obj, "cap_ip", handle->local_ip_str);
cJSON_AddNumberToObject(common_obj, "entrance_id", handle->entry_id);

View File

@@ -152,7 +152,44 @@ TEST(PatternReplace, CaseInsensitiveRussian)
EXPECT_TRUE(output_sz>0);
EXPECT_TRUE(NULL==strstr(output, find));
EXPECT_TRUE(NULL!=strstr(output, replacement));
free(output);
return;
}
TEST(PatternReplace, QueryAdd)
{
const char * find = "(?<=\\?|^|&)q=([^&|^#]*)(?=&|$)";
const char* replacement="q=find";
const char* input="https://cn.bing.com/search?ei=pQnxXPS-LPSGr7wP3u6usAY&q=test&oq=test&gs_l=psy-ab.3..0i131i67j0l8j0i131.26791.27227..27885...0.0..0.235.683.0j3j1......0....1..gws-wiz.......0i71j0i67.klHdqBPS88k";
char* output=NULL;
size_t output_sz=0;
simple_replace(find, replacement, input, strlen(input),&output, &output_sz);
EXPECT_TRUE(output_sz>0);
EXPECT_TRUE(NULL==strstr(output, find));
EXPECT_TRUE(NULL!=strstr(output, replacement));
printf("%s\n", output);
free(output);
return;
}
TEST(PatternReplace, QueryDel)
{
const char * find = "(?<=\\?|^|&)sk=([^&|^#]*)(&|$)";
const char* replacement="";
const char* input="https://cn.bing.com/&search?q=find&qs=n&form=QBLH&sp=-1&pq=find&sk=";
char* output=NULL;
size_t output_sz=0;
simple_replace(find, replacement, input, strlen(input),&output, &output_sz);
EXPECT_TRUE(output_sz>0);
EXPECT_TRUE(NULL==strstr(output, find));
EXPECT_TRUE(NULL!=strstr(output, replacement));
printf("%s\n", output);
free(output);
return;
}