예제 #1
0
    def test_from_args(self):
        fuzzer = Fuzzer(MockDevice(), u'mock-package1', u'mock-target3')
        parser = Args.make_parser('description')

        args = parser.parse_args(['1/3'])
        corpus = Corpus.from_args(fuzzer, args)
        self.assertTrue(os.path.exists(corpus.root))

        tmp_dir = tempfile.mkdtemp()
        try:
            args = parser.parse_args(['1/3', '--staging', tmp_dir])
            corpus = Corpus.from_args(fuzzer, args)
            self.assertEqual(tmp_dir, corpus.root)
        finally:
            shutil.rmtree(tmp_dir)
예제 #2
0
def main():
    parser = ArgParser('Lists corpus instances in CIPD for the named fuzzer')
    args = parser.parse_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    with Corpus.from_args(fuzzer, args) as corpus:
        cipd = Cipd(corpus)
        print(cipd.instances())
    return 0
    def pregenerate(self):
        # overriding as we have to calculate stuff for all users
        print "Generating global TFIDF data"
        pbar = ProgressBar()
        messages = self.threads.messages_by_from_user()
        users = messages.keys()
        self.counters = []

        for user in pbar(users):
            corpus = Corpus.from_messages(messages[user], self.cache)
            corpus.process()
            self.counters.append(corpus.counter())
예제 #4
0
    def pregenerate(self):
        # overriding as we have to calculate stuff for all users
        print "Generating global TFIDF data"
        pbar = ProgressBar()
        messages = self.threads.messages_by_from_user()
        users = messages.keys()
        self.counters = []

        for user in pbar(users):
            corpus = Corpus.from_messages(messages[user], self.cache)
            corpus.process()
            self.counters.append(corpus.counter())
예제 #5
0
    def test_pull(self):
        mock = MockDevice()
        fuzzer = Fuzzer(mock, u'mock-package1', u'mock-target3')
        parser = Args.make_parser('description')

        args = parser.parse_args(['1/3'])
        corpus = Corpus.from_args(fuzzer, args)
        corpus.pull()
        self.assertIn(
            ' '.join(
                mock.get_ssh_cmd([
                    'scp', '[::1]:' + fuzzer.data_path('corpus/*'), corpus.root
                ])), mock.host.history)
예제 #6
0
    def generate_for_user(self, user):
        corpus = Corpus.from_messages(self.threads.messages_including_from_user(user), self.cache)
        corpus.process()

        frequencies = corpus.frequencies(limit = self.WORD_LIMIT)

        # this step is slow, so don't redo it if the file already exists and the hash of frequencies
        # hasn't changed
        filename = "%s/wordcloud_%s.png" % (self.PLOTS_DIR, self.slug(user))
        freqs_hash = hashlib.md5(pickle.dumps(frequencies)).hexdigest()
        cache_key = "wordcloudgenerator_%s" % filename
        if not (os.path.exists(filename) and self.cache.get(cache_key) == freqs_hash):
            self.cache.set(cache_key, freqs_hash)
            WordCloudWrapper.save(frequencies, filename)
예제 #7
0
    def test_push(self):
        mock = MockDevice()
        fuzzer = Fuzzer(mock, u'mock-package1', u'mock-target3')
        parser = Args.make_parser('description')

        args = parser.parse_args(['1/3'])
        corpus = Corpus.from_args(fuzzer, args)
        with tempfile.NamedTemporaryFile(dir=corpus.root) as f:
            corpus.push()
            self.assertIn(
                ' '.join(
                    mock.get_ssh_cmd([
                        'scp', f.name, '[::1]:' + fuzzer.data_path('corpus')
                    ])), mock.host.history)
예제 #8
0
    def generate_for_user(self, user):
        corpus = Corpus.from_messages(
            self.threads.messages_including_from_user(user), self.cache)
        corpus.process()

        frequencies = corpus.frequencies(limit=self.WORD_LIMIT)

        # this step is slow, so don't redo it if the file already exists and the hash of frequencies
        # hasn't changed
        filename = "%s/wordcloud_%s.png" % (self.PLOTS_DIR, self.slug(user))
        freqs_hash = hashlib.md5(pickle.dumps(frequencies)).hexdigest()
        cache_key = "wordcloudgenerator_%s" % filename
        if not (os.path.exists(filename)
                and self.cache.get(cache_key) == freqs_hash):
            self.cache.set(cache_key, freqs_hash)
            WordCloudWrapper.save(frequencies, filename)
예제 #9
0
def main():
    parser = ArgParser(
        'Transfers a fuzzing corpus for a named fuzzer from a device to CIPD')
    args = parser.parse_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    if fuzzer.measure_corpus()[0] == 0:
        print('Ignoring ' + str(fuzzer) + '; corpus is empty.')
        return 0
    with Corpus.from_args(fuzzer, args) as corpus:
        corpus.pull()
        cipd = Cipd(corpus)
        if not args.no_cipd:
            cipd.create()
    return 0
예제 #10
0
def main():
    parser = ArgParser(
        'Starts the named fuzzer.  Additional arguments are passed through.')
    args, fuzzer_args = parser.parse_known_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    if not args.monitor:
        with Corpus.from_args(fuzzer, args) as corpus:
            cipd = Cipd(corpus)
            if not args.no_cipd:
                cipd.install('latest')
            corpus.push()

        print(
            '\n****************************************************************'
        )
        print(' Starting ' + str(fuzzer) + '.')
        print(' Outputs will be written to:')
        print('   ' + fuzzer.results())
        if not args.foreground:
            print(' You should be notified when the fuzzer stops.')
            print(' To check its progress, use `fx fuzz check ' + str(fuzzer) +
                  '`.')
            print(' To stop it manually, use `fx fuzz stop ' + str(fuzzer) +
                  '`.')
        print(
            '****************************************************************\n'
        )
        fuzzer.start(fuzzer_args)
        if not args.foreground:
            subprocess.Popen(['python', sys.argv[0], '--monitor', str(fuzzer)])
    else:
        fuzzer.monitor()
        title = str(fuzzer) + ' has stopped.'
        body = 'Output written to ' + fuzzer.results() + '.'
        print(title)
        print(body)
        host.notify_user(title, body)
    return 0
예제 #11
0
def main():
    parser = ArgParser(
        'Minimizes the current corpus for the named fuzzer. This should be ' +
        'used after running the fuzzer for a while, or after incorporating a '
        + 'third-party corpus using \'fetch-corpus\'')
    args, fuzzer_args = parser.parse_known_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    with Corpus.from_args(fuzzer, args) as corpus:
        cipd = Cipd(corpus)
        if not args.no_cipd:
            cipd.install('latest')
        corpus.push()
        if fuzzer.merge(fuzzer_args) == (0, 0):
            print('Corpus for ' + str(fuzzer) + ' is empty.')
            return 1
        corpus.pull()
        if not args.no_cipd:
            cipd.create()
    return 0
예제 #12
0
#------------------------------------------------------------------------------------------------------#
#                                           NLP Lab: Project                                           #
#------------------------------------------------------------------------------------------------------#
# Students:                                                                                            #
# 1. Ahmad Hakroosh - 203622612                                                                        #
# 2. Rana Zaied     - 201149762                                                                        #
#------------------------------------------------------------------------------------------------------#
# Haifa University                                                                                     #
# Lecturer: Prof. Shuly Wintner                                                                        #
# Semester: 2nd 2018                                                                                   #
#------------------------------------------------------------------------------------------------------#

#------------------------------------------------------------------------------------------------------#
#                                               Imports                                                #
#------------------------------------------------------------------------------------------------------#

from lib.corpus import Corpus

# Instantiate our corpus
corpus = Corpus()
예제 #13
0
 def __init__(self):
     fuzzer = Fuzzer(MockDevice(), u'mock-package1', u'mock-target3')
     self.versions = []
     super(MockCipd, self).__init__(Corpus(fuzzer))