-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optional Lab 2 - Bypassing Firewall using VPN done
- Loading branch information
Showing
6 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
Optional Lab 2 - Bypassing Firewall using VPN/Code/vpnclient.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
#include <arpa/inet.h> | ||
#include <linux/if.h> | ||
#include <linux/if_tun.h> | ||
#include <sys/ioctl.h> | ||
|
||
#define BUFF_SIZE 2000 | ||
#define PORT_NUMBER 55555 | ||
#define SERVER_IP "127.0.0.1" | ||
struct sockaddr_in peerAddr; | ||
|
||
int createTunDevice() { | ||
int tunfd; | ||
struct ifreq ifr; | ||
memset(&ifr, 0, sizeof(ifr)); | ||
|
||
ifr.ifr_flags = IFF_TUN | IFF_NO_PI; | ||
|
||
tunfd = open("/dev/net/tun", O_RDWR); | ||
ioctl(tunfd, TUNSETIFF, &ifr); | ||
|
||
return tunfd; | ||
} | ||
|
||
int connectToUDPServer(){ | ||
int sockfd; | ||
char *hello="Hello"; | ||
|
||
memset(&peerAddr, 0, sizeof(peerAddr)); | ||
peerAddr.sin_family = AF_INET; | ||
peerAddr.sin_port = htons(PORT_NUMBER); | ||
peerAddr.sin_addr.s_addr = inet_addr(SERVER_IP); | ||
|
||
sockfd = socket(AF_INET, SOCK_DGRAM, 0); | ||
|
||
// Send a hello message to "connect" with the VPN server | ||
sendto(sockfd, hello, strlen(hello), 0, | ||
(struct sockaddr *) &peerAddr, sizeof(peerAddr)); | ||
|
||
return sockfd; | ||
} | ||
|
||
|
||
|
||
void tunSelected(int tunfd, int sockfd){ | ||
int len; | ||
char buff[BUFF_SIZE]; | ||
|
||
printf("Got a packet from TUN\n"); | ||
|
||
bzero(buff, BUFF_SIZE); | ||
len = read(tunfd, buff, BUFF_SIZE); | ||
sendto(sockfd, buff, len, 0, (struct sockaddr *) &peerAddr, | ||
sizeof(peerAddr)); | ||
} | ||
|
||
void socketSelected (int tunfd, int sockfd){ | ||
int len; | ||
char buff[BUFF_SIZE]; | ||
|
||
printf("Got a packet from the tunnel\n"); | ||
|
||
bzero(buff, BUFF_SIZE); | ||
len = recvfrom(sockfd, buff, BUFF_SIZE, 0, NULL, NULL); | ||
write(tunfd, buff, len); | ||
|
||
} | ||
int main (int argc, char * argv[]) { | ||
int tunfd, sockfd; | ||
|
||
tunfd = createTunDevice(); | ||
sockfd = connectToUDPServer(); | ||
|
||
// Enter the main loop | ||
while (1) { | ||
fd_set readFDSet; | ||
|
||
FD_ZERO(&readFDSet); | ||
FD_SET(sockfd, &readFDSet); | ||
FD_SET(tunfd, &readFDSet); | ||
select(FD_SETSIZE, &readFDSet, NULL, NULL, NULL); | ||
|
||
if (FD_ISSET(tunfd, &readFDSet)) tunSelected(tunfd, sockfd); | ||
if (FD_ISSET(sockfd, &readFDSet)) socketSelected(tunfd, sockfd); | ||
} | ||
} | ||
|
93 changes: 93 additions & 0 deletions
93
Optional Lab 2 - Bypassing Firewall using VPN/Code/vpnserver.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
#include <arpa/inet.h> | ||
#include <linux/if.h> | ||
#include <linux/if_tun.h> | ||
#include <sys/ioctl.h> | ||
|
||
#define PORT_NUMBER 55555 | ||
#define BUFF_SIZE 2000 | ||
|
||
struct sockaddr_in peerAddr; | ||
|
||
int createTunDevice() { | ||
int tunfd; | ||
struct ifreq ifr; | ||
memset(&ifr, 0, sizeof(ifr)); | ||
|
||
ifr.ifr_flags = IFF_TUN | IFF_NO_PI; | ||
|
||
tunfd = open("/dev/net/tun", O_RDWR); | ||
ioctl(tunfd, TUNSETIFF, &ifr); | ||
|
||
return tunfd; | ||
} | ||
|
||
int initUDPServer() { | ||
int sockfd; | ||
struct sockaddr_in server; | ||
char buff[100]; | ||
|
||
memset(&server, 0, sizeof(server)); | ||
server.sin_family = AF_INET; | ||
server.sin_addr.s_addr = htonl(INADDR_ANY); | ||
server.sin_port = htons(PORT_NUMBER); | ||
|
||
sockfd = socket(AF_INET, SOCK_DGRAM, 0); | ||
bind(sockfd, (struct sockaddr*) &server, sizeof(server)); | ||
|
||
// Wait for the VPN client to "connect". | ||
bzero(buff, 100); | ||
int peerAddrLen = sizeof(struct sockaddr_in); | ||
int len = recvfrom(sockfd, buff, 100, 0, | ||
(struct sockaddr *) &peerAddr, &peerAddrLen); | ||
|
||
printf("Connected with the client: %s\n", buff); | ||
return sockfd; | ||
} | ||
|
||
void tunSelected(int tunfd, int sockfd){ | ||
int len; | ||
char buff[BUFF_SIZE]; | ||
|
||
printf("Got a packet from TUN\n"); | ||
|
||
bzero(buff, BUFF_SIZE); | ||
len = read(tunfd, buff, BUFF_SIZE); | ||
sendto(sockfd, buff, len, 0, (struct sockaddr *) &peerAddr, | ||
sizeof(peerAddr)); | ||
} | ||
|
||
void socketSelected (int tunfd, int sockfd){ | ||
int len; | ||
char buff[BUFF_SIZE]; | ||
|
||
printf("Got a packet from the tunnel\n"); | ||
|
||
bzero(buff, BUFF_SIZE); | ||
len = recvfrom(sockfd, buff, BUFF_SIZE, 0, NULL, NULL); | ||
write(tunfd, buff, len); | ||
|
||
} | ||
int main (int argc, char * argv[]) { | ||
int tunfd, sockfd; | ||
|
||
tunfd = createTunDevice(); | ||
sockfd = initUDPServer(); | ||
|
||
// Enter the main loop | ||
while (1) { | ||
fd_set readFDSet; | ||
|
||
FD_ZERO(&readFDSet); | ||
FD_SET(sockfd, &readFDSet); | ||
FD_SET(tunfd, &readFDSet); | ||
select(FD_SETSIZE, &readFDSet, NULL, NULL, NULL); | ||
|
||
if (FD_ISSET(tunfd, &readFDSet)) tunSelected(tunfd, sockfd); | ||
if (FD_ISSET(sockfd, &readFDSet)) socketSelected(tunfd, sockfd); | ||
} | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
Optional Lab 2 - Bypassing Firewall using VPN/LAB Setup.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
This lab requires SEED LAB 16 as the docker container setup was not working. | ||
|
||
Provided below the link to Seed lab 16 : | ||
|
||
https://seedsecuritylabs.org/lab_env.html | ||
|
||
(OR) | ||
|
||
google drive link -- https://drive.google.com/file/d/12l8OO3PXHjUsf9vfjkAf7-I6bsixvMUa/view | ||
|
Binary file added
BIN
+1.5 MB
Optional Lab 2 - Bypassing Firewall using VPN/Optinal lab 2 report.pdf
Binary file not shown.
Binary file added
BIN
+320 KB
Optional Lab 2 - Bypassing Firewall using VPN/VPN Bypassing Firewall Lab Manual.pdf
Binary file not shown.
Binary file added
BIN
+2.58 MB
Optional Lab 2 - Bypassing Firewall using VPN/VPN Bypassing Firewall.docx
Binary file not shown.