Skip to content

Commit

Permalink
fix(CornerShot ): total shots count improved
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiesec committed Feb 8, 2021
1 parent 2a218f7 commit 1da0efe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ Adding carriers, target and ports is achieved via the *add_shots* method. Once r
from cornershot import CornerShot
cs = CornerShot("username", "password", "fqdn")
cs.add_shots(carriers=["192.168.1.1"],targets=["192.168.1.2","192.168.1.3"])
cs.lock_and_load()
results = cs.open_fire()
```

Expand Down
1 change: 0 additions & 1 deletion cornershot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def parse_port_ranges(ranges):

cs = CornerShot(args.user, args.password, args.domain, workers=args.threads)
cs.add_shots(parse_ip_ranges(args.carrier), parse_ip_ranges(args.target), target_ports=parse_port_ranges(args.tports))
cs.lock_and_load()
cs.open_fire()

except KeyboardInterrupt:
Expand Down
38 changes: 20 additions & 18 deletions cornershot/cornershot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

from . import logger

MAX_QUEUE_SIZE = 1000
MAX_QUEUE_SIZE = 3000
TARGET_PORTS = [135, 445, 3389, 5985, 5986]

DEFAULT_SHOTS = [EVENShot, RPRNShot, RRPShot, EVEN6Shot]

class CornerShot(object):
def __init__(self, username, password, domain, skip_scanned=False, workers=250, shots=None):
def __init__(self, username, password, domain, workers=250, shots=None):

logger.debug(f'CS created with username: {username},domain:{domain},workers:{workers}')
if shots is None:
Expand All @@ -34,7 +34,8 @@ def __init__(self, username, password, domain, skip_scanned=False, workers=250,
self.results = {}
self.shot_list = []
self.total_shots = 0
self.skip_scanned = skip_scanned
self.current_tasks = []
self.skip_scanned = False
self.already_scanned = []

def _takeashot(self):
Expand All @@ -50,10 +51,12 @@ def _takeashot(self):
except Exception:
logger.debug(f'Unexpected exception during shot', exc_info=True)
finally:
logger.info("Putting bullter to result queue...")
self.bulletQ.task_done()
self.resultQ.put(res)
logger.debug(f'Bullet is none!')
except (queue.Empty,TimeoutError):
pass
logger.debug(f'Exception during bullet load', exc_info=True)
except Exception:
logger.debug(f'Unexpected exception during bullet load', exc_info=True)

Expand Down Expand Up @@ -121,31 +124,32 @@ def _get_next_tasks(self,remaining):
trgt = bullet.target + ":" + str(bullet.trgt_port)
if trgt not in self.already_scanned:
new_tasks.append(bullet)
else:
self.total_shots -= 1
iterated_shots += 1
remaining -= 1
else:
break
self.shot_list = self.shot_list[iterated_shots + 1:]
self.shot_list = self.shot_list[iterated_shots:]

else:
new_tasks = self.shot_list[0:remaining]
new_tasks = self.shot_list[0:remaining ]
self.shot_list = self.shot_list[remaining + 1:]

return new_tasks


def _shots_manager(self):
remaining = MAX_QUEUE_SIZE
self.total_shots = len(self.shot_list)
while self.runthreads:
new_tasks = self._get_next_tasks(remaining)
# new_tasks = self.shot_list[0:remaining]
# self.shot_list = self.shot_list[remaining + 1:]
tasks = new_tasks
shuffle(tasks)
self.current_tasks = self._get_next_tasks(remaining)

shuffle(self.current_tasks)

remaining = remaining - len(tasks)
remaining = remaining - len(self.current_tasks)

for bt in tasks:
for bt in self.current_tasks:
time.sleep(uniform(0, 0.026))
self.bulletQ.put(bt)

Expand All @@ -167,8 +171,9 @@ def _shots_manager(self):

self.total_shots = 0

def open_fire(self,blocking=True):
self.lock_and_load()
def open_fire(self,blocking=True,skip_scanned=False):
self.skip_scanned = skip_scanned

num_threads = min(self.total_shots,self.workers)

if self.total_shots > 0:
Expand All @@ -185,9 +190,6 @@ def open_fire(self,blocking=True):
def read_results(self):
return self.results

def lock_and_load(self):
self.total_shots = len(self.shot_list)

def remaining_shots(self):
return self.total_shots

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
setup(
name='cornershot',
python_requires='>=3',
version='0.2.4',
version='0.2.5',
description='Library to test network connectivity',
long_description_content_type='text/markdown',
long_description=long_description,
Expand Down

0 comments on commit 1da0efe

Please sign in to comment.