Add test case: inject IPv4 based (TCP payload & TCP FIN & TCP RST) packet after recv C2S first payload
This commit is contained in:
@@ -20,6 +20,9 @@ target_link_libraries(gtest_inject_tcp_payload_after_recv_c2s_first_payload libp
|
||||
add_executable(gtest_inject_tcp_payload_after_recv_s2c_first_payload gtest_inject_tcp_payload_after_recv_s2c_first_payload.cpp)
|
||||
target_link_libraries(gtest_inject_tcp_payload_after_recv_s2c_first_payload libpacket_injector)
|
||||
|
||||
add_executable(gtest_inject_tcp_payload_fin_rst_after_recv_c2s_first_payload gtest_inject_tcp_payload_fin_rst_after_recv_c2s_first_payload.cpp)
|
||||
target_link_libraries(gtest_inject_tcp_payload_fin_rst_after_recv_c2s_first_payload libpacket_injector)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(gtest_inject_tcp_rst_after_recv_syn_ack)
|
||||
gtest_discover_tests(gtest_inject_tcp_rst_after_recv_sub_ack)
|
||||
@@ -27,6 +30,7 @@ gtest_discover_tests(gtest_inject_tcp_rst_after_recv_c2s_first_payload)
|
||||
gtest_discover_tests(gtest_inject_tcp_rst_after_recv_s2c_first_payload)
|
||||
gtest_discover_tests(gtest_inject_tcp_payload_after_recv_c2s_first_payload)
|
||||
gtest_discover_tests(gtest_inject_tcp_payload_after_recv_s2c_first_payload)
|
||||
gtest_discover_tests(gtest_inject_tcp_payload_fin_rst_after_recv_c2s_first_payload)
|
||||
|
||||
add_executable(packet_injector packet_injector.cpp)
|
||||
target_link_libraries(packet_injector core gtest)
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "packet_injector_test_frame.h"
|
||||
|
||||
TEST(INJECT_IPV4_BASED_TCP_PAYLOAD_FIN_RST, AFTER_RECV_C2S_FIRST_PAYLOAD)
|
||||
{
|
||||
char current_dir[1024] = {0};
|
||||
char work_dir[2048] = {0};
|
||||
char input_dir[2048] = {0};
|
||||
getcwd(current_dir, sizeof(current_dir));
|
||||
snprintf(work_dir, sizeof(work_dir), "%s/%s", current_dir, "inject_ipv4_based_tcp_payload_fin_rst_after_recv_c2s_first_payload");
|
||||
snprintf(input_dir, sizeof(input_dir), "%s/%s", current_dir, "pcap/inject_ipv4_based_tcp_payload_fin_rst_after_recv_c2s_first_payload/test/");
|
||||
|
||||
struct packet_injector_case test = {
|
||||
// descriptor
|
||||
.finish_clean_work_dir = 0,
|
||||
.descriptor = "Inject IPv4 based TCP Payload & FIN & RST after receiving C2S first payload packet.",
|
||||
.work_dir = work_dir,
|
||||
|
||||
// prefix
|
||||
.input_prefix = input_dir,
|
||||
|
||||
// input pcap
|
||||
.input_pcap = "input.pcap",
|
||||
|
||||
// compare
|
||||
.compares = {
|
||||
{
|
||||
.expect_pcap = "expect-192.0.2.110:80-192.0.2.213:37296-1.pcap",
|
||||
.inject_pcap = "inject-192.0.2.110:80-192.0.2.213:37296-1.pcap",
|
||||
},
|
||||
{
|
||||
.expect_pcap = "expect-192.0.2.110:80-192.0.2.213:37296-2.pcap",
|
||||
.inject_pcap = "inject-192.0.2.110:80-192.0.2.213:37296-2.pcap",
|
||||
},
|
||||
{
|
||||
.expect_pcap = "expect-192.0.2.110:80-192.0.2.213:37296-3.pcap",
|
||||
.inject_pcap = "inject-192.0.2.110:80-192.0.2.213:37296-3.pcap",
|
||||
},
|
||||
{
|
||||
.expect_pcap = "expect-192.0.2.110:80-192.0.2.213:37296-4.pcap",
|
||||
.inject_pcap = "inject-192.0.2.110:80-192.0.2.213:37296-4.pcap",
|
||||
},
|
||||
{
|
||||
.expect_pcap = "expect-192.0.2.213:37296-192.0.2.110:80-5.pcap",
|
||||
.inject_pcap = "inject-192.0.2.213:37296-192.0.2.110:80-5.pcap",
|
||||
},
|
||||
{
|
||||
.expect_pcap = "expect-192.0.2.213:37296-192.0.2.110:80-6.pcap",
|
||||
.inject_pcap = "inject-192.0.2.213:37296-192.0.2.110:80-6.pcap",
|
||||
},
|
||||
{
|
||||
.expect_pcap = NULL,
|
||||
.inject_pcap = NULL,
|
||||
},
|
||||
},
|
||||
|
||||
// packet injector command
|
||||
.packet_injector_cmd = {"./packet_injector", "-t", "tcp-payload-fin-rst", "-c", "c2s-packet", "-n", "3"},
|
||||
.diff_skip_pattern = "-I frame.time -I frame.time_epoch -I ip.id -I ip.ttl -I ip.checksum -I tcp.checksum -I tcp.window_size",
|
||||
};
|
||||
|
||||
packet_injector_test_frame_run(&test);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -32,8 +32,9 @@ enum inject_type
|
||||
INJECT_TYPE_TCP_RST = 1,
|
||||
INJECT_TYPE_TCP_FIN = 2,
|
||||
INJECT_TYPE_TCP_PAYLOAD = 3,
|
||||
INJECT_TYPE_UDP_PAYLOAD = 4,
|
||||
INJECT_TYPE_CTRL_MSG = 5,
|
||||
INJECT_TYPE_TCP_PAYLOAD_FIN_RST = 4,
|
||||
INJECT_TYPE_UDP_PAYLOAD = 5,
|
||||
INJECT_TYPE_CTRL_MSG = 6,
|
||||
};
|
||||
|
||||
struct inject_rule
|
||||
@@ -57,7 +58,7 @@ static void usage(char *cmd)
|
||||
printf(" -h <ip> Host IP address\n");
|
||||
printf(" -p <port> Port number\n");
|
||||
printf(" -t <type> Type of manipulation\n");
|
||||
printf(" Options: tcp-rst, tcp-fin, tcp-payload, udp-payload, ctrl-msg\n");
|
||||
printf(" Options: tcp-rst, tcp-fin, tcp-payload, tcp-payload-fin-rst, udp-payload, ctrl-msg\n");
|
||||
printf(" -c <condition> Condition for manipulation\n");
|
||||
printf(" Options: c2s-packet, s2c-packet\n");
|
||||
printf(" -n <number> Number of packets received before injecting action\n\n");
|
||||
@@ -138,6 +139,10 @@ static int packet_injector_on_init(int argc, char **argv, struct inject_rule *ru
|
||||
{
|
||||
rule->inject_type = INJECT_TYPE_TCP_PAYLOAD;
|
||||
}
|
||||
else if (strcmp(type, "tcp-payload-fin-rst") == 0)
|
||||
{
|
||||
rule->inject_type = INJECT_TYPE_TCP_PAYLOAD_FIN_RST;
|
||||
}
|
||||
else if (strcmp(type, "udp-payload") == 0)
|
||||
{
|
||||
rule->inject_type = INJECT_TYPE_UDP_PAYLOAD;
|
||||
@@ -245,6 +250,16 @@ static void packet_injector_on_msg(struct session *sess, int topic_id, const voi
|
||||
EXPECT_TRUE(stellar_inject_tcp_rst(sess, FLOW_DIRECTION_C2S) > 0); // inject RST to server
|
||||
session_set_discard(sess);
|
||||
break;
|
||||
case INJECT_TYPE_TCP_PAYLOAD_FIN_RST:
|
||||
snprintf(buffer, sizeof(buffer), "HTTP/1.1 200 OK\r\nContent-Length: %d\r\n\r\n%s", 5 + 5 + 2, "Hello");
|
||||
EXPECT_TRUE(stellar_inject_payload(sess, FLOW_DIRECTION_S2C, buffer, strlen(buffer)) > 0); // inject payload to client
|
||||
EXPECT_TRUE(stellar_inject_payload(sess, FLOW_DIRECTION_S2C, "World\r\n", 7) > 0); // inject payload to client
|
||||
EXPECT_TRUE(stellar_inject_tcp_fin(sess, FLOW_DIRECTION_S2C) > 0); // inject FIN to client
|
||||
EXPECT_TRUE(stellar_inject_tcp_rst(sess, FLOW_DIRECTION_S2C) > 0); // inject RST to client
|
||||
EXPECT_TRUE(stellar_inject_tcp_fin(sess, FLOW_DIRECTION_C2S) > 0); // inject FIN to server
|
||||
EXPECT_TRUE(stellar_inject_tcp_rst(sess, FLOW_DIRECTION_C2S) > 0); // inject RST to server
|
||||
session_set_discard(sess);
|
||||
break;
|
||||
case INJECT_TYPE_UDP_PAYLOAD:
|
||||
EXPECT_TRUE(stellar_inject_payload(sess, FLOW_DIRECTION_C2S, "Hello Server", 12) > 0);
|
||||
EXPECT_TRUE(stellar_inject_payload(sess, FLOW_DIRECTION_S2C, "Hello Client", 12) > 0);
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user