{"id":955,"date":"2016-10-11T09:20:59","date_gmt":"2016-10-11T07:20:59","guid":{"rendered":"http:\/\/www.netnea.com\/cms\/?page_id=955"},"modified":"2025-11-07T11:10:39","modified_gmt":"2025-11-07T10:10:39","slug":"apache-tutorial-12_capturing-and-decrypting-entire-traffic","status":"publish","type":"page","link":"https:\/\/www.netnea.com\/cms\/apache-tutorial-12_capturing-and-decrypting-entire-traffic\/","title":{"rendered":"Capturing and Decrypting the Entire Traffic"},"content":{"rendered":"\n<h2 id=\"capturing-and-decrypting-the-entire-traffic\">Capturing and decrypting the entire traffic<\/h2>\n<h3 id=\"what-are-we-doing\">What are we doing?<\/h3>\n<p>We are capturing the entire HTTP traffic. We will also be decrypting traffic where necessary.<\/p>\n<h3 id=\"why-are-we-doing-this\">Why are we doing this?<\/h3>\n<p>In daily life, when operating a web or reverse proxy server errors occur that can only be handled with difficultly come up again and again. In numerous cases there is a lack of clarity about what has just passed over the line or there is disagreement about exactly which end of communication was responsible for the error. In cases such as these it is important to be able to capture the entire traffic in order to narrow down the error to this basis.<\/p>\n<h3 id=\"requirements\">Requirements<\/h3>\n<ul>\n<li>An Apache web server, ideally one created using the file structure shown in <a href=\"https:\/\/www.netnea.com\/cms\/apache_tutorial_1_apache_compilieren\/\">Tutorial 1 (Compiling an Apache web server)<\/a>.<\/li>\n<li>Understanding of the minimal configuration in <a href=\"https:\/\/www.netnea.com\/cms\/apache_tutorial_2_apache_minimal_konfigurieren\/\">Tutorial 2 (Configuring a minimal Apache server)<\/a>.<\/li>\n<li>An Apache web server with SSL\/TLS support as in <a href=\"https:\/\/www.netnea.com\/cms\/apache-tutorial-4-ssl-server-konfigurieren\">Tutorial 4 (Configuring an SSL server)<\/a><\/li>\n<li>An Apache web server with extended access log as in <a href=\"https:\/\/www.netnea.com\/cms\/apache-tutorial-5-zugriffslog-ausbauen\/\">Tutorial 5 (Extending and analyzing the access log)<\/a><\/li>\n<li>An Apache web server with ModSecurity as in <a href=\"https:\/\/www.netnea.com\/cms\/apache-tutorial-6-modsecurity-einbinden\/\">Tutorial 6 (Embedding ModSecurity)<\/a><\/li>\n<li>An OWASP ModSecurity Core Rule Set installation as in <a href=\"https:\/\/www.netnea.com\/cms\/apache-tutorial-7-modsecurity-core-rules-einbinden\/\">Tutorial 7 (Embedding ModSecurity Core Rules<\/a><\/li>\n<li>A reverse proxy as in <a href=\"https:\/\/www.netnea.com\/cms\/apache-tutorial-9-reverse-proxy-einrichten\/\">Tutorial 9 (Setting up a reverse proxy)<\/a><\/li>\n<\/ul>\n<h3 id=\"step-1-using-modsecurity-to-capture-the-entire-traffic\">Step 1: Using ModSecurity to capture the entire traffic<\/h3>\n<p>In Tutorial 6 we saw how we are able to configure ModSecurity to capture the entire traffic from a single client IP address. However, depending on the settings of the <code>SecAuditLogParts<\/code> directive, not all parts of the requests are recorded. Let\u2019s have a look at the different options in this directive: The ModSecurity audit engine labels different parts of the audit log using different letter abbreviations. They are as follows:<\/p>\n<ul>\n<li>Part A: The starting part of a single entry\/request (required)<\/li>\n<li>Part B: The HTTP request headers<\/li>\n<li>Part C: The HTTP request body (including raw data for a file upload; only if body access was set via <code>SecRequestBodyAccess<\/code>)<\/li>\n<li>Part E: The HTTP response body (only if body access was enabled via <code>SecRequestBodyAccess<\/code>)<\/li>\n<li>Part F: The HTTP response headers (without the two date and server headers, set by Apache itself right before leaving the server)<\/li>\n<li>Part H: Further information from ModSecurity concerning additional information about the request, such as repeated entries in the Apache error log here, the <code>Action<\/code> taken, timing information, etc. It\u2019s worth taking a look.<\/li>\n<li>Part I: The HTTP request body in a space-saving version (uploaded files are not fully included, only individual key parameters for these files)<\/li>\n<li>Part J: Additional information about file uploads<\/li>\n<li>Part K: A list of all rules that returned a positive answer (the rules themselves are normalized; including all inherited declarations)<\/li>\n<li>Part Z: End of a single entry\/request (required)<\/li>\n<\/ul>\n<p>In Tutorial 6 we made the following selection for the individual headers:<\/p>\n<div class=\"sourceCode\" id=\"cb1\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb1-1\"><a href=\"#cb1-1\" aria-hidden=\"true\"><\/a><span class=\"ex\">SecAuditLogParts<\/span>        ABEFHIJKZ<\/span><\/code><\/pre><\/div>\n<p>We have defined a very comprehensive log. This is the right approach in a lab-like setup. However, in a production environment this is only useful in exceptional cases. A typical variation of this directive in a production environment would thus be:<\/p>\n<div class=\"sourceCode\" id=\"cb2\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb2-1\"><a href=\"#cb2-1\" aria-hidden=\"true\"><\/a><span class=\"ex\">SecAuditLogParts<\/span>            ABFHKZ<\/span><\/code><\/pre><\/div>\n<p>The request and response bodies are no longer being captured. This saves a lot of storage space, which is important on badly tuned systems. The parts of the body that violate individual rules are nonetheless written to the error log and in Part K. This is sufficient in most cases. However, from case to case, you will still want to capture the entire body. In cases such as these you can use a <code>ctl<\/code> directive for the action part of the <code>SecRule<\/code>. Multiple, additional parts can be selected via <code>auditLogParts<\/code>:<\/p>\n<div class=\"sourceCode\" id=\"cb3\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb3-1\"><a href=\"#cb3-1\" aria-hidden=\"true\"><\/a><span class=\"ex\">SecRule<\/span> REMOTE_ADDR  <span class=\"st\">&quot;@streq 127.0.0.1&quot;<\/span>   <span class=\"kw\">\\<\/span><\/span>\n<span id=\"cb3-2\"><a href=\"#cb3-2\" aria-hidden=\"true\"><\/a>    <span class=\"st\">&quot;id:10000,phase:1,pass,log,auditlog,msg:&#39;Initializing full traffic log&#39;,ctl:auditLogParts=+EIJ&quot;<\/span><\/span><\/code><\/pre><\/div>\n<h3 id=\"step-2-using-modsecurity-to-write-the-entire-traffic-of-a-single-session\">Step 2: Using ModSecurity to write the entire traffic of a single session<\/h3>\n<p>The first step enables the dynamic modification of audit log parts for a known IP address. But what if we want to permanently enable dynamic logging for selected sessions and, as shown in the example above, expand it to the entire request?<\/p>\n<p>In his ModSecurity Handbook Ivan Risti\u0107 describes an example in which a ModSecurity <code>collection<\/code> is employed to generate a separate session which remains enabled beyond an individual request. We\u2019ll use this idea as the starting point and write a somewhat more complex example:<\/p>\n<div class=\"sourceCode\" id=\"cb4\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb4-1\"><a href=\"#cb4-1\" aria-hidden=\"true\"><\/a><span class=\"ex\">SecRule<\/span> TX:INBOUND_ANOMALY_SCORE  <span class=\"st\">&quot;@ge 5&quot;<\/span> <span class=\"kw\">\\<\/span><\/span>\n<span id=\"cb4-2\"><a href=\"#cb4-2\" aria-hidden=\"true\"><\/a>  <span class=\"st\">&quot;phase:5,pass,id:10001,log,msg:&#39;Logging enabled (High incoming anomaly score)&#39;, \\<\/span><\/span>\n<span id=\"cb4-3\"><a href=\"#cb4-3\" aria-hidden=\"true\"><\/a><span class=\"st\">  expirevar:ip.logflag=600&quot;<\/span><\/span>\n<span id=\"cb4-4\"><a href=\"#cb4-4\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb4-5\"><a href=\"#cb4-5\" aria-hidden=\"true\"><\/a><span class=\"ex\">SecRule<\/span> TX:OUTBOUND_ANOMALY_SCORE <span class=\"st\">&quot;@ge 5&quot;<\/span> <span class=\"kw\">\\<\/span><\/span>\n<span id=\"cb4-6\"><a href=\"#cb4-6\" aria-hidden=\"true\"><\/a>  <span class=\"st\">&quot;phase:5,pass,id:10002,log,msg:&#39;Logging enabled (High outgoing anomaly score)&#39;, \\<\/span><\/span>\n<span id=\"cb4-7\"><a href=\"#cb4-7\" aria-hidden=\"true\"><\/a><span class=\"st\">  expirevar:ip.logflag=600&quot;<\/span><\/span>\n<span id=\"cb4-8\"><a href=\"#cb4-8\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb4-9\"><a href=\"#cb4-9\" aria-hidden=\"true\"><\/a><span class=\"ex\">SecRule<\/span> <span class=\"kw\">&amp;<\/span><span class=\"ex\">IP<\/span>:LOGFLAG               <span class=\"st\">&quot;@eq 1&quot;<\/span> <span class=\"kw\">\\<\/span><\/span>\n<span id=\"cb4-10\"><a href=\"#cb4-10\" aria-hidden=\"true\"><\/a>  <span class=\"st\">&quot;phase:5,pass,id:10003,log,msg:&#39;Logging is enabled. Enforcing rich auditlog.&#39;, \\<\/span><\/span>\n<span id=\"cb4-11\"><a href=\"#cb4-11\" aria-hidden=\"true\"><\/a><span class=\"st\">  ctl:auditEngine=On,ctl:auditLogParts=+EIJ&quot;<\/span><\/span><\/code><\/pre><\/div>\n<p>In the integration of core rules proposed in the preceding tutorials we have already opened a persistent <code>collection<\/code> based on the IP address of the client making the request. The <code>collection<\/code> which is stored beyond an individual request is suitable for retaining data between different requests.<\/p>\n<p>We\u2019ll use this ability to check its <code>core rules anomaly score<\/code> in the logging phase of the request. If it is 5 or higher (corresponding to an alarm or the <code>critical<\/code> level), we set the variable <code>ip.logflag<\/code> and via <code>expirevar<\/code> give it an expiration of 600 seconds. This means that this variable remains in the <code>IP collection<\/code> for ten minutes and then disappears on its own automatically. This mechanism is repeated for the <code>outgoing anomaly score<\/code> in the subsequent rule.<\/p>\n<p>In the third rule we check whether this <code>Logflag<\/code> is set. We earlier saw a wondrous transformation of variable names depending on application in <code>ModSecurity<\/code>. We are seeing it again here, in which <code>ip.logflag<\/code> must be written in a <code>SecRule<\/code> as the variable <code>IP:LOGFLAG<\/code>. We have also become familiar with the <code>&amp;<\/code> at the beginning: It denotes the number of variables of this name (0 or 1). This means we can check for the presence of <code>ip.logflag<\/code>. If the flag is previously set in both rules or at an earlier point in time in the past 10 minutes, then the audit engine is enabled and parts of the log that are not always set in the default configuration are added.<\/p>\n<p>Forcing the audit log, which we have not yet become familiar with, is required, because we want to log requests that don\u2019t actually violate any of the rules. This means that the audit log is not yet enabled for the request. We make up for this with this rule.<\/p>\n<p>Altogether, these three rules enable us to precisely monitor a conspicuous client beyond an individual suspicious request and to capture the entire client traffic in the audit log once suspicion has been aroused.<\/p>\n<h3 id=\"step-3-sniffing-client-traffic-with-the-serverreverse-proxy\">Step 3: Sniffing client traffic with the server\/reverse proxy<\/h3>\n<p>Traffic between the client and the reverse proxy can normally be well documented using the methods described. In addition, we have the option of documenting traffic on the client. Modern browsers provide options for this and they all seem adequate to me. In practice however there are complications that can make capturing traffic difficult or impossible. Be it a fat client being used outside a browser, the client being used only on a mobile device with an interposed proxy modifying traffic in one direction or the other in such a way that traffic is being modified once more by another module after leaving ModSecurity or that ModSecurity has no access to traffic whatsoever. In individual cases the latter is actually a problem, because an Apache module can abort the processing of a request and suppress access from ModSecurity by doing so.<\/p>\n<p>In these cases one option is to interpose a separate proxy to capture the traffic. A number of tools are available. <code>mitmproxy<\/code>, in particular, appears to have some very interesting features and I use it to great effect. But because the development of this software is still very dynamic, installation of the current version can be quite demanding, which is why I won\u2019t be going into any of the details here. We\u2019ll select a somewhat rougher method.<\/p>\n<p>It is therefore possible for entries in the audit log to not match what was received by the client or no longer match what the client originally sent. In these cases it is preferable to selectively capture the actual traffic and decrypt the encrypted data. This suggestion, however, runs up against the strong encryption we configured in the fourth tutorial to secure it from snooping. The ciphers we prefer rely on <code>forward secrecy<\/code> for this. This means that a snooper is foiled in such a way that even possession of the long-term asymmetric SSL key pair no longer permits snooping. But this also means that no capturing of the traffic of any kind is possible between the client and the server unless we position a process in between that terminates the connection and presents a separate certificate to the client.<\/p>\n<p>In all other cases in which we want to force decryption, but are unable to reconfigure the client, we have to employ a different, weaker type of encryption which is unaware of <code>forward secrecy<\/code>. Something like the <code>AES256-SHA<\/code> cipher which we defined as the only cipher on the client and use to connect to the server. If we are unable to use the cipher on the client side, then we have to weaken encryption on the entire server. It\u2019s immediately obvious that this is not desired and is only useful in a few instances. Be it us binding the client to a separate system or putting a time limit on reconfiguration.<\/p>\n<p>As a test, Apache can also be configured using conditional <code>&lt;if&gt;<\/code> directives, presenting another cipher to an individual client. However, this will only work via <code>SSL renegotiate<\/code>. This means that an SSL handshake was carried out using <code>forward secrecy<\/code>, but it was then repeated with a weaker cipher. However, in my tests the commonly used decryption tools <code>wireshark<\/code> and <code>ssldump<\/code> were unable to handle this method. This means switching the server over to weaker encryption for the moment. In terms of security, I strong advise against relying on this variation until all other means have been exhausted.<\/p>\n<p>In the fourth tutorial we operated the local Laboratory Service using the local <code>snake-oil<\/code> key. We are going to use this certificate once more and instruct the server to use the decryptable <code>AES256-SHA<\/code> cipher.<\/p>\n<div class=\"sourceCode\" id=\"cb5\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb5-1\"><a href=\"#cb5-1\" aria-hidden=\"true\"><\/a>    <span class=\"ex\">...<\/span><\/span>\n<span id=\"cb5-2\"><a href=\"#cb5-2\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb5-3\"><a href=\"#cb5-3\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb5-4\"><a href=\"#cb5-4\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">SSLCertificateKeyFile<\/span>  \/etc\/ssl\/private\/ssl-cert-snakeoil.key<\/span>\n<span id=\"cb5-5\"><a href=\"#cb5-5\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">SSLCertificateFile<\/span>   \/etc\/ssl\/certs\/ssl-cert-snakeoil.pem<\/span>\n<span id=\"cb5-6\"><a href=\"#cb5-6\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb5-7\"><a href=\"#cb5-7\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">SSLProtocol<\/span>             All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1<\/span>\n<span id=\"cb5-8\"><a href=\"#cb5-8\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">SSLCipherSuite<\/span>          <span class=\"st\">&#39;AES256-SHA&#39;<\/span><\/span>\n<span id=\"cb5-9\"><a href=\"#cb5-9\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">SSLHonorCipherOrder<\/span>     On<\/span>\n<span id=\"cb5-10\"><a href=\"#cb5-10\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb5-11\"><a href=\"#cb5-11\" aria-hidden=\"true\"><\/a>    <span class=\"ex\">...<\/span><\/span><\/code><\/pre><\/div>\n<h3 id=\"step-4-capturing-encrypted-traffic-between-the-client-and-the-serverreverse-proxy\">Step 4: Capturing encrypted traffic between the client and the server\/reverse proxy<\/h3>\n<p>The explanations above set the stage for capturing and then decrypting traffic. We\u2019ll be doing it in two steps, first logging the traffic and then decrypting the log. Capturing is also called <code>pulling a PCAP<\/code>. This means we are providing a <code>PCAP<\/code> file, or a network traffic log in <code>PCAP<\/code> format. <code>PCAP<\/code> means <code>packet capture<\/code>. For this we\u2019ll either be using the most widespread tool, <code>tcpdump<\/code>, or <code>tshark<\/code> from the <code>Wireshark<\/code> suite. It is also possible to work right away in the <code>Wireshark<\/code> graphical interface.<\/p>\n<div class=\"sourceCode\" id=\"cb6\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb6-1\"><a href=\"#cb6-1\" aria-hidden=\"true\"><\/a>$<span class=\"op\">&gt;<\/span> <span class=\"fu\">sudo<\/span> tcpdump -i lo -w \/tmp\/localhost-port443.pcap -s0 port 443<\/span>\n<span id=\"cb6-2\"><a href=\"#cb6-2\" aria-hidden=\"true\"><\/a><span class=\"ex\">tcpdump<\/span>: listening on lo, link-type EN10MB (Ethernet), <span class=\"ex\">capture<\/span> size 65535 bytes<\/span>\n<span id=\"cb6-3\"><a href=\"#cb6-3\" aria-hidden=\"true\"><\/a><span class=\"ex\">...<\/span><\/span><\/code><\/pre><\/div>\n<p>Alternatively:<\/p>\n<div class=\"sourceCode\" id=\"cb7\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb7-1\"><a href=\"#cb7-1\" aria-hidden=\"true\"><\/a>$<span class=\"op\">&gt;<\/span> <span class=\"fu\">sudo<\/span> tshark -i lo -w \/tmp\/localhost-port443.pcap -s0 port 443<\/span>\n<span id=\"cb7-2\"><a href=\"#cb7-2\" aria-hidden=\"true\"><\/a><span class=\"ex\">tshark<\/span>: Lua: Error during loading:<\/span>\n<span id=\"cb7-3\"><a href=\"#cb7-3\" aria-hidden=\"true\"><\/a> [<span class=\"ex\">string<\/span> <span class=\"st\">&quot;\/usr\/share\/wireshark\/init.lua&quot;<\/span>]:46: dofile has been disabled due to running Wireshark as ...<\/span>\n<span id=\"cb7-4\"><a href=\"#cb7-4\" aria-hidden=\"true\"><\/a><span class=\"ex\">Running<\/span> as user <span class=\"st\">&quot;root&quot;<\/span> and group <span class=\"st\">&quot;root&quot;<\/span>. This could be dangerous.<\/span>\n<span id=\"cb7-5\"><a href=\"#cb7-5\" aria-hidden=\"true\"><\/a><span class=\"ex\">Capturing<\/span> on <span class=\"st\">&#39;Loopback&#39;<\/span><\/span>\n<span id=\"cb7-6\"><a href=\"#cb7-6\" aria-hidden=\"true\"><\/a><span class=\"ex\">...<\/span><\/span><\/code><\/pre><\/div>\n<p>Here, the two commands that generate an identical log have been instructed to listen to the local <code>lo<\/code> interface and port 443 and to write to the file <code>localhost-port443.pcap<\/code>. The <code>-s0<\/code> option is important. This is referred to as the <code>snap length<\/code> or <code>capture size<\/code>. This indicates exactly how much data to capture from an IP packet. In our case we want the entire packet. The instruction for this is the value 0, which means everything.<\/p>\n<p>These commands are used to start the log and we can now trigger the traffic in a second window. Let\u2019s give it a try using <code>curl<\/code>:<\/p>\n<div class=\"sourceCode\" id=\"cb8\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb8-1\"><a href=\"#cb8-1\" aria-hidden=\"true\"><\/a>$<span class=\"op\">&gt;<\/span> <span class=\"ex\">curl<\/span> -v --ciphers AES256-SHA -k https:\/\/127.0.0.1:443\/index.html<\/span>\n<span id=\"cb8-2\"><a href=\"#cb8-2\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> Rebuilt URL to: https:\/\/localhost:443\/<\/span>\n<span id=\"cb8-3\"><a href=\"#cb8-3\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span>   Trying 127.0.0.1...<\/span>\n<span id=\"cb8-4\"><a href=\"#cb8-4\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> Connected to localhost (127.0.0.1) <span class=\"ex\">port<\/span> 443 (#0)<\/span>\n<span id=\"cb8-5\"><a href=\"#cb8-5\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> found 173 certificates in \/etc\/ssl\/certs\/ca-certificates.crt<\/span>\n<span id=\"cb8-6\"><a href=\"#cb8-6\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> found 697 certificates in \/etc\/ssl\/certs<\/span>\n<span id=\"cb8-7\"><a href=\"#cb8-7\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> ALPN, offering http\/1.1<\/span>\n<span id=\"cb8-8\"><a href=\"#cb8-8\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> SSL connection using TLS1.2 \/ RSA_AES_256_CBC_SHA1<\/span>\n<span id=\"cb8-9\"><a href=\"#cb8-9\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span>        server certificate verification SKIPPED<\/span>\n<span id=\"cb8-10\"><a href=\"#cb8-10\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span>        server certificate status verification SKIPPED<\/span>\n<span id=\"cb8-11\"><a href=\"#cb8-11\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span>        common name: ubuntu (does not match <span class=\"st\">&#39;localhost&#39;<\/span>)<\/span>\n<span id=\"cb8-12\"><a href=\"#cb8-12\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span>        server certificate expiration date OK<\/span>\n<span id=\"cb8-13\"><a href=\"#cb8-13\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span>        server certificate activation date OK<\/span>\n<span id=\"cb8-14\"><a href=\"#cb8-14\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span>        certificate public key: RSA<\/span>\n<span id=\"cb8-15\"><a href=\"#cb8-15\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span>        certificate version: #3<\/span>\n<span id=\"cb8-16\"><a href=\"#cb8-16\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span>        subject: CN=ubuntu<\/span>\n<span id=\"cb8-17\"><a href=\"#cb8-17\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span>        start date: Mon, 27 Feb 2017 20:46:21 GMT<\/span>\n<span id=\"cb8-18\"><a href=\"#cb8-18\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span>        expire date: Thu, 25 Feb 2027 20:46:21 GMT<\/span>\n<span id=\"cb8-19\"><a href=\"#cb8-19\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span>        issuer: CN=ubuntu<\/span>\n<span id=\"cb8-20\"><a href=\"#cb8-20\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span>        compression: NULL<\/span>\n<span id=\"cb8-21\"><a href=\"#cb8-21\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> ALPN, server accepted to use http\/1.1<\/span>\n<span id=\"cb8-22\"><a href=\"#cb8-22\" aria-hidden=\"true\"><\/a><span class=\"ex\">...<\/span><\/span><\/code><\/pre><\/div>\n<p>If the response we wanted was returned by the server, we can quit the log using <code>CTRL-c<\/code> in the <code>sniffing<\/code> window.<\/p>\n<div class=\"sourceCode\" id=\"cb9\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb9-1\"><a href=\"#cb9-1\" aria-hidden=\"true\"><\/a>$<span class=\"op\">&gt;<\/span> <span class=\"fu\">sudo<\/span> tcpdump -i lo -w \/tmp\/localhost-port443.pcap -s0 port 443<\/span>\n<span id=\"cb9-2\"><a href=\"#cb9-2\" aria-hidden=\"true\"><\/a><span class=\"ex\">tcpdump<\/span>: listening on lo, link-type EN10MB (Ethernet), <span class=\"ex\">capture<\/span> size 65535 bytes<\/span>\n<span id=\"cb9-3\"><a href=\"#cb9-3\" aria-hidden=\"true\"><\/a>^<span class=\"ex\">C15<\/span> packets captured<\/span>\n<span id=\"cb9-4\"><a href=\"#cb9-4\" aria-hidden=\"true\"><\/a><span class=\"ex\">30<\/span> packets received by filter<\/span>\n<span id=\"cb9-5\"><a href=\"#cb9-5\" aria-hidden=\"true\"><\/a><span class=\"ex\">0<\/span> packets dropped by kernel<\/span><\/code><\/pre><\/div>\n<h3 id=\"step-5-decrypting-traffic\">Step 5: Decrypting traffic<\/h3>\n<p>Let\u2019s try to decrypt the <code>PCAP<\/code> file. We\u2019ll again be using <code>tshark<\/code> from the <code>Wireshark<\/code> suite. The <code>GUI<\/code> also works, but is less comfortable. What\u2019s important now is to pass the key we used on the server to the tool.<\/p>\n<div class=\"sourceCode\" id=\"cb10\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb10-1\"><a href=\"#cb10-1\" aria-hidden=\"true\"><\/a>$<span class=\"op\">&gt;<\/span> <span class=\"fu\">sudo<\/span> tshark -r \/tmp\/localhost-port443.pcap -o <span class=\"st\">&quot;ssl.desegment_ssl_records: TRUE&quot;<\/span> <span class=\"kw\">\\<\/span><\/span>\n<span id=\"cb10-2\"><a href=\"#cb10-2\" aria-hidden=\"true\"><\/a><span class=\"ex\">-o<\/span> <span class=\"st\">&quot;ssl.desegment_ssl_application_data: TRUE&quot;<\/span> <span class=\"kw\">\\<\/span><\/span>\n<span id=\"cb10-3\"><a href=\"#cb10-3\" aria-hidden=\"true\"><\/a><span class=\"ex\">-o<\/span> <span class=\"st\">&quot;ssl.keys_list: 0.0.0.0,443,http,\/etc\/ssl\/private\/ssl-cert-snakeoil.key&quot;<\/span> <span class=\"kw\">\\<\/span><\/span>\n<span id=\"cb10-4\"><a href=\"#cb10-4\" aria-hidden=\"true\"><\/a><span class=\"ex\">-o<\/span> <span class=\"st\">&quot;ssl.debug_file: \/tmp\/ssl-debug.log&quot;<\/span><\/span>\n<span id=\"cb10-5\"><a href=\"#cb10-5\" aria-hidden=\"true\"><\/a><span class=\"ex\">Running<\/span> as user <span class=\"st\">&quot;root&quot;<\/span> and group <span class=\"st\">&quot;root&quot;<\/span>. This could be dangerous.<\/span>\n<span id=\"cb10-6\"><a href=\"#cb10-6\" aria-hidden=\"true\"><\/a>  <span class=\"ex\">1<\/span>   0.000000    127.0.0.1 -<span class=\"op\">&gt;<\/span> 127.0.0.1    TCP 74 33517 <span class=\"op\">&gt;<\/span> https [SYN] Seq=0 Win=43690 Len=0 MSS=65495 \u2026<\/span>\n<span id=\"cb10-7\"><a href=\"#cb10-7\" aria-hidden=\"true\"><\/a>  <span class=\"ex\">2<\/span>   0.000040    127.0.0.1 -<span class=\"op\">&gt;<\/span> 127.0.0.1    TCP 74 https <span class=\"op\">&gt;<\/span> 33517 [SYN, ACK] Seq=0 Ack=1 Win=43690 Len=0 \u2026 <\/span>\n<span id=\"cb10-8\"><a href=\"#cb10-8\" aria-hidden=\"true\"><\/a>  <span class=\"ex\">3<\/span>   0.000088    127.0.0.1 -<span class=\"op\">&gt;<\/span> 127.0.0.1    TCP 66 33517 <span class=\"op\">&gt;<\/span> https [ACK] Seq=1 Ack=1 Win=43776 Len=0 \u2026<\/span>\n<span id=\"cb10-9\"><a href=\"#cb10-9\" aria-hidden=\"true\"><\/a>  <span class=\"ex\">4<\/span>   0.001381    127.0.0.1 -<span class=\"op\">&gt;<\/span> 127.0.0.1    SSL 161 Client Hello<\/span>\n<span id=\"cb10-10\"><a href=\"#cb10-10\" aria-hidden=\"true\"><\/a>  <span class=\"ex\">5<\/span>   0.001470    127.0.0.1 -<span class=\"op\">&gt;<\/span> 127.0.0.1    TCP 66 https <span class=\"op\">&gt;<\/span> 33517 [ACK] Seq=1 Ack=96 Win=43776 Len=0 \u2026<\/span>\n<span id=\"cb10-11\"><a href=\"#cb10-11\" aria-hidden=\"true\"><\/a>  <span class=\"ex\">6<\/span>   0.002338    127.0.0.1 -<span class=\"op\">&gt;<\/span> 127.0.0.1    TLSv1.2 865 Server Hello, Certificate, Server Hello Done<\/span>\n<span id=\"cb10-12\"><a href=\"#cb10-12\" aria-hidden=\"true\"><\/a>  <span class=\"ex\">7<\/span>   0.002417    127.0.0.1 -<span class=\"op\">&gt;<\/span> 127.0.0.1    TCP 66 33517 <span class=\"op\">&gt;<\/span> https [ACK] Seq=96 Ack=800 Win=45312 Len=0\u2026 <\/span>\n<span id=\"cb10-13\"><a href=\"#cb10-13\" aria-hidden=\"true\"><\/a>  <span class=\"ex\">8<\/span>   0.004330    127.0.0.1 -<span class=\"op\">&gt;<\/span> 127.0.0.1    TLSv1.2 408 Client Key Exchange, Change Cipher Spec, Finished<\/span>\n<span id=\"cb10-14\"><a href=\"#cb10-14\" aria-hidden=\"true\"><\/a>  <span class=\"ex\">9<\/span>   0.018200    127.0.0.1 -<span class=\"op\">&gt;<\/span> 127.0.0.1    TLSv1.2 141 Change Cipher Spec, Finished<\/span>\n<span id=\"cb10-15\"><a href=\"#cb10-15\" aria-hidden=\"true\"><\/a> <span class=\"ex\">10<\/span>   0.019624    127.0.0.1 -<span class=\"op\">&gt;<\/span> 127.0.0.1    TLSv1.2 199 Application Data<\/span>\n<span id=\"cb10-16\"><a href=\"#cb10-16\" aria-hidden=\"true\"><\/a> <span class=\"ex\">11<\/span>   0.028515    127.0.0.1 -<span class=\"op\">&gt;<\/span> 127.0.0.1    TLSv1.2 428 Application Data, Application Data<\/span>\n<span id=\"cb10-17\"><a href=\"#cb10-17\" aria-hidden=\"true\"><\/a> <span class=\"ex\">12<\/span>   0.029827    127.0.0.1 -<span class=\"op\">&gt;<\/span> 127.0.0.1    TLSv1.2 119 Alert (Level: Warning, Description: Close Notify)<\/span>\n<span id=\"cb10-18\"><a href=\"#cb10-18\" aria-hidden=\"true\"><\/a> <span class=\"ex\">13<\/span>   0.030056    127.0.0.1 -<span class=\"op\">&gt;<\/span> 127.0.0.1    TCP 66 33517 <span class=\"op\">&gt;<\/span> https [FIN, ACK] Seq=624 Ack=1237 Win=46976 \u2026<\/span>\n<span id=\"cb10-19\"><a href=\"#cb10-19\" aria-hidden=\"true\"><\/a> <span class=\"ex\">14<\/span>   0.037327    127.0.0.1 -<span class=\"op\">&gt;<\/span> 127.0.0.1    TLSv1.2 119 Alert (Level: Warning, Description: Close Notify)<\/span>\n<span id=\"cb10-20\"><a href=\"#cb10-20\" aria-hidden=\"true\"><\/a> <span class=\"ex\">15<\/span>   0.037417    127.0.0.1 -<span class=\"op\">&gt;<\/span> 127.0.0.1    TCP 54 33517 <span class=\"op\">&gt;<\/span> https [RST] Seq=625 Win=0 Len=0<\/span><\/code><\/pre><\/div>\n<p>Not much is legible here yet. But when we look into the <code>debug file<\/code>, then we see the traffic in it.<\/p>\n<div class=\"sourceCode\" id=\"cb11\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb11-1\"><a href=\"#cb11-1\" aria-hidden=\"true\"><\/a>$<span class=\"op\">&gt;<\/span> <span class=\"fu\">cat<\/span> \/tmp\/ssl-debug.log<\/span>\n<span id=\"cb11-2\"><a href=\"#cb11-2\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb11-3\"><a href=\"#cb11-3\" aria-hidden=\"true\"><\/a><span class=\"ex\">Wireshark<\/span> SSL debug log <\/span>\n<span id=\"cb11-4\"><a href=\"#cb11-4\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb11-5\"><a href=\"#cb11-5\" aria-hidden=\"true\"><\/a><span class=\"ex\">Private<\/span> key imported: KeyID bb:70:71:21:26:c6:6f:79:82:93:1a:08:ab:f9:db:1f:...<\/span>\n<span id=\"cb11-6\"><a href=\"#cb11-6\" aria-hidden=\"true\"><\/a><span class=\"ex\">ssl_load_key<\/span>: swapping p and q parameters and recomputing u<\/span>\n<span id=\"cb11-7\"><a href=\"#cb11-7\" aria-hidden=\"true\"><\/a><span class=\"ex\">ssl_init<\/span> IPv4 addr <span class=\"st\">&#39;127.0.0.1&#39;<\/span> (127.0.0.1) <span class=\"ex\">port<\/span> <span class=\"st\">&#39;443&#39;<\/span> filename <span class=\"st\">&#39;\/etc\/ssl\/private\/ssl-cert-snakeoil.key&#39;<\/span> \u2026<\/span>\n<span id=\"cb11-8\"><a href=\"#cb11-8\" aria-hidden=\"true\"><\/a><span class=\"ex\">password<\/span>(only for p12 file) <span class=\"st\">&#39;&#39;<\/span><\/span>\n<span id=\"cb11-9\"><a href=\"#cb11-9\" aria-hidden=\"true\"><\/a><span class=\"ex\">ssl_init<\/span> private key file \/etc\/ssl\/private\/ssl-cert-snakeoil.key successfully loaded.<\/span>\n<span id=\"cb11-10\"><a href=\"#cb11-10\" aria-hidden=\"true\"><\/a><span class=\"ex\">association_add<\/span> TCP port 443 protocol http handle 0x1af0f10<\/span>\n<span id=\"cb11-11\"><a href=\"#cb11-11\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb11-12\"><a href=\"#cb11-12\" aria-hidden=\"true\"><\/a><span class=\"ex\">dissect_ssl<\/span> enter frame #4 (first time)<\/span>\n<span id=\"cb11-13\"><a href=\"#cb11-13\" aria-hidden=\"true\"><\/a><span class=\"ex\">ssl_session_init<\/span>: initializing ptr 0x7f0044d42438 size 688<\/span>\n<span id=\"cb11-14\"><a href=\"#cb11-14\" aria-hidden=\"true\"><\/a>  <span class=\"ex\">conversation<\/span> = 0x7f0044d41e98, ssl_session = 0x7f0044d42438<\/span>\n<span id=\"cb11-15\"><a href=\"#cb11-15\" aria-hidden=\"true\"><\/a>  <span class=\"ex\">record<\/span>: offset = 0, reported_length_remaining = 95<\/span>\n<span id=\"cb11-16\"><a href=\"#cb11-16\" aria-hidden=\"true\"><\/a><span class=\"ex\">dissect_ssl3_record<\/span>: content_type 22 Handshake<\/span>\n<span id=\"cb11-17\"><a href=\"#cb11-17\" aria-hidden=\"true\"><\/a><span class=\"ex\">decrypt_ssl3_record<\/span>: app_data len 90, ssl state 0x00<\/span>\n<span id=\"cb11-18\"><a href=\"#cb11-18\" aria-hidden=\"true\"><\/a><span class=\"ex\">association_find<\/span>: TCP port 33517 found (nil)<\/span>\n<span id=\"cb11-19\"><a href=\"#cb11-19\" aria-hidden=\"true\"><\/a><span class=\"ex\">packet_from_server<\/span>: is from server - FALSE<\/span>\n<span id=\"cb11-20\"><a href=\"#cb11-20\" aria-hidden=\"true\"><\/a><span class=\"ex\">decrypt_ssl3_record<\/span>: using client decoder<\/span>\n<span id=\"cb11-21\"><a href=\"#cb11-21\" aria-hidden=\"true\"><\/a><span class=\"ex\">decrypt_ssl3_record<\/span>: no decoder available<\/span>\n<span id=\"cb11-22\"><a href=\"#cb11-22\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb11-23\"><a href=\"#cb11-23\" aria-hidden=\"true\"><\/a><span class=\"ex\">...<\/span><\/span>\n<span id=\"cb11-24\"><a href=\"#cb11-24\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb11-25\"><a href=\"#cb11-25\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb11-26\"><a href=\"#cb11-26\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb11-27\"><a href=\"#cb11-27\" aria-hidden=\"true\"><\/a><span class=\"ex\">ssl_generate_keyring_material<\/span> ssl_create_decoder(client)<\/span>\n<span id=\"cb11-28\"><a href=\"#cb11-28\" aria-hidden=\"true\"><\/a><span class=\"ex\">ssl_create_decoder<\/span> CIPHER: AES256<\/span>\n<span id=\"cb11-29\"><a href=\"#cb11-29\" aria-hidden=\"true\"><\/a><span class=\"ex\">decoder<\/span> initialized (digest len 20)<\/span>\n<span id=\"cb11-30\"><a href=\"#cb11-30\" aria-hidden=\"true\"><\/a><span class=\"ex\">ssl_generate_keyring_material<\/span> ssl_create_decoder(server)<\/span>\n<span id=\"cb11-31\"><a href=\"#cb11-31\" aria-hidden=\"true\"><\/a><span class=\"ex\">ssl_create_decoder<\/span> CIPHER: AES256<\/span>\n<span id=\"cb11-32\"><a href=\"#cb11-32\" aria-hidden=\"true\"><\/a><span class=\"ex\">decoder<\/span> initialized (digest len 20)<\/span>\n<span id=\"cb11-33\"><a href=\"#cb11-33\" aria-hidden=\"true\"><\/a><span class=\"ex\">ssl_generate_keyring_material<\/span>: client seq 0, server seq 0<\/span>\n<span id=\"cb11-34\"><a href=\"#cb11-34\" aria-hidden=\"true\"><\/a><span class=\"ex\">ssl_save_session<\/span> stored session id[0]:<\/span>\n<span id=\"cb11-35\"><a href=\"#cb11-35\" aria-hidden=\"true\"><\/a><span class=\"ex\">ssl_save_session<\/span> stored master secret[48]:<\/span>\n<span id=\"cb11-36\"><a href=\"#cb11-36\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb11-37\"><a href=\"#cb11-37\" aria-hidden=\"true\"><\/a><span class=\"ex\">...<\/span><\/span>\n<span id=\"cb11-38\"><a href=\"#cb11-38\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb11-39\"><a href=\"#cb11-39\" aria-hidden=\"true\"><\/a><span class=\"ex\">ssl_decrypt_record<\/span>: allocating 160 bytes for decrypt data (old len 96)<\/span>\n<span id=\"cb11-40\"><a href=\"#cb11-40\" aria-hidden=\"true\"><\/a><span class=\"ex\">Plaintext<\/span>[128]:<\/span>\n<span id=\"cb11-41\"><a href=\"#cb11-41\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">db<\/span> 2f 9e 70 d4 79 7e 51 18 a7 6e 32 1f 95 8f b6 <span class=\"kw\">|<\/span><span class=\"ex\">.<\/span>\/<span class=\"ex\">.p.y<\/span>~Q..n2....<span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-42\"><a href=\"#cb11-42\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">47<\/span> 45 54 20 2f 69 6e 64 65 78 2e 68 74 6d 6c 20 <span class=\"kw\">|<\/span><span class=\"ex\">GET<\/span> \/index.html <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-43\"><a href=\"#cb11-43\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">48<\/span> 54 54 50 2f 31 2e 31 0d 0a 55 73 65 72 2d 41 <span class=\"kw\">|<\/span><span class=\"ex\">HTTP<\/span>\/<span class=\"ex\">1.1..User-A<\/span><span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-44\"><a href=\"#cb11-44\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">67<\/span> 65 6e 74 3a 20 63 75 72 6c 2f 37 2e 33 35 2e <span class=\"kw\">|<\/span><span class=\"ex\">gent<\/span>: curl\/7.35.<span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-45\"><a href=\"#cb11-45\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">30<\/span> 0d 0a 48 6f 73 74 3a 20 31 32 37 2e 30 2e 30 <span class=\"kw\">|<\/span><span class=\"ex\">0..Host<\/span>: 127.0.0<span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-46\"><a href=\"#cb11-46\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">2e<\/span> 31 0d 0a 41 63 63 65 70 74 3a 20 2a 2f 2a 0d <span class=\"kw\">|<\/span><span class=\"ex\">.1..Accept<\/span>: *\/*.<span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-47\"><a href=\"#cb11-47\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">0a<\/span> 0d 0a 96 42 bc 7a 70 a9 e1 8c b7 38 00 cc ca <span class=\"kw\">|<\/span><span class=\"ex\">....B.zp....8...<\/span><span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-48\"><a href=\"#cb11-48\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">6a<\/span> 90 e9 08 9c d5 b9 08 08 08 08 08 08 08 08 08 <span class=\"kw\">|<\/span><span class=\"ex\">j...............<\/span><span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-49\"><a href=\"#cb11-49\" aria-hidden=\"true\"><\/a><span class=\"ex\">ssl_decrypt_record<\/span> found padding 8 final len 119<\/span>\n<span id=\"cb11-50\"><a href=\"#cb11-50\" aria-hidden=\"true\"><\/a><span class=\"ex\">checking<\/span> mac (len 83, version 303, ct 23 seq 1)<\/span>\n<span id=\"cb11-51\"><a href=\"#cb11-51\" aria-hidden=\"true\"><\/a><span class=\"ex\">tls_check_mac<\/span> mac type:SHA1 md 2<\/span>\n<span id=\"cb11-52\"><a href=\"#cb11-52\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb11-53\"><a href=\"#cb11-53\" aria-hidden=\"true\"><\/a><span class=\"ex\">...<\/span><\/span>\n<span id=\"cb11-54\"><a href=\"#cb11-54\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb11-55\"><a href=\"#cb11-55\" aria-hidden=\"true\"><\/a><span class=\"ex\">Plaintext<\/span>[256]:<\/span>\n<span id=\"cb11-56\"><a href=\"#cb11-56\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">f1<\/span> 0b 2a 1a bc 28 29 32 cf 40 98 6b 65 7f f0 a4 <span class=\"kw\">|<\/span><span class=\"ex\">..*..<\/span>()<span class=\"ex\">2.@.ke...<\/span><span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-57\"><a href=\"#cb11-57\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">48<\/span> 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d <span class=\"kw\">|<\/span><span class=\"ex\">HTTP\/1.1<\/span> 200 OK.<span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-58\"><a href=\"#cb11-58\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">0a<\/span> 44 61 74 65 3a 20 57 65 64 2c 20 30 32 20 4d <span class=\"kw\">|<\/span><span class=\"ex\">.Date<\/span>: Wed, 02 M<span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-59\"><a href=\"#cb11-59\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">61<\/span> 72 20 32 30 31 36 20 31 31 3a 31 35 3a 30 34 <span class=\"kw\">|<\/span><span class=\"fu\">ar<\/span> 2016 11:15:04<span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-60\"><a href=\"#cb11-60\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">20<\/span> 47 4d 54 0d 0a 53 65 72 76 65 72 3a 20 41 70 <span class=\"kw\">|<\/span> <span class=\"ex\">GMT..Server<\/span>: Ap<span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-61\"><a href=\"#cb11-61\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">61<\/span> 63 68 65 0d 0a 4c 61 73 74 2d 4d 6f 64 69 66 <span class=\"kw\">|<\/span><span class=\"ex\">ache..Last-Modif<\/span><span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-62\"><a href=\"#cb11-62\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">69<\/span> 65 64 3a 20 4d 6f 6e 2c 20 31 31 20 4a 75 6e <span class=\"kw\">|<\/span><span class=\"ex\">ied<\/span>: Mon, 11 Jun<span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-63\"><a href=\"#cb11-63\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">20<\/span> 32 30 30 37 20 31 38 3a 35 33 3a 31 34 20 47 <span class=\"kw\">|<\/span> <span class=\"ex\">2007<\/span> 18:53:14 G<span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-64\"><a href=\"#cb11-64\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">4d<\/span> 54 0d 0a 45 54 61 67 3a 20 22 32 64 2d 34 33 <span class=\"kw\">|<\/span><span class=\"ex\">MT..ETag<\/span>: <span class=\"st\">&quot;2d-43|<\/span><\/span>\n<span id=\"cb11-65\"><a href=\"#cb11-65\" aria-hidden=\"true\"><\/a><span class=\"st\">| 32 61 35 65 34 61 37 33 61 38 30 22 0d 0a 41 63 |2a5e4a73a80&quot;<\/span>..Ac<span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-66\"><a href=\"#cb11-66\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">63<\/span> 65 70 74 2d 52 61 6e 67 65 73 3a 20 62 79 74 <span class=\"kw\">|<\/span><span class=\"ex\">cept-Ranges<\/span>: byt<span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-67\"><a href=\"#cb11-67\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">65<\/span> 73 0d 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 <span class=\"kw\">|<\/span><span class=\"ex\">es..Content-Leng<\/span><span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-68\"><a href=\"#cb11-68\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">74<\/span> 68 3a 20 34 35 0d 0a 43 6f 6e 74 65 6e 74 2d <span class=\"kw\">|<\/span><span class=\"ex\">th<\/span>: 45..Content-<span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-69\"><a href=\"#cb11-69\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">54<\/span> 79 70 65 3a 20 74 65 78 74 2f 68 74 6d 6c 0d <span class=\"kw\">|<\/span><span class=\"ex\">Type<\/span>: text\/html.<span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-70\"><a href=\"#cb11-70\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">0a<\/span> 0d 0a 48 d5 2d 0c 88 7a b8 8c 31 8a d1 97 cc <span class=\"kw\">|<\/span><span class=\"ex\">...H.-..z..1....<\/span><span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-71\"><a href=\"#cb11-71\" aria-hidden=\"true\"><\/a><span class=\"kw\">|<\/span> <span class=\"ex\">c9<\/span> 5d cd a4 6b 88 e3 08 08 08 08 08 08 08 08 08 <span class=\"kw\">|<\/span><span class=\"ex\">.<\/span>]..k...........<span class=\"kw\">|<\/span><\/span>\n<span id=\"cb11-72\"><a href=\"#cb11-72\" aria-hidden=\"true\"><\/a><span class=\"ex\">ssl_decrypt_record<\/span> found padding 8 final len 247<\/span><\/code><\/pre><\/div>\n<p>The HTTP traffic is now legible, even if in a somewhat difficult format.<\/p>\n<h3 id=\"step-6-sniffing-traffic-between-the-reverse-proxy-and-the-application-server\">Step 6: Sniffing traffic between the reverse proxy and the application server<\/h3>\n<p>The ModSecurity audit log is written after the response to a request is sent. This already makes it clear that the audit log is primarily interesting for what may possibly be the final version of the response. On a reverse proxy this version of the request and above all the response do not necessarily match what the backend system actually sent, because the different Apache modules may have already intervened in the traffic. In order to capture this traffic we will be needing something else. The <code>mod_firehose<\/code> module is present in the development branch of the Apache web server. It can be used to capture and log virtually any place in the traffic. However, the developer community has decided not to include the module in Apache 2.4, but to wait until a later version.<\/p>\n<p>This means that we are again confronted with the problem of having to decrypt network traffic. We can define the <code>cipher<\/code> being used on the reverse proxy side. This is done via the <code>SSLProxyCipherSuite<\/code> directive. But this will only work if we obtain the keys from the application server and client in order to convert the encryption back into plain text. If this is the case, the process is the one described above.<\/p>\n<p>However, the application server key is normally not accessible, so we will have to turn to an alternative. We interpose a small <code>stunnel<\/code> tool between the reverse proxy and the backend. <code>stunnel<\/code> takes over the encryption of the backend for us. This enables the reverse proxy to talk to <code>stunnel<\/code> in plain text, giving us the opportunity to capture this connection 1:1. In order to disable all other snoopers we will be operating <code>stunnel<\/code> on the reverse proxy itself using a local IP address and a separate port. Afterwards, encryption then takes place between <code>stunnel<\/code> and the backend. For testing purposes on the local host network interface here. In practice this can certainly be done on a remote server.<\/p>\n<p>A simple sketch of the setup for illustration:<\/p>\n<div class=\"sourceCode\" id=\"cb12\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb12-1\"><a href=\"#cb12-1\" aria-hidden=\"true\"><\/a>                      <span class=\"ex\">____<\/span> <\/span>\n<span id=\"cb12-2\"><a href=\"#cb12-2\" aria-hidden=\"true\"><\/a>                     <span class=\"kw\">|<\/span>    <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-3\"><a href=\"#cb12-3\" aria-hidden=\"true\"><\/a>                     <span class=\"kw\">|<\/span><span class=\"ex\">____<\/span><span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-4\"><a href=\"#cb12-4\" aria-hidden=\"true\"><\/a>                     \/::::<span class=\"ex\">\/<\/span><\/span>\n<span id=\"cb12-5\"><a href=\"#cb12-5\" aria-hidden=\"true\"><\/a>                       <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-6\"><a href=\"#cb12-6\" aria-hidden=\"true\"><\/a>                       <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-7\"><a href=\"#cb12-7\" aria-hidden=\"true\"><\/a>                       <span class=\"ex\">v<\/span><\/span>\n<span id=\"cb12-8\"><a href=\"#cb12-8\" aria-hidden=\"true\"><\/a>    <span class=\"ex\">.---------------------------------------.<\/span><\/span>\n<span id=\"cb12-9\"><a href=\"#cb12-9\" aria-hidden=\"true\"><\/a>    <span class=\"kw\">|<\/span>                                       <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-10\"><a href=\"#cb12-10\" aria-hidden=\"true\"><\/a>    <span class=\"kw\">|<\/span>     <span class=\"ex\">Reverse<\/span> Proxy: localhost: 443     <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-11\"><a href=\"#cb12-11\" aria-hidden=\"true\"><\/a>    <span class=\"kw\">|<\/span>                                       <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-12\"><a href=\"#cb12-12\" aria-hidden=\"true\"><\/a>    <span class=\"st\">&#39;---------------------------------------&#39;<\/span><\/span>\n<span id=\"cb12-13\"><a href=\"#cb12-13\" aria-hidden=\"true\"><\/a>                       <span class=\"kw\">|<\/span>            <span class=\"ex\">.-----------------------------------.<\/span><\/span>\n<span id=\"cb12-14\"><a href=\"#cb12-14\" aria-hidden=\"true\"><\/a>                       <span class=\"kw\">|<\/span> <span class=\"op\">&lt;<\/span><span class=\"ex\">----------<\/span><span class=\"kw\">|<\/span> $<span class=\"op\">&gt;<\/span> <span class=\"ex\">tcpdump<\/span> -i lo -A -s0 port 8000 <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-15\"><a href=\"#cb12-15\" aria-hidden=\"true\"><\/a>                       <span class=\"ex\">v<\/span>            <span class=\"st\">&#39;-----------------------------------&#39;<\/span><\/span>\n<span id=\"cb12-16\"><a href=\"#cb12-16\" aria-hidden=\"true\"><\/a>    <span class=\"ex\">.---------------------------------------.<\/span><\/span>\n<span id=\"cb12-17\"><a href=\"#cb12-17\" aria-hidden=\"true\"><\/a>    <span class=\"kw\">|<\/span>                                       <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-18\"><a href=\"#cb12-18\" aria-hidden=\"true\"><\/a>    <span class=\"kw\">|<\/span>        <span class=\"ex\">stunnel<\/span>: localhost: 8000       <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-19\"><a href=\"#cb12-19\" aria-hidden=\"true\"><\/a>    <span class=\"kw\">|<\/span>                                       <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-20\"><a href=\"#cb12-20\" aria-hidden=\"true\"><\/a>    <span class=\"st\">&#39;---------------------------------------&#39;<\/span><\/span>\n<span id=\"cb12-21\"><a href=\"#cb12-21\" aria-hidden=\"true\"><\/a>                       <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-22\"><a href=\"#cb12-22\" aria-hidden=\"true\"><\/a>                       <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-23\"><a href=\"#cb12-23\" aria-hidden=\"true\"><\/a>                       <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-24\"><a href=\"#cb12-24\" aria-hidden=\"true\"><\/a>                       <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-25\"><a href=\"#cb12-25\" aria-hidden=\"true\"><\/a>                       <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-26\"><a href=\"#cb12-26\" aria-hidden=\"true\"><\/a>                       <span class=\"ex\">v<\/span><\/span>\n<span id=\"cb12-27\"><a href=\"#cb12-27\" aria-hidden=\"true\"><\/a>    <span class=\"ex\">.---------------------------------------.<\/span><\/span>\n<span id=\"cb12-28\"><a href=\"#cb12-28\" aria-hidden=\"true\"><\/a>    <span class=\"kw\">|<\/span>                                       <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-29\"><a href=\"#cb12-29\" aria-hidden=\"true\"><\/a>    <span class=\"kw\">|<\/span>       <span class=\"ex\">Backend<\/span>: localhost: 8443        <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-30\"><a href=\"#cb12-30\" aria-hidden=\"true\"><\/a>    <span class=\"kw\">|<\/span>                                       <span class=\"kw\">|<\/span><\/span>\n<span id=\"cb12-31\"><a href=\"#cb12-31\" aria-hidden=\"true\"><\/a>    <span class=\"st\">&#39;---------------------------------------&#39;<\/span><\/span><\/code><\/pre><\/div>\n<p>First, the configuration of the reverse proxy:<\/p>\n<div class=\"sourceCode\" id=\"cb13\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb13-1\"><a href=\"#cb13-1\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb13-2\"><a href=\"#cb13-2\" aria-hidden=\"true\"><\/a>    <span class=\"ex\">...<\/span><\/span>\n<span id=\"cb13-3\"><a href=\"#cb13-3\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb13-4\"><a href=\"#cb13-4\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">RewriteRule<\/span>             \/proxy\/(.*)     <span class=\"ex\">http<\/span>:\/\/localhost:8000\/<span class=\"va\">$1<\/span> [proxy,last]<\/span>\n<span id=\"cb13-5\"><a href=\"#cb13-5\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">ProxyPassReverse<\/span>        \/               http:\/\/localhost:8000\/<\/span>\n<span id=\"cb13-6\"><a href=\"#cb13-6\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb13-7\"><a href=\"#cb13-7\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb13-8\"><a href=\"#cb13-8\" aria-hidden=\"true\"><\/a>        <span class=\"op\">&lt;<\/span><span class=\"ex\">Proxy<\/span> http:\/\/localhost:8000\/<span class=\"op\">&gt;<\/span><\/span>\n<span id=\"cb13-9\"><a href=\"#cb13-9\" aria-hidden=\"true\"><\/a>        <\/span>\n<span id=\"cb13-10\"><a href=\"#cb13-10\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">Require<\/span> all granted<\/span>\n<span id=\"cb13-11\"><a href=\"#cb13-11\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb13-12\"><a href=\"#cb13-12\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">Options<\/span> None<\/span>\n<span id=\"cb13-13\"><a href=\"#cb13-13\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb13-14\"><a href=\"#cb13-14\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">ProxySet<\/span> enablereuse=on<\/span>\n<span id=\"cb13-15\"><a href=\"#cb13-15\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb13-16\"><a href=\"#cb13-16\" aria-hidden=\"true\"><\/a>        <span class=\"op\">&lt;<\/span>\/<span class=\"ex\">Proxy<\/span><span class=\"op\">&gt;<\/span><\/span>\n<span id=\"cb13-17\"><a href=\"#cb13-17\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb13-18\"><a href=\"#cb13-18\" aria-hidden=\"true\"><\/a>    <span class=\"ex\">...<\/span><\/span><\/code><\/pre><\/div>\n<p>And here\u2019s the configuration of the <code>stunnel daemon<\/code>:<\/p>\n<div class=\"sourceCode\" id=\"cb14\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb14-1\"><a href=\"#cb14-1\" aria-hidden=\"true\"><\/a>$<span class=\"op\">&gt;<\/span> <span class=\"fu\">cat<\/span> \/tmp\/stunnel.conf<\/span>\n<span id=\"cb14-2\"><a href=\"#cb14-2\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb14-3\"><a href=\"#cb14-3\" aria-hidden=\"true\"><\/a><span class=\"ex\">foreground<\/span> = yes<\/span>\n<span id=\"cb14-4\"><a href=\"#cb14-4\" aria-hidden=\"true\"><\/a><span class=\"ex\">pid<\/span> = \/tmp\/stunnel.pid<\/span>\n<span id=\"cb14-5\"><a href=\"#cb14-5\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb14-6\"><a href=\"#cb14-6\" aria-hidden=\"true\"><\/a><span class=\"ex\">debug<\/span> = 5<\/span>\n<span id=\"cb14-7\"><a href=\"#cb14-7\" aria-hidden=\"true\"><\/a><span class=\"ex\">socket<\/span> = l:TCP_NODELAY=1<\/span>\n<span id=\"cb14-8\"><a href=\"#cb14-8\" aria-hidden=\"true\"><\/a><span class=\"ex\">socket<\/span> = r:TCP_NODELAY=1<\/span>\n<span id=\"cb14-9\"><a href=\"#cb14-9\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb14-10\"><a href=\"#cb14-10\" aria-hidden=\"true\"><\/a>[<span class=\"ex\">https<\/span>]<\/span>\n<span id=\"cb14-11\"><a href=\"#cb14-11\" aria-hidden=\"true\"><\/a><span class=\"ex\">client<\/span> = yes<\/span>\n<span id=\"cb14-12\"><a href=\"#cb14-12\" aria-hidden=\"true\"><\/a><span class=\"ex\">accept<\/span>  = 8000<\/span>\n<span id=\"cb14-13\"><a href=\"#cb14-13\" aria-hidden=\"true\"><\/a><span class=\"ex\">connect<\/span> = localhost:8443<\/span>\n<span id=\"cb14-14\"><a href=\"#cb14-14\" aria-hidden=\"true\"><\/a><span class=\"ex\">TIMEOUTclose<\/span> = 0<\/span><\/code><\/pre><\/div>\n<p>The file is fairly self-explanatory, what\u2019s important is the <code>client<\/code> option: It instructs <code>stunnel<\/code> to accept plain text connections and to encrypt them to and from the backend. The default value is <code>no<\/code> here, which is the exact opposite behavior. The <code>TIMEOUTclose<\/code> option is an empirical value, which is sometimes found in <code>stunnel<\/code> instructions. The configuration of the backend sever still remains. Because we need a backend with SSL\/TLS support, we can no longer use a <code>socat<\/code> backend like we did in Tutorial 9:<\/p>\n<div class=\"sourceCode\" id=\"cb15\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb15-1\"><a href=\"#cb15-1\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb15-2\"><a href=\"#cb15-2\" aria-hidden=\"true\"><\/a><span class=\"ex\">PidFile<\/span> logs\/httpd-backend.pid<\/span>\n<span id=\"cb15-3\"><a href=\"#cb15-3\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb15-4\"><a href=\"#cb15-4\" aria-hidden=\"true\"><\/a><span class=\"ex\">Listen<\/span>  127.0.0.1:8443<\/span>\n<span id=\"cb15-5\"><a href=\"#cb15-5\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb15-6\"><a href=\"#cb15-6\" aria-hidden=\"true\"><\/a><span class=\"ex\">...<\/span><\/span>\n<span id=\"cb15-7\"><a href=\"#cb15-7\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb15-8\"><a href=\"#cb15-8\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span><span class=\"ex\">VirtualHost<\/span> *:<span class=\"op\">8443&gt;<\/span><\/span>\n<span id=\"cb15-9\"><a href=\"#cb15-9\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">ServerName<\/span> localhost<\/span>\n<span id=\"cb15-10\"><a href=\"#cb15-10\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">ServerAlias<\/span> ubuntu<\/span>\n<span id=\"cb15-11\"><a href=\"#cb15-11\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb15-12\"><a href=\"#cb15-12\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">SSLEngine<\/span>               On<\/span>\n<span id=\"cb15-13\"><a href=\"#cb15-13\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">RewriteEngine<\/span>           On<\/span>\n<span id=\"cb15-14\"><a href=\"#cb15-14\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">Header<\/span> always set Strict-Transport-Security <span class=\"st\">&quot;max-age=31536000; includeSubDomains&quot;<\/span> env=HTTPS<\/span>\n<span id=\"cb15-15\"><a href=\"#cb15-15\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb15-16\"><a href=\"#cb15-16\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">SSLCertificateKeyFile<\/span>   \/etc\/ssl\/private\/ssl-cert-snakeoil.key<\/span>\n<span id=\"cb15-17\"><a href=\"#cb15-17\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">SSLCertificateFile<\/span>      \/etc\/ssl\/certs\/ssl-cert-snakeoil.pem<\/span>\n<span id=\"cb15-18\"><a href=\"#cb15-18\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">SSLProtocol<\/span>             All -SSLv2 -SSLv3<\/span>\n<span id=\"cb15-19\"><a href=\"#cb15-19\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">SSLHonorCipherOrder<\/span>     On<\/span>\n<span id=\"cb15-20\"><a href=\"#cb15-20\" aria-hidden=\"true\"><\/a>        <span class=\"ex\">SSLCipherSuite<\/span>          <span class=\"st\">&#39;kEECDH+ECDSA kEECDH kEDH HIGH +SHA !aNULL !eNULL !LOW !MEDIUM \\<\/span><\/span>\n<span id=\"cb15-21\"><a href=\"#cb15-21\" aria-hidden=\"true\"><\/a><span class=\"st\">+!MD5 !EXP !DSS !PSK !SRP !kECDH !CAMELLIA !RC4&#39;<\/span><\/span>\n<span id=\"cb15-22\"><a href=\"#cb15-22\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb15-23\"><a href=\"#cb15-23\" aria-hidden=\"true\"><\/a>        <span class=\"op\">&lt;<\/span><span class=\"ex\">Directory<\/span> \/apache\/htdocs<span class=\"op\">&gt;<\/span><\/span>\n<span id=\"cb15-24\"><a href=\"#cb15-24\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb15-25\"><a href=\"#cb15-25\" aria-hidden=\"true\"><\/a>        <span class=\"op\">&lt;<\/span>\/<span class=\"ex\">Directory<\/span><span class=\"op\">&gt;<\/span><\/span>\n<span id=\"cb15-26\"><a href=\"#cb15-26\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb15-27\"><a href=\"#cb15-27\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span>\/<span class=\"ex\">VirtualHost<\/span><span class=\"op\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n<p>Because this is the second Apache server being started in parallel, it\u2019s important that it doesn\u2019t come to loggerheads with the reverse proxy. We have already differentiated the ports. What\u2019s important is to also separate the <code>PidFile<\/code> file. We do not normally set it explicitly and are satisfied with the default value. But in our case, we have to set it manually. This is what is happening in the configuration above.<\/p>\n<p>We now start the three different servers in sequence. If we use the <code>apachex<\/code> tool to control Apache, then we will suffer a bit each time <code>apachex<\/code> attempts to start the most recent configuration file. A quick <code>touch<\/code> on the desired configuration solves the problem. For <code>stunnel<\/code> it\u2019s important to use the more recent <code>stunnel4<\/code> version. In <code>Debian\/Ubuntu<\/code> it is included in a package of the same name. The start is then very easy:<\/p>\n<div class=\"sourceCode\" id=\"cb16\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb16-1\"><a href=\"#cb16-1\" aria-hidden=\"true\"><\/a>$<span class=\"op\">&gt;<\/span> <span class=\"fu\">sudo<\/span> stunnel4 \/tmp\/stunnel.conf<\/span>\n<span id=\"cb16-2\"><a href=\"#cb16-2\" aria-hidden=\"true\"><\/a><span class=\"ex\">stunnel4<\/span> \/tmp\/stunnel.conf<\/span>\n<span id=\"cb16-3\"><a href=\"#cb16-3\" aria-hidden=\"true\"><\/a><span class=\"ex\">2016.03.02<\/span> 16:28:08 LOG5[8254:140331683964736]: stunnel 4.53 on x86_64-pc-linux-gnu platform<\/span>\n<span id=\"cb16-4\"><a href=\"#cb16-4\" aria-hidden=\"true\"><\/a><span class=\"ex\">2016.03.02<\/span> 16:28:08 LOG5[8254:140331683964736]: Compiled with OpenSSL 1.0.1e 11 Feb 2013<\/span>\n<span id=\"cb16-5\"><a href=\"#cb16-5\" aria-hidden=\"true\"><\/a><span class=\"ex\">2016.03.02<\/span> 16:28:08 LOG5[8254:140331683964736]: Running  with OpenSSL 1.0.1f 6 Jan 2014<\/span>\n<span id=\"cb16-6\"><a href=\"#cb16-6\" aria-hidden=\"true\"><\/a><span class=\"ex\">2016.03.02<\/span> 16:28:08 LOG5[8254:140331683964736]: Update OpenSSL shared libraries or rebuild stunnel<\/span>\n<span id=\"cb16-7\"><a href=\"#cb16-7\" aria-hidden=\"true\"><\/a><span class=\"ex\">2016.03.02<\/span> 16:28:08 LOG5[8254:140331683964736]: Threading:PTHREAD SSL:+ENGINE+OCSP Auth:LIBWRAP \u2026<\/span>\n<span id=\"cb16-8\"><a href=\"#cb16-8\" aria-hidden=\"true\"><\/a><span class=\"ex\">2016.03.02<\/span> 16:28:08 LOG5[8254:140331683964736]: Reading configuration from file \/tmp\/stunnel.conf<\/span>\n<span id=\"cb16-9\"><a href=\"#cb16-9\" aria-hidden=\"true\"><\/a><span class=\"ex\">2016.03.02<\/span> 16:28:08 LOG5[8254:140331683964736]: Configuration successful<\/span><\/code><\/pre><\/div>\n<p>The complete setup is now ready for our curl request. Let\u2019s test it in sequence. First directly on the backend, then via stunnel and finally via the reverse proxy:<\/p>\n<div class=\"sourceCode\" id=\"cb17\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb17-1\"><a href=\"#cb17-1\" aria-hidden=\"true\"><\/a>$<span class=\"op\">&gt;<\/span> <span class=\"ex\">curl<\/span> -v -k https:\/\/localhost:8443\/index.html<\/span>\n<span id=\"cb17-2\"><a href=\"#cb17-2\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> Hostname was NOT found in DNS cache<\/span>\n<span id=\"cb17-3\"><a href=\"#cb17-3\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span>   Trying 127.0.0.1...<\/span>\n<span id=\"cb17-4\"><a href=\"#cb17-4\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> Connected to localhost (127.0.0.1) <span class=\"ex\">port<\/span> 8443 (#0)<\/span>\n<span id=\"cb17-5\"><a href=\"#cb17-5\" aria-hidden=\"true\"><\/a><span class=\"ex\">...<\/span><\/span>\n<span id=\"cb17-6\"><a href=\"#cb17-6\" aria-hidden=\"true\"><\/a><span class=\"op\">&gt;<\/span> <span class=\"ex\">GET<\/span> \/index.html HTTP\/1.1<\/span>\n<span id=\"cb17-7\"><a href=\"#cb17-7\" aria-hidden=\"true\"><\/a><span class=\"op\">&gt;<\/span> <span class=\"ex\">User-Agent<\/span>: curl\/7.35.0<\/span>\n<span id=\"cb17-8\"><a href=\"#cb17-8\" aria-hidden=\"true\"><\/a><span class=\"op\">&gt;<\/span> <span class=\"ex\">Host<\/span>: localhost:8443<\/span>\n<span id=\"cb17-9\"><a href=\"#cb17-9\" aria-hidden=\"true\"><\/a><span class=\"op\">&gt;<\/span> <span class=\"ex\">Accept<\/span>: *\/*<\/span>\n<span id=\"cb17-10\"><a href=\"#cb17-10\" aria-hidden=\"true\"><\/a><span class=\"op\">&gt;<\/span> <\/span>\n<span id=\"cb17-11\"><a href=\"#cb17-11\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">HTTP\/1.1<\/span> 200 OK<\/span>\n<span id=\"cb17-12\"><a href=\"#cb17-12\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Date<\/span>: Thu, 03 Mar 2016 10:00:04 GMT<\/span>\n<span id=\"cb17-13\"><a href=\"#cb17-13\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> Server Apache is not blacklisted<\/span>\n<span id=\"cb17-14\"><a href=\"#cb17-14\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Server<\/span>: Apache<\/span>\n<span id=\"cb17-15\"><a href=\"#cb17-15\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Last-Modified<\/span>: Mon, 11 Jun 2007 18:53:14 GMT<\/span>\n<span id=\"cb17-16\"><a href=\"#cb17-16\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">ETag<\/span>: <span class=\"st\">&quot;2d-432a5e4a73a80&quot;<\/span><\/span>\n<span id=\"cb17-17\"><a href=\"#cb17-17\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Accept-Ranges<\/span>: bytes<\/span>\n<span id=\"cb17-18\"><a href=\"#cb17-18\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Content-Length<\/span>: 45<\/span>\n<span id=\"cb17-19\"><a href=\"#cb17-19\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Content-Type<\/span>: text\/html<\/span>\n<span id=\"cb17-20\"><a href=\"#cb17-20\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <\/span>\n<span id=\"cb17-21\"><a href=\"#cb17-21\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span><span class=\"ex\">html<\/span><span class=\"op\">&gt;&lt;<\/span>body<span class=\"op\">&gt;&lt;<\/span>h1<span class=\"op\">&gt;<\/span>It works!<span class=\"op\">&lt;<\/span>\/h1<span class=\"op\">&gt;&lt;<\/span>\/body<span class=\"op\">&gt;&lt;<\/span>\/html<span class=\"op\">&gt;<\/span><\/span>\n<span id=\"cb17-22\"><a href=\"#cb17-22\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> Connection #0 to host localhost left intact<\/span>\n<span id=\"cb17-23\"><a href=\"#cb17-23\" aria-hidden=\"true\"><\/a>$<span class=\"op\">&gt;<\/span> <span class=\"ex\">curl<\/span> -v http:\/\/localhost:8000\/index.html<\/span>\n<span id=\"cb17-24\"><a href=\"#cb17-24\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> Hostname was NOT found in DNS cache<\/span>\n<span id=\"cb17-25\"><a href=\"#cb17-25\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span>   Trying 127.0.0.1...<\/span>\n<span id=\"cb17-26\"><a href=\"#cb17-26\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> Connected to localhost (127.0.0.1) <span class=\"ex\">port<\/span> 8000 (#0)<\/span>\n<span id=\"cb17-27\"><a href=\"#cb17-27\" aria-hidden=\"true\"><\/a><span class=\"op\">&gt;<\/span> <span class=\"ex\">GET<\/span> \/index.html HTTP\/1.1<\/span>\n<span id=\"cb17-28\"><a href=\"#cb17-28\" aria-hidden=\"true\"><\/a><span class=\"op\">&gt;<\/span> <span class=\"ex\">User-Agent<\/span>: curl\/7.35.0<\/span>\n<span id=\"cb17-29\"><a href=\"#cb17-29\" aria-hidden=\"true\"><\/a><span class=\"op\">&gt;<\/span> <span class=\"ex\">Host<\/span>: localhost:8000<\/span>\n<span id=\"cb17-30\"><a href=\"#cb17-30\" aria-hidden=\"true\"><\/a><span class=\"op\">&gt;<\/span> <span class=\"ex\">Accept<\/span>: *\/*<\/span>\n<span id=\"cb17-31\"><a href=\"#cb17-31\" aria-hidden=\"true\"><\/a><span class=\"op\">&gt;<\/span> <\/span>\n<span id=\"cb17-32\"><a href=\"#cb17-32\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">HTTP\/1.1<\/span> 200 OK<\/span>\n<span id=\"cb17-33\"><a href=\"#cb17-33\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Date<\/span>: Thu, 03 Mar 2016 10:01:04 GMT<\/span>\n<span id=\"cb17-34\"><a href=\"#cb17-34\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> Server Apache is not blacklisted<\/span>\n<span id=\"cb17-35\"><a href=\"#cb17-35\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Server<\/span>: Apache<\/span>\n<span id=\"cb17-36\"><a href=\"#cb17-36\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Last-Modified<\/span>: Mon, 11 Jun 2007 18:53:14 GMT<\/span>\n<span id=\"cb17-37\"><a href=\"#cb17-37\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">ETag<\/span>: <span class=\"st\">&quot;2d-432a5e4a73a80&quot;<\/span><\/span>\n<span id=\"cb17-38\"><a href=\"#cb17-38\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Accept-Ranges<\/span>: bytes<\/span>\n<span id=\"cb17-39\"><a href=\"#cb17-39\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Content-Length<\/span>: 45<\/span>\n<span id=\"cb17-40\"><a href=\"#cb17-40\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Content-Type<\/span>: text\/html<\/span>\n<span id=\"cb17-41\"><a href=\"#cb17-41\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <\/span>\n<span id=\"cb17-42\"><a href=\"#cb17-42\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span><span class=\"ex\">html<\/span><span class=\"op\">&gt;&lt;<\/span>body<span class=\"op\">&gt;&lt;<\/span>h1<span class=\"op\">&gt;<\/span>It works!<span class=\"op\">&lt;<\/span>\/h1<span class=\"op\">&gt;&lt;<\/span>\/body<span class=\"op\">&gt;&lt;<\/span>\/html<span class=\"op\">&gt;<\/span><\/span>\n<span id=\"cb17-43\"><a href=\"#cb17-43\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> Connection #0 to host localhost left intact<\/span>\n<span id=\"cb17-44\"><a href=\"#cb17-44\" aria-hidden=\"true\"><\/a>$<span class=\"op\">&gt;<\/span> <span class=\"ex\">curl<\/span> -v -k https:\/\/localhost:443\/proxy\/index.html<\/span>\n<span id=\"cb17-45\"><a href=\"#cb17-45\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> Hostname was NOT found in DNS cache<\/span>\n<span id=\"cb17-46\"><a href=\"#cb17-46\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span>   Trying 127.0.0.1...<\/span>\n<span id=\"cb17-47\"><a href=\"#cb17-47\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> Connected to localhost (127.0.0.1) <span class=\"ex\">port<\/span> 443 (#0)<\/span>\n<span id=\"cb17-48\"><a href=\"#cb17-48\" aria-hidden=\"true\"><\/a><span class=\"ex\">...<\/span><\/span>\n<span id=\"cb17-49\"><a href=\"#cb17-49\" aria-hidden=\"true\"><\/a><span class=\"op\">&gt;<\/span> <span class=\"ex\">GET<\/span> \/proxy\/index.html HTTP\/1.1<\/span>\n<span id=\"cb17-50\"><a href=\"#cb17-50\" aria-hidden=\"true\"><\/a><span class=\"op\">&gt;<\/span> <span class=\"ex\">User-Agent<\/span>: curl\/7.35.0<\/span>\n<span id=\"cb17-51\"><a href=\"#cb17-51\" aria-hidden=\"true\"><\/a><span class=\"op\">&gt;<\/span> <span class=\"ex\">Host<\/span>: localhost<\/span>\n<span id=\"cb17-52\"><a href=\"#cb17-52\" aria-hidden=\"true\"><\/a><span class=\"op\">&gt;<\/span> <span class=\"ex\">Accept<\/span>: *\/*<\/span>\n<span id=\"cb17-53\"><a href=\"#cb17-53\" aria-hidden=\"true\"><\/a><span class=\"op\">&gt;<\/span> <\/span>\n<span id=\"cb17-54\"><a href=\"#cb17-54\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">HTTP\/1.1<\/span> 200 OK<\/span>\n<span id=\"cb17-55\"><a href=\"#cb17-55\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Date<\/span>: Thu, 03 Mar 2016 10:01:29 GMT<\/span>\n<span id=\"cb17-56\"><a href=\"#cb17-56\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> Server Apache is not blacklisted<\/span>\n<span id=\"cb17-57\"><a href=\"#cb17-57\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Server<\/span>: Apache<\/span>\n<span id=\"cb17-58\"><a href=\"#cb17-58\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Last-Modified<\/span>: Mon, 11 Jun 2007 18:53:14 GMT<\/span>\n<span id=\"cb17-59\"><a href=\"#cb17-59\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">ETag<\/span>: <span class=\"st\">&quot;2d-432a5e4a73a80&quot;<\/span><\/span>\n<span id=\"cb17-60\"><a href=\"#cb17-60\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Accept-Ranges<\/span>: bytes<\/span>\n<span id=\"cb17-61\"><a href=\"#cb17-61\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Content-Length<\/span>: 45<\/span>\n<span id=\"cb17-62\"><a href=\"#cb17-62\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <span class=\"ex\">Content-Type<\/span>: text\/html<\/span>\n<span id=\"cb17-63\"><a href=\"#cb17-63\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span> <\/span>\n<span id=\"cb17-64\"><a href=\"#cb17-64\" aria-hidden=\"true\"><\/a><span class=\"op\">&lt;<\/span><span class=\"ex\">html<\/span><span class=\"op\">&gt;&lt;<\/span>body<span class=\"op\">&gt;&lt;<\/span>h1<span class=\"op\">&gt;<\/span>It works!<span class=\"op\">&lt;<\/span>\/h1<span class=\"op\">&gt;&lt;<\/span>\/body<span class=\"op\">&gt;&lt;<\/span>\/html<span class=\"op\">&gt;<\/span><\/span>\n<span id=\"cb17-65\"><a href=\"#cb17-65\" aria-hidden=\"true\"><\/a><span class=\"ex\">*<\/span> Connection #0 to host localhost left intact<\/span><\/code><\/pre><\/div>\n<p>This worked pretty well. We see the following output in the <code>stunnel<\/code> window:<\/p>\n<div class=\"sourceCode\" id=\"cb18\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb18-1\"><a href=\"#cb18-1\" aria-hidden=\"true\"><\/a><span class=\"ex\">2016.03.03<\/span> 11:03:49 LOG5[5667:140363675346688]: Service [https] accepted connection from \u2026<\/span>\n<span id=\"cb18-2\"><a href=\"#cb18-2\" aria-hidden=\"true\"><\/a><span class=\"ex\">2016.03.03<\/span> 11:03:49 LOG5[5667:140363675346688]: connect_blocking: connected 127.0.0.1:8443<\/span>\n<span id=\"cb18-3\"><a href=\"#cb18-3\" aria-hidden=\"true\"><\/a><span class=\"ex\">2016.03.03<\/span> 11:03:49 LOG5[5667:140363675346688]: Service [https] connected remote server from \u2026<\/span>\n<span id=\"cb18-4\"><a href=\"#cb18-4\" aria-hidden=\"true\"><\/a><span class=\"ex\">2016.03.03<\/span> 11:03:49 LOG3[5667:140363675346688]: transfer: s_poll_wait: TIMEOUTclose exceeded: closing<\/span>\n<span id=\"cb18-5\"><a href=\"#cb18-5\" aria-hidden=\"true\"><\/a><span class=\"ex\">2016.03.03<\/span> 11:03:49 LOG5[5667:140363675346688]: Connection closed: 190 byte(s) <span class=\"ex\">sent<\/span> to SSL, 275 byte(s) \u2026<\/span><\/code><\/pre><\/div>\n<p>Thus, here <code>stunnel<\/code> reports the incoming connection on <code>source port<\/code> 47818 and that it has established a connection to the backend host on port 8443 with <code>source port<\/code> 54593; then come two numbers about the transfer rate. Overall, we can conclude that the setup works and we are ready to sniff the connection. Let\u2019s enable <code>tcpdump<\/code> or <code>tshark<\/code>. Decryption is no longer necessary now, because the connection we are sniffing can be read in plain text between the two localhost <code>sockets<\/code>. That\u2019s why it\u2019s important that we enable <code>snap length<\/code> and ASCII mode via <code>-A<\/code>.<\/p>\n<div class=\"sourceCode\" id=\"cb19\"><pre class=\"sourceCode bash\"><code class=\"sourceCode bash\"><span id=\"cb19-1\"><a href=\"#cb19-1\" aria-hidden=\"true\"><\/a>$<span class=\"op\">&gt;<\/span> <span class=\"fu\">sudo<\/span> tcpdump -i lo -A -s0 port 8000<\/span>\n<span id=\"cb19-2\"><a href=\"#cb19-2\" aria-hidden=\"true\"><\/a><span class=\"ex\">tcpdump<\/span>: verbose output suppressed, use -v or -vv for full protocol decode<\/span>\n<span id=\"cb19-3\"><a href=\"#cb19-3\" aria-hidden=\"true\"><\/a><span class=\"ex\">listening<\/span> on lo, link-type EN10MB (Ethernet), <span class=\"ex\">capture<\/span> size 65535 bytes<\/span>\n<span id=\"cb19-4\"><a href=\"#cb19-4\" aria-hidden=\"true\"><\/a><span class=\"ex\">11<\/span>:07:40.016067 IP localhost.47884 <span class=\"op\">&gt;<\/span> localhost.8000: Flags [S], seq 2684270112, win 43690, options \u2026<\/span>\n<span id=\"cb19-5\"><a href=\"#cb19-5\" aria-hidden=\"true\"><\/a><span class=\"ex\">E..<\/span><span class=\"op\">&lt;<\/span>..@.@.\\............@... .........0.........<\/span>\n<span id=\"cb19-6\"><a href=\"#cb19-6\" aria-hidden=\"true\"><\/a><span class=\"ex\">..V4........<\/span><\/span>\n<span id=\"cb19-7\"><a href=\"#cb19-7\" aria-hidden=\"true\"><\/a><span class=\"ex\">11<\/span>:07:40.016103 IP localhost.8000 <span class=\"op\">&gt;<\/span> localhost.47884: Flags [S.], seq 3592202505, ack 2684270113, win \u2026<\/span>\n<span id=\"cb19-8\"><a href=\"#cb19-8\" aria-hidden=\"true\"><\/a><span class=\"ex\">E..<\/span><span class=\"op\">&lt;<\/span>..@.@.<span class=\"op\">&lt;<\/span>..........@.....     ...!.....0.........<\/span>\n<span id=\"cb19-9\"><a href=\"#cb19-9\" aria-hidden=\"true\"><\/a><span class=\"ex\">..V4..V4....<\/span><\/span>\n<span id=\"cb19-10\"><a href=\"#cb19-10\" aria-hidden=\"true\"><\/a><span class=\"ex\">11<\/span>:07:40.016154 IP localhost.47884 <span class=\"op\">&gt;<\/span> localhost.8000: Flags [.], ack 1, win 342, options [nop,nop,TS \u2026<\/span>\n<span id=\"cb19-11\"><a href=\"#cb19-11\" aria-hidden=\"true\"><\/a><span class=\"ex\">E..4..@.@.<\/span>\\............@...!...<\/span>\n<span id=\"cb19-12\"><a href=\"#cb19-12\" aria-hidden=\"true\"><\/a><span class=\"ex\">...V.<\/span>(.....<\/span>\n<span id=\"cb19-13\"><a href=\"#cb19-13\" aria-hidden=\"true\"><\/a><span class=\"ex\">..V4..V4<\/span><\/span>\n<span id=\"cb19-14\"><a href=\"#cb19-14\" aria-hidden=\"true\"><\/a><span class=\"ex\">11<\/span>:07:40.016647 IP localhost.47884 <span class=\"op\">&gt;<\/span> localhost.8000: Flags [P.], seq 1:191, ack 1, win 342, options \u2026<\/span>\n<span id=\"cb19-15\"><a href=\"#cb19-15\" aria-hidden=\"true\"><\/a><span class=\"ex\">E.....@.@.<\/span>[............@...!...<\/span>\n<span id=\"cb19-16\"><a href=\"#cb19-16\" aria-hidden=\"true\"><\/a><span class=\"ex\">...V.......<\/span><\/span>\n<span id=\"cb19-17\"><a href=\"#cb19-17\" aria-hidden=\"true\"><\/a><span class=\"ex\">..V4..V4GET<\/span> \/index.html HTTP\/1.1<\/span>\n<span id=\"cb19-18\"><a href=\"#cb19-18\" aria-hidden=\"true\"><\/a><span class=\"ex\">Host<\/span>: localhost<\/span>\n<span id=\"cb19-19\"><a href=\"#cb19-19\" aria-hidden=\"true\"><\/a><span class=\"ex\">User-Agent<\/span>: curl\/7.35.0<\/span>\n<span id=\"cb19-20\"><a href=\"#cb19-20\" aria-hidden=\"true\"><\/a><span class=\"ex\">Accept<\/span>: *\/*<\/span>\n<span id=\"cb19-21\"><a href=\"#cb19-21\" aria-hidden=\"true\"><\/a><span class=\"ex\">X-Forwarded-For<\/span>: 127.0.0.1<\/span>\n<span id=\"cb19-22\"><a href=\"#cb19-22\" aria-hidden=\"true\"><\/a><span class=\"ex\">X-Forwarded-Host<\/span>: localhost<\/span>\n<span id=\"cb19-23\"><a href=\"#cb19-23\" aria-hidden=\"true\"><\/a><span class=\"ex\">X-Forwarded-Server<\/span>: localhost<\/span>\n<span id=\"cb19-24\"><a href=\"#cb19-24\" aria-hidden=\"true\"><\/a><span class=\"ex\">Connection<\/span>: close<\/span>\n<span id=\"cb19-25\"><a href=\"#cb19-25\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb19-26\"><a href=\"#cb19-26\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb19-27\"><a href=\"#cb19-27\" aria-hidden=\"true\"><\/a><span class=\"ex\">11<\/span>:07:40.016738 IP localhost.8000 <span class=\"op\">&gt;<\/span> localhost.47884: Flags [.], ack 191, win 350, options [nop,nop,TS \u2026<\/span>\n<span id=\"cb19-28\"><a href=\"#cb19-28\" aria-hidden=\"true\"><\/a><span class=\"ex\">E..4.<\/span><span class=\"op\">&gt;<\/span>@.@.=..........@.....<\/span>\n<span id=\"cb19-29\"><a href=\"#cb19-29\" aria-hidden=\"true\"><\/a><span class=\"ex\">.......<\/span>^.(.....<\/span>\n<span id=\"cb19-30\"><a href=\"#cb19-30\" aria-hidden=\"true\"><\/a><span class=\"ex\">..V4..V4<\/span><\/span>\n<span id=\"cb19-31\"><a href=\"#cb19-31\" aria-hidden=\"true\"><\/a><span class=\"ex\">11<\/span>:07:40.041573 IP localhost.8000 <span class=\"op\">&gt;<\/span> localhost.47884: Flags [P.], seq 1:231, ack 191, win 350, options \u2026<\/span>\n<span id=\"cb19-32\"><a href=\"#cb19-32\" aria-hidden=\"true\"><\/a><span class=\"ex\">E....?@.@.<\/span><span class=\"op\">&lt;<\/span>..........@.....<\/span>\n<span id=\"cb19-33\"><a href=\"#cb19-33\" aria-hidden=\"true\"><\/a><span class=\"ex\">.......<\/span>^.......<\/span>\n<span id=\"cb19-34\"><a href=\"#cb19-34\" aria-hidden=\"true\"><\/a><span class=\"ex\">..V<\/span>:..V4HTTP\/1.1 200 OK<\/span>\n<span id=\"cb19-35\"><a href=\"#cb19-35\" aria-hidden=\"true\"><\/a><span class=\"ex\">Date<\/span>: Thu, 03 Mar 2016 10:07:40 GMT<\/span>\n<span id=\"cb19-36\"><a href=\"#cb19-36\" aria-hidden=\"true\"><\/a><span class=\"ex\">Server<\/span>: Apache<\/span>\n<span id=\"cb19-37\"><a href=\"#cb19-37\" aria-hidden=\"true\"><\/a><span class=\"ex\">Last-Modified<\/span>: Mon, 11 Jun 2007 18:53:14 GMT<\/span>\n<span id=\"cb19-38\"><a href=\"#cb19-38\" aria-hidden=\"true\"><\/a><span class=\"ex\">ETag<\/span>: <span class=\"st\">&quot;2d-432a5e4a73a80&quot;<\/span><\/span>\n<span id=\"cb19-39\"><a href=\"#cb19-39\" aria-hidden=\"true\"><\/a><span class=\"ex\">Accept-Ranges<\/span>: bytes<\/span>\n<span id=\"cb19-40\"><a href=\"#cb19-40\" aria-hidden=\"true\"><\/a><span class=\"ex\">Content-Length<\/span>: 45<\/span>\n<span id=\"cb19-41\"><a href=\"#cb19-41\" aria-hidden=\"true\"><\/a><span class=\"ex\">Connection<\/span>: close<\/span>\n<span id=\"cb19-42\"><a href=\"#cb19-42\" aria-hidden=\"true\"><\/a><span class=\"ex\">Content-Type<\/span>: text\/html<\/span>\n<span id=\"cb19-43\"><a href=\"#cb19-43\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb19-44\"><a href=\"#cb19-44\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb19-45\"><a href=\"#cb19-45\" aria-hidden=\"true\"><\/a><span class=\"ex\">11<\/span>:07:40.041627 IP localhost.47884 <span class=\"op\">&gt;<\/span> localhost.8000: Flags [.], ack 231, win 350, options [nop,nop,TS \u2026<\/span>\n<span id=\"cb19-46\"><a href=\"#cb19-46\" aria-hidden=\"true\"><\/a><span class=\"ex\">E..4..@.@.<\/span>\\............@...........^.(.....<\/span>\n<span id=\"cb19-47\"><a href=\"#cb19-47\" aria-hidden=\"true\"><\/a><span class=\"ex\">..V<\/span>:..V:<\/span>\n<span id=\"cb19-48\"><a href=\"#cb19-48\" aria-hidden=\"true\"><\/a><span class=\"ex\">11<\/span>:07:40.041711 IP localhost.8000 <span class=\"op\">&gt;<\/span> localhost.47884: Flags [P.], seq 231:276, ack 191, win 350, options \u2026<\/span>\n<span id=\"cb19-49\"><a href=\"#cb19-49\" aria-hidden=\"true\"><\/a><span class=\"ex\">E..a.@@.@.<\/span>=T.........@.............^.U.....<\/span>\n<span id=\"cb19-50\"><a href=\"#cb19-50\" aria-hidden=\"true\"><\/a><span class=\"ex\">..V<\/span>:..V:<span class=\"op\">&lt;<\/span>html<span class=\"op\">&gt;&lt;<\/span>body<span class=\"op\">&gt;&lt;<\/span>h1<span class=\"op\">&gt;<\/span>It works!<span class=\"op\">&lt;<\/span>\/h1<span class=\"op\">&gt;&lt;<\/span>\/body<span class=\"op\">&gt;&lt;<\/span>\/html<span class=\"op\">&gt;<\/span><\/span>\n<span id=\"cb19-51\"><a href=\"#cb19-51\" aria-hidden=\"true\"><\/a><\/span>\n<span id=\"cb19-52\"><a href=\"#cb19-52\" aria-hidden=\"true\"><\/a><span class=\"ex\">11<\/span>:07:40.041745 IP localhost.47884 <span class=\"op\">&gt;<\/span> localhost.8000: Flags [.], ack 276, win 350, options [nop,nop,TS val \u2026<\/span>\n<span id=\"cb19-53\"><a href=\"#cb19-53\" aria-hidden=\"true\"><\/a><span class=\"ex\">E..4..@.@.<\/span>\\............@...........^.(.....<\/span>\n<span id=\"cb19-54\"><a href=\"#cb19-54\" aria-hidden=\"true\"><\/a><span class=\"ex\">..V<\/span>:..V:<\/span>\n<span id=\"cb19-55\"><a href=\"#cb19-55\" aria-hidden=\"true\"><\/a><span class=\"ex\">11<\/span>:07:40.042044 IP localhost.47884 <span class=\"op\">&gt;<\/span> localhost.8000: Flags [F.], seq 191, ack 276, win 350, options \u2026<\/span>\n<span id=\"cb19-56\"><a href=\"#cb19-56\" aria-hidden=\"true\"><\/a><span class=\"ex\">E..4..@.@.<\/span>\\............@...........^.(.....<\/span>\n<span id=\"cb19-57\"><a href=\"#cb19-57\" aria-hidden=\"true\"><\/a><span class=\"ex\">..V<\/span>:..V:<\/span>\n<span id=\"cb19-58\"><a href=\"#cb19-58\" aria-hidden=\"true\"><\/a><span class=\"ex\">11<\/span>:07:40.047226 IP localhost.8000 <span class=\"op\">&gt;<\/span> localhost.47884: Flags [F.], seq 276, ack 192, win 350, options \u2026<\/span>\n<span id=\"cb19-59\"><a href=\"#cb19-59\" aria-hidden=\"true\"><\/a><span class=\"ex\">E..4.A@.@.<\/span>=..........@.............^.(.....<\/span>\n<span id=\"cb19-60\"><a href=\"#cb19-60\" aria-hidden=\"true\"><\/a><span class=\"ex\">..V<\/span><span class=\"kw\">;<\/span><span class=\"ex\">..V<\/span>:<\/span>\n<span id=\"cb19-61\"><a href=\"#cb19-61\" aria-hidden=\"true\"><\/a><span class=\"ex\">11<\/span>:07:40.047296 IP localhost.47884 <span class=\"op\">&gt;<\/span> localhost.8000: Flags [.], ack 277, win 350, options [nop,nop,TS \u2026<\/span>\n<span id=\"cb19-62\"><a href=\"#cb19-62\" aria-hidden=\"true\"><\/a><span class=\"ex\">E..4..@.@.<\/span>\\............@...........^.(.....<\/span>\n<span id=\"cb19-63\"><a href=\"#cb19-63\" aria-hidden=\"true\"><\/a><span class=\"ex\">..V<\/span><span class=\"kw\">;<\/span><span class=\"ex\">..V<\/span><span class=\"kw\">;<\/span><\/span><\/code><\/pre><\/div>\n<p>We\u2019ve done it! We are capturing the connection to the backend and are now sure about the traffic being exchanged between the two servers. In practice it is often unclear whether an error is actually being caused on the application server or perhaps on the reverse proxy after all. Using this construct that does not touch the SSL configuration of the backend server, we have a tool giving us a final answer in these relatively frequent cases.<\/p>\n<h3 id=\"references\">References<\/h3>\n<ul>\n<li><a href=\"https:\/\/www.feistyduck.com\/books\/modsecurity-handbook\/\">Ivan Risti\u0107: ModSecurity Handbook<\/a><\/li>\n<li><a href=\"http:\/\/httpd.apache.org\/docs\/trunk\/de\/mod\/mod_firehose.html\">Mod_firehose<\/a><\/li>\n<li><a href=\"https:\/\/mitmproxy.org\/\">mitmproxy<\/a><\/li>\n<li><a href=\"https:\/\/wiki.wireshark.org\/SSL\">Wireshark SSL Howto including a Step by Step guide<\/a><\/li>\n<li><a href=\"https:\/\/www.stunnel.org\/howto.html\">Stunnel Howto<\/a><\/li>\n<\/ul>\n<h3 id=\"license-copying-further-use\">License \/ Copying \/ Further use<\/h3>\n<p><a rel=\"license\" href=\"http:\/\/creativecommons.org\/licenses\/by-nc-sa\/4.0\/\"><img decoding=\"async\" alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https:\/\/i.creativecommons.org\/l\/by-nc-sa\/4.0\/80x15.png\" \/><\/a><br \/>This work is licensed under a <a rel=\"license\" href=\"http:\/\/creativecommons.org\/licenses\/by-nc-sa\/4.0\/\">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License<\/a>.<\/p>\n<h5 id=\"changelog\">Changelog<\/h5>\n<ul>\n<li>2019-11-04: Added env=HTTPS condition to STS header config<\/li>\n<li>2019-10-31: Disabling TLSv1 and TLSv1.1<\/li>\n<li>2019-07-04: Adding ProxySet directive<\/li>\n<li>2018-04-13: Fixed bug with tshark command line call; update title format (markdown); rewordings (Simon Studer)<\/li>\n<li>2017-03-28: Publication<\/li>\n<li>2017-03-05: Added default directives into proxy stanza<\/li>\n<li>2017-03-04: Updated stdout of curl calls<\/li>\n<li>2017-02-16: Reformatting<\/li>\n<li>2016-12-28: Cutting length of line, bugfix in config, remove unnecessary \u201c-k\u201d from curl command<\/li>\n<li>2016-10-10: Fixing small issues<\/li>\n<li>2016-07-15: Apache 2.4.20 -&gt; 2.4.23<\/li>\n<li>2016-07-15: Apache 2.4.20 -&gt; 2.4.23<\/li>\n<li>2016-04-18: Fixing small issues<\/li>\n<li>2016-03-10: Translated to English<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Capturing and decrypting the entire traffic What are we doing? We are capturing the entire HTTP traffic. We will also be decrypting traffic where necessary. Why are we doing this? In daily life, when operating a web or reverse proxy server errors occur that can only be handled with difficultly come up again and again. [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-955","page","type-page","status-publish","czr-hentry"],"_links":{"self":[{"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/pages\/955","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/comments?post=955"}],"version-history":[{"count":2,"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/pages\/955\/revisions"}],"predecessor-version":[{"id":2067,"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/pages\/955\/revisions\/2067"}],"wp:attachment":[{"href":"https:\/\/www.netnea.com\/cms\/wp-json\/wp\/v2\/media?parent=955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}