2016-08-24 23:31:16 +08:00
|
|
|
from network import HostFinger
|
|
|
|
|
|
|
|
|
|
|
|
class HTTPFinger(HostFinger):
|
2016-08-25 20:45:47 +08:00
|
|
|
"""
|
2016-08-24 23:31:16 +08:00
|
|
|
Goal is to recognise HTTP servers, where what we currently care about is apache.
|
2016-08-25 20:45:47 +08:00
|
|
|
"""
|
|
|
|
|
2016-08-24 23:31:16 +08:00
|
|
|
def __init__(self):
|
|
|
|
self._config = __import__('config').WormConfiguration
|
2016-08-25 20:45:47 +08:00
|
|
|
self.HTTP = [(port, str(port)) for port in self._config.HTTP_PORTS]
|
2016-08-24 23:31:16 +08:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _banner_match(service, host, banner):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def get_host_fingerprint(self, host):
|
|
|
|
assert isinstance(host, VictimHost)
|
|
|
|
from requests import get
|
2016-08-25 20:45:47 +08:00
|
|
|
from requests.exceptions import Timeout, ConnectionError
|
2016-08-24 23:31:16 +08:00
|
|
|
from contextlib import closing
|
|
|
|
|
2016-08-25 20:43:59 +08:00
|
|
|
for port in self.HTTP:
|
2016-08-24 23:31:16 +08:00
|
|
|
# check both http and https
|
2016-08-25 20:45:47 +08:00
|
|
|
http = "http://" + host.ip_addr + ":" + port[1]
|
|
|
|
https = "https://" + host.ip_addr + ":" + port[1]
|
2016-08-24 23:31:16 +08:00
|
|
|
|
|
|
|
# try http, we don't optimise for 443
|
2016-08-25 20:43:59 +08:00
|
|
|
for url in (http, https):
|
|
|
|
try:
|
|
|
|
with closing(get(url, verify=False, timeout=1, stream=True)) as req:
|
|
|
|
server = req.headers.get('Server')
|
2016-08-25 20:45:47 +08:00
|
|
|
host.services['tcp-' + port[1]] = server
|
|
|
|
break # https will be the same on the same port
|
2016-08-25 20:43:59 +08:00
|
|
|
except Timeout:
|
|
|
|
pass
|
2016-08-25 20:45:47 +08:00
|
|
|
except ConnectionError: # Someone doesn't like us
|
2016-08-25 20:43:59 +08:00
|
|
|
pass
|
2016-08-24 23:31:16 +08:00
|
|
|
|
2016-08-25 20:45:47 +08:00
|
|
|
return True
|