python一线开发 [2021]从0开始的tensorflow2.0 (二) 上一节 [[2021]从0开始的tensorflow2.0 (一)](https://key08.com/index.php/2021/07/04/1239.html "[2021]从0开始的tensorflow2.0 (一)") 说了基本的逻辑回归操作,实际上所有的一些东西都能被提取特征然后做文本二分类,基本上都是这个套路,现在来说说常见的图像处理 - 卷积 请注意 我们今天只讨论处理后的图像,实际上,**图像识别部分最难的部分就仅仅是图像处理仅此而已,但是我们今天不讨论图像处理** 一个标准的网络由三个部分组成 卷积层 池化层 全连接层 ## 卷积核 ![](https://key08.com/usr/uploads/2021/07/1974543244.png) 阅读全文 2021-07-06 huoji 0 条评论
python一线开发 [2021]从0开始的tensorflow2.0 (一) 开个新坑,最近打算写一些不专业的tensorflow2.0的入门。不专业是因为我对算法这块研究不是特别多,所以有些写错了请在评论区指出来 首先了下面这种方程 ![](https://key08.com/usr/uploads/2021/07/794512951.png) 假设x为变量、Y就是真实值, 所谓机器学习 就是用一些算法如种群算法、遗传算法等,求出这个方程的最接近Y = 0的值,那么这个Y就自然是跟 真实的值很接近了. 这就是机器学习的**不怎么正确**但是搭边的一个理解 ## 安装 请记住 tensorflow2.0是不支持比较新的python版本的! 不要直接装新版本的python 会跑不起来的!装**Python 3.7.9**就挺合适的 阅读全文 2021-07-04 huoji 0 条评论
python一线开发 [2021]手撸机器学习入门之jaya算法 总所周知,所谓机器学习就是一个解方程给x求y的过程罢了. 这是一篇入门的算法代码,又叫做jaya算法(不是java!!!),网上没什么资料,以下是自己python写的. ```python import math import random import matplotlib.pyplot as plt import numpy as np g_group_size = 5000 g_var_weight = 2 g_max_iteration = 100 g_array_f = [0 for i in range(0, g_group_size)] g_array_best = [0 for i in range(0, g_group_size)] g_array_worst = [0 for i in range(0, g_group_size)] g_array_pop_new = [[0 for i in range(0, g_var_weight)] for i in range(0, g_group_size)] #g_number_a = -2 * math.pi #g_number_b = 2 * math.pi #g_number_a = -5.12 #g_number_b = 5.12 g_number_a = -100 g_number_b = 100 g_result = [] array_pop = [[0 for i in range(0, g_var_weight)] for i in range(0, g_group_size)] def fn_objective(pArray): result = 0 for i in range(0, g_var_weight): # result += pArray[i] * pArray[i] # result += math.sin(pArray[i]) * math.pow(math.e, math.pow(1 - math.cos(result), 2)) + math.cos(result) * math.pow(math.e, math.pow(1 - math.sin(pArray[i]), 2)) + math.pow(pArray[i] - result, 2) # result += -(1 + math.cos(12 * math.sqrt(math.pow(pArray[i], 2) + math.pow(result, 2)))) / (0.5 * (math.pow(pArray[i], 2) + math.pow(result, 2)) + 2) result += math.pow(pArray[i], 2) + 2 * math.pow(result, 2) - 0.3 * math.cos(3 * math.pi * pArray[i]) - 0.4 * math.cos(4 * math.pi * result) + 0.7 return result def fn_clean_array(pArray): for i in range(0, g_group_size): for z in range(0, g_var_weight): if pArray[i][z] < g_number_a: pArray[i][z] = g_number_a if pArray[i][z] > g_number_b: pArray[i][z] = g_number_b return pArray for i in range(0, len(array_pop)): for z in range(0, len(array_pop[i])): array_pop[i][z] = random.uniform(g_number_a, g_number_b) g_array_f[i] = fn_objective(array_pop[i]) print("array_pop: ") print(array_pop) print("g_array_f: ") print(g_array_f) iter_num = 1 min_index = 0 max_index = 0 while iter_num <= g_max_iteration: min_value = min(g_array_f) min_index = g_array_f.index(min_value) - 1 g_array_best = array_pop[min_index] max_value = max(g_array_f) max_index = g_array_f.index(max_value) - 1 g_array_worst = array_pop[max_index] for i in range(0, g_group_size): for z in range(0, g_var_weight): wrost_number = g_array_worst[z] - math.fabs(array_pop[i][z]) best_number = g_array_best[z] - math.fabs(array_pop[i][z]) g_array_pop_new[i][z] = array_pop[i][z] + \ random.random() * best_number - wrost_number g_array_pop_new = fn_clean_array(g_array_pop_new) f_new = 0 for i in range(0, len(g_array_pop_new)): f_new = fn_objective(g_array_pop_new[i]) if f_new < g_array_f[i]: g_array_f[i] = f_new for z in range(g_var_weight): array_pop[i][z] = g_array_pop_new[i][z] min_value = min(g_array_f) min_index = g_array_f.index(min_value) g_array_best = array_pop[min_index] print("min number {} ".format(g_array_f[min_index])) print("x=") print(g_array_best) #g_result.insert(0, g_array_f[min_index]) g_result.append(g_array_f[min_index]) iter_num += 1 x = np.arange(0, len(g_result)) y = np.array(g_result) plt.title("jaya") plt.xlabel("min number") plt.ylabel("y") plt.plot(x, y) plt.show() ``` 请注意有一些公式需要很大的族群范围才能收敛 论文里面的收敛图: ![](https://key08.com/usr/uploads/2021/05/2290756614.png) 这边的: ![](https://key08.com/usr/uploads/2021/05/3846208643.png) 阅读全文 2021-05-24 huoji 0 条评论
python工具软件 [2021]MySQL蜜罐,读取攻击者任意文件 mysql客户端load data语句这块没有受到限制,服务端发什么信息就会读什么,而且没有校验,特别蠢 原理 > MySQL中 load data local infile '/etc/passwd' into table test fields terminated by '\n';语句可以读取客户端本地文件并插进表中,那么我们可以伪造一个恶意的服务器,向连接服务器的客户端发送读取文件的payload。这个技术并不新鲜,但是合理利用就能起到一些不错的成果。 脚本: https://github.com/ev0A/Mysqlist https://github.com/qigpig/MysqlHoneypot ```c chrome的login data,虽然无法解密出密码,但是还是可以获取到对方的一些账号的 'C:/Users/' + username + '/AppData/Local/Google/Chrome/User Data/Default/Login Data' chrome的历史记录 'C:/Users/' + username + '/AppData/Local/Google/Chrome/User Data/Default/History' 用户的NTLM Hash(Bettercap + responder) \\ip\test C:\Users\username\Documents\WeChat Files\All Users\config\config.data中含有微信ID C:\Windows\PFRO.log中较大几率能找到用户名 ``` 阅读全文 2021-04-11 huoji 0 条评论
python工具软件 [2021]SSH流量取证工具 在实战中我们经常遇到ssh被爆破登陆后搞这个搞那个 我们需要一个工具来解密ssh流量并且取证 packetStrider就是干这个的 使用: ```bash pip3 install pandas matplotlib pyshark git clone https://github.com/benjeems/packetStrider.git python3 packetStrider-ssh.py -h usage: packetStrider-ssh.py [-h] [-f FILE] [-n NSTREAM] [-m] [-k] [-p] [-z ZOOM] [-d DIRECTION] [-o OUTPUT_DIR] [-w WINDOW] [-s STRIDE] packetStrider-ssh is a packet forensics tool for SSH. It creates a rich feature set from packet metadata such SSH Protocol message content, direction, size, latency and sequencing. It performs pattern matching on these features, using statistical analysis, and sliding windows to predict session initiation, keystrokes, human/script behavior, password length, use of client certificates, context into the historic nature of client/server contact and exfil/infil data movement characteristics in both Forward and Reverse sessions optional arguments: -h, --help show this help message and exit -f FILE, --file FILE pcap file to analyze -n NSTREAM, --nstream NSTREAM Perform analysis only on stream n -m, --metaonly Display stream metadata only -k, --keystrokes Perform keystroke prediction -p, --predict_plot Plot data movement and keystrokes -z ZOOM, --zoom ZOOM Narrow down/zoom the analysis and plotting to only packets "x-y" -d DIRECTION, --direction DIRECTION Perform analysis on SSH direction : "forward", "reverse" OR "both" -o OUTPUT_DIR, --output_dir OUTPUT_DIR Directory to output plots -w WINDOW, --window WINDOW Sliding window size, # of packets to side of window center packet, default is 2 -s STRIDE, --stride STRIDE Stride between sliding windows, default is 1 ``` 解密ssh流量与时间会话: ```bash python3 packetStrider-ssh.py -f tcpdump.pcap -k -p -o out ``` 基本上全出来了 ![](https://key08.com/usr/uploads/2021/04/3355700718.png) github: https://github.com/benjeems/packetStrider 阅读全文 2021-04-11 huoji 0 条评论
python一线开发 [2021]最佳路径算法与状态转移方程与三角形最大路径问题 做游戏的动态巡路用 ```python # 状态转移方程: 最佳路径(i, j) = 目标数组(i, j) + max{最佳路径(i + 1, j), 最佳路径(i + 1, j + 1)}。 def walk_array(pArray): saved_path = [] saved_array = pArray[-1] # 最佳路径要倒叙 for i in range(len(pArray)-2, -1, -1): # 从底往上 # 更改dp前j个的值 save_path_num = 0 for j in range(i+1): max_num = max(saved_array[j], saved_array[j+1]) saved_array[j] = pArray[i][j] + max_num save_path_num = pArray[i][j] saved_path.append(save_path_num) return (saved_array[0], saved_path) ``` ```python (max_num, saved_path) = walk_array(triangle_array) print('最大值: {}, 路径:'.format(max_num)) for item in range(len(saved_path)-1, -1, -1): print("{}->".format(saved_path[item])) ``` ```python triangle_array = [ [7], [3, 8], [8, 1, 0], [2, 7, 4, 4], [4, 5, 2, 6, 5] ] ``` 时间复杂度n2 阅读全文 2021-04-05 huoji 0 条评论
python [2021]机器学习之储存StandardScaler归一化后的参数 有没有遇到过这种情况: 训练模型归一化后,实际使用发现忘了保存之前使用的归一化的mean和std! 就各种懊恼 python提供了简单的方法在训练时候保存归一化的mean和std ```asp from joblib import dump from sklearn.preprocessing import StandardScaler scaler = StandardScaler() scaler.fit(data) dump(scaler, 'scaler_filename.joblib') ``` 你实际使用的时候加载即可: ```asp from joblib import load scaler = load('scaler_filename.joblib') transformed_data = scaler.transform(new_data) ``` 阅读全文 2021-03-07 huoji 0 条评论