From 5581f63df9034370cff54aeda44b365439b141fb Mon Sep 17 00:00:00 2001 From: epochqwert Date: Sun, 21 Jun 2015 23:24:52 -0500 Subject: PoC for turning a socket into a gre tunnel's UDP encapsulation socket on NetBSD. still rough. --- src/bin/great.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/bin/great.c (limited to 'src/bin') diff --git a/src/bin/great.c b/src/bin/great.c new file mode 100644 index 0000000..11976b8 --- /dev/null +++ b/src/bin/great.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PORT 1013 + +/*great = gre auto tunnel*/ + +void dump(unsigned char *b,unsigned int t) { + for(;t;b++,t--) printf("%02x ",*b); +} + +/* TODO: + args. + password? + clean out the extra shit. + clean it up even more. + + arguments: + interface + listen-port + listen-addr + password? +*/ +int main(int argc,char *argv[]) { + struct sockaddr_in sa; + struct sockaddr_in from; + char buf[512]; + socklen_t sl=sizeof(struct sockaddr_in); + int so_link=socket(AF_LINK,SOCK_DGRAM,0); + int so_unspec=socket(AF_UNSPEC,SOCK_DGRAM,0); + int so_inet=socket(AF_INET,SOCK_DGRAM,0); + int so=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP); + memset(&sa,0,(size_t)sizeof(struct sockaddr_in)); + memset(&from,0,(size_t)sizeof(struct sockaddr_in)); + sa.sin_addr.s_addr=inet_addr("192.168.0.2"); + sa.sin_port=htons(PORT); + sa.sin_family=PF_INET; + bind(so,(struct sockaddr *)&sa,sizeof(sa)); + recvfrom(so,buf,sizeof(buf),0,(struct sockaddr *)&from,&sl); + connect(so,(struct sockaddr *)&from,sl); + struct in_addr addr = {from.sin_addr.s_addr}; + printf("%s\n",inet_ntoa(addr)); + + struct ifreq *asdf; + asdf=malloc(sizeof(struct ifreq)); + + memset(asdf,0,sizeof(struct ifreq)); + strcpy(asdf->ifr_name,"gre10"); + printf("destroy: %d\n",ioctl(so_link,SIOCIFDESTROY,asdf));//destroy + + memset(asdf,0,sizeof(struct ifreq)); + strcpy(asdf->ifr_name,"gre10"); + printf("create: %d\n",ioctl(so_link,SIOCIFCREATE,asdf));//create + + memset(asdf,0,sizeof(struct ifreq)); + strcpy(asdf->ifr_name,"gre10"); + asdf->ifr_flags=IPPROTO_UDP; + printf("proto: %d\n",ioctl(so_link,GRESPROTO,asdf));//link0 link2 + + memset(asdf,0,sizeof(struct ifreq)); + strcpy(asdf->ifr_name,"gre10"); + asdf->ifr_value=so; + printf("gressock: %d\n",ioctl(so_inet,GRESSOCK,asdf));//set socket + + sleep(1); + system("ifconfig gre10");//just so you can see what it looks like. + return 0; +} -- cgit v1.2.3