Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error loadFromRemoteSources #99

Open
chmod750 opened this issue Oct 28, 2020 · 2 comments
Open

Error loadFromRemoteSources #99

chmod750 opened this issue Oct 28, 2020 · 2 comments

Comments

@chmod750
Copy link

Hello,

I have an error executing a PSObject payload (ASP.NET Core Runtime 2.1.23). Does it means I have to bypass loadFromRemoteSources restrictions on the target too?

ysoserial.exe -f BinaryFormatter -g PSObject -o base64 -c "ping 10.0.0.1" -t

Unhandled Exception: System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
at System.Reflection.RuntimeAssembly.nLoadFile(String path, Evidence evidence)
at System.Reflection.Assembly.LoadFile(String path)
at ysoserial.Generators.PSObjectGenerator.Generate(String formatter, InputArgs inputArgs) in D:\a\ysoserial.net\ysoserial.net\ysoserial\Generators\PSObjectGenerator.cs:line 67
at ysoserial.Generators.GenericGenerator.GenerateWithInit(String formatter, InputArgs inputArgs) in D:\a\ysoserial.net\ysoserial.net\ysoserial\Generators\GenericGenerator.cs:line 68
at ysoserial.Program.Main(String[] args) in D:\a\ysoserial.net\ysoserial.net\ysoserial\Program.cs:line 197

@gogo2464
Copy link
Contributor

In order to solve it do:

-open powershell
-send "[environment]::Version"

and read the version of .net.

-Now with the version of .net, if you are on 32 bits machine go to %windir%\Microsoft.NET\Framework\[version]\config\machine.config
Else if you are on 64 bits go to %windir%\Microsoft.NET\Framework64\[version]\config\machine.config.

-Then edit the file machine.config in order to get something with <loadFromRemoteSources enabled="true"/> like

<configuration>  
   <runtime>  
      <loadFromRemoteSources enabled="true"/>  
   </runtime>  
</configuration>  

Then it should works.

Sources:

-https://stackoverflow.com/questions/2325473/where-is-machine-config/2325492#2325492
-https://docs.microsoft.com/fr-fr/dotnet/framework/configure-apps/file-schema/runtime/loadfromremotesources-element
-https://stackoverflow.com/questions/1565434/how-do-i-find-the-net-version
-https://askcodez.com/impossible-de-charger-lassembly-a-partir-de-lemplacement-reseau.html

As you can see it was a mitigation and you need that the target system disable this mitigation. No idea if it is bypassable.

@gogo2464
Copy link
Contributor

gogo2464 commented Jun 4, 2023

@chmod750 after a long long reading I think it is a bug that lead to block on c# sandbox.

Some generator bypass it some do not.

Sounds to be a bug. Not your mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants