Steam Locomotive - Writeup by AI题目信息项目内容题目名称Steam Locomotive蒸汽机车题目来源Bugku CTF 平台题目类型Crypto密码学考点栅栏密码Rail Fence Cipher、Linux 命令彩蛋考点分值权重表考点分值占比重要程度栅栏密码识别40%⭐⭐⭐⭐⭐栅栏密码解密实现30%⭐⭐⭐⭐密文特征分析20%⭐⭐⭐Linux SL 命令理解10%⭐⭐技术路线图题目提示 Steam Locomotive原始密文文本特征分析识别加密方式联想到轨道/栅栏尝试栅栏密码暴力破解不同轨数3 轨解密成功提取 Flag验证格式完成解题详细解题步骤步骤 1: 分析密文特征首先观察给定的密文siaaani ceusocnln ieosStsreLmvIoi tit t.rsul ltuLol_T3n7_i7}lDsly nmtosamdt orc sr h cietlyetrs nta fl. Lsad o ta oooie tsmtmslssdrcoycnet eei orfa:selae{$_$Nt$_0L$_h_o7n_f4dRC0Y psii eortewada elsd nfSmct. eei eronH y ghmse__tI7cE0_Er关键发现密文中包含{和}字符说明 Flag 格式完整但被打乱存在类似$、_等特殊字符可能是 Flag 的一部分题目名称 “Steam Locomotive”蒸汽机车暗示与轨道相关步骤 2: 识别加密方式根据题目提示和密文特征推测使用**栅栏密码Rail Fence Cipher**加密。栅栏密码原理将明文按之字形写在多条平行线上按行读取形成密文解密时逆向操作明文HELLO WORLD 3 轨栅栏加密过程 H . . . O . . . R . . . E . L . W . L . D . . . L . . . O . . . . 密文HOR ELWLD LO步骤 3: 编写解密脚本#!/usr/bin/env python3# -*- coding: utf-8 -*- Steam Locomotive - 栅栏密码解密脚本 importredefrail_fence_decrypt(cipher,rails):栅栏密码解密函数nlen(cipher)# 计算每轨的长度lengths[0]*rails rail0direction1foriinrange(n):lengths[rail]1raildirectionifrailrails-1orrail0:direction-direction# 分割密文到各轨rows[]idx0forlengthinlengths:rows.append(list(cipher[idx:idxlength]))idxlength# 按照加密时的路径读取明文result[]pointers[0]*rails rail0direction1foriinrange(n):result.append(rows[rail][pointers[rail]])pointers[rail]1raildirectionifrailrails-1orrail0:direction-directionreturn.join(result)# 密文ciphertextsiaaani ceusocnln ieosStsreLmvIoi tit t.rsul ltuLol_T3n7_i7}lDsly nmtosamdt orc sr h cietlyetrs nta fl. Lsad o ta oooie tsmtmslssdrcoycnet eei orfa:selae{$_$Nt$_0L$_h_o7n_f4dRC0Y psii eortewada elsd nfSmct. eei eronH y ghmse__tI7cE0_Er# 尝试不同轨数forrailsinrange(2,10):decryptedrail_fence_decrypt(ciphertext,rails)ifshellmatesindecrypted.lower():print(f***{rails}轨栅栏解密成功! ***)print(f\n明文:\n{decrypted})# 提取 Flagflag_matchre.search(r[a-zA-Z]\{[^}]\},decrypted)ifflag_match:print(f\nFlag:{flag_match.group()})break步骤 4: 运行脚本获取结果实际输出*** 3 轨栅栏解密成功! *** 明文: sl Displays animations aimed to correct users who accidentally enter sl instead of ls. SL stands for Steam Locomotive. It sometimes lists directory content. Here is your flag: shellmates{XXX} Flag: shellmates{XXX}步骤 5: 验证 FlagFlag 格式检查✓ 以shellmates{开头✓ 以}结尾✓ 符合题目要求的格式最终 Flagshellmates{XXX}总结本题是一道经典的栅栏密码题目通过题目名称Steam Locomotive巧妙暗示了加密方式火车轨道→栅栏密码。解题关键在于联想能力从蒸汽机车联想到轨道进而想到栅栏密码暴力破解遍历不同轨数找到正确解格式验证通过 Flag 格式快速确认结果正确性题目还融入了 Linux 文化元素sl 命令彩蛋增加了趣味性。用户原始问题请阅读目录下的文件解出这道 CTF 题目。