Retire Support For Python 2 (#153)

* removed python2 from readme and travis

* changed except on caps hunter to except PermissionError, supports only from python3

* removed python2 support in main file

* changed cvehunter to use res.text in place of res.content (python3 returnes a bytes object for content)
This commit is contained in:
danielsagi
2019-07-10 13:23:08 +03:00
committed by Liz Rice
parent 911ec5eaf1
commit cc70c83ba4
5 changed files with 9 additions and 21 deletions

View File

@@ -3,7 +3,6 @@ language: python
cache: pip
matrix:
include:
- python: 2.7
#- python: 3.4
#- python: 3.5
- python: 3.6

View File

@@ -74,7 +74,7 @@ You can run the kube-hunter python code directly on your machine.
#### Prerequisites
You will need the following installed:
* python 2.7 or python 3.x
* python 3.x
* pip
Clone the repository:

View File

@@ -1,14 +1,8 @@
#!/usr/bin/env python
from __future__ import print_function
import argparse
import logging
import threading
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
parser = argparse.ArgumentParser(description='Kube-Hunter - hunts for security weaknesses in Kubernetes clusters')
parser.add_argument('--list', action="store_true", help="displays all tests in kubehunter (add --active flag to see active tests)")
@@ -75,13 +69,13 @@ def interactive_set_config():
print("Choose one of the options below:")
for i, (option, explanation) in enumerate(options):
print("{}. {} ({})".format(i+1, option.ljust(20), explanation))
choice = raw_input("Your choice: ")
choice = input("Your choice: ")
if choice == '1':
config.remote = raw_input("Remotes (separated by a ','): ").replace(' ', '').split(',')
config.remote = input("Remotes (separated by a ','): ").replace(' ', '').split(',')
elif choice == '2':
config.internal = True
elif choice == '3':
config.cidr = raw_input("CIDR (example - 192.168.1.0/24): ").replace(' ', '')
config.cidr = input("CIDR (example - 192.168.1.0/24): ").replace(' ', '')
else:
return False
return True

View File

@@ -30,10 +30,7 @@ class PodCapabilitiesHunter(Hunter):
s.close()
logging.debug("Passive hunter's closing RAW socket")
return True
# python2 does not support PermissionError, should be sufficiant to say that
# NET_RAW is disabled by catching all exception. after we stop support for
# python2, should replace to except PermissionError explicitly
except:
except PermissionError:
logging.debug("CAP_NET_RAW not enabled")
def execute(self):

View File

@@ -1,8 +1,6 @@
import logging
import json
import requests
import uuid
import ast
from ...core.events import handler
from ...core.events.types import Vulnerability, Event
@@ -55,11 +53,11 @@ class IsVulnerableToCVEAttack(Hunter):
try:
res = requests.get("{path}/version".format(path=self.path),
headers=self.headers, verify=False)
self.api_server_evidence = res.content
resDict = ast.literal_eval(res.content)
self.api_server_evidence = res.text
resDict = json.loads(res.text)
version = resDict["gitVersion"].split('.')
first_two_minor_digits = eval(version[1])
last_two_minor_digits = eval(version[2])
first_two_minor_digits = int(version[1])
last_two_minor_digits = int(version[2])
logging.debug('Passive Hunter got version from the API server version end point: %d.%d', first_two_minor_digits, last_two_minor_digits)
return [first_two_minor_digits, last_two_minor_digits]