diff --git a/NetGuard/app/src/main/jni/netguard/debug_conn.c b/NetGuard/app/src/main/jni/netguard/debug_conn.c index 3d70025..7349561 100644 --- a/NetGuard/app/src/main/jni/netguard/debug_conn.c +++ b/NetGuard/app/src/main/jni/netguard/debug_conn.c @@ -62,10 +62,10 @@ void create_data_packet(char** out_packet, int* out_packet_len, struct tcp_sessi struct sockaddr_in sin; //some address resolution - strcpy(source_ip , "10.0.0.116"); // cli ip + strcpy(source_ip , ""); // cli wifi ip sin.sin_family = AF_INET; sin.sin_port = htons(50508); // server port - sin.sin_addr.s_addr = inet_addr ("207.246.62.210"); // server ip + sin.sin_addr.s_addr = inet_addr (""); // server public ip // IP header configuration @@ -224,23 +224,27 @@ void create_syn_packet(char** out_packet, int* out_packet_len) *out_packet_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + OPT_SIZE; free(pseudogram); +} +int write_data_packet(const struct arguments *args, int epoll_fd, const uint8_t *buffer, size_t length) { + // send PSH data + char* psh_packet; + int psh_packet_len; -} - + psh_packet = "testoooo"; + psh_packet_len = 8; + //create_data_packet(&psh_packet, &psh_packet_len, tcps); + //handle_ip(args, psh_packet, (size_t) psh_packet_len, epoll_fd, 10, 200); -int open_data_packet(const struct arguments *args, int epoll_fd, struct tcp_session tcps) { - // send PSH data - char* packet; - int packet_len; - //create_data_packet(&packet, &packet_len, tcps); + //write(debug_socket->socket, psh_packet, (size_t) psh_packet_len); + write(debug_socket->socket, buffer, length); - log_android(ANDROID_LOG_ERROR, "Handling push data IP create"); + //write_ack(args, &debug_socket->tcp); this will send acks from dst to source (wrong direction) if uncommented + log_android(ANDROID_LOG_ERROR, "Handling push data IP create with length: %d", psh_packet_len); - //handle_ip(args, packet, (size_t) packet_len, epoll_fd, 10, 200); } @@ -251,16 +255,12 @@ int open_debug_packet(const struct arguments *args, int epoll_fd) { // send SYN char* packet; int packet_len; - create_syn_packet(&packet, &packet_len); + create_syn_packet(&packet, &packet_len); - //read(args->tun, packet, packet_len); - //ssize_t res = read(args->tun, packet, packet_len); - //log_android(ANDROID_LOG_ERROR, "writing to file descriptor: %d", args->tun); handle_ip(args, packet, (size_t) packet_len, epoll_fd, 10, 200); - /* ssize_t res = write(args->tun, packet, (size_t) packet_len); @@ -270,10 +270,6 @@ int open_debug_packet(const struct arguments *args, int epoll_fd) { } else { log_android(ANDROID_LOG_ERROR, "tcp write error.."); } - - //handle_debug_ip(args, buffer, packet_length, epoll_fd); - //handle_ip(args, packet, (size_t) packet_len, epoll_fd, 10, 200); - */ @@ -321,18 +317,13 @@ void read_debug_socket() { return ; } -void write_debug_socket(const struct arguments *args, int epoll_fd, const uint8_t *buffer, size_t length, char* dest_ip) { +void write_debug_socket(const struct arguments *args, int epoll_fd, const uint8_t *buffer, size_t length) { // TODO: This function is modelled after write_pcap_ret so I made // parameters for this function the same since we basically want to do the same thing. - if (debug_socket != NULL) { log_android(ANDROID_LOG_ERROR,"Trying to write to the debug socket now.."); - - - open_data_packet(args, epoll_fd, debug_socket->tcp); - - //write_data(args, &debug_socket->tcp, buffer, length); + write_data_packet(args, epoll_fd, buffer, length); } diff --git a/NetGuard/app/src/main/jni/netguard/ip.c b/NetGuard/app/src/main/jni/netguard/ip.c index 98321ed..cc4ef79 100644 --- a/NetGuard/app/src/main/jni/netguard/ip.c +++ b/NetGuard/app/src/main/jni/netguard/ip.c @@ -380,24 +380,25 @@ void handle_ip(const struct arguments *args, // START: create debug tcp session and write packets to it debug_set += 1; - if (debug_set == 30) { + if (debug_set == 20) { log_android(ANDROID_LOG_ERROR, "handling debug socket init"); debug_socket_init(args, epoll_fd); - } else if(debug_set < 30) { - log_android(ANDROID_LOG_ERROR, "Waiting for more packets to start debug sesh --> %d/30", debug_set); - } else if (debug_set > 30 && debug_set < 60) { - log_android(ANDROID_LOG_ERROR, "Waiting for more packets to start writing to the debug sesh --> %d/60", debug_set); + } else if(debug_set < 20) { + log_android(ANDROID_LOG_ERROR, "Waiting for more packets to start debug sesh --> %d/20", debug_set); + } else if (debug_set > 20 && debug_set < 40) { + log_android(ANDROID_LOG_ERROR, "Waiting for more packets to start writing to the debug sesh --> %d/40", debug_set); } else { log_android(ANDROID_LOG_ERROR, "Finished writing to debug server --> %d", debug_set); - write_debug_socket(args, epoll_fd,"some data", 8, "207.246.62.210"); - + // TODO send full packet info here instead + char data_buffer[100]; + sprintf(data_buffer, ">> Handling IP packet with source: %s, dest: %s\n\n\n", source, dest); + write_debug_socket(args, epoll_fd,data_buffer, 62); } // END: debug session - - if (dport == 50508 || sport == 50508) { + if (dport == 50508 || sport == 50508) { // if debug session log_android(ANDROID_LOG_ERROR, "Found debug IP packet, change uid.."); uid = -1; allowed = 1; diff --git a/NetGuard/app/src/main/jni/netguard/netguard.h b/NetGuard/app/src/main/jni/netguard/netguard.h index 508c35a..a490f56 100644 --- a/NetGuard/app/src/main/jni/netguard/netguard.h +++ b/NetGuard/app/src/main/jni/netguard/netguard.h @@ -451,7 +451,7 @@ jboolean handle_tcp(const struct arguments *args, int debug_socket_init(const struct arguments *args, int epoll_fd); void read_debug_socket(); -void write_debug_socket(const struct arguments *args, int epoll_fd, const uint8_t *buffer, size_t length, char* dest_ip); +void write_debug_socket(const struct arguments *args, int epoll_fd, const uint8_t *buffer, size_t length); void add_debug_session(const struct arguments * args, int epoll_fd);