Category: HackTheBox

XSS with CSP set to “self”

Although initially one might think that the Content Security Policy(CSP) set to self will defeat XSS then depending on the web app, it might not be the case. Depending on how well the application is written there still might be ways to get around it.

When playing around on HTB I came across a machine where the initial foothold was designed to be gained via cross-site scripting(XSS) against a “bot user” on a website. I saw that when editing a field in a order form on my own user I could successfully ender a XSS payload, yet it got blocked by the CSP. As it was set to self, making the web browser reject inline Java Script. After looking around a bit on the page and discovering it’s features I noticed that I can actually upload a profile picture. After discovering that I decided to try and see if there are any restrictions on files that can be uploaded as my avatar. Lucky for me there weren’t any and I successfully uploaded a Java Script file as my profile image.

After having uploaded the malicious Java Script payload as my profile image I could get XSS to trigger on my own order forms. It was just a matter of pointing the inline Java Script to include its source from my profile image.

<script src="http://ctftarget.htb/static/profile/1"></script> 

After that it was just a matter of finding out how to feed that XSS to the bot user, which turned out to be easy – update the bots order form as permissions were broken.

So when you come across restrictive CSP look for other functionalities which might help you reach your goal. And like always use your skills wisely/legally/responsibly.

Notes on Pentesting/CTF “hacking” a gRPC application

Things I describe here are only to be used in a “lab/ctf” environment or on systems you have actually permission to try things out on.


When playing around on HTB I ran into a strange port/service I hadn’t seen before. My nmap scan showed that port 50051 was active but “unknown”. Just out of curiosity opened a connection to it by using telnet after a while it timed out stating that its a HTTP/2 based service:

A quick Google search later it seemed to be a gRPC server. You can read more about it on their website gRPC.

Tools to interact with gRPC

As I hadn’t played around with gRPC previously I spent some time looking at tools and ways to interact with gRPC applications.

The options I found were:

After a quick look I ruled out writing Python code, as it seemed too much for a “simple CTF machine” and my current use case.

Next I took a look at Postman/Insomnia, their interface was similar and they could easily interact with the gRPC service but they were lacking some functionality to conveniently pentest the application.

Yes they were able to show what “Symbols” are available in the gRPC app, it they didn’t return some descriptive info/reflections properly at least in the app I was “hacking” which ended up for me looking at other tools.

grpcurl looked like a nice command line tool and was able to explore the app nicely:

But it also didn’t reflect all the features/parameters of the application and was still lacking something I found that grpcui had!

Now we come to my favorite of the bunch and that got me past the finish line on my target machine – grpcui. What this tool does is give you a WebUI to access and interact with the backend gRPC application. Why this is good for “hacking and pentesting” is that this gives you the option of proxying the connection through BurpSuite and use other automation tools to interact with the gRPC service. The current version of grpcui had a “csrf token”, but it was a static value so you could indefinitely, so basically could be ignored.

Testing/”hacking” a gRPC application

So after having found a tool that seemed to suite my purpose I started poking and prodding at my target gRPC application using a web browser with the help of grpcui.

When starting grpcui it basically starts a little WebUI on localhost:”SomeRandomHighPort” which you should access via a web browser. Startup Example :

If you use the bind parameter to bind it to some IP address that differs from loopback( then your browser will gladly proxy your connections to Burp or ZAP. After that you can continue your “regular pentesting workflow” .

In my case after having poked and prodded at the app for a bit I found that it had a SQLi in it. So I opted to take the raw request from Burp and “unleashed” sqlmap on it and dumped the whole database. That contained a username and password combo in it I could use to access the box over SSH and “user flag claimed”.

HackTheBox don’t get stuck on the decoy’s

Lately I’ve been doing a quite a lot of playing around on HackTheBox. I just love the “competitive mode/season” thing they are trying out, as it just gives you a target for the week. It does add a nice incentive to play around there and makes it harder to forget, as who doesn’t like getting higher on the “leader board”.

But what I’ve noticed over the past few weeks there is that there are some decoy hints on the machines. So if you seem stuck for a while and are quite sure you are doing the right thing.. Just take a step back and go through your notes again. The last decoy I found my self stuck on for a while was an app returning “username” in the header. Of course that was the value for username I used in all the following exploitation steps instead of my own username that I used to register. Wasted a bit of time because of that. It was there purely to throw people off! But hey lesson learned!

Also although nmap might say that some software version is vulnerable then usually that’s not the way in. It still tends to be some web application vulnerability that gives you the initial foothold not “vulnerable ssh daemon” (don’t waste time guessing usernames for scp exploitation). Most likely there is either a path traversal issue which allows you to see get access to something you shouldn’t or SQL injection.

Oh and before I forget, -p- flag for scanning is quite a good idea, as there have been quite a few hosts there where the actually vulnerable service doesn’t show up in the default port selection. And if you feel stuck then surely visit HackTheBox forums/discord servers to get a nudge/do a sanity check on your progress. Really nice and active community there with quite a few people willing to share ideas with out actually spoiling the challenge.