Skip to content

Commit 1587d2b

Browse files
authored
Merge pull request #2376 from mitre/fix_flake8_test
Resolve flake8 errors
2 parents 3e2dc4d + 7196156 commit 1587d2b

26 files changed

+0
-78
lines changed

app/api/packs/advanced.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ async def enable(self):
2222
self.app_svc.application.router.add_route('GET', '/advanced/configurations', self._section_configurations)
2323
self.app_svc.application.router.add_route('GET', '/advanced/exfills', self._section_exfil_files)
2424

25-
""" PRIVATE """
26-
2725
@check_authorization
2826
@template('planners.html')
2927
async def _section_planners(self, request):

app/api/packs/campaign.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ async def enable(self):
2121
self.app_svc.application.router.add_route('GET', '/campaign/profiles', self._section_profiles)
2222
self.app_svc.application.router.add_route('GET', '/campaign/operations', self._section_operations)
2323

24-
""" PRIVATE """
25-
2624
@check_authorization
2725
@template('agents.html')
2826
async def _section_agent(self, request):
@@ -110,8 +108,6 @@ def load_usage_markdown(header):
110108
return dict(operations=operations, groups=groups, adversaries=adversaries, sources=sources, planners=planners,
111109
obfuscators=obfuscators, usage=usage)
112110

113-
""" PRIVATE """
114-
115111
@staticmethod
116112
def _rollup_abilities(abilities):
117113
rolled = defaultdict(list)

app/api/rest_api.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ async def enable(self):
4343
self.app_svc.application.router.add_route('GET', '/api/{index}', self.rest_core_info)
4444
self.app_svc.application.router.add_route('GET', '/file/download_exfil', self.download_exfil_file)
4545

46-
""" BOILERPLATE """
47-
4846
@template('login.html', status=401)
4947
async def login(self, request):
5048
return dict()
@@ -65,8 +63,6 @@ async def landing(self, request):
6563
data = dict(plugins=[p.display for p in plugins], errors=self.app_svc.errors + self._request_errors(request))
6664
return render_template('%s.html' % access[0].name, request, data)
6765

68-
""" API ENDPOINTS """
69-
7066
@check_authorization
7167
async def rest_core(self, request):
7268
try:
@@ -165,8 +161,6 @@ def is_in_exfil_dir(f):
165161
return web.HTTPNotFound(body=str(e))
166162
return web.HTTPBadRequest(body='A file needs to be specified for download')
167163

168-
""" PRIVATE """
169-
170164
@staticmethod
171165
def _request_errors(request):
172166
errors = []

