pythonpython-requestsphishing

Can not automate a script to check url at phishcheck.me with Python requests


Thanks in advance, I am trying to automate the process of getting if a URL is phishing or not using this page (which is a must) phishcheck.me.

This is my python code:

import requests
from time import time
import warnings

warnings.simplefilter("ignore")

def main():
    badurl = "google.com"
    user_agent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36"
    user_agent +=" (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
    url = "https://phishcheck.me/submit"
    referer = 'https://phishcheck.me'
    header = {
        'Referer': referer + "/",
        'User-Agent': user_agent,
        "Origin": referer,
        "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        "Accept": "application/json, text/javascript, */*; q=0.01",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "en-US,en;q=0.9,es;q=0.8",
        "Connection": "keep-alive",
        "Host": "phishcheck.me",
        "X-Requested-With": "XMLHttpRequest"
    }

    client = requests.session()
    client.get(referer, verify=False)
    csrftoken = client.cookies['csrftoken']
    session_id = client.cookies['sessionid']

    cookies = {
        'csrftoken': csrftoken,
        '_ga': 'GA1.2.{0}.1517235473'.format(int(time())),
        '_gid': 'GA1.2.{0}.1519059714'.format(int(time())),
        '_gat': '1',
        "sessionid": session_id
    }

    # Try 1
    payload = {
        'csrfmiddlewaretoken': csrftoken,
        'url': badurl,
        'useragent': '0'
    }
    # Try 2
    payload = "csrfmiddlewaretoken={0}&url={1}&useragent=0".format(
        csrftoken, badurl
    )

    r = client.post(url, headers=header, data=payload,
                    cookies=cookies, verify=False)
    return r

print(main().text)
# {"is_success": false}
print(main().cookies)
# <RequestsCookieJar[<Cookie messages="c0fa3b2c4d55aea15b28a734768e681a2680ff7d$[[__json_message\0540\05440\054Malformed URL. Please check your entry and try again.]]" for phishcheck.me/>]>

The cookies is telling me that I have a Malformed URL, I am not sure about how to fix it.

Here is a screenshot about how the request is created from the phishcheck.me web page.

Chrome developer screenshot

Any detail I am missing, please ask!


Solution

  • You are posting data to /submit instead of /submit/ which leaded you to this error, so you have to change https://phishcheck.me/submit to https://phishcheck.me/submit/ and it will work for you

    Here's the code i used:

    import requests
    
    requests.urllib3.disable_warnings()
    
    url = 'https://phishcheck.me/'
    
    sess = requests.Session()
    
    g = sess.get(url)
    
    DATA = {
        'url': 'http://google.com',  # <- url you scanning
        'useragent': '0',
        'csrfmiddlewaretoken': g.cookies['csrftoken'],
        'recheck': 'True' # <- False if you don't wanna recheck the link again
    }
    
    
    p = sess.post(url + '/submit/', data=DATA)
    
    d = sess.get('https://phishcheck.me/' + str(p.json()['sid']) + '/details')
    
    print(d.text)