日度归档:2022年5月27日

正则表达式,用于提取日志中的异常WEB请求的来源IP地址 2022-5-27

段落1、WEB异常日志分析

WEB日志里面,很多异常

用正则表达式,提取日志中的,异常请求日志,把来源IP地址都提取出来

段落2、代码,python3

#!/usr/bin/python3
# -*- coding:utf-8 -*-
import re

pttn_ssl_crit = ", client: (\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3}), server: 0.0.0.0:443"

s = """
2022/05/27 05:57:08 [crit] 22177#22177: *1505702 SSL_do_handshake() failed (SSL: error:141CF06C:SSL routines:tls_parse_ctos_key_share:bad key share) while SSL handshaking, client: 192.241.221.194, server: 0.0.0.0:443
2022/05/27 05:58:12 [crit] 22177#22177: *1505686 SSL_shutdown() failed (SSL: error:1409F07F:SSL routines:ssl3_write_pending:bad write retry) while closing request, client: 42.185.73.106, server: 0.0.0.0:443
2022/05/27 12:35:25 [crit] 22177#22177: *1539457 SSL_do_handshake() failed (SSL: error:141CF06C:SSL routines:tls_parse_ctos_key_share:bad key share) while SSL handshaking, client: 64.62.197.122, server: 0.0.0.0:443
2022/05/27 12:37:56 [crit] 22177#22177: *1539653 SSL_do_handshake() failed (SSL: error:141CF06C:SSL routines:tls_parse_ctos_key_share:bad key share) while SSL handshaking, client: 125.80.138.80, server: 0.0.0.0:443
2022/05/27 14:41:39 [crit] 22177#22177: *1553119 SSL_do_handshake() failed (SSL: error:141CF06C:SSL routines:tls_parse_ctos_key_share:bad key share) while SSL handshaking, client: 154.89.5.85, server: 0.0.0.0:443
2022/05/27 15:22:47 [crit] 22177#22177: *1557066 SSL_do_handshake() failed (SSL: error:141CF06C:SSL routines:tls_parse_ctos_key_share:bad key share) while SSL handshaking, client: 37.252.255.135, server: 0.0.0.0:443
"""

print(re.findall(pttn_ssl_crit,s))
输出:

['192.241.221.194', '42.185.73.106', '64.62.197.122', '125.80.138.80', '154.89.5.85', '37.252.255.135']

透明代理,iptables技术 2022-5-27

段落1、需求说明

配置透明代理,可根据IP地域,进行路由定向。

本教程,对初学者有相当的难度,需要对iptables规则熟练于心,有差错,整个网络可能出现你无法预料的故障。

GeoIP CN的目标地址,直连

Local,本地地址,保留地址,直连

Node Server,直连

其他,走 socks5://127.0.0.1:10808

段落2、基础设施

系统环境 Ubuntu 20.04 LTS

GeoIP CN的IP CIDR地址清单

ipset 工具集

node server 1枚

段落3、iptables基础知识

段落4、配置方式

# 创建自定义的chain链
iptables -t nat -N V2FLY                 # 在NAT表创建链
iptables -t mangle -N V2FLY              # 在MANAGE表创建链

# 让你的V2FLY服务器IP走直连direct
iptables -t nat -A V2FLY -d AA.BB.CC.DD -j RETURN    # 这里指定NodeServer地址,return 继续执行自定义的动作

# 让你的局域网IP及其他本地及保留地址走direct
# Ignore LANs and any other addresses you'd like to bypass the proxy
# See Wikipedia and RFC5735 for full list of reserved networks.
# See ashi009/bestroutetb for a highly optimized CHN route list.
iptables -t nat -A V2FLY -d 0.0.0.0/8 -j RETURN
iptables -t nat -A V2FLY -d 10.0.0.0/8 -j RETURN
iptables -t nat -A V2FLY -d 127.0.0.0/8 -j RETURN
iptables -t nat -A V2FLY -d 169.254.0.0/16 -j RETURN
iptables -t nat -A V2FLY -d 172.16.0.0/12 -j RETURN
iptables -t nat -A V2FLY -d 192.168.0.0/16 -j RETURN
iptables -t nat -A V2FLY -d 224.0.0.0/4 -j RETURN
iptables -t nat -A V2FLY -d 240.0.0.0/4 -j RETURN

# 其他流量都重定向到你的本地的V2FLY-CLIENT本地端口
iptables -t nat -A V2FLY -p tcp -j REDIRECT --to-ports 10808

# 其他一些DNS流量
# Add any UDP rules
ip route add local default dev lo table 100
ip rule add fwmark 1 lookup 100
iptables -t mangle -A V2FLY -p udp --dport 53 -j TPROXY --on-port 10808 --tproxy-mark 0x01/0x01

# 应用规则,将自定义的链加入到传统的链中
iptables -t nat -A PREROUTING -p tcp -j V2FLY
iptables -t mangle -A PREROUTING -j V2FLY

# 启动客户端 V2FLY-CLIENT 进程常驻
/usr/bin/v2ray/v2ray -config /etc/config/V2FLY.json 
iptables -t nat -I PREROUTING -p tcp -m set --match-set redrock dst -j REDIRECT --to-ports 8848
iptables -t nat -I OUTPUT -p tcp -m set --match-set redrock dst -j REDIRECT --to-ports 8848