精易论坛
标题:
某互金平台协yi登录+转币
[打印本页]
作者:
CrazyWolf
时间:
2018-2-4 00:57
标题:
某互金平台协yi登录+转币
这是前段时间帮我同学做的一个自动化小程序,这里发出来和大家学习交流下,时间仓促,业务逻辑部分没有深思熟虑,写的比较挫,求轻拍。
操作系统:Ubuntu 14.05
运行环境:Python 2.7.xx
0x00. 结构目录
├── account.txt
├── hyhr178.py
├── logger.conf
├── module
│ ├── __init__.py│ ├── buytt.py
│ ├── login.py
│ ├── rk.py
└── README.md
0x01. 文件功能描述
account.txt -- 存放账号密码文件
hyhr178.py -- 程序入口文件,创建多进程任务,执行核心业务逻辑
logger.conf -- log配置文件
__init__.py -- 模块初始化文件,初始化一些模块中的全局常量
buytt.py -- 转币操作模块文件
login.py -- 自动登录模块文件
rk.py -- 自己封装的若快打码接口
README.md -- 项目说明文档
0x02. hyhr178.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: CrazyWolf
# qq: 4850498
import time
import signal
import logging
import logging.config
import multiprocessing
from module.login import Login
from module.buytt import BuyTT
# logger = logging.config.fileConfig('logger.conf')
# log_root = logging.getLogger('root')
# log_hyhr178 = logging.getLogger('hyhr178')
def init_work():
signal.signal(signal.SIGINT, signal.SIG_IGN)
def work(username, password, second_password):
flag = 1
password_err_loop = 0
if username == '' or password == '' or second_password == '':
print '账号或密码或二级密码为空'
return
login = Login()
buytt = BuyTT(username=username, second_password=second_password)
while True:
if flag == 1:
status = login.do(username=username, password=password)
if status == 200:
flag = 2
elif status == 400 or status == 401 or status == 402 or status == 100:
break
elif status == 401:
# try loop two times
password_err_loop += 1
if password_err_loop == 2:
break
else:
time.sleep(5)
elif flag == 2:
status = buytt.verify()
if status == 200:
flag = 3
elif status == 400 or status == 401:
break
else:
time.sleep(5)
elif flag == 3:
status = buytt.buy()
if status == 200 or status == 100:
break
elif status == 500 or status == 501:
time.sleep(10)
elif status == 402 or status == 401:
flag = 2
time.sleep(5)
def cil():
result = []
params = []
# log_root.info('系统开始运行')
# read account file
with open('account.txt', 'r') as f:
line = f.readline()
while line:
if line.find('|') > -1:
params.append(line.strip())
else:
print '[-] 账号密码格式不对 -- {0}'.format(line)
# log_root.info('账号密码格式不对 -- {0}'.format(line))
line = f.readline()
pool = multiprocessing.Pool(processes=len(params), initializer=init_work)
try:
for param in params:
tmp = param.split('|')
result.append(pool.apply_async(work, (tmp[0], tmp[1], tmp[2])))
pool.close()
pool.join()
except KeyboardInterrupt:
pool.terminate()
pool.join()
print '全部处理完成'
if __name__ == "__main__":
cil()
复制代码
0x03. __init__.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: CrazyWolf
# qq: 4850498
import requests
WEBSITE_URL = 'http://hyhr178.com/'
VERIFICATION_CODE_URL = 'http://hyhr178.com/getCaptchaImg?d={0}'
cw_session = requests.session()
RK_SOFT_ID = ''
RK_SOFT_KEY = ''
复制代码
0x04. buytt.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: CrazyWolf
# qq: 4850498
import time
import json
import logging
import logging.config
import module
# logger = logging.config.fileConfig('logger.conf')
# log_root = logging.getLogger('root')
# log_hyhr178 = logging.getLogger('hyhr178')
class BuyTT:
def __init__(self, username, second_password):
self.url_info = 'http://hyhr178.com/getSessionMember'
self.username = username
self.second_password = second_password
self.lever = 1
self.price = 0
self.coin_total = 0.0
self.address = ''
def verify(self):
headers = {
'Host': 'hyhr178.com',
'Connection': 'keep-alive',
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0',
'Accept': 'application/json, text/plain, */*',
'Referer': 'http://hyhr178.com/memberinfo/module/home',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.5',
}
resp = module.cw_session.get(url=self.url_info, headers=headers, verify=False)
if resp.status_code != 200:
print '[-] {0} 请求用户数据失败'.format(self.username)
# log_root.debug('{0} 请求用户数据失败'.format(self.username))
return 500
try:
info = json.loads(resp.text)
if info is None:
# log_root.debug('{0} 解析用户数据失败'.format(self.username))
print '[-] {0} 解析用户数据失败'.format(self.username)
return 501
except Exception:
# log_root.debug('{0} 解析用户数据异常'.format(self.username))
print '[-] {0} 解析用户数据异常'.format(self.username)
return 501
# print info.keys()
self.lever = info[u'team_level_id']
self.coin_total = info[u'member_money11']
self.address = info[u'ssc_code']
print '[+] {0} 当前级别:{1} 当前TT币:{2} 当前Mail:{3}'.format(self.username, self.lever, self.coin_total, self.address)
# log_root.info('{0} 当前级别:{1} 当前TT币:{2} 当前Mail:{3}'.format(self.username, self.lever, self.coin_total, self.address))
if self.coin_total == 0.0:
print '[-] {0} 没有TT币'.format(self.username)
# log_root.debug('{0} 没有TT币'.format(self.username))
return 400
if self.address == '':
print '[-] {0} mail为空'.format(self.username)
# log_root.debug('{0} mail为空'.format(self.username))
return 401
# 2017-12-10 修改为每天兑换100
# if 0 < self.lever < 4:
# self.price = 500
# if self.coin_total < 500.0:
# self.price = self.coin_total
# elif self.lever >= 4:
# self.price = 1000
# if self.coin_total < 1000.0:
# self.price = self.coin_total
self.price = 100
if self.coin_total < 100:
self.price = self.coin_total
else:
print '[-] {0} 获取用户数据失败'.format(self.username)
# log_root.debug('{0} 获取用户数据失败'.format(self.username))
return 402
return 200
def buy(self):
headers = {
'Host': 'hyhr178.com',
'Connection': 'keep-alive',
'Accept': '*/*',
'Origin': 'http://hyhr178.com',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded',
'Referer': 'http://hyhr178.com',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.8,en;q=0.6',
}
data = ''
url = 'http://hyhr178.com/niubi/trans?address={0}&money_pwd={1}&out_qty={2}'.format(self.address, self.second_password, self.price)
resp = module.cw_session.post(url=url, data=data, headers=headers, verify=False)
if resp.status_code != 200:
print '[-] {0} 请求购买失败'.format(self.username)
# log_root.debug('{0} 请求购买失败'.format(self.username))
return 500
try:
result = json.loads(resp.text)
if result[u'success'] is 1:
print '[+] {0} 转入成功'.format(self.username)
# log_hyhr178.info('{0} 转入成功'.format(self.username))
return 200
else:
# if resp.text.find(u'由于当前的兑换人数太多') > -1:
if u'由于当前的兑换人数太多' in resp.text:
print '[-] {0} 当前的兑换人数太多'.format(self.username)
# log_root.debug('{0} 当前的兑换人数太多'.format(self.username))
return 501
else:
print '[-] {0} {1}'.format(self.username, resp.text.encode('utf-8'))
# log_root.debug('{0} {1}'.format(self.username, resp.text))
return 100
except Exception as e:
# log_root.debug(e)
print '[-] {0} {1}'.format(self.username, e)
return 100
复制代码
0x05. login.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: CrazyWolf
# qq: 4850498
import time
import json
import module
import logging
import logging.config
from module.rk import RClient
# logger = logging.config.fileConfig('logger.conf')
# log_root = logging.getLogger('root')
# log_hyhr178 = logging.getLogger('hyhr178')
class Login:
def __init__(self):
self.rk = RClient(username='', password='', soft_id=module.RK_SOFT_ID, soft_key=module.RK_SOFT_KEY)
def do(self, username, password):
"""
登陆操作
:param username:
:param password:
:return:
"""
headers = {
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.5',
'Connection': 'keep-alive',
'Host': 'hyhr178.com',
'Referer': 'http://hyhr178.com/memberinfo/module/home',
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0',
}
# get verification code
code_url = module.VERIFICATION_CODE_URL.format(time.time())
resp = module.cw_session.get(url=code_url, headers=headers, verify=False)
if resp.status_code != 200:
print '[-] {0} 请求验证码失败'.format(username)
# log_root.debug('{0} 请求验证码失败'.format(username))
return 500
# da ma
img = resp.content
result = self.rk.rk_create(im=img, im_type=3040)
if len(result) != 2:
print '[-] {0} {1}'.format(username, result['Error'])
# log_root.debug('{0} {1}'.format(username, result['Error']))
return 400
# print '[+] 打码结果:', username, result['Result']
# log_root.info('{0}的打码结果: {1}'.format(username, result['Result']))
# login
headers = {
'Accept': 'application/json, text/plain, */*',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.5',
'Connection': 'keep-alive',
'Content-Type': 'application/json;charset=utf-8',
'Host': 'hyhr178.com',
'Origin': 'http://hyhr178.com',
'Referer': 'http://hyhr178.com/memberinfo/module/home',
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0',
}
url = 'http://hyhr178.com/doLogin?member_code={0}&member_pwd={1}&security_code={2}'.format(username, password, result['Result'])
# url = 'http://hyhr178.com/doLogin?member_code={0}&member_pwd={1}&security_code={2}'.format(username, password, '1234')
resp = module.cw_session.get(url=url, headers=headers, verify=False)
if resp.status_code != 200:
print '[-] {0} 登录请求失败'.format(username)
# log_root.debug('{0} 登录请求失败'.format(username))
return 500
# {"data":[],"success":1,"msg":"操作成功"}
try:
result = json.loads(resp.text)
if result[u'success'] is 1:
print '[+] {0} 登录成功'.format(username)
# log_root.debug('{0} 登录成功'.format(username))
return 200
else:
# if result[u'msg'].find(u'检验不通过') > -1:
# if u'errorMsg' in result[u'errordata']:
# log_root.debug('{0} {1}'.format(username, result[u'errordata'][u'errorMsg']))
# elif u'secuMsg' in result[u'errordata']:
# log_root.debug('{0} {1}'.format(username, result[u'errordata'][u'secuMsg']))
# else:
# log_root.debug('{0} {1}'.format(username, result[u'errordata']))
if u'密码输入错误' in resp.text:
print '[-] {0} 密码输入错误'.format(username)
# log_root.debug('{0} 密码输入错误'.format(username))
return 401
elif u'验证码输入错误' in resp.text:
self.rk.rk_report_error(result['Id'])
print '[-] {0} 验证码输入错误'.format(username)
# log_root.debug('{0} 验证码输入错误'.format(username))
return 501
elif u'系统暂闭维护中' in resp.text:
print '[-] {0} 系统暂闭维护中'.format(username)
# log_root.debug('{0} 系统暂闭维护中'.format(username))
return 402
else:
print '[-] {0} {1}'.format(username, resp.text.encode('utf-8'))
# log_hyhr178.debug('{0} {1}'.format(username, resp.text))
return 100
except Exception as e:
print '[-] {0} {1}'.format(username, e)
# log_root.debug(e)
return 502
复制代码
0x06. rk.py
#!/usr/bin/env python
# coding:utf-8
import requests
from hashlib import md5
class RClient(object):
def __init__(self, username, password, soft_id, soft_key):
self.username = username
self.password = md5(password).hexdigest()
self.soft_id = soft_id
self.soft_key = soft_key
self.base_params = {
'username': self.username,
'password': self.password,
'softid': self.soft_id,
'softkey': self.soft_key,
}
self.headers = {
'Connection': 'Keep-Alive',
'Expect': '100-continue',
'User-Agent': 'ben',
}
def rk_create(self, im, im_type, timeout=60):
"""
im: 图片字节
im_type: 题目类型
"""
params = {
'typeid': im_type,
'timeout': timeout,
}
params.update(self.base_params)
files = {'image': ('a.jpg', im)}
r = requests.post('http://api.ruokuai.com/create.json', data=params, files=files, headers=self.headers)
return r.json()
def rk_report_error(self, im_id):
"""
im_id:报错题目的ID
"""
params = {
'id': im_id,
}
params.update(self.base_params)
r = requests.post('http://api.ruokuai.com/reporterror.json', data=params, headers=self.headers)
return r.json()
if __name__ == '__main__':
rc = RClient('username', 'password', 'soft_id', 'soft_key')
im = open('a.jpg', 'rb').read()
print rc.rk_create(im, 3040)
复制代码
0x07. logger.conf
[loggers]
keys=root,hyhr178
[handlers]
keys=consoleHandler,hyhr178Handler
[formatters]
keys=fmt
[logger_root]
level=DEBUG
handlers=consoleHandler
[logger_hyhr178]
level=DEBUG
handlers=hyhr178Handler
qualname=hyhr178
[handler_consoleHandler]
class=StreamHandler
lever=DEBUG
formatter=fmt
args=(sys.stdout,)
[handler_hyhr178Handler]
class=logging.handlers.RotatingFileHandler
lever=DEBUG
formatter=fmt
args=('logs.log', 'a', 20000, 5,)
[formatter_fmt]
format=%(asctime)s - %(levelname)s - %(process)d - %(message)s
datafmt=
复制代码
0x08. README.md
apt-get install python-dev
apt-get install libxml2-dev
apt-get install libxslt1-dev
apt-get install zlib1g-dev
pip install requests
pip install pyquery
复制代码
欢迎光临 精易论坛 (https://125.confly.eu.org/)
Powered by Discuz! X3.4