def sendRequests(csrf,session,s): while link_queue.__len__() > 0: try: link = link_queue.pop(0) except IndexError: break if link not in visited: #print sent_links.__len__() parsed = urlparse(link) linkrequest = HTTPrequest() linkrequest.type = "GET" linkrequest.version = "1.1" linkrequest.host = parsed.netloc linkrequest.path = parsed.path linkrequest.cookies['csrf'] = csrf linkrequest.cookies['sessionid'] = session linkrequest.connection = "Keep-Alive" #linkrequest.encoding = "gzip" try: sendRequestOnly(linkrequest,s) sent_links.append(link) print(link + " "+ str(secret_flags.__len__())) except socket.error as err: link_queue.insert(0,link) #s.close() break
def login_to_fakebook(login_link,username,password,csrf): parsedLink = urlparse(login_link) loginrequest = HTTPrequest() loginrequest.type = "POST" loginrequest.version = "1.1" loginrequest.host = parsedLink.netloc loginrequest.path = parsedLink.path loginrequest.connection = "Keep-Alive" loginrequest.cookies['csrf'] = csrf loginrequest.content_type = "application/x-www-form-urlencoded" loginrequest.content = "username="******"&password="******"&csrfmiddlewaretoken="+csrf loginresponse = sendRequest(parsedLink.netloc,loginrequest) return loginresponse
def login_to_fakebook(login_link,username,password,csrf): # parse login link parsedLink = urlparse(login_link) # set parameters for HTTPrequest object loginrequest = HTTPrequest() loginrequest.type = "POST" loginrequest.version = "1.1" loginrequest.host = parsedLink.netloc loginrequest.path = parsedLink.path loginrequest.connection = "Keep-Alive" loginrequest.cookies['csrf'] = csrf # setting the csrf token from previous request loginrequest.content_type = "application/x-www-form-urlencoded" loginrequest.content = "username="******"&password="******"&csrfmiddlewaretoken="+csrf # the content # send request and return response loginresponse = sendRequest(parsedLink.netloc,loginrequest) return loginresponse
def sendRequests(csrf,session,s): # repeat until link_queue is not empty while link_queue.__len__() > 0: # acquire mutex to prevent sync issues mutex.acquire() # pop link from queue # can crash as queue could be empty due to other threads try: link = link_queue.pop(0) except IndexError: mutex.release() # release mutex and break break # if the popped link is not a visited link then send request to it if link not in visited: # make request object for it parsed = urlparse(link) linkrequest = HTTPrequest() linkrequest.type = "GET" linkrequest.version = "1.1" linkrequest.host = parsed.netloc linkrequest.path = parsed.path linkrequest.cookies['csrf'] = csrf # send csrf token linkrequest.cookies['sessionid'] = session # send session id linkrequest.connection = "Keep-Alive" # for pipelining # send the request try: s.send(str(linkrequest)) # if no error add link to sent links sent_links.append(link) except socket.error: # if error occurs due to various reasons then insert link at start of queue link_queue.insert(0,link) mutex.release() # release mutex and break #s.close() break mutex.release() # release mutex after successful transmission so that other threads can transmit
def getCSRF(login_link): parsedLink = urlparse(login_link) request = HTTPrequest() request.type = "GET" request.host = parsedLink.netloc request.path = parsedLink.path request.version = "1.1" request.connection = "close" httpresponse = sendRequest(parsedLink.netloc,request) return httpresponse.csrf
def getCSRF(login_link): # parse link using urlparse parsedLink = urlparse(login_link) # create request using HTTPrequest object request = HTTPrequest() # set parameters of request request.type = "GET" request.host = parsedLink.netloc request.path = parsedLink.path request.version = "1.1" request.connection = "close" # send request and get response httpresponse = sendRequest(parsedLink.netloc,request) return httpresponse.csrf # return csrf token