Sep 1, 2017 01:00 PM
(This post was last modified: Sep 3, 2017 08:34 PM by Barret.)
For a confined environment to execute an assembly with custom set of permissions that you control.
![[Image: rRkZVYP.png?2]](https://i.imgur.com/rRkZVYP.png?2)
![[Image: ckLpoIs.png?1]](https://i.imgur.com/ckLpoIs.png?1)
Not all assembly types work entirely 100% within a boxed environment but most of them will expose their intent within this test environment as shown above with the Jail.Test i supplied.
You have a big list of all sorts of permissions, you can find them here: https://msdn.microsoft.com/en-us/library....110).aspx
And you can add them like so:
PHP Code
<?php
confinement.Permissions.AddPermission(New SecurityPermission(SecurityPermissionFlag.Execution))
confinement.Permissions.AddPermission(New FileIOPermission(FileIOPermissionAccess.AllAccess, "C:\SomeFolder\"))
The Drag&Drop feature is just for Console or Window assemblies, i supplied an additional Jail.Test project which sole purpose is to perform debugging and testing of certain permissions.
To perform a jailed exeuction, drag the Jail.Test.exe onto the jail image of the Jailer application itself and the log will tell you whats going on.
If an assembly has DLL's, you can drag them along with it and they will be loaded into that jailed domain as well.
DLL's have two different approaches, DynamicProxy and TypedProxy.
Dynamic Proxy
Parameters: String[Namespace.Class]
Returns: Object
PHP Code
<?php
jail.ToDynamicProxy("Namespace.Class").MyMethod()
TypedProxy
Parameters: (Of Contract Type), String[Namespace.Class]
Returns: Defined by contract
PHP Code
<?php
jail.ToTypedProxy(Of Contract)("Namespace.Class").MyMethod()
Remark:
A typed proxy is made by a contract class that makes up the interface of the jailed assembly, the methods and properties are assumed to be the same in signature and name reference.
Quick demonstration (a test project is supplied within the github link):
PHP Code
<?php
Private Sub JailCreateAndRun(Assemblies() As String)
'// Collect and append assemblies into our collection
Dim Collection As New Collection
For Each filename As String In Assemblies
If (IO.File.Exists(filename)) Then
Collection.Load(New Loaders.ByFilename(filename))
End If
Next
'// Create confinement
Using confinement As New Confinement("My Jail")
'// Bare minimum (Execution and local path access)
confinement.Permissions.AddPermission(New SecurityPermission(SecurityPermissionFlag.Execution))
confinement.Permissions.AddPermission(New FileIOPermission(FileIOPermissionAccess.AllAccess, confinement.Path))
'// GUI permission
confinement.Permissions.AddPermission(New UIPermission(UIPermissionWindow.AllWindows))
'// Create jail with confinement and collection, will call back for load results
Using jail As Jail = CType(jail.Create(confinement, AddressOf Me.LoadCallback, Collection), Jail)
Try
'// Assign event handler
AddHandler jail.JailBlockedPermission, AddressOf Me.JailBlockedPermission
'// Run application (assuming it has an entrypoint)
jail.Run(New Object() {New String() {}})
Finally
'// Remove event handler
RemoveHandler jail.JailBlockedPermission, AddressOf Me.JailBlockedPermission
End Try
End Using
End Using
End Sub
'// Callback result
Private Sub LoadCallback(sender As Object, loaded As Boolean, ex As Exception)
If (Not loaded) Then
'....Something wend wrong while loading an assembly...
End If
End Sub
'// Callback blocked security events
Private Sub JailBlockedPermission(Sender As Object, Request As Request)
'...a permission demand was made by the assembly but denied, info is stored in Request
End Sub
The project is just at a test stage, bugs are to be expected, leave a comment for questions or fork/download the project.
Github: https://github.com/TheBarret/DotNetJail
- B.




