Exemplo n.º 1
0
    def find_one_city(self, access_points):
        '''
        Connects and interacts with the SnapBuddy client.
        The sequence of calls is as follows:
        1. Call "/" and get redirected to the /authenticate page
        2. POST to /authenticate and get redirected to the /login page
        3. POST to /login and get redirected to the /location/set page
        4. POST to /location/set and get redirected to the /location/confirm page
        5. End of session
        If the location confirmation page is posted, then the number of
        times the user changes their location will be incremented and
        that is constrained.  By stopping before confirming, this
        limitation can be bypassed.

        Assertions are included for each call to verify that the
        expected flow is followed.


        Returns the city as specified by the server
        '''
        with interact.get_session() as session:
            response = self.snap_caller.do_authenticate(session)
            response = self.snap_caller.do_login(session, response.url)
            response = self.snap_caller.do_set_location(
                session, access_points, response.url)

            return CITY_RESPONSE_PATTERN.match(response.text).group(1)
Exemplo n.º 2
0
    def build(self, username, password, interface):
        ignore_image_loading = True  # Don't load images while accessing pages!
        snap_caller = interact.SnapCaller(self.hostname, self.port, username,
                                          password, ignore_image_loading)

        with interact.get_session() as session:
            tuples = self.get_image_users(snap_caller, session)

            print tuples

            for profile_url, user_name in tuples:
                with packetcollector.PacketCollector(
                        interface,
                        "tcp port {}".format(self.port)) as packet_collector:
                    print profile_url, user_name,
                    snap_caller.do_image(session, profile_url)
                    # give it time for the packets to be collected
                    time.sleep(1)
                    packet_collector.stop()
                    request_size, response_size = self.get_transaction(
                        packet_collector.get_pcap())
                    print "\tsize: ", response_size
                    response_size = str(response_size)
                    if self.response_size_map.has_key(response_size):
                        print "\t\t COLLISION!"
                        self.response_size_map[response_size].append(
                            (profile_url, user_name))
                    else:
                        self.response_size_map[response_size] = [(profile_url,
                                                                  user_name)]
Exemplo n.º 3
0
def all_cities_from_server(hostname, port):
    url = "https://{}:{}/cities".format(hostname, port)
    with interact.get_session() as session:
        response = session.get(url)
        for line in response.text.splitlines():
            match = CITY_AND_ACCESS_POINT_PATTERN.match(line)
            if match:
                yield match.groups()
Exemplo n.º 4
0
                          ids,
                          num_filters,
                          num_tests,
                          savedir=None):
        for test in xrange(num_tests):
            filters = ['F00E', 'F00F']
            for filter in filters:
                if filter in ids:
                    ids.remove(filter)
            sampled_filters = random.sample(ids, num_filters)
            filters.extend(sampled_filters)
            print "Testing:", filters,
            (duration, response) = self.test_filter(session, filters)
            assert response.status_code == 200
            print ": ", duration
            if savedir:
                self.save_photo(savedir, response, "_".join(filters))


if __name__ == "__main__":
    if len(sys.argv) < 5:
        print "findcities.py <hostname> <port> <username> <password> <image path>"
        sys.exit(-1)
    caller = FilterTest(sys.argv[1], int(sys.argv[2]), sys.argv[3],
                        sys.argv[4], sys.argv[5])
    ids = ["F%03X" % (num, ) for num in xrange(21)]
    with interact.get_session() as session:
        caller.login(session)
        caller.test_filters(session, ids, '.')
        caller.test_many_filters(session, ids, 2, 6, '.')