# Buggy code
def get_redirected(url):
    # Returns false if url is not right
    headers = {"User-Agent": "Mozilla/5.0"}
    request = urllib2.Request(url, headers=headers)
    try:
        return urllib2.urlopen(request).geturl()
    except urllib2.URLError:
        LOG.error("Can't reach struts2 server")
        return False


# Traceback (CertificateError)
2019-04-17 15:52:15,293 [23152:22664:ERROR] monkey.start.190: Exception while attacking Victim Host 216.58.207.78: OS - [type-linux ] Services - [tcp-443-{'data': ('gws', True), 'name': 'http'} tcp-80-{'data': ('gws', False), 'name': 'http'} ] target monkey: None using Struts2Exploiter: hostname '216.58.207.78' doesn't match either of '*.google.com', '*.android.com', '*.appengine.google.com', '*.cloud.google.com', '*.crowdsource.google.com', '*.g.co', '*.gcp.gvt2.com', '*.ggpht.cn', '*.google-analytics.com', '*.google.ca', '*.google.cl', '*.google.co.in', '*.google.co.jp', '*.google.co.uk', '*.google.com.ar', '*.google.com.au', '*.google.com.br', '*.google.com.co', '*.google.com.mx', '*.google.com.tr', '*.google.com.vn', '*.google.de', '*.google.es', '*.google.fr', '*.google.hu', '*.google.it', '*.google.nl', '*.google.pl', '*.google.pt', '*.googleadapis.com', '*.googleapis.cn', '*.googlecnapps.cn', '*.googlecommerce.com', '*.googlevideo.com', '*.gstatic.cn', '*.gstatic.com', '*.gstaticcnapps.cn', '*.gvt1.com', '*.gvt2.com', '*.metric.gstatic.com', '*.urchin.com', '*.url.google.com', '*.youtube-nocookie.com', '*.youtube.com', '*.youtubeeducation.com', '*.youtubekids.com', '*.yt.be', '*.ytimg.com', 'android.clients.google.com', 'android.com', 'developer.android.google.cn', 'developers.android.google.cn', 'g.co', 'ggpht.cn', 'goo.gl', 'google-analytics.com', 'google.com', 'googlecnapps.cn', 'googlecommerce.com', 'source.android.google.cn', 'urchin.com', 'www.goo.gl', 'youtu.be', 'youtube.com', 'youtubeeducation.com', 'youtubekids.com', 'yt.be'
Traceback (most recent call last):
File "C:\monkey\monkey\infection_monkey\monkey.py", line 181, in start
result = exploiter.exploit_host()
File "C:\monkey\monkey\infection_monkey\exploit\web_rce.py", line 79, in exploit_host
urls = self.build_potential_urls(ports, exploit_config['url_extensions'])
File "C:\monkey\monkey\infection_monkey\exploit\struts2.py", line 41, in build_potential_urls
url_list = [self.get_redirected(url) for url in url_list]
File "C:\monkey\monkey\infection_monkey\exploit\struts2.py", line 50, in get_redirected
return urllib2.urlopen(request).geturl()
File "C:\Python27\lib\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 429, in open
response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 447, in _open
'_open', req)
File "C:\Python27\lib\urllib2.py", line 407, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1241, in https_open
context=self._context)
File "C:\Python27\lib\urllib2.py", line 1195, in do_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
File "C:\Python27\lib\httplib.py", line 1042, in request
self._send_request(method, url, body, headers)
File "C:\Python27\lib\httplib.py", line 1082, in _send_request
self.endheaders(body)
File "C:\Python27\lib\httplib.py", line 1038, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 882, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 844, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 1263, in connect
server_hostname=server_hostname)
File "C:\Python27\lib\ssl.py", line 369, in wrap_socket
_context=self)
File "C:\Python27\lib\ssl.py", line 617, in __init__
self.do_handshake()
File "C:\Python27\lib\ssl.py", line 854, in do_handshake
match_hostname(self.getpeercert(), self.server_hostname)
File "C:\Python27\lib\ssl.py", line 288, in match_hostname
% (hostname, ', '.join(map(repr, dnsnames))))
CertificateError: hostname '216.58.207.78' doesn't match either of '*.google.com', '*.android.com', '*.appengine.google.com', '*.cloud.google.com', '*.crowdsource.google.com', '*.g.co', '*.gcp.gvt2.com', '*.ggpht.cn', '*.google-analytics.com', '*.google.ca', '*.google.cl', '*.google.co.in', '*.google.co.jp', '*.google.co.uk', '*.google.com.ar', '*.google.com.au', '*.google.com.br', '*.google.com.co', '*.google.com.mx', '*.google.com.tr', '*.google.com.vn', '*.google.de', '*.google.es', '*.google.fr', '*.google.hu', '*.google.it', '*.google.nl', '*.google.pl', '*.google.pt', '*.googleadapis.com', '*.googleapis.cn', '*.googlecnapps.cn', '*.googlecommerce.com', '*.googlevideo.com', '*.gstatic.cn', '*.gstatic.com', '*.gstaticcnapps.cn', '*.gvt1.com', '*.gvt2.com', '*.metric.gstatic.com', '*.urchin.com', '*.url.google.com', '*.youtube-nocookie.com', '*.youtube.com', '*.youtubeeducation.com', '*.youtubekids.com', '*.yt.be', '*.ytimg.com', 'android.clients.google.com', 'android.com', 'developer.android.google.cn', 'developers.android.google.cn', 'g.co', 'ggpht.cn', 'goo.gl', 'google-analytics.com', 'google.com', 'googlecnapps.cn', 'googlecommerce.com', 'source.android.google.cn', 'urchin.com', 'www.goo.gl', 'youtu.be', 'youtube.com', 'youtubeeducation.com', 'youtubekids.com', 'yt.be'

# Fixed code
def get_redirected(url):
    # Returns false if url is not right
    headers = {"User-Agent": "Mozilla/5.0"}
    request = urllib2.Request(url, headers=headers)
    try:
        return urllib2.urlopen(
            request, context=ssl._create_unverified_context()
        ).geturl()
    except urllib2.URLError:
        LOG.error("Can't reach struts2 server")
        return False