I do not know how to control user abnormal behavior? This open source project to find out!

As more and more users to join the users of our products, the flow increases. A variety of fast hardware investment institutions began to fancy you, a lot of gray areas have begun eyeing the black hands you a piece of cake flow. At this time, for the protection of user abnormal behavior it will become increasingly important. However, often the reality is always so cruel, can not refuse to do business needs and have security control, under certain cost control, investment choice for manpower has become extremely difficult. For such a scenario, TJ recommend the following open source projects:

- Project Name: unfamiliar street style static rules engine control system

- Github:https://github.com/momosecurity/aswan

Architecture Introduction

Here Insert Picture Description

Background Introduction

  1. List Management

    Provide basic data management functionality for list-type strategy.

    Dimension Data's list include: User ID, IP, device number, payment account number, phone number. Follow-up can also be expanded to other dimensions according to their needs.

    The list contains three types: black, white, gray list

    List must belong to a project (for determining the scope of the list), you can manage the list - the list of projects to add project management.

    Here Insert Picture Description

  2. List type strategy

    Descriptor {parameter name: radio, assuming "user ID"} {opcode: In / Out} {XX items: radio, the optional} {global dimensions: radio direction {}: black / white / gray list}

    Example: User ID User item in the initial blacklist

    Here Insert Picture Description

  3. Boolean strategy

    Does not pass the threshold Boolean type parameter name {descriptor: radio, assuming "account ID"} {Opcode: Yes / No} {built-in functions: User exception} Example: user account ID is abnormal

    Boolean pass threshold value, descriptors {parameter name: radio, assuming "account ID"} {opcode: greater than / less than / equal / not equal} {built-in functions: History Log number} {Threshold: 170} Example : historical account login ID number greater than 100

    Here Insert Picture Description

    内置函数What is? Logic to determine that some custom function, only need to meet the requirements returns a Boolean value. For example, registration time is within a certain range, whether the device is currently used equipment.

  4. Time-frequency-controlled strategy

    描述符为 同一 {计数维度:单选,假设是“设备”} 在 {时段:时间跨度} 内限制 {阈值:整数N} 次 某动作 示例:同一设备一天内限制操作10次. 可是我怎么知道当前已经有多少次呢?这就需要上报,上报后将计数 详见第9条 数据源管理

    Here Insert Picture Description

  5. 限用户数型策略

    描述符为 同一 {计数维度:单选,假设是“设备”} 在 {时段:时间跨度} 内限制 {阈值:整数N} 个用户

    示例:同一设备当天限10个用户 此策略同样需要上报的数据,且由于与用户相关,因此上报数据中必须包含user_id字段(在数据源中需配置) 详见第9条 数据源管理

    Here Insert Picture Description

  6. 规则管理

    管控原子:命中某条策略后的管控动作,比如拦截... 把上面2--5中所述的策略原子按照优先级组合起来,由上向下执行,直到命中某条策略,则返回对应策略的管控原子。此模块更多是重交互,完成策略的配置、组合、权重等等

    Here Insert Picture Description

  7. 日志管理

    所有命中策略的日志均在此展示,也会包含审计相关的日志,下一期会基于此日志,开放拦截溯源功能
    Here Insert Picture Description
    Here Insert Picture Description

  8. 权限配置

    供权限设置使用,精确限定某个用户能看哪些页面的数据。 详见 其它 -- 权限管理。

  9. 数据源配置

    示例策略:同一设备一天内限制登录1000次 那么每次登陆就需要上报一条数据,系统会分类计数,并分类存储。 存储的名字叫啥?就是此处要配置的数据源。对于此策略,只需要配置数据源,命名为login_uid, 字段包含uid, uid类型是string。然后程序就能根据uid为维度计数,并自动计算指定时间窗口内是否超出指定阈值。

    重要:由于逻辑必然依赖时间信息,为通用且必需字段,timestamp为默认隐含字段,类型是时间戳(精确到秒,整数)
    Here Insert Picture Description

    调用样例

  10. 调用查询服务

    假设存在id为1的规则,则可以通过如下方式查询是否命中策略

curl 127.0.0.1:50000/query/ -X POST -d '{"rule_id": "1", "user_id": "10000"}' -H "Content-Type:application/json"
  1. 调用上报服务

    假设存在名称为test的数据源, 且数据源含有的数据是: {"ip": "string", "user_id": "string", "uid": "string"}

curl 127.0.0.1:50000/report/ -X POST -d '{"source": "test", "user_id": "10000", "ip": "127.0.0.1", "uid": "abcabc112333222", "timestamp": 1559049606}' -H "Content-Type:application/json"
  1. 关于服务拆分

    开源样例中,为了简化安装部署,查询和上报揉进了一个服务。实际场景中,显然读写应该分离。

    1.可以直接此方式部署2份,域名不同,一份用于查询(上报接口不被访问),一份用于上报(查询接口不被访问),流量分发在nginx层完成

    2.risk_server.py中修改配置URL_2_HANDLERS,选择您需要的服务接口部署

内置函数的扩展

  1. 不带阈值的内置函数扩展

    是否异常用户内置函数为例
    代码见 aswan/buildin_funcs/sample.py 中的 is_abnormal 方法

  2. 带阈值的内置函数布尔型策略扩展

    历史登录次数内置函数为例
    代码见 aswan/buildin_funcs/sample.py 中的 user_login_count 方法
    注意:阈值计算不包含在内置函数中进行,控制流详见 aswan/buildin_funcs/base.py

其它

增加用户

考虑到企业用户大多数为域账户登录,因此推荐使用LDAP认证模块直接集成。但考虑到大家的场景不一样,因此也可以手动增加用户,样例代码如下:

# coding=utf-8
from django.contrib.auth.models import User

username = 'username'
password = 'password'
email = '[email protected]'
first_name = '测'
last_name = '试'
# 普通用户
User.objects.create_user(username=username, password=password, email=email, first_name=first_name, last_name=last_name)
# 管理员账户
User.objects.create_superuser(username=username, password=password, email=email, first_name=first_name, last_name=last_name)

添加完成后,让用户登录,然后管理员配置权限即可。

权限管理

目前的权限模型包含如下元素,可在对应的页面进行配置。

Here Insert Picture Description

具体图示如下:

Here Insert Picture Description

Here Insert Picture Description

Here Insert Picture Description

配置相关

目前Django部分的配置均存放于 www/settings 目录,非Django部分的配置均位于 config 目录下。

为了在不同环境加载不同的配置,我们使用了RISK_ENV这个环境变量,系统在运行时会自动通过这个环境变量的值加载对应的配置文件。

To facilitate the project started, when this value is not set, the system will load the default configuration develop environment. The test is executed when (python manage.py test), the value of RISK_ENV must be a test.

Past Recommended

Find out more public attention number: TJ Jun

Guess you like

Origin blog.51cto.com/14299052/2411270