302_poc_2.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. import json
  2. import multiprocessing
  3. import random
  4. import re
  5. import threading
  6. import time
  7. from datetime import datetime
  8. from urllib import parse
  9. import requests
  10. from tools.utils import get_random_browser, get_proxy_ip, FileWriter
  11. def poc_2(account, passwd, target_url, log_name):
  12. print('account: %s, passwd: %s' % (account, passwd))
  13. writer = FileWriter(log_name)
  14. writer.write_to_file(f'------{account}, {passwd}------ \n')
  15. user_agent = get_random_browser()
  16. # 随机数分页
  17. page = random.randint(1, 5)
  18. page_size = random.randint(50, 100)
  19. single_proxy = get_proxy_ip(page, page_size)
  20. # single_proxy = 'rrehqcjf:33f90umk8x32@185.199.228.220:7300'
  21. proxies = {
  22. 'http': 'http://' + single_proxy,
  23. # 'https': 'https://' + single_proxy
  24. }
  25. print('proxies:', proxies)
  26. writer.write_to_file(f'account: {account}, passwd: {passwd}, proxies:{proxies} \n')
  27. # session
  28. """
  29. 模拟登录
  30. """
  31. # 定义请求地址
  32. login_url = "https://t.livepocket.jp/api/sessions/create?mytimestamp=" + str(int(time.time()))
  33. # 定义请求header
  34. headers = {'Content-Type': 'application/x-www-form-urlencoded;',
  35. 'Referer': 'https://t.livepocket.jp/login?acroot=header-new_p_u_nl',
  36. # 'Sec-Ch-Ua': 'Chromium',
  37. 'User-Agent': user_agent
  38. }
  39. # 通过字典方式定义请求body
  40. form_data = {"login": account,
  41. "password": passwd,
  42. "auto_login": "on",
  43. "login_password": f"{account}&{passwd}"
  44. }
  45. data = parse.urlencode(form_data)
  46. session = requests.session()
  47. content = session.post(url=login_url, headers=headers, data=data, proxies=proxies).text
  48. cookie = session.cookies
  49. response_cookie = cookie.get_dict()
  50. login_resp = json.loads(content)
  51. token = login_resp['result']['token']
  52. login_session = response_cookie['ci_session']
  53. php_session = response_cookie['PHPSESSID']
  54. # event_id
  55. event_id = 0
  56. response = requests.get(target_url, proxies=proxies)
  57. if response.status_code == 200:
  58. html_string = response.content.decode('utf8')
  59. start_index = html_string.find('https://t.livepocket.jp/purchase/verify?event_id=')
  60. if start_index != -1:
  61. end_index = html_string.find("'", start_index)
  62. if end_index != -1:
  63. event_id = html_string[start_index + len('https://t.livepocket.jp/purchase/verify?event_id='):end_index]
  64. print(f'event_id: {event_id}')
  65. else:
  66. print('End index not found.')
  67. else:
  68. print('Substring not found.')
  69. else:
  70. print('Failed to fetch the page. Status code:', response.status_code)
  71. # ticket_id
  72. ticket_id = 0
  73. response = requests.get(target_url, proxies=proxies)
  74. if response.status_code == 200:
  75. html_string = response.text
  76. match = re.search(r'id="js_order_limited_(\d+)"', html_string)
  77. if match:
  78. ticket_id = match.group(1)
  79. print(ticket_id)
  80. else:
  81. print("未找到匹配的数值")
  82. # event_cname
  83. # url = 'https://t.livepocket.jp/e/lxyyc'
  84. sub_str = target_url.replace("https://t.livepocket.jp/", "")
  85. strs = sub_str.split('/')
  86. cname = strs[len(strs) - 1]
  87. # print(cname)
  88. # redirect_url1
  89. net_url = 'https://t.livepocket.jp/purchase?type=new'
  90. result = requests.Session()
  91. header = {
  92. 'Host': 't.livepocket.jp',
  93. 'User-Agent': "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) "
  94. "Chrome/69.0.3947.100 Safari/537.36",
  95. 'Content-Type': 'application/x-www-form-urlencoded',
  96. 'Referer': f'{target_url}',
  97. }
  98. # my_session = 'IN7u3uuP5WcizQkmRzF%2F3OsLuNNQePnxNBvnlPgqT6FPz2BgyKT2KCJaMvdj8ZSa6wNp2xZIL6VoA7Mj0R2zECMZkOKJOLbsNwUdXwvcsROxjfCzibxEaj4nG%2Bq29dCEUdiWI2TgUsKSFGRZaOP0p37ktl%2B1wSMqMAk918Nkt7APIxpQtZ%2BoLwId4PMOkN3oOIwT3CvsuDbgPQHIuokZXcnNe8uOAUuZBLW4nKOdYimLcSw6oTMt85UXkwm4OyTdxYR3%2B8crA0OfQCyfHXqY%2Bj0t9R0mmNSusRXRDuDBmOCFR58vHVuuwZ0AXNHYoYB0sdm28VL9xgHHrzkvm2M9cpLEIVWUWBWGaZgtO3xp2d8L70%2BfAKwyv6JPGcGmGf9wUQzBltssBpMmYqSfkws1%2Bp8BOhmXOqfljSYbWcxxVVSw%2B2dtoxBXsTf793mD9sVYRsrr8YPGz4JPVGWGU0outg%3D%3D'
  99. cookies = {
  100. 'ci_session': f'{login_session}',
  101. 'PHPSESSID': f'{php_session}',
  102. 'list_count': '{"success":true,"result":{"myticket_count":{"count":"0"},"today_event":{"total_count":0,"data_list":[]},"unread_count":5},"submit":true}',
  103. 'sns_status': '{"success":true,"result":{"facebook":0,"twitter":0,"mixi":0,"line":0,"yahoo":0,"plusid":1,"google":0},"submit":true}',
  104. 'display_init': '{"success":true,"result":{"purchased_tickets":{"total_count":0,"data_list":{"ticket_info":[]}},"lottery_tickets":{"total_count":0,"data_list":{"ticket_info":[]}},"order_limited_event_tickets":{"data_list":{"ticket_info":[]},"total_count":0},"event_order_limit":true},"submit":true}',
  105. }
  106. ticket_key = f'ticket_id_{ticket_id}'
  107. form_data = {
  108. 'redirect_url': 'https://t.livepocket.jp/purchase/',
  109. 'event_id': event_id,
  110. 'event_cname': f'{cname}',
  111. 'ticket_type': 'lottery',
  112. 'facebook_ticket_count': 0,
  113. 'twitter_ticket_count': 0,
  114. 'plusid_linkage_invalidation_flg': 0,
  115. ticket_key: 1
  116. }
  117. print('form_data:', form_data)
  118. response = result.post(net_url, headers=header, cookies=cookies, data=form_data, allow_redirects=False,
  119. proxies=proxies)
  120. print('response.headers: ', response.headers)
  121. if 'Location' in response.headers:
  122. redirect_url1 = response.headers['Location']
  123. print('redirect_url1: ', redirect_url1)
  124. else:
  125. return
  126. # https://t.livepocket.jp/purchase/security?id=309887&type=new
  127. # redirect_url2
  128. response2 = result.get(redirect_url1, headers=header, cookies=cookies, allow_redirects=False, proxies=proxies)
  129. print('response2.headers: ', response2.headers)
  130. if 'Location' in response2.headers:
  131. redirect_url2 = response2.headers['Location']
  132. print('redirect_url2: ', redirect_url2)
  133. else:
  134. return
  135. # https://t.livepocket.jp/purchase/confirm?id=309887&reserved_session_id=423272
  136. # redirect_url3
  137. response3 = result.get(redirect_url2, headers=header, cookies=cookies, allow_redirects=False, proxies=proxies)
  138. print('response3.headers: ', response3.headers)
  139. if 'Location' in response3.headers:
  140. redirect_url3 = response3.headers['Location']
  141. print('redirect_url3: ', redirect_url3)
  142. else:
  143. print('redirect_url3 is None')
  144. return
  145. # https://t.livepocket.jp/purchase/confirm?id=309887&reserved_session_id=794986&otoken=mMyZTgzMmQ4OWQ5ZjY5NWFlNGE2ZmJlMWM5Mm
  146. # drawing_tickets
  147. drawing_url = 'https://t.livepocket.jp/api/drawing_tickets/entry?mytimestamp=' + str(int(time.time()))
  148. region_string = redirect_url3.split('?')[1]
  149. params = region_string.split('&')
  150. reserve_session_id = params[1].split("=")[1]
  151. drawing_headers = {
  152. 'Host': 't.livepocket.jp',
  153. 'User-Agent': user_agent,
  154. 'Content-Type': 'application/x-www-form-urlencoded',
  155. 'Referer': f'{redirect_url3}',
  156. }
  157. drawing_cookies = {
  158. 'ci_session': f'{login_session}',
  159. 'PHPSESSID': f'{php_session}',
  160. }
  161. drawing_form_data = {
  162. 'utoken': f'{token}',
  163. 'onetime_token_name': 'buy_ticket',
  164. 'onetime_token_value': params[2].split('=')[1],
  165. 'url': f'https://t.livepocket.jp/purchase/confirm?id={event_id}&reserved_session_id={reserve_session_id}',
  166. 'payment_method': 0,
  167. 'reserve_session_id': reserve_session_id,
  168. 'event_id': event_id,
  169. 'reserve_ticket[0][ticket_id]': ticket_id,
  170. 'reserve_ticket[0][amount]': 1,
  171. 'payment_type': 'credit'
  172. }
  173. drawing_response = result.post(drawing_url, headers=drawing_headers, cookies=drawing_cookies,
  174. data=drawing_form_data, allow_redirects=False, proxies=proxies)
  175. print('drawing_response.text: ', drawing_response.text)
  176. drawing_data = json.loads(drawing_response.text)
  177. if drawing_data['success']:
  178. order_id = drawing_data['result']['order_id']
  179. onetime_token_name = drawing_data['result']['onetime_token_name']
  180. onetime_token_value = drawing_data['result']['onetime_token_value']
  181. print('account, order_id, onetime_token_name, onetime_token_value', account, order_id, onetime_token_name,
  182. onetime_token_value)
  183. writer.write_to_file(
  184. f'account:{account}, order_id:{order_id}, onetime_token_name:{onetime_token_name}, onetime_token_value:{onetime_token_value} \n')
  185. def process_account(account, log_name):
  186. try:
  187. poc_2(account.strip(), 'panyue666', 'https://t.livepocket.jp/e/sakuhana_197', log_name)
  188. except Exception as ex:
  189. print(f'error: {ex}, account:{account}')
  190. def process_running():
  191. log_name = 'result_' + datetime.now().strftime('%Y%m%d%H%M')
  192. with open('account.txt', 'r') as accounts:
  193. account_list = accounts.readlines()
  194. threads = []
  195. for account in account_list:
  196. thread = threading.Thread(target=process_account, args=(account, log_name))
  197. threads.append(thread)
  198. thread.start()
  199. for thread in threads:
  200. thread.join()
  201. def run_poc(account, password, url, log_name):
  202. try:
  203. poc_2(account, password, url, log_name)
  204. except Exception as e:
  205. print(f'error: {e}, account:{account}')
  206. if __name__ == '__main__':
  207. # 新增下面一行代码即可打包多进程
  208. multiprocessing.freeze_support()
  209. log_name = f"data_{datetime.now().strftime('%Y%m%d%H%M')}.txt"
  210. with open('account.txt', 'r') as accounts:
  211. for account in accounts:
  212. try:
  213. poc_2(account.strip(), 'panyue666', 'https://t.livepocket.jp/e/cx591', log_name)
  214. except Exception as e:
  215. print(f'error: {e}, account:{account}')
  216. # process_running()
  217. # if __name__ == '__main__':
  218. # multiprocessing.freeze_support()
  219. # log_name = f"data_{datetime.now().strftime('%Y%m%d%H%M')}.txt"
  220. #
  221. # # 读取 accounts.txt 文件中的账号数量
  222. # with open('account.txt', 'r') as accounts:
  223. # account_count = sum(1 for _ in accounts)
  224. #
  225. # # 创建线程池
  226. # threads = []
  227. # with open('account.txt', 'r') as accounts:
  228. # for account in accounts:
  229. # account = account.strip()
  230. # t = threading.Thread(target=run_poc,
  231. # args=(account, 'panyue666', 'https://t.livepocket.jp/e/cx591', log_name))
  232. # t.start()
  233. # threads.append(t)
  234. #
  235. # # 如果线程数达到账号数,则等待所有线程执行完毕
  236. # if len(threads) == account_count:
  237. # for t in threads:
  238. # t.join()
  239. # threads.clear()