Using Proxychains in JMeter
Tags: java, testing, tutorial, security
Published: 2022-09-09 12:18:22

<!-- wp:paragraph -->
<p><a href="https://youtu.be/lORCJtspVJ4" target="_blank" rel="noreferrer noopener">Remote distributed load testing </a>is one of the performance models used to measure the performance (or latency) of the application under test, as it helps in scaling the test. Performance testing using IP spoofing helps in testing the application from the end-user location simulation. Like any other commercial tools, JMeter also supports distributed load testing fashion, but as an engineer, we need to spend effort for the initial setup. Cloud vendors like <a href="https://youtu.be/lORCJtspVJ4" target="_blank" rel="noreferrer noopener">AWS</a> or <a href="https://qainsights.com/getting-started-with-azure-load-testing/" target="_blank" rel="noreferrer noopener">Azure</a> have their own flavor of distributed load testing model which heavily relies on JMeter on the backend. In this blog post, I am presenting another perspective to measure the performance of the application using Proxychains. </p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Proxychains</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Before we delve into the model, let us try to understand about Proxychains and its semantics, and also about Tor. Though I have been working as a performance engineer for many years. I also spend time learning around cybersecurity. Proxychains is one of the favorite tools for ethical hackers, penetration testers and security experts. It is written in C language. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><em><a href="https://github.com/haad/proxychains" target="_blank" rel="noreferrer noopener">Proxychains</a> is a UNIX program that hooks network-related libc functions in dynamically linked programs via a preloaded DLL and redirects the connections through SOCKS4a/5 or HTTP proxies.</em></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>I know there are a lot of technical terms involved in the above introduction. Simply put, Proxychains helps in bringing anonymity to the system. It is not 100% foolproof system that brings anonymity, but it makes it hard to track.</p>
<!-- /wp:paragraph -->

<!-- wp:verse -->
<pre class="wp-block-verse">This blog is intended for educational purposes only. I am not responsible for any damage you cause. </pre>
<!-- /wp:verse -->

<!-- wp:heading -->
<h2>How Proxychains works?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Proxychains forces any TCP connection to use either TOR or any other SOCKS4 or SOCKS 5 or HTTP(S) proxy. </p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":9740,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2022/09/image-9.png"><img src="https://qainsights.com/wp-content/uploads/2022/09/image-9-1024x425.png" alt="Proxychains" class="wp-image-9740"/></a><figcaption>Proxychains</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Here are the features of Proxychains:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Various chaining options, such as strict, random and dynamic order</li><li>support any application, including nmap, portscan, JMeter and more</li><li>long chains with configurable timeouts.</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>More proxies, you add the latency shoots up.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Using Proxychains in Performance Testing and Engineering</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Proxychains is more of an ethical hacker utility. Why should we use Proxychains for performance testing and engineering? I hear you. Proxychains brings anonymity via TOR or SOCKS and/or HTTP(S) proxy. This can be used to measure the latency of the application during the load testing. Also, it brings the flavor of security (at scale) in performance testing. </p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Setup</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In this demo, let us use Fedora 36 to install Proxychains, Tor, and JMeter. I spun up a basic droplet in <a href="https://qain.si/do" target="_blank" rel="noreferrer noopener">Digital Ocean</a> to install a demo app using nginx. </p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Install Proxychains</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Launch terminal and enter the following commands, which will update and install Proxychains.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>sudo dnf update

sudo dnf install proxychains-ng</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>To verify the installation, enter <code>proxychains</code> in the terminal, which should display its usage.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Install Tor</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In this demo, I intend to use Tor to bring anonymity. But if you would like to use freely available proxy servers, you can configure it in the proxychains conf file, which we will see in a moment. </p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>sudo dnf install tor</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>After installing Tor, start the service and check the status using <code>systemctl</code> commands.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>sudo systemctl start tor

systemctl status tor</code></pre>
<!-- /wp:code -->

