diff options
Diffstat (limited to 'other/fizzbounce/client.c')
| -rw-r--r-- | other/fizzbounce/client.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/other/fizzbounce/client.c b/other/fizzbounce/client.c new file mode 100644 index 0000000..f017525 --- /dev/null +++ b/other/fizzbounce/client.c | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | |||
| 2 | /* bounce 4 all | ||
| 3 | * 1999 (c) scut | ||
| 4 | * | ||
| 5 | * client routines | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <sys/socket.h> | ||
| 9 | #include <netinet/in.h> | ||
| 10 | #include <arpa/inet.h> | ||
| 11 | #include <pthread.h> | ||
| 12 | #include <signal.h> | ||
| 13 | #include <stdio.h> | ||
| 14 | #include <stdlib.h> | ||
| 15 | #include <string.h> | ||
| 16 | #include "client.h" | ||
| 17 | #include "network.h" | ||
| 18 | #include "relay.h" | ||
| 19 | |||
| 20 | extern int vuln; | ||
| 21 | |||
| 22 | void * | ||
| 23 | cl_handle (client *cl) | ||
| 24 | { | ||
| 25 | int n; | ||
| 26 | char buff[1024]; | ||
| 27 | |||
| 28 | pthread_mutex_lock (&cl->cl_mutex); | ||
| 29 | printf ("new client from %s port %d\n", inet_ntoa (cl->csa.sin_addr), cl->csa.sin_port); | ||
| 30 | pthread_mutex_unlock (&cl->cl_mutex); | ||
| 31 | |||
| 32 | /* now, since we have a client that want's to get relayed, and passed all checks, | ||
| 33 | * establish a connection to the remote server by choosing a bounceip / siteip | ||
| 34 | */ | ||
| 35 | |||
| 36 | printf ("control connection to %s:%d\n", cl->connip, cl->connport); | ||
| 37 | |||
| 38 | pthread_mutex_lock (&cl->cl_mutex); | ||
| 39 | cl->ss = net_connect (&cl->css, cl->connip, cl->connport, 45); | ||
| 40 | if (cl->ss == -1) { | ||
| 41 | printf ("failed to relay client from %s:%d to %s:%d\n", | ||
| 42 | inet_ntoa (cl->csa.sin_addr), cl->csa.sin_port, cl->connip, cl->connport); | ||
| 43 | pthread_mutex_unlock (&cl->cl_mutex); | ||
| 44 | return (NULL); | ||
| 45 | } else { | ||
| 46 | printf ("successfully relayed client from %s:%d to %s:%d\n", | ||
| 47 | inet_ntoa (cl->csa.sin_addr), cl->csa.sin_port, cl->connip, cl->connport); | ||
| 48 | } | ||
| 49 | pthread_mutex_unlock (&cl->cl_mutex); | ||
| 50 | |||
| 51 | /* now since we have both, a connection from the client to us, | ||
| 52 | * and a connection from us to the real server we call the main relay handler | ||
| 53 | */ | ||
| 54 | |||
| 55 | if (vuln == 1) { | ||
| 56 | net_write (cl->ss, "CONNECT %s:%s HTTP/1.0\n\n", cl->ircip, cl->ircport); | ||
| 57 | } else if (vuln == 2) { | ||
| 58 | net_write (cl->ss, "POST http://%s:%s/ HTTP/1.0\n\n", cl->ircip, cl->ircport); | ||
| 59 | } | ||
| 60 | // memset (buff, '\0', sizeof (buff)); | ||
| 61 | // n = net_rlinet (cl->ss, buff, sizeof (buff), 45); | ||
| 62 | |||
| 63 | // if (n <= 0) | ||
| 64 | // goto clerror; | ||
| 65 | |||
| 66 | // printf ("READ: %s\n", buff); | ||
| 67 | // if (strncmp (buff, "HTTP/1.0 200", 12) != 0) | ||
| 68 | // goto clerror; | ||
| 69 | |||
| 70 | sleep (5); | ||
| 71 | memset (buff, '\0', sizeof (buff)); | ||
| 72 | rly_client (cl); | ||
| 73 | |||
| 74 | clerror: | ||
| 75 | close (cl->ss); | ||
| 76 | close (cl->cs); | ||
| 77 | |||
| 78 | /* the relay handler only exits on failure or connection close request, | ||
| 79 | * either from the remote server or our little client | ||
| 80 | * in any case, we have to terminate the client | ||
| 81 | */ | ||
| 82 | |||
| 83 | /* should never happen */ | ||
| 84 | return (NULL); | ||
| 85 | } | ||
| 86 | |||
| 87 | client * | ||
| 88 | cl_add (void) | ||
| 89 | { | ||
| 90 | int n; | ||
| 91 | client *cl; | ||
| 92 | |||
| 93 | cl = (client *) calloc (1, sizeof (client)); | ||
| 94 | if (cl) | ||
| 95 | cl_init (cl); | ||
| 96 | |||
| 97 | return (cl); | ||
| 98 | } | ||
| 99 | |||
| 100 | void | ||
| 101 | cl_init (client *cl) | ||
| 102 | { | ||
| 103 | pthread_mutex_init (&cl->cl_mutex, NULL); | ||
| 104 | return; | ||
| 105 | } | ||
| 106 | |||
