1. Install dependent packages
sudo apt-get build-dep tinyproxy
sudo apt-get install Flex bison
2. Add the following patches
---tinyproxy-1.6.3-orig/src/grammar.y 2004-08-06 13:23:50.000000000-0300
+ + + tinyproxy-1.6.3/src/grammar.y 2006-07-18 22:52:09.000000000-0300
@@ -57,6 +57,9 @@
%token Kw_statpage
%token Kw_via_proxy_name
+/* Proxy Types */
+%token kw_proxy_http KW_PROXY_SOCKS4 KW_PROXY_SOCKS5
+
/* yes/no Switches */
%token Kw_yes Kw_no
@@ -75,6 +78,7 @@
%type <cptr> network_address
%type <cptr> unique_address
%type <num> Loglevels
+%type <num> Upstream_proxy
%%
@@ -167,18 +171,18 @@
Log_message (log_warning, "X-tinyproxy header support is not compiled in.");
#endif
}
- | Kw_upstream unique_address ': ' Number
+ | Upstream_proxy unique_address ': ' Number
{
#ifdef Upstream_support
-Upstream_add ($, $4, NULL);
+ Upstream_add ($, $4, NULL, $);
#else
Log_message (log_warning, "Upstream proxy support is not compiled in.");
#endif
}
- | Kw_upstream unique_address ': ' Number STRING
+ | Upstream_proxy unique_address ': ' Number STRING
{
#ifdef Upstream_support
-Upstream_add ($, $4, $);
+ Upstream_add ($ $, $4, $, $);
#else
Log_message (log_warning, "Upstream proxy support is not compiled in.");
#endif
@@ -186,7 +190,7 @@
| Kw_no Kw_upstream STRING
{
#ifdef Upstream_support
-Upstream_add (NULL, 0, $);
+ upstream_add (NULL, 0, $0);
#else
Log_message (log_warning, "Upstream proxy support is not compiled in.");
#endif
@@ -221,6 +225,13 @@
}
;
+upstream_proxy
+: Kw_upstream kw_proxy_http {$$ = Http_type;}
+ | Kw_upstream kw_proxy_socks4 {$$ = Socks4_type;}
+ | Kw_upstream kw_proxy_socks5 {$$ = Socks5_type;}
+ | Kw_upstream {$$ = Http_type;}
+ ;
+
Loglevels
: kw_log_critical {$$ = Log_crit;}
| kw_log_error {$$ = Log_err;}
---tinyproxy-1.6.3-orig/src/reqs.c 2004-08-06 13:56:55.000000000-0300
+ + + tinyproxy-1.6.3/src/reqs.c 2006-07-19 13:15:07.000000000-0300
@@ -59,9 +59,11 @@
#ifdef Upstream_support
# define Upstream_configured () (config.upstream_list! = NULL)
# define UPSTREAM_HOST (host) Upstream_get (host)
+# define UPSTREAM_IS_HTTP (conn) (Conn->upstream_proxy! = NULL && Conn->upstream_proxy->type = = Http_ TYPE)
#else
# define upstream_configured (0)
# define Upstream_host (HOST) (NULL)
+# define UPSTREAM_IS_HTTP (UP) (0)
#endif
/*
@@ -311,11 +313,21 @@
#endif/* Transparent_proxy */
#ifdef Upstream_support
+char *
+proxy_type_name (Proxy_type type)
+{
+ switch (type) {
+ Case Http_type:return "HTTP";
+ Case Socks4_type:return "SOCKS4";
+ Case Socks5_type:return "SOCKS5";
+ Default:return "Unknown";
+ }
+}
/*
* ADD an entry to the upstream list
*/
void
-upstream_add (const char *host, int port, const char *domain)
+upstream_add (const char *host, int port, const char *domain, Proxy_type type)
{
Char *ptr;
struct Upstream *up = safemalloc (sizeof (struct upstream));
@@ -325,6 +337,8 @@
Return
}
+ Up->type = type;
+
Up->host = Up->domain = NULL;
Up->ip = Up->mask = 0;
@@ -337,7 +351,7 @@
Up->host = Safestrdup (host);
Up->port = port;
-Log_message (Log_info, "Added upstream%s:%d for [default]", host, Port);
+ Log_message (log_info, "Added upstream%s%s:%d for [default]", Proxy_type_name (type), host, Port);
} else if (host = = NULL) {
if (!domain | | domain[0] = = ' + ') {
Log_message (log_warning, "Nonsense no-upstream rule:empty domain");
@@ -375,8 +389,8 @@
Up->port = port;
Up->domain = safestrdup (domain);
-Log_message (Log_info, "Added upstream%s:%d for%s",
-Host, port, domain);
+ Log_message (log_info, "Added upstream%s%s:%d for%s",
+ proxy_type_name (type), host, port, domain);
}
if (!up->domain &&!up->ip) {/* always add default to end */
@@ -456,8 +470,8 @@
up = NULL;
if (UP)
-Log_message (Log_info, "Found proxy%s:%d for%s",
-Up->host, Up->port, host);
+ Log_message (log_info, "Found proxy%s%s:%d for%s",
+ Proxy_type_name (up->type), Up->host, Up->port, host);
Else
Log_message (Log_info, "No Proxy for%s", host);
@@ -1069,10 +1083,10 @@
/*
* Don ' t send headers if there ' s already an error if the request was
* A stats request, or if this is a CONNECT method (unless upstream
-* Proxy is on use.)
+ * HTTP proxy is in use.)
*/
if (connptr->server_fd = =-1 | | connptr->show_stats
- || (Connptr->connect_method && (connptr->upstream_proxy = = NULL))) {
+ || (Connptr->connect_method &&!) Upstream_is_http (connptr))) {
Log_message (Log_info, "Not sending client headers-to-remote machine");
return 0;
}
@@ -1394,6 +1408,87 @@
Return
}
+static int
+connect_to_upstream_proxy (struct conn_s *connptr, struct request_s *request)
+{
+ int len;
+ unsigned char buff[512]; /* won ' t use more than 7 + 255 */
+ unsigned short port;
+ struct hostent *host;
+ struct Upstream *cur_upstream = connptr->upstream_proxy;
+
+ Log_message (Log_conn,
+ "established connection to%s proxy \"%s\ "Using file descriptor%d.",
+ Proxy_type_name (cur_upstream->type), Cur_upstream->host, CONNPTR->SERVER_FD);
+
+ if (Cur_upstream->type = = Socks4_type) {
+
+ buff[0] = 4; Socks version
+ buff[1] = 1; Connect command
+ Port = htons (Request->port);
+ memcpy (&buff[2], &port, 2); Dest Port
+ host = gethostbyname (Request->host);
+ memcpy (&buff[4], host->h_addr_list[0], 4); Dest IP
+ buff[8] = 0; User
+ if (9! = Safe_write (CONNPTR->SERVER_FD, Buff, 9))
+ return-1;
+ if (8! = Safe_read (CONNPTR->SERVER_FD, Buff, 8))
+ return-1;
+ if (buff[0]!=0 | | buff[1]!=90)
+ return-1;
+
+} else if (Cur_upstream->type = = Socks5_type) {
+
+/* init */
+ buff[0] = 5; Socks version
+ buff[1] = 1; Number of methods
+ buff[2] = 0; No Auth method
+ if (3! = Safe_write (CONNPTR->SERVER_FD, Buff, 3))
+ return-1;
+ if (2! = Safe_read (CONNPTR->SERVER_FD, Buff, 2))
+ return-1;
+ if (buff[0]!=5 | | buff[1]!=0)
+ return-1;
+/* Connect */
+ buff[0] = 5; Socks version
+ buff[1] = 1; Connect
+ buff[2] = 0; Reserved
+ buff[3] = 3; DomainName
+ Len=strlen (request->host);
+ if (len>255)
+ return-1;
+ buff[4] = len; Length of DomainName
+ memcpy (&buff[5], request->host, Len); Dest IP
+ Port = htons (Request->port);
+ memcpy (&buff[5+len], &port, 2); Dest Port
+ if (7+len! = Safe_write (connptr->server_fd, Buff, 7+len))
+ return-1;
+ if (4! = Safe_read (CONNPTR->SERVER_FD, Buff, 4))
+ return-1;
+ if (buff[0]!=5 | | buff[1]!=0)
+ return-1;
+ switch (buff[3]) {
+ Case 1:len=4; Break IP v4
+ Case 4:len=16; Break IP V6
+ Case 3://DomainName
+ if (1! = Safe_read (CONNPTR->SERVER_FD, Buff, 1))
+ return-1;
+ len = buff[0]; /* max = 255 */
+ Break;
+ default:return-1;
+ }
+ if (2+len! = Safe_read (connptr->server_fd, Buff, 2+len))
+ return-1;
+} else {
+ return-1;
+ }
+
+ if (Connptr->connect_method)
+ return 0;
+
+ Return Establish_http_connection (connptr, request);
+}
+
/*
* Establish a connection to the upstream proxy server.
*/
@@ -1431,6 +1526,9 @@
return-1;
}
+ if (cur_upstream->type! = http_type)
+ Return Connect_to_upstream_proxy (connptr, request);
+
Log_message (Log_conn,
"Established connection to upstream proxy \"%s\ "Using file descriptor%d.",
Cur_upstream->host, CONNPTR->SERVER_FD);
@@ -1600,7 +1698,7 @@
Return
}
-if (!connptr->connect_method | | (Connptr->upstream_proxy! = NULL)) {
+ if (!connptr->connect_method | | Upstream_is_http (connptr)) {
if (Process_server_headers (CONNPTR) < 0) {
if (connptr->error_variables)
Send_http_error_message (CONNPTR);
---tinyproxy-1.6.3-orig/src/reqs.h 2004-08-06 13:23:51.000000000-0300
+ + + tinyproxy-1.6.3/src/reqs.h 2006-07-18 22:38:18.000000000-0300
@@ -21,6 +21,6 @@
extern void handle_connection (int fd);
extern void add_connect_port_allowed (int port);
-extern void Upstream_add (const char *host, int port, const char *domain);
+extern void Upstream_add (const char *host, int port, const char *domain, proxy_type type);
#endif
---tinyproxy-1.6.3-orig/src/scanner.l 2004-08-06 13:23:51.000000000-0300
+ + + tinyproxy-1.6.3/src/scanner.l 2006-07-19 13:25:25.000000000-0300
@@ -60,6 +60,11 @@
{"Defaulterrorfile", Kw_default_errorpage},
{"Statfile", Kw_statpage},
+/* Proxy types */
+ {"http", kw_proxy_http},
+ {"Socks4", KW_PROXY_SOCKS4},
+ {"Socks5", KW_PROXY_SOCKS5},
+
/* LogLevel and the settings * *
{"LogLevel", Kw_loglevel},
{"Critical", kw_log_critical},
---tinyproxy-1.6.3-orig/src/tinyproxy.h 2004-08-06 13:56:55.000000000-0300
+ + + tinyproxy-1.6.3/src/tinyproxy.h 2006-07-18 22:37:00.000000000-0300
@@ -29,12 +29,14 @@
* Even if upstream support isn't compiled into Tinyproxy, this
* Structure still needs to be defined.
*/
+typedef enum {http_type, Socks4_type, socks5_type} proxy_type;
struct Upstream {
struct upstream *next;
Char *domain; /* Optional */
Char *host;
int port;
in_addr_t IP, mask;
+ Proxy_type type;
};
struct config_s {
3. Compile and install
./configure
Make
sudo make install
4. Open the Tinyproxy configuration file and join the SOCK5 Proxy server address:
sudo gedit/usr/local/etc/tinyproxy/tinyproxy.conf
Upstream SOCKS5 ip:port//IP and Port replace parameters for SOCK5 server such as Tor's IP address and ports
5. Start
sudo tinyproxy-d
With these configurations, you can use your own HTTP and HTTPS proxy servers in many environments.
Ubuntu 12.04.1 Compilation installation Tinyproxy socks version