<!-- wp:image {"align":"center","id":9744,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2022/09/image-10.png"><img src="https://qainsights.com/wp-content/uploads/2022/09/image-10-1024x375.png" alt="tor status" class="wp-image-9744"/></a><figcaption>tor status</figcaption></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>Proxychains Configuration</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Below are the <code>conf</code> file locations that will be used by proxychains in order.</p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">- ./proxychains.conf
- $(HOME)/.proxychains/proxychains.conf
- /etc/proxychains.conf **</pre>
<!-- /wp:preformatted -->

<!-- wp:paragraph -->
<p>Let us configure the below settings in <code>/etc/proxychains.conf</code>. To make the changes, <code>sudo</code> privilege is required. Enter the below command to open the conf file in <code>vim</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>sudo vim /etc/proxychains.conf</code></pre>
<!-- /wp:code -->

<!-- wp:list {"ordered":true} -->
<ol><li>Enable <code>dynamic_chain</code> property, which uses the proxies chained in the order they appear in the list</li><li>Enable <code>proxy_dns</code> to proxy the DNS requests</li><li>Go to the <code>[ProxyList]</code> section and add the below entries:</li></ol>
<!-- /wp:list -->

<!-- wp:code -->
<pre class="wp-block-code"><code>&#91;ProxyList]
socks4    127.0.0.1 9050
socks5    127.0.0.1 9050</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Save the configuration file and exit.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Test the Proxychains and Tor</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>To quickly smoke test the proxychains and tor, issue the below command, which will display your IP address:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>curl ipinfo.io/ip</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Now let us launch curl with proxychains using the below command. This command will show you the different IP address. Because of the proxy chaining, as the log shows.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>proxychains curl ipinfo.io/ip</code></pre>
<!-- /wp:code -->

<!-- wp:image {"id":9746,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image size-large"><a href="https://qainsights.com/wp-content/uploads/2022/09/image-11.png"><img src="https://qainsights.com/wp-content/uploads/2022/09/image-11-1024x223.png" alt="" class="wp-image-9746"/></a></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>Demo Application Setup</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>As I mentioned earlier, the demo app is running on Digital Ocean droplet. You can install nginx using the below commands:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>sudo dnf install nginx

sudo systemctl start nginx

systemctl status nginx</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Let us watch the nginx logs using the below command, which will display the source IP info if anyone accesses the nginx webpage.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>tail /var/log/nginx/access.log -f</code></pre>
<!-- /wp:code -->

<!-- wp:image {"align":"center","id":9748,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2022/09/image-12-e1662745315567.png"><img src="https://qainsights.com/wp-content/uploads/2022/09/image-12-e1662745315567.png" alt="nginx access logs" class="wp-image-9748"/></a><figcaption>nginx access logs</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>In the above screenshot I blurred my actual IP address. But this is how the access log logs the information about the traffic.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Proxychains in JMeter</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Now let us launch the JMeter using the proxychains command, which launches the JMeter test plan.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>proxychains /usr/bin/apache-jmeter-5.5/bin/jmeter.sh -t ~/jmeter-scripts/Proxychains_Demo.jmx</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Here is the test plan design.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":9749,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2022/09/image-13.png"><img src="https://qainsights.com/wp-content/uploads/2022/09/image-13.png" alt="JMeter Test Plan" class="wp-image-9749"/></a><figcaption>JMeter Test Plan</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Execute the JMeter test plan by clicking on the Run button or pressing <code>Ctrl + R</code> shortcut and observe the nginx access logs.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You will see a different IP address. If you google this IP address, it should be from a totally different country. In my case, it was from Romania. This IP address will be persistent for about 20 minutes. If you execute the test again, you will see a different IP address as source.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":9751,"sizeSlug":"large","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-large"><a href="https://qainsights.com/wp-content/uploads/2022/09/image-14.png"><img src="https://qainsights.com/wp-content/uploads/2022/09/image-14-1024x524.png" alt="" class="wp-image-9751"/></a><figcaption>Proxychains JMeter Test Execution</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>If you execute your load test, the source is from varying locations. Using this approach, you can test the actual (server-side) performance of your application. </p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>More Proxychains</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>We can also chain multiple proxies and use strict chain config. But it will increase the latency further.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>There are free proxies available if you simply search in your favorite search engines. But most of them do not work. You can try your best.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This strategy can be extended in running the JMeter test using remote distributed load testing using multiple worker nodes.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Restricting IP Locations</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>By configuring the entry and exit nodes, it is possible to restricts the IP address of specific countries using the <code>torrc</code> file.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Final Words</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Though the Proxychains is for ethical hacking and penetration testing, it can be used in almost any application. Usage of Proxychains along with Tor, helps in testing the application from a real location with few configuration. Otherwise, the initial setup to run tests like this needs networking knowledge. Consult with your network admin team and validate the settings before you use the above approach in performance testing. </p>
<!-- /wp:paragraph -->