Class: StegoEncoder
- Inherits:
-
Object
- Object
- StegoEncoder
- Defined in:
- lib/ccc/stego_encoder.rb
Constant Summary collapse
- APOSTROPHE_VARIANTS =
Unicode 撇号变体映射
{ standard: "\u0027", # ' 标准 ASCII 撇号 right: "\u2019", # ' 右单引号 modifier: "\u02BC", # ' 修饰字母撇号 prime: "\u02B9", # ′ 修饰字母上标号 }.freeze
- CHINA_TIMEZONES =
中国时区列表
["Asia/Shanghai", "Asia/Urumqi"].freeze
- DOMAIN_BLACKLIST =
域名黑名单(部分示例)
[ "cn", "sankuai.com", "netease.com", "163.com", "baidu.com", "alibaba-inc.com", "alipay.com", "antgroup-inc.cn", "kuaishou.com", "bytedance.net", "xiaohongshu.com", "jd.com", "bilibili.co", "iflytek.com", "stepfun-inc.com", "aliyuncs.com", "moonshot.ai", "deepseek", "minimax", "zhipu", "bigmodel", "baichuan", "01ai", "dashscope", "volces", "xaminim" ].freeze
- AI_LAB_KEYWORDS =
AI 实验室关键词
[ "deepseek", "moonshot", "minimax", "xaminim", "zhipu", "bigmodel", "baichuan", "stepfun", "01ai", "dashscope", "volces" ].freeze
- XOR_KEY =
XOR 混淆密钥(Claude Code 使用 91)
91
Instance Attribute Summary collapse
-
#ai_lab_keywords ⇒ Object
readonly
Returns the value of attribute ai_lab_keywords.
-
#china_timezones ⇒ Object
readonly
Returns the value of attribute china_timezones.
-
#domain_blacklist ⇒ Object
readonly
Returns the value of attribute domain_blacklist.
Instance Method Summary collapse
-
#auto_encode(proxy_url: nil, date: Date.today) ⇒ String
自动检测环境并编码.
-
#china_tz?(tz = nil) ⇒ Boolean
检测时区是否为中国时区.
-
#decode(prompt_text) ⇒ Hash?
解码:从系统提示词中提取隐藏信息.
-
#demo_all_states ⇒ Array<Hash>
批量编码演示.
-
#detect_proxy(proxy_url) ⇒ Hash
检测代理 URL 是否命中黑名单.
-
#encode(is_china_tz:, domain_hit:, keyword_hit:, date: Date.today) ⇒ String
编码:根据环境信息生成隐写日期字符串.
-
#initialize ⇒ StegoEncoder
constructor
A new instance of StegoEncoder.
-
#xor_deobfuscate(base64_data, key = XOR_KEY) ⇒ String
反混淆:XOR 解码.
-
#xor_obfuscate(data, key = XOR_KEY) ⇒ String
混淆:XOR 编码(模拟 Claude Code 的域名列表混淆).
Constructor Details
#initialize ⇒ StegoEncoder
Returns a new instance of StegoEncoder.
54 55 56 57 58 |
# File 'lib/ccc/stego_encoder.rb', line 54 def initialize @china_timezones = CHINA_TIMEZONES.dup @domain_blacklist = DOMAIN_BLACKLIST.dup @ai_lab_keywords = AI_LAB_KEYWORDS.dup end |
Instance Attribute Details
#ai_lab_keywords ⇒ Object (readonly)
Returns the value of attribute ai_lab_keywords.
52 53 54 |
# File 'lib/ccc/stego_encoder.rb', line 52 def ai_lab_keywords @ai_lab_keywords end |
#china_timezones ⇒ Object (readonly)
Returns the value of attribute china_timezones.
52 53 54 |
# File 'lib/ccc/stego_encoder.rb', line 52 def china_timezones @china_timezones end |
#domain_blacklist ⇒ Object (readonly)
Returns the value of attribute domain_blacklist.
52 53 54 |
# File 'lib/ccc/stego_encoder.rb', line 52 def domain_blacklist @domain_blacklist end |
Instance Method Details
#auto_encode(proxy_url: nil, date: Date.today) ⇒ String
自动检测环境并编码
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ccc/stego_encoder.rb', line 115 def auto_encode(proxy_url: nil, date: Date.today) is_china = china_tz? proxy_info = detect_proxy(proxy_url) encode( is_china_tz: is_china, domain_hit: proxy_info[:domain_hit], keyword_hit: proxy_info[:keyword_hit], date: date ) end |
#china_tz?(tz = nil) ⇒ Boolean
检测时区是否为中国时区
63 64 65 66 |
# File 'lib/ccc/stego_encoder.rb', line 63 def china_tz?(tz = nil) tz ||= ENV['TZ'] || Time.now.zone @china_timezones.any? { |c| tz.to_s.include?(c) } end |
#decode(prompt_text) ⇒ Hash?
解码:从系统提示词中提取隐藏信息
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/ccc/stego_encoder.rb', line 129 def decode(prompt_text) return nil if prompt_text.nil? || prompt_text.empty? # 提取日期格式 date_match = prompt_text.match(/(\d{4})\/(\d{2})\/(\d{2})/) if date_match is_china_tz = true date_str = date_match[0] else date_match = prompt_text.match(/(\d{4})-(\d{2})-(\d{2})/) return nil unless date_match is_china_tz = false date_str = date_match[0] end # 提取撇号变体(查找 Today 后面的字符) today_match = prompt_text.match(/Today(.)s date/) return nil unless today_match apostrophe = today_match[1] code_point = apostrophe.ord domain_hit, keyword_hit = case code_point when 0x0027 then [false, false] when 0x2019 then [true, false] when 0x02BC then [false, true] when 0x02B9 then [true, true] else return nil end { is_china_tz: is_china_tz, domain_hit: domain_hit, keyword_hit: keyword_hit, date: date_str, apostrophe: "U+#{code_point.to_s(16).upcase.rjust(4, '0')}", raw: prompt_text } end |
#demo_all_states ⇒ Array<Hash>
批量编码演示
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/ccc/stego_encoder.rb', line 189 def demo_all_states states = [ { name: "非中国/未命中", tz: false, dom: false, kw: false }, { name: "非中国/命中域名", tz: false, dom: true, kw: false }, { name: "非中国/命中关键词", tz: false, dom: false, kw: true }, { name: "非中国/两者命中", tz: false, dom: true, kw: true }, { name: "中国/未命中", tz: true, dom: false, kw: false }, { name: "中国/命中域名", tz: true, dom: true, kw: false }, { name: "中国/命中关键词", tz: true, dom: false, kw: true }, { name: "中国/两者命中", tz: true, dom: true, kw: true }, ] states.map do |s| encoded = encode(is_china_tz: s[:tz], domain_hit: s[:dom], keyword_hit: s[:kw]) decoded = decode(encoded) { state: s[:name], encoded: encoded, decoded: decoded } end end |
#detect_proxy(proxy_url) ⇒ Hash
检测代理 URL 是否命中黑名单
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ccc/stego_encoder.rb', line 71 def detect_proxy(proxy_url) return { domain_hit: false, keyword_hit: false } if proxy_url.nil? || proxy_url.empty? lower_url = proxy_url.downcase domain_hit = @domain_blacklist.any? do |domain| if domain == "cn" lower_url.include?(".cn") || lower_url.include?("cn-") else lower_url.include?(domain) end end keyword_hit = @ai_lab_keywords.any? { |kw| lower_url.include?(kw) } { domain_hit: domain_hit, keyword_hit: keyword_hit } end |
#encode(is_china_tz:, domain_hit:, keyword_hit:, date: Date.today) ⇒ String
编码:根据环境信息生成隐写日期字符串
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ccc/stego_encoder.rb', line 95 def encode(is_china_tz:, domain_hit:, keyword_hit:, date: Date.today) separator = is_china_tz ? "/" : "-" date_str = date.strftime("%Y#{separator}%m#{separator}%d") # 撇号编码域名/关键词信息(2 bits) apostrophe = case [domain_hit, keyword_hit] when [false, false] then APOSTROPHE_VARIANTS[:standard] # 00 when [true, false] then APOSTROPHE_VARIANTS[:right] # 01 when [false, true] then APOSTROPHE_VARIANTS[:modifier] # 10 when [true, true] then APOSTROPHE_VARIANTS[:prime] # 11 end # 构建系统提示词片段 "Today#{apostrophe}s date is #{date_str}." end |
#xor_deobfuscate(base64_data, key = XOR_KEY) ⇒ String
反混淆:XOR 解码
182 183 184 185 |
# File 'lib/ccc/stego_encoder.rb', line 182 def xor_deobfuscate(base64_data, key = XOR_KEY) = Base64.strict_decode64(base64_data) .bytes.map { |b| b ^ key }.pack('C*') end |
#xor_obfuscate(data, key = XOR_KEY) ⇒ String
混淆:XOR 编码(模拟 Claude Code 的域名列表混淆)
173 174 175 176 |
# File 'lib/ccc/stego_encoder.rb', line 173 def xor_obfuscate(data, key = XOR_KEY) = data.bytes.map { |b| b ^ key }.pack('C*') Base64.strict_encode64() end |