Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.46 KB | None | 0 0
  1. #!/bin/usr/env python3
  2.  
  3. import argparse
  4. import json
  5. import sys
  6. import time
  7. import requests
  8. from os import path
  9. from mitmproxy.tools import _main as main
  10.  
  11.  
  12. def ensure_file_existence(file_path):
  13.     if not path.isfile(file_path):
  14.         print('Error: the file {} does not exist. Please check the path'.format(file_path))
  15.         sys.exit(-1)
  16.  
  17.  
  18. def run_mitmproxy_live(output):
  19.     main.mitmdump(["--mode", "transparent", "--showhost", "-s", "./cookiefinder.py", "--set",
  20.                    "signin=https://13.33.32.47/ap/signin", "--set", "output=" + path.expanduser(output),
  21.                    "--set", "ajax=https://13.33.32.47/hz/mycd/ajax"])
  22.  
  23.  
  24. def run_mitmproxy_on_file(flows, output):
  25.     main.mitmdump(
  26.         ["-n", "-r", flows, "--showhost", "-s", "./cookiefinder.py", "--set", "signin=https://13.33.32.47/ap/signin",
  27.          "--set", "output=" + path.expanduser(output), "--set", "ajax=https://13.33.32.47/hz/mycd/ajax"])
  28.  
  29.  
  30. def get_info():
  31.     parser = argparse.ArgumentParser()
  32.     parser.add_argument("--cookies", type=str, nargs='?', default="cookies.json", const="cookies.json",
  33.                         help="specify file for finding necessary cookies")
  34.     parser.add_argument("--flows", type=str, nargs='?', help="specify file for incoming flows")
  35.     args = parser.parse_args()
  36.  
  37.     cookies_path = path.expanduser(args.cookies)
  38.  
  39.     if path.isfile(cookies_path):
  40.         with open(cookies_path) as f:
  41.             cookies = json.load(f)
  42.     else:
  43.  
  44.         if args.flows is not None:
  45.             flows_path = path.expanduser(args.flows)
  46.             run_mitmproxy_on_file(flows_path, cookies_path)
  47.         else:
  48.             run_mitmproxy_live(cookies_path)
  49.  
  50.         while not path.exists(cookies_path):
  51.             time.sleep(1)
  52.  
  53.         ensure_file_existence(cookies_path)
  54.  
  55.         with open(cookies_path) as f:
  56.             cookies = json.load(f)
  57.  
  58.     return cookies
  59.  
  60.  
  61. info = get_info()
  62. csrfToken = info["csrfToken"]
  63. cookies = info["cookies"]
  64.  
  65. start_date = str(int(round(time.time() * 1000)) - 86400000)
  66. end_date = str(int(round(time.time() * 1000)))
  67. batchSize = "100"
  68. shouldParseStartDate = "false"
  69. shouldParseEndDate = "false"
  70.  
  71. authority = "www.amazon.com"
  72. accept = "text/html, */*; q=0.01"
  73. content_type = "application/x-www-form-urlencoded"
  74. x_requested_with = "XMLHttpRequest"
  75. accept_language = "en-us"
  76. accept_encoding = "br, gzip, deflate"
  77. origin = "https://www.amazon.com"
  78. referer = "https://www.amazon.com/hz/mycd/alexa/activityHistory"
  79. user_agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 PitanguiBridge/2.2.288637.0-[HARDWARE=iPhone11_2][SOFTWARE=12.4]"
  80. encoded_form = {
  81.     "csrfToken": csrfToken,
  82.     "rangeType": "custom",
  83.     "startDate": start_date,
  84.     "endDate": end_date,
  85.     "batchSize": "100",
  86.     "shouldParseStartDate": "false",
  87.     "shouldParseEndDate": "false"
  88. }
  89. json = json.dumps(encoded_form)
  90.  
  91. headers = {
  92.     "authority": authority,
  93.     "content-type": content_type,
  94.     "accept": accept,
  95.     "x-requested-with": x_requested_with,
  96.     "accept-language": accept_language,
  97.     "accept-encoding": accept_encoding,
  98.     "origin": origin,
  99.     "referer": referer,
  100.     "content-length": str(len(json)),
  101.     "user-agent": user_agent
  102. }
  103.  
  104. response = requests.post("https://amazon.com/hz/mycd/alexa/activityTranscripts", data=encoded_form, headers=headers)
  105. with open("test.html", "w") as f:
  106.     f.write(response.json())
  107.     f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement