<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Labo IT &#187; bypass</title>
	<atom:link href="http://www.laboit.net/tag/bypass/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.laboit.net</link>
	<description>A lot of experiences on new technologies.</description>
	<lastBuildDate>Sun, 13 Jun 2010 13:01:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Implement a HTTP tunnel on a Linux server</title>
		<link>http://www.laboit.net/2009/05/15/implement-a-http-tunnel-on-a-linux-server/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=implement-a-http-tunnel-on-a-linux-server</link>
		<comments>http://www.laboit.net/2009/05/15/implement-a-http-tunnel-on-a-linux-server/#comments</comments>
		<pubDate>Fri, 15 May 2009 17:55:05 +0000</pubDate>
		<dc:creator>Alexandre VIOT</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bypass]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[websense]]></category>

		<guid isPermaLink="false">http://www.laboit.net/?p=196</guid>
		<description><![CDATA[In this article, we will learn how to set up a HTTP tunnel between a PC and a Linux server with the SSH protocol to secure our transactions through a firewall or another. Before to begin any technical part, I will try to explain the operation of Port Forwarding and why implement it. To understand [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">In this article, we will learn how to set up a <strong>HTTP tunnel</strong> between a PC and a Linux server with the SSH protocol to secure our transactions through a firewall or another.</p>
<p style="text-align: left;">
<p style="text-align: justify; padding-left: 30px;">
<p style="text-align: justify;">Before to begin any technical part, I will try to explain the operation of Port Forwarding and why implement it.</p>
<p style="text-align: justify;">To understand this concept, I refresh your memories on the communication of computer:</p>
<p style="text-align: justify;">
<p style="text-align: justify;">To exchange informations, computers need an <strong>IP address</strong> and a <strong>port</strong> number. The port number is important because it&#8217;s thanks to it that the communication exists. Client and server have to communicate on the same port number.</p>
<p style="text-align: justify;">
<p style="text-align: justify;">
<p style="text-align: justify;">Now, we decrypt the <strong>Port Forwarding</strong>. The Port Forwarding consist of redirect informations sent on a port number of a computer to a different port number on another computer.</p>
<p style="text-align: justify; padding-left: 30px;"><span id="more-196"></span></p>
<p style="text-align: justify;">A picture to better understand this redirection:</p>
<p style="text-align: justify; padding-left: 30px;"><img class="aligncenter size-full wp-image-106" title="translation2" src="http://www.laboit.net/wp-content/uploads/2009/04/translation2.png" alt="translation2" width="553" height="133" /></p>
<p style="text-align: center;">
<p style="text-align: left;">
<p style="text-align: justify; padding-left: 30px;">
<p style="text-align: justify; padding-left: 30px;">
<p style="text-align: justify;">In this example, the number port 6000 of client will be encapsulated on port 22. When the request arrives on the server on the port 22, it will be decapsulated et sent on 80.</p>
<p style="text-align: justify;">To simplify, the Port Forwarding swap the port number of communication.</p>
<p style="text-align: justify; padding-left: 30px;">
<p style="text-align: justify; padding-left: 30px;">
<h2 style="text-align: left;">Why implement it</h2>
<p style="text-align: justify; padding-left: 30px;">
<p style="text-align: justify; padding-left: 30px;">
<p style="text-align: justify;">We can ask the question of why implement it. <strong>Port forwarding</strong> with SSH is used when you want<strong> secure</strong> an communication between two computers.</p>
<p style="text-align: justify;">Maybe you have a firewall in your company which allows only the port number 22 and you want to access the internal FTP server. Or a filter on your HTTP requests (Websense, SurfControl) and you want bypass it. Bu avoid this control remains under your responsibility.</p>
<p style="text-align: justify;">How informations communicate , with and without Port Forwarding?</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-107" title="schemahttptunneling1" src="http://www.laboit.net/wp-content/uploads/2009/04/schemahttptunneling1.png" alt="schemahttptunneling1" width="553" height="248" /></p>
<p style="text-align: left;">
<p style="text-align: left;"><strong>Explication</strong>:</p>
<p style="text-align: justify; padding-left: 30px;">
<p style="text-align: justify;">The <strong><span style="color: #000080;">Blue path (1)</span></strong> is the communication in a normal situation. When you request a web page, your request is filtered by the firewall and redirected to Internet. If the website is in the blacklist, then access will be denied.</p>
<p style="text-align: justify;">
<p style="text-align: justify;">The <strong><span style="color: #ff0000;">Red path (2)</span></strong> is the communication with <strong>Port Forwarding</strong>.Your internet request is encapsulated in a secure tunnel and sent to your remote server.</p>
<p style="text-align: justify;">
<p style="text-align: justify;">When you encrypt your transaction between your PC and the server, it means that the firewall can&#8217;t inspect your request.</p>
<p style="text-align: justify;">Once the remote server has received your request, it will go for you on internet and download the web page. Everything in a <strong>secure connection</strong>.</p>
<p style="text-align: justify;"><strong> </strong></p>
<p style="text-align: justify;"><strong>Result:</strong> Secure exchange between two hosts, unable to inspect the content.</p>
<h2 style="text-align: left;">How implement it</h2>
<p style="text-align: justify;">I used for this article a Debian distribution, but this solution works also on Mandriva.</p>
<p style="text-align: justify;">We need :</p>
<p style="text-align: justify; padding-left: 60px;">- A<strong> Linux </strong>server</p>
<p style="text-align: left; padding-left: 60px;">- A client on Microsoft <strong>Windows</strong></p>
<p style="text-align: left; padding-left: 60px;">-  <strong>Putty</strong></p>
<p style="text-align: left;">The server configuration is divided into <strong>4</strong> steps.</p>
<ol>
<li> OpenSSH Installation.</li>
<li>Certificates for SSH.</li>
<li>Configuration of file SSH.</li>
<li>User creation.</li>
</ol>
<p style="text-align: left;">And for client configuration into<strong> 2</strong> steps.</p>
<ol>
<li>Configuration of Putty.</li>
<li>Configuration of your browser.</li>
</ol>
<h2 style="text-align: left;">Server Configuration</h2>
<h5 style="text-align: left;">OpenSSH Installation</h5>
<p style="text-align: justify; padding-left: 30px;">
<p style="text-align: justify;">Port Forwarding is based on the SSH protocol. So the first step is to install <strong>OpenSSH</strong>.</p>
<pre class="brush: bash;">apt-get install openssh-server</pre>
<p style="text-align: left; padding-left: 30px;"><strong> </strong></p>
<p style="text-align: left;"><strong>Note:</strong> Don&#8217;t forget to update your sources with:</p>
<pre class="brush: bash;">apt-get update</pre>
<h5 style="text-align: left;">Generating certificates for SSH</h5>
<p style="text-align: left;">Once you have installed the service SSH, you must have <strong>certificates</strong> to validate the connection.</p>
<p style="text-align: left;">A certificate contains a private key and public key which allow you to encrypt your communications.</p>
<p style="text-align: justify;">During the installation, it is possible that generation of certificates were done automatically. For more security, we are going to recreate them.</p>
<p style="text-align: justify;">
<p style="text-align: left;">To create certificates:</p>
<p style="text-align: left;">
<pre class="brush: bash;">ssh-keygen -t dsa -b 1024</pre>
<p style="text-align: left;">
<pre class="brush: bash;">ssh-keygen -t rsa -b 1024</pre>
<p style="text-align: justify;">The system asks you to specify the path et name for your certificates. I advise you to put them in <strong>/etc/ssh</strong></p>
<h5 style="text-align: left;">Configuration of file SSH</h5>
<p style="text-align: justify;">The next step is the modification of  configuration file of SSH to accepts tunnels and modify certificate&#8217;s paths.</p>
<p style="text-align: justify;">You linux server can also connect to another remote server in SSH. It will be client.</p>
<p style="text-align: justify;">This is why there are two configurations for SSH files: a file named <strong>ssh_config</strong> for the client connection and a <strong>sshd_config</strong> file which allows us to configure our SSH server.</p>
<p style="text-align: left;">We modify the file <strong>sshd_config</strong></p>
<p style="text-align: left;">
<pre class="brush: bash;">vi /etc/ssh/sshd_config</pre>
<p style="text-align: justify;">In first time, we specify new certificate&#8217;s path.</p>
<p style="text-align: left;">To do this, modify lines which contain <strong>HostKey</strong>:</p>
<pre class="brush: bash;"># HostKeys for protocol version 2
HostKey /etc/ssh/certifLaboIT
HostKey /etc/ssh/certifLaboITdsa
</pre>
<p style="text-align: justify;">To allow<strong> SSH tunneling</strong>,  add this command at the end of the file:</p>
<pre class="brush: bash;">#Permit Tunnel
PermitTunnel yes
</pre>
<p style="text-align: left;">It is possible to change the listening port of the server. In case of the port number 22 is blocked by your firewall.</p>
<div id="result_box" style="text-align: left;" dir="ltr">This requires changing the line containing the word:</div>
<pre class="brush: bash;">#What ports, IPs and protocols we listen
Port 22
</pre>
<p style="text-align: justify;">Quit Vim editor and don&#8217;t forget to save your modifications.</p>
<p style="text-align: left;">SSH configuration is now complete.</p>
<p style="text-align: left;">We need to <strong>restart the service</strong> with command:</p>
<pre class="brush: bash;">/etc/init.d/ssh restart</pre>
<h5 style="text-align: left;">User creation</h5>
<p style="text-align: justify;">To avoid login with root account, we create a new user:</p>
<pre class="brush: bash;">useradd LaboIT</pre>
<pre class="brush: bash;">passwd LaboIT</pre>
<p style="text-align: justify;">Server configuration is now complete.</p>
<p style="text-align: justify; padding-left: 30px;">
<h2 style="text-align: left;">Client Configuration</h2>
<p style="text-align: left;">It is important to understand what we are going to do.</p>
<p style="text-align: justify; padding-left: 30px;">
<div id="result_box" style="text-align: justify;" dir="ltr">As a first step we will configure Putty to listen on an<strong> unused</strong> port (example 9999) then we will open an SSH connection to the server. This will create the port forwarding.</div>
<div id="result_box" style="text-align: left;" dir="ltr">In a second step, we specify on our web browser to send all requests to this new port.</div>
<p style="text-align: justify;">
<p style="text-align: justify;">All client requests will be encapsulated in a tunnel by Putty dynamically to use the <strong><span style="color: #ff0000;">red path (2)</span></strong>.</p>
<h5 style="text-align: left;">Configuration of Putty</h5>
<p style="text-align: left;">You can download Putty at this address: <a onclick="javascript:pageTracker._trackPageview('/outbound/article/www.chiark.greenend.org.uk');" href="http://www.chiark.greenend.org.uk/%7Esgtatham/putty/download.html">http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html</a></p>
<p style="text-align: left;">The configuration of the PuTTY executable will be in 2 steps:</p>
<ol>
<li>
<div id="result_box" style="text-align: left;" dir="ltr">Information of the server&#8217;s IP address and its listening port.</div>
</li>
<li>
<div id="result_box" style="text-align: left;" dir="ltr">Creation on the client of a new dynamic port.</div>
</li>
</ol>
<p style="text-align: left; padding-left: 30px;">
<p style="text-align: left;">For the first step, we will fill in the connection information:</p>
<p style="text-align: left; padding-left: 30px;"><img class="aligncenter size-full wp-image-111" title="putty1" src="http://www.laboit.net/wp-content/uploads/2009/04/putty1.png" alt="putty1" width="400" height="384" /></p>
<p style="text-align: center;">
<p style="text-align: left;">
<p style="text-align: justify;">Specify the <strong>IP address</strong> or <strong>FQDN</strong> of the server in the <span style="color: #ff0000;">red box</span>. And then in the <span style="color: #ffff00;">yellow box</span> specify the port is in your configuration <strong>sshd_config</strong> file</p>
<p style="text-align: left;">Second step, creation of new port:</p>
<p style="text-align: left; padding-left: 30px;"><img class="aligncenter size-full wp-image-112" title="putty2" src="http://www.laboit.net/wp-content/uploads/2009/04/putty2.png" alt="putty2" width="400" height="383" /></p>
<p style="text-align: center;">
<p style="text-align: left; padding-left: 30px;">
<p style="text-align: left;">To create a dynamic, port verify that the <strong>dynamic</strong> option is selected and then in the field source port enter <strong>9999</strong>. Once this done, click <strong>Add</strong> to add to the <strong>ports forwarded</strong>.</p>
<p style="text-align: left;">To open the connection to the remote server, click <strong>Open</strong>.</p>
<p style="text-align: left; padding-left: 30px;">
<p style="text-align: left;">
<h5 style="text-align: left;">Configuration of your browser.</h5>
<div id="result_box" style="text-align: left;" dir="ltr">This is the last step, which is the more easier.</div>
<p style="text-align: justify; padding-left: 30px;">
<p style="text-align: justify;">You must specify your favorite browser where it should exit. Indeed, it should not use the<span style="color: #0000ff;"> <strong><span style="color: #000080;">blue path (1)</span></strong></span><strong> </strong>but the <strong><span style="color: #ff0000;">Red (2)</span></strong>.</p>
<p style="text-align: left; padding-left: 30px;">
<div id="result_box" style="text-align: left;" dir="ltr">We need change address of <strong>Host SOCKS</strong>. This information is generally in the connection settings.</div>
<p style="text-align: left; padding-left: 30px;">
<p style="text-align: left;">For the connection host address specify <strong>127.0.0.1</strong>, which is your PC. And in port, you must specify <strong>9999</strong>, that was informed earlier.</p>
<p style="text-align: left; padding-left: 30px;"><img class="aligncenter size-full wp-image-113" title="proxyconfig" src="http://www.laboit.net/wp-content/uploads/2009/04/proxyconfig.png" alt="proxyconfig" width="400" height="220" /></p>
<p style="text-align: left;">
<p style="text-align: left;">You just have to accept the changes and go to your favorite pages.</p>
<p style="text-align: left;">Remember that if your company has set up a filter is for a good reason. So do not overuse. You are solely responsible for your actions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.laboit.net/2009/05/15/implement-a-http-tunnel-on-a-linux-server/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
