Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
urllib2 = "*"

[requires]
python_version = "3.7"
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<tr>
<th>Version</th>
<td>
1.1.0
1.1.1
</td>
</tr>
<tr>
Expand Down Expand Up @@ -41,6 +41,13 @@ You can install PyJFuzz with the following command
git clone https://github.com/mseclab/PyJFuzz.git && cd PyJFuzz && sudo python setup.py install
```

Also, you might want to use the `pipenv` tool to setup the environment.

```
pipenv install --dev

```

Documentation and Examples
==========================

Expand Down
14 changes: 9 additions & 5 deletions pyjfuzz/core/pjf_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
from .pjf_version import PYJFUZZ_LOGLEVEL
import logging
import time

import sys
import logging


from .pjf_version import PYJFUZZ_LOGLEVEL


class PJFLogger(object):

@staticmethod
def init_logger():
logger = logging.getLogger(__name__)
logger.setLevel(level=PYJFUZZ_LOGLEVEL)
filehandler = logging.FileHandler("pjf_{0}.log".format(time.strftime("%d_%m_%Y")))
logger.addHandler(filehandler)
streamhandler = logging.StreamHandler()
logger.addHandler(streamhandler)
sys.tracebacklimit = 10

return logger
7 changes: 4 additions & 3 deletions pyjfuzz/pyjfuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
from .core.pjf_logger import PJFLogger
from .core import pjf_configuration
import argparse
import time
import argparse

from core import pjf_configuration
from core.pjf_logger import PJFLogger


def init_logger():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def install_gramfuzz():

setup(
name="PyJFuzz",
version="1.1.0",
version="1.1.1",
author="Daniele Lingualossa",
author_email="d.linguaglossa@mseclab.it",
description="Trivial JSON fuzzer written in python",
Expand Down
2 changes: 2 additions & 0 deletions test/test_pjf_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def test_json_configuration(self):
parser = argparse.ArgumentParser(description='', formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--J', type=str, default=None)
parser.add_argument('--no-logo', action='store_true', dest='nologo', default=False, required=False)
# This usage case will faile when you invoke the tool directly.
# ToDo: Implement a use case when this test his invoked directly.
parsed = parser.parse_args()
args = PJFConfiguration(parsed)
for arg in parsed.__dict__:
Expand Down
5 changes: 3 additions & 2 deletions test/test_pjf_external_fuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

class TestPJFExternalFuzzer(unittest.TestCase):

# The assumption that the file 'radamsa' is present needs to be challenged.
def test_string_mutation(self):
external_fuzzer = PJFExternalFuzzer(PJFConfiguration(Namespace(nologo=True, command=["radamsa"], stdin=True)))
mutated = external_fuzzer.execute("MUTATION_EXAMPLE")
Expand All @@ -39,11 +40,11 @@ def test_string_mutation(self):
def test_file_mutation(self):
external_fuzzer = PJFExternalFuzzer(PJFConfiguration(Namespace(nologo=True, command=["radamsa","@@"],
stdin=False)))
with file("test.json", "wb") as json_file:
with open("test.json", "w") as json_file:
json_file.write('{"a": 1}')
json_file.close()
external_fuzzer.execute("test.json")
with file("test.json", "rb") as json_file:
with open("test.json", "r") as json_file:
content = json_file.read()
json_file.close()
self.assertTrue(len(content) > 0)
Expand Down
17 changes: 8 additions & 9 deletions test/test_pjf_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
from argparse import Namespace
import time
import unittest
import urllib2

import requests



from pyjfuzz.core.pjf_server import PJFServer
Expand All @@ -42,15 +44,12 @@ def test_start_object(self):
utf8=False, nologo=True)))
server.run()
time.sleep(2)
json_http = urllib2.urlopen("http://127.0.0.1:8080").read()
try:
import requests
requests.packages.urllib3.disable_warnings()
json_https = requests.get('https://127.0.0.1:8443', verify=False).content
self.assertTrue(json_https)
except ImportError:
pass
requests.packages.urllib3.disable_warnings()

json_http = requests.get('http://127.0.0.1:8080').content
json_https = requests.get('https://127.0.0.1:8443', verify=False).content
self.assertTrue(json_http)

server.stop()


Expand Down