app/api/v2/handlers/base_object_api.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ def __init__(self, description, obj_class, schema, ram_key, id_property, auth_sv
2323
def add_routes(self, app: web.Application):
2424
pass
2525

26-
"""GET"""
27-
2826
async def get_all_objects(self, request: web.Request):
2927
access = await self.get_request_permissions(request)
3028

@@ -48,8 +46,6 @@ async def get_object(self, request: web.Request):
4846

4947
return self._api_manager.dump_object_with_filters(obj, include, exclude)
5048

51-
"""POST"""
52-
5349
async def create_object(self, request: web.Request):
5450
data = await request.json()
5551

@@ -75,8 +71,6 @@ async def _error_if_object_with_id_exists(self, obj_id: str):
7571
if self._api_manager.find_object(self.ram_key, search):
7672
raise JsonHttpBadRequest(f'{self.description.capitalize()} with given id already exists: {obj_id}')
7773

78-
"""PATCH"""
79-
8074
async def update_object(self, request: web.Request):
8175
data, access, obj_id, query, search = await self._parse_common_data_from_request(request)
8276

@@ -94,8 +88,6 @@ async def update_on_disk_object(self, request: web.Request):
9488
raise JsonHttpNotFound(f'{self.description.capitalize()} not found: {obj_id}')
9589
return obj
9690

97-
"""PUT"""
98-
9991
async def create_or_update_object(self, request: web.Request):
10092
data, access, obj_id, query, search = await self._parse_common_data_from_request(request)
10193

@@ -120,8 +112,6 @@ async def create_or_update_on_disk_object(self, request: web.Request):
120112

121113
return obj
122114

123-
"""DELETE"""
124-
125115
async def delete_object(self, request: web.Request):
126116
obj_id = request.match_info.get(self.id_property)
127117

@@ -141,8 +131,6 @@ async def delete_on_disk_object(self, request: web.Request):
141131
obj_id = request.match_info.get(self.id_property)
142132
await self._api_manager.remove_object_from_disk_by_id(identifier=obj_id, ram_key=self.ram_key)
143133

144-
"""Helpers"""
145-
146134
async def _parse_common_data_from_request(self, request) -> (dict, dict, str, dict, dict):
147135
data = {}
148136
raw_body = await request.read()

app/api/v2/handlers/operation_api.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ async def get_potential_links_by_paw(self, request: web.Request):
163163
potential_links = await self._api_manager.get_potential_links(operation_id, access, paw)
164164
return web.json_response(potential_links)
165165

166-
'''Overridden Methods'''
167-
168166
async def create_object(self, request: web.Request):
169167
data = await request.json()
170168
await self._error_if_object_with_id_exists(data.get(self.id_property))
@@ -178,8 +176,6 @@ async def update_object(self, request: web.Request):
178176
raise JsonHttpNotFound(f'{self.description.capitalize()} not found: {obj_id}')
179177
return obj
180178

181-
''' PRIVATE '''
182-
183179
async def _read_output_parameter_(self, request: web.Request):
184180
raw_body = await request.read()
185181
output = False

app/api/v2/managers/ability_api_manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ async def update_on_disk_object(self, obj: Any, data: dict, ram_key: str, id_pro
4545
await self._save_and_reload_object(file_path, existing_obj_data, obj_class, obj.access)
4646
return next(self.find_objects(ram_key, {id_property: obj_id}))
4747

48-
'''Helpers'''
4948
def _validate_ability_data(self, create: bool, data: dict):
5049
# Correct ability_id key for ability file saving.
5150
data['id'] = data.pop('ability_id', '')

app/api/v2/managers/base_api_manager.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ def __init__(self, data_svc, file_svc, logger=None):
2323
def log(self):
2424
return self._log
2525

26-
"""Object Retrieval"""
27-
2826
def find_objects(self, ram_key: str, search: dict = None):
2927
"""Find objects matching the given criteria"""
3028
for obj in self._data_svc.ram[ram_key]:
@@ -54,8 +52,6 @@ def dump_object_with_filters(obj: Any, include: List[str] = None, exclude: List[
5452
dumped.pop(exclude_attribute, None)
5553
return dumped
5654

57-
"""Object Creation"""
58-
5955
def create_object_from_schema(self, schema: SchemaMeta, data: dict, access: BaseWorld.Access):
6056
obj_schema = schema()
6157
obj = obj_schema.load(data)
@@ -79,8 +75,6 @@ def _get_allowed_from_access(self, access) -> BaseWorld.Access:
7975
else:
8076
return self._data_svc.Access.RED
8177

82-
"""Object Updates"""
83-
8478
def find_and_update_object(self, ram_key: str, data: dict, search: dict = None):
8579
for obj in self.find_objects(ram_key, search):
8680
new_obj = self.update_object(obj, data)
@@ -112,17 +106,13 @@ async def update_on_disk_object(self, obj: Any, data: dict, ram_key: str, id_pro
112106
await self._save_and_reload_object(file_path, existing_obj_data, obj_class, obj.access)
113107
return next(self.find_objects(ram_key, {id_property: obj_id}))
114108

115-
""""Object Replacement"""
116-
117109
async def replace_on_disk_object(self, obj: Any, data: dict, ram_key: str, id_property: str):
118110
obj_id = getattr(obj, id_property)
119111
file_path = await self._get_existing_object_file_path(obj_id, ram_key)
120112

121113
await self._save_and_reload_object(file_path, data, type(obj), obj.access)
122114
return next(self.find_objects(ram_key, {id_property: obj_id}))
123115

124-
""""Object Removal"""
125-
126116
async def remove_object_from_memory_by_id(self, identifier: str, ram_key: str, id_property: str):
127117
await self._data_svc.remove(ram_key, {id_property: identifier})
128118

@@ -132,8 +122,6 @@ async def remove_object_from_disk_by_id(self, identifier: str, ram_key: str):
132122
if os.path.exists(file_path):
133123
os.remove(file_path)
134124

135-
"""Helpers"""
136-
137125
@staticmethod
138126
async def _get_new_object_file_path(identifier: str, ram_key: str) -> str:
139127
"""Create file path for new object"""

app/api/v2/managers/operation_api_manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ async def get_potential_links(self, operation_id: str, access: dict, paw: str =
122122
potential_links = [potential_link.display for potential_link in operation.potential_links]
123123
return potential_links
124124

125-
"""Object Creation Helpers"""
126125
async def get_operation_object(self, operation_id: str, access: dict):
127126
try:
128127
operation = (await self._data_svc.locate('operations', {'id': operation_id}))[0]

app/contacts/contact_gist.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ async def get_uploads(self):
141141
self.log.error('Receiving file uploads over c2 (%s) failed: %s' % (self.__class__.__name__, e))
142142
return []
143143

144-
""" PRIVATE """
145-
146144
async def _send_instructions(self, agent, instructions):
147145
response = dict(paw=agent.paw,
148146
sleep=await agent.calculate_sleep(),

app/contacts/contact_html.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ def __init__(self, services):
1616
async def start(self):
1717
self.app_svc.application.router.add_route('*', self.get_config('app.contact.html'), self._accept_beacon)
1818

19-
""" PRIVATE """
20-
2119
@template('weather.html')
2220
async def _accept_beacon(self, request):
2321
try:

app/contacts/contact_http.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ def __init__(self, services):
1717
async def start(self):
1818
self.app_svc.application.router.add_route('POST', '/beacon', self._beacon)
1919

20-
""" PRIVATE """
21-
2220
async def _beacon(self, request):
2321
try:
2422
profile = json.loads(self.contact_svc.decode_bytes(await request.read()))

app/contacts/contact_slack.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ async def get_uploads(self):
150150
self.log.error('Receiving file uploads over c2 (%s) failed: %s' % (self.__class__.__name__, e))
151151
return []
152152

153-
""" PRIVATE """
154-
155153
async def _send_instructions(self, agent, instructions):
156154
response = dict(paw=agent.paw,
157155
sleep=await agent.calculate_sleep(),

app/contacts/contact_tcp.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ async def send(self, session_id: int, cmd: str, timeout: int = 60) -> Tuple[int,
9393
self.log.exception(e)
9494
return 1, '~$ ', str(e), ''
9595

96-
""" PRIVATE """
97-
9896
@staticmethod
9997
async def _handshake(reader):
10098
profile_bites = (await reader.readline()).strip()

app/objects/c_agent.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,6 @@ def assign_pending_executor_change(self):
332332
self._executor_change_to_assign = None
333333
return executor_change
334334

335-
""" PRIVATE """
336-
337335
def _replace_payload_data(self, decoded_cmd, file_svc):
338336
for uuid in re.findall(self.RESERVED['payload'], decoded_cmd):
339337
if self.is_uuid4(uuid):

app/objects/c_operation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,6 @@ async def write_event_logs_to_disk(self, file_svc, data_svc, output=False):
337337
await self._write_logs_to_disk(event_logs, file_name, event_logs_dir, file_svc)
338338
logging.debug('Wrote event logs for operation %s to disk at %s/%s' % (self.name, event_logs_dir, file_name))
339339

340-
""" PRIVATE """
341-
342340
async def _write_logs_to_disk(self, logs, file_name, dest_dir, file_svc):
343341
logs_dumps = json.dumps(logs)
344342
await file_svc.save_file(file_name, logs_dumps.encode(), dest_dir, encrypt=False)

app/objects/c_planner.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ async def which_plugin(self):
6262
return plugin
6363
return None
6464

65-
""" PRIVATE """
66-
6765
@staticmethod
6866
def _set_stopping_conditions(conditions):
6967
if conditions:

app/objects/c_plugin.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ async def expand(self, services):
8484
except Exception as e:
8585
logging.error('Error expanding plugin=%s, %s' % (self.name, e))
8686

87-
""" PRIVATE """
88-
8987
def _load_module(self):
9088
try:
9189
return import_module('plugins.%s.hook' % self.name)

app/objects/secondclass/c_link.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ def replace_origin_link_id(self):
223223
decoded_cmd = self.decode_bytes(self.command)
224224
self.command = self.encode_string(decoded_cmd.replace(self.RESERVED['origin_link_id'], self.id))
225225

226-
""" PRIVATE """
227-
228226
def _emit_status_change_event(self, from_status, to_status):
229227
event_svc = BaseService.get_service('event_svc')
230228

app/service/app_svc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ def register_subapp(self, path: str, app: web.Application):
193193
def get_loaded_plugins(self):
194194
return tuple(self._loaded_plugins)
195195

196-
""" PRIVATE """
197-
198196
async def _save_configurations(self, main_config_file='default'):
199197
for cfg_name, cfg_file in [('main', main_config_file), ('agents', 'agents'), ('payloads', 'payloads')]:
200198
with open('conf/%s.yml' % cfg_file, 'w') as config:

app/service/contact_svc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ async def get_tunnel(self, name):
9393
tunnel = [t for t in self.tunnels if t.name == name]
9494
return tunnel[0] if len(tunnel) > 0 else None
9595

96-
""" PRIVATE """
97-
9896
async def _sanitize_paw(self, input_paw):
9997
"""
10098
Remove any characters from the given paw that do not fall in the following set:

app/service/data_svc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,6 @@ async def load_yaml_file(self, object_class, filename, access):
241241
obj.access = access
242242
await self.store(obj)
243243

244-
""" PRIVATE """
245-
246244
async def _load(self, plugins=()):
247245
try:
248246
async_tasks = []

app/service/file_svc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,6 @@ def add_xored_extension(filename):
201201
return filename
202202
return '%s.xored' % filename
203203

204-
""" PRIVATE """
205-
206204
def _save(self, filename, content, encrypt=True):
207205
if encrypt and (self.encryptor and self.encrypt_output):
208206
content = bytes(FILE_ENCRYPTION_FLAG, 'utf-8') + self.encryptor.encrypt(content)

app/service/learning_svc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ async def learn(self, facts, link, blob, operation=None):
5050
await update_scores(operation=None, increment=len(found_facts), used=facts, facts=link.facts)
5151
await self._store_results(link, found_facts, operation)
5252

53-
""" PRIVATE """
54-
5553
@staticmethod
5654
async def _save_fact(link, facts, fact, operation=None):
5755
fact.origin_type = OriginType.LEARNED

app/service/planning_svc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,6 @@ async def sort_links(links):
274274
"""
275275
return sorted(links, key=lambda k: (-k.score))
276276

277-
""" PRIVATE """
278-
279277
async def _stop_bucket_exhaustion(self, planner, operation, condition_stop):
280278
"""Determine whether to continue running the bucket.
281279

app/service/rest_svc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,6 @@ async def build_potential_links(self, operation, agents, abilities):
341341
potential_links.append(pl)
342342
return await self.get_service('planning_svc').sort_links(potential_links)
343343

344-
""" PRIVATE """
345-
346344
async def _build_operation_object(self, access, data):
347345
name = data.pop('name')
348346
group = data.pop('group', '')

app/utility/base_planning_svc.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ async def obfuscate_commands(self, agent, obfuscator, links):
166166
s_link.command = self.encode_string(mod.run(s_link))
167167
return links
168168

169-
""" PRIVATE """
170-
171169
@staticmethod
172170
def _list_historic_duplicate_singletons(operation):
173171
"""

0 commit comments

Comments
 (0)