302_poc_2.py 12 KB

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