Skip to content

Commit

Permalink
now using names instead of message numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
susperius committed Jul 30, 2015
1 parent f5511bc commit 2220dbd
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 36 deletions.
2 changes: 1 addition & 1 deletion node/model/message_types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__author__ = 'susperius'

MESSAGE_TYPES = {0x01: "BEACON", 0x02: "SET_CONFIG", 0x03: "GET_CONFIG", 0x04: "OK", 0x05: "RESET", 0x06: "", 0xFF: "CRASH"}
MESSAGE_TYPES = {"BEACON": 0x01, "SET_CONFIG": 0x02, "GET_CONFIG": 0x03, "OK": 0x04, "RESET": 0x05, "CRASH": 0xFF }
1 change: 1 addition & 0 deletions node/worker/fuzzingworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def __create_testcases(self):
filename += "." + self._fuzzer.file_type
with open("testcases/" + filename, "wb+") as fd:
fd.write(self._fuzzer.fuzz())
gevent.sleep(0) # Get a chance to do other things

def start_worker(self):
if self._greenlet is None:
Expand Down
26 changes: 10 additions & 16 deletions node/worker/listenerworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,16 @@ def __worker_green(self):

def _listener_worker(self, task):
msg_type, msg = pickle.loads(task[1])
self._logger.debug("Listener Worker -> Type:" + str(msg_type))
if msg_type in MESSAGE_TYPES.keys():
if msg_type == 0x01:
pass
elif msg_type == 0x02: # SET_CONFIG
self._set_config(msg)
elif msg_type == 0x03: # GET_CONFIG
self._report_queue.put([0x03, ""])
elif msg_type == 0x04:
pass
elif msg_type == 0x05: # RESET
self._reset = True
elif msg_type == 0x06:
pass
elif msg_type == 0xFF:
pass
if msg_type == 0x01:
pass
elif MESSAGE_TYPES['SET_CONFIG'] == msg_type:
self._set_config(msg)
elif MESSAGE_TYPES['GET_CONFIG'] == msg_type:
self._report_queue.put([MESSAGE_TYPES['GET_CONFIG'], ""])
elif MESSAGE_TYPES['OK'] == msg_type:
pass
elif MESSAGE_TYPES['RESET'] == msg_type:
self._reset = True

def _set_config(self, msg):
with open("node_config.xml", 'w+') as fd:
Expand Down
6 changes: 4 additions & 2 deletions node/worker/reportworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
from communication.reportclient import ReportClient
from worker import Worker
from model.message_types import MESSAGE_TYPES


class ReportWorker(Worker):
Expand All @@ -24,12 +25,13 @@ def __worker_green(self):
while self._running:
if not self._report_queue.empty():
msg_type, msg = self._report_queue.get_nowait()
if msg_type == 0xFF:
self._logger.debug("Report job Type --> " + str(msg_type))
if MESSAGE_TYPES['CRASH'] == msg_type:
self.__report_crash_local(msg)
if self._net_mode:
data_string = pickle.dumps([msg_type, self._file_type, self._program, msg], -1)
self._client.send(data_string)
elif msg_type == 0x03:
elif MESSAGE_TYPES['GET_CONFIG'] == msg_type:
with open("node_config.xml", 'r') as fd:
config = fd.read()
self._client.send(pickle.dumps([msg_type, config], -1))
Expand Down
18 changes: 7 additions & 11 deletions pyfuzz2_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from worker.reportworker import ReportWorker
from worker.nodeclientworker import NodeClientWorker
from web.main import WebSite

from node.model.message_types import MESSAGE_TYPES
gevent.monkey.patch_all()

CONFIG_FILENAME = "server_config.xml"
Expand Down Expand Up @@ -65,25 +65,22 @@ def web_main(self, environ, start_response):
if 'reboot' in parameters:
key = parameters['reboot'][0]
self._beacon_worker.nodes[key].status = False
self._node_queue.put([(key, self._beacon_worker.nodes[key].listener_port), 0x05, ""])
self._node_queue.put([(key, self._beacon_worker.nodes[key].listener_port), MESSAGE_TYPES['RESET'],
""])
if "submit" in parameters and "node" in parameters:
key = parameters['node'][0]
self._logger.debug("Preparing new config")
node_conf = node.model.config.ConfigParser.create_config(environ['wsgi.input'].read())
self._beacon_worker.nodes[key].status = False
self._node_queue.put([(key, self._beacon_worker.nodes[key].listener_port), 0x02, node_conf])
self._node_queue.put([(key, self._beacon_worker.nodes[key].listener_port),
MESSAGE_TYPES['SET_CONFIG'], node_conf])
if "del" in parameters:
key = parameters['del'][0]
del(self._beacon_worker.nodes[key])
status, headers, html = site.home(self._beacon_worker.nodes)
elif func == "node_detail":
if "node" in parameters and parameters['node'][0] in self._beacon_worker.nodes.keys():
key = parameters['node'][0]
'''if "submit" in parameters:
self._logger.debug("Preparing new config")
node_conf = node.model.config.ConfigParser.create_config(environ['wsgi.input'].read())
self._beacon_worker.nodes[key].status = False
self._node_queue.put([(key, self._beacon_worker.nodes[key].listener_port), 0x02, node_conf])'''
status, headers, html = site.node_detail(self._beacon_worker.nodes[key])
else:
status, headers, html = site.file_not_found()
Expand All @@ -94,9 +91,8 @@ def web_main(self, environ, start_response):
else:
status, headers, html = site.file_not_found()
start_response(status, headers)
# debug
html += "<br><br>" + str(environ) + "<br><br>" + func + "<br><br>" + environ['wsgi.input'].read()
# /debug
if self._logger.level == logging.DEBUG:
html += "<br><br>" + str(environ) + "<br><br>" + func + "<br><br>" + environ['wsgi.input'].read()
return html


Expand Down
8 changes: 4 additions & 4 deletions web/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ def node_detail(self, node):
fuzz_types_options = ""
for key in FUZZERS.keys():
fuzz_types_options += "<option>"+key+"</option>\r\n"
node_conf_table += "<tr>\r\n<td><b>Fuzzer Type</b></td>\r\n<td><select id=\"fuzzers\" " + \
"onLoad=\"set_select_value('" + fuzzer_conf["fuzzer_type"] + "')\" " + \
" name=\"fuzzer_type\" onChange=\"changeFuzzer()\">\r\n" + \
fuzz_types_options+"</select>\r\n</td>\r\n</tr>\r\n"
node_conf_table += "<tr>\r\n<td><b>Fuzzer Type</b></td>\r\n<td><select id=\"fuzzers\" " + \
"onLoad=\"set_select_value('" + fuzzer_conf["fuzzer_type"] + "')\" " + \
" name=\"fuzzer_type\" onChange=\"changeFuzzer()\">\r\n" + \
fuzz_types_options+"</select>\r\n</td>\r\n</tr>\r\n"
node_conf_table += "<div id=\"fuzz_config\">\r\n"
for key in FUZZERS[fuzzer_conf["fuzzer_type"]][0]:
node_conf_table += "<tr>\r\n<td><b>" + key + "</b></td>\r\n" + \
Expand Down
5 changes: 3 additions & 2 deletions worker/reportworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import os
from worker import Worker
from node.model.message_types import MESSAGE_TYPES


class ReportWorker(Worker):
Expand All @@ -20,14 +21,14 @@ def __worker_green(self):
address, data_packed = self._report_queue.get_nowait()
data_unpacked = pickle.loads(data_packed)
msg_type = data_unpacked[0]
if msg_type == 0xFF:
if MESSAGE_TYPES['CRASH'] == msg_type:
file_type = data_unpacked[1]
program = data_unpacked[2]
report = data_unpacked[3]
node_name = self._nodes[address].name
self.__report_crash_local(node_name, file_type, program, report)
self._nodes[address].crashed()
elif msg_type == 0x03:
elif MESSAGE_TYPES['GET_CONFIG'] == msg_type:
config = data_unpacked[1]
self._nodes[address].config = config
gevent.sleep(0)
Expand Down

0 comments on commit 2220dbd

Please sign in to comment.