├── .gitignore ├── ChangeLog ├── INSTALL ├── Makefile ├── README ├── connect.c ├── direct.c ├── direct6.c ├── getopt.c ├── getopt.h ├── http.c ├── main.c ├── proxy.c ├── prtunnel.1 ├── prtunnel.h ├── prtunnel.mak └── socks5.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | prtunnel 3 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | Sun Mar 12 2006 Josh Beam 2 | * proxy.c: Made prt_context_list_resize() not attempt to do malloc(0) 3 | when the size parameter is 0, which was causing problems on some 4 | systems. Thanks to Jean-Francois Pirus for sending a fix for this. 5 | * prtunnel.h, proxy.c, direct.c, direct6.c, http.c, socks5.c: 6 | Made the protocol-specific connect functions set the server timeout 7 | so that the program doesn't hang if a server timeout is specified and 8 | a proxy doesn't respond. 9 | * main.c, prtunnel.1, README: Updated version/date. 10 | * prtunnel: Releasing 0.2.7. 11 | 12 | Mon Jan 09 2006 Josh Beam 13 | * main.c, prtunnel.1, README: Updated version/date. 14 | * prtunnel: Releasing 0.2.6. 15 | 16 | Sun Jan 08 2006 Josh Beam 17 | * prtunnel: Applied a patch from Frediano Ziglio that modifies 18 | most of the source files to improve win32 support, adds a 19 | Visual Studio NMAKE file, and makes some other changes. 20 | * getopt.c, getopt.h: New files containing a simple getopt function 21 | to be used on win32. 22 | 23 | Sun May 15 2005 Josh Beam 24 | * prtunnel.1, README: Updated date. 25 | * prtunnel: Releasing 0.2.5. 26 | 27 | Sun May 08 2005 Josh Beam 28 | * proxy.c: Applied patch from Vasil Dimov that makes the local_socks 29 | variable in prt_tcp_handle_connection() initialized to 0. This fixes 30 | a problem where SOCKS data would sometimes be sent to clients that 31 | were not using SOCKS to connect. 32 | * connect.c, direct.c, direct6.c, http.c,main.c, proxy.c, prtunnel.h, 33 | socks5.c: Replaced all calls to read(2) with calls to recv(2). Made 34 | some changes to help with compiling for win32 systems. 35 | * main.c, prtunnel.1, README: Updated version. 36 | 37 | Tue Jun 29 2004 Josh Beam 38 | * proxy.c: Added missing free(readfds) call in prt_tcp_loop(). 39 | * main.c, README, prtunnel.1: Updated version. 40 | * prtunnel: Releasing 0.2.4. Thanks to Ulrik Petersen for reporting 41 | and help in debugging crashes caused by the bugs mentioned in the 42 | last ChangeLog update. 43 | 44 | Sun Jun 27 2004 Josh Beam 45 | * proxy.c: Fixed an overrun problem with prt_context_list_resize() 46 | when making a prt_context_list smaller. Fixed possible fd_set 47 | overflow. 48 | * http.c, socks5.c: Changed all gethostbyname calls to gethostbyname2 49 | calls when IPv6 is enabled. 50 | 51 | Thu Jun 10 2004 Josh Beam 52 | * proxy.c: Made prt_tcp_handle_connection call loop until a successful 53 | connection is made when not in daemon mode. 54 | * main.c, README, prtunnel.1: Updated version. 55 | * prtunnel: Releasing 0.2.3. 56 | 57 | Sun Jun 06 2004 Josh Beam 58 | * proxy.c: Rewrote much of the connection handling code over the past 59 | few days. All connections are now handled in a single process. 60 | * main.c: Got rid of --max-processes option, since it's now obsolete. 61 | * README, prtunnel.1: Removed --max-processes stuff. 62 | 63 | Sat May 22 2004 Josh Beam 64 | * prtunnel: Releasing 0.2.2. 65 | 66 | Fri May 21 2004 Josh Beam 67 | * main.c: Applied a patch (with some modifications by myself) from 68 | Diaconescu Bogdan which adds a proxy username and password prompt. 69 | * README, prtunnel.1: Updated with info on the --password-prompt 70 | option and updated the prtunnel web page URL. 71 | 72 | Sat Sep 06 2003 Josh Beam 73 | * prtunnel: Releasing 0.2.1. 74 | 75 | Wed Sep 03 2003 Josh Beam 76 | * http.c: Changed read_byte extern prototype from returning char (as 77 | the function used to) to returning int (as it now does). 78 | * proxy.c, prtunnel.h: Added missing #ifdef IPV6 stuff. Thanks to 79 | Daniel Kluge for sending a patch. 80 | 81 | Wed Aug 13 2003 Josh Beam 82 | * proxy.c: Made prt_tcp_loop return -1 if socks_method fails. 83 | Made daemon process in prt_tcp_loop close context->localfd if 84 | it successfully forks a child process to handle the connection. 85 | * prtunnel: Releasing 0.2.0. 86 | 87 | Tue Aug 12 2003 Josh Beam 88 | * proxy.c: Removed unused arguments from prt_tcp_loop definition. 89 | Made accept call IPv6 compatible and added context->sockaddr_len 90 | initialization before accept call. 91 | Added missing close call after recieving a connection from a 92 | non-trusted address. 93 | Fixed broken get_seconds function. 94 | * main.c, proxy.c: Changed keepalive variables from int to 95 | unsigned long. 96 | 97 | Mon Aug 11 2003 Josh Beam 98 | * http.c: Added use_http_1_0 argument to http_negotiate function, 99 | instead of having http_negotiate access the flags directly. 100 | 101 | Tue Aug 05 2003 Josh Beam 102 | * proxy.c: Added proper memory allocation error handling in 103 | the socks_method function, and #if 0'd out some udp functions 104 | that aren't used yet. 105 | 106 | Mon Jul 14 2003 Josh Beam 107 | * prtunnel: Massive code cleanups. The proxy.c file is basically 108 | being completely rewritten; this will take a while to finish. 109 | The prt_context struct was added, and the code for all protocols 110 | now uses it. 111 | 112 | Sat Jul 05 2003 Josh Beam 113 | * README, prtunnel.1: Documented --timeout and --server-timeout. 114 | * prtunnel: Releasing 0.1.8. 115 | 116 | Fri Jul 04 2003 Josh Beam 117 | * proxy.c, main.c: Added --server-timeout option. 118 | 119 | Tue Jul 01 2003 Josh Beam 120 | * socks5.c: Added "Bad response from SOCKS5 server" error messages. 121 | 122 | Fri Jun 20 2003 Josh Beam 123 | * proxy.c, main.c: Added --timeout option. 124 | 125 | Wed Jun 18 2003 Josh Beam 126 | * proxy.c: Fixed is_trusted_address() IPv6 handling. Before, it would 127 | return 1 (true) if the first four bytes of an address matched those 128 | of a trusted address, which worked as expected for IPv4 but not IPv6. 129 | * proxy.c, main.c: Added max-processes stuff. 130 | * README, prtunnel.1: Documented max-processes stuff. 131 | * main.c: Fixed segfault when specifying an option that takes an argument 132 | but there aren't enough arguments given. 133 | * prtunnel: Releasing 0.1.7. 134 | 135 | Wed Apr 02 2003 Josh Beam 136 | * http.c: Put "Host" line in HTTP/1.1 commands. 137 | * prtunnel: Releasing 0.1.6. 138 | 139 | Tue Apr 01 2003 Josh Beam 140 | * proxy.c, http.c, socks5.c, Makefile: Removed #define _GNU_SOURCE from 141 | the C source files and added -D_GNU_SOURCE to the Makefile's CFLAGS. 142 | 143 | Fri Mar 28 2003 Josh Beam 144 | Applied patch from ZIGLIO Frediano, with some minor changes by me, that 145 | did the following: 146 | * connect.c: Added #include , changed read_byte to return int 147 | and changed its char c variable to unsigned char c. 148 | * http.c, proxy.c: Added #define _GNU_SOURCE. 149 | * main.c: Allow one non-option argument to be given, setting remotehost 150 | to NULL and remoteport to 0. 151 | * proxy.c: Added socks_method and socks_method_connected functions, 152 | which accept and respond to socks commands if there's no predefined 153 | remotehost. 154 | * socks5.c: Added #define _GNU_SOURCE and #include . 155 | 156 | Thu Mar 20 2003 Josh Beam 157 | * proxy.c: Removed commented out close(2) call. 158 | * prtunnel: Releasing 0.1.5, finally. 159 | 160 | Sat Mar 15 2003 Josh Beam 161 | * http.c, proxy.c: Changed second argument of shutdown(2) calls 162 | to SHUT_RDWR define instead of using an integer directly. 163 | 164 | Wed Mar 12 2003 Josh Beam 165 | * prtunnel.h, http.c, main.c: Added PRT_HTTP_1_0 flag, which, when 166 | set, causes the HTTP code to use HTTP/1.0 instead of HTTP/1.1. 167 | * http.c, proxy.c: Applied patch from Ury N. Stankevich that changes 168 | the HTTP commands to HTTP/1.1 by default and adds shutdown(2) calls 169 | before close(2) calls where needed. 170 | 171 | Tue Mar 11 2003 Josh Beam 172 | * prtunnel.h, proxy.c, main.c: Added PRT_KEEPALIVE_CRLF define 173 | and put it to use. This will use a carriage return plus line feed 174 | for keep-alive data. 175 | * prtunnel.h, proxy.c: Made bitcheck variable a signed int and use 176 | a value of -1 to mean no check. This fixes a problem that wouldn't 177 | allow a bitcheck of 0 to work. Thanks to Ury N. Stankevich for 178 | pointing out this problem. 179 | 180 | Mon Feb 10 2003 Josh Beam 181 | * proxy.c: Made keep-alive function send type-specific data and other 182 | minor changes. 183 | * prtunnel: Releasing 0.1.4. 184 | 185 | Sun Feb 09 2003 Josh Beam 186 | * proxy.c, prtunnel.h: keepalive_type variable added to proxy.c and 187 | its PRT_KEEPALIVE_TELNET define added to prtunnel.h. 188 | * everywhere: --keep-alive option changed to --telnet-keep-alive. 189 | 190 | Fri Feb 07 2003 Josh Beam 191 | * proxy.c, main.c: Added --keep-alive option and the code needed 192 | to use it. 193 | * documentation: Mention --keep-alive option. 194 | 195 | Thu Feb 06 2003 Josh Beam 196 | * prtunnel.h, main.c: Added PRT_IRC_AUTOPONG flag and 197 | --irc-auto-pong option to enable it. 198 | * proxy.c: Added check_incoming_data function for performing actions 199 | when certain data is recieved; currently just handles IRC PINGs. 200 | * documentation: Added info on --irc-auto-pong option. 201 | 202 | Wed Feb 05 2003 Josh Beam 203 | * documentation: Minor stuff. 204 | * proxy.c: Ditto. 205 | * prtunnel: Releasing 0.1.3. 206 | 207 | Tue Feb 04 2003 Josh Beam 208 | * proxy.c: Added SIGINT handler to close listening socket when 209 | quitting and made the exiting parent connection process close it 210 | if not in daemon mode. 211 | * http.c, socks5.c: Changed to connect with IPv6 if the IPv6 flag 212 | is set. 213 | * README, prtunnel.1: Describe -6 option for IPv6 use. 214 | 215 | Mon Feb 03 2003 Josh Beam 216 | * README, prtunnel.1: Slight changes to description paragraphs. 217 | 218 | Thu Jan 30 2003 Josh Beam 219 | * main.c, proxy.c: Did a whole bunch of stuff to support IPv6. 220 | 221 | Tue Jan 28 2003 Josh Beam 222 | * prtunnel.h: Added PRT_IPV6 flag. 223 | * documentation: Very slight changes. 224 | 225 | Mon Jan 27 2003 Josh Beam 226 | * connect.c: Added establish_connection6 function, which is an IPv6 227 | version of establish_connection. 228 | * direct6.c: New direct IPv6 tunneling mode; allows for tunneling of 229 | connections from IPv4 clients to IPv6 servers, for example. 230 | * documentation: Now mentions the direct6 mode. 231 | 232 | Thu Jan 09 2003 Josh Beam 233 | * http.c: send(2) was only called for the non-authorization CONNECT. 234 | No need to explain how stupid this was. Also added a couple of 235 | error messages that should help us find problems with connecting. 236 | * prtunnel: Releasing 0.1.2. 237 | 238 | Mon Jan 06 2003 Josh Beam 239 | * proxy.c: Ugh. Multiply sizeof(struct trusted_address) by 240 | num_trust_addrs PLUS 1, not num_trust_addrs. 241 | * prtunnel: Releasing 0.1.1 due to dumb typo described above; it's 242 | not a big deal though, so this is definitely just a minor update. 243 | 244 | Sun Jan 05 2003 Josh Beam 245 | * proxy.c: s/htons/ntohs/ in the printf about connection attempts 246 | from non-trusted addresses. 247 | * connect.c: Changed sizeof(struct sockaddr) to sizeof(sin) in the 248 | connect(2) call. 249 | 250 | Sat Jan 04 2003 Josh Beam 251 | * README: Make the description more similar with the ones on the 252 | website, freshmeat, etc. 253 | * prtunnel: Other minor changes, and released version 0.1.0. 254 | 255 | Fri Jan 03 2003 Josh Beam 256 | * proxy.c, prtunnel.h: Added bitcheck to struct trusted_address and 257 | put it to use in the appropriate functions in proxy.c. Read the entry 258 | for the -T option in the man page to see what this does. 259 | * documentation: Stuff about the trusted_address bitcheck. 260 | * INSTALL: Added a reminder to read the man page, as it's pretty damn 261 | good compared to the --help message, which is getting crowded. 262 | * proxy.c: Made the bind_to error message a bit more informative. 263 | 264 | Thu Jan 02 2003 Josh Beam 265 | * proxy.c: Removed the wait(2) error message in proxy_kill(); 266 | it was rather pointless. 267 | * proxy.c: Stuff to waitpid(2) for daemon child processes when they're 268 | done. Took a while to figure this one out. 269 | 270 | Wed Jan 01 2003 Josh Beam 271 | * main.c, proxy.c, prtunnel.h: Added struct trusted_address and 272 | put it to use a bit. 273 | * proxy.c: Added some missing close(2) calls. 274 | * main.c, proxy.c, prtunnel.h: Added the PRT_DAEMON flag and used it. 275 | See fw_proxy() in proxy.c for all of the scary accept(2) and fork(2) 276 | stuff. 277 | * all the documentation: Document new features. 278 | 279 | Sun Dec 29 2002 Josh Beam 280 | * proxy.c: Fixed up print_data a little; it's now a bit easier to 281 | differentiate between incoming/outgoing non-color output. 282 | * prtunnel.1: s/MISC/WEBSITE/, since the only thing in that section 283 | is the URL; describe non-color verbose output a bit. 284 | * README: Same stuff about non-color verbose output from man page. 285 | * prtunnel: Released version 0.0.4. 286 | 287 | Thu Dec 26 2002 Josh Beam 288 | * proxy.c, http.c, socks5.c: Print all status messages to stderr instead 289 | of just the ones indicating failure. 290 | * main.c, prtunnel.1, README: Make sure people know where to find the 291 | latest version. 292 | * prtunnel: Released version 0.0.3. 293 | 294 | Wed Dec 25 2002 Josh Beam 295 | * prtunnel.1: That's right, I wrote a man page! Merry Christmas! 296 | * Makefile: install/uninstall the man page. 297 | 298 | Tue Dec 24 2002 Josh Beam 299 | * socks5.c: Added SOCKS5 username/password authentication support. 300 | * socks5.c: Fixed possible buffer overflow with the hostname memcpy. 301 | * http.c, socks5.c: Added some more informative error messages. 302 | * proxy.c: usleep(500) before killing the processes. See the comments 303 | before the first usleep to see why; not a big deal. 304 | * proxy.c: fflush at the end of print_data. 305 | * prtunnel: Released version 0.0.2. 306 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | To build and install, just run: 2 | 3 | make 4 | make install 5 | 6 | The prtunnel binary will be installed to /usr/local/bin/prtunnel by default. 7 | If you want a prefix other than /usr/local, change the PREFIX in the Makefile. 8 | To compile prtunnel without IPv6 support, you must comment out or remove the 9 | "CFLAGS+= -DIPV6" line in the Makefile. 10 | 11 | Read the man page (`man prtunnel') for information on using it. 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PREFIX=/usr/local 2 | CC=gcc 3 | CFLAGS=-Wall -ansi -pedantic -D_GNU_SOURCE 4 | CFLAGS+= -DIPV6 5 | OBJS=connect.o direct.o direct6.o http.o socks5.o proxy.o main.o 6 | 7 | prtunnel: $(OBJS) 8 | $(CC) $(OBJS) -o prtunnel 9 | 10 | install: 11 | install -c prtunnel $(PREFIX)/bin/prtunnel 12 | install -c prtunnel.1 $(PREFIX)/man/man1/prtunnel.1 13 | 14 | uninstall: 15 | rm -f $(PREFIX)/bin/prtunnel 16 | rm -f $(PREFIX)/man/man1/prtunnel.1 17 | 18 | clean: 19 | rm -f prtunnel 20 | rm -f $(OBJS) 21 | 22 | connect.o: connect.c 23 | direct.o: direct.c 24 | direct6.o: direct6.c 25 | http.o: http.c 26 | socks5.o: socks5.c 27 | proxy.o: proxy.c 28 | main.o: main.c 29 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | prtunnel tunnels TCP connections through an HTTP or SOCKS5 proxy server. 2 | It is useful if you're behind such a proxy and want to use a program 3 | that doesn't have native proxy support. 4 | 5 | It's developed on Slackware Linux and OpenBSD (both x86), and should work 6 | on any other Unix-like system. 7 | 8 | prtunnel was written by Josh Beam and is distributed under 9 | a BSD-style license (see prtunnel.h or any other source file for the exact 10 | terms). The latest version can be found at 11 | http://joshbeam.com/software/prtunnel 12 | 13 | 14 | Usage 15 | ----- 16 | prtunnel [options] [ ] 17 | 18 | is the local port you want prtunnel to listen to; 19 | is the name or address of the remote system you want to connect to; 20 | is the port of the service you want to use on . 21 | 22 | If run without the and arguments, prtunnel 23 | will accept SOCKS4/SOCKS5 commands from the client to determine the 24 | remote server to connect to. 25 | 26 | Options: 27 | -D Run as a daemon. prtunnel will run in the background 28 | and accept multiple TCP connections with this option. 29 | -V Verbose output (prints all data transferred to standard 30 | output) 31 | -c Use color to differentiate between incoming and outgoing 32 | data in verbose output; without this, each line of outgoing 33 | verbose output will begin with ">>> " and incoming output 34 | with "<<< " 35 | -6 Enables IPv6 mode. This doesn't affect the way outgoing 36 | connections are made with the direct/direct6 tunneling 37 | modes; direct will always connect with IPv4 and direct6 38 | will always connect with IPv6. 39 | -t Set tunneling mode; http (default), socks5, direct and 40 | direct6 are supported. With http and socks5, you must 41 | specify the address of an http/socks5 proxy to use. 42 | direct will make prtunnel connect directly to the remote 43 | host specified; direct6 does the same, but with IPv6 44 | instead of IPv4. 45 | -H Name or address of the proxy server you wish to use 46 | -P Port that the proxy server uses (8080 default for http, 47 | 1080 default for socks5) 48 | -T
Add a trusted address. For security reasons, only localhost 49 | is trusted by default. Only connections from trusted 50 | addresses are allowed. You can specify an address itself 51 | (like 10.0.0.1), or in the form of address/bitcheck, where 52 | bitcheck is the number of leading bits to compare; for 53 | example, 10.0.0.0/24 would mean any address in the range 54 | of 10.0.0.0 to 10.0.0.255. 55 | -u Set proxy authentication username 56 | -p Set proxy authentication password 57 | --password-prompt 58 | Prompt for proxy username and password 59 | --http-1.0 Use HTTP/1.0 instead of HTTP/1.1 for HTTP connections 60 | --telnet-keep-alive 61 | Causes prtunnel to send keep-alive data at the 62 | specified interval, using the telnet NOP command 63 | --crlf-keep-alive 64 | Causes prtunnel to send keep-alive data at the 65 | specified interval, using a CRLF 66 | --irc-auto-pong Causes prtunnel to automatically respond to PING commands 67 | sent by IRC servers 68 | --timeout